]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.4-201303210011.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.4-201303210011.patch
CommitLineData
5cc84d03
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..b47493f 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@@ -185,6 +204,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@@ -194,6 +215,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160+pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164@@ -203,7 +225,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@@ -213,8 +238,12 @@ series
176 setup
177 setup.bin
178 setup.elf
179+signing_key*
180+size_overflow_hash.h
181 sImage
182+slabinfo
183 sm_tbl*
184+sortextable
185 split-include
186 syscalltab.h
187 tables.c
188@@ -224,6 +253,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192+user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196@@ -235,13 +265,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200+vdsox32.lds
201+vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208+vmlinux.bin.bz2
209 vmlinux.lds
210+vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214@@ -249,9 +283,12 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218+utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222+x509*
223 zImage*
224 zconf.hash.c
225+zconf.lex.c
226 zoffset.h
227diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
228index 986614d..e8bfedc 100644
229--- a/Documentation/kernel-parameters.txt
230+++ b/Documentation/kernel-parameters.txt
231@@ -922,6 +922,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
232 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
233 Default: 1024
234
235+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
236+ ignore grsecurity's /proc restrictions
237+
238+
239 hashdist= [KNL,NUMA] Large hashes allocated during boot
240 are distributed across NUMA nodes. Defaults on
241 for 64-bit NUMA, off otherwise.
242@@ -2121,6 +2125,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
243 the specified number of seconds. This is to be used if
244 your oopses keep scrolling off the screen.
245
246+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
247+ virtualization environments that don't cope well with the
248+ expand down segment used by UDEREF on X86-32 or the frequent
249+ page table updates on X86-64.
250+
251+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
252+
253+ pax_extra_latent_entropy
254+ Enable a very simple form of latent entropy extraction
255+ from the first 4GB of memory as the bootmem allocator
256+ passes the memory pages to the buddy allocator.
257+
258 pcbit= [HW,ISDN]
259
260 pcd. [PARIDE]
261diff --git a/Makefile b/Makefile
262index e20f162..11365cc 100644
263--- a/Makefile
264+++ b/Makefile
265@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
266
267 HOSTCC = gcc
268 HOSTCXX = g++
269-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
270-HOSTCXXFLAGS = -O2
271+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
272+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
273+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
274
275 # Decide whether to build built-in, modular, or both.
276 # Normally, just do built-in.
277@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
278 # Rules shared between *config targets and build targets
279
280 # Basic helpers built in scripts/
281-PHONY += scripts_basic
282-scripts_basic:
283+PHONY += scripts_basic gcc-plugins
284+scripts_basic: gcc-plugins
285 $(Q)$(MAKE) $(build)=scripts/basic
286 $(Q)rm -f .tmp_quiet_recordmcount
287
288@@ -575,6 +576,62 @@ else
289 KBUILD_CFLAGS += -O2
290 endif
291
292+ifndef DISABLE_PAX_PLUGINS
293+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
294+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
295+else
296+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
297+endif
298+ifneq ($(PLUGINCC),)
299+ifndef CONFIG_UML
300+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
301+endif
302+ifdef CONFIG_PAX_MEMORY_STACKLEAK
303+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
304+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
305+endif
306+ifdef CONFIG_KALLOCSTAT_PLUGIN
307+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
308+endif
309+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
310+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
311+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
312+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
313+endif
314+ifdef CONFIG_CHECKER_PLUGIN
315+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
316+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
317+endif
318+endif
319+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
320+ifdef CONFIG_PAX_SIZE_OVERFLOW
321+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
322+endif
323+ifdef CONFIG_PAX_LATENT_ENTROPY
324+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
325+endif
326+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
327+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
328+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
329+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
330+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
331+ifeq ($(KBUILD_EXTMOD),)
332+gcc-plugins:
333+ $(Q)$(MAKE) $(build)=tools/gcc
334+else
335+gcc-plugins: ;
336+endif
337+else
338+gcc-plugins:
339+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
340+ $(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.))
341+else
342+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
343+endif
344+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
345+endif
346+endif
347+
348 include $(srctree)/arch/$(SRCARCH)/Makefile
349
350 ifdef CONFIG_READABLE_ASM
351@@ -731,7 +788,7 @@ export mod_sign_cmd
352
353
354 ifeq ($(KBUILD_EXTMOD),)
355-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
356+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
357
358 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
359 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
360@@ -778,6 +835,8 @@ endif
361
362 # The actual objects are generated when descending,
363 # make sure no implicit rule kicks in
364+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
365+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
366 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
367
368 # Handle descending into subdirectories listed in $(vmlinux-dirs)
369@@ -787,7 +846,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
370 # Error messages still appears in the original language
371
372 PHONY += $(vmlinux-dirs)
373-$(vmlinux-dirs): prepare scripts
374+$(vmlinux-dirs): gcc-plugins prepare scripts
375 $(Q)$(MAKE) $(build)=$@
376
377 # Store (new) KERNELRELASE string in include/config/kernel.release
378@@ -831,6 +890,7 @@ prepare0: archprepare FORCE
379 $(Q)$(MAKE) $(build)=.
380
381 # All the preparing..
382+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
383 prepare: prepare0
384
385 # Generate some files
386@@ -938,6 +998,8 @@ all: modules
387 # using awk while concatenating to the final file.
388
389 PHONY += modules
390+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
391+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
392 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
393 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
394 @$(kecho) ' Building modules, stage 2.';
395@@ -953,7 +1015,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
396
397 # Target to prepare building external modules
398 PHONY += modules_prepare
399-modules_prepare: prepare scripts
400+modules_prepare: gcc-plugins prepare scripts
401
402 # Target to install modules
403 PHONY += modules_install
404@@ -1019,7 +1081,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
405 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
406 signing_key.priv signing_key.x509 x509.genkey \
407 extra_certificates signing_key.x509.keyid \
408- signing_key.x509.signer
409+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
410
411 # clean - Delete most, but leave enough to build external modules
412 #
413@@ -1059,6 +1121,7 @@ distclean: mrproper
414 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
415 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
416 -o -name '.*.rej' \
417+ -o -name '.*.rej' -o -name '*.so' \
418 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
419 -type f -print | xargs rm -f
420
421@@ -1219,6 +1282,8 @@ PHONY += $(module-dirs) modules
422 $(module-dirs): crmodverdir $(objtree)/Module.symvers
423 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
424
425+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 modules: $(module-dirs)
428 @$(kecho) ' Building modules, stage 2.';
429 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
430@@ -1355,17 +1420,21 @@ else
431 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
432 endif
433
434-%.s: %.c prepare scripts FORCE
435+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
436+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
437+%.s: %.c gcc-plugins prepare scripts FORCE
438 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
439 %.i: %.c prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441-%.o: %.c prepare scripts FORCE
442+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
443+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
444+%.o: %.c gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 %.lst: %.c prepare scripts FORCE
447 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
448-%.s: %.S prepare scripts FORCE
449+%.s: %.S gcc-plugins prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451-%.o: %.S prepare scripts FORCE
452+%.o: %.S gcc-plugins prepare scripts FORCE
453 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
454 %.symtypes: %.c prepare scripts FORCE
455 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
456@@ -1375,11 +1444,15 @@ endif
457 $(cmd_crmodverdir)
458 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
459 $(build)=$(build-dir)
460-%/: prepare scripts FORCE
461+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
462+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
463+%/: gcc-plugins prepare scripts FORCE
464 $(cmd_crmodverdir)
465 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
466 $(build)=$(build-dir)
467-%.ko: prepare scripts FORCE
468+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
469+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
470+%.ko: gcc-plugins prepare scripts FORCE
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir) $(@:.ko=.o)
474diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
475index c2cbe4f..f7264b4 100644
476--- a/arch/alpha/include/asm/atomic.h
477+++ b/arch/alpha/include/asm/atomic.h
478@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
479 #define atomic_dec(v) atomic_sub(1,(v))
480 #define atomic64_dec(v) atomic64_sub(1,(v))
481
482+#define atomic64_read_unchecked(v) atomic64_read(v)
483+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
484+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
485+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
486+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
487+#define atomic64_inc_unchecked(v) atomic64_inc(v)
488+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
489+#define atomic64_dec_unchecked(v) atomic64_dec(v)
490+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
491+
492 #define smp_mb__before_atomic_dec() smp_mb()
493 #define smp_mb__after_atomic_dec() smp_mb()
494 #define smp_mb__before_atomic_inc() smp_mb()
495diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
496index ad368a9..fbe0f25 100644
497--- a/arch/alpha/include/asm/cache.h
498+++ b/arch/alpha/include/asm/cache.h
499@@ -4,19 +4,19 @@
500 #ifndef __ARCH_ALPHA_CACHE_H
501 #define __ARCH_ALPHA_CACHE_H
502
503+#include <linux/const.h>
504
505 /* Bytes per L1 (data) cache line. */
506 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
507-# define L1_CACHE_BYTES 64
508 # define L1_CACHE_SHIFT 6
509 #else
510 /* Both EV4 and EV5 are write-through, read-allocate,
511 direct-mapped, physical.
512 */
513-# define L1_CACHE_BYTES 32
514 # define L1_CACHE_SHIFT 5
515 #endif
516
517+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
518 #define SMP_CACHE_BYTES L1_CACHE_BYTES
519
520 #endif
521diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
522index 968d999..d36b2df 100644
523--- a/arch/alpha/include/asm/elf.h
524+++ b/arch/alpha/include/asm/elf.h
525@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
526
527 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
528
529+#ifdef CONFIG_PAX_ASLR
530+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
531+
532+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
533+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
534+#endif
535+
536 /* $0 is set by ld.so to a pointer to a function which might be
537 registered using atexit. This provides a mean for the dynamic
538 linker to call DT_FINI functions for shared libraries that have
539diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
540index bc2a0da..8ad11ee 100644
541--- a/arch/alpha/include/asm/pgalloc.h
542+++ b/arch/alpha/include/asm/pgalloc.h
543@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544 pgd_set(pgd, pmd);
545 }
546
547+static inline void
548+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
549+{
550+ pgd_populate(mm, pgd, pmd);
551+}
552+
553 extern pgd_t *pgd_alloc(struct mm_struct *mm);
554
555 static inline void
556diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
557index 81a4342..348b927 100644
558--- a/arch/alpha/include/asm/pgtable.h
559+++ b/arch/alpha/include/asm/pgtable.h
560@@ -102,6 +102,17 @@ struct vm_area_struct;
561 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
562 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
563 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
564+
565+#ifdef CONFIG_PAX_PAGEEXEC
566+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
567+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
568+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
569+#else
570+# define PAGE_SHARED_NOEXEC PAGE_SHARED
571+# define PAGE_COPY_NOEXEC PAGE_COPY
572+# define PAGE_READONLY_NOEXEC PAGE_READONLY
573+#endif
574+
575 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
576
577 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
578diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
579index 2fd00b7..cfd5069 100644
580--- a/arch/alpha/kernel/module.c
581+++ b/arch/alpha/kernel/module.c
582@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
583
584 /* The small sections were sorted to the end of the segment.
585 The following should definitely cover them. */
586- gp = (u64)me->module_core + me->core_size - 0x8000;
587+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
588 got = sechdrs[me->arch.gotsecindex].sh_addr;
589
590 for (i = 0; i < n; i++) {
591diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
592index 14db93e..47bed62 100644
593--- a/arch/alpha/kernel/osf_sys.c
594+++ b/arch/alpha/kernel/osf_sys.c
595@@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
596 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
597
598 static unsigned long
599-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
600- unsigned long limit)
601+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
602+ unsigned long limit, unsigned long flags)
603 {
604 struct vm_area_struct *vma = find_vma(current->mm, addr);
605-
606+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
607 while (1) {
608 /* At this point: (!vma || addr < vma->vm_end). */
609 if (limit - len < addr)
610 return -ENOMEM;
611- if (!vma || addr + len <= vma->vm_start)
612+ if (check_heap_stack_gap(vma, addr, len, offset))
613 return addr;
614 addr = vma->vm_end;
615 vma = vma->vm_next;
616@@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
617 merely specific addresses, but regions of memory -- perhaps
618 this feature should be incorporated into all ports? */
619
620+#ifdef CONFIG_PAX_RANDMMAP
621+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
622+#endif
623+
624 if (addr) {
625- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
626+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
627 if (addr != (unsigned long) -ENOMEM)
628 return addr;
629 }
630
631 /* Next, try allocating at TASK_UNMAPPED_BASE. */
632- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
633- len, limit);
634+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
635+
636 if (addr != (unsigned long) -ENOMEM)
637 return addr;
638
639 /* Finally, try allocating in low memory. */
640- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
641+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
642
643 return addr;
644 }
645diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
646index 0c4132d..88f0d53 100644
647--- a/arch/alpha/mm/fault.c
648+++ b/arch/alpha/mm/fault.c
649@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
650 __reload_thread(pcb);
651 }
652
653+#ifdef CONFIG_PAX_PAGEEXEC
654+/*
655+ * PaX: decide what to do with offenders (regs->pc = fault address)
656+ *
657+ * returns 1 when task should be killed
658+ * 2 when patched PLT trampoline was detected
659+ * 3 when unpatched PLT trampoline was detected
660+ */
661+static int pax_handle_fetch_fault(struct pt_regs *regs)
662+{
663+
664+#ifdef CONFIG_PAX_EMUPLT
665+ int err;
666+
667+ do { /* PaX: patched PLT emulation #1 */
668+ unsigned int ldah, ldq, jmp;
669+
670+ err = get_user(ldah, (unsigned int *)regs->pc);
671+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
672+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
673+
674+ if (err)
675+ break;
676+
677+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
679+ jmp == 0x6BFB0000U)
680+ {
681+ unsigned long r27, addr;
682+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
684+
685+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686+ err = get_user(r27, (unsigned long *)addr);
687+ if (err)
688+ break;
689+
690+ regs->r27 = r27;
691+ regs->pc = r27;
692+ return 2;
693+ }
694+ } while (0);
695+
696+ do { /* PaX: patched PLT emulation #2 */
697+ unsigned int ldah, lda, br;
698+
699+ err = get_user(ldah, (unsigned int *)regs->pc);
700+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
701+ err |= get_user(br, (unsigned int *)(regs->pc+8));
702+
703+ if (err)
704+ break;
705+
706+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
707+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
708+ (br & 0xFFE00000U) == 0xC3E00000U)
709+ {
710+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
711+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
712+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
713+
714+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
715+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
716+ return 2;
717+ }
718+ } while (0);
719+
720+ do { /* PaX: unpatched PLT emulation */
721+ unsigned int br;
722+
723+ err = get_user(br, (unsigned int *)regs->pc);
724+
725+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
726+ unsigned int br2, ldq, nop, jmp;
727+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
728+
729+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
730+ err = get_user(br2, (unsigned int *)addr);
731+ err |= get_user(ldq, (unsigned int *)(addr+4));
732+ err |= get_user(nop, (unsigned int *)(addr+8));
733+ err |= get_user(jmp, (unsigned int *)(addr+12));
734+ err |= get_user(resolver, (unsigned long *)(addr+16));
735+
736+ if (err)
737+ break;
738+
739+ if (br2 == 0xC3600000U &&
740+ ldq == 0xA77B000CU &&
741+ nop == 0x47FF041FU &&
742+ jmp == 0x6B7B0000U)
743+ {
744+ regs->r28 = regs->pc+4;
745+ regs->r27 = addr+16;
746+ regs->pc = resolver;
747+ return 3;
748+ }
749+ }
750+ } while (0);
751+#endif
752+
753+ return 1;
754+}
755+
756+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
757+{
758+ unsigned long i;
759+
760+ printk(KERN_ERR "PAX: bytes at PC: ");
761+ for (i = 0; i < 5; i++) {
762+ unsigned int c;
763+ if (get_user(c, (unsigned int *)pc+i))
764+ printk(KERN_CONT "???????? ");
765+ else
766+ printk(KERN_CONT "%08x ", c);
767+ }
768+ printk("\n");
769+}
770+#endif
771
772 /*
773 * This routine handles page faults. It determines the address,
774@@ -133,8 +251,29 @@ retry:
775 good_area:
776 si_code = SEGV_ACCERR;
777 if (cause < 0) {
778- if (!(vma->vm_flags & VM_EXEC))
779+ if (!(vma->vm_flags & VM_EXEC)) {
780+
781+#ifdef CONFIG_PAX_PAGEEXEC
782+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
783+ goto bad_area;
784+
785+ up_read(&mm->mmap_sem);
786+ switch (pax_handle_fetch_fault(regs)) {
787+
788+#ifdef CONFIG_PAX_EMUPLT
789+ case 2:
790+ case 3:
791+ return;
792+#endif
793+
794+ }
795+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
796+ do_group_exit(SIGKILL);
797+#else
798 goto bad_area;
799+#endif
800+
801+ }
802 } else if (!cause) {
803 /* Allow reads even for write-only mappings */
804 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
805diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
806index 67874b8..0e40765 100644
807--- a/arch/arm/Kconfig
808+++ b/arch/arm/Kconfig
809@@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
810
811 config UACCESS_WITH_MEMCPY
812 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
813- depends on MMU
814+ depends on MMU && !PAX_MEMORY_UDEREF
815 default y if CPU_FEROCEON
816 help
817 Implement faster copy_to_user and clear_user methods for CPU
818diff --git a/arch/arm/common/gic.c b/arch/arm/common/gic.c
819index 87dfa902..3a523fc 100644
820--- a/arch/arm/common/gic.c
821+++ b/arch/arm/common/gic.c
822@@ -81,7 +81,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
823 * Supported arch specific GIC irq extension.
824 * Default make them NULL.
825 */
826-struct irq_chip gic_arch_extn = {
827+irq_chip_no_const gic_arch_extn __read_only = {
828 .irq_eoi = NULL,
829 .irq_mask = NULL,
830 .irq_unmask = NULL,
831@@ -329,7 +329,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
832 chained_irq_exit(chip, desc);
833 }
834
835-static struct irq_chip gic_chip = {
836+static irq_chip_no_const gic_chip __read_only = {
837 .name = "GIC",
838 .irq_mask = gic_mask_irq,
839 .irq_unmask = gic_unmask_irq,
840diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
841index c79f61f..9ac0642 100644
842--- a/arch/arm/include/asm/atomic.h
843+++ b/arch/arm/include/asm/atomic.h
844@@ -17,17 +17,35 @@
845 #include <asm/barrier.h>
846 #include <asm/cmpxchg.h>
847
848+#ifdef CONFIG_GENERIC_ATOMIC64
849+#include <asm-generic/atomic64.h>
850+#endif
851+
852 #define ATOMIC_INIT(i) { (i) }
853
854 #ifdef __KERNEL__
855
856+#define _ASM_EXTABLE(from, to) \
857+" .pushsection __ex_table,\"a\"\n"\
858+" .align 3\n" \
859+" .long " #from ", " #to"\n" \
860+" .popsection"
861+
862 /*
863 * On ARM, ordinary assignment (str instruction) doesn't clear the local
864 * strex/ldrex monitor on some implementations. The reason we can use it for
865 * atomic_set() is the clrex or dummy strex done on every exception return.
866 */
867 #define atomic_read(v) (*(volatile int *)&(v)->counter)
868+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
869+{
870+ return v->counter;
871+}
872 #define atomic_set(v,i) (((v)->counter) = (i))
873+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
874+{
875+ v->counter = i;
876+}
877
878 #if __LINUX_ARM_ARCH__ >= 6
879
880@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
881 int result;
882
883 __asm__ __volatile__("@ atomic_add\n"
884+"1: ldrex %1, [%3]\n"
885+" adds %0, %1, %4\n"
886+
887+#ifdef CONFIG_PAX_REFCOUNT
888+" bvc 3f\n"
889+"2: bkpt 0xf103\n"
890+"3:\n"
891+#endif
892+
893+" strex %1, %0, [%3]\n"
894+" teq %1, #0\n"
895+" bne 1b"
896+
897+#ifdef CONFIG_PAX_REFCOUNT
898+"\n4:\n"
899+ _ASM_EXTABLE(2b, 4b)
900+#endif
901+
902+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
903+ : "r" (&v->counter), "Ir" (i)
904+ : "cc");
905+}
906+
907+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
908+{
909+ unsigned long tmp;
910+ int result;
911+
912+ __asm__ __volatile__("@ atomic_add_unchecked\n"
913 "1: ldrex %0, [%3]\n"
914 " add %0, %0, %4\n"
915 " strex %1, %0, [%3]\n"
916@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
917 smp_mb();
918
919 __asm__ __volatile__("@ atomic_add_return\n"
920+"1: ldrex %1, [%3]\n"
921+" adds %0, %1, %4\n"
922+
923+#ifdef CONFIG_PAX_REFCOUNT
924+" bvc 3f\n"
925+" mov %0, %1\n"
926+"2: bkpt 0xf103\n"
927+"3:\n"
928+#endif
929+
930+" strex %1, %0, [%3]\n"
931+" teq %1, #0\n"
932+" bne 1b"
933+
934+#ifdef CONFIG_PAX_REFCOUNT
935+"\n4:\n"
936+ _ASM_EXTABLE(2b, 4b)
937+#endif
938+
939+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
940+ : "r" (&v->counter), "Ir" (i)
941+ : "cc");
942+
943+ smp_mb();
944+
945+ return result;
946+}
947+
948+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
949+{
950+ unsigned long tmp;
951+ int result;
952+
953+ smp_mb();
954+
955+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
956 "1: ldrex %0, [%3]\n"
957 " add %0, %0, %4\n"
958 " strex %1, %0, [%3]\n"
959@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
960 int result;
961
962 __asm__ __volatile__("@ atomic_sub\n"
963+"1: ldrex %1, [%3]\n"
964+" subs %0, %1, %4\n"
965+
966+#ifdef CONFIG_PAX_REFCOUNT
967+" bvc 3f\n"
968+"2: bkpt 0xf103\n"
969+"3:\n"
970+#endif
971+
972+" strex %1, %0, [%3]\n"
973+" teq %1, #0\n"
974+" bne 1b"
975+
976+#ifdef CONFIG_PAX_REFCOUNT
977+"\n4:\n"
978+ _ASM_EXTABLE(2b, 4b)
979+#endif
980+
981+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
982+ : "r" (&v->counter), "Ir" (i)
983+ : "cc");
984+}
985+
986+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
987+{
988+ unsigned long tmp;
989+ int result;
990+
991+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
992 "1: ldrex %0, [%3]\n"
993 " sub %0, %0, %4\n"
994 " strex %1, %0, [%3]\n"
995@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
996 smp_mb();
997
998 __asm__ __volatile__("@ atomic_sub_return\n"
999-"1: ldrex %0, [%3]\n"
1000-" sub %0, %0, %4\n"
1001+"1: ldrex %1, [%3]\n"
1002+" subs %0, %1, %4\n"
1003+
1004+#ifdef CONFIG_PAX_REFCOUNT
1005+" bvc 3f\n"
1006+" mov %0, %1\n"
1007+"2: bkpt 0xf103\n"
1008+"3:\n"
1009+#endif
1010+
1011 " strex %1, %0, [%3]\n"
1012 " teq %1, #0\n"
1013 " bne 1b"
1014+
1015+#ifdef CONFIG_PAX_REFCOUNT
1016+"\n4:\n"
1017+ _ASM_EXTABLE(2b, 4b)
1018+#endif
1019+
1020 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1021 : "r" (&v->counter), "Ir" (i)
1022 : "cc");
1023@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1024 return oldval;
1025 }
1026
1027+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1028+{
1029+ unsigned long oldval, res;
1030+
1031+ smp_mb();
1032+
1033+ do {
1034+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1035+ "ldrex %1, [%3]\n"
1036+ "mov %0, #0\n"
1037+ "teq %1, %4\n"
1038+ "strexeq %0, %5, [%3]\n"
1039+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1040+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1041+ : "cc");
1042+ } while (res);
1043+
1044+ smp_mb();
1045+
1046+ return oldval;
1047+}
1048+
1049 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1050 {
1051 unsigned long tmp, tmp2;
1052@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1053
1054 return val;
1055 }
1056+
1057+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1058+{
1059+ return atomic_add_return(i, v);
1060+}
1061+
1062 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1063+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1064+{
1065+ (void) atomic_add_return(i, v);
1066+}
1067
1068 static inline int atomic_sub_return(int i, atomic_t *v)
1069 {
1070@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1071 return val;
1072 }
1073 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1074+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1075+{
1076+ (void) atomic_sub_return(i, v);
1077+}
1078
1079 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1080 {
1081@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1082 return ret;
1083 }
1084
1085+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1086+{
1087+ return atomic_cmpxchg(v, old, new);
1088+}
1089+
1090 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1091 {
1092 unsigned long flags;
1093@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1094 #endif /* __LINUX_ARM_ARCH__ */
1095
1096 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1097+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1098+{
1099+ return xchg(&v->counter, new);
1100+}
1101
1102 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1103 {
1104@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1105 }
1106
1107 #define atomic_inc(v) atomic_add(1, v)
1108+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1109+{
1110+ atomic_add_unchecked(1, v);
1111+}
1112 #define atomic_dec(v) atomic_sub(1, v)
1113+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1114+{
1115+ atomic_sub_unchecked(1, v);
1116+}
1117
1118 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1119+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1120+{
1121+ return atomic_add_return_unchecked(1, v) == 0;
1122+}
1123 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1124 #define atomic_inc_return(v) (atomic_add_return(1, v))
1125+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1126+{
1127+ return atomic_add_return_unchecked(1, v);
1128+}
1129 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1130 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1131
1132@@ -241,6 +428,14 @@ typedef struct {
1133 u64 __aligned(8) counter;
1134 } atomic64_t;
1135
1136+#ifdef CONFIG_PAX_REFCOUNT
1137+typedef struct {
1138+ u64 __aligned(8) counter;
1139+} atomic64_unchecked_t;
1140+#else
1141+typedef atomic64_t atomic64_unchecked_t;
1142+#endif
1143+
1144 #define ATOMIC64_INIT(i) { (i) }
1145
1146 static inline u64 atomic64_read(const atomic64_t *v)
1147@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1148 return result;
1149 }
1150
1151+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1152+{
1153+ u64 result;
1154+
1155+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1156+" ldrexd %0, %H0, [%1]"
1157+ : "=&r" (result)
1158+ : "r" (&v->counter), "Qo" (v->counter)
1159+ );
1160+
1161+ return result;
1162+}
1163+
1164 static inline void atomic64_set(atomic64_t *v, u64 i)
1165 {
1166 u64 tmp;
1167@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1168 : "cc");
1169 }
1170
1171+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1172+{
1173+ u64 tmp;
1174+
1175+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1176+"1: ldrexd %0, %H0, [%2]\n"
1177+" strexd %0, %3, %H3, [%2]\n"
1178+" teq %0, #0\n"
1179+" bne 1b"
1180+ : "=&r" (tmp), "=Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ : "cc");
1183+}
1184+
1185 static inline void atomic64_add(u64 i, atomic64_t *v)
1186 {
1187 u64 result;
1188@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1189 __asm__ __volatile__("@ atomic64_add\n"
1190 "1: ldrexd %0, %H0, [%3]\n"
1191 " adds %0, %0, %4\n"
1192+" adcs %H0, %H0, %H4\n"
1193+
1194+#ifdef CONFIG_PAX_REFCOUNT
1195+" bvc 3f\n"
1196+"2: bkpt 0xf103\n"
1197+"3:\n"
1198+#endif
1199+
1200+" strexd %1, %0, %H0, [%3]\n"
1201+" teq %1, #0\n"
1202+" bne 1b"
1203+
1204+#ifdef CONFIG_PAX_REFCOUNT
1205+"\n4:\n"
1206+ _ASM_EXTABLE(2b, 4b)
1207+#endif
1208+
1209+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1210+ : "r" (&v->counter), "r" (i)
1211+ : "cc");
1212+}
1213+
1214+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1215+{
1216+ u64 result;
1217+ unsigned long tmp;
1218+
1219+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1220+"1: ldrexd %0, %H0, [%3]\n"
1221+" adds %0, %0, %4\n"
1222 " adc %H0, %H0, %H4\n"
1223 " strexd %1, %0, %H0, [%3]\n"
1224 " teq %1, #0\n"
1225@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1226
1227 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1228 {
1229- u64 result;
1230- unsigned long tmp;
1231+ u64 result, tmp;
1232
1233 smp_mb();
1234
1235 __asm__ __volatile__("@ atomic64_add_return\n"
1236+"1: ldrexd %1, %H1, [%3]\n"
1237+" adds %0, %1, %4\n"
1238+" adcs %H0, %H1, %H4\n"
1239+
1240+#ifdef CONFIG_PAX_REFCOUNT
1241+" bvc 3f\n"
1242+" mov %0, %1\n"
1243+" mov %H0, %H1\n"
1244+"2: bkpt 0xf103\n"
1245+"3:\n"
1246+#endif
1247+
1248+" strexd %1, %0, %H0, [%3]\n"
1249+" teq %1, #0\n"
1250+" bne 1b"
1251+
1252+#ifdef CONFIG_PAX_REFCOUNT
1253+"\n4:\n"
1254+ _ASM_EXTABLE(2b, 4b)
1255+#endif
1256+
1257+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1258+ : "r" (&v->counter), "r" (i)
1259+ : "cc");
1260+
1261+ smp_mb();
1262+
1263+ return result;
1264+}
1265+
1266+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1267+{
1268+ u64 result;
1269+ unsigned long tmp;
1270+
1271+ smp_mb();
1272+
1273+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1274 "1: ldrexd %0, %H0, [%3]\n"
1275 " adds %0, %0, %4\n"
1276 " adc %H0, %H0, %H4\n"
1277@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1278 __asm__ __volatile__("@ atomic64_sub\n"
1279 "1: ldrexd %0, %H0, [%3]\n"
1280 " subs %0, %0, %4\n"
1281+" sbcs %H0, %H0, %H4\n"
1282+
1283+#ifdef CONFIG_PAX_REFCOUNT
1284+" bvc 3f\n"
1285+"2: bkpt 0xf103\n"
1286+"3:\n"
1287+#endif
1288+
1289+" strexd %1, %0, %H0, [%3]\n"
1290+" teq %1, #0\n"
1291+" bne 1b"
1292+
1293+#ifdef CONFIG_PAX_REFCOUNT
1294+"\n4:\n"
1295+ _ASM_EXTABLE(2b, 4b)
1296+#endif
1297+
1298+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299+ : "r" (&v->counter), "r" (i)
1300+ : "cc");
1301+}
1302+
1303+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1304+{
1305+ u64 result;
1306+ unsigned long tmp;
1307+
1308+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1309+"1: ldrexd %0, %H0, [%3]\n"
1310+" subs %0, %0, %4\n"
1311 " sbc %H0, %H0, %H4\n"
1312 " strexd %1, %0, %H0, [%3]\n"
1313 " teq %1, #0\n"
1314@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1315
1316 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1317 {
1318- u64 result;
1319- unsigned long tmp;
1320+ u64 result, tmp;
1321
1322 smp_mb();
1323
1324 __asm__ __volatile__("@ atomic64_sub_return\n"
1325-"1: ldrexd %0, %H0, [%3]\n"
1326-" subs %0, %0, %4\n"
1327-" sbc %H0, %H0, %H4\n"
1328+"1: ldrexd %1, %H1, [%3]\n"
1329+" subs %0, %1, %4\n"
1330+" sbcs %H0, %H1, %H4\n"
1331+
1332+#ifdef CONFIG_PAX_REFCOUNT
1333+" bvc 3f\n"
1334+" mov %0, %1\n"
1335+" mov %H0, %H1\n"
1336+"2: bkpt 0xf103\n"
1337+"3:\n"
1338+#endif
1339+
1340 " strexd %1, %0, %H0, [%3]\n"
1341 " teq %1, #0\n"
1342 " bne 1b"
1343+
1344+#ifdef CONFIG_PAX_REFCOUNT
1345+"\n4:\n"
1346+ _ASM_EXTABLE(2b, 4b)
1347+#endif
1348+
1349 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1350 : "r" (&v->counter), "r" (i)
1351 : "cc");
1352@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1353 return oldval;
1354 }
1355
1356+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1357+{
1358+ u64 oldval;
1359+ unsigned long res;
1360+
1361+ smp_mb();
1362+
1363+ do {
1364+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1365+ "ldrexd %1, %H1, [%3]\n"
1366+ "mov %0, #0\n"
1367+ "teq %1, %4\n"
1368+ "teqeq %H1, %H4\n"
1369+ "strexdeq %0, %5, %H5, [%3]"
1370+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1371+ : "r" (&ptr->counter), "r" (old), "r" (new)
1372+ : "cc");
1373+ } while (res);
1374+
1375+ smp_mb();
1376+
1377+ return oldval;
1378+}
1379+
1380 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1381 {
1382 u64 result;
1383@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1384
1385 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1386 {
1387- u64 result;
1388- unsigned long tmp;
1389+ u64 result, tmp;
1390
1391 smp_mb();
1392
1393 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1394-"1: ldrexd %0, %H0, [%3]\n"
1395-" subs %0, %0, #1\n"
1396-" sbc %H0, %H0, #0\n"
1397+"1: ldrexd %1, %H1, [%3]\n"
1398+" subs %0, %1, #1\n"
1399+" sbcs %H0, %H1, #0\n"
1400+
1401+#ifdef CONFIG_PAX_REFCOUNT
1402+" bvc 3f\n"
1403+" mov %0, %1\n"
1404+" mov %H0, %H1\n"
1405+"2: bkpt 0xf103\n"
1406+"3:\n"
1407+#endif
1408+
1409 " teq %H0, #0\n"
1410-" bmi 2f\n"
1411+" bmi 4f\n"
1412 " strexd %1, %0, %H0, [%3]\n"
1413 " teq %1, #0\n"
1414 " bne 1b\n"
1415-"2:"
1416+"4:\n"
1417+
1418+#ifdef CONFIG_PAX_REFCOUNT
1419+ _ASM_EXTABLE(2b, 4b)
1420+#endif
1421+
1422 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1423 : "r" (&v->counter)
1424 : "cc");
1425@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1426 " teq %0, %5\n"
1427 " teqeq %H0, %H5\n"
1428 " moveq %1, #0\n"
1429-" beq 2f\n"
1430+" beq 4f\n"
1431 " adds %0, %0, %6\n"
1432-" adc %H0, %H0, %H6\n"
1433+" adcs %H0, %H0, %H6\n"
1434+
1435+#ifdef CONFIG_PAX_REFCOUNT
1436+" bvc 3f\n"
1437+"2: bkpt 0xf103\n"
1438+"3:\n"
1439+#endif
1440+
1441 " strexd %2, %0, %H0, [%4]\n"
1442 " teq %2, #0\n"
1443 " bne 1b\n"
1444-"2:"
1445+"4:\n"
1446+
1447+#ifdef CONFIG_PAX_REFCOUNT
1448+ _ASM_EXTABLE(2b, 4b)
1449+#endif
1450+
1451 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1452 : "r" (&v->counter), "r" (u), "r" (a)
1453 : "cc");
1454@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1455
1456 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1457 #define atomic64_inc(v) atomic64_add(1LL, (v))
1458+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1459 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1460+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1461 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1462 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1463 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1464+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1465 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1466 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1467 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1468diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1469index 75fe66b..ba3dee4 100644
1470--- a/arch/arm/include/asm/cache.h
1471+++ b/arch/arm/include/asm/cache.h
1472@@ -4,8 +4,10 @@
1473 #ifndef __ASMARM_CACHE_H
1474 #define __ASMARM_CACHE_H
1475
1476+#include <linux/const.h>
1477+
1478 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1479-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1480+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1481
1482 /*
1483 * Memory returned by kmalloc() may be used for DMA, so we must make
1484@@ -24,5 +26,6 @@
1485 #endif
1486
1487 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1488+#define __read_only __attribute__ ((__section__(".data..read_only")))
1489
1490 #endif
1491diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1492index e1489c5..d418304 100644
1493--- a/arch/arm/include/asm/cacheflush.h
1494+++ b/arch/arm/include/asm/cacheflush.h
1495@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1496 void (*dma_unmap_area)(const void *, size_t, int);
1497
1498 void (*dma_flush_range)(const void *, const void *);
1499-};
1500+} __no_const;
1501
1502 /*
1503 * Select the calling method
1504diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1505index 6dcc164..b14d917 100644
1506--- a/arch/arm/include/asm/checksum.h
1507+++ b/arch/arm/include/asm/checksum.h
1508@@ -37,7 +37,19 @@ __wsum
1509 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1510
1511 __wsum
1512-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1513+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1514+
1515+static inline __wsum
1516+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1517+{
1518+ __wsum ret;
1519+ pax_open_userland();
1520+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1521+ pax_close_userland();
1522+ return ret;
1523+}
1524+
1525+
1526
1527 /*
1528 * Fold a partial checksum without adding pseudo headers
1529diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1530index 7eb18c1..e38b6d2 100644
1531--- a/arch/arm/include/asm/cmpxchg.h
1532+++ b/arch/arm/include/asm/cmpxchg.h
1533@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1534
1535 #define xchg(ptr,x) \
1536 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1537+#define xchg_unchecked(ptr,x) \
1538+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1539
1540 #include <asm-generic/cmpxchg-local.h>
1541
1542diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1543index 720799f..2f67631 100644
1544--- a/arch/arm/include/asm/delay.h
1545+++ b/arch/arm/include/asm/delay.h
1546@@ -25,9 +25,9 @@ extern struct arm_delay_ops {
1547 void (*const_udelay)(unsigned long);
1548 void (*udelay)(unsigned long);
1549 bool const_clock;
1550-} arm_delay_ops;
1551+} *arm_delay_ops;
1552
1553-#define __delay(n) arm_delay_ops.delay(n)
1554+#define __delay(n) arm_delay_ops->delay(n)
1555
1556 /*
1557 * This function intentionally does not exist; if you see references to
1558@@ -48,8 +48,8 @@ extern void __bad_udelay(void);
1559 * first constant multiplications gets optimized away if the delay is
1560 * a constant)
1561 */
1562-#define __udelay(n) arm_delay_ops.udelay(n)
1563-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1564+#define __udelay(n) arm_delay_ops->udelay(n)
1565+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1566
1567 #define udelay(n) \
1568 (__builtin_constant_p(n) ? \
1569diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1570index 6ddbe44..b5e38b1 100644
1571--- a/arch/arm/include/asm/domain.h
1572+++ b/arch/arm/include/asm/domain.h
1573@@ -48,18 +48,37 @@
1574 * Domain types
1575 */
1576 #define DOMAIN_NOACCESS 0
1577-#define DOMAIN_CLIENT 1
1578 #ifdef CONFIG_CPU_USE_DOMAINS
1579+#define DOMAIN_USERCLIENT 1
1580+#define DOMAIN_KERNELCLIENT 1
1581 #define DOMAIN_MANAGER 3
1582+#define DOMAIN_VECTORS DOMAIN_USER
1583 #else
1584+
1585+#ifdef CONFIG_PAX_KERNEXEC
1586 #define DOMAIN_MANAGER 1
1587+#define DOMAIN_KERNEXEC 3
1588+#else
1589+#define DOMAIN_MANAGER 1
1590+#endif
1591+
1592+#ifdef CONFIG_PAX_MEMORY_UDEREF
1593+#define DOMAIN_USERCLIENT 0
1594+#define DOMAIN_UDEREF 1
1595+#define DOMAIN_VECTORS DOMAIN_KERNEL
1596+#else
1597+#define DOMAIN_USERCLIENT 1
1598+#define DOMAIN_VECTORS DOMAIN_USER
1599+#endif
1600+#define DOMAIN_KERNELCLIENT 1
1601+
1602 #endif
1603
1604 #define domain_val(dom,type) ((type) << (2*(dom)))
1605
1606 #ifndef __ASSEMBLY__
1607
1608-#ifdef CONFIG_CPU_USE_DOMAINS
1609+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1610 static inline void set_domain(unsigned val)
1611 {
1612 asm volatile(
1613@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1614 isb();
1615 }
1616
1617-#define modify_domain(dom,type) \
1618- do { \
1619- struct thread_info *thread = current_thread_info(); \
1620- unsigned int domain = thread->cpu_domain; \
1621- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1622- thread->cpu_domain = domain | domain_val(dom, type); \
1623- set_domain(thread->cpu_domain); \
1624- } while (0)
1625-
1626+extern void modify_domain(unsigned int dom, unsigned int type);
1627 #else
1628 static inline void set_domain(unsigned val) { }
1629 static inline void modify_domain(unsigned dom, unsigned type) { }
1630diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1631index 38050b1..9d90e8b 100644
1632--- a/arch/arm/include/asm/elf.h
1633+++ b/arch/arm/include/asm/elf.h
1634@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1635 the loader. We need to make sure that it is out of the way of the program
1636 that it will "exec", and that there is sufficient room for the brk. */
1637
1638-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1639+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1640+
1641+#ifdef CONFIG_PAX_ASLR
1642+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1643+
1644+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1645+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1646+#endif
1647
1648 /* When the program starts, a1 contains a pointer to a function to be
1649 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1650@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1651 extern void elf_set_personality(const struct elf32_hdr *);
1652 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1653
1654-struct mm_struct;
1655-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1656-#define arch_randomize_brk arch_randomize_brk
1657-
1658 #endif
1659diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1660index de53547..52b9a28 100644
1661--- a/arch/arm/include/asm/fncpy.h
1662+++ b/arch/arm/include/asm/fncpy.h
1663@@ -81,7 +81,9 @@
1664 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1665 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1666 \
1667+ pax_open_kernel(); \
1668 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1669+ pax_close_kernel(); \
1670 flush_icache_range((unsigned long)(dest_buf), \
1671 (unsigned long)(dest_buf) + (size)); \
1672 \
1673diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1674index e42cf59..7b94b8f 100644
1675--- a/arch/arm/include/asm/futex.h
1676+++ b/arch/arm/include/asm/futex.h
1677@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1679 return -EFAULT;
1680
1681+ pax_open_userland();
1682+
1683 smp_mb();
1684 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1685 "1: ldrex %1, [%4]\n"
1686@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1687 : "cc", "memory");
1688 smp_mb();
1689
1690+ pax_close_userland();
1691+
1692 *uval = val;
1693 return ret;
1694 }
1695@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1696 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1697 return -EFAULT;
1698
1699+ pax_open_userland();
1700+
1701 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1702 "1: " TUSER(ldr) " %1, [%4]\n"
1703 " teq %1, %2\n"
1704@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1705 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1706 : "cc", "memory");
1707
1708+ pax_close_userland();
1709+
1710 *uval = val;
1711 return ret;
1712 }
1713@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1714 return -EFAULT;
1715
1716 pagefault_disable(); /* implies preempt_disable() */
1717+ pax_open_userland();
1718
1719 switch (op) {
1720 case FUTEX_OP_SET:
1721@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1722 ret = -ENOSYS;
1723 }
1724
1725+ pax_close_userland();
1726 pagefault_enable(); /* subsumes preempt_enable() */
1727
1728 if (!ret) {
1729diff --git a/arch/arm/include/asm/hardware/gic.h b/arch/arm/include/asm/hardware/gic.h
1730index 4b1ce6c..bea3f73 100644
1731--- a/arch/arm/include/asm/hardware/gic.h
1732+++ b/arch/arm/include/asm/hardware/gic.h
1733@@ -34,9 +34,10 @@
1734
1735 #ifndef __ASSEMBLY__
1736 #include <linux/irqdomain.h>
1737+#include <linux/irq.h>
1738 struct device_node;
1739
1740-extern struct irq_chip gic_arch_extn;
1741+extern irq_chip_no_const gic_arch_extn;
1742
1743 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
1744 u32 offset, struct device_node *);
1745diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746index 83eb2f7..ed77159 100644
1747--- a/arch/arm/include/asm/kmap_types.h
1748+++ b/arch/arm/include/asm/kmap_types.h
1749@@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753-#define KM_TYPE_NR 16
1754+#define KM_TYPE_NR 17
1755
1756 #endif
1757diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758index 9e614a1..3302cca 100644
1759--- a/arch/arm/include/asm/mach/dma.h
1760+++ b/arch/arm/include/asm/mach/dma.h
1761@@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765-};
1766+} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771index 2fe141f..192dc01 100644
1772--- a/arch/arm/include/asm/mach/map.h
1773+++ b/arch/arm/include/asm/mach/map.h
1774@@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778-#define MT_MEMORY 9
1779+#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781-#define MT_MEMORY_NONCACHED 11
1782+#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787+#define MT_MEMORY_RW 16
1788+#define MT_MEMORY_RX 17
1789+#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794index 53426c6..c7baff3 100644
1795--- a/arch/arm/include/asm/outercache.h
1796+++ b/arch/arm/include/asm/outercache.h
1797@@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801-};
1802+} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807index 812a494..71fc0b6 100644
1808--- a/arch/arm/include/asm/page.h
1809+++ b/arch/arm/include/asm/page.h
1810@@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814-};
1815+} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820index 943504f..c37a730 100644
1821--- a/arch/arm/include/asm/pgalloc.h
1822+++ b/arch/arm/include/asm/pgalloc.h
1823@@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827+#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836+{
1837+ pud_populate(mm, pud, pmd);
1838+}
1839+
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847+#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856+{
1857+#ifdef CONFIG_ARM_LPAE
1858+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859+#else
1860+ if (addr & SECTION_SIZE)
1861+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862+ else
1863+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864+#endif
1865+ flush_pmd_entry(pmdp);
1866+}
1867+
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881index 5cfba15..f415e1a 100644
1882--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884@@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892+
1893 /*
1894 * - section
1895 */
1896+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900@@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908@@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917index f97ee02..07f1be5 100644
1918--- a/arch/arm/include/asm/pgtable-2level.h
1919+++ b/arch/arm/include/asm/pgtable-2level.h
1920@@ -125,6 +125,7 @@
1921 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1922 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1923 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1924+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1925
1926 /*
1927 * These are the memory types, defined to be compatible with
1928diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1929index d795282..a43ea90 100644
1930--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1931+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1932@@ -32,15 +32,18 @@
1933 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1934 #define PMD_BIT4 (_AT(pmdval_t, 0))
1935 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1936+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1937
1938 /*
1939 * - section
1940 */
1941 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1942 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1943+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1944 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1945 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1946 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1947+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1949 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1950 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1951@@ -66,6 +69,7 @@
1952 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1953 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1954 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1955+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1956 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1957
1958 /*
1959diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1960index a3f3792..7b932a6 100644
1961--- a/arch/arm/include/asm/pgtable-3level.h
1962+++ b/arch/arm/include/asm/pgtable-3level.h
1963@@ -74,6 +74,7 @@
1964 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1965 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1966 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1967+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1968 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1969 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1970 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1971@@ -82,6 +83,7 @@
1972 /*
1973 * To be used in assembly code with the upper page attributes.
1974 */
1975+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1976 #define L_PTE_XN_HIGH (1 << (54 - 32))
1977 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1978
1979diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1980index c094749..fd8272e 100644
1981--- a/arch/arm/include/asm/pgtable.h
1982+++ b/arch/arm/include/asm/pgtable.h
1983@@ -30,6 +30,9 @@
1984 #include <asm/pgtable-2level.h>
1985 #endif
1986
1987+#define ktla_ktva(addr) (addr)
1988+#define ktva_ktla(addr) (addr)
1989+
1990 /*
1991 * Just any arbitrary offset to the start of the vmalloc VM area: the
1992 * current 8MB value just means that there will be a 8MB "hole" after the
1993@@ -45,6 +48,9 @@
1994 #define LIBRARY_TEXT_START 0x0c000000
1995
1996 #ifndef __ASSEMBLY__
1997+extern pteval_t __supported_pte_mask;
1998+extern pmdval_t __supported_pmd_mask;
1999+
2000 extern void __pte_error(const char *file, int line, pte_t);
2001 extern void __pmd_error(const char *file, int line, pmd_t);
2002 extern void __pgd_error(const char *file, int line, pgd_t);
2003@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2004 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2005 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2006
2007+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2008+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2009+
2010+#ifdef CONFIG_PAX_KERNEXEC
2011+#include <asm/domain.h>
2012+#include <linux/thread_info.h>
2013+#include <linux/preempt.h>
2014+#endif
2015+
2016+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2017+static inline int test_domain(int domain, int domaintype)
2018+{
2019+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2020+}
2021+#endif
2022+
2023+#ifdef CONFIG_PAX_KERNEXEC
2024+static inline unsigned long pax_open_kernel(void) {
2025+#ifdef CONFIG_ARM_LPAE
2026+ /* TODO */
2027+#else
2028+ preempt_disable();
2029+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2030+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2031+#endif
2032+ return 0;
2033+}
2034+
2035+static inline unsigned long pax_close_kernel(void) {
2036+#ifdef CONFIG_ARM_LPAE
2037+ /* TODO */
2038+#else
2039+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2040+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2041+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2042+ preempt_enable_no_resched();
2043+#endif
2044+ return 0;
2045+}
2046+#else
2047+static inline unsigned long pax_open_kernel(void) { return 0; }
2048+static inline unsigned long pax_close_kernel(void) { return 0; }
2049+#endif
2050+
2051 /*
2052 * This is the lowest virtual address we can permit any user space
2053 * mapping to be mapped at. This is particularly important for
2054@@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2055 /*
2056 * The pgprot_* and protection_map entries will be fixed up in runtime
2057 * to include the cachable and bufferable bits based on memory policy,
2058- * as well as any architecture dependent bits like global/ASID and SMP
2059- * shared mapping bits.
2060+ * as well as any architecture dependent bits like global/ASID, PXN,
2061+ * and SMP shared mapping bits.
2062 */
2063 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2064
2065@@ -240,8 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2066
2067 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2068 {
2069- const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2070- L_PTE_NONE | L_PTE_VALID;
2071+ const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2072 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2073 return pte;
2074 }
2075diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2076index f3628fb..a0672dd 100644
2077--- a/arch/arm/include/asm/proc-fns.h
2078+++ b/arch/arm/include/asm/proc-fns.h
2079@@ -75,7 +75,7 @@ extern struct processor {
2080 unsigned int suspend_size;
2081 void (*do_suspend)(void *);
2082 void (*do_resume)(void *);
2083-} processor;
2084+} __do_const processor;
2085
2086 #ifndef MULTI_CPU
2087 extern void cpu_proc_init(void);
2088diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2089index 06e7d50..8a8e251 100644
2090--- a/arch/arm/include/asm/processor.h
2091+++ b/arch/arm/include/asm/processor.h
2092@@ -65,9 +65,8 @@ struct thread_struct {
2093 regs->ARM_cpsr |= PSR_ENDSTATE; \
2094 regs->ARM_pc = pc & ~1; /* pc */ \
2095 regs->ARM_sp = sp; /* sp */ \
2096- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2097- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2098- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2099+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2100+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2101 nommu_start_thread(regs); \
2102 })
2103
2104diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2105index d3a22be..3a69ad5 100644
2106--- a/arch/arm/include/asm/smp.h
2107+++ b/arch/arm/include/asm/smp.h
2108@@ -107,7 +107,7 @@ struct smp_operations {
2109 int (*cpu_disable)(unsigned int cpu);
2110 #endif
2111 #endif
2112-};
2113+} __no_const;
2114
2115 /*
2116 * set platform specific SMP operations
2117diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2118index cddda1f..ff357f7 100644
2119--- a/arch/arm/include/asm/thread_info.h
2120+++ b/arch/arm/include/asm/thread_info.h
2121@@ -77,9 +77,9 @@ struct thread_info {
2122 .flags = 0, \
2123 .preempt_count = INIT_PREEMPT_COUNT, \
2124 .addr_limit = KERNEL_DS, \
2125- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2126- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2127- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2128+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2129+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2130+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2131 .restart_block = { \
2132 .fn = do_no_restart_syscall, \
2133 }, \
2134@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2135 #define TIF_SYSCALL_AUDIT 9
2136 #define TIF_SYSCALL_TRACEPOINT 10
2137 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2138+
2139+/* within 8 bits of TIF_SYSCALL_TRACE
2140+ * to meet flexible second operand requirements
2141+ */
2142+#define TIF_GRSEC_SETXID 12
2143+
2144 #define TIF_USING_IWMMXT 17
2145 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2146 #define TIF_RESTORE_SIGMASK 20
2147@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2148 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2149 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2150 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2151+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2152
2153 /* Checks for any syscall work in entry-common.S */
2154 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2155- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2156+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2157
2158 /*
2159 * Change these and you break ASM code in entry-common.S
2160diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2161index 7e1f760..752fcb7 100644
2162--- a/arch/arm/include/asm/uaccess.h
2163+++ b/arch/arm/include/asm/uaccess.h
2164@@ -18,6 +18,7 @@
2165 #include <asm/domain.h>
2166 #include <asm/unified.h>
2167 #include <asm/compiler.h>
2168+#include <asm/pgtable.h>
2169
2170 #define VERIFY_READ 0
2171 #define VERIFY_WRITE 1
2172@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2173 #define USER_DS TASK_SIZE
2174 #define get_fs() (current_thread_info()->addr_limit)
2175
2176+static inline void pax_open_userland(void)
2177+{
2178+
2179+#ifdef CONFIG_PAX_MEMORY_UDEREF
2180+ if (get_fs() == USER_DS) {
2181+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2182+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2183+ }
2184+#endif
2185+
2186+}
2187+
2188+static inline void pax_close_userland(void)
2189+{
2190+
2191+#ifdef CONFIG_PAX_MEMORY_UDEREF
2192+ if (get_fs() == USER_DS) {
2193+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2194+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2195+ }
2196+#endif
2197+
2198+}
2199+
2200 static inline void set_fs(mm_segment_t fs)
2201 {
2202 current_thread_info()->addr_limit = fs;
2203- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2204+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2205 }
2206
2207 #define segment_eq(a,b) ((a) == (b))
2208@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2209
2210 #define get_user(x,p) \
2211 ({ \
2212+ int __e; \
2213 might_fault(); \
2214- __get_user_check(x,p); \
2215+ pax_open_userland(); \
2216+ __e = __get_user_check(x,p); \
2217+ pax_close_userland(); \
2218+ __e; \
2219 })
2220
2221 extern int __put_user_1(void *, unsigned int);
2222@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2223
2224 #define put_user(x,p) \
2225 ({ \
2226+ int __e; \
2227 might_fault(); \
2228- __put_user_check(x,p); \
2229+ pax_open_userland(); \
2230+ __e = __put_user_check(x,p); \
2231+ pax_close_userland(); \
2232+ __e; \
2233 })
2234
2235 #else /* CONFIG_MMU */
2236@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2237 #define __get_user(x,ptr) \
2238 ({ \
2239 long __gu_err = 0; \
2240+ pax_open_userland(); \
2241 __get_user_err((x),(ptr),__gu_err); \
2242+ pax_close_userland(); \
2243 __gu_err; \
2244 })
2245
2246 #define __get_user_error(x,ptr,err) \
2247 ({ \
2248+ pax_open_userland(); \
2249 __get_user_err((x),(ptr),err); \
2250+ pax_close_userland(); \
2251 (void) 0; \
2252 })
2253
2254@@ -312,13 +349,17 @@ do { \
2255 #define __put_user(x,ptr) \
2256 ({ \
2257 long __pu_err = 0; \
2258+ pax_open_userland(); \
2259 __put_user_err((x),(ptr),__pu_err); \
2260+ pax_close_userland(); \
2261 __pu_err; \
2262 })
2263
2264 #define __put_user_error(x,ptr,err) \
2265 ({ \
2266+ pax_open_userland(); \
2267 __put_user_err((x),(ptr),err); \
2268+ pax_close_userland(); \
2269 (void) 0; \
2270 })
2271
2272@@ -418,11 +459,44 @@ do { \
2273
2274
2275 #ifdef CONFIG_MMU
2276-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2277-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2278+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2279+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2280+
2281+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2282+{
2283+ unsigned long ret;
2284+
2285+ check_object_size(to, n, false);
2286+ pax_open_userland();
2287+ ret = ___copy_from_user(to, from, n);
2288+ pax_close_userland();
2289+ return ret;
2290+}
2291+
2292+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2293+{
2294+ unsigned long ret;
2295+
2296+ check_object_size(from, n, true);
2297+ pax_open_userland();
2298+ ret = ___copy_to_user(to, from, n);
2299+ pax_close_userland();
2300+ return ret;
2301+}
2302+
2303 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2304-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2305+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2306 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2307+
2308+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2309+{
2310+ unsigned long ret;
2311+ pax_open_userland();
2312+ ret = ___clear_user(addr, n);
2313+ pax_close_userland();
2314+ return ret;
2315+}
2316+
2317 #else
2318 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2319 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2320@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2321
2322 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2323 {
2324+ if ((long)n < 0)
2325+ return n;
2326+
2327 if (access_ok(VERIFY_READ, from, n))
2328 n = __copy_from_user(to, from, n);
2329 else /* security hole - plug it */
2330@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2331
2332 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2333 {
2334+ if ((long)n < 0)
2335+ return n;
2336+
2337 if (access_ok(VERIFY_WRITE, to, n))
2338 n = __copy_to_user(to, from, n);
2339 return n;
2340diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2341index 96ee092..37f1844 100644
2342--- a/arch/arm/include/uapi/asm/ptrace.h
2343+++ b/arch/arm/include/uapi/asm/ptrace.h
2344@@ -73,7 +73,7 @@
2345 * ARMv7 groups of PSR bits
2346 */
2347 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2348-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2349+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2350 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2351 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2352
2353diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2354index 60d3b73..d27ee09 100644
2355--- a/arch/arm/kernel/armksyms.c
2356+++ b/arch/arm/kernel/armksyms.c
2357@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2358 #ifdef CONFIG_MMU
2359 EXPORT_SYMBOL(copy_page);
2360
2361-EXPORT_SYMBOL(__copy_from_user);
2362-EXPORT_SYMBOL(__copy_to_user);
2363-EXPORT_SYMBOL(__clear_user);
2364+EXPORT_SYMBOL(___copy_from_user);
2365+EXPORT_SYMBOL(___copy_to_user);
2366+EXPORT_SYMBOL(___clear_user);
2367
2368 EXPORT_SYMBOL(__get_user_1);
2369 EXPORT_SYMBOL(__get_user_2);
2370diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2371index 0f82098..3dbd3ee 100644
2372--- a/arch/arm/kernel/entry-armv.S
2373+++ b/arch/arm/kernel/entry-armv.S
2374@@ -47,6 +47,87 @@
2375 9997:
2376 .endm
2377
2378+ .macro pax_enter_kernel
2379+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2380+ @ make aligned space for saved DACR
2381+ sub sp, sp, #8
2382+ @ save regs
2383+ stmdb sp!, {r1, r2}
2384+ @ read DACR from cpu_domain into r1
2385+ mov r2, sp
2386+ @ assume 8K pages, since we have to split the immediate in two
2387+ bic r2, r2, #(0x1fc0)
2388+ bic r2, r2, #(0x3f)
2389+ ldr r1, [r2, #TI_CPU_DOMAIN]
2390+ @ store old DACR on stack
2391+ str r1, [sp, #8]
2392+#ifdef CONFIG_PAX_KERNEXEC
2393+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2394+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2395+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2396+#endif
2397+#ifdef CONFIG_PAX_MEMORY_UDEREF
2398+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2399+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2400+#endif
2401+ @ write r1 to current_thread_info()->cpu_domain
2402+ str r1, [r2, #TI_CPU_DOMAIN]
2403+ @ write r1 to DACR
2404+ mcr p15, 0, r1, c3, c0, 0
2405+ @ instruction sync
2406+ instr_sync
2407+ @ restore regs
2408+ ldmia sp!, {r1, r2}
2409+#endif
2410+ .endm
2411+
2412+ .macro pax_open_userland
2413+#ifdef CONFIG_PAX_MEMORY_UDEREF
2414+ @ save regs
2415+ stmdb sp!, {r0, r1}
2416+ @ read DACR from cpu_domain into r1
2417+ mov r0, sp
2418+ @ assume 8K pages, since we have to split the immediate in two
2419+ bic r0, r0, #(0x1fc0)
2420+ bic r0, r0, #(0x3f)
2421+ ldr r1, [r0, #TI_CPU_DOMAIN]
2422+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2423+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2424+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2425+ @ write r1 to current_thread_info()->cpu_domain
2426+ str r1, [r0, #TI_CPU_DOMAIN]
2427+ @ write r1 to DACR
2428+ mcr p15, 0, r1, c3, c0, 0
2429+ @ instruction sync
2430+ instr_sync
2431+ @ restore regs
2432+ ldmia sp!, {r0, r1}
2433+#endif
2434+ .endm
2435+
2436+ .macro pax_close_userland
2437+#ifdef CONFIG_PAX_MEMORY_UDEREF
2438+ @ save regs
2439+ stmdb sp!, {r0, r1}
2440+ @ read DACR from cpu_domain into r1
2441+ mov r0, sp
2442+ @ assume 8K pages, since we have to split the immediate in two
2443+ bic r0, r0, #(0x1fc0)
2444+ bic r0, r0, #(0x3f)
2445+ ldr r1, [r0, #TI_CPU_DOMAIN]
2446+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2447+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2448+ @ write r1 to current_thread_info()->cpu_domain
2449+ str r1, [r0, #TI_CPU_DOMAIN]
2450+ @ write r1 to DACR
2451+ mcr p15, 0, r1, c3, c0, 0
2452+ @ instruction sync
2453+ instr_sync
2454+ @ restore regs
2455+ ldmia sp!, {r0, r1}
2456+#endif
2457+ .endm
2458+
2459 .macro pabt_helper
2460 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2461 #ifdef MULTI_PABORT
2462@@ -89,11 +170,15 @@
2463 * Invalid mode handlers
2464 */
2465 .macro inv_entry, reason
2466+
2467+ pax_enter_kernel
2468+
2469 sub sp, sp, #S_FRAME_SIZE
2470 ARM( stmib sp, {r1 - lr} )
2471 THUMB( stmia sp, {r0 - r12} )
2472 THUMB( str sp, [sp, #S_SP] )
2473 THUMB( str lr, [sp, #S_LR] )
2474+
2475 mov r1, #\reason
2476 .endm
2477
2478@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2479 .macro svc_entry, stack_hole=0
2480 UNWIND(.fnstart )
2481 UNWIND(.save {r0 - pc} )
2482+
2483+ pax_enter_kernel
2484+
2485 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2486+
2487 #ifdef CONFIG_THUMB2_KERNEL
2488 SPFIX( str r0, [sp] ) @ temporarily saved
2489 SPFIX( mov r0, sp )
2490@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2491 ldmia r0, {r3 - r5}
2492 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2493 mov r6, #-1 @ "" "" "" ""
2494+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2495+ @ offset sp by 8 as done in pax_enter_kernel
2496+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2497+#else
2498 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2499+#endif
2500 SPFIX( addeq r2, r2, #4 )
2501 str r3, [sp, #-4]! @ save the "real" r0 copied
2502 @ from the exception stack
2503@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2504 .macro usr_entry
2505 UNWIND(.fnstart )
2506 UNWIND(.cantunwind ) @ don't unwind the user space
2507+
2508+ pax_enter_kernel_user
2509+
2510 sub sp, sp, #S_FRAME_SIZE
2511 ARM( stmib sp, {r1 - r12} )
2512 THUMB( stmia sp, {r0 - r12} )
2513@@ -456,7 +553,9 @@ __und_usr:
2514 tst r3, #PSR_T_BIT @ Thumb mode?
2515 bne __und_usr_thumb
2516 sub r4, r2, #4 @ ARM instr at LR - 4
2517+ pax_open_userland
2518 1: ldrt r0, [r4]
2519+ pax_close_userland
2520 #ifdef CONFIG_CPU_ENDIAN_BE8
2521 rev r0, r0 @ little endian instruction
2522 #endif
2523@@ -491,10 +590,14 @@ __und_usr_thumb:
2524 */
2525 .arch armv6t2
2526 #endif
2527+ pax_open_userland
2528 2: ldrht r5, [r4]
2529+ pax_close_userland
2530 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2531 blo __und_usr_fault_16 @ 16bit undefined instruction
2532+ pax_open_userland
2533 3: ldrht r0, [r2]
2534+ pax_close_userland
2535 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2536 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2537 orr r0, r0, r5, lsl #16
2538@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2539 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2540 THUMB( str sp, [ip], #4 )
2541 THUMB( str lr, [ip], #4 )
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2544 ldr r6, [r2, #TI_CPU_DOMAIN]
2545 #endif
2546 set_tls r3, r4, r5
2547@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2548 ldr r8, =__stack_chk_guard
2549 ldr r7, [r7, #TSK_STACK_CANARY]
2550 #endif
2551-#ifdef CONFIG_CPU_USE_DOMAINS
2552+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2553 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2554 #endif
2555 mov r5, r0
2556diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2557index a6c301e..908821b 100644
2558--- a/arch/arm/kernel/entry-common.S
2559+++ b/arch/arm/kernel/entry-common.S
2560@@ -10,18 +10,46 @@
2561
2562 #include <asm/unistd.h>
2563 #include <asm/ftrace.h>
2564+#include <asm/domain.h>
2565 #include <asm/unwind.h>
2566
2567+#include "entry-header.S"
2568+
2569 #ifdef CONFIG_NEED_RET_TO_USER
2570 #include <mach/entry-macro.S>
2571 #else
2572 .macro arch_ret_to_user, tmp1, tmp2
2573+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574+ @ save regs
2575+ stmdb sp!, {r1, r2}
2576+ @ read DACR from cpu_domain into r1
2577+ mov r2, sp
2578+ @ assume 8K pages, since we have to split the immediate in two
2579+ bic r2, r2, #(0x1fc0)
2580+ bic r2, r2, #(0x3f)
2581+ ldr r1, [r2, #TI_CPU_DOMAIN]
2582+#ifdef CONFIG_PAX_KERNEXEC
2583+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2584+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2585+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2586+#endif
2587+#ifdef CONFIG_PAX_MEMORY_UDEREF
2588+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2589+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2590+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2591+#endif
2592+ @ write r1 to current_thread_info()->cpu_domain
2593+ str r1, [r2, #TI_CPU_DOMAIN]
2594+ @ write r1 to DACR
2595+ mcr p15, 0, r1, c3, c0, 0
2596+ @ instruction sync
2597+ instr_sync
2598+ @ restore regs
2599+ ldmia sp!, {r1, r2}
2600+#endif
2601 .endm
2602 #endif
2603
2604-#include "entry-header.S"
2605-
2606-
2607 .align 5
2608 /*
2609 * This is the fast syscall return path. We do as little as
2610@@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2611
2612 .align 5
2613 ENTRY(vector_swi)
2614+
2615 sub sp, sp, #S_FRAME_SIZE
2616 stmia sp, {r0 - r12} @ Calling r0 - r12
2617 ARM( add r8, sp, #S_PC )
2618@@ -388,6 +417,12 @@ ENTRY(vector_swi)
2619 ldr scno, [lr, #-4] @ get SWI instruction
2620 #endif
2621
2622+ /*
2623+ * do this here to avoid a performance hit of wrapping the code above
2624+ * that directly dereferences userland to parse the SWI instruction
2625+ */
2626+ pax_enter_kernel_user
2627+
2628 #ifdef CONFIG_ALIGNMENT_TRAP
2629 ldr ip, __cr_alignment
2630 ldr ip, [ip]
2631diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2632index 9a8531e..812e287 100644
2633--- a/arch/arm/kernel/entry-header.S
2634+++ b/arch/arm/kernel/entry-header.S
2635@@ -73,9 +73,66 @@
2636 msr cpsr_c, \rtemp @ switch back to the SVC mode
2637 .endm
2638
2639+ .macro pax_enter_kernel_user
2640+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2641+ @ save regs
2642+ stmdb sp!, {r0, r1}
2643+ @ read DACR from cpu_domain into r1
2644+ mov r0, sp
2645+ @ assume 8K pages, since we have to split the immediate in two
2646+ bic r0, r0, #(0x1fc0)
2647+ bic r0, r0, #(0x3f)
2648+ ldr r1, [r0, #TI_CPU_DOMAIN]
2649+#ifdef CONFIG_PAX_MEMORY_UDEREF
2650+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2651+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2652+#endif
2653+#ifdef CONFIG_PAX_KERNEXEC
2654+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2655+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2656+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2657+#endif
2658+ @ write r1 to current_thread_info()->cpu_domain
2659+ str r1, [r0, #TI_CPU_DOMAIN]
2660+ @ write r1 to DACR
2661+ mcr p15, 0, r1, c3, c0, 0
2662+ @ instruction sync
2663+ instr_sync
2664+ @ restore regs
2665+ ldmia sp!, {r0, r1}
2666+#endif
2667+ .endm
2668+
2669+ .macro pax_exit_kernel
2670+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2671+ @ save regs
2672+ stmdb sp!, {r0, r1}
2673+ @ read old DACR from stack into r1
2674+ ldr r1, [sp, #(8 + S_SP)]
2675+ sub r1, r1, #8
2676+ ldr r1, [r1]
2677+
2678+ @ write r1 to current_thread_info()->cpu_domain
2679+ mov r0, sp
2680+ @ assume 8K pages, since we have to split the immediate in two
2681+ bic r0, r0, #(0x1fc0)
2682+ bic r0, r0, #(0x3f)
2683+ str r1, [r0, #TI_CPU_DOMAIN]
2684+ @ write r1 to DACR
2685+ mcr p15, 0, r1, c3, c0, 0
2686+ @ instruction sync
2687+ instr_sync
2688+ @ restore regs
2689+ ldmia sp!, {r0, r1}
2690+#endif
2691+ .endm
2692+
2693 #ifndef CONFIG_THUMB2_KERNEL
2694 .macro svc_exit, rpsr
2695 msr spsr_cxsf, \rpsr
2696+
2697+ pax_exit_kernel
2698+
2699 #if defined(CONFIG_CPU_V6)
2700 ldr r0, [sp]
2701 strex r1, r2, [sp] @ clear the exclusive monitor
2702@@ -121,6 +178,9 @@
2703 .endm
2704 #else /* CONFIG_THUMB2_KERNEL */
2705 .macro svc_exit, rpsr
2706+
2707+ pax_exit_kernel
2708+
2709 ldr lr, [sp, #S_SP] @ top of the stack
2710 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2711 clrex @ clear the exclusive monitor
2712diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2713index 2adda11..7fbe958 100644
2714--- a/arch/arm/kernel/fiq.c
2715+++ b/arch/arm/kernel/fiq.c
2716@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2717 #if defined(CONFIG_CPU_USE_DOMAINS)
2718 memcpy((void *)0xffff001c, start, length);
2719 #else
2720+ pax_open_kernel();
2721 memcpy(vectors_page + 0x1c, start, length);
2722+ pax_close_kernel();
2723 #endif
2724 flush_icache_range(0xffff001c, 0xffff001c + length);
2725 if (!vectors_high())
2726diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2727index e0eb9a1..c7d74a3 100644
2728--- a/arch/arm/kernel/head.S
2729+++ b/arch/arm/kernel/head.S
2730@@ -52,7 +52,9 @@
2731 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2732
2733 .macro pgtbl, rd, phys
2734- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2735+ mov \rd, #TEXT_OFFSET
2736+ sub \rd, #PG_DIR_SIZE
2737+ add \rd, \rd, \phys
2738 .endm
2739
2740 /*
2741@@ -434,7 +436,7 @@ __enable_mmu:
2742 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2743 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2744 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2745- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2746+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2747 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2748 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2749 #endif
2750diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2751index 5ff2e77..556d030 100644
2752--- a/arch/arm/kernel/hw_breakpoint.c
2753+++ b/arch/arm/kernel/hw_breakpoint.c
2754@@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2755 return NOTIFY_OK;
2756 }
2757
2758-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2759+static struct notifier_block dbg_reset_nb = {
2760 .notifier_call = dbg_reset_notify,
2761 };
2762
2763diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2764index 1e9be5d..03edbc2 100644
2765--- a/arch/arm/kernel/module.c
2766+++ b/arch/arm/kernel/module.c
2767@@ -37,12 +37,37 @@
2768 #endif
2769
2770 #ifdef CONFIG_MMU
2771-void *module_alloc(unsigned long size)
2772+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2773 {
2774+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2775+ return NULL;
2776 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2777- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2778+ GFP_KERNEL, prot, -1,
2779 __builtin_return_address(0));
2780 }
2781+
2782+void *module_alloc(unsigned long size)
2783+{
2784+
2785+#ifdef CONFIG_PAX_KERNEXEC
2786+ return __module_alloc(size, PAGE_KERNEL);
2787+#else
2788+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2789+#endif
2790+
2791+}
2792+
2793+#ifdef CONFIG_PAX_KERNEXEC
2794+void module_free_exec(struct module *mod, void *module_region)
2795+{
2796+ module_free(mod, module_region);
2797+}
2798+
2799+void *module_alloc_exec(unsigned long size)
2800+{
2801+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2802+}
2803+#endif
2804 #endif
2805
2806 int
2807diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2808index 07314af..c46655c 100644
2809--- a/arch/arm/kernel/patch.c
2810+++ b/arch/arm/kernel/patch.c
2811@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2812 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2813 int size;
2814
2815+ pax_open_kernel();
2816 if (thumb2 && __opcode_is_thumb16(insn)) {
2817 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2818 size = sizeof(u16);
2819@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2820 *(u32 *)addr = insn;
2821 size = sizeof(u32);
2822 }
2823+ pax_close_kernel();
2824
2825 flush_icache_range((uintptr_t)(addr),
2826 (uintptr_t)(addr) + size);
2827diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2828index 5f66206..dce492f 100644
2829--- a/arch/arm/kernel/perf_event_cpu.c
2830+++ b/arch/arm/kernel/perf_event_cpu.c
2831@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2832 return NOTIFY_OK;
2833 }
2834
2835-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2836+static struct notifier_block cpu_pmu_hotplug_notifier = {
2837 .notifier_call = cpu_pmu_notify,
2838 };
2839
2840diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2841index c6dec5f..e0fddd1 100644
2842--- a/arch/arm/kernel/process.c
2843+++ b/arch/arm/kernel/process.c
2844@@ -28,7 +28,6 @@
2845 #include <linux/tick.h>
2846 #include <linux/utsname.h>
2847 #include <linux/uaccess.h>
2848-#include <linux/random.h>
2849 #include <linux/hw_breakpoint.h>
2850 #include <linux/cpuidle.h>
2851 #include <linux/leds.h>
2852@@ -256,9 +255,10 @@ void machine_power_off(void)
2853 machine_shutdown();
2854 if (pm_power_off)
2855 pm_power_off();
2856+ BUG();
2857 }
2858
2859-void machine_restart(char *cmd)
2860+__noreturn void machine_restart(char *cmd)
2861 {
2862 machine_shutdown();
2863
2864@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2865 init_utsname()->release,
2866 (int)strcspn(init_utsname()->version, " "),
2867 init_utsname()->version);
2868- print_symbol("PC is at %s\n", instruction_pointer(regs));
2869- print_symbol("LR is at %s\n", regs->ARM_lr);
2870+ printk("PC is at %pA\n", instruction_pointer(regs));
2871+ printk("LR is at %pA\n", regs->ARM_lr);
2872 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2873 "sp : %08lx ip : %08lx fp : %08lx\n",
2874 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2875@@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2876 return 0;
2877 }
2878
2879-unsigned long arch_randomize_brk(struct mm_struct *mm)
2880-{
2881- unsigned long range_end = mm->brk + 0x02000000;
2882- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2883-}
2884-
2885 #ifdef CONFIG_MMU
2886 /*
2887 * The vectors page is always readable from user space for the
2888@@ -470,9 +464,8 @@ static int __init gate_vma_init(void)
2889 {
2890 gate_vma.vm_start = 0xffff0000;
2891 gate_vma.vm_end = 0xffff0000 + PAGE_SIZE;
2892- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2893- gate_vma.vm_flags = VM_READ | VM_EXEC |
2894- VM_MAYREAD | VM_MAYEXEC;
2895+ gate_vma.vm_flags = VM_NONE;
2896+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2897 return 0;
2898 }
2899 arch_initcall(gate_vma_init);
2900diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2901index 03deeff..741ce88 100644
2902--- a/arch/arm/kernel/ptrace.c
2903+++ b/arch/arm/kernel/ptrace.c
2904@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2905 return current_thread_info()->syscall;
2906 }
2907
2908+#ifdef CONFIG_GRKERNSEC_SETXID
2909+extern void gr_delayed_cred_worker(void);
2910+#endif
2911+
2912 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2913 {
2914 current_thread_info()->syscall = scno;
2915
2916+#ifdef CONFIG_GRKERNSEC_SETXID
2917+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2918+ gr_delayed_cred_worker();
2919+#endif
2920+
2921 /* Do the secure computing check first; failures should be fast. */
2922 if (secure_computing(scno) == -1)
2923 return -1;
2924diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2925index 3f6cbb2..6d856f5 100644
2926--- a/arch/arm/kernel/setup.c
2927+++ b/arch/arm/kernel/setup.c
2928@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2929 unsigned int elf_hwcap __read_mostly;
2930 EXPORT_SYMBOL(elf_hwcap);
2931
2932+pteval_t __supported_pte_mask __read_only;
2933+pmdval_t __supported_pmd_mask __read_only;
2934
2935 #ifdef MULTI_CPU
2936-struct processor processor __read_mostly;
2937+struct processor processor;
2938 #endif
2939 #ifdef MULTI_TLB
2940-struct cpu_tlb_fns cpu_tlb __read_mostly;
2941+struct cpu_tlb_fns cpu_tlb __read_only;
2942 #endif
2943 #ifdef MULTI_USER
2944-struct cpu_user_fns cpu_user __read_mostly;
2945+struct cpu_user_fns cpu_user __read_only;
2946 #endif
2947 #ifdef MULTI_CACHE
2948-struct cpu_cache_fns cpu_cache __read_mostly;
2949+struct cpu_cache_fns cpu_cache __read_only;
2950 #endif
2951 #ifdef CONFIG_OUTER_CACHE
2952-struct outer_cache_fns outer_cache __read_mostly;
2953+struct outer_cache_fns outer_cache __read_only;
2954 EXPORT_SYMBOL(outer_cache);
2955 #endif
2956
2957@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2958 asm("mrc p15, 0, %0, c0, c1, 4"
2959 : "=r" (mmfr0));
2960 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2961- (mmfr0 & 0x000000f0) >= 0x00000030)
2962+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2963 cpu_arch = CPU_ARCH_ARMv7;
2964- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2965+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2966+ __supported_pte_mask |= L_PTE_PXN;
2967+ __supported_pmd_mask |= PMD_PXNTABLE;
2968+ }
2969+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2970 (mmfr0 & 0x000000f0) == 0x00000020)
2971 cpu_arch = CPU_ARCH_ARMv6;
2972 else
2973@@ -462,7 +468,7 @@ static void __init setup_processor(void)
2974 __cpu_architecture = __get_cpu_architecture();
2975
2976 #ifdef MULTI_CPU
2977- processor = *list->proc;
2978+ memcpy((void *)&processor, list->proc, sizeof processor);
2979 #endif
2980 #ifdef MULTI_TLB
2981 cpu_tlb = *list->tlb;
2982diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
2983index 56f72d2..6924200 100644
2984--- a/arch/arm/kernel/signal.c
2985+++ b/arch/arm/kernel/signal.c
2986@@ -433,22 +433,14 @@ setup_return(struct pt_regs *regs, struct k_sigaction *ka,
2987 __put_user(sigreturn_codes[idx+1], rc+1))
2988 return 1;
2989
2990- if (cpsr & MODE32_BIT) {
2991- /*
2992- * 32-bit code can use the new high-page
2993- * signal return code support.
2994- */
2995- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
2996- } else {
2997- /*
2998- * Ensure that the instruction cache sees
2999- * the return code written onto the stack.
3000- */
3001- flush_icache_range((unsigned long)rc,
3002- (unsigned long)(rc + 2));
3003+ /*
3004+ * Ensure that the instruction cache sees
3005+ * the return code written onto the stack.
3006+ */
3007+ flush_icache_range((unsigned long)rc,
3008+ (unsigned long)(rc + 2));
3009
3010- retcode = ((unsigned long)rc) + thumb;
3011- }
3012+ retcode = ((unsigned long)rc) + thumb;
3013 }
3014
3015 regs->ARM_r0 = usig;
3016diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3017index 58af91c..343ce99 100644
3018--- a/arch/arm/kernel/smp.c
3019+++ b/arch/arm/kernel/smp.c
3020@@ -70,7 +70,7 @@ enum ipi_msg_type {
3021
3022 static DECLARE_COMPLETION(cpu_running);
3023
3024-static struct smp_operations smp_ops;
3025+static struct smp_operations smp_ops __read_only;
3026
3027 void __init smp_set_ops(struct smp_operations *ops)
3028 {
3029diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3030index b0179b8..829510e 100644
3031--- a/arch/arm/kernel/traps.c
3032+++ b/arch/arm/kernel/traps.c
3033@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3034 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3035 {
3036 #ifdef CONFIG_KALLSYMS
3037- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3038+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3039 #else
3040 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3041 #endif
3042@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3043 static int die_owner = -1;
3044 static unsigned int die_nest_count;
3045
3046+extern void gr_handle_kernel_exploit(void);
3047+
3048 static unsigned long oops_begin(void)
3049 {
3050 int cpu;
3051@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3052 panic("Fatal exception in interrupt");
3053 if (panic_on_oops)
3054 panic("Fatal exception");
3055+
3056+ gr_handle_kernel_exploit();
3057+
3058 if (signr)
3059 do_exit(signr);
3060 }
3061@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3062 * The user helper at 0xffff0fe0 must be used instead.
3063 * (see entry-armv.S for details)
3064 */
3065+ pax_open_kernel();
3066 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3067+ pax_close_kernel();
3068 }
3069 return 0;
3070
3071@@ -841,13 +848,10 @@ void __init early_trap_init(void *vectors_base)
3072 */
3073 kuser_get_tls_init(vectors);
3074
3075- /*
3076- * Copy signal return handlers into the vector page, and
3077- * set sigreturn to be a pointer to these.
3078- */
3079- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3080- sigreturn_codes, sizeof(sigreturn_codes));
3081-
3082 flush_icache_range(vectors, vectors + PAGE_SIZE);
3083- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3084+
3085+#ifndef CONFIG_PAX_MEMORY_UDEREF
3086+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3087+#endif
3088+
3089 }
3090diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3091index 11c1785..c67d54c 100644
3092--- a/arch/arm/kernel/vmlinux.lds.S
3093+++ b/arch/arm/kernel/vmlinux.lds.S
3094@@ -8,7 +8,11 @@
3095 #include <asm/thread_info.h>
3096 #include <asm/memory.h>
3097 #include <asm/page.h>
3098-
3099+
3100+#ifdef CONFIG_PAX_KERNEXEC
3101+#include <asm/pgtable.h>
3102+#endif
3103+
3104 #define PROC_INFO \
3105 . = ALIGN(4); \
3106 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3107@@ -90,6 +94,11 @@ SECTIONS
3108 _text = .;
3109 HEAD_TEXT
3110 }
3111+
3112+#ifdef CONFIG_PAX_KERNEXEC
3113+ . = ALIGN(1<<SECTION_SHIFT);
3114+#endif
3115+
3116 .text : { /* Real text segment */
3117 _stext = .; /* Text and read-only data */
3118 __exception_text_start = .;
3119@@ -144,6 +153,10 @@ SECTIONS
3120
3121 _etext = .; /* End of text and rodata section */
3122
3123+#ifdef CONFIG_PAX_KERNEXEC
3124+ . = ALIGN(1<<SECTION_SHIFT);
3125+#endif
3126+
3127 #ifndef CONFIG_XIP_KERNEL
3128 . = ALIGN(PAGE_SIZE);
3129 __init_begin = .;
3130@@ -203,6 +216,11 @@ SECTIONS
3131 . = PAGE_OFFSET + TEXT_OFFSET;
3132 #else
3133 __init_end = .;
3134+
3135+#ifdef CONFIG_PAX_KERNEXEC
3136+ . = ALIGN(1<<SECTION_SHIFT);
3137+#endif
3138+
3139 . = ALIGN(THREAD_SIZE);
3140 __data_loc = .;
3141 #endif
3142diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3143index 14a0d98..7771a7d 100644
3144--- a/arch/arm/lib/clear_user.S
3145+++ b/arch/arm/lib/clear_user.S
3146@@ -12,14 +12,14 @@
3147
3148 .text
3149
3150-/* Prototype: int __clear_user(void *addr, size_t sz)
3151+/* Prototype: int ___clear_user(void *addr, size_t sz)
3152 * Purpose : clear some user memory
3153 * Params : addr - user memory address to clear
3154 * : sz - number of bytes to clear
3155 * Returns : number of bytes NOT cleared
3156 */
3157 ENTRY(__clear_user_std)
3158-WEAK(__clear_user)
3159+WEAK(___clear_user)
3160 stmfd sp!, {r1, lr}
3161 mov r2, #0
3162 cmp r1, #4
3163@@ -44,7 +44,7 @@ WEAK(__clear_user)
3164 USER( strnebt r2, [r0])
3165 mov r0, #0
3166 ldmfd sp!, {r1, pc}
3167-ENDPROC(__clear_user)
3168+ENDPROC(___clear_user)
3169 ENDPROC(__clear_user_std)
3170
3171 .pushsection .fixup,"ax"
3172diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3173index 66a477a..bee61d3 100644
3174--- a/arch/arm/lib/copy_from_user.S
3175+++ b/arch/arm/lib/copy_from_user.S
3176@@ -16,7 +16,7 @@
3177 /*
3178 * Prototype:
3179 *
3180- * size_t __copy_from_user(void *to, const void *from, size_t n)
3181+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3182 *
3183 * Purpose:
3184 *
3185@@ -84,11 +84,11 @@
3186
3187 .text
3188
3189-ENTRY(__copy_from_user)
3190+ENTRY(___copy_from_user)
3191
3192 #include "copy_template.S"
3193
3194-ENDPROC(__copy_from_user)
3195+ENDPROC(___copy_from_user)
3196
3197 .pushsection .fixup,"ax"
3198 .align 0
3199diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3200index 6ee2f67..d1cce76 100644
3201--- a/arch/arm/lib/copy_page.S
3202+++ b/arch/arm/lib/copy_page.S
3203@@ -10,6 +10,7 @@
3204 * ASM optimised string functions
3205 */
3206 #include <linux/linkage.h>
3207+#include <linux/const.h>
3208 #include <asm/assembler.h>
3209 #include <asm/asm-offsets.h>
3210 #include <asm/cache.h>
3211diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3212index d066df6..df28194 100644
3213--- a/arch/arm/lib/copy_to_user.S
3214+++ b/arch/arm/lib/copy_to_user.S
3215@@ -16,7 +16,7 @@
3216 /*
3217 * Prototype:
3218 *
3219- * size_t __copy_to_user(void *to, const void *from, size_t n)
3220+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3221 *
3222 * Purpose:
3223 *
3224@@ -88,11 +88,11 @@
3225 .text
3226
3227 ENTRY(__copy_to_user_std)
3228-WEAK(__copy_to_user)
3229+WEAK(___copy_to_user)
3230
3231 #include "copy_template.S"
3232
3233-ENDPROC(__copy_to_user)
3234+ENDPROC(___copy_to_user)
3235 ENDPROC(__copy_to_user_std)
3236
3237 .pushsection .fixup,"ax"
3238diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3239index 7d08b43..f7ca7ea 100644
3240--- a/arch/arm/lib/csumpartialcopyuser.S
3241+++ b/arch/arm/lib/csumpartialcopyuser.S
3242@@ -57,8 +57,8 @@
3243 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3244 */
3245
3246-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3247-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3248+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3249+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3250
3251 #include "csumpartialcopygeneric.S"
3252
3253diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3254index 6b93f6a..88d9b64 100644
3255--- a/arch/arm/lib/delay.c
3256+++ b/arch/arm/lib/delay.c
3257@@ -28,12 +28,14 @@
3258 /*
3259 * Default to the loop-based delay implementation.
3260 */
3261-struct arm_delay_ops arm_delay_ops = {
3262+static struct arm_delay_ops arm_loop_delay_ops = {
3263 .delay = __loop_delay,
3264 .const_udelay = __loop_const_udelay,
3265 .udelay = __loop_udelay,
3266 };
3267
3268+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3269+
3270 static const struct delay_timer *delay_timer;
3271 static bool delay_calibrated;
3272
3273@@ -67,6 +69,13 @@ static void __timer_udelay(unsigned long usecs)
3274 __timer_const_udelay(usecs * UDELAY_MULT);
3275 }
3276
3277+static struct arm_delay_ops arm_timer_delay_ops = {
3278+ .delay = __timer_delay,
3279+ .const_udelay = __timer_const_udelay,
3280+ .udelay = __timer_udelay,
3281+ .const_clock = true,
3282+};
3283+
3284 void __init register_current_timer_delay(const struct delay_timer *timer)
3285 {
3286 if (!delay_calibrated) {
3287@@ -74,10 +83,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3288 delay_timer = timer;
3289 lpj_fine = timer->freq / HZ;
3290 loops_per_jiffy = lpj_fine;
3291- arm_delay_ops.delay = __timer_delay;
3292- arm_delay_ops.const_udelay = __timer_const_udelay;
3293- arm_delay_ops.udelay = __timer_udelay;
3294- arm_delay_ops.const_clock = true;
3295+ arm_delay_ops = &arm_timer_delay_ops;
3296 delay_calibrated = true;
3297 } else {
3298 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3299diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3300index 025f742..8432b08 100644
3301--- a/arch/arm/lib/uaccess_with_memcpy.c
3302+++ b/arch/arm/lib/uaccess_with_memcpy.c
3303@@ -104,7 +104,7 @@ out:
3304 }
3305
3306 unsigned long
3307-__copy_to_user(void __user *to, const void *from, unsigned long n)
3308+___copy_to_user(void __user *to, const void *from, unsigned long n)
3309 {
3310 /*
3311 * This test is stubbed out of the main function above to keep
3312diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3313index bac21a5..b67ef8e 100644
3314--- a/arch/arm/mach-kirkwood/common.c
3315+++ b/arch/arm/mach-kirkwood/common.c
3316@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3317 clk_gate_ops.disable(hw);
3318 }
3319
3320-static struct clk_ops clk_gate_fn_ops;
3321+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3322+{
3323+ return clk_gate_ops.is_enabled(hw);
3324+}
3325+
3326+static struct clk_ops clk_gate_fn_ops = {
3327+ .enable = clk_gate_fn_enable,
3328+ .disable = clk_gate_fn_disable,
3329+ .is_enabled = clk_gate_fn_is_enabled,
3330+};
3331
3332 static struct clk __init *clk_register_gate_fn(struct device *dev,
3333 const char *name,
3334@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3335 gate_fn->fn_en = fn_en;
3336 gate_fn->fn_dis = fn_dis;
3337
3338- /* ops is the gate ops, but with our enable/disable functions */
3339- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3340- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3341- clk_gate_fn_ops = clk_gate_ops;
3342- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3343- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3344- }
3345-
3346 clk = clk_register(dev, &gate_fn->gate.hw);
3347
3348 if (IS_ERR(clk))
3349diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3350index 0abb30f..54064da 100644
3351--- a/arch/arm/mach-omap2/board-n8x0.c
3352+++ b/arch/arm/mach-omap2/board-n8x0.c
3353@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3354 }
3355 #endif
3356
3357-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3358+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3359 .late_init = n8x0_menelaus_late_init,
3360 };
3361
3362diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3363index 8033cb7..2f7cb62 100644
3364--- a/arch/arm/mach-omap2/gpmc.c
3365+++ b/arch/arm/mach-omap2/gpmc.c
3366@@ -139,7 +139,6 @@ struct omap3_gpmc_regs {
3367 };
3368
3369 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3370-static struct irq_chip gpmc_irq_chip;
3371 static unsigned gpmc_irq_start;
3372
3373 static struct resource gpmc_mem_root;
3374@@ -700,6 +699,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3375
3376 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3377
3378+static struct irq_chip gpmc_irq_chip = {
3379+ .name = "gpmc",
3380+ .irq_startup = gpmc_irq_noop_ret,
3381+ .irq_enable = gpmc_irq_enable,
3382+ .irq_disable = gpmc_irq_disable,
3383+ .irq_shutdown = gpmc_irq_noop,
3384+ .irq_ack = gpmc_irq_noop,
3385+ .irq_mask = gpmc_irq_noop,
3386+ .irq_unmask = gpmc_irq_noop,
3387+
3388+};
3389+
3390 static int gpmc_setup_irq(void)
3391 {
3392 int i;
3393@@ -714,15 +725,6 @@ static int gpmc_setup_irq(void)
3394 return gpmc_irq_start;
3395 }
3396
3397- gpmc_irq_chip.name = "gpmc";
3398- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3399- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3400- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3401- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3402- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3403- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3404- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3405-
3406 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3407 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3408
3409diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3410index 5d3b4f4..ddba3c0 100644
3411--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3412+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3413@@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3414 return NOTIFY_OK;
3415 }
3416
3417-static struct notifier_block __refdata irq_hotplug_notifier = {
3418+static struct notifier_block irq_hotplug_notifier = {
3419 .notifier_call = irq_cpu_hotplug_notify,
3420 };
3421
3422diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3423index e065daa..7b1ad9b 100644
3424--- a/arch/arm/mach-omap2/omap_device.c
3425+++ b/arch/arm/mach-omap2/omap_device.c
3426@@ -686,7 +686,7 @@ void omap_device_delete(struct omap_device *od)
3427 * passes along the return value of omap_device_build_ss().
3428 */
3429 struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
3430- struct omap_hwmod *oh, void *pdata,
3431+ struct omap_hwmod *oh, const void *pdata,
3432 int pdata_len,
3433 struct omap_device_pm_latency *pm_lats,
3434 int pm_lats_cnt, int is_early_device)
3435@@ -720,7 +720,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name, int pdev
3436 */
3437 struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
3438 struct omap_hwmod **ohs, int oh_cnt,
3439- void *pdata, int pdata_len,
3440+ const void *pdata, int pdata_len,
3441 struct omap_device_pm_latency *pm_lats,
3442 int pm_lats_cnt, int is_early_device)
3443 {
3444diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3445index 0933c59..42b8e2d 100644
3446--- a/arch/arm/mach-omap2/omap_device.h
3447+++ b/arch/arm/mach-omap2/omap_device.h
3448@@ -91,14 +91,14 @@ int omap_device_shutdown(struct platform_device *pdev);
3449 /* Core code interface */
3450
3451 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3452- struct omap_hwmod *oh, void *pdata,
3453+ struct omap_hwmod *oh, const void *pdata,
3454 int pdata_len,
3455 struct omap_device_pm_latency *pm_lats,
3456 int pm_lats_cnt, int is_early_device);
3457
3458 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3459 struct omap_hwmod **oh, int oh_cnt,
3460- void *pdata, int pdata_len,
3461+ const void *pdata, int pdata_len,
3462 struct omap_device_pm_latency *pm_lats,
3463 int pm_lats_cnt, int is_early_device);
3464
3465diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3466index 4653efb..8c60bf7 100644
3467--- a/arch/arm/mach-omap2/omap_hwmod.c
3468+++ b/arch/arm/mach-omap2/omap_hwmod.c
3469@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3470 int (*init_clkdm)(struct omap_hwmod *oh);
3471 void (*update_context_lost)(struct omap_hwmod *oh);
3472 int (*get_context_lost)(struct omap_hwmod *oh);
3473-};
3474+} __no_const;
3475
3476 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3477-static struct omap_hwmod_soc_ops soc_ops;
3478+static struct omap_hwmod_soc_ops soc_ops __read_only;
3479
3480 /* omap_hwmod_list contains all registered struct omap_hwmods */
3481 static LIST_HEAD(omap_hwmod_list);
3482diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3483index 7c2b4ed..b2ea51f 100644
3484--- a/arch/arm/mach-omap2/wd_timer.c
3485+++ b/arch/arm/mach-omap2/wd_timer.c
3486@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3487 struct omap_hwmod *oh;
3488 char *oh_name = "wd_timer2";
3489 char *dev_name = "omap_wdt";
3490- struct omap_wd_timer_platform_data pdata;
3491+ static struct omap_wd_timer_platform_data pdata = {
3492+ .read_reset_sources = prm_read_reset_sources
3493+ };
3494
3495 if (!cpu_class_is_omap2() || of_have_populated_dt())
3496 return 0;
3497@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3498 return -EINVAL;
3499 }
3500
3501- pdata.read_reset_sources = prm_read_reset_sources;
3502-
3503 pdev = omap_device_build(dev_name, id, oh, &pdata,
3504 sizeof(struct omap_wd_timer_platform_data),
3505 NULL, 0, 0);
3506diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3507index 6be4c4d..32ac32a 100644
3508--- a/arch/arm/mach-ux500/include/mach/setup.h
3509+++ b/arch/arm/mach-ux500/include/mach/setup.h
3510@@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3511 .type = MT_DEVICE, \
3512 }
3513
3514-#define __MEM_DEV_DESC(x, sz) { \
3515- .virtual = IO_ADDRESS(x), \
3516- .pfn = __phys_to_pfn(x), \
3517- .length = sz, \
3518- .type = MT_MEMORY, \
3519-}
3520-
3521 extern struct smp_operations ux500_smp_ops;
3522 extern void ux500_cpu_die(unsigned int cpu);
3523
3524diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3525index 3fd629d..8b1aca9 100644
3526--- a/arch/arm/mm/Kconfig
3527+++ b/arch/arm/mm/Kconfig
3528@@ -425,7 +425,7 @@ config CPU_32v5
3529
3530 config CPU_32v6
3531 bool
3532- select CPU_USE_DOMAINS if CPU_V6 && MMU
3533+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3534 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3535
3536 config CPU_32v6K
3537@@ -577,6 +577,7 @@ config CPU_CP15_MPU
3538
3539 config CPU_USE_DOMAINS
3540 bool
3541+ depends on !ARM_LPAE && !PAX_KERNEXEC
3542 help
3543 This option enables or disables the use of domain switching
3544 via the set_fs() function.
3545diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3546index db26e2e..ee44569 100644
3547--- a/arch/arm/mm/alignment.c
3548+++ b/arch/arm/mm/alignment.c
3549@@ -211,10 +211,12 @@ union offset_union {
3550 #define __get16_unaligned_check(ins,val,addr) \
3551 do { \
3552 unsigned int err = 0, v, a = addr; \
3553+ pax_open_userland(); \
3554 __get8_unaligned_check(ins,v,a,err); \
3555 val = v << ((BE) ? 8 : 0); \
3556 __get8_unaligned_check(ins,v,a,err); \
3557 val |= v << ((BE) ? 0 : 8); \
3558+ pax_close_userland(); \
3559 if (err) \
3560 goto fault; \
3561 } while (0)
3562@@ -228,6 +230,7 @@ union offset_union {
3563 #define __get32_unaligned_check(ins,val,addr) \
3564 do { \
3565 unsigned int err = 0, v, a = addr; \
3566+ pax_open_userland(); \
3567 __get8_unaligned_check(ins,v,a,err); \
3568 val = v << ((BE) ? 24 : 0); \
3569 __get8_unaligned_check(ins,v,a,err); \
3570@@ -236,6 +239,7 @@ union offset_union {
3571 val |= v << ((BE) ? 8 : 16); \
3572 __get8_unaligned_check(ins,v,a,err); \
3573 val |= v << ((BE) ? 0 : 24); \
3574+ pax_close_userland(); \
3575 if (err) \
3576 goto fault; \
3577 } while (0)
3578@@ -249,6 +253,7 @@ union offset_union {
3579 #define __put16_unaligned_check(ins,val,addr) \
3580 do { \
3581 unsigned int err = 0, v = val, a = addr; \
3582+ pax_open_userland(); \
3583 __asm__( FIRST_BYTE_16 \
3584 ARM( "1: "ins" %1, [%2], #1\n" ) \
3585 THUMB( "1: "ins" %1, [%2]\n" ) \
3586@@ -268,6 +273,7 @@ union offset_union {
3587 " .popsection\n" \
3588 : "=r" (err), "=&r" (v), "=&r" (a) \
3589 : "0" (err), "1" (v), "2" (a)); \
3590+ pax_close_userland(); \
3591 if (err) \
3592 goto fault; \
3593 } while (0)
3594@@ -281,6 +287,7 @@ union offset_union {
3595 #define __put32_unaligned_check(ins,val,addr) \
3596 do { \
3597 unsigned int err = 0, v = val, a = addr; \
3598+ pax_open_userland(); \
3599 __asm__( FIRST_BYTE_32 \
3600 ARM( "1: "ins" %1, [%2], #1\n" ) \
3601 THUMB( "1: "ins" %1, [%2]\n" ) \
3602@@ -310,6 +317,7 @@ union offset_union {
3603 " .popsection\n" \
3604 : "=r" (err), "=&r" (v), "=&r" (a) \
3605 : "0" (err), "1" (v), "2" (a)); \
3606+ pax_close_userland(); \
3607 if (err) \
3608 goto fault; \
3609 } while (0)
3610diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3611index 5dbf13f..e16ab04 100644
3612--- a/arch/arm/mm/fault.c
3613+++ b/arch/arm/mm/fault.c
3614@@ -25,6 +25,7 @@
3615 #include <asm/system_misc.h>
3616 #include <asm/system_info.h>
3617 #include <asm/tlbflush.h>
3618+#include <asm/sections.h>
3619
3620 #include "fault.h"
3621
3622@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3623 if (fixup_exception(regs))
3624 return;
3625
3626+#ifdef CONFIG_PAX_KERNEXEC
3627+ if ((fsr & FSR_WRITE) &&
3628+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3629+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3630+ {
3631+ if (current->signal->curr_ip)
3632+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3633+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3634+ else
3635+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3636+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3637+ }
3638+#endif
3639+
3640 /*
3641 * No handler, we'll have to terminate things with extreme prejudice.
3642 */
3643@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3644 }
3645 #endif
3646
3647+#ifdef CONFIG_PAX_PAGEEXEC
3648+ if (fsr & FSR_LNX_PF) {
3649+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3650+ do_group_exit(SIGKILL);
3651+ }
3652+#endif
3653+
3654 tsk->thread.address = addr;
3655 tsk->thread.error_code = fsr;
3656 tsk->thread.trap_no = 14;
3657@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3658 }
3659 #endif /* CONFIG_MMU */
3660
3661+#ifdef CONFIG_PAX_PAGEEXEC
3662+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3663+{
3664+ long i;
3665+
3666+ printk(KERN_ERR "PAX: bytes at PC: ");
3667+ for (i = 0; i < 20; i++) {
3668+ unsigned char c;
3669+ if (get_user(c, (__force unsigned char __user *)pc+i))
3670+ printk(KERN_CONT "?? ");
3671+ else
3672+ printk(KERN_CONT "%02x ", c);
3673+ }
3674+ printk("\n");
3675+
3676+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3677+ for (i = -1; i < 20; i++) {
3678+ unsigned long c;
3679+ if (get_user(c, (__force unsigned long __user *)sp+i))
3680+ printk(KERN_CONT "???????? ");
3681+ else
3682+ printk(KERN_CONT "%08lx ", c);
3683+ }
3684+ printk("\n");
3685+}
3686+#endif
3687+
3688 /*
3689 * First Level Translation Fault Handler
3690 *
3691@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3692 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3693 struct siginfo info;
3694
3695+#ifdef CONFIG_PAX_MEMORY_UDEREF
3696+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3697+ if (current->signal->curr_ip)
3698+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3699+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3700+ else
3701+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3702+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3703+ goto die;
3704+ }
3705+#endif
3706+
3707 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3708 return;
3709
3710+die:
3711 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3712 inf->name, fsr, addr);
3713
3714@@ -575,9 +637,58 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3715 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3716 struct siginfo info;
3717
3718+ if (user_mode(regs)) {
3719+ if (addr == 0xffff0fe0UL) {
3720+ /*
3721+ * PaX: __kuser_get_tls emulation
3722+ */
3723+ regs->ARM_r0 = current_thread_info()->tp_value;
3724+ regs->ARM_pc = regs->ARM_lr;
3725+ return;
3726+ }
3727+ }
3728+
3729+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3730+<<<<<<< HEAD
3731+ if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3732+ if (current->signal->curr_ip)
3733+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3734+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3735+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3736+ else
3737+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3738+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3739+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3740+=======
3741+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3742+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
3743+ current->comm, task_pid_nr(current),
3744+ from_kuid_munged(&init_user_ns, current_uid()),
3745+ from_kuid_munged(&init_user_ns, current_euid()),
3746+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3747+>>>>>>> c57d8557f5f2d77c2c7fa1f58316819a5e1f9293
3748+ goto die;
3749+ }
3750+#endif
3751+
3752+#ifdef CONFIG_PAX_REFCOUNT
3753+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3754+ unsigned int bkpt;
3755+
3756+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3757+ current->thread.error_code = ifsr;
3758+ current->thread.trap_no = 0;
3759+ pax_report_refcount_overflow(regs);
3760+ fixup_exception(regs);
3761+ return;
3762+ }
3763+ }
3764+#endif
3765+
3766 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3767 return;
3768
3769+die:
3770 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3771 inf->name, ifsr, addr);
3772
3773diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3774index cf08bdf..772656c 100644
3775--- a/arch/arm/mm/fault.h
3776+++ b/arch/arm/mm/fault.h
3777@@ -3,6 +3,7 @@
3778
3779 /*
3780 * Fault status register encodings. We steal bit 31 for our own purposes.
3781+ * Set when the FSR value is from an instruction fault.
3782 */
3783 #define FSR_LNX_PF (1 << 31)
3784 #define FSR_WRITE (1 << 11)
3785@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3786 }
3787 #endif
3788
3789+/* valid for LPAE and !LPAE */
3790+static inline int is_xn_fault(unsigned int fsr)
3791+{
3792+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3793+}
3794+
3795+static inline int is_domain_fault(unsigned int fsr)
3796+{
3797+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3798+}
3799+
3800 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3801 unsigned long search_exception_table(unsigned long addr);
3802
3803diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3804index ad722f1..763fdd3 100644
3805--- a/arch/arm/mm/init.c
3806+++ b/arch/arm/mm/init.c
3807@@ -30,6 +30,8 @@
3808 #include <asm/setup.h>
3809 #include <asm/tlb.h>
3810 #include <asm/fixmap.h>
3811+#include <asm/system_info.h>
3812+#include <asm/cp15.h>
3813
3814 #include <asm/mach/arch.h>
3815 #include <asm/mach/map.h>
3816@@ -736,7 +738,46 @@ void free_initmem(void)
3817 {
3818 #ifdef CONFIG_HAVE_TCM
3819 extern char __tcm_start, __tcm_end;
3820+#endif
3821
3822+#ifdef CONFIG_PAX_KERNEXEC
3823+ unsigned long addr;
3824+ pgd_t *pgd;
3825+ pud_t *pud;
3826+ pmd_t *pmd;
3827+ int cpu_arch = cpu_architecture();
3828+ unsigned int cr = get_cr();
3829+
3830+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3831+ /* make pages tables, etc before .text NX */
3832+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3833+ pgd = pgd_offset_k(addr);
3834+ pud = pud_offset(pgd, addr);
3835+ pmd = pmd_offset(pud, addr);
3836+ __section_update(pmd, addr, PMD_SECT_XN);
3837+ }
3838+ /* make init NX */
3839+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3840+ pgd = pgd_offset_k(addr);
3841+ pud = pud_offset(pgd, addr);
3842+ pmd = pmd_offset(pud, addr);
3843+ __section_update(pmd, addr, PMD_SECT_XN);
3844+ }
3845+ /* make kernel code/rodata RX */
3846+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3847+ pgd = pgd_offset_k(addr);
3848+ pud = pud_offset(pgd, addr);
3849+ pmd = pmd_offset(pud, addr);
3850+#ifdef CONFIG_ARM_LPAE
3851+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3852+#else
3853+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3854+#endif
3855+ }
3856+ }
3857+#endif
3858+
3859+#ifdef CONFIG_HAVE_TCM
3860 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3861 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3862 __phys_to_pfn(__pa(&__tcm_end)),
3863diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3864index 88fd86c..7a224ce 100644
3865--- a/arch/arm/mm/ioremap.c
3866+++ b/arch/arm/mm/ioremap.c
3867@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3868 unsigned int mtype;
3869
3870 if (cached)
3871- mtype = MT_MEMORY;
3872+ mtype = MT_MEMORY_RX;
3873 else
3874- mtype = MT_MEMORY_NONCACHED;
3875+ mtype = MT_MEMORY_NONCACHED_RX;
3876
3877 return __arm_ioremap_caller(phys_addr, size, mtype,
3878 __builtin_return_address(0));
3879diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3880index 10062ce..aa96dd7 100644
3881--- a/arch/arm/mm/mmap.c
3882+++ b/arch/arm/mm/mmap.c
3883@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3884 struct vm_area_struct *vma;
3885 int do_align = 0;
3886 int aliasing = cache_is_vipt_aliasing();
3887+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3888 struct vm_unmapped_area_info info;
3889
3890 /*
3891@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3892 if (len > TASK_SIZE)
3893 return -ENOMEM;
3894
3895+#ifdef CONFIG_PAX_RANDMMAP
3896+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3897+#endif
3898+
3899 if (addr) {
3900 if (do_align)
3901 addr = COLOUR_ALIGN(addr, pgoff);
3902@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3903 addr = PAGE_ALIGN(addr);
3904
3905 vma = find_vma(mm, addr);
3906- if (TASK_SIZE - len >= addr &&
3907- (!vma || addr + len <= vma->vm_start))
3908+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3909 return addr;
3910 }
3911
3912@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3913 unsigned long addr = addr0;
3914 int do_align = 0;
3915 int aliasing = cache_is_vipt_aliasing();
3916+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3917 struct vm_unmapped_area_info info;
3918
3919 /*
3920@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3921 return addr;
3922 }
3923
3924+#ifdef CONFIG_PAX_RANDMMAP
3925+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3926+#endif
3927+
3928 /* requesting a specific address */
3929 if (addr) {
3930 if (do_align)
3931@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3932 else
3933 addr = PAGE_ALIGN(addr);
3934 vma = find_vma(mm, addr);
3935- if (TASK_SIZE - len >= addr &&
3936- (!vma || addr + len <= vma->vm_start))
3937+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3938 return addr;
3939 }
3940
3941@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3942 VM_BUG_ON(addr != -ENOMEM);
3943 info.flags = 0;
3944 info.low_limit = mm->mmap_base;
3945+
3946+#ifdef CONFIG_PAX_RANDMMAP
3947+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3948+ info.low_limit += mm->delta_mmap;
3949+#endif
3950+
3951 info.high_limit = TASK_SIZE;
3952 addr = vm_unmapped_area(&info);
3953 }
3954@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3955 {
3956 unsigned long random_factor = 0UL;
3957
3958+#ifdef CONFIG_PAX_RANDMMAP
3959+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3960+#endif
3961+
3962 /* 8 bits of randomness in 20 address space bits */
3963 if ((current->flags & PF_RANDOMIZE) &&
3964 !(current->personality & ADDR_NO_RANDOMIZE))
3965@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3966
3967 if (mmap_is_legacy()) {
3968 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3969+
3970+#ifdef CONFIG_PAX_RANDMMAP
3971+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3972+ mm->mmap_base += mm->delta_mmap;
3973+#endif
3974+
3975 mm->get_unmapped_area = arch_get_unmapped_area;
3976 mm->unmap_area = arch_unmap_area;
3977 } else {
3978 mm->mmap_base = mmap_base(random_factor);
3979+
3980+#ifdef CONFIG_PAX_RANDMMAP
3981+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3982+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3983+#endif
3984+
3985 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3986 mm->unmap_area = arch_unmap_area_topdown;
3987 }
3988diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3989index ce328c7..35b88dc 100644
3990--- a/arch/arm/mm/mmu.c
3991+++ b/arch/arm/mm/mmu.c
3992@@ -35,6 +35,23 @@
3993
3994 #include "mm.h"
3995
3996+
3997+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3998+void modify_domain(unsigned int dom, unsigned int type)
3999+{
4000+ struct thread_info *thread = current_thread_info();
4001+ unsigned int domain = thread->cpu_domain;
4002+ /*
4003+ * DOMAIN_MANAGER might be defined to some other value,
4004+ * use the arch-defined constant
4005+ */
4006+ domain &= ~domain_val(dom, 3);
4007+ thread->cpu_domain = domain | domain_val(dom, type);
4008+ set_domain(thread->cpu_domain);
4009+}
4010+EXPORT_SYMBOL(modify_domain);
4011+#endif
4012+
4013 /*
4014 * empty_zero_page is a special page that is used for
4015 * zero-initialized data and COW.
4016@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
4017 }
4018 #endif
4019
4020-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4021+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4022 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4023
4024-static struct mem_type mem_types[] = {
4025+#ifdef CONFIG_PAX_KERNEXEC
4026+#define L_PTE_KERNEXEC L_PTE_RDONLY
4027+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4028+#else
4029+#define L_PTE_KERNEXEC L_PTE_DIRTY
4030+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4031+#endif
4032+
4033+static struct mem_type mem_types[] __read_only = {
4034 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4035 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4036 L_PTE_SHARED,
4037@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
4038 [MT_UNCACHED] = {
4039 .prot_pte = PROT_PTE_DEVICE,
4040 .prot_l1 = PMD_TYPE_TABLE,
4041- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4042+ .prot_sect = PROT_SECT_DEVICE,
4043 .domain = DOMAIN_IO,
4044 },
4045 [MT_CACHECLEAN] = {
4046- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4047+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4048 .domain = DOMAIN_KERNEL,
4049 },
4050 #ifndef CONFIG_ARM_LPAE
4051 [MT_MINICLEAN] = {
4052- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4053+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4054 .domain = DOMAIN_KERNEL,
4055 },
4056 #endif
4057@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
4058 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4059 L_PTE_RDONLY,
4060 .prot_l1 = PMD_TYPE_TABLE,
4061- .domain = DOMAIN_USER,
4062+ .domain = DOMAIN_VECTORS,
4063 },
4064 [MT_HIGH_VECTORS] = {
4065 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4066- L_PTE_USER | L_PTE_RDONLY,
4067+ L_PTE_RDONLY,
4068 .prot_l1 = PMD_TYPE_TABLE,
4069- .domain = DOMAIN_USER,
4070+ .domain = DOMAIN_VECTORS,
4071 },
4072- [MT_MEMORY] = {
4073+ [MT_MEMORY_RWX] = {
4074 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4075 .prot_l1 = PMD_TYPE_TABLE,
4076 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4077 .domain = DOMAIN_KERNEL,
4078 },
4079+ [MT_MEMORY_RW] = {
4080+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4081+ .prot_l1 = PMD_TYPE_TABLE,
4082+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4083+ .domain = DOMAIN_KERNEL,
4084+ },
4085+ [MT_MEMORY_RX] = {
4086+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4087+ .prot_l1 = PMD_TYPE_TABLE,
4088+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4089+ .domain = DOMAIN_KERNEL,
4090+ },
4091 [MT_ROM] = {
4092- .prot_sect = PMD_TYPE_SECT,
4093+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4094 .domain = DOMAIN_KERNEL,
4095 },
4096- [MT_MEMORY_NONCACHED] = {
4097+ [MT_MEMORY_NONCACHED_RW] = {
4098 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4099 L_PTE_MT_BUFFERABLE,
4100 .prot_l1 = PMD_TYPE_TABLE,
4101 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4102 .domain = DOMAIN_KERNEL,
4103 },
4104+ [MT_MEMORY_NONCACHED_RX] = {
4105+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4106+ L_PTE_MT_BUFFERABLE,
4107+ .prot_l1 = PMD_TYPE_TABLE,
4108+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4109+ .domain = DOMAIN_KERNEL,
4110+ },
4111 [MT_MEMORY_DTCM] = {
4112- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4113- L_PTE_XN,
4114+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4115 .prot_l1 = PMD_TYPE_TABLE,
4116- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4117+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4118 .domain = DOMAIN_KERNEL,
4119 },
4120 [MT_MEMORY_ITCM] = {
4121@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
4122 },
4123 [MT_MEMORY_SO] = {
4124 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4125- L_PTE_MT_UNCACHED | L_PTE_XN,
4126+ L_PTE_MT_UNCACHED,
4127 .prot_l1 = PMD_TYPE_TABLE,
4128 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4129- PMD_SECT_UNCACHED | PMD_SECT_XN,
4130+ PMD_SECT_UNCACHED,
4131 .domain = DOMAIN_KERNEL,
4132 },
4133 [MT_MEMORY_DMA_READY] = {
4134@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
4135 * to prevent speculative instruction fetches.
4136 */
4137 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4138+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4139 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4140+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4141 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4142+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4143 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4144+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4145+
4146+ /* Mark other regions on ARMv6+ as execute-never */
4147+
4148+#ifdef CONFIG_PAX_KERNEXEC
4149+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4150+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4151+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4152+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4153+#ifndef CONFIG_ARM_LPAE
4154+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4155+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4156+#endif
4157+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4158+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4159+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4160+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4161+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4162+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4163+#endif
4164+
4165+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4166+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4167 }
4168 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4169 /*
4170@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
4171 * from SVC mode and no access from userspace.
4172 */
4173 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4174+#ifdef CONFIG_PAX_KERNEXEC
4175+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4176+#endif
4177 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4178 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4179 #endif
4180@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
4181 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4182 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4183 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4184- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4185- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4186+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4187+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4188+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4189+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4190+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4191+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4192 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4193- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4194- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4195+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4196+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4197+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4198+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4199 }
4200 }
4201
4202@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
4203 if (cpu_arch >= CPU_ARCH_ARMv6) {
4204 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4205 /* Non-cacheable Normal is XCB = 001 */
4206- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4207+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4208+ PMD_SECT_BUFFERED;
4209+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4210 PMD_SECT_BUFFERED;
4211 } else {
4212 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4213- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4214+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4215+ PMD_SECT_TEX(1);
4216+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4217 PMD_SECT_TEX(1);
4218 }
4219 } else {
4220- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4221+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4222+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4223 }
4224
4225 #ifdef CONFIG_ARM_LPAE
4226@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
4227 vecs_pgprot |= PTE_EXT_AF;
4228 #endif
4229
4230+ user_pgprot |= __supported_pte_mask;
4231+
4232 for (i = 0; i < 16; i++) {
4233 pteval_t v = pgprot_val(protection_map[i]);
4234 protection_map[i] = __pgprot(v | user_pgprot);
4235@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4236
4237 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4238 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4239- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4240- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4241+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4242+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4243+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4244+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4245+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4246+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4247 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4248- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4249+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4250+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4251 mem_types[MT_ROM].prot_sect |= cp->pmd;
4252
4253 switch (cp->pmd) {
4254@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4255 * called function. This means you can't use any function or debugging
4256 * method which may touch any device, otherwise the kernel _will_ crash.
4257 */
4258+
4259+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4260+
4261 static void __init devicemaps_init(struct machine_desc *mdesc)
4262 {
4263 struct map_desc map;
4264 unsigned long addr;
4265- void *vectors;
4266
4267- /*
4268- * Allocate the vector page early.
4269- */
4270- vectors = early_alloc(PAGE_SIZE);
4271-
4272- early_trap_init(vectors);
4273+ early_trap_init(&vectors);
4274
4275 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4276 pmd_clear(pmd_off_k(addr));
4277@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4278 * location (0xffff0000). If we aren't using high-vectors, also
4279 * create a mapping at the low-vectors virtual address.
4280 */
4281- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4282+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4283 map.virtual = 0xffff0000;
4284 map.length = PAGE_SIZE;
4285 map.type = MT_HIGH_VECTORS;
4286@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4287 map.pfn = __phys_to_pfn(start);
4288 map.virtual = __phys_to_virt(start);
4289 map.length = end - start;
4290- map.type = MT_MEMORY;
4291
4292+#ifdef CONFIG_PAX_KERNEXEC
4293+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4294+ struct map_desc kernel;
4295+ struct map_desc initmap;
4296+
4297+ /* when freeing initmem we will make this RW */
4298+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4299+ initmap.virtual = (unsigned long)__init_begin;
4300+ initmap.length = _sdata - __init_begin;
4301+ initmap.type = MT_MEMORY_RWX;
4302+ create_mapping(&initmap);
4303+
4304+ /* when freeing initmem we will make this RX */
4305+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4306+ kernel.virtual = (unsigned long)_stext;
4307+ kernel.length = __init_begin - _stext;
4308+ kernel.type = MT_MEMORY_RWX;
4309+ create_mapping(&kernel);
4310+
4311+ if (map.virtual < (unsigned long)_stext) {
4312+ map.length = (unsigned long)_stext - map.virtual;
4313+ map.type = MT_MEMORY_RWX;
4314+ create_mapping(&map);
4315+ }
4316+
4317+ map.pfn = __phys_to_pfn(__pa(_sdata));
4318+ map.virtual = (unsigned long)_sdata;
4319+ map.length = end - __pa(_sdata);
4320+ }
4321+#endif
4322+
4323+ map.type = MT_MEMORY_RW;
4324 create_mapping(&map);
4325 }
4326 }
4327diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4328index 6d98c13..3cfb174 100644
4329--- a/arch/arm/mm/proc-v7-2level.S
4330+++ b/arch/arm/mm/proc-v7-2level.S
4331@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4332 tst r1, #L_PTE_XN
4333 orrne r3, r3, #PTE_EXT_XN
4334
4335+ tst r1, #L_PTE_PXN
4336+ orrne r3, r3, #PTE_EXT_PXN
4337+
4338 tst r1, #L_PTE_YOUNG
4339 tstne r1, #L_PTE_VALID
4340 #ifndef CONFIG_CPU_USE_DOMAINS
4341diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4342index a5bc92d..0bb4730 100644
4343--- a/arch/arm/plat-omap/sram.c
4344+++ b/arch/arm/plat-omap/sram.c
4345@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4346 * Looks like we need to preserve some bootloader code at the
4347 * beginning of SRAM for jumping to flash for reboot to work...
4348 */
4349+ pax_open_kernel();
4350 memset_io(omap_sram_base + omap_sram_skip, 0,
4351 omap_sram_size - omap_sram_skip);
4352+ pax_close_kernel();
4353 }
4354diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4355index f5144cd..71f6d1f 100644
4356--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4357+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4358@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4359 int (*started)(unsigned ch);
4360 int (*flush)(unsigned ch);
4361 int (*stop)(unsigned ch);
4362-};
4363+} __no_const;
4364
4365 extern void *samsung_dmadev_get_ops(void);
4366 extern void *s3c_dma_get_ops(void);
4367diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4368index 0c3ba9f..95722b3 100644
4369--- a/arch/arm64/kernel/debug-monitors.c
4370+++ b/arch/arm64/kernel/debug-monitors.c
4371@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4372 return NOTIFY_OK;
4373 }
4374
4375-static struct notifier_block __cpuinitdata os_lock_nb = {
4376+static struct notifier_block os_lock_nb = {
4377 .notifier_call = os_lock_notify,
4378 };
4379
4380diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4381index 5ab825c..96aaec8 100644
4382--- a/arch/arm64/kernel/hw_breakpoint.c
4383+++ b/arch/arm64/kernel/hw_breakpoint.c
4384@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4385 return NOTIFY_OK;
4386 }
4387
4388-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4389+static struct notifier_block hw_breakpoint_reset_nb = {
4390 .notifier_call = hw_breakpoint_reset_notify,
4391 };
4392
4393diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4394index c3a58a1..78fbf54 100644
4395--- a/arch/avr32/include/asm/cache.h
4396+++ b/arch/avr32/include/asm/cache.h
4397@@ -1,8 +1,10 @@
4398 #ifndef __ASM_AVR32_CACHE_H
4399 #define __ASM_AVR32_CACHE_H
4400
4401+#include <linux/const.h>
4402+
4403 #define L1_CACHE_SHIFT 5
4404-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4405+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4406
4407 /*
4408 * Memory returned by kmalloc() may be used for DMA, so we must make
4409diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4410index e2c3287..6c4f98c 100644
4411--- a/arch/avr32/include/asm/elf.h
4412+++ b/arch/avr32/include/asm/elf.h
4413@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4414 the loader. We need to make sure that it is out of the way of the program
4415 that it will "exec", and that there is sufficient room for the brk. */
4416
4417-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4418+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4419
4420+#ifdef CONFIG_PAX_ASLR
4421+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4422+
4423+#define PAX_DELTA_MMAP_LEN 15
4424+#define PAX_DELTA_STACK_LEN 15
4425+#endif
4426
4427 /* This yields a mask that user programs can use to figure out what
4428 instruction set this CPU supports. This could be done in user space,
4429diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4430index 479330b..53717a8 100644
4431--- a/arch/avr32/include/asm/kmap_types.h
4432+++ b/arch/avr32/include/asm/kmap_types.h
4433@@ -2,9 +2,9 @@
4434 #define __ASM_AVR32_KMAP_TYPES_H
4435
4436 #ifdef CONFIG_DEBUG_HIGHMEM
4437-# define KM_TYPE_NR 29
4438+# define KM_TYPE_NR 30
4439 #else
4440-# define KM_TYPE_NR 14
4441+# define KM_TYPE_NR 15
4442 #endif
4443
4444 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4445diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4446index b2f2d2d..d1c85cb 100644
4447--- a/arch/avr32/mm/fault.c
4448+++ b/arch/avr32/mm/fault.c
4449@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4450
4451 int exception_trace = 1;
4452
4453+#ifdef CONFIG_PAX_PAGEEXEC
4454+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4455+{
4456+ unsigned long i;
4457+
4458+ printk(KERN_ERR "PAX: bytes at PC: ");
4459+ for (i = 0; i < 20; i++) {
4460+ unsigned char c;
4461+ if (get_user(c, (unsigned char *)pc+i))
4462+ printk(KERN_CONT "???????? ");
4463+ else
4464+ printk(KERN_CONT "%02x ", c);
4465+ }
4466+ printk("\n");
4467+}
4468+#endif
4469+
4470 /*
4471 * This routine handles page faults. It determines the address and the
4472 * problem, and then passes it off to one of the appropriate routines.
4473@@ -174,6 +191,16 @@ bad_area:
4474 up_read(&mm->mmap_sem);
4475
4476 if (user_mode(regs)) {
4477+
4478+#ifdef CONFIG_PAX_PAGEEXEC
4479+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4480+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4481+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4482+ do_group_exit(SIGKILL);
4483+ }
4484+ }
4485+#endif
4486+
4487 if (exception_trace && printk_ratelimit())
4488 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4489 "sp %08lx ecr %lu\n",
4490diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4491index 568885a..f8008df 100644
4492--- a/arch/blackfin/include/asm/cache.h
4493+++ b/arch/blackfin/include/asm/cache.h
4494@@ -7,6 +7,7 @@
4495 #ifndef __ARCH_BLACKFIN_CACHE_H
4496 #define __ARCH_BLACKFIN_CACHE_H
4497
4498+#include <linux/const.h>
4499 #include <linux/linkage.h> /* for asmlinkage */
4500
4501 /*
4502@@ -14,7 +15,7 @@
4503 * Blackfin loads 32 bytes for cache
4504 */
4505 #define L1_CACHE_SHIFT 5
4506-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4507+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4509
4510 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4511diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4512index aea2718..3639a60 100644
4513--- a/arch/cris/include/arch-v10/arch/cache.h
4514+++ b/arch/cris/include/arch-v10/arch/cache.h
4515@@ -1,8 +1,9 @@
4516 #ifndef _ASM_ARCH_CACHE_H
4517 #define _ASM_ARCH_CACHE_H
4518
4519+#include <linux/const.h>
4520 /* Etrax 100LX have 32-byte cache-lines. */
4521-#define L1_CACHE_BYTES 32
4522 #define L1_CACHE_SHIFT 5
4523+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4524
4525 #endif /* _ASM_ARCH_CACHE_H */
4526diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4527index 7caf25d..ee65ac5 100644
4528--- a/arch/cris/include/arch-v32/arch/cache.h
4529+++ b/arch/cris/include/arch-v32/arch/cache.h
4530@@ -1,11 +1,12 @@
4531 #ifndef _ASM_CRIS_ARCH_CACHE_H
4532 #define _ASM_CRIS_ARCH_CACHE_H
4533
4534+#include <linux/const.h>
4535 #include <arch/hwregs/dma.h>
4536
4537 /* A cache-line is 32 bytes. */
4538-#define L1_CACHE_BYTES 32
4539 #define L1_CACHE_SHIFT 5
4540+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4541
4542 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4543
4544diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4545index b86329d..6709906 100644
4546--- a/arch/frv/include/asm/atomic.h
4547+++ b/arch/frv/include/asm/atomic.h
4548@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4549 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4550 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4551
4552+#define atomic64_read_unchecked(v) atomic64_read(v)
4553+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4554+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4555+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4556+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4557+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4558+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4559+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4560+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4561+
4562 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4563 {
4564 int c, old;
4565diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4566index 2797163..c2a401d 100644
4567--- a/arch/frv/include/asm/cache.h
4568+++ b/arch/frv/include/asm/cache.h
4569@@ -12,10 +12,11 @@
4570 #ifndef __ASM_CACHE_H
4571 #define __ASM_CACHE_H
4572
4573+#include <linux/const.h>
4574
4575 /* bytes per L1 cache line */
4576 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4577-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4578+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4579
4580 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4581 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4582diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4583index 43901f2..0d8b865 100644
4584--- a/arch/frv/include/asm/kmap_types.h
4585+++ b/arch/frv/include/asm/kmap_types.h
4586@@ -2,6 +2,6 @@
4587 #ifndef _ASM_KMAP_TYPES_H
4588 #define _ASM_KMAP_TYPES_H
4589
4590-#define KM_TYPE_NR 17
4591+#define KM_TYPE_NR 18
4592
4593 #endif
4594diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4595index 385fd30..3aaf4fe 100644
4596--- a/arch/frv/mm/elf-fdpic.c
4597+++ b/arch/frv/mm/elf-fdpic.c
4598@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4599 {
4600 struct vm_area_struct *vma;
4601 unsigned long limit;
4602+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4603
4604 if (len > TASK_SIZE)
4605 return -ENOMEM;
4606@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4607 if (addr) {
4608 addr = PAGE_ALIGN(addr);
4609 vma = find_vma(current->mm, addr);
4610- if (TASK_SIZE - len >= addr &&
4611- (!vma || addr + len <= vma->vm_start))
4612+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4613 goto success;
4614 }
4615
4616@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4617 for (; vma; vma = vma->vm_next) {
4618 if (addr > limit)
4619 break;
4620- if (addr + len <= vma->vm_start)
4621+ if (check_heap_stack_gap(vma, addr, len, offset))
4622 goto success;
4623 addr = vma->vm_end;
4624 }
4625@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4626 for (; vma; vma = vma->vm_next) {
4627 if (addr > limit)
4628 break;
4629- if (addr + len <= vma->vm_start)
4630+ if (check_heap_stack_gap(vma, addr, len, offset))
4631 goto success;
4632 addr = vma->vm_end;
4633 }
4634diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4635index f4ca594..adc72fd6 100644
4636--- a/arch/hexagon/include/asm/cache.h
4637+++ b/arch/hexagon/include/asm/cache.h
4638@@ -21,9 +21,11 @@
4639 #ifndef __ASM_CACHE_H
4640 #define __ASM_CACHE_H
4641
4642+#include <linux/const.h>
4643+
4644 /* Bytes per L1 cache line */
4645-#define L1_CACHE_SHIFT (5)
4646-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4647+#define L1_CACHE_SHIFT 5
4648+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4649
4650 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4651 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4652diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4653index 6e6fe18..a6ae668 100644
4654--- a/arch/ia64/include/asm/atomic.h
4655+++ b/arch/ia64/include/asm/atomic.h
4656@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4657 #define atomic64_inc(v) atomic64_add(1, (v))
4658 #define atomic64_dec(v) atomic64_sub(1, (v))
4659
4660+#define atomic64_read_unchecked(v) atomic64_read(v)
4661+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4662+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4663+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4664+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4665+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4666+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4667+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4668+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4669+
4670 /* Atomic operations are already serializing */
4671 #define smp_mb__before_atomic_dec() barrier()
4672 #define smp_mb__after_atomic_dec() barrier()
4673diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4674index 988254a..e1ee885 100644
4675--- a/arch/ia64/include/asm/cache.h
4676+++ b/arch/ia64/include/asm/cache.h
4677@@ -1,6 +1,7 @@
4678 #ifndef _ASM_IA64_CACHE_H
4679 #define _ASM_IA64_CACHE_H
4680
4681+#include <linux/const.h>
4682
4683 /*
4684 * Copyright (C) 1998-2000 Hewlett-Packard Co
4685@@ -9,7 +10,7 @@
4686
4687 /* Bytes per L1 (data) cache line. */
4688 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4689-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4690+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4691
4692 #ifdef CONFIG_SMP
4693 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4694diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4695index b5298eb..67c6e62 100644
4696--- a/arch/ia64/include/asm/elf.h
4697+++ b/arch/ia64/include/asm/elf.h
4698@@ -42,6 +42,13 @@
4699 */
4700 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4701
4702+#ifdef CONFIG_PAX_ASLR
4703+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4704+
4705+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4706+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4707+#endif
4708+
4709 #define PT_IA_64_UNWIND 0x70000001
4710
4711 /* IA-64 relocations: */
4712diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4713index 96a8d92..617a1cf 100644
4714--- a/arch/ia64/include/asm/pgalloc.h
4715+++ b/arch/ia64/include/asm/pgalloc.h
4716@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4717 pgd_val(*pgd_entry) = __pa(pud);
4718 }
4719
4720+static inline void
4721+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4722+{
4723+ pgd_populate(mm, pgd_entry, pud);
4724+}
4725+
4726 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4727 {
4728 return quicklist_alloc(0, GFP_KERNEL, NULL);
4729@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4730 pud_val(*pud_entry) = __pa(pmd);
4731 }
4732
4733+static inline void
4734+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4735+{
4736+ pud_populate(mm, pud_entry, pmd);
4737+}
4738+
4739 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4740 {
4741 return quicklist_alloc(0, GFP_KERNEL, NULL);
4742diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4743index 815810c..d60bd4c 100644
4744--- a/arch/ia64/include/asm/pgtable.h
4745+++ b/arch/ia64/include/asm/pgtable.h
4746@@ -12,7 +12,7 @@
4747 * David Mosberger-Tang <davidm@hpl.hp.com>
4748 */
4749
4750-
4751+#include <linux/const.h>
4752 #include <asm/mman.h>
4753 #include <asm/page.h>
4754 #include <asm/processor.h>
4755@@ -142,6 +142,17 @@
4756 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4757 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4758 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4759+
4760+#ifdef CONFIG_PAX_PAGEEXEC
4761+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4762+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4763+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4764+#else
4765+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4766+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4767+# define PAGE_COPY_NOEXEC PAGE_COPY
4768+#endif
4769+
4770 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4771 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4772 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4773diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4774index 54ff557..70c88b7 100644
4775--- a/arch/ia64/include/asm/spinlock.h
4776+++ b/arch/ia64/include/asm/spinlock.h
4777@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4778 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4779
4780 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4781- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4782+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4783 }
4784
4785 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4786diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4787index 449c8c0..50cdf87 100644
4788--- a/arch/ia64/include/asm/uaccess.h
4789+++ b/arch/ia64/include/asm/uaccess.h
4790@@ -42,6 +42,8 @@
4791 #include <asm/pgtable.h>
4792 #include <asm/io.h>
4793
4794+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4795+
4796 /*
4797 * For historical reasons, the following macros are grossly misnamed:
4798 */
4799@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4800 static inline unsigned long
4801 __copy_to_user (void __user *to, const void *from, unsigned long count)
4802 {
4803+ if (count > INT_MAX)
4804+ return count;
4805+
4806+ if (!__builtin_constant_p(count))
4807+ check_object_size(from, count, true);
4808+
4809 return __copy_user(to, (__force void __user *) from, count);
4810 }
4811
4812 static inline unsigned long
4813 __copy_from_user (void *to, const void __user *from, unsigned long count)
4814 {
4815+ if (count > INT_MAX)
4816+ return count;
4817+
4818+ if (!__builtin_constant_p(count))
4819+ check_object_size(to, count, false);
4820+
4821 return __copy_user((__force void __user *) to, from, count);
4822 }
4823
4824@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4825 ({ \
4826 void __user *__cu_to = (to); \
4827 const void *__cu_from = (from); \
4828- long __cu_len = (n); \
4829+ unsigned long __cu_len = (n); \
4830 \
4831- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4832+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4833+ if (!__builtin_constant_p(n)) \
4834+ check_object_size(__cu_from, __cu_len, true); \
4835 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4836+ } \
4837 __cu_len; \
4838 })
4839
4840@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4841 ({ \
4842 void *__cu_to = (to); \
4843 const void __user *__cu_from = (from); \
4844- long __cu_len = (n); \
4845+ unsigned long __cu_len = (n); \
4846 \
4847 __chk_user_ptr(__cu_from); \
4848- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4849+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4850+ if (!__builtin_constant_p(n)) \
4851+ check_object_size(__cu_to, __cu_len, false); \
4852 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4853+ } \
4854 __cu_len; \
4855 })
4856
4857diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4858index 2d67317..07d8bfa 100644
4859--- a/arch/ia64/kernel/err_inject.c
4860+++ b/arch/ia64/kernel/err_inject.c
4861@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4862 return NOTIFY_OK;
4863 }
4864
4865-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4866+static struct notifier_block err_inject_cpu_notifier =
4867 {
4868 .notifier_call = err_inject_cpu_callback,
4869 };
4870diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4871index 65bf9cd..794f06b 100644
4872--- a/arch/ia64/kernel/mca.c
4873+++ b/arch/ia64/kernel/mca.c
4874@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4875 return NOTIFY_OK;
4876 }
4877
4878-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4879+static struct notifier_block mca_cpu_notifier = {
4880 .notifier_call = mca_cpu_callback
4881 };
4882
4883diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4884index 24603be..948052d 100644
4885--- a/arch/ia64/kernel/module.c
4886+++ b/arch/ia64/kernel/module.c
4887@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4888 void
4889 module_free (struct module *mod, void *module_region)
4890 {
4891- if (mod && mod->arch.init_unw_table &&
4892- module_region == mod->module_init) {
4893+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4894 unw_remove_unwind_table(mod->arch.init_unw_table);
4895 mod->arch.init_unw_table = NULL;
4896 }
4897@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4898 }
4899
4900 static inline int
4901+in_init_rx (const struct module *mod, uint64_t addr)
4902+{
4903+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4904+}
4905+
4906+static inline int
4907+in_init_rw (const struct module *mod, uint64_t addr)
4908+{
4909+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4910+}
4911+
4912+static inline int
4913 in_init (const struct module *mod, uint64_t addr)
4914 {
4915- return addr - (uint64_t) mod->module_init < mod->init_size;
4916+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4917+}
4918+
4919+static inline int
4920+in_core_rx (const struct module *mod, uint64_t addr)
4921+{
4922+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4923+}
4924+
4925+static inline int
4926+in_core_rw (const struct module *mod, uint64_t addr)
4927+{
4928+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4929 }
4930
4931 static inline int
4932 in_core (const struct module *mod, uint64_t addr)
4933 {
4934- return addr - (uint64_t) mod->module_core < mod->core_size;
4935+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4936 }
4937
4938 static inline int
4939@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4940 break;
4941
4942 case RV_BDREL:
4943- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4944+ if (in_init_rx(mod, val))
4945+ val -= (uint64_t) mod->module_init_rx;
4946+ else if (in_init_rw(mod, val))
4947+ val -= (uint64_t) mod->module_init_rw;
4948+ else if (in_core_rx(mod, val))
4949+ val -= (uint64_t) mod->module_core_rx;
4950+ else if (in_core_rw(mod, val))
4951+ val -= (uint64_t) mod->module_core_rw;
4952 break;
4953
4954 case RV_LTV:
4955@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4956 * addresses have been selected...
4957 */
4958 uint64_t gp;
4959- if (mod->core_size > MAX_LTOFF)
4960+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4961 /*
4962 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4963 * at the end of the module.
4964 */
4965- gp = mod->core_size - MAX_LTOFF / 2;
4966+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4967 else
4968- gp = mod->core_size / 2;
4969- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4970+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4971+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4972 mod->arch.gp = gp;
4973 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4974 }
4975diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4976index 77597e5..6f28f3f 100644
4977--- a/arch/ia64/kernel/palinfo.c
4978+++ b/arch/ia64/kernel/palinfo.c
4979@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4980 return NOTIFY_OK;
4981 }
4982
4983-static struct notifier_block __refdata palinfo_cpu_notifier =
4984+static struct notifier_block palinfo_cpu_notifier =
4985 {
4986 .notifier_call = palinfo_cpu_callback,
4987 .priority = 0,
4988diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4989index 79802e5..1a89ec5 100644
4990--- a/arch/ia64/kernel/salinfo.c
4991+++ b/arch/ia64/kernel/salinfo.c
4992@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4993 return NOTIFY_OK;
4994 }
4995
4996-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4997+static struct notifier_block salinfo_cpu_notifier =
4998 {
4999 .notifier_call = salinfo_cpu_callback,
5000 .priority = 0,
5001diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5002index d9439ef..d0cac6b 100644
5003--- a/arch/ia64/kernel/sys_ia64.c
5004+++ b/arch/ia64/kernel/sys_ia64.c
5005@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5006 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
5007 struct mm_struct *mm = current->mm;
5008 struct vm_area_struct *vma;
5009+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5010
5011 if (len > RGN_MAP_LIMIT)
5012 return -ENOMEM;
5013@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5014 if (REGION_NUMBER(addr) == RGN_HPAGE)
5015 addr = 0;
5016 #endif
5017+
5018+#ifdef CONFIG_PAX_RANDMMAP
5019+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5020+ addr = mm->free_area_cache;
5021+ else
5022+#endif
5023+
5024 if (!addr)
5025 addr = mm->free_area_cache;
5026
5027@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5028 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
5029 /* At this point: (!vma || addr < vma->vm_end). */
5030 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
5031- if (start_addr != TASK_UNMAPPED_BASE) {
5032+ if (start_addr != mm->mmap_base) {
5033 /* Start a new search --- just in case we missed some holes. */
5034- addr = TASK_UNMAPPED_BASE;
5035+ addr = mm->mmap_base;
5036 goto full_search;
5037 }
5038 return -ENOMEM;
5039 }
5040- if (!vma || addr + len <= vma->vm_start) {
5041+ if (check_heap_stack_gap(vma, addr, len, offset)) {
5042 /* Remember the address where we stopped this search: */
5043 mm->free_area_cache = addr + len;
5044 return addr;
5045diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5046index dc00b2c..cce53c2 100644
5047--- a/arch/ia64/kernel/topology.c
5048+++ b/arch/ia64/kernel/topology.c
5049@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5050 return NOTIFY_OK;
5051 }
5052
5053-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5054+static struct notifier_block cache_cpu_notifier =
5055 {
5056 .notifier_call = cache_cpu_callback
5057 };
5058diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5059index 0ccb28f..8992469 100644
5060--- a/arch/ia64/kernel/vmlinux.lds.S
5061+++ b/arch/ia64/kernel/vmlinux.lds.S
5062@@ -198,7 +198,7 @@ SECTIONS {
5063 /* Per-cpu data: */
5064 . = ALIGN(PERCPU_PAGE_SIZE);
5065 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5066- __phys_per_cpu_start = __per_cpu_load;
5067+ __phys_per_cpu_start = per_cpu_load;
5068 /*
5069 * ensure percpu data fits
5070 * into percpu page size
5071diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5072index 6cf0341..d352594 100644
5073--- a/arch/ia64/mm/fault.c
5074+++ b/arch/ia64/mm/fault.c
5075@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5076 return pte_present(pte);
5077 }
5078
5079+#ifdef CONFIG_PAX_PAGEEXEC
5080+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5081+{
5082+ unsigned long i;
5083+
5084+ printk(KERN_ERR "PAX: bytes at PC: ");
5085+ for (i = 0; i < 8; i++) {
5086+ unsigned int c;
5087+ if (get_user(c, (unsigned int *)pc+i))
5088+ printk(KERN_CONT "???????? ");
5089+ else
5090+ printk(KERN_CONT "%08x ", c);
5091+ }
5092+ printk("\n");
5093+}
5094+#endif
5095+
5096 # define VM_READ_BIT 0
5097 # define VM_WRITE_BIT 1
5098 # define VM_EXEC_BIT 2
5099@@ -149,8 +166,21 @@ retry:
5100 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5101 goto bad_area;
5102
5103- if ((vma->vm_flags & mask) != mask)
5104+ if ((vma->vm_flags & mask) != mask) {
5105+
5106+#ifdef CONFIG_PAX_PAGEEXEC
5107+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5108+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5109+ goto bad_area;
5110+
5111+ up_read(&mm->mmap_sem);
5112+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5113+ do_group_exit(SIGKILL);
5114+ }
5115+#endif
5116+
5117 goto bad_area;
5118+ }
5119
5120 /*
5121 * If for any reason at all we couldn't handle the fault, make
5122diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5123index 5ca674b..127c3cb 100644
5124--- a/arch/ia64/mm/hugetlbpage.c
5125+++ b/arch/ia64/mm/hugetlbpage.c
5126@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5127 unsigned long pgoff, unsigned long flags)
5128 {
5129 struct vm_area_struct *vmm;
5130+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5131
5132 if (len > RGN_MAP_LIMIT)
5133 return -ENOMEM;
5134@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5135 /* At this point: (!vmm || addr < vmm->vm_end). */
5136 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
5137 return -ENOMEM;
5138- if (!vmm || (addr + len) <= vmm->vm_start)
5139+ if (check_heap_stack_gap(vmm, addr, len, offset))
5140 return addr;
5141 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
5142 }
5143diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5144index b755ea9..b9a969e 100644
5145--- a/arch/ia64/mm/init.c
5146+++ b/arch/ia64/mm/init.c
5147@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5148 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5149 vma->vm_end = vma->vm_start + PAGE_SIZE;
5150 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5151+
5152+#ifdef CONFIG_PAX_PAGEEXEC
5153+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5154+ vma->vm_flags &= ~VM_EXEC;
5155+
5156+#ifdef CONFIG_PAX_MPROTECT
5157+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5158+ vma->vm_flags &= ~VM_MAYEXEC;
5159+#endif
5160+
5161+ }
5162+#endif
5163+
5164 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5165 down_write(&current->mm->mmap_sem);
5166 if (insert_vm_struct(current->mm, vma)) {
5167diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5168index 40b3ee9..8c2c112 100644
5169--- a/arch/m32r/include/asm/cache.h
5170+++ b/arch/m32r/include/asm/cache.h
5171@@ -1,8 +1,10 @@
5172 #ifndef _ASM_M32R_CACHE_H
5173 #define _ASM_M32R_CACHE_H
5174
5175+#include <linux/const.h>
5176+
5177 /* L1 cache line size */
5178 #define L1_CACHE_SHIFT 4
5179-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5180+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5181
5182 #endif /* _ASM_M32R_CACHE_H */
5183diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5184index 82abd15..d95ae5d 100644
5185--- a/arch/m32r/lib/usercopy.c
5186+++ b/arch/m32r/lib/usercopy.c
5187@@ -14,6 +14,9 @@
5188 unsigned long
5189 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5190 {
5191+ if ((long)n < 0)
5192+ return n;
5193+
5194 prefetch(from);
5195 if (access_ok(VERIFY_WRITE, to, n))
5196 __copy_user(to,from,n);
5197@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5198 unsigned long
5199 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5200 {
5201+ if ((long)n < 0)
5202+ return n;
5203+
5204 prefetchw(to);
5205 if (access_ok(VERIFY_READ, from, n))
5206 __copy_user_zeroing(to,from,n);
5207diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5208index 0395c51..5f26031 100644
5209--- a/arch/m68k/include/asm/cache.h
5210+++ b/arch/m68k/include/asm/cache.h
5211@@ -4,9 +4,11 @@
5212 #ifndef __ARCH_M68K_CACHE_H
5213 #define __ARCH_M68K_CACHE_H
5214
5215+#include <linux/const.h>
5216+
5217 /* bytes per L1 cache line */
5218 #define L1_CACHE_SHIFT 4
5219-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5220+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5221
5222 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5223
5224diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5225index 4efe96a..60e8699 100644
5226--- a/arch/microblaze/include/asm/cache.h
5227+++ b/arch/microblaze/include/asm/cache.h
5228@@ -13,11 +13,12 @@
5229 #ifndef _ASM_MICROBLAZE_CACHE_H
5230 #define _ASM_MICROBLAZE_CACHE_H
5231
5232+#include <linux/const.h>
5233 #include <asm/registers.h>
5234
5235 #define L1_CACHE_SHIFT 5
5236 /* word-granular cache in microblaze */
5237-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5238+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5239
5240 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5241
5242diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5243index 01cc6ba..bcb7a5d 100644
5244--- a/arch/mips/include/asm/atomic.h
5245+++ b/arch/mips/include/asm/atomic.h
5246@@ -21,6 +21,10 @@
5247 #include <asm/cmpxchg.h>
5248 #include <asm/war.h>
5249
5250+#ifdef CONFIG_GENERIC_ATOMIC64
5251+#include <asm-generic/atomic64.h>
5252+#endif
5253+
5254 #define ATOMIC_INIT(i) { (i) }
5255
5256 /*
5257@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5258 */
5259 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5260
5261+#define atomic64_read_unchecked(v) atomic64_read(v)
5262+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5263+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5264+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5265+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5266+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5267+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5268+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5269+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5270+
5271 #endif /* CONFIG_64BIT */
5272
5273 /*
5274diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5275index b4db69f..8f3b093 100644
5276--- a/arch/mips/include/asm/cache.h
5277+++ b/arch/mips/include/asm/cache.h
5278@@ -9,10 +9,11 @@
5279 #ifndef _ASM_CACHE_H
5280 #define _ASM_CACHE_H
5281
5282+#include <linux/const.h>
5283 #include <kmalloc.h>
5284
5285 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5286-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5287+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5288
5289 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5290 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5291diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5292index 455c0ac..ad65fbe 100644
5293--- a/arch/mips/include/asm/elf.h
5294+++ b/arch/mips/include/asm/elf.h
5295@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5296 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5297 #endif
5298
5299+#ifdef CONFIG_PAX_ASLR
5300+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5301+
5302+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5303+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5304+#endif
5305+
5306 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5307 struct linux_binprm;
5308 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5309 int uses_interp);
5310
5311-struct mm_struct;
5312-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5313-#define arch_randomize_brk arch_randomize_brk
5314-
5315 #endif /* _ASM_ELF_H */
5316diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5317index c1f6afa..38cc6e9 100644
5318--- a/arch/mips/include/asm/exec.h
5319+++ b/arch/mips/include/asm/exec.h
5320@@ -12,6 +12,6 @@
5321 #ifndef _ASM_EXEC_H
5322 #define _ASM_EXEC_H
5323
5324-extern unsigned long arch_align_stack(unsigned long sp);
5325+#define arch_align_stack(x) ((x) & ~0xfUL)
5326
5327 #endif /* _ASM_EXEC_H */
5328diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5329index dbaec94..6a14935 100644
5330--- a/arch/mips/include/asm/page.h
5331+++ b/arch/mips/include/asm/page.h
5332@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5333 #ifdef CONFIG_CPU_MIPS32
5334 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5335 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5336- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5337+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5338 #else
5339 typedef struct { unsigned long long pte; } pte_t;
5340 #define pte_val(x) ((x).pte)
5341diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5342index 881d18b..cea38bc 100644
5343--- a/arch/mips/include/asm/pgalloc.h
5344+++ b/arch/mips/include/asm/pgalloc.h
5345@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5346 {
5347 set_pud(pud, __pud((unsigned long)pmd));
5348 }
5349+
5350+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5351+{
5352+ pud_populate(mm, pud, pmd);
5353+}
5354 #endif
5355
5356 /*
5357diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5358index b2050b9..d71bb1b 100644
5359--- a/arch/mips/include/asm/thread_info.h
5360+++ b/arch/mips/include/asm/thread_info.h
5361@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5362 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5363 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5364 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5365+/* li takes a 32bit immediate */
5366+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5367 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5368
5369 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5370@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5371 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5372 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5373 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5374+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5375+
5376+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5377
5378 /* work to do in syscall_trace_leave() */
5379-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5380+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5381
5382 /* work to do on interrupt/exception return */
5383 #define _TIF_WORK_MASK \
5384 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5385 /* work to do on any return to u-space */
5386-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5387+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5388
5389 #endif /* __KERNEL__ */
5390
5391diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5392index 9fdd8bc..4bd7f1a 100644
5393--- a/arch/mips/kernel/binfmt_elfn32.c
5394+++ b/arch/mips/kernel/binfmt_elfn32.c
5395@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5396 #undef ELF_ET_DYN_BASE
5397 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5398
5399+#ifdef CONFIG_PAX_ASLR
5400+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5401+
5402+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5403+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5404+#endif
5405+
5406 #include <asm/processor.h>
5407 #include <linux/module.h>
5408 #include <linux/elfcore.h>
5409diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5410index ff44823..97f8906 100644
5411--- a/arch/mips/kernel/binfmt_elfo32.c
5412+++ b/arch/mips/kernel/binfmt_elfo32.c
5413@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5414 #undef ELF_ET_DYN_BASE
5415 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5416
5417+#ifdef CONFIG_PAX_ASLR
5418+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5419+
5420+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5421+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5422+#endif
5423+
5424 #include <asm/processor.h>
5425
5426 /*
5427diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5428index a11c6f9..be5e164 100644
5429--- a/arch/mips/kernel/process.c
5430+++ b/arch/mips/kernel/process.c
5431@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5432 out:
5433 return pc;
5434 }
5435-
5436-/*
5437- * Don't forget that the stack pointer must be aligned on a 8 bytes
5438- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5439- */
5440-unsigned long arch_align_stack(unsigned long sp)
5441-{
5442- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5443- sp -= get_random_int() & ~PAGE_MASK;
5444-
5445- return sp & ALMASK;
5446-}
5447diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5448index 4812c6d..2069554 100644
5449--- a/arch/mips/kernel/ptrace.c
5450+++ b/arch/mips/kernel/ptrace.c
5451@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5452 return arch;
5453 }
5454
5455+#ifdef CONFIG_GRKERNSEC_SETXID
5456+extern void gr_delayed_cred_worker(void);
5457+#endif
5458+
5459 /*
5460 * Notification of system call entry/exit
5461 * - triggered by current->work.syscall_trace
5462@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5463 /* do the secure computing check first */
5464 secure_computing_strict(regs->regs[2]);
5465
5466+#ifdef CONFIG_GRKERNSEC_SETXID
5467+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5468+ gr_delayed_cred_worker();
5469+#endif
5470+
5471 if (!(current->ptrace & PT_PTRACED))
5472 goto out;
5473
5474diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5475index d20a4bc..7096ae5 100644
5476--- a/arch/mips/kernel/scall32-o32.S
5477+++ b/arch/mips/kernel/scall32-o32.S
5478@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5479
5480 stack_done:
5481 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5482- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5483+ li t1, _TIF_SYSCALL_WORK
5484 and t0, t1
5485 bnez t0, syscall_trace_entry # -> yes
5486
5487diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5488index b64f642..0fe6eab 100644
5489--- a/arch/mips/kernel/scall64-64.S
5490+++ b/arch/mips/kernel/scall64-64.S
5491@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5492
5493 sd a3, PT_R26(sp) # save a3 for syscall restarting
5494
5495- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5496+ li t1, _TIF_SYSCALL_WORK
5497 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5498 and t0, t1, t0
5499 bnez t0, syscall_trace_entry
5500diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5501index c29ac19..c592d05 100644
5502--- a/arch/mips/kernel/scall64-n32.S
5503+++ b/arch/mips/kernel/scall64-n32.S
5504@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5505
5506 sd a3, PT_R26(sp) # save a3 for syscall restarting
5507
5508- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5509+ li t1, _TIF_SYSCALL_WORK
5510 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5511 and t0, t1, t0
5512 bnez t0, n32_syscall_trace_entry
5513diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5514index cf3e75e..72e93fe 100644
5515--- a/arch/mips/kernel/scall64-o32.S
5516+++ b/arch/mips/kernel/scall64-o32.S
5517@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5518 PTR 4b, bad_stack
5519 .previous
5520
5521- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5522+ li t1, _TIF_SYSCALL_WORK
5523 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5524 and t0, t1, t0
5525 bnez t0, trace_a_syscall
5526diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5527index ddcec1e..c7f983e 100644
5528--- a/arch/mips/mm/fault.c
5529+++ b/arch/mips/mm/fault.c
5530@@ -27,6 +27,23 @@
5531 #include <asm/highmem.h> /* For VMALLOC_END */
5532 #include <linux/kdebug.h>
5533
5534+#ifdef CONFIG_PAX_PAGEEXEC
5535+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5536+{
5537+ unsigned long i;
5538+
5539+ printk(KERN_ERR "PAX: bytes at PC: ");
5540+ for (i = 0; i < 5; i++) {
5541+ unsigned int c;
5542+ if (get_user(c, (unsigned int *)pc+i))
5543+ printk(KERN_CONT "???????? ");
5544+ else
5545+ printk(KERN_CONT "%08x ", c);
5546+ }
5547+ printk("\n");
5548+}
5549+#endif
5550+
5551 /*
5552 * This routine handles page faults. It determines the address,
5553 * and the problem, and then passes it off to one of the appropriate
5554diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5555index 7e5fe27..479a219 100644
5556--- a/arch/mips/mm/mmap.c
5557+++ b/arch/mips/mm/mmap.c
5558@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5559 struct vm_area_struct *vma;
5560 unsigned long addr = addr0;
5561 int do_color_align;
5562+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5563 struct vm_unmapped_area_info info;
5564
5565 if (unlikely(len > TASK_SIZE))
5566@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5567 do_color_align = 1;
5568
5569 /* requesting a specific address */
5570+
5571+#ifdef CONFIG_PAX_RANDMMAP
5572+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5573+#endif
5574+
5575 if (addr) {
5576 if (do_color_align)
5577 addr = COLOUR_ALIGN(addr, pgoff);
5578@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5579 addr = PAGE_ALIGN(addr);
5580
5581 vma = find_vma(mm, addr);
5582- if (TASK_SIZE - len >= addr &&
5583- (!vma || addr + len <= vma->vm_start))
5584+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5585 return addr;
5586 }
5587
5588@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5589 {
5590 unsigned long random_factor = 0UL;
5591
5592+#ifdef CONFIG_PAX_RANDMMAP
5593+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5594+#endif
5595+
5596 if (current->flags & PF_RANDOMIZE) {
5597 random_factor = get_random_int();
5598 random_factor = random_factor << PAGE_SHIFT;
5599@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5600
5601 if (mmap_is_legacy()) {
5602 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5603+
5604+#ifdef CONFIG_PAX_RANDMMAP
5605+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5606+ mm->mmap_base += mm->delta_mmap;
5607+#endif
5608+
5609 mm->get_unmapped_area = arch_get_unmapped_area;
5610 mm->unmap_area = arch_unmap_area;
5611 } else {
5612 mm->mmap_base = mmap_base(random_factor);
5613+
5614+#ifdef CONFIG_PAX_RANDMMAP
5615+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5616+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5617+#endif
5618+
5619 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5620 mm->unmap_area = arch_unmap_area_topdown;
5621 }
5622 }
5623
5624-static inline unsigned long brk_rnd(void)
5625-{
5626- unsigned long rnd = get_random_int();
5627-
5628- rnd = rnd << PAGE_SHIFT;
5629- /* 8MB for 32bit, 256MB for 64bit */
5630- if (TASK_IS_32BIT_ADDR)
5631- rnd = rnd & 0x7ffffful;
5632- else
5633- rnd = rnd & 0xffffffful;
5634-
5635- return rnd;
5636-}
5637-
5638-unsigned long arch_randomize_brk(struct mm_struct *mm)
5639-{
5640- unsigned long base = mm->brk;
5641- unsigned long ret;
5642-
5643- ret = PAGE_ALIGN(base + brk_rnd());
5644-
5645- if (ret < mm->brk)
5646- return mm->brk;
5647-
5648- return ret;
5649-}
5650-
5651 int __virt_addr_valid(const volatile void *kaddr)
5652 {
5653 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5654diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5655index 967d144..db12197 100644
5656--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5657+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5658@@ -11,12 +11,14 @@
5659 #ifndef _ASM_PROC_CACHE_H
5660 #define _ASM_PROC_CACHE_H
5661
5662+#include <linux/const.h>
5663+
5664 /* L1 cache */
5665
5666 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5667 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5668-#define L1_CACHE_BYTES 16 /* bytes per entry */
5669 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5670+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5671 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5672
5673 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5674diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5675index bcb5df2..84fabd2 100644
5676--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5677+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5678@@ -16,13 +16,15 @@
5679 #ifndef _ASM_PROC_CACHE_H
5680 #define _ASM_PROC_CACHE_H
5681
5682+#include <linux/const.h>
5683+
5684 /*
5685 * L1 cache
5686 */
5687 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5688 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5689-#define L1_CACHE_BYTES 32 /* bytes per entry */
5690 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5691+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5692 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5693
5694 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5695diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5696index 4ce7a01..449202a 100644
5697--- a/arch/openrisc/include/asm/cache.h
5698+++ b/arch/openrisc/include/asm/cache.h
5699@@ -19,11 +19,13 @@
5700 #ifndef __ASM_OPENRISC_CACHE_H
5701 #define __ASM_OPENRISC_CACHE_H
5702
5703+#include <linux/const.h>
5704+
5705 /* FIXME: How can we replace these with values from the CPU...
5706 * they shouldn't be hard-coded!
5707 */
5708
5709-#define L1_CACHE_BYTES 16
5710 #define L1_CACHE_SHIFT 4
5711+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5712
5713 #endif /* __ASM_OPENRISC_CACHE_H */
5714diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5715index af9cf30..2aae9b2 100644
5716--- a/arch/parisc/include/asm/atomic.h
5717+++ b/arch/parisc/include/asm/atomic.h
5718@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5719
5720 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5721
5722+#define atomic64_read_unchecked(v) atomic64_read(v)
5723+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5724+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5725+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5726+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5727+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5728+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5729+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5730+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5731+
5732 #endif /* !CONFIG_64BIT */
5733
5734
5735diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5736index 47f11c7..3420df2 100644
5737--- a/arch/parisc/include/asm/cache.h
5738+++ b/arch/parisc/include/asm/cache.h
5739@@ -5,6 +5,7 @@
5740 #ifndef __ARCH_PARISC_CACHE_H
5741 #define __ARCH_PARISC_CACHE_H
5742
5743+#include <linux/const.h>
5744
5745 /*
5746 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5747@@ -15,13 +16,13 @@
5748 * just ruin performance.
5749 */
5750 #ifdef CONFIG_PA20
5751-#define L1_CACHE_BYTES 64
5752 #define L1_CACHE_SHIFT 6
5753 #else
5754-#define L1_CACHE_BYTES 32
5755 #define L1_CACHE_SHIFT 5
5756 #endif
5757
5758+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5759+
5760 #ifndef __ASSEMBLY__
5761
5762 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5763diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5764index 19f6cb1..6c78cf2 100644
5765--- a/arch/parisc/include/asm/elf.h
5766+++ b/arch/parisc/include/asm/elf.h
5767@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5768
5769 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5770
5771+#ifdef CONFIG_PAX_ASLR
5772+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5773+
5774+#define PAX_DELTA_MMAP_LEN 16
5775+#define PAX_DELTA_STACK_LEN 16
5776+#endif
5777+
5778 /* This yields a mask that user programs can use to figure out what
5779 instruction set this CPU supports. This could be done in user space,
5780 but it's not easy, and we've already done it here. */
5781diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5782index fc987a1..6e068ef 100644
5783--- a/arch/parisc/include/asm/pgalloc.h
5784+++ b/arch/parisc/include/asm/pgalloc.h
5785@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5786 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5787 }
5788
5789+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5790+{
5791+ pgd_populate(mm, pgd, pmd);
5792+}
5793+
5794 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5795 {
5796 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5797@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5798 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5799 #define pmd_free(mm, x) do { } while (0)
5800 #define pgd_populate(mm, pmd, pte) BUG()
5801+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5802
5803 #endif
5804
5805diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5806index 7df49fa..38b62bf 100644
5807--- a/arch/parisc/include/asm/pgtable.h
5808+++ b/arch/parisc/include/asm/pgtable.h
5809@@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5810 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5811 #define PAGE_COPY PAGE_EXECREAD
5812 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5813+
5814+#ifdef CONFIG_PAX_PAGEEXEC
5815+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5816+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5817+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5818+#else
5819+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5820+# define PAGE_COPY_NOEXEC PAGE_COPY
5821+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5822+#endif
5823+
5824 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5825 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5826 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5827diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5828index 4ba2c93..f5e3974 100644
5829--- a/arch/parisc/include/asm/uaccess.h
5830+++ b/arch/parisc/include/asm/uaccess.h
5831@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5832 const void __user *from,
5833 unsigned long n)
5834 {
5835- int sz = __compiletime_object_size(to);
5836+ size_t sz = __compiletime_object_size(to);
5837 int ret = -EFAULT;
5838
5839- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5840+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5841 ret = __copy_from_user(to, from, n);
5842 else
5843 copy_from_user_overflow();
5844diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5845index 2a625fb..9908930 100644
5846--- a/arch/parisc/kernel/module.c
5847+++ b/arch/parisc/kernel/module.c
5848@@ -98,16 +98,38 @@
5849
5850 /* three functions to determine where in the module core
5851 * or init pieces the location is */
5852+static inline int in_init_rx(struct module *me, void *loc)
5853+{
5854+ return (loc >= me->module_init_rx &&
5855+ loc < (me->module_init_rx + me->init_size_rx));
5856+}
5857+
5858+static inline int in_init_rw(struct module *me, void *loc)
5859+{
5860+ return (loc >= me->module_init_rw &&
5861+ loc < (me->module_init_rw + me->init_size_rw));
5862+}
5863+
5864 static inline int in_init(struct module *me, void *loc)
5865 {
5866- return (loc >= me->module_init &&
5867- loc <= (me->module_init + me->init_size));
5868+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5869+}
5870+
5871+static inline int in_core_rx(struct module *me, void *loc)
5872+{
5873+ return (loc >= me->module_core_rx &&
5874+ loc < (me->module_core_rx + me->core_size_rx));
5875+}
5876+
5877+static inline int in_core_rw(struct module *me, void *loc)
5878+{
5879+ return (loc >= me->module_core_rw &&
5880+ loc < (me->module_core_rw + me->core_size_rw));
5881 }
5882
5883 static inline int in_core(struct module *me, void *loc)
5884 {
5885- return (loc >= me->module_core &&
5886- loc <= (me->module_core + me->core_size));
5887+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5888 }
5889
5890 static inline int in_local(struct module *me, void *loc)
5891@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5892 }
5893
5894 /* align things a bit */
5895- me->core_size = ALIGN(me->core_size, 16);
5896- me->arch.got_offset = me->core_size;
5897- me->core_size += gots * sizeof(struct got_entry);
5898+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5899+ me->arch.got_offset = me->core_size_rw;
5900+ me->core_size_rw += gots * sizeof(struct got_entry);
5901
5902- me->core_size = ALIGN(me->core_size, 16);
5903- me->arch.fdesc_offset = me->core_size;
5904- me->core_size += fdescs * sizeof(Elf_Fdesc);
5905+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5906+ me->arch.fdesc_offset = me->core_size_rw;
5907+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5908
5909 me->arch.got_max = gots;
5910 me->arch.fdesc_max = fdescs;
5911@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5912
5913 BUG_ON(value == 0);
5914
5915- got = me->module_core + me->arch.got_offset;
5916+ got = me->module_core_rw + me->arch.got_offset;
5917 for (i = 0; got[i].addr; i++)
5918 if (got[i].addr == value)
5919 goto out;
5920@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5921 #ifdef CONFIG_64BIT
5922 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5923 {
5924- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5925+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5926
5927 if (!value) {
5928 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5929@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5930
5931 /* Create new one */
5932 fdesc->addr = value;
5933- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5934+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5935 return (Elf_Addr)fdesc;
5936 }
5937 #endif /* CONFIG_64BIT */
5938@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5939
5940 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5941 end = table + sechdrs[me->arch.unwind_section].sh_size;
5942- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5943+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5944
5945 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5946 me->arch.unwind_section, table, end, gp);
5947diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5948index f76c108..92bad82 100644
5949--- a/arch/parisc/kernel/sys_parisc.c
5950+++ b/arch/parisc/kernel/sys_parisc.c
5951@@ -33,9 +33,11 @@
5952 #include <linux/utsname.h>
5953 #include <linux/personality.h>
5954
5955-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5956+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5957+ unsigned long flags)
5958 {
5959 struct vm_area_struct *vma;
5960+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5961
5962 addr = PAGE_ALIGN(addr);
5963
5964@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5965 /* At this point: (!vma || addr < vma->vm_end). */
5966 if (TASK_SIZE - len < addr)
5967 return -ENOMEM;
5968- if (!vma || addr + len <= vma->vm_start)
5969+ if (check_heap_stack_gap(vma, addr, len, offset))
5970 return addr;
5971 addr = vma->vm_end;
5972 }
5973@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5974 return offset & 0x3FF000;
5975 }
5976
5977-static unsigned long get_shared_area(struct address_space *mapping,
5978- unsigned long addr, unsigned long len, unsigned long pgoff)
5979+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5980+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5981 {
5982 struct vm_area_struct *vma;
5983 int offset = mapping ? get_offset(mapping) : 0;
5984+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5985
5986 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5987
5988@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5989 /* At this point: (!vma || addr < vma->vm_end). */
5990 if (TASK_SIZE - len < addr)
5991 return -ENOMEM;
5992- if (!vma || addr + len <= vma->vm_start)
5993+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
5994 return addr;
5995 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5996 if (addr < vma->vm_end) /* handle wraparound */
5997@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5998 if (flags & MAP_FIXED)
5999 return addr;
6000 if (!addr)
6001- addr = TASK_UNMAPPED_BASE;
6002+ addr = current->mm->mmap_base;
6003
6004 if (filp) {
6005- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6006+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6007 } else if(flags & MAP_SHARED) {
6008- addr = get_shared_area(NULL, addr, len, pgoff);
6009+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6010 } else {
6011- addr = get_unshared_area(addr, len);
6012+ addr = get_unshared_area(filp, addr, len, flags);
6013 }
6014 return addr;
6015 }
6016diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6017index 45ba99f..8e22c33 100644
6018--- a/arch/parisc/kernel/traps.c
6019+++ b/arch/parisc/kernel/traps.c
6020@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6021
6022 down_read(&current->mm->mmap_sem);
6023 vma = find_vma(current->mm,regs->iaoq[0]);
6024- if (vma && (regs->iaoq[0] >= vma->vm_start)
6025- && (vma->vm_flags & VM_EXEC)) {
6026-
6027+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6028 fault_address = regs->iaoq[0];
6029 fault_space = regs->iasq[0];
6030
6031diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6032index 18162ce..94de376 100644
6033--- a/arch/parisc/mm/fault.c
6034+++ b/arch/parisc/mm/fault.c
6035@@ -15,6 +15,7 @@
6036 #include <linux/sched.h>
6037 #include <linux/interrupt.h>
6038 #include <linux/module.h>
6039+#include <linux/unistd.h>
6040
6041 #include <asm/uaccess.h>
6042 #include <asm/traps.h>
6043@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6044 static unsigned long
6045 parisc_acctyp(unsigned long code, unsigned int inst)
6046 {
6047- if (code == 6 || code == 16)
6048+ if (code == 6 || code == 7 || code == 16)
6049 return VM_EXEC;
6050
6051 switch (inst & 0xf0000000) {
6052@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6053 }
6054 #endif
6055
6056+#ifdef CONFIG_PAX_PAGEEXEC
6057+/*
6058+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6059+ *
6060+ * returns 1 when task should be killed
6061+ * 2 when rt_sigreturn trampoline was detected
6062+ * 3 when unpatched PLT trampoline was detected
6063+ */
6064+static int pax_handle_fetch_fault(struct pt_regs *regs)
6065+{
6066+
6067+#ifdef CONFIG_PAX_EMUPLT
6068+ int err;
6069+
6070+ do { /* PaX: unpatched PLT emulation */
6071+ unsigned int bl, depwi;
6072+
6073+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6074+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6075+
6076+ if (err)
6077+ break;
6078+
6079+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6080+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6081+
6082+ err = get_user(ldw, (unsigned int *)addr);
6083+ err |= get_user(bv, (unsigned int *)(addr+4));
6084+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6085+
6086+ if (err)
6087+ break;
6088+
6089+ if (ldw == 0x0E801096U &&
6090+ bv == 0xEAC0C000U &&
6091+ ldw2 == 0x0E881095U)
6092+ {
6093+ unsigned int resolver, map;
6094+
6095+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6096+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6097+ if (err)
6098+ break;
6099+
6100+ regs->gr[20] = instruction_pointer(regs)+8;
6101+ regs->gr[21] = map;
6102+ regs->gr[22] = resolver;
6103+ regs->iaoq[0] = resolver | 3UL;
6104+ regs->iaoq[1] = regs->iaoq[0] + 4;
6105+ return 3;
6106+ }
6107+ }
6108+ } while (0);
6109+#endif
6110+
6111+#ifdef CONFIG_PAX_EMUTRAMP
6112+
6113+#ifndef CONFIG_PAX_EMUSIGRT
6114+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6115+ return 1;
6116+#endif
6117+
6118+ do { /* PaX: rt_sigreturn emulation */
6119+ unsigned int ldi1, ldi2, bel, nop;
6120+
6121+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6122+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6123+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6124+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6125+
6126+ if (err)
6127+ break;
6128+
6129+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6130+ ldi2 == 0x3414015AU &&
6131+ bel == 0xE4008200U &&
6132+ nop == 0x08000240U)
6133+ {
6134+ regs->gr[25] = (ldi1 & 2) >> 1;
6135+ regs->gr[20] = __NR_rt_sigreturn;
6136+ regs->gr[31] = regs->iaoq[1] + 16;
6137+ regs->sr[0] = regs->iasq[1];
6138+ regs->iaoq[0] = 0x100UL;
6139+ regs->iaoq[1] = regs->iaoq[0] + 4;
6140+ regs->iasq[0] = regs->sr[2];
6141+ regs->iasq[1] = regs->sr[2];
6142+ return 2;
6143+ }
6144+ } while (0);
6145+#endif
6146+
6147+ return 1;
6148+}
6149+
6150+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6151+{
6152+ unsigned long i;
6153+
6154+ printk(KERN_ERR "PAX: bytes at PC: ");
6155+ for (i = 0; i < 5; i++) {
6156+ unsigned int c;
6157+ if (get_user(c, (unsigned int *)pc+i))
6158+ printk(KERN_CONT "???????? ");
6159+ else
6160+ printk(KERN_CONT "%08x ", c);
6161+ }
6162+ printk("\n");
6163+}
6164+#endif
6165+
6166 int fixup_exception(struct pt_regs *regs)
6167 {
6168 const struct exception_table_entry *fix;
6169@@ -192,8 +303,33 @@ good_area:
6170
6171 acc_type = parisc_acctyp(code,regs->iir);
6172
6173- if ((vma->vm_flags & acc_type) != acc_type)
6174+ if ((vma->vm_flags & acc_type) != acc_type) {
6175+
6176+#ifdef CONFIG_PAX_PAGEEXEC
6177+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6178+ (address & ~3UL) == instruction_pointer(regs))
6179+ {
6180+ up_read(&mm->mmap_sem);
6181+ switch (pax_handle_fetch_fault(regs)) {
6182+
6183+#ifdef CONFIG_PAX_EMUPLT
6184+ case 3:
6185+ return;
6186+#endif
6187+
6188+#ifdef CONFIG_PAX_EMUTRAMP
6189+ case 2:
6190+ return;
6191+#endif
6192+
6193+ }
6194+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6195+ do_group_exit(SIGKILL);
6196+ }
6197+#endif
6198+
6199 goto bad_area;
6200+ }
6201
6202 /*
6203 * If for any reason at all we couldn't handle the fault, make
6204diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6205index e3b1d41..8e81edf 100644
6206--- a/arch/powerpc/include/asm/atomic.h
6207+++ b/arch/powerpc/include/asm/atomic.h
6208@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6209 return t1;
6210 }
6211
6212+#define atomic64_read_unchecked(v) atomic64_read(v)
6213+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6214+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6215+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6216+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6217+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6218+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6219+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6220+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6221+
6222 #endif /* __powerpc64__ */
6223
6224 #endif /* __KERNEL__ */
6225diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6226index 9e495c9..b6878e5 100644
6227--- a/arch/powerpc/include/asm/cache.h
6228+++ b/arch/powerpc/include/asm/cache.h
6229@@ -3,6 +3,7 @@
6230
6231 #ifdef __KERNEL__
6232
6233+#include <linux/const.h>
6234
6235 /* bytes per L1 cache line */
6236 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6237@@ -22,7 +23,7 @@
6238 #define L1_CACHE_SHIFT 7
6239 #endif
6240
6241-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6242+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6243
6244 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6245
6246diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6247index 6abf0a1..459d0f1 100644
6248--- a/arch/powerpc/include/asm/elf.h
6249+++ b/arch/powerpc/include/asm/elf.h
6250@@ -28,8 +28,19 @@
6251 the loader. We need to make sure that it is out of the way of the program
6252 that it will "exec", and that there is sufficient room for the brk. */
6253
6254-extern unsigned long randomize_et_dyn(unsigned long base);
6255-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6256+#define ELF_ET_DYN_BASE (0x20000000)
6257+
6258+#ifdef CONFIG_PAX_ASLR
6259+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6260+
6261+#ifdef __powerpc64__
6262+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6263+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6264+#else
6265+#define PAX_DELTA_MMAP_LEN 15
6266+#define PAX_DELTA_STACK_LEN 15
6267+#endif
6268+#endif
6269
6270 /*
6271 * Our registers are always unsigned longs, whether we're a 32 bit
6272@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6273 (0x7ff >> (PAGE_SHIFT - 12)) : \
6274 (0x3ffff >> (PAGE_SHIFT - 12)))
6275
6276-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6277-#define arch_randomize_brk arch_randomize_brk
6278-
6279-
6280 #ifdef CONFIG_SPU_BASE
6281 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6282 #define NT_SPU 1
6283diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6284index 8196e9c..d83a9f3 100644
6285--- a/arch/powerpc/include/asm/exec.h
6286+++ b/arch/powerpc/include/asm/exec.h
6287@@ -4,6 +4,6 @@
6288 #ifndef _ASM_POWERPC_EXEC_H
6289 #define _ASM_POWERPC_EXEC_H
6290
6291-extern unsigned long arch_align_stack(unsigned long sp);
6292+#define arch_align_stack(x) ((x) & ~0xfUL)
6293
6294 #endif /* _ASM_POWERPC_EXEC_H */
6295diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6296index 5acabbd..7ea14fa 100644
6297--- a/arch/powerpc/include/asm/kmap_types.h
6298+++ b/arch/powerpc/include/asm/kmap_types.h
6299@@ -10,7 +10,7 @@
6300 * 2 of the License, or (at your option) any later version.
6301 */
6302
6303-#define KM_TYPE_NR 16
6304+#define KM_TYPE_NR 17
6305
6306 #endif /* __KERNEL__ */
6307 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6308diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6309index 8565c25..2865190 100644
6310--- a/arch/powerpc/include/asm/mman.h
6311+++ b/arch/powerpc/include/asm/mman.h
6312@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6313 }
6314 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6315
6316-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6317+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6318 {
6319 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6320 }
6321diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6322index f072e97..b436dee 100644
6323--- a/arch/powerpc/include/asm/page.h
6324+++ b/arch/powerpc/include/asm/page.h
6325@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6326 * and needs to be executable. This means the whole heap ends
6327 * up being executable.
6328 */
6329-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6330- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6331+#define VM_DATA_DEFAULT_FLAGS32 \
6332+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6333+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6334
6335 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6336 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6337@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6338 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6339 #endif
6340
6341+#define ktla_ktva(addr) (addr)
6342+#define ktva_ktla(addr) (addr)
6343+
6344 /*
6345 * Use the top bit of the higher-level page table entries to indicate whether
6346 * the entries we point to contain hugepages. This works because we know that
6347diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6348index cd915d6..c10cee8 100644
6349--- a/arch/powerpc/include/asm/page_64.h
6350+++ b/arch/powerpc/include/asm/page_64.h
6351@@ -154,15 +154,18 @@ do { \
6352 * stack by default, so in the absence of a PT_GNU_STACK program header
6353 * we turn execute permission off.
6354 */
6355-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6356- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6357+#define VM_STACK_DEFAULT_FLAGS32 \
6358+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6359+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6360
6361 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6362 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6363
6364+#ifndef CONFIG_PAX_PAGEEXEC
6365 #define VM_STACK_DEFAULT_FLAGS \
6366 (is_32bit_task() ? \
6367 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6368+#endif
6369
6370 #include <asm-generic/getorder.h>
6371
6372diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6373index 292725c..f87ae14 100644
6374--- a/arch/powerpc/include/asm/pgalloc-64.h
6375+++ b/arch/powerpc/include/asm/pgalloc-64.h
6376@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6377 #ifndef CONFIG_PPC_64K_PAGES
6378
6379 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6380+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6381
6382 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6383 {
6384@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6385 pud_set(pud, (unsigned long)pmd);
6386 }
6387
6388+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6389+{
6390+ pud_populate(mm, pud, pmd);
6391+}
6392+
6393 #define pmd_populate(mm, pmd, pte_page) \
6394 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6395 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6396@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6397 #else /* CONFIG_PPC_64K_PAGES */
6398
6399 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6400+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6401
6402 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6403 pte_t *pte)
6404diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6405index a9cbd3b..3b67efa 100644
6406--- a/arch/powerpc/include/asm/pgtable.h
6407+++ b/arch/powerpc/include/asm/pgtable.h
6408@@ -2,6 +2,7 @@
6409 #define _ASM_POWERPC_PGTABLE_H
6410 #ifdef __KERNEL__
6411
6412+#include <linux/const.h>
6413 #ifndef __ASSEMBLY__
6414 #include <asm/processor.h> /* For TASK_SIZE */
6415 #include <asm/mmu.h>
6416diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6417index 4aad413..85d86bf 100644
6418--- a/arch/powerpc/include/asm/pte-hash32.h
6419+++ b/arch/powerpc/include/asm/pte-hash32.h
6420@@ -21,6 +21,7 @@
6421 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6422 #define _PAGE_USER 0x004 /* usermode access allowed */
6423 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6424+#define _PAGE_EXEC _PAGE_GUARDED
6425 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6426 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6427 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6428diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6429index 3d5c9dc..62f8414 100644
6430--- a/arch/powerpc/include/asm/reg.h
6431+++ b/arch/powerpc/include/asm/reg.h
6432@@ -215,6 +215,7 @@
6433 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6434 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6435 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6436+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6437 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6438 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6439 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6440diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6441index 406b7b9..af63426 100644
6442--- a/arch/powerpc/include/asm/thread_info.h
6443+++ b/arch/powerpc/include/asm/thread_info.h
6444@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6445 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6446 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6447 #define TIF_SINGLESTEP 8 /* singlestepping active */
6448-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6449 #define TIF_SECCOMP 10 /* secure computing */
6450 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6451 #define TIF_NOERROR 12 /* Force successful syscall return */
6452@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6453 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6454 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6455 for stack store? */
6456+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6457+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6458+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6459
6460 /* as above, but as bit values */
6461 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6462@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6463 #define _TIF_UPROBE (1<<TIF_UPROBE)
6464 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6465 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6466+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6467 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6468- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6469+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6470+ _TIF_GRSEC_SETXID)
6471
6472 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6473 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6474diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6475index 4db4959..335e00c 100644
6476--- a/arch/powerpc/include/asm/uaccess.h
6477+++ b/arch/powerpc/include/asm/uaccess.h
6478@@ -13,6 +13,8 @@
6479 #define VERIFY_READ 0
6480 #define VERIFY_WRITE 1
6481
6482+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6483+
6484 /*
6485 * The fs value determines whether argument validity checking should be
6486 * performed or not. If get_fs() == USER_DS, checking is performed, with
6487@@ -318,52 +320,6 @@ do { \
6488 extern unsigned long __copy_tofrom_user(void __user *to,
6489 const void __user *from, unsigned long size);
6490
6491-#ifndef __powerpc64__
6492-
6493-static inline unsigned long copy_from_user(void *to,
6494- const void __user *from, unsigned long n)
6495-{
6496- unsigned long over;
6497-
6498- if (access_ok(VERIFY_READ, from, n))
6499- return __copy_tofrom_user((__force void __user *)to, from, n);
6500- if ((unsigned long)from < TASK_SIZE) {
6501- over = (unsigned long)from + n - TASK_SIZE;
6502- return __copy_tofrom_user((__force void __user *)to, from,
6503- n - over) + over;
6504- }
6505- return n;
6506-}
6507-
6508-static inline unsigned long copy_to_user(void __user *to,
6509- const void *from, unsigned long n)
6510-{
6511- unsigned long over;
6512-
6513- if (access_ok(VERIFY_WRITE, to, n))
6514- return __copy_tofrom_user(to, (__force void __user *)from, n);
6515- if ((unsigned long)to < TASK_SIZE) {
6516- over = (unsigned long)to + n - TASK_SIZE;
6517- return __copy_tofrom_user(to, (__force void __user *)from,
6518- n - over) + over;
6519- }
6520- return n;
6521-}
6522-
6523-#else /* __powerpc64__ */
6524-
6525-#define __copy_in_user(to, from, size) \
6526- __copy_tofrom_user((to), (from), (size))
6527-
6528-extern unsigned long copy_from_user(void *to, const void __user *from,
6529- unsigned long n);
6530-extern unsigned long copy_to_user(void __user *to, const void *from,
6531- unsigned long n);
6532-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6533- unsigned long n);
6534-
6535-#endif /* __powerpc64__ */
6536-
6537 static inline unsigned long __copy_from_user_inatomic(void *to,
6538 const void __user *from, unsigned long n)
6539 {
6540@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6541 if (ret == 0)
6542 return 0;
6543 }
6544+
6545+ if (!__builtin_constant_p(n))
6546+ check_object_size(to, n, false);
6547+
6548 return __copy_tofrom_user((__force void __user *)to, from, n);
6549 }
6550
6551@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6552 if (ret == 0)
6553 return 0;
6554 }
6555+
6556+ if (!__builtin_constant_p(n))
6557+ check_object_size(from, n, true);
6558+
6559 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6560 }
6561
6562@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6563 return __copy_to_user_inatomic(to, from, size);
6564 }
6565
6566+#ifndef __powerpc64__
6567+
6568+static inline unsigned long __must_check copy_from_user(void *to,
6569+ const void __user *from, unsigned long n)
6570+{
6571+ unsigned long over;
6572+
6573+ if ((long)n < 0)
6574+ return n;
6575+
6576+ if (access_ok(VERIFY_READ, from, n)) {
6577+ if (!__builtin_constant_p(n))
6578+ check_object_size(to, n, false);
6579+ return __copy_tofrom_user((__force void __user *)to, from, n);
6580+ }
6581+ if ((unsigned long)from < TASK_SIZE) {
6582+ over = (unsigned long)from + n - TASK_SIZE;
6583+ if (!__builtin_constant_p(n - over))
6584+ check_object_size(to, n - over, false);
6585+ return __copy_tofrom_user((__force void __user *)to, from,
6586+ n - over) + over;
6587+ }
6588+ return n;
6589+}
6590+
6591+static inline unsigned long __must_check copy_to_user(void __user *to,
6592+ const void *from, unsigned long n)
6593+{
6594+ unsigned long over;
6595+
6596+ if ((long)n < 0)
6597+ return n;
6598+
6599+ if (access_ok(VERIFY_WRITE, to, n)) {
6600+ if (!__builtin_constant_p(n))
6601+ check_object_size(from, n, true);
6602+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6603+ }
6604+ if ((unsigned long)to < TASK_SIZE) {
6605+ over = (unsigned long)to + n - TASK_SIZE;
6606+ if (!__builtin_constant_p(n))
6607+ check_object_size(from, n - over, true);
6608+ return __copy_tofrom_user(to, (__force void __user *)from,
6609+ n - over) + over;
6610+ }
6611+ return n;
6612+}
6613+
6614+#else /* __powerpc64__ */
6615+
6616+#define __copy_in_user(to, from, size) \
6617+ __copy_tofrom_user((to), (from), (size))
6618+
6619+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6620+{
6621+ if ((long)n < 0 || n > INT_MAX)
6622+ return n;
6623+
6624+ if (!__builtin_constant_p(n))
6625+ check_object_size(to, n, false);
6626+
6627+ if (likely(access_ok(VERIFY_READ, from, n)))
6628+ n = __copy_from_user(to, from, n);
6629+ else
6630+ memset(to, 0, n);
6631+ return n;
6632+}
6633+
6634+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6635+{
6636+ if ((long)n < 0 || n > INT_MAX)
6637+ return n;
6638+
6639+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6640+ if (!__builtin_constant_p(n))
6641+ check_object_size(from, n, true);
6642+ n = __copy_to_user(to, from, n);
6643+ }
6644+ return n;
6645+}
6646+
6647+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6648+ unsigned long n);
6649+
6650+#endif /* __powerpc64__ */
6651+
6652 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6653
6654 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6655diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6656index 4684e33..acc4d19e 100644
6657--- a/arch/powerpc/kernel/exceptions-64e.S
6658+++ b/arch/powerpc/kernel/exceptions-64e.S
6659@@ -715,6 +715,7 @@ storage_fault_common:
6660 std r14,_DAR(r1)
6661 std r15,_DSISR(r1)
6662 addi r3,r1,STACK_FRAME_OVERHEAD
6663+ bl .save_nvgprs
6664 mr r4,r14
6665 mr r5,r15
6666 ld r14,PACA_EXGEN+EX_R14(r13)
6667@@ -723,8 +724,7 @@ storage_fault_common:
6668 cmpdi r3,0
6669 bne- 1f
6670 b .ret_from_except_lite
6671-1: bl .save_nvgprs
6672- mr r5,r3
6673+1: mr r5,r3
6674 addi r3,r1,STACK_FRAME_OVERHEAD
6675 ld r4,_DAR(r1)
6676 bl .bad_page_fault
6677diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6678index 3684cbd..bc89eab 100644
6679--- a/arch/powerpc/kernel/exceptions-64s.S
6680+++ b/arch/powerpc/kernel/exceptions-64s.S
6681@@ -1206,10 +1206,10 @@ handle_page_fault:
6682 11: ld r4,_DAR(r1)
6683 ld r5,_DSISR(r1)
6684 addi r3,r1,STACK_FRAME_OVERHEAD
6685+ bl .save_nvgprs
6686 bl .do_page_fault
6687 cmpdi r3,0
6688 beq+ 12f
6689- bl .save_nvgprs
6690 mr r5,r3
6691 addi r3,r1,STACK_FRAME_OVERHEAD
6692 lwz r4,_DAR(r1)
6693diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6694index 2e3200c..72095ce 100644
6695--- a/arch/powerpc/kernel/module_32.c
6696+++ b/arch/powerpc/kernel/module_32.c
6697@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6698 me->arch.core_plt_section = i;
6699 }
6700 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6701- printk("Module doesn't contain .plt or .init.plt sections.\n");
6702+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6703 return -ENOEXEC;
6704 }
6705
6706@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6707
6708 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6709 /* Init, or core PLT? */
6710- if (location >= mod->module_core
6711- && location < mod->module_core + mod->core_size)
6712+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6713+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6714 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6715- else
6716+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6717+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6718 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6719+ else {
6720+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6721+ return ~0UL;
6722+ }
6723
6724 /* Find this entry, or if that fails, the next avail. entry */
6725 while (entry->jump[0]) {
6726diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6727index 8143067..21ae55b 100644
6728--- a/arch/powerpc/kernel/process.c
6729+++ b/arch/powerpc/kernel/process.c
6730@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6731 * Lookup NIP late so we have the best change of getting the
6732 * above info out without failing
6733 */
6734- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6735- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6736+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6737+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6738 #endif
6739 show_stack(current, (unsigned long *) regs->gpr[1]);
6740 if (!user_mode(regs))
6741@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6742 newsp = stack[0];
6743 ip = stack[STACK_FRAME_LR_SAVE];
6744 if (!firstframe || ip != lr) {
6745- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6746+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6747 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6748 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6749- printk(" (%pS)",
6750+ printk(" (%pA)",
6751 (void *)current->ret_stack[curr_frame].ret);
6752 curr_frame--;
6753 }
6754@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6755 struct pt_regs *regs = (struct pt_regs *)
6756 (sp + STACK_FRAME_OVERHEAD);
6757 lr = regs->link;
6758- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6759+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6760 regs->trap, (void *)regs->nip, (void *)lr);
6761 firstframe = 1;
6762 }
6763@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6764 mtspr(SPRN_CTRLT, ctrl);
6765 }
6766 #endif /* CONFIG_PPC64 */
6767-
6768-unsigned long arch_align_stack(unsigned long sp)
6769-{
6770- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6771- sp -= get_random_int() & ~PAGE_MASK;
6772- return sp & ~0xf;
6773-}
6774-
6775-static inline unsigned long brk_rnd(void)
6776-{
6777- unsigned long rnd = 0;
6778-
6779- /* 8MB for 32bit, 1GB for 64bit */
6780- if (is_32bit_task())
6781- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6782- else
6783- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6784-
6785- return rnd << PAGE_SHIFT;
6786-}
6787-
6788-unsigned long arch_randomize_brk(struct mm_struct *mm)
6789-{
6790- unsigned long base = mm->brk;
6791- unsigned long ret;
6792-
6793-#ifdef CONFIG_PPC_STD_MMU_64
6794- /*
6795- * If we are using 1TB segments and we are allowed to randomise
6796- * the heap, we can put it above 1TB so it is backed by a 1TB
6797- * segment. Otherwise the heap will be in the bottom 1TB
6798- * which always uses 256MB segments and this may result in a
6799- * performance penalty.
6800- */
6801- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6802- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6803-#endif
6804-
6805- ret = PAGE_ALIGN(base + brk_rnd());
6806-
6807- if (ret < mm->brk)
6808- return mm->brk;
6809-
6810- return ret;
6811-}
6812-
6813-unsigned long randomize_et_dyn(unsigned long base)
6814-{
6815- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6816-
6817- if (ret < base)
6818- return base;
6819-
6820- return ret;
6821-}
6822diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6823index c497000..8fde506 100644
6824--- a/arch/powerpc/kernel/ptrace.c
6825+++ b/arch/powerpc/kernel/ptrace.c
6826@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6827 return ret;
6828 }
6829
6830+#ifdef CONFIG_GRKERNSEC_SETXID
6831+extern void gr_delayed_cred_worker(void);
6832+#endif
6833+
6834 /*
6835 * We must return the syscall number to actually look up in the table.
6836 * This can be -1L to skip running any syscall at all.
6837@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6838
6839 secure_computing_strict(regs->gpr[0]);
6840
6841+#ifdef CONFIG_GRKERNSEC_SETXID
6842+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6843+ gr_delayed_cred_worker();
6844+#endif
6845+
6846 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6847 tracehook_report_syscall_entry(regs))
6848 /*
6849@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6850 {
6851 int step;
6852
6853+#ifdef CONFIG_GRKERNSEC_SETXID
6854+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6855+ gr_delayed_cred_worker();
6856+#endif
6857+
6858 audit_syscall_exit(regs);
6859
6860 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6861diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6862index 804e323..79181c1 100644
6863--- a/arch/powerpc/kernel/signal_32.c
6864+++ b/arch/powerpc/kernel/signal_32.c
6865@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6866 /* Save user registers on the stack */
6867 frame = &rt_sf->uc.uc_mcontext;
6868 addr = frame;
6869- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6870+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6871 if (save_user_regs(regs, frame, 0, 1))
6872 goto badframe;
6873 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6874diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6875index 1ca045d..139c3f7 100644
6876--- a/arch/powerpc/kernel/signal_64.c
6877+++ b/arch/powerpc/kernel/signal_64.c
6878@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6879 current->thread.fpscr.val = 0;
6880
6881 /* Set up to return from userspace. */
6882- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6883+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6884 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6885 } else {
6886 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6887diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6888index 3ce1f86..c30e629 100644
6889--- a/arch/powerpc/kernel/sysfs.c
6890+++ b/arch/powerpc/kernel/sysfs.c
6891@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6892 return NOTIFY_OK;
6893 }
6894
6895-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6896+static struct notifier_block sysfs_cpu_nb = {
6897 .notifier_call = sysfs_cpu_notify,
6898 };
6899
6900diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6901index 3251840..3f7c77a 100644
6902--- a/arch/powerpc/kernel/traps.c
6903+++ b/arch/powerpc/kernel/traps.c
6904@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6905 return flags;
6906 }
6907
6908+extern void gr_handle_kernel_exploit(void);
6909+
6910 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6911 int signr)
6912 {
6913@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6914 panic("Fatal exception in interrupt");
6915 if (panic_on_oops)
6916 panic("Fatal exception");
6917+
6918+ gr_handle_kernel_exploit();
6919+
6920 do_exit(signr);
6921 }
6922
6923diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6924index 1b2076f..835e4be 100644
6925--- a/arch/powerpc/kernel/vdso.c
6926+++ b/arch/powerpc/kernel/vdso.c
6927@@ -34,6 +34,7 @@
6928 #include <asm/firmware.h>
6929 #include <asm/vdso.h>
6930 #include <asm/vdso_datapage.h>
6931+#include <asm/mman.h>
6932
6933 #include "setup.h"
6934
6935@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6936 vdso_base = VDSO32_MBASE;
6937 #endif
6938
6939- current->mm->context.vdso_base = 0;
6940+ current->mm->context.vdso_base = ~0UL;
6941
6942 /* vDSO has a problem and was disabled, just don't "enable" it for the
6943 * process
6944@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6945 vdso_base = get_unmapped_area(NULL, vdso_base,
6946 (vdso_pages << PAGE_SHIFT) +
6947 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6948- 0, 0);
6949+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6950 if (IS_ERR_VALUE(vdso_base)) {
6951 rc = vdso_base;
6952 goto fail_mmapsem;
6953diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6954index 5eea6f3..5d10396 100644
6955--- a/arch/powerpc/lib/usercopy_64.c
6956+++ b/arch/powerpc/lib/usercopy_64.c
6957@@ -9,22 +9,6 @@
6958 #include <linux/module.h>
6959 #include <asm/uaccess.h>
6960
6961-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6962-{
6963- if (likely(access_ok(VERIFY_READ, from, n)))
6964- n = __copy_from_user(to, from, n);
6965- else
6966- memset(to, 0, n);
6967- return n;
6968-}
6969-
6970-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6971-{
6972- if (likely(access_ok(VERIFY_WRITE, to, n)))
6973- n = __copy_to_user(to, from, n);
6974- return n;
6975-}
6976-
6977 unsigned long copy_in_user(void __user *to, const void __user *from,
6978 unsigned long n)
6979 {
6980@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6981 return n;
6982 }
6983
6984-EXPORT_SYMBOL(copy_from_user);
6985-EXPORT_SYMBOL(copy_to_user);
6986 EXPORT_SYMBOL(copy_in_user);
6987
6988diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6989index 3a8489a..6a63b3b 100644
6990--- a/arch/powerpc/mm/fault.c
6991+++ b/arch/powerpc/mm/fault.c
6992@@ -32,6 +32,10 @@
6993 #include <linux/perf_event.h>
6994 #include <linux/magic.h>
6995 #include <linux/ratelimit.h>
6996+#include <linux/slab.h>
6997+#include <linux/pagemap.h>
6998+#include <linux/compiler.h>
6999+#include <linux/unistd.h>
7000
7001 #include <asm/firmware.h>
7002 #include <asm/page.h>
7003@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7004 }
7005 #endif
7006
7007+#ifdef CONFIG_PAX_PAGEEXEC
7008+/*
7009+ * PaX: decide what to do with offenders (regs->nip = fault address)
7010+ *
7011+ * returns 1 when task should be killed
7012+ */
7013+static int pax_handle_fetch_fault(struct pt_regs *regs)
7014+{
7015+ return 1;
7016+}
7017+
7018+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7019+{
7020+ unsigned long i;
7021+
7022+ printk(KERN_ERR "PAX: bytes at PC: ");
7023+ for (i = 0; i < 5; i++) {
7024+ unsigned int c;
7025+ if (get_user(c, (unsigned int __user *)pc+i))
7026+ printk(KERN_CONT "???????? ");
7027+ else
7028+ printk(KERN_CONT "%08x ", c);
7029+ }
7030+ printk("\n");
7031+}
7032+#endif
7033+
7034 /*
7035 * Check whether the instruction at regs->nip is a store using
7036 * an update addressing form which will update r1.
7037@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7038 * indicate errors in DSISR but can validly be set in SRR1.
7039 */
7040 if (trap == 0x400)
7041- error_code &= 0x48200000;
7042+ error_code &= 0x58200000;
7043 else
7044 is_write = error_code & DSISR_ISSTORE;
7045 #else
7046@@ -364,7 +395,7 @@ good_area:
7047 * "undefined". Of those that can be set, this is the only
7048 * one which seems bad.
7049 */
7050- if (error_code & 0x10000000)
7051+ if (error_code & DSISR_GUARDED)
7052 /* Guarded storage error. */
7053 goto bad_area;
7054 #endif /* CONFIG_8xx */
7055@@ -379,7 +410,7 @@ good_area:
7056 * processors use the same I/D cache coherency mechanism
7057 * as embedded.
7058 */
7059- if (error_code & DSISR_PROTFAULT)
7060+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7061 goto bad_area;
7062 #endif /* CONFIG_PPC_STD_MMU */
7063
7064@@ -462,6 +493,23 @@ bad_area:
7065 bad_area_nosemaphore:
7066 /* User mode accesses cause a SIGSEGV */
7067 if (user_mode(regs)) {
7068+
7069+#ifdef CONFIG_PAX_PAGEEXEC
7070+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7071+#ifdef CONFIG_PPC_STD_MMU
7072+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7073+#else
7074+ if (is_exec && regs->nip == address) {
7075+#endif
7076+ switch (pax_handle_fetch_fault(regs)) {
7077+ }
7078+
7079+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7080+ do_group_exit(SIGKILL);
7081+ }
7082+ }
7083+#endif
7084+
7085 _exception(SIGSEGV, regs, code, address);
7086 return 0;
7087 }
7088diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7089index 67a42ed..cd463e0 100644
7090--- a/arch/powerpc/mm/mmap_64.c
7091+++ b/arch/powerpc/mm/mmap_64.c
7092@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7093 {
7094 unsigned long rnd = 0;
7095
7096+#ifdef CONFIG_PAX_RANDMMAP
7097+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7098+#endif
7099+
7100 if (current->flags & PF_RANDOMIZE) {
7101 /* 8MB for 32bit, 1GB for 64bit */
7102 if (is_32bit_task())
7103@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7104 */
7105 if (mmap_is_legacy()) {
7106 mm->mmap_base = TASK_UNMAPPED_BASE;
7107+
7108+#ifdef CONFIG_PAX_RANDMMAP
7109+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7110+ mm->mmap_base += mm->delta_mmap;
7111+#endif
7112+
7113 mm->get_unmapped_area = arch_get_unmapped_area;
7114 mm->unmap_area = arch_unmap_area;
7115 } else {
7116 mm->mmap_base = mmap_base();
7117+
7118+#ifdef CONFIG_PAX_RANDMMAP
7119+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7120+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7121+#endif
7122+
7123 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7124 mm->unmap_area = arch_unmap_area_topdown;
7125 }
7126diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7127index e779642..e5bb889 100644
7128--- a/arch/powerpc/mm/mmu_context_nohash.c
7129+++ b/arch/powerpc/mm/mmu_context_nohash.c
7130@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7131 return NOTIFY_OK;
7132 }
7133
7134-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7135+static struct notifier_block mmu_context_cpu_nb = {
7136 .notifier_call = mmu_context_cpu_notify,
7137 };
7138
7139diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7140index bba87ca..c346a33 100644
7141--- a/arch/powerpc/mm/numa.c
7142+++ b/arch/powerpc/mm/numa.c
7143@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7144 return ret;
7145 }
7146
7147-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7148+static struct notifier_block ppc64_numa_nb = {
7149 .notifier_call = cpu_numa_callback,
7150 .priority = 1 /* Must run before sched domains notifier. */
7151 };
7152diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7153index cf9dada..241529f 100644
7154--- a/arch/powerpc/mm/slice.c
7155+++ b/arch/powerpc/mm/slice.c
7156@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7157 if ((mm->task_size - len) < addr)
7158 return 0;
7159 vma = find_vma(mm, addr);
7160- return (!vma || (addr + len) <= vma->vm_start);
7161+ return check_heap_stack_gap(vma, addr, len, 0);
7162 }
7163
7164 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7165@@ -272,7 +272,7 @@ full_search:
7166 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7167 continue;
7168 }
7169- if (!vma || addr + len <= vma->vm_start) {
7170+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7171 /*
7172 * Remember the place where we stopped the search:
7173 */
7174@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7175 }
7176 }
7177
7178- addr = mm->mmap_base;
7179- while (addr > len) {
7180+ if (mm->mmap_base < len)
7181+ addr = -ENOMEM;
7182+ else
7183+ addr = mm->mmap_base - len;
7184+
7185+ while (!IS_ERR_VALUE(addr)) {
7186 /* Go down by chunk size */
7187- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7188+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7189
7190 /* Check for hit with different page size */
7191 mask = slice_range_to_mask(addr, len);
7192@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7193 * return with success:
7194 */
7195 vma = find_vma(mm, addr);
7196- if (!vma || (addr + len) <= vma->vm_start) {
7197+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7198 /* remember the address as a hint for next time */
7199 if (use_cache)
7200 mm->free_area_cache = addr;
7201@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7202 mm->cached_hole_size = vma->vm_start - addr;
7203
7204 /* try just below the current vma->vm_start */
7205- addr = vma->vm_start;
7206+ addr = skip_heap_stack_gap(vma, len, 0);
7207 }
7208
7209 /*
7210@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7211 if (fixed && addr > (mm->task_size - len))
7212 return -EINVAL;
7213
7214+#ifdef CONFIG_PAX_RANDMMAP
7215+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7216+ addr = 0;
7217+#endif
7218+
7219 /* If hint, make sure it matches our alignment restrictions */
7220 if (!fixed && addr) {
7221 addr = _ALIGN_UP(addr, 1ul << pshift);
7222diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7223index bdb738a..49c9f95 100644
7224--- a/arch/powerpc/platforms/powermac/smp.c
7225+++ b/arch/powerpc/platforms/powermac/smp.c
7226@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7227 return NOTIFY_OK;
7228 }
7229
7230-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7231+static struct notifier_block smp_core99_cpu_nb = {
7232 .notifier_call = smp_core99_cpu_notify,
7233 };
7234 #endif /* CONFIG_HOTPLUG_CPU */
7235diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7236index c797832..ce575c8 100644
7237--- a/arch/s390/include/asm/atomic.h
7238+++ b/arch/s390/include/asm/atomic.h
7239@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7240 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7241 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7242
7243+#define atomic64_read_unchecked(v) atomic64_read(v)
7244+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7245+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7246+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7247+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7248+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7249+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7250+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7251+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7252+
7253 #define smp_mb__before_atomic_dec() smp_mb()
7254 #define smp_mb__after_atomic_dec() smp_mb()
7255 #define smp_mb__before_atomic_inc() smp_mb()
7256diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7257index 4d7ccac..d03d0ad 100644
7258--- a/arch/s390/include/asm/cache.h
7259+++ b/arch/s390/include/asm/cache.h
7260@@ -9,8 +9,10 @@
7261 #ifndef __ARCH_S390_CACHE_H
7262 #define __ARCH_S390_CACHE_H
7263
7264-#define L1_CACHE_BYTES 256
7265+#include <linux/const.h>
7266+
7267 #define L1_CACHE_SHIFT 8
7268+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7269 #define NET_SKB_PAD 32
7270
7271 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7272diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7273index 178ff96..8c93bd1 100644
7274--- a/arch/s390/include/asm/elf.h
7275+++ b/arch/s390/include/asm/elf.h
7276@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7277 the loader. We need to make sure that it is out of the way of the program
7278 that it will "exec", and that there is sufficient room for the brk. */
7279
7280-extern unsigned long randomize_et_dyn(unsigned long base);
7281-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7282+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7283+
7284+#ifdef CONFIG_PAX_ASLR
7285+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7286+
7287+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7288+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7289+#endif
7290
7291 /* This yields a mask that user programs can use to figure out what
7292 instruction set this CPU supports. */
7293@@ -210,9 +216,6 @@ struct linux_binprm;
7294 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7295 int arch_setup_additional_pages(struct linux_binprm *, int);
7296
7297-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7298-#define arch_randomize_brk arch_randomize_brk
7299-
7300 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7301
7302 #endif
7303diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7304index c4a93d6..4d2a9b4 100644
7305--- a/arch/s390/include/asm/exec.h
7306+++ b/arch/s390/include/asm/exec.h
7307@@ -7,6 +7,6 @@
7308 #ifndef __ASM_EXEC_H
7309 #define __ASM_EXEC_H
7310
7311-extern unsigned long arch_align_stack(unsigned long sp);
7312+#define arch_align_stack(x) ((x) & ~0xfUL)
7313
7314 #endif /* __ASM_EXEC_H */
7315diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7316index 34268df..ea97318 100644
7317--- a/arch/s390/include/asm/uaccess.h
7318+++ b/arch/s390/include/asm/uaccess.h
7319@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7320 copy_to_user(void __user *to, const void *from, unsigned long n)
7321 {
7322 might_fault();
7323+
7324+ if ((long)n < 0)
7325+ return n;
7326+
7327 if (access_ok(VERIFY_WRITE, to, n))
7328 n = __copy_to_user(to, from, n);
7329 return n;
7330@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7331 static inline unsigned long __must_check
7332 __copy_from_user(void *to, const void __user *from, unsigned long n)
7333 {
7334+ if ((long)n < 0)
7335+ return n;
7336+
7337 if (__builtin_constant_p(n) && (n <= 256))
7338 return uaccess.copy_from_user_small(n, from, to);
7339 else
7340@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7341 static inline unsigned long __must_check
7342 copy_from_user(void *to, const void __user *from, unsigned long n)
7343 {
7344- unsigned int sz = __compiletime_object_size(to);
7345+ size_t sz = __compiletime_object_size(to);
7346
7347 might_fault();
7348- if (unlikely(sz != -1 && sz < n)) {
7349+
7350+ if ((long)n < 0)
7351+ return n;
7352+
7353+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7354 copy_from_user_overflow();
7355 return n;
7356 }
7357diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7358index 4610dea..cf0af21 100644
7359--- a/arch/s390/kernel/module.c
7360+++ b/arch/s390/kernel/module.c
7361@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7362
7363 /* Increase core size by size of got & plt and set start
7364 offsets for got and plt. */
7365- me->core_size = ALIGN(me->core_size, 4);
7366- me->arch.got_offset = me->core_size;
7367- me->core_size += me->arch.got_size;
7368- me->arch.plt_offset = me->core_size;
7369- me->core_size += me->arch.plt_size;
7370+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7371+ me->arch.got_offset = me->core_size_rw;
7372+ me->core_size_rw += me->arch.got_size;
7373+ me->arch.plt_offset = me->core_size_rx;
7374+ me->core_size_rx += me->arch.plt_size;
7375 return 0;
7376 }
7377
7378@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7379 if (info->got_initialized == 0) {
7380 Elf_Addr *gotent;
7381
7382- gotent = me->module_core + me->arch.got_offset +
7383+ gotent = me->module_core_rw + me->arch.got_offset +
7384 info->got_offset;
7385 *gotent = val;
7386 info->got_initialized = 1;
7387@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7388 else if (r_type == R_390_GOTENT ||
7389 r_type == R_390_GOTPLTENT)
7390 *(unsigned int *) loc =
7391- (val + (Elf_Addr) me->module_core - loc) >> 1;
7392+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7393 else if (r_type == R_390_GOT64 ||
7394 r_type == R_390_GOTPLT64)
7395 *(unsigned long *) loc = val;
7396@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7397 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7398 if (info->plt_initialized == 0) {
7399 unsigned int *ip;
7400- ip = me->module_core + me->arch.plt_offset +
7401+ ip = me->module_core_rx + me->arch.plt_offset +
7402 info->plt_offset;
7403 #ifndef CONFIG_64BIT
7404 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7405@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7406 val - loc + 0xffffUL < 0x1ffffeUL) ||
7407 (r_type == R_390_PLT32DBL &&
7408 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7409- val = (Elf_Addr) me->module_core +
7410+ val = (Elf_Addr) me->module_core_rx +
7411 me->arch.plt_offset +
7412 info->plt_offset;
7413 val += rela->r_addend - loc;
7414@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7415 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7416 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7417 val = val + rela->r_addend -
7418- ((Elf_Addr) me->module_core + me->arch.got_offset);
7419+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7420 if (r_type == R_390_GOTOFF16)
7421 *(unsigned short *) loc = val;
7422 else if (r_type == R_390_GOTOFF32)
7423@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7424 break;
7425 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7426 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7427- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7428+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7429 rela->r_addend - loc;
7430 if (r_type == R_390_GOTPC)
7431 *(unsigned int *) loc = val;
7432diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7433index 536d645..4a5bd9e 100644
7434--- a/arch/s390/kernel/process.c
7435+++ b/arch/s390/kernel/process.c
7436@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7437 }
7438 return 0;
7439 }
7440-
7441-unsigned long arch_align_stack(unsigned long sp)
7442-{
7443- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7444- sp -= get_random_int() & ~PAGE_MASK;
7445- return sp & ~0xf;
7446-}
7447-
7448-static inline unsigned long brk_rnd(void)
7449-{
7450- /* 8MB for 32bit, 1GB for 64bit */
7451- if (is_32bit_task())
7452- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7453- else
7454- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7455-}
7456-
7457-unsigned long arch_randomize_brk(struct mm_struct *mm)
7458-{
7459- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7460-
7461- if (ret < mm->brk)
7462- return mm->brk;
7463- return ret;
7464-}
7465-
7466-unsigned long randomize_et_dyn(unsigned long base)
7467-{
7468- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7469-
7470- if (!(current->flags & PF_RANDOMIZE))
7471- return base;
7472- if (ret < base)
7473- return base;
7474- return ret;
7475-}
7476diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7477index c59a5ef..3fae59c 100644
7478--- a/arch/s390/mm/mmap.c
7479+++ b/arch/s390/mm/mmap.c
7480@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7481 */
7482 if (mmap_is_legacy()) {
7483 mm->mmap_base = TASK_UNMAPPED_BASE;
7484+
7485+#ifdef CONFIG_PAX_RANDMMAP
7486+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7487+ mm->mmap_base += mm->delta_mmap;
7488+#endif
7489+
7490 mm->get_unmapped_area = arch_get_unmapped_area;
7491 mm->unmap_area = arch_unmap_area;
7492 } else {
7493 mm->mmap_base = mmap_base();
7494+
7495+#ifdef CONFIG_PAX_RANDMMAP
7496+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7497+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7498+#endif
7499+
7500 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7501 mm->unmap_area = arch_unmap_area_topdown;
7502 }
7503@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7504 */
7505 if (mmap_is_legacy()) {
7506 mm->mmap_base = TASK_UNMAPPED_BASE;
7507+
7508+#ifdef CONFIG_PAX_RANDMMAP
7509+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7510+ mm->mmap_base += mm->delta_mmap;
7511+#endif
7512+
7513 mm->get_unmapped_area = s390_get_unmapped_area;
7514 mm->unmap_area = arch_unmap_area;
7515 } else {
7516 mm->mmap_base = mmap_base();
7517+
7518+#ifdef CONFIG_PAX_RANDMMAP
7519+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7520+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7521+#endif
7522+
7523 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7524 mm->unmap_area = arch_unmap_area_topdown;
7525 }
7526diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7527index ae3d59f..f65f075 100644
7528--- a/arch/score/include/asm/cache.h
7529+++ b/arch/score/include/asm/cache.h
7530@@ -1,7 +1,9 @@
7531 #ifndef _ASM_SCORE_CACHE_H
7532 #define _ASM_SCORE_CACHE_H
7533
7534+#include <linux/const.h>
7535+
7536 #define L1_CACHE_SHIFT 4
7537-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7538+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7539
7540 #endif /* _ASM_SCORE_CACHE_H */
7541diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7542index f9f3cd5..58ff438 100644
7543--- a/arch/score/include/asm/exec.h
7544+++ b/arch/score/include/asm/exec.h
7545@@ -1,6 +1,6 @@
7546 #ifndef _ASM_SCORE_EXEC_H
7547 #define _ASM_SCORE_EXEC_H
7548
7549-extern unsigned long arch_align_stack(unsigned long sp);
7550+#define arch_align_stack(x) (x)
7551
7552 #endif /* _ASM_SCORE_EXEC_H */
7553diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7554index 7956846..5f37677 100644
7555--- a/arch/score/kernel/process.c
7556+++ b/arch/score/kernel/process.c
7557@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7558
7559 return task_pt_regs(task)->cp0_epc;
7560 }
7561-
7562-unsigned long arch_align_stack(unsigned long sp)
7563-{
7564- return sp;
7565-}
7566diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7567index ef9e555..331bd29 100644
7568--- a/arch/sh/include/asm/cache.h
7569+++ b/arch/sh/include/asm/cache.h
7570@@ -9,10 +9,11 @@
7571 #define __ASM_SH_CACHE_H
7572 #ifdef __KERNEL__
7573
7574+#include <linux/const.h>
7575 #include <linux/init.h>
7576 #include <cpu/cache.h>
7577
7578-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7579+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7580
7581 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7582
7583diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7584index 03f2b55..b027032 100644
7585--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7586+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7587@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7588 return NOTIFY_OK;
7589 }
7590
7591-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7592+static struct notifier_block shx3_cpu_notifier = {
7593 .notifier_call = shx3_cpu_callback,
7594 };
7595
7596diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7597index 6777177..cb5e44f 100644
7598--- a/arch/sh/mm/mmap.c
7599+++ b/arch/sh/mm/mmap.c
7600@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7601 struct mm_struct *mm = current->mm;
7602 struct vm_area_struct *vma;
7603 int do_colour_align;
7604+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7605 struct vm_unmapped_area_info info;
7606
7607 if (flags & MAP_FIXED) {
7608@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7609 if (filp || (flags & MAP_SHARED))
7610 do_colour_align = 1;
7611
7612+#ifdef CONFIG_PAX_RANDMMAP
7613+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7614+#endif
7615+
7616 if (addr) {
7617 if (do_colour_align)
7618 addr = COLOUR_ALIGN(addr, pgoff);
7619@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7620 addr = PAGE_ALIGN(addr);
7621
7622 vma = find_vma(mm, addr);
7623- if (TASK_SIZE - len >= addr &&
7624- (!vma || addr + len <= vma->vm_start))
7625+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7626 return addr;
7627 }
7628
7629 info.flags = 0;
7630 info.length = len;
7631- info.low_limit = TASK_UNMAPPED_BASE;
7632+ info.low_limit = mm->mmap_base;
7633 info.high_limit = TASK_SIZE;
7634 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7635 info.align_offset = pgoff << PAGE_SHIFT;
7636@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7637 struct mm_struct *mm = current->mm;
7638 unsigned long addr = addr0;
7639 int do_colour_align;
7640+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7641 struct vm_unmapped_area_info info;
7642
7643 if (flags & MAP_FIXED) {
7644@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7645 if (filp || (flags & MAP_SHARED))
7646 do_colour_align = 1;
7647
7648+#ifdef CONFIG_PAX_RANDMMAP
7649+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7650+#endif
7651+
7652 /* requesting a specific address */
7653 if (addr) {
7654 if (do_colour_align)
7655@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7656 addr = PAGE_ALIGN(addr);
7657
7658 vma = find_vma(mm, addr);
7659- if (TASK_SIZE - len >= addr &&
7660- (!vma || addr + len <= vma->vm_start))
7661+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7662 return addr;
7663 }
7664
7665@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7666 VM_BUG_ON(addr != -ENOMEM);
7667 info.flags = 0;
7668 info.low_limit = TASK_UNMAPPED_BASE;
7669+
7670+#ifdef CONFIG_PAX_RANDMMAP
7671+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7672+ info.low_limit += mm->delta_mmap;
7673+#endif
7674+
7675 info.high_limit = TASK_SIZE;
7676 addr = vm_unmapped_area(&info);
7677 }
7678diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7679index be56a24..443328f 100644
7680--- a/arch/sparc/include/asm/atomic_64.h
7681+++ b/arch/sparc/include/asm/atomic_64.h
7682@@ -14,18 +14,40 @@
7683 #define ATOMIC64_INIT(i) { (i) }
7684
7685 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7686+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7687+{
7688+ return v->counter;
7689+}
7690 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7691+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7692+{
7693+ return v->counter;
7694+}
7695
7696 #define atomic_set(v, i) (((v)->counter) = i)
7697+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7698+{
7699+ v->counter = i;
7700+}
7701 #define atomic64_set(v, i) (((v)->counter) = i)
7702+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7703+{
7704+ v->counter = i;
7705+}
7706
7707 extern void atomic_add(int, atomic_t *);
7708+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7709 extern void atomic64_add(long, atomic64_t *);
7710+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7711 extern void atomic_sub(int, atomic_t *);
7712+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7713 extern void atomic64_sub(long, atomic64_t *);
7714+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7715
7716 extern int atomic_add_ret(int, atomic_t *);
7717+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7718 extern long atomic64_add_ret(long, atomic64_t *);
7719+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7720 extern int atomic_sub_ret(int, atomic_t *);
7721 extern long atomic64_sub_ret(long, atomic64_t *);
7722
7723@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7724 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7725
7726 #define atomic_inc_return(v) atomic_add_ret(1, v)
7727+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7728+{
7729+ return atomic_add_ret_unchecked(1, v);
7730+}
7731 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7732+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7733+{
7734+ return atomic64_add_ret_unchecked(1, v);
7735+}
7736
7737 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7738 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7739
7740 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7741+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7742+{
7743+ return atomic_add_ret_unchecked(i, v);
7744+}
7745 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7746+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7747+{
7748+ return atomic64_add_ret_unchecked(i, v);
7749+}
7750
7751 /*
7752 * atomic_inc_and_test - increment and test
7753@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7754 * other cases.
7755 */
7756 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7757+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7758+{
7759+ return atomic_inc_return_unchecked(v) == 0;
7760+}
7761 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7762
7763 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7764@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7765 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7766
7767 #define atomic_inc(v) atomic_add(1, v)
7768+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7769+{
7770+ atomic_add_unchecked(1, v);
7771+}
7772 #define atomic64_inc(v) atomic64_add(1, v)
7773+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7774+{
7775+ atomic64_add_unchecked(1, v);
7776+}
7777
7778 #define atomic_dec(v) atomic_sub(1, v)
7779+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7780+{
7781+ atomic_sub_unchecked(1, v);
7782+}
7783 #define atomic64_dec(v) atomic64_sub(1, v)
7784+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7785+{
7786+ atomic64_sub_unchecked(1, v);
7787+}
7788
7789 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7790 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7791
7792 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7793+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7794+{
7795+ return cmpxchg(&v->counter, old, new);
7796+}
7797 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7798+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7799+{
7800+ return xchg(&v->counter, new);
7801+}
7802
7803 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7804 {
7805- int c, old;
7806+ int c, old, new;
7807 c = atomic_read(v);
7808 for (;;) {
7809- if (unlikely(c == (u)))
7810+ if (unlikely(c == u))
7811 break;
7812- old = atomic_cmpxchg((v), c, c + (a));
7813+
7814+ asm volatile("addcc %2, %0, %0\n"
7815+
7816+#ifdef CONFIG_PAX_REFCOUNT
7817+ "tvs %%icc, 6\n"
7818+#endif
7819+
7820+ : "=r" (new)
7821+ : "0" (c), "ir" (a)
7822+ : "cc");
7823+
7824+ old = atomic_cmpxchg(v, c, new);
7825 if (likely(old == c))
7826 break;
7827 c = old;
7828@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7829 #define atomic64_cmpxchg(v, o, n) \
7830 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7831 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7832+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7833+{
7834+ return xchg(&v->counter, new);
7835+}
7836
7837 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7838 {
7839- long c, old;
7840+ long c, old, new;
7841 c = atomic64_read(v);
7842 for (;;) {
7843- if (unlikely(c == (u)))
7844+ if (unlikely(c == u))
7845 break;
7846- old = atomic64_cmpxchg((v), c, c + (a));
7847+
7848+ asm volatile("addcc %2, %0, %0\n"
7849+
7850+#ifdef CONFIG_PAX_REFCOUNT
7851+ "tvs %%xcc, 6\n"
7852+#endif
7853+
7854+ : "=r" (new)
7855+ : "0" (c), "ir" (a)
7856+ : "cc");
7857+
7858+ old = atomic64_cmpxchg(v, c, new);
7859 if (likely(old == c))
7860 break;
7861 c = old;
7862 }
7863- return c != (u);
7864+ return c != u;
7865 }
7866
7867 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7868diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7869index 5bb6991..5c2132e 100644
7870--- a/arch/sparc/include/asm/cache.h
7871+++ b/arch/sparc/include/asm/cache.h
7872@@ -7,10 +7,12 @@
7873 #ifndef _SPARC_CACHE_H
7874 #define _SPARC_CACHE_H
7875
7876+#include <linux/const.h>
7877+
7878 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7879
7880 #define L1_CACHE_SHIFT 5
7881-#define L1_CACHE_BYTES 32
7882+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7883
7884 #ifdef CONFIG_SPARC32
7885 #define SMP_CACHE_BYTES_SHIFT 5
7886diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7887index ac74a2c..a9e58af 100644
7888--- a/arch/sparc/include/asm/elf_32.h
7889+++ b/arch/sparc/include/asm/elf_32.h
7890@@ -114,6 +114,13 @@ typedef struct {
7891
7892 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7893
7894+#ifdef CONFIG_PAX_ASLR
7895+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7896+
7897+#define PAX_DELTA_MMAP_LEN 16
7898+#define PAX_DELTA_STACK_LEN 16
7899+#endif
7900+
7901 /* This yields a mask that user programs can use to figure out what
7902 instruction set this cpu supports. This can NOT be done in userspace
7903 on Sparc. */
7904diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7905index 370ca1e..d4f4a98 100644
7906--- a/arch/sparc/include/asm/elf_64.h
7907+++ b/arch/sparc/include/asm/elf_64.h
7908@@ -189,6 +189,13 @@ typedef struct {
7909 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7910 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7911
7912+#ifdef CONFIG_PAX_ASLR
7913+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7914+
7915+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7916+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7917+#endif
7918+
7919 extern unsigned long sparc64_elf_hwcap;
7920 #define ELF_HWCAP sparc64_elf_hwcap
7921
7922diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7923index 9b1c36d..209298b 100644
7924--- a/arch/sparc/include/asm/pgalloc_32.h
7925+++ b/arch/sparc/include/asm/pgalloc_32.h
7926@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7927 }
7928
7929 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7930+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7931
7932 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7933 unsigned long address)
7934diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7935index bcfe063..b333142 100644
7936--- a/arch/sparc/include/asm/pgalloc_64.h
7937+++ b/arch/sparc/include/asm/pgalloc_64.h
7938@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7939 }
7940
7941 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7942+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7943
7944 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7945 {
7946diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7947index 6fc1348..390c50a 100644
7948--- a/arch/sparc/include/asm/pgtable_32.h
7949+++ b/arch/sparc/include/asm/pgtable_32.h
7950@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7951 #define PAGE_SHARED SRMMU_PAGE_SHARED
7952 #define PAGE_COPY SRMMU_PAGE_COPY
7953 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7954+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7955+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7956+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7957 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7958
7959 /* Top-level page directory - dummy used by init-mm.
7960@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7961
7962 /* xwr */
7963 #define __P000 PAGE_NONE
7964-#define __P001 PAGE_READONLY
7965-#define __P010 PAGE_COPY
7966-#define __P011 PAGE_COPY
7967+#define __P001 PAGE_READONLY_NOEXEC
7968+#define __P010 PAGE_COPY_NOEXEC
7969+#define __P011 PAGE_COPY_NOEXEC
7970 #define __P100 PAGE_READONLY
7971 #define __P101 PAGE_READONLY
7972 #define __P110 PAGE_COPY
7973 #define __P111 PAGE_COPY
7974
7975 #define __S000 PAGE_NONE
7976-#define __S001 PAGE_READONLY
7977-#define __S010 PAGE_SHARED
7978-#define __S011 PAGE_SHARED
7979+#define __S001 PAGE_READONLY_NOEXEC
7980+#define __S010 PAGE_SHARED_NOEXEC
7981+#define __S011 PAGE_SHARED_NOEXEC
7982 #define __S100 PAGE_READONLY
7983 #define __S101 PAGE_READONLY
7984 #define __S110 PAGE_SHARED
7985diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7986index 79da178..c2eede8 100644
7987--- a/arch/sparc/include/asm/pgtsrmmu.h
7988+++ b/arch/sparc/include/asm/pgtsrmmu.h
7989@@ -115,6 +115,11 @@
7990 SRMMU_EXEC | SRMMU_REF)
7991 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7992 SRMMU_EXEC | SRMMU_REF)
7993+
7994+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7995+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7996+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7997+
7998 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7999 SRMMU_DIRTY | SRMMU_REF)
8000
8001diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
8002index 9689176..63c18ea 100644
8003--- a/arch/sparc/include/asm/spinlock_64.h
8004+++ b/arch/sparc/include/asm/spinlock_64.h
8005@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
8006
8007 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
8008
8009-static void inline arch_read_lock(arch_rwlock_t *lock)
8010+static inline void arch_read_lock(arch_rwlock_t *lock)
8011 {
8012 unsigned long tmp1, tmp2;
8013
8014 __asm__ __volatile__ (
8015 "1: ldsw [%2], %0\n"
8016 " brlz,pn %0, 2f\n"
8017-"4: add %0, 1, %1\n"
8018+"4: addcc %0, 1, %1\n"
8019+
8020+#ifdef CONFIG_PAX_REFCOUNT
8021+" tvs %%icc, 6\n"
8022+#endif
8023+
8024 " cas [%2], %0, %1\n"
8025 " cmp %0, %1\n"
8026 " bne,pn %%icc, 1b\n"
8027@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8028 " .previous"
8029 : "=&r" (tmp1), "=&r" (tmp2)
8030 : "r" (lock)
8031- : "memory");
8032+ : "memory", "cc");
8033 }
8034
8035-static int inline arch_read_trylock(arch_rwlock_t *lock)
8036+static inline int arch_read_trylock(arch_rwlock_t *lock)
8037 {
8038 int tmp1, tmp2;
8039
8040@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8041 "1: ldsw [%2], %0\n"
8042 " brlz,a,pn %0, 2f\n"
8043 " mov 0, %0\n"
8044-" add %0, 1, %1\n"
8045+" addcc %0, 1, %1\n"
8046+
8047+#ifdef CONFIG_PAX_REFCOUNT
8048+" tvs %%icc, 6\n"
8049+#endif
8050+
8051 " cas [%2], %0, %1\n"
8052 " cmp %0, %1\n"
8053 " bne,pn %%icc, 1b\n"
8054@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8055 return tmp1;
8056 }
8057
8058-static void inline arch_read_unlock(arch_rwlock_t *lock)
8059+static inline void arch_read_unlock(arch_rwlock_t *lock)
8060 {
8061 unsigned long tmp1, tmp2;
8062
8063 __asm__ __volatile__(
8064 "1: lduw [%2], %0\n"
8065-" sub %0, 1, %1\n"
8066+" subcc %0, 1, %1\n"
8067+
8068+#ifdef CONFIG_PAX_REFCOUNT
8069+" tvs %%icc, 6\n"
8070+#endif
8071+
8072 " cas [%2], %0, %1\n"
8073 " cmp %0, %1\n"
8074 " bne,pn %%xcc, 1b\n"
8075@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8076 : "memory");
8077 }
8078
8079-static void inline arch_write_lock(arch_rwlock_t *lock)
8080+static inline void arch_write_lock(arch_rwlock_t *lock)
8081 {
8082 unsigned long mask, tmp1, tmp2;
8083
8084@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8085 : "memory");
8086 }
8087
8088-static void inline arch_write_unlock(arch_rwlock_t *lock)
8089+static inline void arch_write_unlock(arch_rwlock_t *lock)
8090 {
8091 __asm__ __volatile__(
8092 " stw %%g0, [%0]"
8093@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8094 : "memory");
8095 }
8096
8097-static int inline arch_write_trylock(arch_rwlock_t *lock)
8098+static inline int arch_write_trylock(arch_rwlock_t *lock)
8099 {
8100 unsigned long mask, tmp1, tmp2, result;
8101
8102diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8103index 25849ae..924c54b 100644
8104--- a/arch/sparc/include/asm/thread_info_32.h
8105+++ b/arch/sparc/include/asm/thread_info_32.h
8106@@ -49,6 +49,8 @@ struct thread_info {
8107 unsigned long w_saved;
8108
8109 struct restart_block restart_block;
8110+
8111+ unsigned long lowest_stack;
8112 };
8113
8114 /*
8115diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8116index 269bd92..e46a9b8 100644
8117--- a/arch/sparc/include/asm/thread_info_64.h
8118+++ b/arch/sparc/include/asm/thread_info_64.h
8119@@ -63,6 +63,8 @@ struct thread_info {
8120 struct pt_regs *kern_una_regs;
8121 unsigned int kern_una_insn;
8122
8123+ unsigned long lowest_stack;
8124+
8125 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8126 };
8127
8128@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8129 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8130 /* flag bit 6 is available */
8131 #define TIF_32BIT 7 /* 32-bit binary */
8132-/* flag bit 8 is available */
8133+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8134 #define TIF_SECCOMP 9 /* secure computing */
8135 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8136 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8137+
8138 /* NOTE: Thread flags >= 12 should be ones we have no interest
8139 * in using in assembly, else we can't use the mask as
8140 * an immediate value in instructions such as andcc.
8141@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8142 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8143 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8144 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8145+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8146
8147 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8148 _TIF_DO_NOTIFY_RESUME_MASK | \
8149 _TIF_NEED_RESCHED)
8150 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8151
8152+#define _TIF_WORK_SYSCALL \
8153+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8154+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8155+
8156+
8157 /*
8158 * Thread-synchronous status.
8159 *
8160diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8161index 0167d26..9acd8ed 100644
8162--- a/arch/sparc/include/asm/uaccess.h
8163+++ b/arch/sparc/include/asm/uaccess.h
8164@@ -1,5 +1,13 @@
8165 #ifndef ___ASM_SPARC_UACCESS_H
8166 #define ___ASM_SPARC_UACCESS_H
8167+
8168+#ifdef __KERNEL__
8169+#ifndef __ASSEMBLY__
8170+#include <linux/types.h>
8171+extern void check_object_size(const void *ptr, unsigned long n, bool to);
8172+#endif
8173+#endif
8174+
8175 #if defined(__sparc__) && defined(__arch64__)
8176 #include <asm/uaccess_64.h>
8177 #else
8178diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8179index 53a28dd..50c38c3 100644
8180--- a/arch/sparc/include/asm/uaccess_32.h
8181+++ b/arch/sparc/include/asm/uaccess_32.h
8182@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8183
8184 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8185 {
8186- if (n && __access_ok((unsigned long) to, n))
8187+ if ((long)n < 0)
8188+ return n;
8189+
8190+ if (n && __access_ok((unsigned long) to, n)) {
8191+ if (!__builtin_constant_p(n))
8192+ check_object_size(from, n, true);
8193 return __copy_user(to, (__force void __user *) from, n);
8194- else
8195+ } else
8196 return n;
8197 }
8198
8199 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8200 {
8201+ if ((long)n < 0)
8202+ return n;
8203+
8204+ if (!__builtin_constant_p(n))
8205+ check_object_size(from, n, true);
8206+
8207 return __copy_user(to, (__force void __user *) from, n);
8208 }
8209
8210 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8211 {
8212- if (n && __access_ok((unsigned long) from, n))
8213+ if ((long)n < 0)
8214+ return n;
8215+
8216+ if (n && __access_ok((unsigned long) from, n)) {
8217+ if (!__builtin_constant_p(n))
8218+ check_object_size(to, n, false);
8219 return __copy_user((__force void __user *) to, from, n);
8220- else
8221+ } else
8222 return n;
8223 }
8224
8225 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8226 {
8227+ if ((long)n < 0)
8228+ return n;
8229+
8230 return __copy_user((__force void __user *) to, from, n);
8231 }
8232
8233diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8234index e562d3c..191f176 100644
8235--- a/arch/sparc/include/asm/uaccess_64.h
8236+++ b/arch/sparc/include/asm/uaccess_64.h
8237@@ -10,6 +10,7 @@
8238 #include <linux/compiler.h>
8239 #include <linux/string.h>
8240 #include <linux/thread_info.h>
8241+#include <linux/kernel.h>
8242 #include <asm/asi.h>
8243 #include <asm/spitfire.h>
8244 #include <asm-generic/uaccess-unaligned.h>
8245@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8246 static inline unsigned long __must_check
8247 copy_from_user(void *to, const void __user *from, unsigned long size)
8248 {
8249- unsigned long ret = ___copy_from_user(to, from, size);
8250+ unsigned long ret;
8251
8252+ if ((long)size < 0 || size > INT_MAX)
8253+ return size;
8254+
8255+ if (!__builtin_constant_p(size))
8256+ check_object_size(to, size, false);
8257+
8258+ ret = ___copy_from_user(to, from, size);
8259 if (unlikely(ret))
8260 ret = copy_from_user_fixup(to, from, size);
8261
8262@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8263 static inline unsigned long __must_check
8264 copy_to_user(void __user *to, const void *from, unsigned long size)
8265 {
8266- unsigned long ret = ___copy_to_user(to, from, size);
8267+ unsigned long ret;
8268
8269+ if ((long)size < 0 || size > INT_MAX)
8270+ return size;
8271+
8272+ if (!__builtin_constant_p(size))
8273+ check_object_size(from, size, true);
8274+
8275+ ret = ___copy_to_user(to, from, size);
8276 if (unlikely(ret))
8277 ret = copy_to_user_fixup(to, from, size);
8278 return ret;
8279diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8280index 6cf591b..b49e65a 100644
8281--- a/arch/sparc/kernel/Makefile
8282+++ b/arch/sparc/kernel/Makefile
8283@@ -3,7 +3,7 @@
8284 #
8285
8286 asflags-y := -ansi
8287-ccflags-y := -Werror
8288+#ccflags-y := -Werror
8289
8290 extra-y := head_$(BITS).o
8291
8292diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8293index be8e862..5b50b12 100644
8294--- a/arch/sparc/kernel/process_32.c
8295+++ b/arch/sparc/kernel/process_32.c
8296@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8297
8298 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8299 r->psr, r->pc, r->npc, r->y, print_tainted());
8300- printk("PC: <%pS>\n", (void *) r->pc);
8301+ printk("PC: <%pA>\n", (void *) r->pc);
8302 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8303 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8304 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8305 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8306 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8307 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8308- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8309+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8310
8311 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8312 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8313@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8314 rw = (struct reg_window32 *) fp;
8315 pc = rw->ins[7];
8316 printk("[%08lx : ", pc);
8317- printk("%pS ] ", (void *) pc);
8318+ printk("%pA ] ", (void *) pc);
8319 fp = rw->ins[6];
8320 } while (++count < 16);
8321 printk("\n");
8322diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8323index cdb80b2..5ca141d 100644
8324--- a/arch/sparc/kernel/process_64.c
8325+++ b/arch/sparc/kernel/process_64.c
8326@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8327 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8328 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8329 if (regs->tstate & TSTATE_PRIV)
8330- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8331+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8332 }
8333
8334 void show_regs(struct pt_regs *regs)
8335 {
8336 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8337 regs->tpc, regs->tnpc, regs->y, print_tainted());
8338- printk("TPC: <%pS>\n", (void *) regs->tpc);
8339+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8340 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8341 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8342 regs->u_regs[3]);
8343@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8344 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8345 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8346 regs->u_regs[15]);
8347- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8348+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8349 show_regwindow(regs);
8350 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8351 }
8352@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8353 ((tp && tp->task) ? tp->task->pid : -1));
8354
8355 if (gp->tstate & TSTATE_PRIV) {
8356- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8357+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8358 (void *) gp->tpc,
8359 (void *) gp->o7,
8360 (void *) gp->i7,
8361diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8362index 7ff45e4..a58f271 100644
8363--- a/arch/sparc/kernel/ptrace_64.c
8364+++ b/arch/sparc/kernel/ptrace_64.c
8365@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8366 return ret;
8367 }
8368
8369+#ifdef CONFIG_GRKERNSEC_SETXID
8370+extern void gr_delayed_cred_worker(void);
8371+#endif
8372+
8373 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8374 {
8375 int ret = 0;
8376@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8377 /* do the secure computing check first */
8378 secure_computing_strict(regs->u_regs[UREG_G1]);
8379
8380+#ifdef CONFIG_GRKERNSEC_SETXID
8381+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8382+ gr_delayed_cred_worker();
8383+#endif
8384+
8385 if (test_thread_flag(TIF_SYSCALL_TRACE))
8386 ret = tracehook_report_syscall_entry(regs);
8387
8388@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8389
8390 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8391 {
8392+#ifdef CONFIG_GRKERNSEC_SETXID
8393+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8394+ gr_delayed_cred_worker();
8395+#endif
8396+
8397 audit_syscall_exit(regs);
8398
8399 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8400diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8401index 2da0bdc..79128d2 100644
8402--- a/arch/sparc/kernel/sys_sparc_32.c
8403+++ b/arch/sparc/kernel/sys_sparc_32.c
8404@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8405 if (len > TASK_SIZE - PAGE_SIZE)
8406 return -ENOMEM;
8407 if (!addr)
8408- addr = TASK_UNMAPPED_BASE;
8409+ addr = current->mm->mmap_base;
8410
8411 info.flags = 0;
8412 info.length = len;
8413diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8414index 708bc29..f0129cb 100644
8415--- a/arch/sparc/kernel/sys_sparc_64.c
8416+++ b/arch/sparc/kernel/sys_sparc_64.c
8417@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8418 struct vm_area_struct * vma;
8419 unsigned long task_size = TASK_SIZE;
8420 int do_color_align;
8421+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8422 struct vm_unmapped_area_info info;
8423
8424 if (flags & MAP_FIXED) {
8425 /* We do not accept a shared mapping if it would violate
8426 * cache aliasing constraints.
8427 */
8428- if ((flags & MAP_SHARED) &&
8429+ if ((filp || (flags & MAP_SHARED)) &&
8430 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8431 return -EINVAL;
8432 return addr;
8433@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8434 if (filp || (flags & MAP_SHARED))
8435 do_color_align = 1;
8436
8437+#ifdef CONFIG_PAX_RANDMMAP
8438+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8439+#endif
8440+
8441 if (addr) {
8442 if (do_color_align)
8443 addr = COLOR_ALIGN(addr, pgoff);
8444@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8445 addr = PAGE_ALIGN(addr);
8446
8447 vma = find_vma(mm, addr);
8448- if (task_size - len >= addr &&
8449- (!vma || addr + len <= vma->vm_start))
8450+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8451 return addr;
8452 }
8453
8454 info.flags = 0;
8455 info.length = len;
8456- info.low_limit = TASK_UNMAPPED_BASE;
8457+ info.low_limit = mm->mmap_base;
8458 info.high_limit = min(task_size, VA_EXCLUDE_START);
8459 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8460 info.align_offset = pgoff << PAGE_SHIFT;
8461@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8462 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8463 VM_BUG_ON(addr != -ENOMEM);
8464 info.low_limit = VA_EXCLUDE_END;
8465+
8466+#ifdef CONFIG_PAX_RANDMMAP
8467+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8468+ info.low_limit += mm->delta_mmap;
8469+#endif
8470+
8471 info.high_limit = task_size;
8472 addr = vm_unmapped_area(&info);
8473 }
8474@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8475 unsigned long task_size = STACK_TOP32;
8476 unsigned long addr = addr0;
8477 int do_color_align;
8478+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8479 struct vm_unmapped_area_info info;
8480
8481 /* This should only ever run for 32-bit processes. */
8482@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8483 /* We do not accept a shared mapping if it would violate
8484 * cache aliasing constraints.
8485 */
8486- if ((flags & MAP_SHARED) &&
8487+ if ((filp || (flags & MAP_SHARED)) &&
8488 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8489 return -EINVAL;
8490 return addr;
8491@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8492 if (filp || (flags & MAP_SHARED))
8493 do_color_align = 1;
8494
8495+#ifdef CONFIG_PAX_RANDMMAP
8496+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8497+#endif
8498+
8499 /* requesting a specific address */
8500 if (addr) {
8501 if (do_color_align)
8502@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8503 addr = PAGE_ALIGN(addr);
8504
8505 vma = find_vma(mm, addr);
8506- if (task_size - len >= addr &&
8507- (!vma || addr + len <= vma->vm_start))
8508+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8509 return addr;
8510 }
8511
8512@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8513 VM_BUG_ON(addr != -ENOMEM);
8514 info.flags = 0;
8515 info.low_limit = TASK_UNMAPPED_BASE;
8516+
8517+#ifdef CONFIG_PAX_RANDMMAP
8518+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8519+ info.low_limit += mm->delta_mmap;
8520+#endif
8521+
8522 info.high_limit = STACK_TOP32;
8523 addr = vm_unmapped_area(&info);
8524 }
8525@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8526 {
8527 unsigned long rnd = 0UL;
8528
8529+#ifdef CONFIG_PAX_RANDMMAP
8530+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8531+#endif
8532+
8533 if (current->flags & PF_RANDOMIZE) {
8534 unsigned long val = get_random_int();
8535 if (test_thread_flag(TIF_32BIT))
8536@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8537 gap == RLIM_INFINITY ||
8538 sysctl_legacy_va_layout) {
8539 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8540+
8541+#ifdef CONFIG_PAX_RANDMMAP
8542+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8543+ mm->mmap_base += mm->delta_mmap;
8544+#endif
8545+
8546 mm->get_unmapped_area = arch_get_unmapped_area;
8547 mm->unmap_area = arch_unmap_area;
8548 } else {
8549@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8550 gap = (task_size / 6 * 5);
8551
8552 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8553+
8554+#ifdef CONFIG_PAX_RANDMMAP
8555+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8556+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8557+#endif
8558+
8559 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8560 mm->unmap_area = arch_unmap_area_topdown;
8561 }
8562diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8563index e0fed77..604a7e5 100644
8564--- a/arch/sparc/kernel/syscalls.S
8565+++ b/arch/sparc/kernel/syscalls.S
8566@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8567 #endif
8568 .align 32
8569 1: ldx [%g6 + TI_FLAGS], %l5
8570- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8571+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8572 be,pt %icc, rtrap
8573 nop
8574 call syscall_trace_leave
8575@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8576
8577 srl %i5, 0, %o5 ! IEU1
8578 srl %i2, 0, %o2 ! IEU0 Group
8579- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8580+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8581 bne,pn %icc, linux_syscall_trace32 ! CTI
8582 mov %i0, %l5 ! IEU1
8583 call %l7 ! CTI Group brk forced
8584@@ -213,7 +213,7 @@ linux_sparc_syscall:
8585
8586 mov %i3, %o3 ! IEU1
8587 mov %i4, %o4 ! IEU0 Group
8588- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8589+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8590 bne,pn %icc, linux_syscall_trace ! CTI Group
8591 mov %i0, %l5 ! IEU0
8592 2: call %l7 ! CTI Group brk forced
8593@@ -229,7 +229,7 @@ ret_sys_call:
8594
8595 cmp %o0, -ERESTART_RESTARTBLOCK
8596 bgeu,pn %xcc, 1f
8597- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8598+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8599 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8600
8601 2:
8602diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8603index 654e8aa..45f431b 100644
8604--- a/arch/sparc/kernel/sysfs.c
8605+++ b/arch/sparc/kernel/sysfs.c
8606@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8607 return NOTIFY_OK;
8608 }
8609
8610-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8611+static struct notifier_block sysfs_cpu_nb = {
8612 .notifier_call = sysfs_cpu_notify,
8613 };
8614
8615diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8616index a5785ea..405c5f7 100644
8617--- a/arch/sparc/kernel/traps_32.c
8618+++ b/arch/sparc/kernel/traps_32.c
8619@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8620 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8621 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8622
8623+extern void gr_handle_kernel_exploit(void);
8624+
8625 void die_if_kernel(char *str, struct pt_regs *regs)
8626 {
8627 static int die_counter;
8628@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8629 count++ < 30 &&
8630 (((unsigned long) rw) >= PAGE_OFFSET) &&
8631 !(((unsigned long) rw) & 0x7)) {
8632- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8633+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8634 (void *) rw->ins[7]);
8635 rw = (struct reg_window32 *)rw->ins[6];
8636 }
8637 }
8638 printk("Instruction DUMP:");
8639 instruction_dump ((unsigned long *) regs->pc);
8640- if(regs->psr & PSR_PS)
8641+ if(regs->psr & PSR_PS) {
8642+ gr_handle_kernel_exploit();
8643 do_exit(SIGKILL);
8644+ }
8645 do_exit(SIGSEGV);
8646 }
8647
8648diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8649index e7ecf15..6520e65 100644
8650--- a/arch/sparc/kernel/traps_64.c
8651+++ b/arch/sparc/kernel/traps_64.c
8652@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8653 i + 1,
8654 p->trapstack[i].tstate, p->trapstack[i].tpc,
8655 p->trapstack[i].tnpc, p->trapstack[i].tt);
8656- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8657+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8658 }
8659 }
8660
8661@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8662
8663 lvl -= 0x100;
8664 if (regs->tstate & TSTATE_PRIV) {
8665+
8666+#ifdef CONFIG_PAX_REFCOUNT
8667+ if (lvl == 6)
8668+ pax_report_refcount_overflow(regs);
8669+#endif
8670+
8671 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8672 die_if_kernel(buffer, regs);
8673 }
8674@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8675 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8676 {
8677 char buffer[32];
8678-
8679+
8680 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8681 0, lvl, SIGTRAP) == NOTIFY_STOP)
8682 return;
8683
8684+#ifdef CONFIG_PAX_REFCOUNT
8685+ if (lvl == 6)
8686+ pax_report_refcount_overflow(regs);
8687+#endif
8688+
8689 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8690
8691 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8692@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8693 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8694 printk("%s" "ERROR(%d): ",
8695 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8696- printk("TPC<%pS>\n", (void *) regs->tpc);
8697+ printk("TPC<%pA>\n", (void *) regs->tpc);
8698 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8699 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8700 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8701@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8702 smp_processor_id(),
8703 (type & 0x1) ? 'I' : 'D',
8704 regs->tpc);
8705- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8706+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8707 panic("Irrecoverable Cheetah+ parity error.");
8708 }
8709
8710@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8711 smp_processor_id(),
8712 (type & 0x1) ? 'I' : 'D',
8713 regs->tpc);
8714- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8715+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8716 }
8717
8718 struct sun4v_error_entry {
8719@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8720
8721 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8722 regs->tpc, tl);
8723- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8724+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8725 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8726- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8727+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8728 (void *) regs->u_regs[UREG_I7]);
8729 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8730 "pte[%lx] error[%lx]\n",
8731@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8732
8733 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8734 regs->tpc, tl);
8735- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8736+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8737 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8738- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8739+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8740 (void *) regs->u_regs[UREG_I7]);
8741 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8742 "pte[%lx] error[%lx]\n",
8743@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8744 fp = (unsigned long)sf->fp + STACK_BIAS;
8745 }
8746
8747- printk(" [%016lx] %pS\n", pc, (void *) pc);
8748+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8749 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8750 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8751 int index = tsk->curr_ret_stack;
8752 if (tsk->ret_stack && index >= graph) {
8753 pc = tsk->ret_stack[index - graph].ret;
8754- printk(" [%016lx] %pS\n", pc, (void *) pc);
8755+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8756 graph++;
8757 }
8758 }
8759@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8760 return (struct reg_window *) (fp + STACK_BIAS);
8761 }
8762
8763+extern void gr_handle_kernel_exploit(void);
8764+
8765 void die_if_kernel(char *str, struct pt_regs *regs)
8766 {
8767 static int die_counter;
8768@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8769 while (rw &&
8770 count++ < 30 &&
8771 kstack_valid(tp, (unsigned long) rw)) {
8772- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8773+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8774 (void *) rw->ins[7]);
8775
8776 rw = kernel_stack_up(rw);
8777@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8778 }
8779 user_instruction_dump ((unsigned int __user *) regs->tpc);
8780 }
8781- if (regs->tstate & TSTATE_PRIV)
8782+ if (regs->tstate & TSTATE_PRIV) {
8783+ gr_handle_kernel_exploit();
8784 do_exit(SIGKILL);
8785+ }
8786 do_exit(SIGSEGV);
8787 }
8788 EXPORT_SYMBOL(die_if_kernel);
8789diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8790index 8201c25e..072a2a7 100644
8791--- a/arch/sparc/kernel/unaligned_64.c
8792+++ b/arch/sparc/kernel/unaligned_64.c
8793@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8794 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8795
8796 if (__ratelimit(&ratelimit)) {
8797- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8798+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8799 regs->tpc, (void *) regs->tpc);
8800 }
8801 }
8802diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8803index 8410065f2..4fd4ca22 100644
8804--- a/arch/sparc/lib/Makefile
8805+++ b/arch/sparc/lib/Makefile
8806@@ -2,7 +2,7 @@
8807 #
8808
8809 asflags-y := -ansi -DST_DIV0=0x02
8810-ccflags-y := -Werror
8811+#ccflags-y := -Werror
8812
8813 lib-$(CONFIG_SPARC32) += ashrdi3.o
8814 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8815diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8816index 85c233d..68500e0 100644
8817--- a/arch/sparc/lib/atomic_64.S
8818+++ b/arch/sparc/lib/atomic_64.S
8819@@ -17,7 +17,12 @@
8820 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8821 BACKOFF_SETUP(%o2)
8822 1: lduw [%o1], %g1
8823- add %g1, %o0, %g7
8824+ addcc %g1, %o0, %g7
8825+
8826+#ifdef CONFIG_PAX_REFCOUNT
8827+ tvs %icc, 6
8828+#endif
8829+
8830 cas [%o1], %g1, %g7
8831 cmp %g1, %g7
8832 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8833@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8834 2: BACKOFF_SPIN(%o2, %o3, 1b)
8835 ENDPROC(atomic_add)
8836
8837+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8838+ BACKOFF_SETUP(%o2)
8839+1: lduw [%o1], %g1
8840+ add %g1, %o0, %g7
8841+ cas [%o1], %g1, %g7
8842+ cmp %g1, %g7
8843+ bne,pn %icc, 2f
8844+ nop
8845+ retl
8846+ nop
8847+2: BACKOFF_SPIN(%o2, %o3, 1b)
8848+ENDPROC(atomic_add_unchecked)
8849+
8850 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8851 BACKOFF_SETUP(%o2)
8852 1: lduw [%o1], %g1
8853- sub %g1, %o0, %g7
8854+ subcc %g1, %o0, %g7
8855+
8856+#ifdef CONFIG_PAX_REFCOUNT
8857+ tvs %icc, 6
8858+#endif
8859+
8860 cas [%o1], %g1, %g7
8861 cmp %g1, %g7
8862 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8863@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8864 2: BACKOFF_SPIN(%o2, %o3, 1b)
8865 ENDPROC(atomic_sub)
8866
8867+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8868+ BACKOFF_SETUP(%o2)
8869+1: lduw [%o1], %g1
8870+ sub %g1, %o0, %g7
8871+ cas [%o1], %g1, %g7
8872+ cmp %g1, %g7
8873+ bne,pn %icc, 2f
8874+ nop
8875+ retl
8876+ nop
8877+2: BACKOFF_SPIN(%o2, %o3, 1b)
8878+ENDPROC(atomic_sub_unchecked)
8879+
8880 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8881 BACKOFF_SETUP(%o2)
8882 1: lduw [%o1], %g1
8883- add %g1, %o0, %g7
8884+ addcc %g1, %o0, %g7
8885+
8886+#ifdef CONFIG_PAX_REFCOUNT
8887+ tvs %icc, 6
8888+#endif
8889+
8890 cas [%o1], %g1, %g7
8891 cmp %g1, %g7
8892 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8893@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8894 2: BACKOFF_SPIN(%o2, %o3, 1b)
8895 ENDPROC(atomic_add_ret)
8896
8897+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8898+ BACKOFF_SETUP(%o2)
8899+1: lduw [%o1], %g1
8900+ addcc %g1, %o0, %g7
8901+ cas [%o1], %g1, %g7
8902+ cmp %g1, %g7
8903+ bne,pn %icc, 2f
8904+ add %g7, %o0, %g7
8905+ sra %g7, 0, %o0
8906+ retl
8907+ nop
8908+2: BACKOFF_SPIN(%o2, %o3, 1b)
8909+ENDPROC(atomic_add_ret_unchecked)
8910+
8911 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8912 BACKOFF_SETUP(%o2)
8913 1: lduw [%o1], %g1
8914- sub %g1, %o0, %g7
8915+ subcc %g1, %o0, %g7
8916+
8917+#ifdef CONFIG_PAX_REFCOUNT
8918+ tvs %icc, 6
8919+#endif
8920+
8921 cas [%o1], %g1, %g7
8922 cmp %g1, %g7
8923 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8924@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8925 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8926 BACKOFF_SETUP(%o2)
8927 1: ldx [%o1], %g1
8928- add %g1, %o0, %g7
8929+ addcc %g1, %o0, %g7
8930+
8931+#ifdef CONFIG_PAX_REFCOUNT
8932+ tvs %xcc, 6
8933+#endif
8934+
8935 casx [%o1], %g1, %g7
8936 cmp %g1, %g7
8937 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8938@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8939 2: BACKOFF_SPIN(%o2, %o3, 1b)
8940 ENDPROC(atomic64_add)
8941
8942+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8943+ BACKOFF_SETUP(%o2)
8944+1: ldx [%o1], %g1
8945+ addcc %g1, %o0, %g7
8946+ casx [%o1], %g1, %g7
8947+ cmp %g1, %g7
8948+ bne,pn %xcc, 2f
8949+ nop
8950+ retl
8951+ nop
8952+2: BACKOFF_SPIN(%o2, %o3, 1b)
8953+ENDPROC(atomic64_add_unchecked)
8954+
8955 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8956 BACKOFF_SETUP(%o2)
8957 1: ldx [%o1], %g1
8958- sub %g1, %o0, %g7
8959+ subcc %g1, %o0, %g7
8960+
8961+#ifdef CONFIG_PAX_REFCOUNT
8962+ tvs %xcc, 6
8963+#endif
8964+
8965 casx [%o1], %g1, %g7
8966 cmp %g1, %g7
8967 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8968@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8969 2: BACKOFF_SPIN(%o2, %o3, 1b)
8970 ENDPROC(atomic64_sub)
8971
8972+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8973+ BACKOFF_SETUP(%o2)
8974+1: ldx [%o1], %g1
8975+ subcc %g1, %o0, %g7
8976+ casx [%o1], %g1, %g7
8977+ cmp %g1, %g7
8978+ bne,pn %xcc, 2f
8979+ nop
8980+ retl
8981+ nop
8982+2: BACKOFF_SPIN(%o2, %o3, 1b)
8983+ENDPROC(atomic64_sub_unchecked)
8984+
8985 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8986 BACKOFF_SETUP(%o2)
8987 1: ldx [%o1], %g1
8988- add %g1, %o0, %g7
8989+ addcc %g1, %o0, %g7
8990+
8991+#ifdef CONFIG_PAX_REFCOUNT
8992+ tvs %xcc, 6
8993+#endif
8994+
8995 casx [%o1], %g1, %g7
8996 cmp %g1, %g7
8997 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8998@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8999 2: BACKOFF_SPIN(%o2, %o3, 1b)
9000 ENDPROC(atomic64_add_ret)
9001
9002+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9003+ BACKOFF_SETUP(%o2)
9004+1: ldx [%o1], %g1
9005+ addcc %g1, %o0, %g7
9006+ casx [%o1], %g1, %g7
9007+ cmp %g1, %g7
9008+ bne,pn %xcc, 2f
9009+ add %g7, %o0, %g7
9010+ mov %g7, %o0
9011+ retl
9012+ nop
9013+2: BACKOFF_SPIN(%o2, %o3, 1b)
9014+ENDPROC(atomic64_add_ret_unchecked)
9015+
9016 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9017 BACKOFF_SETUP(%o2)
9018 1: ldx [%o1], %g1
9019- sub %g1, %o0, %g7
9020+ subcc %g1, %o0, %g7
9021+
9022+#ifdef CONFIG_PAX_REFCOUNT
9023+ tvs %xcc, 6
9024+#endif
9025+
9026 casx [%o1], %g1, %g7
9027 cmp %g1, %g7
9028 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9029diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9030index 0c4e35e..745d3e4 100644
9031--- a/arch/sparc/lib/ksyms.c
9032+++ b/arch/sparc/lib/ksyms.c
9033@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9034
9035 /* Atomic counter implementation. */
9036 EXPORT_SYMBOL(atomic_add);
9037+EXPORT_SYMBOL(atomic_add_unchecked);
9038 EXPORT_SYMBOL(atomic_add_ret);
9039+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9040 EXPORT_SYMBOL(atomic_sub);
9041+EXPORT_SYMBOL(atomic_sub_unchecked);
9042 EXPORT_SYMBOL(atomic_sub_ret);
9043 EXPORT_SYMBOL(atomic64_add);
9044+EXPORT_SYMBOL(atomic64_add_unchecked);
9045 EXPORT_SYMBOL(atomic64_add_ret);
9046+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9047 EXPORT_SYMBOL(atomic64_sub);
9048+EXPORT_SYMBOL(atomic64_sub_unchecked);
9049 EXPORT_SYMBOL(atomic64_sub_ret);
9050 EXPORT_SYMBOL(atomic64_dec_if_positive);
9051
9052diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9053index 30c3ecc..736f015 100644
9054--- a/arch/sparc/mm/Makefile
9055+++ b/arch/sparc/mm/Makefile
9056@@ -2,7 +2,7 @@
9057 #
9058
9059 asflags-y := -ansi
9060-ccflags-y := -Werror
9061+#ccflags-y := -Werror
9062
9063 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9064 obj-y += fault_$(BITS).o
9065diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9066index e98bfda..ea8d221 100644
9067--- a/arch/sparc/mm/fault_32.c
9068+++ b/arch/sparc/mm/fault_32.c
9069@@ -21,6 +21,9 @@
9070 #include <linux/perf_event.h>
9071 #include <linux/interrupt.h>
9072 #include <linux/kdebug.h>
9073+#include <linux/slab.h>
9074+#include <linux/pagemap.h>
9075+#include <linux/compiler.h>
9076
9077 #include <asm/page.h>
9078 #include <asm/pgtable.h>
9079@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9080 return safe_compute_effective_address(regs, insn);
9081 }
9082
9083+#ifdef CONFIG_PAX_PAGEEXEC
9084+#ifdef CONFIG_PAX_DLRESOLVE
9085+static void pax_emuplt_close(struct vm_area_struct *vma)
9086+{
9087+ vma->vm_mm->call_dl_resolve = 0UL;
9088+}
9089+
9090+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9091+{
9092+ unsigned int *kaddr;
9093+
9094+ vmf->page = alloc_page(GFP_HIGHUSER);
9095+ if (!vmf->page)
9096+ return VM_FAULT_OOM;
9097+
9098+ kaddr = kmap(vmf->page);
9099+ memset(kaddr, 0, PAGE_SIZE);
9100+ kaddr[0] = 0x9DE3BFA8U; /* save */
9101+ flush_dcache_page(vmf->page);
9102+ kunmap(vmf->page);
9103+ return VM_FAULT_MAJOR;
9104+}
9105+
9106+static const struct vm_operations_struct pax_vm_ops = {
9107+ .close = pax_emuplt_close,
9108+ .fault = pax_emuplt_fault
9109+};
9110+
9111+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9112+{
9113+ int ret;
9114+
9115+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9116+ vma->vm_mm = current->mm;
9117+ vma->vm_start = addr;
9118+ vma->vm_end = addr + PAGE_SIZE;
9119+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9120+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9121+ vma->vm_ops = &pax_vm_ops;
9122+
9123+ ret = insert_vm_struct(current->mm, vma);
9124+ if (ret)
9125+ return ret;
9126+
9127+ ++current->mm->total_vm;
9128+ return 0;
9129+}
9130+#endif
9131+
9132+/*
9133+ * PaX: decide what to do with offenders (regs->pc = fault address)
9134+ *
9135+ * returns 1 when task should be killed
9136+ * 2 when patched PLT trampoline was detected
9137+ * 3 when unpatched PLT trampoline was detected
9138+ */
9139+static int pax_handle_fetch_fault(struct pt_regs *regs)
9140+{
9141+
9142+#ifdef CONFIG_PAX_EMUPLT
9143+ int err;
9144+
9145+ do { /* PaX: patched PLT emulation #1 */
9146+ unsigned int sethi1, sethi2, jmpl;
9147+
9148+ err = get_user(sethi1, (unsigned int *)regs->pc);
9149+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9150+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9151+
9152+ if (err)
9153+ break;
9154+
9155+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9156+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9157+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9158+ {
9159+ unsigned int addr;
9160+
9161+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9162+ addr = regs->u_regs[UREG_G1];
9163+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9164+ regs->pc = addr;
9165+ regs->npc = addr+4;
9166+ return 2;
9167+ }
9168+ } while (0);
9169+
9170+ do { /* PaX: patched PLT emulation #2 */
9171+ unsigned int ba;
9172+
9173+ err = get_user(ba, (unsigned int *)regs->pc);
9174+
9175+ if (err)
9176+ break;
9177+
9178+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9179+ unsigned int addr;
9180+
9181+ if ((ba & 0xFFC00000U) == 0x30800000U)
9182+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9183+ else
9184+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9185+ regs->pc = addr;
9186+ regs->npc = addr+4;
9187+ return 2;
9188+ }
9189+ } while (0);
9190+
9191+ do { /* PaX: patched PLT emulation #3 */
9192+ unsigned int sethi, bajmpl, nop;
9193+
9194+ err = get_user(sethi, (unsigned int *)regs->pc);
9195+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9196+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9197+
9198+ if (err)
9199+ break;
9200+
9201+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9202+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9203+ nop == 0x01000000U)
9204+ {
9205+ unsigned int addr;
9206+
9207+ addr = (sethi & 0x003FFFFFU) << 10;
9208+ regs->u_regs[UREG_G1] = addr;
9209+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9210+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9211+ else
9212+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9213+ regs->pc = addr;
9214+ regs->npc = addr+4;
9215+ return 2;
9216+ }
9217+ } while (0);
9218+
9219+ do { /* PaX: unpatched PLT emulation step 1 */
9220+ unsigned int sethi, ba, nop;
9221+
9222+ err = get_user(sethi, (unsigned int *)regs->pc);
9223+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9224+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9225+
9226+ if (err)
9227+ break;
9228+
9229+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9230+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9231+ nop == 0x01000000U)
9232+ {
9233+ unsigned int addr, save, call;
9234+
9235+ if ((ba & 0xFFC00000U) == 0x30800000U)
9236+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9237+ else
9238+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9239+
9240+ err = get_user(save, (unsigned int *)addr);
9241+ err |= get_user(call, (unsigned int *)(addr+4));
9242+ err |= get_user(nop, (unsigned int *)(addr+8));
9243+ if (err)
9244+ break;
9245+
9246+#ifdef CONFIG_PAX_DLRESOLVE
9247+ if (save == 0x9DE3BFA8U &&
9248+ (call & 0xC0000000U) == 0x40000000U &&
9249+ nop == 0x01000000U)
9250+ {
9251+ struct vm_area_struct *vma;
9252+ unsigned long call_dl_resolve;
9253+
9254+ down_read(&current->mm->mmap_sem);
9255+ call_dl_resolve = current->mm->call_dl_resolve;
9256+ up_read(&current->mm->mmap_sem);
9257+ if (likely(call_dl_resolve))
9258+ goto emulate;
9259+
9260+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9261+
9262+ down_write(&current->mm->mmap_sem);
9263+ if (current->mm->call_dl_resolve) {
9264+ call_dl_resolve = current->mm->call_dl_resolve;
9265+ up_write(&current->mm->mmap_sem);
9266+ if (vma)
9267+ kmem_cache_free(vm_area_cachep, vma);
9268+ goto emulate;
9269+ }
9270+
9271+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9272+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9273+ up_write(&current->mm->mmap_sem);
9274+ if (vma)
9275+ kmem_cache_free(vm_area_cachep, vma);
9276+ return 1;
9277+ }
9278+
9279+ if (pax_insert_vma(vma, call_dl_resolve)) {
9280+ up_write(&current->mm->mmap_sem);
9281+ kmem_cache_free(vm_area_cachep, vma);
9282+ return 1;
9283+ }
9284+
9285+ current->mm->call_dl_resolve = call_dl_resolve;
9286+ up_write(&current->mm->mmap_sem);
9287+
9288+emulate:
9289+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9290+ regs->pc = call_dl_resolve;
9291+ regs->npc = addr+4;
9292+ return 3;
9293+ }
9294+#endif
9295+
9296+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9297+ if ((save & 0xFFC00000U) == 0x05000000U &&
9298+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9299+ nop == 0x01000000U)
9300+ {
9301+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9302+ regs->u_regs[UREG_G2] = addr + 4;
9303+ addr = (save & 0x003FFFFFU) << 10;
9304+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9305+ regs->pc = addr;
9306+ regs->npc = addr+4;
9307+ return 3;
9308+ }
9309+ }
9310+ } while (0);
9311+
9312+ do { /* PaX: unpatched PLT emulation step 2 */
9313+ unsigned int save, call, nop;
9314+
9315+ err = get_user(save, (unsigned int *)(regs->pc-4));
9316+ err |= get_user(call, (unsigned int *)regs->pc);
9317+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9318+ if (err)
9319+ break;
9320+
9321+ if (save == 0x9DE3BFA8U &&
9322+ (call & 0xC0000000U) == 0x40000000U &&
9323+ nop == 0x01000000U)
9324+ {
9325+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9326+
9327+ regs->u_regs[UREG_RETPC] = regs->pc;
9328+ regs->pc = dl_resolve;
9329+ regs->npc = dl_resolve+4;
9330+ return 3;
9331+ }
9332+ } while (0);
9333+#endif
9334+
9335+ return 1;
9336+}
9337+
9338+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9339+{
9340+ unsigned long i;
9341+
9342+ printk(KERN_ERR "PAX: bytes at PC: ");
9343+ for (i = 0; i < 8; i++) {
9344+ unsigned int c;
9345+ if (get_user(c, (unsigned int *)pc+i))
9346+ printk(KERN_CONT "???????? ");
9347+ else
9348+ printk(KERN_CONT "%08x ", c);
9349+ }
9350+ printk("\n");
9351+}
9352+#endif
9353+
9354 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9355 int text_fault)
9356 {
9357@@ -230,6 +504,24 @@ good_area:
9358 if (!(vma->vm_flags & VM_WRITE))
9359 goto bad_area;
9360 } else {
9361+
9362+#ifdef CONFIG_PAX_PAGEEXEC
9363+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9364+ up_read(&mm->mmap_sem);
9365+ switch (pax_handle_fetch_fault(regs)) {
9366+
9367+#ifdef CONFIG_PAX_EMUPLT
9368+ case 2:
9369+ case 3:
9370+ return;
9371+#endif
9372+
9373+ }
9374+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9375+ do_group_exit(SIGKILL);
9376+ }
9377+#endif
9378+
9379 /* Allow reads even for write-only mappings */
9380 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9381 goto bad_area;
9382diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9383index 5062ff3..e0b75f3 100644
9384--- a/arch/sparc/mm/fault_64.c
9385+++ b/arch/sparc/mm/fault_64.c
9386@@ -21,6 +21,9 @@
9387 #include <linux/kprobes.h>
9388 #include <linux/kdebug.h>
9389 #include <linux/percpu.h>
9390+#include <linux/slab.h>
9391+#include <linux/pagemap.h>
9392+#include <linux/compiler.h>
9393
9394 #include <asm/page.h>
9395 #include <asm/pgtable.h>
9396@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9397 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9398 regs->tpc);
9399 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9400- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9401+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9402 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9403 dump_stack();
9404 unhandled_fault(regs->tpc, current, regs);
9405@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9406 show_regs(regs);
9407 }
9408
9409+#ifdef CONFIG_PAX_PAGEEXEC
9410+#ifdef CONFIG_PAX_DLRESOLVE
9411+static void pax_emuplt_close(struct vm_area_struct *vma)
9412+{
9413+ vma->vm_mm->call_dl_resolve = 0UL;
9414+}
9415+
9416+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9417+{
9418+ unsigned int *kaddr;
9419+
9420+ vmf->page = alloc_page(GFP_HIGHUSER);
9421+ if (!vmf->page)
9422+ return VM_FAULT_OOM;
9423+
9424+ kaddr = kmap(vmf->page);
9425+ memset(kaddr, 0, PAGE_SIZE);
9426+ kaddr[0] = 0x9DE3BFA8U; /* save */
9427+ flush_dcache_page(vmf->page);
9428+ kunmap(vmf->page);
9429+ return VM_FAULT_MAJOR;
9430+}
9431+
9432+static const struct vm_operations_struct pax_vm_ops = {
9433+ .close = pax_emuplt_close,
9434+ .fault = pax_emuplt_fault
9435+};
9436+
9437+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9438+{
9439+ int ret;
9440+
9441+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9442+ vma->vm_mm = current->mm;
9443+ vma->vm_start = addr;
9444+ vma->vm_end = addr + PAGE_SIZE;
9445+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9446+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9447+ vma->vm_ops = &pax_vm_ops;
9448+
9449+ ret = insert_vm_struct(current->mm, vma);
9450+ if (ret)
9451+ return ret;
9452+
9453+ ++current->mm->total_vm;
9454+ return 0;
9455+}
9456+#endif
9457+
9458+/*
9459+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9460+ *
9461+ * returns 1 when task should be killed
9462+ * 2 when patched PLT trampoline was detected
9463+ * 3 when unpatched PLT trampoline was detected
9464+ */
9465+static int pax_handle_fetch_fault(struct pt_regs *regs)
9466+{
9467+
9468+#ifdef CONFIG_PAX_EMUPLT
9469+ int err;
9470+
9471+ do { /* PaX: patched PLT emulation #1 */
9472+ unsigned int sethi1, sethi2, jmpl;
9473+
9474+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9475+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9476+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9477+
9478+ if (err)
9479+ break;
9480+
9481+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9482+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9483+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9484+ {
9485+ unsigned long addr;
9486+
9487+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9488+ addr = regs->u_regs[UREG_G1];
9489+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9490+
9491+ if (test_thread_flag(TIF_32BIT))
9492+ addr &= 0xFFFFFFFFUL;
9493+
9494+ regs->tpc = addr;
9495+ regs->tnpc = addr+4;
9496+ return 2;
9497+ }
9498+ } while (0);
9499+
9500+ do { /* PaX: patched PLT emulation #2 */
9501+ unsigned int ba;
9502+
9503+ err = get_user(ba, (unsigned int *)regs->tpc);
9504+
9505+ if (err)
9506+ break;
9507+
9508+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9509+ unsigned long addr;
9510+
9511+ if ((ba & 0xFFC00000U) == 0x30800000U)
9512+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9513+ else
9514+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9515+
9516+ if (test_thread_flag(TIF_32BIT))
9517+ addr &= 0xFFFFFFFFUL;
9518+
9519+ regs->tpc = addr;
9520+ regs->tnpc = addr+4;
9521+ return 2;
9522+ }
9523+ } while (0);
9524+
9525+ do { /* PaX: patched PLT emulation #3 */
9526+ unsigned int sethi, bajmpl, nop;
9527+
9528+ err = get_user(sethi, (unsigned int *)regs->tpc);
9529+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9530+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9531+
9532+ if (err)
9533+ break;
9534+
9535+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9536+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9537+ nop == 0x01000000U)
9538+ {
9539+ unsigned long addr;
9540+
9541+ addr = (sethi & 0x003FFFFFU) << 10;
9542+ regs->u_regs[UREG_G1] = addr;
9543+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9544+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9545+ else
9546+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9547+
9548+ if (test_thread_flag(TIF_32BIT))
9549+ addr &= 0xFFFFFFFFUL;
9550+
9551+ regs->tpc = addr;
9552+ regs->tnpc = addr+4;
9553+ return 2;
9554+ }
9555+ } while (0);
9556+
9557+ do { /* PaX: patched PLT emulation #4 */
9558+ unsigned int sethi, mov1, call, mov2;
9559+
9560+ err = get_user(sethi, (unsigned int *)regs->tpc);
9561+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9562+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9563+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9564+
9565+ if (err)
9566+ break;
9567+
9568+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9569+ mov1 == 0x8210000FU &&
9570+ (call & 0xC0000000U) == 0x40000000U &&
9571+ mov2 == 0x9E100001U)
9572+ {
9573+ unsigned long addr;
9574+
9575+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9576+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9577+
9578+ if (test_thread_flag(TIF_32BIT))
9579+ addr &= 0xFFFFFFFFUL;
9580+
9581+ regs->tpc = addr;
9582+ regs->tnpc = addr+4;
9583+ return 2;
9584+ }
9585+ } while (0);
9586+
9587+ do { /* PaX: patched PLT emulation #5 */
9588+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9589+
9590+ err = get_user(sethi, (unsigned int *)regs->tpc);
9591+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9592+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9593+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9594+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9595+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9596+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9597+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9598+
9599+ if (err)
9600+ break;
9601+
9602+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9603+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9604+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9605+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9606+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9607+ sllx == 0x83287020U &&
9608+ jmpl == 0x81C04005U &&
9609+ nop == 0x01000000U)
9610+ {
9611+ unsigned long addr;
9612+
9613+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9614+ regs->u_regs[UREG_G1] <<= 32;
9615+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9616+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9617+ regs->tpc = addr;
9618+ regs->tnpc = addr+4;
9619+ return 2;
9620+ }
9621+ } while (0);
9622+
9623+ do { /* PaX: patched PLT emulation #6 */
9624+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9625+
9626+ err = get_user(sethi, (unsigned int *)regs->tpc);
9627+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9628+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9629+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9630+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9631+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9632+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9633+
9634+ if (err)
9635+ break;
9636+
9637+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9638+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9639+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9640+ sllx == 0x83287020U &&
9641+ (or & 0xFFFFE000U) == 0x8A116000U &&
9642+ jmpl == 0x81C04005U &&
9643+ nop == 0x01000000U)
9644+ {
9645+ unsigned long addr;
9646+
9647+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9648+ regs->u_regs[UREG_G1] <<= 32;
9649+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9650+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9651+ regs->tpc = addr;
9652+ regs->tnpc = addr+4;
9653+ return 2;
9654+ }
9655+ } while (0);
9656+
9657+ do { /* PaX: unpatched PLT emulation step 1 */
9658+ unsigned int sethi, ba, nop;
9659+
9660+ err = get_user(sethi, (unsigned int *)regs->tpc);
9661+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9662+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9663+
9664+ if (err)
9665+ break;
9666+
9667+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9668+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9669+ nop == 0x01000000U)
9670+ {
9671+ unsigned long addr;
9672+ unsigned int save, call;
9673+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9674+
9675+ if ((ba & 0xFFC00000U) == 0x30800000U)
9676+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9677+ else
9678+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9679+
9680+ if (test_thread_flag(TIF_32BIT))
9681+ addr &= 0xFFFFFFFFUL;
9682+
9683+ err = get_user(save, (unsigned int *)addr);
9684+ err |= get_user(call, (unsigned int *)(addr+4));
9685+ err |= get_user(nop, (unsigned int *)(addr+8));
9686+ if (err)
9687+ break;
9688+
9689+#ifdef CONFIG_PAX_DLRESOLVE
9690+ if (save == 0x9DE3BFA8U &&
9691+ (call & 0xC0000000U) == 0x40000000U &&
9692+ nop == 0x01000000U)
9693+ {
9694+ struct vm_area_struct *vma;
9695+ unsigned long call_dl_resolve;
9696+
9697+ down_read(&current->mm->mmap_sem);
9698+ call_dl_resolve = current->mm->call_dl_resolve;
9699+ up_read(&current->mm->mmap_sem);
9700+ if (likely(call_dl_resolve))
9701+ goto emulate;
9702+
9703+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9704+
9705+ down_write(&current->mm->mmap_sem);
9706+ if (current->mm->call_dl_resolve) {
9707+ call_dl_resolve = current->mm->call_dl_resolve;
9708+ up_write(&current->mm->mmap_sem);
9709+ if (vma)
9710+ kmem_cache_free(vm_area_cachep, vma);
9711+ goto emulate;
9712+ }
9713+
9714+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9715+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9716+ up_write(&current->mm->mmap_sem);
9717+ if (vma)
9718+ kmem_cache_free(vm_area_cachep, vma);
9719+ return 1;
9720+ }
9721+
9722+ if (pax_insert_vma(vma, call_dl_resolve)) {
9723+ up_write(&current->mm->mmap_sem);
9724+ kmem_cache_free(vm_area_cachep, vma);
9725+ return 1;
9726+ }
9727+
9728+ current->mm->call_dl_resolve = call_dl_resolve;
9729+ up_write(&current->mm->mmap_sem);
9730+
9731+emulate:
9732+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9733+ regs->tpc = call_dl_resolve;
9734+ regs->tnpc = addr+4;
9735+ return 3;
9736+ }
9737+#endif
9738+
9739+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9740+ if ((save & 0xFFC00000U) == 0x05000000U &&
9741+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9742+ nop == 0x01000000U)
9743+ {
9744+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9745+ regs->u_regs[UREG_G2] = addr + 4;
9746+ addr = (save & 0x003FFFFFU) << 10;
9747+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9748+
9749+ if (test_thread_flag(TIF_32BIT))
9750+ addr &= 0xFFFFFFFFUL;
9751+
9752+ regs->tpc = addr;
9753+ regs->tnpc = addr+4;
9754+ return 3;
9755+ }
9756+
9757+ /* PaX: 64-bit PLT stub */
9758+ err = get_user(sethi1, (unsigned int *)addr);
9759+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9760+ err |= get_user(or1, (unsigned int *)(addr+8));
9761+ err |= get_user(or2, (unsigned int *)(addr+12));
9762+ err |= get_user(sllx, (unsigned int *)(addr+16));
9763+ err |= get_user(add, (unsigned int *)(addr+20));
9764+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9765+ err |= get_user(nop, (unsigned int *)(addr+28));
9766+ if (err)
9767+ break;
9768+
9769+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9770+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9771+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9772+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9773+ sllx == 0x89293020U &&
9774+ add == 0x8A010005U &&
9775+ jmpl == 0x89C14000U &&
9776+ nop == 0x01000000U)
9777+ {
9778+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9779+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9780+ regs->u_regs[UREG_G4] <<= 32;
9781+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9782+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9783+ regs->u_regs[UREG_G4] = addr + 24;
9784+ addr = regs->u_regs[UREG_G5];
9785+ regs->tpc = addr;
9786+ regs->tnpc = addr+4;
9787+ return 3;
9788+ }
9789+ }
9790+ } while (0);
9791+
9792+#ifdef CONFIG_PAX_DLRESOLVE
9793+ do { /* PaX: unpatched PLT emulation step 2 */
9794+ unsigned int save, call, nop;
9795+
9796+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9797+ err |= get_user(call, (unsigned int *)regs->tpc);
9798+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9799+ if (err)
9800+ break;
9801+
9802+ if (save == 0x9DE3BFA8U &&
9803+ (call & 0xC0000000U) == 0x40000000U &&
9804+ nop == 0x01000000U)
9805+ {
9806+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9807+
9808+ if (test_thread_flag(TIF_32BIT))
9809+ dl_resolve &= 0xFFFFFFFFUL;
9810+
9811+ regs->u_regs[UREG_RETPC] = regs->tpc;
9812+ regs->tpc = dl_resolve;
9813+ regs->tnpc = dl_resolve+4;
9814+ return 3;
9815+ }
9816+ } while (0);
9817+#endif
9818+
9819+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9820+ unsigned int sethi, ba, nop;
9821+
9822+ err = get_user(sethi, (unsigned int *)regs->tpc);
9823+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9824+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9825+
9826+ if (err)
9827+ break;
9828+
9829+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9830+ (ba & 0xFFF00000U) == 0x30600000U &&
9831+ nop == 0x01000000U)
9832+ {
9833+ unsigned long addr;
9834+
9835+ addr = (sethi & 0x003FFFFFU) << 10;
9836+ regs->u_regs[UREG_G1] = addr;
9837+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9838+
9839+ if (test_thread_flag(TIF_32BIT))
9840+ addr &= 0xFFFFFFFFUL;
9841+
9842+ regs->tpc = addr;
9843+ regs->tnpc = addr+4;
9844+ return 2;
9845+ }
9846+ } while (0);
9847+
9848+#endif
9849+
9850+ return 1;
9851+}
9852+
9853+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9854+{
9855+ unsigned long i;
9856+
9857+ printk(KERN_ERR "PAX: bytes at PC: ");
9858+ for (i = 0; i < 8; i++) {
9859+ unsigned int c;
9860+ if (get_user(c, (unsigned int *)pc+i))
9861+ printk(KERN_CONT "???????? ");
9862+ else
9863+ printk(KERN_CONT "%08x ", c);
9864+ }
9865+ printk("\n");
9866+}
9867+#endif
9868+
9869 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9870 {
9871 struct mm_struct *mm = current->mm;
9872@@ -341,6 +804,29 @@ retry:
9873 if (!vma)
9874 goto bad_area;
9875
9876+#ifdef CONFIG_PAX_PAGEEXEC
9877+ /* PaX: detect ITLB misses on non-exec pages */
9878+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9879+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9880+ {
9881+ if (address != regs->tpc)
9882+ goto good_area;
9883+
9884+ up_read(&mm->mmap_sem);
9885+ switch (pax_handle_fetch_fault(regs)) {
9886+
9887+#ifdef CONFIG_PAX_EMUPLT
9888+ case 2:
9889+ case 3:
9890+ return;
9891+#endif
9892+
9893+ }
9894+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9895+ do_group_exit(SIGKILL);
9896+ }
9897+#endif
9898+
9899 /* Pure DTLB misses do not tell us whether the fault causing
9900 * load/store/atomic was a write or not, it only says that there
9901 * was no match. So in such a case we (carefully) read the
9902diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9903index d2b5944..bd813f2 100644
9904--- a/arch/sparc/mm/hugetlbpage.c
9905+++ b/arch/sparc/mm/hugetlbpage.c
9906@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9907
9908 info.flags = 0;
9909 info.length = len;
9910- info.low_limit = TASK_UNMAPPED_BASE;
9911+ info.low_limit = mm->mmap_base;
9912 info.high_limit = min(task_size, VA_EXCLUDE_START);
9913 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9914 info.align_offset = 0;
9915@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9916 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9917 VM_BUG_ON(addr != -ENOMEM);
9918 info.low_limit = VA_EXCLUDE_END;
9919+
9920+#ifdef CONFIG_PAX_RANDMMAP
9921+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9922+ info.low_limit += mm->delta_mmap;
9923+#endif
9924+
9925 info.high_limit = task_size;
9926 addr = vm_unmapped_area(&info);
9927 }
9928@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9929 VM_BUG_ON(addr != -ENOMEM);
9930 info.flags = 0;
9931 info.low_limit = TASK_UNMAPPED_BASE;
9932+
9933+#ifdef CONFIG_PAX_RANDMMAP
9934+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9935+ info.low_limit += mm->delta_mmap;
9936+#endif
9937+
9938 info.high_limit = STACK_TOP32;
9939 addr = vm_unmapped_area(&info);
9940 }
9941@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9942 struct mm_struct *mm = current->mm;
9943 struct vm_area_struct *vma;
9944 unsigned long task_size = TASK_SIZE;
9945+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9946
9947 if (test_thread_flag(TIF_32BIT))
9948 task_size = STACK_TOP32;
9949@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9950 return addr;
9951 }
9952
9953+#ifdef CONFIG_PAX_RANDMMAP
9954+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9955+#endif
9956+
9957 if (addr) {
9958 addr = ALIGN(addr, HPAGE_SIZE);
9959 vma = find_vma(mm, addr);
9960- if (task_size - len >= addr &&
9961- (!vma || addr + len <= vma->vm_start))
9962+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9963 return addr;
9964 }
9965 if (mm->get_unmapped_area == arch_get_unmapped_area)
9966diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9967index f4500c6..889656c 100644
9968--- a/arch/tile/include/asm/atomic_64.h
9969+++ b/arch/tile/include/asm/atomic_64.h
9970@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9971
9972 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9973
9974+#define atomic64_read_unchecked(v) atomic64_read(v)
9975+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9976+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9977+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9978+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9979+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9980+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9981+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9982+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9983+
9984 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9985 #define smp_mb__before_atomic_dec() smp_mb()
9986 #define smp_mb__after_atomic_dec() smp_mb()
9987diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9988index a9a5299..0fce79e 100644
9989--- a/arch/tile/include/asm/cache.h
9990+++ b/arch/tile/include/asm/cache.h
9991@@ -15,11 +15,12 @@
9992 #ifndef _ASM_TILE_CACHE_H
9993 #define _ASM_TILE_CACHE_H
9994
9995+#include <linux/const.h>
9996 #include <arch/chip.h>
9997
9998 /* bytes per L1 data cache line */
9999 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10000-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10001+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10002
10003 /* bytes per L2 cache line */
10004 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10005diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10006index 9ab078a..d6635c2 100644
10007--- a/arch/tile/include/asm/uaccess.h
10008+++ b/arch/tile/include/asm/uaccess.h
10009@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10010 const void __user *from,
10011 unsigned long n)
10012 {
10013- int sz = __compiletime_object_size(to);
10014+ size_t sz = __compiletime_object_size(to);
10015
10016- if (likely(sz == -1 || sz >= n))
10017+ if (likely(sz == (size_t)-1 || sz >= n))
10018 n = _copy_from_user(to, from, n);
10019 else
10020 copy_from_user_overflow();
10021diff --git a/arch/um/Makefile b/arch/um/Makefile
10022index 133f7de..1d6f2f1 100644
10023--- a/arch/um/Makefile
10024+++ b/arch/um/Makefile
10025@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10026 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10027 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10028
10029+ifdef CONSTIFY_PLUGIN
10030+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10031+endif
10032+
10033 #This will adjust *FLAGS accordingly to the platform.
10034 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10035
10036diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10037index 19e1bdd..3665b77 100644
10038--- a/arch/um/include/asm/cache.h
10039+++ b/arch/um/include/asm/cache.h
10040@@ -1,6 +1,7 @@
10041 #ifndef __UM_CACHE_H
10042 #define __UM_CACHE_H
10043
10044+#include <linux/const.h>
10045
10046 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10047 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10048@@ -12,6 +13,6 @@
10049 # define L1_CACHE_SHIFT 5
10050 #endif
10051
10052-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10053+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10054
10055 #endif
10056diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10057index 2e0a6b1..a64d0f5 100644
10058--- a/arch/um/include/asm/kmap_types.h
10059+++ b/arch/um/include/asm/kmap_types.h
10060@@ -8,6 +8,6 @@
10061
10062 /* No more #include "asm/arch/kmap_types.h" ! */
10063
10064-#define KM_TYPE_NR 14
10065+#define KM_TYPE_NR 15
10066
10067 #endif
10068diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10069index 5ff53d9..5850cdf 100644
10070--- a/arch/um/include/asm/page.h
10071+++ b/arch/um/include/asm/page.h
10072@@ -14,6 +14,9 @@
10073 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10074 #define PAGE_MASK (~(PAGE_SIZE-1))
10075
10076+#define ktla_ktva(addr) (addr)
10077+#define ktva_ktla(addr) (addr)
10078+
10079 #ifndef __ASSEMBLY__
10080
10081 struct page;
10082diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10083index 0032f92..cd151e0 100644
10084--- a/arch/um/include/asm/pgtable-3level.h
10085+++ b/arch/um/include/asm/pgtable-3level.h
10086@@ -58,6 +58,7 @@
10087 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10088 #define pud_populate(mm, pud, pmd) \
10089 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10090+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10091
10092 #ifdef CONFIG_64BIT
10093 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10094diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10095index b462b13..e7a19aa 100644
10096--- a/arch/um/kernel/process.c
10097+++ b/arch/um/kernel/process.c
10098@@ -386,22 +386,6 @@ int singlestepping(void * t)
10099 return 2;
10100 }
10101
10102-/*
10103- * Only x86 and x86_64 have an arch_align_stack().
10104- * All other arches have "#define arch_align_stack(x) (x)"
10105- * in their asm/system.h
10106- * As this is included in UML from asm-um/system-generic.h,
10107- * we can use it to behave as the subarch does.
10108- */
10109-#ifndef arch_align_stack
10110-unsigned long arch_align_stack(unsigned long sp)
10111-{
10112- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10113- sp -= get_random_int() % 8192;
10114- return sp & ~0xf;
10115-}
10116-#endif
10117-
10118 unsigned long get_wchan(struct task_struct *p)
10119 {
10120 unsigned long stack_page, sp, ip;
10121diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10122index ad8f795..2c7eec6 100644
10123--- a/arch/unicore32/include/asm/cache.h
10124+++ b/arch/unicore32/include/asm/cache.h
10125@@ -12,8 +12,10 @@
10126 #ifndef __UNICORE_CACHE_H__
10127 #define __UNICORE_CACHE_H__
10128
10129-#define L1_CACHE_SHIFT (5)
10130-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10131+#include <linux/const.h>
10132+
10133+#define L1_CACHE_SHIFT 5
10134+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10135
10136 /*
10137 * Memory returned by kmalloc() may be used for DMA, so we must make
10138diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10139index 0694d09..b58b3aa 100644
10140--- a/arch/x86/Kconfig
10141+++ b/arch/x86/Kconfig
10142@@ -238,7 +238,7 @@ config X86_HT
10143
10144 config X86_32_LAZY_GS
10145 def_bool y
10146- depends on X86_32 && !CC_STACKPROTECTOR
10147+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10148
10149 config ARCH_HWEIGHT_CFLAGS
10150 string
10151@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
10152
10153 config X86_MSR
10154 tristate "/dev/cpu/*/msr - Model-specific register support"
10155+ depends on !GRKERNSEC_KMEM
10156 ---help---
10157 This device gives privileged processes access to the x86
10158 Model-Specific Registers (MSRs). It is a character device with
10159@@ -1054,7 +1055,7 @@ choice
10160
10161 config NOHIGHMEM
10162 bool "off"
10163- depends on !X86_NUMAQ
10164+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10165 ---help---
10166 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10167 However, the address space of 32-bit x86 processors is only 4
10168@@ -1091,7 +1092,7 @@ config NOHIGHMEM
10169
10170 config HIGHMEM4G
10171 bool "4GB"
10172- depends on !X86_NUMAQ
10173+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10174 ---help---
10175 Select this if you have a 32-bit processor and between 1 and 4
10176 gigabytes of physical RAM.
10177@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
10178 hex
10179 default 0xB0000000 if VMSPLIT_3G_OPT
10180 default 0x80000000 if VMSPLIT_2G
10181- default 0x78000000 if VMSPLIT_2G_OPT
10182+ default 0x70000000 if VMSPLIT_2G_OPT
10183 default 0x40000000 if VMSPLIT_1G
10184 default 0xC0000000
10185 depends on X86_32
10186@@ -1542,6 +1543,7 @@ config SECCOMP
10187
10188 config CC_STACKPROTECTOR
10189 bool "Enable -fstack-protector buffer overflow detection"
10190+ depends on X86_64 || !PAX_MEMORY_UDEREF
10191 ---help---
10192 This option turns on the -fstack-protector GCC feature. This
10193 feature puts, at the beginning of functions, a canary value on
10194@@ -1599,6 +1601,7 @@ config KEXEC_JUMP
10195 config PHYSICAL_START
10196 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
10197 default "0x1000000"
10198+ range 0x400000 0x40000000
10199 ---help---
10200 This gives the physical address where the kernel is loaded.
10201
10202@@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
10203 config PHYSICAL_ALIGN
10204 hex "Alignment value to which kernel should be aligned" if X86_32
10205 default "0x1000000"
10206+ range 0x400000 0x1000000 if PAX_KERNEXEC
10207 range 0x2000 0x1000000
10208 ---help---
10209 This value puts the alignment restrictions on physical address
10210@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
10211 If unsure, say N.
10212
10213 config COMPAT_VDSO
10214- def_bool y
10215+ def_bool n
10216 prompt "Compat VDSO support"
10217 depends on X86_32 || IA32_EMULATION
10218+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10219 ---help---
10220 Map the 32-bit VDSO to the predictable old-style address too.
10221
10222diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10223index c026cca..14657ae 100644
10224--- a/arch/x86/Kconfig.cpu
10225+++ b/arch/x86/Kconfig.cpu
10226@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10227
10228 config X86_F00F_BUG
10229 def_bool y
10230- depends on M586MMX || M586TSC || M586 || M486
10231+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10232
10233 config X86_INVD_BUG
10234 def_bool y
10235@@ -327,7 +327,7 @@ config X86_INVD_BUG
10236
10237 config X86_ALIGNMENT_16
10238 def_bool y
10239- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10240+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10241
10242 config X86_INTEL_USERCOPY
10243 def_bool y
10244@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10245 # generates cmov.
10246 config X86_CMOV
10247 def_bool y
10248- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10249+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10250
10251 config X86_MINIMUM_CPU_FAMILY
10252 int
10253diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10254index b322f12..652d0d9 100644
10255--- a/arch/x86/Kconfig.debug
10256+++ b/arch/x86/Kconfig.debug
10257@@ -84,7 +84,7 @@ config X86_PTDUMP
10258 config DEBUG_RODATA
10259 bool "Write protect kernel read-only data structures"
10260 default y
10261- depends on DEBUG_KERNEL
10262+ depends on DEBUG_KERNEL && BROKEN
10263 ---help---
10264 Mark the kernel read-only data as write-protected in the pagetables,
10265 in order to catch accidental (and incorrect) writes to such const
10266@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10267
10268 config DEBUG_SET_MODULE_RONX
10269 bool "Set loadable kernel module data as NX and text as RO"
10270- depends on MODULES
10271+ depends on MODULES && BROKEN
10272 ---help---
10273 This option helps catch unintended modifications to loadable
10274 kernel module's text and read-only data. It also prevents execution
10275@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10276
10277 config DEBUG_STRICT_USER_COPY_CHECKS
10278 bool "Strict copy size checks"
10279- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10280+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10281 ---help---
10282 Enabling this option turns a certain set of sanity checks for user
10283 copy operations into compile time failures.
10284diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10285index e71fc42..7829607 100644
10286--- a/arch/x86/Makefile
10287+++ b/arch/x86/Makefile
10288@@ -50,6 +50,7 @@ else
10289 UTS_MACHINE := x86_64
10290 CHECKFLAGS += -D__x86_64__ -m64
10291
10292+ biarch := $(call cc-option,-m64)
10293 KBUILD_AFLAGS += -m64
10294 KBUILD_CFLAGS += -m64
10295
10296@@ -230,3 +231,12 @@ define archhelp
10297 echo ' FDARGS="..." arguments for the booted kernel'
10298 echo ' FDINITRD=file initrd for the booted kernel'
10299 endef
10300+
10301+define OLD_LD
10302+
10303+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10304+*** Please upgrade your binutils to 2.18 or newer
10305+endef
10306+
10307+archprepare:
10308+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10309diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10310index 379814b..add62ce 100644
10311--- a/arch/x86/boot/Makefile
10312+++ b/arch/x86/boot/Makefile
10313@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10314 $(call cc-option, -fno-stack-protector) \
10315 $(call cc-option, -mpreferred-stack-boundary=2)
10316 KBUILD_CFLAGS += $(call cc-option, -m32)
10317+ifdef CONSTIFY_PLUGIN
10318+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10319+endif
10320 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10321 GCOV_PROFILE := n
10322
10323diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10324index 878e4b9..20537ab 100644
10325--- a/arch/x86/boot/bitops.h
10326+++ b/arch/x86/boot/bitops.h
10327@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10328 u8 v;
10329 const u32 *p = (const u32 *)addr;
10330
10331- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10332+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10333 return v;
10334 }
10335
10336@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10337
10338 static inline void set_bit(int nr, void *addr)
10339 {
10340- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10341+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10342 }
10343
10344 #endif /* BOOT_BITOPS_H */
10345diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10346index 18997e5..83d9c67 100644
10347--- a/arch/x86/boot/boot.h
10348+++ b/arch/x86/boot/boot.h
10349@@ -85,7 +85,7 @@ static inline void io_delay(void)
10350 static inline u16 ds(void)
10351 {
10352 u16 seg;
10353- asm("movw %%ds,%0" : "=rm" (seg));
10354+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10355 return seg;
10356 }
10357
10358@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10359 static inline int memcmp(const void *s1, const void *s2, size_t len)
10360 {
10361 u8 diff;
10362- asm("repe; cmpsb; setnz %0"
10363+ asm volatile("repe; cmpsb; setnz %0"
10364 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10365 return diff;
10366 }
10367diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10368index 8a84501..b2d165f 100644
10369--- a/arch/x86/boot/compressed/Makefile
10370+++ b/arch/x86/boot/compressed/Makefile
10371@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10372 KBUILD_CFLAGS += $(cflags-y)
10373 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10374 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10375+ifdef CONSTIFY_PLUGIN
10376+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10377+endif
10378
10379 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10380 GCOV_PROFILE := n
10381diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10382index c205035..5853587 100644
10383--- a/arch/x86/boot/compressed/eboot.c
10384+++ b/arch/x86/boot/compressed/eboot.c
10385@@ -150,7 +150,6 @@ again:
10386 *addr = max_addr;
10387 }
10388
10389-free_pool:
10390 efi_call_phys1(sys_table->boottime->free_pool, map);
10391
10392 fail:
10393@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10394 if (i == map_size / desc_size)
10395 status = EFI_NOT_FOUND;
10396
10397-free_pool:
10398 efi_call_phys1(sys_table->boottime->free_pool, map);
10399 fail:
10400 return status;
10401diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10402index 1e3184f..0d11e2e 100644
10403--- a/arch/x86/boot/compressed/head_32.S
10404+++ b/arch/x86/boot/compressed/head_32.S
10405@@ -118,7 +118,7 @@ preferred_addr:
10406 notl %eax
10407 andl %eax, %ebx
10408 #else
10409- movl $LOAD_PHYSICAL_ADDR, %ebx
10410+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10411 #endif
10412
10413 /* Target address to relocate to for decompression */
10414@@ -204,7 +204,7 @@ relocated:
10415 * and where it was actually loaded.
10416 */
10417 movl %ebp, %ebx
10418- subl $LOAD_PHYSICAL_ADDR, %ebx
10419+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10420 jz 2f /* Nothing to be done if loaded at compiled addr. */
10421 /*
10422 * Process relocations.
10423@@ -212,8 +212,7 @@ relocated:
10424
10425 1: subl $4, %edi
10426 movl (%edi), %ecx
10427- testl %ecx, %ecx
10428- jz 2f
10429+ jecxz 2f
10430 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10431 jmp 1b
10432 2:
10433diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10434index f5d1aaa..cce11dc 100644
10435--- a/arch/x86/boot/compressed/head_64.S
10436+++ b/arch/x86/boot/compressed/head_64.S
10437@@ -91,7 +91,7 @@ ENTRY(startup_32)
10438 notl %eax
10439 andl %eax, %ebx
10440 #else
10441- movl $LOAD_PHYSICAL_ADDR, %ebx
10442+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10443 #endif
10444
10445 /* Target address to relocate to for decompression */
10446@@ -273,7 +273,7 @@ preferred_addr:
10447 notq %rax
10448 andq %rax, %rbp
10449 #else
10450- movq $LOAD_PHYSICAL_ADDR, %rbp
10451+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10452 #endif
10453
10454 /* Target address to relocate to for decompression */
10455diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10456index 88f7ff6..ed695dd 100644
10457--- a/arch/x86/boot/compressed/misc.c
10458+++ b/arch/x86/boot/compressed/misc.c
10459@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10460 case PT_LOAD:
10461 #ifdef CONFIG_RELOCATABLE
10462 dest = output;
10463- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10464+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10465 #else
10466 dest = (void *)(phdr->p_paddr);
10467 #endif
10468@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10469 error("Destination address too large");
10470 #endif
10471 #ifndef CONFIG_RELOCATABLE
10472- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10473+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10474 error("Wrong destination address");
10475 #endif
10476
10477diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10478index 4d3ff03..e4972ff 100644
10479--- a/arch/x86/boot/cpucheck.c
10480+++ b/arch/x86/boot/cpucheck.c
10481@@ -74,7 +74,7 @@ static int has_fpu(void)
10482 u16 fcw = -1, fsw = -1;
10483 u32 cr0;
10484
10485- asm("movl %%cr0,%0" : "=r" (cr0));
10486+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10487 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10488 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10489 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10490@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10491 {
10492 u32 f0, f1;
10493
10494- asm("pushfl ; "
10495+ asm volatile("pushfl ; "
10496 "pushfl ; "
10497 "popl %0 ; "
10498 "movl %0,%1 ; "
10499@@ -115,7 +115,7 @@ static void get_flags(void)
10500 set_bit(X86_FEATURE_FPU, cpu.flags);
10501
10502 if (has_eflag(X86_EFLAGS_ID)) {
10503- asm("cpuid"
10504+ asm volatile("cpuid"
10505 : "=a" (max_intel_level),
10506 "=b" (cpu_vendor[0]),
10507 "=d" (cpu_vendor[1]),
10508@@ -124,7 +124,7 @@ static void get_flags(void)
10509
10510 if (max_intel_level >= 0x00000001 &&
10511 max_intel_level <= 0x0000ffff) {
10512- asm("cpuid"
10513+ asm volatile("cpuid"
10514 : "=a" (tfms),
10515 "=c" (cpu.flags[4]),
10516 "=d" (cpu.flags[0])
10517@@ -136,7 +136,7 @@ static void get_flags(void)
10518 cpu.model += ((tfms >> 16) & 0xf) << 4;
10519 }
10520
10521- asm("cpuid"
10522+ asm volatile("cpuid"
10523 : "=a" (max_amd_level)
10524 : "a" (0x80000000)
10525 : "ebx", "ecx", "edx");
10526@@ -144,7 +144,7 @@ static void get_flags(void)
10527 if (max_amd_level >= 0x80000001 &&
10528 max_amd_level <= 0x8000ffff) {
10529 u32 eax = 0x80000001;
10530- asm("cpuid"
10531+ asm volatile("cpuid"
10532 : "+a" (eax),
10533 "=c" (cpu.flags[6]),
10534 "=d" (cpu.flags[1])
10535@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10536 u32 ecx = MSR_K7_HWCR;
10537 u32 eax, edx;
10538
10539- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10540+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10541 eax &= ~(1 << 15);
10542- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10543+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10544
10545 get_flags(); /* Make sure it really did something */
10546 err = check_flags();
10547@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10548 u32 ecx = MSR_VIA_FCR;
10549 u32 eax, edx;
10550
10551- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10552+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10553 eax |= (1<<1)|(1<<7);
10554- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10555+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10556
10557 set_bit(X86_FEATURE_CX8, cpu.flags);
10558 err = check_flags();
10559@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10560 u32 eax, edx;
10561 u32 level = 1;
10562
10563- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10564- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10565- asm("cpuid"
10566+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10567+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10568+ asm volatile("cpuid"
10569 : "+a" (level), "=d" (cpu.flags[0])
10570 : : "ecx", "ebx");
10571- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10572+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10573
10574 err = check_flags();
10575 }
10576diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10577index 944ce59..87ee37a 100644
10578--- a/arch/x86/boot/header.S
10579+++ b/arch/x86/boot/header.S
10580@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10581 # single linked list of
10582 # struct setup_data
10583
10584-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10585+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10586
10587 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10588+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10589+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10590+#else
10591 #define VO_INIT_SIZE (VO__end - VO__text)
10592+#endif
10593 #if ZO_INIT_SIZE > VO_INIT_SIZE
10594 #define INIT_SIZE ZO_INIT_SIZE
10595 #else
10596diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10597index db75d07..8e6d0af 100644
10598--- a/arch/x86/boot/memory.c
10599+++ b/arch/x86/boot/memory.c
10600@@ -19,7 +19,7 @@
10601
10602 static int detect_memory_e820(void)
10603 {
10604- int count = 0;
10605+ unsigned int count = 0;
10606 struct biosregs ireg, oreg;
10607 struct e820entry *desc = boot_params.e820_map;
10608 static struct e820entry buf; /* static so it is zeroed */
10609diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10610index 11e8c6e..fdbb1ed 100644
10611--- a/arch/x86/boot/video-vesa.c
10612+++ b/arch/x86/boot/video-vesa.c
10613@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10614
10615 boot_params.screen_info.vesapm_seg = oreg.es;
10616 boot_params.screen_info.vesapm_off = oreg.di;
10617+ boot_params.screen_info.vesapm_size = oreg.cx;
10618 }
10619
10620 /*
10621diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10622index 43eda28..5ab5fdb 100644
10623--- a/arch/x86/boot/video.c
10624+++ b/arch/x86/boot/video.c
10625@@ -96,7 +96,7 @@ static void store_mode_params(void)
10626 static unsigned int get_entry(void)
10627 {
10628 char entry_buf[4];
10629- int i, len = 0;
10630+ unsigned int i, len = 0;
10631 int key;
10632 unsigned int v;
10633
10634diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10635index 5b577d5..3c1fed4 100644
10636--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10637+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10638@@ -8,6 +8,8 @@
10639 * including this sentence is retained in full.
10640 */
10641
10642+#include <asm/alternative-asm.h>
10643+
10644 .extern crypto_ft_tab
10645 .extern crypto_it_tab
10646 .extern crypto_fl_tab
10647@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10648 je B192; \
10649 leaq 32(r9),r9;
10650
10651+#define ret pax_force_retaddr 0, 1; ret
10652+
10653 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10654 movq r1,r2; \
10655 movq r3,r4; \
10656diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10657index 3470624..201259d 100644
10658--- a/arch/x86/crypto/aesni-intel_asm.S
10659+++ b/arch/x86/crypto/aesni-intel_asm.S
10660@@ -31,6 +31,7 @@
10661
10662 #include <linux/linkage.h>
10663 #include <asm/inst.h>
10664+#include <asm/alternative-asm.h>
10665
10666 #ifdef __x86_64__
10667 .data
10668@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10669 pop %r14
10670 pop %r13
10671 pop %r12
10672+ pax_force_retaddr 0, 1
10673 ret
10674+ENDPROC(aesni_gcm_dec)
10675
10676
10677 /*****************************************************************************
10678@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10679 pop %r14
10680 pop %r13
10681 pop %r12
10682+ pax_force_retaddr 0, 1
10683 ret
10684+ENDPROC(aesni_gcm_enc)
10685
10686 #endif
10687
10688@@ -1714,6 +1719,7 @@ _key_expansion_256a:
10689 pxor %xmm1, %xmm0
10690 movaps %xmm0, (TKEYP)
10691 add $0x10, TKEYP
10692+ pax_force_retaddr_bts
10693 ret
10694
10695 .align 4
10696@@ -1738,6 +1744,7 @@ _key_expansion_192a:
10697 shufps $0b01001110, %xmm2, %xmm1
10698 movaps %xmm1, 0x10(TKEYP)
10699 add $0x20, TKEYP
10700+ pax_force_retaddr_bts
10701 ret
10702
10703 .align 4
10704@@ -1757,6 +1764,7 @@ _key_expansion_192b:
10705
10706 movaps %xmm0, (TKEYP)
10707 add $0x10, TKEYP
10708+ pax_force_retaddr_bts
10709 ret
10710
10711 .align 4
10712@@ -1769,6 +1777,7 @@ _key_expansion_256b:
10713 pxor %xmm1, %xmm2
10714 movaps %xmm2, (TKEYP)
10715 add $0x10, TKEYP
10716+ pax_force_retaddr_bts
10717 ret
10718
10719 /*
10720@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10721 #ifndef __x86_64__
10722 popl KEYP
10723 #endif
10724+ pax_force_retaddr 0, 1
10725 ret
10726+ENDPROC(aesni_set_key)
10727
10728 /*
10729 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10730@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10731 popl KLEN
10732 popl KEYP
10733 #endif
10734+ pax_force_retaddr 0, 1
10735 ret
10736+ENDPROC(aesni_enc)
10737
10738 /*
10739 * _aesni_enc1: internal ABI
10740@@ -1959,6 +1972,7 @@ _aesni_enc1:
10741 AESENC KEY STATE
10742 movaps 0x70(TKEYP), KEY
10743 AESENCLAST KEY STATE
10744+ pax_force_retaddr_bts
10745 ret
10746
10747 /*
10748@@ -2067,6 +2081,7 @@ _aesni_enc4:
10749 AESENCLAST KEY STATE2
10750 AESENCLAST KEY STATE3
10751 AESENCLAST KEY STATE4
10752+ pax_force_retaddr_bts
10753 ret
10754
10755 /*
10756@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10757 popl KLEN
10758 popl KEYP
10759 #endif
10760+ pax_force_retaddr 0, 1
10761 ret
10762+ENDPROC(aesni_dec)
10763
10764 /*
10765 * _aesni_dec1: internal ABI
10766@@ -2146,6 +2163,7 @@ _aesni_dec1:
10767 AESDEC KEY STATE
10768 movaps 0x70(TKEYP), KEY
10769 AESDECLAST KEY STATE
10770+ pax_force_retaddr_bts
10771 ret
10772
10773 /*
10774@@ -2254,6 +2272,7 @@ _aesni_dec4:
10775 AESDECLAST KEY STATE2
10776 AESDECLAST KEY STATE3
10777 AESDECLAST KEY STATE4
10778+ pax_force_retaddr_bts
10779 ret
10780
10781 /*
10782@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10783 popl KEYP
10784 popl LEN
10785 #endif
10786+ pax_force_retaddr 0, 1
10787 ret
10788+ENDPROC(aesni_ecb_enc)
10789
10790 /*
10791 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10792@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10793 popl KEYP
10794 popl LEN
10795 #endif
10796+ pax_force_retaddr 0, 1
10797 ret
10798+ENDPROC(aesni_ecb_dec)
10799
10800 /*
10801 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10802@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10803 popl LEN
10804 popl IVP
10805 #endif
10806+ pax_force_retaddr 0, 1
10807 ret
10808+ENDPROC(aesni_cbc_enc)
10809
10810 /*
10811 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10812@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10813 popl LEN
10814 popl IVP
10815 #endif
10816+ pax_force_retaddr 0, 1
10817 ret
10818+ENDPROC(aesni_cbc_dec)
10819
10820 #ifdef __x86_64__
10821 .align 16
10822@@ -2526,6 +2553,7 @@ _aesni_inc_init:
10823 mov $1, TCTR_LOW
10824 MOVQ_R64_XMM TCTR_LOW INC
10825 MOVQ_R64_XMM CTR TCTR_LOW
10826+ pax_force_retaddr_bts
10827 ret
10828
10829 /*
10830@@ -2554,6 +2582,7 @@ _aesni_inc:
10831 .Linc_low:
10832 movaps CTR, IV
10833 PSHUFB_XMM BSWAP_MASK IV
10834+ pax_force_retaddr_bts
10835 ret
10836
10837 /*
10838@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10839 .Lctr_enc_ret:
10840 movups IV, (IVP)
10841 .Lctr_enc_just_ret:
10842+ pax_force_retaddr 0, 1
10843 ret
10844+ENDPROC(aesni_ctr_enc)
10845 #endif
10846diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10847index 391d245..67f35c2 100644
10848--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10849+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10850@@ -20,6 +20,8 @@
10851 *
10852 */
10853
10854+#include <asm/alternative-asm.h>
10855+
10856 .file "blowfish-x86_64-asm.S"
10857 .text
10858
10859@@ -151,9 +153,11 @@ __blowfish_enc_blk:
10860 jnz __enc_xor;
10861
10862 write_block();
10863+ pax_force_retaddr 0, 1
10864 ret;
10865 __enc_xor:
10866 xor_block();
10867+ pax_force_retaddr 0, 1
10868 ret;
10869
10870 .align 8
10871@@ -188,6 +192,7 @@ blowfish_dec_blk:
10872
10873 movq %r11, %rbp;
10874
10875+ pax_force_retaddr 0, 1
10876 ret;
10877
10878 /**********************************************************************
10879@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10880
10881 popq %rbx;
10882 popq %rbp;
10883+ pax_force_retaddr 0, 1
10884 ret;
10885
10886 __enc_xor4:
10887@@ -349,6 +355,7 @@ __enc_xor4:
10888
10889 popq %rbx;
10890 popq %rbp;
10891+ pax_force_retaddr 0, 1
10892 ret;
10893
10894 .align 8
10895@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10896 popq %rbx;
10897 popq %rbp;
10898
10899+ pax_force_retaddr 0, 1
10900 ret;
10901
10902diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10903index 0b33743..7a56206 100644
10904--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10905+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10906@@ -20,6 +20,8 @@
10907 *
10908 */
10909
10910+#include <asm/alternative-asm.h>
10911+
10912 .file "camellia-x86_64-asm_64.S"
10913 .text
10914
10915@@ -229,12 +231,14 @@ __enc_done:
10916 enc_outunpack(mov, RT1);
10917
10918 movq RRBP, %rbp;
10919+ pax_force_retaddr 0, 1
10920 ret;
10921
10922 __enc_xor:
10923 enc_outunpack(xor, RT1);
10924
10925 movq RRBP, %rbp;
10926+ pax_force_retaddr 0, 1
10927 ret;
10928
10929 .global camellia_dec_blk;
10930@@ -275,6 +279,7 @@ __dec_rounds16:
10931 dec_outunpack();
10932
10933 movq RRBP, %rbp;
10934+ pax_force_retaddr 0, 1
10935 ret;
10936
10937 /**********************************************************************
10938@@ -468,6 +473,7 @@ __enc2_done:
10939
10940 movq RRBP, %rbp;
10941 popq %rbx;
10942+ pax_force_retaddr 0, 1
10943 ret;
10944
10945 __enc2_xor:
10946@@ -475,6 +481,7 @@ __enc2_xor:
10947
10948 movq RRBP, %rbp;
10949 popq %rbx;
10950+ pax_force_retaddr 0, 1
10951 ret;
10952
10953 .global camellia_dec_blk_2way;
10954@@ -517,4 +524,5 @@ __dec2_rounds16:
10955
10956 movq RRBP, %rbp;
10957 movq RXOR, %rbx;
10958+ pax_force_retaddr 0, 1
10959 ret;
10960diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10961index 15b00ac..2071784 100644
10962--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10963+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10964@@ -23,6 +23,8 @@
10965 *
10966 */
10967
10968+#include <asm/alternative-asm.h>
10969+
10970 .file "cast5-avx-x86_64-asm_64.S"
10971
10972 .extern cast_s1
10973@@ -281,6 +283,7 @@ __skip_enc:
10974 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10975 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10976
10977+ pax_force_retaddr 0, 1
10978 ret;
10979
10980 .align 16
10981@@ -353,6 +356,7 @@ __dec_tail:
10982 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10983 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10984
10985+ pax_force_retaddr 0, 1
10986 ret;
10987
10988 __skip_dec:
10989@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10990 vmovdqu RR4, (6*4*4)(%r11);
10991 vmovdqu RL4, (7*4*4)(%r11);
10992
10993+ pax_force_retaddr
10994 ret;
10995
10996 .align 16
10997@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10998 vmovdqu RR4, (6*4*4)(%r11);
10999 vmovdqu RL4, (7*4*4)(%r11);
11000
11001+ pax_force_retaddr
11002 ret;
11003
11004 .align 16
11005@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
11006
11007 popq %r12;
11008
11009+ pax_force_retaddr
11010 ret;
11011
11012 .align 16
11013@@ -555,4 +562,5 @@ cast5_ctr_16way:
11014
11015 popq %r12;
11016
11017+ pax_force_retaddr
11018 ret;
11019diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11020index 2569d0d..637c289 100644
11021--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11022+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11023@@ -23,6 +23,8 @@
11024 *
11025 */
11026
11027+#include <asm/alternative-asm.h>
11028+
11029 #include "glue_helper-asm-avx.S"
11030
11031 .file "cast6-avx-x86_64-asm_64.S"
11032@@ -294,6 +296,7 @@ __cast6_enc_blk8:
11033 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11034 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11035
11036+ pax_force_retaddr 0, 1
11037 ret;
11038
11039 .align 8
11040@@ -340,6 +343,7 @@ __cast6_dec_blk8:
11041 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11042 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11043
11044+ pax_force_retaddr 0, 1
11045 ret;
11046
11047 .align 8
11048@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
11049
11050 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11051
11052+ pax_force_retaddr
11053 ret;
11054
11055 .align 8
11056@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
11057
11058 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11059
11060+ pax_force_retaddr
11061 ret;
11062
11063 .align 8
11064@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
11065
11066 popq %r12;
11067
11068+ pax_force_retaddr
11069 ret;
11070
11071 .align 8
11072@@ -436,4 +443,5 @@ cast6_ctr_8way:
11073
11074 popq %r12;
11075
11076+ pax_force_retaddr
11077 ret;
11078diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11079index 6214a9b..1f4fc9a 100644
11080--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11081+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11082@@ -1,3 +1,5 @@
11083+#include <asm/alternative-asm.h>
11084+
11085 # enter ECRYPT_encrypt_bytes
11086 .text
11087 .p2align 5
11088@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
11089 add %r11,%rsp
11090 mov %rdi,%rax
11091 mov %rsi,%rdx
11092+ pax_force_retaddr 0, 1
11093 ret
11094 # bytesatleast65:
11095 ._bytesatleast65:
11096@@ -891,6 +894,7 @@ ECRYPT_keysetup:
11097 add %r11,%rsp
11098 mov %rdi,%rax
11099 mov %rsi,%rdx
11100+ pax_force_retaddr
11101 ret
11102 # enter ECRYPT_ivsetup
11103 .text
11104@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
11105 add %r11,%rsp
11106 mov %rdi,%rax
11107 mov %rsi,%rdx
11108+ pax_force_retaddr
11109 ret
11110diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11111index 02b0e9f..cf4cf5c 100644
11112--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11113+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11114@@ -24,6 +24,8 @@
11115 *
11116 */
11117
11118+#include <asm/alternative-asm.h>
11119+
11120 #include "glue_helper-asm-avx.S"
11121
11122 .file "serpent-avx-x86_64-asm_64.S"
11123@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
11124 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11125 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11126
11127+ pax_force_retaddr
11128 ret;
11129
11130 .align 8
11131@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
11132 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11133 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11134
11135+ pax_force_retaddr
11136 ret;
11137
11138 .align 8
11139@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
11140
11141 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11142
11143+ pax_force_retaddr
11144 ret;
11145
11146 .align 8
11147@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
11148
11149 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11150
11151+ pax_force_retaddr
11152 ret;
11153
11154 .align 8
11155@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
11156
11157 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11158
11159+ pax_force_retaddr
11160 ret;
11161
11162 .align 8
11163@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
11164
11165 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11166
11167+ pax_force_retaddr
11168 ret;
11169diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11170index 3ee1ff0..cbc568b 100644
11171--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11172+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11173@@ -24,6 +24,8 @@
11174 *
11175 */
11176
11177+#include <asm/alternative-asm.h>
11178+
11179 .file "serpent-sse2-x86_64-asm_64.S"
11180 .text
11181
11182@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
11183 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11184 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11185
11186+ pax_force_retaddr
11187 ret;
11188
11189 __enc_xor8:
11190 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11191 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11192
11193+ pax_force_retaddr
11194 ret;
11195
11196 .align 8
11197@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
11198 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11199 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11200
11201+ pax_force_retaddr
11202 ret;
11203diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11204index 49d6987..df66bd4 100644
11205--- a/arch/x86/crypto/sha1_ssse3_asm.S
11206+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11207@@ -28,6 +28,8 @@
11208 * (at your option) any later version.
11209 */
11210
11211+#include <asm/alternative-asm.h>
11212+
11213 #define CTX %rdi // arg1
11214 #define BUF %rsi // arg2
11215 #define CNT %rdx // arg3
11216@@ -104,6 +106,7 @@
11217 pop %r12
11218 pop %rbp
11219 pop %rbx
11220+ pax_force_retaddr 0, 1
11221 ret
11222
11223 .size \name, .-\name
11224diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11225index ebac16b..8092eb9 100644
11226--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11227+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11228@@ -23,6 +23,8 @@
11229 *
11230 */
11231
11232+#include <asm/alternative-asm.h>
11233+
11234 #include "glue_helper-asm-avx.S"
11235
11236 .file "twofish-avx-x86_64-asm_64.S"
11237@@ -283,6 +285,7 @@ __twofish_enc_blk8:
11238 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11239 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11240
11241+ pax_force_retaddr 0, 1
11242 ret;
11243
11244 .align 8
11245@@ -324,6 +327,7 @@ __twofish_dec_blk8:
11246 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11247 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11248
11249+ pax_force_retaddr 0, 1
11250 ret;
11251
11252 .align 8
11253@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11254
11255 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11256
11257+ pax_force_retaddr 0, 1
11258 ret;
11259
11260 .align 8
11261@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11262
11263 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11264
11265+ pax_force_retaddr 0, 1
11266 ret;
11267
11268 .align 8
11269@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11270
11271 popq %r12;
11272
11273+ pax_force_retaddr 0, 1
11274 ret;
11275
11276 .align 8
11277@@ -420,4 +427,5 @@ twofish_ctr_8way:
11278
11279 popq %r12;
11280
11281+ pax_force_retaddr 0, 1
11282 ret;
11283diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11284index 5b012a2..36d5364 100644
11285--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11286+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11287@@ -20,6 +20,8 @@
11288 *
11289 */
11290
11291+#include <asm/alternative-asm.h>
11292+
11293 .file "twofish-x86_64-asm-3way.S"
11294 .text
11295
11296@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11297 popq %r13;
11298 popq %r14;
11299 popq %r15;
11300+ pax_force_retaddr 0, 1
11301 ret;
11302
11303 __enc_xor3:
11304@@ -271,6 +274,7 @@ __enc_xor3:
11305 popq %r13;
11306 popq %r14;
11307 popq %r15;
11308+ pax_force_retaddr 0, 1
11309 ret;
11310
11311 .global twofish_dec_blk_3way
11312@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11313 popq %r13;
11314 popq %r14;
11315 popq %r15;
11316+ pax_force_retaddr 0, 1
11317 ret;
11318
11319diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11320index 7bcf3fc..f53832f 100644
11321--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11322+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11323@@ -21,6 +21,7 @@
11324 .text
11325
11326 #include <asm/asm-offsets.h>
11327+#include <asm/alternative-asm.h>
11328
11329 #define a_offset 0
11330 #define b_offset 4
11331@@ -268,6 +269,7 @@ twofish_enc_blk:
11332
11333 popq R1
11334 movq $1,%rax
11335+ pax_force_retaddr 0, 1
11336 ret
11337
11338 twofish_dec_blk:
11339@@ -319,4 +321,5 @@ twofish_dec_blk:
11340
11341 popq R1
11342 movq $1,%rax
11343+ pax_force_retaddr 0, 1
11344 ret
11345diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11346index a703af1..f5b9c36 100644
11347--- a/arch/x86/ia32/ia32_aout.c
11348+++ b/arch/x86/ia32/ia32_aout.c
11349@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11350 unsigned long dump_start, dump_size;
11351 struct user32 dump;
11352
11353+ memset(&dump, 0, sizeof(dump));
11354+
11355 fs = get_fs();
11356 set_fs(KERNEL_DS);
11357 has_dumped = 1;
11358diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11359index a1daf4a..f8c4537 100644
11360--- a/arch/x86/ia32/ia32_signal.c
11361+++ b/arch/x86/ia32/ia32_signal.c
11362@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11363 sp -= frame_size;
11364 /* Align the stack pointer according to the i386 ABI,
11365 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11366- sp = ((sp + 4) & -16ul) - 4;
11367+ sp = ((sp - 12) & -16ul) - 4;
11368 return (void __user *) sp;
11369 }
11370
11371@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11372 * These are actually not used anymore, but left because some
11373 * gdb versions depend on them as a marker.
11374 */
11375- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11376+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11377 } put_user_catch(err);
11378
11379 if (err)
11380@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11381 0xb8,
11382 __NR_ia32_rt_sigreturn,
11383 0x80cd,
11384- 0,
11385+ 0
11386 };
11387
11388 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11389@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11390
11391 if (ka->sa.sa_flags & SA_RESTORER)
11392 restorer = ka->sa.sa_restorer;
11393+ else if (current->mm->context.vdso)
11394+ /* Return stub is in 32bit vsyscall page */
11395+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11396 else
11397- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11398- rt_sigreturn);
11399+ restorer = &frame->retcode;
11400 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11401
11402 /*
11403 * Not actually used anymore, but left because some gdb
11404 * versions need it.
11405 */
11406- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11407+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11408 } put_user_catch(err);
11409
11410 err |= copy_siginfo_to_user32(&frame->info, info);
11411diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11412index 142c4ce..19b683f 100644
11413--- a/arch/x86/ia32/ia32entry.S
11414+++ b/arch/x86/ia32/ia32entry.S
11415@@ -15,8 +15,10 @@
11416 #include <asm/irqflags.h>
11417 #include <asm/asm.h>
11418 #include <asm/smap.h>
11419+#include <asm/pgtable.h>
11420 #include <linux/linkage.h>
11421 #include <linux/err.h>
11422+#include <asm/alternative-asm.h>
11423
11424 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11425 #include <linux/elf-em.h>
11426@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11427 ENDPROC(native_irq_enable_sysexit)
11428 #endif
11429
11430+ .macro pax_enter_kernel_user
11431+ pax_set_fptr_mask
11432+#ifdef CONFIG_PAX_MEMORY_UDEREF
11433+ call pax_enter_kernel_user
11434+#endif
11435+ .endm
11436+
11437+ .macro pax_exit_kernel_user
11438+#ifdef CONFIG_PAX_MEMORY_UDEREF
11439+ call pax_exit_kernel_user
11440+#endif
11441+#ifdef CONFIG_PAX_RANDKSTACK
11442+ pushq %rax
11443+ pushq %r11
11444+ call pax_randomize_kstack
11445+ popq %r11
11446+ popq %rax
11447+#endif
11448+ .endm
11449+
11450+.macro pax_erase_kstack
11451+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11452+ call pax_erase_kstack
11453+#endif
11454+.endm
11455+
11456 /*
11457 * 32bit SYSENTER instruction entry.
11458 *
11459@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11460 CFI_REGISTER rsp,rbp
11461 SWAPGS_UNSAFE_STACK
11462 movq PER_CPU_VAR(kernel_stack), %rsp
11463- addq $(KERNEL_STACK_OFFSET),%rsp
11464- /*
11465- * No need to follow this irqs on/off section: the syscall
11466- * disabled irqs, here we enable it straight after entry:
11467- */
11468- ENABLE_INTERRUPTS(CLBR_NONE)
11469 movl %ebp,%ebp /* zero extension */
11470 pushq_cfi $__USER32_DS
11471 /*CFI_REL_OFFSET ss,0*/
11472@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11473 CFI_REL_OFFSET rsp,0
11474 pushfq_cfi
11475 /*CFI_REL_OFFSET rflags,0*/
11476- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11477- CFI_REGISTER rip,r10
11478+ orl $X86_EFLAGS_IF,(%rsp)
11479+ GET_THREAD_INFO(%r11)
11480+ movl TI_sysenter_return(%r11), %r11d
11481+ CFI_REGISTER rip,r11
11482 pushq_cfi $__USER32_CS
11483 /*CFI_REL_OFFSET cs,0*/
11484 movl %eax, %eax
11485- pushq_cfi %r10
11486+ pushq_cfi %r11
11487 CFI_REL_OFFSET rip,0
11488 pushq_cfi %rax
11489 cld
11490 SAVE_ARGS 0,1,0
11491+ pax_enter_kernel_user
11492+
11493+#ifdef CONFIG_PAX_RANDKSTACK
11494+ pax_erase_kstack
11495+#endif
11496+
11497+ /*
11498+ * No need to follow this irqs on/off section: the syscall
11499+ * disabled irqs, here we enable it straight after entry:
11500+ */
11501+ ENABLE_INTERRUPTS(CLBR_NONE)
11502 /* no need to do an access_ok check here because rbp has been
11503 32bit zero extended */
11504+
11505+#ifdef CONFIG_PAX_MEMORY_UDEREF
11506+ mov $PAX_USER_SHADOW_BASE,%r11
11507+ add %r11,%rbp
11508+#endif
11509+
11510 ASM_STAC
11511 1: movl (%rbp),%ebp
11512 _ASM_EXTABLE(1b,ia32_badarg)
11513 ASM_CLAC
11514- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11515- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11516+ GET_THREAD_INFO(%r11)
11517+ orl $TS_COMPAT,TI_status(%r11)
11518+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11519 CFI_REMEMBER_STATE
11520 jnz sysenter_tracesys
11521 cmpq $(IA32_NR_syscalls-1),%rax
11522@@ -162,12 +204,15 @@ sysenter_do_call:
11523 sysenter_dispatch:
11524 call *ia32_sys_call_table(,%rax,8)
11525 movq %rax,RAX-ARGOFFSET(%rsp)
11526+ GET_THREAD_INFO(%r11)
11527 DISABLE_INTERRUPTS(CLBR_NONE)
11528 TRACE_IRQS_OFF
11529- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11530+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11531 jnz sysexit_audit
11532 sysexit_from_sys_call:
11533- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11534+ pax_exit_kernel_user
11535+ pax_erase_kstack
11536+ andl $~TS_COMPAT,TI_status(%r11)
11537 /* clear IF, that popfq doesn't enable interrupts early */
11538 andl $~0x200,EFLAGS-R11(%rsp)
11539 movl RIP-R11(%rsp),%edx /* User %eip */
11540@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11541 movl %eax,%esi /* 2nd arg: syscall number */
11542 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11543 call __audit_syscall_entry
11544+
11545+ pax_erase_kstack
11546+
11547 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11548 cmpq $(IA32_NR_syscalls-1),%rax
11549 ja ia32_badsys
11550@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11551 .endm
11552
11553 .macro auditsys_exit exit
11554- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11555+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11556 jnz ia32_ret_from_sys_call
11557 TRACE_IRQS_ON
11558 ENABLE_INTERRUPTS(CLBR_NONE)
11559@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11560 1: setbe %al /* 1 if error, 0 if not */
11561 movzbl %al,%edi /* zero-extend that into %edi */
11562 call __audit_syscall_exit
11563+ GET_THREAD_INFO(%r11)
11564 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11565 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11566 DISABLE_INTERRUPTS(CLBR_NONE)
11567 TRACE_IRQS_OFF
11568- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11569+ testl %edi,TI_flags(%r11)
11570 jz \exit
11571 CLEAR_RREGS -ARGOFFSET
11572 jmp int_with_check
11573@@ -237,7 +286,7 @@ sysexit_audit:
11574
11575 sysenter_tracesys:
11576 #ifdef CONFIG_AUDITSYSCALL
11577- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11578+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11579 jz sysenter_auditsys
11580 #endif
11581 SAVE_REST
11582@@ -249,6 +298,9 @@ sysenter_tracesys:
11583 RESTORE_REST
11584 cmpq $(IA32_NR_syscalls-1),%rax
11585 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11586+
11587+ pax_erase_kstack
11588+
11589 jmp sysenter_do_call
11590 CFI_ENDPROC
11591 ENDPROC(ia32_sysenter_target)
11592@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11593 ENTRY(ia32_cstar_target)
11594 CFI_STARTPROC32 simple
11595 CFI_SIGNAL_FRAME
11596- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11597+ CFI_DEF_CFA rsp,0
11598 CFI_REGISTER rip,rcx
11599 /*CFI_REGISTER rflags,r11*/
11600 SWAPGS_UNSAFE_STACK
11601 movl %esp,%r8d
11602 CFI_REGISTER rsp,r8
11603 movq PER_CPU_VAR(kernel_stack),%rsp
11604+ SAVE_ARGS 8*6,0,0
11605+ pax_enter_kernel_user
11606+
11607+#ifdef CONFIG_PAX_RANDKSTACK
11608+ pax_erase_kstack
11609+#endif
11610+
11611 /*
11612 * No need to follow this irqs on/off section: the syscall
11613 * disabled irqs and here we enable it straight after entry:
11614 */
11615 ENABLE_INTERRUPTS(CLBR_NONE)
11616- SAVE_ARGS 8,0,0
11617 movl %eax,%eax /* zero extension */
11618 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11619 movq %rcx,RIP-ARGOFFSET(%rsp)
11620@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11621 /* no need to do an access_ok check here because r8 has been
11622 32bit zero extended */
11623 /* hardware stack frame is complete now */
11624+
11625+#ifdef CONFIG_PAX_MEMORY_UDEREF
11626+ mov $PAX_USER_SHADOW_BASE,%r11
11627+ add %r11,%r8
11628+#endif
11629+
11630 ASM_STAC
11631 1: movl (%r8),%r9d
11632 _ASM_EXTABLE(1b,ia32_badarg)
11633 ASM_CLAC
11634- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11635- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11636+ GET_THREAD_INFO(%r11)
11637+ orl $TS_COMPAT,TI_status(%r11)
11638+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11639 CFI_REMEMBER_STATE
11640 jnz cstar_tracesys
11641 cmpq $IA32_NR_syscalls-1,%rax
11642@@ -319,12 +384,15 @@ cstar_do_call:
11643 cstar_dispatch:
11644 call *ia32_sys_call_table(,%rax,8)
11645 movq %rax,RAX-ARGOFFSET(%rsp)
11646+ GET_THREAD_INFO(%r11)
11647 DISABLE_INTERRUPTS(CLBR_NONE)
11648 TRACE_IRQS_OFF
11649- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11650+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11651 jnz sysretl_audit
11652 sysretl_from_sys_call:
11653- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11654+ pax_exit_kernel_user
11655+ pax_erase_kstack
11656+ andl $~TS_COMPAT,TI_status(%r11)
11657 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11658 movl RIP-ARGOFFSET(%rsp),%ecx
11659 CFI_REGISTER rip,rcx
11660@@ -352,7 +420,7 @@ sysretl_audit:
11661
11662 cstar_tracesys:
11663 #ifdef CONFIG_AUDITSYSCALL
11664- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11665+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11666 jz cstar_auditsys
11667 #endif
11668 xchgl %r9d,%ebp
11669@@ -366,6 +434,9 @@ cstar_tracesys:
11670 xchgl %ebp,%r9d
11671 cmpq $(IA32_NR_syscalls-1),%rax
11672 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11673+
11674+ pax_erase_kstack
11675+
11676 jmp cstar_do_call
11677 END(ia32_cstar_target)
11678
11679@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11680 CFI_REL_OFFSET rip,RIP-RIP
11681 PARAVIRT_ADJUST_EXCEPTION_FRAME
11682 SWAPGS
11683- /*
11684- * No need to follow this irqs on/off section: the syscall
11685- * disabled irqs and here we enable it straight after entry:
11686- */
11687- ENABLE_INTERRUPTS(CLBR_NONE)
11688 movl %eax,%eax
11689 pushq_cfi %rax
11690 cld
11691 /* note the registers are not zero extended to the sf.
11692 this could be a problem. */
11693 SAVE_ARGS 0,1,0
11694- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11695- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11696+ pax_enter_kernel_user
11697+
11698+#ifdef CONFIG_PAX_RANDKSTACK
11699+ pax_erase_kstack
11700+#endif
11701+
11702+ /*
11703+ * No need to follow this irqs on/off section: the syscall
11704+ * disabled irqs and here we enable it straight after entry:
11705+ */
11706+ ENABLE_INTERRUPTS(CLBR_NONE)
11707+ GET_THREAD_INFO(%r11)
11708+ orl $TS_COMPAT,TI_status(%r11)
11709+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11710 jnz ia32_tracesys
11711 cmpq $(IA32_NR_syscalls-1),%rax
11712 ja ia32_badsys
11713@@ -442,6 +520,9 @@ ia32_tracesys:
11714 RESTORE_REST
11715 cmpq $(IA32_NR_syscalls-1),%rax
11716 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11717+
11718+ pax_erase_kstack
11719+
11720 jmp ia32_do_call
11721 END(ia32_syscall)
11722
11723diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11724index d0b689b..34be51d 100644
11725--- a/arch/x86/ia32/sys_ia32.c
11726+++ b/arch/x86/ia32/sys_ia32.c
11727@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11728 */
11729 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11730 {
11731- typeof(ubuf->st_uid) uid = 0;
11732- typeof(ubuf->st_gid) gid = 0;
11733+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11734+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11735 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11736 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11737 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11738@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11739 mm_segment_t old_fs = get_fs();
11740
11741 set_fs(KERNEL_DS);
11742- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11743+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11744 set_fs(old_fs);
11745 if (put_compat_timespec(&t, interval))
11746 return -EFAULT;
11747@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11748 mm_segment_t old_fs = get_fs();
11749
11750 set_fs(KERNEL_DS);
11751- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11752+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11753 set_fs(old_fs);
11754 if (!ret) {
11755 switch (_NSIG_WORDS) {
11756@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11757 if (copy_siginfo_from_user32(&info, uinfo))
11758 return -EFAULT;
11759 set_fs(KERNEL_DS);
11760- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11761+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11762 set_fs(old_fs);
11763 return ret;
11764 }
11765@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11766 return -EFAULT;
11767
11768 set_fs(KERNEL_DS);
11769- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11770+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11771 count);
11772 set_fs(old_fs);
11773
11774diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11775index 372231c..a5aa1a1 100644
11776--- a/arch/x86/include/asm/alternative-asm.h
11777+++ b/arch/x86/include/asm/alternative-asm.h
11778@@ -18,6 +18,45 @@
11779 .endm
11780 #endif
11781
11782+#ifdef KERNEXEC_PLUGIN
11783+ .macro pax_force_retaddr_bts rip=0
11784+ btsq $63,\rip(%rsp)
11785+ .endm
11786+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11787+ .macro pax_force_retaddr rip=0, reload=0
11788+ btsq $63,\rip(%rsp)
11789+ .endm
11790+ .macro pax_force_fptr ptr
11791+ btsq $63,\ptr
11792+ .endm
11793+ .macro pax_set_fptr_mask
11794+ .endm
11795+#endif
11796+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11797+ .macro pax_force_retaddr rip=0, reload=0
11798+ .if \reload
11799+ pax_set_fptr_mask
11800+ .endif
11801+ orq %r10,\rip(%rsp)
11802+ .endm
11803+ .macro pax_force_fptr ptr
11804+ orq %r10,\ptr
11805+ .endm
11806+ .macro pax_set_fptr_mask
11807+ movabs $0x8000000000000000,%r10
11808+ .endm
11809+#endif
11810+#else
11811+ .macro pax_force_retaddr rip=0, reload=0
11812+ .endm
11813+ .macro pax_force_fptr ptr
11814+ .endm
11815+ .macro pax_force_retaddr_bts rip=0
11816+ .endm
11817+ .macro pax_set_fptr_mask
11818+ .endm
11819+#endif
11820+
11821 .macro altinstruction_entry orig alt feature orig_len alt_len
11822 .long \orig - .
11823 .long \alt - .
11824diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11825index 58ed6d9..f1cbe58 100644
11826--- a/arch/x86/include/asm/alternative.h
11827+++ b/arch/x86/include/asm/alternative.h
11828@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11829 ".pushsection .discard,\"aw\",@progbits\n" \
11830 DISCARD_ENTRY(1) \
11831 ".popsection\n" \
11832- ".pushsection .altinstr_replacement, \"ax\"\n" \
11833+ ".pushsection .altinstr_replacement, \"a\"\n" \
11834 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11835 ".popsection"
11836
11837@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11838 DISCARD_ENTRY(1) \
11839 DISCARD_ENTRY(2) \
11840 ".popsection\n" \
11841- ".pushsection .altinstr_replacement, \"ax\"\n" \
11842+ ".pushsection .altinstr_replacement, \"a\"\n" \
11843 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11844 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11845 ".popsection"
11846diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11847index 3388034..050f0b9 100644
11848--- a/arch/x86/include/asm/apic.h
11849+++ b/arch/x86/include/asm/apic.h
11850@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11851
11852 #ifdef CONFIG_X86_LOCAL_APIC
11853
11854-extern unsigned int apic_verbosity;
11855+extern int apic_verbosity;
11856 extern int local_apic_timer_c2_ok;
11857
11858 extern int disable_apic;
11859diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11860index 20370c6..a2eb9b0 100644
11861--- a/arch/x86/include/asm/apm.h
11862+++ b/arch/x86/include/asm/apm.h
11863@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11864 __asm__ __volatile__(APM_DO_ZERO_SEGS
11865 "pushl %%edi\n\t"
11866 "pushl %%ebp\n\t"
11867- "lcall *%%cs:apm_bios_entry\n\t"
11868+ "lcall *%%ss:apm_bios_entry\n\t"
11869 "setc %%al\n\t"
11870 "popl %%ebp\n\t"
11871 "popl %%edi\n\t"
11872@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11873 __asm__ __volatile__(APM_DO_ZERO_SEGS
11874 "pushl %%edi\n\t"
11875 "pushl %%ebp\n\t"
11876- "lcall *%%cs:apm_bios_entry\n\t"
11877+ "lcall *%%ss:apm_bios_entry\n\t"
11878 "setc %%bl\n\t"
11879 "popl %%ebp\n\t"
11880 "popl %%edi\n\t"
11881diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11882index 722aa3b..3a0bb27 100644
11883--- a/arch/x86/include/asm/atomic.h
11884+++ b/arch/x86/include/asm/atomic.h
11885@@ -22,7 +22,18 @@
11886 */
11887 static inline int atomic_read(const atomic_t *v)
11888 {
11889- return (*(volatile int *)&(v)->counter);
11890+ return (*(volatile const int *)&(v)->counter);
11891+}
11892+
11893+/**
11894+ * atomic_read_unchecked - read atomic variable
11895+ * @v: pointer of type atomic_unchecked_t
11896+ *
11897+ * Atomically reads the value of @v.
11898+ */
11899+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11900+{
11901+ return (*(volatile const int *)&(v)->counter);
11902 }
11903
11904 /**
11905@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11906 }
11907
11908 /**
11909+ * atomic_set_unchecked - set atomic variable
11910+ * @v: pointer of type atomic_unchecked_t
11911+ * @i: required value
11912+ *
11913+ * Atomically sets the value of @v to @i.
11914+ */
11915+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11916+{
11917+ v->counter = i;
11918+}
11919+
11920+/**
11921 * atomic_add - add integer to atomic variable
11922 * @i: integer value to add
11923 * @v: pointer of type atomic_t
11924@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11925 */
11926 static inline void atomic_add(int i, atomic_t *v)
11927 {
11928- asm volatile(LOCK_PREFIX "addl %1,%0"
11929+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11930+
11931+#ifdef CONFIG_PAX_REFCOUNT
11932+ "jno 0f\n"
11933+ LOCK_PREFIX "subl %1,%0\n"
11934+ "int $4\n0:\n"
11935+ _ASM_EXTABLE(0b, 0b)
11936+#endif
11937+
11938+ : "+m" (v->counter)
11939+ : "ir" (i));
11940+}
11941+
11942+/**
11943+ * atomic_add_unchecked - add integer to atomic variable
11944+ * @i: integer value to add
11945+ * @v: pointer of type atomic_unchecked_t
11946+ *
11947+ * Atomically adds @i to @v.
11948+ */
11949+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11950+{
11951+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11952 : "+m" (v->counter)
11953 : "ir" (i));
11954 }
11955@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11956 */
11957 static inline void atomic_sub(int i, atomic_t *v)
11958 {
11959- asm volatile(LOCK_PREFIX "subl %1,%0"
11960+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11961+
11962+#ifdef CONFIG_PAX_REFCOUNT
11963+ "jno 0f\n"
11964+ LOCK_PREFIX "addl %1,%0\n"
11965+ "int $4\n0:\n"
11966+ _ASM_EXTABLE(0b, 0b)
11967+#endif
11968+
11969+ : "+m" (v->counter)
11970+ : "ir" (i));
11971+}
11972+
11973+/**
11974+ * atomic_sub_unchecked - subtract integer from atomic variable
11975+ * @i: integer value to subtract
11976+ * @v: pointer of type atomic_unchecked_t
11977+ *
11978+ * Atomically subtracts @i from @v.
11979+ */
11980+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11981+{
11982+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11983 : "+m" (v->counter)
11984 : "ir" (i));
11985 }
11986@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11987 {
11988 unsigned char c;
11989
11990- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11991+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
11992+
11993+#ifdef CONFIG_PAX_REFCOUNT
11994+ "jno 0f\n"
11995+ LOCK_PREFIX "addl %2,%0\n"
11996+ "int $4\n0:\n"
11997+ _ASM_EXTABLE(0b, 0b)
11998+#endif
11999+
12000+ "sete %1\n"
12001 : "+m" (v->counter), "=qm" (c)
12002 : "ir" (i) : "memory");
12003 return c;
12004@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12005 */
12006 static inline void atomic_inc(atomic_t *v)
12007 {
12008- asm volatile(LOCK_PREFIX "incl %0"
12009+ asm volatile(LOCK_PREFIX "incl %0\n"
12010+
12011+#ifdef CONFIG_PAX_REFCOUNT
12012+ "jno 0f\n"
12013+ LOCK_PREFIX "decl %0\n"
12014+ "int $4\n0:\n"
12015+ _ASM_EXTABLE(0b, 0b)
12016+#endif
12017+
12018+ : "+m" (v->counter));
12019+}
12020+
12021+/**
12022+ * atomic_inc_unchecked - increment atomic variable
12023+ * @v: pointer of type atomic_unchecked_t
12024+ *
12025+ * Atomically increments @v by 1.
12026+ */
12027+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12028+{
12029+ asm volatile(LOCK_PREFIX "incl %0\n"
12030 : "+m" (v->counter));
12031 }
12032
12033@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12034 */
12035 static inline void atomic_dec(atomic_t *v)
12036 {
12037- asm volatile(LOCK_PREFIX "decl %0"
12038+ asm volatile(LOCK_PREFIX "decl %0\n"
12039+
12040+#ifdef CONFIG_PAX_REFCOUNT
12041+ "jno 0f\n"
12042+ LOCK_PREFIX "incl %0\n"
12043+ "int $4\n0:\n"
12044+ _ASM_EXTABLE(0b, 0b)
12045+#endif
12046+
12047+ : "+m" (v->counter));
12048+}
12049+
12050+/**
12051+ * atomic_dec_unchecked - decrement atomic variable
12052+ * @v: pointer of type atomic_unchecked_t
12053+ *
12054+ * Atomically decrements @v by 1.
12055+ */
12056+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12057+{
12058+ asm volatile(LOCK_PREFIX "decl %0\n"
12059 : "+m" (v->counter));
12060 }
12061
12062@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12063 {
12064 unsigned char c;
12065
12066- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12067+ asm volatile(LOCK_PREFIX "decl %0\n"
12068+
12069+#ifdef CONFIG_PAX_REFCOUNT
12070+ "jno 0f\n"
12071+ LOCK_PREFIX "incl %0\n"
12072+ "int $4\n0:\n"
12073+ _ASM_EXTABLE(0b, 0b)
12074+#endif
12075+
12076+ "sete %1\n"
12077 : "+m" (v->counter), "=qm" (c)
12078 : : "memory");
12079 return c != 0;
12080@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12081 {
12082 unsigned char c;
12083
12084- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12085+ asm volatile(LOCK_PREFIX "incl %0\n"
12086+
12087+#ifdef CONFIG_PAX_REFCOUNT
12088+ "jno 0f\n"
12089+ LOCK_PREFIX "decl %0\n"
12090+ "int $4\n0:\n"
12091+ _ASM_EXTABLE(0b, 0b)
12092+#endif
12093+
12094+ "sete %1\n"
12095+ : "+m" (v->counter), "=qm" (c)
12096+ : : "memory");
12097+ return c != 0;
12098+}
12099+
12100+/**
12101+ * atomic_inc_and_test_unchecked - increment and test
12102+ * @v: pointer of type atomic_unchecked_t
12103+ *
12104+ * Atomically increments @v by 1
12105+ * and returns true if the result is zero, or false for all
12106+ * other cases.
12107+ */
12108+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12109+{
12110+ unsigned char c;
12111+
12112+ asm volatile(LOCK_PREFIX "incl %0\n"
12113+ "sete %1\n"
12114 : "+m" (v->counter), "=qm" (c)
12115 : : "memory");
12116 return c != 0;
12117@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12118 {
12119 unsigned char c;
12120
12121- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12122+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12123+
12124+#ifdef CONFIG_PAX_REFCOUNT
12125+ "jno 0f\n"
12126+ LOCK_PREFIX "subl %2,%0\n"
12127+ "int $4\n0:\n"
12128+ _ASM_EXTABLE(0b, 0b)
12129+#endif
12130+
12131+ "sets %1\n"
12132 : "+m" (v->counter), "=qm" (c)
12133 : "ir" (i) : "memory");
12134 return c;
12135@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12136 */
12137 static inline int atomic_add_return(int i, atomic_t *v)
12138 {
12139+ return i + xadd_check_overflow(&v->counter, i);
12140+}
12141+
12142+/**
12143+ * atomic_add_return_unchecked - add integer and return
12144+ * @i: integer value to add
12145+ * @v: pointer of type atomic_unchecked_t
12146+ *
12147+ * Atomically adds @i to @v and returns @i + @v
12148+ */
12149+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12150+{
12151 return i + xadd(&v->counter, i);
12152 }
12153
12154@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12155 }
12156
12157 #define atomic_inc_return(v) (atomic_add_return(1, v))
12158+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12159+{
12160+ return atomic_add_return_unchecked(1, v);
12161+}
12162 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12163
12164 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12165@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12166 return cmpxchg(&v->counter, old, new);
12167 }
12168
12169+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12170+{
12171+ return cmpxchg(&v->counter, old, new);
12172+}
12173+
12174 static inline int atomic_xchg(atomic_t *v, int new)
12175 {
12176 return xchg(&v->counter, new);
12177 }
12178
12179+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12180+{
12181+ return xchg(&v->counter, new);
12182+}
12183+
12184 /**
12185 * __atomic_add_unless - add unless the number is already a given value
12186 * @v: pointer of type atomic_t
12187@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12188 */
12189 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12190 {
12191- int c, old;
12192+ int c, old, new;
12193 c = atomic_read(v);
12194 for (;;) {
12195- if (unlikely(c == (u)))
12196+ if (unlikely(c == u))
12197 break;
12198- old = atomic_cmpxchg((v), c, c + (a));
12199+
12200+ asm volatile("addl %2,%0\n"
12201+
12202+#ifdef CONFIG_PAX_REFCOUNT
12203+ "jno 0f\n"
12204+ "subl %2,%0\n"
12205+ "int $4\n0:\n"
12206+ _ASM_EXTABLE(0b, 0b)
12207+#endif
12208+
12209+ : "=r" (new)
12210+ : "0" (c), "ir" (a));
12211+
12212+ old = atomic_cmpxchg(v, c, new);
12213 if (likely(old == c))
12214 break;
12215 c = old;
12216@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12217 }
12218
12219 /**
12220+ * atomic_inc_not_zero_hint - increment if not null
12221+ * @v: pointer of type atomic_t
12222+ * @hint: probable value of the atomic before the increment
12223+ *
12224+ * This version of atomic_inc_not_zero() gives a hint of probable
12225+ * value of the atomic. This helps processor to not read the memory
12226+ * before doing the atomic read/modify/write cycle, lowering
12227+ * number of bus transactions on some arches.
12228+ *
12229+ * Returns: 0 if increment was not done, 1 otherwise.
12230+ */
12231+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12232+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12233+{
12234+ int val, c = hint, new;
12235+
12236+ /* sanity test, should be removed by compiler if hint is a constant */
12237+ if (!hint)
12238+ return __atomic_add_unless(v, 1, 0);
12239+
12240+ do {
12241+ asm volatile("incl %0\n"
12242+
12243+#ifdef CONFIG_PAX_REFCOUNT
12244+ "jno 0f\n"
12245+ "decl %0\n"
12246+ "int $4\n0:\n"
12247+ _ASM_EXTABLE(0b, 0b)
12248+#endif
12249+
12250+ : "=r" (new)
12251+ : "0" (c));
12252+
12253+ val = atomic_cmpxchg(v, c, new);
12254+ if (val == c)
12255+ return 1;
12256+ c = val;
12257+ } while (c);
12258+
12259+ return 0;
12260+}
12261+
12262+/**
12263 * atomic_inc_short - increment of a short integer
12264 * @v: pointer to type int
12265 *
12266@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12267 #endif
12268
12269 /* These are x86-specific, used by some header files */
12270-#define atomic_clear_mask(mask, addr) \
12271- asm volatile(LOCK_PREFIX "andl %0,%1" \
12272- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12273+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12274+{
12275+ asm volatile(LOCK_PREFIX "andl %1,%0"
12276+ : "+m" (v->counter)
12277+ : "r" (~(mask))
12278+ : "memory");
12279+}
12280
12281-#define atomic_set_mask(mask, addr) \
12282- asm volatile(LOCK_PREFIX "orl %0,%1" \
12283- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12284- : "memory")
12285+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12286+{
12287+ asm volatile(LOCK_PREFIX "andl %1,%0"
12288+ : "+m" (v->counter)
12289+ : "r" (~(mask))
12290+ : "memory");
12291+}
12292+
12293+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12294+{
12295+ asm volatile(LOCK_PREFIX "orl %1,%0"
12296+ : "+m" (v->counter)
12297+ : "r" (mask)
12298+ : "memory");
12299+}
12300+
12301+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12302+{
12303+ asm volatile(LOCK_PREFIX "orl %1,%0"
12304+ : "+m" (v->counter)
12305+ : "r" (mask)
12306+ : "memory");
12307+}
12308
12309 /* Atomic operations are already serializing on x86 */
12310 #define smp_mb__before_atomic_dec() barrier()
12311diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12312index b154de7..aadebd8 100644
12313--- a/arch/x86/include/asm/atomic64_32.h
12314+++ b/arch/x86/include/asm/atomic64_32.h
12315@@ -12,6 +12,14 @@ typedef struct {
12316 u64 __aligned(8) counter;
12317 } atomic64_t;
12318
12319+#ifdef CONFIG_PAX_REFCOUNT
12320+typedef struct {
12321+ u64 __aligned(8) counter;
12322+} atomic64_unchecked_t;
12323+#else
12324+typedef atomic64_t atomic64_unchecked_t;
12325+#endif
12326+
12327 #define ATOMIC64_INIT(val) { (val) }
12328
12329 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12330@@ -37,21 +45,31 @@ typedef struct {
12331 ATOMIC64_DECL_ONE(sym##_386)
12332
12333 ATOMIC64_DECL_ONE(add_386);
12334+ATOMIC64_DECL_ONE(add_unchecked_386);
12335 ATOMIC64_DECL_ONE(sub_386);
12336+ATOMIC64_DECL_ONE(sub_unchecked_386);
12337 ATOMIC64_DECL_ONE(inc_386);
12338+ATOMIC64_DECL_ONE(inc_unchecked_386);
12339 ATOMIC64_DECL_ONE(dec_386);
12340+ATOMIC64_DECL_ONE(dec_unchecked_386);
12341 #endif
12342
12343 #define alternative_atomic64(f, out, in...) \
12344 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12345
12346 ATOMIC64_DECL(read);
12347+ATOMIC64_DECL(read_unchecked);
12348 ATOMIC64_DECL(set);
12349+ATOMIC64_DECL(set_unchecked);
12350 ATOMIC64_DECL(xchg);
12351 ATOMIC64_DECL(add_return);
12352+ATOMIC64_DECL(add_return_unchecked);
12353 ATOMIC64_DECL(sub_return);
12354+ATOMIC64_DECL(sub_return_unchecked);
12355 ATOMIC64_DECL(inc_return);
12356+ATOMIC64_DECL(inc_return_unchecked);
12357 ATOMIC64_DECL(dec_return);
12358+ATOMIC64_DECL(dec_return_unchecked);
12359 ATOMIC64_DECL(dec_if_positive);
12360 ATOMIC64_DECL(inc_not_zero);
12361 ATOMIC64_DECL(add_unless);
12362@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12363 }
12364
12365 /**
12366+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12367+ * @p: pointer to type atomic64_unchecked_t
12368+ * @o: expected value
12369+ * @n: new value
12370+ *
12371+ * Atomically sets @v to @n if it was equal to @o and returns
12372+ * the old value.
12373+ */
12374+
12375+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12376+{
12377+ return cmpxchg64(&v->counter, o, n);
12378+}
12379+
12380+/**
12381 * atomic64_xchg - xchg atomic64 variable
12382 * @v: pointer to type atomic64_t
12383 * @n: value to assign
12384@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12385 }
12386
12387 /**
12388+ * atomic64_set_unchecked - set atomic64 variable
12389+ * @v: pointer to type atomic64_unchecked_t
12390+ * @n: value to assign
12391+ *
12392+ * Atomically sets the value of @v to @n.
12393+ */
12394+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12395+{
12396+ unsigned high = (unsigned)(i >> 32);
12397+ unsigned low = (unsigned)i;
12398+ alternative_atomic64(set, /* no output */,
12399+ "S" (v), "b" (low), "c" (high)
12400+ : "eax", "edx", "memory");
12401+}
12402+
12403+/**
12404 * atomic64_read - read atomic64 variable
12405 * @v: pointer to type atomic64_t
12406 *
12407@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12408 }
12409
12410 /**
12411+ * atomic64_read_unchecked - read atomic64 variable
12412+ * @v: pointer to type atomic64_unchecked_t
12413+ *
12414+ * Atomically reads the value of @v and returns it.
12415+ */
12416+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12417+{
12418+ long long r;
12419+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12420+ return r;
12421+ }
12422+
12423+/**
12424 * atomic64_add_return - add and return
12425 * @i: integer value to add
12426 * @v: pointer to type atomic64_t
12427@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12428 return i;
12429 }
12430
12431+/**
12432+ * atomic64_add_return_unchecked - add and return
12433+ * @i: integer value to add
12434+ * @v: pointer to type atomic64_unchecked_t
12435+ *
12436+ * Atomically adds @i to @v and returns @i + *@v
12437+ */
12438+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12439+{
12440+ alternative_atomic64(add_return_unchecked,
12441+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12442+ ASM_NO_INPUT_CLOBBER("memory"));
12443+ return i;
12444+}
12445+
12446 /*
12447 * Other variants with different arithmetic operators:
12448 */
12449@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12450 return a;
12451 }
12452
12453+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12454+{
12455+ long long a;
12456+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12457+ "S" (v) : "memory", "ecx");
12458+ return a;
12459+}
12460+
12461 static inline long long atomic64_dec_return(atomic64_t *v)
12462 {
12463 long long a;
12464@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12465 }
12466
12467 /**
12468+ * atomic64_add_unchecked - add integer to atomic64 variable
12469+ * @i: integer value to add
12470+ * @v: pointer to type atomic64_unchecked_t
12471+ *
12472+ * Atomically adds @i to @v.
12473+ */
12474+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12475+{
12476+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12477+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12478+ ASM_NO_INPUT_CLOBBER("memory"));
12479+ return i;
12480+}
12481+
12482+/**
12483 * atomic64_sub - subtract the atomic64 variable
12484 * @i: integer value to subtract
12485 * @v: pointer to type atomic64_t
12486diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12487index 0e1cbfc..5623683 100644
12488--- a/arch/x86/include/asm/atomic64_64.h
12489+++ b/arch/x86/include/asm/atomic64_64.h
12490@@ -18,7 +18,19 @@
12491 */
12492 static inline long atomic64_read(const atomic64_t *v)
12493 {
12494- return (*(volatile long *)&(v)->counter);
12495+ return (*(volatile const long *)&(v)->counter);
12496+}
12497+
12498+/**
12499+ * atomic64_read_unchecked - read atomic64 variable
12500+ * @v: pointer of type atomic64_unchecked_t
12501+ *
12502+ * Atomically reads the value of @v.
12503+ * Doesn't imply a read memory barrier.
12504+ */
12505+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12506+{
12507+ return (*(volatile const long *)&(v)->counter);
12508 }
12509
12510 /**
12511@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12512 }
12513
12514 /**
12515+ * atomic64_set_unchecked - set atomic64 variable
12516+ * @v: pointer to type atomic64_unchecked_t
12517+ * @i: required value
12518+ *
12519+ * Atomically sets the value of @v to @i.
12520+ */
12521+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12522+{
12523+ v->counter = i;
12524+}
12525+
12526+/**
12527 * atomic64_add - add integer to atomic64 variable
12528 * @i: integer value to add
12529 * @v: pointer to type atomic64_t
12530@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12531 */
12532 static inline void atomic64_add(long i, atomic64_t *v)
12533 {
12534+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12535+
12536+#ifdef CONFIG_PAX_REFCOUNT
12537+ "jno 0f\n"
12538+ LOCK_PREFIX "subq %1,%0\n"
12539+ "int $4\n0:\n"
12540+ _ASM_EXTABLE(0b, 0b)
12541+#endif
12542+
12543+ : "=m" (v->counter)
12544+ : "er" (i), "m" (v->counter));
12545+}
12546+
12547+/**
12548+ * atomic64_add_unchecked - add integer to atomic64 variable
12549+ * @i: integer value to add
12550+ * @v: pointer to type atomic64_unchecked_t
12551+ *
12552+ * Atomically adds @i to @v.
12553+ */
12554+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12555+{
12556 asm volatile(LOCK_PREFIX "addq %1,%0"
12557 : "=m" (v->counter)
12558 : "er" (i), "m" (v->counter));
12559@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12560 */
12561 static inline void atomic64_sub(long i, atomic64_t *v)
12562 {
12563- asm volatile(LOCK_PREFIX "subq %1,%0"
12564+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12565+
12566+#ifdef CONFIG_PAX_REFCOUNT
12567+ "jno 0f\n"
12568+ LOCK_PREFIX "addq %1,%0\n"
12569+ "int $4\n0:\n"
12570+ _ASM_EXTABLE(0b, 0b)
12571+#endif
12572+
12573+ : "=m" (v->counter)
12574+ : "er" (i), "m" (v->counter));
12575+}
12576+
12577+/**
12578+ * atomic64_sub_unchecked - subtract the atomic64 variable
12579+ * @i: integer value to subtract
12580+ * @v: pointer to type atomic64_unchecked_t
12581+ *
12582+ * Atomically subtracts @i from @v.
12583+ */
12584+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12585+{
12586+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12587 : "=m" (v->counter)
12588 : "er" (i), "m" (v->counter));
12589 }
12590@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12591 {
12592 unsigned char c;
12593
12594- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12595+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12596+
12597+#ifdef CONFIG_PAX_REFCOUNT
12598+ "jno 0f\n"
12599+ LOCK_PREFIX "addq %2,%0\n"
12600+ "int $4\n0:\n"
12601+ _ASM_EXTABLE(0b, 0b)
12602+#endif
12603+
12604+ "sete %1\n"
12605 : "=m" (v->counter), "=qm" (c)
12606 : "er" (i), "m" (v->counter) : "memory");
12607 return c;
12608@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12609 */
12610 static inline void atomic64_inc(atomic64_t *v)
12611 {
12612+ asm volatile(LOCK_PREFIX "incq %0\n"
12613+
12614+#ifdef CONFIG_PAX_REFCOUNT
12615+ "jno 0f\n"
12616+ LOCK_PREFIX "decq %0\n"
12617+ "int $4\n0:\n"
12618+ _ASM_EXTABLE(0b, 0b)
12619+#endif
12620+
12621+ : "=m" (v->counter)
12622+ : "m" (v->counter));
12623+}
12624+
12625+/**
12626+ * atomic64_inc_unchecked - increment atomic64 variable
12627+ * @v: pointer to type atomic64_unchecked_t
12628+ *
12629+ * Atomically increments @v by 1.
12630+ */
12631+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12632+{
12633 asm volatile(LOCK_PREFIX "incq %0"
12634 : "=m" (v->counter)
12635 : "m" (v->counter));
12636@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12637 */
12638 static inline void atomic64_dec(atomic64_t *v)
12639 {
12640- asm volatile(LOCK_PREFIX "decq %0"
12641+ asm volatile(LOCK_PREFIX "decq %0\n"
12642+
12643+#ifdef CONFIG_PAX_REFCOUNT
12644+ "jno 0f\n"
12645+ LOCK_PREFIX "incq %0\n"
12646+ "int $4\n0:\n"
12647+ _ASM_EXTABLE(0b, 0b)
12648+#endif
12649+
12650+ : "=m" (v->counter)
12651+ : "m" (v->counter));
12652+}
12653+
12654+/**
12655+ * atomic64_dec_unchecked - decrement atomic64 variable
12656+ * @v: pointer to type atomic64_t
12657+ *
12658+ * Atomically decrements @v by 1.
12659+ */
12660+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12661+{
12662+ asm volatile(LOCK_PREFIX "decq %0\n"
12663 : "=m" (v->counter)
12664 : "m" (v->counter));
12665 }
12666@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12667 {
12668 unsigned char c;
12669
12670- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12671+ asm volatile(LOCK_PREFIX "decq %0\n"
12672+
12673+#ifdef CONFIG_PAX_REFCOUNT
12674+ "jno 0f\n"
12675+ LOCK_PREFIX "incq %0\n"
12676+ "int $4\n0:\n"
12677+ _ASM_EXTABLE(0b, 0b)
12678+#endif
12679+
12680+ "sete %1\n"
12681 : "=m" (v->counter), "=qm" (c)
12682 : "m" (v->counter) : "memory");
12683 return c != 0;
12684@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12685 {
12686 unsigned char c;
12687
12688- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12689+ asm volatile(LOCK_PREFIX "incq %0\n"
12690+
12691+#ifdef CONFIG_PAX_REFCOUNT
12692+ "jno 0f\n"
12693+ LOCK_PREFIX "decq %0\n"
12694+ "int $4\n0:\n"
12695+ _ASM_EXTABLE(0b, 0b)
12696+#endif
12697+
12698+ "sete %1\n"
12699 : "=m" (v->counter), "=qm" (c)
12700 : "m" (v->counter) : "memory");
12701 return c != 0;
12702@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12703 {
12704 unsigned char c;
12705
12706- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12707+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12708+
12709+#ifdef CONFIG_PAX_REFCOUNT
12710+ "jno 0f\n"
12711+ LOCK_PREFIX "subq %2,%0\n"
12712+ "int $4\n0:\n"
12713+ _ASM_EXTABLE(0b, 0b)
12714+#endif
12715+
12716+ "sets %1\n"
12717 : "=m" (v->counter), "=qm" (c)
12718 : "er" (i), "m" (v->counter) : "memory");
12719 return c;
12720@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12721 */
12722 static inline long atomic64_add_return(long i, atomic64_t *v)
12723 {
12724+ return i + xadd_check_overflow(&v->counter, i);
12725+}
12726+
12727+/**
12728+ * atomic64_add_return_unchecked - add and return
12729+ * @i: integer value to add
12730+ * @v: pointer to type atomic64_unchecked_t
12731+ *
12732+ * Atomically adds @i to @v and returns @i + @v
12733+ */
12734+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12735+{
12736 return i + xadd(&v->counter, i);
12737 }
12738
12739@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12740 }
12741
12742 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12743+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12744+{
12745+ return atomic64_add_return_unchecked(1, v);
12746+}
12747 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12748
12749 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12750@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12751 return cmpxchg(&v->counter, old, new);
12752 }
12753
12754+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12755+{
12756+ return cmpxchg(&v->counter, old, new);
12757+}
12758+
12759 static inline long atomic64_xchg(atomic64_t *v, long new)
12760 {
12761 return xchg(&v->counter, new);
12762@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12763 */
12764 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12765 {
12766- long c, old;
12767+ long c, old, new;
12768 c = atomic64_read(v);
12769 for (;;) {
12770- if (unlikely(c == (u)))
12771+ if (unlikely(c == u))
12772 break;
12773- old = atomic64_cmpxchg((v), c, c + (a));
12774+
12775+ asm volatile("add %2,%0\n"
12776+
12777+#ifdef CONFIG_PAX_REFCOUNT
12778+ "jno 0f\n"
12779+ "sub %2,%0\n"
12780+ "int $4\n0:\n"
12781+ _ASM_EXTABLE(0b, 0b)
12782+#endif
12783+
12784+ : "=r" (new)
12785+ : "0" (c), "ir" (a));
12786+
12787+ old = atomic64_cmpxchg(v, c, new);
12788 if (likely(old == c))
12789 break;
12790 c = old;
12791 }
12792- return c != (u);
12793+ return c != u;
12794 }
12795
12796 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12797diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12798index 6dfd019..28e188d 100644
12799--- a/arch/x86/include/asm/bitops.h
12800+++ b/arch/x86/include/asm/bitops.h
12801@@ -40,7 +40,7 @@
12802 * a mask operation on a byte.
12803 */
12804 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12805-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12806+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12807 #define CONST_MASK(nr) (1 << ((nr) & 7))
12808
12809 /**
12810@@ -486,7 +486,7 @@ static inline int fls(int x)
12811 * at position 64.
12812 */
12813 #ifdef CONFIG_X86_64
12814-static __always_inline int fls64(__u64 x)
12815+static __always_inline long fls64(__u64 x)
12816 {
12817 int bitpos = -1;
12818 /*
12819diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12820index 4fa687a..60f2d39 100644
12821--- a/arch/x86/include/asm/boot.h
12822+++ b/arch/x86/include/asm/boot.h
12823@@ -6,10 +6,15 @@
12824 #include <uapi/asm/boot.h>
12825
12826 /* Physical address where kernel should be loaded. */
12827-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12828+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12829 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12830 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12831
12832+#ifndef __ASSEMBLY__
12833+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12834+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12835+#endif
12836+
12837 /* Minimum kernel alignment, as a power of two */
12838 #ifdef CONFIG_X86_64
12839 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12840diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12841index 48f99f1..d78ebf9 100644
12842--- a/arch/x86/include/asm/cache.h
12843+++ b/arch/x86/include/asm/cache.h
12844@@ -5,12 +5,13 @@
12845
12846 /* L1 cache line size */
12847 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12848-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12849+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12850
12851 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12852+#define __read_only __attribute__((__section__(".data..read_only")))
12853
12854 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12855-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12856+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12857
12858 #ifdef CONFIG_X86_VSMP
12859 #ifdef CONFIG_SMP
12860diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12861index 9863ee3..4a1f8e1 100644
12862--- a/arch/x86/include/asm/cacheflush.h
12863+++ b/arch/x86/include/asm/cacheflush.h
12864@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12865 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12866
12867 if (pg_flags == _PGMT_DEFAULT)
12868- return -1;
12869+ return ~0UL;
12870 else if (pg_flags == _PGMT_WC)
12871 return _PAGE_CACHE_WC;
12872 else if (pg_flags == _PGMT_UC_MINUS)
12873diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12874index 46fc474..b02b0f9 100644
12875--- a/arch/x86/include/asm/checksum_32.h
12876+++ b/arch/x86/include/asm/checksum_32.h
12877@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12878 int len, __wsum sum,
12879 int *src_err_ptr, int *dst_err_ptr);
12880
12881+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12882+ int len, __wsum sum,
12883+ int *src_err_ptr, int *dst_err_ptr);
12884+
12885+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12886+ int len, __wsum sum,
12887+ int *src_err_ptr, int *dst_err_ptr);
12888+
12889 /*
12890 * Note: when you get a NULL pointer exception here this means someone
12891 * passed in an incorrect kernel address to one of these functions.
12892@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12893 int *err_ptr)
12894 {
12895 might_sleep();
12896- return csum_partial_copy_generic((__force void *)src, dst,
12897+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12898 len, sum, err_ptr, NULL);
12899 }
12900
12901@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12902 {
12903 might_sleep();
12904 if (access_ok(VERIFY_WRITE, dst, len))
12905- return csum_partial_copy_generic(src, (__force void *)dst,
12906+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12907 len, sum, NULL, err_ptr);
12908
12909 if (len)
12910diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12911index 8d871ea..c1a0dc9 100644
12912--- a/arch/x86/include/asm/cmpxchg.h
12913+++ b/arch/x86/include/asm/cmpxchg.h
12914@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12915 __compiletime_error("Bad argument size for cmpxchg");
12916 extern void __xadd_wrong_size(void)
12917 __compiletime_error("Bad argument size for xadd");
12918+extern void __xadd_check_overflow_wrong_size(void)
12919+ __compiletime_error("Bad argument size for xadd_check_overflow");
12920 extern void __add_wrong_size(void)
12921 __compiletime_error("Bad argument size for add");
12922+extern void __add_check_overflow_wrong_size(void)
12923+ __compiletime_error("Bad argument size for add_check_overflow");
12924
12925 /*
12926 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12927@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12928 __ret; \
12929 })
12930
12931+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12932+ ({ \
12933+ __typeof__ (*(ptr)) __ret = (arg); \
12934+ switch (sizeof(*(ptr))) { \
12935+ case __X86_CASE_L: \
12936+ asm volatile (lock #op "l %0, %1\n" \
12937+ "jno 0f\n" \
12938+ "mov %0,%1\n" \
12939+ "int $4\n0:\n" \
12940+ _ASM_EXTABLE(0b, 0b) \
12941+ : "+r" (__ret), "+m" (*(ptr)) \
12942+ : : "memory", "cc"); \
12943+ break; \
12944+ case __X86_CASE_Q: \
12945+ asm volatile (lock #op "q %q0, %1\n" \
12946+ "jno 0f\n" \
12947+ "mov %0,%1\n" \
12948+ "int $4\n0:\n" \
12949+ _ASM_EXTABLE(0b, 0b) \
12950+ : "+r" (__ret), "+m" (*(ptr)) \
12951+ : : "memory", "cc"); \
12952+ break; \
12953+ default: \
12954+ __ ## op ## _check_overflow_wrong_size(); \
12955+ } \
12956+ __ret; \
12957+ })
12958+
12959 /*
12960 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12961 * Since this is generally used to protect other memory information, we
12962@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12963 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12964 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12965
12966+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12967+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12968+
12969 #define __add(ptr, inc, lock) \
12970 ({ \
12971 __typeof__ (*(ptr)) __ret = (inc); \
12972diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12973index 2d9075e..b75a844 100644
12974--- a/arch/x86/include/asm/cpufeature.h
12975+++ b/arch/x86/include/asm/cpufeature.h
12976@@ -206,7 +206,7 @@
12977 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12978 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12979 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12980-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12981+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12982 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12983 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12984 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12985@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12986 ".section .discard,\"aw\",@progbits\n"
12987 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12988 ".previous\n"
12989- ".section .altinstr_replacement,\"ax\"\n"
12990+ ".section .altinstr_replacement,\"a\"\n"
12991 "3: movb $1,%0\n"
12992 "4:\n"
12993 ".previous\n"
12994diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12995index 8bf1c06..b6ae785 100644
12996--- a/arch/x86/include/asm/desc.h
12997+++ b/arch/x86/include/asm/desc.h
12998@@ -4,6 +4,7 @@
12999 #include <asm/desc_defs.h>
13000 #include <asm/ldt.h>
13001 #include <asm/mmu.h>
13002+#include <asm/pgtable.h>
13003
13004 #include <linux/smp.h>
13005 #include <linux/percpu.h>
13006@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13007
13008 desc->type = (info->read_exec_only ^ 1) << 1;
13009 desc->type |= info->contents << 2;
13010+ desc->type |= info->seg_not_present ^ 1;
13011
13012 desc->s = 1;
13013 desc->dpl = 0x3;
13014@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13015 }
13016
13017 extern struct desc_ptr idt_descr;
13018-extern gate_desc idt_table[];
13019 extern struct desc_ptr nmi_idt_descr;
13020-extern gate_desc nmi_idt_table[];
13021-
13022-struct gdt_page {
13023- struct desc_struct gdt[GDT_ENTRIES];
13024-} __attribute__((aligned(PAGE_SIZE)));
13025-
13026-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13027+extern gate_desc idt_table[256];
13028+extern gate_desc nmi_idt_table[256];
13029
13030+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13031 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13032 {
13033- return per_cpu(gdt_page, cpu).gdt;
13034+ return cpu_gdt_table[cpu];
13035 }
13036
13037 #ifdef CONFIG_X86_64
13038@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13039 unsigned long base, unsigned dpl, unsigned flags,
13040 unsigned short seg)
13041 {
13042- gate->a = (seg << 16) | (base & 0xffff);
13043- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13044+ gate->gate.offset_low = base;
13045+ gate->gate.seg = seg;
13046+ gate->gate.reserved = 0;
13047+ gate->gate.type = type;
13048+ gate->gate.s = 0;
13049+ gate->gate.dpl = dpl;
13050+ gate->gate.p = 1;
13051+ gate->gate.offset_high = base >> 16;
13052 }
13053
13054 #endif
13055@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13056
13057 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13058 {
13059+ pax_open_kernel();
13060 memcpy(&idt[entry], gate, sizeof(*gate));
13061+ pax_close_kernel();
13062 }
13063
13064 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13065 {
13066+ pax_open_kernel();
13067 memcpy(&ldt[entry], desc, 8);
13068+ pax_close_kernel();
13069 }
13070
13071 static inline void
13072@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13073 default: size = sizeof(*gdt); break;
13074 }
13075
13076+ pax_open_kernel();
13077 memcpy(&gdt[entry], desc, size);
13078+ pax_close_kernel();
13079 }
13080
13081 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13082@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13083
13084 static inline void native_load_tr_desc(void)
13085 {
13086+ pax_open_kernel();
13087 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13088+ pax_close_kernel();
13089 }
13090
13091 static inline void native_load_gdt(const struct desc_ptr *dtr)
13092@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13093 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13094 unsigned int i;
13095
13096+ pax_open_kernel();
13097 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13098 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13099+ pax_close_kernel();
13100 }
13101
13102 #define _LDT_empty(info) \
13103@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13104 preempt_enable();
13105 }
13106
13107-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13108+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13109 {
13110 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13111 }
13112@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13113 }
13114
13115 #ifdef CONFIG_X86_64
13116-static inline void set_nmi_gate(int gate, void *addr)
13117+static inline void set_nmi_gate(int gate, const void *addr)
13118 {
13119 gate_desc s;
13120
13121@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13122 }
13123 #endif
13124
13125-static inline void _set_gate(int gate, unsigned type, void *addr,
13126+static inline void _set_gate(int gate, unsigned type, const void *addr,
13127 unsigned dpl, unsigned ist, unsigned seg)
13128 {
13129 gate_desc s;
13130@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13131 * Pentium F0 0F bugfix can have resulted in the mapped
13132 * IDT being write-protected.
13133 */
13134-static inline void set_intr_gate(unsigned int n, void *addr)
13135+static inline void set_intr_gate(unsigned int n, const void *addr)
13136 {
13137 BUG_ON((unsigned)n > 0xFF);
13138 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13139@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13140 /*
13141 * This routine sets up an interrupt gate at directory privilege level 3.
13142 */
13143-static inline void set_system_intr_gate(unsigned int n, void *addr)
13144+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13145 {
13146 BUG_ON((unsigned)n > 0xFF);
13147 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13148 }
13149
13150-static inline void set_system_trap_gate(unsigned int n, void *addr)
13151+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13152 {
13153 BUG_ON((unsigned)n > 0xFF);
13154 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13155 }
13156
13157-static inline void set_trap_gate(unsigned int n, void *addr)
13158+static inline void set_trap_gate(unsigned int n, const void *addr)
13159 {
13160 BUG_ON((unsigned)n > 0xFF);
13161 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13162@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13163 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13164 {
13165 BUG_ON((unsigned)n > 0xFF);
13166- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13167+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13168 }
13169
13170-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13171+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13172 {
13173 BUG_ON((unsigned)n > 0xFF);
13174 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13175 }
13176
13177-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13178+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13179 {
13180 BUG_ON((unsigned)n > 0xFF);
13181 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13182 }
13183
13184+#ifdef CONFIG_X86_32
13185+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13186+{
13187+ struct desc_struct d;
13188+
13189+ if (likely(limit))
13190+ limit = (limit - 1UL) >> PAGE_SHIFT;
13191+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13192+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13193+}
13194+#endif
13195+
13196 #endif /* _ASM_X86_DESC_H */
13197diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13198index 278441f..b95a174 100644
13199--- a/arch/x86/include/asm/desc_defs.h
13200+++ b/arch/x86/include/asm/desc_defs.h
13201@@ -31,6 +31,12 @@ struct desc_struct {
13202 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13203 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13204 };
13205+ struct {
13206+ u16 offset_low;
13207+ u16 seg;
13208+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13209+ unsigned offset_high: 16;
13210+ } gate;
13211 };
13212 } __attribute__((packed));
13213
13214diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13215index ced283a..ffe04cc 100644
13216--- a/arch/x86/include/asm/div64.h
13217+++ b/arch/x86/include/asm/div64.h
13218@@ -39,7 +39,7 @@
13219 __mod; \
13220 })
13221
13222-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13223+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13224 {
13225 union {
13226 u64 v64;
13227diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13228index 9c999c1..3860cb8 100644
13229--- a/arch/x86/include/asm/elf.h
13230+++ b/arch/x86/include/asm/elf.h
13231@@ -243,7 +243,25 @@ extern int force_personality32;
13232 the loader. We need to make sure that it is out of the way of the program
13233 that it will "exec", and that there is sufficient room for the brk. */
13234
13235+#ifdef CONFIG_PAX_SEGMEXEC
13236+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13237+#else
13238 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13239+#endif
13240+
13241+#ifdef CONFIG_PAX_ASLR
13242+#ifdef CONFIG_X86_32
13243+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13244+
13245+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13246+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13247+#else
13248+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13249+
13250+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13251+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13252+#endif
13253+#endif
13254
13255 /* This yields a mask that user programs can use to figure out what
13256 instruction set this CPU supports. This could be done in user space,
13257@@ -296,16 +314,12 @@ do { \
13258
13259 #define ARCH_DLINFO \
13260 do { \
13261- if (vdso_enabled) \
13262- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13263- (unsigned long)current->mm->context.vdso); \
13264+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13265 } while (0)
13266
13267 #define ARCH_DLINFO_X32 \
13268 do { \
13269- if (vdso_enabled) \
13270- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13271- (unsigned long)current->mm->context.vdso); \
13272+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13273 } while (0)
13274
13275 #define AT_SYSINFO 32
13276@@ -320,7 +334,7 @@ else \
13277
13278 #endif /* !CONFIG_X86_32 */
13279
13280-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13281+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13282
13283 #define VDSO_ENTRY \
13284 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13285@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13286 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13287 #define compat_arch_setup_additional_pages syscall32_setup_pages
13288
13289-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13290-#define arch_randomize_brk arch_randomize_brk
13291-
13292 /*
13293 * True on X86_32 or when emulating IA32 on X86_64
13294 */
13295diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13296index 75ce3f4..882e801 100644
13297--- a/arch/x86/include/asm/emergency-restart.h
13298+++ b/arch/x86/include/asm/emergency-restart.h
13299@@ -13,6 +13,6 @@ enum reboot_type {
13300
13301 extern enum reboot_type reboot_type;
13302
13303-extern void machine_emergency_restart(void);
13304+extern void machine_emergency_restart(void) __noreturn;
13305
13306 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13307diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13308index 41ab26e..a88c9e6 100644
13309--- a/arch/x86/include/asm/fpu-internal.h
13310+++ b/arch/x86/include/asm/fpu-internal.h
13311@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13312 ({ \
13313 int err; \
13314 asm volatile(ASM_STAC "\n" \
13315- "1:" #insn "\n\t" \
13316+ "1:" \
13317+ __copyuser_seg \
13318+ #insn "\n\t" \
13319 "2: " ASM_CLAC "\n" \
13320 ".section .fixup,\"ax\"\n" \
13321 "3: movl $-1,%[err]\n" \
13322@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13323 "emms\n\t" /* clear stack tags */
13324 "fildl %P[addr]", /* set F?P to defined value */
13325 X86_FEATURE_FXSAVE_LEAK,
13326- [addr] "m" (tsk->thread.fpu.has_fpu));
13327+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13328
13329 return fpu_restore_checking(&tsk->thread.fpu);
13330 }
13331diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13332index be27ba1..8f13ff9 100644
13333--- a/arch/x86/include/asm/futex.h
13334+++ b/arch/x86/include/asm/futex.h
13335@@ -12,6 +12,7 @@
13336 #include <asm/smap.h>
13337
13338 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13339+ typecheck(u32 __user *, uaddr); \
13340 asm volatile("\t" ASM_STAC "\n" \
13341 "1:\t" insn "\n" \
13342 "2:\t" ASM_CLAC "\n" \
13343@@ -20,15 +21,16 @@
13344 "\tjmp\t2b\n" \
13345 "\t.previous\n" \
13346 _ASM_EXTABLE(1b, 3b) \
13347- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13348+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13349 : "i" (-EFAULT), "0" (oparg), "1" (0))
13350
13351 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13352+ typecheck(u32 __user *, uaddr); \
13353 asm volatile("\t" ASM_STAC "\n" \
13354 "1:\tmovl %2, %0\n" \
13355 "\tmovl\t%0, %3\n" \
13356 "\t" insn "\n" \
13357- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13358+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13359 "\tjnz\t1b\n" \
13360 "3:\t" ASM_CLAC "\n" \
13361 "\t.section .fixup,\"ax\"\n" \
13362@@ -38,7 +40,7 @@
13363 _ASM_EXTABLE(1b, 4b) \
13364 _ASM_EXTABLE(2b, 4b) \
13365 : "=&a" (oldval), "=&r" (ret), \
13366- "+m" (*uaddr), "=&r" (tem) \
13367+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13368 : "r" (oparg), "i" (-EFAULT), "1" (0))
13369
13370 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13371@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13372
13373 switch (op) {
13374 case FUTEX_OP_SET:
13375- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13376+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13377 break;
13378 case FUTEX_OP_ADD:
13379- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13380+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13381 uaddr, oparg);
13382 break;
13383 case FUTEX_OP_OR:
13384@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13385 return -EFAULT;
13386
13387 asm volatile("\t" ASM_STAC "\n"
13388- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13389+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13390 "2:\t" ASM_CLAC "\n"
13391 "\t.section .fixup, \"ax\"\n"
13392 "3:\tmov %3, %0\n"
13393 "\tjmp 2b\n"
13394 "\t.previous\n"
13395 _ASM_EXTABLE(1b, 3b)
13396- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13397+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13398 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13399 : "memory"
13400 );
13401diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13402index eb92a6e..b98b2f4 100644
13403--- a/arch/x86/include/asm/hw_irq.h
13404+++ b/arch/x86/include/asm/hw_irq.h
13405@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13406 extern void enable_IO_APIC(void);
13407
13408 /* Statistics */
13409-extern atomic_t irq_err_count;
13410-extern atomic_t irq_mis_count;
13411+extern atomic_unchecked_t irq_err_count;
13412+extern atomic_unchecked_t irq_mis_count;
13413
13414 /* EISA */
13415 extern void eisa_set_level_irq(unsigned int irq);
13416diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13417index a203659..9889f1c 100644
13418--- a/arch/x86/include/asm/i8259.h
13419+++ b/arch/x86/include/asm/i8259.h
13420@@ -62,7 +62,7 @@ struct legacy_pic {
13421 void (*init)(int auto_eoi);
13422 int (*irq_pending)(unsigned int irq);
13423 void (*make_irq)(unsigned int irq);
13424-};
13425+} __do_const;
13426
13427 extern struct legacy_pic *legacy_pic;
13428 extern struct legacy_pic null_legacy_pic;
13429diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13430index d8e8eef..1765f78 100644
13431--- a/arch/x86/include/asm/io.h
13432+++ b/arch/x86/include/asm/io.h
13433@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13434 "m" (*(volatile type __force *)addr) barrier); }
13435
13436 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13437-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13438-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13439+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13440+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13441
13442 build_mmio_read(__readb, "b", unsigned char, "=q", )
13443-build_mmio_read(__readw, "w", unsigned short, "=r", )
13444-build_mmio_read(__readl, "l", unsigned int, "=r", )
13445+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13446+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13447
13448 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13449 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13450@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13451 return ioremap_nocache(offset, size);
13452 }
13453
13454-extern void iounmap(volatile void __iomem *addr);
13455+extern void iounmap(const volatile void __iomem *addr);
13456
13457 extern void set_iounmap_nonlazy(void);
13458
13459@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13460
13461 #include <linux/vmalloc.h>
13462
13463+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13464+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13465+{
13466+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13467+}
13468+
13469+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13470+{
13471+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13472+}
13473+
13474 /*
13475 * Convert a virtual cached pointer to an uncached pointer
13476 */
13477diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13478index bba3cf8..06bc8da 100644
13479--- a/arch/x86/include/asm/irqflags.h
13480+++ b/arch/x86/include/asm/irqflags.h
13481@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13482 sti; \
13483 sysexit
13484
13485+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13486+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13487+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13488+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13489+
13490 #else
13491 #define INTERRUPT_RETURN iret
13492 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13493diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13494index d3ddd17..c9fb0cc 100644
13495--- a/arch/x86/include/asm/kprobes.h
13496+++ b/arch/x86/include/asm/kprobes.h
13497@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13498 #define RELATIVEJUMP_SIZE 5
13499 #define RELATIVECALL_OPCODE 0xe8
13500 #define RELATIVE_ADDR_SIZE 4
13501-#define MAX_STACK_SIZE 64
13502-#define MIN_STACK_SIZE(ADDR) \
13503- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13504- THREAD_SIZE - (unsigned long)(ADDR))) \
13505- ? (MAX_STACK_SIZE) \
13506- : (((unsigned long)current_thread_info()) + \
13507- THREAD_SIZE - (unsigned long)(ADDR)))
13508+#define MAX_STACK_SIZE 64UL
13509+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13510
13511 #define flush_insn_slot(p) do { } while (0)
13512
13513diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
13514index dc87b65..85039f9 100644
13515--- a/arch/x86/include/asm/kvm_host.h
13516+++ b/arch/x86/include/asm/kvm_host.h
13517@@ -419,8 +419,8 @@ struct kvm_vcpu_arch {
13518 gpa_t time;
13519 struct pvclock_vcpu_time_info hv_clock;
13520 unsigned int hw_tsc_khz;
13521- unsigned int time_offset;
13522- struct page *time_page;
13523+ struct gfn_to_hva_cache pv_time;
13524+ bool pv_time_enabled;
13525 /* set guest stopped flag in pvclock flags field */
13526 bool pvclock_set_guest_stopped_request;
13527
13528diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13529index 2d89e39..baee879 100644
13530--- a/arch/x86/include/asm/local.h
13531+++ b/arch/x86/include/asm/local.h
13532@@ -10,33 +10,97 @@ typedef struct {
13533 atomic_long_t a;
13534 } local_t;
13535
13536+typedef struct {
13537+ atomic_long_unchecked_t a;
13538+} local_unchecked_t;
13539+
13540 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13541
13542 #define local_read(l) atomic_long_read(&(l)->a)
13543+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13544 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13545+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13546
13547 static inline void local_inc(local_t *l)
13548 {
13549- asm volatile(_ASM_INC "%0"
13550+ asm volatile(_ASM_INC "%0\n"
13551+
13552+#ifdef CONFIG_PAX_REFCOUNT
13553+ "jno 0f\n"
13554+ _ASM_DEC "%0\n"
13555+ "int $4\n0:\n"
13556+ _ASM_EXTABLE(0b, 0b)
13557+#endif
13558+
13559+ : "+m" (l->a.counter));
13560+}
13561+
13562+static inline void local_inc_unchecked(local_unchecked_t *l)
13563+{
13564+ asm volatile(_ASM_INC "%0\n"
13565 : "+m" (l->a.counter));
13566 }
13567
13568 static inline void local_dec(local_t *l)
13569 {
13570- asm volatile(_ASM_DEC "%0"
13571+ asm volatile(_ASM_DEC "%0\n"
13572+
13573+#ifdef CONFIG_PAX_REFCOUNT
13574+ "jno 0f\n"
13575+ _ASM_INC "%0\n"
13576+ "int $4\n0:\n"
13577+ _ASM_EXTABLE(0b, 0b)
13578+#endif
13579+
13580+ : "+m" (l->a.counter));
13581+}
13582+
13583+static inline void local_dec_unchecked(local_unchecked_t *l)
13584+{
13585+ asm volatile(_ASM_DEC "%0\n"
13586 : "+m" (l->a.counter));
13587 }
13588
13589 static inline void local_add(long i, local_t *l)
13590 {
13591- asm volatile(_ASM_ADD "%1,%0"
13592+ asm volatile(_ASM_ADD "%1,%0\n"
13593+
13594+#ifdef CONFIG_PAX_REFCOUNT
13595+ "jno 0f\n"
13596+ _ASM_SUB "%1,%0\n"
13597+ "int $4\n0:\n"
13598+ _ASM_EXTABLE(0b, 0b)
13599+#endif
13600+
13601+ : "+m" (l->a.counter)
13602+ : "ir" (i));
13603+}
13604+
13605+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13606+{
13607+ asm volatile(_ASM_ADD "%1,%0\n"
13608 : "+m" (l->a.counter)
13609 : "ir" (i));
13610 }
13611
13612 static inline void local_sub(long i, local_t *l)
13613 {
13614- asm volatile(_ASM_SUB "%1,%0"
13615+ asm volatile(_ASM_SUB "%1,%0\n"
13616+
13617+#ifdef CONFIG_PAX_REFCOUNT
13618+ "jno 0f\n"
13619+ _ASM_ADD "%1,%0\n"
13620+ "int $4\n0:\n"
13621+ _ASM_EXTABLE(0b, 0b)
13622+#endif
13623+
13624+ : "+m" (l->a.counter)
13625+ : "ir" (i));
13626+}
13627+
13628+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13629+{
13630+ asm volatile(_ASM_SUB "%1,%0\n"
13631 : "+m" (l->a.counter)
13632 : "ir" (i));
13633 }
13634@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13635 {
13636 unsigned char c;
13637
13638- asm volatile(_ASM_SUB "%2,%0; sete %1"
13639+ asm volatile(_ASM_SUB "%2,%0\n"
13640+
13641+#ifdef CONFIG_PAX_REFCOUNT
13642+ "jno 0f\n"
13643+ _ASM_ADD "%2,%0\n"
13644+ "int $4\n0:\n"
13645+ _ASM_EXTABLE(0b, 0b)
13646+#endif
13647+
13648+ "sete %1\n"
13649 : "+m" (l->a.counter), "=qm" (c)
13650 : "ir" (i) : "memory");
13651 return c;
13652@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13653 {
13654 unsigned char c;
13655
13656- asm volatile(_ASM_DEC "%0; sete %1"
13657+ asm volatile(_ASM_DEC "%0\n"
13658+
13659+#ifdef CONFIG_PAX_REFCOUNT
13660+ "jno 0f\n"
13661+ _ASM_INC "%0\n"
13662+ "int $4\n0:\n"
13663+ _ASM_EXTABLE(0b, 0b)
13664+#endif
13665+
13666+ "sete %1\n"
13667 : "+m" (l->a.counter), "=qm" (c)
13668 : : "memory");
13669 return c != 0;
13670@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13671 {
13672 unsigned char c;
13673
13674- asm volatile(_ASM_INC "%0; sete %1"
13675+ asm volatile(_ASM_INC "%0\n"
13676+
13677+#ifdef CONFIG_PAX_REFCOUNT
13678+ "jno 0f\n"
13679+ _ASM_DEC "%0\n"
13680+ "int $4\n0:\n"
13681+ _ASM_EXTABLE(0b, 0b)
13682+#endif
13683+
13684+ "sete %1\n"
13685 : "+m" (l->a.counter), "=qm" (c)
13686 : : "memory");
13687 return c != 0;
13688@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13689 {
13690 unsigned char c;
13691
13692- asm volatile(_ASM_ADD "%2,%0; sets %1"
13693+ asm volatile(_ASM_ADD "%2,%0\n"
13694+
13695+#ifdef CONFIG_PAX_REFCOUNT
13696+ "jno 0f\n"
13697+ _ASM_SUB "%2,%0\n"
13698+ "int $4\n0:\n"
13699+ _ASM_EXTABLE(0b, 0b)
13700+#endif
13701+
13702+ "sets %1\n"
13703 : "+m" (l->a.counter), "=qm" (c)
13704 : "ir" (i) : "memory");
13705 return c;
13706@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13707 static inline long local_add_return(long i, local_t *l)
13708 {
13709 long __i = i;
13710+ asm volatile(_ASM_XADD "%0, %1\n"
13711+
13712+#ifdef CONFIG_PAX_REFCOUNT
13713+ "jno 0f\n"
13714+ _ASM_MOV "%0,%1\n"
13715+ "int $4\n0:\n"
13716+ _ASM_EXTABLE(0b, 0b)
13717+#endif
13718+
13719+ : "+r" (i), "+m" (l->a.counter)
13720+ : : "memory");
13721+ return i + __i;
13722+}
13723+
13724+/**
13725+ * local_add_return_unchecked - add and return
13726+ * @i: integer value to add
13727+ * @l: pointer to type local_unchecked_t
13728+ *
13729+ * Atomically adds @i to @l and returns @i + @l
13730+ */
13731+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13732+{
13733+ long __i = i;
13734 asm volatile(_ASM_XADD "%0, %1;"
13735 : "+r" (i), "+m" (l->a.counter)
13736 : : "memory");
13737@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13738
13739 #define local_cmpxchg(l, o, n) \
13740 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13741+#define local_cmpxchg_unchecked(l, o, n) \
13742+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13743 /* Always has a lock prefix */
13744 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13745
13746diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13747new file mode 100644
13748index 0000000..2bfd3ba
13749--- /dev/null
13750+++ b/arch/x86/include/asm/mman.h
13751@@ -0,0 +1,15 @@
13752+#ifndef _X86_MMAN_H
13753+#define _X86_MMAN_H
13754+
13755+#include <uapi/asm/mman.h>
13756+
13757+#ifdef __KERNEL__
13758+#ifndef __ASSEMBLY__
13759+#ifdef CONFIG_X86_32
13760+#define arch_mmap_check i386_mmap_check
13761+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13762+#endif
13763+#endif
13764+#endif
13765+
13766+#endif /* X86_MMAN_H */
13767diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13768index 5f55e69..e20bfb1 100644
13769--- a/arch/x86/include/asm/mmu.h
13770+++ b/arch/x86/include/asm/mmu.h
13771@@ -9,7 +9,7 @@
13772 * we put the segment information here.
13773 */
13774 typedef struct {
13775- void *ldt;
13776+ struct desc_struct *ldt;
13777 int size;
13778
13779 #ifdef CONFIG_X86_64
13780@@ -18,7 +18,19 @@ typedef struct {
13781 #endif
13782
13783 struct mutex lock;
13784- void *vdso;
13785+ unsigned long vdso;
13786+
13787+#ifdef CONFIG_X86_32
13788+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13789+ unsigned long user_cs_base;
13790+ unsigned long user_cs_limit;
13791+
13792+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13793+ cpumask_t cpu_user_cs_mask;
13794+#endif
13795+
13796+#endif
13797+#endif
13798 } mm_context_t;
13799
13800 #ifdef CONFIG_SMP
13801diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13802index cdbf367..adb37ac 100644
13803--- a/arch/x86/include/asm/mmu_context.h
13804+++ b/arch/x86/include/asm/mmu_context.h
13805@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13806
13807 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13808 {
13809+
13810+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13811+ unsigned int i;
13812+ pgd_t *pgd;
13813+
13814+ pax_open_kernel();
13815+ pgd = get_cpu_pgd(smp_processor_id());
13816+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13817+ set_pgd_batched(pgd+i, native_make_pgd(0));
13818+ pax_close_kernel();
13819+#endif
13820+
13821 #ifdef CONFIG_SMP
13822 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13823 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13824@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13825 struct task_struct *tsk)
13826 {
13827 unsigned cpu = smp_processor_id();
13828+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13829+ int tlbstate = TLBSTATE_OK;
13830+#endif
13831
13832 if (likely(prev != next)) {
13833 #ifdef CONFIG_SMP
13834+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13835+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13836+#endif
13837 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13838 this_cpu_write(cpu_tlbstate.active_mm, next);
13839 #endif
13840 cpumask_set_cpu(cpu, mm_cpumask(next));
13841
13842 /* Re-load page tables */
13843+#ifdef CONFIG_PAX_PER_CPU_PGD
13844+ pax_open_kernel();
13845+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13846+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13847+ pax_close_kernel();
13848+ load_cr3(get_cpu_pgd(cpu));
13849+#else
13850 load_cr3(next->pgd);
13851+#endif
13852
13853 /* stop flush ipis for the previous mm */
13854 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13855@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13856 */
13857 if (unlikely(prev->context.ldt != next->context.ldt))
13858 load_LDT_nolock(&next->context);
13859- }
13860+
13861+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13862+ if (!(__supported_pte_mask & _PAGE_NX)) {
13863+ smp_mb__before_clear_bit();
13864+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13865+ smp_mb__after_clear_bit();
13866+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13867+ }
13868+#endif
13869+
13870+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13871+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13872+ prev->context.user_cs_limit != next->context.user_cs_limit))
13873+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13874 #ifdef CONFIG_SMP
13875+ else if (unlikely(tlbstate != TLBSTATE_OK))
13876+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13877+#endif
13878+#endif
13879+
13880+ }
13881 else {
13882+
13883+#ifdef CONFIG_PAX_PER_CPU_PGD
13884+ pax_open_kernel();
13885+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13886+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13887+ pax_close_kernel();
13888+ load_cr3(get_cpu_pgd(cpu));
13889+#endif
13890+
13891+#ifdef CONFIG_SMP
13892 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13893 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13894
13895@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13896 * tlb flush IPI delivery. We must reload CR3
13897 * to make sure to use no freed page tables.
13898 */
13899+
13900+#ifndef CONFIG_PAX_PER_CPU_PGD
13901 load_cr3(next->pgd);
13902+#endif
13903+
13904 load_LDT_nolock(&next->context);
13905+
13906+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13907+ if (!(__supported_pte_mask & _PAGE_NX))
13908+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13909+#endif
13910+
13911+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13912+#ifdef CONFIG_PAX_PAGEEXEC
13913+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13914+#endif
13915+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13916+#endif
13917+
13918 }
13919+#endif
13920 }
13921-#endif
13922 }
13923
13924 #define activate_mm(prev, next) \
13925diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13926index e3b7819..b257c64 100644
13927--- a/arch/x86/include/asm/module.h
13928+++ b/arch/x86/include/asm/module.h
13929@@ -5,6 +5,7 @@
13930
13931 #ifdef CONFIG_X86_64
13932 /* X86_64 does not define MODULE_PROC_FAMILY */
13933+#define MODULE_PROC_FAMILY ""
13934 #elif defined CONFIG_M486
13935 #define MODULE_PROC_FAMILY "486 "
13936 #elif defined CONFIG_M586
13937@@ -57,8 +58,20 @@
13938 #error unknown processor family
13939 #endif
13940
13941-#ifdef CONFIG_X86_32
13942-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13943+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13944+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13945+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13946+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13947+#else
13948+#define MODULE_PAX_KERNEXEC ""
13949 #endif
13950
13951+#ifdef CONFIG_PAX_MEMORY_UDEREF
13952+#define MODULE_PAX_UDEREF "UDEREF "
13953+#else
13954+#define MODULE_PAX_UDEREF ""
13955+#endif
13956+
13957+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13958+
13959 #endif /* _ASM_X86_MODULE_H */
13960diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
13961index c0fa356..07a498a 100644
13962--- a/arch/x86/include/asm/nmi.h
13963+++ b/arch/x86/include/asm/nmi.h
13964@@ -42,11 +42,11 @@ struct nmiaction {
13965 nmi_handler_t handler;
13966 unsigned long flags;
13967 const char *name;
13968-};
13969+} __do_const;
13970
13971 #define register_nmi_handler(t, fn, fg, n, init...) \
13972 ({ \
13973- static struct nmiaction init fn##_na = { \
13974+ static const struct nmiaction init fn##_na = { \
13975 .handler = (fn), \
13976 .name = (n), \
13977 .flags = (fg), \
13978@@ -54,7 +54,7 @@ struct nmiaction {
13979 __register_nmi_handler((t), &fn##_na); \
13980 })
13981
13982-int __register_nmi_handler(unsigned int, struct nmiaction *);
13983+int __register_nmi_handler(unsigned int, const struct nmiaction *);
13984
13985 void unregister_nmi_handler(unsigned int, const char *);
13986
13987diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13988index 320f7bb..e89f8f8 100644
13989--- a/arch/x86/include/asm/page_64_types.h
13990+++ b/arch/x86/include/asm/page_64_types.h
13991@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13992
13993 /* duplicated to the one in bootmem.h */
13994 extern unsigned long max_pfn;
13995-extern unsigned long phys_base;
13996+extern const unsigned long phys_base;
13997
13998 extern unsigned long __phys_addr(unsigned long);
13999 #define __phys_reloc_hide(x) (x)
14000diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14001index 5edd174..c395822 100644
14002--- a/arch/x86/include/asm/paravirt.h
14003+++ b/arch/x86/include/asm/paravirt.h
14004@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
14005 return (pmd_t) { ret };
14006 }
14007
14008-static inline pmdval_t pmd_val(pmd_t pmd)
14009+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14010 {
14011 pmdval_t ret;
14012
14013@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14014 val);
14015 }
14016
14017+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14018+{
14019+ pgdval_t val = native_pgd_val(pgd);
14020+
14021+ if (sizeof(pgdval_t) > sizeof(long))
14022+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14023+ val, (u64)val >> 32);
14024+ else
14025+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14026+ val);
14027+}
14028+
14029 static inline void pgd_clear(pgd_t *pgdp)
14030 {
14031 set_pgd(pgdp, __pgd(0));
14032@@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14033 pv_mmu_ops.set_fixmap(idx, phys, flags);
14034 }
14035
14036+#ifdef CONFIG_PAX_KERNEXEC
14037+static inline unsigned long pax_open_kernel(void)
14038+{
14039+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14040+}
14041+
14042+static inline unsigned long pax_close_kernel(void)
14043+{
14044+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14045+}
14046+#else
14047+static inline unsigned long pax_open_kernel(void) { return 0; }
14048+static inline unsigned long pax_close_kernel(void) { return 0; }
14049+#endif
14050+
14051 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14052
14053 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14054@@ -927,7 +954,7 @@ extern void default_banner(void);
14055
14056 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14057 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14058-#define PARA_INDIRECT(addr) *%cs:addr
14059+#define PARA_INDIRECT(addr) *%ss:addr
14060 #endif
14061
14062 #define INTERRUPT_RETURN \
14063@@ -1002,6 +1029,21 @@ extern void default_banner(void);
14064 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14065 CLBR_NONE, \
14066 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14067+
14068+#define GET_CR0_INTO_RDI \
14069+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14070+ mov %rax,%rdi
14071+
14072+#define SET_RDI_INTO_CR0 \
14073+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14074+
14075+#define GET_CR3_INTO_RDI \
14076+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14077+ mov %rax,%rdi
14078+
14079+#define SET_RDI_INTO_CR3 \
14080+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14081+
14082 #endif /* CONFIG_X86_32 */
14083
14084 #endif /* __ASSEMBLY__ */
14085diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14086index 142236e..5446ffbc 100644
14087--- a/arch/x86/include/asm/paravirt_types.h
14088+++ b/arch/x86/include/asm/paravirt_types.h
14089@@ -84,7 +84,7 @@ struct pv_init_ops {
14090 */
14091 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14092 unsigned long addr, unsigned len);
14093-};
14094+} __no_const;
14095
14096
14097 struct pv_lazy_ops {
14098@@ -97,7 +97,7 @@ struct pv_time_ops {
14099 unsigned long long (*sched_clock)(void);
14100 unsigned long long (*steal_clock)(int cpu);
14101 unsigned long (*get_tsc_khz)(void);
14102-};
14103+} __no_const;
14104
14105 struct pv_cpu_ops {
14106 /* hooks for various privileged instructions */
14107@@ -191,7 +191,7 @@ struct pv_cpu_ops {
14108
14109 void (*start_context_switch)(struct task_struct *prev);
14110 void (*end_context_switch)(struct task_struct *next);
14111-};
14112+} __no_const;
14113
14114 struct pv_irq_ops {
14115 /*
14116@@ -222,7 +222,7 @@ struct pv_apic_ops {
14117 unsigned long start_eip,
14118 unsigned long start_esp);
14119 #endif
14120-};
14121+} __no_const;
14122
14123 struct pv_mmu_ops {
14124 unsigned long (*read_cr2)(void);
14125@@ -312,6 +312,7 @@ struct pv_mmu_ops {
14126 struct paravirt_callee_save make_pud;
14127
14128 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14129+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14130 #endif /* PAGETABLE_LEVELS == 4 */
14131 #endif /* PAGETABLE_LEVELS >= 3 */
14132
14133@@ -323,6 +324,12 @@ struct pv_mmu_ops {
14134 an mfn. We can tell which is which from the index. */
14135 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14136 phys_addr_t phys, pgprot_t flags);
14137+
14138+#ifdef CONFIG_PAX_KERNEXEC
14139+ unsigned long (*pax_open_kernel)(void);
14140+ unsigned long (*pax_close_kernel)(void);
14141+#endif
14142+
14143 };
14144
14145 struct arch_spinlock;
14146@@ -333,7 +340,7 @@ struct pv_lock_ops {
14147 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14148 int (*spin_trylock)(struct arch_spinlock *lock);
14149 void (*spin_unlock)(struct arch_spinlock *lock);
14150-};
14151+} __no_const;
14152
14153 /* This contains all the paravirt structures: we get a convenient
14154 * number for each function using the offset which we use to indicate
14155diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14156index b4389a4..7024269 100644
14157--- a/arch/x86/include/asm/pgalloc.h
14158+++ b/arch/x86/include/asm/pgalloc.h
14159@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14160 pmd_t *pmd, pte_t *pte)
14161 {
14162 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14163+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14164+}
14165+
14166+static inline void pmd_populate_user(struct mm_struct *mm,
14167+ pmd_t *pmd, pte_t *pte)
14168+{
14169+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14170 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14171 }
14172
14173@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14174
14175 #ifdef CONFIG_X86_PAE
14176 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14177+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14178+{
14179+ pud_populate(mm, pudp, pmd);
14180+}
14181 #else /* !CONFIG_X86_PAE */
14182 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14183 {
14184 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14185 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14186 }
14187+
14188+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14189+{
14190+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14191+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14192+}
14193 #endif /* CONFIG_X86_PAE */
14194
14195 #if PAGETABLE_LEVELS > 3
14196@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14197 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14198 }
14199
14200+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14201+{
14202+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14203+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14204+}
14205+
14206 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14207 {
14208 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14209diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14210index f2b489c..4f7e2e5 100644
14211--- a/arch/x86/include/asm/pgtable-2level.h
14212+++ b/arch/x86/include/asm/pgtable-2level.h
14213@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14214
14215 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14216 {
14217+ pax_open_kernel();
14218 *pmdp = pmd;
14219+ pax_close_kernel();
14220 }
14221
14222 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14223diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14224index 4cc9f2b..5fd9226 100644
14225--- a/arch/x86/include/asm/pgtable-3level.h
14226+++ b/arch/x86/include/asm/pgtable-3level.h
14227@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14228
14229 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14230 {
14231+ pax_open_kernel();
14232 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14233+ pax_close_kernel();
14234 }
14235
14236 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14237 {
14238+ pax_open_kernel();
14239 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14240+ pax_close_kernel();
14241 }
14242
14243 /*
14244diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14245index 1c1a955..50f828c 100644
14246--- a/arch/x86/include/asm/pgtable.h
14247+++ b/arch/x86/include/asm/pgtable.h
14248@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14249
14250 #ifndef __PAGETABLE_PUD_FOLDED
14251 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14252+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14253 #define pgd_clear(pgd) native_pgd_clear(pgd)
14254 #endif
14255
14256@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14257
14258 #define arch_end_context_switch(prev) do {} while(0)
14259
14260+#define pax_open_kernel() native_pax_open_kernel()
14261+#define pax_close_kernel() native_pax_close_kernel()
14262 #endif /* CONFIG_PARAVIRT */
14263
14264+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14265+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14266+
14267+#ifdef CONFIG_PAX_KERNEXEC
14268+static inline unsigned long native_pax_open_kernel(void)
14269+{
14270+ unsigned long cr0;
14271+
14272+ preempt_disable();
14273+ barrier();
14274+ cr0 = read_cr0() ^ X86_CR0_WP;
14275+ BUG_ON(cr0 & X86_CR0_WP);
14276+ write_cr0(cr0);
14277+ return cr0 ^ X86_CR0_WP;
14278+}
14279+
14280+static inline unsigned long native_pax_close_kernel(void)
14281+{
14282+ unsigned long cr0;
14283+
14284+ cr0 = read_cr0() ^ X86_CR0_WP;
14285+ BUG_ON(!(cr0 & X86_CR0_WP));
14286+ write_cr0(cr0);
14287+ barrier();
14288+ preempt_enable_no_resched();
14289+ return cr0 ^ X86_CR0_WP;
14290+}
14291+#else
14292+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14293+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14294+#endif
14295+
14296 /*
14297 * The following only work if pte_present() is true.
14298 * Undefined behaviour if not..
14299 */
14300+static inline int pte_user(pte_t pte)
14301+{
14302+ return pte_val(pte) & _PAGE_USER;
14303+}
14304+
14305 static inline int pte_dirty(pte_t pte)
14306 {
14307 return pte_flags(pte) & _PAGE_DIRTY;
14308@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14309 return pte_clear_flags(pte, _PAGE_RW);
14310 }
14311
14312+static inline pte_t pte_mkread(pte_t pte)
14313+{
14314+ return __pte(pte_val(pte) | _PAGE_USER);
14315+}
14316+
14317 static inline pte_t pte_mkexec(pte_t pte)
14318 {
14319- return pte_clear_flags(pte, _PAGE_NX);
14320+#ifdef CONFIG_X86_PAE
14321+ if (__supported_pte_mask & _PAGE_NX)
14322+ return pte_clear_flags(pte, _PAGE_NX);
14323+ else
14324+#endif
14325+ return pte_set_flags(pte, _PAGE_USER);
14326+}
14327+
14328+static inline pte_t pte_exprotect(pte_t pte)
14329+{
14330+#ifdef CONFIG_X86_PAE
14331+ if (__supported_pte_mask & _PAGE_NX)
14332+ return pte_set_flags(pte, _PAGE_NX);
14333+ else
14334+#endif
14335+ return pte_clear_flags(pte, _PAGE_USER);
14336 }
14337
14338 static inline pte_t pte_mkdirty(pte_t pte)
14339@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14340 #endif
14341
14342 #ifndef __ASSEMBLY__
14343+
14344+#ifdef CONFIG_PAX_PER_CPU_PGD
14345+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14346+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14347+{
14348+ return cpu_pgd[cpu];
14349+}
14350+#endif
14351+
14352 #include <linux/mm_types.h>
14353
14354 static inline int pte_none(pte_t pte)
14355@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14356
14357 static inline int pgd_bad(pgd_t pgd)
14358 {
14359- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14360+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14361 }
14362
14363 static inline int pgd_none(pgd_t pgd)
14364@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14365 * pgd_offset() returns a (pgd_t *)
14366 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14367 */
14368-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14369+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14370+
14371+#ifdef CONFIG_PAX_PER_CPU_PGD
14372+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14373+#endif
14374+
14375 /*
14376 * a shortcut which implies the use of the kernel's pgd, instead
14377 * of a process's
14378@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14379 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14380 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14381
14382+#ifdef CONFIG_X86_32
14383+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14384+#else
14385+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14386+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14387+
14388+#ifdef CONFIG_PAX_MEMORY_UDEREF
14389+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14390+#else
14391+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14392+#endif
14393+
14394+#endif
14395+
14396 #ifndef __ASSEMBLY__
14397
14398 extern int direct_gbpages;
14399@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14400 * dst and src can be on the same page, but the range must not overlap,
14401 * and must not cross a page boundary.
14402 */
14403-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14404+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14405 {
14406- memcpy(dst, src, count * sizeof(pgd_t));
14407+ pax_open_kernel();
14408+ while (count--)
14409+ *dst++ = *src++;
14410+ pax_close_kernel();
14411 }
14412
14413+#ifdef CONFIG_PAX_PER_CPU_PGD
14414+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14415+#endif
14416+
14417+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14418+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14419+#else
14420+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14421+#endif
14422
14423 #include <asm-generic/pgtable.h>
14424 #endif /* __ASSEMBLY__ */
14425diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14426index 8faa215..a8a17ea 100644
14427--- a/arch/x86/include/asm/pgtable_32.h
14428+++ b/arch/x86/include/asm/pgtable_32.h
14429@@ -25,9 +25,6 @@
14430 struct mm_struct;
14431 struct vm_area_struct;
14432
14433-extern pgd_t swapper_pg_dir[1024];
14434-extern pgd_t initial_page_table[1024];
14435-
14436 static inline void pgtable_cache_init(void) { }
14437 static inline void check_pgt_cache(void) { }
14438 void paging_init(void);
14439@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14440 # include <asm/pgtable-2level.h>
14441 #endif
14442
14443+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14444+extern pgd_t initial_page_table[PTRS_PER_PGD];
14445+#ifdef CONFIG_X86_PAE
14446+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14447+#endif
14448+
14449 #if defined(CONFIG_HIGHPTE)
14450 #define pte_offset_map(dir, address) \
14451 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14452@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14453 /* Clear a kernel PTE and flush it from the TLB */
14454 #define kpte_clear_flush(ptep, vaddr) \
14455 do { \
14456+ pax_open_kernel(); \
14457 pte_clear(&init_mm, (vaddr), (ptep)); \
14458+ pax_close_kernel(); \
14459 __flush_tlb_one((vaddr)); \
14460 } while (0)
14461
14462@@ -75,6 +80,9 @@ do { \
14463
14464 #endif /* !__ASSEMBLY__ */
14465
14466+#define HAVE_ARCH_UNMAPPED_AREA
14467+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14468+
14469 /*
14470 * kern_addr_valid() is (1) for FLATMEM and (0) for
14471 * SPARSEMEM and DISCONTIGMEM
14472diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14473index ed5903b..c7fe163 100644
14474--- a/arch/x86/include/asm/pgtable_32_types.h
14475+++ b/arch/x86/include/asm/pgtable_32_types.h
14476@@ -8,7 +8,7 @@
14477 */
14478 #ifdef CONFIG_X86_PAE
14479 # include <asm/pgtable-3level_types.h>
14480-# define PMD_SIZE (1UL << PMD_SHIFT)
14481+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14482 # define PMD_MASK (~(PMD_SIZE - 1))
14483 #else
14484 # include <asm/pgtable-2level_types.h>
14485@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14486 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14487 #endif
14488
14489+#ifdef CONFIG_PAX_KERNEXEC
14490+#ifndef __ASSEMBLY__
14491+extern unsigned char MODULES_EXEC_VADDR[];
14492+extern unsigned char MODULES_EXEC_END[];
14493+#endif
14494+#include <asm/boot.h>
14495+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14496+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14497+#else
14498+#define ktla_ktva(addr) (addr)
14499+#define ktva_ktla(addr) (addr)
14500+#endif
14501+
14502 #define MODULES_VADDR VMALLOC_START
14503 #define MODULES_END VMALLOC_END
14504 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14505diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14506index 47356f9..deb94a2 100644
14507--- a/arch/x86/include/asm/pgtable_64.h
14508+++ b/arch/x86/include/asm/pgtable_64.h
14509@@ -16,10 +16,14 @@
14510
14511 extern pud_t level3_kernel_pgt[512];
14512 extern pud_t level3_ident_pgt[512];
14513+extern pud_t level3_vmalloc_start_pgt[512];
14514+extern pud_t level3_vmalloc_end_pgt[512];
14515+extern pud_t level3_vmemmap_pgt[512];
14516+extern pud_t level2_vmemmap_pgt[512];
14517 extern pmd_t level2_kernel_pgt[512];
14518 extern pmd_t level2_fixmap_pgt[512];
14519-extern pmd_t level2_ident_pgt[512];
14520-extern pgd_t init_level4_pgt[];
14521+extern pmd_t level2_ident_pgt[512*2];
14522+extern pgd_t init_level4_pgt[512];
14523
14524 #define swapper_pg_dir init_level4_pgt
14525
14526@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14527
14528 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14529 {
14530+ pax_open_kernel();
14531 *pmdp = pmd;
14532+ pax_close_kernel();
14533 }
14534
14535 static inline void native_pmd_clear(pmd_t *pmd)
14536@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14537
14538 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14539 {
14540+ pax_open_kernel();
14541 *pudp = pud;
14542+ pax_close_kernel();
14543 }
14544
14545 static inline void native_pud_clear(pud_t *pud)
14546@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14547
14548 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14549 {
14550+ pax_open_kernel();
14551+ *pgdp = pgd;
14552+ pax_close_kernel();
14553+}
14554+
14555+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14556+{
14557 *pgdp = pgd;
14558 }
14559
14560diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14561index 766ea16..5b96cb3 100644
14562--- a/arch/x86/include/asm/pgtable_64_types.h
14563+++ b/arch/x86/include/asm/pgtable_64_types.h
14564@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14565 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14566 #define MODULES_END _AC(0xffffffffff000000, UL)
14567 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14568+#define MODULES_EXEC_VADDR MODULES_VADDR
14569+#define MODULES_EXEC_END MODULES_END
14570+
14571+#define ktla_ktva(addr) (addr)
14572+#define ktva_ktla(addr) (addr)
14573
14574 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14575diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14576index 3c32db8..1ddccf5 100644
14577--- a/arch/x86/include/asm/pgtable_types.h
14578+++ b/arch/x86/include/asm/pgtable_types.h
14579@@ -16,13 +16,12 @@
14580 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14581 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14582 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14583-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14584+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14585 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14586 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14587 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14588-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14589-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14590-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14591+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14592+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14593 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14594
14595 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14596@@ -40,7 +39,6 @@
14597 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14598 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14599 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14600-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14601 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14602 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14603 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14604@@ -57,8 +55,10 @@
14605
14606 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14607 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14608-#else
14609+#elif defined(CONFIG_KMEMCHECK)
14610 #define _PAGE_NX (_AT(pteval_t, 0))
14611+#else
14612+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14613 #endif
14614
14615 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14616@@ -116,6 +116,9 @@
14617 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14618 _PAGE_ACCESSED)
14619
14620+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14621+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14622+
14623 #define __PAGE_KERNEL_EXEC \
14624 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14625 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14626@@ -126,7 +129,7 @@
14627 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14628 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14629 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14630-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14631+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14632 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14633 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14634 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14635@@ -188,8 +191,8 @@
14636 * bits are combined, this will alow user to access the high address mapped
14637 * VDSO in the presence of CONFIG_COMPAT_VDSO
14638 */
14639-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14640-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14641+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14642+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14643 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14644 #endif
14645
14646@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14647 {
14648 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14649 }
14650+#endif
14651
14652+#if PAGETABLE_LEVELS == 3
14653+#include <asm-generic/pgtable-nopud.h>
14654+#endif
14655+
14656+#if PAGETABLE_LEVELS == 2
14657+#include <asm-generic/pgtable-nopmd.h>
14658+#endif
14659+
14660+#ifndef __ASSEMBLY__
14661 #if PAGETABLE_LEVELS > 3
14662 typedef struct { pudval_t pud; } pud_t;
14663
14664@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14665 return pud.pud;
14666 }
14667 #else
14668-#include <asm-generic/pgtable-nopud.h>
14669-
14670 static inline pudval_t native_pud_val(pud_t pud)
14671 {
14672 return native_pgd_val(pud.pgd);
14673@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14674 return pmd.pmd;
14675 }
14676 #else
14677-#include <asm-generic/pgtable-nopmd.h>
14678-
14679 static inline pmdval_t native_pmd_val(pmd_t pmd)
14680 {
14681 return native_pgd_val(pmd.pud.pgd);
14682@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14683
14684 extern pteval_t __supported_pte_mask;
14685 extern void set_nx(void);
14686-extern int nx_enabled;
14687
14688 #define pgprot_writecombine pgprot_writecombine
14689 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14690diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14691index 888184b..a07ac89 100644
14692--- a/arch/x86/include/asm/processor.h
14693+++ b/arch/x86/include/asm/processor.h
14694@@ -287,7 +287,7 @@ struct tss_struct {
14695
14696 } ____cacheline_aligned;
14697
14698-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14699+extern struct tss_struct init_tss[NR_CPUS];
14700
14701 /*
14702 * Save the original ist values for checking stack pointers during debugging
14703@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14704 */
14705 #define TASK_SIZE PAGE_OFFSET
14706 #define TASK_SIZE_MAX TASK_SIZE
14707+
14708+#ifdef CONFIG_PAX_SEGMEXEC
14709+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14710+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14711+#else
14712 #define STACK_TOP TASK_SIZE
14713-#define STACK_TOP_MAX STACK_TOP
14714+#endif
14715+
14716+#define STACK_TOP_MAX TASK_SIZE
14717
14718 #define INIT_THREAD { \
14719- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14720+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14721 .vm86_info = NULL, \
14722 .sysenter_cs = __KERNEL_CS, \
14723 .io_bitmap_ptr = NULL, \
14724@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14725 */
14726 #define INIT_TSS { \
14727 .x86_tss = { \
14728- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14729+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14730 .ss0 = __KERNEL_DS, \
14731 .ss1 = __KERNEL_CS, \
14732 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14733@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14734 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14735
14736 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14737-#define KSTK_TOP(info) \
14738-({ \
14739- unsigned long *__ptr = (unsigned long *)(info); \
14740- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14741-})
14742+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14743
14744 /*
14745 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14746@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14747 #define task_pt_regs(task) \
14748 ({ \
14749 struct pt_regs *__regs__; \
14750- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14751+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14752 __regs__ - 1; \
14753 })
14754
14755@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14756 /*
14757 * User space process size. 47bits minus one guard page.
14758 */
14759-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14760+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14761
14762 /* This decides where the kernel will search for a free chunk of vm
14763 * space during mmap's.
14764 */
14765 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14766- 0xc0000000 : 0xFFFFe000)
14767+ 0xc0000000 : 0xFFFFf000)
14768
14769 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14770 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14771@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14772 #define STACK_TOP_MAX TASK_SIZE_MAX
14773
14774 #define INIT_THREAD { \
14775- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14776+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14777 }
14778
14779 #define INIT_TSS { \
14780- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14781+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14782 }
14783
14784 /*
14785@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14786 */
14787 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14788
14789+#ifdef CONFIG_PAX_SEGMEXEC
14790+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14791+#endif
14792+
14793 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14794
14795 /* Get/set a process' ability to use the timestamp counter instruction */
14796@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14797 #define cpu_has_amd_erratum(x) (false)
14798 #endif /* CONFIG_CPU_SUP_AMD */
14799
14800-extern unsigned long arch_align_stack(unsigned long sp);
14801+#define arch_align_stack(x) ((x) & ~0xfUL)
14802 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14803
14804 void default_idle(void);
14805 bool set_pm_idle_to_default(void);
14806
14807-void stop_this_cpu(void *dummy);
14808+void stop_this_cpu(void *dummy) __noreturn;
14809
14810 #endif /* _ASM_X86_PROCESSOR_H */
14811diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14812index 942a086..6c26446 100644
14813--- a/arch/x86/include/asm/ptrace.h
14814+++ b/arch/x86/include/asm/ptrace.h
14815@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14816 }
14817
14818 /*
14819- * user_mode_vm(regs) determines whether a register set came from user mode.
14820+ * user_mode(regs) determines whether a register set came from user mode.
14821 * This is true if V8086 mode was enabled OR if the register set was from
14822 * protected mode with RPL-3 CS value. This tricky test checks that with
14823 * one comparison. Many places in the kernel can bypass this full check
14824- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14825+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14826+ * be used.
14827 */
14828-static inline int user_mode(struct pt_regs *regs)
14829+static inline int user_mode_novm(struct pt_regs *regs)
14830 {
14831 #ifdef CONFIG_X86_32
14832 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14833 #else
14834- return !!(regs->cs & 3);
14835+ return !!(regs->cs & SEGMENT_RPL_MASK);
14836 #endif
14837 }
14838
14839-static inline int user_mode_vm(struct pt_regs *regs)
14840+static inline int user_mode(struct pt_regs *regs)
14841 {
14842 #ifdef CONFIG_X86_32
14843 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14844 USER_RPL;
14845 #else
14846- return user_mode(regs);
14847+ return user_mode_novm(regs);
14848 #endif
14849 }
14850
14851@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14852 #ifdef CONFIG_X86_64
14853 static inline bool user_64bit_mode(struct pt_regs *regs)
14854 {
14855+ unsigned long cs = regs->cs & 0xffff;
14856 #ifndef CONFIG_PARAVIRT
14857 /*
14858 * On non-paravirt systems, this is the only long mode CPL 3
14859 * selector. We do not allow long mode selectors in the LDT.
14860 */
14861- return regs->cs == __USER_CS;
14862+ return cs == __USER_CS;
14863 #else
14864 /* Headers are too twisted for this to go in paravirt.h. */
14865- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14866+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14867 #endif
14868 }
14869
14870@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14871 * Traps from the kernel do not save sp and ss.
14872 * Use the helper function to retrieve sp.
14873 */
14874- if (offset == offsetof(struct pt_regs, sp) &&
14875- regs->cs == __KERNEL_CS)
14876- return kernel_stack_pointer(regs);
14877+ if (offset == offsetof(struct pt_regs, sp)) {
14878+ unsigned long cs = regs->cs & 0xffff;
14879+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14880+ return kernel_stack_pointer(regs);
14881+ }
14882 #endif
14883 return *(unsigned long *)((unsigned long)regs + offset);
14884 }
14885diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14886index fe1ec5b..dc5c3fe 100644
14887--- a/arch/x86/include/asm/realmode.h
14888+++ b/arch/x86/include/asm/realmode.h
14889@@ -22,16 +22,14 @@ struct real_mode_header {
14890 #endif
14891 /* APM/BIOS reboot */
14892 u32 machine_real_restart_asm;
14893-#ifdef CONFIG_X86_64
14894 u32 machine_real_restart_seg;
14895-#endif
14896 };
14897
14898 /* This must match data at trampoline_32/64.S */
14899 struct trampoline_header {
14900 #ifdef CONFIG_X86_32
14901 u32 start;
14902- u16 gdt_pad;
14903+ u16 boot_cs;
14904 u16 gdt_limit;
14905 u32 gdt_base;
14906 #else
14907diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14908index a82c4f1..ac45053 100644
14909--- a/arch/x86/include/asm/reboot.h
14910+++ b/arch/x86/include/asm/reboot.h
14911@@ -6,13 +6,13 @@
14912 struct pt_regs;
14913
14914 struct machine_ops {
14915- void (*restart)(char *cmd);
14916- void (*halt)(void);
14917- void (*power_off)(void);
14918+ void (* __noreturn restart)(char *cmd);
14919+ void (* __noreturn halt)(void);
14920+ void (* __noreturn power_off)(void);
14921 void (*shutdown)(void);
14922 void (*crash_shutdown)(struct pt_regs *);
14923- void (*emergency_restart)(void);
14924-};
14925+ void (* __noreturn emergency_restart)(void);
14926+} __no_const;
14927
14928 extern struct machine_ops machine_ops;
14929
14930diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14931index 2dbe4a7..ce1db00 100644
14932--- a/arch/x86/include/asm/rwsem.h
14933+++ b/arch/x86/include/asm/rwsem.h
14934@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14935 {
14936 asm volatile("# beginning down_read\n\t"
14937 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14938+
14939+#ifdef CONFIG_PAX_REFCOUNT
14940+ "jno 0f\n"
14941+ LOCK_PREFIX _ASM_DEC "(%1)\n"
14942+ "int $4\n0:\n"
14943+ _ASM_EXTABLE(0b, 0b)
14944+#endif
14945+
14946 /* adds 0x00000001 */
14947 " jns 1f\n"
14948 " call call_rwsem_down_read_failed\n"
14949@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14950 "1:\n\t"
14951 " mov %1,%2\n\t"
14952 " add %3,%2\n\t"
14953+
14954+#ifdef CONFIG_PAX_REFCOUNT
14955+ "jno 0f\n"
14956+ "sub %3,%2\n"
14957+ "int $4\n0:\n"
14958+ _ASM_EXTABLE(0b, 0b)
14959+#endif
14960+
14961 " jle 2f\n\t"
14962 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14963 " jnz 1b\n\t"
14964@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14965 long tmp;
14966 asm volatile("# beginning down_write\n\t"
14967 LOCK_PREFIX " xadd %1,(%2)\n\t"
14968+
14969+#ifdef CONFIG_PAX_REFCOUNT
14970+ "jno 0f\n"
14971+ "mov %1,(%2)\n"
14972+ "int $4\n0:\n"
14973+ _ASM_EXTABLE(0b, 0b)
14974+#endif
14975+
14976 /* adds 0xffff0001, returns the old value */
14977 " test %1,%1\n\t"
14978 /* was the count 0 before? */
14979@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14980 long tmp;
14981 asm volatile("# beginning __up_read\n\t"
14982 LOCK_PREFIX " xadd %1,(%2)\n\t"
14983+
14984+#ifdef CONFIG_PAX_REFCOUNT
14985+ "jno 0f\n"
14986+ "mov %1,(%2)\n"
14987+ "int $4\n0:\n"
14988+ _ASM_EXTABLE(0b, 0b)
14989+#endif
14990+
14991 /* subtracts 1, returns the old value */
14992 " jns 1f\n\t"
14993 " call call_rwsem_wake\n" /* expects old value in %edx */
14994@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14995 long tmp;
14996 asm volatile("# beginning __up_write\n\t"
14997 LOCK_PREFIX " xadd %1,(%2)\n\t"
14998+
14999+#ifdef CONFIG_PAX_REFCOUNT
15000+ "jno 0f\n"
15001+ "mov %1,(%2)\n"
15002+ "int $4\n0:\n"
15003+ _ASM_EXTABLE(0b, 0b)
15004+#endif
15005+
15006 /* subtracts 0xffff0001, returns the old value */
15007 " jns 1f\n\t"
15008 " call call_rwsem_wake\n" /* expects old value in %edx */
15009@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15010 {
15011 asm volatile("# beginning __downgrade_write\n\t"
15012 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15013+
15014+#ifdef CONFIG_PAX_REFCOUNT
15015+ "jno 0f\n"
15016+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15017+ "int $4\n0:\n"
15018+ _ASM_EXTABLE(0b, 0b)
15019+#endif
15020+
15021 /*
15022 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15023 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15024@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15025 */
15026 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15027 {
15028- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15029+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15030+
15031+#ifdef CONFIG_PAX_REFCOUNT
15032+ "jno 0f\n"
15033+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15034+ "int $4\n0:\n"
15035+ _ASM_EXTABLE(0b, 0b)
15036+#endif
15037+
15038 : "+m" (sem->count)
15039 : "er" (delta));
15040 }
15041@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15042 */
15043 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15044 {
15045- return delta + xadd(&sem->count, delta);
15046+ return delta + xadd_check_overflow(&sem->count, delta);
15047 }
15048
15049 #endif /* __KERNEL__ */
15050diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15051index c48a950..c6d7468 100644
15052--- a/arch/x86/include/asm/segment.h
15053+++ b/arch/x86/include/asm/segment.h
15054@@ -64,10 +64,15 @@
15055 * 26 - ESPFIX small SS
15056 * 27 - per-cpu [ offset to per-cpu data area ]
15057 * 28 - stack_canary-20 [ for stack protector ]
15058- * 29 - unused
15059- * 30 - unused
15060+ * 29 - PCI BIOS CS
15061+ * 30 - PCI BIOS DS
15062 * 31 - TSS for double fault handler
15063 */
15064+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15065+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15066+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15067+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15068+
15069 #define GDT_ENTRY_TLS_MIN 6
15070 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15071
15072@@ -79,6 +84,8 @@
15073
15074 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15075
15076+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15077+
15078 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15079
15080 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15081@@ -104,6 +111,12 @@
15082 #define __KERNEL_STACK_CANARY 0
15083 #endif
15084
15085+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15086+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15087+
15088+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15089+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15090+
15091 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15092
15093 /*
15094@@ -141,7 +154,7 @@
15095 */
15096
15097 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15098-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15099+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15100
15101
15102 #else
15103@@ -165,6 +178,8 @@
15104 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15105 #define __USER32_DS __USER_DS
15106
15107+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15108+
15109 #define GDT_ENTRY_TSS 8 /* needs two entries */
15110 #define GDT_ENTRY_LDT 10 /* needs two entries */
15111 #define GDT_ENTRY_TLS_MIN 12
15112@@ -185,6 +200,7 @@
15113 #endif
15114
15115 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15116+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15117 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15118 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15119 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15120@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15121 {
15122 unsigned long __limit;
15123 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15124- return __limit + 1;
15125+ return __limit;
15126 }
15127
15128 #endif /* !__ASSEMBLY__ */
15129diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15130index b073aae..39f9bdd 100644
15131--- a/arch/x86/include/asm/smp.h
15132+++ b/arch/x86/include/asm/smp.h
15133@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15134 /* cpus sharing the last level cache: */
15135 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15136 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15137-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15138+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15139
15140 static inline struct cpumask *cpu_sibling_mask(int cpu)
15141 {
15142@@ -79,7 +79,7 @@ struct smp_ops {
15143
15144 void (*send_call_func_ipi)(const struct cpumask *mask);
15145 void (*send_call_func_single_ipi)(int cpu);
15146-};
15147+} __no_const;
15148
15149 /* Globals due to paravirt */
15150 extern void set_cpu_sibling_map(int cpu);
15151@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15152 extern int safe_smp_processor_id(void);
15153
15154 #elif defined(CONFIG_X86_64_SMP)
15155-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15156-
15157-#define stack_smp_processor_id() \
15158-({ \
15159- struct thread_info *ti; \
15160- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15161- ti->cpu; \
15162-})
15163+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15164+#define stack_smp_processor_id() raw_smp_processor_id()
15165 #define safe_smp_processor_id() smp_processor_id()
15166
15167 #endif
15168diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15169index 33692ea..350a534 100644
15170--- a/arch/x86/include/asm/spinlock.h
15171+++ b/arch/x86/include/asm/spinlock.h
15172@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15173 static inline void arch_read_lock(arch_rwlock_t *rw)
15174 {
15175 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15176+
15177+#ifdef CONFIG_PAX_REFCOUNT
15178+ "jno 0f\n"
15179+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15180+ "int $4\n0:\n"
15181+ _ASM_EXTABLE(0b, 0b)
15182+#endif
15183+
15184 "jns 1f\n"
15185 "call __read_lock_failed\n\t"
15186 "1:\n"
15187@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15188 static inline void arch_write_lock(arch_rwlock_t *rw)
15189 {
15190 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15191+
15192+#ifdef CONFIG_PAX_REFCOUNT
15193+ "jno 0f\n"
15194+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15195+ "int $4\n0:\n"
15196+ _ASM_EXTABLE(0b, 0b)
15197+#endif
15198+
15199 "jz 1f\n"
15200 "call __write_lock_failed\n\t"
15201 "1:\n"
15202@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15203
15204 static inline void arch_read_unlock(arch_rwlock_t *rw)
15205 {
15206- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15207+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15208+
15209+#ifdef CONFIG_PAX_REFCOUNT
15210+ "jno 0f\n"
15211+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15212+ "int $4\n0:\n"
15213+ _ASM_EXTABLE(0b, 0b)
15214+#endif
15215+
15216 :"+m" (rw->lock) : : "memory");
15217 }
15218
15219 static inline void arch_write_unlock(arch_rwlock_t *rw)
15220 {
15221- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15222+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15223+
15224+#ifdef CONFIG_PAX_REFCOUNT
15225+ "jno 0f\n"
15226+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15227+ "int $4\n0:\n"
15228+ _ASM_EXTABLE(0b, 0b)
15229+#endif
15230+
15231 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15232 }
15233
15234diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15235index 6a99859..03cb807 100644
15236--- a/arch/x86/include/asm/stackprotector.h
15237+++ b/arch/x86/include/asm/stackprotector.h
15238@@ -47,7 +47,7 @@
15239 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15240 */
15241 #define GDT_STACK_CANARY_INIT \
15242- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15243+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15244
15245 /*
15246 * Initialize the stackprotector canary value.
15247@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15248
15249 static inline void load_stack_canary_segment(void)
15250 {
15251-#ifdef CONFIG_X86_32
15252+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15253 asm volatile ("mov %0, %%gs" : : "r" (0));
15254 #endif
15255 }
15256diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15257index 70bbe39..4ae2bd4 100644
15258--- a/arch/x86/include/asm/stacktrace.h
15259+++ b/arch/x86/include/asm/stacktrace.h
15260@@ -11,28 +11,20 @@
15261
15262 extern int kstack_depth_to_print;
15263
15264-struct thread_info;
15265+struct task_struct;
15266 struct stacktrace_ops;
15267
15268-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15269- unsigned long *stack,
15270- unsigned long bp,
15271- const struct stacktrace_ops *ops,
15272- void *data,
15273- unsigned long *end,
15274- int *graph);
15275+typedef unsigned long walk_stack_t(struct task_struct *task,
15276+ void *stack_start,
15277+ unsigned long *stack,
15278+ unsigned long bp,
15279+ const struct stacktrace_ops *ops,
15280+ void *data,
15281+ unsigned long *end,
15282+ int *graph);
15283
15284-extern unsigned long
15285-print_context_stack(struct thread_info *tinfo,
15286- unsigned long *stack, unsigned long bp,
15287- const struct stacktrace_ops *ops, void *data,
15288- unsigned long *end, int *graph);
15289-
15290-extern unsigned long
15291-print_context_stack_bp(struct thread_info *tinfo,
15292- unsigned long *stack, unsigned long bp,
15293- const struct stacktrace_ops *ops, void *data,
15294- unsigned long *end, int *graph);
15295+extern walk_stack_t print_context_stack;
15296+extern walk_stack_t print_context_stack_bp;
15297
15298 /* Generic stack tracer with callbacks */
15299
15300@@ -40,7 +32,7 @@ struct stacktrace_ops {
15301 void (*address)(void *data, unsigned long address, int reliable);
15302 /* On negative return stop dumping */
15303 int (*stack)(void *data, char *name);
15304- walk_stack_t walk_stack;
15305+ walk_stack_t *walk_stack;
15306 };
15307
15308 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15309diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15310index 4ec45b3..a4f0a8a 100644
15311--- a/arch/x86/include/asm/switch_to.h
15312+++ b/arch/x86/include/asm/switch_to.h
15313@@ -108,7 +108,7 @@ do { \
15314 "call __switch_to\n\t" \
15315 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15316 __switch_canary \
15317- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15318+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15319 "movq %%rax,%%rdi\n\t" \
15320 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15321 "jnz ret_from_fork\n\t" \
15322@@ -119,7 +119,7 @@ do { \
15323 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15324 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15325 [_tif_fork] "i" (_TIF_FORK), \
15326- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15327+ [thread_info] "m" (current_tinfo), \
15328 [current_task] "m" (current_task) \
15329 __switch_canary_iparam \
15330 : "memory", "cc" __EXTRA_CLOBBER)
15331diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15332index 2d946e6..e453ec4 100644
15333--- a/arch/x86/include/asm/thread_info.h
15334+++ b/arch/x86/include/asm/thread_info.h
15335@@ -10,6 +10,7 @@
15336 #include <linux/compiler.h>
15337 #include <asm/page.h>
15338 #include <asm/types.h>
15339+#include <asm/percpu.h>
15340
15341 /*
15342 * low level task data that entry.S needs immediate access to
15343@@ -24,7 +25,6 @@ struct exec_domain;
15344 #include <linux/atomic.h>
15345
15346 struct thread_info {
15347- struct task_struct *task; /* main task structure */
15348 struct exec_domain *exec_domain; /* execution domain */
15349 __u32 flags; /* low level flags */
15350 __u32 status; /* thread synchronous flags */
15351@@ -34,19 +34,13 @@ struct thread_info {
15352 mm_segment_t addr_limit;
15353 struct restart_block restart_block;
15354 void __user *sysenter_return;
15355-#ifdef CONFIG_X86_32
15356- unsigned long previous_esp; /* ESP of the previous stack in
15357- case of nested (IRQ) stacks
15358- */
15359- __u8 supervisor_stack[0];
15360-#endif
15361+ unsigned long lowest_stack;
15362 unsigned int sig_on_uaccess_error:1;
15363 unsigned int uaccess_err:1; /* uaccess failed */
15364 };
15365
15366-#define INIT_THREAD_INFO(tsk) \
15367+#define INIT_THREAD_INFO \
15368 { \
15369- .task = &tsk, \
15370 .exec_domain = &default_exec_domain, \
15371 .flags = 0, \
15372 .cpu = 0, \
15373@@ -57,7 +51,7 @@ struct thread_info {
15374 }, \
15375 }
15376
15377-#define init_thread_info (init_thread_union.thread_info)
15378+#define init_thread_info (init_thread_union.stack)
15379 #define init_stack (init_thread_union.stack)
15380
15381 #else /* !__ASSEMBLY__ */
15382@@ -98,6 +92,7 @@ struct thread_info {
15383 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15384 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15385 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15386+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15387
15388 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15389 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15390@@ -122,17 +117,18 @@ struct thread_info {
15391 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15392 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15393 #define _TIF_X32 (1 << TIF_X32)
15394+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15395
15396 /* work to do in syscall_trace_enter() */
15397 #define _TIF_WORK_SYSCALL_ENTRY \
15398 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15399 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15400- _TIF_NOHZ)
15401+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15402
15403 /* work to do in syscall_trace_leave() */
15404 #define _TIF_WORK_SYSCALL_EXIT \
15405 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15406- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15407+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15408
15409 /* work to do on interrupt/exception return */
15410 #define _TIF_WORK_MASK \
15411@@ -143,7 +139,7 @@ struct thread_info {
15412 /* work to do on any return to user space */
15413 #define _TIF_ALLWORK_MASK \
15414 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15415- _TIF_NOHZ)
15416+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15417
15418 /* Only used for 64 bit */
15419 #define _TIF_DO_NOTIFY_MASK \
15420@@ -159,45 +155,40 @@ struct thread_info {
15421
15422 #define PREEMPT_ACTIVE 0x10000000
15423
15424-#ifdef CONFIG_X86_32
15425-
15426-#define STACK_WARN (THREAD_SIZE/8)
15427-/*
15428- * macros/functions for gaining access to the thread information structure
15429- *
15430- * preempt_count needs to be 1 initially, until the scheduler is functional.
15431- */
15432-#ifndef __ASSEMBLY__
15433-
15434-
15435-/* how to get the current stack pointer from C */
15436-register unsigned long current_stack_pointer asm("esp") __used;
15437-
15438-/* how to get the thread information struct from C */
15439-static inline struct thread_info *current_thread_info(void)
15440-{
15441- return (struct thread_info *)
15442- (current_stack_pointer & ~(THREAD_SIZE - 1));
15443-}
15444-
15445-#else /* !__ASSEMBLY__ */
15446-
15447+#ifdef __ASSEMBLY__
15448 /* how to get the thread information struct from ASM */
15449 #define GET_THREAD_INFO(reg) \
15450- movl $-THREAD_SIZE, reg; \
15451- andl %esp, reg
15452+ mov PER_CPU_VAR(current_tinfo), reg
15453
15454 /* use this one if reg already contains %esp */
15455-#define GET_THREAD_INFO_WITH_ESP(reg) \
15456- andl $-THREAD_SIZE, reg
15457+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15458+#else
15459+/* how to get the thread information struct from C */
15460+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15461+
15462+static __always_inline struct thread_info *current_thread_info(void)
15463+{
15464+ return this_cpu_read_stable(current_tinfo);
15465+}
15466+#endif
15467+
15468+#ifdef CONFIG_X86_32
15469+
15470+#define STACK_WARN (THREAD_SIZE/8)
15471+/*
15472+ * macros/functions for gaining access to the thread information structure
15473+ *
15474+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15475+ */
15476+#ifndef __ASSEMBLY__
15477+
15478+/* how to get the current stack pointer from C */
15479+register unsigned long current_stack_pointer asm("esp") __used;
15480
15481 #endif
15482
15483 #else /* X86_32 */
15484
15485-#include <asm/percpu.h>
15486-#define KERNEL_STACK_OFFSET (5*8)
15487-
15488 /*
15489 * macros/functions for gaining access to the thread information structure
15490 * preempt_count needs to be 1 initially, until the scheduler is functional.
15491@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15492 #ifndef __ASSEMBLY__
15493 DECLARE_PER_CPU(unsigned long, kernel_stack);
15494
15495-static inline struct thread_info *current_thread_info(void)
15496-{
15497- struct thread_info *ti;
15498- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15499- KERNEL_STACK_OFFSET - THREAD_SIZE);
15500- return ti;
15501-}
15502-
15503-#else /* !__ASSEMBLY__ */
15504-
15505-/* how to get the thread information struct from ASM */
15506-#define GET_THREAD_INFO(reg) \
15507- movq PER_CPU_VAR(kernel_stack),reg ; \
15508- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15509-
15510-/*
15511- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15512- * a certain register (to be used in assembler memory operands).
15513- */
15514-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15515-
15516+/* how to get the current stack pointer from C */
15517+register unsigned long current_stack_pointer asm("rsp") __used;
15518 #endif
15519
15520 #endif /* !X86_32 */
15521@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15522 extern void arch_task_cache_init(void);
15523 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15524 extern void arch_release_task_struct(struct task_struct *tsk);
15525+
15526+#define __HAVE_THREAD_FUNCTIONS
15527+#define task_thread_info(task) (&(task)->tinfo)
15528+#define task_stack_page(task) ((task)->stack)
15529+#define setup_thread_stack(p, org) do {} while (0)
15530+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15531+
15532 #endif
15533 #endif /* _ASM_X86_THREAD_INFO_H */
15534diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15535index 1709801..0a60f2f 100644
15536--- a/arch/x86/include/asm/uaccess.h
15537+++ b/arch/x86/include/asm/uaccess.h
15538@@ -7,6 +7,7 @@
15539 #include <linux/compiler.h>
15540 #include <linux/thread_info.h>
15541 #include <linux/string.h>
15542+#include <linux/sched.h>
15543 #include <asm/asm.h>
15544 #include <asm/page.h>
15545 #include <asm/smap.h>
15546@@ -29,7 +30,12 @@
15547
15548 #define get_ds() (KERNEL_DS)
15549 #define get_fs() (current_thread_info()->addr_limit)
15550+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15551+void __set_fs(mm_segment_t x);
15552+void set_fs(mm_segment_t x);
15553+#else
15554 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15555+#endif
15556
15557 #define segment_eq(a, b) ((a).seg == (b).seg)
15558
15559@@ -77,8 +83,33 @@
15560 * checks that the pointer is in the user space range - after calling
15561 * this function, memory access functions may still return -EFAULT.
15562 */
15563-#define access_ok(type, addr, size) \
15564- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15565+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15566+#define access_ok(type, addr, size) \
15567+({ \
15568+ long __size = size; \
15569+ unsigned long __addr = (unsigned long)addr; \
15570+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15571+ unsigned long __end_ao = __addr + __size - 1; \
15572+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15573+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15574+ while(__addr_ao <= __end_ao) { \
15575+ char __c_ao; \
15576+ __addr_ao += PAGE_SIZE; \
15577+ if (__size > PAGE_SIZE) \
15578+ cond_resched(); \
15579+ if (__get_user(__c_ao, (char __user *)__addr)) \
15580+ break; \
15581+ if (type != VERIFY_WRITE) { \
15582+ __addr = __addr_ao; \
15583+ continue; \
15584+ } \
15585+ if (__put_user(__c_ao, (char __user *)__addr)) \
15586+ break; \
15587+ __addr = __addr_ao; \
15588+ } \
15589+ } \
15590+ __ret_ao; \
15591+})
15592
15593 /*
15594 * The exception table consists of pairs of addresses relative to the
15595@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15596 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15597 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15598
15599-
15600+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15601+#define __copyuser_seg "gs;"
15602+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15603+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15604+#else
15605+#define __copyuser_seg
15606+#define __COPYUSER_SET_ES
15607+#define __COPYUSER_RESTORE_ES
15608+#endif
15609
15610 #ifdef CONFIG_X86_32
15611 #define __put_user_asm_u64(x, addr, err, errret) \
15612 asm volatile(ASM_STAC "\n" \
15613- "1: movl %%eax,0(%2)\n" \
15614- "2: movl %%edx,4(%2)\n" \
15615+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15616+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15617 "3: " ASM_CLAC "\n" \
15618 ".section .fixup,\"ax\"\n" \
15619 "4: movl %3,%0\n" \
15620@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15621
15622 #define __put_user_asm_ex_u64(x, addr) \
15623 asm volatile(ASM_STAC "\n" \
15624- "1: movl %%eax,0(%1)\n" \
15625- "2: movl %%edx,4(%1)\n" \
15626+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15627+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15628 "3: " ASM_CLAC "\n" \
15629 _ASM_EXTABLE_EX(1b, 2b) \
15630 _ASM_EXTABLE_EX(2b, 3b) \
15631@@ -259,7 +298,7 @@ extern void __put_user_8(void);
15632 __typeof__(*(ptr)) __pu_val; \
15633 __chk_user_ptr(ptr); \
15634 might_fault(); \
15635- __pu_val = x; \
15636+ __pu_val = (x); \
15637 switch (sizeof(*(ptr))) { \
15638 case 1: \
15639 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15640@@ -358,7 +397,7 @@ do { \
15641
15642 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15643 asm volatile(ASM_STAC "\n" \
15644- "1: mov"itype" %2,%"rtype"1\n" \
15645+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15646 "2: " ASM_CLAC "\n" \
15647 ".section .fixup,\"ax\"\n" \
15648 "3: mov %3,%0\n" \
15649@@ -366,7 +405,7 @@ do { \
15650 " jmp 2b\n" \
15651 ".previous\n" \
15652 _ASM_EXTABLE(1b, 3b) \
15653- : "=r" (err), ltype(x) \
15654+ : "=r" (err), ltype (x) \
15655 : "m" (__m(addr)), "i" (errret), "0" (err))
15656
15657 #define __get_user_size_ex(x, ptr, size) \
15658@@ -391,7 +430,7 @@ do { \
15659 } while (0)
15660
15661 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15662- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15663+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15664 "2:\n" \
15665 _ASM_EXTABLE_EX(1b, 2b) \
15666 : ltype(x) : "m" (__m(addr)))
15667@@ -408,13 +447,24 @@ do { \
15668 int __gu_err; \
15669 unsigned long __gu_val; \
15670 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15671- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15672+ (x) = (__typeof__(*(ptr)))__gu_val; \
15673 __gu_err; \
15674 })
15675
15676 /* FIXME: this hack is definitely wrong -AK */
15677 struct __large_struct { unsigned long buf[100]; };
15678-#define __m(x) (*(struct __large_struct __user *)(x))
15679+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15680+#define ____m(x) \
15681+({ \
15682+ unsigned long ____x = (unsigned long)(x); \
15683+ if (____x < PAX_USER_SHADOW_BASE) \
15684+ ____x += PAX_USER_SHADOW_BASE; \
15685+ (void __user *)____x; \
15686+})
15687+#else
15688+#define ____m(x) (x)
15689+#endif
15690+#define __m(x) (*(struct __large_struct __user *)____m(x))
15691
15692 /*
15693 * Tell gcc we read from memory instead of writing: this is because
15694@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15695 */
15696 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15697 asm volatile(ASM_STAC "\n" \
15698- "1: mov"itype" %"rtype"1,%2\n" \
15699+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15700 "2: " ASM_CLAC "\n" \
15701 ".section .fixup,\"ax\"\n" \
15702 "3: mov %3,%0\n" \
15703@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15704 ".previous\n" \
15705 _ASM_EXTABLE(1b, 3b) \
15706 : "=r"(err) \
15707- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15708+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15709
15710 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15711- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15712+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15713 "2:\n" \
15714 _ASM_EXTABLE_EX(1b, 2b) \
15715 : : ltype(x), "m" (__m(addr)))
15716@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15717 * On error, the variable @x is set to zero.
15718 */
15719
15720+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15721+#define __get_user(x, ptr) get_user((x), (ptr))
15722+#else
15723 #define __get_user(x, ptr) \
15724 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15725+#endif
15726
15727 /**
15728 * __put_user: - Write a simple value into user space, with less checking.
15729@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15730 * Returns zero on success, or -EFAULT on error.
15731 */
15732
15733+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15734+#define __put_user(x, ptr) put_user((x), (ptr))
15735+#else
15736 #define __put_user(x, ptr) \
15737 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15738+#endif
15739
15740 #define __get_user_unaligned __get_user
15741 #define __put_user_unaligned __put_user
15742@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15743 #define get_user_ex(x, ptr) do { \
15744 unsigned long __gue_val; \
15745 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15746- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15747+ (x) = (__typeof__(*(ptr)))__gue_val; \
15748 } while (0)
15749
15750 #define put_user_try uaccess_try
15751@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15752 extern __must_check long strlen_user(const char __user *str);
15753 extern __must_check long strnlen_user(const char __user *str, long n);
15754
15755-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15756-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15757+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15758+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15759
15760 /*
15761 * movsl can be slow when source and dest are not both 8-byte aligned
15762diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15763index 7f760a9..04b1c65 100644
15764--- a/arch/x86/include/asm/uaccess_32.h
15765+++ b/arch/x86/include/asm/uaccess_32.h
15766@@ -11,15 +11,15 @@
15767 #include <asm/page.h>
15768
15769 unsigned long __must_check __copy_to_user_ll
15770- (void __user *to, const void *from, unsigned long n);
15771+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15772 unsigned long __must_check __copy_from_user_ll
15773- (void *to, const void __user *from, unsigned long n);
15774+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15775 unsigned long __must_check __copy_from_user_ll_nozero
15776- (void *to, const void __user *from, unsigned long n);
15777+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15778 unsigned long __must_check __copy_from_user_ll_nocache
15779- (void *to, const void __user *from, unsigned long n);
15780+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15781 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15782- (void *to, const void __user *from, unsigned long n);
15783+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15784
15785 /**
15786 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15787@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15788 static __always_inline unsigned long __must_check
15789 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15790 {
15791+ if ((long)n < 0)
15792+ return n;
15793+
15794+ check_object_size(from, n, true);
15795+
15796 if (__builtin_constant_p(n)) {
15797 unsigned long ret;
15798
15799@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15800 __copy_to_user(void __user *to, const void *from, unsigned long n)
15801 {
15802 might_fault();
15803+
15804 return __copy_to_user_inatomic(to, from, n);
15805 }
15806
15807 static __always_inline unsigned long
15808 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15809 {
15810+ if ((long)n < 0)
15811+ return n;
15812+
15813 /* Avoid zeroing the tail if the copy fails..
15814 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15815 * but as the zeroing behaviour is only significant when n is not
15816@@ -137,6 +146,12 @@ static __always_inline unsigned long
15817 __copy_from_user(void *to, const void __user *from, unsigned long n)
15818 {
15819 might_fault();
15820+
15821+ if ((long)n < 0)
15822+ return n;
15823+
15824+ check_object_size(to, n, false);
15825+
15826 if (__builtin_constant_p(n)) {
15827 unsigned long ret;
15828
15829@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15830 const void __user *from, unsigned long n)
15831 {
15832 might_fault();
15833+
15834+ if ((long)n < 0)
15835+ return n;
15836+
15837 if (__builtin_constant_p(n)) {
15838 unsigned long ret;
15839
15840@@ -181,15 +200,19 @@ static __always_inline unsigned long
15841 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15842 unsigned long n)
15843 {
15844- return __copy_from_user_ll_nocache_nozero(to, from, n);
15845+ if ((long)n < 0)
15846+ return n;
15847+
15848+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15849 }
15850
15851-unsigned long __must_check copy_to_user(void __user *to,
15852- const void *from, unsigned long n);
15853-unsigned long __must_check _copy_from_user(void *to,
15854- const void __user *from,
15855- unsigned long n);
15856-
15857+extern void copy_to_user_overflow(void)
15858+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15859+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15860+#else
15861+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15862+#endif
15863+;
15864
15865 extern void copy_from_user_overflow(void)
15866 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15867@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15868 #endif
15869 ;
15870
15871-static inline unsigned long __must_check copy_from_user(void *to,
15872- const void __user *from,
15873- unsigned long n)
15874+/**
15875+ * copy_to_user: - Copy a block of data into user space.
15876+ * @to: Destination address, in user space.
15877+ * @from: Source address, in kernel space.
15878+ * @n: Number of bytes to copy.
15879+ *
15880+ * Context: User context only. This function may sleep.
15881+ *
15882+ * Copy data from kernel space to user space.
15883+ *
15884+ * Returns number of bytes that could not be copied.
15885+ * On success, this will be zero.
15886+ */
15887+static inline unsigned long __must_check
15888+copy_to_user(void __user *to, const void *from, unsigned long n)
15889 {
15890- int sz = __compiletime_object_size(to);
15891+ size_t sz = __compiletime_object_size(from);
15892
15893- if (likely(sz == -1 || sz >= n))
15894- n = _copy_from_user(to, from, n);
15895- else
15896+ if (unlikely(sz != (size_t)-1 && sz < n))
15897+ copy_to_user_overflow();
15898+ else if (access_ok(VERIFY_WRITE, to, n))
15899+ n = __copy_to_user(to, from, n);
15900+ return n;
15901+}
15902+
15903+/**
15904+ * copy_from_user: - Copy a block of data from user space.
15905+ * @to: Destination address, in kernel space.
15906+ * @from: Source address, in user space.
15907+ * @n: Number of bytes to copy.
15908+ *
15909+ * Context: User context only. This function may sleep.
15910+ *
15911+ * Copy data from user space to kernel space.
15912+ *
15913+ * Returns number of bytes that could not be copied.
15914+ * On success, this will be zero.
15915+ *
15916+ * If some data could not be copied, this function will pad the copied
15917+ * data to the requested size using zero bytes.
15918+ */
15919+static inline unsigned long __must_check
15920+copy_from_user(void *to, const void __user *from, unsigned long n)
15921+{
15922+ size_t sz = __compiletime_object_size(to);
15923+
15924+ check_object_size(to, n, false);
15925+
15926+ if (unlikely(sz != (size_t)-1 && sz < n))
15927 copy_from_user_overflow();
15928-
15929+ else if (access_ok(VERIFY_READ, from, n))
15930+ n = __copy_from_user(to, from, n);
15931+ else if ((long)n > 0)
15932+ memset(to, 0, n);
15933 return n;
15934 }
15935
15936diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15937index 142810c..747941a 100644
15938--- a/arch/x86/include/asm/uaccess_64.h
15939+++ b/arch/x86/include/asm/uaccess_64.h
15940@@ -10,6 +10,9 @@
15941 #include <asm/alternative.h>
15942 #include <asm/cpufeature.h>
15943 #include <asm/page.h>
15944+#include <asm/pgtable.h>
15945+
15946+#define set_fs(x) (current_thread_info()->addr_limit = (x))
15947
15948 /*
15949 * Copy To/From Userspace
15950@@ -17,13 +20,13 @@
15951
15952 /* Handles exceptions in both to and from, but doesn't do access_ok */
15953 __must_check unsigned long
15954-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15955+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15956 __must_check unsigned long
15957-copy_user_generic_string(void *to, const void *from, unsigned len);
15958+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15959 __must_check unsigned long
15960-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15961+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15962
15963-static __always_inline __must_check unsigned long
15964+static __always_inline __must_check __size_overflow(3) unsigned long
15965 copy_user_generic(void *to, const void *from, unsigned len)
15966 {
15967 unsigned ret;
15968@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15969 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15970 "=d" (len)),
15971 "1" (to), "2" (from), "3" (len)
15972- : "memory", "rcx", "r8", "r9", "r10", "r11");
15973+ : "memory", "rcx", "r8", "r9", "r11");
15974 return ret;
15975 }
15976
15977+static __always_inline __must_check unsigned long
15978+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15979+static __always_inline __must_check unsigned long
15980+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15981 __must_check unsigned long
15982-_copy_to_user(void __user *to, const void *from, unsigned len);
15983-__must_check unsigned long
15984-_copy_from_user(void *to, const void __user *from, unsigned len);
15985-__must_check unsigned long
15986-copy_in_user(void __user *to, const void __user *from, unsigned len);
15987+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15988+
15989+extern void copy_to_user_overflow(void)
15990+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15991+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15992+#else
15993+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15994+#endif
15995+;
15996+
15997+extern void copy_from_user_overflow(void)
15998+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15999+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16000+#else
16001+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16002+#endif
16003+;
16004
16005 static inline unsigned long __must_check copy_from_user(void *to,
16006 const void __user *from,
16007 unsigned long n)
16008 {
16009- int sz = __compiletime_object_size(to);
16010-
16011 might_fault();
16012- if (likely(sz == -1 || sz >= n))
16013- n = _copy_from_user(to, from, n);
16014-#ifdef CONFIG_DEBUG_VM
16015- else
16016- WARN(1, "Buffer overflow detected!\n");
16017-#endif
16018+
16019+ check_object_size(to, n, false);
16020+
16021+ if (access_ok(VERIFY_READ, from, n))
16022+ n = __copy_from_user(to, from, n);
16023+ else if (n < INT_MAX)
16024+ memset(to, 0, n);
16025 return n;
16026 }
16027
16028 static __always_inline __must_check
16029-int copy_to_user(void __user *dst, const void *src, unsigned size)
16030+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16031 {
16032 might_fault();
16033
16034- return _copy_to_user(dst, src, size);
16035+ if (access_ok(VERIFY_WRITE, dst, size))
16036+ size = __copy_to_user(dst, src, size);
16037+ return size;
16038 }
16039
16040 static __always_inline __must_check
16041-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16042+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16043 {
16044- int ret = 0;
16045+ size_t sz = __compiletime_object_size(dst);
16046+ unsigned ret = 0;
16047
16048 might_fault();
16049+
16050+ if (size > INT_MAX)
16051+ return size;
16052+
16053+ check_object_size(dst, size, false);
16054+
16055+#ifdef CONFIG_PAX_MEMORY_UDEREF
16056+ if (!__access_ok(VERIFY_READ, src, size))
16057+ return size;
16058+#endif
16059+
16060+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16061+ copy_from_user_overflow();
16062+ return size;
16063+ }
16064+
16065 if (!__builtin_constant_p(size))
16066- return copy_user_generic(dst, (__force void *)src, size);
16067+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16068 switch (size) {
16069- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16070+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16071 ret, "b", "b", "=q", 1);
16072 return ret;
16073- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16074+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16075 ret, "w", "w", "=r", 2);
16076 return ret;
16077- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16078+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16079 ret, "l", "k", "=r", 4);
16080 return ret;
16081- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16082+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16083 ret, "q", "", "=r", 8);
16084 return ret;
16085 case 10:
16086- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16087+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16088 ret, "q", "", "=r", 10);
16089 if (unlikely(ret))
16090 return ret;
16091 __get_user_asm(*(u16 *)(8 + (char *)dst),
16092- (u16 __user *)(8 + (char __user *)src),
16093+ (const u16 __user *)(8 + (const char __user *)src),
16094 ret, "w", "w", "=r", 2);
16095 return ret;
16096 case 16:
16097- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16098+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16099 ret, "q", "", "=r", 16);
16100 if (unlikely(ret))
16101 return ret;
16102 __get_user_asm(*(u64 *)(8 + (char *)dst),
16103- (u64 __user *)(8 + (char __user *)src),
16104+ (const u64 __user *)(8 + (const char __user *)src),
16105 ret, "q", "", "=r", 8);
16106 return ret;
16107 default:
16108- return copy_user_generic(dst, (__force void *)src, size);
16109+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16110 }
16111 }
16112
16113 static __always_inline __must_check
16114-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16115+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16116 {
16117- int ret = 0;
16118+ size_t sz = __compiletime_object_size(src);
16119+ unsigned ret = 0;
16120
16121 might_fault();
16122+
16123+ if (size > INT_MAX)
16124+ return size;
16125+
16126+ check_object_size(src, size, true);
16127+
16128+#ifdef CONFIG_PAX_MEMORY_UDEREF
16129+ if (!__access_ok(VERIFY_WRITE, dst, size))
16130+ return size;
16131+#endif
16132+
16133+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16134+ copy_to_user_overflow();
16135+ return size;
16136+ }
16137+
16138 if (!__builtin_constant_p(size))
16139- return copy_user_generic((__force void *)dst, src, size);
16140+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16141 switch (size) {
16142- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16143+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16144 ret, "b", "b", "iq", 1);
16145 return ret;
16146- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16147+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16148 ret, "w", "w", "ir", 2);
16149 return ret;
16150- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16151+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16152 ret, "l", "k", "ir", 4);
16153 return ret;
16154- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16155+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16156 ret, "q", "", "er", 8);
16157 return ret;
16158 case 10:
16159- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16160+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16161 ret, "q", "", "er", 10);
16162 if (unlikely(ret))
16163 return ret;
16164 asm("":::"memory");
16165- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16166+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16167 ret, "w", "w", "ir", 2);
16168 return ret;
16169 case 16:
16170- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16171+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16172 ret, "q", "", "er", 16);
16173 if (unlikely(ret))
16174 return ret;
16175 asm("":::"memory");
16176- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16177+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16178 ret, "q", "", "er", 8);
16179 return ret;
16180 default:
16181- return copy_user_generic((__force void *)dst, src, size);
16182+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16183 }
16184 }
16185
16186 static __always_inline __must_check
16187-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16188+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16189 {
16190- int ret = 0;
16191+ unsigned ret = 0;
16192
16193 might_fault();
16194+
16195+ if (size > INT_MAX)
16196+ return size;
16197+
16198+#ifdef CONFIG_PAX_MEMORY_UDEREF
16199+ if (!__access_ok(VERIFY_READ, src, size))
16200+ return size;
16201+ if (!__access_ok(VERIFY_WRITE, dst, size))
16202+ return size;
16203+#endif
16204+
16205 if (!__builtin_constant_p(size))
16206- return copy_user_generic((__force void *)dst,
16207- (__force void *)src, size);
16208+ return copy_user_generic((__force_kernel void *)____m(dst),
16209+ (__force_kernel const void *)____m(src), size);
16210 switch (size) {
16211 case 1: {
16212 u8 tmp;
16213- __get_user_asm(tmp, (u8 __user *)src,
16214+ __get_user_asm(tmp, (const u8 __user *)src,
16215 ret, "b", "b", "=q", 1);
16216 if (likely(!ret))
16217 __put_user_asm(tmp, (u8 __user *)dst,
16218@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16219 }
16220 case 2: {
16221 u16 tmp;
16222- __get_user_asm(tmp, (u16 __user *)src,
16223+ __get_user_asm(tmp, (const u16 __user *)src,
16224 ret, "w", "w", "=r", 2);
16225 if (likely(!ret))
16226 __put_user_asm(tmp, (u16 __user *)dst,
16227@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16228
16229 case 4: {
16230 u32 tmp;
16231- __get_user_asm(tmp, (u32 __user *)src,
16232+ __get_user_asm(tmp, (const u32 __user *)src,
16233 ret, "l", "k", "=r", 4);
16234 if (likely(!ret))
16235 __put_user_asm(tmp, (u32 __user *)dst,
16236@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16237 }
16238 case 8: {
16239 u64 tmp;
16240- __get_user_asm(tmp, (u64 __user *)src,
16241+ __get_user_asm(tmp, (const u64 __user *)src,
16242 ret, "q", "", "=r", 8);
16243 if (likely(!ret))
16244 __put_user_asm(tmp, (u64 __user *)dst,
16245@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16246 return ret;
16247 }
16248 default:
16249- return copy_user_generic((__force void *)dst,
16250- (__force void *)src, size);
16251+ return copy_user_generic((__force_kernel void *)____m(dst),
16252+ (__force_kernel const void *)____m(src), size);
16253 }
16254 }
16255
16256 static __must_check __always_inline int
16257-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16258+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16259 {
16260- return copy_user_generic(dst, (__force const void *)src, size);
16261+ if (size > INT_MAX)
16262+ return size;
16263+
16264+#ifdef CONFIG_PAX_MEMORY_UDEREF
16265+ if (!__access_ok(VERIFY_READ, src, size))
16266+ return size;
16267+#endif
16268+
16269+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16270 }
16271
16272-static __must_check __always_inline int
16273-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16274+static __must_check __always_inline unsigned long
16275+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16276 {
16277- return copy_user_generic((__force void *)dst, src, size);
16278+ if (size > INT_MAX)
16279+ return size;
16280+
16281+#ifdef CONFIG_PAX_MEMORY_UDEREF
16282+ if (!__access_ok(VERIFY_WRITE, dst, size))
16283+ return size;
16284+#endif
16285+
16286+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16287 }
16288
16289-extern long __copy_user_nocache(void *dst, const void __user *src,
16290- unsigned size, int zerorest);
16291+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16292+ unsigned long size, int zerorest) __size_overflow(3);
16293
16294-static inline int
16295-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16296+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16297 {
16298 might_sleep();
16299+
16300+ if (size > INT_MAX)
16301+ return size;
16302+
16303+#ifdef CONFIG_PAX_MEMORY_UDEREF
16304+ if (!__access_ok(VERIFY_READ, src, size))
16305+ return size;
16306+#endif
16307+
16308 return __copy_user_nocache(dst, src, size, 1);
16309 }
16310
16311-static inline int
16312-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16313- unsigned size)
16314+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16315+ unsigned long size)
16316 {
16317+ if (size > INT_MAX)
16318+ return size;
16319+
16320+#ifdef CONFIG_PAX_MEMORY_UDEREF
16321+ if (!__access_ok(VERIFY_READ, src, size))
16322+ return size;
16323+#endif
16324+
16325 return __copy_user_nocache(dst, src, size, 0);
16326 }
16327
16328-unsigned long
16329-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16330+extern unsigned long
16331+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16332
16333 #endif /* _ASM_X86_UACCESS_64_H */
16334diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16335index 5b238981..77fdd78 100644
16336--- a/arch/x86/include/asm/word-at-a-time.h
16337+++ b/arch/x86/include/asm/word-at-a-time.h
16338@@ -11,7 +11,7 @@
16339 * and shift, for example.
16340 */
16341 struct word_at_a_time {
16342- const unsigned long one_bits, high_bits;
16343+ unsigned long one_bits, high_bits;
16344 };
16345
16346 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16347diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16348index 5769349..a3d3e2a 100644
16349--- a/arch/x86/include/asm/x86_init.h
16350+++ b/arch/x86/include/asm/x86_init.h
16351@@ -141,7 +141,7 @@ struct x86_init_ops {
16352 struct x86_init_timers timers;
16353 struct x86_init_iommu iommu;
16354 struct x86_init_pci pci;
16355-};
16356+} __no_const;
16357
16358 /**
16359 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16360@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16361 void (*setup_percpu_clockev)(void);
16362 void (*early_percpu_clock_init)(void);
16363 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16364-};
16365+} __no_const;
16366
16367 /**
16368 * struct x86_platform_ops - platform specific runtime functions
16369@@ -178,7 +178,7 @@ struct x86_platform_ops {
16370 void (*save_sched_clock_state)(void);
16371 void (*restore_sched_clock_state)(void);
16372 void (*apic_post_init)(void);
16373-};
16374+} __no_const;
16375
16376 struct pci_dev;
16377
16378@@ -187,14 +187,14 @@ struct x86_msi_ops {
16379 void (*teardown_msi_irq)(unsigned int irq);
16380 void (*teardown_msi_irqs)(struct pci_dev *dev);
16381 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16382-};
16383+} __no_const;
16384
16385 struct x86_io_apic_ops {
16386 void (*init) (void);
16387 unsigned int (*read) (unsigned int apic, unsigned int reg);
16388 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16389 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16390-};
16391+} __no_const;
16392
16393 extern struct x86_init_ops x86_init;
16394 extern struct x86_cpuinit_ops x86_cpuinit;
16395diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16396index 0415cda..b43d877 100644
16397--- a/arch/x86/include/asm/xsave.h
16398+++ b/arch/x86/include/asm/xsave.h
16399@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16400 return -EFAULT;
16401
16402 __asm__ __volatile__(ASM_STAC "\n"
16403- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16404+ "1:"
16405+ __copyuser_seg
16406+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16407 "2: " ASM_CLAC "\n"
16408 ".section .fixup,\"ax\"\n"
16409 "3: movl $-1,%[err]\n"
16410@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16411 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16412 {
16413 int err;
16414- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16415+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16416 u32 lmask = mask;
16417 u32 hmask = mask >> 32;
16418
16419 __asm__ __volatile__(ASM_STAC "\n"
16420- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16421+ "1:"
16422+ __copyuser_seg
16423+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16424 "2: " ASM_CLAC "\n"
16425 ".section .fixup,\"ax\"\n"
16426 "3: movl $-1,%[err]\n"
16427diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16428index bbae024..e1528f9 100644
16429--- a/arch/x86/include/uapi/asm/e820.h
16430+++ b/arch/x86/include/uapi/asm/e820.h
16431@@ -63,7 +63,7 @@ struct e820map {
16432 #define ISA_START_ADDRESS 0xa0000
16433 #define ISA_END_ADDRESS 0x100000
16434
16435-#define BIOS_BEGIN 0x000a0000
16436+#define BIOS_BEGIN 0x000c0000
16437 #define BIOS_END 0x00100000
16438
16439 #define BIOS_ROM_BASE 0xffe00000
16440diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16441index 34e923a..0c6bb6e 100644
16442--- a/arch/x86/kernel/Makefile
16443+++ b/arch/x86/kernel/Makefile
16444@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16445 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16446 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16447 obj-y += probe_roms.o
16448-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16449+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16450 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16451 obj-y += syscall_$(BITS).o
16452 obj-$(CONFIG_X86_64) += vsyscall_64.o
16453diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16454index bacf4b0..4ede72e 100644
16455--- a/arch/x86/kernel/acpi/boot.c
16456+++ b/arch/x86/kernel/acpi/boot.c
16457@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16458 * If your system is blacklisted here, but you find that acpi=force
16459 * works for you, please contact linux-acpi@vger.kernel.org
16460 */
16461-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16462+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16463 /*
16464 * Boxes that need ACPI disabled
16465 */
16466@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16467 };
16468
16469 /* second table for DMI checks that should run after early-quirks */
16470-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16471+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16472 /*
16473 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16474 * which includes some code which overrides all temperature
16475diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16476index d5e0d71..6533e08 100644
16477--- a/arch/x86/kernel/acpi/sleep.c
16478+++ b/arch/x86/kernel/acpi/sleep.c
16479@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16480 #else /* CONFIG_64BIT */
16481 #ifdef CONFIG_SMP
16482 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16483+
16484+ pax_open_kernel();
16485 early_gdt_descr.address =
16486 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16487+ pax_close_kernel();
16488+
16489 initial_gs = per_cpu_offset(smp_processor_id());
16490 #endif
16491 initial_code = (unsigned long)wakeup_long64;
16492diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16493index 13ab720..95d5442 100644
16494--- a/arch/x86/kernel/acpi/wakeup_32.S
16495+++ b/arch/x86/kernel/acpi/wakeup_32.S
16496@@ -30,13 +30,11 @@ wakeup_pmode_return:
16497 # and restore the stack ... but you need gdt for this to work
16498 movl saved_context_esp, %esp
16499
16500- movl %cs:saved_magic, %eax
16501- cmpl $0x12345678, %eax
16502+ cmpl $0x12345678, saved_magic
16503 jne bogus_magic
16504
16505 # jump to place where we left off
16506- movl saved_eip, %eax
16507- jmp *%eax
16508+ jmp *(saved_eip)
16509
16510 bogus_magic:
16511 jmp bogus_magic
16512diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16513index ef5ccca..bd83949 100644
16514--- a/arch/x86/kernel/alternative.c
16515+++ b/arch/x86/kernel/alternative.c
16516@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16517 */
16518 for (a = start; a < end; a++) {
16519 instr = (u8 *)&a->instr_offset + a->instr_offset;
16520+
16521+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16522+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16523+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16524+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16525+#endif
16526+
16527 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16528 BUG_ON(a->replacementlen > a->instrlen);
16529 BUG_ON(a->instrlen > sizeof(insnbuf));
16530@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16531 for (poff = start; poff < end; poff++) {
16532 u8 *ptr = (u8 *)poff + *poff;
16533
16534+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16535+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16536+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16537+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16538+#endif
16539+
16540 if (!*poff || ptr < text || ptr >= text_end)
16541 continue;
16542 /* turn DS segment override prefix into lock prefix */
16543- if (*ptr == 0x3e)
16544+ if (*ktla_ktva(ptr) == 0x3e)
16545 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16546 }
16547 mutex_unlock(&text_mutex);
16548@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16549 for (poff = start; poff < end; poff++) {
16550 u8 *ptr = (u8 *)poff + *poff;
16551
16552+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16553+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16554+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16555+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16556+#endif
16557+
16558 if (!*poff || ptr < text || ptr >= text_end)
16559 continue;
16560 /* turn lock prefix into DS segment override prefix */
16561- if (*ptr == 0xf0)
16562+ if (*ktla_ktva(ptr) == 0xf0)
16563 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16564 }
16565 mutex_unlock(&text_mutex);
16566@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16567
16568 BUG_ON(p->len > MAX_PATCH_LEN);
16569 /* prep the buffer with the original instructions */
16570- memcpy(insnbuf, p->instr, p->len);
16571+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16572 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16573 (unsigned long)p->instr, p->len);
16574
16575@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16576 if (!uniproc_patched || num_possible_cpus() == 1)
16577 free_init_pages("SMP alternatives",
16578 (unsigned long)__smp_locks,
16579- (unsigned long)__smp_locks_end);
16580+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16581 #endif
16582
16583 apply_paravirt(__parainstructions, __parainstructions_end);
16584@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16585 * instructions. And on the local CPU you need to be protected again NMI or MCE
16586 * handlers seeing an inconsistent instruction while you patch.
16587 */
16588-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16589+void *__kprobes text_poke_early(void *addr, const void *opcode,
16590 size_t len)
16591 {
16592 unsigned long flags;
16593 local_irq_save(flags);
16594- memcpy(addr, opcode, len);
16595+
16596+ pax_open_kernel();
16597+ memcpy(ktla_ktva(addr), opcode, len);
16598 sync_core();
16599+ pax_close_kernel();
16600+
16601 local_irq_restore(flags);
16602 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16603 that causes hangs on some VIA CPUs. */
16604@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16605 */
16606 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16607 {
16608- unsigned long flags;
16609- char *vaddr;
16610+ unsigned char *vaddr = ktla_ktva(addr);
16611 struct page *pages[2];
16612- int i;
16613+ size_t i;
16614
16615 if (!core_kernel_text((unsigned long)addr)) {
16616- pages[0] = vmalloc_to_page(addr);
16617- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16618+ pages[0] = vmalloc_to_page(vaddr);
16619+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16620 } else {
16621- pages[0] = virt_to_page(addr);
16622+ pages[0] = virt_to_page(vaddr);
16623 WARN_ON(!PageReserved(pages[0]));
16624- pages[1] = virt_to_page(addr + PAGE_SIZE);
16625+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16626 }
16627 BUG_ON(!pages[0]);
16628- local_irq_save(flags);
16629- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16630- if (pages[1])
16631- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16632- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16633- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16634- clear_fixmap(FIX_TEXT_POKE0);
16635- if (pages[1])
16636- clear_fixmap(FIX_TEXT_POKE1);
16637- local_flush_tlb();
16638- sync_core();
16639- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16640- that causes hangs on some VIA CPUs. */
16641+ text_poke_early(addr, opcode, len);
16642 for (i = 0; i < len; i++)
16643- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16644- local_irq_restore(flags);
16645+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16646 return addr;
16647 }
16648
16649diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16650index cbf5121..812b537 100644
16651--- a/arch/x86/kernel/apic/apic.c
16652+++ b/arch/x86/kernel/apic/apic.c
16653@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16654 /*
16655 * Debug level, exported for io_apic.c
16656 */
16657-unsigned int apic_verbosity;
16658+int apic_verbosity;
16659
16660 int pic_mode;
16661
16662@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16663 apic_write(APIC_ESR, 0);
16664 v1 = apic_read(APIC_ESR);
16665 ack_APIC_irq();
16666- atomic_inc(&irq_err_count);
16667+ atomic_inc_unchecked(&irq_err_count);
16668
16669 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16670 smp_processor_id(), v0 , v1);
16671diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16672index 00c77cf..2dc6a2d 100644
16673--- a/arch/x86/kernel/apic/apic_flat_64.c
16674+++ b/arch/x86/kernel/apic/apic_flat_64.c
16675@@ -157,7 +157,7 @@ static int flat_probe(void)
16676 return 1;
16677 }
16678
16679-static struct apic apic_flat = {
16680+static struct apic apic_flat __read_only = {
16681 .name = "flat",
16682 .probe = flat_probe,
16683 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16684@@ -271,7 +271,7 @@ static int physflat_probe(void)
16685 return 0;
16686 }
16687
16688-static struct apic apic_physflat = {
16689+static struct apic apic_physflat __read_only = {
16690
16691 .name = "physical flat",
16692 .probe = physflat_probe,
16693diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16694index e145f28..2752888 100644
16695--- a/arch/x86/kernel/apic/apic_noop.c
16696+++ b/arch/x86/kernel/apic/apic_noop.c
16697@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16698 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16699 }
16700
16701-struct apic apic_noop = {
16702+struct apic apic_noop __read_only = {
16703 .name = "noop",
16704 .probe = noop_probe,
16705 .acpi_madt_oem_check = NULL,
16706diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16707index d50e364..543bee3 100644
16708--- a/arch/x86/kernel/apic/bigsmp_32.c
16709+++ b/arch/x86/kernel/apic/bigsmp_32.c
16710@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16711 return dmi_bigsmp;
16712 }
16713
16714-static struct apic apic_bigsmp = {
16715+static struct apic apic_bigsmp __read_only = {
16716
16717 .name = "bigsmp",
16718 .probe = probe_bigsmp,
16719diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16720index 0874799..a7a7892 100644
16721--- a/arch/x86/kernel/apic/es7000_32.c
16722+++ b/arch/x86/kernel/apic/es7000_32.c
16723@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16724 return ret && es7000_apic_is_cluster();
16725 }
16726
16727-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16728-static struct apic __refdata apic_es7000_cluster = {
16729+static struct apic apic_es7000_cluster __read_only = {
16730
16731 .name = "es7000",
16732 .probe = probe_es7000,
16733@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16734 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16735 };
16736
16737-static struct apic __refdata apic_es7000 = {
16738+static struct apic apic_es7000 __read_only = {
16739
16740 .name = "es7000",
16741 .probe = probe_es7000,
16742diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16743index b739d39..aebc14c 100644
16744--- a/arch/x86/kernel/apic/io_apic.c
16745+++ b/arch/x86/kernel/apic/io_apic.c
16746@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16747 }
16748 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16749
16750-void lock_vector_lock(void)
16751+void lock_vector_lock(void) __acquires(vector_lock)
16752 {
16753 /* Used to the online set of cpus does not change
16754 * during assign_irq_vector.
16755@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16756 raw_spin_lock(&vector_lock);
16757 }
16758
16759-void unlock_vector_lock(void)
16760+void unlock_vector_lock(void) __releases(vector_lock)
16761 {
16762 raw_spin_unlock(&vector_lock);
16763 }
16764@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16765 ack_APIC_irq();
16766 }
16767
16768-atomic_t irq_mis_count;
16769+atomic_unchecked_t irq_mis_count;
16770
16771 #ifdef CONFIG_GENERIC_PENDING_IRQ
16772 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16773@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16774 * at the cpu.
16775 */
16776 if (!(v & (1 << (i & 0x1f)))) {
16777- atomic_inc(&irq_mis_count);
16778+ atomic_inc_unchecked(&irq_mis_count);
16779
16780 eoi_ioapic_irq(irq, cfg);
16781 }
16782@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
16783
16784 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
16785 {
16786- chip->irq_print_chip = ir_print_prefix;
16787- chip->irq_ack = ir_ack_apic_edge;
16788- chip->irq_eoi = ir_ack_apic_level;
16789+ pax_open_kernel();
16790+ *(void **)&chip->irq_print_chip = ir_print_prefix;
16791+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
16792+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
16793
16794- chip->irq_set_affinity = set_remapped_irq_affinity;
16795+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
16796+ pax_close_kernel();
16797 }
16798 #endif /* CONFIG_IRQ_REMAP */
16799
16800diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16801index d661ee9..791fd33 100644
16802--- a/arch/x86/kernel/apic/numaq_32.c
16803+++ b/arch/x86/kernel/apic/numaq_32.c
16804@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16805 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16806 }
16807
16808-/* Use __refdata to keep false positive warning calm. */
16809-static struct apic __refdata apic_numaq = {
16810+static struct apic apic_numaq __read_only = {
16811
16812 .name = "NUMAQ",
16813 .probe = probe_numaq,
16814diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16815index eb35ef9..f184a21 100644
16816--- a/arch/x86/kernel/apic/probe_32.c
16817+++ b/arch/x86/kernel/apic/probe_32.c
16818@@ -72,7 +72,7 @@ static int probe_default(void)
16819 return 1;
16820 }
16821
16822-static struct apic apic_default = {
16823+static struct apic apic_default __read_only = {
16824
16825 .name = "default",
16826 .probe = probe_default,
16827diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16828index 77c95c0..434f8a4 100644
16829--- a/arch/x86/kernel/apic/summit_32.c
16830+++ b/arch/x86/kernel/apic/summit_32.c
16831@@ -486,7 +486,7 @@ void setup_summit(void)
16832 }
16833 #endif
16834
16835-static struct apic apic_summit = {
16836+static struct apic apic_summit __read_only = {
16837
16838 .name = "summit",
16839 .probe = probe_summit,
16840diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16841index c88baa4..757aee1 100644
16842--- a/arch/x86/kernel/apic/x2apic_cluster.c
16843+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16844@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16845 return notifier_from_errno(err);
16846 }
16847
16848-static struct notifier_block __refdata x2apic_cpu_notifier = {
16849+static struct notifier_block x2apic_cpu_notifier = {
16850 .notifier_call = update_clusterinfo,
16851 };
16852
16853@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16854 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16855 }
16856
16857-static struct apic apic_x2apic_cluster = {
16858+static struct apic apic_x2apic_cluster __read_only = {
16859
16860 .name = "cluster x2apic",
16861 .probe = x2apic_cluster_probe,
16862diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16863index 562a76d..a003c0f 100644
16864--- a/arch/x86/kernel/apic/x2apic_phys.c
16865+++ b/arch/x86/kernel/apic/x2apic_phys.c
16866@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16867 return apic == &apic_x2apic_phys;
16868 }
16869
16870-static struct apic apic_x2apic_phys = {
16871+static struct apic apic_x2apic_phys __read_only = {
16872
16873 .name = "physical x2apic",
16874 .probe = x2apic_phys_probe,
16875diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16876index 8cfade9..b9d04fc 100644
16877--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16878+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16879@@ -333,7 +333,7 @@ static int uv_probe(void)
16880 return apic == &apic_x2apic_uv_x;
16881 }
16882
16883-static struct apic __refdata apic_x2apic_uv_x = {
16884+static struct apic apic_x2apic_uv_x __read_only = {
16885
16886 .name = "UV large system",
16887 .probe = uv_probe,
16888diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16889index d65464e..1035d31 100644
16890--- a/arch/x86/kernel/apm_32.c
16891+++ b/arch/x86/kernel/apm_32.c
16892@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16893 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16894 * even though they are called in protected mode.
16895 */
16896-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16897+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16898 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16899
16900 static const char driver_version[] = "1.16ac"; /* no spaces */
16901@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16902 BUG_ON(cpu != 0);
16903 gdt = get_cpu_gdt_table(cpu);
16904 save_desc_40 = gdt[0x40 / 8];
16905+
16906+ pax_open_kernel();
16907 gdt[0x40 / 8] = bad_bios_desc;
16908+ pax_close_kernel();
16909
16910 apm_irq_save(flags);
16911 APM_DO_SAVE_SEGS;
16912@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16913 &call->esi);
16914 APM_DO_RESTORE_SEGS;
16915 apm_irq_restore(flags);
16916+
16917+ pax_open_kernel();
16918 gdt[0x40 / 8] = save_desc_40;
16919+ pax_close_kernel();
16920+
16921 put_cpu();
16922
16923 return call->eax & 0xff;
16924@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16925 BUG_ON(cpu != 0);
16926 gdt = get_cpu_gdt_table(cpu);
16927 save_desc_40 = gdt[0x40 / 8];
16928+
16929+ pax_open_kernel();
16930 gdt[0x40 / 8] = bad_bios_desc;
16931+ pax_close_kernel();
16932
16933 apm_irq_save(flags);
16934 APM_DO_SAVE_SEGS;
16935@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16936 &call->eax);
16937 APM_DO_RESTORE_SEGS;
16938 apm_irq_restore(flags);
16939+
16940+ pax_open_kernel();
16941 gdt[0x40 / 8] = save_desc_40;
16942+ pax_close_kernel();
16943+
16944 put_cpu();
16945 return error;
16946 }
16947@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16948 * code to that CPU.
16949 */
16950 gdt = get_cpu_gdt_table(0);
16951+
16952+ pax_open_kernel();
16953 set_desc_base(&gdt[APM_CS >> 3],
16954 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16955 set_desc_base(&gdt[APM_CS_16 >> 3],
16956 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16957 set_desc_base(&gdt[APM_DS >> 3],
16958 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16959+ pax_close_kernel();
16960
16961 proc_create("apm", 0, NULL, &apm_file_ops);
16962
16963diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16964index 2861082..6d4718e 100644
16965--- a/arch/x86/kernel/asm-offsets.c
16966+++ b/arch/x86/kernel/asm-offsets.c
16967@@ -33,6 +33,8 @@ void common(void) {
16968 OFFSET(TI_status, thread_info, status);
16969 OFFSET(TI_addr_limit, thread_info, addr_limit);
16970 OFFSET(TI_preempt_count, thread_info, preempt_count);
16971+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16972+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16973
16974 BLANK();
16975 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16976@@ -53,8 +55,26 @@ void common(void) {
16977 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16978 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16979 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16980+
16981+#ifdef CONFIG_PAX_KERNEXEC
16982+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16983 #endif
16984
16985+#ifdef CONFIG_PAX_MEMORY_UDEREF
16986+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16987+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16988+#ifdef CONFIG_X86_64
16989+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16990+#endif
16991+#endif
16992+
16993+#endif
16994+
16995+ BLANK();
16996+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16997+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16998+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16999+
17000 #ifdef CONFIG_XEN
17001 BLANK();
17002 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17003diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17004index 1b4754f..fbb4227 100644
17005--- a/arch/x86/kernel/asm-offsets_64.c
17006+++ b/arch/x86/kernel/asm-offsets_64.c
17007@@ -76,6 +76,7 @@ int main(void)
17008 BLANK();
17009 #undef ENTRY
17010
17011+ DEFINE(TSS_size, sizeof(struct tss_struct));
17012 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17013 BLANK();
17014
17015diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17016index a0e067d..9c7db16 100644
17017--- a/arch/x86/kernel/cpu/Makefile
17018+++ b/arch/x86/kernel/cpu/Makefile
17019@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17020 CFLAGS_REMOVE_perf_event.o = -pg
17021 endif
17022
17023-# Make sure load_percpu_segment has no stackprotector
17024-nostackp := $(call cc-option, -fno-stack-protector)
17025-CFLAGS_common.o := $(nostackp)
17026-
17027 obj-y := intel_cacheinfo.o scattered.o topology.o
17028 obj-y += proc.o capflags.o powerflags.o common.o
17029 obj-y += vmware.o hypervisor.o mshyperv.o
17030diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17031index 15239ff..e23e04e 100644
17032--- a/arch/x86/kernel/cpu/amd.c
17033+++ b/arch/x86/kernel/cpu/amd.c
17034@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17035 unsigned int size)
17036 {
17037 /* AMD errata T13 (order #21922) */
17038- if ((c->x86 == 6)) {
17039+ if (c->x86 == 6) {
17040 /* Duron Rev A0 */
17041 if (c->x86_model == 3 && c->x86_mask == 0)
17042 size = 64;
17043diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17044index 9c3ab43..51e6366 100644
17045--- a/arch/x86/kernel/cpu/common.c
17046+++ b/arch/x86/kernel/cpu/common.c
17047@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17048
17049 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17050
17051-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17052-#ifdef CONFIG_X86_64
17053- /*
17054- * We need valid kernel segments for data and code in long mode too
17055- * IRET will check the segment types kkeil 2000/10/28
17056- * Also sysret mandates a special GDT layout
17057- *
17058- * TLS descriptors are currently at a different place compared to i386.
17059- * Hopefully nobody expects them at a fixed place (Wine?)
17060- */
17061- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17062- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17063- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17064- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17065- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17066- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17067-#else
17068- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17069- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17070- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17071- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17072- /*
17073- * Segments used for calling PnP BIOS have byte granularity.
17074- * They code segments and data segments have fixed 64k limits,
17075- * the transfer segment sizes are set at run time.
17076- */
17077- /* 32-bit code */
17078- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17079- /* 16-bit code */
17080- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17081- /* 16-bit data */
17082- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17083- /* 16-bit data */
17084- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17085- /* 16-bit data */
17086- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17087- /*
17088- * The APM segments have byte granularity and their bases
17089- * are set at run time. All have 64k limits.
17090- */
17091- /* 32-bit code */
17092- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17093- /* 16-bit code */
17094- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17095- /* data */
17096- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17097-
17098- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17099- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17100- GDT_STACK_CANARY_INIT
17101-#endif
17102-} };
17103-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17104-
17105 static int __init x86_xsave_setup(char *s)
17106 {
17107 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17108@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
17109 {
17110 struct desc_ptr gdt_descr;
17111
17112- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17113+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17114 gdt_descr.size = GDT_SIZE - 1;
17115 load_gdt(&gdt_descr);
17116 /* Reload the per-cpu base */
17117@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17118 /* Filter out anything that depends on CPUID levels we don't have */
17119 filter_cpuid_features(c, true);
17120
17121+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17122+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17123+#endif
17124+
17125 /* If the model name is still unset, do table lookup. */
17126 if (!c->x86_model_id[0]) {
17127 const char *p;
17128@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
17129 }
17130 __setup("clearcpuid=", setup_disablecpuid);
17131
17132+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17133+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17134+
17135 #ifdef CONFIG_X86_64
17136 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17137-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17138- (unsigned long) nmi_idt_table };
17139+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17140
17141 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17142 irq_stack_union) __aligned(PAGE_SIZE);
17143@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17144 EXPORT_PER_CPU_SYMBOL(current_task);
17145
17146 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17147- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17148+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17149 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17150
17151 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17152@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
17153 int i;
17154
17155 cpu = stack_smp_processor_id();
17156- t = &per_cpu(init_tss, cpu);
17157+ t = init_tss + cpu;
17158 oist = &per_cpu(orig_ist, cpu);
17159
17160 #ifdef CONFIG_NUMA
17161@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
17162 switch_to_new_gdt(cpu);
17163 loadsegment(fs, 0);
17164
17165- load_idt((const struct desc_ptr *)&idt_descr);
17166+ load_idt(&idt_descr);
17167
17168 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17169 syscall_init();
17170@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
17171 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17172 barrier();
17173
17174- x86_configure_nx();
17175 enable_x2apic();
17176
17177 /*
17178@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
17179 {
17180 int cpu = smp_processor_id();
17181 struct task_struct *curr = current;
17182- struct tss_struct *t = &per_cpu(init_tss, cpu);
17183+ struct tss_struct *t = init_tss + cpu;
17184 struct thread_struct *thread = &curr->thread;
17185
17186 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
17187diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17188index fcaabd0..7b55a26 100644
17189--- a/arch/x86/kernel/cpu/intel.c
17190+++ b/arch/x86/kernel/cpu/intel.c
17191@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17192 * Update the IDT descriptor and reload the IDT so that
17193 * it uses the read-only mapped virtual address.
17194 */
17195- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17196+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17197 load_idt(&idt_descr);
17198 }
17199 #endif
17200diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17201index 84c1309..39b7224 100644
17202--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17203+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17204@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17205 };
17206
17207 #ifdef CONFIG_AMD_NB
17208+static struct attribute *default_attrs_amd_nb[] = {
17209+ &type.attr,
17210+ &level.attr,
17211+ &coherency_line_size.attr,
17212+ &physical_line_partition.attr,
17213+ &ways_of_associativity.attr,
17214+ &number_of_sets.attr,
17215+ &size.attr,
17216+ &shared_cpu_map.attr,
17217+ &shared_cpu_list.attr,
17218+ NULL,
17219+ NULL,
17220+ NULL,
17221+ NULL
17222+};
17223+
17224 static struct attribute ** __cpuinit amd_l3_attrs(void)
17225 {
17226 static struct attribute **attrs;
17227@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17228
17229 n = ARRAY_SIZE(default_attrs);
17230
17231- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17232- n += 2;
17233-
17234- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17235- n += 1;
17236-
17237- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17238- if (attrs == NULL)
17239- return attrs = default_attrs;
17240-
17241- for (n = 0; default_attrs[n]; n++)
17242- attrs[n] = default_attrs[n];
17243+ attrs = default_attrs_amd_nb;
17244
17245 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17246 attrs[n++] = &cache_disable_0.attr;
17247@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17248 .default_attrs = default_attrs,
17249 };
17250
17251+#ifdef CONFIG_AMD_NB
17252+static struct kobj_type ktype_cache_amd_nb = {
17253+ .sysfs_ops = &sysfs_ops,
17254+ .default_attrs = default_attrs_amd_nb,
17255+};
17256+#endif
17257+
17258 static struct kobj_type ktype_percpu_entry = {
17259 .sysfs_ops = &sysfs_ops,
17260 };
17261@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17262 return retval;
17263 }
17264
17265+#ifdef CONFIG_AMD_NB
17266+ amd_l3_attrs();
17267+#endif
17268+
17269 for (i = 0; i < num_cache_leaves; i++) {
17270+ struct kobj_type *ktype;
17271+
17272 this_object = INDEX_KOBJECT_PTR(cpu, i);
17273 this_object->cpu = cpu;
17274 this_object->index = i;
17275
17276 this_leaf = CPUID4_INFO_IDX(cpu, i);
17277
17278- ktype_cache.default_attrs = default_attrs;
17279+ ktype = &ktype_cache;
17280 #ifdef CONFIG_AMD_NB
17281 if (this_leaf->base.nb)
17282- ktype_cache.default_attrs = amd_l3_attrs();
17283+ ktype = &ktype_cache_amd_nb;
17284 #endif
17285 retval = kobject_init_and_add(&(this_object->kobj),
17286- &ktype_cache,
17287+ ktype,
17288 per_cpu(ici_cache_kobject, cpu),
17289 "index%1lu", i);
17290 if (unlikely(retval)) {
17291@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17292 return NOTIFY_OK;
17293 }
17294
17295-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17296+static struct notifier_block cacheinfo_cpu_notifier = {
17297 .notifier_call = cacheinfo_cpu_callback,
17298 };
17299
17300diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17301index 80dbda8..be16652 100644
17302--- a/arch/x86/kernel/cpu/mcheck/mce.c
17303+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17304@@ -45,6 +45,7 @@
17305 #include <asm/processor.h>
17306 #include <asm/mce.h>
17307 #include <asm/msr.h>
17308+#include <asm/local.h>
17309
17310 #include "mce-internal.h"
17311
17312@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17313 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17314 m->cs, m->ip);
17315
17316- if (m->cs == __KERNEL_CS)
17317+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17318 print_symbol("{%s}", m->ip);
17319 pr_cont("\n");
17320 }
17321@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17322
17323 #define PANIC_TIMEOUT 5 /* 5 seconds */
17324
17325-static atomic_t mce_paniced;
17326+static atomic_unchecked_t mce_paniced;
17327
17328 static int fake_panic;
17329-static atomic_t mce_fake_paniced;
17330+static atomic_unchecked_t mce_fake_paniced;
17331
17332 /* Panic in progress. Enable interrupts and wait for final IPI */
17333 static void wait_for_panic(void)
17334@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17335 /*
17336 * Make sure only one CPU runs in machine check panic
17337 */
17338- if (atomic_inc_return(&mce_paniced) > 1)
17339+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17340 wait_for_panic();
17341 barrier();
17342
17343@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17344 console_verbose();
17345 } else {
17346 /* Don't log too much for fake panic */
17347- if (atomic_inc_return(&mce_fake_paniced) > 1)
17348+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17349 return;
17350 }
17351 /* First print corrected ones that are still unlogged */
17352@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17353 * might have been modified by someone else.
17354 */
17355 rmb();
17356- if (atomic_read(&mce_paniced))
17357+ if (atomic_read_unchecked(&mce_paniced))
17358 wait_for_panic();
17359 if (!mca_cfg.monarch_timeout)
17360 goto out;
17361@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17362 }
17363
17364 /* Call the installed machine check handler for this CPU setup. */
17365-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17366+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17367 unexpected_machine_check;
17368
17369 /*
17370@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17371 return;
17372 }
17373
17374+ pax_open_kernel();
17375 machine_check_vector = do_machine_check;
17376+ pax_close_kernel();
17377
17378 __mcheck_cpu_init_generic();
17379 __mcheck_cpu_init_vendor(c);
17380@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17381 */
17382
17383 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17384-static int mce_chrdev_open_count; /* #times opened */
17385+static local_t mce_chrdev_open_count; /* #times opened */
17386 static int mce_chrdev_open_exclu; /* already open exclusive? */
17387
17388 static int mce_chrdev_open(struct inode *inode, struct file *file)
17389@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17390 spin_lock(&mce_chrdev_state_lock);
17391
17392 if (mce_chrdev_open_exclu ||
17393- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17394+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17395 spin_unlock(&mce_chrdev_state_lock);
17396
17397 return -EBUSY;
17398@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17399
17400 if (file->f_flags & O_EXCL)
17401 mce_chrdev_open_exclu = 1;
17402- mce_chrdev_open_count++;
17403+ local_inc(&mce_chrdev_open_count);
17404
17405 spin_unlock(&mce_chrdev_state_lock);
17406
17407@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17408 {
17409 spin_lock(&mce_chrdev_state_lock);
17410
17411- mce_chrdev_open_count--;
17412+ local_dec(&mce_chrdev_open_count);
17413 mce_chrdev_open_exclu = 0;
17414
17415 spin_unlock(&mce_chrdev_state_lock);
17416@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17417 return NOTIFY_OK;
17418 }
17419
17420-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17421+static struct notifier_block mce_cpu_notifier = {
17422 .notifier_call = mce_cpu_callback,
17423 };
17424
17425@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17426
17427 for (i = 0; i < mca_cfg.banks; i++) {
17428 struct mce_bank *b = &mce_banks[i];
17429- struct device_attribute *a = &b->attr;
17430+ device_attribute_no_const *a = &b->attr;
17431
17432 sysfs_attr_init(&a->attr);
17433 a->attr.name = b->attrname;
17434@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17435 static void mce_reset(void)
17436 {
17437 cpu_missing = 0;
17438- atomic_set(&mce_fake_paniced, 0);
17439+ atomic_set_unchecked(&mce_fake_paniced, 0);
17440 atomic_set(&mce_executing, 0);
17441 atomic_set(&mce_callin, 0);
17442 atomic_set(&global_nwo, 0);
17443diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17444index 2d5454c..51987eb 100644
17445--- a/arch/x86/kernel/cpu/mcheck/p5.c
17446+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17447@@ -11,6 +11,7 @@
17448 #include <asm/processor.h>
17449 #include <asm/mce.h>
17450 #include <asm/msr.h>
17451+#include <asm/pgtable.h>
17452
17453 /* By default disabled */
17454 int mce_p5_enabled __read_mostly;
17455@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17456 if (!cpu_has(c, X86_FEATURE_MCE))
17457 return;
17458
17459+ pax_open_kernel();
17460 machine_check_vector = pentium_machine_check;
17461+ pax_close_kernel();
17462 /* Make sure the vector pointer is visible before we enable MCEs: */
17463 wmb();
17464
17465diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17466index 47a1870..8c019a7 100644
17467--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17468+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17469@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17470 return notifier_from_errno(err);
17471 }
17472
17473-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17474+static struct notifier_block thermal_throttle_cpu_notifier =
17475 {
17476 .notifier_call = thermal_throttle_cpu_callback,
17477 };
17478diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17479index 2d7998f..17c9de1 100644
17480--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17481+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17482@@ -10,6 +10,7 @@
17483 #include <asm/processor.h>
17484 #include <asm/mce.h>
17485 #include <asm/msr.h>
17486+#include <asm/pgtable.h>
17487
17488 /* Machine check handler for WinChip C6: */
17489 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17490@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17491 {
17492 u32 lo, hi;
17493
17494+ pax_open_kernel();
17495 machine_check_vector = winchip_machine_check;
17496+ pax_close_kernel();
17497 /* Make sure the vector pointer is visible before we enable MCEs: */
17498 wmb();
17499
17500diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17501index 726bf96..81f0526 100644
17502--- a/arch/x86/kernel/cpu/mtrr/main.c
17503+++ b/arch/x86/kernel/cpu/mtrr/main.c
17504@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17505 u64 size_or_mask, size_and_mask;
17506 static bool mtrr_aps_delayed_init;
17507
17508-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17509+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17510
17511 const struct mtrr_ops *mtrr_if;
17512
17513diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17514index df5e41f..816c719 100644
17515--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17516+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17517@@ -25,7 +25,7 @@ struct mtrr_ops {
17518 int (*validate_add_page)(unsigned long base, unsigned long size,
17519 unsigned int type);
17520 int (*have_wrcomb)(void);
17521-};
17522+} __do_const;
17523
17524 extern int generic_get_free_region(unsigned long base, unsigned long size,
17525 int replace_reg);
17526diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17527index 6774c17..72c1b22 100644
17528--- a/arch/x86/kernel/cpu/perf_event.c
17529+++ b/arch/x86/kernel/cpu/perf_event.c
17530@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17531 pr_info("no hardware sampling interrupt available.\n");
17532 }
17533
17534-static struct attribute_group x86_pmu_format_group = {
17535+static attribute_group_no_const x86_pmu_format_group = {
17536 .name = "format",
17537 .attrs = NULL,
17538 };
17539@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17540 struct perf_pmu_events_attr {
17541 struct device_attribute attr;
17542 u64 id;
17543-};
17544+} __do_const;
17545
17546 /*
17547 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17548@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17549 NULL,
17550 };
17551
17552-static struct attribute_group x86_pmu_events_group = {
17553+static attribute_group_no_const x86_pmu_events_group = {
17554 .name = "events",
17555 .attrs = events_attr,
17556 };
17557@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17558 if (idx > GDT_ENTRIES)
17559 return 0;
17560
17561- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17562+ desc = get_cpu_gdt_table(smp_processor_id());
17563 }
17564
17565 return get_desc_base(desc + idx);
17566@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17567 break;
17568
17569 perf_callchain_store(entry, frame.return_address);
17570- fp = frame.next_frame;
17571+ fp = (const void __force_user *)frame.next_frame;
17572 }
17573 }
17574
17575diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17576index 4914e94..60b06e3 100644
17577--- a/arch/x86/kernel/cpu/perf_event_intel.c
17578+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17579@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17580 * v2 and above have a perf capabilities MSR
17581 */
17582 if (version > 1) {
17583- u64 capabilities;
17584+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17585
17586- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17587- x86_pmu.intel_cap.capabilities = capabilities;
17588+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17589+ x86_pmu.intel_cap.capabilities = capabilities;
17590 }
17591
17592 intel_ds_init();
17593diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17594index b43200d..d235b3e 100644
17595--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17596+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17597@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17598 static int __init uncore_type_init(struct intel_uncore_type *type)
17599 {
17600 struct intel_uncore_pmu *pmus;
17601- struct attribute_group *events_group;
17602+ attribute_group_no_const *attr_group;
17603 struct attribute **attrs;
17604 int i, j;
17605
17606@@ -2455,19 +2455,19 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
17607 while (type->event_descs[i].attr.attr.name)
17608 i++;
17609
17610- events_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
17611- sizeof(*events_group), GFP_KERNEL);
17612- if (!events_group)
17613+ attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
17614+ sizeof(*attr_group), GFP_KERNEL);
17615+ if (!attr_group)
17616 goto fail;
17617
17618- attrs = (struct attribute **)(events_group + 1);
17619- events_group->name = "events";
17620- events_group->attrs = attrs;
17621+ attrs = (struct attribute **)(attr_group + 1);
17622+ attr_group->name = "events";
17623+ attr_group->attrs = attrs;
17624
17625 for (j = 0; j < i; j++)
17626 attrs[j] = &type->event_descs[j].attr.attr;
17627
17628- type->events_group = events_group;
17629+ type->events_group = attr_group;
17630 }
17631
17632 type->pmu_group = &uncore_pmu_attr_group;
17633@@ -2826,7 +2826,7 @@ static int
17634 return NOTIFY_OK;
17635 }
17636
17637-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17638+static struct notifier_block uncore_cpu_nb = {
17639 .notifier_call = uncore_cpu_notifier,
17640 /*
17641 * to migrate uncore events, our notifier should be executed
17642diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17643index e68a455..975a932 100644
17644--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17645+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17646@@ -428,7 +428,7 @@ struct intel_uncore_box {
17647 struct uncore_event_desc {
17648 struct kobj_attribute attr;
17649 const char *config;
17650-};
17651+} __do_const;
17652
17653 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17654 { \
17655diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17656index 60c7891..9e911d3 100644
17657--- a/arch/x86/kernel/cpuid.c
17658+++ b/arch/x86/kernel/cpuid.c
17659@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17660 return notifier_from_errno(err);
17661 }
17662
17663-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17664+static struct notifier_block cpuid_class_cpu_notifier =
17665 {
17666 .notifier_call = cpuid_class_cpu_callback,
17667 };
17668diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17669index 74467fe..18793d5 100644
17670--- a/arch/x86/kernel/crash.c
17671+++ b/arch/x86/kernel/crash.c
17672@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17673 {
17674 #ifdef CONFIG_X86_32
17675 struct pt_regs fixed_regs;
17676-#endif
17677
17678-#ifdef CONFIG_X86_32
17679- if (!user_mode_vm(regs)) {
17680+ if (!user_mode(regs)) {
17681 crash_fixup_ss_esp(&fixed_regs, regs);
17682 regs = &fixed_regs;
17683 }
17684diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17685index 37250fe..bf2ec74 100644
17686--- a/arch/x86/kernel/doublefault_32.c
17687+++ b/arch/x86/kernel/doublefault_32.c
17688@@ -11,7 +11,7 @@
17689
17690 #define DOUBLEFAULT_STACKSIZE (1024)
17691 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17692-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17693+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17694
17695 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17696
17697@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17698 unsigned long gdt, tss;
17699
17700 store_gdt(&gdt_desc);
17701- gdt = gdt_desc.address;
17702+ gdt = (unsigned long)gdt_desc.address;
17703
17704 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17705
17706@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17707 /* 0x2 bit is always set */
17708 .flags = X86_EFLAGS_SF | 0x2,
17709 .sp = STACK_START,
17710- .es = __USER_DS,
17711+ .es = __KERNEL_DS,
17712 .cs = __KERNEL_CS,
17713 .ss = __KERNEL_DS,
17714- .ds = __USER_DS,
17715+ .ds = __KERNEL_DS,
17716 .fs = __KERNEL_PERCPU,
17717
17718 .__cr3 = __pa_nodebug(swapper_pg_dir),
17719diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17720index ae42418b..787c16b 100644
17721--- a/arch/x86/kernel/dumpstack.c
17722+++ b/arch/x86/kernel/dumpstack.c
17723@@ -2,6 +2,9 @@
17724 * Copyright (C) 1991, 1992 Linus Torvalds
17725 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17726 */
17727+#ifdef CONFIG_GRKERNSEC_HIDESYM
17728+#define __INCLUDED_BY_HIDESYM 1
17729+#endif
17730 #include <linux/kallsyms.h>
17731 #include <linux/kprobes.h>
17732 #include <linux/uaccess.h>
17733@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17734 static void
17735 print_ftrace_graph_addr(unsigned long addr, void *data,
17736 const struct stacktrace_ops *ops,
17737- struct thread_info *tinfo, int *graph)
17738+ struct task_struct *task, int *graph)
17739 {
17740- struct task_struct *task;
17741 unsigned long ret_addr;
17742 int index;
17743
17744 if (addr != (unsigned long)return_to_handler)
17745 return;
17746
17747- task = tinfo->task;
17748 index = task->curr_ret_stack;
17749
17750 if (!task->ret_stack || index < *graph)
17751@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17752 static inline void
17753 print_ftrace_graph_addr(unsigned long addr, void *data,
17754 const struct stacktrace_ops *ops,
17755- struct thread_info *tinfo, int *graph)
17756+ struct task_struct *task, int *graph)
17757 { }
17758 #endif
17759
17760@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17761 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17762 */
17763
17764-static inline int valid_stack_ptr(struct thread_info *tinfo,
17765- void *p, unsigned int size, void *end)
17766+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17767 {
17768- void *t = tinfo;
17769 if (end) {
17770 if (p < end && p >= (end-THREAD_SIZE))
17771 return 1;
17772@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17773 }
17774
17775 unsigned long
17776-print_context_stack(struct thread_info *tinfo,
17777+print_context_stack(struct task_struct *task, void *stack_start,
17778 unsigned long *stack, unsigned long bp,
17779 const struct stacktrace_ops *ops, void *data,
17780 unsigned long *end, int *graph)
17781 {
17782 struct stack_frame *frame = (struct stack_frame *)bp;
17783
17784- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17785+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17786 unsigned long addr;
17787
17788 addr = *stack;
17789@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17790 } else {
17791 ops->address(data, addr, 0);
17792 }
17793- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17794+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17795 }
17796 stack++;
17797 }
17798@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17799 EXPORT_SYMBOL_GPL(print_context_stack);
17800
17801 unsigned long
17802-print_context_stack_bp(struct thread_info *tinfo,
17803+print_context_stack_bp(struct task_struct *task, void *stack_start,
17804 unsigned long *stack, unsigned long bp,
17805 const struct stacktrace_ops *ops, void *data,
17806 unsigned long *end, int *graph)
17807@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17808 struct stack_frame *frame = (struct stack_frame *)bp;
17809 unsigned long *ret_addr = &frame->return_address;
17810
17811- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17812+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17813 unsigned long addr = *ret_addr;
17814
17815 if (!__kernel_text_address(addr))
17816@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17817 ops->address(data, addr, 1);
17818 frame = frame->next_frame;
17819 ret_addr = &frame->return_address;
17820- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17821+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17822 }
17823
17824 return (unsigned long)frame;
17825@@ -189,7 +188,7 @@ void dump_stack(void)
17826
17827 bp = stack_frame(current, NULL);
17828 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17829- current->pid, current->comm, print_tainted(),
17830+ task_pid_nr(current), current->comm, print_tainted(),
17831 init_utsname()->release,
17832 (int)strcspn(init_utsname()->version, " "),
17833 init_utsname()->version);
17834@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17835 }
17836 EXPORT_SYMBOL_GPL(oops_begin);
17837
17838+extern void gr_handle_kernel_exploit(void);
17839+
17840 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17841 {
17842 if (regs && kexec_should_crash(current))
17843@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17844 panic("Fatal exception in interrupt");
17845 if (panic_on_oops)
17846 panic("Fatal exception");
17847- do_exit(signr);
17848+
17849+ gr_handle_kernel_exploit();
17850+
17851+ do_group_exit(signr);
17852 }
17853
17854 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17855@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17856 print_modules();
17857 show_regs(regs);
17858 #ifdef CONFIG_X86_32
17859- if (user_mode_vm(regs)) {
17860+ if (user_mode(regs)) {
17861 sp = regs->sp;
17862 ss = regs->ss & 0xffff;
17863 } else {
17864@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17865 unsigned long flags = oops_begin();
17866 int sig = SIGSEGV;
17867
17868- if (!user_mode_vm(regs))
17869+ if (!user_mode(regs))
17870 report_bug(regs->ip, regs);
17871
17872 if (__die(str, regs, err))
17873diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17874index 1038a41..db2c12b 100644
17875--- a/arch/x86/kernel/dumpstack_32.c
17876+++ b/arch/x86/kernel/dumpstack_32.c
17877@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17878 bp = stack_frame(task, regs);
17879
17880 for (;;) {
17881- struct thread_info *context;
17882+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17883
17884- context = (struct thread_info *)
17885- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17886- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17887+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17888
17889- stack = (unsigned long *)context->previous_esp;
17890- if (!stack)
17891+ if (stack_start == task_stack_page(task))
17892 break;
17893+ stack = *(unsigned long **)stack_start;
17894 if (ops->stack(data, "IRQ") < 0)
17895 break;
17896 touch_nmi_watchdog();
17897@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17898 {
17899 int i;
17900
17901- __show_regs(regs, !user_mode_vm(regs));
17902+ __show_regs(regs, !user_mode(regs));
17903
17904 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17905 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17906@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17907 * When in-kernel, we also print out the stack and code at the
17908 * time of the fault..
17909 */
17910- if (!user_mode_vm(regs)) {
17911+ if (!user_mode(regs)) {
17912 unsigned int code_prologue = code_bytes * 43 / 64;
17913 unsigned int code_len = code_bytes;
17914 unsigned char c;
17915 u8 *ip;
17916+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17917
17918 pr_emerg("Stack:\n");
17919 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17920
17921 pr_emerg("Code:");
17922
17923- ip = (u8 *)regs->ip - code_prologue;
17924+ ip = (u8 *)regs->ip - code_prologue + cs_base;
17925 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17926 /* try starting at IP */
17927- ip = (u8 *)regs->ip;
17928+ ip = (u8 *)regs->ip + cs_base;
17929 code_len = code_len - code_prologue + 1;
17930 }
17931 for (i = 0; i < code_len; i++, ip++) {
17932@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17933 pr_cont(" Bad EIP value.");
17934 break;
17935 }
17936- if (ip == (u8 *)regs->ip)
17937+ if (ip == (u8 *)regs->ip + cs_base)
17938 pr_cont(" <%02x>", c);
17939 else
17940 pr_cont(" %02x", c);
17941@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17942 {
17943 unsigned short ud2;
17944
17945+ ip = ktla_ktva(ip);
17946 if (ip < PAGE_OFFSET)
17947 return 0;
17948 if (probe_kernel_address((unsigned short *)ip, ud2))
17949@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17950
17951 return ud2 == 0x0b0f;
17952 }
17953+
17954+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17955+void pax_check_alloca(unsigned long size)
17956+{
17957+ unsigned long sp = (unsigned long)&sp, stack_left;
17958+
17959+ /* all kernel stacks are of the same size */
17960+ stack_left = sp & (THREAD_SIZE - 1);
17961+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17962+}
17963+EXPORT_SYMBOL(pax_check_alloca);
17964+#endif
17965diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17966index b653675..51cc8c0 100644
17967--- a/arch/x86/kernel/dumpstack_64.c
17968+++ b/arch/x86/kernel/dumpstack_64.c
17969@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17970 unsigned long *irq_stack_end =
17971 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17972 unsigned used = 0;
17973- struct thread_info *tinfo;
17974 int graph = 0;
17975 unsigned long dummy;
17976+ void *stack_start;
17977
17978 if (!task)
17979 task = current;
17980@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17981 * current stack address. If the stacks consist of nested
17982 * exceptions
17983 */
17984- tinfo = task_thread_info(task);
17985 for (;;) {
17986 char *id;
17987 unsigned long *estack_end;
17988+
17989 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17990 &used, &id);
17991
17992@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17993 if (ops->stack(data, id) < 0)
17994 break;
17995
17996- bp = ops->walk_stack(tinfo, stack, bp, ops,
17997+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17998 data, estack_end, &graph);
17999 ops->stack(data, "<EOE>");
18000 /*
18001@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18002 * second-to-last pointer (index -2 to end) in the
18003 * exception stack:
18004 */
18005+ if ((u16)estack_end[-1] != __KERNEL_DS)
18006+ goto out;
18007 stack = (unsigned long *) estack_end[-2];
18008 continue;
18009 }
18010@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18011 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18012 if (ops->stack(data, "IRQ") < 0)
18013 break;
18014- bp = ops->walk_stack(tinfo, stack, bp,
18015+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18016 ops, data, irq_stack_end, &graph);
18017 /*
18018 * We link to the next stack (which would be
18019@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18020 /*
18021 * This handles the process stack:
18022 */
18023- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18024+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18025+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18026+out:
18027 put_cpu();
18028 }
18029 EXPORT_SYMBOL(dump_trace);
18030@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18031 {
18032 int i;
18033 unsigned long sp;
18034- const int cpu = smp_processor_id();
18035+ const int cpu = raw_smp_processor_id();
18036 struct task_struct *cur = current;
18037
18038 sp = regs->sp;
18039@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18040
18041 return ud2 == 0x0b0f;
18042 }
18043+
18044+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18045+void pax_check_alloca(unsigned long size)
18046+{
18047+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18048+ unsigned cpu, used;
18049+ char *id;
18050+
18051+ /* check the process stack first */
18052+ stack_start = (unsigned long)task_stack_page(current);
18053+ stack_end = stack_start + THREAD_SIZE;
18054+ if (likely(stack_start <= sp && sp < stack_end)) {
18055+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18056+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18057+ return;
18058+ }
18059+
18060+ cpu = get_cpu();
18061+
18062+ /* check the irq stacks */
18063+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18064+ stack_start = stack_end - IRQ_STACK_SIZE;
18065+ if (stack_start <= sp && sp < stack_end) {
18066+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18067+ put_cpu();
18068+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18069+ return;
18070+ }
18071+
18072+ /* check the exception stacks */
18073+ used = 0;
18074+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18075+ stack_start = stack_end - EXCEPTION_STKSZ;
18076+ if (stack_end && stack_start <= sp && sp < stack_end) {
18077+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18078+ put_cpu();
18079+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18080+ return;
18081+ }
18082+
18083+ put_cpu();
18084+
18085+ /* unknown stack */
18086+ BUG();
18087+}
18088+EXPORT_SYMBOL(pax_check_alloca);
18089+#endif
18090diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18091index 9b9f18b..9fcaa04 100644
18092--- a/arch/x86/kernel/early_printk.c
18093+++ b/arch/x86/kernel/early_printk.c
18094@@ -7,6 +7,7 @@
18095 #include <linux/pci_regs.h>
18096 #include <linux/pci_ids.h>
18097 #include <linux/errno.h>
18098+#include <linux/sched.h>
18099 #include <asm/io.h>
18100 #include <asm/processor.h>
18101 #include <asm/fcntl.h>
18102diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18103index 6ed91d9..6cc365b 100644
18104--- a/arch/x86/kernel/entry_32.S
18105+++ b/arch/x86/kernel/entry_32.S
18106@@ -177,13 +177,153 @@
18107 /*CFI_REL_OFFSET gs, PT_GS*/
18108 .endm
18109 .macro SET_KERNEL_GS reg
18110+
18111+#ifdef CONFIG_CC_STACKPROTECTOR
18112 movl $(__KERNEL_STACK_CANARY), \reg
18113+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18114+ movl $(__USER_DS), \reg
18115+#else
18116+ xorl \reg, \reg
18117+#endif
18118+
18119 movl \reg, %gs
18120 .endm
18121
18122 #endif /* CONFIG_X86_32_LAZY_GS */
18123
18124-.macro SAVE_ALL
18125+.macro pax_enter_kernel
18126+#ifdef CONFIG_PAX_KERNEXEC
18127+ call pax_enter_kernel
18128+#endif
18129+.endm
18130+
18131+.macro pax_exit_kernel
18132+#ifdef CONFIG_PAX_KERNEXEC
18133+ call pax_exit_kernel
18134+#endif
18135+.endm
18136+
18137+#ifdef CONFIG_PAX_KERNEXEC
18138+ENTRY(pax_enter_kernel)
18139+#ifdef CONFIG_PARAVIRT
18140+ pushl %eax
18141+ pushl %ecx
18142+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18143+ mov %eax, %esi
18144+#else
18145+ mov %cr0, %esi
18146+#endif
18147+ bts $16, %esi
18148+ jnc 1f
18149+ mov %cs, %esi
18150+ cmp $__KERNEL_CS, %esi
18151+ jz 3f
18152+ ljmp $__KERNEL_CS, $3f
18153+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18154+2:
18155+#ifdef CONFIG_PARAVIRT
18156+ mov %esi, %eax
18157+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18158+#else
18159+ mov %esi, %cr0
18160+#endif
18161+3:
18162+#ifdef CONFIG_PARAVIRT
18163+ popl %ecx
18164+ popl %eax
18165+#endif
18166+ ret
18167+ENDPROC(pax_enter_kernel)
18168+
18169+ENTRY(pax_exit_kernel)
18170+#ifdef CONFIG_PARAVIRT
18171+ pushl %eax
18172+ pushl %ecx
18173+#endif
18174+ mov %cs, %esi
18175+ cmp $__KERNEXEC_KERNEL_CS, %esi
18176+ jnz 2f
18177+#ifdef CONFIG_PARAVIRT
18178+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18179+ mov %eax, %esi
18180+#else
18181+ mov %cr0, %esi
18182+#endif
18183+ btr $16, %esi
18184+ ljmp $__KERNEL_CS, $1f
18185+1:
18186+#ifdef CONFIG_PARAVIRT
18187+ mov %esi, %eax
18188+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18189+#else
18190+ mov %esi, %cr0
18191+#endif
18192+2:
18193+#ifdef CONFIG_PARAVIRT
18194+ popl %ecx
18195+ popl %eax
18196+#endif
18197+ ret
18198+ENDPROC(pax_exit_kernel)
18199+#endif
18200+
18201+.macro pax_erase_kstack
18202+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18203+ call pax_erase_kstack
18204+#endif
18205+.endm
18206+
18207+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18208+/*
18209+ * ebp: thread_info
18210+ */
18211+ENTRY(pax_erase_kstack)
18212+ pushl %edi
18213+ pushl %ecx
18214+ pushl %eax
18215+
18216+ mov TI_lowest_stack(%ebp), %edi
18217+ mov $-0xBEEF, %eax
18218+ std
18219+
18220+1: mov %edi, %ecx
18221+ and $THREAD_SIZE_asm - 1, %ecx
18222+ shr $2, %ecx
18223+ repne scasl
18224+ jecxz 2f
18225+
18226+ cmp $2*16, %ecx
18227+ jc 2f
18228+
18229+ mov $2*16, %ecx
18230+ repe scasl
18231+ jecxz 2f
18232+ jne 1b
18233+
18234+2: cld
18235+ mov %esp, %ecx
18236+ sub %edi, %ecx
18237+
18238+ cmp $THREAD_SIZE_asm, %ecx
18239+ jb 3f
18240+ ud2
18241+3:
18242+
18243+ shr $2, %ecx
18244+ rep stosl
18245+
18246+ mov TI_task_thread_sp0(%ebp), %edi
18247+ sub $128, %edi
18248+ mov %edi, TI_lowest_stack(%ebp)
18249+
18250+ popl %eax
18251+ popl %ecx
18252+ popl %edi
18253+ ret
18254+ENDPROC(pax_erase_kstack)
18255+#endif
18256+
18257+.macro __SAVE_ALL _DS
18258 cld
18259 PUSH_GS
18260 pushl_cfi %fs
18261@@ -206,7 +346,7 @@
18262 CFI_REL_OFFSET ecx, 0
18263 pushl_cfi %ebx
18264 CFI_REL_OFFSET ebx, 0
18265- movl $(__USER_DS), %edx
18266+ movl $\_DS, %edx
18267 movl %edx, %ds
18268 movl %edx, %es
18269 movl $(__KERNEL_PERCPU), %edx
18270@@ -214,6 +354,15 @@
18271 SET_KERNEL_GS %edx
18272 .endm
18273
18274+.macro SAVE_ALL
18275+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18276+ __SAVE_ALL __KERNEL_DS
18277+ pax_enter_kernel
18278+#else
18279+ __SAVE_ALL __USER_DS
18280+#endif
18281+.endm
18282+
18283 .macro RESTORE_INT_REGS
18284 popl_cfi %ebx
18285 CFI_RESTORE ebx
18286@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18287 popfl_cfi
18288 jmp syscall_exit
18289 CFI_ENDPROC
18290-END(ret_from_fork)
18291+ENDPROC(ret_from_fork)
18292
18293 ENTRY(ret_from_kernel_thread)
18294 CFI_STARTPROC
18295@@ -344,7 +493,15 @@ ret_from_intr:
18296 andl $SEGMENT_RPL_MASK, %eax
18297 #endif
18298 cmpl $USER_RPL, %eax
18299+
18300+#ifdef CONFIG_PAX_KERNEXEC
18301+ jae resume_userspace
18302+
18303+ pax_exit_kernel
18304+ jmp resume_kernel
18305+#else
18306 jb resume_kernel # not returning to v8086 or userspace
18307+#endif
18308
18309 ENTRY(resume_userspace)
18310 LOCKDEP_SYS_EXIT
18311@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18312 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18313 # int/exception return?
18314 jne work_pending
18315- jmp restore_all
18316-END(ret_from_exception)
18317+ jmp restore_all_pax
18318+ENDPROC(ret_from_exception)
18319
18320 #ifdef CONFIG_PREEMPT
18321 ENTRY(resume_kernel)
18322@@ -372,7 +529,7 @@ need_resched:
18323 jz restore_all
18324 call preempt_schedule_irq
18325 jmp need_resched
18326-END(resume_kernel)
18327+ENDPROC(resume_kernel)
18328 #endif
18329 CFI_ENDPROC
18330 /*
18331@@ -406,30 +563,45 @@ sysenter_past_esp:
18332 /*CFI_REL_OFFSET cs, 0*/
18333 /*
18334 * Push current_thread_info()->sysenter_return to the stack.
18335- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18336- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18337 */
18338- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18339+ pushl_cfi $0
18340 CFI_REL_OFFSET eip, 0
18341
18342 pushl_cfi %eax
18343 SAVE_ALL
18344+ GET_THREAD_INFO(%ebp)
18345+ movl TI_sysenter_return(%ebp),%ebp
18346+ movl %ebp,PT_EIP(%esp)
18347 ENABLE_INTERRUPTS(CLBR_NONE)
18348
18349 /*
18350 * Load the potential sixth argument from user stack.
18351 * Careful about security.
18352 */
18353+ movl PT_OLDESP(%esp),%ebp
18354+
18355+#ifdef CONFIG_PAX_MEMORY_UDEREF
18356+ mov PT_OLDSS(%esp),%ds
18357+1: movl %ds:(%ebp),%ebp
18358+ push %ss
18359+ pop %ds
18360+#else
18361 cmpl $__PAGE_OFFSET-3,%ebp
18362 jae syscall_fault
18363 ASM_STAC
18364 1: movl (%ebp),%ebp
18365 ASM_CLAC
18366+#endif
18367+
18368 movl %ebp,PT_EBP(%esp)
18369 _ASM_EXTABLE(1b,syscall_fault)
18370
18371 GET_THREAD_INFO(%ebp)
18372
18373+#ifdef CONFIG_PAX_RANDKSTACK
18374+ pax_erase_kstack
18375+#endif
18376+
18377 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18378 jnz sysenter_audit
18379 sysenter_do_call:
18380@@ -444,12 +616,24 @@ sysenter_do_call:
18381 testl $_TIF_ALLWORK_MASK, %ecx
18382 jne sysexit_audit
18383 sysenter_exit:
18384+
18385+#ifdef CONFIG_PAX_RANDKSTACK
18386+ pushl_cfi %eax
18387+ movl %esp, %eax
18388+ call pax_randomize_kstack
18389+ popl_cfi %eax
18390+#endif
18391+
18392+ pax_erase_kstack
18393+
18394 /* if something modifies registers it must also disable sysexit */
18395 movl PT_EIP(%esp), %edx
18396 movl PT_OLDESP(%esp), %ecx
18397 xorl %ebp,%ebp
18398 TRACE_IRQS_ON
18399 1: mov PT_FS(%esp), %fs
18400+2: mov PT_DS(%esp), %ds
18401+3: mov PT_ES(%esp), %es
18402 PTGS_TO_GS
18403 ENABLE_INTERRUPTS_SYSEXIT
18404
18405@@ -466,6 +650,9 @@ sysenter_audit:
18406 movl %eax,%edx /* 2nd arg: syscall number */
18407 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18408 call __audit_syscall_entry
18409+
18410+ pax_erase_kstack
18411+
18412 pushl_cfi %ebx
18413 movl PT_EAX(%esp),%eax /* reload syscall number */
18414 jmp sysenter_do_call
18415@@ -491,10 +678,16 @@ sysexit_audit:
18416
18417 CFI_ENDPROC
18418 .pushsection .fixup,"ax"
18419-2: movl $0,PT_FS(%esp)
18420+4: movl $0,PT_FS(%esp)
18421+ jmp 1b
18422+5: movl $0,PT_DS(%esp)
18423+ jmp 1b
18424+6: movl $0,PT_ES(%esp)
18425 jmp 1b
18426 .popsection
18427- _ASM_EXTABLE(1b,2b)
18428+ _ASM_EXTABLE(1b,4b)
18429+ _ASM_EXTABLE(2b,5b)
18430+ _ASM_EXTABLE(3b,6b)
18431 PTGS_TO_GS_EX
18432 ENDPROC(ia32_sysenter_target)
18433
18434@@ -509,6 +702,11 @@ ENTRY(system_call)
18435 pushl_cfi %eax # save orig_eax
18436 SAVE_ALL
18437 GET_THREAD_INFO(%ebp)
18438+
18439+#ifdef CONFIG_PAX_RANDKSTACK
18440+ pax_erase_kstack
18441+#endif
18442+
18443 # system call tracing in operation / emulation
18444 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18445 jnz syscall_trace_entry
18446@@ -527,6 +725,15 @@ syscall_exit:
18447 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18448 jne syscall_exit_work
18449
18450+restore_all_pax:
18451+
18452+#ifdef CONFIG_PAX_RANDKSTACK
18453+ movl %esp, %eax
18454+ call pax_randomize_kstack
18455+#endif
18456+
18457+ pax_erase_kstack
18458+
18459 restore_all:
18460 TRACE_IRQS_IRET
18461 restore_all_notrace:
18462@@ -583,14 +790,34 @@ ldt_ss:
18463 * compensating for the offset by changing to the ESPFIX segment with
18464 * a base address that matches for the difference.
18465 */
18466-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18467+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18468 mov %esp, %edx /* load kernel esp */
18469 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18470 mov %dx, %ax /* eax: new kernel esp */
18471 sub %eax, %edx /* offset (low word is 0) */
18472+#ifdef CONFIG_SMP
18473+ movl PER_CPU_VAR(cpu_number), %ebx
18474+ shll $PAGE_SHIFT_asm, %ebx
18475+ addl $cpu_gdt_table, %ebx
18476+#else
18477+ movl $cpu_gdt_table, %ebx
18478+#endif
18479 shr $16, %edx
18480- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18481- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18482+
18483+#ifdef CONFIG_PAX_KERNEXEC
18484+ mov %cr0, %esi
18485+ btr $16, %esi
18486+ mov %esi, %cr0
18487+#endif
18488+
18489+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18490+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18491+
18492+#ifdef CONFIG_PAX_KERNEXEC
18493+ bts $16, %esi
18494+ mov %esi, %cr0
18495+#endif
18496+
18497 pushl_cfi $__ESPFIX_SS
18498 pushl_cfi %eax /* new kernel esp */
18499 /* Disable interrupts, but do not irqtrace this section: we
18500@@ -619,20 +846,18 @@ work_resched:
18501 movl TI_flags(%ebp), %ecx
18502 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18503 # than syscall tracing?
18504- jz restore_all
18505+ jz restore_all_pax
18506 testb $_TIF_NEED_RESCHED, %cl
18507 jnz work_resched
18508
18509 work_notifysig: # deal with pending signals and
18510 # notify-resume requests
18511+ movl %esp, %eax
18512 #ifdef CONFIG_VM86
18513 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18514- movl %esp, %eax
18515 jne work_notifysig_v86 # returning to kernel-space or
18516 # vm86-space
18517 1:
18518-#else
18519- movl %esp, %eax
18520 #endif
18521 TRACE_IRQS_ON
18522 ENABLE_INTERRUPTS(CLBR_NONE)
18523@@ -653,7 +878,7 @@ work_notifysig_v86:
18524 movl %eax, %esp
18525 jmp 1b
18526 #endif
18527-END(work_pending)
18528+ENDPROC(work_pending)
18529
18530 # perform syscall exit tracing
18531 ALIGN
18532@@ -661,11 +886,14 @@ syscall_trace_entry:
18533 movl $-ENOSYS,PT_EAX(%esp)
18534 movl %esp, %eax
18535 call syscall_trace_enter
18536+
18537+ pax_erase_kstack
18538+
18539 /* What it returned is what we'll actually use. */
18540 cmpl $(NR_syscalls), %eax
18541 jnae syscall_call
18542 jmp syscall_exit
18543-END(syscall_trace_entry)
18544+ENDPROC(syscall_trace_entry)
18545
18546 # perform syscall exit tracing
18547 ALIGN
18548@@ -678,21 +906,25 @@ syscall_exit_work:
18549 movl %esp, %eax
18550 call syscall_trace_leave
18551 jmp resume_userspace
18552-END(syscall_exit_work)
18553+ENDPROC(syscall_exit_work)
18554 CFI_ENDPROC
18555
18556 RING0_INT_FRAME # can't unwind into user space anyway
18557 syscall_fault:
18558+#ifdef CONFIG_PAX_MEMORY_UDEREF
18559+ push %ss
18560+ pop %ds
18561+#endif
18562 ASM_CLAC
18563 GET_THREAD_INFO(%ebp)
18564 movl $-EFAULT,PT_EAX(%esp)
18565 jmp resume_userspace
18566-END(syscall_fault)
18567+ENDPROC(syscall_fault)
18568
18569 syscall_badsys:
18570 movl $-ENOSYS,PT_EAX(%esp)
18571 jmp resume_userspace
18572-END(syscall_badsys)
18573+ENDPROC(syscall_badsys)
18574 CFI_ENDPROC
18575 /*
18576 * End of kprobes section
18577@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18578 * normal stack and adjusts ESP with the matching offset.
18579 */
18580 /* fixup the stack */
18581- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18582- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18583+#ifdef CONFIG_SMP
18584+ movl PER_CPU_VAR(cpu_number), %ebx
18585+ shll $PAGE_SHIFT_asm, %ebx
18586+ addl $cpu_gdt_table, %ebx
18587+#else
18588+ movl $cpu_gdt_table, %ebx
18589+#endif
18590+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18591+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18592 shl $16, %eax
18593 addl %esp, %eax /* the adjusted stack pointer */
18594 pushl_cfi $__KERNEL_DS
18595@@ -807,7 +1046,7 @@ vector=vector+1
18596 .endr
18597 2: jmp common_interrupt
18598 .endr
18599-END(irq_entries_start)
18600+ENDPROC(irq_entries_start)
18601
18602 .previous
18603 END(interrupt)
18604@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18605 pushl_cfi $do_coprocessor_error
18606 jmp error_code
18607 CFI_ENDPROC
18608-END(coprocessor_error)
18609+ENDPROC(coprocessor_error)
18610
18611 ENTRY(simd_coprocessor_error)
18612 RING0_INT_FRAME
18613@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18614 #endif
18615 jmp error_code
18616 CFI_ENDPROC
18617-END(simd_coprocessor_error)
18618+ENDPROC(simd_coprocessor_error)
18619
18620 ENTRY(device_not_available)
18621 RING0_INT_FRAME
18622@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18623 pushl_cfi $do_device_not_available
18624 jmp error_code
18625 CFI_ENDPROC
18626-END(device_not_available)
18627+ENDPROC(device_not_available)
18628
18629 #ifdef CONFIG_PARAVIRT
18630 ENTRY(native_iret)
18631 iret
18632 _ASM_EXTABLE(native_iret, iret_exc)
18633-END(native_iret)
18634+ENDPROC(native_iret)
18635
18636 ENTRY(native_irq_enable_sysexit)
18637 sti
18638 sysexit
18639-END(native_irq_enable_sysexit)
18640+ENDPROC(native_irq_enable_sysexit)
18641 #endif
18642
18643 ENTRY(overflow)
18644@@ -910,7 +1149,7 @@ ENTRY(overflow)
18645 pushl_cfi $do_overflow
18646 jmp error_code
18647 CFI_ENDPROC
18648-END(overflow)
18649+ENDPROC(overflow)
18650
18651 ENTRY(bounds)
18652 RING0_INT_FRAME
18653@@ -919,7 +1158,7 @@ ENTRY(bounds)
18654 pushl_cfi $do_bounds
18655 jmp error_code
18656 CFI_ENDPROC
18657-END(bounds)
18658+ENDPROC(bounds)
18659
18660 ENTRY(invalid_op)
18661 RING0_INT_FRAME
18662@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18663 pushl_cfi $do_invalid_op
18664 jmp error_code
18665 CFI_ENDPROC
18666-END(invalid_op)
18667+ENDPROC(invalid_op)
18668
18669 ENTRY(coprocessor_segment_overrun)
18670 RING0_INT_FRAME
18671@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18672 pushl_cfi $do_coprocessor_segment_overrun
18673 jmp error_code
18674 CFI_ENDPROC
18675-END(coprocessor_segment_overrun)
18676+ENDPROC(coprocessor_segment_overrun)
18677
18678 ENTRY(invalid_TSS)
18679 RING0_EC_FRAME
18680@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18681 pushl_cfi $do_invalid_TSS
18682 jmp error_code
18683 CFI_ENDPROC
18684-END(invalid_TSS)
18685+ENDPROC(invalid_TSS)
18686
18687 ENTRY(segment_not_present)
18688 RING0_EC_FRAME
18689@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18690 pushl_cfi $do_segment_not_present
18691 jmp error_code
18692 CFI_ENDPROC
18693-END(segment_not_present)
18694+ENDPROC(segment_not_present)
18695
18696 ENTRY(stack_segment)
18697 RING0_EC_FRAME
18698@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18699 pushl_cfi $do_stack_segment
18700 jmp error_code
18701 CFI_ENDPROC
18702-END(stack_segment)
18703+ENDPROC(stack_segment)
18704
18705 ENTRY(alignment_check)
18706 RING0_EC_FRAME
18707@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18708 pushl_cfi $do_alignment_check
18709 jmp error_code
18710 CFI_ENDPROC
18711-END(alignment_check)
18712+ENDPROC(alignment_check)
18713
18714 ENTRY(divide_error)
18715 RING0_INT_FRAME
18716@@ -978,7 +1217,7 @@ ENTRY(divide_error)
18717 pushl_cfi $do_divide_error
18718 jmp error_code
18719 CFI_ENDPROC
18720-END(divide_error)
18721+ENDPROC(divide_error)
18722
18723 #ifdef CONFIG_X86_MCE
18724 ENTRY(machine_check)
18725@@ -988,7 +1227,7 @@ ENTRY(machine_check)
18726 pushl_cfi machine_check_vector
18727 jmp error_code
18728 CFI_ENDPROC
18729-END(machine_check)
18730+ENDPROC(machine_check)
18731 #endif
18732
18733 ENTRY(spurious_interrupt_bug)
18734@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18735 pushl_cfi $do_spurious_interrupt_bug
18736 jmp error_code
18737 CFI_ENDPROC
18738-END(spurious_interrupt_bug)
18739+ENDPROC(spurious_interrupt_bug)
18740 /*
18741 * End of kprobes section
18742 */
18743@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18744
18745 ENTRY(mcount)
18746 ret
18747-END(mcount)
18748+ENDPROC(mcount)
18749
18750 ENTRY(ftrace_caller)
18751 cmpl $0, function_trace_stop
18752@@ -1134,7 +1373,7 @@ ftrace_graph_call:
18753 .globl ftrace_stub
18754 ftrace_stub:
18755 ret
18756-END(ftrace_caller)
18757+ENDPROC(ftrace_caller)
18758
18759 ENTRY(ftrace_regs_caller)
18760 pushf /* push flags before compare (in cs location) */
18761@@ -1235,7 +1474,7 @@ trace:
18762 popl %ecx
18763 popl %eax
18764 jmp ftrace_stub
18765-END(mcount)
18766+ENDPROC(mcount)
18767 #endif /* CONFIG_DYNAMIC_FTRACE */
18768 #endif /* CONFIG_FUNCTION_TRACER */
18769
18770@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18771 popl %ecx
18772 popl %eax
18773 ret
18774-END(ftrace_graph_caller)
18775+ENDPROC(ftrace_graph_caller)
18776
18777 .globl return_to_handler
18778 return_to_handler:
18779@@ -1309,15 +1548,18 @@ error_code:
18780 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18781 REG_TO_PTGS %ecx
18782 SET_KERNEL_GS %ecx
18783- movl $(__USER_DS), %ecx
18784+ movl $(__KERNEL_DS), %ecx
18785 movl %ecx, %ds
18786 movl %ecx, %es
18787+
18788+ pax_enter_kernel
18789+
18790 TRACE_IRQS_OFF
18791 movl %esp,%eax # pt_regs pointer
18792 call *%edi
18793 jmp ret_from_exception
18794 CFI_ENDPROC
18795-END(page_fault)
18796+ENDPROC(page_fault)
18797
18798 /*
18799 * Debug traps and NMI can happen at the one SYSENTER instruction
18800@@ -1360,7 +1602,7 @@ debug_stack_correct:
18801 call do_debug
18802 jmp ret_from_exception
18803 CFI_ENDPROC
18804-END(debug)
18805+ENDPROC(debug)
18806
18807 /*
18808 * NMI is doubly nasty. It can happen _while_ we're handling
18809@@ -1398,6 +1640,9 @@ nmi_stack_correct:
18810 xorl %edx,%edx # zero error code
18811 movl %esp,%eax # pt_regs pointer
18812 call do_nmi
18813+
18814+ pax_exit_kernel
18815+
18816 jmp restore_all_notrace
18817 CFI_ENDPROC
18818
18819@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18820 FIXUP_ESPFIX_STACK # %eax == %esp
18821 xorl %edx,%edx # zero error code
18822 call do_nmi
18823+
18824+ pax_exit_kernel
18825+
18826 RESTORE_REGS
18827 lss 12+4(%esp), %esp # back to espfix stack
18828 CFI_ADJUST_CFA_OFFSET -24
18829 jmp irq_return
18830 CFI_ENDPROC
18831-END(nmi)
18832+ENDPROC(nmi)
18833
18834 ENTRY(int3)
18835 RING0_INT_FRAME
18836@@ -1452,14 +1700,14 @@ ENTRY(int3)
18837 call do_int3
18838 jmp ret_from_exception
18839 CFI_ENDPROC
18840-END(int3)
18841+ENDPROC(int3)
18842
18843 ENTRY(general_protection)
18844 RING0_EC_FRAME
18845 pushl_cfi $do_general_protection
18846 jmp error_code
18847 CFI_ENDPROC
18848-END(general_protection)
18849+ENDPROC(general_protection)
18850
18851 #ifdef CONFIG_KVM_GUEST
18852 ENTRY(async_page_fault)
18853@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18854 pushl_cfi $do_async_page_fault
18855 jmp error_code
18856 CFI_ENDPROC
18857-END(async_page_fault)
18858+ENDPROC(async_page_fault)
18859 #endif
18860
18861 /*
18862diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18863index cb3c591..bc63707 100644
18864--- a/arch/x86/kernel/entry_64.S
18865+++ b/arch/x86/kernel/entry_64.S
18866@@ -59,6 +59,8 @@
18867 #include <asm/context_tracking.h>
18868 #include <asm/smap.h>
18869 #include <linux/err.h>
18870+#include <asm/pgtable.h>
18871+#include <asm/alternative-asm.h>
18872
18873 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18874 #include <linux/elf-em.h>
18875@@ -80,8 +82,9 @@
18876 #ifdef CONFIG_DYNAMIC_FTRACE
18877
18878 ENTRY(function_hook)
18879+ pax_force_retaddr
18880 retq
18881-END(function_hook)
18882+ENDPROC(function_hook)
18883
18884 /* skip is set if stack has been adjusted */
18885 .macro ftrace_caller_setup skip=0
18886@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18887 #endif
18888
18889 GLOBAL(ftrace_stub)
18890+ pax_force_retaddr
18891 retq
18892-END(ftrace_caller)
18893+ENDPROC(ftrace_caller)
18894
18895 ENTRY(ftrace_regs_caller)
18896 /* Save the current flags before compare (in SS location)*/
18897@@ -191,7 +195,7 @@ ftrace_restore_flags:
18898 popfq
18899 jmp ftrace_stub
18900
18901-END(ftrace_regs_caller)
18902+ENDPROC(ftrace_regs_caller)
18903
18904
18905 #else /* ! CONFIG_DYNAMIC_FTRACE */
18906@@ -212,6 +216,7 @@ ENTRY(function_hook)
18907 #endif
18908
18909 GLOBAL(ftrace_stub)
18910+ pax_force_retaddr
18911 retq
18912
18913 trace:
18914@@ -225,12 +230,13 @@ trace:
18915 #endif
18916 subq $MCOUNT_INSN_SIZE, %rdi
18917
18918+ pax_force_fptr ftrace_trace_function
18919 call *ftrace_trace_function
18920
18921 MCOUNT_RESTORE_FRAME
18922
18923 jmp ftrace_stub
18924-END(function_hook)
18925+ENDPROC(function_hook)
18926 #endif /* CONFIG_DYNAMIC_FTRACE */
18927 #endif /* CONFIG_FUNCTION_TRACER */
18928
18929@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18930
18931 MCOUNT_RESTORE_FRAME
18932
18933+ pax_force_retaddr
18934 retq
18935-END(ftrace_graph_caller)
18936+ENDPROC(ftrace_graph_caller)
18937
18938 GLOBAL(return_to_handler)
18939 subq $24, %rsp
18940@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18941 movq 8(%rsp), %rdx
18942 movq (%rsp), %rax
18943 addq $24, %rsp
18944+ pax_force_fptr %rdi
18945 jmp *%rdi
18946+ENDPROC(return_to_handler)
18947 #endif
18948
18949
18950@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18951 ENDPROC(native_usergs_sysret64)
18952 #endif /* CONFIG_PARAVIRT */
18953
18954+ .macro ljmpq sel, off
18955+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18956+ .byte 0x48; ljmp *1234f(%rip)
18957+ .pushsection .rodata
18958+ .align 16
18959+ 1234: .quad \off; .word \sel
18960+ .popsection
18961+#else
18962+ pushq $\sel
18963+ pushq $\off
18964+ lretq
18965+#endif
18966+ .endm
18967+
18968+ .macro pax_enter_kernel
18969+ pax_set_fptr_mask
18970+#ifdef CONFIG_PAX_KERNEXEC
18971+ call pax_enter_kernel
18972+#endif
18973+ .endm
18974+
18975+ .macro pax_exit_kernel
18976+#ifdef CONFIG_PAX_KERNEXEC
18977+ call pax_exit_kernel
18978+#endif
18979+ .endm
18980+
18981+#ifdef CONFIG_PAX_KERNEXEC
18982+ENTRY(pax_enter_kernel)
18983+ pushq %rdi
18984+
18985+#ifdef CONFIG_PARAVIRT
18986+ PV_SAVE_REGS(CLBR_RDI)
18987+#endif
18988+
18989+ GET_CR0_INTO_RDI
18990+ bts $16,%rdi
18991+ jnc 3f
18992+ mov %cs,%edi
18993+ cmp $__KERNEL_CS,%edi
18994+ jnz 2f
18995+1:
18996+
18997+#ifdef CONFIG_PARAVIRT
18998+ PV_RESTORE_REGS(CLBR_RDI)
18999+#endif
19000+
19001+ popq %rdi
19002+ pax_force_retaddr
19003+ retq
19004+
19005+2: ljmpq __KERNEL_CS,1f
19006+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19007+4: SET_RDI_INTO_CR0
19008+ jmp 1b
19009+ENDPROC(pax_enter_kernel)
19010+
19011+ENTRY(pax_exit_kernel)
19012+ pushq %rdi
19013+
19014+#ifdef CONFIG_PARAVIRT
19015+ PV_SAVE_REGS(CLBR_RDI)
19016+#endif
19017+
19018+ mov %cs,%rdi
19019+ cmp $__KERNEXEC_KERNEL_CS,%edi
19020+ jz 2f
19021+1:
19022+
19023+#ifdef CONFIG_PARAVIRT
19024+ PV_RESTORE_REGS(CLBR_RDI);
19025+#endif
19026+
19027+ popq %rdi
19028+ pax_force_retaddr
19029+ retq
19030+
19031+2: GET_CR0_INTO_RDI
19032+ btr $16,%rdi
19033+ ljmpq __KERNEL_CS,3f
19034+3: SET_RDI_INTO_CR0
19035+ jmp 1b
19036+ENDPROC(pax_exit_kernel)
19037+#endif
19038+
19039+ .macro pax_enter_kernel_user
19040+ pax_set_fptr_mask
19041+#ifdef CONFIG_PAX_MEMORY_UDEREF
19042+ call pax_enter_kernel_user
19043+#endif
19044+ .endm
19045+
19046+ .macro pax_exit_kernel_user
19047+#ifdef CONFIG_PAX_MEMORY_UDEREF
19048+ call pax_exit_kernel_user
19049+#endif
19050+#ifdef CONFIG_PAX_RANDKSTACK
19051+ pushq %rax
19052+ call pax_randomize_kstack
19053+ popq %rax
19054+#endif
19055+ .endm
19056+
19057+#ifdef CONFIG_PAX_MEMORY_UDEREF
19058+ENTRY(pax_enter_kernel_user)
19059+ pushq %rdi
19060+ pushq %rbx
19061+
19062+#ifdef CONFIG_PARAVIRT
19063+ PV_SAVE_REGS(CLBR_RDI)
19064+#endif
19065+
19066+ GET_CR3_INTO_RDI
19067+ mov %rdi,%rbx
19068+ add $__START_KERNEL_map,%rbx
19069+ sub phys_base(%rip),%rbx
19070+
19071+#ifdef CONFIG_PARAVIRT
19072+ pushq %rdi
19073+ cmpl $0, pv_info+PARAVIRT_enabled
19074+ jz 1f
19075+ i = 0
19076+ .rept USER_PGD_PTRS
19077+ mov i*8(%rbx),%rsi
19078+ mov $0,%sil
19079+ lea i*8(%rbx),%rdi
19080+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19081+ i = i + 1
19082+ .endr
19083+ jmp 2f
19084+1:
19085+#endif
19086+
19087+ i = 0
19088+ .rept USER_PGD_PTRS
19089+ movb $0,i*8(%rbx)
19090+ i = i + 1
19091+ .endr
19092+
19093+#ifdef CONFIG_PARAVIRT
19094+2: popq %rdi
19095+#endif
19096+ SET_RDI_INTO_CR3
19097+
19098+#ifdef CONFIG_PAX_KERNEXEC
19099+ GET_CR0_INTO_RDI
19100+ bts $16,%rdi
19101+ SET_RDI_INTO_CR0
19102+#endif
19103+
19104+#ifdef CONFIG_PARAVIRT
19105+ PV_RESTORE_REGS(CLBR_RDI)
19106+#endif
19107+
19108+ popq %rbx
19109+ popq %rdi
19110+ pax_force_retaddr
19111+ retq
19112+ENDPROC(pax_enter_kernel_user)
19113+
19114+ENTRY(pax_exit_kernel_user)
19115+ push %rdi
19116+
19117+#ifdef CONFIG_PARAVIRT
19118+ pushq %rbx
19119+ PV_SAVE_REGS(CLBR_RDI)
19120+#endif
19121+
19122+#ifdef CONFIG_PAX_KERNEXEC
19123+ GET_CR0_INTO_RDI
19124+ btr $16,%rdi
19125+ SET_RDI_INTO_CR0
19126+#endif
19127+
19128+ GET_CR3_INTO_RDI
19129+ add $__START_KERNEL_map,%rdi
19130+ sub phys_base(%rip),%rdi
19131+
19132+#ifdef CONFIG_PARAVIRT
19133+ cmpl $0, pv_info+PARAVIRT_enabled
19134+ jz 1f
19135+ mov %rdi,%rbx
19136+ i = 0
19137+ .rept USER_PGD_PTRS
19138+ mov i*8(%rbx),%rsi
19139+ mov $0x67,%sil
19140+ lea i*8(%rbx),%rdi
19141+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19142+ i = i + 1
19143+ .endr
19144+ jmp 2f
19145+1:
19146+#endif
19147+
19148+ i = 0
19149+ .rept USER_PGD_PTRS
19150+ movb $0x67,i*8(%rdi)
19151+ i = i + 1
19152+ .endr
19153+
19154+#ifdef CONFIG_PARAVIRT
19155+2: PV_RESTORE_REGS(CLBR_RDI)
19156+ popq %rbx
19157+#endif
19158+
19159+ popq %rdi
19160+ pax_force_retaddr
19161+ retq
19162+ENDPROC(pax_exit_kernel_user)
19163+#endif
19164+
19165+.macro pax_erase_kstack
19166+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19167+ call pax_erase_kstack
19168+#endif
19169+.endm
19170+
19171+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19172+ENTRY(pax_erase_kstack)
19173+ pushq %rdi
19174+ pushq %rcx
19175+ pushq %rax
19176+ pushq %r11
19177+
19178+ GET_THREAD_INFO(%r11)
19179+ mov TI_lowest_stack(%r11), %rdi
19180+ mov $-0xBEEF, %rax
19181+ std
19182+
19183+1: mov %edi, %ecx
19184+ and $THREAD_SIZE_asm - 1, %ecx
19185+ shr $3, %ecx
19186+ repne scasq
19187+ jecxz 2f
19188+
19189+ cmp $2*8, %ecx
19190+ jc 2f
19191+
19192+ mov $2*8, %ecx
19193+ repe scasq
19194+ jecxz 2f
19195+ jne 1b
19196+
19197+2: cld
19198+ mov %esp, %ecx
19199+ sub %edi, %ecx
19200+
19201+ cmp $THREAD_SIZE_asm, %rcx
19202+ jb 3f
19203+ ud2
19204+3:
19205+
19206+ shr $3, %ecx
19207+ rep stosq
19208+
19209+ mov TI_task_thread_sp0(%r11), %rdi
19210+ sub $256, %rdi
19211+ mov %rdi, TI_lowest_stack(%r11)
19212+
19213+ popq %r11
19214+ popq %rax
19215+ popq %rcx
19216+ popq %rdi
19217+ pax_force_retaddr
19218+ ret
19219+ENDPROC(pax_erase_kstack)
19220+#endif
19221
19222 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19223 #ifdef CONFIG_TRACE_IRQFLAGS
19224@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
19225 .endm
19226
19227 .macro UNFAKE_STACK_FRAME
19228- addq $8*6, %rsp
19229- CFI_ADJUST_CFA_OFFSET -(6*8)
19230+ addq $8*6 + ARG_SKIP, %rsp
19231+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19232 .endm
19233
19234 /*
19235@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
19236 movq %rsp, %rsi
19237
19238 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19239- testl $3, CS-RBP(%rsi)
19240+ testb $3, CS-RBP(%rsi)
19241 je 1f
19242 SWAPGS
19243 /*
19244@@ -498,9 +774,10 @@ ENTRY(save_rest)
19245 movq_cfi r15, R15+16
19246 movq %r11, 8(%rsp) /* return address */
19247 FIXUP_TOP_OF_STACK %r11, 16
19248+ pax_force_retaddr
19249 ret
19250 CFI_ENDPROC
19251-END(save_rest)
19252+ENDPROC(save_rest)
19253
19254 /* save complete stack frame */
19255 .pushsection .kprobes.text, "ax"
19256@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
19257 js 1f /* negative -> in kernel */
19258 SWAPGS
19259 xorl %ebx,%ebx
19260-1: ret
19261+1: pax_force_retaddr_bts
19262+ ret
19263 CFI_ENDPROC
19264-END(save_paranoid)
19265+ENDPROC(save_paranoid)
19266 .popsection
19267
19268 /*
19269@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
19270
19271 RESTORE_REST
19272
19273- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19274+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19275 jz 1f
19276
19277 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19278@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
19279 RESTORE_REST
19280 jmp int_ret_from_sys_call
19281 CFI_ENDPROC
19282-END(ret_from_fork)
19283+ENDPROC(ret_from_fork)
19284
19285 /*
19286 * System call entry. Up to 6 arguments in registers are supported.
19287@@ -608,7 +886,7 @@ END(ret_from_fork)
19288 ENTRY(system_call)
19289 CFI_STARTPROC simple
19290 CFI_SIGNAL_FRAME
19291- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19292+ CFI_DEF_CFA rsp,0
19293 CFI_REGISTER rip,rcx
19294 /*CFI_REGISTER rflags,r11*/
19295 SWAPGS_UNSAFE_STACK
19296@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
19297
19298 movq %rsp,PER_CPU_VAR(old_rsp)
19299 movq PER_CPU_VAR(kernel_stack),%rsp
19300+ SAVE_ARGS 8*6,0
19301+ pax_enter_kernel_user
19302+
19303+#ifdef CONFIG_PAX_RANDKSTACK
19304+ pax_erase_kstack
19305+#endif
19306+
19307 /*
19308 * No need to follow this irqs off/on section - it's straight
19309 * and short:
19310 */
19311 ENABLE_INTERRUPTS(CLBR_NONE)
19312- SAVE_ARGS 8,0
19313 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19314 movq %rcx,RIP-ARGOFFSET(%rsp)
19315 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19316- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19317+ GET_THREAD_INFO(%rcx)
19318+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19319 jnz tracesys
19320 system_call_fastpath:
19321 #if __SYSCALL_MASK == ~0
19322@@ -640,7 +925,7 @@ system_call_fastpath:
19323 cmpl $__NR_syscall_max,%eax
19324 #endif
19325 ja badsys
19326- movq %r10,%rcx
19327+ movq R10-ARGOFFSET(%rsp),%rcx
19328 call *sys_call_table(,%rax,8) # XXX: rip relative
19329 movq %rax,RAX-ARGOFFSET(%rsp)
19330 /*
19331@@ -654,10 +939,13 @@ sysret_check:
19332 LOCKDEP_SYS_EXIT
19333 DISABLE_INTERRUPTS(CLBR_NONE)
19334 TRACE_IRQS_OFF
19335- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19336+ GET_THREAD_INFO(%rcx)
19337+ movl TI_flags(%rcx),%edx
19338 andl %edi,%edx
19339 jnz sysret_careful
19340 CFI_REMEMBER_STATE
19341+ pax_exit_kernel_user
19342+ pax_erase_kstack
19343 /*
19344 * sysretq will re-enable interrupts:
19345 */
19346@@ -709,14 +997,18 @@ badsys:
19347 * jump back to the normal fast path.
19348 */
19349 auditsys:
19350- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19351+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19352 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19353 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19354 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19355 movq %rax,%rsi /* 2nd arg: syscall number */
19356 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19357 call __audit_syscall_entry
19358+
19359+ pax_erase_kstack
19360+
19361 LOAD_ARGS 0 /* reload call-clobbered registers */
19362+ pax_set_fptr_mask
19363 jmp system_call_fastpath
19364
19365 /*
19366@@ -737,7 +1029,7 @@ sysret_audit:
19367 /* Do syscall tracing */
19368 tracesys:
19369 #ifdef CONFIG_AUDITSYSCALL
19370- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19371+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19372 jz auditsys
19373 #endif
19374 SAVE_REST
19375@@ -745,12 +1037,16 @@ tracesys:
19376 FIXUP_TOP_OF_STACK %rdi
19377 movq %rsp,%rdi
19378 call syscall_trace_enter
19379+
19380+ pax_erase_kstack
19381+
19382 /*
19383 * Reload arg registers from stack in case ptrace changed them.
19384 * We don't reload %rax because syscall_trace_enter() returned
19385 * the value it wants us to use in the table lookup.
19386 */
19387 LOAD_ARGS ARGOFFSET, 1
19388+ pax_set_fptr_mask
19389 RESTORE_REST
19390 #if __SYSCALL_MASK == ~0
19391 cmpq $__NR_syscall_max,%rax
19392@@ -759,7 +1055,7 @@ tracesys:
19393 cmpl $__NR_syscall_max,%eax
19394 #endif
19395 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19396- movq %r10,%rcx /* fixup for C */
19397+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19398 call *sys_call_table(,%rax,8)
19399 movq %rax,RAX-ARGOFFSET(%rsp)
19400 /* Use IRET because user could have changed frame */
19401@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19402 andl %edi,%edx
19403 jnz int_careful
19404 andl $~TS_COMPAT,TI_status(%rcx)
19405- jmp retint_swapgs
19406+ pax_exit_kernel_user
19407+ pax_erase_kstack
19408+ jmp retint_swapgs_pax
19409
19410 /* Either reschedule or signal or syscall exit tracking needed. */
19411 /* First do a reschedule test. */
19412@@ -826,7 +1124,7 @@ int_restore_rest:
19413 TRACE_IRQS_OFF
19414 jmp int_with_check
19415 CFI_ENDPROC
19416-END(system_call)
19417+ENDPROC(system_call)
19418
19419 /*
19420 * Certain special system calls that need to save a complete full stack frame.
19421@@ -842,7 +1140,7 @@ ENTRY(\label)
19422 call \func
19423 jmp ptregscall_common
19424 CFI_ENDPROC
19425-END(\label)
19426+ENDPROC(\label)
19427 .endm
19428
19429 .macro FORK_LIKE func
19430@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19431 DEFAULT_FRAME 0 8 /* offset 8: return address */
19432 call sys_\func
19433 RESTORE_TOP_OF_STACK %r11, 8
19434+ pax_force_retaddr
19435 ret $REST_SKIP /* pop extended registers */
19436 CFI_ENDPROC
19437-END(stub_\func)
19438+ENDPROC(stub_\func)
19439 .endm
19440
19441 FORK_LIKE clone
19442@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19443 movq_cfi_restore R12+8, r12
19444 movq_cfi_restore RBP+8, rbp
19445 movq_cfi_restore RBX+8, rbx
19446+ pax_force_retaddr
19447 ret $REST_SKIP /* pop extended registers */
19448 CFI_ENDPROC
19449-END(ptregscall_common)
19450+ENDPROC(ptregscall_common)
19451
19452 ENTRY(stub_execve)
19453 CFI_STARTPROC
19454@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19455 RESTORE_REST
19456 jmp int_ret_from_sys_call
19457 CFI_ENDPROC
19458-END(stub_execve)
19459+ENDPROC(stub_execve)
19460
19461 /*
19462 * sigreturn is special because it needs to restore all registers on return.
19463@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19464 RESTORE_REST
19465 jmp int_ret_from_sys_call
19466 CFI_ENDPROC
19467-END(stub_rt_sigreturn)
19468+ENDPROC(stub_rt_sigreturn)
19469
19470 #ifdef CONFIG_X86_X32_ABI
19471 ENTRY(stub_x32_rt_sigreturn)
19472@@ -975,7 +1275,7 @@ vector=vector+1
19473 2: jmp common_interrupt
19474 .endr
19475 CFI_ENDPROC
19476-END(irq_entries_start)
19477+ENDPROC(irq_entries_start)
19478
19479 .previous
19480 END(interrupt)
19481@@ -995,6 +1295,16 @@ END(interrupt)
19482 subq $ORIG_RAX-RBP, %rsp
19483 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19484 SAVE_ARGS_IRQ
19485+#ifdef CONFIG_PAX_MEMORY_UDEREF
19486+ testb $3, CS(%rdi)
19487+ jnz 1f
19488+ pax_enter_kernel
19489+ jmp 2f
19490+1: pax_enter_kernel_user
19491+2:
19492+#else
19493+ pax_enter_kernel
19494+#endif
19495 call \func
19496 .endm
19497
19498@@ -1027,7 +1337,7 @@ ret_from_intr:
19499
19500 exit_intr:
19501 GET_THREAD_INFO(%rcx)
19502- testl $3,CS-ARGOFFSET(%rsp)
19503+ testb $3,CS-ARGOFFSET(%rsp)
19504 je retint_kernel
19505
19506 /* Interrupt came from user space */
19507@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19508 * The iretq could re-enable interrupts:
19509 */
19510 DISABLE_INTERRUPTS(CLBR_ANY)
19511+ pax_exit_kernel_user
19512+retint_swapgs_pax:
19513 TRACE_IRQS_IRETQ
19514 SWAPGS
19515 jmp restore_args
19516
19517 retint_restore_args: /* return to kernel space */
19518 DISABLE_INTERRUPTS(CLBR_ANY)
19519+ pax_exit_kernel
19520+ pax_force_retaddr (RIP-ARGOFFSET)
19521 /*
19522 * The iretq could re-enable interrupts:
19523 */
19524@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19525 #endif
19526
19527 CFI_ENDPROC
19528-END(common_interrupt)
19529+ENDPROC(common_interrupt)
19530 /*
19531 * End of kprobes section
19532 */
19533@@ -1155,7 +1469,7 @@ ENTRY(\sym)
19534 interrupt \do_sym
19535 jmp ret_from_intr
19536 CFI_ENDPROC
19537-END(\sym)
19538+ENDPROC(\sym)
19539 .endm
19540
19541 #ifdef CONFIG_SMP
19542@@ -1211,12 +1525,22 @@ ENTRY(\sym)
19543 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19544 call error_entry
19545 DEFAULT_FRAME 0
19546+#ifdef CONFIG_PAX_MEMORY_UDEREF
19547+ testb $3, CS(%rsp)
19548+ jnz 1f
19549+ pax_enter_kernel
19550+ jmp 2f
19551+1: pax_enter_kernel_user
19552+2:
19553+#else
19554+ pax_enter_kernel
19555+#endif
19556 movq %rsp,%rdi /* pt_regs pointer */
19557 xorl %esi,%esi /* no error code */
19558 call \do_sym
19559 jmp error_exit /* %ebx: no swapgs flag */
19560 CFI_ENDPROC
19561-END(\sym)
19562+ENDPROC(\sym)
19563 .endm
19564
19565 .macro paranoidzeroentry sym do_sym
19566@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19567 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19568 call save_paranoid
19569 TRACE_IRQS_OFF
19570+#ifdef CONFIG_PAX_MEMORY_UDEREF
19571+ testb $3, CS(%rsp)
19572+ jnz 1f
19573+ pax_enter_kernel
19574+ jmp 2f
19575+1: pax_enter_kernel_user
19576+2:
19577+#else
19578+ pax_enter_kernel
19579+#endif
19580 movq %rsp,%rdi /* pt_regs pointer */
19581 xorl %esi,%esi /* no error code */
19582 call \do_sym
19583 jmp paranoid_exit /* %ebx: no swapgs flag */
19584 CFI_ENDPROC
19585-END(\sym)
19586+ENDPROC(\sym)
19587 .endm
19588
19589-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19590+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19591 .macro paranoidzeroentry_ist sym do_sym ist
19592 ENTRY(\sym)
19593 INTR_FRAME
19594@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19595 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19596 call save_paranoid
19597 TRACE_IRQS_OFF_DEBUG
19598+#ifdef CONFIG_PAX_MEMORY_UDEREF
19599+ testb $3, CS(%rsp)
19600+ jnz 1f
19601+ pax_enter_kernel
19602+ jmp 2f
19603+1: pax_enter_kernel_user
19604+2:
19605+#else
19606+ pax_enter_kernel
19607+#endif
19608 movq %rsp,%rdi /* pt_regs pointer */
19609 xorl %esi,%esi /* no error code */
19610+#ifdef CONFIG_SMP
19611+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19612+ lea init_tss(%r12), %r12
19613+#else
19614+ lea init_tss(%rip), %r12
19615+#endif
19616 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19617 call \do_sym
19618 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19619 jmp paranoid_exit /* %ebx: no swapgs flag */
19620 CFI_ENDPROC
19621-END(\sym)
19622+ENDPROC(\sym)
19623 .endm
19624
19625 .macro errorentry sym do_sym
19626@@ -1267,13 +1617,23 @@ ENTRY(\sym)
19627 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19628 call error_entry
19629 DEFAULT_FRAME 0
19630+#ifdef CONFIG_PAX_MEMORY_UDEREF
19631+ testb $3, CS(%rsp)
19632+ jnz 1f
19633+ pax_enter_kernel
19634+ jmp 2f
19635+1: pax_enter_kernel_user
19636+2:
19637+#else
19638+ pax_enter_kernel
19639+#endif
19640 movq %rsp,%rdi /* pt_regs pointer */
19641 movq ORIG_RAX(%rsp),%rsi /* get error code */
19642 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19643 call \do_sym
19644 jmp error_exit /* %ebx: no swapgs flag */
19645 CFI_ENDPROC
19646-END(\sym)
19647+ENDPROC(\sym)
19648 .endm
19649
19650 /* error code is on the stack already */
19651@@ -1287,13 +1647,23 @@ ENTRY(\sym)
19652 call save_paranoid
19653 DEFAULT_FRAME 0
19654 TRACE_IRQS_OFF
19655+#ifdef CONFIG_PAX_MEMORY_UDEREF
19656+ testb $3, CS(%rsp)
19657+ jnz 1f
19658+ pax_enter_kernel
19659+ jmp 2f
19660+1: pax_enter_kernel_user
19661+2:
19662+#else
19663+ pax_enter_kernel
19664+#endif
19665 movq %rsp,%rdi /* pt_regs pointer */
19666 movq ORIG_RAX(%rsp),%rsi /* get error code */
19667 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19668 call \do_sym
19669 jmp paranoid_exit /* %ebx: no swapgs flag */
19670 CFI_ENDPROC
19671-END(\sym)
19672+ENDPROC(\sym)
19673 .endm
19674
19675 zeroentry divide_error do_divide_error
19676@@ -1323,9 +1693,10 @@ gs_change:
19677 2: mfence /* workaround */
19678 SWAPGS
19679 popfq_cfi
19680+ pax_force_retaddr
19681 ret
19682 CFI_ENDPROC
19683-END(native_load_gs_index)
19684+ENDPROC(native_load_gs_index)
19685
19686 _ASM_EXTABLE(gs_change,bad_gs)
19687 .section .fixup,"ax"
19688@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19689 CFI_DEF_CFA_REGISTER rsp
19690 CFI_ADJUST_CFA_OFFSET -8
19691 decl PER_CPU_VAR(irq_count)
19692+ pax_force_retaddr
19693 ret
19694 CFI_ENDPROC
19695-END(call_softirq)
19696+ENDPROC(call_softirq)
19697
19698 #ifdef CONFIG_XEN
19699 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19700@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19701 decl PER_CPU_VAR(irq_count)
19702 jmp error_exit
19703 CFI_ENDPROC
19704-END(xen_do_hypervisor_callback)
19705+ENDPROC(xen_do_hypervisor_callback)
19706
19707 /*
19708 * Hypervisor uses this for application faults while it executes.
19709@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19710 SAVE_ALL
19711 jmp error_exit
19712 CFI_ENDPROC
19713-END(xen_failsafe_callback)
19714+ENDPROC(xen_failsafe_callback)
19715
19716 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19717 xen_hvm_callback_vector xen_evtchn_do_upcall
19718@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19719 TRACE_IRQS_OFF_DEBUG
19720 testl %ebx,%ebx /* swapgs needed? */
19721 jnz paranoid_restore
19722- testl $3,CS(%rsp)
19723+ testb $3,CS(%rsp)
19724 jnz paranoid_userspace
19725+#ifdef CONFIG_PAX_MEMORY_UDEREF
19726+ pax_exit_kernel
19727+ TRACE_IRQS_IRETQ 0
19728+ SWAPGS_UNSAFE_STACK
19729+ RESTORE_ALL 8
19730+ pax_force_retaddr_bts
19731+ jmp irq_return
19732+#endif
19733 paranoid_swapgs:
19734+#ifdef CONFIG_PAX_MEMORY_UDEREF
19735+ pax_exit_kernel_user
19736+#else
19737+ pax_exit_kernel
19738+#endif
19739 TRACE_IRQS_IRETQ 0
19740 SWAPGS_UNSAFE_STACK
19741 RESTORE_ALL 8
19742 jmp irq_return
19743 paranoid_restore:
19744+ pax_exit_kernel
19745 TRACE_IRQS_IRETQ_DEBUG 0
19746 RESTORE_ALL 8
19747+ pax_force_retaddr_bts
19748 jmp irq_return
19749 paranoid_userspace:
19750 GET_THREAD_INFO(%rcx)
19751@@ -1539,7 +1926,7 @@ paranoid_schedule:
19752 TRACE_IRQS_OFF
19753 jmp paranoid_userspace
19754 CFI_ENDPROC
19755-END(paranoid_exit)
19756+ENDPROC(paranoid_exit)
19757
19758 /*
19759 * Exception entry point. This expects an error code/orig_rax on the stack.
19760@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19761 movq_cfi r14, R14+8
19762 movq_cfi r15, R15+8
19763 xorl %ebx,%ebx
19764- testl $3,CS+8(%rsp)
19765+ testb $3,CS+8(%rsp)
19766 je error_kernelspace
19767 error_swapgs:
19768 SWAPGS
19769 error_sti:
19770 TRACE_IRQS_OFF
19771+ pax_force_retaddr_bts
19772 ret
19773
19774 /*
19775@@ -1598,7 +1986,7 @@ bstep_iret:
19776 movq %rcx,RIP+8(%rsp)
19777 jmp error_swapgs
19778 CFI_ENDPROC
19779-END(error_entry)
19780+ENDPROC(error_entry)
19781
19782
19783 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19784@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19785 jnz retint_careful
19786 jmp retint_swapgs
19787 CFI_ENDPROC
19788-END(error_exit)
19789+ENDPROC(error_exit)
19790
19791 /*
19792 * Test if a given stack is an NMI stack or not.
19793@@ -1676,9 +2064,11 @@ ENTRY(nmi)
19794 * If %cs was not the kernel segment, then the NMI triggered in user
19795 * space, which means it is definitely not nested.
19796 */
19797+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19798+ je 1f
19799 cmpl $__KERNEL_CS, 16(%rsp)
19800 jne first_nmi
19801-
19802+1:
19803 /*
19804 * Check the special variable on the stack to see if NMIs are
19805 * executing.
19806@@ -1847,6 +2237,17 @@ end_repeat_nmi:
19807 */
19808 movq %cr2, %r12
19809
19810+#ifdef CONFIG_PAX_MEMORY_UDEREF
19811+ testb $3, CS(%rsp)
19812+ jnz 1f
19813+ pax_enter_kernel
19814+ jmp 2f
19815+1: pax_enter_kernel_user
19816+2:
19817+#else
19818+ pax_enter_kernel
19819+#endif
19820+
19821 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19822 movq %rsp,%rdi
19823 movq $-1,%rsi
19824@@ -1862,23 +2263,34 @@ end_repeat_nmi:
19825 testl %ebx,%ebx /* swapgs needed? */
19826 jnz nmi_restore
19827 nmi_swapgs:
19828+#ifdef CONFIG_PAX_MEMORY_UDEREF
19829+ pax_exit_kernel_user
19830+#else
19831+ pax_exit_kernel
19832+#endif
19833 SWAPGS_UNSAFE_STACK
19834+ RESTORE_ALL 6*8
19835+ /* Clear the NMI executing stack variable */
19836+ movq $0, 5*8(%rsp)
19837+ jmp irq_return
19838 nmi_restore:
19839+ pax_exit_kernel
19840 /* Pop the extra iret frame at once */
19841 RESTORE_ALL 6*8
19842+ pax_force_retaddr_bts
19843
19844 /* Clear the NMI executing stack variable */
19845 movq $0, 5*8(%rsp)
19846 jmp irq_return
19847 CFI_ENDPROC
19848-END(nmi)
19849+ENDPROC(nmi)
19850
19851 ENTRY(ignore_sysret)
19852 CFI_STARTPROC
19853 mov $-ENOSYS,%eax
19854 sysret
19855 CFI_ENDPROC
19856-END(ignore_sysret)
19857+ENDPROC(ignore_sysret)
19858
19859 /*
19860 * End of kprobes section
19861diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19862index 1d41402..af9a46a 100644
19863--- a/arch/x86/kernel/ftrace.c
19864+++ b/arch/x86/kernel/ftrace.c
19865@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19866 {
19867 unsigned char replaced[MCOUNT_INSN_SIZE];
19868
19869+ ip = ktla_ktva(ip);
19870+
19871 /*
19872 * Note: Due to modules and __init, code can
19873 * disappear and change, we need to protect against faulting
19874@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19875 unsigned char old[MCOUNT_INSN_SIZE], *new;
19876 int ret;
19877
19878- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19879+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19880 new = ftrace_call_replace(ip, (unsigned long)func);
19881
19882 /* See comment above by declaration of modifying_ftrace_code */
19883@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19884 /* Also update the regs callback function */
19885 if (!ret) {
19886 ip = (unsigned long)(&ftrace_regs_call);
19887- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19888+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19889 new = ftrace_call_replace(ip, (unsigned long)func);
19890 ret = ftrace_modify_code(ip, old, new);
19891 }
19892@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19893 * kernel identity mapping to modify code.
19894 */
19895 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19896- ip = (unsigned long)__va(__pa(ip));
19897+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19898
19899 return probe_kernel_write((void *)ip, val, size);
19900 }
19901@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19902 unsigned char replaced[MCOUNT_INSN_SIZE];
19903 unsigned char brk = BREAKPOINT_INSTRUCTION;
19904
19905- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19906+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19907 return -EFAULT;
19908
19909 /* Make sure it is what we expect it to be */
19910@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19911 return ret;
19912
19913 fail_update:
19914- probe_kernel_write((void *)ip, &old_code[0], 1);
19915+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19916 goto out;
19917 }
19918
19919@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19920 {
19921 unsigned char code[MCOUNT_INSN_SIZE];
19922
19923+ ip = ktla_ktva(ip);
19924+
19925 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19926 return -EFAULT;
19927
19928diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19929index c18f59d..9c0c9f6 100644
19930--- a/arch/x86/kernel/head32.c
19931+++ b/arch/x86/kernel/head32.c
19932@@ -18,6 +18,7 @@
19933 #include <asm/io_apic.h>
19934 #include <asm/bios_ebda.h>
19935 #include <asm/tlbflush.h>
19936+#include <asm/boot.h>
19937
19938 static void __init i386_default_early_setup(void)
19939 {
19940@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19941
19942 void __init i386_start_kernel(void)
19943 {
19944- memblock_reserve(__pa_symbol(&_text),
19945- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19946+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19947
19948 #ifdef CONFIG_BLK_DEV_INITRD
19949 /* Reserve INITRD */
19950diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19951index c8932c7..d56b622 100644
19952--- a/arch/x86/kernel/head_32.S
19953+++ b/arch/x86/kernel/head_32.S
19954@@ -26,6 +26,12 @@
19955 /* Physical address */
19956 #define pa(X) ((X) - __PAGE_OFFSET)
19957
19958+#ifdef CONFIG_PAX_KERNEXEC
19959+#define ta(X) (X)
19960+#else
19961+#define ta(X) ((X) - __PAGE_OFFSET)
19962+#endif
19963+
19964 /*
19965 * References to members of the new_cpu_data structure.
19966 */
19967@@ -55,11 +61,7 @@
19968 * and small than max_low_pfn, otherwise will waste some page table entries
19969 */
19970
19971-#if PTRS_PER_PMD > 1
19972-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19973-#else
19974-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19975-#endif
19976+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19977
19978 /* Number of possible pages in the lowmem region */
19979 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19980@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19981 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19982
19983 /*
19984+ * Real beginning of normal "text" segment
19985+ */
19986+ENTRY(stext)
19987+ENTRY(_stext)
19988+
19989+/*
19990 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19991 * %esi points to the real-mode code as a 32-bit pointer.
19992 * CS and DS must be 4 GB flat segments, but we don't depend on
19993@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19994 * can.
19995 */
19996 __HEAD
19997+
19998+#ifdef CONFIG_PAX_KERNEXEC
19999+ jmp startup_32
20000+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20001+.fill PAGE_SIZE-5,1,0xcc
20002+#endif
20003+
20004 ENTRY(startup_32)
20005 movl pa(stack_start),%ecx
20006
20007@@ -106,6 +121,59 @@ ENTRY(startup_32)
20008 2:
20009 leal -__PAGE_OFFSET(%ecx),%esp
20010
20011+#ifdef CONFIG_SMP
20012+ movl $pa(cpu_gdt_table),%edi
20013+ movl $__per_cpu_load,%eax
20014+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20015+ rorl $16,%eax
20016+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20017+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20018+ movl $__per_cpu_end - 1,%eax
20019+ subl $__per_cpu_start,%eax
20020+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20021+#endif
20022+
20023+#ifdef CONFIG_PAX_MEMORY_UDEREF
20024+ movl $NR_CPUS,%ecx
20025+ movl $pa(cpu_gdt_table),%edi
20026+1:
20027+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20028+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20029+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20030+ addl $PAGE_SIZE_asm,%edi
20031+ loop 1b
20032+#endif
20033+
20034+#ifdef CONFIG_PAX_KERNEXEC
20035+ movl $pa(boot_gdt),%edi
20036+ movl $__LOAD_PHYSICAL_ADDR,%eax
20037+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20038+ rorl $16,%eax
20039+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20040+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20041+ rorl $16,%eax
20042+
20043+ ljmp $(__BOOT_CS),$1f
20044+1:
20045+
20046+ movl $NR_CPUS,%ecx
20047+ movl $pa(cpu_gdt_table),%edi
20048+ addl $__PAGE_OFFSET,%eax
20049+1:
20050+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20051+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20052+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20053+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20054+ rorl $16,%eax
20055+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20056+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20057+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20058+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20059+ rorl $16,%eax
20060+ addl $PAGE_SIZE_asm,%edi
20061+ loop 1b
20062+#endif
20063+
20064 /*
20065 * Clear BSS first so that there are no surprises...
20066 */
20067@@ -196,8 +264,11 @@ ENTRY(startup_32)
20068 movl %eax, pa(max_pfn_mapped)
20069
20070 /* Do early initialization of the fixmap area */
20071- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20072- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20073+#ifdef CONFIG_COMPAT_VDSO
20074+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20075+#else
20076+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20077+#endif
20078 #else /* Not PAE */
20079
20080 page_pde_offset = (__PAGE_OFFSET >> 20);
20081@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20082 movl %eax, pa(max_pfn_mapped)
20083
20084 /* Do early initialization of the fixmap area */
20085- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20086- movl %eax,pa(initial_page_table+0xffc)
20087+#ifdef CONFIG_COMPAT_VDSO
20088+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20089+#else
20090+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20091+#endif
20092 #endif
20093
20094 #ifdef CONFIG_PARAVIRT
20095@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20096 cmpl $num_subarch_entries, %eax
20097 jae bad_subarch
20098
20099- movl pa(subarch_entries)(,%eax,4), %eax
20100- subl $__PAGE_OFFSET, %eax
20101- jmp *%eax
20102+ jmp *pa(subarch_entries)(,%eax,4)
20103
20104 bad_subarch:
20105 WEAK(lguest_entry)
20106@@ -256,10 +328,10 @@ WEAK(xen_entry)
20107 __INITDATA
20108
20109 subarch_entries:
20110- .long default_entry /* normal x86/PC */
20111- .long lguest_entry /* lguest hypervisor */
20112- .long xen_entry /* Xen hypervisor */
20113- .long default_entry /* Moorestown MID */
20114+ .long ta(default_entry) /* normal x86/PC */
20115+ .long ta(lguest_entry) /* lguest hypervisor */
20116+ .long ta(xen_entry) /* Xen hypervisor */
20117+ .long ta(default_entry) /* Moorestown MID */
20118 num_subarch_entries = (. - subarch_entries) / 4
20119 .previous
20120 #else
20121@@ -335,6 +407,7 @@ default_entry:
20122 movl pa(mmu_cr4_features),%eax
20123 movl %eax,%cr4
20124
20125+#ifdef CONFIG_X86_PAE
20126 testb $X86_CR4_PAE, %al # check if PAE is enabled
20127 jz 6f
20128
20129@@ -363,6 +436,9 @@ default_entry:
20130 /* Make changes effective */
20131 wrmsr
20132
20133+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20134+#endif
20135+
20136 6:
20137
20138 /*
20139@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
20140 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20141 movl %eax,%ss # after changing gdt.
20142
20143- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20144+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20145 movl %eax,%ds
20146 movl %eax,%es
20147
20148 movl $(__KERNEL_PERCPU), %eax
20149 movl %eax,%fs # set this cpu's percpu
20150
20151+#ifdef CONFIG_CC_STACKPROTECTOR
20152 movl $(__KERNEL_STACK_CANARY),%eax
20153+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20154+ movl $(__USER_DS),%eax
20155+#else
20156+ xorl %eax,%eax
20157+#endif
20158 movl %eax,%gs
20159
20160 xorl %eax,%eax # Clear LDT
20161@@ -544,8 +626,11 @@ setup_once:
20162 * relocation. Manually set base address in stack canary
20163 * segment descriptor.
20164 */
20165- movl $gdt_page,%eax
20166+ movl $cpu_gdt_table,%eax
20167 movl $stack_canary,%ecx
20168+#ifdef CONFIG_SMP
20169+ addl $__per_cpu_load,%ecx
20170+#endif
20171 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20172 shrl $16, %ecx
20173 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20174@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
20175 /* This is global to keep gas from relaxing the jumps */
20176 ENTRY(early_idt_handler)
20177 cld
20178- cmpl $2,%ss:early_recursion_flag
20179+ cmpl $1,%ss:early_recursion_flag
20180 je hlt_loop
20181 incl %ss:early_recursion_flag
20182
20183@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
20184 pushl (20+6*4)(%esp) /* trapno */
20185 pushl $fault_msg
20186 call printk
20187-#endif
20188 call dump_stack
20189+#endif
20190 hlt_loop:
20191 hlt
20192 jmp hlt_loop
20193@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
20194 /* This is the default interrupt "handler" :-) */
20195 ALIGN
20196 ignore_int:
20197- cld
20198 #ifdef CONFIG_PRINTK
20199+ cmpl $2,%ss:early_recursion_flag
20200+ je hlt_loop
20201+ incl %ss:early_recursion_flag
20202+ cld
20203 pushl %eax
20204 pushl %ecx
20205 pushl %edx
20206@@ -644,9 +732,6 @@ ignore_int:
20207 movl $(__KERNEL_DS),%eax
20208 movl %eax,%ds
20209 movl %eax,%es
20210- cmpl $2,early_recursion_flag
20211- je hlt_loop
20212- incl early_recursion_flag
20213 pushl 16(%esp)
20214 pushl 24(%esp)
20215 pushl 32(%esp)
20216@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
20217 /*
20218 * BSS section
20219 */
20220-__PAGE_ALIGNED_BSS
20221- .align PAGE_SIZE
20222 #ifdef CONFIG_X86_PAE
20223+.section .initial_pg_pmd,"a",@progbits
20224 initial_pg_pmd:
20225 .fill 1024*KPMDS,4,0
20226 #else
20227+.section .initial_page_table,"a",@progbits
20228 ENTRY(initial_page_table)
20229 .fill 1024,4,0
20230 #endif
20231+.section .initial_pg_fixmap,"a",@progbits
20232 initial_pg_fixmap:
20233 .fill 1024,4,0
20234+.section .empty_zero_page,"a",@progbits
20235 ENTRY(empty_zero_page)
20236 .fill 4096,1,0
20237+.section .swapper_pg_dir,"a",@progbits
20238 ENTRY(swapper_pg_dir)
20239+#ifdef CONFIG_X86_PAE
20240+ .fill 4,8,0
20241+#else
20242 .fill 1024,4,0
20243+#endif
20244+
20245+/*
20246+ * The IDT has to be page-aligned to simplify the Pentium
20247+ * F0 0F bug workaround.. We have a special link segment
20248+ * for this.
20249+ */
20250+.section .idt,"a",@progbits
20251+ENTRY(idt_table)
20252+ .fill 256,8,0
20253
20254 /*
20255 * This starts the data section.
20256 */
20257 #ifdef CONFIG_X86_PAE
20258-__PAGE_ALIGNED_DATA
20259- /* Page-aligned for the benefit of paravirt? */
20260- .align PAGE_SIZE
20261+.section .initial_page_table,"a",@progbits
20262 ENTRY(initial_page_table)
20263 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20264 # if KPMDS == 3
20265@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
20266 # error "Kernel PMDs should be 1, 2 or 3"
20267 # endif
20268 .align PAGE_SIZE /* needs to be page-sized too */
20269+
20270+#ifdef CONFIG_PAX_PER_CPU_PGD
20271+ENTRY(cpu_pgd)
20272+ .rept NR_CPUS
20273+ .fill 4,8,0
20274+ .endr
20275+#endif
20276+
20277 #endif
20278
20279 .data
20280 .balign 4
20281 ENTRY(stack_start)
20282- .long init_thread_union+THREAD_SIZE
20283+ .long init_thread_union+THREAD_SIZE-8
20284
20285 __INITRODATA
20286 int_msg:
20287@@ -754,7 +861,7 @@ fault_msg:
20288 * segment size, and 32-bit linear address value:
20289 */
20290
20291- .data
20292+.section .rodata,"a",@progbits
20293 .globl boot_gdt_descr
20294 .globl idt_descr
20295
20296@@ -763,7 +870,7 @@ fault_msg:
20297 .word 0 # 32 bit align gdt_desc.address
20298 boot_gdt_descr:
20299 .word __BOOT_DS+7
20300- .long boot_gdt - __PAGE_OFFSET
20301+ .long pa(boot_gdt)
20302
20303 .word 0 # 32-bit align idt_desc.address
20304 idt_descr:
20305@@ -774,7 +881,7 @@ idt_descr:
20306 .word 0 # 32 bit align gdt_desc.address
20307 ENTRY(early_gdt_descr)
20308 .word GDT_ENTRIES*8-1
20309- .long gdt_page /* Overwritten for secondary CPUs */
20310+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20311
20312 /*
20313 * The boot_gdt must mirror the equivalent in setup.S and is
20314@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
20315 .align L1_CACHE_BYTES
20316 ENTRY(boot_gdt)
20317 .fill GDT_ENTRY_BOOT_CS,8,0
20318- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20319- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20320+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20321+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20322+
20323+ .align PAGE_SIZE_asm
20324+ENTRY(cpu_gdt_table)
20325+ .rept NR_CPUS
20326+ .quad 0x0000000000000000 /* NULL descriptor */
20327+ .quad 0x0000000000000000 /* 0x0b reserved */
20328+ .quad 0x0000000000000000 /* 0x13 reserved */
20329+ .quad 0x0000000000000000 /* 0x1b reserved */
20330+
20331+#ifdef CONFIG_PAX_KERNEXEC
20332+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20333+#else
20334+ .quad 0x0000000000000000 /* 0x20 unused */
20335+#endif
20336+
20337+ .quad 0x0000000000000000 /* 0x28 unused */
20338+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20339+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20340+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20341+ .quad 0x0000000000000000 /* 0x4b reserved */
20342+ .quad 0x0000000000000000 /* 0x53 reserved */
20343+ .quad 0x0000000000000000 /* 0x5b reserved */
20344+
20345+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20346+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20347+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20348+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20349+
20350+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20351+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20352+
20353+ /*
20354+ * Segments used for calling PnP BIOS have byte granularity.
20355+ * The code segments and data segments have fixed 64k limits,
20356+ * the transfer segment sizes are set at run time.
20357+ */
20358+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20359+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20360+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20361+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20362+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20363+
20364+ /*
20365+ * The APM segments have byte granularity and their bases
20366+ * are set at run time. All have 64k limits.
20367+ */
20368+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20369+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20370+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20371+
20372+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20373+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20374+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20375+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20376+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20377+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20378+
20379+ /* Be sure this is zeroed to avoid false validations in Xen */
20380+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20381+ .endr
20382diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20383index 980053c..74d3b44 100644
20384--- a/arch/x86/kernel/head_64.S
20385+++ b/arch/x86/kernel/head_64.S
20386@@ -20,6 +20,8 @@
20387 #include <asm/processor-flags.h>
20388 #include <asm/percpu.h>
20389 #include <asm/nops.h>
20390+#include <asm/cpufeature.h>
20391+#include <asm/alternative-asm.h>
20392
20393 #ifdef CONFIG_PARAVIRT
20394 #include <asm/asm-offsets.h>
20395@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20396 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20397 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20398 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20399+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20400+L3_VMALLOC_START = pud_index(VMALLOC_START)
20401+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20402+L3_VMALLOC_END = pud_index(VMALLOC_END)
20403+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20404+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20405
20406 .text
20407 __HEAD
20408@@ -88,35 +96,23 @@ startup_64:
20409 */
20410 addq %rbp, init_level4_pgt + 0(%rip)
20411 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20412+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20413+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20414+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20415 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20416
20417 addq %rbp, level3_ident_pgt + 0(%rip)
20418+#ifndef CONFIG_XEN
20419+ addq %rbp, level3_ident_pgt + 8(%rip)
20420+#endif
20421
20422- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20423- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20424+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20425+
20426+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20427+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20428
20429 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20430-
20431- /* Add an Identity mapping if I am above 1G */
20432- leaq _text(%rip), %rdi
20433- andq $PMD_PAGE_MASK, %rdi
20434-
20435- movq %rdi, %rax
20436- shrq $PUD_SHIFT, %rax
20437- andq $(PTRS_PER_PUD - 1), %rax
20438- jz ident_complete
20439-
20440- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20441- leaq level3_ident_pgt(%rip), %rbx
20442- movq %rdx, 0(%rbx, %rax, 8)
20443-
20444- movq %rdi, %rax
20445- shrq $PMD_SHIFT, %rax
20446- andq $(PTRS_PER_PMD - 1), %rax
20447- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20448- leaq level2_spare_pgt(%rip), %rbx
20449- movq %rdx, 0(%rbx, %rax, 8)
20450-ident_complete:
20451+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20452
20453 /*
20454 * Fixup the kernel text+data virtual addresses. Note that
20455@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20456 * after the boot processor executes this code.
20457 */
20458
20459- /* Enable PAE mode and PGE */
20460- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20461+ /* Enable PAE mode and PSE/PGE */
20462+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20463 movq %rax, %cr4
20464
20465 /* Setup early boot stage 4 level pagetables. */
20466@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20467 movl $MSR_EFER, %ecx
20468 rdmsr
20469 btsl $_EFER_SCE, %eax /* Enable System Call */
20470- btl $20,%edi /* No Execute supported? */
20471+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20472 jnc 1f
20473 btsl $_EFER_NX, %eax
20474+ leaq init_level4_pgt(%rip), %rdi
20475+#ifndef CONFIG_EFI
20476+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20477+#endif
20478+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20479+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20480+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20481+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20482 1: wrmsr /* Make changes effective */
20483
20484 /* Setup cr0 */
20485@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20486 * jump. In addition we need to ensure %cs is set so we make this
20487 * a far return.
20488 */
20489+ pax_set_fptr_mask
20490 movq initial_code(%rip),%rax
20491 pushq $0 # fake return address to stop unwinder
20492 pushq $__KERNEL_CS # set correct cs
20493@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20494 bad_address:
20495 jmp bad_address
20496
20497- .section ".init.text","ax"
20498+ __INIT
20499 .globl early_idt_handlers
20500 early_idt_handlers:
20501 # 104(%rsp) %rflags
20502@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20503 call dump_stack
20504 #ifdef CONFIG_KALLSYMS
20505 leaq early_idt_ripmsg(%rip),%rdi
20506- movq 40(%rsp),%rsi # %rip again
20507+ movq 88(%rsp),%rsi # %rip again
20508 call __print_symbol
20509 #endif
20510 #endif /* EARLY_PRINTK */
20511@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20512 addq $16,%rsp # drop vector number and error code
20513 decl early_recursion_flag(%rip)
20514 INTERRUPT_RETURN
20515+ .previous
20516
20517+ __INITDATA
20518 .balign 4
20519 early_recursion_flag:
20520 .long 0
20521+ .previous
20522
20523+ .section .rodata,"a",@progbits
20524 #ifdef CONFIG_EARLY_PRINTK
20525 early_idt_msg:
20526 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20527@@ -376,6 +385,7 @@ early_idt_ripmsg:
20528 #endif /* CONFIG_EARLY_PRINTK */
20529 .previous
20530
20531+ .section .rodata,"a",@progbits
20532 #define NEXT_PAGE(name) \
20533 .balign PAGE_SIZE; \
20534 ENTRY(name)
20535@@ -388,7 +398,6 @@ ENTRY(name)
20536 i = i + 1 ; \
20537 .endr
20538
20539- .data
20540 /*
20541 * This default setting generates an ident mapping at address 0x100000
20542 * and a mapping for the kernel that precisely maps virtual address
20543@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20544 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20545 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20546 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20547+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20548+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20549+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20550+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20551+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20552+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20553 .org init_level4_pgt + L4_START_KERNEL*8, 0
20554 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20555 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20556
20557+#ifdef CONFIG_PAX_PER_CPU_PGD
20558+NEXT_PAGE(cpu_pgd)
20559+ .rept NR_CPUS
20560+ .fill 512,8,0
20561+ .endr
20562+#endif
20563+
20564 NEXT_PAGE(level3_ident_pgt)
20565 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20566+#ifdef CONFIG_XEN
20567 .fill 511,8,0
20568+#else
20569+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20570+ .fill 510,8,0
20571+#endif
20572+
20573+NEXT_PAGE(level3_vmalloc_start_pgt)
20574+ .fill 512,8,0
20575+
20576+NEXT_PAGE(level3_vmalloc_end_pgt)
20577+ .fill 512,8,0
20578+
20579+NEXT_PAGE(level3_vmemmap_pgt)
20580+ .fill L3_VMEMMAP_START,8,0
20581+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20582
20583 NEXT_PAGE(level3_kernel_pgt)
20584 .fill L3_START_KERNEL,8,0
20585@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20586 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20587 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20588
20589+NEXT_PAGE(level2_vmemmap_pgt)
20590+ .fill 512,8,0
20591+
20592 NEXT_PAGE(level2_fixmap_pgt)
20593- .fill 506,8,0
20594- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20595- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20596- .fill 5,8,0
20597+ .fill 507,8,0
20598+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20599+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20600+ .fill 4,8,0
20601
20602-NEXT_PAGE(level1_fixmap_pgt)
20603+NEXT_PAGE(level1_vsyscall_pgt)
20604 .fill 512,8,0
20605
20606-NEXT_PAGE(level2_ident_pgt)
20607- /* Since I easily can, map the first 1G.
20608+ /* Since I easily can, map the first 2G.
20609 * Don't set NX because code runs from these pages.
20610 */
20611- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20612+NEXT_PAGE(level2_ident_pgt)
20613+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20614
20615 NEXT_PAGE(level2_kernel_pgt)
20616 /*
20617@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20618 * If you want to increase this then increase MODULES_VADDR
20619 * too.)
20620 */
20621- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20622- KERNEL_IMAGE_SIZE/PMD_SIZE)
20623-
20624-NEXT_PAGE(level2_spare_pgt)
20625- .fill 512, 8, 0
20626+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20627
20628 #undef PMDS
20629 #undef NEXT_PAGE
20630
20631- .data
20632+ .align PAGE_SIZE
20633+ENTRY(cpu_gdt_table)
20634+ .rept NR_CPUS
20635+ .quad 0x0000000000000000 /* NULL descriptor */
20636+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20637+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20638+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20639+ .quad 0x00cffb000000ffff /* __USER32_CS */
20640+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20641+ .quad 0x00affb000000ffff /* __USER_CS */
20642+
20643+#ifdef CONFIG_PAX_KERNEXEC
20644+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20645+#else
20646+ .quad 0x0 /* unused */
20647+#endif
20648+
20649+ .quad 0,0 /* TSS */
20650+ .quad 0,0 /* LDT */
20651+ .quad 0,0,0 /* three TLS descriptors */
20652+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20653+ /* asm/segment.h:GDT_ENTRIES must match this */
20654+
20655+ /* zero the remaining page */
20656+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20657+ .endr
20658+
20659 .align 16
20660 .globl early_gdt_descr
20661 early_gdt_descr:
20662 .word GDT_ENTRIES*8-1
20663 early_gdt_descr_base:
20664- .quad INIT_PER_CPU_VAR(gdt_page)
20665+ .quad cpu_gdt_table
20666
20667 ENTRY(phys_base)
20668 /* This must match the first entry in level2_kernel_pgt */
20669 .quad 0x0000000000000000
20670
20671 #include "../../x86/xen/xen-head.S"
20672-
20673- .section .bss, "aw", @nobits
20674+
20675+ .section .rodata,"a",@progbits
20676 .align L1_CACHE_BYTES
20677 ENTRY(idt_table)
20678- .skip IDT_ENTRIES * 16
20679+ .fill 512,8,0
20680
20681 .align L1_CACHE_BYTES
20682 ENTRY(nmi_idt_table)
20683- .skip IDT_ENTRIES * 16
20684+ .fill 512,8,0
20685
20686 __PAGE_ALIGNED_BSS
20687 .align PAGE_SIZE
20688diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20689index 9c3bd4a..e1d9b35 100644
20690--- a/arch/x86/kernel/i386_ksyms_32.c
20691+++ b/arch/x86/kernel/i386_ksyms_32.c
20692@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20693 EXPORT_SYMBOL(cmpxchg8b_emu);
20694 #endif
20695
20696+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20697+
20698 /* Networking helper routines. */
20699 EXPORT_SYMBOL(csum_partial_copy_generic);
20700+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20701+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20702
20703 EXPORT_SYMBOL(__get_user_1);
20704 EXPORT_SYMBOL(__get_user_2);
20705@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20706
20707 EXPORT_SYMBOL(csum_partial);
20708 EXPORT_SYMBOL(empty_zero_page);
20709+
20710+#ifdef CONFIG_PAX_KERNEXEC
20711+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20712+#endif
20713diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20714index 245a71d..89d9ce4 100644
20715--- a/arch/x86/kernel/i387.c
20716+++ b/arch/x86/kernel/i387.c
20717@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20718 static inline bool interrupted_user_mode(void)
20719 {
20720 struct pt_regs *regs = get_irq_regs();
20721- return regs && user_mode_vm(regs);
20722+ return regs && user_mode(regs);
20723 }
20724
20725 /*
20726diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20727index 9a5c460..b332a4b 100644
20728--- a/arch/x86/kernel/i8259.c
20729+++ b/arch/x86/kernel/i8259.c
20730@@ -209,7 +209,7 @@ spurious_8259A_irq:
20731 "spurious 8259A interrupt: IRQ%d.\n", irq);
20732 spurious_irq_mask |= irqmask;
20733 }
20734- atomic_inc(&irq_err_count);
20735+ atomic_inc_unchecked(&irq_err_count);
20736 /*
20737 * Theoretically we do not have to handle this IRQ,
20738 * but in Linux this does not cause problems and is
20739@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20740 /* (slave's support for AEOI in flat mode is to be investigated) */
20741 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20742
20743+ pax_open_kernel();
20744 if (auto_eoi)
20745 /*
20746 * In AEOI mode we just have to mask the interrupt
20747 * when acking.
20748 */
20749- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20750+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20751 else
20752- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20753+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20754+ pax_close_kernel();
20755
20756 udelay(100); /* wait for 8259A to initialize */
20757
20758diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20759index a979b5b..1d6db75 100644
20760--- a/arch/x86/kernel/io_delay.c
20761+++ b/arch/x86/kernel/io_delay.c
20762@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20763 * Quirk table for systems that misbehave (lock up, etc.) if port
20764 * 0x80 is used:
20765 */
20766-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20767+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20768 {
20769 .callback = dmi_io_delay_0xed_port,
20770 .ident = "Compaq Presario V6000",
20771diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20772index 8c96897..be66bfa 100644
20773--- a/arch/x86/kernel/ioport.c
20774+++ b/arch/x86/kernel/ioport.c
20775@@ -6,6 +6,7 @@
20776 #include <linux/sched.h>
20777 #include <linux/kernel.h>
20778 #include <linux/capability.h>
20779+#include <linux/security.h>
20780 #include <linux/errno.h>
20781 #include <linux/types.h>
20782 #include <linux/ioport.h>
20783@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20784
20785 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20786 return -EINVAL;
20787+#ifdef CONFIG_GRKERNSEC_IO
20788+ if (turn_on && grsec_disable_privio) {
20789+ gr_handle_ioperm();
20790+ return -EPERM;
20791+ }
20792+#endif
20793 if (turn_on && !capable(CAP_SYS_RAWIO))
20794 return -EPERM;
20795
20796@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20797 * because the ->io_bitmap_max value must match the bitmap
20798 * contents:
20799 */
20800- tss = &per_cpu(init_tss, get_cpu());
20801+ tss = init_tss + get_cpu();
20802
20803 if (turn_on)
20804 bitmap_clear(t->io_bitmap_ptr, from, num);
20805@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20806 return -EINVAL;
20807 /* Trying to gain more privileges? */
20808 if (level > old) {
20809+#ifdef CONFIG_GRKERNSEC_IO
20810+ if (grsec_disable_privio) {
20811+ gr_handle_iopl();
20812+ return -EPERM;
20813+ }
20814+#endif
20815 if (!capable(CAP_SYS_RAWIO))
20816 return -EPERM;
20817 }
20818diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20819index e4595f1..ee3bfb8 100644
20820--- a/arch/x86/kernel/irq.c
20821+++ b/arch/x86/kernel/irq.c
20822@@ -18,7 +18,7 @@
20823 #include <asm/mce.h>
20824 #include <asm/hw_irq.h>
20825
20826-atomic_t irq_err_count;
20827+atomic_unchecked_t irq_err_count;
20828
20829 /* Function pointer for generic interrupt vector handling */
20830 void (*x86_platform_ipi_callback)(void) = NULL;
20831@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20832 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20833 seq_printf(p, " Machine check polls\n");
20834 #endif
20835- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20836+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20837 #if defined(CONFIG_X86_IO_APIC)
20838- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20839+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20840 #endif
20841 return 0;
20842 }
20843@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20844
20845 u64 arch_irq_stat(void)
20846 {
20847- u64 sum = atomic_read(&irq_err_count);
20848+ u64 sum = atomic_read_unchecked(&irq_err_count);
20849
20850 #ifdef CONFIG_X86_IO_APIC
20851- sum += atomic_read(&irq_mis_count);
20852+ sum += atomic_read_unchecked(&irq_mis_count);
20853 #endif
20854 return sum;
20855 }
20856diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20857index 344faf8..355f60d 100644
20858--- a/arch/x86/kernel/irq_32.c
20859+++ b/arch/x86/kernel/irq_32.c
20860@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20861 __asm__ __volatile__("andl %%esp,%0" :
20862 "=r" (sp) : "0" (THREAD_SIZE - 1));
20863
20864- return sp < (sizeof(struct thread_info) + STACK_WARN);
20865+ return sp < STACK_WARN;
20866 }
20867
20868 static void print_stack_overflow(void)
20869@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20870 * per-CPU IRQ handling contexts (thread information and stack)
20871 */
20872 union irq_ctx {
20873- struct thread_info tinfo;
20874- u32 stack[THREAD_SIZE/sizeof(u32)];
20875+ unsigned long previous_esp;
20876+ u32 stack[THREAD_SIZE/sizeof(u32)];
20877 } __attribute__((aligned(THREAD_SIZE)));
20878
20879 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20880@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20881 static inline int
20882 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20883 {
20884- union irq_ctx *curctx, *irqctx;
20885+ union irq_ctx *irqctx;
20886 u32 *isp, arg1, arg2;
20887
20888- curctx = (union irq_ctx *) current_thread_info();
20889 irqctx = __this_cpu_read(hardirq_ctx);
20890
20891 /*
20892@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20893 * handler) we can't do that and just have to keep using the
20894 * current stack (which is the irq stack already after all)
20895 */
20896- if (unlikely(curctx == irqctx))
20897+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20898 return 0;
20899
20900 /* build the stack frame on the IRQ stack */
20901- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20902- irqctx->tinfo.task = curctx->tinfo.task;
20903- irqctx->tinfo.previous_esp = current_stack_pointer;
20904+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20905+ irqctx->previous_esp = current_stack_pointer;
20906
20907- /* Copy the preempt_count so that the [soft]irq checks work. */
20908- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20909+#ifdef CONFIG_PAX_MEMORY_UDEREF
20910+ __set_fs(MAKE_MM_SEG(0));
20911+#endif
20912
20913 if (unlikely(overflow))
20914 call_on_stack(print_stack_overflow, isp);
20915@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20916 : "0" (irq), "1" (desc), "2" (isp),
20917 "D" (desc->handle_irq)
20918 : "memory", "cc", "ecx");
20919+
20920+#ifdef CONFIG_PAX_MEMORY_UDEREF
20921+ __set_fs(current_thread_info()->addr_limit);
20922+#endif
20923+
20924 return 1;
20925 }
20926
20927@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20928 */
20929 void __cpuinit irq_ctx_init(int cpu)
20930 {
20931- union irq_ctx *irqctx;
20932-
20933 if (per_cpu(hardirq_ctx, cpu))
20934 return;
20935
20936- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20937- THREADINFO_GFP,
20938- THREAD_SIZE_ORDER));
20939- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20940- irqctx->tinfo.cpu = cpu;
20941- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20942- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20943-
20944- per_cpu(hardirq_ctx, cpu) = irqctx;
20945-
20946- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20947- THREADINFO_GFP,
20948- THREAD_SIZE_ORDER));
20949- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20950- irqctx->tinfo.cpu = cpu;
20951- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20952-
20953- per_cpu(softirq_ctx, cpu) = irqctx;
20954+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20955+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20956+
20957+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20958+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20959
20960 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20961 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20962@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20963 asmlinkage void do_softirq(void)
20964 {
20965 unsigned long flags;
20966- struct thread_info *curctx;
20967 union irq_ctx *irqctx;
20968 u32 *isp;
20969
20970@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20971 local_irq_save(flags);
20972
20973 if (local_softirq_pending()) {
20974- curctx = current_thread_info();
20975 irqctx = __this_cpu_read(softirq_ctx);
20976- irqctx->tinfo.task = curctx->task;
20977- irqctx->tinfo.previous_esp = current_stack_pointer;
20978+ irqctx->previous_esp = current_stack_pointer;
20979
20980 /* build the stack frame on the softirq stack */
20981- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20982+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20983+
20984+#ifdef CONFIG_PAX_MEMORY_UDEREF
20985+ __set_fs(MAKE_MM_SEG(0));
20986+#endif
20987
20988 call_on_stack(__do_softirq, isp);
20989+
20990+#ifdef CONFIG_PAX_MEMORY_UDEREF
20991+ __set_fs(current_thread_info()->addr_limit);
20992+#endif
20993+
20994 /*
20995 * Shouldn't happen, we returned above if in_interrupt():
20996 */
20997@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20998 if (unlikely(!desc))
20999 return false;
21000
21001- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21002+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21003 if (unlikely(overflow))
21004 print_stack_overflow();
21005 desc->handle_irq(irq, desc);
21006diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21007index d04d3ec..ea4b374 100644
21008--- a/arch/x86/kernel/irq_64.c
21009+++ b/arch/x86/kernel/irq_64.c
21010@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21011 u64 estack_top, estack_bottom;
21012 u64 curbase = (u64)task_stack_page(current);
21013
21014- if (user_mode_vm(regs))
21015+ if (user_mode(regs))
21016 return;
21017
21018 if (regs->sp >= curbase + sizeof(struct thread_info) +
21019diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21020index dc1404b..bbc43e7 100644
21021--- a/arch/x86/kernel/kdebugfs.c
21022+++ b/arch/x86/kernel/kdebugfs.c
21023@@ -27,7 +27,7 @@ struct setup_data_node {
21024 u32 len;
21025 };
21026
21027-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21028+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21029 size_t count, loff_t *ppos)
21030 {
21031 struct setup_data_node *node = file->private_data;
21032diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21033index 836f832..a8bda67 100644
21034--- a/arch/x86/kernel/kgdb.c
21035+++ b/arch/x86/kernel/kgdb.c
21036@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21037 #ifdef CONFIG_X86_32
21038 switch (regno) {
21039 case GDB_SS:
21040- if (!user_mode_vm(regs))
21041+ if (!user_mode(regs))
21042 *(unsigned long *)mem = __KERNEL_DS;
21043 break;
21044 case GDB_SP:
21045- if (!user_mode_vm(regs))
21046+ if (!user_mode(regs))
21047 *(unsigned long *)mem = kernel_stack_pointer(regs);
21048 break;
21049 case GDB_GS:
21050@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21051 bp->attr.bp_addr = breakinfo[breakno].addr;
21052 bp->attr.bp_len = breakinfo[breakno].len;
21053 bp->attr.bp_type = breakinfo[breakno].type;
21054- info->address = breakinfo[breakno].addr;
21055+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21056+ info->address = ktla_ktva(breakinfo[breakno].addr);
21057+ else
21058+ info->address = breakinfo[breakno].addr;
21059 info->len = breakinfo[breakno].len;
21060 info->type = breakinfo[breakno].type;
21061 val = arch_install_hw_breakpoint(bp);
21062@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21063 case 'k':
21064 /* clear the trace bit */
21065 linux_regs->flags &= ~X86_EFLAGS_TF;
21066- atomic_set(&kgdb_cpu_doing_single_step, -1);
21067+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21068
21069 /* set the trace bit if we're stepping */
21070 if (remcomInBuffer[0] == 's') {
21071 linux_regs->flags |= X86_EFLAGS_TF;
21072- atomic_set(&kgdb_cpu_doing_single_step,
21073+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21074 raw_smp_processor_id());
21075 }
21076
21077@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21078
21079 switch (cmd) {
21080 case DIE_DEBUG:
21081- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21082+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21083 if (user_mode(regs))
21084 return single_step_cont(regs, args);
21085 break;
21086@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21087 #endif /* CONFIG_DEBUG_RODATA */
21088
21089 bpt->type = BP_BREAKPOINT;
21090- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21091+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21092 BREAK_INSTR_SIZE);
21093 if (err)
21094 return err;
21095- err = probe_kernel_write((char *)bpt->bpt_addr,
21096+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21097 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21098 #ifdef CONFIG_DEBUG_RODATA
21099 if (!err)
21100@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21101 return -EBUSY;
21102 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21103 BREAK_INSTR_SIZE);
21104- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21105+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21106 if (err)
21107 return err;
21108 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21109@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21110 if (mutex_is_locked(&text_mutex))
21111 goto knl_write;
21112 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21113- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21114+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21115 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21116 goto knl_write;
21117 return err;
21118 knl_write:
21119 #endif /* CONFIG_DEBUG_RODATA */
21120- return probe_kernel_write((char *)bpt->bpt_addr,
21121+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21122 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21123 }
21124
21125diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
21126index c5e410e..ed5a7f0 100644
21127--- a/arch/x86/kernel/kprobes-opt.c
21128+++ b/arch/x86/kernel/kprobes-opt.c
21129@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21130 * Verify if the address gap is in 2GB range, because this uses
21131 * a relative jump.
21132 */
21133- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21134+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21135 if (abs(rel) > 0x7fffffff)
21136 return -ERANGE;
21137
21138@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21139 op->optinsn.size = ret;
21140
21141 /* Copy arch-dep-instance from template */
21142- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21143+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21144
21145 /* Set probe information */
21146 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21147
21148 /* Set probe function call */
21149- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21150+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21151
21152 /* Set returning jmp instruction at the tail of out-of-line buffer */
21153- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21154+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21155 (u8 *)op->kp.addr + op->optinsn.size);
21156
21157 flush_icache_range((unsigned long) buf,
21158@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21159 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21160
21161 /* Backup instructions which will be replaced by jump address */
21162- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21163+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21164 RELATIVE_ADDR_SIZE);
21165
21166 insn_buf[0] = RELATIVEJUMP_OPCODE;
21167@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21168 /* This kprobe is really able to run optimized path. */
21169 op = container_of(p, struct optimized_kprobe, kp);
21170 /* Detour through copied instructions */
21171- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21172+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21173 if (!reenter)
21174 reset_current_kprobe();
21175 preempt_enable_no_resched();
21176diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
21177index 57916c0..9e0b9d0 100644
21178--- a/arch/x86/kernel/kprobes.c
21179+++ b/arch/x86/kernel/kprobes.c
21180@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21181 s32 raddr;
21182 } __attribute__((packed)) *insn;
21183
21184- insn = (struct __arch_relative_insn *)from;
21185+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21186+
21187+ pax_open_kernel();
21188 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21189 insn->op = op;
21190+ pax_close_kernel();
21191 }
21192
21193 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21194@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21195 kprobe_opcode_t opcode;
21196 kprobe_opcode_t *orig_opcodes = opcodes;
21197
21198- if (search_exception_tables((unsigned long)opcodes))
21199+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21200 return 0; /* Page fault may occur on this address. */
21201
21202 retry:
21203@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21204 * for the first byte, we can recover the original instruction
21205 * from it and kp->opcode.
21206 */
21207- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21208+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21209 buf[0] = kp->opcode;
21210- return (unsigned long)buf;
21211+ return ktva_ktla((unsigned long)buf);
21212 }
21213
21214 /*
21215@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21216 /* Another subsystem puts a breakpoint, failed to recover */
21217 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21218 return 0;
21219+ pax_open_kernel();
21220 memcpy(dest, insn.kaddr, insn.length);
21221+ pax_close_kernel();
21222
21223 #ifdef CONFIG_X86_64
21224 if (insn_rip_relative(&insn)) {
21225@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21226 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21227 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21228 disp = (u8 *) dest + insn_offset_displacement(&insn);
21229+ pax_open_kernel();
21230 *(s32 *) disp = (s32) newdisp;
21231+ pax_close_kernel();
21232 }
21233 #endif
21234 return insn.length;
21235@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21236 * nor set current_kprobe, because it doesn't use single
21237 * stepping.
21238 */
21239- regs->ip = (unsigned long)p->ainsn.insn;
21240+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21241 preempt_enable_no_resched();
21242 return;
21243 }
21244@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21245 regs->flags &= ~X86_EFLAGS_IF;
21246 /* single step inline if the instruction is an int3 */
21247 if (p->opcode == BREAKPOINT_INSTRUCTION)
21248- regs->ip = (unsigned long)p->addr;
21249+ regs->ip = ktla_ktva((unsigned long)p->addr);
21250 else
21251- regs->ip = (unsigned long)p->ainsn.insn;
21252+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21253 }
21254
21255 /*
21256@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21257 setup_singlestep(p, regs, kcb, 0);
21258 return 1;
21259 }
21260- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21261+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21262 /*
21263 * The breakpoint instruction was removed right
21264 * after we hit it. Another cpu has removed
21265@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21266 " movq %rax, 152(%rsp)\n"
21267 RESTORE_REGS_STRING
21268 " popfq\n"
21269+#ifdef KERNEXEC_PLUGIN
21270+ " btsq $63,(%rsp)\n"
21271+#endif
21272 #else
21273 " pushf\n"
21274 SAVE_REGS_STRING
21275@@ -788,7 +798,7 @@ static void __kprobes
21276 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21277 {
21278 unsigned long *tos = stack_addr(regs);
21279- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21280+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21281 unsigned long orig_ip = (unsigned long)p->addr;
21282 kprobe_opcode_t *insn = p->ainsn.insn;
21283
21284@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21285 struct die_args *args = data;
21286 int ret = NOTIFY_DONE;
21287
21288- if (args->regs && user_mode_vm(args->regs))
21289+ if (args->regs && user_mode(args->regs))
21290 return ret;
21291
21292 switch (val) {
21293diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21294index 9c2bd8b..bb1131c 100644
21295--- a/arch/x86/kernel/kvm.c
21296+++ b/arch/x86/kernel/kvm.c
21297@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21298 return NOTIFY_OK;
21299 }
21300
21301-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21302+static struct notifier_block kvm_cpu_notifier = {
21303 .notifier_call = kvm_cpu_notify,
21304 };
21305 #endif
21306diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21307index ebc9873..1b9724b 100644
21308--- a/arch/x86/kernel/ldt.c
21309+++ b/arch/x86/kernel/ldt.c
21310@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21311 if (reload) {
21312 #ifdef CONFIG_SMP
21313 preempt_disable();
21314- load_LDT(pc);
21315+ load_LDT_nolock(pc);
21316 if (!cpumask_equal(mm_cpumask(current->mm),
21317 cpumask_of(smp_processor_id())))
21318 smp_call_function(flush_ldt, current->mm, 1);
21319 preempt_enable();
21320 #else
21321- load_LDT(pc);
21322+ load_LDT_nolock(pc);
21323 #endif
21324 }
21325 if (oldsize) {
21326@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21327 return err;
21328
21329 for (i = 0; i < old->size; i++)
21330- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21331+ write_ldt_entry(new->ldt, i, old->ldt + i);
21332 return 0;
21333 }
21334
21335@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21336 retval = copy_ldt(&mm->context, &old_mm->context);
21337 mutex_unlock(&old_mm->context.lock);
21338 }
21339+
21340+ if (tsk == current) {
21341+ mm->context.vdso = 0;
21342+
21343+#ifdef CONFIG_X86_32
21344+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21345+ mm->context.user_cs_base = 0UL;
21346+ mm->context.user_cs_limit = ~0UL;
21347+
21348+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21349+ cpus_clear(mm->context.cpu_user_cs_mask);
21350+#endif
21351+
21352+#endif
21353+#endif
21354+
21355+ }
21356+
21357 return retval;
21358 }
21359
21360@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21361 }
21362 }
21363
21364+#ifdef CONFIG_PAX_SEGMEXEC
21365+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21366+ error = -EINVAL;
21367+ goto out_unlock;
21368+ }
21369+#endif
21370+
21371 fill_ldt(&ldt, &ldt_info);
21372 if (oldmode)
21373 ldt.avl = 0;
21374diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21375index 5b19e4d..6476a76 100644
21376--- a/arch/x86/kernel/machine_kexec_32.c
21377+++ b/arch/x86/kernel/machine_kexec_32.c
21378@@ -26,7 +26,7 @@
21379 #include <asm/cacheflush.h>
21380 #include <asm/debugreg.h>
21381
21382-static void set_idt(void *newidt, __u16 limit)
21383+static void set_idt(struct desc_struct *newidt, __u16 limit)
21384 {
21385 struct desc_ptr curidt;
21386
21387@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21388 }
21389
21390
21391-static void set_gdt(void *newgdt, __u16 limit)
21392+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21393 {
21394 struct desc_ptr curgdt;
21395
21396@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21397 }
21398
21399 control_page = page_address(image->control_code_page);
21400- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21401+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21402
21403 relocate_kernel_ptr = control_page;
21404 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21405diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21406index 3a04b22..1d2eb09 100644
21407--- a/arch/x86/kernel/microcode_core.c
21408+++ b/arch/x86/kernel/microcode_core.c
21409@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21410 return NOTIFY_OK;
21411 }
21412
21413-static struct notifier_block __refdata mc_cpu_notifier = {
21414+static struct notifier_block mc_cpu_notifier = {
21415 .notifier_call = mc_cpu_callback,
21416 };
21417
21418diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21419index 3544aed..01ddc1c 100644
21420--- a/arch/x86/kernel/microcode_intel.c
21421+++ b/arch/x86/kernel/microcode_intel.c
21422@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21423
21424 static int get_ucode_user(void *to, const void *from, size_t n)
21425 {
21426- return copy_from_user(to, from, n);
21427+ return copy_from_user(to, (const void __force_user *)from, n);
21428 }
21429
21430 static enum ucode_state
21431 request_microcode_user(int cpu, const void __user *buf, size_t size)
21432 {
21433- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21434+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21435 }
21436
21437 static void microcode_fini_cpu(int cpu)
21438diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21439index 216a4d7..228255a 100644
21440--- a/arch/x86/kernel/module.c
21441+++ b/arch/x86/kernel/module.c
21442@@ -43,15 +43,60 @@ do { \
21443 } while (0)
21444 #endif
21445
21446-void *module_alloc(unsigned long size)
21447+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21448 {
21449- if (PAGE_ALIGN(size) > MODULES_LEN)
21450+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21451 return NULL;
21452 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21453- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21454+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21455 -1, __builtin_return_address(0));
21456 }
21457
21458+void *module_alloc(unsigned long size)
21459+{
21460+
21461+#ifdef CONFIG_PAX_KERNEXEC
21462+ return __module_alloc(size, PAGE_KERNEL);
21463+#else
21464+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21465+#endif
21466+
21467+}
21468+
21469+#ifdef CONFIG_PAX_KERNEXEC
21470+#ifdef CONFIG_X86_32
21471+void *module_alloc_exec(unsigned long size)
21472+{
21473+ struct vm_struct *area;
21474+
21475+ if (size == 0)
21476+ return NULL;
21477+
21478+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21479+ return area ? area->addr : NULL;
21480+}
21481+EXPORT_SYMBOL(module_alloc_exec);
21482+
21483+void module_free_exec(struct module *mod, void *module_region)
21484+{
21485+ vunmap(module_region);
21486+}
21487+EXPORT_SYMBOL(module_free_exec);
21488+#else
21489+void module_free_exec(struct module *mod, void *module_region)
21490+{
21491+ module_free(mod, module_region);
21492+}
21493+EXPORT_SYMBOL(module_free_exec);
21494+
21495+void *module_alloc_exec(unsigned long size)
21496+{
21497+ return __module_alloc(size, PAGE_KERNEL_RX);
21498+}
21499+EXPORT_SYMBOL(module_alloc_exec);
21500+#endif
21501+#endif
21502+
21503 #ifdef CONFIG_X86_32
21504 int apply_relocate(Elf32_Shdr *sechdrs,
21505 const char *strtab,
21506@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21507 unsigned int i;
21508 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21509 Elf32_Sym *sym;
21510- uint32_t *location;
21511+ uint32_t *plocation, location;
21512
21513 DEBUGP("Applying relocate section %u to %u\n",
21514 relsec, sechdrs[relsec].sh_info);
21515 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21516 /* This is where to make the change */
21517- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21518- + rel[i].r_offset;
21519+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21520+ location = (uint32_t)plocation;
21521+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21522+ plocation = ktla_ktva((void *)plocation);
21523 /* This is the symbol it is referring to. Note that all
21524 undefined symbols have been resolved. */
21525 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21526@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21527 switch (ELF32_R_TYPE(rel[i].r_info)) {
21528 case R_386_32:
21529 /* We add the value into the location given */
21530- *location += sym->st_value;
21531+ pax_open_kernel();
21532+ *plocation += sym->st_value;
21533+ pax_close_kernel();
21534 break;
21535 case R_386_PC32:
21536 /* Add the value, subtract its position */
21537- *location += sym->st_value - (uint32_t)location;
21538+ pax_open_kernel();
21539+ *plocation += sym->st_value - location;
21540+ pax_close_kernel();
21541 break;
21542 default:
21543 pr_err("%s: Unknown relocation: %u\n",
21544@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21545 case R_X86_64_NONE:
21546 break;
21547 case R_X86_64_64:
21548+ pax_open_kernel();
21549 *(u64 *)loc = val;
21550+ pax_close_kernel();
21551 break;
21552 case R_X86_64_32:
21553+ pax_open_kernel();
21554 *(u32 *)loc = val;
21555+ pax_close_kernel();
21556 if (val != *(u32 *)loc)
21557 goto overflow;
21558 break;
21559 case R_X86_64_32S:
21560+ pax_open_kernel();
21561 *(s32 *)loc = val;
21562+ pax_close_kernel();
21563 if ((s64)val != *(s32 *)loc)
21564 goto overflow;
21565 break;
21566 case R_X86_64_PC32:
21567 val -= (u64)loc;
21568+ pax_open_kernel();
21569 *(u32 *)loc = val;
21570+ pax_close_kernel();
21571+
21572 #if 0
21573 if ((s64)val != *(s32 *)loc)
21574 goto overflow;
21575diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21576index 4929502..686c291 100644
21577--- a/arch/x86/kernel/msr.c
21578+++ b/arch/x86/kernel/msr.c
21579@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21580 return notifier_from_errno(err);
21581 }
21582
21583-static struct notifier_block __refdata msr_class_cpu_notifier = {
21584+static struct notifier_block msr_class_cpu_notifier = {
21585 .notifier_call = msr_class_cpu_callback,
21586 };
21587
21588diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21589index f84f5c5..f404e81 100644
21590--- a/arch/x86/kernel/nmi.c
21591+++ b/arch/x86/kernel/nmi.c
21592@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21593 return handled;
21594 }
21595
21596-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21597+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21598 {
21599 struct nmi_desc *desc = nmi_to_desc(type);
21600 unsigned long flags;
21601@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21602 * event confuses some handlers (kdump uses this flag)
21603 */
21604 if (action->flags & NMI_FLAG_FIRST)
21605- list_add_rcu(&action->list, &desc->head);
21606+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21607 else
21608- list_add_tail_rcu(&action->list, &desc->head);
21609+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21610
21611 spin_unlock_irqrestore(&desc->lock, flags);
21612 return 0;
21613@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21614 if (!strcmp(n->name, name)) {
21615 WARN(in_nmi(),
21616 "Trying to free NMI (%s) from NMI context!\n", n->name);
21617- list_del_rcu(&n->list);
21618+ pax_list_del_rcu((struct list_head *)&n->list);
21619 break;
21620 }
21621 }
21622@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21623 dotraplinkage notrace __kprobes void
21624 do_nmi(struct pt_regs *regs, long error_code)
21625 {
21626+
21627+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21628+ if (!user_mode(regs)) {
21629+ unsigned long cs = regs->cs & 0xFFFF;
21630+ unsigned long ip = ktva_ktla(regs->ip);
21631+
21632+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21633+ regs->ip = ip;
21634+ }
21635+#endif
21636+
21637 nmi_nesting_preprocess(regs);
21638
21639 nmi_enter();
21640diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21641index 6d9582e..f746287 100644
21642--- a/arch/x86/kernel/nmi_selftest.c
21643+++ b/arch/x86/kernel/nmi_selftest.c
21644@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21645 {
21646 /* trap all the unknown NMIs we may generate */
21647 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21648- __initdata);
21649+ __initconst);
21650 }
21651
21652 static void __init cleanup_nmi_testsuite(void)
21653@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21654 unsigned long timeout;
21655
21656 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21657- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21658+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21659 nmi_fail = FAILURE;
21660 return;
21661 }
21662diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21663index 676b8c7..870ba04 100644
21664--- a/arch/x86/kernel/paravirt-spinlocks.c
21665+++ b/arch/x86/kernel/paravirt-spinlocks.c
21666@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21667 arch_spin_lock(lock);
21668 }
21669
21670-struct pv_lock_ops pv_lock_ops = {
21671+struct pv_lock_ops pv_lock_ops __read_only = {
21672 #ifdef CONFIG_SMP
21673 .spin_is_locked = __ticket_spin_is_locked,
21674 .spin_is_contended = __ticket_spin_is_contended,
21675diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21676index 17fff18..5cfa0f4 100644
21677--- a/arch/x86/kernel/paravirt.c
21678+++ b/arch/x86/kernel/paravirt.c
21679@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21680 {
21681 return x;
21682 }
21683+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21684+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21685+#endif
21686
21687 void __init default_banner(void)
21688 {
21689@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21690 if (opfunc == NULL)
21691 /* If there's no function, patch it with a ud2a (BUG) */
21692 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21693- else if (opfunc == _paravirt_nop)
21694+ else if (opfunc == (void *)_paravirt_nop)
21695 /* If the operation is a nop, then nop the callsite */
21696 ret = paravirt_patch_nop();
21697
21698 /* identity functions just return their single argument */
21699- else if (opfunc == _paravirt_ident_32)
21700+ else if (opfunc == (void *)_paravirt_ident_32)
21701 ret = paravirt_patch_ident_32(insnbuf, len);
21702- else if (opfunc == _paravirt_ident_64)
21703+ else if (opfunc == (void *)_paravirt_ident_64)
21704 ret = paravirt_patch_ident_64(insnbuf, len);
21705+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21706+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21707+ ret = paravirt_patch_ident_64(insnbuf, len);
21708+#endif
21709
21710 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21711 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21712@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21713 if (insn_len > len || start == NULL)
21714 insn_len = len;
21715 else
21716- memcpy(insnbuf, start, insn_len);
21717+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21718
21719 return insn_len;
21720 }
21721@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21722 preempt_enable();
21723 }
21724
21725-struct pv_info pv_info = {
21726+struct pv_info pv_info __read_only = {
21727 .name = "bare hardware",
21728 .paravirt_enabled = 0,
21729 .kernel_rpl = 0,
21730@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21731 #endif
21732 };
21733
21734-struct pv_init_ops pv_init_ops = {
21735+struct pv_init_ops pv_init_ops __read_only = {
21736 .patch = native_patch,
21737 };
21738
21739-struct pv_time_ops pv_time_ops = {
21740+struct pv_time_ops pv_time_ops __read_only = {
21741 .sched_clock = native_sched_clock,
21742 .steal_clock = native_steal_clock,
21743 };
21744
21745-struct pv_irq_ops pv_irq_ops = {
21746+struct pv_irq_ops pv_irq_ops __read_only = {
21747 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21748 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21749 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21750@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21751 #endif
21752 };
21753
21754-struct pv_cpu_ops pv_cpu_ops = {
21755+struct pv_cpu_ops pv_cpu_ops __read_only = {
21756 .cpuid = native_cpuid,
21757 .get_debugreg = native_get_debugreg,
21758 .set_debugreg = native_set_debugreg,
21759@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21760 .end_context_switch = paravirt_nop,
21761 };
21762
21763-struct pv_apic_ops pv_apic_ops = {
21764+struct pv_apic_ops pv_apic_ops __read_only= {
21765 #ifdef CONFIG_X86_LOCAL_APIC
21766 .startup_ipi_hook = paravirt_nop,
21767 #endif
21768 };
21769
21770-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21771+#ifdef CONFIG_X86_32
21772+#ifdef CONFIG_X86_PAE
21773+/* 64-bit pagetable entries */
21774+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21775+#else
21776 /* 32-bit pagetable entries */
21777 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21778+#endif
21779 #else
21780 /* 64-bit pagetable entries */
21781 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21782 #endif
21783
21784-struct pv_mmu_ops pv_mmu_ops = {
21785+struct pv_mmu_ops pv_mmu_ops __read_only = {
21786
21787 .read_cr2 = native_read_cr2,
21788 .write_cr2 = native_write_cr2,
21789@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21790 .make_pud = PTE_IDENT,
21791
21792 .set_pgd = native_set_pgd,
21793+ .set_pgd_batched = native_set_pgd_batched,
21794 #endif
21795 #endif /* PAGETABLE_LEVELS >= 3 */
21796
21797@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21798 },
21799
21800 .set_fixmap = native_set_fixmap,
21801+
21802+#ifdef CONFIG_PAX_KERNEXEC
21803+ .pax_open_kernel = native_pax_open_kernel,
21804+ .pax_close_kernel = native_pax_close_kernel,
21805+#endif
21806+
21807 };
21808
21809 EXPORT_SYMBOL_GPL(pv_time_ops);
21810diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21811index 35ccf75..7a15747 100644
21812--- a/arch/x86/kernel/pci-iommu_table.c
21813+++ b/arch/x86/kernel/pci-iommu_table.c
21814@@ -2,7 +2,7 @@
21815 #include <asm/iommu_table.h>
21816 #include <linux/string.h>
21817 #include <linux/kallsyms.h>
21818-
21819+#include <linux/sched.h>
21820
21821 #define DEBUG 1
21822
21823diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21824index 6c483ba..d10ce2f 100644
21825--- a/arch/x86/kernel/pci-swiotlb.c
21826+++ b/arch/x86/kernel/pci-swiotlb.c
21827@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21828 void *vaddr, dma_addr_t dma_addr,
21829 struct dma_attrs *attrs)
21830 {
21831- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21832+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21833 }
21834
21835 static struct dma_map_ops swiotlb_dma_ops = {
21836diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21837index 2ed787f..f70c9f6 100644
21838--- a/arch/x86/kernel/process.c
21839+++ b/arch/x86/kernel/process.c
21840@@ -36,7 +36,8 @@
21841 * section. Since TSS's are completely CPU-local, we want them
21842 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21843 */
21844-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21845+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21846+EXPORT_SYMBOL(init_tss);
21847
21848 #ifdef CONFIG_X86_64
21849 static DEFINE_PER_CPU(unsigned char, is_idle);
21850@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21851 task_xstate_cachep =
21852 kmem_cache_create("task_xstate", xstate_size,
21853 __alignof__(union thread_xstate),
21854- SLAB_PANIC | SLAB_NOTRACK, NULL);
21855+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21856 }
21857
21858 /*
21859@@ -105,7 +106,7 @@ void exit_thread(void)
21860 unsigned long *bp = t->io_bitmap_ptr;
21861
21862 if (bp) {
21863- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21864+ struct tss_struct *tss = init_tss + get_cpu();
21865
21866 t->io_bitmap_ptr = NULL;
21867 clear_thread_flag(TIF_IO_BITMAP);
21868@@ -136,7 +137,7 @@ void show_regs_common(void)
21869 board = dmi_get_system_info(DMI_BOARD_NAME);
21870
21871 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21872- current->pid, current->comm, print_tainted(),
21873+ task_pid_nr(current), current->comm, print_tainted(),
21874 init_utsname()->release,
21875 (int)strcspn(init_utsname()->version, " "),
21876 init_utsname()->version,
21877@@ -149,6 +150,9 @@ void flush_thread(void)
21878 {
21879 struct task_struct *tsk = current;
21880
21881+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21882+ loadsegment(gs, 0);
21883+#endif
21884 flush_ptrace_hw_breakpoint(tsk);
21885 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21886 drop_init_fpu(tsk);
21887@@ -301,7 +305,7 @@ static void __exit_idle(void)
21888 void exit_idle(void)
21889 {
21890 /* idle loop has pid 0 */
21891- if (current->pid)
21892+ if (task_pid_nr(current))
21893 return;
21894 __exit_idle();
21895 }
21896@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21897
21898 return ret;
21899 }
21900-void stop_this_cpu(void *dummy)
21901+__noreturn void stop_this_cpu(void *dummy)
21902 {
21903 local_irq_disable();
21904 /*
21905@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21906 }
21907 early_param("idle", idle_setup);
21908
21909-unsigned long arch_align_stack(unsigned long sp)
21910+#ifdef CONFIG_PAX_RANDKSTACK
21911+void pax_randomize_kstack(struct pt_regs *regs)
21912 {
21913- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21914- sp -= get_random_int() % 8192;
21915- return sp & ~0xf;
21916-}
21917+ struct thread_struct *thread = &current->thread;
21918+ unsigned long time;
21919
21920-unsigned long arch_randomize_brk(struct mm_struct *mm)
21921-{
21922- unsigned long range_end = mm->brk + 0x02000000;
21923- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21924-}
21925+ if (!randomize_va_space)
21926+ return;
21927+
21928+ if (v8086_mode(regs))
21929+ return;
21930
21931+ rdtscl(time);
21932+
21933+ /* P4 seems to return a 0 LSB, ignore it */
21934+#ifdef CONFIG_MPENTIUM4
21935+ time &= 0x3EUL;
21936+ time <<= 2;
21937+#elif defined(CONFIG_X86_64)
21938+ time &= 0xFUL;
21939+ time <<= 4;
21940+#else
21941+ time &= 0x1FUL;
21942+ time <<= 3;
21943+#endif
21944+
21945+ thread->sp0 ^= time;
21946+ load_sp0(init_tss + smp_processor_id(), thread);
21947+
21948+#ifdef CONFIG_X86_64
21949+ this_cpu_write(kernel_stack, thread->sp0);
21950+#endif
21951+}
21952+#endif
21953diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21954index b5a8905..d9cacac 100644
21955--- a/arch/x86/kernel/process_32.c
21956+++ b/arch/x86/kernel/process_32.c
21957@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21958 unsigned long thread_saved_pc(struct task_struct *tsk)
21959 {
21960 return ((unsigned long *)tsk->thread.sp)[3];
21961+//XXX return tsk->thread.eip;
21962 }
21963
21964 void __show_regs(struct pt_regs *regs, int all)
21965@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21966 unsigned long sp;
21967 unsigned short ss, gs;
21968
21969- if (user_mode_vm(regs)) {
21970+ if (user_mode(regs)) {
21971 sp = regs->sp;
21972 ss = regs->ss & 0xffff;
21973- gs = get_user_gs(regs);
21974 } else {
21975 sp = kernel_stack_pointer(regs);
21976 savesegment(ss, ss);
21977- savesegment(gs, gs);
21978 }
21979+ gs = get_user_gs(regs);
21980
21981 show_regs_common();
21982
21983 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21984 (u16)regs->cs, regs->ip, regs->flags,
21985- smp_processor_id());
21986+ raw_smp_processor_id());
21987 print_symbol("EIP is at %s\n", regs->ip);
21988
21989 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21990@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21991 int copy_thread(unsigned long clone_flags, unsigned long sp,
21992 unsigned long arg, struct task_struct *p)
21993 {
21994- struct pt_regs *childregs = task_pt_regs(p);
21995+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21996 struct task_struct *tsk;
21997 int err;
21998
21999 p->thread.sp = (unsigned long) childregs;
22000 p->thread.sp0 = (unsigned long) (childregs+1);
22001+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22002
22003 if (unlikely(p->flags & PF_KTHREAD)) {
22004 /* kernel thread */
22005 memset(childregs, 0, sizeof(struct pt_regs));
22006 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22007- task_user_gs(p) = __KERNEL_STACK_CANARY;
22008- childregs->ds = __USER_DS;
22009- childregs->es = __USER_DS;
22010+ savesegment(gs, childregs->gs);
22011+ childregs->ds = __KERNEL_DS;
22012+ childregs->es = __KERNEL_DS;
22013 childregs->fs = __KERNEL_PERCPU;
22014 childregs->bx = sp; /* function */
22015 childregs->bp = arg;
22016@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22017 struct thread_struct *prev = &prev_p->thread,
22018 *next = &next_p->thread;
22019 int cpu = smp_processor_id();
22020- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22021+ struct tss_struct *tss = init_tss + cpu;
22022 fpu_switch_t fpu;
22023
22024 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22025@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22026 */
22027 lazy_save_gs(prev->gs);
22028
22029+#ifdef CONFIG_PAX_MEMORY_UDEREF
22030+ __set_fs(task_thread_info(next_p)->addr_limit);
22031+#endif
22032+
22033 /*
22034 * Load the per-thread Thread-Local Storage descriptor.
22035 */
22036@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22037 */
22038 arch_end_context_switch(next_p);
22039
22040+ this_cpu_write(current_task, next_p);
22041+ this_cpu_write(current_tinfo, &next_p->tinfo);
22042+
22043 /*
22044 * Restore %gs if needed (which is common)
22045 */
22046@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22047
22048 switch_fpu_finish(next_p, fpu);
22049
22050- this_cpu_write(current_task, next_p);
22051-
22052 return prev_p;
22053 }
22054
22055@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22056 } while (count++ < 16);
22057 return 0;
22058 }
22059-
22060diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22061index 6e68a61..955a9a5 100644
22062--- a/arch/x86/kernel/process_64.c
22063+++ b/arch/x86/kernel/process_64.c
22064@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22065 struct pt_regs *childregs;
22066 struct task_struct *me = current;
22067
22068- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22069+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22070 childregs = task_pt_regs(p);
22071 p->thread.sp = (unsigned long) childregs;
22072 p->thread.usersp = me->thread.usersp;
22073+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22074 set_tsk_thread_flag(p, TIF_FORK);
22075 p->fpu_counter = 0;
22076 p->thread.io_bitmap_ptr = NULL;
22077@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22078 struct thread_struct *prev = &prev_p->thread;
22079 struct thread_struct *next = &next_p->thread;
22080 int cpu = smp_processor_id();
22081- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22082+ struct tss_struct *tss = init_tss + cpu;
22083 unsigned fsindex, gsindex;
22084 fpu_switch_t fpu;
22085
22086@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22087 prev->usersp = this_cpu_read(old_rsp);
22088 this_cpu_write(old_rsp, next->usersp);
22089 this_cpu_write(current_task, next_p);
22090+ this_cpu_write(current_tinfo, &next_p->tinfo);
22091
22092- this_cpu_write(kernel_stack,
22093- (unsigned long)task_stack_page(next_p) +
22094- THREAD_SIZE - KERNEL_STACK_OFFSET);
22095+ this_cpu_write(kernel_stack, next->sp0);
22096
22097 /*
22098 * Now maybe reload the debug registers and handle I/O bitmaps
22099@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22100 if (!p || p == current || p->state == TASK_RUNNING)
22101 return 0;
22102 stack = (unsigned long)task_stack_page(p);
22103- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22104+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22105 return 0;
22106 fp = *(u64 *)(p->thread.sp);
22107 do {
22108- if (fp < (unsigned long)stack ||
22109- fp >= (unsigned long)stack+THREAD_SIZE)
22110+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22111 return 0;
22112 ip = *(u64 *)(fp+8);
22113 if (!in_sched_functions(ip))
22114diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22115index b629bbe..0fa615a 100644
22116--- a/arch/x86/kernel/ptrace.c
22117+++ b/arch/x86/kernel/ptrace.c
22118@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22119 {
22120 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22121 unsigned long sp = (unsigned long)&regs->sp;
22122- struct thread_info *tinfo;
22123
22124- if (context == (sp & ~(THREAD_SIZE - 1)))
22125+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22126 return sp;
22127
22128- tinfo = (struct thread_info *)context;
22129- if (tinfo->previous_esp)
22130- return tinfo->previous_esp;
22131+ sp = *(unsigned long *)context;
22132+ if (sp)
22133+ return sp;
22134
22135 return (unsigned long)regs;
22136 }
22137@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22138 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22139 {
22140 int i;
22141- int dr7 = 0;
22142+ unsigned long dr7 = 0;
22143 struct arch_hw_breakpoint *info;
22144
22145 for (i = 0; i < HBP_NUM; i++) {
22146@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22147 unsigned long addr, unsigned long data)
22148 {
22149 int ret;
22150- unsigned long __user *datap = (unsigned long __user *)data;
22151+ unsigned long __user *datap = (__force unsigned long __user *)data;
22152
22153 switch (request) {
22154 /* read the word at location addr in the USER area. */
22155@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22156 if ((int) addr < 0)
22157 return -EIO;
22158 ret = do_get_thread_area(child, addr,
22159- (struct user_desc __user *)data);
22160+ (__force struct user_desc __user *) data);
22161 break;
22162
22163 case PTRACE_SET_THREAD_AREA:
22164 if ((int) addr < 0)
22165 return -EIO;
22166 ret = do_set_thread_area(child, addr,
22167- (struct user_desc __user *)data, 0);
22168+ (__force struct user_desc __user *) data, 0);
22169 break;
22170 #endif
22171
22172@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22173
22174 #ifdef CONFIG_X86_64
22175
22176-static struct user_regset x86_64_regsets[] __read_mostly = {
22177+static user_regset_no_const x86_64_regsets[] __read_only = {
22178 [REGSET_GENERAL] = {
22179 .core_note_type = NT_PRSTATUS,
22180 .n = sizeof(struct user_regs_struct) / sizeof(long),
22181@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22182 #endif /* CONFIG_X86_64 */
22183
22184 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22185-static struct user_regset x86_32_regsets[] __read_mostly = {
22186+static user_regset_no_const x86_32_regsets[] __read_only = {
22187 [REGSET_GENERAL] = {
22188 .core_note_type = NT_PRSTATUS,
22189 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22190@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22191 */
22192 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22193
22194-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22195+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22196 {
22197 #ifdef CONFIG_X86_64
22198 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22199@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22200 memset(info, 0, sizeof(*info));
22201 info->si_signo = SIGTRAP;
22202 info->si_code = si_code;
22203- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22204+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22205 }
22206
22207 void user_single_step_siginfo(struct task_struct *tsk,
22208@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22209 # define IS_IA32 0
22210 #endif
22211
22212+#ifdef CONFIG_GRKERNSEC_SETXID
22213+extern void gr_delayed_cred_worker(void);
22214+#endif
22215+
22216 /*
22217 * We must return the syscall number to actually look up in the table.
22218 * This can be -1L to skip running any syscall at all.
22219@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22220
22221 user_exit();
22222
22223+#ifdef CONFIG_GRKERNSEC_SETXID
22224+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22225+ gr_delayed_cred_worker();
22226+#endif
22227+
22228 /*
22229 * If we stepped into a sysenter/syscall insn, it trapped in
22230 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22231@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22232 */
22233 user_exit();
22234
22235+#ifdef CONFIG_GRKERNSEC_SETXID
22236+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22237+ gr_delayed_cred_worker();
22238+#endif
22239+
22240 audit_syscall_exit(regs);
22241
22242 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22243diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22244index 2cb9470..ff1fd80 100644
22245--- a/arch/x86/kernel/pvclock.c
22246+++ b/arch/x86/kernel/pvclock.c
22247@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22248 return pv_tsc_khz;
22249 }
22250
22251-static atomic64_t last_value = ATOMIC64_INIT(0);
22252+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22253
22254 void pvclock_resume(void)
22255 {
22256- atomic64_set(&last_value, 0);
22257+ atomic64_set_unchecked(&last_value, 0);
22258 }
22259
22260 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22261@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22262 * updating at the same time, and one of them could be slightly behind,
22263 * making the assumption that last_value always go forward fail to hold.
22264 */
22265- last = atomic64_read(&last_value);
22266+ last = atomic64_read_unchecked(&last_value);
22267 do {
22268 if (ret < last)
22269 return last;
22270- last = atomic64_cmpxchg(&last_value, last, ret);
22271+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22272 } while (unlikely(last != ret));
22273
22274 return ret;
22275diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22276index 76fa1e9..abf09ea 100644
22277--- a/arch/x86/kernel/reboot.c
22278+++ b/arch/x86/kernel/reboot.c
22279@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22280 EXPORT_SYMBOL(pm_power_off);
22281
22282 static const struct desc_ptr no_idt = {};
22283-static int reboot_mode;
22284+static unsigned short reboot_mode;
22285 enum reboot_type reboot_type = BOOT_ACPI;
22286 int reboot_force;
22287
22288@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22289
22290 void __noreturn machine_real_restart(unsigned int type)
22291 {
22292+
22293+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22294+ struct desc_struct *gdt;
22295+#endif
22296+
22297 local_irq_disable();
22298
22299 /*
22300@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22301
22302 /* Jump to the identity-mapped low memory code */
22303 #ifdef CONFIG_X86_32
22304- asm volatile("jmpl *%0" : :
22305+
22306+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22307+ gdt = get_cpu_gdt_table(smp_processor_id());
22308+ pax_open_kernel();
22309+#ifdef CONFIG_PAX_MEMORY_UDEREF
22310+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22311+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22312+ loadsegment(ds, __KERNEL_DS);
22313+ loadsegment(es, __KERNEL_DS);
22314+ loadsegment(ss, __KERNEL_DS);
22315+#endif
22316+#ifdef CONFIG_PAX_KERNEXEC
22317+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22318+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22319+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22320+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22321+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22322+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22323+#endif
22324+ pax_close_kernel();
22325+#endif
22326+
22327+ asm volatile("ljmpl *%0" : :
22328 "rm" (real_mode_header->machine_real_restart_asm),
22329 "a" (type));
22330 #else
22331@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22332 * try to force a triple fault and then cycle between hitting the keyboard
22333 * controller and doing that
22334 */
22335-static void native_machine_emergency_restart(void)
22336+static void __noreturn native_machine_emergency_restart(void)
22337 {
22338 int i;
22339 int attempt = 0;
22340@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22341 #endif
22342 }
22343
22344-static void __machine_emergency_restart(int emergency)
22345+static void __noreturn __machine_emergency_restart(int emergency)
22346 {
22347 reboot_emergency = emergency;
22348 machine_ops.emergency_restart();
22349 }
22350
22351-static void native_machine_restart(char *__unused)
22352+static void __noreturn native_machine_restart(char *__unused)
22353 {
22354 pr_notice("machine restart\n");
22355
22356@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22357 __machine_emergency_restart(0);
22358 }
22359
22360-static void native_machine_halt(void)
22361+static void __noreturn native_machine_halt(void)
22362 {
22363 /* Stop other cpus and apics */
22364 machine_shutdown();
22365@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22366 stop_this_cpu(NULL);
22367 }
22368
22369-static void native_machine_power_off(void)
22370+static void __noreturn native_machine_power_off(void)
22371 {
22372 if (pm_power_off) {
22373 if (!reboot_force)
22374@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22375 }
22376 /* A fallback in case there is no PM info available */
22377 tboot_shutdown(TB_SHUTDOWN_HALT);
22378+ unreachable();
22379 }
22380
22381-struct machine_ops machine_ops = {
22382+struct machine_ops machine_ops __read_only = {
22383 .power_off = native_machine_power_off,
22384 .shutdown = native_machine_shutdown,
22385 .emergency_restart = native_machine_emergency_restart,
22386diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22387index 7a6f3b3..bed145d7 100644
22388--- a/arch/x86/kernel/relocate_kernel_64.S
22389+++ b/arch/x86/kernel/relocate_kernel_64.S
22390@@ -11,6 +11,7 @@
22391 #include <asm/kexec.h>
22392 #include <asm/processor-flags.h>
22393 #include <asm/pgtable_types.h>
22394+#include <asm/alternative-asm.h>
22395
22396 /*
22397 * Must be relocatable PIC code callable as a C function
22398@@ -160,13 +161,14 @@ identity_mapped:
22399 xorq %rbp, %rbp
22400 xorq %r8, %r8
22401 xorq %r9, %r9
22402- xorq %r10, %r9
22403+ xorq %r10, %r10
22404 xorq %r11, %r11
22405 xorq %r12, %r12
22406 xorq %r13, %r13
22407 xorq %r14, %r14
22408 xorq %r15, %r15
22409
22410+ pax_force_retaddr 0, 1
22411 ret
22412
22413 1:
22414diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22415index 8b24289..d37b58b 100644
22416--- a/arch/x86/kernel/setup.c
22417+++ b/arch/x86/kernel/setup.c
22418@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22419
22420 switch (data->type) {
22421 case SETUP_E820_EXT:
22422- parse_e820_ext(data);
22423+ parse_e820_ext((struct setup_data __force_kernel *)data);
22424 break;
22425 case SETUP_DTB:
22426 add_dtb(pa_data);
22427@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22428 * area (640->1Mb) as ram even though it is not.
22429 * take them out.
22430 */
22431- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22432+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22433
22434 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22435 }
22436@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22437
22438 if (!boot_params.hdr.root_flags)
22439 root_mountflags &= ~MS_RDONLY;
22440- init_mm.start_code = (unsigned long) _text;
22441- init_mm.end_code = (unsigned long) _etext;
22442+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22443+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22444 init_mm.end_data = (unsigned long) _edata;
22445 init_mm.brk = _brk_end;
22446
22447- code_resource.start = virt_to_phys(_text);
22448- code_resource.end = virt_to_phys(_etext)-1;
22449- data_resource.start = virt_to_phys(_etext);
22450+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22451+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22452+ data_resource.start = virt_to_phys(_sdata);
22453 data_resource.end = virt_to_phys(_edata)-1;
22454 bss_resource.start = virt_to_phys(&__bss_start);
22455 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22456diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22457index 5cdff03..80fa283 100644
22458--- a/arch/x86/kernel/setup_percpu.c
22459+++ b/arch/x86/kernel/setup_percpu.c
22460@@ -21,19 +21,17 @@
22461 #include <asm/cpu.h>
22462 #include <asm/stackprotector.h>
22463
22464-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22465+#ifdef CONFIG_SMP
22466+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22467 EXPORT_PER_CPU_SYMBOL(cpu_number);
22468+#endif
22469
22470-#ifdef CONFIG_X86_64
22471 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22472-#else
22473-#define BOOT_PERCPU_OFFSET 0
22474-#endif
22475
22476 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22477 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22478
22479-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22480+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22481 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22482 };
22483 EXPORT_SYMBOL(__per_cpu_offset);
22484@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22485 {
22486 #ifdef CONFIG_NEED_MULTIPLE_NODES
22487 pg_data_t *last = NULL;
22488- unsigned int cpu;
22489+ int cpu;
22490
22491 for_each_possible_cpu(cpu) {
22492 int node = early_cpu_to_node(cpu);
22493@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22494 {
22495 #ifdef CONFIG_X86_32
22496 struct desc_struct gdt;
22497+ unsigned long base = per_cpu_offset(cpu);
22498
22499- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22500- 0x2 | DESCTYPE_S, 0x8);
22501- gdt.s = 1;
22502+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22503+ 0x83 | DESCTYPE_S, 0xC);
22504 write_gdt_entry(get_cpu_gdt_table(cpu),
22505 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22506 #endif
22507@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22508 /* alrighty, percpu areas up and running */
22509 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22510 for_each_possible_cpu(cpu) {
22511+#ifdef CONFIG_CC_STACKPROTECTOR
22512+#ifdef CONFIG_X86_32
22513+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22514+#endif
22515+#endif
22516 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22517 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22518 per_cpu(cpu_number, cpu) = cpu;
22519@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22520 */
22521 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22522 #endif
22523+#ifdef CONFIG_CC_STACKPROTECTOR
22524+#ifdef CONFIG_X86_32
22525+ if (!cpu)
22526+ per_cpu(stack_canary.canary, cpu) = canary;
22527+#endif
22528+#endif
22529 /*
22530 * Up to this point, the boot CPU has been using .init.data
22531 * area. Reload any changed state for the boot CPU.
22532diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22533index d6bf1f3..3ffce5a 100644
22534--- a/arch/x86/kernel/signal.c
22535+++ b/arch/x86/kernel/signal.c
22536@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22537 * Align the stack pointer according to the i386 ABI,
22538 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22539 */
22540- sp = ((sp + 4) & -16ul) - 4;
22541+ sp = ((sp - 12) & -16ul) - 4;
22542 #else /* !CONFIG_X86_32 */
22543 sp = round_down(sp, 16) - 8;
22544 #endif
22545@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22546 }
22547
22548 if (current->mm->context.vdso)
22549- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22550+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22551 else
22552- restorer = &frame->retcode;
22553+ restorer = (void __user *)&frame->retcode;
22554 if (ka->sa.sa_flags & SA_RESTORER)
22555 restorer = ka->sa.sa_restorer;
22556
22557@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22558 * reasons and because gdb uses it as a signature to notice
22559 * signal handler stack frames.
22560 */
22561- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22562+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22563
22564 if (err)
22565 return -EFAULT;
22566@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22567 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22568
22569 /* Set up to return from userspace. */
22570- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22571+ if (current->mm->context.vdso)
22572+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22573+ else
22574+ restorer = (void __user *)&frame->retcode;
22575 if (ka->sa.sa_flags & SA_RESTORER)
22576 restorer = ka->sa.sa_restorer;
22577 put_user_ex(restorer, &frame->pretcode);
22578@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22579 * reasons and because gdb uses it as a signature to notice
22580 * signal handler stack frames.
22581 */
22582- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22583+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22584 } put_user_catch(err);
22585
22586 err |= copy_siginfo_to_user(&frame->info, info);
22587diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22588index 48d2b7d..90d328a 100644
22589--- a/arch/x86/kernel/smp.c
22590+++ b/arch/x86/kernel/smp.c
22591@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22592
22593 __setup("nonmi_ipi", nonmi_ipi_setup);
22594
22595-struct smp_ops smp_ops = {
22596+struct smp_ops smp_ops __read_only = {
22597 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22598 .smp_prepare_cpus = native_smp_prepare_cpus,
22599 .smp_cpus_done = native_smp_cpus_done,
22600diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22601index ed0fe38..87fc692 100644
22602--- a/arch/x86/kernel/smpboot.c
22603+++ b/arch/x86/kernel/smpboot.c
22604@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22605 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22606 (THREAD_SIZE + task_stack_page(idle))) - 1);
22607 per_cpu(current_task, cpu) = idle;
22608+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22609
22610 #ifdef CONFIG_X86_32
22611 /* Stack for startup_32 can be just as for start_secondary onwards */
22612@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22613 #else
22614 clear_tsk_thread_flag(idle, TIF_FORK);
22615 initial_gs = per_cpu_offset(cpu);
22616- per_cpu(kernel_stack, cpu) =
22617- (unsigned long)task_stack_page(idle) -
22618- KERNEL_STACK_OFFSET + THREAD_SIZE;
22619+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22620 #endif
22621+
22622+ pax_open_kernel();
22623 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22624+ pax_close_kernel();
22625+
22626 initial_code = (unsigned long)start_secondary;
22627 stack_start = idle->thread.sp;
22628
22629@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22630 /* the FPU context is blank, nobody can own it */
22631 __cpu_disable_lazy_restore(cpu);
22632
22633+#ifdef CONFIG_PAX_PER_CPU_PGD
22634+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22635+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22636+ KERNEL_PGD_PTRS);
22637+#endif
22638+
22639+ /* the FPU context is blank, nobody can own it */
22640+ __cpu_disable_lazy_restore(cpu);
22641+
22642 err = do_boot_cpu(apicid, cpu, tidle);
22643 if (err) {
22644 pr_debug("do_boot_cpu failed %d\n", err);
22645diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22646index 9b4d51d..5d28b58 100644
22647--- a/arch/x86/kernel/step.c
22648+++ b/arch/x86/kernel/step.c
22649@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22650 struct desc_struct *desc;
22651 unsigned long base;
22652
22653- seg &= ~7UL;
22654+ seg >>= 3;
22655
22656 mutex_lock(&child->mm->context.lock);
22657- if (unlikely((seg >> 3) >= child->mm->context.size))
22658+ if (unlikely(seg >= child->mm->context.size))
22659 addr = -1L; /* bogus selector, access would fault */
22660 else {
22661 desc = child->mm->context.ldt + seg;
22662@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22663 addr += base;
22664 }
22665 mutex_unlock(&child->mm->context.lock);
22666- }
22667+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22668+ addr = ktla_ktva(addr);
22669
22670 return addr;
22671 }
22672@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22673 unsigned char opcode[15];
22674 unsigned long addr = convert_ip_to_linear(child, regs);
22675
22676+ if (addr == -EINVAL)
22677+ return 0;
22678+
22679 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22680 for (i = 0; i < copied; i++) {
22681 switch (opcode[i]) {
22682diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22683new file mode 100644
22684index 0000000..207bec6
22685--- /dev/null
22686+++ b/arch/x86/kernel/sys_i386_32.c
22687@@ -0,0 +1,250 @@
22688+/*
22689+ * This file contains various random system calls that
22690+ * have a non-standard calling sequence on the Linux/i386
22691+ * platform.
22692+ */
22693+
22694+#include <linux/errno.h>
22695+#include <linux/sched.h>
22696+#include <linux/mm.h>
22697+#include <linux/fs.h>
22698+#include <linux/smp.h>
22699+#include <linux/sem.h>
22700+#include <linux/msg.h>
22701+#include <linux/shm.h>
22702+#include <linux/stat.h>
22703+#include <linux/syscalls.h>
22704+#include <linux/mman.h>
22705+#include <linux/file.h>
22706+#include <linux/utsname.h>
22707+#include <linux/ipc.h>
22708+
22709+#include <linux/uaccess.h>
22710+#include <linux/unistd.h>
22711+
22712+#include <asm/syscalls.h>
22713+
22714+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22715+{
22716+ unsigned long pax_task_size = TASK_SIZE;
22717+
22718+#ifdef CONFIG_PAX_SEGMEXEC
22719+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22720+ pax_task_size = SEGMEXEC_TASK_SIZE;
22721+#endif
22722+
22723+ if (flags & MAP_FIXED)
22724+ if (len > pax_task_size || addr > pax_task_size - len)
22725+ return -EINVAL;
22726+
22727+ return 0;
22728+}
22729+
22730+unsigned long
22731+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22732+ unsigned long len, unsigned long pgoff, unsigned long flags)
22733+{
22734+ struct mm_struct *mm = current->mm;
22735+ struct vm_area_struct *vma;
22736+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22737+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22738+
22739+#ifdef CONFIG_PAX_SEGMEXEC
22740+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22741+ pax_task_size = SEGMEXEC_TASK_SIZE;
22742+#endif
22743+
22744+ pax_task_size -= PAGE_SIZE;
22745+
22746+ if (len > pax_task_size)
22747+ return -ENOMEM;
22748+
22749+ if (flags & MAP_FIXED)
22750+ return addr;
22751+
22752+#ifdef CONFIG_PAX_RANDMMAP
22753+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22754+#endif
22755+
22756+ if (addr) {
22757+ addr = PAGE_ALIGN(addr);
22758+ if (pax_task_size - len >= addr) {
22759+ vma = find_vma(mm, addr);
22760+ if (check_heap_stack_gap(vma, addr, len, offset))
22761+ return addr;
22762+ }
22763+ }
22764+ if (len > mm->cached_hole_size) {
22765+ start_addr = addr = mm->free_area_cache;
22766+ } else {
22767+ start_addr = addr = mm->mmap_base;
22768+ mm->cached_hole_size = 0;
22769+ }
22770+
22771+#ifdef CONFIG_PAX_PAGEEXEC
22772+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22773+ start_addr = 0x00110000UL;
22774+
22775+#ifdef CONFIG_PAX_RANDMMAP
22776+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22777+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22778+#endif
22779+
22780+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22781+ start_addr = addr = mm->mmap_base;
22782+ else
22783+ addr = start_addr;
22784+ }
22785+#endif
22786+
22787+full_search:
22788+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22789+ /* At this point: (!vma || addr < vma->vm_end). */
22790+ if (pax_task_size - len < addr) {
22791+ /*
22792+ * Start a new search - just in case we missed
22793+ * some holes.
22794+ */
22795+ if (start_addr != mm->mmap_base) {
22796+ start_addr = addr = mm->mmap_base;
22797+ mm->cached_hole_size = 0;
22798+ goto full_search;
22799+ }
22800+ return -ENOMEM;
22801+ }
22802+ if (check_heap_stack_gap(vma, addr, len, offset))
22803+ break;
22804+ if (addr + mm->cached_hole_size < vma->vm_start)
22805+ mm->cached_hole_size = vma->vm_start - addr;
22806+ addr = vma->vm_end;
22807+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22808+ start_addr = addr = mm->mmap_base;
22809+ mm->cached_hole_size = 0;
22810+ goto full_search;
22811+ }
22812+ }
22813+
22814+ /*
22815+ * Remember the place where we stopped the search:
22816+ */
22817+ mm->free_area_cache = addr + len;
22818+ return addr;
22819+}
22820+
22821+unsigned long
22822+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22823+ const unsigned long len, const unsigned long pgoff,
22824+ const unsigned long flags)
22825+{
22826+ struct vm_area_struct *vma;
22827+ struct mm_struct *mm = current->mm;
22828+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22829+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22830+
22831+#ifdef CONFIG_PAX_SEGMEXEC
22832+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22833+ pax_task_size = SEGMEXEC_TASK_SIZE;
22834+#endif
22835+
22836+ pax_task_size -= PAGE_SIZE;
22837+
22838+ /* requested length too big for entire address space */
22839+ if (len > pax_task_size)
22840+ return -ENOMEM;
22841+
22842+ if (flags & MAP_FIXED)
22843+ return addr;
22844+
22845+#ifdef CONFIG_PAX_PAGEEXEC
22846+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22847+ goto bottomup;
22848+#endif
22849+
22850+#ifdef CONFIG_PAX_RANDMMAP
22851+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22852+#endif
22853+
22854+ /* requesting a specific address */
22855+ if (addr) {
22856+ addr = PAGE_ALIGN(addr);
22857+ if (pax_task_size - len >= addr) {
22858+ vma = find_vma(mm, addr);
22859+ if (check_heap_stack_gap(vma, addr, len, offset))
22860+ return addr;
22861+ }
22862+ }
22863+
22864+ /* check if free_area_cache is useful for us */
22865+ if (len <= mm->cached_hole_size) {
22866+ mm->cached_hole_size = 0;
22867+ mm->free_area_cache = mm->mmap_base;
22868+ }
22869+
22870+ /* either no address requested or can't fit in requested address hole */
22871+ addr = mm->free_area_cache;
22872+
22873+ /* make sure it can fit in the remaining address space */
22874+ if (addr > len) {
22875+ vma = find_vma(mm, addr-len);
22876+ if (check_heap_stack_gap(vma, addr - len, len, offset))
22877+ /* remember the address as a hint for next time */
22878+ return (mm->free_area_cache = addr-len);
22879+ }
22880+
22881+ if (mm->mmap_base < len)
22882+ goto bottomup;
22883+
22884+ addr = mm->mmap_base-len;
22885+
22886+ do {
22887+ /*
22888+ * Lookup failure means no vma is above this address,
22889+ * else if new region fits below vma->vm_start,
22890+ * return with success:
22891+ */
22892+ vma = find_vma(mm, addr);
22893+ if (check_heap_stack_gap(vma, addr, len, offset))
22894+ /* remember the address as a hint for next time */
22895+ return (mm->free_area_cache = addr);
22896+
22897+ /* remember the largest hole we saw so far */
22898+ if (addr + mm->cached_hole_size < vma->vm_start)
22899+ mm->cached_hole_size = vma->vm_start - addr;
22900+
22901+ /* try just below the current vma->vm_start */
22902+ addr = skip_heap_stack_gap(vma, len, offset);
22903+ } while (!IS_ERR_VALUE(addr));
22904+
22905+bottomup:
22906+ /*
22907+ * A failed mmap() very likely causes application failure,
22908+ * so fall back to the bottom-up function here. This scenario
22909+ * can happen with large stack limits and large mmap()
22910+ * allocations.
22911+ */
22912+
22913+#ifdef CONFIG_PAX_SEGMEXEC
22914+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22915+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22916+ else
22917+#endif
22918+
22919+ mm->mmap_base = TASK_UNMAPPED_BASE;
22920+
22921+#ifdef CONFIG_PAX_RANDMMAP
22922+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22923+ mm->mmap_base += mm->delta_mmap;
22924+#endif
22925+
22926+ mm->free_area_cache = mm->mmap_base;
22927+ mm->cached_hole_size = ~0UL;
22928+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22929+ /*
22930+ * Restore the topdown base:
22931+ */
22932+ mm->mmap_base = base;
22933+ mm->free_area_cache = base;
22934+ mm->cached_hole_size = ~0UL;
22935+
22936+ return addr;
22937+}
22938diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22939index 97ef74b..57a1882 100644
22940--- a/arch/x86/kernel/sys_x86_64.c
22941+++ b/arch/x86/kernel/sys_x86_64.c
22942@@ -81,8 +81,8 @@ out:
22943 return error;
22944 }
22945
22946-static void find_start_end(unsigned long flags, unsigned long *begin,
22947- unsigned long *end)
22948+static void find_start_end(struct mm_struct *mm, unsigned long flags,
22949+ unsigned long *begin, unsigned long *end)
22950 {
22951 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22952 unsigned long new_begin;
22953@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22954 *begin = new_begin;
22955 }
22956 } else {
22957- *begin = TASK_UNMAPPED_BASE;
22958+ *begin = mm->mmap_base;
22959 *end = TASK_SIZE;
22960 }
22961 }
22962@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22963 struct vm_area_struct *vma;
22964 struct vm_unmapped_area_info info;
22965 unsigned long begin, end;
22966+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22967
22968 if (flags & MAP_FIXED)
22969 return addr;
22970
22971- find_start_end(flags, &begin, &end);
22972+ find_start_end(mm, flags, &begin, &end);
22973
22974 if (len > end)
22975 return -ENOMEM;
22976
22977+#ifdef CONFIG_PAX_RANDMMAP
22978+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22979+#endif
22980+
22981 if (addr) {
22982 addr = PAGE_ALIGN(addr);
22983 vma = find_vma(mm, addr);
22984- if (end - len >= addr &&
22985- (!vma || addr + len <= vma->vm_start))
22986+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22987 return addr;
22988 }
22989
22990@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22991 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22992 goto bottomup;
22993
22994+#ifdef CONFIG_PAX_RANDMMAP
22995+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22996+#endif
22997+
22998 /* requesting a specific address */
22999 if (addr) {
23000 addr = PAGE_ALIGN(addr);
23001diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23002index f84fe00..f41d9f1 100644
23003--- a/arch/x86/kernel/tboot.c
23004+++ b/arch/x86/kernel/tboot.c
23005@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23006
23007 void tboot_shutdown(u32 shutdown_type)
23008 {
23009- void (*shutdown)(void);
23010+ void (* __noreturn shutdown)(void);
23011
23012 if (!tboot_enabled())
23013 return;
23014@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23015
23016 switch_to_tboot_pt();
23017
23018- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23019+ shutdown = (void *)tboot->shutdown_entry;
23020 shutdown();
23021
23022 /* should not reach here */
23023@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23024 return 0;
23025 }
23026
23027-static atomic_t ap_wfs_count;
23028+static atomic_unchecked_t ap_wfs_count;
23029
23030 static int tboot_wait_for_aps(int num_aps)
23031 {
23032@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23033 {
23034 switch (action) {
23035 case CPU_DYING:
23036- atomic_inc(&ap_wfs_count);
23037+ atomic_inc_unchecked(&ap_wfs_count);
23038 if (num_online_cpus() == 1)
23039- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23040+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23041 return NOTIFY_BAD;
23042 break;
23043 }
23044 return NOTIFY_OK;
23045 }
23046
23047-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23048+static struct notifier_block tboot_cpu_notifier =
23049 {
23050 .notifier_call = tboot_cpu_callback,
23051 };
23052@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23053
23054 tboot_create_trampoline();
23055
23056- atomic_set(&ap_wfs_count, 0);
23057+ atomic_set_unchecked(&ap_wfs_count, 0);
23058 register_hotcpu_notifier(&tboot_cpu_notifier);
23059
23060 acpi_os_set_prepare_sleep(&tboot_sleep);
23061diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23062index 24d3c91..d06b473 100644
23063--- a/arch/x86/kernel/time.c
23064+++ b/arch/x86/kernel/time.c
23065@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23066 {
23067 unsigned long pc = instruction_pointer(regs);
23068
23069- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23070+ if (!user_mode(regs) && in_lock_functions(pc)) {
23071 #ifdef CONFIG_FRAME_POINTER
23072- return *(unsigned long *)(regs->bp + sizeof(long));
23073+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23074 #else
23075 unsigned long *sp =
23076 (unsigned long *)kernel_stack_pointer(regs);
23077@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23078 * or above a saved flags. Eflags has bits 22-31 zero,
23079 * kernel addresses don't.
23080 */
23081+
23082+#ifdef CONFIG_PAX_KERNEXEC
23083+ return ktla_ktva(sp[0]);
23084+#else
23085 if (sp[0] >> 22)
23086 return sp[0];
23087 if (sp[1] >> 22)
23088 return sp[1];
23089 #endif
23090+
23091+#endif
23092 }
23093 return pc;
23094 }
23095diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23096index 9d9d2f9..cad418a 100644
23097--- a/arch/x86/kernel/tls.c
23098+++ b/arch/x86/kernel/tls.c
23099@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23100 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23101 return -EINVAL;
23102
23103+#ifdef CONFIG_PAX_SEGMEXEC
23104+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23105+ return -EINVAL;
23106+#endif
23107+
23108 set_tls_desc(p, idx, &info, 1);
23109
23110 return 0;
23111@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23112
23113 if (kbuf)
23114 info = kbuf;
23115- else if (__copy_from_user(infobuf, ubuf, count))
23116+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23117 return -EFAULT;
23118 else
23119 info = infobuf;
23120diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23121index ecffca1..95c4d13 100644
23122--- a/arch/x86/kernel/traps.c
23123+++ b/arch/x86/kernel/traps.c
23124@@ -68,12 +68,6 @@
23125 #include <asm/setup.h>
23126
23127 asmlinkage int system_call(void);
23128-
23129-/*
23130- * The IDT has to be page-aligned to simplify the Pentium
23131- * F0 0F bug workaround.
23132- */
23133-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23134 #endif
23135
23136 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23137@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23138 }
23139
23140 static int __kprobes
23141-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23142+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23143 struct pt_regs *regs, long error_code)
23144 {
23145 #ifdef CONFIG_X86_32
23146- if (regs->flags & X86_VM_MASK) {
23147+ if (v8086_mode(regs)) {
23148 /*
23149 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23150 * On nmi (interrupt 2), do_trap should not be called.
23151@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23152 return -1;
23153 }
23154 #endif
23155- if (!user_mode(regs)) {
23156+ if (!user_mode_novm(regs)) {
23157 if (!fixup_exception(regs)) {
23158 tsk->thread.error_code = error_code;
23159 tsk->thread.trap_nr = trapnr;
23160+
23161+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23162+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23163+ str = "PAX: suspicious stack segment fault";
23164+#endif
23165+
23166 die(str, regs, error_code);
23167 }
23168+
23169+#ifdef CONFIG_PAX_REFCOUNT
23170+ if (trapnr == 4)
23171+ pax_report_refcount_overflow(regs);
23172+#endif
23173+
23174 return 0;
23175 }
23176
23177@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23178 }
23179
23180 static void __kprobes
23181-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23182+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23183 long error_code, siginfo_t *info)
23184 {
23185 struct task_struct *tsk = current;
23186@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23187 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23188 printk_ratelimit()) {
23189 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23190- tsk->comm, tsk->pid, str,
23191+ tsk->comm, task_pid_nr(tsk), str,
23192 regs->ip, regs->sp, error_code);
23193 print_vma_addr(" in ", regs->ip);
23194 pr_cont("\n");
23195@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23196 conditional_sti(regs);
23197
23198 #ifdef CONFIG_X86_32
23199- if (regs->flags & X86_VM_MASK) {
23200+ if (v8086_mode(regs)) {
23201 local_irq_enable();
23202 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23203 goto exit;
23204@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23205 #endif
23206
23207 tsk = current;
23208- if (!user_mode(regs)) {
23209+ if (!user_mode_novm(regs)) {
23210 if (fixup_exception(regs))
23211 goto exit;
23212
23213 tsk->thread.error_code = error_code;
23214 tsk->thread.trap_nr = X86_TRAP_GP;
23215 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23216- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23217+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23218+
23219+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23220+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23221+ die("PAX: suspicious general protection fault", regs, error_code);
23222+ else
23223+#endif
23224+
23225 die("general protection fault", regs, error_code);
23226+ }
23227 goto exit;
23228 }
23229
23230+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23231+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23232+ struct mm_struct *mm = tsk->mm;
23233+ unsigned long limit;
23234+
23235+ down_write(&mm->mmap_sem);
23236+ limit = mm->context.user_cs_limit;
23237+ if (limit < TASK_SIZE) {
23238+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23239+ up_write(&mm->mmap_sem);
23240+ return;
23241+ }
23242+ up_write(&mm->mmap_sem);
23243+ }
23244+#endif
23245+
23246 tsk->thread.error_code = error_code;
23247 tsk->thread.trap_nr = X86_TRAP_GP;
23248
23249@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23250 /* It's safe to allow irq's after DR6 has been saved */
23251 preempt_conditional_sti(regs);
23252
23253- if (regs->flags & X86_VM_MASK) {
23254+ if (v8086_mode(regs)) {
23255 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23256 X86_TRAP_DB);
23257 preempt_conditional_cli(regs);
23258@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23259 * We already checked v86 mode above, so we can check for kernel mode
23260 * by just checking the CPL of CS.
23261 */
23262- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23263+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23264 tsk->thread.debugreg6 &= ~DR_STEP;
23265 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23266 regs->flags &= ~X86_EFLAGS_TF;
23267@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23268 return;
23269 conditional_sti(regs);
23270
23271- if (!user_mode_vm(regs))
23272+ if (!user_mode(regs))
23273 {
23274 if (!fixup_exception(regs)) {
23275 task->thread.error_code = error_code;
23276diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23277index c71025b..b117501 100644
23278--- a/arch/x86/kernel/uprobes.c
23279+++ b/arch/x86/kernel/uprobes.c
23280@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23281 int ret = NOTIFY_DONE;
23282
23283 /* We are only interested in userspace traps */
23284- if (regs && !user_mode_vm(regs))
23285+ if (regs && !user_mode(regs))
23286 return NOTIFY_DONE;
23287
23288 switch (val) {
23289diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23290index b9242ba..50c5edd 100644
23291--- a/arch/x86/kernel/verify_cpu.S
23292+++ b/arch/x86/kernel/verify_cpu.S
23293@@ -20,6 +20,7 @@
23294 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23295 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23296 * arch/x86/kernel/head_32.S: processor startup
23297+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23298 *
23299 * verify_cpu, returns the status of longmode and SSE in register %eax.
23300 * 0: Success 1: Failure
23301diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23302index 1dfe69c..a3df6f6 100644
23303--- a/arch/x86/kernel/vm86_32.c
23304+++ b/arch/x86/kernel/vm86_32.c
23305@@ -43,6 +43,7 @@
23306 #include <linux/ptrace.h>
23307 #include <linux/audit.h>
23308 #include <linux/stddef.h>
23309+#include <linux/grsecurity.h>
23310
23311 #include <asm/uaccess.h>
23312 #include <asm/io.h>
23313@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23314 do_exit(SIGSEGV);
23315 }
23316
23317- tss = &per_cpu(init_tss, get_cpu());
23318+ tss = init_tss + get_cpu();
23319 current->thread.sp0 = current->thread.saved_sp0;
23320 current->thread.sysenter_cs = __KERNEL_CS;
23321 load_sp0(tss, &current->thread);
23322@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23323 struct task_struct *tsk;
23324 int tmp, ret = -EPERM;
23325
23326+#ifdef CONFIG_GRKERNSEC_VM86
23327+ if (!capable(CAP_SYS_RAWIO)) {
23328+ gr_handle_vm86();
23329+ goto out;
23330+ }
23331+#endif
23332+
23333 tsk = current;
23334 if (tsk->thread.saved_sp0)
23335 goto out;
23336@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23337 int tmp, ret;
23338 struct vm86plus_struct __user *v86;
23339
23340+#ifdef CONFIG_GRKERNSEC_VM86
23341+ if (!capable(CAP_SYS_RAWIO)) {
23342+ gr_handle_vm86();
23343+ ret = -EPERM;
23344+ goto out;
23345+ }
23346+#endif
23347+
23348 tsk = current;
23349 switch (cmd) {
23350 case VM86_REQUEST_IRQ:
23351@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23352 tsk->thread.saved_fs = info->regs32->fs;
23353 tsk->thread.saved_gs = get_user_gs(info->regs32);
23354
23355- tss = &per_cpu(init_tss, get_cpu());
23356+ tss = init_tss + get_cpu();
23357 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23358 if (cpu_has_sep)
23359 tsk->thread.sysenter_cs = 0;
23360@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23361 goto cannot_handle;
23362 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23363 goto cannot_handle;
23364- intr_ptr = (unsigned long __user *) (i << 2);
23365+ intr_ptr = (__force unsigned long __user *) (i << 2);
23366 if (get_user(segoffs, intr_ptr))
23367 goto cannot_handle;
23368 if ((segoffs >> 16) == BIOSSEG)
23369diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23370index 22a1530..8fbaaad 100644
23371--- a/arch/x86/kernel/vmlinux.lds.S
23372+++ b/arch/x86/kernel/vmlinux.lds.S
23373@@ -26,6 +26,13 @@
23374 #include <asm/page_types.h>
23375 #include <asm/cache.h>
23376 #include <asm/boot.h>
23377+#include <asm/segment.h>
23378+
23379+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23380+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23381+#else
23382+#define __KERNEL_TEXT_OFFSET 0
23383+#endif
23384
23385 #undef i386 /* in case the preprocessor is a 32bit one */
23386
23387@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23388
23389 PHDRS {
23390 text PT_LOAD FLAGS(5); /* R_E */
23391+#ifdef CONFIG_X86_32
23392+ module PT_LOAD FLAGS(5); /* R_E */
23393+#endif
23394+#ifdef CONFIG_XEN
23395+ rodata PT_LOAD FLAGS(5); /* R_E */
23396+#else
23397+ rodata PT_LOAD FLAGS(4); /* R__ */
23398+#endif
23399 data PT_LOAD FLAGS(6); /* RW_ */
23400-#ifdef CONFIG_X86_64
23401+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23402 #ifdef CONFIG_SMP
23403 percpu PT_LOAD FLAGS(6); /* RW_ */
23404 #endif
23405+ text.init PT_LOAD FLAGS(5); /* R_E */
23406+ text.exit PT_LOAD FLAGS(5); /* R_E */
23407 init PT_LOAD FLAGS(7); /* RWE */
23408-#endif
23409 note PT_NOTE FLAGS(0); /* ___ */
23410 }
23411
23412 SECTIONS
23413 {
23414 #ifdef CONFIG_X86_32
23415- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23416- phys_startup_32 = startup_32 - LOAD_OFFSET;
23417+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23418 #else
23419- . = __START_KERNEL;
23420- phys_startup_64 = startup_64 - LOAD_OFFSET;
23421+ . = __START_KERNEL;
23422 #endif
23423
23424 /* Text and read-only data */
23425- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23426- _text = .;
23427+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23428 /* bootstrapping code */
23429+#ifdef CONFIG_X86_32
23430+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23431+#else
23432+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23433+#endif
23434+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23435+ _text = .;
23436 HEAD_TEXT
23437 #ifdef CONFIG_X86_32
23438 . = ALIGN(PAGE_SIZE);
23439@@ -108,13 +128,48 @@ SECTIONS
23440 IRQENTRY_TEXT
23441 *(.fixup)
23442 *(.gnu.warning)
23443- /* End of text section */
23444- _etext = .;
23445 } :text = 0x9090
23446
23447- NOTES :text :note
23448+ . += __KERNEL_TEXT_OFFSET;
23449
23450- EXCEPTION_TABLE(16) :text = 0x9090
23451+#ifdef CONFIG_X86_32
23452+ . = ALIGN(PAGE_SIZE);
23453+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23454+
23455+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23456+ MODULES_EXEC_VADDR = .;
23457+ BYTE(0)
23458+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23459+ . = ALIGN(HPAGE_SIZE) - 1;
23460+ MODULES_EXEC_END = .;
23461+#endif
23462+
23463+ } :module
23464+#endif
23465+
23466+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23467+ /* End of text section */
23468+ BYTE(0)
23469+ _etext = . - __KERNEL_TEXT_OFFSET;
23470+ }
23471+
23472+#ifdef CONFIG_X86_32
23473+ . = ALIGN(PAGE_SIZE);
23474+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23475+ *(.idt)
23476+ . = ALIGN(PAGE_SIZE);
23477+ *(.empty_zero_page)
23478+ *(.initial_pg_fixmap)
23479+ *(.initial_pg_pmd)
23480+ *(.initial_page_table)
23481+ *(.swapper_pg_dir)
23482+ } :rodata
23483+#endif
23484+
23485+ . = ALIGN(PAGE_SIZE);
23486+ NOTES :rodata :note
23487+
23488+ EXCEPTION_TABLE(16) :rodata
23489
23490 #if defined(CONFIG_DEBUG_RODATA)
23491 /* .text should occupy whole number of pages */
23492@@ -126,16 +181,20 @@ SECTIONS
23493
23494 /* Data */
23495 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23496+
23497+#ifdef CONFIG_PAX_KERNEXEC
23498+ . = ALIGN(HPAGE_SIZE);
23499+#else
23500+ . = ALIGN(PAGE_SIZE);
23501+#endif
23502+
23503 /* Start of data section */
23504 _sdata = .;
23505
23506 /* init_task */
23507 INIT_TASK_DATA(THREAD_SIZE)
23508
23509-#ifdef CONFIG_X86_32
23510- /* 32 bit has nosave before _edata */
23511 NOSAVE_DATA
23512-#endif
23513
23514 PAGE_ALIGNED_DATA(PAGE_SIZE)
23515
23516@@ -176,12 +235,19 @@ SECTIONS
23517 #endif /* CONFIG_X86_64 */
23518
23519 /* Init code and data - will be freed after init */
23520- . = ALIGN(PAGE_SIZE);
23521 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23522+ BYTE(0)
23523+
23524+#ifdef CONFIG_PAX_KERNEXEC
23525+ . = ALIGN(HPAGE_SIZE);
23526+#else
23527+ . = ALIGN(PAGE_SIZE);
23528+#endif
23529+
23530 __init_begin = .; /* paired with __init_end */
23531- }
23532+ } :init.begin
23533
23534-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23535+#ifdef CONFIG_SMP
23536 /*
23537 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23538 * output PHDR, so the next output section - .init.text - should
23539@@ -190,12 +256,27 @@ SECTIONS
23540 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23541 #endif
23542
23543- INIT_TEXT_SECTION(PAGE_SIZE)
23544-#ifdef CONFIG_X86_64
23545- :init
23546-#endif
23547+ . = ALIGN(PAGE_SIZE);
23548+ init_begin = .;
23549+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23550+ VMLINUX_SYMBOL(_sinittext) = .;
23551+ INIT_TEXT
23552+ VMLINUX_SYMBOL(_einittext) = .;
23553+ . = ALIGN(PAGE_SIZE);
23554+ } :text.init
23555
23556- INIT_DATA_SECTION(16)
23557+ /*
23558+ * .exit.text is discard at runtime, not link time, to deal with
23559+ * references from .altinstructions and .eh_frame
23560+ */
23561+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23562+ EXIT_TEXT
23563+ . = ALIGN(16);
23564+ } :text.exit
23565+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23566+
23567+ . = ALIGN(PAGE_SIZE);
23568+ INIT_DATA_SECTION(16) :init
23569
23570 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23571 __x86_cpu_dev_start = .;
23572@@ -257,19 +338,12 @@ SECTIONS
23573 }
23574
23575 . = ALIGN(8);
23576- /*
23577- * .exit.text is discard at runtime, not link time, to deal with
23578- * references from .altinstructions and .eh_frame
23579- */
23580- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23581- EXIT_TEXT
23582- }
23583
23584 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23585 EXIT_DATA
23586 }
23587
23588-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23589+#ifndef CONFIG_SMP
23590 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23591 #endif
23592
23593@@ -288,16 +362,10 @@ SECTIONS
23594 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23595 __smp_locks = .;
23596 *(.smp_locks)
23597- . = ALIGN(PAGE_SIZE);
23598 __smp_locks_end = .;
23599+ . = ALIGN(PAGE_SIZE);
23600 }
23601
23602-#ifdef CONFIG_X86_64
23603- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23604- NOSAVE_DATA
23605- }
23606-#endif
23607-
23608 /* BSS */
23609 . = ALIGN(PAGE_SIZE);
23610 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23611@@ -313,6 +381,7 @@ SECTIONS
23612 __brk_base = .;
23613 . += 64 * 1024; /* 64k alignment slop space */
23614 *(.brk_reservation) /* areas brk users have reserved */
23615+ . = ALIGN(HPAGE_SIZE);
23616 __brk_limit = .;
23617 }
23618
23619@@ -339,13 +408,12 @@ SECTIONS
23620 * for the boot processor.
23621 */
23622 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23623-INIT_PER_CPU(gdt_page);
23624 INIT_PER_CPU(irq_stack_union);
23625
23626 /*
23627 * Build-time check on the image size:
23628 */
23629-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23630+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23631 "kernel image bigger than KERNEL_IMAGE_SIZE");
23632
23633 #ifdef CONFIG_SMP
23634diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23635index 9a907a6..f83f921 100644
23636--- a/arch/x86/kernel/vsyscall_64.c
23637+++ b/arch/x86/kernel/vsyscall_64.c
23638@@ -56,15 +56,13 @@
23639 DEFINE_VVAR(int, vgetcpu_mode);
23640 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23641
23642-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23643+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23644
23645 static int __init vsyscall_setup(char *str)
23646 {
23647 if (str) {
23648 if (!strcmp("emulate", str))
23649 vsyscall_mode = EMULATE;
23650- else if (!strcmp("native", str))
23651- vsyscall_mode = NATIVE;
23652 else if (!strcmp("none", str))
23653 vsyscall_mode = NONE;
23654 else
23655@@ -323,8 +321,7 @@ do_ret:
23656 return true;
23657
23658 sigsegv:
23659- force_sig(SIGSEGV, current);
23660- return true;
23661+ do_group_exit(SIGKILL);
23662 }
23663
23664 /*
23665@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23666 extern char __vvar_page;
23667 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23668
23669- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23670- vsyscall_mode == NATIVE
23671- ? PAGE_KERNEL_VSYSCALL
23672- : PAGE_KERNEL_VVAR);
23673+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23674 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23675 (unsigned long)VSYSCALL_START);
23676
23677diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23678index 1330dd1..d220b99 100644
23679--- a/arch/x86/kernel/x8664_ksyms_64.c
23680+++ b/arch/x86/kernel/x8664_ksyms_64.c
23681@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23682 EXPORT_SYMBOL(copy_user_generic_unrolled);
23683 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23684 EXPORT_SYMBOL(__copy_user_nocache);
23685-EXPORT_SYMBOL(_copy_from_user);
23686-EXPORT_SYMBOL(_copy_to_user);
23687
23688 EXPORT_SYMBOL(copy_page);
23689 EXPORT_SYMBOL(clear_page);
23690diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23691index 7a3d075..6cb373d 100644
23692--- a/arch/x86/kernel/x86_init.c
23693+++ b/arch/x86/kernel/x86_init.c
23694@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23695 },
23696 };
23697
23698-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23699+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23700 .early_percpu_clock_init = x86_init_noop,
23701 .setup_percpu_clockev = setup_secondary_APIC_clock,
23702 };
23703@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23704 static void default_nmi_init(void) { };
23705 static int default_i8042_detect(void) { return 1; };
23706
23707-struct x86_platform_ops x86_platform = {
23708+struct x86_platform_ops x86_platform __read_only = {
23709 .calibrate_tsc = native_calibrate_tsc,
23710 .get_wallclock = mach_get_cmos_time,
23711 .set_wallclock = mach_set_rtc_mmss,
23712@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23713 };
23714
23715 EXPORT_SYMBOL_GPL(x86_platform);
23716-struct x86_msi_ops x86_msi = {
23717+struct x86_msi_ops x86_msi __read_only = {
23718 .setup_msi_irqs = native_setup_msi_irqs,
23719 .teardown_msi_irq = native_teardown_msi_irq,
23720 .teardown_msi_irqs = default_teardown_msi_irqs,
23721 .restore_msi_irqs = default_restore_msi_irqs,
23722 };
23723
23724-struct x86_io_apic_ops x86_io_apic_ops = {
23725+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23726 .init = native_io_apic_init_mappings,
23727 .read = native_io_apic_read,
23728 .write = native_io_apic_write,
23729diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23730index ada87a3..afea76d 100644
23731--- a/arch/x86/kernel/xsave.c
23732+++ b/arch/x86/kernel/xsave.c
23733@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23734 {
23735 int err;
23736
23737+ buf = (struct xsave_struct __user *)____m(buf);
23738 if (use_xsave())
23739 err = xsave_user(buf);
23740 else if (use_fxsr())
23741@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23742 */
23743 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23744 {
23745+ buf = (void __user *)____m(buf);
23746 if (use_xsave()) {
23747 if ((unsigned long)buf % 64 || fx_only) {
23748 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23749diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23750index a20ecb5..d0e2194 100644
23751--- a/arch/x86/kvm/cpuid.c
23752+++ b/arch/x86/kvm/cpuid.c
23753@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23754 struct kvm_cpuid2 *cpuid,
23755 struct kvm_cpuid_entry2 __user *entries)
23756 {
23757- int r;
23758+ int r, i;
23759
23760 r = -E2BIG;
23761 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23762 goto out;
23763 r = -EFAULT;
23764- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23765- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23766+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23767 goto out;
23768+ for (i = 0; i < cpuid->nent; ++i) {
23769+ struct kvm_cpuid_entry2 cpuid_entry;
23770+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23771+ goto out;
23772+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23773+ }
23774 vcpu->arch.cpuid_nent = cpuid->nent;
23775 kvm_apic_set_version(vcpu);
23776 kvm_x86_ops->cpuid_update(vcpu);
23777@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23778 struct kvm_cpuid2 *cpuid,
23779 struct kvm_cpuid_entry2 __user *entries)
23780 {
23781- int r;
23782+ int r, i;
23783
23784 r = -E2BIG;
23785 if (cpuid->nent < vcpu->arch.cpuid_nent)
23786 goto out;
23787 r = -EFAULT;
23788- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23789- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23790+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23791 goto out;
23792+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23793+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23794+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23795+ goto out;
23796+ }
23797 return 0;
23798
23799 out:
23800diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23801index a27e763..54bfe43 100644
23802--- a/arch/x86/kvm/emulate.c
23803+++ b/arch/x86/kvm/emulate.c
23804@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23805
23806 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23807 do { \
23808+ unsigned long _tmp; \
23809 __asm__ __volatile__ ( \
23810 _PRE_EFLAGS("0", "4", "2") \
23811 _op _suffix " %"_x"3,%1; " \
23812@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23813 /* Raw emulation: instruction has two explicit operands. */
23814 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23815 do { \
23816- unsigned long _tmp; \
23817- \
23818 switch ((ctxt)->dst.bytes) { \
23819 case 2: \
23820 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23821@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23822
23823 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23824 do { \
23825- unsigned long _tmp; \
23826 switch ((ctxt)->dst.bytes) { \
23827 case 1: \
23828 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23829diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23830index 9392f52..0e56d77 100644
23831--- a/arch/x86/kvm/lapic.c
23832+++ b/arch/x86/kvm/lapic.c
23833@@ -55,7 +55,7 @@
23834 #define APIC_BUS_CYCLE_NS 1
23835
23836 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23837-#define apic_debug(fmt, arg...)
23838+#define apic_debug(fmt, arg...) do {} while (0)
23839
23840 #define APIC_LVT_NUM 6
23841 /* 14 is the version for Xeon and Pentium 8.4.8*/
23842diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23843index 891eb6d..e027900 100644
23844--- a/arch/x86/kvm/paging_tmpl.h
23845+++ b/arch/x86/kvm/paging_tmpl.h
23846@@ -208,7 +208,7 @@ retry_walk:
23847 if (unlikely(kvm_is_error_hva(host_addr)))
23848 goto error;
23849
23850- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23851+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23852 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23853 goto error;
23854 walker->ptep_user[walker->level - 1] = ptep_user;
23855diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23856index d29d3cd..ec9d522 100644
23857--- a/arch/x86/kvm/svm.c
23858+++ b/arch/x86/kvm/svm.c
23859@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23860 int cpu = raw_smp_processor_id();
23861
23862 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23863+
23864+ pax_open_kernel();
23865 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23866+ pax_close_kernel();
23867+
23868 load_TR_desc();
23869 }
23870
23871@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23872 #endif
23873 #endif
23874
23875+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23876+ __set_fs(current_thread_info()->addr_limit);
23877+#endif
23878+
23879 reload_tss(vcpu);
23880
23881 local_irq_disable();
23882diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23883index 9120ae1..238abc0 100644
23884--- a/arch/x86/kvm/vmx.c
23885+++ b/arch/x86/kvm/vmx.c
23886@@ -1370,7 +1370,11 @@ static void reload_tss(void)
23887 struct desc_struct *descs;
23888
23889 descs = (void *)gdt->address;
23890+
23891+ pax_open_kernel();
23892 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23893+ pax_close_kernel();
23894+
23895 load_TR_desc();
23896 }
23897
23898@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23899 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23900 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23901
23902+#ifdef CONFIG_PAX_PER_CPU_PGD
23903+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23904+#endif
23905+
23906 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23907 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23908 vmx->loaded_vmcs->cpu = cpu;
23909@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23910 if (!cpu_has_vmx_flexpriority())
23911 flexpriority_enabled = 0;
23912
23913- if (!cpu_has_vmx_tpr_shadow())
23914- kvm_x86_ops->update_cr8_intercept = NULL;
23915+ if (!cpu_has_vmx_tpr_shadow()) {
23916+ pax_open_kernel();
23917+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23918+ pax_close_kernel();
23919+ }
23920
23921 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23922 kvm_disable_largepages();
23923@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23924
23925 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23926 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23927+
23928+#ifndef CONFIG_PAX_PER_CPU_PGD
23929 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23930+#endif
23931
23932 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23933 #ifdef CONFIG_X86_64
23934@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23935 native_store_idt(&dt);
23936 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23937
23938- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23939+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23940
23941 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23942 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23943@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23944 "jmp 2f \n\t"
23945 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23946 "2: "
23947+
23948+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23949+ "ljmp %[cs],$3f\n\t"
23950+ "3: "
23951+#endif
23952+
23953 /* Save guest registers, load host registers, keep flags */
23954 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23955 "pop %0 \n\t"
23956@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23957 #endif
23958 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23959 [wordsize]"i"(sizeof(ulong))
23960+
23961+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23962+ ,[cs]"i"(__KERNEL_CS)
23963+#endif
23964+
23965 : "cc", "memory"
23966 #ifdef CONFIG_X86_64
23967 , "rax", "rbx", "rdi", "rsi"
23968@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23969 if (debugctlmsr)
23970 update_debugctlmsr(debugctlmsr);
23971
23972-#ifndef CONFIG_X86_64
23973+#ifdef CONFIG_X86_32
23974 /*
23975 * The sysexit path does not restore ds/es, so we must set them to
23976 * a reasonable value ourselves.
23977@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23978 * may be executed in interrupt context, which saves and restore segments
23979 * around it, nullifying its effect.
23980 */
23981- loadsegment(ds, __USER_DS);
23982- loadsegment(es, __USER_DS);
23983+ loadsegment(ds, __KERNEL_DS);
23984+ loadsegment(es, __KERNEL_DS);
23985+ loadsegment(ss, __KERNEL_DS);
23986+
23987+#ifdef CONFIG_PAX_KERNEXEC
23988+ loadsegment(fs, __KERNEL_PERCPU);
23989+#endif
23990+
23991+#ifdef CONFIG_PAX_MEMORY_UDEREF
23992+ __set_fs(current_thread_info()->addr_limit);
23993+#endif
23994+
23995 #endif
23996
23997 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23998diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23999index c243b81..b692af3 100644
24000--- a/arch/x86/kvm/x86.c
24001+++ b/arch/x86/kvm/x86.c
24002@@ -1408,10 +1408,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24003 unsigned long flags, this_tsc_khz;
24004 struct kvm_vcpu_arch *vcpu = &v->arch;
24005 struct kvm_arch *ka = &v->kvm->arch;
24006- void *shared_kaddr;
24007 s64 kernel_ns, max_kernel_ns;
24008 u64 tsc_timestamp, host_tsc;
24009- struct pvclock_vcpu_time_info *guest_hv_clock;
24010+ struct pvclock_vcpu_time_info guest_hv_clock;
24011 u8 pvclock_flags;
24012 bool use_master_clock;
24013
24014@@ -1465,7 +1464,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24015
24016 local_irq_restore(flags);
24017
24018- if (!vcpu->time_page)
24019+ if (!vcpu->pv_time_enabled)
24020 return 0;
24021
24022 /*
24023@@ -1527,12 +1526,12 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24024 */
24025 vcpu->hv_clock.version += 2;
24026
24027- shared_kaddr = kmap_atomic(vcpu->time_page);
24028-
24029- guest_hv_clock = shared_kaddr + vcpu->time_offset;
24030+ if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
24031+ &guest_hv_clock, sizeof(guest_hv_clock))))
24032+ return 0;
24033
24034 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
24035- pvclock_flags = (guest_hv_clock->flags & PVCLOCK_GUEST_STOPPED);
24036+ pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);
24037
24038 if (vcpu->pvclock_set_guest_stopped_request) {
24039 pvclock_flags |= PVCLOCK_GUEST_STOPPED;
24040@@ -1545,12 +1544,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24041
24042 vcpu->hv_clock.flags = pvclock_flags;
24043
24044- memcpy(shared_kaddr + vcpu->time_offset, &vcpu->hv_clock,
24045- sizeof(vcpu->hv_clock));
24046-
24047- kunmap_atomic(shared_kaddr);
24048-
24049- mark_page_dirty(v->kvm, vcpu->time >> PAGE_SHIFT);
24050+ kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
24051+ &vcpu->hv_clock,
24052+ sizeof(vcpu->hv_clock));
24053 return 0;
24054 }
24055
24056@@ -1692,8 +1688,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24057 {
24058 struct kvm *kvm = vcpu->kvm;
24059 int lm = is_long_mode(vcpu);
24060- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24061- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24062+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24063+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24064 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24065 : kvm->arch.xen_hvm_config.blob_size_32;
24066 u32 page_num = data & ~PAGE_MASK;
24067@@ -1839,10 +1835,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
24068
24069 static void kvmclock_reset(struct kvm_vcpu *vcpu)
24070 {
24071- if (vcpu->arch.time_page) {
24072- kvm_release_page_dirty(vcpu->arch.time_page);
24073- vcpu->arch.time_page = NULL;
24074- }
24075+ vcpu->arch.pv_time_enabled = false;
24076 }
24077
24078 static void accumulate_steal_time(struct kvm_vcpu *vcpu)
24079@@ -1948,6 +1941,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24080 break;
24081 case MSR_KVM_SYSTEM_TIME_NEW:
24082 case MSR_KVM_SYSTEM_TIME: {
24083+ u64 gpa_offset;
24084 kvmclock_reset(vcpu);
24085
24086 vcpu->arch.time = data;
24087@@ -1957,14 +1951,17 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24088 if (!(data & 1))
24089 break;
24090
24091- /* ...but clean it before doing the actual write */
24092- vcpu->arch.time_offset = data & ~(PAGE_MASK | 1);
24093+ gpa_offset = data & ~(PAGE_MASK | 1);
24094
24095- vcpu->arch.time_page =
24096- gfn_to_page(vcpu->kvm, data >> PAGE_SHIFT);
24097+ /* Check that the address is 32-byte aligned. */
24098+ if (gpa_offset & (sizeof(struct pvclock_vcpu_time_info) - 1))
24099+ break;
24100
24101- if (is_error_page(vcpu->arch.time_page))
24102- vcpu->arch.time_page = NULL;
24103+ if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
24104+ &vcpu->arch.pv_time, data & ~1ULL))
24105+ vcpu->arch.pv_time_enabled = false;
24106+ else
24107+ vcpu->arch.pv_time_enabled = true;
24108
24109 break;
24110 }
24111@@ -2571,6 +2568,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24112 if (n < msr_list.nmsrs)
24113 goto out;
24114 r = -EFAULT;
24115+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24116+ goto out;
24117 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24118 num_msrs_to_save * sizeof(u32)))
24119 goto out;
24120@@ -2700,7 +2699,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24121 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24122 struct kvm_interrupt *irq)
24123 {
24124- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24125+ if (irq->irq >= KVM_NR_INTERRUPTS)
24126 return -EINVAL;
24127 if (irqchip_in_kernel(vcpu->kvm))
24128 return -ENXIO;
24129@@ -2967,7 +2966,7 @@ static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu,
24130 */
24131 static int kvm_set_guest_paused(struct kvm_vcpu *vcpu)
24132 {
24133- if (!vcpu->arch.time_page)
24134+ if (!vcpu->arch.pv_time_enabled)
24135 return -EINVAL;
24136 vcpu->arch.pvclock_set_guest_stopped_request = true;
24137 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
24138@@ -5213,7 +5212,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24139 };
24140 #endif
24141
24142-int kvm_arch_init(void *opaque)
24143+int kvm_arch_init(const void *opaque)
24144 {
24145 int r;
24146 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24147@@ -6661,6 +6660,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
24148 goto fail_free_wbinvd_dirty_mask;
24149
24150 vcpu->arch.ia32_tsc_adjust_msr = 0x0;
24151+ vcpu->arch.pv_time_enabled = false;
24152 kvm_async_pf_hash_reset(vcpu);
24153 kvm_pmu_init(vcpu);
24154
24155diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24156index df4176c..23ce092 100644
24157--- a/arch/x86/lguest/boot.c
24158+++ b/arch/x86/lguest/boot.c
24159@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24160 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24161 * Launcher to reboot us.
24162 */
24163-static void lguest_restart(char *reason)
24164+static __noreturn void lguest_restart(char *reason)
24165 {
24166 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24167+ BUG();
24168 }
24169
24170 /*G:050
24171diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24172index 00933d5..3a64af9 100644
24173--- a/arch/x86/lib/atomic64_386_32.S
24174+++ b/arch/x86/lib/atomic64_386_32.S
24175@@ -48,6 +48,10 @@ BEGIN(read)
24176 movl (v), %eax
24177 movl 4(v), %edx
24178 RET_ENDP
24179+BEGIN(read_unchecked)
24180+ movl (v), %eax
24181+ movl 4(v), %edx
24182+RET_ENDP
24183 #undef v
24184
24185 #define v %esi
24186@@ -55,6 +59,10 @@ BEGIN(set)
24187 movl %ebx, (v)
24188 movl %ecx, 4(v)
24189 RET_ENDP
24190+BEGIN(set_unchecked)
24191+ movl %ebx, (v)
24192+ movl %ecx, 4(v)
24193+RET_ENDP
24194 #undef v
24195
24196 #define v %esi
24197@@ -70,6 +78,20 @@ RET_ENDP
24198 BEGIN(add)
24199 addl %eax, (v)
24200 adcl %edx, 4(v)
24201+
24202+#ifdef CONFIG_PAX_REFCOUNT
24203+ jno 0f
24204+ subl %eax, (v)
24205+ sbbl %edx, 4(v)
24206+ int $4
24207+0:
24208+ _ASM_EXTABLE(0b, 0b)
24209+#endif
24210+
24211+RET_ENDP
24212+BEGIN(add_unchecked)
24213+ addl %eax, (v)
24214+ adcl %edx, 4(v)
24215 RET_ENDP
24216 #undef v
24217
24218@@ -77,6 +99,24 @@ RET_ENDP
24219 BEGIN(add_return)
24220 addl (v), %eax
24221 adcl 4(v), %edx
24222+
24223+#ifdef CONFIG_PAX_REFCOUNT
24224+ into
24225+1234:
24226+ _ASM_EXTABLE(1234b, 2f)
24227+#endif
24228+
24229+ movl %eax, (v)
24230+ movl %edx, 4(v)
24231+
24232+#ifdef CONFIG_PAX_REFCOUNT
24233+2:
24234+#endif
24235+
24236+RET_ENDP
24237+BEGIN(add_return_unchecked)
24238+ addl (v), %eax
24239+ adcl 4(v), %edx
24240 movl %eax, (v)
24241 movl %edx, 4(v)
24242 RET_ENDP
24243@@ -86,6 +126,20 @@ RET_ENDP
24244 BEGIN(sub)
24245 subl %eax, (v)
24246 sbbl %edx, 4(v)
24247+
24248+#ifdef CONFIG_PAX_REFCOUNT
24249+ jno 0f
24250+ addl %eax, (v)
24251+ adcl %edx, 4(v)
24252+ int $4
24253+0:
24254+ _ASM_EXTABLE(0b, 0b)
24255+#endif
24256+
24257+RET_ENDP
24258+BEGIN(sub_unchecked)
24259+ subl %eax, (v)
24260+ sbbl %edx, 4(v)
24261 RET_ENDP
24262 #undef v
24263
24264@@ -96,6 +150,27 @@ BEGIN(sub_return)
24265 sbbl $0, %edx
24266 addl (v), %eax
24267 adcl 4(v), %edx
24268+
24269+#ifdef CONFIG_PAX_REFCOUNT
24270+ into
24271+1234:
24272+ _ASM_EXTABLE(1234b, 2f)
24273+#endif
24274+
24275+ movl %eax, (v)
24276+ movl %edx, 4(v)
24277+
24278+#ifdef CONFIG_PAX_REFCOUNT
24279+2:
24280+#endif
24281+
24282+RET_ENDP
24283+BEGIN(sub_return_unchecked)
24284+ negl %edx
24285+ negl %eax
24286+ sbbl $0, %edx
24287+ addl (v), %eax
24288+ adcl 4(v), %edx
24289 movl %eax, (v)
24290 movl %edx, 4(v)
24291 RET_ENDP
24292@@ -105,6 +180,20 @@ RET_ENDP
24293 BEGIN(inc)
24294 addl $1, (v)
24295 adcl $0, 4(v)
24296+
24297+#ifdef CONFIG_PAX_REFCOUNT
24298+ jno 0f
24299+ subl $1, (v)
24300+ sbbl $0, 4(v)
24301+ int $4
24302+0:
24303+ _ASM_EXTABLE(0b, 0b)
24304+#endif
24305+
24306+RET_ENDP
24307+BEGIN(inc_unchecked)
24308+ addl $1, (v)
24309+ adcl $0, 4(v)
24310 RET_ENDP
24311 #undef v
24312
24313@@ -114,6 +203,26 @@ BEGIN(inc_return)
24314 movl 4(v), %edx
24315 addl $1, %eax
24316 adcl $0, %edx
24317+
24318+#ifdef CONFIG_PAX_REFCOUNT
24319+ into
24320+1234:
24321+ _ASM_EXTABLE(1234b, 2f)
24322+#endif
24323+
24324+ movl %eax, (v)
24325+ movl %edx, 4(v)
24326+
24327+#ifdef CONFIG_PAX_REFCOUNT
24328+2:
24329+#endif
24330+
24331+RET_ENDP
24332+BEGIN(inc_return_unchecked)
24333+ movl (v), %eax
24334+ movl 4(v), %edx
24335+ addl $1, %eax
24336+ adcl $0, %edx
24337 movl %eax, (v)
24338 movl %edx, 4(v)
24339 RET_ENDP
24340@@ -123,6 +232,20 @@ RET_ENDP
24341 BEGIN(dec)
24342 subl $1, (v)
24343 sbbl $0, 4(v)
24344+
24345+#ifdef CONFIG_PAX_REFCOUNT
24346+ jno 0f
24347+ addl $1, (v)
24348+ adcl $0, 4(v)
24349+ int $4
24350+0:
24351+ _ASM_EXTABLE(0b, 0b)
24352+#endif
24353+
24354+RET_ENDP
24355+BEGIN(dec_unchecked)
24356+ subl $1, (v)
24357+ sbbl $0, 4(v)
24358 RET_ENDP
24359 #undef v
24360
24361@@ -132,6 +255,26 @@ BEGIN(dec_return)
24362 movl 4(v), %edx
24363 subl $1, %eax
24364 sbbl $0, %edx
24365+
24366+#ifdef CONFIG_PAX_REFCOUNT
24367+ into
24368+1234:
24369+ _ASM_EXTABLE(1234b, 2f)
24370+#endif
24371+
24372+ movl %eax, (v)
24373+ movl %edx, 4(v)
24374+
24375+#ifdef CONFIG_PAX_REFCOUNT
24376+2:
24377+#endif
24378+
24379+RET_ENDP
24380+BEGIN(dec_return_unchecked)
24381+ movl (v), %eax
24382+ movl 4(v), %edx
24383+ subl $1, %eax
24384+ sbbl $0, %edx
24385 movl %eax, (v)
24386 movl %edx, 4(v)
24387 RET_ENDP
24388@@ -143,6 +286,13 @@ BEGIN(add_unless)
24389 adcl %edx, %edi
24390 addl (v), %eax
24391 adcl 4(v), %edx
24392+
24393+#ifdef CONFIG_PAX_REFCOUNT
24394+ into
24395+1234:
24396+ _ASM_EXTABLE(1234b, 2f)
24397+#endif
24398+
24399 cmpl %eax, %ecx
24400 je 3f
24401 1:
24402@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24403 1:
24404 addl $1, %eax
24405 adcl $0, %edx
24406+
24407+#ifdef CONFIG_PAX_REFCOUNT
24408+ into
24409+1234:
24410+ _ASM_EXTABLE(1234b, 2f)
24411+#endif
24412+
24413 movl %eax, (v)
24414 movl %edx, 4(v)
24415 movl $1, %eax
24416@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24417 movl 4(v), %edx
24418 subl $1, %eax
24419 sbbl $0, %edx
24420+
24421+#ifdef CONFIG_PAX_REFCOUNT
24422+ into
24423+1234:
24424+ _ASM_EXTABLE(1234b, 1f)
24425+#endif
24426+
24427 js 1f
24428 movl %eax, (v)
24429 movl %edx, 4(v)
24430diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24431index f5cc9eb..51fa319 100644
24432--- a/arch/x86/lib/atomic64_cx8_32.S
24433+++ b/arch/x86/lib/atomic64_cx8_32.S
24434@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24435 CFI_STARTPROC
24436
24437 read64 %ecx
24438+ pax_force_retaddr
24439 ret
24440 CFI_ENDPROC
24441 ENDPROC(atomic64_read_cx8)
24442
24443+ENTRY(atomic64_read_unchecked_cx8)
24444+ CFI_STARTPROC
24445+
24446+ read64 %ecx
24447+ pax_force_retaddr
24448+ ret
24449+ CFI_ENDPROC
24450+ENDPROC(atomic64_read_unchecked_cx8)
24451+
24452 ENTRY(atomic64_set_cx8)
24453 CFI_STARTPROC
24454
24455@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24456 cmpxchg8b (%esi)
24457 jne 1b
24458
24459+ pax_force_retaddr
24460 ret
24461 CFI_ENDPROC
24462 ENDPROC(atomic64_set_cx8)
24463
24464+ENTRY(atomic64_set_unchecked_cx8)
24465+ CFI_STARTPROC
24466+
24467+1:
24468+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24469+ * are atomic on 586 and newer */
24470+ cmpxchg8b (%esi)
24471+ jne 1b
24472+
24473+ pax_force_retaddr
24474+ ret
24475+ CFI_ENDPROC
24476+ENDPROC(atomic64_set_unchecked_cx8)
24477+
24478 ENTRY(atomic64_xchg_cx8)
24479 CFI_STARTPROC
24480
24481@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24482 cmpxchg8b (%esi)
24483 jne 1b
24484
24485+ pax_force_retaddr
24486 ret
24487 CFI_ENDPROC
24488 ENDPROC(atomic64_xchg_cx8)
24489
24490-.macro addsub_return func ins insc
24491-ENTRY(atomic64_\func\()_return_cx8)
24492+.macro addsub_return func ins insc unchecked=""
24493+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24494 CFI_STARTPROC
24495 SAVE ebp
24496 SAVE ebx
24497@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24498 movl %edx, %ecx
24499 \ins\()l %esi, %ebx
24500 \insc\()l %edi, %ecx
24501+
24502+.ifb \unchecked
24503+#ifdef CONFIG_PAX_REFCOUNT
24504+ into
24505+2:
24506+ _ASM_EXTABLE(2b, 3f)
24507+#endif
24508+.endif
24509+
24510 LOCK_PREFIX
24511 cmpxchg8b (%ebp)
24512 jne 1b
24513-
24514-10:
24515 movl %ebx, %eax
24516 movl %ecx, %edx
24517+
24518+.ifb \unchecked
24519+#ifdef CONFIG_PAX_REFCOUNT
24520+3:
24521+#endif
24522+.endif
24523+
24524 RESTORE edi
24525 RESTORE esi
24526 RESTORE ebx
24527 RESTORE ebp
24528+ pax_force_retaddr
24529 ret
24530 CFI_ENDPROC
24531-ENDPROC(atomic64_\func\()_return_cx8)
24532+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24533 .endm
24534
24535 addsub_return add add adc
24536 addsub_return sub sub sbb
24537+addsub_return add add adc _unchecked
24538+addsub_return sub sub sbb _unchecked
24539
24540-.macro incdec_return func ins insc
24541-ENTRY(atomic64_\func\()_return_cx8)
24542+.macro incdec_return func ins insc unchecked=""
24543+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24544 CFI_STARTPROC
24545 SAVE ebx
24546
24547@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24548 movl %edx, %ecx
24549 \ins\()l $1, %ebx
24550 \insc\()l $0, %ecx
24551+
24552+.ifb \unchecked
24553+#ifdef CONFIG_PAX_REFCOUNT
24554+ into
24555+2:
24556+ _ASM_EXTABLE(2b, 3f)
24557+#endif
24558+.endif
24559+
24560 LOCK_PREFIX
24561 cmpxchg8b (%esi)
24562 jne 1b
24563
24564-10:
24565 movl %ebx, %eax
24566 movl %ecx, %edx
24567+
24568+.ifb \unchecked
24569+#ifdef CONFIG_PAX_REFCOUNT
24570+3:
24571+#endif
24572+.endif
24573+
24574 RESTORE ebx
24575+ pax_force_retaddr
24576 ret
24577 CFI_ENDPROC
24578-ENDPROC(atomic64_\func\()_return_cx8)
24579+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24580 .endm
24581
24582 incdec_return inc add adc
24583 incdec_return dec sub sbb
24584+incdec_return inc add adc _unchecked
24585+incdec_return dec sub sbb _unchecked
24586
24587 ENTRY(atomic64_dec_if_positive_cx8)
24588 CFI_STARTPROC
24589@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24590 movl %edx, %ecx
24591 subl $1, %ebx
24592 sbb $0, %ecx
24593+
24594+#ifdef CONFIG_PAX_REFCOUNT
24595+ into
24596+1234:
24597+ _ASM_EXTABLE(1234b, 2f)
24598+#endif
24599+
24600 js 2f
24601 LOCK_PREFIX
24602 cmpxchg8b (%esi)
24603@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24604 movl %ebx, %eax
24605 movl %ecx, %edx
24606 RESTORE ebx
24607+ pax_force_retaddr
24608 ret
24609 CFI_ENDPROC
24610 ENDPROC(atomic64_dec_if_positive_cx8)
24611@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24612 movl %edx, %ecx
24613 addl %ebp, %ebx
24614 adcl %edi, %ecx
24615+
24616+#ifdef CONFIG_PAX_REFCOUNT
24617+ into
24618+1234:
24619+ _ASM_EXTABLE(1234b, 3f)
24620+#endif
24621+
24622 LOCK_PREFIX
24623 cmpxchg8b (%esi)
24624 jne 1b
24625@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24626 CFI_ADJUST_CFA_OFFSET -8
24627 RESTORE ebx
24628 RESTORE ebp
24629+ pax_force_retaddr
24630 ret
24631 4:
24632 cmpl %edx, 4(%esp)
24633@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24634 xorl %ecx, %ecx
24635 addl $1, %ebx
24636 adcl %edx, %ecx
24637+
24638+#ifdef CONFIG_PAX_REFCOUNT
24639+ into
24640+1234:
24641+ _ASM_EXTABLE(1234b, 3f)
24642+#endif
24643+
24644 LOCK_PREFIX
24645 cmpxchg8b (%esi)
24646 jne 1b
24647@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24648 movl $1, %eax
24649 3:
24650 RESTORE ebx
24651+ pax_force_retaddr
24652 ret
24653 CFI_ENDPROC
24654 ENDPROC(atomic64_inc_not_zero_cx8)
24655diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24656index 2af5df3..62b1a5a 100644
24657--- a/arch/x86/lib/checksum_32.S
24658+++ b/arch/x86/lib/checksum_32.S
24659@@ -29,7 +29,8 @@
24660 #include <asm/dwarf2.h>
24661 #include <asm/errno.h>
24662 #include <asm/asm.h>
24663-
24664+#include <asm/segment.h>
24665+
24666 /*
24667 * computes a partial checksum, e.g. for TCP/UDP fragments
24668 */
24669@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24670
24671 #define ARGBASE 16
24672 #define FP 12
24673-
24674-ENTRY(csum_partial_copy_generic)
24675+
24676+ENTRY(csum_partial_copy_generic_to_user)
24677 CFI_STARTPROC
24678+
24679+#ifdef CONFIG_PAX_MEMORY_UDEREF
24680+ pushl_cfi %gs
24681+ popl_cfi %es
24682+ jmp csum_partial_copy_generic
24683+#endif
24684+
24685+ENTRY(csum_partial_copy_generic_from_user)
24686+
24687+#ifdef CONFIG_PAX_MEMORY_UDEREF
24688+ pushl_cfi %gs
24689+ popl_cfi %ds
24690+#endif
24691+
24692+ENTRY(csum_partial_copy_generic)
24693 subl $4,%esp
24694 CFI_ADJUST_CFA_OFFSET 4
24695 pushl_cfi %edi
24696@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24697 jmp 4f
24698 SRC(1: movw (%esi), %bx )
24699 addl $2, %esi
24700-DST( movw %bx, (%edi) )
24701+DST( movw %bx, %es:(%edi) )
24702 addl $2, %edi
24703 addw %bx, %ax
24704 adcl $0, %eax
24705@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24706 SRC(1: movl (%esi), %ebx )
24707 SRC( movl 4(%esi), %edx )
24708 adcl %ebx, %eax
24709-DST( movl %ebx, (%edi) )
24710+DST( movl %ebx, %es:(%edi) )
24711 adcl %edx, %eax
24712-DST( movl %edx, 4(%edi) )
24713+DST( movl %edx, %es:4(%edi) )
24714
24715 SRC( movl 8(%esi), %ebx )
24716 SRC( movl 12(%esi), %edx )
24717 adcl %ebx, %eax
24718-DST( movl %ebx, 8(%edi) )
24719+DST( movl %ebx, %es:8(%edi) )
24720 adcl %edx, %eax
24721-DST( movl %edx, 12(%edi) )
24722+DST( movl %edx, %es:12(%edi) )
24723
24724 SRC( movl 16(%esi), %ebx )
24725 SRC( movl 20(%esi), %edx )
24726 adcl %ebx, %eax
24727-DST( movl %ebx, 16(%edi) )
24728+DST( movl %ebx, %es:16(%edi) )
24729 adcl %edx, %eax
24730-DST( movl %edx, 20(%edi) )
24731+DST( movl %edx, %es:20(%edi) )
24732
24733 SRC( movl 24(%esi), %ebx )
24734 SRC( movl 28(%esi), %edx )
24735 adcl %ebx, %eax
24736-DST( movl %ebx, 24(%edi) )
24737+DST( movl %ebx, %es:24(%edi) )
24738 adcl %edx, %eax
24739-DST( movl %edx, 28(%edi) )
24740+DST( movl %edx, %es:28(%edi) )
24741
24742 lea 32(%esi), %esi
24743 lea 32(%edi), %edi
24744@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24745 shrl $2, %edx # This clears CF
24746 SRC(3: movl (%esi), %ebx )
24747 adcl %ebx, %eax
24748-DST( movl %ebx, (%edi) )
24749+DST( movl %ebx, %es:(%edi) )
24750 lea 4(%esi), %esi
24751 lea 4(%edi), %edi
24752 dec %edx
24753@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24754 jb 5f
24755 SRC( movw (%esi), %cx )
24756 leal 2(%esi), %esi
24757-DST( movw %cx, (%edi) )
24758+DST( movw %cx, %es:(%edi) )
24759 leal 2(%edi), %edi
24760 je 6f
24761 shll $16,%ecx
24762 SRC(5: movb (%esi), %cl )
24763-DST( movb %cl, (%edi) )
24764+DST( movb %cl, %es:(%edi) )
24765 6: addl %ecx, %eax
24766 adcl $0, %eax
24767 7:
24768@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24769
24770 6001:
24771 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24772- movl $-EFAULT, (%ebx)
24773+ movl $-EFAULT, %ss:(%ebx)
24774
24775 # zero the complete destination - computing the rest
24776 # is too much work
24777@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24778
24779 6002:
24780 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24781- movl $-EFAULT,(%ebx)
24782+ movl $-EFAULT,%ss:(%ebx)
24783 jmp 5000b
24784
24785 .previous
24786
24787+ pushl_cfi %ss
24788+ popl_cfi %ds
24789+ pushl_cfi %ss
24790+ popl_cfi %es
24791 popl_cfi %ebx
24792 CFI_RESTORE ebx
24793 popl_cfi %esi
24794@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24795 popl_cfi %ecx # equivalent to addl $4,%esp
24796 ret
24797 CFI_ENDPROC
24798-ENDPROC(csum_partial_copy_generic)
24799+ENDPROC(csum_partial_copy_generic_to_user)
24800
24801 #else
24802
24803 /* Version for PentiumII/PPro */
24804
24805 #define ROUND1(x) \
24806+ nop; nop; nop; \
24807 SRC(movl x(%esi), %ebx ) ; \
24808 addl %ebx, %eax ; \
24809- DST(movl %ebx, x(%edi) ) ;
24810+ DST(movl %ebx, %es:x(%edi)) ;
24811
24812 #define ROUND(x) \
24813+ nop; nop; nop; \
24814 SRC(movl x(%esi), %ebx ) ; \
24815 adcl %ebx, %eax ; \
24816- DST(movl %ebx, x(%edi) ) ;
24817+ DST(movl %ebx, %es:x(%edi)) ;
24818
24819 #define ARGBASE 12
24820-
24821-ENTRY(csum_partial_copy_generic)
24822+
24823+ENTRY(csum_partial_copy_generic_to_user)
24824 CFI_STARTPROC
24825+
24826+#ifdef CONFIG_PAX_MEMORY_UDEREF
24827+ pushl_cfi %gs
24828+ popl_cfi %es
24829+ jmp csum_partial_copy_generic
24830+#endif
24831+
24832+ENTRY(csum_partial_copy_generic_from_user)
24833+
24834+#ifdef CONFIG_PAX_MEMORY_UDEREF
24835+ pushl_cfi %gs
24836+ popl_cfi %ds
24837+#endif
24838+
24839+ENTRY(csum_partial_copy_generic)
24840 pushl_cfi %ebx
24841 CFI_REL_OFFSET ebx, 0
24842 pushl_cfi %edi
24843@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24844 subl %ebx, %edi
24845 lea -1(%esi),%edx
24846 andl $-32,%edx
24847- lea 3f(%ebx,%ebx), %ebx
24848+ lea 3f(%ebx,%ebx,2), %ebx
24849 testl %esi, %esi
24850 jmp *%ebx
24851 1: addl $64,%esi
24852@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24853 jb 5f
24854 SRC( movw (%esi), %dx )
24855 leal 2(%esi), %esi
24856-DST( movw %dx, (%edi) )
24857+DST( movw %dx, %es:(%edi) )
24858 leal 2(%edi), %edi
24859 je 6f
24860 shll $16,%edx
24861 5:
24862 SRC( movb (%esi), %dl )
24863-DST( movb %dl, (%edi) )
24864+DST( movb %dl, %es:(%edi) )
24865 6: addl %edx, %eax
24866 adcl $0, %eax
24867 7:
24868 .section .fixup, "ax"
24869 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24870- movl $-EFAULT, (%ebx)
24871+ movl $-EFAULT, %ss:(%ebx)
24872 # zero the complete destination (computing the rest is too much work)
24873 movl ARGBASE+8(%esp),%edi # dst
24874 movl ARGBASE+12(%esp),%ecx # len
24875@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24876 rep; stosb
24877 jmp 7b
24878 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24879- movl $-EFAULT, (%ebx)
24880+ movl $-EFAULT, %ss:(%ebx)
24881 jmp 7b
24882 .previous
24883
24884+#ifdef CONFIG_PAX_MEMORY_UDEREF
24885+ pushl_cfi %ss
24886+ popl_cfi %ds
24887+ pushl_cfi %ss
24888+ popl_cfi %es
24889+#endif
24890+
24891 popl_cfi %esi
24892 CFI_RESTORE esi
24893 popl_cfi %edi
24894@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24895 CFI_RESTORE ebx
24896 ret
24897 CFI_ENDPROC
24898-ENDPROC(csum_partial_copy_generic)
24899+ENDPROC(csum_partial_copy_generic_to_user)
24900
24901 #undef ROUND
24902 #undef ROUND1
24903diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24904index f2145cf..cea889d 100644
24905--- a/arch/x86/lib/clear_page_64.S
24906+++ b/arch/x86/lib/clear_page_64.S
24907@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24908 movl $4096/8,%ecx
24909 xorl %eax,%eax
24910 rep stosq
24911+ pax_force_retaddr
24912 ret
24913 CFI_ENDPROC
24914 ENDPROC(clear_page_c)
24915@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24916 movl $4096,%ecx
24917 xorl %eax,%eax
24918 rep stosb
24919+ pax_force_retaddr
24920 ret
24921 CFI_ENDPROC
24922 ENDPROC(clear_page_c_e)
24923@@ -43,6 +45,7 @@ ENTRY(clear_page)
24924 leaq 64(%rdi),%rdi
24925 jnz .Lloop
24926 nop
24927+ pax_force_retaddr
24928 ret
24929 CFI_ENDPROC
24930 .Lclear_page_end:
24931@@ -58,7 +61,7 @@ ENDPROC(clear_page)
24932
24933 #include <asm/cpufeature.h>
24934
24935- .section .altinstr_replacement,"ax"
24936+ .section .altinstr_replacement,"a"
24937 1: .byte 0xeb /* jmp <disp8> */
24938 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24939 2: .byte 0xeb /* jmp <disp8> */
24940diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24941index 1e572c5..2a162cd 100644
24942--- a/arch/x86/lib/cmpxchg16b_emu.S
24943+++ b/arch/x86/lib/cmpxchg16b_emu.S
24944@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24945
24946 popf
24947 mov $1, %al
24948+ pax_force_retaddr
24949 ret
24950
24951 not_same:
24952 popf
24953 xor %al,%al
24954+ pax_force_retaddr
24955 ret
24956
24957 CFI_ENDPROC
24958diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24959index 176cca6..1166c50 100644
24960--- a/arch/x86/lib/copy_page_64.S
24961+++ b/arch/x86/lib/copy_page_64.S
24962@@ -9,6 +9,7 @@ copy_page_rep:
24963 CFI_STARTPROC
24964 movl $4096/8, %ecx
24965 rep movsq
24966+ pax_force_retaddr
24967 ret
24968 CFI_ENDPROC
24969 ENDPROC(copy_page_rep)
24970@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24971
24972 ENTRY(copy_page)
24973 CFI_STARTPROC
24974- subq $2*8, %rsp
24975- CFI_ADJUST_CFA_OFFSET 2*8
24976+ subq $3*8, %rsp
24977+ CFI_ADJUST_CFA_OFFSET 3*8
24978 movq %rbx, (%rsp)
24979 CFI_REL_OFFSET rbx, 0
24980 movq %r12, 1*8(%rsp)
24981 CFI_REL_OFFSET r12, 1*8
24982+ movq %r13, 2*8(%rsp)
24983+ CFI_REL_OFFSET r13, 2*8
24984
24985 movl $(4096/64)-5, %ecx
24986 .p2align 4
24987@@ -36,7 +39,7 @@ ENTRY(copy_page)
24988 movq 0x8*2(%rsi), %rdx
24989 movq 0x8*3(%rsi), %r8
24990 movq 0x8*4(%rsi), %r9
24991- movq 0x8*5(%rsi), %r10
24992+ movq 0x8*5(%rsi), %r13
24993 movq 0x8*6(%rsi), %r11
24994 movq 0x8*7(%rsi), %r12
24995
24996@@ -47,7 +50,7 @@ ENTRY(copy_page)
24997 movq %rdx, 0x8*2(%rdi)
24998 movq %r8, 0x8*3(%rdi)
24999 movq %r9, 0x8*4(%rdi)
25000- movq %r10, 0x8*5(%rdi)
25001+ movq %r13, 0x8*5(%rdi)
25002 movq %r11, 0x8*6(%rdi)
25003 movq %r12, 0x8*7(%rdi)
25004
25005@@ -66,7 +69,7 @@ ENTRY(copy_page)
25006 movq 0x8*2(%rsi), %rdx
25007 movq 0x8*3(%rsi), %r8
25008 movq 0x8*4(%rsi), %r9
25009- movq 0x8*5(%rsi), %r10
25010+ movq 0x8*5(%rsi), %r13
25011 movq 0x8*6(%rsi), %r11
25012 movq 0x8*7(%rsi), %r12
25013
25014@@ -75,7 +78,7 @@ ENTRY(copy_page)
25015 movq %rdx, 0x8*2(%rdi)
25016 movq %r8, 0x8*3(%rdi)
25017 movq %r9, 0x8*4(%rdi)
25018- movq %r10, 0x8*5(%rdi)
25019+ movq %r13, 0x8*5(%rdi)
25020 movq %r11, 0x8*6(%rdi)
25021 movq %r12, 0x8*7(%rdi)
25022
25023@@ -87,8 +90,11 @@ ENTRY(copy_page)
25024 CFI_RESTORE rbx
25025 movq 1*8(%rsp), %r12
25026 CFI_RESTORE r12
25027- addq $2*8, %rsp
25028- CFI_ADJUST_CFA_OFFSET -2*8
25029+ movq 2*8(%rsp), %r13
25030+ CFI_RESTORE r13
25031+ addq $3*8, %rsp
25032+ CFI_ADJUST_CFA_OFFSET -3*8
25033+ pax_force_retaddr
25034 ret
25035 .Lcopy_page_end:
25036 CFI_ENDPROC
25037@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25038
25039 #include <asm/cpufeature.h>
25040
25041- .section .altinstr_replacement,"ax"
25042+ .section .altinstr_replacement,"a"
25043 1: .byte 0xeb /* jmp <disp8> */
25044 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25045 2:
25046diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25047index a30ca15..d25fab6 100644
25048--- a/arch/x86/lib/copy_user_64.S
25049+++ b/arch/x86/lib/copy_user_64.S
25050@@ -18,6 +18,7 @@
25051 #include <asm/alternative-asm.h>
25052 #include <asm/asm.h>
25053 #include <asm/smap.h>
25054+#include <asm/pgtable.h>
25055
25056 /*
25057 * By placing feature2 after feature1 in altinstructions section, we logically
25058@@ -31,7 +32,7 @@
25059 .byte 0xe9 /* 32bit jump */
25060 .long \orig-1f /* by default jump to orig */
25061 1:
25062- .section .altinstr_replacement,"ax"
25063+ .section .altinstr_replacement,"a"
25064 2: .byte 0xe9 /* near jump with 32bit immediate */
25065 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25066 3: .byte 0xe9 /* near jump with 32bit immediate */
25067@@ -70,47 +71,20 @@
25068 #endif
25069 .endm
25070
25071-/* Standard copy_to_user with segment limit checking */
25072-ENTRY(_copy_to_user)
25073- CFI_STARTPROC
25074- GET_THREAD_INFO(%rax)
25075- movq %rdi,%rcx
25076- addq %rdx,%rcx
25077- jc bad_to_user
25078- cmpq TI_addr_limit(%rax),%rcx
25079- ja bad_to_user
25080- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25081- copy_user_generic_unrolled,copy_user_generic_string, \
25082- copy_user_enhanced_fast_string
25083- CFI_ENDPROC
25084-ENDPROC(_copy_to_user)
25085-
25086-/* Standard copy_from_user with segment limit checking */
25087-ENTRY(_copy_from_user)
25088- CFI_STARTPROC
25089- GET_THREAD_INFO(%rax)
25090- movq %rsi,%rcx
25091- addq %rdx,%rcx
25092- jc bad_from_user
25093- cmpq TI_addr_limit(%rax),%rcx
25094- ja bad_from_user
25095- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25096- copy_user_generic_unrolled,copy_user_generic_string, \
25097- copy_user_enhanced_fast_string
25098- CFI_ENDPROC
25099-ENDPROC(_copy_from_user)
25100-
25101 .section .fixup,"ax"
25102 /* must zero dest */
25103 ENTRY(bad_from_user)
25104 bad_from_user:
25105 CFI_STARTPROC
25106+ testl %edx,%edx
25107+ js bad_to_user
25108 movl %edx,%ecx
25109 xorl %eax,%eax
25110 rep
25111 stosb
25112 bad_to_user:
25113 movl %edx,%eax
25114+ pax_force_retaddr
25115 ret
25116 CFI_ENDPROC
25117 ENDPROC(bad_from_user)
25118@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25119 jz 17f
25120 1: movq (%rsi),%r8
25121 2: movq 1*8(%rsi),%r9
25122-3: movq 2*8(%rsi),%r10
25123+3: movq 2*8(%rsi),%rax
25124 4: movq 3*8(%rsi),%r11
25125 5: movq %r8,(%rdi)
25126 6: movq %r9,1*8(%rdi)
25127-7: movq %r10,2*8(%rdi)
25128+7: movq %rax,2*8(%rdi)
25129 8: movq %r11,3*8(%rdi)
25130 9: movq 4*8(%rsi),%r8
25131 10: movq 5*8(%rsi),%r9
25132-11: movq 6*8(%rsi),%r10
25133+11: movq 6*8(%rsi),%rax
25134 12: movq 7*8(%rsi),%r11
25135 13: movq %r8,4*8(%rdi)
25136 14: movq %r9,5*8(%rdi)
25137-15: movq %r10,6*8(%rdi)
25138+15: movq %rax,6*8(%rdi)
25139 16: movq %r11,7*8(%rdi)
25140 leaq 64(%rsi),%rsi
25141 leaq 64(%rdi),%rdi
25142@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25143 jnz 21b
25144 23: xor %eax,%eax
25145 ASM_CLAC
25146+ pax_force_retaddr
25147 ret
25148
25149 .section .fixup,"ax"
25150@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25151 movsb
25152 4: xorl %eax,%eax
25153 ASM_CLAC
25154+ pax_force_retaddr
25155 ret
25156
25157 .section .fixup,"ax"
25158@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25159 movsb
25160 2: xorl %eax,%eax
25161 ASM_CLAC
25162+ pax_force_retaddr
25163 ret
25164
25165 .section .fixup,"ax"
25166diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25167index 6a4f43c..f5f9e26 100644
25168--- a/arch/x86/lib/copy_user_nocache_64.S
25169+++ b/arch/x86/lib/copy_user_nocache_64.S
25170@@ -8,6 +8,7 @@
25171
25172 #include <linux/linkage.h>
25173 #include <asm/dwarf2.h>
25174+#include <asm/alternative-asm.h>
25175
25176 #define FIX_ALIGNMENT 1
25177
25178@@ -16,6 +17,7 @@
25179 #include <asm/thread_info.h>
25180 #include <asm/asm.h>
25181 #include <asm/smap.h>
25182+#include <asm/pgtable.h>
25183
25184 .macro ALIGN_DESTINATION
25185 #ifdef FIX_ALIGNMENT
25186@@ -49,6 +51,15 @@
25187 */
25188 ENTRY(__copy_user_nocache)
25189 CFI_STARTPROC
25190+
25191+#ifdef CONFIG_PAX_MEMORY_UDEREF
25192+ mov $PAX_USER_SHADOW_BASE,%rcx
25193+ cmp %rcx,%rsi
25194+ jae 1f
25195+ add %rcx,%rsi
25196+1:
25197+#endif
25198+
25199 ASM_STAC
25200 cmpl $8,%edx
25201 jb 20f /* less then 8 bytes, go to byte copy loop */
25202@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25203 jz 17f
25204 1: movq (%rsi),%r8
25205 2: movq 1*8(%rsi),%r9
25206-3: movq 2*8(%rsi),%r10
25207+3: movq 2*8(%rsi),%rax
25208 4: movq 3*8(%rsi),%r11
25209 5: movnti %r8,(%rdi)
25210 6: movnti %r9,1*8(%rdi)
25211-7: movnti %r10,2*8(%rdi)
25212+7: movnti %rax,2*8(%rdi)
25213 8: movnti %r11,3*8(%rdi)
25214 9: movq 4*8(%rsi),%r8
25215 10: movq 5*8(%rsi),%r9
25216-11: movq 6*8(%rsi),%r10
25217+11: movq 6*8(%rsi),%rax
25218 12: movq 7*8(%rsi),%r11
25219 13: movnti %r8,4*8(%rdi)
25220 14: movnti %r9,5*8(%rdi)
25221-15: movnti %r10,6*8(%rdi)
25222+15: movnti %rax,6*8(%rdi)
25223 16: movnti %r11,7*8(%rdi)
25224 leaq 64(%rsi),%rsi
25225 leaq 64(%rdi),%rdi
25226@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25227 23: xorl %eax,%eax
25228 ASM_CLAC
25229 sfence
25230+ pax_force_retaddr
25231 ret
25232
25233 .section .fixup,"ax"
25234diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25235index 2419d5f..953ee51 100644
25236--- a/arch/x86/lib/csum-copy_64.S
25237+++ b/arch/x86/lib/csum-copy_64.S
25238@@ -9,6 +9,7 @@
25239 #include <asm/dwarf2.h>
25240 #include <asm/errno.h>
25241 #include <asm/asm.h>
25242+#include <asm/alternative-asm.h>
25243
25244 /*
25245 * Checksum copy with exception handling.
25246@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25247 CFI_RESTORE rbp
25248 addq $7*8, %rsp
25249 CFI_ADJUST_CFA_OFFSET -7*8
25250+ pax_force_retaddr 0, 1
25251 ret
25252 CFI_RESTORE_STATE
25253
25254diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25255index 25b7ae8..169fafc 100644
25256--- a/arch/x86/lib/csum-wrappers_64.c
25257+++ b/arch/x86/lib/csum-wrappers_64.c
25258@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25259 len -= 2;
25260 }
25261 }
25262- isum = csum_partial_copy_generic((__force const void *)src,
25263+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25264 dst, len, isum, errp, NULL);
25265 if (unlikely(*errp))
25266 goto out_err;
25267@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25268 }
25269
25270 *errp = 0;
25271- return csum_partial_copy_generic(src, (void __force *)dst,
25272+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25273 len, isum, NULL, errp);
25274 }
25275 EXPORT_SYMBOL(csum_partial_copy_to_user);
25276diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25277index 156b9c8..b144132 100644
25278--- a/arch/x86/lib/getuser.S
25279+++ b/arch/x86/lib/getuser.S
25280@@ -34,17 +34,40 @@
25281 #include <asm/thread_info.h>
25282 #include <asm/asm.h>
25283 #include <asm/smap.h>
25284+#include <asm/segment.h>
25285+#include <asm/pgtable.h>
25286+#include <asm/alternative-asm.h>
25287+
25288+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25289+#define __copyuser_seg gs;
25290+#else
25291+#define __copyuser_seg
25292+#endif
25293
25294 .text
25295 ENTRY(__get_user_1)
25296 CFI_STARTPROC
25297+
25298+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25299 GET_THREAD_INFO(%_ASM_DX)
25300 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25301 jae bad_get_user
25302 ASM_STAC
25303-1: movzb (%_ASM_AX),%edx
25304+
25305+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25306+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25307+ cmp %_ASM_DX,%_ASM_AX
25308+ jae 1234f
25309+ add %_ASM_DX,%_ASM_AX
25310+1234:
25311+#endif
25312+
25313+#endif
25314+
25315+1: __copyuser_seg movzb (%_ASM_AX),%edx
25316 xor %eax,%eax
25317 ASM_CLAC
25318+ pax_force_retaddr
25319 ret
25320 CFI_ENDPROC
25321 ENDPROC(__get_user_1)
25322@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
25323 ENTRY(__get_user_2)
25324 CFI_STARTPROC
25325 add $1,%_ASM_AX
25326+
25327+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25328 jc bad_get_user
25329 GET_THREAD_INFO(%_ASM_DX)
25330 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25331 jae bad_get_user
25332 ASM_STAC
25333-2: movzwl -1(%_ASM_AX),%edx
25334+
25335+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25336+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25337+ cmp %_ASM_DX,%_ASM_AX
25338+ jae 1234f
25339+ add %_ASM_DX,%_ASM_AX
25340+1234:
25341+#endif
25342+
25343+#endif
25344+
25345+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25346 xor %eax,%eax
25347 ASM_CLAC
25348+ pax_force_retaddr
25349 ret
25350 CFI_ENDPROC
25351 ENDPROC(__get_user_2)
25352@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
25353 ENTRY(__get_user_4)
25354 CFI_STARTPROC
25355 add $3,%_ASM_AX
25356+
25357+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25358 jc bad_get_user
25359 GET_THREAD_INFO(%_ASM_DX)
25360 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25361 jae bad_get_user
25362 ASM_STAC
25363-3: mov -3(%_ASM_AX),%edx
25364+
25365+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25366+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25367+ cmp %_ASM_DX,%_ASM_AX
25368+ jae 1234f
25369+ add %_ASM_DX,%_ASM_AX
25370+1234:
25371+#endif
25372+
25373+#endif
25374+
25375+3: __copyuser_seg mov -3(%_ASM_AX),%edx
25376 xor %eax,%eax
25377 ASM_CLAC
25378+ pax_force_retaddr
25379 ret
25380 CFI_ENDPROC
25381 ENDPROC(__get_user_4)
25382@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25383 GET_THREAD_INFO(%_ASM_DX)
25384 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25385 jae bad_get_user
25386+
25387+#ifdef CONFIG_PAX_MEMORY_UDEREF
25388+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25389+ cmp %_ASM_DX,%_ASM_AX
25390+ jae 1234f
25391+ add %_ASM_DX,%_ASM_AX
25392+1234:
25393+#endif
25394+
25395 ASM_STAC
25396 4: movq -7(%_ASM_AX),%_ASM_DX
25397 xor %eax,%eax
25398 ASM_CLAC
25399+ pax_force_retaddr
25400 ret
25401 CFI_ENDPROC
25402 ENDPROC(__get_user_8)
25403@@ -101,6 +162,7 @@ bad_get_user:
25404 xor %edx,%edx
25405 mov $(-EFAULT),%_ASM_AX
25406 ASM_CLAC
25407+ pax_force_retaddr
25408 ret
25409 CFI_ENDPROC
25410 END(bad_get_user)
25411diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25412index 54fcffe..7be149e 100644
25413--- a/arch/x86/lib/insn.c
25414+++ b/arch/x86/lib/insn.c
25415@@ -20,8 +20,10 @@
25416
25417 #ifdef __KERNEL__
25418 #include <linux/string.h>
25419+#include <asm/pgtable_types.h>
25420 #else
25421 #include <string.h>
25422+#define ktla_ktva(addr) addr
25423 #endif
25424 #include <asm/inat.h>
25425 #include <asm/insn.h>
25426@@ -53,8 +55,8 @@
25427 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25428 {
25429 memset(insn, 0, sizeof(*insn));
25430- insn->kaddr = kaddr;
25431- insn->next_byte = kaddr;
25432+ insn->kaddr = ktla_ktva(kaddr);
25433+ insn->next_byte = ktla_ktva(kaddr);
25434 insn->x86_64 = x86_64 ? 1 : 0;
25435 insn->opnd_bytes = 4;
25436 if (x86_64)
25437diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25438index 05a95e7..326f2fa 100644
25439--- a/arch/x86/lib/iomap_copy_64.S
25440+++ b/arch/x86/lib/iomap_copy_64.S
25441@@ -17,6 +17,7 @@
25442
25443 #include <linux/linkage.h>
25444 #include <asm/dwarf2.h>
25445+#include <asm/alternative-asm.h>
25446
25447 /*
25448 * override generic version in lib/iomap_copy.c
25449@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25450 CFI_STARTPROC
25451 movl %edx,%ecx
25452 rep movsd
25453+ pax_force_retaddr
25454 ret
25455 CFI_ENDPROC
25456 ENDPROC(__iowrite32_copy)
25457diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25458index 1c273be..da9cc0e 100644
25459--- a/arch/x86/lib/memcpy_64.S
25460+++ b/arch/x86/lib/memcpy_64.S
25461@@ -33,6 +33,7 @@
25462 rep movsq
25463 movl %edx, %ecx
25464 rep movsb
25465+ pax_force_retaddr
25466 ret
25467 .Lmemcpy_e:
25468 .previous
25469@@ -49,6 +50,7 @@
25470 movq %rdi, %rax
25471 movq %rdx, %rcx
25472 rep movsb
25473+ pax_force_retaddr
25474 ret
25475 .Lmemcpy_e_e:
25476 .previous
25477@@ -76,13 +78,13 @@ ENTRY(memcpy)
25478 */
25479 movq 0*8(%rsi), %r8
25480 movq 1*8(%rsi), %r9
25481- movq 2*8(%rsi), %r10
25482+ movq 2*8(%rsi), %rcx
25483 movq 3*8(%rsi), %r11
25484 leaq 4*8(%rsi), %rsi
25485
25486 movq %r8, 0*8(%rdi)
25487 movq %r9, 1*8(%rdi)
25488- movq %r10, 2*8(%rdi)
25489+ movq %rcx, 2*8(%rdi)
25490 movq %r11, 3*8(%rdi)
25491 leaq 4*8(%rdi), %rdi
25492 jae .Lcopy_forward_loop
25493@@ -105,12 +107,12 @@ ENTRY(memcpy)
25494 subq $0x20, %rdx
25495 movq -1*8(%rsi), %r8
25496 movq -2*8(%rsi), %r9
25497- movq -3*8(%rsi), %r10
25498+ movq -3*8(%rsi), %rcx
25499 movq -4*8(%rsi), %r11
25500 leaq -4*8(%rsi), %rsi
25501 movq %r8, -1*8(%rdi)
25502 movq %r9, -2*8(%rdi)
25503- movq %r10, -3*8(%rdi)
25504+ movq %rcx, -3*8(%rdi)
25505 movq %r11, -4*8(%rdi)
25506 leaq -4*8(%rdi), %rdi
25507 jae .Lcopy_backward_loop
25508@@ -130,12 +132,13 @@ ENTRY(memcpy)
25509 */
25510 movq 0*8(%rsi), %r8
25511 movq 1*8(%rsi), %r9
25512- movq -2*8(%rsi, %rdx), %r10
25513+ movq -2*8(%rsi, %rdx), %rcx
25514 movq -1*8(%rsi, %rdx), %r11
25515 movq %r8, 0*8(%rdi)
25516 movq %r9, 1*8(%rdi)
25517- movq %r10, -2*8(%rdi, %rdx)
25518+ movq %rcx, -2*8(%rdi, %rdx)
25519 movq %r11, -1*8(%rdi, %rdx)
25520+ pax_force_retaddr
25521 retq
25522 .p2align 4
25523 .Lless_16bytes:
25524@@ -148,6 +151,7 @@ ENTRY(memcpy)
25525 movq -1*8(%rsi, %rdx), %r9
25526 movq %r8, 0*8(%rdi)
25527 movq %r9, -1*8(%rdi, %rdx)
25528+ pax_force_retaddr
25529 retq
25530 .p2align 4
25531 .Lless_8bytes:
25532@@ -161,6 +165,7 @@ ENTRY(memcpy)
25533 movl -4(%rsi, %rdx), %r8d
25534 movl %ecx, (%rdi)
25535 movl %r8d, -4(%rdi, %rdx)
25536+ pax_force_retaddr
25537 retq
25538 .p2align 4
25539 .Lless_3bytes:
25540@@ -179,6 +184,7 @@ ENTRY(memcpy)
25541 movb %cl, (%rdi)
25542
25543 .Lend:
25544+ pax_force_retaddr
25545 retq
25546 CFI_ENDPROC
25547 ENDPROC(memcpy)
25548diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25549index ee16461..c39c199 100644
25550--- a/arch/x86/lib/memmove_64.S
25551+++ b/arch/x86/lib/memmove_64.S
25552@@ -61,13 +61,13 @@ ENTRY(memmove)
25553 5:
25554 sub $0x20, %rdx
25555 movq 0*8(%rsi), %r11
25556- movq 1*8(%rsi), %r10
25557+ movq 1*8(%rsi), %rcx
25558 movq 2*8(%rsi), %r9
25559 movq 3*8(%rsi), %r8
25560 leaq 4*8(%rsi), %rsi
25561
25562 movq %r11, 0*8(%rdi)
25563- movq %r10, 1*8(%rdi)
25564+ movq %rcx, 1*8(%rdi)
25565 movq %r9, 2*8(%rdi)
25566 movq %r8, 3*8(%rdi)
25567 leaq 4*8(%rdi), %rdi
25568@@ -81,10 +81,10 @@ ENTRY(memmove)
25569 4:
25570 movq %rdx, %rcx
25571 movq -8(%rsi, %rdx), %r11
25572- lea -8(%rdi, %rdx), %r10
25573+ lea -8(%rdi, %rdx), %r9
25574 shrq $3, %rcx
25575 rep movsq
25576- movq %r11, (%r10)
25577+ movq %r11, (%r9)
25578 jmp 13f
25579 .Lmemmove_end_forward:
25580
25581@@ -95,14 +95,14 @@ ENTRY(memmove)
25582 7:
25583 movq %rdx, %rcx
25584 movq (%rsi), %r11
25585- movq %rdi, %r10
25586+ movq %rdi, %r9
25587 leaq -8(%rsi, %rdx), %rsi
25588 leaq -8(%rdi, %rdx), %rdi
25589 shrq $3, %rcx
25590 std
25591 rep movsq
25592 cld
25593- movq %r11, (%r10)
25594+ movq %r11, (%r9)
25595 jmp 13f
25596
25597 /*
25598@@ -127,13 +127,13 @@ ENTRY(memmove)
25599 8:
25600 subq $0x20, %rdx
25601 movq -1*8(%rsi), %r11
25602- movq -2*8(%rsi), %r10
25603+ movq -2*8(%rsi), %rcx
25604 movq -3*8(%rsi), %r9
25605 movq -4*8(%rsi), %r8
25606 leaq -4*8(%rsi), %rsi
25607
25608 movq %r11, -1*8(%rdi)
25609- movq %r10, -2*8(%rdi)
25610+ movq %rcx, -2*8(%rdi)
25611 movq %r9, -3*8(%rdi)
25612 movq %r8, -4*8(%rdi)
25613 leaq -4*8(%rdi), %rdi
25614@@ -151,11 +151,11 @@ ENTRY(memmove)
25615 * Move data from 16 bytes to 31 bytes.
25616 */
25617 movq 0*8(%rsi), %r11
25618- movq 1*8(%rsi), %r10
25619+ movq 1*8(%rsi), %rcx
25620 movq -2*8(%rsi, %rdx), %r9
25621 movq -1*8(%rsi, %rdx), %r8
25622 movq %r11, 0*8(%rdi)
25623- movq %r10, 1*8(%rdi)
25624+ movq %rcx, 1*8(%rdi)
25625 movq %r9, -2*8(%rdi, %rdx)
25626 movq %r8, -1*8(%rdi, %rdx)
25627 jmp 13f
25628@@ -167,9 +167,9 @@ ENTRY(memmove)
25629 * Move data from 8 bytes to 15 bytes.
25630 */
25631 movq 0*8(%rsi), %r11
25632- movq -1*8(%rsi, %rdx), %r10
25633+ movq -1*8(%rsi, %rdx), %r9
25634 movq %r11, 0*8(%rdi)
25635- movq %r10, -1*8(%rdi, %rdx)
25636+ movq %r9, -1*8(%rdi, %rdx)
25637 jmp 13f
25638 10:
25639 cmpq $4, %rdx
25640@@ -178,9 +178,9 @@ ENTRY(memmove)
25641 * Move data from 4 bytes to 7 bytes.
25642 */
25643 movl (%rsi), %r11d
25644- movl -4(%rsi, %rdx), %r10d
25645+ movl -4(%rsi, %rdx), %r9d
25646 movl %r11d, (%rdi)
25647- movl %r10d, -4(%rdi, %rdx)
25648+ movl %r9d, -4(%rdi, %rdx)
25649 jmp 13f
25650 11:
25651 cmp $2, %rdx
25652@@ -189,9 +189,9 @@ ENTRY(memmove)
25653 * Move data from 2 bytes to 3 bytes.
25654 */
25655 movw (%rsi), %r11w
25656- movw -2(%rsi, %rdx), %r10w
25657+ movw -2(%rsi, %rdx), %r9w
25658 movw %r11w, (%rdi)
25659- movw %r10w, -2(%rdi, %rdx)
25660+ movw %r9w, -2(%rdi, %rdx)
25661 jmp 13f
25662 12:
25663 cmp $1, %rdx
25664@@ -202,6 +202,7 @@ ENTRY(memmove)
25665 movb (%rsi), %r11b
25666 movb %r11b, (%rdi)
25667 13:
25668+ pax_force_retaddr
25669 retq
25670 CFI_ENDPROC
25671
25672@@ -210,6 +211,7 @@ ENTRY(memmove)
25673 /* Forward moving data. */
25674 movq %rdx, %rcx
25675 rep movsb
25676+ pax_force_retaddr
25677 retq
25678 .Lmemmove_end_forward_efs:
25679 .previous
25680diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25681index 2dcb380..963660a 100644
25682--- a/arch/x86/lib/memset_64.S
25683+++ b/arch/x86/lib/memset_64.S
25684@@ -30,6 +30,7 @@
25685 movl %edx,%ecx
25686 rep stosb
25687 movq %r9,%rax
25688+ pax_force_retaddr
25689 ret
25690 .Lmemset_e:
25691 .previous
25692@@ -52,6 +53,7 @@
25693 movq %rdx,%rcx
25694 rep stosb
25695 movq %r9,%rax
25696+ pax_force_retaddr
25697 ret
25698 .Lmemset_e_e:
25699 .previous
25700@@ -59,7 +61,7 @@
25701 ENTRY(memset)
25702 ENTRY(__memset)
25703 CFI_STARTPROC
25704- movq %rdi,%r10
25705+ movq %rdi,%r11
25706
25707 /* expand byte value */
25708 movzbl %sil,%ecx
25709@@ -117,7 +119,8 @@ ENTRY(__memset)
25710 jnz .Lloop_1
25711
25712 .Lende:
25713- movq %r10,%rax
25714+ movq %r11,%rax
25715+ pax_force_retaddr
25716 ret
25717
25718 CFI_RESTORE_STATE
25719diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25720index c9f2d9b..e7fd2c0 100644
25721--- a/arch/x86/lib/mmx_32.c
25722+++ b/arch/x86/lib/mmx_32.c
25723@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25724 {
25725 void *p;
25726 int i;
25727+ unsigned long cr0;
25728
25729 if (unlikely(in_interrupt()))
25730 return __memcpy(to, from, len);
25731@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25732 kernel_fpu_begin();
25733
25734 __asm__ __volatile__ (
25735- "1: prefetch (%0)\n" /* This set is 28 bytes */
25736- " prefetch 64(%0)\n"
25737- " prefetch 128(%0)\n"
25738- " prefetch 192(%0)\n"
25739- " prefetch 256(%0)\n"
25740+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25741+ " prefetch 64(%1)\n"
25742+ " prefetch 128(%1)\n"
25743+ " prefetch 192(%1)\n"
25744+ " prefetch 256(%1)\n"
25745 "2: \n"
25746 ".section .fixup, \"ax\"\n"
25747- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25748+ "3: \n"
25749+
25750+#ifdef CONFIG_PAX_KERNEXEC
25751+ " movl %%cr0, %0\n"
25752+ " movl %0, %%eax\n"
25753+ " andl $0xFFFEFFFF, %%eax\n"
25754+ " movl %%eax, %%cr0\n"
25755+#endif
25756+
25757+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25758+
25759+#ifdef CONFIG_PAX_KERNEXEC
25760+ " movl %0, %%cr0\n"
25761+#endif
25762+
25763 " jmp 2b\n"
25764 ".previous\n"
25765 _ASM_EXTABLE(1b, 3b)
25766- : : "r" (from));
25767+ : "=&r" (cr0) : "r" (from) : "ax");
25768
25769 for ( ; i > 5; i--) {
25770 __asm__ __volatile__ (
25771- "1: prefetch 320(%0)\n"
25772- "2: movq (%0), %%mm0\n"
25773- " movq 8(%0), %%mm1\n"
25774- " movq 16(%0), %%mm2\n"
25775- " movq 24(%0), %%mm3\n"
25776- " movq %%mm0, (%1)\n"
25777- " movq %%mm1, 8(%1)\n"
25778- " movq %%mm2, 16(%1)\n"
25779- " movq %%mm3, 24(%1)\n"
25780- " movq 32(%0), %%mm0\n"
25781- " movq 40(%0), %%mm1\n"
25782- " movq 48(%0), %%mm2\n"
25783- " movq 56(%0), %%mm3\n"
25784- " movq %%mm0, 32(%1)\n"
25785- " movq %%mm1, 40(%1)\n"
25786- " movq %%mm2, 48(%1)\n"
25787- " movq %%mm3, 56(%1)\n"
25788+ "1: prefetch 320(%1)\n"
25789+ "2: movq (%1), %%mm0\n"
25790+ " movq 8(%1), %%mm1\n"
25791+ " movq 16(%1), %%mm2\n"
25792+ " movq 24(%1), %%mm3\n"
25793+ " movq %%mm0, (%2)\n"
25794+ " movq %%mm1, 8(%2)\n"
25795+ " movq %%mm2, 16(%2)\n"
25796+ " movq %%mm3, 24(%2)\n"
25797+ " movq 32(%1), %%mm0\n"
25798+ " movq 40(%1), %%mm1\n"
25799+ " movq 48(%1), %%mm2\n"
25800+ " movq 56(%1), %%mm3\n"
25801+ " movq %%mm0, 32(%2)\n"
25802+ " movq %%mm1, 40(%2)\n"
25803+ " movq %%mm2, 48(%2)\n"
25804+ " movq %%mm3, 56(%2)\n"
25805 ".section .fixup, \"ax\"\n"
25806- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25807+ "3:\n"
25808+
25809+#ifdef CONFIG_PAX_KERNEXEC
25810+ " movl %%cr0, %0\n"
25811+ " movl %0, %%eax\n"
25812+ " andl $0xFFFEFFFF, %%eax\n"
25813+ " movl %%eax, %%cr0\n"
25814+#endif
25815+
25816+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25817+
25818+#ifdef CONFIG_PAX_KERNEXEC
25819+ " movl %0, %%cr0\n"
25820+#endif
25821+
25822 " jmp 2b\n"
25823 ".previous\n"
25824 _ASM_EXTABLE(1b, 3b)
25825- : : "r" (from), "r" (to) : "memory");
25826+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25827
25828 from += 64;
25829 to += 64;
25830@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25831 static void fast_copy_page(void *to, void *from)
25832 {
25833 int i;
25834+ unsigned long cr0;
25835
25836 kernel_fpu_begin();
25837
25838@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25839 * but that is for later. -AV
25840 */
25841 __asm__ __volatile__(
25842- "1: prefetch (%0)\n"
25843- " prefetch 64(%0)\n"
25844- " prefetch 128(%0)\n"
25845- " prefetch 192(%0)\n"
25846- " prefetch 256(%0)\n"
25847+ "1: prefetch (%1)\n"
25848+ " prefetch 64(%1)\n"
25849+ " prefetch 128(%1)\n"
25850+ " prefetch 192(%1)\n"
25851+ " prefetch 256(%1)\n"
25852 "2: \n"
25853 ".section .fixup, \"ax\"\n"
25854- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25855+ "3: \n"
25856+
25857+#ifdef CONFIG_PAX_KERNEXEC
25858+ " movl %%cr0, %0\n"
25859+ " movl %0, %%eax\n"
25860+ " andl $0xFFFEFFFF, %%eax\n"
25861+ " movl %%eax, %%cr0\n"
25862+#endif
25863+
25864+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25865+
25866+#ifdef CONFIG_PAX_KERNEXEC
25867+ " movl %0, %%cr0\n"
25868+#endif
25869+
25870 " jmp 2b\n"
25871 ".previous\n"
25872- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25873+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25874
25875 for (i = 0; i < (4096-320)/64; i++) {
25876 __asm__ __volatile__ (
25877- "1: prefetch 320(%0)\n"
25878- "2: movq (%0), %%mm0\n"
25879- " movntq %%mm0, (%1)\n"
25880- " movq 8(%0), %%mm1\n"
25881- " movntq %%mm1, 8(%1)\n"
25882- " movq 16(%0), %%mm2\n"
25883- " movntq %%mm2, 16(%1)\n"
25884- " movq 24(%0), %%mm3\n"
25885- " movntq %%mm3, 24(%1)\n"
25886- " movq 32(%0), %%mm4\n"
25887- " movntq %%mm4, 32(%1)\n"
25888- " movq 40(%0), %%mm5\n"
25889- " movntq %%mm5, 40(%1)\n"
25890- " movq 48(%0), %%mm6\n"
25891- " movntq %%mm6, 48(%1)\n"
25892- " movq 56(%0), %%mm7\n"
25893- " movntq %%mm7, 56(%1)\n"
25894+ "1: prefetch 320(%1)\n"
25895+ "2: movq (%1), %%mm0\n"
25896+ " movntq %%mm0, (%2)\n"
25897+ " movq 8(%1), %%mm1\n"
25898+ " movntq %%mm1, 8(%2)\n"
25899+ " movq 16(%1), %%mm2\n"
25900+ " movntq %%mm2, 16(%2)\n"
25901+ " movq 24(%1), %%mm3\n"
25902+ " movntq %%mm3, 24(%2)\n"
25903+ " movq 32(%1), %%mm4\n"
25904+ " movntq %%mm4, 32(%2)\n"
25905+ " movq 40(%1), %%mm5\n"
25906+ " movntq %%mm5, 40(%2)\n"
25907+ " movq 48(%1), %%mm6\n"
25908+ " movntq %%mm6, 48(%2)\n"
25909+ " movq 56(%1), %%mm7\n"
25910+ " movntq %%mm7, 56(%2)\n"
25911 ".section .fixup, \"ax\"\n"
25912- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25913+ "3:\n"
25914+
25915+#ifdef CONFIG_PAX_KERNEXEC
25916+ " movl %%cr0, %0\n"
25917+ " movl %0, %%eax\n"
25918+ " andl $0xFFFEFFFF, %%eax\n"
25919+ " movl %%eax, %%cr0\n"
25920+#endif
25921+
25922+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25923+
25924+#ifdef CONFIG_PAX_KERNEXEC
25925+ " movl %0, %%cr0\n"
25926+#endif
25927+
25928 " jmp 2b\n"
25929 ".previous\n"
25930- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25931+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25932
25933 from += 64;
25934 to += 64;
25935@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25936 static void fast_copy_page(void *to, void *from)
25937 {
25938 int i;
25939+ unsigned long cr0;
25940
25941 kernel_fpu_begin();
25942
25943 __asm__ __volatile__ (
25944- "1: prefetch (%0)\n"
25945- " prefetch 64(%0)\n"
25946- " prefetch 128(%0)\n"
25947- " prefetch 192(%0)\n"
25948- " prefetch 256(%0)\n"
25949+ "1: prefetch (%1)\n"
25950+ " prefetch 64(%1)\n"
25951+ " prefetch 128(%1)\n"
25952+ " prefetch 192(%1)\n"
25953+ " prefetch 256(%1)\n"
25954 "2: \n"
25955 ".section .fixup, \"ax\"\n"
25956- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25957+ "3: \n"
25958+
25959+#ifdef CONFIG_PAX_KERNEXEC
25960+ " movl %%cr0, %0\n"
25961+ " movl %0, %%eax\n"
25962+ " andl $0xFFFEFFFF, %%eax\n"
25963+ " movl %%eax, %%cr0\n"
25964+#endif
25965+
25966+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25967+
25968+#ifdef CONFIG_PAX_KERNEXEC
25969+ " movl %0, %%cr0\n"
25970+#endif
25971+
25972 " jmp 2b\n"
25973 ".previous\n"
25974- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25975+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25976
25977 for (i = 0; i < 4096/64; i++) {
25978 __asm__ __volatile__ (
25979- "1: prefetch 320(%0)\n"
25980- "2: movq (%0), %%mm0\n"
25981- " movq 8(%0), %%mm1\n"
25982- " movq 16(%0), %%mm2\n"
25983- " movq 24(%0), %%mm3\n"
25984- " movq %%mm0, (%1)\n"
25985- " movq %%mm1, 8(%1)\n"
25986- " movq %%mm2, 16(%1)\n"
25987- " movq %%mm3, 24(%1)\n"
25988- " movq 32(%0), %%mm0\n"
25989- " movq 40(%0), %%mm1\n"
25990- " movq 48(%0), %%mm2\n"
25991- " movq 56(%0), %%mm3\n"
25992- " movq %%mm0, 32(%1)\n"
25993- " movq %%mm1, 40(%1)\n"
25994- " movq %%mm2, 48(%1)\n"
25995- " movq %%mm3, 56(%1)\n"
25996+ "1: prefetch 320(%1)\n"
25997+ "2: movq (%1), %%mm0\n"
25998+ " movq 8(%1), %%mm1\n"
25999+ " movq 16(%1), %%mm2\n"
26000+ " movq 24(%1), %%mm3\n"
26001+ " movq %%mm0, (%2)\n"
26002+ " movq %%mm1, 8(%2)\n"
26003+ " movq %%mm2, 16(%2)\n"
26004+ " movq %%mm3, 24(%2)\n"
26005+ " movq 32(%1), %%mm0\n"
26006+ " movq 40(%1), %%mm1\n"
26007+ " movq 48(%1), %%mm2\n"
26008+ " movq 56(%1), %%mm3\n"
26009+ " movq %%mm0, 32(%2)\n"
26010+ " movq %%mm1, 40(%2)\n"
26011+ " movq %%mm2, 48(%2)\n"
26012+ " movq %%mm3, 56(%2)\n"
26013 ".section .fixup, \"ax\"\n"
26014- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26015+ "3:\n"
26016+
26017+#ifdef CONFIG_PAX_KERNEXEC
26018+ " movl %%cr0, %0\n"
26019+ " movl %0, %%eax\n"
26020+ " andl $0xFFFEFFFF, %%eax\n"
26021+ " movl %%eax, %%cr0\n"
26022+#endif
26023+
26024+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26025+
26026+#ifdef CONFIG_PAX_KERNEXEC
26027+ " movl %0, %%cr0\n"
26028+#endif
26029+
26030 " jmp 2b\n"
26031 ".previous\n"
26032 _ASM_EXTABLE(1b, 3b)
26033- : : "r" (from), "r" (to) : "memory");
26034+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26035
26036 from += 64;
26037 to += 64;
26038diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26039index f6d13ee..aca5f0b 100644
26040--- a/arch/x86/lib/msr-reg.S
26041+++ b/arch/x86/lib/msr-reg.S
26042@@ -3,6 +3,7 @@
26043 #include <asm/dwarf2.h>
26044 #include <asm/asm.h>
26045 #include <asm/msr.h>
26046+#include <asm/alternative-asm.h>
26047
26048 #ifdef CONFIG_X86_64
26049 /*
26050@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26051 CFI_STARTPROC
26052 pushq_cfi %rbx
26053 pushq_cfi %rbp
26054- movq %rdi, %r10 /* Save pointer */
26055+ movq %rdi, %r9 /* Save pointer */
26056 xorl %r11d, %r11d /* Return value */
26057 movl (%rdi), %eax
26058 movl 4(%rdi), %ecx
26059@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26060 movl 28(%rdi), %edi
26061 CFI_REMEMBER_STATE
26062 1: \op
26063-2: movl %eax, (%r10)
26064+2: movl %eax, (%r9)
26065 movl %r11d, %eax /* Return value */
26066- movl %ecx, 4(%r10)
26067- movl %edx, 8(%r10)
26068- movl %ebx, 12(%r10)
26069- movl %ebp, 20(%r10)
26070- movl %esi, 24(%r10)
26071- movl %edi, 28(%r10)
26072+ movl %ecx, 4(%r9)
26073+ movl %edx, 8(%r9)
26074+ movl %ebx, 12(%r9)
26075+ movl %ebp, 20(%r9)
26076+ movl %esi, 24(%r9)
26077+ movl %edi, 28(%r9)
26078 popq_cfi %rbp
26079 popq_cfi %rbx
26080+ pax_force_retaddr
26081 ret
26082 3:
26083 CFI_RESTORE_STATE
26084diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26085index fc6ba17..04471c5 100644
26086--- a/arch/x86/lib/putuser.S
26087+++ b/arch/x86/lib/putuser.S
26088@@ -16,7 +16,9 @@
26089 #include <asm/errno.h>
26090 #include <asm/asm.h>
26091 #include <asm/smap.h>
26092-
26093+#include <asm/segment.h>
26094+#include <asm/pgtable.h>
26095+#include <asm/alternative-asm.h>
26096
26097 /*
26098 * __put_user_X
26099@@ -30,57 +32,125 @@
26100 * as they get called from within inline assembly.
26101 */
26102
26103-#define ENTER CFI_STARTPROC ; \
26104- GET_THREAD_INFO(%_ASM_BX)
26105-#define EXIT ASM_CLAC ; \
26106- ret ; \
26107+#define ENTER CFI_STARTPROC
26108+#define EXIT ASM_CLAC ; \
26109+ pax_force_retaddr ; \
26110+ ret ; \
26111 CFI_ENDPROC
26112
26113+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26114+#define _DEST %_ASM_CX,%_ASM_BX
26115+#else
26116+#define _DEST %_ASM_CX
26117+#endif
26118+
26119+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26120+#define __copyuser_seg gs;
26121+#else
26122+#define __copyuser_seg
26123+#endif
26124+
26125 .text
26126 ENTRY(__put_user_1)
26127 ENTER
26128+
26129+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26130+ GET_THREAD_INFO(%_ASM_BX)
26131 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26132 jae bad_put_user
26133 ASM_STAC
26134-1: movb %al,(%_ASM_CX)
26135+
26136+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26137+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26138+ cmp %_ASM_BX,%_ASM_CX
26139+ jb 1234f
26140+ xor %ebx,%ebx
26141+1234:
26142+#endif
26143+
26144+#endif
26145+
26146+1: __copyuser_seg movb %al,(_DEST)
26147 xor %eax,%eax
26148 EXIT
26149 ENDPROC(__put_user_1)
26150
26151 ENTRY(__put_user_2)
26152 ENTER
26153+
26154+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26155+ GET_THREAD_INFO(%_ASM_BX)
26156 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26157 sub $1,%_ASM_BX
26158 cmp %_ASM_BX,%_ASM_CX
26159 jae bad_put_user
26160 ASM_STAC
26161-2: movw %ax,(%_ASM_CX)
26162+
26163+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26164+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26165+ cmp %_ASM_BX,%_ASM_CX
26166+ jb 1234f
26167+ xor %ebx,%ebx
26168+1234:
26169+#endif
26170+
26171+#endif
26172+
26173+2: __copyuser_seg movw %ax,(_DEST)
26174 xor %eax,%eax
26175 EXIT
26176 ENDPROC(__put_user_2)
26177
26178 ENTRY(__put_user_4)
26179 ENTER
26180+
26181+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26182+ GET_THREAD_INFO(%_ASM_BX)
26183 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26184 sub $3,%_ASM_BX
26185 cmp %_ASM_BX,%_ASM_CX
26186 jae bad_put_user
26187 ASM_STAC
26188-3: movl %eax,(%_ASM_CX)
26189+
26190+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26191+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26192+ cmp %_ASM_BX,%_ASM_CX
26193+ jb 1234f
26194+ xor %ebx,%ebx
26195+1234:
26196+#endif
26197+
26198+#endif
26199+
26200+3: __copyuser_seg movl %eax,(_DEST)
26201 xor %eax,%eax
26202 EXIT
26203 ENDPROC(__put_user_4)
26204
26205 ENTRY(__put_user_8)
26206 ENTER
26207+
26208+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26209+ GET_THREAD_INFO(%_ASM_BX)
26210 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26211 sub $7,%_ASM_BX
26212 cmp %_ASM_BX,%_ASM_CX
26213 jae bad_put_user
26214 ASM_STAC
26215-4: mov %_ASM_AX,(%_ASM_CX)
26216+
26217+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26218+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26219+ cmp %_ASM_BX,%_ASM_CX
26220+ jb 1234f
26221+ xor %ebx,%ebx
26222+1234:
26223+#endif
26224+
26225+#endif
26226+
26227+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26228 #ifdef CONFIG_X86_32
26229-5: movl %edx,4(%_ASM_CX)
26230+5: __copyuser_seg movl %edx,4(_DEST)
26231 #endif
26232 xor %eax,%eax
26233 EXIT
26234diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26235index 1cad221..de671ee 100644
26236--- a/arch/x86/lib/rwlock.S
26237+++ b/arch/x86/lib/rwlock.S
26238@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26239 FRAME
26240 0: LOCK_PREFIX
26241 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26242+
26243+#ifdef CONFIG_PAX_REFCOUNT
26244+ jno 1234f
26245+ LOCK_PREFIX
26246+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26247+ int $4
26248+1234:
26249+ _ASM_EXTABLE(1234b, 1234b)
26250+#endif
26251+
26252 1: rep; nop
26253 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26254 jne 1b
26255 LOCK_PREFIX
26256 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26257+
26258+#ifdef CONFIG_PAX_REFCOUNT
26259+ jno 1234f
26260+ LOCK_PREFIX
26261+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26262+ int $4
26263+1234:
26264+ _ASM_EXTABLE(1234b, 1234b)
26265+#endif
26266+
26267 jnz 0b
26268 ENDFRAME
26269+ pax_force_retaddr
26270 ret
26271 CFI_ENDPROC
26272 END(__write_lock_failed)
26273@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26274 FRAME
26275 0: LOCK_PREFIX
26276 READ_LOCK_SIZE(inc) (%__lock_ptr)
26277+
26278+#ifdef CONFIG_PAX_REFCOUNT
26279+ jno 1234f
26280+ LOCK_PREFIX
26281+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26282+ int $4
26283+1234:
26284+ _ASM_EXTABLE(1234b, 1234b)
26285+#endif
26286+
26287 1: rep; nop
26288 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26289 js 1b
26290 LOCK_PREFIX
26291 READ_LOCK_SIZE(dec) (%__lock_ptr)
26292+
26293+#ifdef CONFIG_PAX_REFCOUNT
26294+ jno 1234f
26295+ LOCK_PREFIX
26296+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26297+ int $4
26298+1234:
26299+ _ASM_EXTABLE(1234b, 1234b)
26300+#endif
26301+
26302 js 0b
26303 ENDFRAME
26304+ pax_force_retaddr
26305 ret
26306 CFI_ENDPROC
26307 END(__read_lock_failed)
26308diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26309index 5dff5f0..cadebf4 100644
26310--- a/arch/x86/lib/rwsem.S
26311+++ b/arch/x86/lib/rwsem.S
26312@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26313 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26314 CFI_RESTORE __ASM_REG(dx)
26315 restore_common_regs
26316+ pax_force_retaddr
26317 ret
26318 CFI_ENDPROC
26319 ENDPROC(call_rwsem_down_read_failed)
26320@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26321 movq %rax,%rdi
26322 call rwsem_down_write_failed
26323 restore_common_regs
26324+ pax_force_retaddr
26325 ret
26326 CFI_ENDPROC
26327 ENDPROC(call_rwsem_down_write_failed)
26328@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26329 movq %rax,%rdi
26330 call rwsem_wake
26331 restore_common_regs
26332-1: ret
26333+1: pax_force_retaddr
26334+ ret
26335 CFI_ENDPROC
26336 ENDPROC(call_rwsem_wake)
26337
26338@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26339 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26340 CFI_RESTORE __ASM_REG(dx)
26341 restore_common_regs
26342+ pax_force_retaddr
26343 ret
26344 CFI_ENDPROC
26345 ENDPROC(call_rwsem_downgrade_wake)
26346diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26347index a63efd6..ccecad8 100644
26348--- a/arch/x86/lib/thunk_64.S
26349+++ b/arch/x86/lib/thunk_64.S
26350@@ -8,6 +8,7 @@
26351 #include <linux/linkage.h>
26352 #include <asm/dwarf2.h>
26353 #include <asm/calling.h>
26354+#include <asm/alternative-asm.h>
26355
26356 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26357 .macro THUNK name, func, put_ret_addr_in_rdi=0
26358@@ -41,5 +42,6 @@
26359 SAVE_ARGS
26360 restore:
26361 RESTORE_ARGS
26362+ pax_force_retaddr
26363 ret
26364 CFI_ENDPROC
26365diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26366index f0312d7..9c39d63 100644
26367--- a/arch/x86/lib/usercopy_32.c
26368+++ b/arch/x86/lib/usercopy_32.c
26369@@ -42,11 +42,13 @@ do { \
26370 int __d0; \
26371 might_fault(); \
26372 __asm__ __volatile__( \
26373+ __COPYUSER_SET_ES \
26374 ASM_STAC "\n" \
26375 "0: rep; stosl\n" \
26376 " movl %2,%0\n" \
26377 "1: rep; stosb\n" \
26378 "2: " ASM_CLAC "\n" \
26379+ __COPYUSER_RESTORE_ES \
26380 ".section .fixup,\"ax\"\n" \
26381 "3: lea 0(%2,%0,4),%0\n" \
26382 " jmp 2b\n" \
26383@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26384
26385 #ifdef CONFIG_X86_INTEL_USERCOPY
26386 static unsigned long
26387-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26388+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26389 {
26390 int d0, d1;
26391 __asm__ __volatile__(
26392@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26393 " .align 2,0x90\n"
26394 "3: movl 0(%4), %%eax\n"
26395 "4: movl 4(%4), %%edx\n"
26396- "5: movl %%eax, 0(%3)\n"
26397- "6: movl %%edx, 4(%3)\n"
26398+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26399+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26400 "7: movl 8(%4), %%eax\n"
26401 "8: movl 12(%4),%%edx\n"
26402- "9: movl %%eax, 8(%3)\n"
26403- "10: movl %%edx, 12(%3)\n"
26404+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26405+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26406 "11: movl 16(%4), %%eax\n"
26407 "12: movl 20(%4), %%edx\n"
26408- "13: movl %%eax, 16(%3)\n"
26409- "14: movl %%edx, 20(%3)\n"
26410+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26411+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26412 "15: movl 24(%4), %%eax\n"
26413 "16: movl 28(%4), %%edx\n"
26414- "17: movl %%eax, 24(%3)\n"
26415- "18: movl %%edx, 28(%3)\n"
26416+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26417+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26418 "19: movl 32(%4), %%eax\n"
26419 "20: movl 36(%4), %%edx\n"
26420- "21: movl %%eax, 32(%3)\n"
26421- "22: movl %%edx, 36(%3)\n"
26422+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26423+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26424 "23: movl 40(%4), %%eax\n"
26425 "24: movl 44(%4), %%edx\n"
26426- "25: movl %%eax, 40(%3)\n"
26427- "26: movl %%edx, 44(%3)\n"
26428+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26429+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26430 "27: movl 48(%4), %%eax\n"
26431 "28: movl 52(%4), %%edx\n"
26432- "29: movl %%eax, 48(%3)\n"
26433- "30: movl %%edx, 52(%3)\n"
26434+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26435+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26436 "31: movl 56(%4), %%eax\n"
26437 "32: movl 60(%4), %%edx\n"
26438- "33: movl %%eax, 56(%3)\n"
26439- "34: movl %%edx, 60(%3)\n"
26440+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26441+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26442 " addl $-64, %0\n"
26443 " addl $64, %4\n"
26444 " addl $64, %3\n"
26445@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26446 " shrl $2, %0\n"
26447 " andl $3, %%eax\n"
26448 " cld\n"
26449+ __COPYUSER_SET_ES
26450 "99: rep; movsl\n"
26451 "36: movl %%eax, %0\n"
26452 "37: rep; movsb\n"
26453 "100:\n"
26454+ __COPYUSER_RESTORE_ES
26455 ".section .fixup,\"ax\"\n"
26456 "101: lea 0(%%eax,%0,4),%0\n"
26457 " jmp 100b\n"
26458@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26459 }
26460
26461 static unsigned long
26462+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26463+{
26464+ int d0, d1;
26465+ __asm__ __volatile__(
26466+ " .align 2,0x90\n"
26467+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26468+ " cmpl $67, %0\n"
26469+ " jbe 3f\n"
26470+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26471+ " .align 2,0x90\n"
26472+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26473+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26474+ "5: movl %%eax, 0(%3)\n"
26475+ "6: movl %%edx, 4(%3)\n"
26476+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26477+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26478+ "9: movl %%eax, 8(%3)\n"
26479+ "10: movl %%edx, 12(%3)\n"
26480+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26481+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26482+ "13: movl %%eax, 16(%3)\n"
26483+ "14: movl %%edx, 20(%3)\n"
26484+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26485+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26486+ "17: movl %%eax, 24(%3)\n"
26487+ "18: movl %%edx, 28(%3)\n"
26488+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26489+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26490+ "21: movl %%eax, 32(%3)\n"
26491+ "22: movl %%edx, 36(%3)\n"
26492+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26493+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26494+ "25: movl %%eax, 40(%3)\n"
26495+ "26: movl %%edx, 44(%3)\n"
26496+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26497+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26498+ "29: movl %%eax, 48(%3)\n"
26499+ "30: movl %%edx, 52(%3)\n"
26500+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26501+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26502+ "33: movl %%eax, 56(%3)\n"
26503+ "34: movl %%edx, 60(%3)\n"
26504+ " addl $-64, %0\n"
26505+ " addl $64, %4\n"
26506+ " addl $64, %3\n"
26507+ " cmpl $63, %0\n"
26508+ " ja 1b\n"
26509+ "35: movl %0, %%eax\n"
26510+ " shrl $2, %0\n"
26511+ " andl $3, %%eax\n"
26512+ " cld\n"
26513+ "99: rep; "__copyuser_seg" movsl\n"
26514+ "36: movl %%eax, %0\n"
26515+ "37: rep; "__copyuser_seg" movsb\n"
26516+ "100:\n"
26517+ ".section .fixup,\"ax\"\n"
26518+ "101: lea 0(%%eax,%0,4),%0\n"
26519+ " jmp 100b\n"
26520+ ".previous\n"
26521+ _ASM_EXTABLE(1b,100b)
26522+ _ASM_EXTABLE(2b,100b)
26523+ _ASM_EXTABLE(3b,100b)
26524+ _ASM_EXTABLE(4b,100b)
26525+ _ASM_EXTABLE(5b,100b)
26526+ _ASM_EXTABLE(6b,100b)
26527+ _ASM_EXTABLE(7b,100b)
26528+ _ASM_EXTABLE(8b,100b)
26529+ _ASM_EXTABLE(9b,100b)
26530+ _ASM_EXTABLE(10b,100b)
26531+ _ASM_EXTABLE(11b,100b)
26532+ _ASM_EXTABLE(12b,100b)
26533+ _ASM_EXTABLE(13b,100b)
26534+ _ASM_EXTABLE(14b,100b)
26535+ _ASM_EXTABLE(15b,100b)
26536+ _ASM_EXTABLE(16b,100b)
26537+ _ASM_EXTABLE(17b,100b)
26538+ _ASM_EXTABLE(18b,100b)
26539+ _ASM_EXTABLE(19b,100b)
26540+ _ASM_EXTABLE(20b,100b)
26541+ _ASM_EXTABLE(21b,100b)
26542+ _ASM_EXTABLE(22b,100b)
26543+ _ASM_EXTABLE(23b,100b)
26544+ _ASM_EXTABLE(24b,100b)
26545+ _ASM_EXTABLE(25b,100b)
26546+ _ASM_EXTABLE(26b,100b)
26547+ _ASM_EXTABLE(27b,100b)
26548+ _ASM_EXTABLE(28b,100b)
26549+ _ASM_EXTABLE(29b,100b)
26550+ _ASM_EXTABLE(30b,100b)
26551+ _ASM_EXTABLE(31b,100b)
26552+ _ASM_EXTABLE(32b,100b)
26553+ _ASM_EXTABLE(33b,100b)
26554+ _ASM_EXTABLE(34b,100b)
26555+ _ASM_EXTABLE(35b,100b)
26556+ _ASM_EXTABLE(36b,100b)
26557+ _ASM_EXTABLE(37b,100b)
26558+ _ASM_EXTABLE(99b,101b)
26559+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26560+ : "1"(to), "2"(from), "0"(size)
26561+ : "eax", "edx", "memory");
26562+ return size;
26563+}
26564+
26565+static unsigned long __size_overflow(3)
26566 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26567 {
26568 int d0, d1;
26569 __asm__ __volatile__(
26570 " .align 2,0x90\n"
26571- "0: movl 32(%4), %%eax\n"
26572+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26573 " cmpl $67, %0\n"
26574 " jbe 2f\n"
26575- "1: movl 64(%4), %%eax\n"
26576+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26577 " .align 2,0x90\n"
26578- "2: movl 0(%4), %%eax\n"
26579- "21: movl 4(%4), %%edx\n"
26580+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26581+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26582 " movl %%eax, 0(%3)\n"
26583 " movl %%edx, 4(%3)\n"
26584- "3: movl 8(%4), %%eax\n"
26585- "31: movl 12(%4),%%edx\n"
26586+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26587+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26588 " movl %%eax, 8(%3)\n"
26589 " movl %%edx, 12(%3)\n"
26590- "4: movl 16(%4), %%eax\n"
26591- "41: movl 20(%4), %%edx\n"
26592+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26593+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26594 " movl %%eax, 16(%3)\n"
26595 " movl %%edx, 20(%3)\n"
26596- "10: movl 24(%4), %%eax\n"
26597- "51: movl 28(%4), %%edx\n"
26598+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26599+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26600 " movl %%eax, 24(%3)\n"
26601 " movl %%edx, 28(%3)\n"
26602- "11: movl 32(%4), %%eax\n"
26603- "61: movl 36(%4), %%edx\n"
26604+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26605+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26606 " movl %%eax, 32(%3)\n"
26607 " movl %%edx, 36(%3)\n"
26608- "12: movl 40(%4), %%eax\n"
26609- "71: movl 44(%4), %%edx\n"
26610+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26611+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26612 " movl %%eax, 40(%3)\n"
26613 " movl %%edx, 44(%3)\n"
26614- "13: movl 48(%4), %%eax\n"
26615- "81: movl 52(%4), %%edx\n"
26616+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26617+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26618 " movl %%eax, 48(%3)\n"
26619 " movl %%edx, 52(%3)\n"
26620- "14: movl 56(%4), %%eax\n"
26621- "91: movl 60(%4), %%edx\n"
26622+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26623+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26624 " movl %%eax, 56(%3)\n"
26625 " movl %%edx, 60(%3)\n"
26626 " addl $-64, %0\n"
26627@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26628 " shrl $2, %0\n"
26629 " andl $3, %%eax\n"
26630 " cld\n"
26631- "6: rep; movsl\n"
26632+ "6: rep; "__copyuser_seg" movsl\n"
26633 " movl %%eax,%0\n"
26634- "7: rep; movsb\n"
26635+ "7: rep; "__copyuser_seg" movsb\n"
26636 "8:\n"
26637 ".section .fixup,\"ax\"\n"
26638 "9: lea 0(%%eax,%0,4),%0\n"
26639@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26640 * hyoshiok@miraclelinux.com
26641 */
26642
26643-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26644+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26645 const void __user *from, unsigned long size)
26646 {
26647 int d0, d1;
26648
26649 __asm__ __volatile__(
26650 " .align 2,0x90\n"
26651- "0: movl 32(%4), %%eax\n"
26652+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26653 " cmpl $67, %0\n"
26654 " jbe 2f\n"
26655- "1: movl 64(%4), %%eax\n"
26656+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26657 " .align 2,0x90\n"
26658- "2: movl 0(%4), %%eax\n"
26659- "21: movl 4(%4), %%edx\n"
26660+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26661+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26662 " movnti %%eax, 0(%3)\n"
26663 " movnti %%edx, 4(%3)\n"
26664- "3: movl 8(%4), %%eax\n"
26665- "31: movl 12(%4),%%edx\n"
26666+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26667+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26668 " movnti %%eax, 8(%3)\n"
26669 " movnti %%edx, 12(%3)\n"
26670- "4: movl 16(%4), %%eax\n"
26671- "41: movl 20(%4), %%edx\n"
26672+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26673+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26674 " movnti %%eax, 16(%3)\n"
26675 " movnti %%edx, 20(%3)\n"
26676- "10: movl 24(%4), %%eax\n"
26677- "51: movl 28(%4), %%edx\n"
26678+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26679+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26680 " movnti %%eax, 24(%3)\n"
26681 " movnti %%edx, 28(%3)\n"
26682- "11: movl 32(%4), %%eax\n"
26683- "61: movl 36(%4), %%edx\n"
26684+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26685+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26686 " movnti %%eax, 32(%3)\n"
26687 " movnti %%edx, 36(%3)\n"
26688- "12: movl 40(%4), %%eax\n"
26689- "71: movl 44(%4), %%edx\n"
26690+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26691+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26692 " movnti %%eax, 40(%3)\n"
26693 " movnti %%edx, 44(%3)\n"
26694- "13: movl 48(%4), %%eax\n"
26695- "81: movl 52(%4), %%edx\n"
26696+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26697+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26698 " movnti %%eax, 48(%3)\n"
26699 " movnti %%edx, 52(%3)\n"
26700- "14: movl 56(%4), %%eax\n"
26701- "91: movl 60(%4), %%edx\n"
26702+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26703+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26704 " movnti %%eax, 56(%3)\n"
26705 " movnti %%edx, 60(%3)\n"
26706 " addl $-64, %0\n"
26707@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26708 " shrl $2, %0\n"
26709 " andl $3, %%eax\n"
26710 " cld\n"
26711- "6: rep; movsl\n"
26712+ "6: rep; "__copyuser_seg" movsl\n"
26713 " movl %%eax,%0\n"
26714- "7: rep; movsb\n"
26715+ "7: rep; "__copyuser_seg" movsb\n"
26716 "8:\n"
26717 ".section .fixup,\"ax\"\n"
26718 "9: lea 0(%%eax,%0,4),%0\n"
26719@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26720 return size;
26721 }
26722
26723-static unsigned long __copy_user_intel_nocache(void *to,
26724+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26725 const void __user *from, unsigned long size)
26726 {
26727 int d0, d1;
26728
26729 __asm__ __volatile__(
26730 " .align 2,0x90\n"
26731- "0: movl 32(%4), %%eax\n"
26732+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26733 " cmpl $67, %0\n"
26734 " jbe 2f\n"
26735- "1: movl 64(%4), %%eax\n"
26736+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26737 " .align 2,0x90\n"
26738- "2: movl 0(%4), %%eax\n"
26739- "21: movl 4(%4), %%edx\n"
26740+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26741+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26742 " movnti %%eax, 0(%3)\n"
26743 " movnti %%edx, 4(%3)\n"
26744- "3: movl 8(%4), %%eax\n"
26745- "31: movl 12(%4),%%edx\n"
26746+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26747+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26748 " movnti %%eax, 8(%3)\n"
26749 " movnti %%edx, 12(%3)\n"
26750- "4: movl 16(%4), %%eax\n"
26751- "41: movl 20(%4), %%edx\n"
26752+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26753+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26754 " movnti %%eax, 16(%3)\n"
26755 " movnti %%edx, 20(%3)\n"
26756- "10: movl 24(%4), %%eax\n"
26757- "51: movl 28(%4), %%edx\n"
26758+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26759+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26760 " movnti %%eax, 24(%3)\n"
26761 " movnti %%edx, 28(%3)\n"
26762- "11: movl 32(%4), %%eax\n"
26763- "61: movl 36(%4), %%edx\n"
26764+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26765+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26766 " movnti %%eax, 32(%3)\n"
26767 " movnti %%edx, 36(%3)\n"
26768- "12: movl 40(%4), %%eax\n"
26769- "71: movl 44(%4), %%edx\n"
26770+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26771+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26772 " movnti %%eax, 40(%3)\n"
26773 " movnti %%edx, 44(%3)\n"
26774- "13: movl 48(%4), %%eax\n"
26775- "81: movl 52(%4), %%edx\n"
26776+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26777+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26778 " movnti %%eax, 48(%3)\n"
26779 " movnti %%edx, 52(%3)\n"
26780- "14: movl 56(%4), %%eax\n"
26781- "91: movl 60(%4), %%edx\n"
26782+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26783+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26784 " movnti %%eax, 56(%3)\n"
26785 " movnti %%edx, 60(%3)\n"
26786 " addl $-64, %0\n"
26787@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26788 " shrl $2, %0\n"
26789 " andl $3, %%eax\n"
26790 " cld\n"
26791- "6: rep; movsl\n"
26792+ "6: rep; "__copyuser_seg" movsl\n"
26793 " movl %%eax,%0\n"
26794- "7: rep; movsb\n"
26795+ "7: rep; "__copyuser_seg" movsb\n"
26796 "8:\n"
26797 ".section .fixup,\"ax\"\n"
26798 "9: lea 0(%%eax,%0,4),%0\n"
26799@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26800 */
26801 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26802 unsigned long size);
26803-unsigned long __copy_user_intel(void __user *to, const void *from,
26804+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26805+ unsigned long size);
26806+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26807 unsigned long size);
26808 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26809 const void __user *from, unsigned long size);
26810 #endif /* CONFIG_X86_INTEL_USERCOPY */
26811
26812 /* Generic arbitrary sized copy. */
26813-#define __copy_user(to, from, size) \
26814+#define __copy_user(to, from, size, prefix, set, restore) \
26815 do { \
26816 int __d0, __d1, __d2; \
26817 __asm__ __volatile__( \
26818+ set \
26819 " cmp $7,%0\n" \
26820 " jbe 1f\n" \
26821 " movl %1,%0\n" \
26822 " negl %0\n" \
26823 " andl $7,%0\n" \
26824 " subl %0,%3\n" \
26825- "4: rep; movsb\n" \
26826+ "4: rep; "prefix"movsb\n" \
26827 " movl %3,%0\n" \
26828 " shrl $2,%0\n" \
26829 " andl $3,%3\n" \
26830 " .align 2,0x90\n" \
26831- "0: rep; movsl\n" \
26832+ "0: rep; "prefix"movsl\n" \
26833 " movl %3,%0\n" \
26834- "1: rep; movsb\n" \
26835+ "1: rep; "prefix"movsb\n" \
26836 "2:\n" \
26837+ restore \
26838 ".section .fixup,\"ax\"\n" \
26839 "5: addl %3,%0\n" \
26840 " jmp 2b\n" \
26841@@ -538,14 +650,14 @@ do { \
26842 " negl %0\n" \
26843 " andl $7,%0\n" \
26844 " subl %0,%3\n" \
26845- "4: rep; movsb\n" \
26846+ "4: rep; "__copyuser_seg"movsb\n" \
26847 " movl %3,%0\n" \
26848 " shrl $2,%0\n" \
26849 " andl $3,%3\n" \
26850 " .align 2,0x90\n" \
26851- "0: rep; movsl\n" \
26852+ "0: rep; "__copyuser_seg"movsl\n" \
26853 " movl %3,%0\n" \
26854- "1: rep; movsb\n" \
26855+ "1: rep; "__copyuser_seg"movsb\n" \
26856 "2:\n" \
26857 ".section .fixup,\"ax\"\n" \
26858 "5: addl %3,%0\n" \
26859@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26860 {
26861 stac();
26862 if (movsl_is_ok(to, from, n))
26863- __copy_user(to, from, n);
26864+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26865 else
26866- n = __copy_user_intel(to, from, n);
26867+ n = __generic_copy_to_user_intel(to, from, n);
26868 clac();
26869 return n;
26870 }
26871@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26872 {
26873 stac();
26874 if (movsl_is_ok(to, from, n))
26875- __copy_user(to, from, n);
26876+ __copy_user(to, from, n, __copyuser_seg, "", "");
26877 else
26878- n = __copy_user_intel((void __user *)to,
26879- (const void *)from, n);
26880+ n = __generic_copy_from_user_intel(to, from, n);
26881 clac();
26882 return n;
26883 }
26884@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26885 if (n > 64 && cpu_has_xmm2)
26886 n = __copy_user_intel_nocache(to, from, n);
26887 else
26888- __copy_user(to, from, n);
26889+ __copy_user(to, from, n, __copyuser_seg, "", "");
26890 #else
26891- __copy_user(to, from, n);
26892+ __copy_user(to, from, n, __copyuser_seg, "", "");
26893 #endif
26894 clac();
26895 return n;
26896 }
26897 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26898
26899-/**
26900- * copy_to_user: - Copy a block of data into user space.
26901- * @to: Destination address, in user space.
26902- * @from: Source address, in kernel space.
26903- * @n: Number of bytes to copy.
26904- *
26905- * Context: User context only. This function may sleep.
26906- *
26907- * Copy data from kernel space to user space.
26908- *
26909- * Returns number of bytes that could not be copied.
26910- * On success, this will be zero.
26911- */
26912-unsigned long
26913-copy_to_user(void __user *to, const void *from, unsigned long n)
26914-{
26915- if (access_ok(VERIFY_WRITE, to, n))
26916- n = __copy_to_user(to, from, n);
26917- return n;
26918-}
26919-EXPORT_SYMBOL(copy_to_user);
26920-
26921-/**
26922- * copy_from_user: - Copy a block of data from user space.
26923- * @to: Destination address, in kernel space.
26924- * @from: Source address, in user space.
26925- * @n: Number of bytes to copy.
26926- *
26927- * Context: User context only. This function may sleep.
26928- *
26929- * Copy data from user space to kernel space.
26930- *
26931- * Returns number of bytes that could not be copied.
26932- * On success, this will be zero.
26933- *
26934- * If some data could not be copied, this function will pad the copied
26935- * data to the requested size using zero bytes.
26936- */
26937-unsigned long
26938-_copy_from_user(void *to, const void __user *from, unsigned long n)
26939-{
26940- if (access_ok(VERIFY_READ, from, n))
26941- n = __copy_from_user(to, from, n);
26942- else
26943- memset(to, 0, n);
26944- return n;
26945-}
26946-EXPORT_SYMBOL(_copy_from_user);
26947-
26948 void copy_from_user_overflow(void)
26949 {
26950 WARN(1, "Buffer overflow detected!\n");
26951 }
26952 EXPORT_SYMBOL(copy_from_user_overflow);
26953+
26954+void copy_to_user_overflow(void)
26955+{
26956+ WARN(1, "Buffer overflow detected!\n");
26957+}
26958+EXPORT_SYMBOL(copy_to_user_overflow);
26959+
26960+#ifdef CONFIG_PAX_MEMORY_UDEREF
26961+void __set_fs(mm_segment_t x)
26962+{
26963+ switch (x.seg) {
26964+ case 0:
26965+ loadsegment(gs, 0);
26966+ break;
26967+ case TASK_SIZE_MAX:
26968+ loadsegment(gs, __USER_DS);
26969+ break;
26970+ case -1UL:
26971+ loadsegment(gs, __KERNEL_DS);
26972+ break;
26973+ default:
26974+ BUG();
26975+ }
26976+ return;
26977+}
26978+EXPORT_SYMBOL(__set_fs);
26979+
26980+void set_fs(mm_segment_t x)
26981+{
26982+ current_thread_info()->addr_limit = x;
26983+ __set_fs(x);
26984+}
26985+EXPORT_SYMBOL(set_fs);
26986+#endif
26987diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26988index 05928aa..b33dea1 100644
26989--- a/arch/x86/lib/usercopy_64.c
26990+++ b/arch/x86/lib/usercopy_64.c
26991@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26992 _ASM_EXTABLE(0b,3b)
26993 _ASM_EXTABLE(1b,2b)
26994 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26995- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26996+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26997 [zero] "r" (0UL), [eight] "r" (8UL));
26998 clac();
26999 return size;
27000@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27001 }
27002 EXPORT_SYMBOL(clear_user);
27003
27004-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27005+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27006 {
27007- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27008- return copy_user_generic((__force void *)to, (__force void *)from, len);
27009- }
27010- return len;
27011+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27012+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27013+ return len;
27014 }
27015 EXPORT_SYMBOL(copy_in_user);
27016
27017@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27018 * it is not necessary to optimize tail handling.
27019 */
27020 unsigned long
27021-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27022+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27023 {
27024 char c;
27025 unsigned zero_len;
27026@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27027 clac();
27028 return len;
27029 }
27030+
27031+void copy_from_user_overflow(void)
27032+{
27033+ WARN(1, "Buffer overflow detected!\n");
27034+}
27035+EXPORT_SYMBOL(copy_from_user_overflow);
27036+
27037+void copy_to_user_overflow(void)
27038+{
27039+ WARN(1, "Buffer overflow detected!\n");
27040+}
27041+EXPORT_SYMBOL(copy_to_user_overflow);
27042diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27043index 903ec1e..c4166b2 100644
27044--- a/arch/x86/mm/extable.c
27045+++ b/arch/x86/mm/extable.c
27046@@ -6,12 +6,24 @@
27047 static inline unsigned long
27048 ex_insn_addr(const struct exception_table_entry *x)
27049 {
27050- return (unsigned long)&x->insn + x->insn;
27051+ unsigned long reloc = 0;
27052+
27053+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27054+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27055+#endif
27056+
27057+ return (unsigned long)&x->insn + x->insn + reloc;
27058 }
27059 static inline unsigned long
27060 ex_fixup_addr(const struct exception_table_entry *x)
27061 {
27062- return (unsigned long)&x->fixup + x->fixup;
27063+ unsigned long reloc = 0;
27064+
27065+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27066+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27067+#endif
27068+
27069+ return (unsigned long)&x->fixup + x->fixup + reloc;
27070 }
27071
27072 int fixup_exception(struct pt_regs *regs)
27073@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27074 unsigned long new_ip;
27075
27076 #ifdef CONFIG_PNPBIOS
27077- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27078+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27079 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27080 extern u32 pnp_bios_is_utter_crap;
27081 pnp_bios_is_utter_crap = 1;
27082@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27083 i += 4;
27084 p->fixup -= i;
27085 i += 4;
27086+
27087+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27088+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27089+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27090+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27091+#endif
27092+
27093 }
27094 }
27095
27096diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27097index fb674fd..1be28b9 100644
27098--- a/arch/x86/mm/fault.c
27099+++ b/arch/x86/mm/fault.c
27100@@ -13,12 +13,19 @@
27101 #include <linux/perf_event.h> /* perf_sw_event */
27102 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27103 #include <linux/prefetch.h> /* prefetchw */
27104+#include <linux/unistd.h>
27105+#include <linux/compiler.h>
27106
27107 #include <asm/traps.h> /* dotraplinkage, ... */
27108 #include <asm/pgalloc.h> /* pgd_*(), ... */
27109 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27110 #include <asm/fixmap.h> /* VSYSCALL_START */
27111 #include <asm/context_tracking.h> /* exception_enter(), ... */
27112+#include <asm/tlbflush.h>
27113+
27114+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27115+#include <asm/stacktrace.h>
27116+#endif
27117
27118 /*
27119 * Page fault error code bits:
27120@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27121 int ret = 0;
27122
27123 /* kprobe_running() needs smp_processor_id() */
27124- if (kprobes_built_in() && !user_mode_vm(regs)) {
27125+ if (kprobes_built_in() && !user_mode(regs)) {
27126 preempt_disable();
27127 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27128 ret = 1;
27129@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27130 return !instr_lo || (instr_lo>>1) == 1;
27131 case 0x00:
27132 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27133- if (probe_kernel_address(instr, opcode))
27134+ if (user_mode(regs)) {
27135+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27136+ return 0;
27137+ } else if (probe_kernel_address(instr, opcode))
27138 return 0;
27139
27140 *prefetch = (instr_lo == 0xF) &&
27141@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27142 while (instr < max_instr) {
27143 unsigned char opcode;
27144
27145- if (probe_kernel_address(instr, opcode))
27146+ if (user_mode(regs)) {
27147+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27148+ break;
27149+ } else if (probe_kernel_address(instr, opcode))
27150 break;
27151
27152 instr++;
27153@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27154 force_sig_info(si_signo, &info, tsk);
27155 }
27156
27157+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27158+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27159+#endif
27160+
27161+#ifdef CONFIG_PAX_EMUTRAMP
27162+static int pax_handle_fetch_fault(struct pt_regs *regs);
27163+#endif
27164+
27165+#ifdef CONFIG_PAX_PAGEEXEC
27166+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27167+{
27168+ pgd_t *pgd;
27169+ pud_t *pud;
27170+ pmd_t *pmd;
27171+
27172+ pgd = pgd_offset(mm, address);
27173+ if (!pgd_present(*pgd))
27174+ return NULL;
27175+ pud = pud_offset(pgd, address);
27176+ if (!pud_present(*pud))
27177+ return NULL;
27178+ pmd = pmd_offset(pud, address);
27179+ if (!pmd_present(*pmd))
27180+ return NULL;
27181+ return pmd;
27182+}
27183+#endif
27184+
27185 DEFINE_SPINLOCK(pgd_lock);
27186 LIST_HEAD(pgd_list);
27187
27188@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27189 for (address = VMALLOC_START & PMD_MASK;
27190 address >= TASK_SIZE && address < FIXADDR_TOP;
27191 address += PMD_SIZE) {
27192+
27193+#ifdef CONFIG_PAX_PER_CPU_PGD
27194+ unsigned long cpu;
27195+#else
27196 struct page *page;
27197+#endif
27198
27199 spin_lock(&pgd_lock);
27200+
27201+#ifdef CONFIG_PAX_PER_CPU_PGD
27202+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27203+ pgd_t *pgd = get_cpu_pgd(cpu);
27204+ pmd_t *ret;
27205+#else
27206 list_for_each_entry(page, &pgd_list, lru) {
27207+ pgd_t *pgd = page_address(page);
27208 spinlock_t *pgt_lock;
27209 pmd_t *ret;
27210
27211@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
27212 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27213
27214 spin_lock(pgt_lock);
27215- ret = vmalloc_sync_one(page_address(page), address);
27216+#endif
27217+
27218+ ret = vmalloc_sync_one(pgd, address);
27219+
27220+#ifndef CONFIG_PAX_PER_CPU_PGD
27221 spin_unlock(pgt_lock);
27222+#endif
27223
27224 if (!ret)
27225 break;
27226@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27227 * an interrupt in the middle of a task switch..
27228 */
27229 pgd_paddr = read_cr3();
27230+
27231+#ifdef CONFIG_PAX_PER_CPU_PGD
27232+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27233+#endif
27234+
27235 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27236 if (!pmd_k)
27237 return -1;
27238@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27239 * happen within a race in page table update. In the later
27240 * case just flush:
27241 */
27242+
27243+#ifdef CONFIG_PAX_PER_CPU_PGD
27244+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27245+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27246+#else
27247 pgd = pgd_offset(current->active_mm, address);
27248+#endif
27249+
27250 pgd_ref = pgd_offset_k(address);
27251 if (pgd_none(*pgd_ref))
27252 return -1;
27253@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27254 static int is_errata100(struct pt_regs *regs, unsigned long address)
27255 {
27256 #ifdef CONFIG_X86_64
27257- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27258+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27259 return 1;
27260 #endif
27261 return 0;
27262@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27263 }
27264
27265 static const char nx_warning[] = KERN_CRIT
27266-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27267+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27268
27269 static void
27270 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27271@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27272 if (!oops_may_print())
27273 return;
27274
27275- if (error_code & PF_INSTR) {
27276+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27277 unsigned int level;
27278
27279 pte_t *pte = lookup_address(address, &level);
27280
27281 if (pte && pte_present(*pte) && !pte_exec(*pte))
27282- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27283+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27284 }
27285
27286+#ifdef CONFIG_PAX_KERNEXEC
27287+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27288+ if (current->signal->curr_ip)
27289+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27290+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27291+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27292+ else
27293+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27294+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27295+ }
27296+#endif
27297+
27298 printk(KERN_ALERT "BUG: unable to handle kernel ");
27299 if (address < PAGE_SIZE)
27300 printk(KERN_CONT "NULL pointer dereference");
27301@@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27302 return;
27303 }
27304 #endif
27305+
27306+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27307+ if (pax_is_fetch_fault(regs, error_code, address)) {
27308+
27309+#ifdef CONFIG_PAX_EMUTRAMP
27310+ switch (pax_handle_fetch_fault(regs)) {
27311+ case 2:
27312+ return;
27313+ }
27314+#endif
27315+
27316+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27317+ do_group_exit(SIGKILL);
27318+ }
27319+#endif
27320+
27321 /* Kernel addresses are always protection faults: */
27322 if (address >= TASK_SIZE)
27323 error_code |= PF_PROT;
27324@@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27325 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27326 printk(KERN_ERR
27327 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27328- tsk->comm, tsk->pid, address);
27329+ tsk->comm, task_pid_nr(tsk), address);
27330 code = BUS_MCEERR_AR;
27331 }
27332 #endif
27333@@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27334 return 1;
27335 }
27336
27337+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27338+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27339+{
27340+ pte_t *pte;
27341+ pmd_t *pmd;
27342+ spinlock_t *ptl;
27343+ unsigned char pte_mask;
27344+
27345+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27346+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27347+ return 0;
27348+
27349+ /* PaX: it's our fault, let's handle it if we can */
27350+
27351+ /* PaX: take a look at read faults before acquiring any locks */
27352+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27353+ /* instruction fetch attempt from a protected page in user mode */
27354+ up_read(&mm->mmap_sem);
27355+
27356+#ifdef CONFIG_PAX_EMUTRAMP
27357+ switch (pax_handle_fetch_fault(regs)) {
27358+ case 2:
27359+ return 1;
27360+ }
27361+#endif
27362+
27363+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27364+ do_group_exit(SIGKILL);
27365+ }
27366+
27367+ pmd = pax_get_pmd(mm, address);
27368+ if (unlikely(!pmd))
27369+ return 0;
27370+
27371+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27372+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27373+ pte_unmap_unlock(pte, ptl);
27374+ return 0;
27375+ }
27376+
27377+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27378+ /* write attempt to a protected page in user mode */
27379+ pte_unmap_unlock(pte, ptl);
27380+ return 0;
27381+ }
27382+
27383+#ifdef CONFIG_SMP
27384+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27385+#else
27386+ if (likely(address > get_limit(regs->cs)))
27387+#endif
27388+ {
27389+ set_pte(pte, pte_mkread(*pte));
27390+ __flush_tlb_one(address);
27391+ pte_unmap_unlock(pte, ptl);
27392+ up_read(&mm->mmap_sem);
27393+ return 1;
27394+ }
27395+
27396+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27397+
27398+ /*
27399+ * PaX: fill DTLB with user rights and retry
27400+ */
27401+ __asm__ __volatile__ (
27402+ "orb %2,(%1)\n"
27403+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27404+/*
27405+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27406+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27407+ * page fault when examined during a TLB load attempt. this is true not only
27408+ * for PTEs holding a non-present entry but also present entries that will
27409+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27410+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27411+ * for our target pages since their PTEs are simply not in the TLBs at all.
27412+
27413+ * the best thing in omitting it is that we gain around 15-20% speed in the
27414+ * fast path of the page fault handler and can get rid of tracing since we
27415+ * can no longer flush unintended entries.
27416+ */
27417+ "invlpg (%0)\n"
27418+#endif
27419+ __copyuser_seg"testb $0,(%0)\n"
27420+ "xorb %3,(%1)\n"
27421+ :
27422+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27423+ : "memory", "cc");
27424+ pte_unmap_unlock(pte, ptl);
27425+ up_read(&mm->mmap_sem);
27426+ return 1;
27427+}
27428+#endif
27429+
27430 /*
27431 * Handle a spurious fault caused by a stale TLB entry.
27432 *
27433@@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
27434 static inline int
27435 access_error(unsigned long error_code, struct vm_area_struct *vma)
27436 {
27437+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27438+ return 1;
27439+
27440 if (error_code & PF_WRITE) {
27441 /* write, present and write, not present: */
27442 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27443@@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27444 if (error_code & PF_USER)
27445 return false;
27446
27447- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27448+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27449 return false;
27450
27451 return true;
27452@@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27453 {
27454 struct vm_area_struct *vma;
27455 struct task_struct *tsk;
27456- unsigned long address;
27457 struct mm_struct *mm;
27458 int fault;
27459 int write = error_code & PF_WRITE;
27460 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27461 (write ? FAULT_FLAG_WRITE : 0);
27462
27463- tsk = current;
27464- mm = tsk->mm;
27465-
27466 /* Get the faulting address: */
27467- address = read_cr2();
27468+ unsigned long address = read_cr2();
27469+
27470+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27471+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27472+ if (!search_exception_tables(regs->ip)) {
27473+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27474+ bad_area_nosemaphore(regs, error_code, address);
27475+ return;
27476+ }
27477+ if (address < PAX_USER_SHADOW_BASE) {
27478+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27479+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27480+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27481+ } else
27482+ address -= PAX_USER_SHADOW_BASE;
27483+ }
27484+#endif
27485+
27486+ tsk = current;
27487+ mm = tsk->mm;
27488
27489 /*
27490 * Detect and handle instructions that would cause a page fault for
27491@@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27492 * User-mode registers count as a user access even for any
27493 * potential system fault or CPU buglet:
27494 */
27495- if (user_mode_vm(regs)) {
27496+ if (user_mode(regs)) {
27497 local_irq_enable();
27498 error_code |= PF_USER;
27499 } else {
27500@@ -1146,6 +1355,11 @@ retry:
27501 might_sleep();
27502 }
27503
27504+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27505+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27506+ return;
27507+#endif
27508+
27509 vma = find_vma(mm, address);
27510 if (unlikely(!vma)) {
27511 bad_area(regs, error_code, address);
27512@@ -1157,18 +1371,24 @@ retry:
27513 bad_area(regs, error_code, address);
27514 return;
27515 }
27516- if (error_code & PF_USER) {
27517- /*
27518- * Accessing the stack below %sp is always a bug.
27519- * The large cushion allows instructions like enter
27520- * and pusha to work. ("enter $65535, $31" pushes
27521- * 32 pointers and then decrements %sp by 65535.)
27522- */
27523- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27524- bad_area(regs, error_code, address);
27525- return;
27526- }
27527+ /*
27528+ * Accessing the stack below %sp is always a bug.
27529+ * The large cushion allows instructions like enter
27530+ * and pusha to work. ("enter $65535, $31" pushes
27531+ * 32 pointers and then decrements %sp by 65535.)
27532+ */
27533+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27534+ bad_area(regs, error_code, address);
27535+ return;
27536 }
27537+
27538+#ifdef CONFIG_PAX_SEGMEXEC
27539+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27540+ bad_area(regs, error_code, address);
27541+ return;
27542+ }
27543+#endif
27544+
27545 if (unlikely(expand_stack(vma, address))) {
27546 bad_area(regs, error_code, address);
27547 return;
27548@@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27549 __do_page_fault(regs, error_code);
27550 exception_exit(regs);
27551 }
27552+
27553+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27554+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27555+{
27556+ struct mm_struct *mm = current->mm;
27557+ unsigned long ip = regs->ip;
27558+
27559+ if (v8086_mode(regs))
27560+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27561+
27562+#ifdef CONFIG_PAX_PAGEEXEC
27563+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27564+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27565+ return true;
27566+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27567+ return true;
27568+ return false;
27569+ }
27570+#endif
27571+
27572+#ifdef CONFIG_PAX_SEGMEXEC
27573+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27574+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27575+ return true;
27576+ return false;
27577+ }
27578+#endif
27579+
27580+ return false;
27581+}
27582+#endif
27583+
27584+#ifdef CONFIG_PAX_EMUTRAMP
27585+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27586+{
27587+ int err;
27588+
27589+ do { /* PaX: libffi trampoline emulation */
27590+ unsigned char mov, jmp;
27591+ unsigned int addr1, addr2;
27592+
27593+#ifdef CONFIG_X86_64
27594+ if ((regs->ip + 9) >> 32)
27595+ break;
27596+#endif
27597+
27598+ err = get_user(mov, (unsigned char __user *)regs->ip);
27599+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27600+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27601+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27602+
27603+ if (err)
27604+ break;
27605+
27606+ if (mov == 0xB8 && jmp == 0xE9) {
27607+ regs->ax = addr1;
27608+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27609+ return 2;
27610+ }
27611+ } while (0);
27612+
27613+ do { /* PaX: gcc trampoline emulation #1 */
27614+ unsigned char mov1, mov2;
27615+ unsigned short jmp;
27616+ unsigned int addr1, addr2;
27617+
27618+#ifdef CONFIG_X86_64
27619+ if ((regs->ip + 11) >> 32)
27620+ break;
27621+#endif
27622+
27623+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27624+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27625+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27626+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27627+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27628+
27629+ if (err)
27630+ break;
27631+
27632+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27633+ regs->cx = addr1;
27634+ regs->ax = addr2;
27635+ regs->ip = addr2;
27636+ return 2;
27637+ }
27638+ } while (0);
27639+
27640+ do { /* PaX: gcc trampoline emulation #2 */
27641+ unsigned char mov, jmp;
27642+ unsigned int addr1, addr2;
27643+
27644+#ifdef CONFIG_X86_64
27645+ if ((regs->ip + 9) >> 32)
27646+ break;
27647+#endif
27648+
27649+ err = get_user(mov, (unsigned char __user *)regs->ip);
27650+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27651+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27652+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27653+
27654+ if (err)
27655+ break;
27656+
27657+ if (mov == 0xB9 && jmp == 0xE9) {
27658+ regs->cx = addr1;
27659+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27660+ return 2;
27661+ }
27662+ } while (0);
27663+
27664+ return 1; /* PaX in action */
27665+}
27666+
27667+#ifdef CONFIG_X86_64
27668+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27669+{
27670+ int err;
27671+
27672+ do { /* PaX: libffi trampoline emulation */
27673+ unsigned short mov1, mov2, jmp1;
27674+ unsigned char stcclc, jmp2;
27675+ unsigned long addr1, addr2;
27676+
27677+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27678+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27679+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27680+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27681+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27682+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27683+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27684+
27685+ if (err)
27686+ break;
27687+
27688+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27689+ regs->r11 = addr1;
27690+ regs->r10 = addr2;
27691+ if (stcclc == 0xF8)
27692+ regs->flags &= ~X86_EFLAGS_CF;
27693+ else
27694+ regs->flags |= X86_EFLAGS_CF;
27695+ regs->ip = addr1;
27696+ return 2;
27697+ }
27698+ } while (0);
27699+
27700+ do { /* PaX: gcc trampoline emulation #1 */
27701+ unsigned short mov1, mov2, jmp1;
27702+ unsigned char jmp2;
27703+ unsigned int addr1;
27704+ unsigned long addr2;
27705+
27706+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27707+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27708+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27709+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27710+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27711+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27712+
27713+ if (err)
27714+ break;
27715+
27716+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27717+ regs->r11 = addr1;
27718+ regs->r10 = addr2;
27719+ regs->ip = addr1;
27720+ return 2;
27721+ }
27722+ } while (0);
27723+
27724+ do { /* PaX: gcc trampoline emulation #2 */
27725+ unsigned short mov1, mov2, jmp1;
27726+ unsigned char jmp2;
27727+ unsigned long addr1, addr2;
27728+
27729+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27730+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27731+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27732+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27733+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27734+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27735+
27736+ if (err)
27737+ break;
27738+
27739+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27740+ regs->r11 = addr1;
27741+ regs->r10 = addr2;
27742+ regs->ip = addr1;
27743+ return 2;
27744+ }
27745+ } while (0);
27746+
27747+ return 1; /* PaX in action */
27748+}
27749+#endif
27750+
27751+/*
27752+ * PaX: decide what to do with offenders (regs->ip = fault address)
27753+ *
27754+ * returns 1 when task should be killed
27755+ * 2 when gcc trampoline was detected
27756+ */
27757+static int pax_handle_fetch_fault(struct pt_regs *regs)
27758+{
27759+ if (v8086_mode(regs))
27760+ return 1;
27761+
27762+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27763+ return 1;
27764+
27765+#ifdef CONFIG_X86_32
27766+ return pax_handle_fetch_fault_32(regs);
27767+#else
27768+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27769+ return pax_handle_fetch_fault_32(regs);
27770+ else
27771+ return pax_handle_fetch_fault_64(regs);
27772+#endif
27773+}
27774+#endif
27775+
27776+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27777+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27778+{
27779+ long i;
27780+
27781+ printk(KERN_ERR "PAX: bytes at PC: ");
27782+ for (i = 0; i < 20; i++) {
27783+ unsigned char c;
27784+ if (get_user(c, (unsigned char __force_user *)pc+i))
27785+ printk(KERN_CONT "?? ");
27786+ else
27787+ printk(KERN_CONT "%02x ", c);
27788+ }
27789+ printk("\n");
27790+
27791+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27792+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27793+ unsigned long c;
27794+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27795+#ifdef CONFIG_X86_32
27796+ printk(KERN_CONT "???????? ");
27797+#else
27798+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27799+ printk(KERN_CONT "???????? ???????? ");
27800+ else
27801+ printk(KERN_CONT "???????????????? ");
27802+#endif
27803+ } else {
27804+#ifdef CONFIG_X86_64
27805+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27806+ printk(KERN_CONT "%08x ", (unsigned int)c);
27807+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27808+ } else
27809+#endif
27810+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27811+ }
27812+ }
27813+ printk("\n");
27814+}
27815+#endif
27816+
27817+/**
27818+ * probe_kernel_write(): safely attempt to write to a location
27819+ * @dst: address to write to
27820+ * @src: pointer to the data that shall be written
27821+ * @size: size of the data chunk
27822+ *
27823+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27824+ * happens, handle that and return -EFAULT.
27825+ */
27826+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27827+{
27828+ long ret;
27829+ mm_segment_t old_fs = get_fs();
27830+
27831+ set_fs(KERNEL_DS);
27832+ pagefault_disable();
27833+ pax_open_kernel();
27834+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27835+ pax_close_kernel();
27836+ pagefault_enable();
27837+ set_fs(old_fs);
27838+
27839+ return ret ? -EFAULT : 0;
27840+}
27841diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27842index dd74e46..7d26398 100644
27843--- a/arch/x86/mm/gup.c
27844+++ b/arch/x86/mm/gup.c
27845@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27846 addr = start;
27847 len = (unsigned long) nr_pages << PAGE_SHIFT;
27848 end = start + len;
27849- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27850+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27851 (void __user *)start, len)))
27852 return 0;
27853
27854diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27855index 6f31ee5..8ee4164 100644
27856--- a/arch/x86/mm/highmem_32.c
27857+++ b/arch/x86/mm/highmem_32.c
27858@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27859 idx = type + KM_TYPE_NR*smp_processor_id();
27860 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27861 BUG_ON(!pte_none(*(kmap_pte-idx)));
27862+
27863+ pax_open_kernel();
27864 set_pte(kmap_pte-idx, mk_pte(page, prot));
27865+ pax_close_kernel();
27866+
27867 arch_flush_lazy_mmu_mode();
27868
27869 return (void *)vaddr;
27870diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27871index ae1aa71..56316db 100644
27872--- a/arch/x86/mm/hugetlbpage.c
27873+++ b/arch/x86/mm/hugetlbpage.c
27874@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27875 info.flags = 0;
27876 info.length = len;
27877 info.low_limit = TASK_UNMAPPED_BASE;
27878+
27879+#ifdef CONFIG_PAX_RANDMMAP
27880+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27881+ info.low_limit += current->mm->delta_mmap;
27882+#endif
27883+
27884 info.high_limit = TASK_SIZE;
27885 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27886 info.align_offset = 0;
27887@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27888 VM_BUG_ON(addr != -ENOMEM);
27889 info.flags = 0;
27890 info.low_limit = TASK_UNMAPPED_BASE;
27891+
27892+#ifdef CONFIG_PAX_RANDMMAP
27893+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27894+ info.low_limit += current->mm->delta_mmap;
27895+#endif
27896+
27897 info.high_limit = TASK_SIZE;
27898 addr = vm_unmapped_area(&info);
27899 }
27900@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27901 struct hstate *h = hstate_file(file);
27902 struct mm_struct *mm = current->mm;
27903 struct vm_area_struct *vma;
27904+ unsigned long pax_task_size = TASK_SIZE;
27905+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27906
27907 if (len & ~huge_page_mask(h))
27908 return -EINVAL;
27909- if (len > TASK_SIZE)
27910+
27911+#ifdef CONFIG_PAX_SEGMEXEC
27912+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27913+ pax_task_size = SEGMEXEC_TASK_SIZE;
27914+#endif
27915+
27916+ pax_task_size -= PAGE_SIZE;
27917+
27918+ if (len > pax_task_size)
27919 return -ENOMEM;
27920
27921 if (flags & MAP_FIXED) {
27922@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27923 return addr;
27924 }
27925
27926+#ifdef CONFIG_PAX_RANDMMAP
27927+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27928+#endif
27929+
27930 if (addr) {
27931 addr = ALIGN(addr, huge_page_size(h));
27932 vma = find_vma(mm, addr);
27933- if (TASK_SIZE - len >= addr &&
27934- (!vma || addr + len <= vma->vm_start))
27935+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27936 return addr;
27937 }
27938 if (mm->get_unmapped_area == arch_get_unmapped_area)
27939diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27940index d7aea41..0fc945b 100644
27941--- a/arch/x86/mm/init.c
27942+++ b/arch/x86/mm/init.c
27943@@ -4,6 +4,7 @@
27944 #include <linux/swap.h>
27945 #include <linux/memblock.h>
27946 #include <linux/bootmem.h> /* for max_low_pfn */
27947+#include <linux/tboot.h>
27948
27949 #include <asm/cacheflush.h>
27950 #include <asm/e820.h>
27951@@ -16,6 +17,8 @@
27952 #include <asm/tlb.h>
27953 #include <asm/proto.h>
27954 #include <asm/dma.h> /* for MAX_DMA_PFN */
27955+#include <asm/desc.h>
27956+#include <asm/bios_ebda.h>
27957
27958 unsigned long __initdata pgt_buf_start;
27959 unsigned long __meminitdata pgt_buf_end;
27960@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27961 {
27962 int i;
27963 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27964- unsigned long start = 0, good_end;
27965+ unsigned long start = 0x100000, good_end;
27966 phys_addr_t base;
27967
27968 for (i = 0; i < nr_range; i++) {
27969@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27970 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27971 * mmio resources as well as potential bios/acpi data regions.
27972 */
27973+
27974+#ifdef CONFIG_GRKERNSEC_KMEM
27975+static unsigned int ebda_start __read_only;
27976+static unsigned int ebda_end __read_only;
27977+#endif
27978+
27979 int devmem_is_allowed(unsigned long pagenr)
27980 {
27981- if (pagenr < 256)
27982+#ifdef CONFIG_GRKERNSEC_KMEM
27983+ /* allow BDA */
27984+ if (!pagenr)
27985 return 1;
27986+ /* allow EBDA */
27987+ if (pagenr >= ebda_start && pagenr < ebda_end)
27988+ return 1;
27989+ /* if tboot is in use, allow access to its hardcoded serial log range */
27990+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27991+ return 1;
27992+#else
27993+ if (!pagenr)
27994+ return 1;
27995+#ifdef CONFIG_VM86
27996+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27997+ return 1;
27998+#endif
27999+#endif
28000+
28001+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28002+ return 1;
28003+#ifdef CONFIG_GRKERNSEC_KMEM
28004+ /* throw out everything else below 1MB */
28005+ if (pagenr <= 256)
28006+ return 0;
28007+#endif
28008 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28009 return 0;
28010 if (!page_is_ram(pagenr))
28011@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28012 #endif
28013 }
28014
28015+#ifdef CONFIG_GRKERNSEC_KMEM
28016+static inline void gr_init_ebda(void)
28017+{
28018+ unsigned int ebda_addr;
28019+ unsigned int ebda_size = 0;
28020+
28021+ ebda_addr = get_bios_ebda();
28022+ if (ebda_addr) {
28023+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28024+ ebda_size <<= 10;
28025+ }
28026+ if (ebda_addr && ebda_size) {
28027+ ebda_start = ebda_addr >> PAGE_SHIFT;
28028+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28029+ } else {
28030+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28031+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28032+ }
28033+}
28034+#else
28035+static inline void gr_init_ebda(void) { }
28036+#endif
28037+
28038 void free_initmem(void)
28039 {
28040+#ifdef CONFIG_PAX_KERNEXEC
28041+#ifdef CONFIG_X86_32
28042+ /* PaX: limit KERNEL_CS to actual size */
28043+ unsigned long addr, limit;
28044+ struct desc_struct d;
28045+ int cpu;
28046+#else
28047+ pgd_t *pgd;
28048+ pud_t *pud;
28049+ pmd_t *pmd;
28050+ unsigned long addr, end;
28051+#endif
28052+#endif
28053+
28054+ gr_init_ebda();
28055+
28056+#ifdef CONFIG_PAX_KERNEXEC
28057+#ifdef CONFIG_X86_32
28058+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28059+ limit = (limit - 1UL) >> PAGE_SHIFT;
28060+
28061+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28062+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28063+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28064+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28065+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28066+ }
28067+
28068+ /* PaX: make KERNEL_CS read-only */
28069+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28070+ if (!paravirt_enabled())
28071+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28072+/*
28073+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28074+ pgd = pgd_offset_k(addr);
28075+ pud = pud_offset(pgd, addr);
28076+ pmd = pmd_offset(pud, addr);
28077+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28078+ }
28079+*/
28080+#ifdef CONFIG_X86_PAE
28081+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28082+/*
28083+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28084+ pgd = pgd_offset_k(addr);
28085+ pud = pud_offset(pgd, addr);
28086+ pmd = pmd_offset(pud, addr);
28087+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28088+ }
28089+*/
28090+#endif
28091+
28092+#ifdef CONFIG_MODULES
28093+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28094+#endif
28095+
28096+#else
28097+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28098+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28099+ pgd = pgd_offset_k(addr);
28100+ pud = pud_offset(pgd, addr);
28101+ pmd = pmd_offset(pud, addr);
28102+ if (!pmd_present(*pmd))
28103+ continue;
28104+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28105+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28106+ else
28107+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28108+ }
28109+
28110+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28111+ end = addr + KERNEL_IMAGE_SIZE;
28112+ for (; addr < end; addr += PMD_SIZE) {
28113+ pgd = pgd_offset_k(addr);
28114+ pud = pud_offset(pgd, addr);
28115+ pmd = pmd_offset(pud, addr);
28116+ if (!pmd_present(*pmd))
28117+ continue;
28118+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28119+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28120+ }
28121+#endif
28122+
28123+ flush_tlb_all();
28124+#endif
28125+
28126 free_init_pages("unused kernel memory",
28127 (unsigned long)(&__init_begin),
28128 (unsigned long)(&__init_end));
28129diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28130index 745d66b..56bf568 100644
28131--- a/arch/x86/mm/init_32.c
28132+++ b/arch/x86/mm/init_32.c
28133@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
28134 }
28135
28136 /*
28137- * Creates a middle page table and puts a pointer to it in the
28138- * given global directory entry. This only returns the gd entry
28139- * in non-PAE compilation mode, since the middle layer is folded.
28140- */
28141-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28142-{
28143- pud_t *pud;
28144- pmd_t *pmd_table;
28145-
28146-#ifdef CONFIG_X86_PAE
28147- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28148- if (after_bootmem)
28149- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
28150- else
28151- pmd_table = (pmd_t *)alloc_low_page();
28152- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28153- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28154- pud = pud_offset(pgd, 0);
28155- BUG_ON(pmd_table != pmd_offset(pud, 0));
28156-
28157- return pmd_table;
28158- }
28159-#endif
28160- pud = pud_offset(pgd, 0);
28161- pmd_table = pmd_offset(pud, 0);
28162-
28163- return pmd_table;
28164-}
28165-
28166-/*
28167 * Create a page table and place a pointer to it in a middle page
28168 * directory entry:
28169 */
28170@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28171 page_table = (pte_t *)alloc_low_page();
28172
28173 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28174+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28175+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28176+#else
28177 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28178+#endif
28179 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28180 }
28181
28182 return pte_offset_kernel(pmd, 0);
28183 }
28184
28185+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28186+{
28187+ pud_t *pud;
28188+ pmd_t *pmd_table;
28189+
28190+ pud = pud_offset(pgd, 0);
28191+ pmd_table = pmd_offset(pud, 0);
28192+
28193+ return pmd_table;
28194+}
28195+
28196 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28197 {
28198 int pgd_idx = pgd_index(vaddr);
28199@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28200 int pgd_idx, pmd_idx;
28201 unsigned long vaddr;
28202 pgd_t *pgd;
28203+ pud_t *pud;
28204 pmd_t *pmd;
28205 pte_t *pte = NULL;
28206
28207@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28208 pgd = pgd_base + pgd_idx;
28209
28210 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28211- pmd = one_md_table_init(pgd);
28212- pmd = pmd + pmd_index(vaddr);
28213+ pud = pud_offset(pgd, vaddr);
28214+ pmd = pmd_offset(pud, vaddr);
28215+
28216+#ifdef CONFIG_X86_PAE
28217+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28218+#endif
28219+
28220 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28221 pmd++, pmd_idx++) {
28222 pte = page_table_kmap_check(one_page_table_init(pmd),
28223@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28224 }
28225 }
28226
28227-static inline int is_kernel_text(unsigned long addr)
28228+static inline int is_kernel_text(unsigned long start, unsigned long end)
28229 {
28230- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28231- return 1;
28232- return 0;
28233+ if ((start > ktla_ktva((unsigned long)_etext) ||
28234+ end <= ktla_ktva((unsigned long)_stext)) &&
28235+ (start > ktla_ktva((unsigned long)_einittext) ||
28236+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28237+
28238+#ifdef CONFIG_ACPI_SLEEP
28239+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28240+#endif
28241+
28242+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28243+ return 0;
28244+ return 1;
28245 }
28246
28247 /*
28248@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
28249 unsigned long last_map_addr = end;
28250 unsigned long start_pfn, end_pfn;
28251 pgd_t *pgd_base = swapper_pg_dir;
28252- int pgd_idx, pmd_idx, pte_ofs;
28253+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28254 unsigned long pfn;
28255 pgd_t *pgd;
28256+ pud_t *pud;
28257 pmd_t *pmd;
28258 pte_t *pte;
28259 unsigned pages_2m, pages_4k;
28260@@ -280,8 +281,13 @@ repeat:
28261 pfn = start_pfn;
28262 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28263 pgd = pgd_base + pgd_idx;
28264- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28265- pmd = one_md_table_init(pgd);
28266+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28267+ pud = pud_offset(pgd, 0);
28268+ pmd = pmd_offset(pud, 0);
28269+
28270+#ifdef CONFIG_X86_PAE
28271+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28272+#endif
28273
28274 if (pfn >= end_pfn)
28275 continue;
28276@@ -293,14 +299,13 @@ repeat:
28277 #endif
28278 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28279 pmd++, pmd_idx++) {
28280- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28281+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28282
28283 /*
28284 * Map with big pages if possible, otherwise
28285 * create normal page tables:
28286 */
28287 if (use_pse) {
28288- unsigned int addr2;
28289 pgprot_t prot = PAGE_KERNEL_LARGE;
28290 /*
28291 * first pass will use the same initial
28292@@ -310,11 +315,7 @@ repeat:
28293 __pgprot(PTE_IDENT_ATTR |
28294 _PAGE_PSE);
28295
28296- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28297- PAGE_OFFSET + PAGE_SIZE-1;
28298-
28299- if (is_kernel_text(addr) ||
28300- is_kernel_text(addr2))
28301+ if (is_kernel_text(address, address + PMD_SIZE))
28302 prot = PAGE_KERNEL_LARGE_EXEC;
28303
28304 pages_2m++;
28305@@ -331,7 +332,7 @@ repeat:
28306 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28307 pte += pte_ofs;
28308 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28309- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28310+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28311 pgprot_t prot = PAGE_KERNEL;
28312 /*
28313 * first pass will use the same initial
28314@@ -339,7 +340,7 @@ repeat:
28315 */
28316 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28317
28318- if (is_kernel_text(addr))
28319+ if (is_kernel_text(address, address + PAGE_SIZE))
28320 prot = PAGE_KERNEL_EXEC;
28321
28322 pages_4k++;
28323@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
28324
28325 pud = pud_offset(pgd, va);
28326 pmd = pmd_offset(pud, va);
28327- if (!pmd_present(*pmd))
28328+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
28329 break;
28330
28331 pte = pte_offset_kernel(pmd, va);
28332@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
28333
28334 static void __init pagetable_init(void)
28335 {
28336- pgd_t *pgd_base = swapper_pg_dir;
28337-
28338- permanent_kmaps_init(pgd_base);
28339+ permanent_kmaps_init(swapper_pg_dir);
28340 }
28341
28342-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28343+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28344 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28345
28346 /* user-defined highmem size */
28347@@ -728,6 +727,12 @@ void __init mem_init(void)
28348
28349 pci_iommu_alloc();
28350
28351+#ifdef CONFIG_PAX_PER_CPU_PGD
28352+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28353+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28354+ KERNEL_PGD_PTRS);
28355+#endif
28356+
28357 #ifdef CONFIG_FLATMEM
28358 BUG_ON(!mem_map);
28359 #endif
28360@@ -754,7 +759,7 @@ void __init mem_init(void)
28361 reservedpages++;
28362
28363 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28364- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28365+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28366 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28367
28368 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28369@@ -795,10 +800,10 @@ void __init mem_init(void)
28370 ((unsigned long)&__init_end -
28371 (unsigned long)&__init_begin) >> 10,
28372
28373- (unsigned long)&_etext, (unsigned long)&_edata,
28374- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28375+ (unsigned long)&_sdata, (unsigned long)&_edata,
28376+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28377
28378- (unsigned long)&_text, (unsigned long)&_etext,
28379+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28380 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28381
28382 /*
28383@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28384 if (!kernel_set_to_readonly)
28385 return;
28386
28387+ start = ktla_ktva(start);
28388 pr_debug("Set kernel text: %lx - %lx for read write\n",
28389 start, start+size);
28390
28391@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28392 if (!kernel_set_to_readonly)
28393 return;
28394
28395+ start = ktla_ktva(start);
28396 pr_debug("Set kernel text: %lx - %lx for read only\n",
28397 start, start+size);
28398
28399@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28400 unsigned long start = PFN_ALIGN(_text);
28401 unsigned long size = PFN_ALIGN(_etext) - start;
28402
28403+ start = ktla_ktva(start);
28404 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28405 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28406 size >> 10);
28407diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28408index 75c9a6a..498d677 100644
28409--- a/arch/x86/mm/init_64.c
28410+++ b/arch/x86/mm/init_64.c
28411@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28412 * around without checking the pgd every time.
28413 */
28414
28415-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28416+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28417 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28418
28419 int force_personality32;
28420@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28421
28422 for (address = start; address <= end; address += PGDIR_SIZE) {
28423 const pgd_t *pgd_ref = pgd_offset_k(address);
28424+
28425+#ifdef CONFIG_PAX_PER_CPU_PGD
28426+ unsigned long cpu;
28427+#else
28428 struct page *page;
28429+#endif
28430
28431 if (pgd_none(*pgd_ref))
28432 continue;
28433
28434 spin_lock(&pgd_lock);
28435+
28436+#ifdef CONFIG_PAX_PER_CPU_PGD
28437+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28438+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28439+#else
28440 list_for_each_entry(page, &pgd_list, lru) {
28441 pgd_t *pgd;
28442 spinlock_t *pgt_lock;
28443@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28444 /* the pgt_lock only for Xen */
28445 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28446 spin_lock(pgt_lock);
28447+#endif
28448
28449 if (pgd_none(*pgd))
28450 set_pgd(pgd, *pgd_ref);
28451@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28452 BUG_ON(pgd_page_vaddr(*pgd)
28453 != pgd_page_vaddr(*pgd_ref));
28454
28455+#ifndef CONFIG_PAX_PER_CPU_PGD
28456 spin_unlock(pgt_lock);
28457+#endif
28458+
28459 }
28460 spin_unlock(&pgd_lock);
28461 }
28462@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28463 {
28464 if (pgd_none(*pgd)) {
28465 pud_t *pud = (pud_t *)spp_getpage();
28466- pgd_populate(&init_mm, pgd, pud);
28467+ pgd_populate_kernel(&init_mm, pgd, pud);
28468 if (pud != pud_offset(pgd, 0))
28469 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28470 pud, pud_offset(pgd, 0));
28471@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28472 {
28473 if (pud_none(*pud)) {
28474 pmd_t *pmd = (pmd_t *) spp_getpage();
28475- pud_populate(&init_mm, pud, pmd);
28476+ pud_populate_kernel(&init_mm, pud, pmd);
28477 if (pmd != pmd_offset(pud, 0))
28478 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28479 pmd, pmd_offset(pud, 0));
28480@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28481 pmd = fill_pmd(pud, vaddr);
28482 pte = fill_pte(pmd, vaddr);
28483
28484+ pax_open_kernel();
28485 set_pte(pte, new_pte);
28486+ pax_close_kernel();
28487
28488 /*
28489 * It's enough to flush this one mapping.
28490@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28491 pgd = pgd_offset_k((unsigned long)__va(phys));
28492 if (pgd_none(*pgd)) {
28493 pud = (pud_t *) spp_getpage();
28494- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28495- _PAGE_USER));
28496+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28497 }
28498 pud = pud_offset(pgd, (unsigned long)__va(phys));
28499 if (pud_none(*pud)) {
28500 pmd = (pmd_t *) spp_getpage();
28501- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28502- _PAGE_USER));
28503+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28504 }
28505 pmd = pmd_offset(pud, phys);
28506 BUG_ON(!pmd_none(*pmd));
28507@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28508 if (pfn >= pgt_buf_top)
28509 panic("alloc_low_page: ran out of memory");
28510
28511- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28512+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28513 clear_page(adr);
28514 *phys = pfn * PAGE_SIZE;
28515 return adr;
28516@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28517
28518 phys = __pa(virt);
28519 left = phys & (PAGE_SIZE - 1);
28520- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28521+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28522 adr = (void *)(((unsigned long)adr) | left);
28523
28524 return adr;
28525@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28526 unmap_low_page(pmd);
28527
28528 spin_lock(&init_mm.page_table_lock);
28529- pud_populate(&init_mm, pud, __va(pmd_phys));
28530+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28531 spin_unlock(&init_mm.page_table_lock);
28532 }
28533 __flush_tlb_all();
28534@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28535 unmap_low_page(pud);
28536
28537 spin_lock(&init_mm.page_table_lock);
28538- pgd_populate(&init_mm, pgd, __va(pud_phys));
28539+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28540 spin_unlock(&init_mm.page_table_lock);
28541 pgd_changed = true;
28542 }
28543@@ -693,6 +707,12 @@ void __init mem_init(void)
28544
28545 pci_iommu_alloc();
28546
28547+#ifdef CONFIG_PAX_PER_CPU_PGD
28548+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28549+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28550+ KERNEL_PGD_PTRS);
28551+#endif
28552+
28553 /* clear_bss() already clear the empty_zero_page */
28554
28555 reservedpages = 0;
28556@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28557 static struct vm_area_struct gate_vma = {
28558 .vm_start = VSYSCALL_START,
28559 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28560- .vm_page_prot = PAGE_READONLY_EXEC,
28561- .vm_flags = VM_READ | VM_EXEC
28562+ .vm_page_prot = PAGE_READONLY,
28563+ .vm_flags = VM_READ
28564 };
28565
28566 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28567@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28568
28569 const char *arch_vma_name(struct vm_area_struct *vma)
28570 {
28571- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28572+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28573 return "[vdso]";
28574 if (vma == &gate_vma)
28575 return "[vsyscall]";
28576diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28577index 7b179b4..6bd1777 100644
28578--- a/arch/x86/mm/iomap_32.c
28579+++ b/arch/x86/mm/iomap_32.c
28580@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28581 type = kmap_atomic_idx_push();
28582 idx = type + KM_TYPE_NR * smp_processor_id();
28583 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28584+
28585+ pax_open_kernel();
28586 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28587+ pax_close_kernel();
28588+
28589 arch_flush_lazy_mmu_mode();
28590
28591 return (void *)vaddr;
28592diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28593index 78fe3f1..2f9433c 100644
28594--- a/arch/x86/mm/ioremap.c
28595+++ b/arch/x86/mm/ioremap.c
28596@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28597 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28598 int is_ram = page_is_ram(pfn);
28599
28600- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28601+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28602 return NULL;
28603 WARN_ON_ONCE(is_ram);
28604 }
28605@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28606 *
28607 * Caller must ensure there is only one unmapping for the same pointer.
28608 */
28609-void iounmap(volatile void __iomem *addr)
28610+void iounmap(const volatile void __iomem *addr)
28611 {
28612 struct vm_struct *p, *o;
28613
28614@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28615
28616 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28617 if (page_is_ram(start >> PAGE_SHIFT))
28618+#ifdef CONFIG_HIGHMEM
28619+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28620+#endif
28621 return __va(phys);
28622
28623 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28624@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
28625 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28626
28627 static __initdata int after_paging_init;
28628-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28629+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28630
28631 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28632 {
28633@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
28634 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28635
28636 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28637- memset(bm_pte, 0, sizeof(bm_pte));
28638- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28639+ pmd_populate_user(&init_mm, pmd, bm_pte);
28640
28641 /*
28642 * The boot-ioremap range spans multiple pmds, for which
28643diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28644index d87dd6d..bf3fa66 100644
28645--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28646+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28647@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28648 * memory (e.g. tracked pages)? For now, we need this to avoid
28649 * invoking kmemcheck for PnP BIOS calls.
28650 */
28651- if (regs->flags & X86_VM_MASK)
28652+ if (v8086_mode(regs))
28653 return false;
28654- if (regs->cs != __KERNEL_CS)
28655+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28656 return false;
28657
28658 pte = kmemcheck_pte_lookup(address);
28659diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28660index 845df68..1d8d29f 100644
28661--- a/arch/x86/mm/mmap.c
28662+++ b/arch/x86/mm/mmap.c
28663@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28664 * Leave an at least ~128 MB hole with possible stack randomization.
28665 */
28666 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28667-#define MAX_GAP (TASK_SIZE/6*5)
28668+#define MAX_GAP (pax_task_size/6*5)
28669
28670 static int mmap_is_legacy(void)
28671 {
28672@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28673 return rnd << PAGE_SHIFT;
28674 }
28675
28676-static unsigned long mmap_base(void)
28677+static unsigned long mmap_base(struct mm_struct *mm)
28678 {
28679 unsigned long gap = rlimit(RLIMIT_STACK);
28680+ unsigned long pax_task_size = TASK_SIZE;
28681+
28682+#ifdef CONFIG_PAX_SEGMEXEC
28683+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28684+ pax_task_size = SEGMEXEC_TASK_SIZE;
28685+#endif
28686
28687 if (gap < MIN_GAP)
28688 gap = MIN_GAP;
28689 else if (gap > MAX_GAP)
28690 gap = MAX_GAP;
28691
28692- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28693+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28694 }
28695
28696 /*
28697 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28698 * does, but not when emulating X86_32
28699 */
28700-static unsigned long mmap_legacy_base(void)
28701+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28702 {
28703- if (mmap_is_ia32())
28704+ if (mmap_is_ia32()) {
28705+
28706+#ifdef CONFIG_PAX_SEGMEXEC
28707+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28708+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28709+ else
28710+#endif
28711+
28712 return TASK_UNMAPPED_BASE;
28713- else
28714+ } else
28715 return TASK_UNMAPPED_BASE + mmap_rnd();
28716 }
28717
28718@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28719 void arch_pick_mmap_layout(struct mm_struct *mm)
28720 {
28721 if (mmap_is_legacy()) {
28722- mm->mmap_base = mmap_legacy_base();
28723+ mm->mmap_base = mmap_legacy_base(mm);
28724+
28725+#ifdef CONFIG_PAX_RANDMMAP
28726+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28727+ mm->mmap_base += mm->delta_mmap;
28728+#endif
28729+
28730 mm->get_unmapped_area = arch_get_unmapped_area;
28731 mm->unmap_area = arch_unmap_area;
28732 } else {
28733- mm->mmap_base = mmap_base();
28734+ mm->mmap_base = mmap_base(mm);
28735+
28736+#ifdef CONFIG_PAX_RANDMMAP
28737+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28738+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28739+#endif
28740+
28741 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28742 mm->unmap_area = arch_unmap_area_topdown;
28743 }
28744diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28745index dc0b727..f612039 100644
28746--- a/arch/x86/mm/mmio-mod.c
28747+++ b/arch/x86/mm/mmio-mod.c
28748@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28749 break;
28750 default:
28751 {
28752- unsigned char *ip = (unsigned char *)instptr;
28753+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28754 my_trace->opcode = MMIO_UNKNOWN_OP;
28755 my_trace->width = 0;
28756 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28757@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28758 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28759 void __iomem *addr)
28760 {
28761- static atomic_t next_id;
28762+ static atomic_unchecked_t next_id;
28763 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28764 /* These are page-unaligned. */
28765 struct mmiotrace_map map = {
28766@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28767 .private = trace
28768 },
28769 .phys = offset,
28770- .id = atomic_inc_return(&next_id)
28771+ .id = atomic_inc_return_unchecked(&next_id)
28772 };
28773 map.map_id = trace->id;
28774
28775@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28776 ioremap_trace_core(offset, size, addr);
28777 }
28778
28779-static void iounmap_trace_core(volatile void __iomem *addr)
28780+static void iounmap_trace_core(const volatile void __iomem *addr)
28781 {
28782 struct mmiotrace_map map = {
28783 .phys = 0,
28784@@ -328,7 +328,7 @@ not_enabled:
28785 }
28786 }
28787
28788-void mmiotrace_iounmap(volatile void __iomem *addr)
28789+void mmiotrace_iounmap(const volatile void __iomem *addr)
28790 {
28791 might_sleep();
28792 if (is_enabled()) /* recheck and proper locking in *_core() */
28793diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28794index 8504f36..5fc68f2 100644
28795--- a/arch/x86/mm/numa.c
28796+++ b/arch/x86/mm/numa.c
28797@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28798 return true;
28799 }
28800
28801-static int __init numa_register_memblks(struct numa_meminfo *mi)
28802+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28803 {
28804 unsigned long uninitialized_var(pfn_align);
28805 int i, nid;
28806diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28807index b008656..773eac2 100644
28808--- a/arch/x86/mm/pageattr-test.c
28809+++ b/arch/x86/mm/pageattr-test.c
28810@@ -36,7 +36,7 @@ enum {
28811
28812 static int pte_testbit(pte_t pte)
28813 {
28814- return pte_flags(pte) & _PAGE_UNUSED1;
28815+ return pte_flags(pte) & _PAGE_CPA_TEST;
28816 }
28817
28818 struct split_state {
28819diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28820index a718e0d..77419bc 100644
28821--- a/arch/x86/mm/pageattr.c
28822+++ b/arch/x86/mm/pageattr.c
28823@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28824 */
28825 #ifdef CONFIG_PCI_BIOS
28826 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28827- pgprot_val(forbidden) |= _PAGE_NX;
28828+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28829 #endif
28830
28831 /*
28832@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28833 * Does not cover __inittext since that is gone later on. On
28834 * 64bit we do not enforce !NX on the low mapping
28835 */
28836- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28837- pgprot_val(forbidden) |= _PAGE_NX;
28838+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28839+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28840
28841+#ifdef CONFIG_DEBUG_RODATA
28842 /*
28843 * The .rodata section needs to be read-only. Using the pfn
28844 * catches all aliases.
28845@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28846 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28847 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28848 pgprot_val(forbidden) |= _PAGE_RW;
28849+#endif
28850
28851 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28852 /*
28853@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28854 }
28855 #endif
28856
28857+#ifdef CONFIG_PAX_KERNEXEC
28858+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28859+ pgprot_val(forbidden) |= _PAGE_RW;
28860+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28861+ }
28862+#endif
28863+
28864 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28865
28866 return prot;
28867@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28868 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28869 {
28870 /* change init_mm */
28871+ pax_open_kernel();
28872 set_pte_atomic(kpte, pte);
28873+
28874 #ifdef CONFIG_X86_32
28875 if (!SHARED_KERNEL_PMD) {
28876+
28877+#ifdef CONFIG_PAX_PER_CPU_PGD
28878+ unsigned long cpu;
28879+#else
28880 struct page *page;
28881+#endif
28882
28883+#ifdef CONFIG_PAX_PER_CPU_PGD
28884+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28885+ pgd_t *pgd = get_cpu_pgd(cpu);
28886+#else
28887 list_for_each_entry(page, &pgd_list, lru) {
28888- pgd_t *pgd;
28889+ pgd_t *pgd = (pgd_t *)page_address(page);
28890+#endif
28891+
28892 pud_t *pud;
28893 pmd_t *pmd;
28894
28895- pgd = (pgd_t *)page_address(page) + pgd_index(address);
28896+ pgd += pgd_index(address);
28897 pud = pud_offset(pgd, address);
28898 pmd = pmd_offset(pud, address);
28899 set_pte_atomic((pte_t *)pmd, pte);
28900 }
28901 }
28902 #endif
28903+ pax_close_kernel();
28904 }
28905
28906 static int
28907diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28908index 0eb572e..92f5c1e 100644
28909--- a/arch/x86/mm/pat.c
28910+++ b/arch/x86/mm/pat.c
28911@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28912
28913 if (!entry) {
28914 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28915- current->comm, current->pid, start, end - 1);
28916+ current->comm, task_pid_nr(current), start, end - 1);
28917 return -EINVAL;
28918 }
28919
28920@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28921
28922 while (cursor < to) {
28923 if (!devmem_is_allowed(pfn)) {
28924- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28925- current->comm, from, to - 1);
28926+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28927+ current->comm, from, to - 1, cursor);
28928 return 0;
28929 }
28930 cursor += PAGE_SIZE;
28931@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28932 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28933 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28934 "for [mem %#010Lx-%#010Lx]\n",
28935- current->comm, current->pid,
28936+ current->comm, task_pid_nr(current),
28937 cattr_name(flags),
28938 base, (unsigned long long)(base + size-1));
28939 return -EINVAL;
28940@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28941 flags = lookup_memtype(paddr);
28942 if (want_flags != flags) {
28943 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28944- current->comm, current->pid,
28945+ current->comm, task_pid_nr(current),
28946 cattr_name(want_flags),
28947 (unsigned long long)paddr,
28948 (unsigned long long)(paddr + size - 1),
28949@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28950 free_memtype(paddr, paddr + size);
28951 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28952 " for [mem %#010Lx-%#010Lx], got %s\n",
28953- current->comm, current->pid,
28954+ current->comm, task_pid_nr(current),
28955 cattr_name(want_flags),
28956 (unsigned long long)paddr,
28957 (unsigned long long)(paddr + size - 1),
28958diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28959index 9f0614d..92ae64a 100644
28960--- a/arch/x86/mm/pf_in.c
28961+++ b/arch/x86/mm/pf_in.c
28962@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28963 int i;
28964 enum reason_type rv = OTHERS;
28965
28966- p = (unsigned char *)ins_addr;
28967+ p = (unsigned char *)ktla_ktva(ins_addr);
28968 p += skip_prefix(p, &prf);
28969 p += get_opcode(p, &opcode);
28970
28971@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28972 struct prefix_bits prf;
28973 int i;
28974
28975- p = (unsigned char *)ins_addr;
28976+ p = (unsigned char *)ktla_ktva(ins_addr);
28977 p += skip_prefix(p, &prf);
28978 p += get_opcode(p, &opcode);
28979
28980@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28981 struct prefix_bits prf;
28982 int i;
28983
28984- p = (unsigned char *)ins_addr;
28985+ p = (unsigned char *)ktla_ktva(ins_addr);
28986 p += skip_prefix(p, &prf);
28987 p += get_opcode(p, &opcode);
28988
28989@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28990 struct prefix_bits prf;
28991 int i;
28992
28993- p = (unsigned char *)ins_addr;
28994+ p = (unsigned char *)ktla_ktva(ins_addr);
28995 p += skip_prefix(p, &prf);
28996 p += get_opcode(p, &opcode);
28997 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28998@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28999 struct prefix_bits prf;
29000 int i;
29001
29002- p = (unsigned char *)ins_addr;
29003+ p = (unsigned char *)ktla_ktva(ins_addr);
29004 p += skip_prefix(p, &prf);
29005 p += get_opcode(p, &opcode);
29006 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29007diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29008index e27fbf8..8b56dc9 100644
29009--- a/arch/x86/mm/pgtable.c
29010+++ b/arch/x86/mm/pgtable.c
29011@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29012 list_del(&page->lru);
29013 }
29014
29015-#define UNSHARED_PTRS_PER_PGD \
29016- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29017+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29018+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29019
29020+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29021+{
29022+ unsigned int count = USER_PGD_PTRS;
29023
29024+ while (count--)
29025+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29026+}
29027+#endif
29028+
29029+#ifdef CONFIG_PAX_PER_CPU_PGD
29030+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29031+{
29032+ unsigned int count = USER_PGD_PTRS;
29033+
29034+ while (count--) {
29035+ pgd_t pgd;
29036+
29037+#ifdef CONFIG_X86_64
29038+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29039+#else
29040+ pgd = *src++;
29041+#endif
29042+
29043+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29044+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29045+#endif
29046+
29047+ *dst++ = pgd;
29048+ }
29049+
29050+}
29051+#endif
29052+
29053+#ifdef CONFIG_X86_64
29054+#define pxd_t pud_t
29055+#define pyd_t pgd_t
29056+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29057+#define pxd_free(mm, pud) pud_free((mm), (pud))
29058+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29059+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29060+#define PYD_SIZE PGDIR_SIZE
29061+#else
29062+#define pxd_t pmd_t
29063+#define pyd_t pud_t
29064+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29065+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29066+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29067+#define pyd_offset(mm, address) pud_offset((mm), (address))
29068+#define PYD_SIZE PUD_SIZE
29069+#endif
29070+
29071+#ifdef CONFIG_PAX_PER_CPU_PGD
29072+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29073+static inline void pgd_dtor(pgd_t *pgd) {}
29074+#else
29075 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29076 {
29077 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29078@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
29079 pgd_list_del(pgd);
29080 spin_unlock(&pgd_lock);
29081 }
29082+#endif
29083
29084 /*
29085 * List of all pgd's needed for non-PAE so it can invalidate entries
29086@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
29087 * -- nyc
29088 */
29089
29090-#ifdef CONFIG_X86_PAE
29091+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29092 /*
29093 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29094 * updating the top-level pagetable entries to guarantee the
29095@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
29096 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29097 * and initialize the kernel pmds here.
29098 */
29099-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29100+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29101
29102 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29103 {
29104@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29105 */
29106 flush_tlb_mm(mm);
29107 }
29108+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29109+#define PREALLOCATED_PXDS USER_PGD_PTRS
29110 #else /* !CONFIG_X86_PAE */
29111
29112 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29113-#define PREALLOCATED_PMDS 0
29114+#define PREALLOCATED_PXDS 0
29115
29116 #endif /* CONFIG_X86_PAE */
29117
29118-static void free_pmds(pmd_t *pmds[])
29119+static void free_pxds(pxd_t *pxds[])
29120 {
29121 int i;
29122
29123- for(i = 0; i < PREALLOCATED_PMDS; i++)
29124- if (pmds[i])
29125- free_page((unsigned long)pmds[i]);
29126+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29127+ if (pxds[i])
29128+ free_page((unsigned long)pxds[i]);
29129 }
29130
29131-static int preallocate_pmds(pmd_t *pmds[])
29132+static int preallocate_pxds(pxd_t *pxds[])
29133 {
29134 int i;
29135 bool failed = false;
29136
29137- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29138- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29139- if (pmd == NULL)
29140+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29141+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29142+ if (pxd == NULL)
29143 failed = true;
29144- pmds[i] = pmd;
29145+ pxds[i] = pxd;
29146 }
29147
29148 if (failed) {
29149- free_pmds(pmds);
29150+ free_pxds(pxds);
29151 return -ENOMEM;
29152 }
29153
29154@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29155 * preallocate which never got a corresponding vma will need to be
29156 * freed manually.
29157 */
29158-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29159+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29160 {
29161 int i;
29162
29163- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29164+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29165 pgd_t pgd = pgdp[i];
29166
29167 if (pgd_val(pgd) != 0) {
29168- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29169+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29170
29171- pgdp[i] = native_make_pgd(0);
29172+ set_pgd(pgdp + i, native_make_pgd(0));
29173
29174- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29175- pmd_free(mm, pmd);
29176+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29177+ pxd_free(mm, pxd);
29178 }
29179 }
29180 }
29181
29182-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29183+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29184 {
29185- pud_t *pud;
29186+ pyd_t *pyd;
29187 unsigned long addr;
29188 int i;
29189
29190- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29191+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29192 return;
29193
29194- pud = pud_offset(pgd, 0);
29195+#ifdef CONFIG_X86_64
29196+ pyd = pyd_offset(mm, 0L);
29197+#else
29198+ pyd = pyd_offset(pgd, 0L);
29199+#endif
29200
29201- for (addr = i = 0; i < PREALLOCATED_PMDS;
29202- i++, pud++, addr += PUD_SIZE) {
29203- pmd_t *pmd = pmds[i];
29204+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29205+ i++, pyd++, addr += PYD_SIZE) {
29206+ pxd_t *pxd = pxds[i];
29207
29208 if (i >= KERNEL_PGD_BOUNDARY)
29209- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29210- sizeof(pmd_t) * PTRS_PER_PMD);
29211+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29212+ sizeof(pxd_t) * PTRS_PER_PMD);
29213
29214- pud_populate(mm, pud, pmd);
29215+ pyd_populate(mm, pyd, pxd);
29216 }
29217 }
29218
29219 pgd_t *pgd_alloc(struct mm_struct *mm)
29220 {
29221 pgd_t *pgd;
29222- pmd_t *pmds[PREALLOCATED_PMDS];
29223+ pxd_t *pxds[PREALLOCATED_PXDS];
29224
29225 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29226
29227@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29228
29229 mm->pgd = pgd;
29230
29231- if (preallocate_pmds(pmds) != 0)
29232+ if (preallocate_pxds(pxds) != 0)
29233 goto out_free_pgd;
29234
29235 if (paravirt_pgd_alloc(mm) != 0)
29236- goto out_free_pmds;
29237+ goto out_free_pxds;
29238
29239 /*
29240 * Make sure that pre-populating the pmds is atomic with
29241@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29242 spin_lock(&pgd_lock);
29243
29244 pgd_ctor(mm, pgd);
29245- pgd_prepopulate_pmd(mm, pgd, pmds);
29246+ pgd_prepopulate_pxd(mm, pgd, pxds);
29247
29248 spin_unlock(&pgd_lock);
29249
29250 return pgd;
29251
29252-out_free_pmds:
29253- free_pmds(pmds);
29254+out_free_pxds:
29255+ free_pxds(pxds);
29256 out_free_pgd:
29257 free_page((unsigned long)pgd);
29258 out:
29259@@ -295,7 +356,7 @@ out:
29260
29261 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29262 {
29263- pgd_mop_up_pmds(mm, pgd);
29264+ pgd_mop_up_pxds(mm, pgd);
29265 pgd_dtor(pgd);
29266 paravirt_pgd_free(mm, pgd);
29267 free_page((unsigned long)pgd);
29268diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29269index a69bcb8..19068ab 100644
29270--- a/arch/x86/mm/pgtable_32.c
29271+++ b/arch/x86/mm/pgtable_32.c
29272@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29273 return;
29274 }
29275 pte = pte_offset_kernel(pmd, vaddr);
29276+
29277+ pax_open_kernel();
29278 if (pte_val(pteval))
29279 set_pte_at(&init_mm, vaddr, pte, pteval);
29280 else
29281 pte_clear(&init_mm, vaddr, pte);
29282+ pax_close_kernel();
29283
29284 /*
29285 * It's enough to flush this one mapping.
29286diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29287index d2e2735..5c6586f 100644
29288--- a/arch/x86/mm/physaddr.c
29289+++ b/arch/x86/mm/physaddr.c
29290@@ -8,7 +8,7 @@
29291
29292 #ifdef CONFIG_X86_64
29293
29294-unsigned long __phys_addr(unsigned long x)
29295+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29296 {
29297 if (x >= __START_KERNEL_map) {
29298 x -= __START_KERNEL_map;
29299@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29300 #else
29301
29302 #ifdef CONFIG_DEBUG_VIRTUAL
29303-unsigned long __phys_addr(unsigned long x)
29304+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29305 {
29306 /* VMALLOC_* aren't constants */
29307 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
29308diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29309index 410531d..0f16030 100644
29310--- a/arch/x86/mm/setup_nx.c
29311+++ b/arch/x86/mm/setup_nx.c
29312@@ -5,8 +5,10 @@
29313 #include <asm/pgtable.h>
29314 #include <asm/proto.h>
29315
29316+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29317 static int disable_nx __cpuinitdata;
29318
29319+#ifndef CONFIG_PAX_PAGEEXEC
29320 /*
29321 * noexec = on|off
29322 *
29323@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29324 return 0;
29325 }
29326 early_param("noexec", noexec_setup);
29327+#endif
29328+
29329+#endif
29330
29331 void __cpuinit x86_configure_nx(void)
29332 {
29333+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29334 if (cpu_has_nx && !disable_nx)
29335 __supported_pte_mask |= _PAGE_NX;
29336 else
29337+#endif
29338 __supported_pte_mask &= ~_PAGE_NX;
29339 }
29340
29341diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29342index 13a6b29..c2fff23 100644
29343--- a/arch/x86/mm/tlb.c
29344+++ b/arch/x86/mm/tlb.c
29345@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29346 BUG();
29347 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29348 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29349+
29350+#ifndef CONFIG_PAX_PER_CPU_PGD
29351 load_cr3(swapper_pg_dir);
29352+#endif
29353+
29354 }
29355 }
29356 EXPORT_SYMBOL_GPL(leave_mm);
29357diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29358index 877b9a1..a8ecf42 100644
29359--- a/arch/x86/net/bpf_jit.S
29360+++ b/arch/x86/net/bpf_jit.S
29361@@ -9,6 +9,7 @@
29362 */
29363 #include <linux/linkage.h>
29364 #include <asm/dwarf2.h>
29365+#include <asm/alternative-asm.h>
29366
29367 /*
29368 * Calling convention :
29369@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29370 jle bpf_slow_path_word
29371 mov (SKBDATA,%rsi),%eax
29372 bswap %eax /* ntohl() */
29373+ pax_force_retaddr
29374 ret
29375
29376 sk_load_half:
29377@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29378 jle bpf_slow_path_half
29379 movzwl (SKBDATA,%rsi),%eax
29380 rol $8,%ax # ntohs()
29381+ pax_force_retaddr
29382 ret
29383
29384 sk_load_byte:
29385@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29386 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29387 jle bpf_slow_path_byte
29388 movzbl (SKBDATA,%rsi),%eax
29389+ pax_force_retaddr
29390 ret
29391
29392 /**
29393@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29394 movzbl (SKBDATA,%rsi),%ebx
29395 and $15,%bl
29396 shl $2,%bl
29397+ pax_force_retaddr
29398 ret
29399
29400 /* rsi contains offset and can be scratched */
29401@@ -109,6 +114,7 @@ bpf_slow_path_word:
29402 js bpf_error
29403 mov -12(%rbp),%eax
29404 bswap %eax
29405+ pax_force_retaddr
29406 ret
29407
29408 bpf_slow_path_half:
29409@@ -117,12 +123,14 @@ bpf_slow_path_half:
29410 mov -12(%rbp),%ax
29411 rol $8,%ax
29412 movzwl %ax,%eax
29413+ pax_force_retaddr
29414 ret
29415
29416 bpf_slow_path_byte:
29417 bpf_slow_path_common(1)
29418 js bpf_error
29419 movzbl -12(%rbp),%eax
29420+ pax_force_retaddr
29421 ret
29422
29423 bpf_slow_path_byte_msh:
29424@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29425 and $15,%al
29426 shl $2,%al
29427 xchg %eax,%ebx
29428+ pax_force_retaddr
29429 ret
29430
29431 #define sk_negative_common(SIZE) \
29432@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29433 sk_negative_common(4)
29434 mov (%rax), %eax
29435 bswap %eax
29436+ pax_force_retaddr
29437 ret
29438
29439 bpf_slow_path_half_neg:
29440@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29441 mov (%rax),%ax
29442 rol $8,%ax
29443 movzwl %ax,%eax
29444+ pax_force_retaddr
29445 ret
29446
29447 bpf_slow_path_byte_neg:
29448@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29449 .globl sk_load_byte_negative_offset
29450 sk_negative_common(1)
29451 movzbl (%rax), %eax
29452+ pax_force_retaddr
29453 ret
29454
29455 bpf_slow_path_byte_msh_neg:
29456@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29457 and $15,%al
29458 shl $2,%al
29459 xchg %eax,%ebx
29460+ pax_force_retaddr
29461 ret
29462
29463 bpf_error:
29464@@ -197,4 +210,5 @@ bpf_error:
29465 xor %eax,%eax
29466 mov -8(%rbp),%rbx
29467 leaveq
29468+ pax_force_retaddr
29469 ret
29470diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29471index d11a470..3f9adff3 100644
29472--- a/arch/x86/net/bpf_jit_comp.c
29473+++ b/arch/x86/net/bpf_jit_comp.c
29474@@ -12,6 +12,7 @@
29475 #include <linux/netdevice.h>
29476 #include <linux/filter.h>
29477 #include <linux/if_vlan.h>
29478+#include <linux/random.h>
29479
29480 /*
29481 * Conventions :
29482@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29483 return ptr + len;
29484 }
29485
29486+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29487+#define MAX_INSTR_CODE_SIZE 96
29488+#else
29489+#define MAX_INSTR_CODE_SIZE 64
29490+#endif
29491+
29492 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29493
29494 #define EMIT1(b1) EMIT(b1, 1)
29495 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29496 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29497 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29498+
29499+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29500+/* original constant will appear in ecx */
29501+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29502+do { \
29503+ /* mov ecx, randkey */ \
29504+ EMIT1(0xb9); \
29505+ EMIT(_key, 4); \
29506+ /* xor ecx, randkey ^ off */ \
29507+ EMIT2(0x81, 0xf1); \
29508+ EMIT((_key) ^ (_off), 4); \
29509+} while (0)
29510+
29511+#define EMIT1_off32(b1, _off) \
29512+do { \
29513+ switch (b1) { \
29514+ case 0x05: /* add eax, imm32 */ \
29515+ case 0x2d: /* sub eax, imm32 */ \
29516+ case 0x25: /* and eax, imm32 */ \
29517+ case 0x0d: /* or eax, imm32 */ \
29518+ case 0xb8: /* mov eax, imm32 */ \
29519+ case 0x3d: /* cmp eax, imm32 */ \
29520+ case 0xa9: /* test eax, imm32 */ \
29521+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29522+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29523+ break; \
29524+ case 0xbb: /* mov ebx, imm32 */ \
29525+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29526+ /* mov ebx, ecx */ \
29527+ EMIT2(0x89, 0xcb); \
29528+ break; \
29529+ case 0xbe: /* mov esi, imm32 */ \
29530+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29531+ /* mov esi, ecx */ \
29532+ EMIT2(0x89, 0xce); \
29533+ break; \
29534+ case 0xe9: /* jmp rel imm32 */ \
29535+ EMIT1(b1); \
29536+ EMIT(_off, 4); \
29537+ /* prevent fall-through, we're not called if off = 0 */ \
29538+ EMIT(0xcccccccc, 4); \
29539+ EMIT(0xcccccccc, 4); \
29540+ break; \
29541+ default: \
29542+ EMIT1(b1); \
29543+ EMIT(_off, 4); \
29544+ } \
29545+} while (0)
29546+
29547+#define EMIT2_off32(b1, b2, _off) \
29548+do { \
29549+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29550+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29551+ EMIT(randkey, 4); \
29552+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29553+ EMIT((_off) - randkey, 4); \
29554+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29555+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29556+ /* imul eax, ecx */ \
29557+ EMIT3(0x0f, 0xaf, 0xc1); \
29558+ } else { \
29559+ EMIT2(b1, b2); \
29560+ EMIT(_off, 4); \
29561+ } \
29562+} while (0)
29563+#else
29564 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29565+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29566+#endif
29567
29568 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29569 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29570@@ -90,6 +165,24 @@ do { \
29571 #define X86_JBE 0x76
29572 #define X86_JA 0x77
29573
29574+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29575+#define APPEND_FLOW_VERIFY() \
29576+do { \
29577+ /* mov ecx, randkey */ \
29578+ EMIT1(0xb9); \
29579+ EMIT(randkey, 4); \
29580+ /* cmp ecx, randkey */ \
29581+ EMIT2(0x81, 0xf9); \
29582+ EMIT(randkey, 4); \
29583+ /* jz after 8 int 3s */ \
29584+ EMIT2(0x74, 0x08); \
29585+ EMIT(0xcccccccc, 4); \
29586+ EMIT(0xcccccccc, 4); \
29587+} while (0)
29588+#else
29589+#define APPEND_FLOW_VERIFY() do { } while (0)
29590+#endif
29591+
29592 #define EMIT_COND_JMP(op, offset) \
29593 do { \
29594 if (is_near(offset)) \
29595@@ -97,6 +190,7 @@ do { \
29596 else { \
29597 EMIT2(0x0f, op + 0x10); \
29598 EMIT(offset, 4); /* jxx .+off32 */ \
29599+ APPEND_FLOW_VERIFY(); \
29600 } \
29601 } while (0)
29602
29603@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29604 set_fs(old_fs);
29605 }
29606
29607+struct bpf_jit_work {
29608+ struct work_struct work;
29609+ void *image;
29610+};
29611+
29612 #define CHOOSE_LOAD_FUNC(K, func) \
29613 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29614
29615 void bpf_jit_compile(struct sk_filter *fp)
29616 {
29617- u8 temp[64];
29618+ u8 temp[MAX_INSTR_CODE_SIZE];
29619 u8 *prog;
29620 unsigned int proglen, oldproglen = 0;
29621 int ilen, i;
29622@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29623 unsigned int *addrs;
29624 const struct sock_filter *filter = fp->insns;
29625 int flen = fp->len;
29626+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29627+ unsigned int randkey;
29628+#endif
29629
29630 if (!bpf_jit_enable)
29631 return;
29632@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29633 if (addrs == NULL)
29634 return;
29635
29636+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29637+ if (!fp->work)
29638+ goto out;
29639+
29640+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29641+ randkey = get_random_int();
29642+#endif
29643+
29644 /* Before first pass, make a rough estimation of addrs[]
29645- * each bpf instruction is translated to less than 64 bytes
29646+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29647 */
29648 for (proglen = 0, i = 0; i < flen; i++) {
29649- proglen += 64;
29650+ proglen += MAX_INSTR_CODE_SIZE;
29651 addrs[i] = proglen;
29652 }
29653 cleanup_addr = proglen; /* epilogue address */
29654@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29655 case BPF_S_ALU_MUL_K: /* A *= K */
29656 if (is_imm8(K))
29657 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29658- else {
29659- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29660- EMIT(K, 4);
29661- }
29662+ else
29663+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29664 break;
29665 case BPF_S_ALU_DIV_X: /* A /= X; */
29666 seen |= SEEN_XREG;
29667@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29668 break;
29669 case BPF_S_ALU_MOD_K: /* A %= K; */
29670 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29671+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29672+ DILUTE_CONST_SEQUENCE(K, randkey);
29673+#else
29674 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29675+#endif
29676 EMIT2(0xf7, 0xf1); /* div %ecx */
29677 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29678 break;
29679 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29680+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29681+ DILUTE_CONST_SEQUENCE(K, randkey);
29682+ // imul rax, rcx
29683+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29684+#else
29685 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29686 EMIT(K, 4);
29687+#endif
29688 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29689 break;
29690 case BPF_S_ALU_AND_X:
29691@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29692 if (is_imm8(K)) {
29693 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29694 } else {
29695- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29696- EMIT(K, 4);
29697+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29698 }
29699 } else {
29700 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29701@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29702 break;
29703 default:
29704 /* hmm, too complex filter, give up with jit compiler */
29705- goto out;
29706+ goto error;
29707 }
29708 ilen = prog - temp;
29709 if (image) {
29710 if (unlikely(proglen + ilen > oldproglen)) {
29711 pr_err("bpb_jit_compile fatal error\n");
29712- kfree(addrs);
29713- module_free(NULL, image);
29714- return;
29715+ module_free_exec(NULL, image);
29716+ goto error;
29717 }
29718+ pax_open_kernel();
29719 memcpy(image + proglen, temp, ilen);
29720+ pax_close_kernel();
29721 }
29722 proglen += ilen;
29723 addrs[i] = proglen;
29724@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29725 break;
29726 }
29727 if (proglen == oldproglen) {
29728- image = module_alloc(max_t(unsigned int,
29729- proglen,
29730- sizeof(struct work_struct)));
29731+ image = module_alloc_exec(proglen);
29732 if (!image)
29733- goto out;
29734+ goto error;
29735 }
29736 oldproglen = proglen;
29737 }
29738@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29739 bpf_flush_icache(image, image + proglen);
29740
29741 fp->bpf_func = (void *)image;
29742- }
29743+ } else
29744+error:
29745+ kfree(fp->work);
29746+
29747 out:
29748 kfree(addrs);
29749 return;
29750@@ -707,18 +826,20 @@ out:
29751
29752 static void jit_free_defer(struct work_struct *arg)
29753 {
29754- module_free(NULL, arg);
29755+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29756+ kfree(arg);
29757 }
29758
29759 /* run from softirq, we must use a work_struct to call
29760- * module_free() from process context
29761+ * module_free_exec() from process context
29762 */
29763 void bpf_jit_free(struct sk_filter *fp)
29764 {
29765 if (fp->bpf_func != sk_run_filter) {
29766- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29767+ struct work_struct *work = &fp->work->work;
29768
29769 INIT_WORK(work, jit_free_defer);
29770+ fp->work->image = fp->bpf_func;
29771 schedule_work(work);
29772 }
29773 }
29774diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29775index d6aa6e8..266395a 100644
29776--- a/arch/x86/oprofile/backtrace.c
29777+++ b/arch/x86/oprofile/backtrace.c
29778@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29779 struct stack_frame_ia32 *fp;
29780 unsigned long bytes;
29781
29782- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29783+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29784 if (bytes != sizeof(bufhead))
29785 return NULL;
29786
29787- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29788+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29789
29790 oprofile_add_trace(bufhead[0].return_address);
29791
29792@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29793 struct stack_frame bufhead[2];
29794 unsigned long bytes;
29795
29796- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29797+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29798 if (bytes != sizeof(bufhead))
29799 return NULL;
29800
29801@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29802 {
29803 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29804
29805- if (!user_mode_vm(regs)) {
29806+ if (!user_mode(regs)) {
29807 unsigned long stack = kernel_stack_pointer(regs);
29808 if (depth)
29809 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29810diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29811index 48768df..ba9143c 100644
29812--- a/arch/x86/oprofile/nmi_int.c
29813+++ b/arch/x86/oprofile/nmi_int.c
29814@@ -23,6 +23,7 @@
29815 #include <asm/nmi.h>
29816 #include <asm/msr.h>
29817 #include <asm/apic.h>
29818+#include <asm/pgtable.h>
29819
29820 #include "op_counter.h"
29821 #include "op_x86_model.h"
29822@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29823 if (ret)
29824 return ret;
29825
29826- if (!model->num_virt_counters)
29827- model->num_virt_counters = model->num_counters;
29828+ if (!model->num_virt_counters) {
29829+ pax_open_kernel();
29830+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29831+ pax_close_kernel();
29832+ }
29833
29834 mux_init(ops);
29835
29836diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29837index b2b9443..be58856 100644
29838--- a/arch/x86/oprofile/op_model_amd.c
29839+++ b/arch/x86/oprofile/op_model_amd.c
29840@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29841 num_counters = AMD64_NUM_COUNTERS;
29842 }
29843
29844- op_amd_spec.num_counters = num_counters;
29845- op_amd_spec.num_controls = num_counters;
29846- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29847+ pax_open_kernel();
29848+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29849+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29850+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29851+ pax_close_kernel();
29852
29853 return 0;
29854 }
29855diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29856index d90528e..0127e2b 100644
29857--- a/arch/x86/oprofile/op_model_ppro.c
29858+++ b/arch/x86/oprofile/op_model_ppro.c
29859@@ -19,6 +19,7 @@
29860 #include <asm/msr.h>
29861 #include <asm/apic.h>
29862 #include <asm/nmi.h>
29863+#include <asm/pgtable.h>
29864
29865 #include "op_x86_model.h"
29866 #include "op_counter.h"
29867@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29868
29869 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29870
29871- op_arch_perfmon_spec.num_counters = num_counters;
29872- op_arch_perfmon_spec.num_controls = num_counters;
29873+ pax_open_kernel();
29874+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
29875+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
29876+ pax_close_kernel();
29877 }
29878
29879 static int arch_perfmon_init(struct oprofile_operations *ignore)
29880diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
29881index 71e8a67..6a313bb 100644
29882--- a/arch/x86/oprofile/op_x86_model.h
29883+++ b/arch/x86/oprofile/op_x86_model.h
29884@@ -52,7 +52,7 @@ struct op_x86_model_spec {
29885 void (*switch_ctrl)(struct op_x86_model_spec const *model,
29886 struct op_msrs const * const msrs);
29887 #endif
29888-};
29889+} __do_const;
29890
29891 struct op_counter_config;
29892
29893diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29894index e9e6ed5..e47ae67 100644
29895--- a/arch/x86/pci/amd_bus.c
29896+++ b/arch/x86/pci/amd_bus.c
29897@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29898 return NOTIFY_OK;
29899 }
29900
29901-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29902+static struct notifier_block amd_cpu_notifier = {
29903 .notifier_call = amd_cpu_notify,
29904 };
29905
29906diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
29907index 372e9b8..e775a6c 100644
29908--- a/arch/x86/pci/irq.c
29909+++ b/arch/x86/pci/irq.c
29910@@ -50,7 +50,7 @@ struct irq_router {
29911 struct irq_router_handler {
29912 u16 vendor;
29913 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
29914-};
29915+} __do_const;
29916
29917 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
29918 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
29919@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
29920 return 0;
29921 }
29922
29923-static __initdata struct irq_router_handler pirq_routers[] = {
29924+static __initconst const struct irq_router_handler pirq_routers[] = {
29925 { PCI_VENDOR_ID_INTEL, intel_router_probe },
29926 { PCI_VENDOR_ID_AL, ali_router_probe },
29927 { PCI_VENDOR_ID_ITE, ite_router_probe },
29928@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
29929 static void __init pirq_find_router(struct irq_router *r)
29930 {
29931 struct irq_routing_table *rt = pirq_table;
29932- struct irq_router_handler *h;
29933+ const struct irq_router_handler *h;
29934
29935 #ifdef CONFIG_PCI_BIOS
29936 if (!rt->signature) {
29937@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
29938 return 0;
29939 }
29940
29941-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
29942+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
29943 {
29944 .callback = fix_broken_hp_bios_irq9,
29945 .ident = "HP Pavilion N5400 Series Laptop",
29946diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29947index 6eb18c4..20d83de 100644
29948--- a/arch/x86/pci/mrst.c
29949+++ b/arch/x86/pci/mrst.c
29950@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29951 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29952 pci_mmcfg_late_init();
29953 pcibios_enable_irq = mrst_pci_irq_enable;
29954- pci_root_ops = pci_mrst_ops;
29955+ pax_open_kernel();
29956+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29957+ pax_close_kernel();
29958 pci_soc_mode = 1;
29959 /* Continue with standard init */
29960 return 1;
29961diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29962index c77b24a..c979855 100644
29963--- a/arch/x86/pci/pcbios.c
29964+++ b/arch/x86/pci/pcbios.c
29965@@ -79,7 +79,7 @@ union bios32 {
29966 static struct {
29967 unsigned long address;
29968 unsigned short segment;
29969-} bios32_indirect = { 0, __KERNEL_CS };
29970+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29971
29972 /*
29973 * Returns the entry point for the given service, NULL on error
29974@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29975 unsigned long length; /* %ecx */
29976 unsigned long entry; /* %edx */
29977 unsigned long flags;
29978+ struct desc_struct d, *gdt;
29979
29980 local_irq_save(flags);
29981- __asm__("lcall *(%%edi); cld"
29982+
29983+ gdt = get_cpu_gdt_table(smp_processor_id());
29984+
29985+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29986+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29987+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29988+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29989+
29990+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29991 : "=a" (return_code),
29992 "=b" (address),
29993 "=c" (length),
29994 "=d" (entry)
29995 : "0" (service),
29996 "1" (0),
29997- "D" (&bios32_indirect));
29998+ "D" (&bios32_indirect),
29999+ "r"(__PCIBIOS_DS)
30000+ : "memory");
30001+
30002+ pax_open_kernel();
30003+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30004+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30005+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30006+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30007+ pax_close_kernel();
30008+
30009 local_irq_restore(flags);
30010
30011 switch (return_code) {
30012- case 0:
30013- return address + entry;
30014- case 0x80: /* Not present */
30015- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30016- return 0;
30017- default: /* Shouldn't happen */
30018- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30019- service, return_code);
30020+ case 0: {
30021+ int cpu;
30022+ unsigned char flags;
30023+
30024+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30025+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30026+ printk(KERN_WARNING "bios32_service: not valid\n");
30027 return 0;
30028+ }
30029+ address = address + PAGE_OFFSET;
30030+ length += 16UL; /* some BIOSs underreport this... */
30031+ flags = 4;
30032+ if (length >= 64*1024*1024) {
30033+ length >>= PAGE_SHIFT;
30034+ flags |= 8;
30035+ }
30036+
30037+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30038+ gdt = get_cpu_gdt_table(cpu);
30039+ pack_descriptor(&d, address, length, 0x9b, flags);
30040+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30041+ pack_descriptor(&d, address, length, 0x93, flags);
30042+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30043+ }
30044+ return entry;
30045+ }
30046+ case 0x80: /* Not present */
30047+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30048+ return 0;
30049+ default: /* Shouldn't happen */
30050+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30051+ service, return_code);
30052+ return 0;
30053 }
30054 }
30055
30056 static struct {
30057 unsigned long address;
30058 unsigned short segment;
30059-} pci_indirect = { 0, __KERNEL_CS };
30060+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30061
30062-static int pci_bios_present;
30063+static int pci_bios_present __read_only;
30064
30065 static int check_pcibios(void)
30066 {
30067@@ -131,11 +174,13 @@ static int check_pcibios(void)
30068 unsigned long flags, pcibios_entry;
30069
30070 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30071- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30072+ pci_indirect.address = pcibios_entry;
30073
30074 local_irq_save(flags);
30075- __asm__(
30076- "lcall *(%%edi); cld\n\t"
30077+ __asm__("movw %w6, %%ds\n\t"
30078+ "lcall *%%ss:(%%edi); cld\n\t"
30079+ "push %%ss\n\t"
30080+ "pop %%ds\n\t"
30081 "jc 1f\n\t"
30082 "xor %%ah, %%ah\n"
30083 "1:"
30084@@ -144,7 +189,8 @@ static int check_pcibios(void)
30085 "=b" (ebx),
30086 "=c" (ecx)
30087 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30088- "D" (&pci_indirect)
30089+ "D" (&pci_indirect),
30090+ "r" (__PCIBIOS_DS)
30091 : "memory");
30092 local_irq_restore(flags);
30093
30094@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30095
30096 switch (len) {
30097 case 1:
30098- __asm__("lcall *(%%esi); cld\n\t"
30099+ __asm__("movw %w6, %%ds\n\t"
30100+ "lcall *%%ss:(%%esi); cld\n\t"
30101+ "push %%ss\n\t"
30102+ "pop %%ds\n\t"
30103 "jc 1f\n\t"
30104 "xor %%ah, %%ah\n"
30105 "1:"
30106@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30107 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30108 "b" (bx),
30109 "D" ((long)reg),
30110- "S" (&pci_indirect));
30111+ "S" (&pci_indirect),
30112+ "r" (__PCIBIOS_DS));
30113 /*
30114 * Zero-extend the result beyond 8 bits, do not trust the
30115 * BIOS having done it:
30116@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30117 *value &= 0xff;
30118 break;
30119 case 2:
30120- __asm__("lcall *(%%esi); cld\n\t"
30121+ __asm__("movw %w6, %%ds\n\t"
30122+ "lcall *%%ss:(%%esi); cld\n\t"
30123+ "push %%ss\n\t"
30124+ "pop %%ds\n\t"
30125 "jc 1f\n\t"
30126 "xor %%ah, %%ah\n"
30127 "1:"
30128@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30129 : "1" (PCIBIOS_READ_CONFIG_WORD),
30130 "b" (bx),
30131 "D" ((long)reg),
30132- "S" (&pci_indirect));
30133+ "S" (&pci_indirect),
30134+ "r" (__PCIBIOS_DS));
30135 /*
30136 * Zero-extend the result beyond 16 bits, do not trust the
30137 * BIOS having done it:
30138@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30139 *value &= 0xffff;
30140 break;
30141 case 4:
30142- __asm__("lcall *(%%esi); cld\n\t"
30143+ __asm__("movw %w6, %%ds\n\t"
30144+ "lcall *%%ss:(%%esi); cld\n\t"
30145+ "push %%ss\n\t"
30146+ "pop %%ds\n\t"
30147 "jc 1f\n\t"
30148 "xor %%ah, %%ah\n"
30149 "1:"
30150@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30151 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30152 "b" (bx),
30153 "D" ((long)reg),
30154- "S" (&pci_indirect));
30155+ "S" (&pci_indirect),
30156+ "r" (__PCIBIOS_DS));
30157 break;
30158 }
30159
30160@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30161
30162 switch (len) {
30163 case 1:
30164- __asm__("lcall *(%%esi); cld\n\t"
30165+ __asm__("movw %w6, %%ds\n\t"
30166+ "lcall *%%ss:(%%esi); cld\n\t"
30167+ "push %%ss\n\t"
30168+ "pop %%ds\n\t"
30169 "jc 1f\n\t"
30170 "xor %%ah, %%ah\n"
30171 "1:"
30172@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30173 "c" (value),
30174 "b" (bx),
30175 "D" ((long)reg),
30176- "S" (&pci_indirect));
30177+ "S" (&pci_indirect),
30178+ "r" (__PCIBIOS_DS));
30179 break;
30180 case 2:
30181- __asm__("lcall *(%%esi); cld\n\t"
30182+ __asm__("movw %w6, %%ds\n\t"
30183+ "lcall *%%ss:(%%esi); cld\n\t"
30184+ "push %%ss\n\t"
30185+ "pop %%ds\n\t"
30186 "jc 1f\n\t"
30187 "xor %%ah, %%ah\n"
30188 "1:"
30189@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30190 "c" (value),
30191 "b" (bx),
30192 "D" ((long)reg),
30193- "S" (&pci_indirect));
30194+ "S" (&pci_indirect),
30195+ "r" (__PCIBIOS_DS));
30196 break;
30197 case 4:
30198- __asm__("lcall *(%%esi); cld\n\t"
30199+ __asm__("movw %w6, %%ds\n\t"
30200+ "lcall *%%ss:(%%esi); cld\n\t"
30201+ "push %%ss\n\t"
30202+ "pop %%ds\n\t"
30203 "jc 1f\n\t"
30204 "xor %%ah, %%ah\n"
30205 "1:"
30206@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30207 "c" (value),
30208 "b" (bx),
30209 "D" ((long)reg),
30210- "S" (&pci_indirect));
30211+ "S" (&pci_indirect),
30212+ "r" (__PCIBIOS_DS));
30213 break;
30214 }
30215
30216@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30217
30218 DBG("PCI: Fetching IRQ routing table... ");
30219 __asm__("push %%es\n\t"
30220+ "movw %w8, %%ds\n\t"
30221 "push %%ds\n\t"
30222 "pop %%es\n\t"
30223- "lcall *(%%esi); cld\n\t"
30224+ "lcall *%%ss:(%%esi); cld\n\t"
30225 "pop %%es\n\t"
30226+ "push %%ss\n\t"
30227+ "pop %%ds\n"
30228 "jc 1f\n\t"
30229 "xor %%ah, %%ah\n"
30230 "1:"
30231@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30232 "1" (0),
30233 "D" ((long) &opt),
30234 "S" (&pci_indirect),
30235- "m" (opt)
30236+ "m" (opt),
30237+ "r" (__PCIBIOS_DS)
30238 : "memory");
30239 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30240 if (ret & 0xff00)
30241@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30242 {
30243 int ret;
30244
30245- __asm__("lcall *(%%esi); cld\n\t"
30246+ __asm__("movw %w5, %%ds\n\t"
30247+ "lcall *%%ss:(%%esi); cld\n\t"
30248+ "push %%ss\n\t"
30249+ "pop %%ds\n"
30250 "jc 1f\n\t"
30251 "xor %%ah, %%ah\n"
30252 "1:"
30253@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30254 : "0" (PCIBIOS_SET_PCI_HW_INT),
30255 "b" ((dev->bus->number << 8) | dev->devfn),
30256 "c" ((irq << 8) | (pin + 10)),
30257- "S" (&pci_indirect));
30258+ "S" (&pci_indirect),
30259+ "r" (__PCIBIOS_DS));
30260 return !(ret & 0xff00);
30261 }
30262 EXPORT_SYMBOL(pcibios_set_irq_routing);
30263diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30264index 40e4469..1ab536e 100644
30265--- a/arch/x86/platform/efi/efi_32.c
30266+++ b/arch/x86/platform/efi/efi_32.c
30267@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30268 {
30269 struct desc_ptr gdt_descr;
30270
30271+#ifdef CONFIG_PAX_KERNEXEC
30272+ struct desc_struct d;
30273+#endif
30274+
30275 local_irq_save(efi_rt_eflags);
30276
30277 load_cr3(initial_page_table);
30278 __flush_tlb_all();
30279
30280+#ifdef CONFIG_PAX_KERNEXEC
30281+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30282+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30283+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30284+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30285+#endif
30286+
30287 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30288 gdt_descr.size = GDT_SIZE - 1;
30289 load_gdt(&gdt_descr);
30290@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30291 {
30292 struct desc_ptr gdt_descr;
30293
30294+#ifdef CONFIG_PAX_KERNEXEC
30295+ struct desc_struct d;
30296+
30297+ memset(&d, 0, sizeof d);
30298+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30299+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30300+#endif
30301+
30302 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30303 gdt_descr.size = GDT_SIZE - 1;
30304 load_gdt(&gdt_descr);
30305diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30306index fbe66e6..eae5e38 100644
30307--- a/arch/x86/platform/efi/efi_stub_32.S
30308+++ b/arch/x86/platform/efi/efi_stub_32.S
30309@@ -6,7 +6,9 @@
30310 */
30311
30312 #include <linux/linkage.h>
30313+#include <linux/init.h>
30314 #include <asm/page_types.h>
30315+#include <asm/segment.h>
30316
30317 /*
30318 * efi_call_phys(void *, ...) is a function with variable parameters.
30319@@ -20,7 +22,7 @@
30320 * service functions will comply with gcc calling convention, too.
30321 */
30322
30323-.text
30324+__INIT
30325 ENTRY(efi_call_phys)
30326 /*
30327 * 0. The function can only be called in Linux kernel. So CS has been
30328@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30329 * The mapping of lower virtual memory has been created in prelog and
30330 * epilog.
30331 */
30332- movl $1f, %edx
30333- subl $__PAGE_OFFSET, %edx
30334- jmp *%edx
30335+#ifdef CONFIG_PAX_KERNEXEC
30336+ movl $(__KERNEXEC_EFI_DS), %edx
30337+ mov %edx, %ds
30338+ mov %edx, %es
30339+ mov %edx, %ss
30340+ addl $2f,(1f)
30341+ ljmp *(1f)
30342+
30343+__INITDATA
30344+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30345+.previous
30346+
30347+2:
30348+ subl $2b,(1b)
30349+#else
30350+ jmp 1f-__PAGE_OFFSET
30351 1:
30352+#endif
30353
30354 /*
30355 * 2. Now on the top of stack is the return
30356@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30357 * parameter 2, ..., param n. To make things easy, we save the return
30358 * address of efi_call_phys in a global variable.
30359 */
30360- popl %edx
30361- movl %edx, saved_return_addr
30362- /* get the function pointer into ECX*/
30363- popl %ecx
30364- movl %ecx, efi_rt_function_ptr
30365- movl $2f, %edx
30366- subl $__PAGE_OFFSET, %edx
30367- pushl %edx
30368+ popl (saved_return_addr)
30369+ popl (efi_rt_function_ptr)
30370
30371 /*
30372 * 3. Clear PG bit in %CR0.
30373@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30374 /*
30375 * 5. Call the physical function.
30376 */
30377- jmp *%ecx
30378+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30379
30380-2:
30381 /*
30382 * 6. After EFI runtime service returns, control will return to
30383 * following instruction. We'd better readjust stack pointer first.
30384@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30385 movl %cr0, %edx
30386 orl $0x80000000, %edx
30387 movl %edx, %cr0
30388- jmp 1f
30389-1:
30390+
30391 /*
30392 * 8. Now restore the virtual mode from flat mode by
30393 * adding EIP with PAGE_OFFSET.
30394 */
30395- movl $1f, %edx
30396- jmp *%edx
30397+#ifdef CONFIG_PAX_KERNEXEC
30398+ movl $(__KERNEL_DS), %edx
30399+ mov %edx, %ds
30400+ mov %edx, %es
30401+ mov %edx, %ss
30402+ ljmp $(__KERNEL_CS),$1f
30403+#else
30404+ jmp 1f+__PAGE_OFFSET
30405+#endif
30406 1:
30407
30408 /*
30409 * 9. Balance the stack. And because EAX contain the return value,
30410 * we'd better not clobber it.
30411 */
30412- leal efi_rt_function_ptr, %edx
30413- movl (%edx), %ecx
30414- pushl %ecx
30415+ pushl (efi_rt_function_ptr)
30416
30417 /*
30418- * 10. Push the saved return address onto the stack and return.
30419+ * 10. Return to the saved return address.
30420 */
30421- leal saved_return_addr, %edx
30422- movl (%edx), %ecx
30423- pushl %ecx
30424- ret
30425+ jmpl *(saved_return_addr)
30426 ENDPROC(efi_call_phys)
30427 .previous
30428
30429-.data
30430+__INITDATA
30431 saved_return_addr:
30432 .long 0
30433 efi_rt_function_ptr:
30434diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30435index 4c07cca..2c8427d 100644
30436--- a/arch/x86/platform/efi/efi_stub_64.S
30437+++ b/arch/x86/platform/efi/efi_stub_64.S
30438@@ -7,6 +7,7 @@
30439 */
30440
30441 #include <linux/linkage.h>
30442+#include <asm/alternative-asm.h>
30443
30444 #define SAVE_XMM \
30445 mov %rsp, %rax; \
30446@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30447 call *%rdi
30448 addq $32, %rsp
30449 RESTORE_XMM
30450+ pax_force_retaddr 0, 1
30451 ret
30452 ENDPROC(efi_call0)
30453
30454@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30455 call *%rdi
30456 addq $32, %rsp
30457 RESTORE_XMM
30458+ pax_force_retaddr 0, 1
30459 ret
30460 ENDPROC(efi_call1)
30461
30462@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30463 call *%rdi
30464 addq $32, %rsp
30465 RESTORE_XMM
30466+ pax_force_retaddr 0, 1
30467 ret
30468 ENDPROC(efi_call2)
30469
30470@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30471 call *%rdi
30472 addq $32, %rsp
30473 RESTORE_XMM
30474+ pax_force_retaddr 0, 1
30475 ret
30476 ENDPROC(efi_call3)
30477
30478@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30479 call *%rdi
30480 addq $32, %rsp
30481 RESTORE_XMM
30482+ pax_force_retaddr 0, 1
30483 ret
30484 ENDPROC(efi_call4)
30485
30486@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30487 call *%rdi
30488 addq $48, %rsp
30489 RESTORE_XMM
30490+ pax_force_retaddr 0, 1
30491 ret
30492 ENDPROC(efi_call5)
30493
30494@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30495 call *%rdi
30496 addq $48, %rsp
30497 RESTORE_XMM
30498+ pax_force_retaddr 0, 1
30499 ret
30500 ENDPROC(efi_call6)
30501diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30502index e31bcd8..f12dc46 100644
30503--- a/arch/x86/platform/mrst/mrst.c
30504+++ b/arch/x86/platform/mrst/mrst.c
30505@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30506 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30507 int sfi_mrtc_num;
30508
30509-static void mrst_power_off(void)
30510+static __noreturn void mrst_power_off(void)
30511 {
30512+ BUG();
30513 }
30514
30515-static void mrst_reboot(void)
30516+static __noreturn void mrst_reboot(void)
30517 {
30518 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30519+ BUG();
30520 }
30521
30522 /* parse all the mtimer info to a static mtimer array */
30523diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30524index d6ee929..3637cb5 100644
30525--- a/arch/x86/platform/olpc/olpc_dt.c
30526+++ b/arch/x86/platform/olpc/olpc_dt.c
30527@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30528 return res;
30529 }
30530
30531-static struct of_pdt_ops prom_olpc_ops __initdata = {
30532+static struct of_pdt_ops prom_olpc_ops __initconst = {
30533 .nextprop = olpc_dt_nextprop,
30534 .getproplen = olpc_dt_getproplen,
30535 .getproperty = olpc_dt_getproperty,
30536diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30537index 3c68768..07e82b8 100644
30538--- a/arch/x86/power/cpu.c
30539+++ b/arch/x86/power/cpu.c
30540@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30541 static void fix_processor_context(void)
30542 {
30543 int cpu = smp_processor_id();
30544- struct tss_struct *t = &per_cpu(init_tss, cpu);
30545+ struct tss_struct *t = init_tss + cpu;
30546
30547 set_tss_desc(cpu, t); /*
30548 * This just modifies memory; should not be
30549@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30550 */
30551
30552 #ifdef CONFIG_X86_64
30553- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30554-
30555 syscall_init(); /* This sets MSR_*STAR and related */
30556 #endif
30557 load_TR_desc(); /* This does ltr */
30558diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30559index cbca565..bae7133 100644
30560--- a/arch/x86/realmode/init.c
30561+++ b/arch/x86/realmode/init.c
30562@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30563 __va(real_mode_header->trampoline_header);
30564
30565 #ifdef CONFIG_X86_32
30566- trampoline_header->start = __pa(startup_32_smp);
30567+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30568+
30569+#ifdef CONFIG_PAX_KERNEXEC
30570+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30571+#endif
30572+
30573+ trampoline_header->boot_cs = __BOOT_CS;
30574 trampoline_header->gdt_limit = __BOOT_DS + 7;
30575 trampoline_header->gdt_base = __pa(boot_gdt);
30576 #else
30577diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30578index 8869287..d577672 100644
30579--- a/arch/x86/realmode/rm/Makefile
30580+++ b/arch/x86/realmode/rm/Makefile
30581@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30582 $(call cc-option, -fno-unit-at-a-time)) \
30583 $(call cc-option, -fno-stack-protector) \
30584 $(call cc-option, -mpreferred-stack-boundary=2)
30585+ifdef CONSTIFY_PLUGIN
30586+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30587+endif
30588 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30589 GCOV_PROFILE := n
30590diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30591index a28221d..93c40f1 100644
30592--- a/arch/x86/realmode/rm/header.S
30593+++ b/arch/x86/realmode/rm/header.S
30594@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30595 #endif
30596 /* APM/BIOS reboot */
30597 .long pa_machine_real_restart_asm
30598-#ifdef CONFIG_X86_64
30599+#ifdef CONFIG_X86_32
30600+ .long __KERNEL_CS
30601+#else
30602 .long __KERNEL32_CS
30603 #endif
30604 END(real_mode_header)
30605diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30606index c1b2791..f9e31c7 100644
30607--- a/arch/x86/realmode/rm/trampoline_32.S
30608+++ b/arch/x86/realmode/rm/trampoline_32.S
30609@@ -25,6 +25,12 @@
30610 #include <asm/page_types.h>
30611 #include "realmode.h"
30612
30613+#ifdef CONFIG_PAX_KERNEXEC
30614+#define ta(X) (X)
30615+#else
30616+#define ta(X) (pa_ ## X)
30617+#endif
30618+
30619 .text
30620 .code16
30621
30622@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30623
30624 cli # We should be safe anyway
30625
30626- movl tr_start, %eax # where we need to go
30627-
30628 movl $0xA5A5A5A5, trampoline_status
30629 # write marker for master knows we're running
30630
30631@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30632 movw $1, %dx # protected mode (PE) bit
30633 lmsw %dx # into protected mode
30634
30635- ljmpl $__BOOT_CS, $pa_startup_32
30636+ ljmpl *(trampoline_header)
30637
30638 .section ".text32","ax"
30639 .code32
30640@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30641 .balign 8
30642 GLOBAL(trampoline_header)
30643 tr_start: .space 4
30644- tr_gdt_pad: .space 2
30645+ tr_boot_cs: .space 2
30646 tr_gdt: .space 6
30647 END(trampoline_header)
30648
30649diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30650index bb360dc..3e5945f 100644
30651--- a/arch/x86/realmode/rm/trampoline_64.S
30652+++ b/arch/x86/realmode/rm/trampoline_64.S
30653@@ -107,7 +107,7 @@ ENTRY(startup_32)
30654 wrmsr
30655
30656 # Enable paging and in turn activate Long Mode
30657- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30658+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30659 movl %eax, %cr0
30660
30661 /*
30662diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30663index 79d67bd..c7e1b90 100644
30664--- a/arch/x86/tools/relocs.c
30665+++ b/arch/x86/tools/relocs.c
30666@@ -12,10 +12,13 @@
30667 #include <regex.h>
30668 #include <tools/le_byteshift.h>
30669
30670+#include "../../../include/generated/autoconf.h"
30671+
30672 static void die(char *fmt, ...);
30673
30674 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30675 static Elf32_Ehdr ehdr;
30676+static Elf32_Phdr *phdr;
30677 static unsigned long reloc_count, reloc_idx;
30678 static unsigned long *relocs;
30679 static unsigned long reloc16_count, reloc16_idx;
30680@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30681 }
30682 }
30683
30684+static void read_phdrs(FILE *fp)
30685+{
30686+ unsigned int i;
30687+
30688+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30689+ if (!phdr) {
30690+ die("Unable to allocate %d program headers\n",
30691+ ehdr.e_phnum);
30692+ }
30693+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30694+ die("Seek to %d failed: %s\n",
30695+ ehdr.e_phoff, strerror(errno));
30696+ }
30697+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30698+ die("Cannot read ELF program headers: %s\n",
30699+ strerror(errno));
30700+ }
30701+ for(i = 0; i < ehdr.e_phnum; i++) {
30702+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30703+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30704+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30705+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30706+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30707+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30708+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30709+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30710+ }
30711+
30712+}
30713+
30714 static void read_shdrs(FILE *fp)
30715 {
30716- int i;
30717+ unsigned int i;
30718 Elf32_Shdr shdr;
30719
30720 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30721@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30722
30723 static void read_strtabs(FILE *fp)
30724 {
30725- int i;
30726+ unsigned int i;
30727 for (i = 0; i < ehdr.e_shnum; i++) {
30728 struct section *sec = &secs[i];
30729 if (sec->shdr.sh_type != SHT_STRTAB) {
30730@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30731
30732 static void read_symtabs(FILE *fp)
30733 {
30734- int i,j;
30735+ unsigned int i,j;
30736 for (i = 0; i < ehdr.e_shnum; i++) {
30737 struct section *sec = &secs[i];
30738 if (sec->shdr.sh_type != SHT_SYMTAB) {
30739@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30740 }
30741
30742
30743-static void read_relocs(FILE *fp)
30744+static void read_relocs(FILE *fp, int use_real_mode)
30745 {
30746- int i,j;
30747+ unsigned int i,j;
30748+ uint32_t base;
30749+
30750 for (i = 0; i < ehdr.e_shnum; i++) {
30751 struct section *sec = &secs[i];
30752 if (sec->shdr.sh_type != SHT_REL) {
30753@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30754 die("Cannot read symbol table: %s\n",
30755 strerror(errno));
30756 }
30757+ base = 0;
30758+
30759+#ifdef CONFIG_X86_32
30760+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30761+ if (phdr[j].p_type != PT_LOAD )
30762+ continue;
30763+ 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)
30764+ continue;
30765+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30766+ break;
30767+ }
30768+#endif
30769+
30770 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30771 Elf32_Rel *rel = &sec->reltab[j];
30772- rel->r_offset = elf32_to_cpu(rel->r_offset);
30773+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30774 rel->r_info = elf32_to_cpu(rel->r_info);
30775 }
30776 }
30777@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30778
30779 static void print_absolute_symbols(void)
30780 {
30781- int i;
30782+ unsigned int i;
30783 printf("Absolute symbols\n");
30784 printf(" Num: Value Size Type Bind Visibility Name\n");
30785 for (i = 0; i < ehdr.e_shnum; i++) {
30786 struct section *sec = &secs[i];
30787 char *sym_strtab;
30788- int j;
30789+ unsigned int j;
30790
30791 if (sec->shdr.sh_type != SHT_SYMTAB) {
30792 continue;
30793@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30794
30795 static void print_absolute_relocs(void)
30796 {
30797- int i, printed = 0;
30798+ unsigned int i, printed = 0;
30799
30800 for (i = 0; i < ehdr.e_shnum; i++) {
30801 struct section *sec = &secs[i];
30802 struct section *sec_applies, *sec_symtab;
30803 char *sym_strtab;
30804 Elf32_Sym *sh_symtab;
30805- int j;
30806+ unsigned int j;
30807 if (sec->shdr.sh_type != SHT_REL) {
30808 continue;
30809 }
30810@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30811 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30812 int use_real_mode)
30813 {
30814- int i;
30815+ unsigned int i;
30816 /* Walk through the relocations */
30817 for (i = 0; i < ehdr.e_shnum; i++) {
30818 char *sym_strtab;
30819 Elf32_Sym *sh_symtab;
30820 struct section *sec_applies, *sec_symtab;
30821- int j;
30822+ unsigned int j;
30823 struct section *sec = &secs[i];
30824
30825 if (sec->shdr.sh_type != SHT_REL) {
30826@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30827 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30828 r_type = ELF32_R_TYPE(rel->r_info);
30829
30830+ if (!use_real_mode) {
30831+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30832+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30833+ continue;
30834+
30835+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30836+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30837+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30838+ continue;
30839+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30840+ continue;
30841+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30842+ continue;
30843+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30844+ continue;
30845+#endif
30846+ }
30847+
30848 shn_abs = sym->st_shndx == SHN_ABS;
30849
30850 switch (r_type) {
30851@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30852
30853 static void emit_relocs(int as_text, int use_real_mode)
30854 {
30855- int i;
30856+ unsigned int i;
30857 /* Count how many relocations I have and allocate space for them. */
30858 reloc_count = 0;
30859 walk_relocs(count_reloc, use_real_mode);
30860@@ -808,10 +874,11 @@ int main(int argc, char **argv)
30861 fname, strerror(errno));
30862 }
30863 read_ehdr(fp);
30864+ read_phdrs(fp);
30865 read_shdrs(fp);
30866 read_strtabs(fp);
30867 read_symtabs(fp);
30868- read_relocs(fp);
30869+ read_relocs(fp, use_real_mode);
30870 if (show_absolute_syms) {
30871 print_absolute_symbols();
30872 goto out;
30873diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30874index fd14be1..e3c79c0 100644
30875--- a/arch/x86/vdso/Makefile
30876+++ b/arch/x86/vdso/Makefile
30877@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30878 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30879 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30880
30881-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30882+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30883 GCOV_PROFILE := n
30884
30885 #
30886diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30887index 0faad64..39ef157 100644
30888--- a/arch/x86/vdso/vdso32-setup.c
30889+++ b/arch/x86/vdso/vdso32-setup.c
30890@@ -25,6 +25,7 @@
30891 #include <asm/tlbflush.h>
30892 #include <asm/vdso.h>
30893 #include <asm/proto.h>
30894+#include <asm/mman.h>
30895
30896 enum {
30897 VDSO_DISABLED = 0,
30898@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30899 void enable_sep_cpu(void)
30900 {
30901 int cpu = get_cpu();
30902- struct tss_struct *tss = &per_cpu(init_tss, cpu);
30903+ struct tss_struct *tss = init_tss + cpu;
30904
30905 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30906 put_cpu();
30907@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30908 gate_vma.vm_start = FIXADDR_USER_START;
30909 gate_vma.vm_end = FIXADDR_USER_END;
30910 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30911- gate_vma.vm_page_prot = __P101;
30912+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30913
30914 return 0;
30915 }
30916@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30917 if (compat)
30918 addr = VDSO_HIGH_BASE;
30919 else {
30920- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30921+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30922 if (IS_ERR_VALUE(addr)) {
30923 ret = addr;
30924 goto up_fail;
30925 }
30926 }
30927
30928- current->mm->context.vdso = (void *)addr;
30929+ current->mm->context.vdso = addr;
30930
30931 if (compat_uses_vma || !compat) {
30932 /*
30933@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30934 }
30935
30936 current_thread_info()->sysenter_return =
30937- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30938+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30939
30940 up_fail:
30941 if (ret)
30942- current->mm->context.vdso = NULL;
30943+ current->mm->context.vdso = 0;
30944
30945 up_write(&mm->mmap_sem);
30946
30947@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30948
30949 const char *arch_vma_name(struct vm_area_struct *vma)
30950 {
30951- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30952+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30953 return "[vdso]";
30954+
30955+#ifdef CONFIG_PAX_SEGMEXEC
30956+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30957+ return "[vdso]";
30958+#endif
30959+
30960 return NULL;
30961 }
30962
30963@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30964 * Check to see if the corresponding task was created in compat vdso
30965 * mode.
30966 */
30967- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30968+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30969 return &gate_vma;
30970 return NULL;
30971 }
30972diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30973index 431e875..cbb23f3 100644
30974--- a/arch/x86/vdso/vma.c
30975+++ b/arch/x86/vdso/vma.c
30976@@ -16,8 +16,6 @@
30977 #include <asm/vdso.h>
30978 #include <asm/page.h>
30979
30980-unsigned int __read_mostly vdso_enabled = 1;
30981-
30982 extern char vdso_start[], vdso_end[];
30983 extern unsigned short vdso_sync_cpuid;
30984
30985@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30986 * unaligned here as a result of stack start randomization.
30987 */
30988 addr = PAGE_ALIGN(addr);
30989- addr = align_vdso_addr(addr);
30990
30991 return addr;
30992 }
30993@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30994 unsigned size)
30995 {
30996 struct mm_struct *mm = current->mm;
30997- unsigned long addr;
30998+ unsigned long addr = 0;
30999 int ret;
31000
31001- if (!vdso_enabled)
31002- return 0;
31003-
31004 down_write(&mm->mmap_sem);
31005+
31006+#ifdef CONFIG_PAX_RANDMMAP
31007+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31008+#endif
31009+
31010 addr = vdso_addr(mm->start_stack, size);
31011+ addr = align_vdso_addr(addr);
31012 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31013 if (IS_ERR_VALUE(addr)) {
31014 ret = addr;
31015 goto up_fail;
31016 }
31017
31018- current->mm->context.vdso = (void *)addr;
31019+ mm->context.vdso = addr;
31020
31021 ret = install_special_mapping(mm, addr, size,
31022 VM_READ|VM_EXEC|
31023 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31024 pages);
31025- if (ret) {
31026- current->mm->context.vdso = NULL;
31027- goto up_fail;
31028- }
31029+ if (ret)
31030+ mm->context.vdso = 0;
31031
31032 up_fail:
31033 up_write(&mm->mmap_sem);
31034@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31035 vdsox32_size);
31036 }
31037 #endif
31038-
31039-static __init int vdso_setup(char *s)
31040-{
31041- vdso_enabled = simple_strtoul(s, NULL, 0);
31042- return 0;
31043-}
31044-__setup("vdso=", vdso_setup);
31045diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31046index 2262003..f229ced 100644
31047--- a/arch/x86/xen/enlighten.c
31048+++ b/arch/x86/xen/enlighten.c
31049@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31050
31051 struct shared_info xen_dummy_shared_info;
31052
31053-void *xen_initial_gdt;
31054-
31055 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31056 __read_mostly int xen_have_vector_callback;
31057 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31058@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31059 {
31060 unsigned long va = dtr->address;
31061 unsigned int size = dtr->size + 1;
31062- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31063- unsigned long frames[pages];
31064+ unsigned long frames[65536 / PAGE_SIZE];
31065 int f;
31066
31067 /*
31068@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31069 {
31070 unsigned long va = dtr->address;
31071 unsigned int size = dtr->size + 1;
31072- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31073- unsigned long frames[pages];
31074+ unsigned long frames[65536 / PAGE_SIZE];
31075 int f;
31076
31077 /*
31078@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31079 return 0;
31080 }
31081
31082-static void set_xen_basic_apic_ops(void)
31083+static void __init set_xen_basic_apic_ops(void)
31084 {
31085 apic->read = xen_apic_read;
31086 apic->write = xen_apic_write;
31087@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31088 #endif
31089 };
31090
31091-static void xen_reboot(int reason)
31092+static __noreturn void xen_reboot(int reason)
31093 {
31094 struct sched_shutdown r = { .reason = reason };
31095
31096- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31097- BUG();
31098+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31099+ BUG();
31100 }
31101
31102-static void xen_restart(char *msg)
31103+static __noreturn void xen_restart(char *msg)
31104 {
31105 xen_reboot(SHUTDOWN_reboot);
31106 }
31107
31108-static void xen_emergency_restart(void)
31109+static __noreturn void xen_emergency_restart(void)
31110 {
31111 xen_reboot(SHUTDOWN_reboot);
31112 }
31113
31114-static void xen_machine_halt(void)
31115+static __noreturn void xen_machine_halt(void)
31116 {
31117 xen_reboot(SHUTDOWN_poweroff);
31118 }
31119
31120-static void xen_machine_power_off(void)
31121+static __noreturn void xen_machine_power_off(void)
31122 {
31123 if (pm_power_off)
31124 pm_power_off();
31125@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
31126 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31127
31128 /* Work out if we support NX */
31129- x86_configure_nx();
31130+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31131+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31132+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31133+ unsigned l, h;
31134+
31135+ __supported_pte_mask |= _PAGE_NX;
31136+ rdmsr(MSR_EFER, l, h);
31137+ l |= EFER_NX;
31138+ wrmsr(MSR_EFER, l, h);
31139+ }
31140+#endif
31141
31142 xen_setup_features();
31143
31144@@ -1399,14 +1405,7 @@ asmlinkage void __init xen_start_kernel(void)
31145 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
31146 }
31147
31148- machine_ops = xen_machine_ops;
31149-
31150- /*
31151- * The only reliable way to retain the initial address of the
31152- * percpu gdt_page is to remember it here, so we can go and
31153- * mark it RW later, when the initial percpu area is freed.
31154- */
31155- xen_initial_gdt = &per_cpu(gdt_page, 0);
31156+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
31157
31158 xen_smp_init();
31159
31160@@ -1598,7 +1597,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31161 return NOTIFY_OK;
31162 }
31163
31164-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31165+static struct notifier_block xen_hvm_cpu_notifier = {
31166 .notifier_call = xen_hvm_cpu_notify,
31167 };
31168
31169diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31170index 01de35c..0bda07b 100644
31171--- a/arch/x86/xen/mmu.c
31172+++ b/arch/x86/xen/mmu.c
31173@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31174 /* L3_k[510] -> level2_kernel_pgt
31175 * L3_i[511] -> level2_fixmap_pgt */
31176 convert_pfn_mfn(level3_kernel_pgt);
31177+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31178+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31179+ convert_pfn_mfn(level3_vmemmap_pgt);
31180
31181 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31182 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31183@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31184 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31185 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31186 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31187+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31188+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31189+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31190 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31191 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31192+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31193 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31194 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31195
31196@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
31197 pv_mmu_ops.set_pud = xen_set_pud;
31198 #if PAGETABLE_LEVELS == 4
31199 pv_mmu_ops.set_pgd = xen_set_pgd;
31200+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31201 #endif
31202
31203 /* This will work as long as patching hasn't happened yet
31204@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31205 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31206 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31207 .set_pgd = xen_set_pgd_hyper,
31208+ .set_pgd_batched = xen_set_pgd_hyper,
31209
31210 .alloc_pud = xen_alloc_pmd_init,
31211 .release_pud = xen_release_pmd_init,
31212diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31213index 34bc4ce..c34aa24 100644
31214--- a/arch/x86/xen/smp.c
31215+++ b/arch/x86/xen/smp.c
31216@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31217 {
31218 BUG_ON(smp_processor_id() != 0);
31219 native_smp_prepare_boot_cpu();
31220-
31221- /* We've switched to the "real" per-cpu gdt, so make sure the
31222- old memory can be recycled */
31223- make_lowmem_page_readwrite(xen_initial_gdt);
31224-
31225 xen_filter_cpu_maps();
31226 xen_setup_vcpu_info_placement();
31227 }
31228@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31229 gdt = get_cpu_gdt_table(cpu);
31230
31231 ctxt->flags = VGCF_IN_KERNEL;
31232- ctxt->user_regs.ds = __USER_DS;
31233- ctxt->user_regs.es = __USER_DS;
31234+ ctxt->user_regs.ds = __KERNEL_DS;
31235+ ctxt->user_regs.es = __KERNEL_DS;
31236 ctxt->user_regs.ss = __KERNEL_DS;
31237 #ifdef CONFIG_X86_32
31238 ctxt->user_regs.fs = __KERNEL_PERCPU;
31239- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31240+ savesegment(gs, ctxt->user_regs.gs);
31241 #else
31242 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31243 #endif
31244@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31245 int rc;
31246
31247 per_cpu(current_task, cpu) = idle;
31248+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31249 #ifdef CONFIG_X86_32
31250 irq_ctx_init(cpu);
31251 #else
31252 clear_tsk_thread_flag(idle, TIF_FORK);
31253- per_cpu(kernel_stack, cpu) =
31254- (unsigned long)task_stack_page(idle) -
31255- KERNEL_STACK_OFFSET + THREAD_SIZE;
31256+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31257 #endif
31258 xen_setup_runstate_info(cpu);
31259 xen_setup_timer(cpu);
31260@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31261
31262 void __init xen_smp_init(void)
31263 {
31264- smp_ops = xen_smp_ops;
31265+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31266 xen_fill_possible_map();
31267 xen_init_spinlocks();
31268 }
31269diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31270index 33ca6e4..0ded929 100644
31271--- a/arch/x86/xen/xen-asm_32.S
31272+++ b/arch/x86/xen/xen-asm_32.S
31273@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31274 ESP_OFFSET=4 # bytes pushed onto stack
31275
31276 /*
31277- * Store vcpu_info pointer for easy access. Do it this way to
31278- * avoid having to reload %fs
31279+ * Store vcpu_info pointer for easy access.
31280 */
31281 #ifdef CONFIG_SMP
31282- GET_THREAD_INFO(%eax)
31283- movl %ss:TI_cpu(%eax), %eax
31284- movl %ss:__per_cpu_offset(,%eax,4), %eax
31285- mov %ss:xen_vcpu(%eax), %eax
31286+ push %fs
31287+ mov $(__KERNEL_PERCPU), %eax
31288+ mov %eax, %fs
31289+ mov PER_CPU_VAR(xen_vcpu), %eax
31290+ pop %fs
31291 #else
31292 movl %ss:xen_vcpu, %eax
31293 #endif
31294diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31295index 7faed58..ba4427c 100644
31296--- a/arch/x86/xen/xen-head.S
31297+++ b/arch/x86/xen/xen-head.S
31298@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31299 #ifdef CONFIG_X86_32
31300 mov %esi,xen_start_info
31301 mov $init_thread_union+THREAD_SIZE,%esp
31302+#ifdef CONFIG_SMP
31303+ movl $cpu_gdt_table,%edi
31304+ movl $__per_cpu_load,%eax
31305+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31306+ rorl $16,%eax
31307+ movb %al,__KERNEL_PERCPU + 4(%edi)
31308+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31309+ movl $__per_cpu_end - 1,%eax
31310+ subl $__per_cpu_start,%eax
31311+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31312+#endif
31313 #else
31314 mov %rsi,xen_start_info
31315 mov $init_thread_union+THREAD_SIZE,%rsp
31316diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31317index a95b417..b6dbd0b 100644
31318--- a/arch/x86/xen/xen-ops.h
31319+++ b/arch/x86/xen/xen-ops.h
31320@@ -10,8 +10,6 @@
31321 extern const char xen_hypervisor_callback[];
31322 extern const char xen_failsafe_callback[];
31323
31324-extern void *xen_initial_gdt;
31325-
31326 struct trap_info;
31327 void xen_copy_trap_info(struct trap_info *traps);
31328
31329diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31330index 525bd3d..ef888b1 100644
31331--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31332+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31333@@ -119,9 +119,9 @@
31334 ----------------------------------------------------------------------*/
31335
31336 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31337-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31338 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31339 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31340+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31341
31342 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31343 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31344diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31345index 2f33760..835e50a 100644
31346--- a/arch/xtensa/variants/fsf/include/variant/core.h
31347+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31348@@ -11,6 +11,7 @@
31349 #ifndef _XTENSA_CORE_H
31350 #define _XTENSA_CORE_H
31351
31352+#include <linux/const.h>
31353
31354 /****************************************************************************
31355 Parameters Useful for Any Code, USER or PRIVILEGED
31356@@ -112,9 +113,9 @@
31357 ----------------------------------------------------------------------*/
31358
31359 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31360-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31361 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31362 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31363+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31364
31365 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31366 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31367diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31368index af00795..2bb8105 100644
31369--- a/arch/xtensa/variants/s6000/include/variant/core.h
31370+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31371@@ -11,6 +11,7 @@
31372 #ifndef _XTENSA_CORE_CONFIGURATION_H
31373 #define _XTENSA_CORE_CONFIGURATION_H
31374
31375+#include <linux/const.h>
31376
31377 /****************************************************************************
31378 Parameters Useful for Any Code, USER or PRIVILEGED
31379@@ -118,9 +119,9 @@
31380 ----------------------------------------------------------------------*/
31381
31382 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31383-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31384 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31385 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31386+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31387
31388 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31389 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31390diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31391index 58916af..eb9dbcf6 100644
31392--- a/block/blk-iopoll.c
31393+++ b/block/blk-iopoll.c
31394@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31395 }
31396 EXPORT_SYMBOL(blk_iopoll_complete);
31397
31398-static void blk_iopoll_softirq(struct softirq_action *h)
31399+static void blk_iopoll_softirq(void)
31400 {
31401 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31402 int rearm = 0, budget = blk_iopoll_budget;
31403@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31404 return NOTIFY_OK;
31405 }
31406
31407-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31408+static struct notifier_block blk_iopoll_cpu_notifier = {
31409 .notifier_call = blk_iopoll_cpu_notify,
31410 };
31411
31412diff --git a/block/blk-map.c b/block/blk-map.c
31413index 623e1cd..ca1e109 100644
31414--- a/block/blk-map.c
31415+++ b/block/blk-map.c
31416@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31417 if (!len || !kbuf)
31418 return -EINVAL;
31419
31420- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31421+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31422 if (do_copy)
31423 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31424 else
31425diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31426index 467c8de..f3628c5 100644
31427--- a/block/blk-softirq.c
31428+++ b/block/blk-softirq.c
31429@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31430 * Softirq action handler - move entries to local list and loop over them
31431 * while passing them to the queue registered handler.
31432 */
31433-static void blk_done_softirq(struct softirq_action *h)
31434+static void blk_done_softirq(void)
31435 {
31436 struct list_head *cpu_list, local_list;
31437
31438@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31439 return NOTIFY_OK;
31440 }
31441
31442-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31443+static struct notifier_block blk_cpu_notifier = {
31444 .notifier_call = blk_cpu_notify,
31445 };
31446
31447diff --git a/block/bsg.c b/block/bsg.c
31448index ff64ae3..593560c 100644
31449--- a/block/bsg.c
31450+++ b/block/bsg.c
31451@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31452 struct sg_io_v4 *hdr, struct bsg_device *bd,
31453 fmode_t has_write_perm)
31454 {
31455+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31456+ unsigned char *cmdptr;
31457+
31458 if (hdr->request_len > BLK_MAX_CDB) {
31459 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31460 if (!rq->cmd)
31461 return -ENOMEM;
31462- }
31463+ cmdptr = rq->cmd;
31464+ } else
31465+ cmdptr = tmpcmd;
31466
31467- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31468+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31469 hdr->request_len))
31470 return -EFAULT;
31471
31472+ if (cmdptr != rq->cmd)
31473+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31474+
31475 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31476 if (blk_verify_command(rq->cmd, has_write_perm))
31477 return -EPERM;
31478diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31479index 7c668c8..db3521c 100644
31480--- a/block/compat_ioctl.c
31481+++ b/block/compat_ioctl.c
31482@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31483 err |= __get_user(f->spec1, &uf->spec1);
31484 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31485 err |= __get_user(name, &uf->name);
31486- f->name = compat_ptr(name);
31487+ f->name = (void __force_kernel *)compat_ptr(name);
31488 if (err) {
31489 err = -EFAULT;
31490 goto out;
31491diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31492index b62fb88..bdab4c4 100644
31493--- a/block/partitions/efi.c
31494+++ b/block/partitions/efi.c
31495@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31496 if (!gpt)
31497 return NULL;
31498
31499+ if (!le32_to_cpu(gpt->num_partition_entries))
31500+ return NULL;
31501+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31502+ if (!pte)
31503+ return NULL;
31504+
31505 count = le32_to_cpu(gpt->num_partition_entries) *
31506 le32_to_cpu(gpt->sizeof_partition_entry);
31507- if (!count)
31508- return NULL;
31509- pte = kzalloc(count, GFP_KERNEL);
31510- if (!pte)
31511- return NULL;
31512-
31513 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31514 (u8 *) pte,
31515 count) < count) {
31516diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31517index 9a87daa..fb17486 100644
31518--- a/block/scsi_ioctl.c
31519+++ b/block/scsi_ioctl.c
31520@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31521 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31522 struct sg_io_hdr *hdr, fmode_t mode)
31523 {
31524- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31525+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31526+ unsigned char *cmdptr;
31527+
31528+ if (rq->cmd != rq->__cmd)
31529+ cmdptr = rq->cmd;
31530+ else
31531+ cmdptr = tmpcmd;
31532+
31533+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31534 return -EFAULT;
31535+
31536+ if (cmdptr != rq->cmd)
31537+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31538+
31539 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31540 return -EPERM;
31541
31542@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31543 int err;
31544 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31545 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31546+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31547+ unsigned char *cmdptr;
31548
31549 if (!sic)
31550 return -EINVAL;
31551@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31552 */
31553 err = -EFAULT;
31554 rq->cmd_len = cmdlen;
31555- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31556+
31557+ if (rq->cmd != rq->__cmd)
31558+ cmdptr = rq->cmd;
31559+ else
31560+ cmdptr = tmpcmd;
31561+
31562+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31563 goto error;
31564
31565+ if (rq->cmd != cmdptr)
31566+ memcpy(rq->cmd, cmdptr, cmdlen);
31567+
31568 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31569 goto error;
31570
31571diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31572index 7bdd61b..afec999 100644
31573--- a/crypto/cryptd.c
31574+++ b/crypto/cryptd.c
31575@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31576
31577 struct cryptd_blkcipher_request_ctx {
31578 crypto_completion_t complete;
31579-};
31580+} __no_const;
31581
31582 struct cryptd_hash_ctx {
31583 struct crypto_shash *child;
31584@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31585
31586 struct cryptd_aead_request_ctx {
31587 crypto_completion_t complete;
31588-};
31589+} __no_const;
31590
31591 static void cryptd_queue_worker(struct work_struct *work);
31592
31593diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
31594index f6d9baf..dfd511f 100644
31595--- a/crypto/crypto_user.c
31596+++ b/crypto/crypto_user.c
31597@@ -30,6 +30,8 @@
31598
31599 #include "internal.h"
31600
31601+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
31602+
31603 static DEFINE_MUTEX(crypto_cfg_mutex);
31604
31605 /* The crypto netlink socket */
31606@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
31607 struct crypto_dump_info info;
31608 int err;
31609
31610- if (!p->cru_driver_name)
31611+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31612+ return -EINVAL;
31613+
31614+ if (!p->cru_driver_name[0])
31615 return -EINVAL;
31616
31617 alg = crypto_alg_match(p, 1);
31618@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31619 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31620 LIST_HEAD(list);
31621
31622+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31623+ return -EINVAL;
31624+
31625 if (priority && !strlen(p->cru_driver_name))
31626 return -EINVAL;
31627
31628@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31629 struct crypto_alg *alg;
31630 struct crypto_user_alg *p = nlmsg_data(nlh);
31631
31632+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31633+ return -EINVAL;
31634+
31635 alg = crypto_alg_match(p, 1);
31636 if (!alg)
31637 return -ENOENT;
31638@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31639 struct crypto_user_alg *p = nlmsg_data(nlh);
31640 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31641
31642+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31643+ return -EINVAL;
31644+
31645 if (strlen(p->cru_driver_name))
31646 exact = 1;
31647
31648diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31649index f220d64..d359ad6 100644
31650--- a/drivers/acpi/apei/apei-internal.h
31651+++ b/drivers/acpi/apei/apei-internal.h
31652@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31653 struct apei_exec_ins_type {
31654 u32 flags;
31655 apei_exec_ins_func_t run;
31656-};
31657+} __do_const;
31658
31659 struct apei_exec_context {
31660 u32 ip;
31661diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31662index e6defd8..c26a225 100644
31663--- a/drivers/acpi/apei/cper.c
31664+++ b/drivers/acpi/apei/cper.c
31665@@ -38,12 +38,12 @@
31666 */
31667 u64 cper_next_record_id(void)
31668 {
31669- static atomic64_t seq;
31670+ static atomic64_unchecked_t seq;
31671
31672- if (!atomic64_read(&seq))
31673- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31674+ if (!atomic64_read_unchecked(&seq))
31675+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31676
31677- return atomic64_inc_return(&seq);
31678+ return atomic64_inc_return_unchecked(&seq);
31679 }
31680 EXPORT_SYMBOL_GPL(cper_next_record_id);
31681
31682diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31683index be60399..778b33e8 100644
31684--- a/drivers/acpi/bgrt.c
31685+++ b/drivers/acpi/bgrt.c
31686@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31687 return -ENODEV;
31688
31689 sysfs_bin_attr_init(&image_attr);
31690- image_attr.private = bgrt_image;
31691- image_attr.size = bgrt_image_size;
31692+ pax_open_kernel();
31693+ *(void **)&image_attr.private = bgrt_image;
31694+ *(size_t *)&image_attr.size = bgrt_image_size;
31695+ pax_close_kernel();
31696
31697 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31698 if (!bgrt_kobj)
31699diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31700index cb96296..b81293b 100644
31701--- a/drivers/acpi/blacklist.c
31702+++ b/drivers/acpi/blacklist.c
31703@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31704 u32 is_critical_error;
31705 };
31706
31707-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31708+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31709
31710 /*
31711 * POLICY: If *anything* doesn't work, put it on the blacklist.
31712@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31713 return 0;
31714 }
31715
31716-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31717+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31718 {
31719 .callback = dmi_disable_osi_vista,
31720 .ident = "Fujitsu Siemens",
31721diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31722index 7586544..636a2f0 100644
31723--- a/drivers/acpi/ec_sys.c
31724+++ b/drivers/acpi/ec_sys.c
31725@@ -12,6 +12,7 @@
31726 #include <linux/acpi.h>
31727 #include <linux/debugfs.h>
31728 #include <linux/module.h>
31729+#include <linux/uaccess.h>
31730 #include "internal.h"
31731
31732 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31733@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31734 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31735 */
31736 unsigned int size = EC_SPACE_SIZE;
31737- u8 *data = (u8 *) buf;
31738+ u8 data;
31739 loff_t init_off = *off;
31740 int err = 0;
31741
31742@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31743 size = count;
31744
31745 while (size) {
31746- err = ec_read(*off, &data[*off - init_off]);
31747+ err = ec_read(*off, &data);
31748 if (err)
31749 return err;
31750+ if (put_user(data, &buf[*off - init_off]))
31751+ return -EFAULT;
31752 *off += 1;
31753 size--;
31754 }
31755@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31756
31757 unsigned int size = count;
31758 loff_t init_off = *off;
31759- u8 *data = (u8 *) buf;
31760 int err = 0;
31761
31762 if (*off >= EC_SPACE_SIZE)
31763@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31764 }
31765
31766 while (size) {
31767- u8 byte_write = data[*off - init_off];
31768+ u8 byte_write;
31769+ if (get_user(byte_write, &buf[*off - init_off]))
31770+ return -EFAULT;
31771 err = ec_write(*off, byte_write);
31772 if (err)
31773 return err;
31774diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31775index e83311b..142b5cc 100644
31776--- a/drivers/acpi/processor_driver.c
31777+++ b/drivers/acpi/processor_driver.c
31778@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31779 return 0;
31780 #endif
31781
31782- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31783+ BUG_ON(pr->id >= nr_cpu_ids);
31784
31785 /*
31786 * Buggy BIOS check
31787diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31788index ed9a1cc..f4a354c 100644
31789--- a/drivers/acpi/processor_idle.c
31790+++ b/drivers/acpi/processor_idle.c
31791@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31792 {
31793 int i, count = CPUIDLE_DRIVER_STATE_START;
31794 struct acpi_processor_cx *cx;
31795- struct cpuidle_state *state;
31796+ cpuidle_state_no_const *state;
31797 struct cpuidle_driver *drv = &acpi_idle_driver;
31798
31799 if (!pr->flags.power_setup_done)
31800diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31801index ea61ca9..3fdd70d 100644
31802--- a/drivers/acpi/sysfs.c
31803+++ b/drivers/acpi/sysfs.c
31804@@ -420,11 +420,11 @@ static u32 num_counters;
31805 static struct attribute **all_attrs;
31806 static u32 acpi_gpe_count;
31807
31808-static struct attribute_group interrupt_stats_attr_group = {
31809+static attribute_group_no_const interrupt_stats_attr_group = {
31810 .name = "interrupts",
31811 };
31812
31813-static struct kobj_attribute *counter_attrs;
31814+static kobj_attribute_no_const *counter_attrs;
31815
31816 static void delete_gpe_attr_array(void)
31817 {
31818diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
31819index 6cd7805..07facb3 100644
31820--- a/drivers/ata/libahci.c
31821+++ b/drivers/ata/libahci.c
31822@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
31823 }
31824 EXPORT_SYMBOL_GPL(ahci_kick_engine);
31825
31826-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31827+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31828 struct ata_taskfile *tf, int is_cmd, u16 flags,
31829 unsigned long timeout_msec)
31830 {
31831diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31832index 46cd3f4..0871ad0 100644
31833--- a/drivers/ata/libata-core.c
31834+++ b/drivers/ata/libata-core.c
31835@@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31836 struct ata_port *ap;
31837 unsigned int tag;
31838
31839- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31840+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31841 ap = qc->ap;
31842
31843 qc->flags = 0;
31844@@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31845 struct ata_port *ap;
31846 struct ata_link *link;
31847
31848- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31849+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31850 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31851 ap = qc->ap;
31852 link = qc->dev->link;
31853@@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31854 return;
31855
31856 spin_lock(&lock);
31857+ pax_open_kernel();
31858
31859 for (cur = ops->inherits; cur; cur = cur->inherits) {
31860 void **inherit = (void **)cur;
31861@@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31862 if (IS_ERR(*pp))
31863 *pp = NULL;
31864
31865- ops->inherits = NULL;
31866+ *(struct ata_port_operations **)&ops->inherits = NULL;
31867
31868+ pax_close_kernel();
31869 spin_unlock(&lock);
31870 }
31871
31872diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31873index 405022d..fb70e53 100644
31874--- a/drivers/ata/pata_arasan_cf.c
31875+++ b/drivers/ata/pata_arasan_cf.c
31876@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31877 /* Handle platform specific quirks */
31878 if (pdata->quirk) {
31879 if (pdata->quirk & CF_BROKEN_PIO) {
31880- ap->ops->set_piomode = NULL;
31881+ pax_open_kernel();
31882+ *(void **)&ap->ops->set_piomode = NULL;
31883+ pax_close_kernel();
31884 ap->pio_mask = 0;
31885 }
31886 if (pdata->quirk & CF_BROKEN_MWDMA)
31887diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31888index f9b983a..887b9d8 100644
31889--- a/drivers/atm/adummy.c
31890+++ b/drivers/atm/adummy.c
31891@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31892 vcc->pop(vcc, skb);
31893 else
31894 dev_kfree_skb_any(skb);
31895- atomic_inc(&vcc->stats->tx);
31896+ atomic_inc_unchecked(&vcc->stats->tx);
31897
31898 return 0;
31899 }
31900diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31901index 77a7480..05cde58 100644
31902--- a/drivers/atm/ambassador.c
31903+++ b/drivers/atm/ambassador.c
31904@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31905 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31906
31907 // VC layer stats
31908- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31909+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31910
31911 // free the descriptor
31912 kfree (tx_descr);
31913@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31914 dump_skb ("<<<", vc, skb);
31915
31916 // VC layer stats
31917- atomic_inc(&atm_vcc->stats->rx);
31918+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31919 __net_timestamp(skb);
31920 // end of our responsibility
31921 atm_vcc->push (atm_vcc, skb);
31922@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31923 } else {
31924 PRINTK (KERN_INFO, "dropped over-size frame");
31925 // should we count this?
31926- atomic_inc(&atm_vcc->stats->rx_drop);
31927+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31928 }
31929
31930 } else {
31931@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31932 }
31933
31934 if (check_area (skb->data, skb->len)) {
31935- atomic_inc(&atm_vcc->stats->tx_err);
31936+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31937 return -ENOMEM; // ?
31938 }
31939
31940diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31941index b22d71c..d6e1049 100644
31942--- a/drivers/atm/atmtcp.c
31943+++ b/drivers/atm/atmtcp.c
31944@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31945 if (vcc->pop) vcc->pop(vcc,skb);
31946 else dev_kfree_skb(skb);
31947 if (dev_data) return 0;
31948- atomic_inc(&vcc->stats->tx_err);
31949+ atomic_inc_unchecked(&vcc->stats->tx_err);
31950 return -ENOLINK;
31951 }
31952 size = skb->len+sizeof(struct atmtcp_hdr);
31953@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31954 if (!new_skb) {
31955 if (vcc->pop) vcc->pop(vcc,skb);
31956 else dev_kfree_skb(skb);
31957- atomic_inc(&vcc->stats->tx_err);
31958+ atomic_inc_unchecked(&vcc->stats->tx_err);
31959 return -ENOBUFS;
31960 }
31961 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31962@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31963 if (vcc->pop) vcc->pop(vcc,skb);
31964 else dev_kfree_skb(skb);
31965 out_vcc->push(out_vcc,new_skb);
31966- atomic_inc(&vcc->stats->tx);
31967- atomic_inc(&out_vcc->stats->rx);
31968+ atomic_inc_unchecked(&vcc->stats->tx);
31969+ atomic_inc_unchecked(&out_vcc->stats->rx);
31970 return 0;
31971 }
31972
31973@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31974 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31975 read_unlock(&vcc_sklist_lock);
31976 if (!out_vcc) {
31977- atomic_inc(&vcc->stats->tx_err);
31978+ atomic_inc_unchecked(&vcc->stats->tx_err);
31979 goto done;
31980 }
31981 skb_pull(skb,sizeof(struct atmtcp_hdr));
31982@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31983 __net_timestamp(new_skb);
31984 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31985 out_vcc->push(out_vcc,new_skb);
31986- atomic_inc(&vcc->stats->tx);
31987- atomic_inc(&out_vcc->stats->rx);
31988+ atomic_inc_unchecked(&vcc->stats->tx);
31989+ atomic_inc_unchecked(&out_vcc->stats->rx);
31990 done:
31991 if (vcc->pop) vcc->pop(vcc,skb);
31992 else dev_kfree_skb(skb);
31993diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31994index c1eb6fa..4c71be9 100644
31995--- a/drivers/atm/eni.c
31996+++ b/drivers/atm/eni.c
31997@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31998 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31999 vcc->dev->number);
32000 length = 0;
32001- atomic_inc(&vcc->stats->rx_err);
32002+ atomic_inc_unchecked(&vcc->stats->rx_err);
32003 }
32004 else {
32005 length = ATM_CELL_SIZE-1; /* no HEC */
32006@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32007 size);
32008 }
32009 eff = length = 0;
32010- atomic_inc(&vcc->stats->rx_err);
32011+ atomic_inc_unchecked(&vcc->stats->rx_err);
32012 }
32013 else {
32014 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32015@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32016 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32017 vcc->dev->number,vcc->vci,length,size << 2,descr);
32018 length = eff = 0;
32019- atomic_inc(&vcc->stats->rx_err);
32020+ atomic_inc_unchecked(&vcc->stats->rx_err);
32021 }
32022 }
32023 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32024@@ -767,7 +767,7 @@ rx_dequeued++;
32025 vcc->push(vcc,skb);
32026 pushed++;
32027 }
32028- atomic_inc(&vcc->stats->rx);
32029+ atomic_inc_unchecked(&vcc->stats->rx);
32030 }
32031 wake_up(&eni_dev->rx_wait);
32032 }
32033@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32034 PCI_DMA_TODEVICE);
32035 if (vcc->pop) vcc->pop(vcc,skb);
32036 else dev_kfree_skb_irq(skb);
32037- atomic_inc(&vcc->stats->tx);
32038+ atomic_inc_unchecked(&vcc->stats->tx);
32039 wake_up(&eni_dev->tx_wait);
32040 dma_complete++;
32041 }
32042diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32043index b41c948..a002b17 100644
32044--- a/drivers/atm/firestream.c
32045+++ b/drivers/atm/firestream.c
32046@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32047 }
32048 }
32049
32050- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32051+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32052
32053 fs_dprintk (FS_DEBUG_TXMEM, "i");
32054 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32055@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32056 #endif
32057 skb_put (skb, qe->p1 & 0xffff);
32058 ATM_SKB(skb)->vcc = atm_vcc;
32059- atomic_inc(&atm_vcc->stats->rx);
32060+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32061 __net_timestamp(skb);
32062 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32063 atm_vcc->push (atm_vcc, skb);
32064@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32065 kfree (pe);
32066 }
32067 if (atm_vcc)
32068- atomic_inc(&atm_vcc->stats->rx_drop);
32069+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32070 break;
32071 case 0x1f: /* Reassembly abort: no buffers. */
32072 /* Silently increment error counter. */
32073 if (atm_vcc)
32074- atomic_inc(&atm_vcc->stats->rx_drop);
32075+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32076 break;
32077 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32078 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32079diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32080index 204814e..cede831 100644
32081--- a/drivers/atm/fore200e.c
32082+++ b/drivers/atm/fore200e.c
32083@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32084 #endif
32085 /* check error condition */
32086 if (*entry->status & STATUS_ERROR)
32087- atomic_inc(&vcc->stats->tx_err);
32088+ atomic_inc_unchecked(&vcc->stats->tx_err);
32089 else
32090- atomic_inc(&vcc->stats->tx);
32091+ atomic_inc_unchecked(&vcc->stats->tx);
32092 }
32093 }
32094
32095@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32096 if (skb == NULL) {
32097 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32098
32099- atomic_inc(&vcc->stats->rx_drop);
32100+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32101 return -ENOMEM;
32102 }
32103
32104@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32105
32106 dev_kfree_skb_any(skb);
32107
32108- atomic_inc(&vcc->stats->rx_drop);
32109+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32110 return -ENOMEM;
32111 }
32112
32113 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32114
32115 vcc->push(vcc, skb);
32116- atomic_inc(&vcc->stats->rx);
32117+ atomic_inc_unchecked(&vcc->stats->rx);
32118
32119 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32120
32121@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32122 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32123 fore200e->atm_dev->number,
32124 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32125- atomic_inc(&vcc->stats->rx_err);
32126+ atomic_inc_unchecked(&vcc->stats->rx_err);
32127 }
32128 }
32129
32130@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32131 goto retry_here;
32132 }
32133
32134- atomic_inc(&vcc->stats->tx_err);
32135+ atomic_inc_unchecked(&vcc->stats->tx_err);
32136
32137 fore200e->tx_sat++;
32138 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32139diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32140index 72b6960..cf9167a 100644
32141--- a/drivers/atm/he.c
32142+++ b/drivers/atm/he.c
32143@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32144
32145 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32146 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32147- atomic_inc(&vcc->stats->rx_drop);
32148+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32149 goto return_host_buffers;
32150 }
32151
32152@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32153 RBRQ_LEN_ERR(he_dev->rbrq_head)
32154 ? "LEN_ERR" : "",
32155 vcc->vpi, vcc->vci);
32156- atomic_inc(&vcc->stats->rx_err);
32157+ atomic_inc_unchecked(&vcc->stats->rx_err);
32158 goto return_host_buffers;
32159 }
32160
32161@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32162 vcc->push(vcc, skb);
32163 spin_lock(&he_dev->global_lock);
32164
32165- atomic_inc(&vcc->stats->rx);
32166+ atomic_inc_unchecked(&vcc->stats->rx);
32167
32168 return_host_buffers:
32169 ++pdus_assembled;
32170@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32171 tpd->vcc->pop(tpd->vcc, tpd->skb);
32172 else
32173 dev_kfree_skb_any(tpd->skb);
32174- atomic_inc(&tpd->vcc->stats->tx_err);
32175+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32176 }
32177 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32178 return;
32179@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32180 vcc->pop(vcc, skb);
32181 else
32182 dev_kfree_skb_any(skb);
32183- atomic_inc(&vcc->stats->tx_err);
32184+ atomic_inc_unchecked(&vcc->stats->tx_err);
32185 return -EINVAL;
32186 }
32187
32188@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32189 vcc->pop(vcc, skb);
32190 else
32191 dev_kfree_skb_any(skb);
32192- atomic_inc(&vcc->stats->tx_err);
32193+ atomic_inc_unchecked(&vcc->stats->tx_err);
32194 return -EINVAL;
32195 }
32196 #endif
32197@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32198 vcc->pop(vcc, skb);
32199 else
32200 dev_kfree_skb_any(skb);
32201- atomic_inc(&vcc->stats->tx_err);
32202+ atomic_inc_unchecked(&vcc->stats->tx_err);
32203 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32204 return -ENOMEM;
32205 }
32206@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32207 vcc->pop(vcc, skb);
32208 else
32209 dev_kfree_skb_any(skb);
32210- atomic_inc(&vcc->stats->tx_err);
32211+ atomic_inc_unchecked(&vcc->stats->tx_err);
32212 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32213 return -ENOMEM;
32214 }
32215@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32216 __enqueue_tpd(he_dev, tpd, cid);
32217 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32218
32219- atomic_inc(&vcc->stats->tx);
32220+ atomic_inc_unchecked(&vcc->stats->tx);
32221
32222 return 0;
32223 }
32224diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32225index 1dc0519..1aadaf7 100644
32226--- a/drivers/atm/horizon.c
32227+++ b/drivers/atm/horizon.c
32228@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32229 {
32230 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32231 // VC layer stats
32232- atomic_inc(&vcc->stats->rx);
32233+ atomic_inc_unchecked(&vcc->stats->rx);
32234 __net_timestamp(skb);
32235 // end of our responsibility
32236 vcc->push (vcc, skb);
32237@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32238 dev->tx_iovec = NULL;
32239
32240 // VC layer stats
32241- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32242+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32243
32244 // free the skb
32245 hrz_kfree_skb (skb);
32246diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32247index 272f009..a18ba55 100644
32248--- a/drivers/atm/idt77252.c
32249+++ b/drivers/atm/idt77252.c
32250@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32251 else
32252 dev_kfree_skb(skb);
32253
32254- atomic_inc(&vcc->stats->tx);
32255+ atomic_inc_unchecked(&vcc->stats->tx);
32256 }
32257
32258 atomic_dec(&scq->used);
32259@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32260 if ((sb = dev_alloc_skb(64)) == NULL) {
32261 printk("%s: Can't allocate buffers for aal0.\n",
32262 card->name);
32263- atomic_add(i, &vcc->stats->rx_drop);
32264+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32265 break;
32266 }
32267 if (!atm_charge(vcc, sb->truesize)) {
32268 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32269 card->name);
32270- atomic_add(i - 1, &vcc->stats->rx_drop);
32271+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32272 dev_kfree_skb(sb);
32273 break;
32274 }
32275@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32276 ATM_SKB(sb)->vcc = vcc;
32277 __net_timestamp(sb);
32278 vcc->push(vcc, sb);
32279- atomic_inc(&vcc->stats->rx);
32280+ atomic_inc_unchecked(&vcc->stats->rx);
32281
32282 cell += ATM_CELL_PAYLOAD;
32283 }
32284@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32285 "(CDC: %08x)\n",
32286 card->name, len, rpp->len, readl(SAR_REG_CDC));
32287 recycle_rx_pool_skb(card, rpp);
32288- atomic_inc(&vcc->stats->rx_err);
32289+ atomic_inc_unchecked(&vcc->stats->rx_err);
32290 return;
32291 }
32292 if (stat & SAR_RSQE_CRC) {
32293 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32294 recycle_rx_pool_skb(card, rpp);
32295- atomic_inc(&vcc->stats->rx_err);
32296+ atomic_inc_unchecked(&vcc->stats->rx_err);
32297 return;
32298 }
32299 if (skb_queue_len(&rpp->queue) > 1) {
32300@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32301 RXPRINTK("%s: Can't alloc RX skb.\n",
32302 card->name);
32303 recycle_rx_pool_skb(card, rpp);
32304- atomic_inc(&vcc->stats->rx_err);
32305+ atomic_inc_unchecked(&vcc->stats->rx_err);
32306 return;
32307 }
32308 if (!atm_charge(vcc, skb->truesize)) {
32309@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32310 __net_timestamp(skb);
32311
32312 vcc->push(vcc, skb);
32313- atomic_inc(&vcc->stats->rx);
32314+ atomic_inc_unchecked(&vcc->stats->rx);
32315
32316 return;
32317 }
32318@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32319 __net_timestamp(skb);
32320
32321 vcc->push(vcc, skb);
32322- atomic_inc(&vcc->stats->rx);
32323+ atomic_inc_unchecked(&vcc->stats->rx);
32324
32325 if (skb->truesize > SAR_FB_SIZE_3)
32326 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32327@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32328 if (vcc->qos.aal != ATM_AAL0) {
32329 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32330 card->name, vpi, vci);
32331- atomic_inc(&vcc->stats->rx_drop);
32332+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32333 goto drop;
32334 }
32335
32336 if ((sb = dev_alloc_skb(64)) == NULL) {
32337 printk("%s: Can't allocate buffers for AAL0.\n",
32338 card->name);
32339- atomic_inc(&vcc->stats->rx_err);
32340+ atomic_inc_unchecked(&vcc->stats->rx_err);
32341 goto drop;
32342 }
32343
32344@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32345 ATM_SKB(sb)->vcc = vcc;
32346 __net_timestamp(sb);
32347 vcc->push(vcc, sb);
32348- atomic_inc(&vcc->stats->rx);
32349+ atomic_inc_unchecked(&vcc->stats->rx);
32350
32351 drop:
32352 skb_pull(queue, 64);
32353@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32354
32355 if (vc == NULL) {
32356 printk("%s: NULL connection in send().\n", card->name);
32357- atomic_inc(&vcc->stats->tx_err);
32358+ atomic_inc_unchecked(&vcc->stats->tx_err);
32359 dev_kfree_skb(skb);
32360 return -EINVAL;
32361 }
32362 if (!test_bit(VCF_TX, &vc->flags)) {
32363 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32364- atomic_inc(&vcc->stats->tx_err);
32365+ atomic_inc_unchecked(&vcc->stats->tx_err);
32366 dev_kfree_skb(skb);
32367 return -EINVAL;
32368 }
32369@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32370 break;
32371 default:
32372 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32373- atomic_inc(&vcc->stats->tx_err);
32374+ atomic_inc_unchecked(&vcc->stats->tx_err);
32375 dev_kfree_skb(skb);
32376 return -EINVAL;
32377 }
32378
32379 if (skb_shinfo(skb)->nr_frags != 0) {
32380 printk("%s: No scatter-gather yet.\n", card->name);
32381- atomic_inc(&vcc->stats->tx_err);
32382+ atomic_inc_unchecked(&vcc->stats->tx_err);
32383 dev_kfree_skb(skb);
32384 return -EINVAL;
32385 }
32386@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32387
32388 err = queue_skb(card, vc, skb, oam);
32389 if (err) {
32390- atomic_inc(&vcc->stats->tx_err);
32391+ atomic_inc_unchecked(&vcc->stats->tx_err);
32392 dev_kfree_skb(skb);
32393 return err;
32394 }
32395@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32396 skb = dev_alloc_skb(64);
32397 if (!skb) {
32398 printk("%s: Out of memory in send_oam().\n", card->name);
32399- atomic_inc(&vcc->stats->tx_err);
32400+ atomic_inc_unchecked(&vcc->stats->tx_err);
32401 return -ENOMEM;
32402 }
32403 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32404diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32405index 4217f29..88f547a 100644
32406--- a/drivers/atm/iphase.c
32407+++ b/drivers/atm/iphase.c
32408@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32409 status = (u_short) (buf_desc_ptr->desc_mode);
32410 if (status & (RX_CER | RX_PTE | RX_OFL))
32411 {
32412- atomic_inc(&vcc->stats->rx_err);
32413+ atomic_inc_unchecked(&vcc->stats->rx_err);
32414 IF_ERR(printk("IA: bad packet, dropping it");)
32415 if (status & RX_CER) {
32416 IF_ERR(printk(" cause: packet CRC error\n");)
32417@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32418 len = dma_addr - buf_addr;
32419 if (len > iadev->rx_buf_sz) {
32420 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32421- atomic_inc(&vcc->stats->rx_err);
32422+ atomic_inc_unchecked(&vcc->stats->rx_err);
32423 goto out_free_desc;
32424 }
32425
32426@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32427 ia_vcc = INPH_IA_VCC(vcc);
32428 if (ia_vcc == NULL)
32429 {
32430- atomic_inc(&vcc->stats->rx_err);
32431+ atomic_inc_unchecked(&vcc->stats->rx_err);
32432 atm_return(vcc, skb->truesize);
32433 dev_kfree_skb_any(skb);
32434 goto INCR_DLE;
32435@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32436 if ((length > iadev->rx_buf_sz) || (length >
32437 (skb->len - sizeof(struct cpcs_trailer))))
32438 {
32439- atomic_inc(&vcc->stats->rx_err);
32440+ atomic_inc_unchecked(&vcc->stats->rx_err);
32441 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32442 length, skb->len);)
32443 atm_return(vcc, skb->truesize);
32444@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32445
32446 IF_RX(printk("rx_dle_intr: skb push");)
32447 vcc->push(vcc,skb);
32448- atomic_inc(&vcc->stats->rx);
32449+ atomic_inc_unchecked(&vcc->stats->rx);
32450 iadev->rx_pkt_cnt++;
32451 }
32452 INCR_DLE:
32453@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32454 {
32455 struct k_sonet_stats *stats;
32456 stats = &PRIV(_ia_dev[board])->sonet_stats;
32457- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32458- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32459- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32460- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32461- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32462- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32463- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32464- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32465- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32466+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32467+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32468+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32469+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32470+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32471+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32472+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32473+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32474+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32475 }
32476 ia_cmds.status = 0;
32477 break;
32478@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32479 if ((desc == 0) || (desc > iadev->num_tx_desc))
32480 {
32481 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32482- atomic_inc(&vcc->stats->tx);
32483+ atomic_inc_unchecked(&vcc->stats->tx);
32484 if (vcc->pop)
32485 vcc->pop(vcc, skb);
32486 else
32487@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32488 ATM_DESC(skb) = vcc->vci;
32489 skb_queue_tail(&iadev->tx_dma_q, skb);
32490
32491- atomic_inc(&vcc->stats->tx);
32492+ atomic_inc_unchecked(&vcc->stats->tx);
32493 iadev->tx_pkt_cnt++;
32494 /* Increment transaction counter */
32495 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32496
32497 #if 0
32498 /* add flow control logic */
32499- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32500+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32501 if (iavcc->vc_desc_cnt > 10) {
32502 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32503 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32504diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32505index fa7d701..1e404c7 100644
32506--- a/drivers/atm/lanai.c
32507+++ b/drivers/atm/lanai.c
32508@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32509 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32510 lanai_endtx(lanai, lvcc);
32511 lanai_free_skb(lvcc->tx.atmvcc, skb);
32512- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32513+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32514 }
32515
32516 /* Try to fill the buffer - don't call unless there is backlog */
32517@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32518 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32519 __net_timestamp(skb);
32520 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32521- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32522+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32523 out:
32524 lvcc->rx.buf.ptr = end;
32525 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32526@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32527 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32528 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32529 lanai->stats.service_rxnotaal5++;
32530- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32531+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32532 return 0;
32533 }
32534 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32535@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32536 int bytes;
32537 read_unlock(&vcc_sklist_lock);
32538 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32539- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32540+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32541 lvcc->stats.x.aal5.service_trash++;
32542 bytes = (SERVICE_GET_END(s) * 16) -
32543 (((unsigned long) lvcc->rx.buf.ptr) -
32544@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32545 }
32546 if (s & SERVICE_STREAM) {
32547 read_unlock(&vcc_sklist_lock);
32548- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32549+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32550 lvcc->stats.x.aal5.service_stream++;
32551 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32552 "PDU on VCI %d!\n", lanai->number, vci);
32553@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32554 return 0;
32555 }
32556 DPRINTK("got rx crc error on vci %d\n", vci);
32557- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32558+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32559 lvcc->stats.x.aal5.service_rxcrc++;
32560 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32561 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32562diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32563index ed1d2b7..8cffc1f 100644
32564--- a/drivers/atm/nicstar.c
32565+++ b/drivers/atm/nicstar.c
32566@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32567 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32568 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32569 card->index);
32570- atomic_inc(&vcc->stats->tx_err);
32571+ atomic_inc_unchecked(&vcc->stats->tx_err);
32572 dev_kfree_skb_any(skb);
32573 return -EINVAL;
32574 }
32575@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32576 if (!vc->tx) {
32577 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32578 card->index);
32579- atomic_inc(&vcc->stats->tx_err);
32580+ atomic_inc_unchecked(&vcc->stats->tx_err);
32581 dev_kfree_skb_any(skb);
32582 return -EINVAL;
32583 }
32584@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32585 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32586 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32587 card->index);
32588- atomic_inc(&vcc->stats->tx_err);
32589+ atomic_inc_unchecked(&vcc->stats->tx_err);
32590 dev_kfree_skb_any(skb);
32591 return -EINVAL;
32592 }
32593
32594 if (skb_shinfo(skb)->nr_frags != 0) {
32595 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32596- atomic_inc(&vcc->stats->tx_err);
32597+ atomic_inc_unchecked(&vcc->stats->tx_err);
32598 dev_kfree_skb_any(skb);
32599 return -EINVAL;
32600 }
32601@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32602 }
32603
32604 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32605- atomic_inc(&vcc->stats->tx_err);
32606+ atomic_inc_unchecked(&vcc->stats->tx_err);
32607 dev_kfree_skb_any(skb);
32608 return -EIO;
32609 }
32610- atomic_inc(&vcc->stats->tx);
32611+ atomic_inc_unchecked(&vcc->stats->tx);
32612
32613 return 0;
32614 }
32615@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32616 printk
32617 ("nicstar%d: Can't allocate buffers for aal0.\n",
32618 card->index);
32619- atomic_add(i, &vcc->stats->rx_drop);
32620+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32621 break;
32622 }
32623 if (!atm_charge(vcc, sb->truesize)) {
32624 RXPRINTK
32625 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32626 card->index);
32627- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32628+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32629 dev_kfree_skb_any(sb);
32630 break;
32631 }
32632@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32633 ATM_SKB(sb)->vcc = vcc;
32634 __net_timestamp(sb);
32635 vcc->push(vcc, sb);
32636- atomic_inc(&vcc->stats->rx);
32637+ atomic_inc_unchecked(&vcc->stats->rx);
32638 cell += ATM_CELL_PAYLOAD;
32639 }
32640
32641@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32642 if (iovb == NULL) {
32643 printk("nicstar%d: Out of iovec buffers.\n",
32644 card->index);
32645- atomic_inc(&vcc->stats->rx_drop);
32646+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32647 recycle_rx_buf(card, skb);
32648 return;
32649 }
32650@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32651 small or large buffer itself. */
32652 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32653 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32654- atomic_inc(&vcc->stats->rx_err);
32655+ atomic_inc_unchecked(&vcc->stats->rx_err);
32656 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32657 NS_MAX_IOVECS);
32658 NS_PRV_IOVCNT(iovb) = 0;
32659@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32660 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32661 card->index);
32662 which_list(card, skb);
32663- atomic_inc(&vcc->stats->rx_err);
32664+ atomic_inc_unchecked(&vcc->stats->rx_err);
32665 recycle_rx_buf(card, skb);
32666 vc->rx_iov = NULL;
32667 recycle_iov_buf(card, iovb);
32668@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32669 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32670 card->index);
32671 which_list(card, skb);
32672- atomic_inc(&vcc->stats->rx_err);
32673+ atomic_inc_unchecked(&vcc->stats->rx_err);
32674 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32675 NS_PRV_IOVCNT(iovb));
32676 vc->rx_iov = NULL;
32677@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32678 printk(" - PDU size mismatch.\n");
32679 else
32680 printk(".\n");
32681- atomic_inc(&vcc->stats->rx_err);
32682+ atomic_inc_unchecked(&vcc->stats->rx_err);
32683 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32684 NS_PRV_IOVCNT(iovb));
32685 vc->rx_iov = NULL;
32686@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32687 /* skb points to a small buffer */
32688 if (!atm_charge(vcc, skb->truesize)) {
32689 push_rxbufs(card, skb);
32690- atomic_inc(&vcc->stats->rx_drop);
32691+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32692 } else {
32693 skb_put(skb, len);
32694 dequeue_sm_buf(card, skb);
32695@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32696 ATM_SKB(skb)->vcc = vcc;
32697 __net_timestamp(skb);
32698 vcc->push(vcc, skb);
32699- atomic_inc(&vcc->stats->rx);
32700+ atomic_inc_unchecked(&vcc->stats->rx);
32701 }
32702 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32703 struct sk_buff *sb;
32704@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32705 if (len <= NS_SMBUFSIZE) {
32706 if (!atm_charge(vcc, sb->truesize)) {
32707 push_rxbufs(card, sb);
32708- atomic_inc(&vcc->stats->rx_drop);
32709+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32710 } else {
32711 skb_put(sb, len);
32712 dequeue_sm_buf(card, sb);
32713@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32714 ATM_SKB(sb)->vcc = vcc;
32715 __net_timestamp(sb);
32716 vcc->push(vcc, sb);
32717- atomic_inc(&vcc->stats->rx);
32718+ atomic_inc_unchecked(&vcc->stats->rx);
32719 }
32720
32721 push_rxbufs(card, skb);
32722@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32723
32724 if (!atm_charge(vcc, skb->truesize)) {
32725 push_rxbufs(card, skb);
32726- atomic_inc(&vcc->stats->rx_drop);
32727+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32728 } else {
32729 dequeue_lg_buf(card, skb);
32730 #ifdef NS_USE_DESTRUCTORS
32731@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32732 ATM_SKB(skb)->vcc = vcc;
32733 __net_timestamp(skb);
32734 vcc->push(vcc, skb);
32735- atomic_inc(&vcc->stats->rx);
32736+ atomic_inc_unchecked(&vcc->stats->rx);
32737 }
32738
32739 push_rxbufs(card, sb);
32740@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32741 printk
32742 ("nicstar%d: Out of huge buffers.\n",
32743 card->index);
32744- atomic_inc(&vcc->stats->rx_drop);
32745+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32746 recycle_iovec_rx_bufs(card,
32747 (struct iovec *)
32748 iovb->data,
32749@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32750 card->hbpool.count++;
32751 } else
32752 dev_kfree_skb_any(hb);
32753- atomic_inc(&vcc->stats->rx_drop);
32754+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32755 } else {
32756 /* Copy the small buffer to the huge buffer */
32757 sb = (struct sk_buff *)iov->iov_base;
32758@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32759 #endif /* NS_USE_DESTRUCTORS */
32760 __net_timestamp(hb);
32761 vcc->push(vcc, hb);
32762- atomic_inc(&vcc->stats->rx);
32763+ atomic_inc_unchecked(&vcc->stats->rx);
32764 }
32765 }
32766
32767diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32768index 0474a89..06ea4a1 100644
32769--- a/drivers/atm/solos-pci.c
32770+++ b/drivers/atm/solos-pci.c
32771@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32772 }
32773 atm_charge(vcc, skb->truesize);
32774 vcc->push(vcc, skb);
32775- atomic_inc(&vcc->stats->rx);
32776+ atomic_inc_unchecked(&vcc->stats->rx);
32777 break;
32778
32779 case PKT_STATUS:
32780@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32781 vcc = SKB_CB(oldskb)->vcc;
32782
32783 if (vcc) {
32784- atomic_inc(&vcc->stats->tx);
32785+ atomic_inc_unchecked(&vcc->stats->tx);
32786 solos_pop(vcc, oldskb);
32787 } else {
32788 dev_kfree_skb_irq(oldskb);
32789diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32790index 0215934..ce9f5b1 100644
32791--- a/drivers/atm/suni.c
32792+++ b/drivers/atm/suni.c
32793@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32794
32795
32796 #define ADD_LIMITED(s,v) \
32797- atomic_add((v),&stats->s); \
32798- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32799+ atomic_add_unchecked((v),&stats->s); \
32800+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32801
32802
32803 static void suni_hz(unsigned long from_timer)
32804diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32805index 5120a96..e2572bd 100644
32806--- a/drivers/atm/uPD98402.c
32807+++ b/drivers/atm/uPD98402.c
32808@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32809 struct sonet_stats tmp;
32810 int error = 0;
32811
32812- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32813+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32814 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32815 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32816 if (zero && !error) {
32817@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32818
32819
32820 #define ADD_LIMITED(s,v) \
32821- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32822- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32823- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32824+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32825+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32826+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32827
32828
32829 static void stat_event(struct atm_dev *dev)
32830@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32831 if (reason & uPD98402_INT_PFM) stat_event(dev);
32832 if (reason & uPD98402_INT_PCO) {
32833 (void) GET(PCOCR); /* clear interrupt cause */
32834- atomic_add(GET(HECCT),
32835+ atomic_add_unchecked(GET(HECCT),
32836 &PRIV(dev)->sonet_stats.uncorr_hcs);
32837 }
32838 if ((reason & uPD98402_INT_RFO) &&
32839@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32840 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32841 uPD98402_INT_LOS),PIMR); /* enable them */
32842 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32843- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32844- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32845- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32846+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32847+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32848+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32849 return 0;
32850 }
32851
32852diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32853index 969c3c2..9b72956 100644
32854--- a/drivers/atm/zatm.c
32855+++ b/drivers/atm/zatm.c
32856@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32857 }
32858 if (!size) {
32859 dev_kfree_skb_irq(skb);
32860- if (vcc) atomic_inc(&vcc->stats->rx_err);
32861+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32862 continue;
32863 }
32864 if (!atm_charge(vcc,skb->truesize)) {
32865@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32866 skb->len = size;
32867 ATM_SKB(skb)->vcc = vcc;
32868 vcc->push(vcc,skb);
32869- atomic_inc(&vcc->stats->rx);
32870+ atomic_inc_unchecked(&vcc->stats->rx);
32871 }
32872 zout(pos & 0xffff,MTA(mbx));
32873 #if 0 /* probably a stupid idea */
32874@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32875 skb_queue_head(&zatm_vcc->backlog,skb);
32876 break;
32877 }
32878- atomic_inc(&vcc->stats->tx);
32879+ atomic_inc_unchecked(&vcc->stats->tx);
32880 wake_up(&zatm_vcc->tx_wait);
32881 }
32882
32883diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32884index 6856303..0602d70 100644
32885--- a/drivers/base/bus.c
32886+++ b/drivers/base/bus.c
32887@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32888 return -EINVAL;
32889
32890 mutex_lock(&subsys->p->mutex);
32891- list_add_tail(&sif->node, &subsys->p->interfaces);
32892+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32893 if (sif->add_dev) {
32894 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32895 while ((dev = subsys_dev_iter_next(&iter)))
32896@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32897 subsys = sif->subsys;
32898
32899 mutex_lock(&subsys->p->mutex);
32900- list_del_init(&sif->node);
32901+ pax_list_del_init((struct list_head *)&sif->node);
32902 if (sif->remove_dev) {
32903 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32904 while ((dev = subsys_dev_iter_next(&iter)))
32905diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32906index 17cf7ca..7e553e1 100644
32907--- a/drivers/base/devtmpfs.c
32908+++ b/drivers/base/devtmpfs.c
32909@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32910 if (!thread)
32911 return 0;
32912
32913- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32914+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32915 if (err)
32916 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32917 else
32918diff --git a/drivers/base/node.c b/drivers/base/node.c
32919index fac124a..66bd4ab 100644
32920--- a/drivers/base/node.c
32921+++ b/drivers/base/node.c
32922@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
32923 struct node_attr {
32924 struct device_attribute attr;
32925 enum node_states state;
32926-};
32927+} __do_const;
32928
32929 static ssize_t show_node_state(struct device *dev,
32930 struct device_attribute *attr, char *buf)
32931diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
32932index acc3a8d..981c236 100644
32933--- a/drivers/base/power/domain.c
32934+++ b/drivers/base/power/domain.c
32935@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
32936 {
32937 struct cpuidle_driver *cpuidle_drv;
32938 struct gpd_cpu_data *cpu_data;
32939- struct cpuidle_state *idle_state;
32940+ cpuidle_state_no_const *idle_state;
32941 int ret = 0;
32942
32943 if (IS_ERR_OR_NULL(genpd) || state < 0)
32944@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
32945 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
32946 {
32947 struct gpd_cpu_data *cpu_data;
32948- struct cpuidle_state *idle_state;
32949+ cpuidle_state_no_const *idle_state;
32950 int ret = 0;
32951
32952 if (IS_ERR_OR_NULL(genpd))
32953diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32954index e6ee5e8..98ad7fc 100644
32955--- a/drivers/base/power/wakeup.c
32956+++ b/drivers/base/power/wakeup.c
32957@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32958 * They need to be modified together atomically, so it's better to use one
32959 * atomic variable to hold them both.
32960 */
32961-static atomic_t combined_event_count = ATOMIC_INIT(0);
32962+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32963
32964 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32965 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32966
32967 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32968 {
32969- unsigned int comb = atomic_read(&combined_event_count);
32970+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
32971
32972 *cnt = (comb >> IN_PROGRESS_BITS);
32973 *inpr = comb & MAX_IN_PROGRESS;
32974@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32975 ws->start_prevent_time = ws->last_time;
32976
32977 /* Increment the counter of events in progress. */
32978- cec = atomic_inc_return(&combined_event_count);
32979+ cec = atomic_inc_return_unchecked(&combined_event_count);
32980
32981 trace_wakeup_source_activate(ws->name, cec);
32982 }
32983@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32984 * Increment the counter of registered wakeup events and decrement the
32985 * couter of wakeup events in progress simultaneously.
32986 */
32987- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32988+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32989 trace_wakeup_source_deactivate(ws->name, cec);
32990
32991 split_counters(&cnt, &inpr);
32992diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
32993index e8d11b6..7b1b36f 100644
32994--- a/drivers/base/syscore.c
32995+++ b/drivers/base/syscore.c
32996@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
32997 void register_syscore_ops(struct syscore_ops *ops)
32998 {
32999 mutex_lock(&syscore_ops_lock);
33000- list_add_tail(&ops->node, &syscore_ops_list);
33001+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33002 mutex_unlock(&syscore_ops_lock);
33003 }
33004 EXPORT_SYMBOL_GPL(register_syscore_ops);
33005@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33006 void unregister_syscore_ops(struct syscore_ops *ops)
33007 {
33008 mutex_lock(&syscore_ops_lock);
33009- list_del(&ops->node);
33010+ pax_list_del((struct list_head *)&ops->node);
33011 mutex_unlock(&syscore_ops_lock);
33012 }
33013 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33014diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33015index ade58bc..867143d 100644
33016--- a/drivers/block/cciss.c
33017+++ b/drivers/block/cciss.c
33018@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33019 int err;
33020 u32 cp;
33021
33022+ memset(&arg64, 0, sizeof(arg64));
33023+
33024 err = 0;
33025 err |=
33026 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33027@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33028 while (!list_empty(&h->reqQ)) {
33029 c = list_entry(h->reqQ.next, CommandList_struct, list);
33030 /* can't do anything if fifo is full */
33031- if ((h->access.fifo_full(h))) {
33032+ if ((h->access->fifo_full(h))) {
33033 dev_warn(&h->pdev->dev, "fifo full\n");
33034 break;
33035 }
33036@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33037 h->Qdepth--;
33038
33039 /* Tell the controller execute command */
33040- h->access.submit_command(h, c);
33041+ h->access->submit_command(h, c);
33042
33043 /* Put job onto the completed Q */
33044 addQ(&h->cmpQ, c);
33045@@ -3441,17 +3443,17 @@ startio:
33046
33047 static inline unsigned long get_next_completion(ctlr_info_t *h)
33048 {
33049- return h->access.command_completed(h);
33050+ return h->access->command_completed(h);
33051 }
33052
33053 static inline int interrupt_pending(ctlr_info_t *h)
33054 {
33055- return h->access.intr_pending(h);
33056+ return h->access->intr_pending(h);
33057 }
33058
33059 static inline long interrupt_not_for_us(ctlr_info_t *h)
33060 {
33061- return ((h->access.intr_pending(h) == 0) ||
33062+ return ((h->access->intr_pending(h) == 0) ||
33063 (h->interrupts_enabled == 0));
33064 }
33065
33066@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33067 u32 a;
33068
33069 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33070- return h->access.command_completed(h);
33071+ return h->access->command_completed(h);
33072
33073 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33074 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33075@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33076 trans_support & CFGTBL_Trans_use_short_tags);
33077
33078 /* Change the access methods to the performant access methods */
33079- h->access = SA5_performant_access;
33080+ h->access = &SA5_performant_access;
33081 h->transMethod = CFGTBL_Trans_Performant;
33082
33083 return;
33084@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33085 if (prod_index < 0)
33086 return -ENODEV;
33087 h->product_name = products[prod_index].product_name;
33088- h->access = *(products[prod_index].access);
33089+ h->access = products[prod_index].access;
33090
33091 if (cciss_board_disabled(h)) {
33092 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33093@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33094 }
33095
33096 /* make sure the board interrupts are off */
33097- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33098+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33099 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33100 if (rc)
33101 goto clean2;
33102@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33103 * fake ones to scoop up any residual completions.
33104 */
33105 spin_lock_irqsave(&h->lock, flags);
33106- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33107+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33108 spin_unlock_irqrestore(&h->lock, flags);
33109 free_irq(h->intr[h->intr_mode], h);
33110 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33111@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33112 dev_info(&h->pdev->dev, "Board READY.\n");
33113 dev_info(&h->pdev->dev,
33114 "Waiting for stale completions to drain.\n");
33115- h->access.set_intr_mask(h, CCISS_INTR_ON);
33116+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33117 msleep(10000);
33118- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33119+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33120
33121 rc = controller_reset_failed(h->cfgtable);
33122 if (rc)
33123@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33124 cciss_scsi_setup(h);
33125
33126 /* Turn the interrupts on so we can service requests */
33127- h->access.set_intr_mask(h, CCISS_INTR_ON);
33128+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33129
33130 /* Get the firmware version */
33131 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33132@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33133 kfree(flush_buf);
33134 if (return_code != IO_OK)
33135 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33136- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33137+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33138 free_irq(h->intr[h->intr_mode], h);
33139 }
33140
33141diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33142index 7fda30e..eb5dfe0 100644
33143--- a/drivers/block/cciss.h
33144+++ b/drivers/block/cciss.h
33145@@ -101,7 +101,7 @@ struct ctlr_info
33146 /* information about each logical volume */
33147 drive_info_struct *drv[CISS_MAX_LUN];
33148
33149- struct access_method access;
33150+ struct access_method *access;
33151
33152 /* queue and queue Info */
33153 struct list_head reqQ;
33154diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33155index 3f08713..56a586a 100644
33156--- a/drivers/block/cpqarray.c
33157+++ b/drivers/block/cpqarray.c
33158@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33159 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33160 goto Enomem4;
33161 }
33162- hba[i]->access.set_intr_mask(hba[i], 0);
33163+ hba[i]->access->set_intr_mask(hba[i], 0);
33164 if (request_irq(hba[i]->intr, do_ida_intr,
33165 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33166 {
33167@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33168 add_timer(&hba[i]->timer);
33169
33170 /* Enable IRQ now that spinlock and rate limit timer are set up */
33171- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33172+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33173
33174 for(j=0; j<NWD; j++) {
33175 struct gendisk *disk = ida_gendisk[i][j];
33176@@ -694,7 +694,7 @@ DBGINFO(
33177 for(i=0; i<NR_PRODUCTS; i++) {
33178 if (board_id == products[i].board_id) {
33179 c->product_name = products[i].product_name;
33180- c->access = *(products[i].access);
33181+ c->access = products[i].access;
33182 break;
33183 }
33184 }
33185@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33186 hba[ctlr]->intr = intr;
33187 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33188 hba[ctlr]->product_name = products[j].product_name;
33189- hba[ctlr]->access = *(products[j].access);
33190+ hba[ctlr]->access = products[j].access;
33191 hba[ctlr]->ctlr = ctlr;
33192 hba[ctlr]->board_id = board_id;
33193 hba[ctlr]->pci_dev = NULL; /* not PCI */
33194@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33195
33196 while((c = h->reqQ) != NULL) {
33197 /* Can't do anything if we're busy */
33198- if (h->access.fifo_full(h) == 0)
33199+ if (h->access->fifo_full(h) == 0)
33200 return;
33201
33202 /* Get the first entry from the request Q */
33203@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33204 h->Qdepth--;
33205
33206 /* Tell the controller to do our bidding */
33207- h->access.submit_command(h, c);
33208+ h->access->submit_command(h, c);
33209
33210 /* Get onto the completion Q */
33211 addQ(&h->cmpQ, c);
33212@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33213 unsigned long flags;
33214 __u32 a,a1;
33215
33216- istat = h->access.intr_pending(h);
33217+ istat = h->access->intr_pending(h);
33218 /* Is this interrupt for us? */
33219 if (istat == 0)
33220 return IRQ_NONE;
33221@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33222 */
33223 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33224 if (istat & FIFO_NOT_EMPTY) {
33225- while((a = h->access.command_completed(h))) {
33226+ while((a = h->access->command_completed(h))) {
33227 a1 = a; a &= ~3;
33228 if ((c = h->cmpQ) == NULL)
33229 {
33230@@ -1449,11 +1449,11 @@ static int sendcmd(
33231 /*
33232 * Disable interrupt
33233 */
33234- info_p->access.set_intr_mask(info_p, 0);
33235+ info_p->access->set_intr_mask(info_p, 0);
33236 /* Make sure there is room in the command FIFO */
33237 /* Actually it should be completely empty at this time. */
33238 for (i = 200000; i > 0; i--) {
33239- temp = info_p->access.fifo_full(info_p);
33240+ temp = info_p->access->fifo_full(info_p);
33241 if (temp != 0) {
33242 break;
33243 }
33244@@ -1466,7 +1466,7 @@ DBG(
33245 /*
33246 * Send the cmd
33247 */
33248- info_p->access.submit_command(info_p, c);
33249+ info_p->access->submit_command(info_p, c);
33250 complete = pollcomplete(ctlr);
33251
33252 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33253@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33254 * we check the new geometry. Then turn interrupts back on when
33255 * we're done.
33256 */
33257- host->access.set_intr_mask(host, 0);
33258+ host->access->set_intr_mask(host, 0);
33259 getgeometry(ctlr);
33260- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33261+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33262
33263 for(i=0; i<NWD; i++) {
33264 struct gendisk *disk = ida_gendisk[ctlr][i];
33265@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
33266 /* Wait (up to 2 seconds) for a command to complete */
33267
33268 for (i = 200000; i > 0; i--) {
33269- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33270+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33271 if (done == 0) {
33272 udelay(10); /* a short fixed delay */
33273 } else
33274diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33275index be73e9d..7fbf140 100644
33276--- a/drivers/block/cpqarray.h
33277+++ b/drivers/block/cpqarray.h
33278@@ -99,7 +99,7 @@ struct ctlr_info {
33279 drv_info_t drv[NWD];
33280 struct proc_dir_entry *proc;
33281
33282- struct access_method access;
33283+ struct access_method *access;
33284
33285 cmdlist_t *reqQ;
33286 cmdlist_t *cmpQ;
33287diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33288index 6b51afa..17e1191 100644
33289--- a/drivers/block/drbd/drbd_int.h
33290+++ b/drivers/block/drbd/drbd_int.h
33291@@ -582,7 +582,7 @@ struct drbd_epoch {
33292 struct drbd_tconn *tconn;
33293 struct list_head list;
33294 unsigned int barrier_nr;
33295- atomic_t epoch_size; /* increased on every request added. */
33296+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33297 atomic_t active; /* increased on every req. added, and dec on every finished. */
33298 unsigned long flags;
33299 };
33300@@ -1011,7 +1011,7 @@ struct drbd_conf {
33301 int al_tr_cycle;
33302 int al_tr_pos; /* position of the next transaction in the journal */
33303 wait_queue_head_t seq_wait;
33304- atomic_t packet_seq;
33305+ atomic_unchecked_t packet_seq;
33306 unsigned int peer_seq;
33307 spinlock_t peer_seq_lock;
33308 unsigned int minor;
33309@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33310 char __user *uoptval;
33311 int err;
33312
33313- uoptval = (char __user __force *)optval;
33314+ uoptval = (char __force_user *)optval;
33315
33316 set_fs(KERNEL_DS);
33317 if (level == SOL_SOCKET)
33318diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33319index 8c13eeb..217adee 100644
33320--- a/drivers/block/drbd/drbd_main.c
33321+++ b/drivers/block/drbd/drbd_main.c
33322@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33323 p->sector = sector;
33324 p->block_id = block_id;
33325 p->blksize = blksize;
33326- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33327+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33328 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33329 }
33330
33331@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33332 return -EIO;
33333 p->sector = cpu_to_be64(req->i.sector);
33334 p->block_id = (unsigned long)req;
33335- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33336+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33337 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33338 if (mdev->state.conn >= C_SYNC_SOURCE &&
33339 mdev->state.conn <= C_PAUSED_SYNC_T)
33340@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33341 {
33342 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33343
33344- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33345- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33346+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33347+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33348 kfree(tconn->current_epoch);
33349
33350 idr_destroy(&tconn->volumes);
33351diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33352index a9eccfc..f5efe87 100644
33353--- a/drivers/block/drbd/drbd_receiver.c
33354+++ b/drivers/block/drbd/drbd_receiver.c
33355@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33356 {
33357 int err;
33358
33359- atomic_set(&mdev->packet_seq, 0);
33360+ atomic_set_unchecked(&mdev->packet_seq, 0);
33361 mdev->peer_seq = 0;
33362
33363 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33364@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33365 do {
33366 next_epoch = NULL;
33367
33368- epoch_size = atomic_read(&epoch->epoch_size);
33369+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33370
33371 switch (ev & ~EV_CLEANUP) {
33372 case EV_PUT:
33373@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33374 rv = FE_DESTROYED;
33375 } else {
33376 epoch->flags = 0;
33377- atomic_set(&epoch->epoch_size, 0);
33378+ atomic_set_unchecked(&epoch->epoch_size, 0);
33379 /* atomic_set(&epoch->active, 0); is already zero */
33380 if (rv == FE_STILL_LIVE)
33381 rv = FE_RECYCLED;
33382@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33383 conn_wait_active_ee_empty(tconn);
33384 drbd_flush(tconn);
33385
33386- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33387+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33388 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33389 if (epoch)
33390 break;
33391@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33392 }
33393
33394 epoch->flags = 0;
33395- atomic_set(&epoch->epoch_size, 0);
33396+ atomic_set_unchecked(&epoch->epoch_size, 0);
33397 atomic_set(&epoch->active, 0);
33398
33399 spin_lock(&tconn->epoch_lock);
33400- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33401+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33402 list_add(&epoch->list, &tconn->current_epoch->list);
33403 tconn->current_epoch = epoch;
33404 tconn->epochs++;
33405@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33406
33407 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33408 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33409- atomic_inc(&tconn->current_epoch->epoch_size);
33410+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33411 err2 = drbd_drain_block(mdev, pi->size);
33412 if (!err)
33413 err = err2;
33414@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33415
33416 spin_lock(&tconn->epoch_lock);
33417 peer_req->epoch = tconn->current_epoch;
33418- atomic_inc(&peer_req->epoch->epoch_size);
33419+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33420 atomic_inc(&peer_req->epoch->active);
33421 spin_unlock(&tconn->epoch_lock);
33422
33423@@ -4346,7 +4346,7 @@ struct data_cmd {
33424 int expect_payload;
33425 size_t pkt_size;
33426 int (*fn)(struct drbd_tconn *, struct packet_info *);
33427-};
33428+} __do_const;
33429
33430 static struct data_cmd drbd_cmd_handler[] = {
33431 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33432@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33433 if (!list_empty(&tconn->current_epoch->list))
33434 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33435 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33436- atomic_set(&tconn->current_epoch->epoch_size, 0);
33437+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33438 tconn->send.seen_any_write_yet = false;
33439
33440 conn_info(tconn, "Connection closed\n");
33441@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33442 struct asender_cmd {
33443 size_t pkt_size;
33444 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33445-};
33446+} __do_const;
33447
33448 static struct asender_cmd asender_tbl[] = {
33449 [P_PING] = { 0, got_Ping },
33450diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33451index 8bc6d39..f492563 100644
33452--- a/drivers/block/loop.c
33453+++ b/drivers/block/loop.c
33454@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33455 mm_segment_t old_fs = get_fs();
33456
33457 set_fs(get_ds());
33458- bw = file->f_op->write(file, buf, len, &pos);
33459+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33460 set_fs(old_fs);
33461 if (likely(bw == len))
33462 return 0;
33463diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33464index d620b44..587561e 100644
33465--- a/drivers/cdrom/cdrom.c
33466+++ b/drivers/cdrom/cdrom.c
33467@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33468 ENSURE(reset, CDC_RESET);
33469 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33470 cdi->mc_flags = 0;
33471- cdo->n_minors = 0;
33472 cdi->options = CDO_USE_FFLAGS;
33473
33474 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33475@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33476 else
33477 cdi->cdda_method = CDDA_OLD;
33478
33479- if (!cdo->generic_packet)
33480- cdo->generic_packet = cdrom_dummy_generic_packet;
33481+ if (!cdo->generic_packet) {
33482+ pax_open_kernel();
33483+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33484+ pax_close_kernel();
33485+ }
33486
33487 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33488 mutex_lock(&cdrom_mutex);
33489@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33490 if (cdi->exit)
33491 cdi->exit(cdi);
33492
33493- cdi->ops->n_minors--;
33494 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33495 }
33496
33497diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33498index d59cdcb..11afddf 100644
33499--- a/drivers/cdrom/gdrom.c
33500+++ b/drivers/cdrom/gdrom.c
33501@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33502 .audio_ioctl = gdrom_audio_ioctl,
33503 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33504 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33505- .n_minors = 1,
33506 };
33507
33508 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33509diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33510index 72bedad..8181ce1 100644
33511--- a/drivers/char/Kconfig
33512+++ b/drivers/char/Kconfig
33513@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33514
33515 config DEVKMEM
33516 bool "/dev/kmem virtual device support"
33517- default y
33518+ default n
33519+ depends on !GRKERNSEC_KMEM
33520 help
33521 Say Y here if you want to support the /dev/kmem device. The
33522 /dev/kmem device is rarely used, but can be used for certain
33523@@ -581,6 +582,7 @@ config DEVPORT
33524 bool
33525 depends on !M68K
33526 depends on ISA || PCI
33527+ depends on !GRKERNSEC_KMEM
33528 default y
33529
33530 source "drivers/s390/char/Kconfig"
33531diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33532index 2e04433..22afc64 100644
33533--- a/drivers/char/agp/frontend.c
33534+++ b/drivers/char/agp/frontend.c
33535@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33536 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33537 return -EFAULT;
33538
33539- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33540+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33541 return -EFAULT;
33542
33543 client = agp_find_client_by_pid(reserve.pid);
33544diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33545index 21cb980..f15107c 100644
33546--- a/drivers/char/genrtc.c
33547+++ b/drivers/char/genrtc.c
33548@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33549 switch (cmd) {
33550
33551 case RTC_PLL_GET:
33552+ memset(&pll, 0, sizeof(pll));
33553 if (get_rtc_pll(&pll))
33554 return -EINVAL;
33555 else
33556diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33557index fe6d4be..89f32100 100644
33558--- a/drivers/char/hpet.c
33559+++ b/drivers/char/hpet.c
33560@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33561 }
33562
33563 static int
33564-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33565+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33566 struct hpet_info *info)
33567 {
33568 struct hpet_timer __iomem *timer;
33569diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33570index 053201b0..8335cce 100644
33571--- a/drivers/char/ipmi/ipmi_msghandler.c
33572+++ b/drivers/char/ipmi/ipmi_msghandler.c
33573@@ -420,7 +420,7 @@ struct ipmi_smi {
33574 struct proc_dir_entry *proc_dir;
33575 char proc_dir_name[10];
33576
33577- atomic_t stats[IPMI_NUM_STATS];
33578+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33579
33580 /*
33581 * run_to_completion duplicate of smb_info, smi_info
33582@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33583
33584
33585 #define ipmi_inc_stat(intf, stat) \
33586- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33587+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33588 #define ipmi_get_stat(intf, stat) \
33589- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33590+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33591
33592 static int is_lan_addr(struct ipmi_addr *addr)
33593 {
33594@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33595 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33596 init_waitqueue_head(&intf->waitq);
33597 for (i = 0; i < IPMI_NUM_STATS; i++)
33598- atomic_set(&intf->stats[i], 0);
33599+ atomic_set_unchecked(&intf->stats[i], 0);
33600
33601 intf->proc_dir = NULL;
33602
33603diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33604index 1c7fdcd..4899100 100644
33605--- a/drivers/char/ipmi/ipmi_si_intf.c
33606+++ b/drivers/char/ipmi/ipmi_si_intf.c
33607@@ -275,7 +275,7 @@ struct smi_info {
33608 unsigned char slave_addr;
33609
33610 /* Counters and things for the proc filesystem. */
33611- atomic_t stats[SI_NUM_STATS];
33612+ atomic_unchecked_t stats[SI_NUM_STATS];
33613
33614 struct task_struct *thread;
33615
33616@@ -284,9 +284,9 @@ struct smi_info {
33617 };
33618
33619 #define smi_inc_stat(smi, stat) \
33620- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33621+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33622 #define smi_get_stat(smi, stat) \
33623- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33624+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33625
33626 #define SI_MAX_PARMS 4
33627
33628@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
33629 atomic_set(&new_smi->req_events, 0);
33630 new_smi->run_to_completion = 0;
33631 for (i = 0; i < SI_NUM_STATS; i++)
33632- atomic_set(&new_smi->stats[i], 0);
33633+ atomic_set_unchecked(&new_smi->stats[i], 0);
33634
33635 new_smi->interrupt_disabled = 1;
33636 atomic_set(&new_smi->stop_operation, 0);
33637diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33638index c6fa3bc..4ca3e42 100644
33639--- a/drivers/char/mem.c
33640+++ b/drivers/char/mem.c
33641@@ -18,6 +18,7 @@
33642 #include <linux/raw.h>
33643 #include <linux/tty.h>
33644 #include <linux/capability.h>
33645+#include <linux/security.h>
33646 #include <linux/ptrace.h>
33647 #include <linux/device.h>
33648 #include <linux/highmem.h>
33649@@ -37,6 +38,10 @@
33650
33651 #define DEVPORT_MINOR 4
33652
33653+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33654+extern const struct file_operations grsec_fops;
33655+#endif
33656+
33657 static inline unsigned long size_inside_page(unsigned long start,
33658 unsigned long size)
33659 {
33660@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33661
33662 while (cursor < to) {
33663 if (!devmem_is_allowed(pfn)) {
33664+#ifdef CONFIG_GRKERNSEC_KMEM
33665+ gr_handle_mem_readwrite(from, to);
33666+#else
33667 printk(KERN_INFO
33668 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33669 current->comm, from, to);
33670+#endif
33671 return 0;
33672 }
33673 cursor += PAGE_SIZE;
33674@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33675 }
33676 return 1;
33677 }
33678+#elif defined(CONFIG_GRKERNSEC_KMEM)
33679+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33680+{
33681+ return 0;
33682+}
33683 #else
33684 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33685 {
33686@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33687
33688 while (count > 0) {
33689 unsigned long remaining;
33690+ char *temp;
33691
33692 sz = size_inside_page(p, count);
33693
33694@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33695 if (!ptr)
33696 return -EFAULT;
33697
33698- remaining = copy_to_user(buf, ptr, sz);
33699+#ifdef CONFIG_PAX_USERCOPY
33700+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33701+ if (!temp) {
33702+ unxlate_dev_mem_ptr(p, ptr);
33703+ return -ENOMEM;
33704+ }
33705+ memcpy(temp, ptr, sz);
33706+#else
33707+ temp = ptr;
33708+#endif
33709+
33710+ remaining = copy_to_user(buf, temp, sz);
33711+
33712+#ifdef CONFIG_PAX_USERCOPY
33713+ kfree(temp);
33714+#endif
33715+
33716 unxlate_dev_mem_ptr(p, ptr);
33717 if (remaining)
33718 return -EFAULT;
33719@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33720 size_t count, loff_t *ppos)
33721 {
33722 unsigned long p = *ppos;
33723- ssize_t low_count, read, sz;
33724+ ssize_t low_count, read, sz, err = 0;
33725 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33726- int err = 0;
33727
33728 read = 0;
33729 if (p < (unsigned long) high_memory) {
33730@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33731 }
33732 #endif
33733 while (low_count > 0) {
33734+ char *temp;
33735+
33736 sz = size_inside_page(p, low_count);
33737
33738 /*
33739@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33740 */
33741 kbuf = xlate_dev_kmem_ptr((char *)p);
33742
33743- if (copy_to_user(buf, kbuf, sz))
33744+#ifdef CONFIG_PAX_USERCOPY
33745+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33746+ if (!temp)
33747+ return -ENOMEM;
33748+ memcpy(temp, kbuf, sz);
33749+#else
33750+ temp = kbuf;
33751+#endif
33752+
33753+ err = copy_to_user(buf, temp, sz);
33754+
33755+#ifdef CONFIG_PAX_USERCOPY
33756+ kfree(temp);
33757+#endif
33758+
33759+ if (err)
33760 return -EFAULT;
33761 buf += sz;
33762 p += sz;
33763@@ -833,6 +880,9 @@ static const struct memdev {
33764 #ifdef CONFIG_CRASH_DUMP
33765 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33766 #endif
33767+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33768+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33769+#endif
33770 };
33771
33772 static int memory_open(struct inode *inode, struct file *filp)
33773diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33774index 9df78e2..01ba9ae 100644
33775--- a/drivers/char/nvram.c
33776+++ b/drivers/char/nvram.c
33777@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33778
33779 spin_unlock_irq(&rtc_lock);
33780
33781- if (copy_to_user(buf, contents, tmp - contents))
33782+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33783 return -EFAULT;
33784
33785 *ppos = i;
33786diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33787index b66eaa0..2619d1b 100644
33788--- a/drivers/char/pcmcia/synclink_cs.c
33789+++ b/drivers/char/pcmcia/synclink_cs.c
33790@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33791
33792 if (debug_level >= DEBUG_LEVEL_INFO)
33793 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33794- __FILE__,__LINE__, info->device_name, port->count);
33795+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
33796
33797- WARN_ON(!port->count);
33798+ WARN_ON(!atomic_read(&port->count));
33799
33800 if (tty_port_close_start(port, tty, filp) == 0)
33801 goto cleanup;
33802@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33803 cleanup:
33804 if (debug_level >= DEBUG_LEVEL_INFO)
33805 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
33806- tty->driver->name, port->count);
33807+ tty->driver->name, atomic_read(&port->count));
33808 }
33809
33810 /* Wait until the transmitter is empty.
33811@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33812
33813 if (debug_level >= DEBUG_LEVEL_INFO)
33814 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
33815- __FILE__,__LINE__,tty->driver->name, port->count);
33816+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
33817
33818 /* If port is closing, signal caller to try again */
33819 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
33820@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33821 goto cleanup;
33822 }
33823 spin_lock(&port->lock);
33824- port->count++;
33825+ atomic_inc(&port->count);
33826 spin_unlock(&port->lock);
33827 spin_unlock_irqrestore(&info->netlock, flags);
33828
33829- if (port->count == 1) {
33830+ if (atomic_read(&port->count) == 1) {
33831 /* 1st open on this device, init hardware */
33832 retval = startup(info, tty);
33833 if (retval < 0)
33834@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
33835 unsigned short new_crctype;
33836
33837 /* return error if TTY interface open */
33838- if (info->port.count)
33839+ if (atomic_read(&info->port.count))
33840 return -EBUSY;
33841
33842 switch (encoding)
33843@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
33844
33845 /* arbitrate between network and tty opens */
33846 spin_lock_irqsave(&info->netlock, flags);
33847- if (info->port.count != 0 || info->netcount != 0) {
33848+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
33849 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
33850 spin_unlock_irqrestore(&info->netlock, flags);
33851 return -EBUSY;
33852@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33853 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
33854
33855 /* return error if TTY interface open */
33856- if (info->port.count)
33857+ if (atomic_read(&info->port.count))
33858 return -EBUSY;
33859
33860 if (cmd != SIOCWANDEV)
33861diff --git a/drivers/char/random.c b/drivers/char/random.c
33862index 57d4b15..253207b 100644
33863--- a/drivers/char/random.c
33864+++ b/drivers/char/random.c
33865@@ -272,8 +272,13 @@
33866 /*
33867 * Configuration information
33868 */
33869+#ifdef CONFIG_GRKERNSEC_RANDNET
33870+#define INPUT_POOL_WORDS 512
33871+#define OUTPUT_POOL_WORDS 128
33872+#else
33873 #define INPUT_POOL_WORDS 128
33874 #define OUTPUT_POOL_WORDS 32
33875+#endif
33876 #define SEC_XFER_SIZE 512
33877 #define EXTRACT_SIZE 10
33878
33879@@ -313,10 +318,17 @@ static struct poolinfo {
33880 int poolwords;
33881 int tap1, tap2, tap3, tap4, tap5;
33882 } poolinfo_table[] = {
33883+#ifdef CONFIG_GRKERNSEC_RANDNET
33884+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33885+ { 512, 411, 308, 208, 104, 1 },
33886+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33887+ { 128, 103, 76, 51, 25, 1 },
33888+#else
33889 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33890 { 128, 103, 76, 51, 25, 1 },
33891 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33892 { 32, 26, 20, 14, 7, 1 },
33893+#endif
33894 #if 0
33895 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33896 { 2048, 1638, 1231, 819, 411, 1 },
33897@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33898 input_rotate += i ? 7 : 14;
33899 }
33900
33901- ACCESS_ONCE(r->input_rotate) = input_rotate;
33902- ACCESS_ONCE(r->add_ptr) = i;
33903+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33904+ ACCESS_ONCE_RW(r->add_ptr) = i;
33905 smp_wmb();
33906
33907 if (out)
33908@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33909
33910 extract_buf(r, tmp);
33911 i = min_t(int, nbytes, EXTRACT_SIZE);
33912- if (copy_to_user(buf, tmp, i)) {
33913+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33914 ret = -EFAULT;
33915 break;
33916 }
33917@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33918 #include <linux/sysctl.h>
33919
33920 static int min_read_thresh = 8, min_write_thresh;
33921-static int max_read_thresh = INPUT_POOL_WORDS * 32;
33922+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33923 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33924 static char sysctl_bootid[16];
33925
33926@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
33927 static int proc_do_uuid(ctl_table *table, int write,
33928 void __user *buffer, size_t *lenp, loff_t *ppos)
33929 {
33930- ctl_table fake_table;
33931+ ctl_table_no_const fake_table;
33932 unsigned char buf[64], tmp_uuid[16], *uuid;
33933
33934 uuid = table->data;
33935diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33936index d780295..b29f3a8 100644
33937--- a/drivers/char/sonypi.c
33938+++ b/drivers/char/sonypi.c
33939@@ -54,6 +54,7 @@
33940
33941 #include <asm/uaccess.h>
33942 #include <asm/io.h>
33943+#include <asm/local.h>
33944
33945 #include <linux/sonypi.h>
33946
33947@@ -490,7 +491,7 @@ static struct sonypi_device {
33948 spinlock_t fifo_lock;
33949 wait_queue_head_t fifo_proc_list;
33950 struct fasync_struct *fifo_async;
33951- int open_count;
33952+ local_t open_count;
33953 int model;
33954 struct input_dev *input_jog_dev;
33955 struct input_dev *input_key_dev;
33956@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33957 static int sonypi_misc_release(struct inode *inode, struct file *file)
33958 {
33959 mutex_lock(&sonypi_device.lock);
33960- sonypi_device.open_count--;
33961+ local_dec(&sonypi_device.open_count);
33962 mutex_unlock(&sonypi_device.lock);
33963 return 0;
33964 }
33965@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33966 {
33967 mutex_lock(&sonypi_device.lock);
33968 /* Flush input queue on first open */
33969- if (!sonypi_device.open_count)
33970+ if (!local_read(&sonypi_device.open_count))
33971 kfifo_reset(&sonypi_device.fifo);
33972- sonypi_device.open_count++;
33973+ local_inc(&sonypi_device.open_count);
33974 mutex_unlock(&sonypi_device.lock);
33975
33976 return 0;
33977diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33978index 93211df..c7805f7 100644
33979--- a/drivers/char/tpm/tpm.c
33980+++ b/drivers/char/tpm/tpm.c
33981@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33982 chip->vendor.req_complete_val)
33983 goto out_recv;
33984
33985- if ((status == chip->vendor.req_canceled)) {
33986+ if (status == chip->vendor.req_canceled) {
33987 dev_err(chip->dev, "Operation Canceled\n");
33988 rc = -ECANCELED;
33989 goto out;
33990diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33991index 56051d0..11cf3b7 100644
33992--- a/drivers/char/tpm/tpm_acpi.c
33993+++ b/drivers/char/tpm/tpm_acpi.c
33994@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33995 virt = acpi_os_map_memory(start, len);
33996 if (!virt) {
33997 kfree(log->bios_event_log);
33998+ log->bios_event_log = NULL;
33999 printk("%s: ERROR - Unable to map memory\n", __func__);
34000 return -EIO;
34001 }
34002
34003- memcpy_fromio(log->bios_event_log, virt, len);
34004+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34005
34006 acpi_os_unmap_memory(virt, len);
34007 return 0;
34008diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34009index 84ddc55..1d32f1e 100644
34010--- a/drivers/char/tpm/tpm_eventlog.c
34011+++ b/drivers/char/tpm/tpm_eventlog.c
34012@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34013 event = addr;
34014
34015 if ((event->event_type == 0 && event->event_size == 0) ||
34016- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34017+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34018 return NULL;
34019
34020 return addr;
34021@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34022 return NULL;
34023
34024 if ((event->event_type == 0 && event->event_size == 0) ||
34025- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34026+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34027 return NULL;
34028
34029 (*pos)++;
34030@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34031 int i;
34032
34033 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34034- seq_putc(m, data[i]);
34035+ if (!seq_putc(m, data[i]))
34036+ return -EFAULT;
34037
34038 return 0;
34039 }
34040diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34041index ee4dbea..69c817b 100644
34042--- a/drivers/char/virtio_console.c
34043+++ b/drivers/char/virtio_console.c
34044@@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34045 if (to_user) {
34046 ssize_t ret;
34047
34048- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34049+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34050 if (ret)
34051 return -EFAULT;
34052 } else {
34053@@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34054 if (!port_has_data(port) && !port->host_connected)
34055 return 0;
34056
34057- return fill_readbuf(port, ubuf, count, true);
34058+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34059 }
34060
34061 static int wait_port_writable(struct port *port, bool nonblock)
34062diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
34063index 8ae1a61..9c00613 100644
34064--- a/drivers/clocksource/arm_generic.c
34065+++ b/drivers/clocksource/arm_generic.c
34066@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34067 return NOTIFY_OK;
34068 }
34069
34070-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34071+static struct notifier_block arch_timer_cpu_nb = {
34072 .notifier_call = arch_timer_cpu_notify,
34073 };
34074
34075diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34076index 7b0d49d..134fac9 100644
34077--- a/drivers/cpufreq/acpi-cpufreq.c
34078+++ b/drivers/cpufreq/acpi-cpufreq.c
34079@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34080 return sprintf(buf, "%u\n", boost_enabled);
34081 }
34082
34083-static struct global_attr global_boost = __ATTR(boost, 0644,
34084+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34085 show_global_boost,
34086 store_global_boost);
34087
34088@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34089 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34090 per_cpu(acfreq_data, cpu) = data;
34091
34092- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34093- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34094+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34095+ pax_open_kernel();
34096+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34097+ pax_close_kernel();
34098+ }
34099
34100 result = acpi_processor_register_performance(data->acpi_data, cpu);
34101 if (result)
34102@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34103 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34104 break;
34105 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34106- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34107+ pax_open_kernel();
34108+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34109+ pax_close_kernel();
34110 policy->cur = get_cur_freq_on_cpu(cpu);
34111 break;
34112 default:
34113@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34114 acpi_processor_notify_smm(THIS_MODULE);
34115
34116 /* Check for APERF/MPERF support in hardware */
34117- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34118- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34119+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34120+ pax_open_kernel();
34121+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34122+ pax_close_kernel();
34123+ }
34124
34125 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34126 for (i = 0; i < perf->state_count; i++)
34127diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34128index 1f93dbd..305cef1 100644
34129--- a/drivers/cpufreq/cpufreq.c
34130+++ b/drivers/cpufreq/cpufreq.c
34131@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34132 return NOTIFY_OK;
34133 }
34134
34135-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34136+static struct notifier_block cpufreq_cpu_notifier = {
34137 .notifier_call = cpufreq_cpu_callback,
34138 };
34139
34140@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34141
34142 pr_debug("trying to register driver %s\n", driver_data->name);
34143
34144- if (driver_data->setpolicy)
34145- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34146+ if (driver_data->setpolicy) {
34147+ pax_open_kernel();
34148+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34149+ pax_close_kernel();
34150+ }
34151
34152 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34153 if (cpufreq_driver) {
34154diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34155index 6c5f1d3..c7e2f35e 100644
34156--- a/drivers/cpufreq/cpufreq_governor.c
34157+++ b/drivers/cpufreq/cpufreq_governor.c
34158@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34159 * governor, thus we are bound to jiffes/HZ
34160 */
34161 if (dbs_data->governor == GOV_CONSERVATIVE) {
34162- struct cs_ops *ops = dbs_data->gov_ops;
34163+ const struct cs_ops *ops = dbs_data->gov_ops;
34164
34165 cpufreq_register_notifier(ops->notifier_block,
34166 CPUFREQ_TRANSITION_NOTIFIER);
34167@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34168 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
34169 jiffies_to_usecs(10);
34170 } else {
34171- struct od_ops *ops = dbs_data->gov_ops;
34172+ const struct od_ops *ops = dbs_data->gov_ops;
34173
34174 od_tuners->io_is_busy = ops->io_busy();
34175 }
34176@@ -268,7 +268,7 @@ second_time:
34177 cs_dbs_info->enable = 1;
34178 cs_dbs_info->requested_freq = policy->cur;
34179 } else {
34180- struct od_ops *ops = dbs_data->gov_ops;
34181+ const struct od_ops *ops = dbs_data->gov_ops;
34182 od_dbs_info->rate_mult = 1;
34183 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
34184 ops->powersave_bias_init_cpu(cpu);
34185@@ -289,7 +289,7 @@ second_time:
34186 mutex_destroy(&cpu_cdbs->timer_mutex);
34187 dbs_data->enable--;
34188 if (!dbs_data->enable) {
34189- struct cs_ops *ops = dbs_data->gov_ops;
34190+ const struct cs_ops *ops = dbs_data->gov_ops;
34191
34192 sysfs_remove_group(cpufreq_global_kobject,
34193 dbs_data->attr_group);
34194diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34195index f661654..6c8e638 100644
34196--- a/drivers/cpufreq/cpufreq_governor.h
34197+++ b/drivers/cpufreq/cpufreq_governor.h
34198@@ -142,7 +142,7 @@ struct dbs_data {
34199 void (*gov_check_cpu)(int cpu, unsigned int load);
34200
34201 /* Governor specific ops, see below */
34202- void *gov_ops;
34203+ const void *gov_ops;
34204 };
34205
34206 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34207diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34208index 9d7732b..0b1a793 100644
34209--- a/drivers/cpufreq/cpufreq_stats.c
34210+++ b/drivers/cpufreq/cpufreq_stats.c
34211@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34212 }
34213
34214 /* priority=1 so this will get called before cpufreq_remove_dev */
34215-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34216+static struct notifier_block cpufreq_stat_cpu_notifier = {
34217 .notifier_call = cpufreq_stat_cpu_callback,
34218 .priority = 1,
34219 };
34220diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34221index 827629c9..0bc6a03 100644
34222--- a/drivers/cpufreq/p4-clockmod.c
34223+++ b/drivers/cpufreq/p4-clockmod.c
34224@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34225 case 0x0F: /* Core Duo */
34226 case 0x16: /* Celeron Core */
34227 case 0x1C: /* Atom */
34228- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34229+ pax_open_kernel();
34230+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34231+ pax_close_kernel();
34232 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34233 case 0x0D: /* Pentium M (Dothan) */
34234- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34235+ pax_open_kernel();
34236+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34237+ pax_close_kernel();
34238 /* fall through */
34239 case 0x09: /* Pentium M (Banias) */
34240 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34241@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34242
34243 /* on P-4s, the TSC runs with constant frequency independent whether
34244 * throttling is active or not. */
34245- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34246+ pax_open_kernel();
34247+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34248+ pax_close_kernel();
34249
34250 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34251 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34252diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34253index 3a953d5..f5993f6 100644
34254--- a/drivers/cpufreq/speedstep-centrino.c
34255+++ b/drivers/cpufreq/speedstep-centrino.c
34256@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34257 !cpu_has(cpu, X86_FEATURE_EST))
34258 return -ENODEV;
34259
34260- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34261- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34262+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34263+ pax_open_kernel();
34264+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34265+ pax_close_kernel();
34266+ }
34267
34268 if (policy->cpu != 0)
34269 return -ENODEV;
34270diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34271index e1f6860..f8de20b 100644
34272--- a/drivers/cpuidle/cpuidle.c
34273+++ b/drivers/cpuidle/cpuidle.c
34274@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
34275
34276 static void poll_idle_init(struct cpuidle_driver *drv)
34277 {
34278- struct cpuidle_state *state = &drv->states[0];
34279+ cpuidle_state_no_const *state = &drv->states[0];
34280
34281 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34282 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34283diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34284index ea2f8e7..70ac501 100644
34285--- a/drivers/cpuidle/governor.c
34286+++ b/drivers/cpuidle/governor.c
34287@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34288 mutex_lock(&cpuidle_lock);
34289 if (__cpuidle_find_governor(gov->name) == NULL) {
34290 ret = 0;
34291- list_add_tail(&gov->governor_list, &cpuidle_governors);
34292+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34293 if (!cpuidle_curr_governor ||
34294 cpuidle_curr_governor->rating < gov->rating)
34295 cpuidle_switch_governor(gov);
34296@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34297 new_gov = cpuidle_replace_governor(gov->rating);
34298 cpuidle_switch_governor(new_gov);
34299 }
34300- list_del(&gov->governor_list);
34301+ pax_list_del((struct list_head *)&gov->governor_list);
34302 mutex_unlock(&cpuidle_lock);
34303 }
34304
34305diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34306index 428754a..8bdf9cc 100644
34307--- a/drivers/cpuidle/sysfs.c
34308+++ b/drivers/cpuidle/sysfs.c
34309@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34310 NULL
34311 };
34312
34313-static struct attribute_group cpuidle_attr_group = {
34314+static attribute_group_no_const cpuidle_attr_group = {
34315 .attrs = cpuidle_default_attrs,
34316 .name = "cpuidle",
34317 };
34318diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34319index 3b36797..289c16a 100644
34320--- a/drivers/devfreq/devfreq.c
34321+++ b/drivers/devfreq/devfreq.c
34322@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34323 goto err_out;
34324 }
34325
34326- list_add(&governor->node, &devfreq_governor_list);
34327+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34328
34329 list_for_each_entry(devfreq, &devfreq_list, node) {
34330 int ret = 0;
34331@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34332 }
34333 }
34334
34335- list_del(&governor->node);
34336+ pax_list_del((struct list_head *)&governor->node);
34337 err_out:
34338 mutex_unlock(&devfreq_list_lock);
34339
34340diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34341index b70709b..1d8d02a 100644
34342--- a/drivers/dma/sh/shdma.c
34343+++ b/drivers/dma/sh/shdma.c
34344@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34345 return ret;
34346 }
34347
34348-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34349+static struct notifier_block sh_dmae_nmi_notifier = {
34350 .notifier_call = sh_dmae_nmi_handler,
34351
34352 /* Run before NMI debug handler and KGDB */
34353diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34354index 0ca1ca7..6e6f454 100644
34355--- a/drivers/edac/edac_mc_sysfs.c
34356+++ b/drivers/edac/edac_mc_sysfs.c
34357@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34358 struct dev_ch_attribute {
34359 struct device_attribute attr;
34360 int channel;
34361-};
34362+} __do_const;
34363
34364 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34365 struct dev_ch_attribute dev_attr_legacy_##_name = \
34366diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34367index 0056c4d..23b54d9 100644
34368--- a/drivers/edac/edac_pci_sysfs.c
34369+++ b/drivers/edac/edac_pci_sysfs.c
34370@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34371 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34372 static int edac_pci_poll_msec = 1000; /* one second workq period */
34373
34374-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34375-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34376+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34377+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34378
34379 static struct kobject *edac_pci_top_main_kobj;
34380 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34381@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34382 void *value;
34383 ssize_t(*show) (void *, char *);
34384 ssize_t(*store) (void *, const char *, size_t);
34385-};
34386+} __do_const;
34387
34388 /* Set of show/store abstract level functions for PCI Parity object */
34389 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34390@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34391 edac_printk(KERN_CRIT, EDAC_PCI,
34392 "Signaled System Error on %s\n",
34393 pci_name(dev));
34394- atomic_inc(&pci_nonparity_count);
34395+ atomic_inc_unchecked(&pci_nonparity_count);
34396 }
34397
34398 if (status & (PCI_STATUS_PARITY)) {
34399@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34400 "Master Data Parity Error on %s\n",
34401 pci_name(dev));
34402
34403- atomic_inc(&pci_parity_count);
34404+ atomic_inc_unchecked(&pci_parity_count);
34405 }
34406
34407 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34408@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34409 "Detected Parity Error on %s\n",
34410 pci_name(dev));
34411
34412- atomic_inc(&pci_parity_count);
34413+ atomic_inc_unchecked(&pci_parity_count);
34414 }
34415 }
34416
34417@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34418 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34419 "Signaled System Error on %s\n",
34420 pci_name(dev));
34421- atomic_inc(&pci_nonparity_count);
34422+ atomic_inc_unchecked(&pci_nonparity_count);
34423 }
34424
34425 if (status & (PCI_STATUS_PARITY)) {
34426@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34427 "Master Data Parity Error on "
34428 "%s\n", pci_name(dev));
34429
34430- atomic_inc(&pci_parity_count);
34431+ atomic_inc_unchecked(&pci_parity_count);
34432 }
34433
34434 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34435@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34436 "Detected Parity Error on %s\n",
34437 pci_name(dev));
34438
34439- atomic_inc(&pci_parity_count);
34440+ atomic_inc_unchecked(&pci_parity_count);
34441 }
34442 }
34443 }
34444@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34445 if (!check_pci_errors)
34446 return;
34447
34448- before_count = atomic_read(&pci_parity_count);
34449+ before_count = atomic_read_unchecked(&pci_parity_count);
34450
34451 /* scan all PCI devices looking for a Parity Error on devices and
34452 * bridges.
34453@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34454 /* Only if operator has selected panic on PCI Error */
34455 if (edac_pci_get_panic_on_pe()) {
34456 /* If the count is different 'after' from 'before' */
34457- if (before_count != atomic_read(&pci_parity_count))
34458+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34459 panic("EDAC: PCI Parity Error");
34460 }
34461 }
34462diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34463index 6796799..99e8377 100644
34464--- a/drivers/edac/mce_amd.h
34465+++ b/drivers/edac/mce_amd.h
34466@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34467 struct amd_decoder_ops {
34468 bool (*mc0_mce)(u16, u8);
34469 bool (*mc1_mce)(u16, u8);
34470-};
34471+} __no_const;
34472
34473 void amd_report_gart_errors(bool);
34474 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34475diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34476index 57ea7f4..789e3c3 100644
34477--- a/drivers/firewire/core-card.c
34478+++ b/drivers/firewire/core-card.c
34479@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34480
34481 void fw_core_remove_card(struct fw_card *card)
34482 {
34483- struct fw_card_driver dummy_driver = dummy_driver_template;
34484+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34485
34486 card->driver->update_phy_reg(card, 4,
34487 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34488diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34489index f8d2287..5aaf4db 100644
34490--- a/drivers/firewire/core-cdev.c
34491+++ b/drivers/firewire/core-cdev.c
34492@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34493 int ret;
34494
34495 if ((request->channels == 0 && request->bandwidth == 0) ||
34496- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34497- request->bandwidth < 0)
34498+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34499 return -EINVAL;
34500
34501 r = kmalloc(sizeof(*r), GFP_KERNEL);
34502diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34503index af3e8aa..eb2f227 100644
34504--- a/drivers/firewire/core-device.c
34505+++ b/drivers/firewire/core-device.c
34506@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34507 struct config_rom_attribute {
34508 struct device_attribute attr;
34509 u32 key;
34510-};
34511+} __do_const;
34512
34513 static ssize_t show_immediate(struct device *dev,
34514 struct device_attribute *dattr, char *buf)
34515diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34516index 28a94c7..58da63a 100644
34517--- a/drivers/firewire/core-transaction.c
34518+++ b/drivers/firewire/core-transaction.c
34519@@ -38,6 +38,7 @@
34520 #include <linux/timer.h>
34521 #include <linux/types.h>
34522 #include <linux/workqueue.h>
34523+#include <linux/sched.h>
34524
34525 #include <asm/byteorder.h>
34526
34527diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34528index 515a42c..5ecf3ba 100644
34529--- a/drivers/firewire/core.h
34530+++ b/drivers/firewire/core.h
34531@@ -111,6 +111,7 @@ struct fw_card_driver {
34532
34533 int (*stop_iso)(struct fw_iso_context *ctx);
34534 };
34535+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34536
34537 void fw_card_initialize(struct fw_card *card,
34538 const struct fw_card_driver *driver, struct device *device);
34539diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34540index 94a58a0..f5eba42 100644
34541--- a/drivers/firmware/dmi-id.c
34542+++ b/drivers/firmware/dmi-id.c
34543@@ -16,7 +16,7 @@
34544 struct dmi_device_attribute{
34545 struct device_attribute dev_attr;
34546 int field;
34547-};
34548+} __do_const;
34549 #define to_dmi_dev_attr(_dev_attr) \
34550 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34551
34552diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34553index 4cd392d..4b629e1 100644
34554--- a/drivers/firmware/dmi_scan.c
34555+++ b/drivers/firmware/dmi_scan.c
34556@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
34557 }
34558 }
34559 else {
34560- /*
34561- * no iounmap() for that ioremap(); it would be a no-op, but
34562- * it's so early in setup that sucker gets confused into doing
34563- * what it shouldn't if we actually call it.
34564- */
34565 p = dmi_ioremap(0xF0000, 0x10000);
34566 if (p == NULL)
34567 goto error;
34568@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34569 if (buf == NULL)
34570 return -1;
34571
34572- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34573+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34574
34575 iounmap(buf);
34576 return 0;
34577diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34578index 2a2e145..73745e79 100644
34579--- a/drivers/firmware/efivars.c
34580+++ b/drivers/firmware/efivars.c
34581@@ -133,7 +133,7 @@ struct efivar_attribute {
34582 };
34583
34584 static struct efivars __efivars;
34585-static struct efivar_operations ops;
34586+static efivar_operations_no_const ops __read_only;
34587
34588 #define PSTORE_EFI_ATTRIBUTES \
34589 (EFI_VARIABLE_NON_VOLATILE | \
34590@@ -1798,7 +1798,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34591 static int
34592 create_efivars_bin_attributes(struct efivars *efivars)
34593 {
34594- struct bin_attribute *attr;
34595+ bin_attribute_no_const *attr;
34596 int error;
34597
34598 /* new_var */
34599diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34600index 2a90ba6..07f3733 100644
34601--- a/drivers/firmware/google/memconsole.c
34602+++ b/drivers/firmware/google/memconsole.c
34603@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34604 if (!found_memconsole())
34605 return -ENODEV;
34606
34607- memconsole_bin_attr.size = memconsole_length;
34608+ pax_open_kernel();
34609+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34610+ pax_close_kernel();
34611
34612 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34613
34614diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34615index 6f2306d..af9476a 100644
34616--- a/drivers/gpio/gpio-ich.c
34617+++ b/drivers/gpio/gpio-ich.c
34618@@ -69,7 +69,7 @@ struct ichx_desc {
34619 /* Some chipsets have quirks, let these use their own request/get */
34620 int (*request)(struct gpio_chip *chip, unsigned offset);
34621 int (*get)(struct gpio_chip *chip, unsigned offset);
34622-};
34623+} __do_const;
34624
34625 static struct {
34626 spinlock_t lock;
34627diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34628index 9902732..64b62dd 100644
34629--- a/drivers/gpio/gpio-vr41xx.c
34630+++ b/drivers/gpio/gpio-vr41xx.c
34631@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34632 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34633 maskl, pendl, maskh, pendh);
34634
34635- atomic_inc(&irq_err_count);
34636+ atomic_inc_unchecked(&irq_err_count);
34637
34638 return -EINVAL;
34639 }
34640diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34641index 7b2d378..cc947ea 100644
34642--- a/drivers/gpu/drm/drm_crtc_helper.c
34643+++ b/drivers/gpu/drm/drm_crtc_helper.c
34644@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34645 struct drm_crtc *tmp;
34646 int crtc_mask = 1;
34647
34648- WARN(!crtc, "checking null crtc?\n");
34649+ BUG_ON(!crtc);
34650
34651 dev = crtc->dev;
34652
34653diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34654index be174ca..7f38143 100644
34655--- a/drivers/gpu/drm/drm_drv.c
34656+++ b/drivers/gpu/drm/drm_drv.c
34657@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
34658 /**
34659 * Copy and IOCTL return string to user space
34660 */
34661-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34662+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34663 {
34664 int len;
34665
34666@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
34667 struct drm_file *file_priv = filp->private_data;
34668 struct drm_device *dev;
34669 struct drm_ioctl_desc *ioctl;
34670- drm_ioctl_t *func;
34671+ drm_ioctl_no_const_t func;
34672 unsigned int nr = DRM_IOCTL_NR(cmd);
34673 int retcode = -EINVAL;
34674 char stack_kdata[128];
34675@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
34676 return -ENODEV;
34677
34678 atomic_inc(&dev->ioctl_count);
34679- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34680+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34681 ++file_priv->ioctl_count;
34682
34683 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34684diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34685index 133b413..fd68225 100644
34686--- a/drivers/gpu/drm/drm_fops.c
34687+++ b/drivers/gpu/drm/drm_fops.c
34688@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34689 }
34690
34691 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34692- atomic_set(&dev->counts[i], 0);
34693+ atomic_set_unchecked(&dev->counts[i], 0);
34694
34695 dev->sigdata.lock = NULL;
34696
34697@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
34698 if (drm_device_is_unplugged(dev))
34699 return -ENODEV;
34700
34701- if (!dev->open_count++)
34702+ if (local_inc_return(&dev->open_count) == 1)
34703 need_setup = 1;
34704 mutex_lock(&dev->struct_mutex);
34705 old_mapping = dev->dev_mapping;
34706@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
34707 retcode = drm_open_helper(inode, filp, dev);
34708 if (retcode)
34709 goto err_undo;
34710- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34711+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34712 if (need_setup) {
34713 retcode = drm_setup(dev);
34714 if (retcode)
34715@@ -164,7 +164,7 @@ err_undo:
34716 iput(container_of(dev->dev_mapping, struct inode, i_data));
34717 dev->dev_mapping = old_mapping;
34718 mutex_unlock(&dev->struct_mutex);
34719- dev->open_count--;
34720+ local_dec(&dev->open_count);
34721 return retcode;
34722 }
34723 EXPORT_SYMBOL(drm_open);
34724@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
34725
34726 mutex_lock(&drm_global_mutex);
34727
34728- DRM_DEBUG("open_count = %d\n", dev->open_count);
34729+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34730
34731 if (dev->driver->preclose)
34732 dev->driver->preclose(dev, file_priv);
34733@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
34734 * Begin inline drm_release
34735 */
34736
34737- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34738+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34739 task_pid_nr(current),
34740 (long)old_encode_dev(file_priv->minor->device),
34741- dev->open_count);
34742+ local_read(&dev->open_count));
34743
34744 /* Release any auth tokens that might point to this file_priv,
34745 (do that under the drm_global_mutex) */
34746@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
34747 * End inline drm_release
34748 */
34749
34750- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34751- if (!--dev->open_count) {
34752+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34753+ if (local_dec_and_test(&dev->open_count)) {
34754 if (atomic_read(&dev->ioctl_count)) {
34755 DRM_ERROR("Device busy: %d\n",
34756 atomic_read(&dev->ioctl_count));
34757diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34758index f731116..629842c 100644
34759--- a/drivers/gpu/drm/drm_global.c
34760+++ b/drivers/gpu/drm/drm_global.c
34761@@ -36,7 +36,7 @@
34762 struct drm_global_item {
34763 struct mutex mutex;
34764 void *object;
34765- int refcount;
34766+ atomic_t refcount;
34767 };
34768
34769 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34770@@ -49,7 +49,7 @@ void drm_global_init(void)
34771 struct drm_global_item *item = &glob[i];
34772 mutex_init(&item->mutex);
34773 item->object = NULL;
34774- item->refcount = 0;
34775+ atomic_set(&item->refcount, 0);
34776 }
34777 }
34778
34779@@ -59,7 +59,7 @@ void drm_global_release(void)
34780 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34781 struct drm_global_item *item = &glob[i];
34782 BUG_ON(item->object != NULL);
34783- BUG_ON(item->refcount != 0);
34784+ BUG_ON(atomic_read(&item->refcount) != 0);
34785 }
34786 }
34787
34788@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34789 void *object;
34790
34791 mutex_lock(&item->mutex);
34792- if (item->refcount == 0) {
34793+ if (atomic_read(&item->refcount) == 0) {
34794 item->object = kzalloc(ref->size, GFP_KERNEL);
34795 if (unlikely(item->object == NULL)) {
34796 ret = -ENOMEM;
34797@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34798 goto out_err;
34799
34800 }
34801- ++item->refcount;
34802+ atomic_inc(&item->refcount);
34803 ref->object = item->object;
34804 object = item->object;
34805 mutex_unlock(&item->mutex);
34806@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34807 struct drm_global_item *item = &glob[ref->global_type];
34808
34809 mutex_lock(&item->mutex);
34810- BUG_ON(item->refcount == 0);
34811+ BUG_ON(atomic_read(&item->refcount) == 0);
34812 BUG_ON(ref->object != item->object);
34813- if (--item->refcount == 0) {
34814+ if (atomic_dec_and_test(&item->refcount)) {
34815 ref->release(ref);
34816 item->object = NULL;
34817 }
34818diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
34819index d4b20ce..77a8d41 100644
34820--- a/drivers/gpu/drm/drm_info.c
34821+++ b/drivers/gpu/drm/drm_info.c
34822@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
34823 struct drm_local_map *map;
34824 struct drm_map_list *r_list;
34825
34826- /* Hardcoded from _DRM_FRAME_BUFFER,
34827- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
34828- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
34829- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
34830+ static const char * const types[] = {
34831+ [_DRM_FRAME_BUFFER] = "FB",
34832+ [_DRM_REGISTERS] = "REG",
34833+ [_DRM_SHM] = "SHM",
34834+ [_DRM_AGP] = "AGP",
34835+ [_DRM_SCATTER_GATHER] = "SG",
34836+ [_DRM_CONSISTENT] = "PCI",
34837+ [_DRM_GEM] = "GEM" };
34838 const char *type;
34839 int i;
34840
34841@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
34842 map = r_list->map;
34843 if (!map)
34844 continue;
34845- if (map->type < 0 || map->type > 5)
34846+ if (map->type >= ARRAY_SIZE(types))
34847 type = "??";
34848 else
34849 type = types[map->type];
34850@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
34851 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
34852 vma->vm_flags & VM_LOCKED ? 'l' : '-',
34853 vma->vm_flags & VM_IO ? 'i' : '-',
34854+#ifdef CONFIG_GRKERNSEC_HIDESYM
34855+ 0);
34856+#else
34857 vma->vm_pgoff);
34858+#endif
34859
34860 #if defined(__i386__)
34861 pgprot = pgprot_val(vma->vm_page_prot);
34862diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
34863index 2f4c434..dd12cd2 100644
34864--- a/drivers/gpu/drm/drm_ioc32.c
34865+++ b/drivers/gpu/drm/drm_ioc32.c
34866@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
34867 request = compat_alloc_user_space(nbytes);
34868 if (!access_ok(VERIFY_WRITE, request, nbytes))
34869 return -EFAULT;
34870- list = (struct drm_buf_desc *) (request + 1);
34871+ list = (struct drm_buf_desc __user *) (request + 1);
34872
34873 if (__put_user(count, &request->count)
34874 || __put_user(list, &request->list))
34875@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
34876 request = compat_alloc_user_space(nbytes);
34877 if (!access_ok(VERIFY_WRITE, request, nbytes))
34878 return -EFAULT;
34879- list = (struct drm_buf_pub *) (request + 1);
34880+ list = (struct drm_buf_pub __user *) (request + 1);
34881
34882 if (__put_user(count, &request->count)
34883 || __put_user(list, &request->list))
34884@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
34885 return 0;
34886 }
34887
34888-drm_ioctl_compat_t *drm_compat_ioctls[] = {
34889+drm_ioctl_compat_t drm_compat_ioctls[] = {
34890 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
34891 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
34892 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
34893@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
34894 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34895 {
34896 unsigned int nr = DRM_IOCTL_NR(cmd);
34897- drm_ioctl_compat_t *fn;
34898 int ret;
34899
34900 /* Assume that ioctls without an explicit compat routine will just
34901@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34902 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
34903 return drm_ioctl(filp, cmd, arg);
34904
34905- fn = drm_compat_ioctls[nr];
34906-
34907- if (fn != NULL)
34908- ret = (*fn) (filp, cmd, arg);
34909+ if (drm_compat_ioctls[nr] != NULL)
34910+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
34911 else
34912 ret = drm_ioctl(filp, cmd, arg);
34913
34914diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
34915index e77bd8b..1571b85 100644
34916--- a/drivers/gpu/drm/drm_ioctl.c
34917+++ b/drivers/gpu/drm/drm_ioctl.c
34918@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
34919 stats->data[i].value =
34920 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
34921 else
34922- stats->data[i].value = atomic_read(&dev->counts[i]);
34923+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
34924 stats->data[i].type = dev->types[i];
34925 }
34926
34927diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
34928index d752c96..fe08455 100644
34929--- a/drivers/gpu/drm/drm_lock.c
34930+++ b/drivers/gpu/drm/drm_lock.c
34931@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34932 if (drm_lock_take(&master->lock, lock->context)) {
34933 master->lock.file_priv = file_priv;
34934 master->lock.lock_time = jiffies;
34935- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
34936+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
34937 break; /* Got lock */
34938 }
34939
34940@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34941 return -EINVAL;
34942 }
34943
34944- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
34945+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
34946
34947 if (drm_lock_free(&master->lock, lock->context)) {
34948 /* FIXME: Should really bail out here. */
34949diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
34950index 200e104..59facda 100644
34951--- a/drivers/gpu/drm/drm_stub.c
34952+++ b/drivers/gpu/drm/drm_stub.c
34953@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
34954
34955 drm_device_set_unplugged(dev);
34956
34957- if (dev->open_count == 0) {
34958+ if (local_read(&dev->open_count) == 0) {
34959 drm_put_dev(dev);
34960 }
34961 mutex_unlock(&drm_global_mutex);
34962diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
34963index 004ecdf..db1f6e0 100644
34964--- a/drivers/gpu/drm/i810/i810_dma.c
34965+++ b/drivers/gpu/drm/i810/i810_dma.c
34966@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
34967 dma->buflist[vertex->idx],
34968 vertex->discard, vertex->used);
34969
34970- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34971- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34972+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34973+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34974 sarea_priv->last_enqueue = dev_priv->counter - 1;
34975 sarea_priv->last_dispatch = (int)hw_status[5];
34976
34977@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
34978 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
34979 mc->last_render);
34980
34981- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34982- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34983+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34984+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34985 sarea_priv->last_enqueue = dev_priv->counter - 1;
34986 sarea_priv->last_dispatch = (int)hw_status[5];
34987
34988diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
34989index 6e0acad..93c8289 100644
34990--- a/drivers/gpu/drm/i810/i810_drv.h
34991+++ b/drivers/gpu/drm/i810/i810_drv.h
34992@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
34993 int page_flipping;
34994
34995 wait_queue_head_t irq_queue;
34996- atomic_t irq_received;
34997- atomic_t irq_emitted;
34998+ atomic_unchecked_t irq_received;
34999+ atomic_unchecked_t irq_emitted;
35000
35001 int front_offset;
35002 } drm_i810_private_t;
35003diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35004index 8a7c48b..72effc2 100644
35005--- a/drivers/gpu/drm/i915/i915_debugfs.c
35006+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35007@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35008 I915_READ(GTIMR));
35009 }
35010 seq_printf(m, "Interrupts received: %d\n",
35011- atomic_read(&dev_priv->irq_received));
35012+ atomic_read_unchecked(&dev_priv->irq_received));
35013 for_each_ring(ring, dev_priv, i) {
35014 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35015 seq_printf(m,
35016diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35017index 99daa89..84ebd44 100644
35018--- a/drivers/gpu/drm/i915/i915_dma.c
35019+++ b/drivers/gpu/drm/i915/i915_dma.c
35020@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35021 bool can_switch;
35022
35023 spin_lock(&dev->count_lock);
35024- can_switch = (dev->open_count == 0);
35025+ can_switch = (local_read(&dev->open_count) == 0);
35026 spin_unlock(&dev->count_lock);
35027 return can_switch;
35028 }
35029diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35030index 7339a4b..445aaba 100644
35031--- a/drivers/gpu/drm/i915/i915_drv.h
35032+++ b/drivers/gpu/drm/i915/i915_drv.h
35033@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
35034 drm_dma_handle_t *status_page_dmah;
35035 struct resource mch_res;
35036
35037- atomic_t irq_received;
35038+ atomic_unchecked_t irq_received;
35039
35040 /* protects the irq masks */
35041 spinlock_t irq_lock;
35042@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
35043 * will be page flipped away on the next vblank. When it
35044 * reaches 0, dev_priv->pending_flip_queue will be woken up.
35045 */
35046- atomic_t pending_flip;
35047+ atomic_unchecked_t pending_flip;
35048 };
35049 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
35050
35051@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35052 struct drm_i915_private *dev_priv, unsigned port);
35053 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35054 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35055-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35056+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35057 {
35058 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35059 }
35060diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35061index 26d08bb..e24fb51 100644
35062--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35063+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35064@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
35065 i915_gem_clflush_object(obj);
35066
35067 if (obj->base.pending_write_domain)
35068- flips |= atomic_read(&obj->pending_flip);
35069+ flips |= atomic_read_unchecked(&obj->pending_flip);
35070
35071 flush_domains |= obj->base.write_domain;
35072 }
35073@@ -703,18 +703,23 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35074
35075 static int
35076 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35077- int count)
35078+ unsigned int count)
35079 {
35080- int i;
35081+ unsigned int i;
35082+ int relocs_total = 0;
35083+ int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35084
35085 for (i = 0; i < count; i++) {
35086 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
35087 int length; /* limited by fault_in_pages_readable() */
35088
35089- /* First check for malicious input causing overflow */
35090- if (exec[i].relocation_count >
35091- INT_MAX / sizeof(struct drm_i915_gem_relocation_entry))
35092+ /* First check for malicious input causing overflow in
35093+ * the worst case where we need to allocate the entire
35094+ * relocation tree as a single array.
35095+ */
35096+ if (exec[i].relocation_count > relocs_max - relocs_total)
35097 return -EINVAL;
35098+ relocs_total += exec[i].relocation_count;
35099
35100 length = exec[i].relocation_count *
35101 sizeof(struct drm_i915_gem_relocation_entry);
35102@@ -1197,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35103 return -ENOMEM;
35104 }
35105 ret = copy_from_user(exec2_list,
35106- (struct drm_i915_relocation_entry __user *)
35107+ (struct drm_i915_gem_exec_object2 __user *)
35108 (uintptr_t) args->buffers_ptr,
35109 sizeof(*exec2_list) * args->buffer_count);
35110 if (ret != 0) {
35111diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35112index 3c59584..500f2e9 100644
35113--- a/drivers/gpu/drm/i915/i915_ioc32.c
35114+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35115@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35116 (unsigned long)request);
35117 }
35118
35119-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35120+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35121 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35122 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35123 [DRM_I915_GETPARAM] = compat_i915_getparam,
35124@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35125 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35126 {
35127 unsigned int nr = DRM_IOCTL_NR(cmd);
35128- drm_ioctl_compat_t *fn = NULL;
35129 int ret;
35130
35131 if (nr < DRM_COMMAND_BASE)
35132 return drm_compat_ioctl(filp, cmd, arg);
35133
35134- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35135- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35136-
35137- if (fn != NULL)
35138+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35139+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35140 ret = (*fn) (filp, cmd, arg);
35141- else
35142+ } else
35143 ret = drm_ioctl(filp, cmd, arg);
35144
35145 return ret;
35146diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35147index fe84338..a863190 100644
35148--- a/drivers/gpu/drm/i915/i915_irq.c
35149+++ b/drivers/gpu/drm/i915/i915_irq.c
35150@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35151 u32 pipe_stats[I915_MAX_PIPES];
35152 bool blc_event;
35153
35154- atomic_inc(&dev_priv->irq_received);
35155+ atomic_inc_unchecked(&dev_priv->irq_received);
35156
35157 while (true) {
35158 iir = I915_READ(VLV_IIR);
35159@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35160 irqreturn_t ret = IRQ_NONE;
35161 int i;
35162
35163- atomic_inc(&dev_priv->irq_received);
35164+ atomic_inc_unchecked(&dev_priv->irq_received);
35165
35166 /* disable master interrupt before clearing iir */
35167 de_ier = I915_READ(DEIER);
35168@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35169 int ret = IRQ_NONE;
35170 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
35171
35172- atomic_inc(&dev_priv->irq_received);
35173+ atomic_inc_unchecked(&dev_priv->irq_received);
35174
35175 /* disable master interrupt before clearing iir */
35176 de_ier = I915_READ(DEIER);
35177@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35178 {
35179 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35180
35181- atomic_set(&dev_priv->irq_received, 0);
35182+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35183
35184 I915_WRITE(HWSTAM, 0xeffe);
35185
35186@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35187 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35188 int pipe;
35189
35190- atomic_set(&dev_priv->irq_received, 0);
35191+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35192
35193 /* VLV magic */
35194 I915_WRITE(VLV_IMR, 0);
35195@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35196 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35197 int pipe;
35198
35199- atomic_set(&dev_priv->irq_received, 0);
35200+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35201
35202 for_each_pipe(pipe)
35203 I915_WRITE(PIPESTAT(pipe), 0);
35204@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35205 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35206 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35207
35208- atomic_inc(&dev_priv->irq_received);
35209+ atomic_inc_unchecked(&dev_priv->irq_received);
35210
35211 iir = I915_READ16(IIR);
35212 if (iir == 0)
35213@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35214 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35215 int pipe;
35216
35217- atomic_set(&dev_priv->irq_received, 0);
35218+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35219
35220 if (I915_HAS_HOTPLUG(dev)) {
35221 I915_WRITE(PORT_HOTPLUG_EN, 0);
35222@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35223 };
35224 int pipe, ret = IRQ_NONE;
35225
35226- atomic_inc(&dev_priv->irq_received);
35227+ atomic_inc_unchecked(&dev_priv->irq_received);
35228
35229 iir = I915_READ(IIR);
35230 do {
35231@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35232 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35233 int pipe;
35234
35235- atomic_set(&dev_priv->irq_received, 0);
35236+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35237
35238 I915_WRITE(PORT_HOTPLUG_EN, 0);
35239 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35240@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35241 int irq_received;
35242 int ret = IRQ_NONE, pipe;
35243
35244- atomic_inc(&dev_priv->irq_received);
35245+ atomic_inc_unchecked(&dev_priv->irq_received);
35246
35247 iir = I915_READ(IIR);
35248
35249diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35250index 80aa1fc..85cfce3 100644
35251--- a/drivers/gpu/drm/i915/intel_display.c
35252+++ b/drivers/gpu/drm/i915/intel_display.c
35253@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35254
35255 wait_event(dev_priv->pending_flip_queue,
35256 atomic_read(&dev_priv->mm.wedged) ||
35257- atomic_read(&obj->pending_flip) == 0);
35258+ atomic_read_unchecked(&obj->pending_flip) == 0);
35259
35260 /* Big Hammer, we also need to ensure that any pending
35261 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35262@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35263
35264 obj = work->old_fb_obj;
35265
35266- atomic_clear_mask(1 << intel_crtc->plane,
35267- &obj->pending_flip.counter);
35268+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35269 wake_up(&dev_priv->pending_flip_queue);
35270
35271 queue_work(dev_priv->wq, &work->work);
35272@@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35273 /* Block clients from rendering to the new back buffer until
35274 * the flip occurs and the object is no longer visible.
35275 */
35276- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35277+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35278 atomic_inc(&intel_crtc->unpin_work_count);
35279
35280 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35281@@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35282
35283 cleanup_pending:
35284 atomic_dec(&intel_crtc->unpin_work_count);
35285- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35286+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35287 drm_gem_object_unreference(&work->old_fb_obj->base);
35288 drm_gem_object_unreference(&obj->base);
35289 mutex_unlock(&dev->struct_mutex);
35290@@ -8849,13 +8848,13 @@ struct intel_quirk {
35291 int subsystem_vendor;
35292 int subsystem_device;
35293 void (*hook)(struct drm_device *dev);
35294-};
35295+} __do_const;
35296
35297 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35298 struct intel_dmi_quirk {
35299 void (*hook)(struct drm_device *dev);
35300 const struct dmi_system_id (*dmi_id_list)[];
35301-};
35302+} __do_const;
35303
35304 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35305 {
35306@@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35307 return 1;
35308 }
35309
35310+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35311+ {
35312+ .callback = intel_dmi_reverse_brightness,
35313+ .ident = "NCR Corporation",
35314+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35315+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35316+ },
35317+ },
35318+ { } /* terminating entry */
35319+};
35320+
35321 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35322 {
35323- .dmi_id_list = &(const struct dmi_system_id[]) {
35324- {
35325- .callback = intel_dmi_reverse_brightness,
35326- .ident = "NCR Corporation",
35327- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35328- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35329- },
35330- },
35331- { } /* terminating entry */
35332- },
35333+ .dmi_id_list = &intel_dmi_quirks_table,
35334 .hook = quirk_invert_brightness,
35335 },
35336 };
35337diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35338index 54558a0..2d97005 100644
35339--- a/drivers/gpu/drm/mga/mga_drv.h
35340+++ b/drivers/gpu/drm/mga/mga_drv.h
35341@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35342 u32 clear_cmd;
35343 u32 maccess;
35344
35345- atomic_t vbl_received; /**< Number of vblanks received. */
35346+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35347 wait_queue_head_t fence_queue;
35348- atomic_t last_fence_retired;
35349+ atomic_unchecked_t last_fence_retired;
35350 u32 next_fence_to_post;
35351
35352 unsigned int fb_cpp;
35353diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35354index 709e90d..89a1c0d 100644
35355--- a/drivers/gpu/drm/mga/mga_ioc32.c
35356+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35357@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35358 return 0;
35359 }
35360
35361-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35362+drm_ioctl_compat_t mga_compat_ioctls[] = {
35363 [DRM_MGA_INIT] = compat_mga_init,
35364 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35365 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35366@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35367 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35368 {
35369 unsigned int nr = DRM_IOCTL_NR(cmd);
35370- drm_ioctl_compat_t *fn = NULL;
35371 int ret;
35372
35373 if (nr < DRM_COMMAND_BASE)
35374 return drm_compat_ioctl(filp, cmd, arg);
35375
35376- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35377- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35378-
35379- if (fn != NULL)
35380+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35381+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35382 ret = (*fn) (filp, cmd, arg);
35383- else
35384+ } else
35385 ret = drm_ioctl(filp, cmd, arg);
35386
35387 return ret;
35388diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35389index 598c281..60d590e 100644
35390--- a/drivers/gpu/drm/mga/mga_irq.c
35391+++ b/drivers/gpu/drm/mga/mga_irq.c
35392@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35393 if (crtc != 0)
35394 return 0;
35395
35396- return atomic_read(&dev_priv->vbl_received);
35397+ return atomic_read_unchecked(&dev_priv->vbl_received);
35398 }
35399
35400
35401@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35402 /* VBLANK interrupt */
35403 if (status & MGA_VLINEPEN) {
35404 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35405- atomic_inc(&dev_priv->vbl_received);
35406+ atomic_inc_unchecked(&dev_priv->vbl_received);
35407 drm_handle_vblank(dev, 0);
35408 handled = 1;
35409 }
35410@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35411 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35412 MGA_WRITE(MGA_PRIMEND, prim_end);
35413
35414- atomic_inc(&dev_priv->last_fence_retired);
35415+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35416 DRM_WAKEUP(&dev_priv->fence_queue);
35417 handled = 1;
35418 }
35419@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35420 * using fences.
35421 */
35422 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35423- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35424+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35425 - *sequence) <= (1 << 23)));
35426
35427 *sequence = cur_fence;
35428diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35429index 865eddf..62c4cc3 100644
35430--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35431+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35432@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35433 struct bit_table {
35434 const char id;
35435 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35436-};
35437+} __no_const;
35438
35439 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35440
35441diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35442index aa89eb9..d45d38b 100644
35443--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35444+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35445@@ -80,7 +80,7 @@ struct nouveau_drm {
35446 struct drm_global_reference mem_global_ref;
35447 struct ttm_bo_global_ref bo_global_ref;
35448 struct ttm_bo_device bdev;
35449- atomic_t validate_sequence;
35450+ atomic_unchecked_t validate_sequence;
35451 int (*move)(struct nouveau_channel *,
35452 struct ttm_buffer_object *,
35453 struct ttm_mem_reg *, struct ttm_mem_reg *);
35454diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35455index cdb83ac..27f0a16 100644
35456--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35457+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35458@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35459 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35460 struct nouveau_channel *);
35461 u32 (*read)(struct nouveau_channel *);
35462-};
35463+} __no_const;
35464
35465 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35466
35467diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35468index 8bf695c..9fbc90a 100644
35469--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35470+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35471@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35472 int trycnt = 0;
35473 int ret, i;
35474
35475- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35476+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35477 retry:
35478 if (++trycnt > 100000) {
35479 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35480diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35481index 08214bc..9208577 100644
35482--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35483+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35484@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35485 unsigned long arg)
35486 {
35487 unsigned int nr = DRM_IOCTL_NR(cmd);
35488- drm_ioctl_compat_t *fn = NULL;
35489+ drm_ioctl_compat_t fn = NULL;
35490 int ret;
35491
35492 if (nr < DRM_COMMAND_BASE)
35493diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35494index 25d3495..d81aaf6 100644
35495--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35496+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35497@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35498 bool can_switch;
35499
35500 spin_lock(&dev->count_lock);
35501- can_switch = (dev->open_count == 0);
35502+ can_switch = (local_read(&dev->open_count) == 0);
35503 spin_unlock(&dev->count_lock);
35504 return can_switch;
35505 }
35506diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35507index d4660cf..70dbe65 100644
35508--- a/drivers/gpu/drm/r128/r128_cce.c
35509+++ b/drivers/gpu/drm/r128/r128_cce.c
35510@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35511
35512 /* GH: Simple idle check.
35513 */
35514- atomic_set(&dev_priv->idle_count, 0);
35515+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35516
35517 /* We don't support anything other than bus-mastering ring mode,
35518 * but the ring can be in either AGP or PCI space for the ring
35519diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35520index 930c71b..499aded 100644
35521--- a/drivers/gpu/drm/r128/r128_drv.h
35522+++ b/drivers/gpu/drm/r128/r128_drv.h
35523@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35524 int is_pci;
35525 unsigned long cce_buffers_offset;
35526
35527- atomic_t idle_count;
35528+ atomic_unchecked_t idle_count;
35529
35530 int page_flipping;
35531 int current_page;
35532 u32 crtc_offset;
35533 u32 crtc_offset_cntl;
35534
35535- atomic_t vbl_received;
35536+ atomic_unchecked_t vbl_received;
35537
35538 u32 color_fmt;
35539 unsigned int front_offset;
35540diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35541index a954c54..9cc595c 100644
35542--- a/drivers/gpu/drm/r128/r128_ioc32.c
35543+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35544@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35545 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35546 }
35547
35548-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35549+drm_ioctl_compat_t r128_compat_ioctls[] = {
35550 [DRM_R128_INIT] = compat_r128_init,
35551 [DRM_R128_DEPTH] = compat_r128_depth,
35552 [DRM_R128_STIPPLE] = compat_r128_stipple,
35553@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35554 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35555 {
35556 unsigned int nr = DRM_IOCTL_NR(cmd);
35557- drm_ioctl_compat_t *fn = NULL;
35558 int ret;
35559
35560 if (nr < DRM_COMMAND_BASE)
35561 return drm_compat_ioctl(filp, cmd, arg);
35562
35563- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35564- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35565-
35566- if (fn != NULL)
35567+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35568+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35569 ret = (*fn) (filp, cmd, arg);
35570- else
35571+ } else
35572 ret = drm_ioctl(filp, cmd, arg);
35573
35574 return ret;
35575diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35576index 2ea4f09..d391371 100644
35577--- a/drivers/gpu/drm/r128/r128_irq.c
35578+++ b/drivers/gpu/drm/r128/r128_irq.c
35579@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35580 if (crtc != 0)
35581 return 0;
35582
35583- return atomic_read(&dev_priv->vbl_received);
35584+ return atomic_read_unchecked(&dev_priv->vbl_received);
35585 }
35586
35587 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35588@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35589 /* VBLANK interrupt */
35590 if (status & R128_CRTC_VBLANK_INT) {
35591 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35592- atomic_inc(&dev_priv->vbl_received);
35593+ atomic_inc_unchecked(&dev_priv->vbl_received);
35594 drm_handle_vblank(dev, 0);
35595 return IRQ_HANDLED;
35596 }
35597diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35598index 19bb7e6..de7e2a2 100644
35599--- a/drivers/gpu/drm/r128/r128_state.c
35600+++ b/drivers/gpu/drm/r128/r128_state.c
35601@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35602
35603 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35604 {
35605- if (atomic_read(&dev_priv->idle_count) == 0)
35606+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35607 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35608 else
35609- atomic_set(&dev_priv->idle_count, 0);
35610+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35611 }
35612
35613 #endif
35614diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35615index 5a82b6b..9e69c73 100644
35616--- a/drivers/gpu/drm/radeon/mkregtable.c
35617+++ b/drivers/gpu/drm/radeon/mkregtable.c
35618@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35619 regex_t mask_rex;
35620 regmatch_t match[4];
35621 char buf[1024];
35622- size_t end;
35623+ long end;
35624 int len;
35625 int done = 0;
35626 int r;
35627 unsigned o;
35628 struct offset *offset;
35629 char last_reg_s[10];
35630- int last_reg;
35631+ unsigned long last_reg;
35632
35633 if (regcomp
35634 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35635diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35636index 0d6562b..a154330 100644
35637--- a/drivers/gpu/drm/radeon/radeon_device.c
35638+++ b/drivers/gpu/drm/radeon/radeon_device.c
35639@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35640 bool can_switch;
35641
35642 spin_lock(&dev->count_lock);
35643- can_switch = (dev->open_count == 0);
35644+ can_switch = (local_read(&dev->open_count) == 0);
35645 spin_unlock(&dev->count_lock);
35646 return can_switch;
35647 }
35648diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35649index e7fdf16..f4f6490 100644
35650--- a/drivers/gpu/drm/radeon/radeon_drv.h
35651+++ b/drivers/gpu/drm/radeon/radeon_drv.h
35652@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35653
35654 /* SW interrupt */
35655 wait_queue_head_t swi_queue;
35656- atomic_t swi_emitted;
35657+ atomic_unchecked_t swi_emitted;
35658 int vblank_crtc;
35659 uint32_t irq_enable_reg;
35660 uint32_t r500_disp_irq_reg;
35661diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35662index c180df8..5fd8186 100644
35663--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35664+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35665@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35666 request = compat_alloc_user_space(sizeof(*request));
35667 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35668 || __put_user(req32.param, &request->param)
35669- || __put_user((void __user *)(unsigned long)req32.value,
35670+ || __put_user((unsigned long)req32.value,
35671 &request->value))
35672 return -EFAULT;
35673
35674@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35675 #define compat_radeon_cp_setparam NULL
35676 #endif /* X86_64 || IA64 */
35677
35678-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35679+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35680 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35681 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35682 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35683@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35684 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35685 {
35686 unsigned int nr = DRM_IOCTL_NR(cmd);
35687- drm_ioctl_compat_t *fn = NULL;
35688 int ret;
35689
35690 if (nr < DRM_COMMAND_BASE)
35691 return drm_compat_ioctl(filp, cmd, arg);
35692
35693- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35694- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35695-
35696- if (fn != NULL)
35697+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35698+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35699 ret = (*fn) (filp, cmd, arg);
35700- else
35701+ } else
35702 ret = drm_ioctl(filp, cmd, arg);
35703
35704 return ret;
35705diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35706index e771033..a0bc6b3 100644
35707--- a/drivers/gpu/drm/radeon/radeon_irq.c
35708+++ b/drivers/gpu/drm/radeon/radeon_irq.c
35709@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35710 unsigned int ret;
35711 RING_LOCALS;
35712
35713- atomic_inc(&dev_priv->swi_emitted);
35714- ret = atomic_read(&dev_priv->swi_emitted);
35715+ atomic_inc_unchecked(&dev_priv->swi_emitted);
35716+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35717
35718 BEGIN_RING(4);
35719 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35720@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35721 drm_radeon_private_t *dev_priv =
35722 (drm_radeon_private_t *) dev->dev_private;
35723
35724- atomic_set(&dev_priv->swi_emitted, 0);
35725+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35726 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35727
35728 dev->max_vblank_count = 0x001fffff;
35729diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35730index 8e9057b..af6dacb 100644
35731--- a/drivers/gpu/drm/radeon/radeon_state.c
35732+++ b/drivers/gpu/drm/radeon/radeon_state.c
35733@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35734 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35735 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35736
35737- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35738+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35739 sarea_priv->nbox * sizeof(depth_boxes[0])))
35740 return -EFAULT;
35741
35742@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35743 {
35744 drm_radeon_private_t *dev_priv = dev->dev_private;
35745 drm_radeon_getparam_t *param = data;
35746- int value;
35747+ int value = 0;
35748
35749 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35750
35751diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35752index 93f760e..8088227 100644
35753--- a/drivers/gpu/drm/radeon/radeon_ttm.c
35754+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35755@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35756 man->size = size >> PAGE_SHIFT;
35757 }
35758
35759-static struct vm_operations_struct radeon_ttm_vm_ops;
35760+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35761 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35762
35763 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35764@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35765 }
35766 if (unlikely(ttm_vm_ops == NULL)) {
35767 ttm_vm_ops = vma->vm_ops;
35768+ pax_open_kernel();
35769 radeon_ttm_vm_ops = *ttm_vm_ops;
35770 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35771+ pax_close_kernel();
35772 }
35773 vma->vm_ops = &radeon_ttm_vm_ops;
35774 return 0;
35775@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35776 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35777 else
35778 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35779- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35780- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35781- radeon_mem_types_list[i].driver_features = 0;
35782+ pax_open_kernel();
35783+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35784+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35785+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35786 if (i == 0)
35787- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35788+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35789 else
35790- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35791-
35792+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35793+ pax_close_kernel();
35794 }
35795 /* Add ttm page pool to debugfs */
35796 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35797- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35798- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35799- radeon_mem_types_list[i].driver_features = 0;
35800- radeon_mem_types_list[i++].data = NULL;
35801+ pax_open_kernel();
35802+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35803+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35804+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35805+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35806+ pax_close_kernel();
35807 #ifdef CONFIG_SWIOTLB
35808 if (swiotlb_nr_tbl()) {
35809 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35810- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35811- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35812- radeon_mem_types_list[i].driver_features = 0;
35813- radeon_mem_types_list[i++].data = NULL;
35814+ pax_open_kernel();
35815+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35816+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35817+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35818+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35819+ pax_close_kernel();
35820 }
35821 #endif
35822 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35823diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35824index 5706d2a..17aedaa 100644
35825--- a/drivers/gpu/drm/radeon/rs690.c
35826+++ b/drivers/gpu/drm/radeon/rs690.c
35827@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35828 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35829 rdev->pm.sideport_bandwidth.full)
35830 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35831- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35832+ read_delay_latency.full = dfixed_const(800 * 1000);
35833 read_delay_latency.full = dfixed_div(read_delay_latency,
35834 rdev->pm.igp_sideport_mclk);
35835+ a.full = dfixed_const(370);
35836+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35837 } else {
35838 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35839 rdev->pm.k8_bandwidth.full)
35840diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35841index bd2a3b4..122d9ad 100644
35842--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35843+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35844@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35845 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35846 struct shrink_control *sc)
35847 {
35848- static atomic_t start_pool = ATOMIC_INIT(0);
35849+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35850 unsigned i;
35851- unsigned pool_offset = atomic_add_return(1, &start_pool);
35852+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35853 struct ttm_page_pool *pool;
35854 int shrink_pages = sc->nr_to_scan;
35855
35856diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35857index 1eb060c..188b1fc 100644
35858--- a/drivers/gpu/drm/udl/udl_fb.c
35859+++ b/drivers/gpu/drm/udl/udl_fb.c
35860@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35861 fb_deferred_io_cleanup(info);
35862 kfree(info->fbdefio);
35863 info->fbdefio = NULL;
35864- info->fbops->fb_mmap = udl_fb_mmap;
35865 }
35866
35867 pr_warn("released /dev/fb%d user=%d count=%d\n",
35868diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35869index 893a650..6190d3b 100644
35870--- a/drivers/gpu/drm/via/via_drv.h
35871+++ b/drivers/gpu/drm/via/via_drv.h
35872@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35873 typedef uint32_t maskarray_t[5];
35874
35875 typedef struct drm_via_irq {
35876- atomic_t irq_received;
35877+ atomic_unchecked_t irq_received;
35878 uint32_t pending_mask;
35879 uint32_t enable_mask;
35880 wait_queue_head_t irq_queue;
35881@@ -75,7 +75,7 @@ typedef struct drm_via_private {
35882 struct timeval last_vblank;
35883 int last_vblank_valid;
35884 unsigned usec_per_vblank;
35885- atomic_t vbl_received;
35886+ atomic_unchecked_t vbl_received;
35887 drm_via_state_t hc_state;
35888 char pci_buf[VIA_PCI_BUF_SIZE];
35889 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35890diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35891index ac98964..5dbf512 100644
35892--- a/drivers/gpu/drm/via/via_irq.c
35893+++ b/drivers/gpu/drm/via/via_irq.c
35894@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35895 if (crtc != 0)
35896 return 0;
35897
35898- return atomic_read(&dev_priv->vbl_received);
35899+ return atomic_read_unchecked(&dev_priv->vbl_received);
35900 }
35901
35902 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35903@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35904
35905 status = VIA_READ(VIA_REG_INTERRUPT);
35906 if (status & VIA_IRQ_VBLANK_PENDING) {
35907- atomic_inc(&dev_priv->vbl_received);
35908- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35909+ atomic_inc_unchecked(&dev_priv->vbl_received);
35910+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35911 do_gettimeofday(&cur_vblank);
35912 if (dev_priv->last_vblank_valid) {
35913 dev_priv->usec_per_vblank =
35914@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35915 dev_priv->last_vblank = cur_vblank;
35916 dev_priv->last_vblank_valid = 1;
35917 }
35918- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35919+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35920 DRM_DEBUG("US per vblank is: %u\n",
35921 dev_priv->usec_per_vblank);
35922 }
35923@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35924
35925 for (i = 0; i < dev_priv->num_irqs; ++i) {
35926 if (status & cur_irq->pending_mask) {
35927- atomic_inc(&cur_irq->irq_received);
35928+ atomic_inc_unchecked(&cur_irq->irq_received);
35929 DRM_WAKEUP(&cur_irq->irq_queue);
35930 handled = 1;
35931 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35932@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35933 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35934 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35935 masks[irq][4]));
35936- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35937+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35938 } else {
35939 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35940 (((cur_irq_sequence =
35941- atomic_read(&cur_irq->irq_received)) -
35942+ atomic_read_unchecked(&cur_irq->irq_received)) -
35943 *sequence) <= (1 << 23)));
35944 }
35945 *sequence = cur_irq_sequence;
35946@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35947 }
35948
35949 for (i = 0; i < dev_priv->num_irqs; ++i) {
35950- atomic_set(&cur_irq->irq_received, 0);
35951+ atomic_set_unchecked(&cur_irq->irq_received, 0);
35952 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35953 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35954 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35955@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35956 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35957 case VIA_IRQ_RELATIVE:
35958 irqwait->request.sequence +=
35959- atomic_read(&cur_irq->irq_received);
35960+ atomic_read_unchecked(&cur_irq->irq_received);
35961 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35962 case VIA_IRQ_ABSOLUTE:
35963 break;
35964diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35965index 13aeda7..4a952d1 100644
35966--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35967+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35968@@ -290,7 +290,7 @@ struct vmw_private {
35969 * Fencing and IRQs.
35970 */
35971
35972- atomic_t marker_seq;
35973+ atomic_unchecked_t marker_seq;
35974 wait_queue_head_t fence_queue;
35975 wait_queue_head_t fifo_queue;
35976 int fence_queue_waiters; /* Protected by hw_mutex */
35977diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35978index 3eb1486..0a47ee9 100644
35979--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35980+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35981@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35982 (unsigned int) min,
35983 (unsigned int) fifo->capabilities);
35984
35985- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35986+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35987 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35988 vmw_marker_queue_init(&fifo->marker_queue);
35989 return vmw_fifo_send_fence(dev_priv, &dummy);
35990@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35991 if (reserveable)
35992 iowrite32(bytes, fifo_mem +
35993 SVGA_FIFO_RESERVED);
35994- return fifo_mem + (next_cmd >> 2);
35995+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
35996 } else {
35997 need_bounce = true;
35998 }
35999@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36000
36001 fm = vmw_fifo_reserve(dev_priv, bytes);
36002 if (unlikely(fm == NULL)) {
36003- *seqno = atomic_read(&dev_priv->marker_seq);
36004+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36005 ret = -ENOMEM;
36006 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36007 false, 3*HZ);
36008@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36009 }
36010
36011 do {
36012- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36013+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36014 } while (*seqno == 0);
36015
36016 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36017diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36018index 4640adb..e1384ed 100644
36019--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36020+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36021@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36022 * emitted. Then the fence is stale and signaled.
36023 */
36024
36025- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36026+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36027 > VMW_FENCE_WRAP);
36028
36029 return ret;
36030@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36031
36032 if (fifo_idle)
36033 down_read(&fifo_state->rwsem);
36034- signal_seq = atomic_read(&dev_priv->marker_seq);
36035+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36036 ret = 0;
36037
36038 for (;;) {
36039diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36040index 8a8725c..afed796 100644
36041--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36042+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36043@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36044 while (!vmw_lag_lt(queue, us)) {
36045 spin_lock(&queue->lock);
36046 if (list_empty(&queue->head))
36047- seqno = atomic_read(&dev_priv->marker_seq);
36048+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36049 else {
36050 marker = list_first_entry(&queue->head,
36051 struct vmw_marker, head);
36052diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36053index ceb3040..6160c5c 100644
36054--- a/drivers/hid/hid-core.c
36055+++ b/drivers/hid/hid-core.c
36056@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36057
36058 int hid_add_device(struct hid_device *hdev)
36059 {
36060- static atomic_t id = ATOMIC_INIT(0);
36061+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36062 int ret;
36063
36064 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36065@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
36066 /* XXX hack, any other cleaner solution after the driver core
36067 * is converted to allow more than 20 bytes as the device name? */
36068 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36069- hdev->vendor, hdev->product, atomic_inc_return(&id));
36070+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36071
36072 hid_debug_register(hdev, dev_name(&hdev->dev));
36073 ret = device_add(&hdev->dev);
36074diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36075index eec3291..8ed706b 100644
36076--- a/drivers/hid/hid-wiimote-debug.c
36077+++ b/drivers/hid/hid-wiimote-debug.c
36078@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36079 else if (size == 0)
36080 return -EIO;
36081
36082- if (copy_to_user(u, buf, size))
36083+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36084 return -EFAULT;
36085
36086 *off += size;
36087diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36088index 773a2f2..7ce08bc 100644
36089--- a/drivers/hv/channel.c
36090+++ b/drivers/hv/channel.c
36091@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36092 int ret = 0;
36093 int t;
36094
36095- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36096- atomic_inc(&vmbus_connection.next_gpadl_handle);
36097+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36098+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36099
36100 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36101 if (ret)
36102diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36103index 3648f8f..30ef30d 100644
36104--- a/drivers/hv/hv.c
36105+++ b/drivers/hv/hv.c
36106@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36107 u64 output_address = (output) ? virt_to_phys(output) : 0;
36108 u32 output_address_hi = output_address >> 32;
36109 u32 output_address_lo = output_address & 0xFFFFFFFF;
36110- void *hypercall_page = hv_context.hypercall_page;
36111+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36112
36113 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36114 "=a"(hv_status_lo) : "d" (control_hi),
36115diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36116index d8d1fad..b91caf7 100644
36117--- a/drivers/hv/hyperv_vmbus.h
36118+++ b/drivers/hv/hyperv_vmbus.h
36119@@ -594,7 +594,7 @@ enum vmbus_connect_state {
36120 struct vmbus_connection {
36121 enum vmbus_connect_state conn_state;
36122
36123- atomic_t next_gpadl_handle;
36124+ atomic_unchecked_t next_gpadl_handle;
36125
36126 /*
36127 * Represents channel interrupts. Each bit position represents a
36128diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36129index 8e1a9ec..4687821 100644
36130--- a/drivers/hv/vmbus_drv.c
36131+++ b/drivers/hv/vmbus_drv.c
36132@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36133 {
36134 int ret = 0;
36135
36136- static atomic_t device_num = ATOMIC_INIT(0);
36137+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36138
36139 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36140- atomic_inc_return(&device_num));
36141+ atomic_inc_return_unchecked(&device_num));
36142
36143 child_device_obj->device.bus = &hv_bus;
36144 child_device_obj->device.parent = &hv_acpi_dev->dev;
36145diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36146index 1672e2a..4a6297c 100644
36147--- a/drivers/hwmon/acpi_power_meter.c
36148+++ b/drivers/hwmon/acpi_power_meter.c
36149@@ -117,7 +117,7 @@ struct sensor_template {
36150 struct device_attribute *devattr,
36151 const char *buf, size_t count);
36152 int index;
36153-};
36154+} __do_const;
36155
36156 /* Averaging interval */
36157 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36158@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36159 struct sensor_template *attrs)
36160 {
36161 struct device *dev = &resource->acpi_dev->dev;
36162- struct sensor_device_attribute *sensors =
36163+ sensor_device_attribute_no_const *sensors =
36164 &resource->sensors[resource->num_sensors];
36165 int res = 0;
36166
36167diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36168index b41baff..4953e4d 100644
36169--- a/drivers/hwmon/applesmc.c
36170+++ b/drivers/hwmon/applesmc.c
36171@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36172 {
36173 struct applesmc_node_group *grp;
36174 struct applesmc_dev_attr *node;
36175- struct attribute *attr;
36176+ attribute_no_const *attr;
36177 int ret, i;
36178
36179 for (grp = groups; grp->format; grp++) {
36180diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36181index 56dbcfb..9874bf1 100644
36182--- a/drivers/hwmon/asus_atk0110.c
36183+++ b/drivers/hwmon/asus_atk0110.c
36184@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36185 struct atk_sensor_data {
36186 struct list_head list;
36187 struct atk_data *data;
36188- struct device_attribute label_attr;
36189- struct device_attribute input_attr;
36190- struct device_attribute limit1_attr;
36191- struct device_attribute limit2_attr;
36192+ device_attribute_no_const label_attr;
36193+ device_attribute_no_const input_attr;
36194+ device_attribute_no_const limit1_attr;
36195+ device_attribute_no_const limit2_attr;
36196 char label_attr_name[ATTR_NAME_SIZE];
36197 char input_attr_name[ATTR_NAME_SIZE];
36198 char limit1_attr_name[ATTR_NAME_SIZE];
36199@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36200 static struct device_attribute atk_name_attr =
36201 __ATTR(name, 0444, atk_name_show, NULL);
36202
36203-static void atk_init_attribute(struct device_attribute *attr, char *name,
36204+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36205 sysfs_show_func show)
36206 {
36207 sysfs_attr_init(&attr->attr);
36208diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36209index d64923d..72591e8 100644
36210--- a/drivers/hwmon/coretemp.c
36211+++ b/drivers/hwmon/coretemp.c
36212@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36213 return NOTIFY_OK;
36214 }
36215
36216-static struct notifier_block coretemp_cpu_notifier __refdata = {
36217+static struct notifier_block coretemp_cpu_notifier = {
36218 .notifier_call = coretemp_cpu_callback,
36219 };
36220
36221diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36222index a14f634..2916ee2 100644
36223--- a/drivers/hwmon/ibmaem.c
36224+++ b/drivers/hwmon/ibmaem.c
36225@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36226 struct aem_rw_sensor_template *rw)
36227 {
36228 struct device *dev = &data->pdev->dev;
36229- struct sensor_device_attribute *sensors = data->sensors;
36230+ sensor_device_attribute_no_const *sensors = data->sensors;
36231 int err;
36232
36233 /* Set up read-only sensors */
36234diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36235index 7d19b1b..8fdaaac 100644
36236--- a/drivers/hwmon/pmbus/pmbus_core.c
36237+++ b/drivers/hwmon/pmbus/pmbus_core.c
36238@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36239
36240 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36241 do { \
36242- struct sensor_device_attribute *a \
36243+ sensor_device_attribute_no_const *a \
36244 = &data->_type##s[data->num_##_type##s].attribute; \
36245 BUG_ON(data->num_attributes >= data->max_attributes); \
36246 sysfs_attr_init(&a->dev_attr.attr); \
36247diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36248index 8047fed..1e956f0 100644
36249--- a/drivers/hwmon/sht15.c
36250+++ b/drivers/hwmon/sht15.c
36251@@ -169,7 +169,7 @@ struct sht15_data {
36252 int supply_uV;
36253 bool supply_uV_valid;
36254 struct work_struct update_supply_work;
36255- atomic_t interrupt_handled;
36256+ atomic_unchecked_t interrupt_handled;
36257 };
36258
36259 /**
36260@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36261 return ret;
36262
36263 gpio_direction_input(data->pdata->gpio_data);
36264- atomic_set(&data->interrupt_handled, 0);
36265+ atomic_set_unchecked(&data->interrupt_handled, 0);
36266
36267 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36268 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36269 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36270 /* Only relevant if the interrupt hasn't occurred. */
36271- if (!atomic_read(&data->interrupt_handled))
36272+ if (!atomic_read_unchecked(&data->interrupt_handled))
36273 schedule_work(&data->read_work);
36274 }
36275 ret = wait_event_timeout(data->wait_queue,
36276@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36277
36278 /* First disable the interrupt */
36279 disable_irq_nosync(irq);
36280- atomic_inc(&data->interrupt_handled);
36281+ atomic_inc_unchecked(&data->interrupt_handled);
36282 /* Then schedule a reading work struct */
36283 if (data->state != SHT15_READING_NOTHING)
36284 schedule_work(&data->read_work);
36285@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36286 * If not, then start the interrupt again - care here as could
36287 * have gone low in meantime so verify it hasn't!
36288 */
36289- atomic_set(&data->interrupt_handled, 0);
36290+ atomic_set_unchecked(&data->interrupt_handled, 0);
36291 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36292 /* If still not occurred or another handler was scheduled */
36293 if (gpio_get_value(data->pdata->gpio_data)
36294- || atomic_read(&data->interrupt_handled))
36295+ || atomic_read_unchecked(&data->interrupt_handled))
36296 return;
36297 }
36298
36299diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36300index 76f157b..9c0db1b 100644
36301--- a/drivers/hwmon/via-cputemp.c
36302+++ b/drivers/hwmon/via-cputemp.c
36303@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36304 return NOTIFY_OK;
36305 }
36306
36307-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36308+static struct notifier_block via_cputemp_cpu_notifier = {
36309 .notifier_call = via_cputemp_cpu_callback,
36310 };
36311
36312diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36313index 378fcb5..5e91fa8 100644
36314--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36315+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36316@@ -43,7 +43,7 @@
36317 extern struct i2c_adapter amd756_smbus;
36318
36319 static struct i2c_adapter *s4882_adapter;
36320-static struct i2c_algorithm *s4882_algo;
36321+static i2c_algorithm_no_const *s4882_algo;
36322
36323 /* Wrapper access functions for multiplexed SMBus */
36324 static DEFINE_MUTEX(amd756_lock);
36325diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36326index 29015eb..af2d8e9 100644
36327--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36328+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36329@@ -41,7 +41,7 @@
36330 extern struct i2c_adapter *nforce2_smbus;
36331
36332 static struct i2c_adapter *s4985_adapter;
36333-static struct i2c_algorithm *s4985_algo;
36334+static i2c_algorithm_no_const *s4985_algo;
36335
36336 /* Wrapper access functions for multiplexed SMBus */
36337 static DEFINE_MUTEX(nforce2_lock);
36338diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36339index 8126824..55a2798 100644
36340--- a/drivers/ide/ide-cd.c
36341+++ b/drivers/ide/ide-cd.c
36342@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36343 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36344 if ((unsigned long)buf & alignment
36345 || blk_rq_bytes(rq) & q->dma_pad_mask
36346- || object_is_on_stack(buf))
36347+ || object_starts_on_stack(buf))
36348 drive->dma = 0;
36349 }
36350 }
36351diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36352index 8848f16..f8e6dd8 100644
36353--- a/drivers/iio/industrialio-core.c
36354+++ b/drivers/iio/industrialio-core.c
36355@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36356 }
36357
36358 static
36359-int __iio_device_attr_init(struct device_attribute *dev_attr,
36360+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36361 const char *postfix,
36362 struct iio_chan_spec const *chan,
36363 ssize_t (*readfunc)(struct device *dev,
36364diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36365index 394fea2..c833880 100644
36366--- a/drivers/infiniband/core/cm.c
36367+++ b/drivers/infiniband/core/cm.c
36368@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36369
36370 struct cm_counter_group {
36371 struct kobject obj;
36372- atomic_long_t counter[CM_ATTR_COUNT];
36373+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36374 };
36375
36376 struct cm_counter_attribute {
36377@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36378 struct ib_mad_send_buf *msg = NULL;
36379 int ret;
36380
36381- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36382+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36383 counter[CM_REQ_COUNTER]);
36384
36385 /* Quick state check to discard duplicate REQs. */
36386@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36387 if (!cm_id_priv)
36388 return;
36389
36390- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36391+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36392 counter[CM_REP_COUNTER]);
36393 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36394 if (ret)
36395@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36396 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36397 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36398 spin_unlock_irq(&cm_id_priv->lock);
36399- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36400+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36401 counter[CM_RTU_COUNTER]);
36402 goto out;
36403 }
36404@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36405 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36406 dreq_msg->local_comm_id);
36407 if (!cm_id_priv) {
36408- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36409+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36410 counter[CM_DREQ_COUNTER]);
36411 cm_issue_drep(work->port, work->mad_recv_wc);
36412 return -EINVAL;
36413@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36414 case IB_CM_MRA_REP_RCVD:
36415 break;
36416 case IB_CM_TIMEWAIT:
36417- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36418+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36419 counter[CM_DREQ_COUNTER]);
36420 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36421 goto unlock;
36422@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36423 cm_free_msg(msg);
36424 goto deref;
36425 case IB_CM_DREQ_RCVD:
36426- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36427+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36428 counter[CM_DREQ_COUNTER]);
36429 goto unlock;
36430 default:
36431@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36432 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36433 cm_id_priv->msg, timeout)) {
36434 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36435- atomic_long_inc(&work->port->
36436+ atomic_long_inc_unchecked(&work->port->
36437 counter_group[CM_RECV_DUPLICATES].
36438 counter[CM_MRA_COUNTER]);
36439 goto out;
36440@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36441 break;
36442 case IB_CM_MRA_REQ_RCVD:
36443 case IB_CM_MRA_REP_RCVD:
36444- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36445+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36446 counter[CM_MRA_COUNTER]);
36447 /* fall through */
36448 default:
36449@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36450 case IB_CM_LAP_IDLE:
36451 break;
36452 case IB_CM_MRA_LAP_SENT:
36453- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36454+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36455 counter[CM_LAP_COUNTER]);
36456 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36457 goto unlock;
36458@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36459 cm_free_msg(msg);
36460 goto deref;
36461 case IB_CM_LAP_RCVD:
36462- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36463+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36464 counter[CM_LAP_COUNTER]);
36465 goto unlock;
36466 default:
36467@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36468 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36469 if (cur_cm_id_priv) {
36470 spin_unlock_irq(&cm.lock);
36471- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36472+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36473 counter[CM_SIDR_REQ_COUNTER]);
36474 goto out; /* Duplicate message. */
36475 }
36476@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36477 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36478 msg->retries = 1;
36479
36480- atomic_long_add(1 + msg->retries,
36481+ atomic_long_add_unchecked(1 + msg->retries,
36482 &port->counter_group[CM_XMIT].counter[attr_index]);
36483 if (msg->retries)
36484- atomic_long_add(msg->retries,
36485+ atomic_long_add_unchecked(msg->retries,
36486 &port->counter_group[CM_XMIT_RETRIES].
36487 counter[attr_index]);
36488
36489@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36490 }
36491
36492 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36493- atomic_long_inc(&port->counter_group[CM_RECV].
36494+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36495 counter[attr_id - CM_ATTR_ID_OFFSET]);
36496
36497 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36498@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36499 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36500
36501 return sprintf(buf, "%ld\n",
36502- atomic_long_read(&group->counter[cm_attr->index]));
36503+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36504 }
36505
36506 static const struct sysfs_ops cm_counter_ops = {
36507diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36508index 176c8f9..2627b62 100644
36509--- a/drivers/infiniband/core/fmr_pool.c
36510+++ b/drivers/infiniband/core/fmr_pool.c
36511@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36512
36513 struct task_struct *thread;
36514
36515- atomic_t req_ser;
36516- atomic_t flush_ser;
36517+ atomic_unchecked_t req_ser;
36518+ atomic_unchecked_t flush_ser;
36519
36520 wait_queue_head_t force_wait;
36521 };
36522@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36523 struct ib_fmr_pool *pool = pool_ptr;
36524
36525 do {
36526- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36527+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36528 ib_fmr_batch_release(pool);
36529
36530- atomic_inc(&pool->flush_ser);
36531+ atomic_inc_unchecked(&pool->flush_ser);
36532 wake_up_interruptible(&pool->force_wait);
36533
36534 if (pool->flush_function)
36535@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36536 }
36537
36538 set_current_state(TASK_INTERRUPTIBLE);
36539- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36540+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36541 !kthread_should_stop())
36542 schedule();
36543 __set_current_state(TASK_RUNNING);
36544@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36545 pool->dirty_watermark = params->dirty_watermark;
36546 pool->dirty_len = 0;
36547 spin_lock_init(&pool->pool_lock);
36548- atomic_set(&pool->req_ser, 0);
36549- atomic_set(&pool->flush_ser, 0);
36550+ atomic_set_unchecked(&pool->req_ser, 0);
36551+ atomic_set_unchecked(&pool->flush_ser, 0);
36552 init_waitqueue_head(&pool->force_wait);
36553
36554 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36555@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36556 }
36557 spin_unlock_irq(&pool->pool_lock);
36558
36559- serial = atomic_inc_return(&pool->req_ser);
36560+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36561 wake_up_process(pool->thread);
36562
36563 if (wait_event_interruptible(pool->force_wait,
36564- atomic_read(&pool->flush_ser) - serial >= 0))
36565+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36566 return -EINTR;
36567
36568 return 0;
36569@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36570 } else {
36571 list_add_tail(&fmr->list, &pool->dirty_list);
36572 if (++pool->dirty_len >= pool->dirty_watermark) {
36573- atomic_inc(&pool->req_ser);
36574+ atomic_inc_unchecked(&pool->req_ser);
36575 wake_up_process(pool->thread);
36576 }
36577 }
36578diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36579index afd8179..598063f 100644
36580--- a/drivers/infiniband/hw/cxgb4/mem.c
36581+++ b/drivers/infiniband/hw/cxgb4/mem.c
36582@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36583 int err;
36584 struct fw_ri_tpte tpt;
36585 u32 stag_idx;
36586- static atomic_t key;
36587+ static atomic_unchecked_t key;
36588
36589 if (c4iw_fatal_error(rdev))
36590 return -EIO;
36591@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36592 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36593 rdev->stats.stag.max = rdev->stats.stag.cur;
36594 mutex_unlock(&rdev->stats.lock);
36595- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36596+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36597 }
36598 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36599 __func__, stag_state, type, pdid, stag_idx);
36600diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36601index 79b3dbc..96e5fcc 100644
36602--- a/drivers/infiniband/hw/ipath/ipath_rc.c
36603+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36604@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36605 struct ib_atomic_eth *ateth;
36606 struct ipath_ack_entry *e;
36607 u64 vaddr;
36608- atomic64_t *maddr;
36609+ atomic64_unchecked_t *maddr;
36610 u64 sdata;
36611 u32 rkey;
36612 u8 next;
36613@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36614 IB_ACCESS_REMOTE_ATOMIC)))
36615 goto nack_acc_unlck;
36616 /* Perform atomic OP and save result. */
36617- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36618+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36619 sdata = be64_to_cpu(ateth->swap_data);
36620 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36621 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36622- (u64) atomic64_add_return(sdata, maddr) - sdata :
36623+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36624 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36625 be64_to_cpu(ateth->compare_data),
36626 sdata);
36627diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36628index 1f95bba..9530f87 100644
36629--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36630+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36631@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36632 unsigned long flags;
36633 struct ib_wc wc;
36634 u64 sdata;
36635- atomic64_t *maddr;
36636+ atomic64_unchecked_t *maddr;
36637 enum ib_wc_status send_status;
36638
36639 /*
36640@@ -382,11 +382,11 @@ again:
36641 IB_ACCESS_REMOTE_ATOMIC)))
36642 goto acc_err;
36643 /* Perform atomic OP and save result. */
36644- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36645+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36646 sdata = wqe->wr.wr.atomic.compare_add;
36647 *(u64 *) sqp->s_sge.sge.vaddr =
36648 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36649- (u64) atomic64_add_return(sdata, maddr) - sdata :
36650+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36651 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36652 sdata, wqe->wr.wr.atomic.swap);
36653 goto send_comp;
36654diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
36655index 9d3e5c1..d9afe4a 100644
36656--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
36657+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
36658@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
36659 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
36660 }
36661
36662-int mthca_QUERY_FW(struct mthca_dev *dev)
36663+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
36664 {
36665 struct mthca_mailbox *mailbox;
36666 u32 *outbox;
36667diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
36668index ed9a989..e0c5871 100644
36669--- a/drivers/infiniband/hw/mthca/mthca_mr.c
36670+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
36671@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
36672 return key;
36673 }
36674
36675-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36676+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36677 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
36678 {
36679 struct mthca_mailbox *mailbox;
36680diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36681index 5b152a3..c1f3e83 100644
36682--- a/drivers/infiniband/hw/nes/nes.c
36683+++ b/drivers/infiniband/hw/nes/nes.c
36684@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36685 LIST_HEAD(nes_adapter_list);
36686 static LIST_HEAD(nes_dev_list);
36687
36688-atomic_t qps_destroyed;
36689+atomic_unchecked_t qps_destroyed;
36690
36691 static unsigned int ee_flsh_adapter;
36692 static unsigned int sysfs_nonidx_addr;
36693@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36694 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36695 struct nes_adapter *nesadapter = nesdev->nesadapter;
36696
36697- atomic_inc(&qps_destroyed);
36698+ atomic_inc_unchecked(&qps_destroyed);
36699
36700 /* Free the control structures */
36701
36702diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36703index 33cc589..3bd6538 100644
36704--- a/drivers/infiniband/hw/nes/nes.h
36705+++ b/drivers/infiniband/hw/nes/nes.h
36706@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36707 extern unsigned int wqm_quanta;
36708 extern struct list_head nes_adapter_list;
36709
36710-extern atomic_t cm_connects;
36711-extern atomic_t cm_accepts;
36712-extern atomic_t cm_disconnects;
36713-extern atomic_t cm_closes;
36714-extern atomic_t cm_connecteds;
36715-extern atomic_t cm_connect_reqs;
36716-extern atomic_t cm_rejects;
36717-extern atomic_t mod_qp_timouts;
36718-extern atomic_t qps_created;
36719-extern atomic_t qps_destroyed;
36720-extern atomic_t sw_qps_destroyed;
36721+extern atomic_unchecked_t cm_connects;
36722+extern atomic_unchecked_t cm_accepts;
36723+extern atomic_unchecked_t cm_disconnects;
36724+extern atomic_unchecked_t cm_closes;
36725+extern atomic_unchecked_t cm_connecteds;
36726+extern atomic_unchecked_t cm_connect_reqs;
36727+extern atomic_unchecked_t cm_rejects;
36728+extern atomic_unchecked_t mod_qp_timouts;
36729+extern atomic_unchecked_t qps_created;
36730+extern atomic_unchecked_t qps_destroyed;
36731+extern atomic_unchecked_t sw_qps_destroyed;
36732 extern u32 mh_detected;
36733 extern u32 mh_pauses_sent;
36734 extern u32 cm_packets_sent;
36735@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36736 extern u32 cm_packets_received;
36737 extern u32 cm_packets_dropped;
36738 extern u32 cm_packets_retrans;
36739-extern atomic_t cm_listens_created;
36740-extern atomic_t cm_listens_destroyed;
36741+extern atomic_unchecked_t cm_listens_created;
36742+extern atomic_unchecked_t cm_listens_destroyed;
36743 extern u32 cm_backlog_drops;
36744-extern atomic_t cm_loopbacks;
36745-extern atomic_t cm_nodes_created;
36746-extern atomic_t cm_nodes_destroyed;
36747-extern atomic_t cm_accel_dropped_pkts;
36748-extern atomic_t cm_resets_recvd;
36749-extern atomic_t pau_qps_created;
36750-extern atomic_t pau_qps_destroyed;
36751+extern atomic_unchecked_t cm_loopbacks;
36752+extern atomic_unchecked_t cm_nodes_created;
36753+extern atomic_unchecked_t cm_nodes_destroyed;
36754+extern atomic_unchecked_t cm_accel_dropped_pkts;
36755+extern atomic_unchecked_t cm_resets_recvd;
36756+extern atomic_unchecked_t pau_qps_created;
36757+extern atomic_unchecked_t pau_qps_destroyed;
36758
36759 extern u32 int_mod_timer_init;
36760 extern u32 int_mod_cq_depth_256;
36761diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36762index 22ea67e..dcbe3bc 100644
36763--- a/drivers/infiniband/hw/nes/nes_cm.c
36764+++ b/drivers/infiniband/hw/nes/nes_cm.c
36765@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36766 u32 cm_packets_retrans;
36767 u32 cm_packets_created;
36768 u32 cm_packets_received;
36769-atomic_t cm_listens_created;
36770-atomic_t cm_listens_destroyed;
36771+atomic_unchecked_t cm_listens_created;
36772+atomic_unchecked_t cm_listens_destroyed;
36773 u32 cm_backlog_drops;
36774-atomic_t cm_loopbacks;
36775-atomic_t cm_nodes_created;
36776-atomic_t cm_nodes_destroyed;
36777-atomic_t cm_accel_dropped_pkts;
36778-atomic_t cm_resets_recvd;
36779+atomic_unchecked_t cm_loopbacks;
36780+atomic_unchecked_t cm_nodes_created;
36781+atomic_unchecked_t cm_nodes_destroyed;
36782+atomic_unchecked_t cm_accel_dropped_pkts;
36783+atomic_unchecked_t cm_resets_recvd;
36784
36785 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36786 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36787@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36788
36789 static struct nes_cm_core *g_cm_core;
36790
36791-atomic_t cm_connects;
36792-atomic_t cm_accepts;
36793-atomic_t cm_disconnects;
36794-atomic_t cm_closes;
36795-atomic_t cm_connecteds;
36796-atomic_t cm_connect_reqs;
36797-atomic_t cm_rejects;
36798+atomic_unchecked_t cm_connects;
36799+atomic_unchecked_t cm_accepts;
36800+atomic_unchecked_t cm_disconnects;
36801+atomic_unchecked_t cm_closes;
36802+atomic_unchecked_t cm_connecteds;
36803+atomic_unchecked_t cm_connect_reqs;
36804+atomic_unchecked_t cm_rejects;
36805
36806 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36807 {
36808@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36809 kfree(listener);
36810 listener = NULL;
36811 ret = 0;
36812- atomic_inc(&cm_listens_destroyed);
36813+ atomic_inc_unchecked(&cm_listens_destroyed);
36814 } else {
36815 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36816 }
36817@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36818 cm_node->rem_mac);
36819
36820 add_hte_node(cm_core, cm_node);
36821- atomic_inc(&cm_nodes_created);
36822+ atomic_inc_unchecked(&cm_nodes_created);
36823
36824 return cm_node;
36825 }
36826@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36827 }
36828
36829 atomic_dec(&cm_core->node_cnt);
36830- atomic_inc(&cm_nodes_destroyed);
36831+ atomic_inc_unchecked(&cm_nodes_destroyed);
36832 nesqp = cm_node->nesqp;
36833 if (nesqp) {
36834 nesqp->cm_node = NULL;
36835@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36836
36837 static void drop_packet(struct sk_buff *skb)
36838 {
36839- atomic_inc(&cm_accel_dropped_pkts);
36840+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36841 dev_kfree_skb_any(skb);
36842 }
36843
36844@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36845 {
36846
36847 int reset = 0; /* whether to send reset in case of err.. */
36848- atomic_inc(&cm_resets_recvd);
36849+ atomic_inc_unchecked(&cm_resets_recvd);
36850 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36851 " refcnt=%d\n", cm_node, cm_node->state,
36852 atomic_read(&cm_node->ref_count));
36853@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36854 rem_ref_cm_node(cm_node->cm_core, cm_node);
36855 return NULL;
36856 }
36857- atomic_inc(&cm_loopbacks);
36858+ atomic_inc_unchecked(&cm_loopbacks);
36859 loopbackremotenode->loopbackpartner = cm_node;
36860 loopbackremotenode->tcp_cntxt.rcv_wscale =
36861 NES_CM_DEFAULT_RCV_WND_SCALE;
36862@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36863 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36864 else {
36865 rem_ref_cm_node(cm_core, cm_node);
36866- atomic_inc(&cm_accel_dropped_pkts);
36867+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36868 dev_kfree_skb_any(skb);
36869 }
36870 break;
36871@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36872
36873 if ((cm_id) && (cm_id->event_handler)) {
36874 if (issue_disconn) {
36875- atomic_inc(&cm_disconnects);
36876+ atomic_inc_unchecked(&cm_disconnects);
36877 cm_event.event = IW_CM_EVENT_DISCONNECT;
36878 cm_event.status = disconn_status;
36879 cm_event.local_addr = cm_id->local_addr;
36880@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36881 }
36882
36883 if (issue_close) {
36884- atomic_inc(&cm_closes);
36885+ atomic_inc_unchecked(&cm_closes);
36886 nes_disconnect(nesqp, 1);
36887
36888 cm_id->provider_data = nesqp;
36889@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36890
36891 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36892 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36893- atomic_inc(&cm_accepts);
36894+ atomic_inc_unchecked(&cm_accepts);
36895
36896 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36897 netdev_refcnt_read(nesvnic->netdev));
36898@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36899 struct nes_cm_core *cm_core;
36900 u8 *start_buff;
36901
36902- atomic_inc(&cm_rejects);
36903+ atomic_inc_unchecked(&cm_rejects);
36904 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36905 loopback = cm_node->loopbackpartner;
36906 cm_core = cm_node->cm_core;
36907@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36908 ntohl(cm_id->local_addr.sin_addr.s_addr),
36909 ntohs(cm_id->local_addr.sin_port));
36910
36911- atomic_inc(&cm_connects);
36912+ atomic_inc_unchecked(&cm_connects);
36913 nesqp->active_conn = 1;
36914
36915 /* cache the cm_id in the qp */
36916@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36917 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36918 return err;
36919 }
36920- atomic_inc(&cm_listens_created);
36921+ atomic_inc_unchecked(&cm_listens_created);
36922 }
36923
36924 cm_id->add_ref(cm_id);
36925@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36926
36927 if (nesqp->destroyed)
36928 return;
36929- atomic_inc(&cm_connecteds);
36930+ atomic_inc_unchecked(&cm_connecteds);
36931 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36932 " local port 0x%04X. jiffies = %lu.\n",
36933 nesqp->hwqp.qp_id,
36934@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36935
36936 cm_id->add_ref(cm_id);
36937 ret = cm_id->event_handler(cm_id, &cm_event);
36938- atomic_inc(&cm_closes);
36939+ atomic_inc_unchecked(&cm_closes);
36940 cm_event.event = IW_CM_EVENT_CLOSE;
36941 cm_event.status = 0;
36942 cm_event.provider_data = cm_id->provider_data;
36943@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36944 return;
36945 cm_id = cm_node->cm_id;
36946
36947- atomic_inc(&cm_connect_reqs);
36948+ atomic_inc_unchecked(&cm_connect_reqs);
36949 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36950 cm_node, cm_id, jiffies);
36951
36952@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
36953 return;
36954 cm_id = cm_node->cm_id;
36955
36956- atomic_inc(&cm_connect_reqs);
36957+ atomic_inc_unchecked(&cm_connect_reqs);
36958 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36959 cm_node, cm_id, jiffies);
36960
36961diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36962index 4166452..fc952c3 100644
36963--- a/drivers/infiniband/hw/nes/nes_mgt.c
36964+++ b/drivers/infiniband/hw/nes/nes_mgt.c
36965@@ -40,8 +40,8 @@
36966 #include "nes.h"
36967 #include "nes_mgt.h"
36968
36969-atomic_t pau_qps_created;
36970-atomic_t pau_qps_destroyed;
36971+atomic_unchecked_t pau_qps_created;
36972+atomic_unchecked_t pau_qps_destroyed;
36973
36974 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36975 {
36976@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36977 {
36978 struct sk_buff *skb;
36979 unsigned long flags;
36980- atomic_inc(&pau_qps_destroyed);
36981+ atomic_inc_unchecked(&pau_qps_destroyed);
36982
36983 /* Free packets that have not yet been forwarded */
36984 /* Lock is acquired by skb_dequeue when removing the skb */
36985@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36986 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36987 skb_queue_head_init(&nesqp->pau_list);
36988 spin_lock_init(&nesqp->pau_lock);
36989- atomic_inc(&pau_qps_created);
36990+ atomic_inc_unchecked(&pau_qps_created);
36991 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
36992 }
36993
36994diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
36995index 9542e16..a008c40 100644
36996--- a/drivers/infiniband/hw/nes/nes_nic.c
36997+++ b/drivers/infiniband/hw/nes/nes_nic.c
36998@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
36999 target_stat_values[++index] = mh_detected;
37000 target_stat_values[++index] = mh_pauses_sent;
37001 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37002- target_stat_values[++index] = atomic_read(&cm_connects);
37003- target_stat_values[++index] = atomic_read(&cm_accepts);
37004- target_stat_values[++index] = atomic_read(&cm_disconnects);
37005- target_stat_values[++index] = atomic_read(&cm_connecteds);
37006- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37007- target_stat_values[++index] = atomic_read(&cm_rejects);
37008- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37009- target_stat_values[++index] = atomic_read(&qps_created);
37010- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37011- target_stat_values[++index] = atomic_read(&qps_destroyed);
37012- target_stat_values[++index] = atomic_read(&cm_closes);
37013+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37014+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37015+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37016+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37017+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37018+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37019+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37020+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37021+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37022+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37023+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37024 target_stat_values[++index] = cm_packets_sent;
37025 target_stat_values[++index] = cm_packets_bounced;
37026 target_stat_values[++index] = cm_packets_created;
37027 target_stat_values[++index] = cm_packets_received;
37028 target_stat_values[++index] = cm_packets_dropped;
37029 target_stat_values[++index] = cm_packets_retrans;
37030- target_stat_values[++index] = atomic_read(&cm_listens_created);
37031- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37032+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37033+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37034 target_stat_values[++index] = cm_backlog_drops;
37035- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37036- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37037- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37038- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37039- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37040+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37041+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37042+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37043+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37044+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37045 target_stat_values[++index] = nesadapter->free_4kpbl;
37046 target_stat_values[++index] = nesadapter->free_256pbl;
37047 target_stat_values[++index] = int_mod_timer_init;
37048 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37049 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37050 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37051- target_stat_values[++index] = atomic_read(&pau_qps_created);
37052- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37053+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37054+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37055 }
37056
37057 /**
37058diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37059index 07e4fba..685f041 100644
37060--- a/drivers/infiniband/hw/nes/nes_verbs.c
37061+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37062@@ -46,9 +46,9 @@
37063
37064 #include <rdma/ib_umem.h>
37065
37066-atomic_t mod_qp_timouts;
37067-atomic_t qps_created;
37068-atomic_t sw_qps_destroyed;
37069+atomic_unchecked_t mod_qp_timouts;
37070+atomic_unchecked_t qps_created;
37071+atomic_unchecked_t sw_qps_destroyed;
37072
37073 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37074
37075@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37076 if (init_attr->create_flags)
37077 return ERR_PTR(-EINVAL);
37078
37079- atomic_inc(&qps_created);
37080+ atomic_inc_unchecked(&qps_created);
37081 switch (init_attr->qp_type) {
37082 case IB_QPT_RC:
37083 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37084@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37085 struct iw_cm_event cm_event;
37086 int ret = 0;
37087
37088- atomic_inc(&sw_qps_destroyed);
37089+ atomic_inc_unchecked(&sw_qps_destroyed);
37090 nesqp->destroyed = 1;
37091
37092 /* Blow away the connection if it exists. */
37093diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37094index 4d11575..3e890e5 100644
37095--- a/drivers/infiniband/hw/qib/qib.h
37096+++ b/drivers/infiniband/hw/qib/qib.h
37097@@ -51,6 +51,7 @@
37098 #include <linux/completion.h>
37099 #include <linux/kref.h>
37100 #include <linux/sched.h>
37101+#include <linux/slab.h>
37102
37103 #include "qib_common.h"
37104 #include "qib_verbs.h"
37105diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37106index da739d9..da1c7f4 100644
37107--- a/drivers/input/gameport/gameport.c
37108+++ b/drivers/input/gameport/gameport.c
37109@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37110 */
37111 static void gameport_init_port(struct gameport *gameport)
37112 {
37113- static atomic_t gameport_no = ATOMIC_INIT(0);
37114+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37115
37116 __module_get(THIS_MODULE);
37117
37118 mutex_init(&gameport->drv_mutex);
37119 device_initialize(&gameport->dev);
37120 dev_set_name(&gameport->dev, "gameport%lu",
37121- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37122+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37123 gameport->dev.bus = &gameport_bus;
37124 gameport->dev.release = gameport_release_port;
37125 if (gameport->parent)
37126diff --git a/drivers/input/input.c b/drivers/input/input.c
37127index c044699..174d71a 100644
37128--- a/drivers/input/input.c
37129+++ b/drivers/input/input.c
37130@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37131 */
37132 int input_register_device(struct input_dev *dev)
37133 {
37134- static atomic_t input_no = ATOMIC_INIT(0);
37135+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37136 struct input_devres *devres = NULL;
37137 struct input_handler *handler;
37138 unsigned int packet_size;
37139@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37140 dev->setkeycode = input_default_setkeycode;
37141
37142 dev_set_name(&dev->dev, "input%ld",
37143- (unsigned long) atomic_inc_return(&input_no) - 1);
37144+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37145
37146 error = device_add(&dev->dev);
37147 if (error)
37148diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37149index 04c69af..5f92d00 100644
37150--- a/drivers/input/joystick/sidewinder.c
37151+++ b/drivers/input/joystick/sidewinder.c
37152@@ -30,6 +30,7 @@
37153 #include <linux/kernel.h>
37154 #include <linux/module.h>
37155 #include <linux/slab.h>
37156+#include <linux/sched.h>
37157 #include <linux/init.h>
37158 #include <linux/input.h>
37159 #include <linux/gameport.h>
37160diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37161index d6cbfe9..6225402 100644
37162--- a/drivers/input/joystick/xpad.c
37163+++ b/drivers/input/joystick/xpad.c
37164@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37165
37166 static int xpad_led_probe(struct usb_xpad *xpad)
37167 {
37168- static atomic_t led_seq = ATOMIC_INIT(0);
37169+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37170 long led_no;
37171 struct xpad_led *led;
37172 struct led_classdev *led_cdev;
37173@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37174 if (!led)
37175 return -ENOMEM;
37176
37177- led_no = (long)atomic_inc_return(&led_seq) - 1;
37178+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37179
37180 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37181 led->xpad = xpad;
37182diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37183index fe1df23..5b710f3 100644
37184--- a/drivers/input/mouse/psmouse.h
37185+++ b/drivers/input/mouse/psmouse.h
37186@@ -115,7 +115,7 @@ struct psmouse_attribute {
37187 ssize_t (*set)(struct psmouse *psmouse, void *data,
37188 const char *buf, size_t count);
37189 bool protect;
37190-};
37191+} __do_const;
37192 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37193
37194 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37195diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37196index 4c842c3..590b0bf 100644
37197--- a/drivers/input/mousedev.c
37198+++ b/drivers/input/mousedev.c
37199@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37200
37201 spin_unlock_irq(&client->packet_lock);
37202
37203- if (copy_to_user(buffer, data, count))
37204+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37205 return -EFAULT;
37206
37207 return count;
37208diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37209index 25fc597..558bf3b 100644
37210--- a/drivers/input/serio/serio.c
37211+++ b/drivers/input/serio/serio.c
37212@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37213 */
37214 static void serio_init_port(struct serio *serio)
37215 {
37216- static atomic_t serio_no = ATOMIC_INIT(0);
37217+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37218
37219 __module_get(THIS_MODULE);
37220
37221@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37222 mutex_init(&serio->drv_mutex);
37223 device_initialize(&serio->dev);
37224 dev_set_name(&serio->dev, "serio%ld",
37225- (long)atomic_inc_return(&serio_no) - 1);
37226+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37227 serio->dev.bus = &serio_bus;
37228 serio->dev.release = serio_release_port;
37229 serio->dev.groups = serio_device_attr_groups;
37230diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37231index ddbdaca..be18a78 100644
37232--- a/drivers/iommu/iommu.c
37233+++ b/drivers/iommu/iommu.c
37234@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37235 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37236 {
37237 bus_register_notifier(bus, &iommu_bus_nb);
37238- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37239+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37240 }
37241
37242 /**
37243diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37244index 89562a8..218999b 100644
37245--- a/drivers/isdn/capi/capi.c
37246+++ b/drivers/isdn/capi/capi.c
37247@@ -81,8 +81,8 @@ struct capiminor {
37248
37249 struct capi20_appl *ap;
37250 u32 ncci;
37251- atomic_t datahandle;
37252- atomic_t msgid;
37253+ atomic_unchecked_t datahandle;
37254+ atomic_unchecked_t msgid;
37255
37256 struct tty_port port;
37257 int ttyinstop;
37258@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37259 capimsg_setu16(s, 2, mp->ap->applid);
37260 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37261 capimsg_setu8 (s, 5, CAPI_RESP);
37262- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37263+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37264 capimsg_setu32(s, 8, mp->ncci);
37265 capimsg_setu16(s, 12, datahandle);
37266 }
37267@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37268 mp->outbytes -= len;
37269 spin_unlock_bh(&mp->outlock);
37270
37271- datahandle = atomic_inc_return(&mp->datahandle);
37272+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37273 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37274 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37275 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37276 capimsg_setu16(skb->data, 2, mp->ap->applid);
37277 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37278 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37279- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37280+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37281 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37282 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37283 capimsg_setu16(skb->data, 16, len); /* Data length */
37284diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37285index 67abf3f..076b3a6 100644
37286--- a/drivers/isdn/gigaset/interface.c
37287+++ b/drivers/isdn/gigaset/interface.c
37288@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37289 }
37290 tty->driver_data = cs;
37291
37292- ++cs->port.count;
37293+ atomic_inc(&cs->port.count);
37294
37295- if (cs->port.count == 1) {
37296+ if (atomic_read(&cs->port.count) == 1) {
37297 tty_port_tty_set(&cs->port, tty);
37298 tty->low_latency = 1;
37299 }
37300@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37301
37302 if (!cs->connected)
37303 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37304- else if (!cs->port.count)
37305+ else if (!atomic_read(&cs->port.count))
37306 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37307- else if (!--cs->port.count)
37308+ else if (!atomic_dec_return(&cs->port.count))
37309 tty_port_tty_set(&cs->port, NULL);
37310
37311 mutex_unlock(&cs->mutex);
37312diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37313index 821f7ac..28d4030 100644
37314--- a/drivers/isdn/hardware/avm/b1.c
37315+++ b/drivers/isdn/hardware/avm/b1.c
37316@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37317 }
37318 if (left) {
37319 if (t4file->user) {
37320- if (copy_from_user(buf, dp, left))
37321+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37322 return -EFAULT;
37323 } else {
37324 memcpy(buf, dp, left);
37325@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37326 }
37327 if (left) {
37328 if (config->user) {
37329- if (copy_from_user(buf, dp, left))
37330+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37331 return -EFAULT;
37332 } else {
37333 memcpy(buf, dp, left);
37334diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37335index e09dc8a..15e2efb 100644
37336--- a/drivers/isdn/i4l/isdn_tty.c
37337+++ b/drivers/isdn/i4l/isdn_tty.c
37338@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37339
37340 #ifdef ISDN_DEBUG_MODEM_OPEN
37341 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37342- port->count);
37343+ atomic_read(&port->count));
37344 #endif
37345- port->count++;
37346+ atomic_inc(&port->count);
37347 port->tty = tty;
37348 /*
37349 * Start up serial port
37350@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37351 #endif
37352 return;
37353 }
37354- if ((tty->count == 1) && (port->count != 1)) {
37355+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37356 /*
37357 * Uh, oh. tty->count is 1, which means that the tty
37358 * structure will be freed. Info->count should always
37359@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37360 * serial port won't be shutdown.
37361 */
37362 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37363- "info->count is %d\n", port->count);
37364- port->count = 1;
37365+ "info->count is %d\n", atomic_read(&port->count));
37366+ atomic_set(&port->count, 1);
37367 }
37368- if (--port->count < 0) {
37369+ if (atomic_dec_return(&port->count) < 0) {
37370 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37371- info->line, port->count);
37372- port->count = 0;
37373+ info->line, atomic_read(&port->count));
37374+ atomic_set(&port->count, 0);
37375 }
37376- if (port->count) {
37377+ if (atomic_read(&port->count)) {
37378 #ifdef ISDN_DEBUG_MODEM_OPEN
37379 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37380 #endif
37381@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37382 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37383 return;
37384 isdn_tty_shutdown(info);
37385- port->count = 0;
37386+ atomic_set(&port->count, 0);
37387 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37388 port->tty = NULL;
37389 wake_up_interruptible(&port->open_wait);
37390@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37391 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37392 modem_info *info = &dev->mdm.info[i];
37393
37394- if (info->port.count == 0)
37395+ if (atomic_read(&info->port.count) == 0)
37396 continue;
37397 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37398 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37399diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37400index e74df7c..03a03ba 100644
37401--- a/drivers/isdn/icn/icn.c
37402+++ b/drivers/isdn/icn/icn.c
37403@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37404 if (count > len)
37405 count = len;
37406 if (user) {
37407- if (copy_from_user(msg, buf, count))
37408+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37409 return -EFAULT;
37410 } else
37411 memcpy(msg, buf, count);
37412diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37413index 6a8405d..0bd1c7e 100644
37414--- a/drivers/leds/leds-clevo-mail.c
37415+++ b/drivers/leds/leds-clevo-mail.c
37416@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37417 * detected as working, but in reality it is not) as low as
37418 * possible.
37419 */
37420-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37421+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37422 {
37423 .callback = clevo_mail_led_dmi_callback,
37424 .ident = "Clevo D410J",
37425diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37426index ec9b287..65c9bf4 100644
37427--- a/drivers/leds/leds-ss4200.c
37428+++ b/drivers/leds/leds-ss4200.c
37429@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37430 * detected as working, but in reality it is not) as low as
37431 * possible.
37432 */
37433-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37434+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37435 {
37436 .callback = ss4200_led_dmi_callback,
37437 .ident = "Intel SS4200-E",
37438diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37439index a5ebc00..982886f 100644
37440--- a/drivers/lguest/core.c
37441+++ b/drivers/lguest/core.c
37442@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37443 * it's worked so far. The end address needs +1 because __get_vm_area
37444 * allocates an extra guard page, so we need space for that.
37445 */
37446+
37447+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37448+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37449+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37450+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37451+#else
37452 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37453 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37454 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37455+#endif
37456+
37457 if (!switcher_vma) {
37458 err = -ENOMEM;
37459 printk("lguest: could not map switcher pages high\n");
37460@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37461 * Now the Switcher is mapped at the right address, we can't fail!
37462 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37463 */
37464- memcpy(switcher_vma->addr, start_switcher_text,
37465+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37466 end_switcher_text - start_switcher_text);
37467
37468 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37469diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37470index 3b62be16..e33134a 100644
37471--- a/drivers/lguest/page_tables.c
37472+++ b/drivers/lguest/page_tables.c
37473@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37474 /*:*/
37475
37476 #ifdef CONFIG_X86_PAE
37477-static void release_pmd(pmd_t *spmd)
37478+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37479 {
37480 /* If the entry's not present, there's nothing to release. */
37481 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37482diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37483index 4af12e1..0e89afe 100644
37484--- a/drivers/lguest/x86/core.c
37485+++ b/drivers/lguest/x86/core.c
37486@@ -59,7 +59,7 @@ static struct {
37487 /* Offset from where switcher.S was compiled to where we've copied it */
37488 static unsigned long switcher_offset(void)
37489 {
37490- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37491+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37492 }
37493
37494 /* This cpu's struct lguest_pages. */
37495@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37496 * These copies are pretty cheap, so we do them unconditionally: */
37497 /* Save the current Host top-level page directory.
37498 */
37499+
37500+#ifdef CONFIG_PAX_PER_CPU_PGD
37501+ pages->state.host_cr3 = read_cr3();
37502+#else
37503 pages->state.host_cr3 = __pa(current->mm->pgd);
37504+#endif
37505+
37506 /*
37507 * Set up the Guest's page tables to see this CPU's pages (and no
37508 * other CPU's pages).
37509@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37510 * compiled-in switcher code and the high-mapped copy we just made.
37511 */
37512 for (i = 0; i < IDT_ENTRIES; i++)
37513- default_idt_entries[i] += switcher_offset();
37514+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37515
37516 /*
37517 * Set up the Switcher's per-cpu areas.
37518@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37519 * it will be undisturbed when we switch. To change %cs and jump we
37520 * need this structure to feed to Intel's "lcall" instruction.
37521 */
37522- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37523+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37524 lguest_entry.segment = LGUEST_CS;
37525
37526 /*
37527diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37528index 40634b0..4f5855e 100644
37529--- a/drivers/lguest/x86/switcher_32.S
37530+++ b/drivers/lguest/x86/switcher_32.S
37531@@ -87,6 +87,7 @@
37532 #include <asm/page.h>
37533 #include <asm/segment.h>
37534 #include <asm/lguest.h>
37535+#include <asm/processor-flags.h>
37536
37537 // We mark the start of the code to copy
37538 // It's placed in .text tho it's never run here
37539@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37540 // Changes type when we load it: damn Intel!
37541 // For after we switch over our page tables
37542 // That entry will be read-only: we'd crash.
37543+
37544+#ifdef CONFIG_PAX_KERNEXEC
37545+ mov %cr0, %edx
37546+ xor $X86_CR0_WP, %edx
37547+ mov %edx, %cr0
37548+#endif
37549+
37550 movl $(GDT_ENTRY_TSS*8), %edx
37551 ltr %dx
37552
37553@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37554 // Let's clear it again for our return.
37555 // The GDT descriptor of the Host
37556 // Points to the table after two "size" bytes
37557- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37558+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37559 // Clear "used" from type field (byte 5, bit 2)
37560- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37561+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37562+
37563+#ifdef CONFIG_PAX_KERNEXEC
37564+ mov %cr0, %eax
37565+ xor $X86_CR0_WP, %eax
37566+ mov %eax, %cr0
37567+#endif
37568
37569 // Once our page table's switched, the Guest is live!
37570 // The Host fades as we run this final step.
37571@@ -295,13 +309,12 @@ deliver_to_host:
37572 // I consulted gcc, and it gave
37573 // These instructions, which I gladly credit:
37574 leal (%edx,%ebx,8), %eax
37575- movzwl (%eax),%edx
37576- movl 4(%eax), %eax
37577- xorw %ax, %ax
37578- orl %eax, %edx
37579+ movl 4(%eax), %edx
37580+ movw (%eax), %dx
37581 // Now the address of the handler's in %edx
37582 // We call it now: its "iret" drops us home.
37583- jmp *%edx
37584+ ljmp $__KERNEL_CS, $1f
37585+1: jmp *%edx
37586
37587 // Every interrupt can come to us here
37588 // But we must truly tell each apart.
37589diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37590index 7155945..4bcc562 100644
37591--- a/drivers/md/bitmap.c
37592+++ b/drivers/md/bitmap.c
37593@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37594 chunk_kb ? "KB" : "B");
37595 if (bitmap->storage.file) {
37596 seq_printf(seq, ", file: ");
37597- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37598+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37599 }
37600
37601 seq_printf(seq, "\n");
37602diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37603index eee353d..74504c4 100644
37604--- a/drivers/md/dm-ioctl.c
37605+++ b/drivers/md/dm-ioctl.c
37606@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37607 cmd == DM_LIST_VERSIONS_CMD)
37608 return 0;
37609
37610- if ((cmd == DM_DEV_CREATE_CMD)) {
37611+ if (cmd == DM_DEV_CREATE_CMD) {
37612 if (!*param->name) {
37613 DMWARN("name not supplied when creating device");
37614 return -EINVAL;
37615diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37616index 7f24190..0e18099 100644
37617--- a/drivers/md/dm-raid1.c
37618+++ b/drivers/md/dm-raid1.c
37619@@ -40,7 +40,7 @@ enum dm_raid1_error {
37620
37621 struct mirror {
37622 struct mirror_set *ms;
37623- atomic_t error_count;
37624+ atomic_unchecked_t error_count;
37625 unsigned long error_type;
37626 struct dm_dev *dev;
37627 sector_t offset;
37628@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37629 struct mirror *m;
37630
37631 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37632- if (!atomic_read(&m->error_count))
37633+ if (!atomic_read_unchecked(&m->error_count))
37634 return m;
37635
37636 return NULL;
37637@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37638 * simple way to tell if a device has encountered
37639 * errors.
37640 */
37641- atomic_inc(&m->error_count);
37642+ atomic_inc_unchecked(&m->error_count);
37643
37644 if (test_and_set_bit(error_type, &m->error_type))
37645 return;
37646@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37647 struct mirror *m = get_default_mirror(ms);
37648
37649 do {
37650- if (likely(!atomic_read(&m->error_count)))
37651+ if (likely(!atomic_read_unchecked(&m->error_count)))
37652 return m;
37653
37654 if (m-- == ms->mirror)
37655@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37656 {
37657 struct mirror *default_mirror = get_default_mirror(m->ms);
37658
37659- return !atomic_read(&default_mirror->error_count);
37660+ return !atomic_read_unchecked(&default_mirror->error_count);
37661 }
37662
37663 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37664@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37665 */
37666 if (likely(region_in_sync(ms, region, 1)))
37667 m = choose_mirror(ms, bio->bi_sector);
37668- else if (m && atomic_read(&m->error_count))
37669+ else if (m && atomic_read_unchecked(&m->error_count))
37670 m = NULL;
37671
37672 if (likely(m))
37673@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37674 }
37675
37676 ms->mirror[mirror].ms = ms;
37677- atomic_set(&(ms->mirror[mirror].error_count), 0);
37678+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37679 ms->mirror[mirror].error_type = 0;
37680 ms->mirror[mirror].offset = offset;
37681
37682@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37683 */
37684 static char device_status_char(struct mirror *m)
37685 {
37686- if (!atomic_read(&(m->error_count)))
37687+ if (!atomic_read_unchecked(&(m->error_count)))
37688 return 'A';
37689
37690 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37691diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37692index aaecefa..23b3026 100644
37693--- a/drivers/md/dm-stripe.c
37694+++ b/drivers/md/dm-stripe.c
37695@@ -20,7 +20,7 @@ struct stripe {
37696 struct dm_dev *dev;
37697 sector_t physical_start;
37698
37699- atomic_t error_count;
37700+ atomic_unchecked_t error_count;
37701 };
37702
37703 struct stripe_c {
37704@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37705 kfree(sc);
37706 return r;
37707 }
37708- atomic_set(&(sc->stripe[i].error_count), 0);
37709+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37710 }
37711
37712 ti->private = sc;
37713@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
37714 DMEMIT("%d ", sc->stripes);
37715 for (i = 0; i < sc->stripes; i++) {
37716 DMEMIT("%s ", sc->stripe[i].dev->name);
37717- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37718+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37719 'D' : 'A';
37720 }
37721 buffer[i] = '\0';
37722@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37723 */
37724 for (i = 0; i < sc->stripes; i++)
37725 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37726- atomic_inc(&(sc->stripe[i].error_count));
37727- if (atomic_read(&(sc->stripe[i].error_count)) <
37728+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
37729+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37730 DM_IO_ERROR_THRESHOLD)
37731 schedule_work(&sc->trigger_event);
37732 }
37733diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37734index daf25d0..d74f49f 100644
37735--- a/drivers/md/dm-table.c
37736+++ b/drivers/md/dm-table.c
37737@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37738 if (!dev_size)
37739 return 0;
37740
37741- if ((start >= dev_size) || (start + len > dev_size)) {
37742+ if ((start >= dev_size) || (len > dev_size - start)) {
37743 DMWARN("%s: %s too small for target: "
37744 "start=%llu, len=%llu, dev_size=%llu",
37745 dm_device_name(ti->table->md), bdevname(bdev, b),
37746diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37747index 4d6e853..a234157 100644
37748--- a/drivers/md/dm-thin-metadata.c
37749+++ b/drivers/md/dm-thin-metadata.c
37750@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37751 {
37752 pmd->info.tm = pmd->tm;
37753 pmd->info.levels = 2;
37754- pmd->info.value_type.context = pmd->data_sm;
37755+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37756 pmd->info.value_type.size = sizeof(__le64);
37757 pmd->info.value_type.inc = data_block_inc;
37758 pmd->info.value_type.dec = data_block_dec;
37759@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37760
37761 pmd->bl_info.tm = pmd->tm;
37762 pmd->bl_info.levels = 1;
37763- pmd->bl_info.value_type.context = pmd->data_sm;
37764+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37765 pmd->bl_info.value_type.size = sizeof(__le64);
37766 pmd->bl_info.value_type.inc = data_block_inc;
37767 pmd->bl_info.value_type.dec = data_block_dec;
37768diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37769index 0d8f086..f5a91d5 100644
37770--- a/drivers/md/dm.c
37771+++ b/drivers/md/dm.c
37772@@ -170,9 +170,9 @@ struct mapped_device {
37773 /*
37774 * Event handling.
37775 */
37776- atomic_t event_nr;
37777+ atomic_unchecked_t event_nr;
37778 wait_queue_head_t eventq;
37779- atomic_t uevent_seq;
37780+ atomic_unchecked_t uevent_seq;
37781 struct list_head uevent_list;
37782 spinlock_t uevent_lock; /* Protect access to uevent_list */
37783
37784@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37785 rwlock_init(&md->map_lock);
37786 atomic_set(&md->holders, 1);
37787 atomic_set(&md->open_count, 0);
37788- atomic_set(&md->event_nr, 0);
37789- atomic_set(&md->uevent_seq, 0);
37790+ atomic_set_unchecked(&md->event_nr, 0);
37791+ atomic_set_unchecked(&md->uevent_seq, 0);
37792 INIT_LIST_HEAD(&md->uevent_list);
37793 spin_lock_init(&md->uevent_lock);
37794
37795@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
37796
37797 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37798
37799- atomic_inc(&md->event_nr);
37800+ atomic_inc_unchecked(&md->event_nr);
37801 wake_up(&md->eventq);
37802 }
37803
37804@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37805
37806 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37807 {
37808- return atomic_add_return(1, &md->uevent_seq);
37809+ return atomic_add_return_unchecked(1, &md->uevent_seq);
37810 }
37811
37812 uint32_t dm_get_event_nr(struct mapped_device *md)
37813 {
37814- return atomic_read(&md->event_nr);
37815+ return atomic_read_unchecked(&md->event_nr);
37816 }
37817
37818 int dm_wait_event(struct mapped_device *md, int event_nr)
37819 {
37820 return wait_event_interruptible(md->eventq,
37821- (event_nr != atomic_read(&md->event_nr)));
37822+ (event_nr != atomic_read_unchecked(&md->event_nr)));
37823 }
37824
37825 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37826diff --git a/drivers/md/md.c b/drivers/md/md.c
37827index f363135..9b38815 100644
37828--- a/drivers/md/md.c
37829+++ b/drivers/md/md.c
37830@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37831 * start build, activate spare
37832 */
37833 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37834-static atomic_t md_event_count;
37835+static atomic_unchecked_t md_event_count;
37836 void md_new_event(struct mddev *mddev)
37837 {
37838- atomic_inc(&md_event_count);
37839+ atomic_inc_unchecked(&md_event_count);
37840 wake_up(&md_event_waiters);
37841 }
37842 EXPORT_SYMBOL_GPL(md_new_event);
37843@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37844 */
37845 static void md_new_event_inintr(struct mddev *mddev)
37846 {
37847- atomic_inc(&md_event_count);
37848+ atomic_inc_unchecked(&md_event_count);
37849 wake_up(&md_event_waiters);
37850 }
37851
37852@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37853 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37854 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37855 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37856- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37857+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37858
37859 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37860 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37861@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37862 else
37863 sb->resync_offset = cpu_to_le64(0);
37864
37865- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37866+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37867
37868 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37869 sb->size = cpu_to_le64(mddev->dev_sectors);
37870@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37871 static ssize_t
37872 errors_show(struct md_rdev *rdev, char *page)
37873 {
37874- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37875+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37876 }
37877
37878 static ssize_t
37879@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37880 char *e;
37881 unsigned long n = simple_strtoul(buf, &e, 10);
37882 if (*buf && (*e == 0 || *e == '\n')) {
37883- atomic_set(&rdev->corrected_errors, n);
37884+ atomic_set_unchecked(&rdev->corrected_errors, n);
37885 return len;
37886 }
37887 return -EINVAL;
37888@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
37889 rdev->sb_loaded = 0;
37890 rdev->bb_page = NULL;
37891 atomic_set(&rdev->nr_pending, 0);
37892- atomic_set(&rdev->read_errors, 0);
37893- atomic_set(&rdev->corrected_errors, 0);
37894+ atomic_set_unchecked(&rdev->read_errors, 0);
37895+ atomic_set_unchecked(&rdev->corrected_errors, 0);
37896
37897 INIT_LIST_HEAD(&rdev->same_set);
37898 init_waitqueue_head(&rdev->blocked_wait);
37899@@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37900
37901 spin_unlock(&pers_lock);
37902 seq_printf(seq, "\n");
37903- seq->poll_event = atomic_read(&md_event_count);
37904+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37905 return 0;
37906 }
37907 if (v == (void*)2) {
37908@@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37909 return error;
37910
37911 seq = file->private_data;
37912- seq->poll_event = atomic_read(&md_event_count);
37913+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37914 return error;
37915 }
37916
37917@@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37918 /* always allow read */
37919 mask = POLLIN | POLLRDNORM;
37920
37921- if (seq->poll_event != atomic_read(&md_event_count))
37922+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37923 mask |= POLLERR | POLLPRI;
37924 return mask;
37925 }
37926@@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37927 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37928 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37929 (int)part_stat_read(&disk->part0, sectors[1]) -
37930- atomic_read(&disk->sync_io);
37931+ atomic_read_unchecked(&disk->sync_io);
37932 /* sync IO will cause sync_io to increase before the disk_stats
37933 * as sync_io is counted when a request starts, and
37934 * disk_stats is counted when it completes.
37935diff --git a/drivers/md/md.h b/drivers/md/md.h
37936index eca59c3..7c42285 100644
37937--- a/drivers/md/md.h
37938+++ b/drivers/md/md.h
37939@@ -94,13 +94,13 @@ struct md_rdev {
37940 * only maintained for arrays that
37941 * support hot removal
37942 */
37943- atomic_t read_errors; /* number of consecutive read errors that
37944+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
37945 * we have tried to ignore.
37946 */
37947 struct timespec last_read_error; /* monotonic time since our
37948 * last read error
37949 */
37950- atomic_t corrected_errors; /* number of corrected read errors,
37951+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37952 * for reporting to userspace and storing
37953 * in superblock.
37954 */
37955@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37956
37957 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37958 {
37959- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37960+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37961 }
37962
37963 struct md_personality
37964diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37965index 1cbfc6b..56e1dbb 100644
37966--- a/drivers/md/persistent-data/dm-space-map.h
37967+++ b/drivers/md/persistent-data/dm-space-map.h
37968@@ -60,6 +60,7 @@ struct dm_space_map {
37969 int (*root_size)(struct dm_space_map *sm, size_t *result);
37970 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37971 };
37972+typedef struct dm_space_map __no_const dm_space_map_no_const;
37973
37974 /*----------------------------------------------------------------*/
37975
37976diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37977index 75b1f89..00ba344 100644
37978--- a/drivers/md/raid1.c
37979+++ b/drivers/md/raid1.c
37980@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37981 if (r1_sync_page_io(rdev, sect, s,
37982 bio->bi_io_vec[idx].bv_page,
37983 READ) != 0)
37984- atomic_add(s, &rdev->corrected_errors);
37985+ atomic_add_unchecked(s, &rdev->corrected_errors);
37986 }
37987 sectors -= s;
37988 sect += s;
37989@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37990 test_bit(In_sync, &rdev->flags)) {
37991 if (r1_sync_page_io(rdev, sect, s,
37992 conf->tmppage, READ)) {
37993- atomic_add(s, &rdev->corrected_errors);
37994+ atomic_add_unchecked(s, &rdev->corrected_errors);
37995 printk(KERN_INFO
37996 "md/raid1:%s: read error corrected "
37997 "(%d sectors at %llu on %s)\n",
37998diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
37999index 8d925dc..11d674f 100644
38000--- a/drivers/md/raid10.c
38001+++ b/drivers/md/raid10.c
38002@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
38003 /* The write handler will notice the lack of
38004 * R10BIO_Uptodate and record any errors etc
38005 */
38006- atomic_add(r10_bio->sectors,
38007+ atomic_add_unchecked(r10_bio->sectors,
38008 &conf->mirrors[d].rdev->corrected_errors);
38009
38010 /* for reconstruct, we always reschedule after a read.
38011@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38012 {
38013 struct timespec cur_time_mon;
38014 unsigned long hours_since_last;
38015- unsigned int read_errors = atomic_read(&rdev->read_errors);
38016+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38017
38018 ktime_get_ts(&cur_time_mon);
38019
38020@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38021 * overflowing the shift of read_errors by hours_since_last.
38022 */
38023 if (hours_since_last >= 8 * sizeof(read_errors))
38024- atomic_set(&rdev->read_errors, 0);
38025+ atomic_set_unchecked(&rdev->read_errors, 0);
38026 else
38027- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38028+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38029 }
38030
38031 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38032@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38033 return;
38034
38035 check_decay_read_errors(mddev, rdev);
38036- atomic_inc(&rdev->read_errors);
38037- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38038+ atomic_inc_unchecked(&rdev->read_errors);
38039+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38040 char b[BDEVNAME_SIZE];
38041 bdevname(rdev->bdev, b);
38042
38043@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38044 "md/raid10:%s: %s: Raid device exceeded "
38045 "read_error threshold [cur %d:max %d]\n",
38046 mdname(mddev), b,
38047- atomic_read(&rdev->read_errors), max_read_errors);
38048+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38049 printk(KERN_NOTICE
38050 "md/raid10:%s: %s: Failing raid device\n",
38051 mdname(mddev), b);
38052@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38053 sect +
38054 choose_data_offset(r10_bio, rdev)),
38055 bdevname(rdev->bdev, b));
38056- atomic_add(s, &rdev->corrected_errors);
38057+ atomic_add_unchecked(s, &rdev->corrected_errors);
38058 }
38059
38060 rdev_dec_pending(rdev, mddev);
38061diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38062index 19d77a0..56051b92 100644
38063--- a/drivers/md/raid5.c
38064+++ b/drivers/md/raid5.c
38065@@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38066 mdname(conf->mddev), STRIPE_SECTORS,
38067 (unsigned long long)s,
38068 bdevname(rdev->bdev, b));
38069- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38070+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38071 clear_bit(R5_ReadError, &sh->dev[i].flags);
38072 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38073 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38074 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38075
38076- if (atomic_read(&rdev->read_errors))
38077- atomic_set(&rdev->read_errors, 0);
38078+ if (atomic_read_unchecked(&rdev->read_errors))
38079+ atomic_set_unchecked(&rdev->read_errors, 0);
38080 } else {
38081 const char *bdn = bdevname(rdev->bdev, b);
38082 int retry = 0;
38083 int set_bad = 0;
38084
38085 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38086- atomic_inc(&rdev->read_errors);
38087+ atomic_inc_unchecked(&rdev->read_errors);
38088 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38089 printk_ratelimited(
38090 KERN_WARNING
38091@@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38092 mdname(conf->mddev),
38093 (unsigned long long)s,
38094 bdn);
38095- } else if (atomic_read(&rdev->read_errors)
38096+ } else if (atomic_read_unchecked(&rdev->read_errors)
38097 > conf->max_nr_stripes)
38098 printk(KERN_WARNING
38099 "md/raid:%s: Too many read errors, failing device %s.\n",
38100diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38101index d33101a..6b13069 100644
38102--- a/drivers/media/dvb-core/dvbdev.c
38103+++ b/drivers/media/dvb-core/dvbdev.c
38104@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38105 const struct dvb_device *template, void *priv, int type)
38106 {
38107 struct dvb_device *dvbdev;
38108- struct file_operations *dvbdevfops;
38109+ file_operations_no_const *dvbdevfops;
38110 struct device *clsdev;
38111 int minor;
38112 int id;
38113diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38114index 404f63a..4796533 100644
38115--- a/drivers/media/dvb-frontends/dib3000.h
38116+++ b/drivers/media/dvb-frontends/dib3000.h
38117@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38118 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38119 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38120 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38121-};
38122+} __no_const;
38123
38124 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
38125 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38126diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38127index 8e9a668..78d6310 100644
38128--- a/drivers/media/platform/omap/omap_vout.c
38129+++ b/drivers/media/platform/omap/omap_vout.c
38130@@ -63,7 +63,6 @@ enum omap_vout_channels {
38131 OMAP_VIDEO2,
38132 };
38133
38134-static struct videobuf_queue_ops video_vbq_ops;
38135 /* Variables configurable through module params*/
38136 static u32 video1_numbuffers = 3;
38137 static u32 video2_numbuffers = 3;
38138@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38139 {
38140 struct videobuf_queue *q;
38141 struct omap_vout_device *vout = NULL;
38142+ static struct videobuf_queue_ops video_vbq_ops = {
38143+ .buf_setup = omap_vout_buffer_setup,
38144+ .buf_prepare = omap_vout_buffer_prepare,
38145+ .buf_release = omap_vout_buffer_release,
38146+ .buf_queue = omap_vout_buffer_queue,
38147+ };
38148
38149 vout = video_drvdata(file);
38150 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38151@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38152 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38153
38154 q = &vout->vbq;
38155- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38156- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38157- video_vbq_ops.buf_release = omap_vout_buffer_release;
38158- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38159 spin_lock_init(&vout->vbq_lock);
38160
38161 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38162diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38163index b671e20..34088b7 100644
38164--- a/drivers/media/platform/s5p-tv/mixer.h
38165+++ b/drivers/media/platform/s5p-tv/mixer.h
38166@@ -155,7 +155,7 @@ struct mxr_layer {
38167 /** layer index (unique identifier) */
38168 int idx;
38169 /** callbacks for layer methods */
38170- struct mxr_layer_ops ops;
38171+ struct mxr_layer_ops *ops;
38172 /** format array */
38173 const struct mxr_format **fmt_array;
38174 /** size of format array */
38175diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38176index b93a21f..2535195 100644
38177--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38178+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38179@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38180 {
38181 struct mxr_layer *layer;
38182 int ret;
38183- struct mxr_layer_ops ops = {
38184+ static struct mxr_layer_ops ops = {
38185 .release = mxr_graph_layer_release,
38186 .buffer_set = mxr_graph_buffer_set,
38187 .stream_set = mxr_graph_stream_set,
38188diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38189index 3b1670a..595c939 100644
38190--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38191+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38192@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38193 layer->update_buf = next;
38194 }
38195
38196- layer->ops.buffer_set(layer, layer->update_buf);
38197+ layer->ops->buffer_set(layer, layer->update_buf);
38198
38199 if (done && done != layer->shadow_buf)
38200 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38201diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38202index 1f3b743..e839271 100644
38203--- a/drivers/media/platform/s5p-tv/mixer_video.c
38204+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38205@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38206 layer->geo.src.height = layer->geo.src.full_height;
38207
38208 mxr_geometry_dump(mdev, &layer->geo);
38209- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38210+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38211 mxr_geometry_dump(mdev, &layer->geo);
38212 }
38213
38214@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38215 layer->geo.dst.full_width = mbus_fmt.width;
38216 layer->geo.dst.full_height = mbus_fmt.height;
38217 layer->geo.dst.field = mbus_fmt.field;
38218- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38219+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38220
38221 mxr_geometry_dump(mdev, &layer->geo);
38222 }
38223@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38224 /* set source size to highest accepted value */
38225 geo->src.full_width = max(geo->dst.full_width, pix->width);
38226 geo->src.full_height = max(geo->dst.full_height, pix->height);
38227- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38228+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38229 mxr_geometry_dump(mdev, &layer->geo);
38230 /* set cropping to total visible screen */
38231 geo->src.width = pix->width;
38232@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38233 geo->src.x_offset = 0;
38234 geo->src.y_offset = 0;
38235 /* assure consistency of geometry */
38236- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38237+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38238 mxr_geometry_dump(mdev, &layer->geo);
38239 /* set full size to lowest possible value */
38240 geo->src.full_width = 0;
38241 geo->src.full_height = 0;
38242- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38243+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38244 mxr_geometry_dump(mdev, &layer->geo);
38245
38246 /* returning results */
38247@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38248 target->width = s->r.width;
38249 target->height = s->r.height;
38250
38251- layer->ops.fix_geometry(layer, stage, s->flags);
38252+ layer->ops->fix_geometry(layer, stage, s->flags);
38253
38254 /* retrieve update selection rectangle */
38255 res.left = target->x_offset;
38256@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38257 mxr_output_get(mdev);
38258
38259 mxr_layer_update_output(layer);
38260- layer->ops.format_set(layer);
38261+ layer->ops->format_set(layer);
38262 /* enabling layer in hardware */
38263 spin_lock_irqsave(&layer->enq_slock, flags);
38264 layer->state = MXR_LAYER_STREAMING;
38265 spin_unlock_irqrestore(&layer->enq_slock, flags);
38266
38267- layer->ops.stream_set(layer, MXR_ENABLE);
38268+ layer->ops->stream_set(layer, MXR_ENABLE);
38269 mxr_streamer_get(mdev);
38270
38271 return 0;
38272@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38273 spin_unlock_irqrestore(&layer->enq_slock, flags);
38274
38275 /* disabling layer in hardware */
38276- layer->ops.stream_set(layer, MXR_DISABLE);
38277+ layer->ops->stream_set(layer, MXR_DISABLE);
38278 /* remove one streamer */
38279 mxr_streamer_put(mdev);
38280 /* allow changes in output configuration */
38281@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38282
38283 void mxr_layer_release(struct mxr_layer *layer)
38284 {
38285- if (layer->ops.release)
38286- layer->ops.release(layer);
38287+ if (layer->ops->release)
38288+ layer->ops->release(layer);
38289 }
38290
38291 void mxr_base_layer_release(struct mxr_layer *layer)
38292@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38293
38294 layer->mdev = mdev;
38295 layer->idx = idx;
38296- layer->ops = *ops;
38297+ layer->ops = ops;
38298
38299 spin_lock_init(&layer->enq_slock);
38300 INIT_LIST_HEAD(&layer->enq_list);
38301diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38302index 3d13a63..da31bf1 100644
38303--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38304+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38305@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38306 {
38307 struct mxr_layer *layer;
38308 int ret;
38309- struct mxr_layer_ops ops = {
38310+ static struct mxr_layer_ops ops = {
38311 .release = mxr_vp_layer_release,
38312 .buffer_set = mxr_vp_buffer_set,
38313 .stream_set = mxr_vp_stream_set,
38314diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38315index 643d80a..56bb96b 100644
38316--- a/drivers/media/radio/radio-cadet.c
38317+++ b/drivers/media/radio/radio-cadet.c
38318@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38319 unsigned char readbuf[RDS_BUFFER];
38320 int i = 0;
38321
38322+ if (count > RDS_BUFFER)
38323+ return -EFAULT;
38324 mutex_lock(&dev->lock);
38325 if (dev->rdsstat == 0)
38326 cadet_start_rds(dev);
38327@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38328 while (i < count && dev->rdsin != dev->rdsout)
38329 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38330
38331- if (i && copy_to_user(data, readbuf, i))
38332+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38333 i = -EFAULT;
38334 unlock:
38335 mutex_unlock(&dev->lock);
38336diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38337index 3940bb0..fb3952a 100644
38338--- a/drivers/media/usb/dvb-usb/cxusb.c
38339+++ b/drivers/media/usb/dvb-usb/cxusb.c
38340@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38341
38342 struct dib0700_adapter_state {
38343 int (*set_param_save) (struct dvb_frontend *);
38344-};
38345+} __no_const;
38346
38347 static int dib7070_set_param_override(struct dvb_frontend *fe)
38348 {
38349diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38350index 9382895..ac8093c 100644
38351--- a/drivers/media/usb/dvb-usb/dw2102.c
38352+++ b/drivers/media/usb/dvb-usb/dw2102.c
38353@@ -95,7 +95,7 @@ struct su3000_state {
38354
38355 struct s6x0_state {
38356 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38357-};
38358+} __no_const;
38359
38360 /* debug */
38361 static int dvb_usb_dw2102_debug;
38362diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38363index aa6e7c7..4cd8061 100644
38364--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38365+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38366@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38367 struct file *file, void *fh, void *p);
38368 } u;
38369 void (*debug)(const void *arg, bool write_only);
38370-};
38371+} __do_const;
38372+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38373
38374 /* This control needs a priority check */
38375 #define INFO_FL_PRIO (1 << 0)
38376@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38377 struct video_device *vfd = video_devdata(file);
38378 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38379 bool write_only = false;
38380- struct v4l2_ioctl_info default_info;
38381+ v4l2_ioctl_info_no_const default_info;
38382 const struct v4l2_ioctl_info *info;
38383 void *fh = file->private_data;
38384 struct v4l2_fh *vfh = NULL;
38385diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38386index 29b2172..a7c5b31 100644
38387--- a/drivers/memstick/host/r592.c
38388+++ b/drivers/memstick/host/r592.c
38389@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38390 /* Executes one TPC (data is read/written from small or large fifo) */
38391 static void r592_execute_tpc(struct r592_device *dev)
38392 {
38393- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38394+ bool is_write;
38395 int len, error;
38396 u32 status, reg;
38397
38398@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38399 return;
38400 }
38401
38402+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38403 len = dev->req->long_data ?
38404 dev->req->sg.length : dev->req->data_len;
38405
38406diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38407index fb69baa..3aeea2e 100644
38408--- a/drivers/message/fusion/mptbase.c
38409+++ b/drivers/message/fusion/mptbase.c
38410@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38411 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38412 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38413
38414+#ifdef CONFIG_GRKERNSEC_HIDESYM
38415+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38416+#else
38417 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38418 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38419+#endif
38420+
38421 /*
38422 * Rounding UP to nearest 4-kB boundary here...
38423 */
38424@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38425 ioc->facts.GlobalCredits);
38426
38427 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38428+#ifdef CONFIG_GRKERNSEC_HIDESYM
38429+ NULL, NULL);
38430+#else
38431 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38432+#endif
38433 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38434 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38435 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38436diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38437index fa43c39..daeb158 100644
38438--- a/drivers/message/fusion/mptsas.c
38439+++ b/drivers/message/fusion/mptsas.c
38440@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38441 return 0;
38442 }
38443
38444+static inline void
38445+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38446+{
38447+ if (phy_info->port_details) {
38448+ phy_info->port_details->rphy = rphy;
38449+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38450+ ioc->name, rphy));
38451+ }
38452+
38453+ if (rphy) {
38454+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38455+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38456+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38457+ ioc->name, rphy, rphy->dev.release));
38458+ }
38459+}
38460+
38461 /* no mutex */
38462 static void
38463 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38464@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38465 return NULL;
38466 }
38467
38468-static inline void
38469-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38470-{
38471- if (phy_info->port_details) {
38472- phy_info->port_details->rphy = rphy;
38473- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38474- ioc->name, rphy));
38475- }
38476-
38477- if (rphy) {
38478- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38479- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38480- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38481- ioc->name, rphy, rphy->dev.release));
38482- }
38483-}
38484-
38485 static inline struct sas_port *
38486 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38487 {
38488diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38489index 164afa7..b6b2e74 100644
38490--- a/drivers/message/fusion/mptscsih.c
38491+++ b/drivers/message/fusion/mptscsih.c
38492@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38493
38494 h = shost_priv(SChost);
38495
38496- if (h) {
38497- if (h->info_kbuf == NULL)
38498- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38499- return h->info_kbuf;
38500- h->info_kbuf[0] = '\0';
38501+ if (!h)
38502+ return NULL;
38503
38504- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38505- h->info_kbuf[size-1] = '\0';
38506- }
38507+ if (h->info_kbuf == NULL)
38508+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38509+ return h->info_kbuf;
38510+ h->info_kbuf[0] = '\0';
38511+
38512+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38513+ h->info_kbuf[size-1] = '\0';
38514
38515 return h->info_kbuf;
38516 }
38517diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38518index 8001aa6..b137580 100644
38519--- a/drivers/message/i2o/i2o_proc.c
38520+++ b/drivers/message/i2o/i2o_proc.c
38521@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38522 "Array Controller Device"
38523 };
38524
38525-static char *chtostr(char *tmp, u8 *chars, int n)
38526-{
38527- tmp[0] = 0;
38528- return strncat(tmp, (char *)chars, n);
38529-}
38530-
38531 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38532 char *group)
38533 {
38534@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38535 } *result;
38536
38537 i2o_exec_execute_ddm_table ddm_table;
38538- char tmp[28 + 1];
38539
38540 result = kmalloc(sizeof(*result), GFP_KERNEL);
38541 if (!result)
38542@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38543
38544 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38545 seq_printf(seq, "%-#8x", ddm_table.module_id);
38546- seq_printf(seq, "%-29s",
38547- chtostr(tmp, ddm_table.module_name_version, 28));
38548+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38549 seq_printf(seq, "%9d ", ddm_table.data_size);
38550 seq_printf(seq, "%8d", ddm_table.code_size);
38551
38552@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38553
38554 i2o_driver_result_table *result;
38555 i2o_driver_store_table *dst;
38556- char tmp[28 + 1];
38557
38558 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38559 if (result == NULL)
38560@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38561
38562 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38563 seq_printf(seq, "%-#8x", dst->module_id);
38564- seq_printf(seq, "%-29s",
38565- chtostr(tmp, dst->module_name_version, 28));
38566- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38567+ seq_printf(seq, "%-.28s", dst->module_name_version);
38568+ seq_printf(seq, "%-.8s", dst->date);
38569 seq_printf(seq, "%8d ", dst->module_size);
38570 seq_printf(seq, "%8d ", dst->mpb_size);
38571 seq_printf(seq, "0x%04x", dst->module_flags);
38572@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38573 // == (allow) 512d bytes (max)
38574 static u16 *work16 = (u16 *) work32;
38575 int token;
38576- char tmp[16 + 1];
38577
38578 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38579
38580@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38581 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38582 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38583 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38584- seq_printf(seq, "Vendor info : %s\n",
38585- chtostr(tmp, (u8 *) (work32 + 2), 16));
38586- seq_printf(seq, "Product info : %s\n",
38587- chtostr(tmp, (u8 *) (work32 + 6), 16));
38588- seq_printf(seq, "Description : %s\n",
38589- chtostr(tmp, (u8 *) (work32 + 10), 16));
38590- seq_printf(seq, "Product rev. : %s\n",
38591- chtostr(tmp, (u8 *) (work32 + 14), 8));
38592+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38593+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38594+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38595+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38596
38597 seq_printf(seq, "Serial number : ");
38598 print_serial_number(seq, (u8 *) (work32 + 16),
38599@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38600 u8 pad[256]; // allow up to 256 byte (max) serial number
38601 } result;
38602
38603- char tmp[24 + 1];
38604-
38605 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38606
38607 if (token < 0) {
38608@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38609 }
38610
38611 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38612- seq_printf(seq, "Module name : %s\n",
38613- chtostr(tmp, result.module_name, 24));
38614- seq_printf(seq, "Module revision : %s\n",
38615- chtostr(tmp, result.module_rev, 8));
38616+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
38617+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38618
38619 seq_printf(seq, "Serial number : ");
38620 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38621@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38622 u8 instance_number[4];
38623 } result;
38624
38625- char tmp[64 + 1];
38626-
38627 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38628
38629 if (token < 0) {
38630@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38631 return 0;
38632 }
38633
38634- seq_printf(seq, "Device name : %s\n",
38635- chtostr(tmp, result.device_name, 64));
38636- seq_printf(seq, "Service name : %s\n",
38637- chtostr(tmp, result.service_name, 64));
38638- seq_printf(seq, "Physical name : %s\n",
38639- chtostr(tmp, result.physical_location, 64));
38640- seq_printf(seq, "Instance number : %s\n",
38641- chtostr(tmp, result.instance_number, 4));
38642+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
38643+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
38644+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38645+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38646
38647 return 0;
38648 }
38649diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38650index a8c08f3..155fe3d 100644
38651--- a/drivers/message/i2o/iop.c
38652+++ b/drivers/message/i2o/iop.c
38653@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38654
38655 spin_lock_irqsave(&c->context_list_lock, flags);
38656
38657- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38658- atomic_inc(&c->context_list_counter);
38659+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38660+ atomic_inc_unchecked(&c->context_list_counter);
38661
38662- entry->context = atomic_read(&c->context_list_counter);
38663+ entry->context = atomic_read_unchecked(&c->context_list_counter);
38664
38665 list_add(&entry->list, &c->context_list);
38666
38667@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38668
38669 #if BITS_PER_LONG == 64
38670 spin_lock_init(&c->context_list_lock);
38671- atomic_set(&c->context_list_counter, 0);
38672+ atomic_set_unchecked(&c->context_list_counter, 0);
38673 INIT_LIST_HEAD(&c->context_list);
38674 #endif
38675
38676diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38677index 45ece11..8efa218 100644
38678--- a/drivers/mfd/janz-cmodio.c
38679+++ b/drivers/mfd/janz-cmodio.c
38680@@ -13,6 +13,7 @@
38681
38682 #include <linux/kernel.h>
38683 #include <linux/module.h>
38684+#include <linux/slab.h>
38685 #include <linux/init.h>
38686 #include <linux/pci.h>
38687 #include <linux/interrupt.h>
38688diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38689index a5f9888..1c0ed56 100644
38690--- a/drivers/mfd/twl4030-irq.c
38691+++ b/drivers/mfd/twl4030-irq.c
38692@@ -35,6 +35,7 @@
38693 #include <linux/of.h>
38694 #include <linux/irqdomain.h>
38695 #include <linux/i2c/twl.h>
38696+#include <asm/pgtable.h>
38697
38698 #include "twl-core.h"
38699
38700@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38701 * Install an irq handler for each of the SIH modules;
38702 * clone dummy irq_chip since PIH can't *do* anything
38703 */
38704- twl4030_irq_chip = dummy_irq_chip;
38705- twl4030_irq_chip.name = "twl4030";
38706+ pax_open_kernel();
38707+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38708+ *(const char **)&twl4030_irq_chip.name = "twl4030";
38709
38710- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38711+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38712+ pax_close_kernel();
38713
38714 for (i = irq_base; i < irq_end; i++) {
38715 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38716diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38717index 277a8db..0e0b754 100644
38718--- a/drivers/mfd/twl6030-irq.c
38719+++ b/drivers/mfd/twl6030-irq.c
38720@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38721 * install an irq handler for each of the modules;
38722 * clone dummy irq_chip since PIH can't *do* anything
38723 */
38724- twl6030_irq_chip = dummy_irq_chip;
38725- twl6030_irq_chip.name = "twl6030";
38726- twl6030_irq_chip.irq_set_type = NULL;
38727- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38728+ pax_open_kernel();
38729+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38730+ *(const char **)&twl6030_irq_chip.name = "twl6030";
38731+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38732+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38733+ pax_close_kernel();
38734
38735 for (i = irq_base; i < irq_end; i++) {
38736 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38737diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38738index f428d86..274c368 100644
38739--- a/drivers/misc/c2port/core.c
38740+++ b/drivers/misc/c2port/core.c
38741@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38742 mutex_init(&c2dev->mutex);
38743
38744 /* Create binary file */
38745- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38746+ pax_open_kernel();
38747+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38748+ pax_close_kernel();
38749 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38750 if (unlikely(ret))
38751 goto error_device_create_bin_file;
38752diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38753index 3aa9a96..59cf685 100644
38754--- a/drivers/misc/kgdbts.c
38755+++ b/drivers/misc/kgdbts.c
38756@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38757 char before[BREAK_INSTR_SIZE];
38758 char after[BREAK_INSTR_SIZE];
38759
38760- probe_kernel_read(before, (char *)kgdbts_break_test,
38761+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38762 BREAK_INSTR_SIZE);
38763 init_simple_test();
38764 ts.tst = plant_and_detach_test;
38765@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38766 /* Activate test with initial breakpoint */
38767 if (!is_early)
38768 kgdb_breakpoint();
38769- probe_kernel_read(after, (char *)kgdbts_break_test,
38770+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38771 BREAK_INSTR_SIZE);
38772 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38773 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38774diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38775index 4a87e5c..76bdf5c 100644
38776--- a/drivers/misc/lis3lv02d/lis3lv02d.c
38777+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38778@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38779 * the lid is closed. This leads to interrupts as soon as a little move
38780 * is done.
38781 */
38782- atomic_inc(&lis3->count);
38783+ atomic_inc_unchecked(&lis3->count);
38784
38785 wake_up_interruptible(&lis3->misc_wait);
38786 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38787@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38788 if (lis3->pm_dev)
38789 pm_runtime_get_sync(lis3->pm_dev);
38790
38791- atomic_set(&lis3->count, 0);
38792+ atomic_set_unchecked(&lis3->count, 0);
38793 return 0;
38794 }
38795
38796@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38797 add_wait_queue(&lis3->misc_wait, &wait);
38798 while (true) {
38799 set_current_state(TASK_INTERRUPTIBLE);
38800- data = atomic_xchg(&lis3->count, 0);
38801+ data = atomic_xchg_unchecked(&lis3->count, 0);
38802 if (data)
38803 break;
38804
38805@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38806 struct lis3lv02d, miscdev);
38807
38808 poll_wait(file, &lis3->misc_wait, wait);
38809- if (atomic_read(&lis3->count))
38810+ if (atomic_read_unchecked(&lis3->count))
38811 return POLLIN | POLLRDNORM;
38812 return 0;
38813 }
38814diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38815index c439c82..1f20f57 100644
38816--- a/drivers/misc/lis3lv02d/lis3lv02d.h
38817+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38818@@ -297,7 +297,7 @@ struct lis3lv02d {
38819 struct input_polled_dev *idev; /* input device */
38820 struct platform_device *pdev; /* platform device */
38821 struct regulator_bulk_data regulators[2];
38822- atomic_t count; /* interrupt count after last read */
38823+ atomic_unchecked_t count; /* interrupt count after last read */
38824 union axis_conversion ac; /* hw -> logical axis */
38825 int mapped_btns[3];
38826
38827diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38828index 2f30bad..c4c13d0 100644
38829--- a/drivers/misc/sgi-gru/gruhandles.c
38830+++ b/drivers/misc/sgi-gru/gruhandles.c
38831@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38832 unsigned long nsec;
38833
38834 nsec = CLKS2NSEC(clks);
38835- atomic_long_inc(&mcs_op_statistics[op].count);
38836- atomic_long_add(nsec, &mcs_op_statistics[op].total);
38837+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38838+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38839 if (mcs_op_statistics[op].max < nsec)
38840 mcs_op_statistics[op].max = nsec;
38841 }
38842diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38843index 950dbe9..eeef0f8 100644
38844--- a/drivers/misc/sgi-gru/gruprocfs.c
38845+++ b/drivers/misc/sgi-gru/gruprocfs.c
38846@@ -32,9 +32,9 @@
38847
38848 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38849
38850-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38851+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38852 {
38853- unsigned long val = atomic_long_read(v);
38854+ unsigned long val = atomic_long_read_unchecked(v);
38855
38856 seq_printf(s, "%16lu %s\n", val, id);
38857 }
38858@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38859
38860 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38861 for (op = 0; op < mcsop_last; op++) {
38862- count = atomic_long_read(&mcs_op_statistics[op].count);
38863- total = atomic_long_read(&mcs_op_statistics[op].total);
38864+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38865+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38866 max = mcs_op_statistics[op].max;
38867 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38868 count ? total / count : 0, max);
38869diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38870index 5c3ce24..4915ccb 100644
38871--- a/drivers/misc/sgi-gru/grutables.h
38872+++ b/drivers/misc/sgi-gru/grutables.h
38873@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38874 * GRU statistics.
38875 */
38876 struct gru_stats_s {
38877- atomic_long_t vdata_alloc;
38878- atomic_long_t vdata_free;
38879- atomic_long_t gts_alloc;
38880- atomic_long_t gts_free;
38881- atomic_long_t gms_alloc;
38882- atomic_long_t gms_free;
38883- atomic_long_t gts_double_allocate;
38884- atomic_long_t assign_context;
38885- atomic_long_t assign_context_failed;
38886- atomic_long_t free_context;
38887- atomic_long_t load_user_context;
38888- atomic_long_t load_kernel_context;
38889- atomic_long_t lock_kernel_context;
38890- atomic_long_t unlock_kernel_context;
38891- atomic_long_t steal_user_context;
38892- atomic_long_t steal_kernel_context;
38893- atomic_long_t steal_context_failed;
38894- atomic_long_t nopfn;
38895- atomic_long_t asid_new;
38896- atomic_long_t asid_next;
38897- atomic_long_t asid_wrap;
38898- atomic_long_t asid_reuse;
38899- atomic_long_t intr;
38900- atomic_long_t intr_cbr;
38901- atomic_long_t intr_tfh;
38902- atomic_long_t intr_spurious;
38903- atomic_long_t intr_mm_lock_failed;
38904- atomic_long_t call_os;
38905- atomic_long_t call_os_wait_queue;
38906- atomic_long_t user_flush_tlb;
38907- atomic_long_t user_unload_context;
38908- atomic_long_t user_exception;
38909- atomic_long_t set_context_option;
38910- atomic_long_t check_context_retarget_intr;
38911- atomic_long_t check_context_unload;
38912- atomic_long_t tlb_dropin;
38913- atomic_long_t tlb_preload_page;
38914- atomic_long_t tlb_dropin_fail_no_asid;
38915- atomic_long_t tlb_dropin_fail_upm;
38916- atomic_long_t tlb_dropin_fail_invalid;
38917- atomic_long_t tlb_dropin_fail_range_active;
38918- atomic_long_t tlb_dropin_fail_idle;
38919- atomic_long_t tlb_dropin_fail_fmm;
38920- atomic_long_t tlb_dropin_fail_no_exception;
38921- atomic_long_t tfh_stale_on_fault;
38922- atomic_long_t mmu_invalidate_range;
38923- atomic_long_t mmu_invalidate_page;
38924- atomic_long_t flush_tlb;
38925- atomic_long_t flush_tlb_gru;
38926- atomic_long_t flush_tlb_gru_tgh;
38927- atomic_long_t flush_tlb_gru_zero_asid;
38928+ atomic_long_unchecked_t vdata_alloc;
38929+ atomic_long_unchecked_t vdata_free;
38930+ atomic_long_unchecked_t gts_alloc;
38931+ atomic_long_unchecked_t gts_free;
38932+ atomic_long_unchecked_t gms_alloc;
38933+ atomic_long_unchecked_t gms_free;
38934+ atomic_long_unchecked_t gts_double_allocate;
38935+ atomic_long_unchecked_t assign_context;
38936+ atomic_long_unchecked_t assign_context_failed;
38937+ atomic_long_unchecked_t free_context;
38938+ atomic_long_unchecked_t load_user_context;
38939+ atomic_long_unchecked_t load_kernel_context;
38940+ atomic_long_unchecked_t lock_kernel_context;
38941+ atomic_long_unchecked_t unlock_kernel_context;
38942+ atomic_long_unchecked_t steal_user_context;
38943+ atomic_long_unchecked_t steal_kernel_context;
38944+ atomic_long_unchecked_t steal_context_failed;
38945+ atomic_long_unchecked_t nopfn;
38946+ atomic_long_unchecked_t asid_new;
38947+ atomic_long_unchecked_t asid_next;
38948+ atomic_long_unchecked_t asid_wrap;
38949+ atomic_long_unchecked_t asid_reuse;
38950+ atomic_long_unchecked_t intr;
38951+ atomic_long_unchecked_t intr_cbr;
38952+ atomic_long_unchecked_t intr_tfh;
38953+ atomic_long_unchecked_t intr_spurious;
38954+ atomic_long_unchecked_t intr_mm_lock_failed;
38955+ atomic_long_unchecked_t call_os;
38956+ atomic_long_unchecked_t call_os_wait_queue;
38957+ atomic_long_unchecked_t user_flush_tlb;
38958+ atomic_long_unchecked_t user_unload_context;
38959+ atomic_long_unchecked_t user_exception;
38960+ atomic_long_unchecked_t set_context_option;
38961+ atomic_long_unchecked_t check_context_retarget_intr;
38962+ atomic_long_unchecked_t check_context_unload;
38963+ atomic_long_unchecked_t tlb_dropin;
38964+ atomic_long_unchecked_t tlb_preload_page;
38965+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38966+ atomic_long_unchecked_t tlb_dropin_fail_upm;
38967+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
38968+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
38969+ atomic_long_unchecked_t tlb_dropin_fail_idle;
38970+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
38971+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38972+ atomic_long_unchecked_t tfh_stale_on_fault;
38973+ atomic_long_unchecked_t mmu_invalidate_range;
38974+ atomic_long_unchecked_t mmu_invalidate_page;
38975+ atomic_long_unchecked_t flush_tlb;
38976+ atomic_long_unchecked_t flush_tlb_gru;
38977+ atomic_long_unchecked_t flush_tlb_gru_tgh;
38978+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38979
38980- atomic_long_t copy_gpa;
38981- atomic_long_t read_gpa;
38982+ atomic_long_unchecked_t copy_gpa;
38983+ atomic_long_unchecked_t read_gpa;
38984
38985- atomic_long_t mesq_receive;
38986- atomic_long_t mesq_receive_none;
38987- atomic_long_t mesq_send;
38988- atomic_long_t mesq_send_failed;
38989- atomic_long_t mesq_noop;
38990- atomic_long_t mesq_send_unexpected_error;
38991- atomic_long_t mesq_send_lb_overflow;
38992- atomic_long_t mesq_send_qlimit_reached;
38993- atomic_long_t mesq_send_amo_nacked;
38994- atomic_long_t mesq_send_put_nacked;
38995- atomic_long_t mesq_page_overflow;
38996- atomic_long_t mesq_qf_locked;
38997- atomic_long_t mesq_qf_noop_not_full;
38998- atomic_long_t mesq_qf_switch_head_failed;
38999- atomic_long_t mesq_qf_unexpected_error;
39000- atomic_long_t mesq_noop_unexpected_error;
39001- atomic_long_t mesq_noop_lb_overflow;
39002- atomic_long_t mesq_noop_qlimit_reached;
39003- atomic_long_t mesq_noop_amo_nacked;
39004- atomic_long_t mesq_noop_put_nacked;
39005- atomic_long_t mesq_noop_page_overflow;
39006+ atomic_long_unchecked_t mesq_receive;
39007+ atomic_long_unchecked_t mesq_receive_none;
39008+ atomic_long_unchecked_t mesq_send;
39009+ atomic_long_unchecked_t mesq_send_failed;
39010+ atomic_long_unchecked_t mesq_noop;
39011+ atomic_long_unchecked_t mesq_send_unexpected_error;
39012+ atomic_long_unchecked_t mesq_send_lb_overflow;
39013+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39014+ atomic_long_unchecked_t mesq_send_amo_nacked;
39015+ atomic_long_unchecked_t mesq_send_put_nacked;
39016+ atomic_long_unchecked_t mesq_page_overflow;
39017+ atomic_long_unchecked_t mesq_qf_locked;
39018+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39019+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39020+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39021+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39022+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39023+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39024+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39025+ atomic_long_unchecked_t mesq_noop_put_nacked;
39026+ atomic_long_unchecked_t mesq_noop_page_overflow;
39027
39028 };
39029
39030@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39031 tghop_invalidate, mcsop_last};
39032
39033 struct mcs_op_statistic {
39034- atomic_long_t count;
39035- atomic_long_t total;
39036+ atomic_long_unchecked_t count;
39037+ atomic_long_unchecked_t total;
39038 unsigned long max;
39039 };
39040
39041@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39042
39043 #define STAT(id) do { \
39044 if (gru_options & OPT_STATS) \
39045- atomic_long_inc(&gru_stats.id); \
39046+ atomic_long_inc_unchecked(&gru_stats.id); \
39047 } while (0)
39048
39049 #ifdef CONFIG_SGI_GRU_DEBUG
39050diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39051index c862cd4..0d176fe 100644
39052--- a/drivers/misc/sgi-xp/xp.h
39053+++ b/drivers/misc/sgi-xp/xp.h
39054@@ -288,7 +288,7 @@ struct xpc_interface {
39055 xpc_notify_func, void *);
39056 void (*received) (short, int, void *);
39057 enum xp_retval (*partid_to_nasids) (short, void *);
39058-};
39059+} __no_const;
39060
39061 extern struct xpc_interface xpc_interface;
39062
39063diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39064index b94d5f7..7f494c5 100644
39065--- a/drivers/misc/sgi-xp/xpc.h
39066+++ b/drivers/misc/sgi-xp/xpc.h
39067@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39068 void (*received_payload) (struct xpc_channel *, void *);
39069 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39070 };
39071+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39072
39073 /* struct xpc_partition act_state values (for XPC HB) */
39074
39075@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39076 /* found in xpc_main.c */
39077 extern struct device *xpc_part;
39078 extern struct device *xpc_chan;
39079-extern struct xpc_arch_operations xpc_arch_ops;
39080+extern xpc_arch_operations_no_const xpc_arch_ops;
39081 extern int xpc_disengage_timelimit;
39082 extern int xpc_disengage_timedout;
39083 extern int xpc_activate_IRQ_rcvd;
39084diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39085index d971817..33bdca5 100644
39086--- a/drivers/misc/sgi-xp/xpc_main.c
39087+++ b/drivers/misc/sgi-xp/xpc_main.c
39088@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39089 .notifier_call = xpc_system_die,
39090 };
39091
39092-struct xpc_arch_operations xpc_arch_ops;
39093+xpc_arch_operations_no_const xpc_arch_ops;
39094
39095 /*
39096 * Timer function to enforce the timelimit on the partition disengage.
39097@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39098
39099 if (((die_args->trapnr == X86_TRAP_MF) ||
39100 (die_args->trapnr == X86_TRAP_XF)) &&
39101- !user_mode_vm(die_args->regs))
39102+ !user_mode(die_args->regs))
39103 xpc_die_deactivate();
39104
39105 break;
39106diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39107index 6d8f701..35b6369 100644
39108--- a/drivers/mmc/core/mmc_ops.c
39109+++ b/drivers/mmc/core/mmc_ops.c
39110@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39111 void *data_buf;
39112 int is_on_stack;
39113
39114- is_on_stack = object_is_on_stack(buf);
39115+ is_on_stack = object_starts_on_stack(buf);
39116 if (is_on_stack) {
39117 /*
39118 * dma onto stack is unsafe/nonportable, but callers to this
39119diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39120index 53b8fd9..615b462 100644
39121--- a/drivers/mmc/host/dw_mmc.h
39122+++ b/drivers/mmc/host/dw_mmc.h
39123@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39124 int (*parse_dt)(struct dw_mci *host);
39125 int (*setup_bus)(struct dw_mci *host,
39126 struct device_node *slot_np, u8 bus_width);
39127-};
39128+} __do_const;
39129 #endif /* _DW_MMC_H_ */
39130diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39131index 82a8de1..3c56ccb 100644
39132--- a/drivers/mmc/host/sdhci-s3c.c
39133+++ b/drivers/mmc/host/sdhci-s3c.c
39134@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39135 * we can use overriding functions instead of default.
39136 */
39137 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39138- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39139- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39140- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39141+ pax_open_kernel();
39142+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39143+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39144+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39145+ pax_close_kernel();
39146 }
39147
39148 /* It supports additional host capabilities if needed */
39149diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39150index a4eb8b5..8c0628f 100644
39151--- a/drivers/mtd/devices/doc2000.c
39152+++ b/drivers/mtd/devices/doc2000.c
39153@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39154
39155 /* The ECC will not be calculated correctly if less than 512 is written */
39156 /* DBB-
39157- if (len != 0x200 && eccbuf)
39158+ if (len != 0x200)
39159 printk(KERN_WARNING
39160 "ECC needs a full sector write (adr: %lx size %lx)\n",
39161 (long) to, (long) len);
39162diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39163index 0c8bb6b..6f35deb 100644
39164--- a/drivers/mtd/nand/denali.c
39165+++ b/drivers/mtd/nand/denali.c
39166@@ -24,6 +24,7 @@
39167 #include <linux/slab.h>
39168 #include <linux/mtd/mtd.h>
39169 #include <linux/module.h>
39170+#include <linux/slab.h>
39171
39172 #include "denali.h"
39173
39174diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39175index 51b9d6a..52af9a7 100644
39176--- a/drivers/mtd/nftlmount.c
39177+++ b/drivers/mtd/nftlmount.c
39178@@ -24,6 +24,7 @@
39179 #include <asm/errno.h>
39180 #include <linux/delay.h>
39181 #include <linux/slab.h>
39182+#include <linux/sched.h>
39183 #include <linux/mtd/mtd.h>
39184 #include <linux/mtd/nand.h>
39185 #include <linux/mtd/nftl.h>
39186diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39187index 8dd6ba5..419cc1d 100644
39188--- a/drivers/mtd/sm_ftl.c
39189+++ b/drivers/mtd/sm_ftl.c
39190@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39191 #define SM_CIS_VENDOR_OFFSET 0x59
39192 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39193 {
39194- struct attribute_group *attr_group;
39195+ attribute_group_no_const *attr_group;
39196 struct attribute **attributes;
39197 struct sm_sysfs_attribute *vendor_attribute;
39198
39199diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39200index a079da17..f86ffd5 100644
39201--- a/drivers/net/bonding/bond_main.c
39202+++ b/drivers/net/bonding/bond_main.c
39203@@ -4862,7 +4862,7 @@ static unsigned int bond_get_num_tx_queues(void)
39204 return tx_queues;
39205 }
39206
39207-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39208+static struct rtnl_link_ops bond_link_ops = {
39209 .kind = "bond",
39210 .priv_size = sizeof(struct bonding),
39211 .setup = bond_setup,
39212diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39213index 70dba5d..11a0919 100644
39214--- a/drivers/net/ethernet/8390/ax88796.c
39215+++ b/drivers/net/ethernet/8390/ax88796.c
39216@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39217 if (ax->plat->reg_offsets)
39218 ei_local->reg_offset = ax->plat->reg_offsets;
39219 else {
39220+ resource_size_t _mem_size = mem_size;
39221+ do_div(_mem_size, 0x18);
39222 ei_local->reg_offset = ax->reg_offsets;
39223 for (ret = 0; ret < 0x18; ret++)
39224- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39225+ ax->reg_offsets[ret] = _mem_size * ret;
39226 }
39227
39228 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39229diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39230index 0991534..8098e92 100644
39231--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39232+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39233@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39234 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39235 {
39236 /* RX_MODE controlling object */
39237- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39238+ bnx2x_init_rx_mode_obj(bp);
39239
39240 /* multicast configuration controlling object */
39241 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39242diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39243index 09b625e..15b16fe 100644
39244--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39245+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39246@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39247 return rc;
39248 }
39249
39250-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39251- struct bnx2x_rx_mode_obj *o)
39252+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39253 {
39254 if (CHIP_IS_E1x(bp)) {
39255- o->wait_comp = bnx2x_empty_rx_mode_wait;
39256- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39257+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39258+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39259 } else {
39260- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39261- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39262+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39263+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39264 }
39265 }
39266
39267diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39268index adbd91b..58ec94a 100644
39269--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39270+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39271@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39272
39273 /********************* RX MODE ****************/
39274
39275-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39276- struct bnx2x_rx_mode_obj *o);
39277+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39278
39279 /**
39280 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39281diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39282index d330e81..ce1fb9a 100644
39283--- a/drivers/net/ethernet/broadcom/tg3.h
39284+++ b/drivers/net/ethernet/broadcom/tg3.h
39285@@ -146,6 +146,7 @@
39286 #define CHIPREV_ID_5750_A0 0x4000
39287 #define CHIPREV_ID_5750_A1 0x4001
39288 #define CHIPREV_ID_5750_A3 0x4003
39289+#define CHIPREV_ID_5750_C1 0x4201
39290 #define CHIPREV_ID_5750_C2 0x4202
39291 #define CHIPREV_ID_5752_A0_HW 0x5000
39292 #define CHIPREV_ID_5752_A0 0x6000
39293diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39294index 8cffcdf..aadf043 100644
39295--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39296+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39297@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39298 */
39299 struct l2t_skb_cb {
39300 arp_failure_handler_func arp_failure_handler;
39301-};
39302+} __no_const;
39303
39304 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39305
39306diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39307index 4c83003..2a2a5b9 100644
39308--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39309+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39310@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39311 for (i=0; i<ETH_ALEN; i++) {
39312 tmp.addr[i] = dev->dev_addr[i];
39313 }
39314- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39315+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39316 break;
39317
39318 case DE4X5_SET_HWADDR: /* Set the hardware address */
39319@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39320 spin_lock_irqsave(&lp->lock, flags);
39321 memcpy(&statbuf, &lp->pktStats, ioc->len);
39322 spin_unlock_irqrestore(&lp->lock, flags);
39323- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39324+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39325 return -EFAULT;
39326 break;
39327 }
39328diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39329index 4d6f3c5..6169e60 100644
39330--- a/drivers/net/ethernet/emulex/benet/be_main.c
39331+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39332@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39333
39334 if (wrapped)
39335 newacc += 65536;
39336- ACCESS_ONCE(*acc) = newacc;
39337+ ACCESS_ONCE_RW(*acc) = newacc;
39338 }
39339
39340 void be_parse_stats(struct be_adapter *adapter)
39341diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39342index 74d749e..eefb1bd 100644
39343--- a/drivers/net/ethernet/faraday/ftgmac100.c
39344+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39345@@ -31,6 +31,8 @@
39346 #include <linux/netdevice.h>
39347 #include <linux/phy.h>
39348 #include <linux/platform_device.h>
39349+#include <linux/interrupt.h>
39350+#include <linux/irqreturn.h>
39351 #include <net/ip.h>
39352
39353 #include "ftgmac100.h"
39354diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39355index b901a01..1ff32ee 100644
39356--- a/drivers/net/ethernet/faraday/ftmac100.c
39357+++ b/drivers/net/ethernet/faraday/ftmac100.c
39358@@ -31,6 +31,8 @@
39359 #include <linux/module.h>
39360 #include <linux/netdevice.h>
39361 #include <linux/platform_device.h>
39362+#include <linux/interrupt.h>
39363+#include <linux/irqreturn.h>
39364
39365 #include "ftmac100.h"
39366
39367diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39368index bb9256a..56d8752 100644
39369--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39370+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39371@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39372 }
39373
39374 /* update the base incval used to calculate frequency adjustment */
39375- ACCESS_ONCE(adapter->base_incval) = incval;
39376+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39377 smp_mb();
39378
39379 /* need lock to prevent incorrect read while modifying cyclecounter */
39380diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39381index fbe5363..266b4e3 100644
39382--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39383+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39384@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39385 struct __vxge_hw_fifo *fifo;
39386 struct vxge_hw_fifo_config *config;
39387 u32 txdl_size, txdl_per_memblock;
39388- struct vxge_hw_mempool_cbs fifo_mp_callback;
39389+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39390+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39391+ };
39392+
39393 struct __vxge_hw_virtualpath *vpath;
39394
39395 if ((vp == NULL) || (attr == NULL)) {
39396@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39397 goto exit;
39398 }
39399
39400- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39401-
39402 fifo->mempool =
39403 __vxge_hw_mempool_create(vpath->hldev,
39404 fifo->config->memblock_size,
39405diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39406index 998974f..ecd26db 100644
39407--- a/drivers/net/ethernet/realtek/r8169.c
39408+++ b/drivers/net/ethernet/realtek/r8169.c
39409@@ -741,22 +741,22 @@ struct rtl8169_private {
39410 struct mdio_ops {
39411 void (*write)(struct rtl8169_private *, int, int);
39412 int (*read)(struct rtl8169_private *, int);
39413- } mdio_ops;
39414+ } __no_const mdio_ops;
39415
39416 struct pll_power_ops {
39417 void (*down)(struct rtl8169_private *);
39418 void (*up)(struct rtl8169_private *);
39419- } pll_power_ops;
39420+ } __no_const pll_power_ops;
39421
39422 struct jumbo_ops {
39423 void (*enable)(struct rtl8169_private *);
39424 void (*disable)(struct rtl8169_private *);
39425- } jumbo_ops;
39426+ } __no_const jumbo_ops;
39427
39428 struct csi_ops {
39429 void (*write)(struct rtl8169_private *, int, int);
39430 u32 (*read)(struct rtl8169_private *, int);
39431- } csi_ops;
39432+ } __no_const csi_ops;
39433
39434 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39435 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39436diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39437index 0767043f..08c2553 100644
39438--- a/drivers/net/ethernet/sfc/ptp.c
39439+++ b/drivers/net/ethernet/sfc/ptp.c
39440@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39441 (u32)((u64)ptp->start.dma_addr >> 32));
39442
39443 /* Clear flag that signals MC ready */
39444- ACCESS_ONCE(*start) = 0;
39445+ ACCESS_ONCE_RW(*start) = 0;
39446 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39447 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39448
39449diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39450index 0c74a70..3bc6f68 100644
39451--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39452+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39453@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39454
39455 writel(value, ioaddr + MMC_CNTRL);
39456
39457- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39458- MMC_CNTRL, value);
39459+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39460+// MMC_CNTRL, value);
39461 }
39462
39463 /* To mask all all interrupts.*/
39464diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39465index e6fe0d8..2b7d752 100644
39466--- a/drivers/net/hyperv/hyperv_net.h
39467+++ b/drivers/net/hyperv/hyperv_net.h
39468@@ -101,7 +101,7 @@ struct rndis_device {
39469
39470 enum rndis_device_state state;
39471 bool link_state;
39472- atomic_t new_req_id;
39473+ atomic_unchecked_t new_req_id;
39474
39475 spinlock_t request_lock;
39476 struct list_head req_list;
39477diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39478index 2b657d4..9903bc0 100644
39479--- a/drivers/net/hyperv/rndis_filter.c
39480+++ b/drivers/net/hyperv/rndis_filter.c
39481@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39482 * template
39483 */
39484 set = &rndis_msg->msg.set_req;
39485- set->req_id = atomic_inc_return(&dev->new_req_id);
39486+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39487
39488 /* Add to the request list */
39489 spin_lock_irqsave(&dev->request_lock, flags);
39490@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39491
39492 /* Setup the rndis set */
39493 halt = &request->request_msg.msg.halt_req;
39494- halt->req_id = atomic_inc_return(&dev->new_req_id);
39495+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39496
39497 /* Ignore return since this msg is optional. */
39498 rndis_filter_send_request(dev, request);
39499diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39500index 1e9cb0b..7839125 100644
39501--- a/drivers/net/ieee802154/fakehard.c
39502+++ b/drivers/net/ieee802154/fakehard.c
39503@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39504 phy->transmit_power = 0xbf;
39505
39506 dev->netdev_ops = &fake_ops;
39507- dev->ml_priv = &fake_mlme;
39508+ dev->ml_priv = (void *)&fake_mlme;
39509
39510 priv = netdev_priv(dev);
39511 priv->phy = phy;
39512diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39513index e5cb723..1fc0461 100644
39514--- a/drivers/net/macvlan.c
39515+++ b/drivers/net/macvlan.c
39516@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39517 int macvlan_link_register(struct rtnl_link_ops *ops)
39518 {
39519 /* common fields */
39520- ops->priv_size = sizeof(struct macvlan_dev);
39521- ops->validate = macvlan_validate;
39522- ops->maxtype = IFLA_MACVLAN_MAX;
39523- ops->policy = macvlan_policy;
39524- ops->changelink = macvlan_changelink;
39525- ops->get_size = macvlan_get_size;
39526- ops->fill_info = macvlan_fill_info;
39527+ pax_open_kernel();
39528+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39529+ *(void **)&ops->validate = macvlan_validate;
39530+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39531+ *(const void **)&ops->policy = macvlan_policy;
39532+ *(void **)&ops->changelink = macvlan_changelink;
39533+ *(void **)&ops->get_size = macvlan_get_size;
39534+ *(void **)&ops->fill_info = macvlan_fill_info;
39535+ pax_close_kernel();
39536
39537 return rtnl_link_register(ops);
39538 };
39539@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39540 return NOTIFY_DONE;
39541 }
39542
39543-static struct notifier_block macvlan_notifier_block __read_mostly = {
39544+static struct notifier_block macvlan_notifier_block = {
39545 .notifier_call = macvlan_device_event,
39546 };
39547
39548diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39549index 0f0f9ce..0ca5819 100644
39550--- a/drivers/net/macvtap.c
39551+++ b/drivers/net/macvtap.c
39552@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39553 return NOTIFY_DONE;
39554 }
39555
39556-static struct notifier_block macvtap_notifier_block __read_mostly = {
39557+static struct notifier_block macvtap_notifier_block = {
39558 .notifier_call = macvtap_device_event,
39559 };
39560
39561diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39562index daec9b0..6428fcb 100644
39563--- a/drivers/net/phy/mdio-bitbang.c
39564+++ b/drivers/net/phy/mdio-bitbang.c
39565@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39566 struct mdiobb_ctrl *ctrl = bus->priv;
39567
39568 module_put(ctrl->ops->owner);
39569+ mdiobus_unregister(bus);
39570 mdiobus_free(bus);
39571 }
39572 EXPORT_SYMBOL(free_mdio_bitbang);
39573diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39574index 508570e..f706dc7 100644
39575--- a/drivers/net/ppp/ppp_generic.c
39576+++ b/drivers/net/ppp/ppp_generic.c
39577@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39578 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39579 struct ppp_stats stats;
39580 struct ppp_comp_stats cstats;
39581- char *vers;
39582
39583 switch (cmd) {
39584 case SIOCGPPPSTATS:
39585@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39586 break;
39587
39588 case SIOCGPPPVER:
39589- vers = PPP_VERSION;
39590- if (copy_to_user(addr, vers, strlen(vers) + 1))
39591+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39592 break;
39593 err = 0;
39594 break;
39595diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39596index 8efe47a..a8075c5 100644
39597--- a/drivers/net/team/team.c
39598+++ b/drivers/net/team/team.c
39599@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
39600 return NOTIFY_DONE;
39601 }
39602
39603-static struct notifier_block team_notifier_block __read_mostly = {
39604+static struct notifier_block team_notifier_block = {
39605 .notifier_call = team_device_event,
39606 };
39607
39608diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39609index cb95fe5..a5bdab5 100644
39610--- a/drivers/net/tun.c
39611+++ b/drivers/net/tun.c
39612@@ -1838,7 +1838,7 @@ unlock:
39613 }
39614
39615 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39616- unsigned long arg, int ifreq_len)
39617+ unsigned long arg, size_t ifreq_len)
39618 {
39619 struct tun_file *tfile = file->private_data;
39620 struct tun_struct *tun;
39621@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39622 int vnet_hdr_sz;
39623 int ret;
39624
39625+ if (ifreq_len > sizeof ifr)
39626+ return -EFAULT;
39627+
39628 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39629 if (copy_from_user(&ifr, argp, ifreq_len))
39630 return -EFAULT;
39631diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39632index cd8ccb2..cff5144 100644
39633--- a/drivers/net/usb/hso.c
39634+++ b/drivers/net/usb/hso.c
39635@@ -71,7 +71,7 @@
39636 #include <asm/byteorder.h>
39637 #include <linux/serial_core.h>
39638 #include <linux/serial.h>
39639-
39640+#include <asm/local.h>
39641
39642 #define MOD_AUTHOR "Option Wireless"
39643 #define MOD_DESCRIPTION "USB High Speed Option driver"
39644@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39645 struct urb *urb;
39646
39647 urb = serial->rx_urb[0];
39648- if (serial->port.count > 0) {
39649+ if (atomic_read(&serial->port.count) > 0) {
39650 count = put_rxbuf_data(urb, serial);
39651 if (count == -1)
39652 return;
39653@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39654 DUMP1(urb->transfer_buffer, urb->actual_length);
39655
39656 /* Anyone listening? */
39657- if (serial->port.count == 0)
39658+ if (atomic_read(&serial->port.count) == 0)
39659 return;
39660
39661 if (status == 0) {
39662@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39663 tty_port_tty_set(&serial->port, tty);
39664
39665 /* check for port already opened, if not set the termios */
39666- serial->port.count++;
39667- if (serial->port.count == 1) {
39668+ if (atomic_inc_return(&serial->port.count) == 1) {
39669 serial->rx_state = RX_IDLE;
39670 /* Force default termio settings */
39671 _hso_serial_set_termios(tty, NULL);
39672@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39673 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39674 if (result) {
39675 hso_stop_serial_device(serial->parent);
39676- serial->port.count--;
39677+ atomic_dec(&serial->port.count);
39678 kref_put(&serial->parent->ref, hso_serial_ref_free);
39679 }
39680 } else {
39681@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39682
39683 /* reset the rts and dtr */
39684 /* do the actual close */
39685- serial->port.count--;
39686+ atomic_dec(&serial->port.count);
39687
39688- if (serial->port.count <= 0) {
39689- serial->port.count = 0;
39690+ if (atomic_read(&serial->port.count) <= 0) {
39691+ atomic_set(&serial->port.count, 0);
39692 tty_port_tty_set(&serial->port, NULL);
39693 if (!usb_gone)
39694 hso_stop_serial_device(serial->parent);
39695@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39696
39697 /* the actual setup */
39698 spin_lock_irqsave(&serial->serial_lock, flags);
39699- if (serial->port.count)
39700+ if (atomic_read(&serial->port.count))
39701 _hso_serial_set_termios(tty, old);
39702 else
39703 tty->termios = *old;
39704@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39705 D1("Pending read interrupt on port %d\n", i);
39706 spin_lock(&serial->serial_lock);
39707 if (serial->rx_state == RX_IDLE &&
39708- serial->port.count > 0) {
39709+ atomic_read(&serial->port.count) > 0) {
39710 /* Setup and send a ctrl req read on
39711 * port i */
39712 if (!serial->rx_urb_filled[0]) {
39713@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39714 /* Start all serial ports */
39715 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39716 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39717- if (dev2ser(serial_table[i])->port.count) {
39718+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39719 result =
39720 hso_start_serial_device(serial_table[i], GFP_NOIO);
39721 hso_kick_transmit(dev2ser(serial_table[i]));
39722diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39723index 6993bfa..9053a34 100644
39724--- a/drivers/net/vxlan.c
39725+++ b/drivers/net/vxlan.c
39726@@ -1428,7 +1428,7 @@ nla_put_failure:
39727 return -EMSGSIZE;
39728 }
39729
39730-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39731+static struct rtnl_link_ops vxlan_link_ops = {
39732 .kind = "vxlan",
39733 .maxtype = IFLA_VXLAN_MAX,
39734 .policy = vxlan_policy,
39735diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
39736index 77fa428..996b355 100644
39737--- a/drivers/net/wireless/at76c50x-usb.c
39738+++ b/drivers/net/wireless/at76c50x-usb.c
39739@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
39740 }
39741
39742 /* Convert timeout from the DFU status to jiffies */
39743-static inline unsigned long at76_get_timeout(struct dfu_status *s)
39744+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
39745 {
39746 return msecs_to_jiffies((s->poll_timeout[2] << 16)
39747 | (s->poll_timeout[1] << 8)
39748diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39749index 8d78253..bebbb68 100644
39750--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39751+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39752@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39753 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39754 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39755
39756- ACCESS_ONCE(ads->ds_link) = i->link;
39757- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39758+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
39759+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39760
39761 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39762 ctl6 = SM(i->keytype, AR_EncrType);
39763@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39764
39765 if ((i->is_first || i->is_last) &&
39766 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39767- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39768+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39769 | set11nTries(i->rates, 1)
39770 | set11nTries(i->rates, 2)
39771 | set11nTries(i->rates, 3)
39772 | (i->dur_update ? AR_DurUpdateEna : 0)
39773 | SM(0, AR_BurstDur);
39774
39775- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39776+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39777 | set11nRate(i->rates, 1)
39778 | set11nRate(i->rates, 2)
39779 | set11nRate(i->rates, 3);
39780 } else {
39781- ACCESS_ONCE(ads->ds_ctl2) = 0;
39782- ACCESS_ONCE(ads->ds_ctl3) = 0;
39783+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39784+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39785 }
39786
39787 if (!i->is_first) {
39788- ACCESS_ONCE(ads->ds_ctl0) = 0;
39789- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39790- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39791+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39792+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39793+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39794 return;
39795 }
39796
39797@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39798 break;
39799 }
39800
39801- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39802+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39803 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39804 | SM(i->txpower, AR_XmitPower)
39805 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39806@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39807 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39808 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39809
39810- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39811- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39812+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39813+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39814
39815 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39816 return;
39817
39818- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39819+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39820 | set11nPktDurRTSCTS(i->rates, 1);
39821
39822- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39823+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39824 | set11nPktDurRTSCTS(i->rates, 3);
39825
39826- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39827+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39828 | set11nRateFlags(i->rates, 1)
39829 | set11nRateFlags(i->rates, 2)
39830 | set11nRateFlags(i->rates, 3)
39831diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39832index 301bf72..3f5654f 100644
39833--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39834+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39835@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39836 (i->qcu << AR_TxQcuNum_S) | desc_len;
39837
39838 checksum += val;
39839- ACCESS_ONCE(ads->info) = val;
39840+ ACCESS_ONCE_RW(ads->info) = val;
39841
39842 checksum += i->link;
39843- ACCESS_ONCE(ads->link) = i->link;
39844+ ACCESS_ONCE_RW(ads->link) = i->link;
39845
39846 checksum += i->buf_addr[0];
39847- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39848+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39849 checksum += i->buf_addr[1];
39850- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39851+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39852 checksum += i->buf_addr[2];
39853- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39854+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39855 checksum += i->buf_addr[3];
39856- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39857+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39858
39859 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39860- ACCESS_ONCE(ads->ctl3) = val;
39861+ ACCESS_ONCE_RW(ads->ctl3) = val;
39862 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39863- ACCESS_ONCE(ads->ctl5) = val;
39864+ ACCESS_ONCE_RW(ads->ctl5) = val;
39865 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39866- ACCESS_ONCE(ads->ctl7) = val;
39867+ ACCESS_ONCE_RW(ads->ctl7) = val;
39868 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39869- ACCESS_ONCE(ads->ctl9) = val;
39870+ ACCESS_ONCE_RW(ads->ctl9) = val;
39871
39872 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39873- ACCESS_ONCE(ads->ctl10) = checksum;
39874+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
39875
39876 if (i->is_first || i->is_last) {
39877- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39878+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39879 | set11nTries(i->rates, 1)
39880 | set11nTries(i->rates, 2)
39881 | set11nTries(i->rates, 3)
39882 | (i->dur_update ? AR_DurUpdateEna : 0)
39883 | SM(0, AR_BurstDur);
39884
39885- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39886+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39887 | set11nRate(i->rates, 1)
39888 | set11nRate(i->rates, 2)
39889 | set11nRate(i->rates, 3);
39890 } else {
39891- ACCESS_ONCE(ads->ctl13) = 0;
39892- ACCESS_ONCE(ads->ctl14) = 0;
39893+ ACCESS_ONCE_RW(ads->ctl13) = 0;
39894+ ACCESS_ONCE_RW(ads->ctl14) = 0;
39895 }
39896
39897 ads->ctl20 = 0;
39898@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39899
39900 ctl17 = SM(i->keytype, AR_EncrType);
39901 if (!i->is_first) {
39902- ACCESS_ONCE(ads->ctl11) = 0;
39903- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39904- ACCESS_ONCE(ads->ctl15) = 0;
39905- ACCESS_ONCE(ads->ctl16) = 0;
39906- ACCESS_ONCE(ads->ctl17) = ctl17;
39907- ACCESS_ONCE(ads->ctl18) = 0;
39908- ACCESS_ONCE(ads->ctl19) = 0;
39909+ ACCESS_ONCE_RW(ads->ctl11) = 0;
39910+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39911+ ACCESS_ONCE_RW(ads->ctl15) = 0;
39912+ ACCESS_ONCE_RW(ads->ctl16) = 0;
39913+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39914+ ACCESS_ONCE_RW(ads->ctl18) = 0;
39915+ ACCESS_ONCE_RW(ads->ctl19) = 0;
39916 return;
39917 }
39918
39919- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39920+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39921 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39922 | SM(i->txpower, AR_XmitPower)
39923 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39924@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39925 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39926 ctl12 |= SM(val, AR_PAPRDChainMask);
39927
39928- ACCESS_ONCE(ads->ctl12) = ctl12;
39929- ACCESS_ONCE(ads->ctl17) = ctl17;
39930+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39931+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39932
39933- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39934+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39935 | set11nPktDurRTSCTS(i->rates, 1);
39936
39937- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39938+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39939 | set11nPktDurRTSCTS(i->rates, 3);
39940
39941- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39942+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39943 | set11nRateFlags(i->rates, 1)
39944 | set11nRateFlags(i->rates, 2)
39945 | set11nRateFlags(i->rates, 3)
39946 | SM(i->rtscts_rate, AR_RTSCTSRate);
39947
39948- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39949+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39950 }
39951
39952 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39953diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39954index 9d26fc5..60d9f14 100644
39955--- a/drivers/net/wireless/ath/ath9k/hw.h
39956+++ b/drivers/net/wireless/ath/ath9k/hw.h
39957@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39958
39959 /* ANI */
39960 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39961-};
39962+} __no_const;
39963
39964 /**
39965 * struct ath_hw_ops - callbacks used by hardware code and driver code
39966@@ -688,7 +688,7 @@ struct ath_hw_ops {
39967 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39968 struct ath_hw_antcomb_conf *antconf);
39969 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39970-};
39971+} __no_const;
39972
39973 struct ath_nf_limits {
39974 s16 max;
39975diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
39976index 3726cd6..b655808 100644
39977--- a/drivers/net/wireless/iwlegacy/3945-mac.c
39978+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
39979@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39980 */
39981 if (il3945_mod_params.disable_hw_scan) {
39982 D_INFO("Disabling hw_scan\n");
39983- il3945_mac_ops.hw_scan = NULL;
39984+ pax_open_kernel();
39985+ *(void **)&il3945_mac_ops.hw_scan = NULL;
39986+ pax_close_kernel();
39987 }
39988
39989 D_INFO("*** LOAD DRIVER ***\n");
39990diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39991index 5b9533e..7733880 100644
39992--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39993+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39994@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
39995 {
39996 struct iwl_priv *priv = file->private_data;
39997 char buf[64];
39998- int buf_size;
39999+ size_t buf_size;
40000 u32 offset, len;
40001
40002 memset(buf, 0, sizeof(buf));
40003@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40004 struct iwl_priv *priv = file->private_data;
40005
40006 char buf[8];
40007- int buf_size;
40008+ size_t buf_size;
40009 u32 reset_flag;
40010
40011 memset(buf, 0, sizeof(buf));
40012@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40013 {
40014 struct iwl_priv *priv = file->private_data;
40015 char buf[8];
40016- int buf_size;
40017+ size_t buf_size;
40018 int ht40;
40019
40020 memset(buf, 0, sizeof(buf));
40021@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40022 {
40023 struct iwl_priv *priv = file->private_data;
40024 char buf[8];
40025- int buf_size;
40026+ size_t buf_size;
40027 int value;
40028
40029 memset(buf, 0, sizeof(buf));
40030@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40031 {
40032 struct iwl_priv *priv = file->private_data;
40033 char buf[8];
40034- int buf_size;
40035+ size_t buf_size;
40036 int clear;
40037
40038 memset(buf, 0, sizeof(buf));
40039@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40040 {
40041 struct iwl_priv *priv = file->private_data;
40042 char buf[8];
40043- int buf_size;
40044+ size_t buf_size;
40045 int trace;
40046
40047 memset(buf, 0, sizeof(buf));
40048@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40049 {
40050 struct iwl_priv *priv = file->private_data;
40051 char buf[8];
40052- int buf_size;
40053+ size_t buf_size;
40054 int missed;
40055
40056 memset(buf, 0, sizeof(buf));
40057@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40058
40059 struct iwl_priv *priv = file->private_data;
40060 char buf[8];
40061- int buf_size;
40062+ size_t buf_size;
40063 int plcp;
40064
40065 memset(buf, 0, sizeof(buf));
40066@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40067
40068 struct iwl_priv *priv = file->private_data;
40069 char buf[8];
40070- int buf_size;
40071+ size_t buf_size;
40072 int flush;
40073
40074 memset(buf, 0, sizeof(buf));
40075@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40076
40077 struct iwl_priv *priv = file->private_data;
40078 char buf[8];
40079- int buf_size;
40080+ size_t buf_size;
40081 int rts;
40082
40083 if (!priv->cfg->ht_params)
40084@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40085 {
40086 struct iwl_priv *priv = file->private_data;
40087 char buf[8];
40088- int buf_size;
40089+ size_t buf_size;
40090
40091 memset(buf, 0, sizeof(buf));
40092 buf_size = min(count, sizeof(buf) - 1);
40093@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40094 struct iwl_priv *priv = file->private_data;
40095 u32 event_log_flag;
40096 char buf[8];
40097- int buf_size;
40098+ size_t buf_size;
40099
40100 /* check that the interface is up */
40101 if (!iwl_is_ready(priv))
40102@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40103 struct iwl_priv *priv = file->private_data;
40104 char buf[8];
40105 u32 calib_disabled;
40106- int buf_size;
40107+ size_t buf_size;
40108
40109 memset(buf, 0, sizeof(buf));
40110 buf_size = min(count, sizeof(buf) - 1);
40111diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40112index 35708b9..31f7754 100644
40113--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40114+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40115@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40116 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40117
40118 char buf[8];
40119- int buf_size;
40120+ size_t buf_size;
40121 u32 reset_flag;
40122
40123 memset(buf, 0, sizeof(buf));
40124@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40125 {
40126 struct iwl_trans *trans = file->private_data;
40127 char buf[8];
40128- int buf_size;
40129+ size_t buf_size;
40130 int csr;
40131
40132 memset(buf, 0, sizeof(buf));
40133diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40134index ff90855..e46d223 100644
40135--- a/drivers/net/wireless/mac80211_hwsim.c
40136+++ b/drivers/net/wireless/mac80211_hwsim.c
40137@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
40138
40139 if (channels > 1) {
40140 hwsim_if_comb.num_different_channels = channels;
40141- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40142- mac80211_hwsim_ops.cancel_hw_scan =
40143- mac80211_hwsim_cancel_hw_scan;
40144- mac80211_hwsim_ops.sw_scan_start = NULL;
40145- mac80211_hwsim_ops.sw_scan_complete = NULL;
40146- mac80211_hwsim_ops.remain_on_channel =
40147- mac80211_hwsim_roc;
40148- mac80211_hwsim_ops.cancel_remain_on_channel =
40149- mac80211_hwsim_croc;
40150- mac80211_hwsim_ops.add_chanctx =
40151- mac80211_hwsim_add_chanctx;
40152- mac80211_hwsim_ops.remove_chanctx =
40153- mac80211_hwsim_remove_chanctx;
40154- mac80211_hwsim_ops.change_chanctx =
40155- mac80211_hwsim_change_chanctx;
40156- mac80211_hwsim_ops.assign_vif_chanctx =
40157- mac80211_hwsim_assign_vif_chanctx;
40158- mac80211_hwsim_ops.unassign_vif_chanctx =
40159- mac80211_hwsim_unassign_vif_chanctx;
40160+ pax_open_kernel();
40161+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40162+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40163+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40164+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40165+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40166+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40167+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40168+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40169+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40170+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40171+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40172+ pax_close_kernel();
40173 }
40174
40175 spin_lock_init(&hwsim_radio_lock);
40176diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40177index abe1d03..fb02c22 100644
40178--- a/drivers/net/wireless/rndis_wlan.c
40179+++ b/drivers/net/wireless/rndis_wlan.c
40180@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40181
40182 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40183
40184- if (rts_threshold < 0 || rts_threshold > 2347)
40185+ if (rts_threshold > 2347)
40186 rts_threshold = 2347;
40187
40188 tmp = cpu_to_le32(rts_threshold);
40189diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40190index 0751b35..246ba3e 100644
40191--- a/drivers/net/wireless/rt2x00/rt2x00.h
40192+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40193@@ -398,7 +398,7 @@ struct rt2x00_intf {
40194 * for hardware which doesn't support hardware
40195 * sequence counting.
40196 */
40197- atomic_t seqno;
40198+ atomic_unchecked_t seqno;
40199 };
40200
40201 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40202diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40203index e488b94..14b6a0c 100644
40204--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40205+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40206@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40207 * sequence counter given by mac80211.
40208 */
40209 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40210- seqno = atomic_add_return(0x10, &intf->seqno);
40211+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40212 else
40213- seqno = atomic_read(&intf->seqno);
40214+ seqno = atomic_read_unchecked(&intf->seqno);
40215
40216 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40217 hdr->seq_ctrl |= cpu_to_le16(seqno);
40218diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40219index e57ee48..541cf6c 100644
40220--- a/drivers/net/wireless/ti/wl1251/sdio.c
40221+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40222@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40223
40224 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40225
40226- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40227- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40228+ pax_open_kernel();
40229+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40230+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40231+ pax_close_kernel();
40232
40233 wl1251_info("using dedicated interrupt line");
40234 } else {
40235- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40236- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40237+ pax_open_kernel();
40238+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40239+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40240+ pax_close_kernel();
40241
40242 wl1251_info("using SDIO interrupt");
40243 }
40244diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40245index e5f5f8f..fdf15b7 100644
40246--- a/drivers/net/wireless/ti/wl12xx/main.c
40247+++ b/drivers/net/wireless/ti/wl12xx/main.c
40248@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40249 sizeof(wl->conf.mem));
40250
40251 /* read data preparation is only needed by wl127x */
40252- wl->ops->prepare_read = wl127x_prepare_read;
40253+ pax_open_kernel();
40254+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40255+ pax_close_kernel();
40256
40257 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40258 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40259@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40260 sizeof(wl->conf.mem));
40261
40262 /* read data preparation is only needed by wl127x */
40263- wl->ops->prepare_read = wl127x_prepare_read;
40264+ pax_open_kernel();
40265+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40266+ pax_close_kernel();
40267
40268 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40269 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40270diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
40271index 8d8c1f8..e754844 100644
40272--- a/drivers/net/wireless/ti/wl18xx/main.c
40273+++ b/drivers/net/wireless/ti/wl18xx/main.c
40274@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
40275 }
40276
40277 if (!checksum_param) {
40278- wl18xx_ops.set_rx_csum = NULL;
40279- wl18xx_ops.init_vif = NULL;
40280+ pax_open_kernel();
40281+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
40282+ *(void **)&wl18xx_ops.init_vif = NULL;
40283+ pax_close_kernel();
40284 }
40285
40286 /* Enable 11a Band only if we have 5G antennas */
40287diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
40288index d93b2b6..ae50401 100644
40289--- a/drivers/oprofile/buffer_sync.c
40290+++ b/drivers/oprofile/buffer_sync.c
40291@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
40292 if (cookie == NO_COOKIE)
40293 offset = pc;
40294 if (cookie == INVALID_COOKIE) {
40295- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40296+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40297 offset = pc;
40298 }
40299 if (cookie != last_cookie) {
40300@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
40301 /* add userspace sample */
40302
40303 if (!mm) {
40304- atomic_inc(&oprofile_stats.sample_lost_no_mm);
40305+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
40306 return 0;
40307 }
40308
40309 cookie = lookup_dcookie(mm, s->eip, &offset);
40310
40311 if (cookie == INVALID_COOKIE) {
40312- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40313+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40314 return 0;
40315 }
40316
40317@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
40318 /* ignore backtraces if failed to add a sample */
40319 if (state == sb_bt_start) {
40320 state = sb_bt_ignore;
40321- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
40322+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
40323 }
40324 }
40325 release_mm(mm);
40326diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
40327index c0cc4e7..44d4e54 100644
40328--- a/drivers/oprofile/event_buffer.c
40329+++ b/drivers/oprofile/event_buffer.c
40330@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
40331 }
40332
40333 if (buffer_pos == buffer_size) {
40334- atomic_inc(&oprofile_stats.event_lost_overflow);
40335+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
40336 return;
40337 }
40338
40339diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
40340index ed2c3ec..deda85a 100644
40341--- a/drivers/oprofile/oprof.c
40342+++ b/drivers/oprofile/oprof.c
40343@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
40344 if (oprofile_ops.switch_events())
40345 return;
40346
40347- atomic_inc(&oprofile_stats.multiplex_counter);
40348+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
40349 start_switch_worker();
40350 }
40351
40352diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
40353index 84a208d..d61b0a1 100644
40354--- a/drivers/oprofile/oprofile_files.c
40355+++ b/drivers/oprofile/oprofile_files.c
40356@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
40357
40358 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
40359
40360-static ssize_t timeout_read(struct file *file, char __user *buf,
40361+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
40362 size_t count, loff_t *offset)
40363 {
40364 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
40365diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
40366index 917d28e..d62d981 100644
40367--- a/drivers/oprofile/oprofile_stats.c
40368+++ b/drivers/oprofile/oprofile_stats.c
40369@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
40370 cpu_buf->sample_invalid_eip = 0;
40371 }
40372
40373- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
40374- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
40375- atomic_set(&oprofile_stats.event_lost_overflow, 0);
40376- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
40377- atomic_set(&oprofile_stats.multiplex_counter, 0);
40378+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
40379+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
40380+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
40381+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
40382+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
40383 }
40384
40385
40386diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
40387index 38b6fc0..b5cbfce 100644
40388--- a/drivers/oprofile/oprofile_stats.h
40389+++ b/drivers/oprofile/oprofile_stats.h
40390@@ -13,11 +13,11 @@
40391 #include <linux/atomic.h>
40392
40393 struct oprofile_stat_struct {
40394- atomic_t sample_lost_no_mm;
40395- atomic_t sample_lost_no_mapping;
40396- atomic_t bt_lost_no_mapping;
40397- atomic_t event_lost_overflow;
40398- atomic_t multiplex_counter;
40399+ atomic_unchecked_t sample_lost_no_mm;
40400+ atomic_unchecked_t sample_lost_no_mapping;
40401+ atomic_unchecked_t bt_lost_no_mapping;
40402+ atomic_unchecked_t event_lost_overflow;
40403+ atomic_unchecked_t multiplex_counter;
40404 };
40405
40406 extern struct oprofile_stat_struct oprofile_stats;
40407diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40408index 849357c..b83c1e0 100644
40409--- a/drivers/oprofile/oprofilefs.c
40410+++ b/drivers/oprofile/oprofilefs.c
40411@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
40412
40413
40414 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40415- char const *name, atomic_t *val)
40416+ char const *name, atomic_unchecked_t *val)
40417 {
40418 return __oprofilefs_create_file(sb, root, name,
40419 &atomic_ro_fops, 0444, val);
40420diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40421index 93404f7..4a313d8 100644
40422--- a/drivers/oprofile/timer_int.c
40423+++ b/drivers/oprofile/timer_int.c
40424@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40425 return NOTIFY_OK;
40426 }
40427
40428-static struct notifier_block __refdata oprofile_cpu_notifier = {
40429+static struct notifier_block oprofile_cpu_notifier = {
40430 .notifier_call = oprofile_cpu_notify,
40431 };
40432
40433diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40434index 3f56bc0..707d642 100644
40435--- a/drivers/parport/procfs.c
40436+++ b/drivers/parport/procfs.c
40437@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40438
40439 *ppos += len;
40440
40441- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40442+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40443 }
40444
40445 #ifdef CONFIG_PARPORT_1284
40446@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
40447
40448 *ppos += len;
40449
40450- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
40451+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
40452 }
40453 #endif /* IEEE1284.3 support. */
40454
40455diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40456index c35e8ad..fc33beb 100644
40457--- a/drivers/pci/hotplug/acpiphp_ibm.c
40458+++ b/drivers/pci/hotplug/acpiphp_ibm.c
40459@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40460 goto init_cleanup;
40461 }
40462
40463- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40464+ pax_open_kernel();
40465+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40466+ pax_close_kernel();
40467 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40468
40469 return retval;
40470diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40471index a6a71c4..c91097b 100644
40472--- a/drivers/pci/hotplug/cpcihp_generic.c
40473+++ b/drivers/pci/hotplug/cpcihp_generic.c
40474@@ -73,7 +73,6 @@ static u16 port;
40475 static unsigned int enum_bit;
40476 static u8 enum_mask;
40477
40478-static struct cpci_hp_controller_ops generic_hpc_ops;
40479 static struct cpci_hp_controller generic_hpc;
40480
40481 static int __init validate_parameters(void)
40482@@ -139,6 +138,10 @@ static int query_enum(void)
40483 return ((value & enum_mask) == enum_mask);
40484 }
40485
40486+static struct cpci_hp_controller_ops generic_hpc_ops = {
40487+ .query_enum = query_enum,
40488+};
40489+
40490 static int __init cpcihp_generic_init(void)
40491 {
40492 int status;
40493@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40494 pci_dev_put(dev);
40495
40496 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40497- generic_hpc_ops.query_enum = query_enum;
40498 generic_hpc.ops = &generic_hpc_ops;
40499
40500 status = cpci_hp_register_controller(&generic_hpc);
40501diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40502index 449b4bb..257e2e8 100644
40503--- a/drivers/pci/hotplug/cpcihp_zt5550.c
40504+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40505@@ -59,7 +59,6 @@
40506 /* local variables */
40507 static bool debug;
40508 static bool poll;
40509-static struct cpci_hp_controller_ops zt5550_hpc_ops;
40510 static struct cpci_hp_controller zt5550_hpc;
40511
40512 /* Primary cPCI bus bridge device */
40513@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40514 return 0;
40515 }
40516
40517+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40518+ .query_enum = zt5550_hc_query_enum,
40519+};
40520+
40521 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40522 {
40523 int status;
40524@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40525 dbg("returned from zt5550_hc_config");
40526
40527 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40528- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40529 zt5550_hpc.ops = &zt5550_hpc_ops;
40530 if(!poll) {
40531 zt5550_hpc.irq = hc_dev->irq;
40532 zt5550_hpc.irq_flags = IRQF_SHARED;
40533 zt5550_hpc.dev_id = hc_dev;
40534
40535- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40536- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40537- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40538+ pax_open_kernel();
40539+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40540+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40541+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40542+ pax_open_kernel();
40543 } else {
40544 info("using ENUM# polling mode");
40545 }
40546diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40547index 76ba8a1..20ca857 100644
40548--- a/drivers/pci/hotplug/cpqphp_nvram.c
40549+++ b/drivers/pci/hotplug/cpqphp_nvram.c
40550@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40551
40552 void compaq_nvram_init (void __iomem *rom_start)
40553 {
40554+
40555+#ifndef CONFIG_PAX_KERNEXEC
40556 if (rom_start) {
40557 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40558 }
40559+#endif
40560+
40561 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40562
40563 /* initialize our int15 lock */
40564diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40565index 202f4a9..8ee47d0 100644
40566--- a/drivers/pci/hotplug/pci_hotplug_core.c
40567+++ b/drivers/pci/hotplug/pci_hotplug_core.c
40568@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40569 return -EINVAL;
40570 }
40571
40572- slot->ops->owner = owner;
40573- slot->ops->mod_name = mod_name;
40574+ pax_open_kernel();
40575+ *(struct module **)&slot->ops->owner = owner;
40576+ *(const char **)&slot->ops->mod_name = mod_name;
40577+ pax_close_kernel();
40578
40579 mutex_lock(&pci_hp_mutex);
40580 /*
40581diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40582index 939bd1d..a1459c9 100644
40583--- a/drivers/pci/hotplug/pciehp_core.c
40584+++ b/drivers/pci/hotplug/pciehp_core.c
40585@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40586 struct slot *slot = ctrl->slot;
40587 struct hotplug_slot *hotplug = NULL;
40588 struct hotplug_slot_info *info = NULL;
40589- struct hotplug_slot_ops *ops = NULL;
40590+ hotplug_slot_ops_no_const *ops = NULL;
40591 char name[SLOT_NAME_SIZE];
40592 int retval = -ENOMEM;
40593
40594diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40595index 9c6e9bb..2916736 100644
40596--- a/drivers/pci/pci-sysfs.c
40597+++ b/drivers/pci/pci-sysfs.c
40598@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40599 {
40600 /* allocate attribute structure, piggyback attribute name */
40601 int name_len = write_combine ? 13 : 10;
40602- struct bin_attribute *res_attr;
40603+ bin_attribute_no_const *res_attr;
40604 int retval;
40605
40606 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40607@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40608 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40609 {
40610 int retval;
40611- struct bin_attribute *attr;
40612+ bin_attribute_no_const *attr;
40613
40614 /* If the device has VPD, try to expose it in sysfs. */
40615 if (dev->vpd) {
40616@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40617 {
40618 int retval;
40619 int rom_size = 0;
40620- struct bin_attribute *attr;
40621+ bin_attribute_no_const *attr;
40622
40623 if (!sysfs_initialized)
40624 return -EACCES;
40625diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40626index e851829..a1a7196 100644
40627--- a/drivers/pci/pci.h
40628+++ b/drivers/pci/pci.h
40629@@ -98,7 +98,7 @@ struct pci_vpd_ops {
40630 struct pci_vpd {
40631 unsigned int len;
40632 const struct pci_vpd_ops *ops;
40633- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40634+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40635 };
40636
40637 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40638diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40639index 8474b6a..ee81993 100644
40640--- a/drivers/pci/pcie/aspm.c
40641+++ b/drivers/pci/pcie/aspm.c
40642@@ -27,9 +27,9 @@
40643 #define MODULE_PARAM_PREFIX "pcie_aspm."
40644
40645 /* Note: those are not register definitions */
40646-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40647-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40648-#define ASPM_STATE_L1 (4) /* L1 state */
40649+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40650+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40651+#define ASPM_STATE_L1 (4U) /* L1 state */
40652 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40653 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40654
40655diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40656index 6186f03..1a78714 100644
40657--- a/drivers/pci/probe.c
40658+++ b/drivers/pci/probe.c
40659@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40660 struct pci_bus_region region;
40661 bool bar_too_big = false, bar_disabled = false;
40662
40663- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40664+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40665
40666 /* No printks while decoding is disabled! */
40667 if (!dev->mmio_always_on) {
40668diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40669index 9b8505c..f00870a 100644
40670--- a/drivers/pci/proc.c
40671+++ b/drivers/pci/proc.c
40672@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40673 static int __init pci_proc_init(void)
40674 {
40675 struct pci_dev *dev = NULL;
40676+
40677+#ifdef CONFIG_GRKERNSEC_PROC_ADD
40678+#ifdef CONFIG_GRKERNSEC_PROC_USER
40679+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40680+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40681+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40682+#endif
40683+#else
40684 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40685+#endif
40686 proc_create("devices", 0, proc_bus_pci_dir,
40687 &proc_bus_pci_dev_operations);
40688 proc_initialized = 1;
40689diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40690index 2111dbb..79e434b 100644
40691--- a/drivers/platform/x86/msi-laptop.c
40692+++ b/drivers/platform/x86/msi-laptop.c
40693@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40694 int result;
40695
40696 /* allow userland write sysfs file */
40697- dev_attr_bluetooth.store = store_bluetooth;
40698- dev_attr_wlan.store = store_wlan;
40699- dev_attr_threeg.store = store_threeg;
40700- dev_attr_bluetooth.attr.mode |= S_IWUSR;
40701- dev_attr_wlan.attr.mode |= S_IWUSR;
40702- dev_attr_threeg.attr.mode |= S_IWUSR;
40703+ pax_open_kernel();
40704+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40705+ *(void **)&dev_attr_wlan.store = store_wlan;
40706+ *(void **)&dev_attr_threeg.store = store_threeg;
40707+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40708+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40709+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40710+ pax_close_kernel();
40711
40712 /* disable hardware control by fn key */
40713 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40714diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40715index 0fe987f..6f3d5c3 100644
40716--- a/drivers/platform/x86/sony-laptop.c
40717+++ b/drivers/platform/x86/sony-laptop.c
40718@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40719 }
40720
40721 /* High speed charging function */
40722-static struct device_attribute *hsc_handle;
40723+static device_attribute_no_const *hsc_handle;
40724
40725 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40726 struct device_attribute *attr,
40727diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40728index f946ca7..f25c833 100644
40729--- a/drivers/platform/x86/thinkpad_acpi.c
40730+++ b/drivers/platform/x86/thinkpad_acpi.c
40731@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40732 return 0;
40733 }
40734
40735-void static hotkey_mask_warn_incomplete_mask(void)
40736+static void hotkey_mask_warn_incomplete_mask(void)
40737 {
40738 /* log only what the user can fix... */
40739 const u32 wantedmask = hotkey_driver_mask &
40740@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40741 }
40742 }
40743
40744-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40745- struct tp_nvram_state *newn,
40746- const u32 event_mask)
40747-{
40748-
40749 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40750 do { \
40751 if ((event_mask & (1 << __scancode)) && \
40752@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40753 tpacpi_hotkey_send_key(__scancode); \
40754 } while (0)
40755
40756- void issue_volchange(const unsigned int oldvol,
40757- const unsigned int newvol)
40758- {
40759- unsigned int i = oldvol;
40760+static void issue_volchange(const unsigned int oldvol,
40761+ const unsigned int newvol,
40762+ const u32 event_mask)
40763+{
40764+ unsigned int i = oldvol;
40765
40766- while (i > newvol) {
40767- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40768- i--;
40769- }
40770- while (i < newvol) {
40771- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40772- i++;
40773- }
40774+ while (i > newvol) {
40775+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40776+ i--;
40777 }
40778+ while (i < newvol) {
40779+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40780+ i++;
40781+ }
40782+}
40783
40784- void issue_brightnesschange(const unsigned int oldbrt,
40785- const unsigned int newbrt)
40786- {
40787- unsigned int i = oldbrt;
40788+static void issue_brightnesschange(const unsigned int oldbrt,
40789+ const unsigned int newbrt,
40790+ const u32 event_mask)
40791+{
40792+ unsigned int i = oldbrt;
40793
40794- while (i > newbrt) {
40795- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40796- i--;
40797- }
40798- while (i < newbrt) {
40799- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40800- i++;
40801- }
40802+ while (i > newbrt) {
40803+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40804+ i--;
40805+ }
40806+ while (i < newbrt) {
40807+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40808+ i++;
40809 }
40810+}
40811
40812+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40813+ struct tp_nvram_state *newn,
40814+ const u32 event_mask)
40815+{
40816 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40817 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40818 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40819@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40820 oldn->volume_level != newn->volume_level) {
40821 /* recently muted, or repeated mute keypress, or
40822 * multiple presses ending in mute */
40823- issue_volchange(oldn->volume_level, newn->volume_level);
40824+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40825 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40826 }
40827 } else {
40828@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40829 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40830 }
40831 if (oldn->volume_level != newn->volume_level) {
40832- issue_volchange(oldn->volume_level, newn->volume_level);
40833+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40834 } else if (oldn->volume_toggle != newn->volume_toggle) {
40835 /* repeated vol up/down keypress at end of scale ? */
40836 if (newn->volume_level == 0)
40837@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40838 /* handle brightness */
40839 if (oldn->brightness_level != newn->brightness_level) {
40840 issue_brightnesschange(oldn->brightness_level,
40841- newn->brightness_level);
40842+ newn->brightness_level,
40843+ event_mask);
40844 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40845 /* repeated key presses that didn't change state */
40846 if (newn->brightness_level == 0)
40847@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40848 && !tp_features.bright_unkfw)
40849 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40850 }
40851+}
40852
40853 #undef TPACPI_COMPARE_KEY
40854 #undef TPACPI_MAY_SEND_KEY
40855-}
40856
40857 /*
40858 * Polling driver
40859diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40860index 769d265..a3a05ca 100644
40861--- a/drivers/pnp/pnpbios/bioscalls.c
40862+++ b/drivers/pnp/pnpbios/bioscalls.c
40863@@ -58,7 +58,7 @@ do { \
40864 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40865 } while(0)
40866
40867-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40868+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40869 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40870
40871 /*
40872@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40873
40874 cpu = get_cpu();
40875 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40876+
40877+ pax_open_kernel();
40878 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40879+ pax_close_kernel();
40880
40881 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40882 spin_lock_irqsave(&pnp_bios_lock, flags);
40883@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40884 :"memory");
40885 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40886
40887+ pax_open_kernel();
40888 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40889+ pax_close_kernel();
40890+
40891 put_cpu();
40892
40893 /* If we get here and this is set then the PnP BIOS faulted on us. */
40894@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40895 return status;
40896 }
40897
40898-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40899+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40900 {
40901 int i;
40902
40903@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40904 pnp_bios_callpoint.offset = header->fields.pm16offset;
40905 pnp_bios_callpoint.segment = PNP_CS16;
40906
40907+ pax_open_kernel();
40908+
40909 for_each_possible_cpu(i) {
40910 struct desc_struct *gdt = get_cpu_gdt_table(i);
40911 if (!gdt)
40912@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40913 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40914 (unsigned long)__va(header->fields.pm16dseg));
40915 }
40916+
40917+ pax_close_kernel();
40918 }
40919diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40920index 3e6db1c..1fbbdae 100644
40921--- a/drivers/pnp/resource.c
40922+++ b/drivers/pnp/resource.c
40923@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40924 return 1;
40925
40926 /* check if the resource is valid */
40927- if (*irq < 0 || *irq > 15)
40928+ if (*irq > 15)
40929 return 0;
40930
40931 /* check if the resource is reserved */
40932@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40933 return 1;
40934
40935 /* check if the resource is valid */
40936- if (*dma < 0 || *dma == 4 || *dma > 7)
40937+ if (*dma == 4 || *dma > 7)
40938 return 0;
40939
40940 /* check if the resource is reserved */
40941diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40942index 7df7c5f..bd48c47 100644
40943--- a/drivers/power/pda_power.c
40944+++ b/drivers/power/pda_power.c
40945@@ -37,7 +37,11 @@ static int polling;
40946
40947 #ifdef CONFIG_USB_OTG_UTILS
40948 static struct usb_phy *transceiver;
40949-static struct notifier_block otg_nb;
40950+static int otg_handle_notification(struct notifier_block *nb,
40951+ unsigned long event, void *unused);
40952+static struct notifier_block otg_nb = {
40953+ .notifier_call = otg_handle_notification
40954+};
40955 #endif
40956
40957 static struct regulator *ac_draw;
40958@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40959
40960 #ifdef CONFIG_USB_OTG_UTILS
40961 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
40962- otg_nb.notifier_call = otg_handle_notification;
40963 ret = usb_register_notifier(transceiver, &otg_nb);
40964 if (ret) {
40965 dev_err(dev, "failure to register otg notifier\n");
40966diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
40967index cc439fd..8fa30df 100644
40968--- a/drivers/power/power_supply.h
40969+++ b/drivers/power/power_supply.h
40970@@ -16,12 +16,12 @@ struct power_supply;
40971
40972 #ifdef CONFIG_SYSFS
40973
40974-extern void power_supply_init_attrs(struct device_type *dev_type);
40975+extern void power_supply_init_attrs(void);
40976 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
40977
40978 #else
40979
40980-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
40981+static inline void power_supply_init_attrs(void) {}
40982 #define power_supply_uevent NULL
40983
40984 #endif /* CONFIG_SYSFS */
40985diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
40986index 8a7cfb3..72e6e9b 100644
40987--- a/drivers/power/power_supply_core.c
40988+++ b/drivers/power/power_supply_core.c
40989@@ -24,7 +24,10 @@
40990 struct class *power_supply_class;
40991 EXPORT_SYMBOL_GPL(power_supply_class);
40992
40993-static struct device_type power_supply_dev_type;
40994+extern const struct attribute_group *power_supply_attr_groups[];
40995+static struct device_type power_supply_dev_type = {
40996+ .groups = power_supply_attr_groups,
40997+};
40998
40999 static int __power_supply_changed_work(struct device *dev, void *data)
41000 {
41001@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41002 return PTR_ERR(power_supply_class);
41003
41004 power_supply_class->dev_uevent = power_supply_uevent;
41005- power_supply_init_attrs(&power_supply_dev_type);
41006+ power_supply_init_attrs();
41007
41008 return 0;
41009 }
41010diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41011index 40fa3b7..d9c2e0e 100644
41012--- a/drivers/power/power_supply_sysfs.c
41013+++ b/drivers/power/power_supply_sysfs.c
41014@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
41015 .is_visible = power_supply_attr_is_visible,
41016 };
41017
41018-static const struct attribute_group *power_supply_attr_groups[] = {
41019+const struct attribute_group *power_supply_attr_groups[] = {
41020 &power_supply_attr_group,
41021 NULL,
41022 };
41023
41024-void power_supply_init_attrs(struct device_type *dev_type)
41025+void power_supply_init_attrs(void)
41026 {
41027 int i;
41028
41029- dev_type->groups = power_supply_attr_groups;
41030-
41031 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41032 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41033 }
41034diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41035index 4d7c635..9860196 100644
41036--- a/drivers/regulator/max8660.c
41037+++ b/drivers/regulator/max8660.c
41038@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41039 max8660->shadow_regs[MAX8660_OVER1] = 5;
41040 } else {
41041 /* Otherwise devices can be toggled via software */
41042- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41043- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41044+ pax_open_kernel();
41045+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41046+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41047+ pax_close_kernel();
41048 }
41049
41050 /*
41051diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41052index 9a8ea91..c483dd9 100644
41053--- a/drivers/regulator/max8973-regulator.c
41054+++ b/drivers/regulator/max8973-regulator.c
41055@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41056 if (!pdata->enable_ext_control) {
41057 max->desc.enable_reg = MAX8973_VOUT;
41058 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41059- max8973_dcdc_ops.enable = regulator_enable_regmap;
41060- max8973_dcdc_ops.disable = regulator_disable_regmap;
41061- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41062+ pax_open_kernel();
41063+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41064+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41065+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41066+ pax_close_kernel();
41067 }
41068
41069 max->enable_external_control = pdata->enable_ext_control;
41070diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41071index 0d84b1f..c2da6ac 100644
41072--- a/drivers/regulator/mc13892-regulator.c
41073+++ b/drivers/regulator/mc13892-regulator.c
41074@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41075 }
41076 mc13xxx_unlock(mc13892);
41077
41078- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41079+ pax_open_kernel();
41080+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41081 = mc13892_vcam_set_mode;
41082- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41083+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41084 = mc13892_vcam_get_mode;
41085+ pax_close_kernel();
41086
41087 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41088 ARRAY_SIZE(mc13892_regulators));
41089diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41090index 16630aa..6afc992 100644
41091--- a/drivers/rtc/rtc-cmos.c
41092+++ b/drivers/rtc/rtc-cmos.c
41093@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41094 hpet_rtc_timer_init();
41095
41096 /* export at least the first block of NVRAM */
41097- nvram.size = address_space - NVRAM_OFFSET;
41098+ pax_open_kernel();
41099+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41100+ pax_close_kernel();
41101 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41102 if (retval < 0) {
41103 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41104diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41105index 9a86b4b..3a383dc 100644
41106--- a/drivers/rtc/rtc-dev.c
41107+++ b/drivers/rtc/rtc-dev.c
41108@@ -14,6 +14,7 @@
41109 #include <linux/module.h>
41110 #include <linux/rtc.h>
41111 #include <linux/sched.h>
41112+#include <linux/grsecurity.h>
41113 #include "rtc-core.h"
41114
41115 static dev_t rtc_devt;
41116@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
41117 if (copy_from_user(&tm, uarg, sizeof(tm)))
41118 return -EFAULT;
41119
41120+ gr_log_timechange();
41121+
41122 return rtc_set_time(rtc, &tm);
41123
41124 case RTC_PIE_ON:
41125diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41126index e0d0ba4..3c65868 100644
41127--- a/drivers/rtc/rtc-ds1307.c
41128+++ b/drivers/rtc/rtc-ds1307.c
41129@@ -106,7 +106,7 @@ struct ds1307 {
41130 u8 offset; /* register's offset */
41131 u8 regs[11];
41132 u16 nvram_offset;
41133- struct bin_attribute *nvram;
41134+ bin_attribute_no_const *nvram;
41135 enum ds_type type;
41136 unsigned long flags;
41137 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41138diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41139index 130f29a..6179d03 100644
41140--- a/drivers/rtc/rtc-m48t59.c
41141+++ b/drivers/rtc/rtc-m48t59.c
41142@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41143 goto out;
41144 }
41145
41146- m48t59_nvram_attr.size = pdata->offset;
41147+ pax_open_kernel();
41148+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41149+ pax_close_kernel();
41150
41151 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41152 if (ret) {
41153diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41154index e693af6..2e525b6 100644
41155--- a/drivers/scsi/bfa/bfa_fcpim.h
41156+++ b/drivers/scsi/bfa/bfa_fcpim.h
41157@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41158
41159 struct bfa_itn_s {
41160 bfa_isr_func_t isr;
41161-};
41162+} __no_const;
41163
41164 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41165 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41166diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41167index 23a90e7..9cf04ee 100644
41168--- a/drivers/scsi/bfa/bfa_ioc.h
41169+++ b/drivers/scsi/bfa/bfa_ioc.h
41170@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41171 bfa_ioc_disable_cbfn_t disable_cbfn;
41172 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41173 bfa_ioc_reset_cbfn_t reset_cbfn;
41174-};
41175+} __no_const;
41176
41177 /*
41178 * IOC event notification mechanism.
41179@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41180 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41181 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41182 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41183-};
41184+} __no_const;
41185
41186 /*
41187 * Queue element to wait for room in request queue. FIFO order is
41188diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41189index 593085a..47aa999 100644
41190--- a/drivers/scsi/hosts.c
41191+++ b/drivers/scsi/hosts.c
41192@@ -42,7 +42,7 @@
41193 #include "scsi_logging.h"
41194
41195
41196-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41197+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41198
41199
41200 static void scsi_host_cls_release(struct device *dev)
41201@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41202 * subtract one because we increment first then return, but we need to
41203 * know what the next host number was before increment
41204 */
41205- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41206+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41207 shost->dma_channel = 0xff;
41208
41209 /* These three are default values which can be overridden */
41210diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41211index 4f33806..afd6f60 100644
41212--- a/drivers/scsi/hpsa.c
41213+++ b/drivers/scsi/hpsa.c
41214@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41215 unsigned long flags;
41216
41217 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41218- return h->access.command_completed(h, q);
41219+ return h->access->command_completed(h, q);
41220
41221 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41222 a = rq->head[rq->current_entry];
41223@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
41224 while (!list_empty(&h->reqQ)) {
41225 c = list_entry(h->reqQ.next, struct CommandList, list);
41226 /* can't do anything if fifo is full */
41227- if ((h->access.fifo_full(h))) {
41228+ if ((h->access->fifo_full(h))) {
41229 dev_warn(&h->pdev->dev, "fifo full\n");
41230 break;
41231 }
41232@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
41233
41234 /* Tell the controller execute command */
41235 spin_unlock_irqrestore(&h->lock, flags);
41236- h->access.submit_command(h, c);
41237+ h->access->submit_command(h, c);
41238 spin_lock_irqsave(&h->lock, flags);
41239 }
41240 spin_unlock_irqrestore(&h->lock, flags);
41241@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
41242
41243 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
41244 {
41245- return h->access.command_completed(h, q);
41246+ return h->access->command_completed(h, q);
41247 }
41248
41249 static inline bool interrupt_pending(struct ctlr_info *h)
41250 {
41251- return h->access.intr_pending(h);
41252+ return h->access->intr_pending(h);
41253 }
41254
41255 static inline long interrupt_not_for_us(struct ctlr_info *h)
41256 {
41257- return (h->access.intr_pending(h) == 0) ||
41258+ return (h->access->intr_pending(h) == 0) ||
41259 (h->interrupts_enabled == 0);
41260 }
41261
41262@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
41263 if (prod_index < 0)
41264 return -ENODEV;
41265 h->product_name = products[prod_index].product_name;
41266- h->access = *(products[prod_index].access);
41267+ h->access = products[prod_index].access;
41268
41269 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
41270 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
41271@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
41272
41273 assert_spin_locked(&lockup_detector_lock);
41274 remove_ctlr_from_lockup_detector_list(h);
41275- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41276+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41277 spin_lock_irqsave(&h->lock, flags);
41278 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
41279 spin_unlock_irqrestore(&h->lock, flags);
41280@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
41281 }
41282
41283 /* make sure the board interrupts are off */
41284- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41285+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41286
41287 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
41288 goto clean2;
41289@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
41290 * fake ones to scoop up any residual completions.
41291 */
41292 spin_lock_irqsave(&h->lock, flags);
41293- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41294+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41295 spin_unlock_irqrestore(&h->lock, flags);
41296 free_irqs(h);
41297 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
41298@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
41299 dev_info(&h->pdev->dev, "Board READY.\n");
41300 dev_info(&h->pdev->dev,
41301 "Waiting for stale completions to drain.\n");
41302- h->access.set_intr_mask(h, HPSA_INTR_ON);
41303+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41304 msleep(10000);
41305- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41306+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41307
41308 rc = controller_reset_failed(h->cfgtable);
41309 if (rc)
41310@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
41311 }
41312
41313 /* Turn the interrupts on so we can service requests */
41314- h->access.set_intr_mask(h, HPSA_INTR_ON);
41315+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41316
41317 hpsa_hba_inquiry(h);
41318 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
41319@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
41320 * To write all data in the battery backed cache to disks
41321 */
41322 hpsa_flush_cache(h);
41323- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41324+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41325 hpsa_free_irqs_and_disable_msix(h);
41326 }
41327
41328@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
41329 return;
41330 }
41331 /* Change the access methods to the performant access methods */
41332- h->access = SA5_performant_access;
41333+ h->access = &SA5_performant_access;
41334 h->transMethod = CFGTBL_Trans_Performant;
41335 }
41336
41337diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
41338index 9816479..c5d4e97 100644
41339--- a/drivers/scsi/hpsa.h
41340+++ b/drivers/scsi/hpsa.h
41341@@ -79,7 +79,7 @@ struct ctlr_info {
41342 unsigned int msix_vector;
41343 unsigned int msi_vector;
41344 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
41345- struct access_method access;
41346+ struct access_method *access;
41347
41348 /* queue and queue Info */
41349 struct list_head reqQ;
41350diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
41351index c772d8d..35c362c 100644
41352--- a/drivers/scsi/libfc/fc_exch.c
41353+++ b/drivers/scsi/libfc/fc_exch.c
41354@@ -100,12 +100,12 @@ struct fc_exch_mgr {
41355 u16 pool_max_index;
41356
41357 struct {
41358- atomic_t no_free_exch;
41359- atomic_t no_free_exch_xid;
41360- atomic_t xid_not_found;
41361- atomic_t xid_busy;
41362- atomic_t seq_not_found;
41363- atomic_t non_bls_resp;
41364+ atomic_unchecked_t no_free_exch;
41365+ atomic_unchecked_t no_free_exch_xid;
41366+ atomic_unchecked_t xid_not_found;
41367+ atomic_unchecked_t xid_busy;
41368+ atomic_unchecked_t seq_not_found;
41369+ atomic_unchecked_t non_bls_resp;
41370 } stats;
41371 };
41372
41373@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
41374 /* allocate memory for exchange */
41375 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
41376 if (!ep) {
41377- atomic_inc(&mp->stats.no_free_exch);
41378+ atomic_inc_unchecked(&mp->stats.no_free_exch);
41379 goto out;
41380 }
41381 memset(ep, 0, sizeof(*ep));
41382@@ -786,7 +786,7 @@ out:
41383 return ep;
41384 err:
41385 spin_unlock_bh(&pool->lock);
41386- atomic_inc(&mp->stats.no_free_exch_xid);
41387+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
41388 mempool_free(ep, mp->ep_pool);
41389 return NULL;
41390 }
41391@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41392 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41393 ep = fc_exch_find(mp, xid);
41394 if (!ep) {
41395- atomic_inc(&mp->stats.xid_not_found);
41396+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41397 reject = FC_RJT_OX_ID;
41398 goto out;
41399 }
41400@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41401 ep = fc_exch_find(mp, xid);
41402 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41403 if (ep) {
41404- atomic_inc(&mp->stats.xid_busy);
41405+ atomic_inc_unchecked(&mp->stats.xid_busy);
41406 reject = FC_RJT_RX_ID;
41407 goto rel;
41408 }
41409@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41410 }
41411 xid = ep->xid; /* get our XID */
41412 } else if (!ep) {
41413- atomic_inc(&mp->stats.xid_not_found);
41414+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41415 reject = FC_RJT_RX_ID; /* XID not found */
41416 goto out;
41417 }
41418@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41419 } else {
41420 sp = &ep->seq;
41421 if (sp->id != fh->fh_seq_id) {
41422- atomic_inc(&mp->stats.seq_not_found);
41423+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41424 if (f_ctl & FC_FC_END_SEQ) {
41425 /*
41426 * Update sequence_id based on incoming last
41427@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41428
41429 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41430 if (!ep) {
41431- atomic_inc(&mp->stats.xid_not_found);
41432+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41433 goto out;
41434 }
41435 if (ep->esb_stat & ESB_ST_COMPLETE) {
41436- atomic_inc(&mp->stats.xid_not_found);
41437+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41438 goto rel;
41439 }
41440 if (ep->rxid == FC_XID_UNKNOWN)
41441 ep->rxid = ntohs(fh->fh_rx_id);
41442 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41443- atomic_inc(&mp->stats.xid_not_found);
41444+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41445 goto rel;
41446 }
41447 if (ep->did != ntoh24(fh->fh_s_id) &&
41448 ep->did != FC_FID_FLOGI) {
41449- atomic_inc(&mp->stats.xid_not_found);
41450+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41451 goto rel;
41452 }
41453 sof = fr_sof(fp);
41454@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41455 sp->ssb_stat |= SSB_ST_RESP;
41456 sp->id = fh->fh_seq_id;
41457 } else if (sp->id != fh->fh_seq_id) {
41458- atomic_inc(&mp->stats.seq_not_found);
41459+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41460 goto rel;
41461 }
41462
41463@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41464 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41465
41466 if (!sp)
41467- atomic_inc(&mp->stats.xid_not_found);
41468+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41469 else
41470- atomic_inc(&mp->stats.non_bls_resp);
41471+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
41472
41473 fc_frame_free(fp);
41474 }
41475@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41476
41477 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41478 mp = ema->mp;
41479- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
41480+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
41481 st->fc_no_free_exch_xid +=
41482- atomic_read(&mp->stats.no_free_exch_xid);
41483- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
41484- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
41485- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
41486- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
41487+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
41488+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
41489+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
41490+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
41491+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
41492 }
41493 }
41494 EXPORT_SYMBOL(fc_exch_update_stats);
41495diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
41496index bdb81cd..d3c7c2c 100644
41497--- a/drivers/scsi/libsas/sas_ata.c
41498+++ b/drivers/scsi/libsas/sas_ata.c
41499@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
41500 .postreset = ata_std_postreset,
41501 .error_handler = ata_std_error_handler,
41502 .post_internal_cmd = sas_ata_post_internal,
41503- .qc_defer = ata_std_qc_defer,
41504+ .qc_defer = ata_std_qc_defer,
41505 .qc_prep = ata_noop_qc_prep,
41506 .qc_issue = sas_ata_qc_issue,
41507 .qc_fill_rtf = sas_ata_qc_fill_rtf,
41508diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
41509index df4c13a..a51e90c 100644
41510--- a/drivers/scsi/lpfc/lpfc.h
41511+++ b/drivers/scsi/lpfc/lpfc.h
41512@@ -424,7 +424,7 @@ struct lpfc_vport {
41513 struct dentry *debug_nodelist;
41514 struct dentry *vport_debugfs_root;
41515 struct lpfc_debugfs_trc *disc_trc;
41516- atomic_t disc_trc_cnt;
41517+ atomic_unchecked_t disc_trc_cnt;
41518 #endif
41519 uint8_t stat_data_enabled;
41520 uint8_t stat_data_blocked;
41521@@ -842,8 +842,8 @@ struct lpfc_hba {
41522 struct timer_list fabric_block_timer;
41523 unsigned long bit_flags;
41524 #define FABRIC_COMANDS_BLOCKED 0
41525- atomic_t num_rsrc_err;
41526- atomic_t num_cmd_success;
41527+ atomic_unchecked_t num_rsrc_err;
41528+ atomic_unchecked_t num_cmd_success;
41529 unsigned long last_rsrc_error_time;
41530 unsigned long last_ramp_down_time;
41531 unsigned long last_ramp_up_time;
41532@@ -879,7 +879,7 @@ struct lpfc_hba {
41533
41534 struct dentry *debug_slow_ring_trc;
41535 struct lpfc_debugfs_trc *slow_ring_trc;
41536- atomic_t slow_ring_trc_cnt;
41537+ atomic_unchecked_t slow_ring_trc_cnt;
41538 /* iDiag debugfs sub-directory */
41539 struct dentry *idiag_root;
41540 struct dentry *idiag_pci_cfg;
41541diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41542index f63f5ff..de29189 100644
41543--- a/drivers/scsi/lpfc/lpfc_debugfs.c
41544+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41545@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41546
41547 #include <linux/debugfs.h>
41548
41549-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41550+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41551 static unsigned long lpfc_debugfs_start_time = 0L;
41552
41553 /* iDiag */
41554@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41555 lpfc_debugfs_enable = 0;
41556
41557 len = 0;
41558- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41559+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41560 (lpfc_debugfs_max_disc_trc - 1);
41561 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41562 dtp = vport->disc_trc + i;
41563@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41564 lpfc_debugfs_enable = 0;
41565
41566 len = 0;
41567- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41568+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41569 (lpfc_debugfs_max_slow_ring_trc - 1);
41570 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41571 dtp = phba->slow_ring_trc + i;
41572@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41573 !vport || !vport->disc_trc)
41574 return;
41575
41576- index = atomic_inc_return(&vport->disc_trc_cnt) &
41577+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41578 (lpfc_debugfs_max_disc_trc - 1);
41579 dtp = vport->disc_trc + index;
41580 dtp->fmt = fmt;
41581 dtp->data1 = data1;
41582 dtp->data2 = data2;
41583 dtp->data3 = data3;
41584- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41585+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41586 dtp->jif = jiffies;
41587 #endif
41588 return;
41589@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41590 !phba || !phba->slow_ring_trc)
41591 return;
41592
41593- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41594+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41595 (lpfc_debugfs_max_slow_ring_trc - 1);
41596 dtp = phba->slow_ring_trc + index;
41597 dtp->fmt = fmt;
41598 dtp->data1 = data1;
41599 dtp->data2 = data2;
41600 dtp->data3 = data3;
41601- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41602+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41603 dtp->jif = jiffies;
41604 #endif
41605 return;
41606@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41607 "slow_ring buffer\n");
41608 goto debug_failed;
41609 }
41610- atomic_set(&phba->slow_ring_trc_cnt, 0);
41611+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41612 memset(phba->slow_ring_trc, 0,
41613 (sizeof(struct lpfc_debugfs_trc) *
41614 lpfc_debugfs_max_slow_ring_trc));
41615@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41616 "buffer\n");
41617 goto debug_failed;
41618 }
41619- atomic_set(&vport->disc_trc_cnt, 0);
41620+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41621
41622 snprintf(name, sizeof(name), "discovery_trace");
41623 vport->debug_disc_trc =
41624diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41625index 89ad558..76956c4 100644
41626--- a/drivers/scsi/lpfc/lpfc_init.c
41627+++ b/drivers/scsi/lpfc/lpfc_init.c
41628@@ -10618,8 +10618,10 @@ lpfc_init(void)
41629 "misc_register returned with status %d", error);
41630
41631 if (lpfc_enable_npiv) {
41632- lpfc_transport_functions.vport_create = lpfc_vport_create;
41633- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41634+ pax_open_kernel();
41635+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41636+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41637+ pax_close_kernel();
41638 }
41639 lpfc_transport_template =
41640 fc_attach_transport(&lpfc_transport_functions);
41641diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41642index 60e5a17..ff7a793 100644
41643--- a/drivers/scsi/lpfc/lpfc_scsi.c
41644+++ b/drivers/scsi/lpfc/lpfc_scsi.c
41645@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41646 uint32_t evt_posted;
41647
41648 spin_lock_irqsave(&phba->hbalock, flags);
41649- atomic_inc(&phba->num_rsrc_err);
41650+ atomic_inc_unchecked(&phba->num_rsrc_err);
41651 phba->last_rsrc_error_time = jiffies;
41652
41653 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41654@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41655 unsigned long flags;
41656 struct lpfc_hba *phba = vport->phba;
41657 uint32_t evt_posted;
41658- atomic_inc(&phba->num_cmd_success);
41659+ atomic_inc_unchecked(&phba->num_cmd_success);
41660
41661 if (vport->cfg_lun_queue_depth <= queue_depth)
41662 return;
41663@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41664 unsigned long num_rsrc_err, num_cmd_success;
41665 int i;
41666
41667- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41668- num_cmd_success = atomic_read(&phba->num_cmd_success);
41669+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41670+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41671
41672 /*
41673 * The error and success command counters are global per
41674@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41675 }
41676 }
41677 lpfc_destroy_vport_work_array(phba, vports);
41678- atomic_set(&phba->num_rsrc_err, 0);
41679- atomic_set(&phba->num_cmd_success, 0);
41680+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41681+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41682 }
41683
41684 /**
41685@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41686 }
41687 }
41688 lpfc_destroy_vport_work_array(phba, vports);
41689- atomic_set(&phba->num_rsrc_err, 0);
41690- atomic_set(&phba->num_cmd_success, 0);
41691+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41692+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41693 }
41694
41695 /**
41696diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41697index b46f5e9..c4c4ccb 100644
41698--- a/drivers/scsi/pmcraid.c
41699+++ b/drivers/scsi/pmcraid.c
41700@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41701 res->scsi_dev = scsi_dev;
41702 scsi_dev->hostdata = res;
41703 res->change_detected = 0;
41704- atomic_set(&res->read_failures, 0);
41705- atomic_set(&res->write_failures, 0);
41706+ atomic_set_unchecked(&res->read_failures, 0);
41707+ atomic_set_unchecked(&res->write_failures, 0);
41708 rc = 0;
41709 }
41710 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41711@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41712
41713 /* If this was a SCSI read/write command keep count of errors */
41714 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41715- atomic_inc(&res->read_failures);
41716+ atomic_inc_unchecked(&res->read_failures);
41717 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41718- atomic_inc(&res->write_failures);
41719+ atomic_inc_unchecked(&res->write_failures);
41720
41721 if (!RES_IS_GSCSI(res->cfg_entry) &&
41722 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41723@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41724 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41725 * hrrq_id assigned here in queuecommand
41726 */
41727- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41728+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41729 pinstance->num_hrrq;
41730 cmd->cmd_done = pmcraid_io_done;
41731
41732@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
41733 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41734 * hrrq_id assigned here in queuecommand
41735 */
41736- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41737+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41738 pinstance->num_hrrq;
41739
41740 if (request_size) {
41741@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41742
41743 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41744 /* add resources only after host is added into system */
41745- if (!atomic_read(&pinstance->expose_resources))
41746+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41747 return;
41748
41749 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41750@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41751 init_waitqueue_head(&pinstance->reset_wait_q);
41752
41753 atomic_set(&pinstance->outstanding_cmds, 0);
41754- atomic_set(&pinstance->last_message_id, 0);
41755- atomic_set(&pinstance->expose_resources, 0);
41756+ atomic_set_unchecked(&pinstance->last_message_id, 0);
41757+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41758
41759 INIT_LIST_HEAD(&pinstance->free_res_q);
41760 INIT_LIST_HEAD(&pinstance->used_res_q);
41761@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41762 /* Schedule worker thread to handle CCN and take care of adding and
41763 * removing devices to OS
41764 */
41765- atomic_set(&pinstance->expose_resources, 1);
41766+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41767 schedule_work(&pinstance->worker_q);
41768 return rc;
41769
41770diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41771index e1d150f..6c6df44 100644
41772--- a/drivers/scsi/pmcraid.h
41773+++ b/drivers/scsi/pmcraid.h
41774@@ -748,7 +748,7 @@ struct pmcraid_instance {
41775 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41776
41777 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41778- atomic_t last_message_id;
41779+ atomic_unchecked_t last_message_id;
41780
41781 /* configuration table */
41782 struct pmcraid_config_table *cfg_table;
41783@@ -777,7 +777,7 @@ struct pmcraid_instance {
41784 atomic_t outstanding_cmds;
41785
41786 /* should add/delete resources to mid-layer now ?*/
41787- atomic_t expose_resources;
41788+ atomic_unchecked_t expose_resources;
41789
41790
41791
41792@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41793 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41794 };
41795 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41796- atomic_t read_failures; /* count of failed READ commands */
41797- atomic_t write_failures; /* count of failed WRITE commands */
41798+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41799+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41800
41801 /* To indicate add/delete/modify during CCN */
41802 u8 change_detected;
41803diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41804index 83d7984..a27d947 100644
41805--- a/drivers/scsi/qla2xxx/qla_attr.c
41806+++ b/drivers/scsi/qla2xxx/qla_attr.c
41807@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41808 return 0;
41809 }
41810
41811-struct fc_function_template qla2xxx_transport_functions = {
41812+fc_function_template_no_const qla2xxx_transport_functions = {
41813
41814 .show_host_node_name = 1,
41815 .show_host_port_name = 1,
41816@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41817 .bsg_timeout = qla24xx_bsg_timeout,
41818 };
41819
41820-struct fc_function_template qla2xxx_transport_vport_functions = {
41821+fc_function_template_no_const qla2xxx_transport_vport_functions = {
41822
41823 .show_host_node_name = 1,
41824 .show_host_port_name = 1,
41825diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41826index 2411d1a..4673766 100644
41827--- a/drivers/scsi/qla2xxx/qla_gbl.h
41828+++ b/drivers/scsi/qla2xxx/qla_gbl.h
41829@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41830 struct device_attribute;
41831 extern struct device_attribute *qla2x00_host_attrs[];
41832 struct fc_function_template;
41833-extern struct fc_function_template qla2xxx_transport_functions;
41834-extern struct fc_function_template qla2xxx_transport_vport_functions;
41835+extern fc_function_template_no_const qla2xxx_transport_functions;
41836+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41837 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41838 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41839 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41840diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41841index 10d23f8..a7d5d4c 100644
41842--- a/drivers/scsi/qla2xxx/qla_os.c
41843+++ b/drivers/scsi/qla2xxx/qla_os.c
41844@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41845 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41846 /* Ok, a 64bit DMA mask is applicable. */
41847 ha->flags.enable_64bit_addressing = 1;
41848- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41849- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41850+ pax_open_kernel();
41851+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41852+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41853+ pax_close_kernel();
41854 return;
41855 }
41856 }
41857diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41858index 329d553..f20d31d 100644
41859--- a/drivers/scsi/qla4xxx/ql4_def.h
41860+++ b/drivers/scsi/qla4xxx/ql4_def.h
41861@@ -273,7 +273,7 @@ struct ddb_entry {
41862 * (4000 only) */
41863 atomic_t relogin_timer; /* Max Time to wait for
41864 * relogin to complete */
41865- atomic_t relogin_retry_count; /* Num of times relogin has been
41866+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41867 * retried */
41868 uint32_t default_time2wait; /* Default Min time between
41869 * relogins (+aens) */
41870diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41871index 4cec123..7c1329f 100644
41872--- a/drivers/scsi/qla4xxx/ql4_os.c
41873+++ b/drivers/scsi/qla4xxx/ql4_os.c
41874@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41875 */
41876 if (!iscsi_is_session_online(cls_sess)) {
41877 /* Reset retry relogin timer */
41878- atomic_inc(&ddb_entry->relogin_retry_count);
41879+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41880 DEBUG2(ql4_printk(KERN_INFO, ha,
41881 "%s: index[%d] relogin timed out-retrying"
41882 " relogin (%d), retry (%d)\n", __func__,
41883 ddb_entry->fw_ddb_index,
41884- atomic_read(&ddb_entry->relogin_retry_count),
41885+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41886 ddb_entry->default_time2wait + 4));
41887 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41888 atomic_set(&ddb_entry->retry_relogin_timer,
41889@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41890
41891 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41892 atomic_set(&ddb_entry->relogin_timer, 0);
41893- atomic_set(&ddb_entry->relogin_retry_count, 0);
41894+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41895 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41896 ddb_entry->default_relogin_timeout =
41897 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41898diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41899index 2c0d0ec..4e8681a 100644
41900--- a/drivers/scsi/scsi.c
41901+++ b/drivers/scsi/scsi.c
41902@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41903 unsigned long timeout;
41904 int rtn = 0;
41905
41906- atomic_inc(&cmd->device->iorequest_cnt);
41907+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41908
41909 /* check if the device is still usable */
41910 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41911diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41912index f1bf5af..f67e943 100644
41913--- a/drivers/scsi/scsi_lib.c
41914+++ b/drivers/scsi/scsi_lib.c
41915@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41916 shost = sdev->host;
41917 scsi_init_cmd_errh(cmd);
41918 cmd->result = DID_NO_CONNECT << 16;
41919- atomic_inc(&cmd->device->iorequest_cnt);
41920+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41921
41922 /*
41923 * SCSI request completion path will do scsi_device_unbusy(),
41924@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41925
41926 INIT_LIST_HEAD(&cmd->eh_entry);
41927
41928- atomic_inc(&cmd->device->iodone_cnt);
41929+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41930 if (cmd->result)
41931- atomic_inc(&cmd->device->ioerr_cnt);
41932+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41933
41934 disposition = scsi_decide_disposition(cmd);
41935 if (disposition != SUCCESS &&
41936diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41937index 931a7d9..0c2a754 100644
41938--- a/drivers/scsi/scsi_sysfs.c
41939+++ b/drivers/scsi/scsi_sysfs.c
41940@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41941 char *buf) \
41942 { \
41943 struct scsi_device *sdev = to_scsi_device(dev); \
41944- unsigned long long count = atomic_read(&sdev->field); \
41945+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41946 return snprintf(buf, 20, "0x%llx\n", count); \
41947 } \
41948 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41949diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41950index 84a1fdf..693b0d6 100644
41951--- a/drivers/scsi/scsi_tgt_lib.c
41952+++ b/drivers/scsi/scsi_tgt_lib.c
41953@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41954 int err;
41955
41956 dprintk("%lx %u\n", uaddr, len);
41957- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41958+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41959 if (err) {
41960 /*
41961 * TODO: need to fixup sg_tablesize, max_segment_size,
41962diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41963index e894ca7..de9d7660 100644
41964--- a/drivers/scsi/scsi_transport_fc.c
41965+++ b/drivers/scsi/scsi_transport_fc.c
41966@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
41967 * Netlink Infrastructure
41968 */
41969
41970-static atomic_t fc_event_seq;
41971+static atomic_unchecked_t fc_event_seq;
41972
41973 /**
41974 * fc_get_event_number - Obtain the next sequential FC event number
41975@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
41976 u32
41977 fc_get_event_number(void)
41978 {
41979- return atomic_add_return(1, &fc_event_seq);
41980+ return atomic_add_return_unchecked(1, &fc_event_seq);
41981 }
41982 EXPORT_SYMBOL(fc_get_event_number);
41983
41984@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
41985 {
41986 int error;
41987
41988- atomic_set(&fc_event_seq, 0);
41989+ atomic_set_unchecked(&fc_event_seq, 0);
41990
41991 error = transport_class_register(&fc_host_class);
41992 if (error)
41993@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
41994 char *cp;
41995
41996 *val = simple_strtoul(buf, &cp, 0);
41997- if ((*cp && (*cp != '\n')) || (*val < 0))
41998+ if (*cp && (*cp != '\n'))
41999 return -EINVAL;
42000 /*
42001 * Check for overflow; dev_loss_tmo is u32
42002diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42003index 31969f2..2b348f0 100644
42004--- a/drivers/scsi/scsi_transport_iscsi.c
42005+++ b/drivers/scsi/scsi_transport_iscsi.c
42006@@ -79,7 +79,7 @@ struct iscsi_internal {
42007 struct transport_container session_cont;
42008 };
42009
42010-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42011+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42012 static struct workqueue_struct *iscsi_eh_timer_workq;
42013
42014 static DEFINE_IDA(iscsi_sess_ida);
42015@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42016 int err;
42017
42018 ihost = shost->shost_data;
42019- session->sid = atomic_add_return(1, &iscsi_session_nr);
42020+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42021
42022 if (target_id == ISCSI_MAX_TARGET) {
42023 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42024@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
42025 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42026 ISCSI_TRANSPORT_VERSION);
42027
42028- atomic_set(&iscsi_session_nr, 0);
42029+ atomic_set_unchecked(&iscsi_session_nr, 0);
42030
42031 err = class_register(&iscsi_transport_class);
42032 if (err)
42033diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42034index f379c7f..e8fc69c 100644
42035--- a/drivers/scsi/scsi_transport_srp.c
42036+++ b/drivers/scsi/scsi_transport_srp.c
42037@@ -33,7 +33,7 @@
42038 #include "scsi_transport_srp_internal.h"
42039
42040 struct srp_host_attrs {
42041- atomic_t next_port_id;
42042+ atomic_unchecked_t next_port_id;
42043 };
42044 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42045
42046@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42047 struct Scsi_Host *shost = dev_to_shost(dev);
42048 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42049
42050- atomic_set(&srp_host->next_port_id, 0);
42051+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42052 return 0;
42053 }
42054
42055@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42056 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42057 rport->roles = ids->roles;
42058
42059- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42060+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42061 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42062
42063 transport_setup_device(&rport->dev);
42064diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42065index 7992635..609faf8 100644
42066--- a/drivers/scsi/sd.c
42067+++ b/drivers/scsi/sd.c
42068@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
42069 sdkp->disk = gd;
42070 sdkp->index = index;
42071 atomic_set(&sdkp->openers, 0);
42072- atomic_set(&sdkp->device->ioerr_cnt, 0);
42073+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42074
42075 if (!sdp->request_queue->rq_timeout) {
42076 if (sdp->type != TYPE_MOD)
42077diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42078index be2c9a6..275525c 100644
42079--- a/drivers/scsi/sg.c
42080+++ b/drivers/scsi/sg.c
42081@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42082 sdp->disk->disk_name,
42083 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42084 NULL,
42085- (char *)arg);
42086+ (char __user *)arg);
42087 case BLKTRACESTART:
42088 return blk_trace_startstop(sdp->device->request_queue, 1);
42089 case BLKTRACESTOP:
42090diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42091index 19ee901..6e8c2ef 100644
42092--- a/drivers/spi/spi.c
42093+++ b/drivers/spi/spi.c
42094@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
42095 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42096
42097 /* portable code must never pass more than 32 bytes */
42098-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42099+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42100
42101 static u8 *buf;
42102
42103diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42104index c7a5f97..71ecd35 100644
42105--- a/drivers/staging/iio/iio_hwmon.c
42106+++ b/drivers/staging/iio/iio_hwmon.c
42107@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
42108 static int iio_hwmon_probe(struct platform_device *pdev)
42109 {
42110 struct iio_hwmon_state *st;
42111- struct sensor_device_attribute *a;
42112+ sensor_device_attribute_no_const *a;
42113 int ret, i;
42114 int in_i = 1, temp_i = 1, curr_i = 1;
42115 enum iio_chan_type type;
42116diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42117index 34afc16..ffe44dd 100644
42118--- a/drivers/staging/octeon/ethernet-rx.c
42119+++ b/drivers/staging/octeon/ethernet-rx.c
42120@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42121 /* Increment RX stats for virtual ports */
42122 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42123 #ifdef CONFIG_64BIT
42124- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42125- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42126+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42127+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42128 #else
42129- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42130- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42131+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42132+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42133 #endif
42134 }
42135 netif_receive_skb(skb);
42136@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42137 dev->name);
42138 */
42139 #ifdef CONFIG_64BIT
42140- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42141+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42142 #else
42143- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42144+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42145 #endif
42146 dev_kfree_skb_irq(skb);
42147 }
42148diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42149index ef32dc1..a159d68 100644
42150--- a/drivers/staging/octeon/ethernet.c
42151+++ b/drivers/staging/octeon/ethernet.c
42152@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42153 * since the RX tasklet also increments it.
42154 */
42155 #ifdef CONFIG_64BIT
42156- atomic64_add(rx_status.dropped_packets,
42157- (atomic64_t *)&priv->stats.rx_dropped);
42158+ atomic64_add_unchecked(rx_status.dropped_packets,
42159+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42160 #else
42161- atomic_add(rx_status.dropped_packets,
42162- (atomic_t *)&priv->stats.rx_dropped);
42163+ atomic_add_unchecked(rx_status.dropped_packets,
42164+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42165 #endif
42166 }
42167
42168diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42169index a2b7e03..aaf3630 100644
42170--- a/drivers/staging/ramster/tmem.c
42171+++ b/drivers/staging/ramster/tmem.c
42172@@ -50,25 +50,25 @@
42173 * A tmem host implementation must use this function to register callbacks
42174 * for memory allocation.
42175 */
42176-static struct tmem_hostops tmem_hostops;
42177+static struct tmem_hostops *tmem_hostops;
42178
42179 static void tmem_objnode_tree_init(void);
42180
42181 void tmem_register_hostops(struct tmem_hostops *m)
42182 {
42183 tmem_objnode_tree_init();
42184- tmem_hostops = *m;
42185+ tmem_hostops = m;
42186 }
42187
42188 /*
42189 * A tmem host implementation must use this function to register
42190 * callbacks for a page-accessible memory (PAM) implementation.
42191 */
42192-static struct tmem_pamops tmem_pamops;
42193+static struct tmem_pamops *tmem_pamops;
42194
42195 void tmem_register_pamops(struct tmem_pamops *m)
42196 {
42197- tmem_pamops = *m;
42198+ tmem_pamops = m;
42199 }
42200
42201 /*
42202@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42203 obj->pampd_count = 0;
42204 #ifdef CONFIG_RAMSTER
42205 if (tmem_pamops.new_obj != NULL)
42206- (*tmem_pamops.new_obj)(obj);
42207+ (tmem_pamops->new_obj)(obj);
42208 #endif
42209 SET_SENTINEL(obj, OBJ);
42210
42211@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42212 rbnode = rb_next(rbnode);
42213 tmem_pampd_destroy_all_in_obj(obj, true);
42214 tmem_obj_free(obj, hb);
42215- (*tmem_hostops.obj_free)(obj, pool);
42216+ (tmem_hostops->obj_free)(obj, pool);
42217 }
42218 spin_unlock(&hb->lock);
42219 }
42220@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
42221 ASSERT_SENTINEL(obj, OBJ);
42222 BUG_ON(obj->pool == NULL);
42223 ASSERT_SENTINEL(obj->pool, POOL);
42224- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
42225+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
42226 if (unlikely(objnode == NULL))
42227 goto out;
42228 objnode->obj = obj;
42229@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
42230 ASSERT_SENTINEL(pool, POOL);
42231 objnode->obj->objnode_count--;
42232 objnode->obj = NULL;
42233- (*tmem_hostops.objnode_free)(objnode, pool);
42234+ (tmem_hostops->objnode_free)(objnode, pool);
42235 }
42236
42237 /*
42238@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
42239 void *old_pampd = *(void **)slot;
42240 *(void **)slot = new_pampd;
42241 if (!no_free)
42242- (*tmem_pamops.free)(old_pampd, obj->pool,
42243+ (tmem_pamops->free)(old_pampd, obj->pool,
42244 NULL, 0, false);
42245 ret = new_pampd;
42246 }
42247@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
42248 if (objnode->slots[i]) {
42249 if (ht == 1) {
42250 obj->pampd_count--;
42251- (*tmem_pamops.free)(objnode->slots[i],
42252+ (tmem_pamops->free)(objnode->slots[i],
42253 obj->pool, NULL, 0, true);
42254 objnode->slots[i] = NULL;
42255 continue;
42256@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42257 return;
42258 if (obj->objnode_tree_height == 0) {
42259 obj->pampd_count--;
42260- (*tmem_pamops.free)(obj->objnode_tree_root,
42261+ (tmem_pamops->free)(obj->objnode_tree_root,
42262 obj->pool, NULL, 0, true);
42263 } else {
42264 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
42265@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42266 obj->objnode_tree_root = NULL;
42267 #ifdef CONFIG_RAMSTER
42268 if (tmem_pamops.free_obj != NULL)
42269- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
42270+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
42271 #endif
42272 }
42273
42274@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42275 /* if found, is a dup put, flush the old one */
42276 pampd_del = tmem_pampd_delete_from_obj(obj, index);
42277 BUG_ON(pampd_del != pampd);
42278- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42279+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42280 if (obj->pampd_count == 0) {
42281 objnew = obj;
42282 objfound = NULL;
42283@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42284 pampd = NULL;
42285 }
42286 } else {
42287- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
42288+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
42289 if (unlikely(obj == NULL)) {
42290 ret = -ENOMEM;
42291 goto out;
42292@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42293 if (unlikely(ret == -ENOMEM))
42294 /* may have partially built objnode tree ("stump") */
42295 goto delete_and_free;
42296- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
42297+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
42298 goto out;
42299
42300 delete_and_free:
42301 (void)tmem_pampd_delete_from_obj(obj, index);
42302 if (pampd)
42303- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
42304+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
42305 if (objnew) {
42306 tmem_obj_free(objnew, hb);
42307- (*tmem_hostops.obj_free)(objnew, pool);
42308+ (tmem_hostops->obj_free)(objnew, pool);
42309 }
42310 out:
42311 spin_unlock(&hb->lock);
42312@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
42313 if (pampd != NULL) {
42314 BUG_ON(obj == NULL);
42315 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
42316- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
42317+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
42318 } else if (delete) {
42319 BUG_ON(obj == NULL);
42320 (void)tmem_pampd_delete_from_obj(obj, index);
42321@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42322 int ret = 0;
42323
42324 if (!is_ephemeral(pool))
42325- new_pampd = (*tmem_pamops.repatriate_preload)(
42326+ new_pampd = (tmem_pamops->repatriate_preload)(
42327 old_pampd, pool, oidp, index, &intransit);
42328 if (intransit)
42329 ret = -EAGAIN;
42330@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42331 /* must release the hb->lock else repatriate can't sleep */
42332 spin_unlock(&hb->lock);
42333 if (!intransit)
42334- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
42335+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
42336 oidp, index, free, data);
42337 if (ret == -EAGAIN) {
42338 /* rare I think, but should cond_resched()??? */
42339@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
42340 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
42341 /* if we bug here, pamops wasn't properly set up for ramster */
42342 BUG_ON(tmem_pamops.replace_in_obj == NULL);
42343- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
42344+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
42345 out:
42346 spin_unlock(&hb->lock);
42347 return ret;
42348@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42349 if (free) {
42350 if (obj->pampd_count == 0) {
42351 tmem_obj_free(obj, hb);
42352- (*tmem_hostops.obj_free)(obj, pool);
42353+ (tmem_hostops->obj_free)(obj, pool);
42354 obj = NULL;
42355 }
42356 }
42357 if (free)
42358- ret = (*tmem_pamops.get_data_and_free)(
42359+ ret = (tmem_pamops->get_data_and_free)(
42360 data, sizep, raw, pampd, pool, oidp, index);
42361 else
42362- ret = (*tmem_pamops.get_data)(
42363+ ret = (tmem_pamops->get_data)(
42364 data, sizep, raw, pampd, pool, oidp, index);
42365 if (ret < 0)
42366 goto out;
42367@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
42368 pampd = tmem_pampd_delete_from_obj(obj, index);
42369 if (pampd == NULL)
42370 goto out;
42371- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42372+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42373 if (obj->pampd_count == 0) {
42374 tmem_obj_free(obj, hb);
42375- (*tmem_hostops.obj_free)(obj, pool);
42376+ (tmem_hostops->obj_free)(obj, pool);
42377 }
42378 ret = 0;
42379
42380@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
42381 goto out;
42382 tmem_pampd_destroy_all_in_obj(obj, false);
42383 tmem_obj_free(obj, hb);
42384- (*tmem_hostops.obj_free)(obj, pool);
42385+ (tmem_hostops->obj_free)(obj, pool);
42386 ret = 0;
42387
42388 out:
42389diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
42390index dc23395..cf7e9b1 100644
42391--- a/drivers/staging/rtl8712/rtl871x_io.h
42392+++ b/drivers/staging/rtl8712/rtl871x_io.h
42393@@ -108,7 +108,7 @@ struct _io_ops {
42394 u8 *pmem);
42395 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42396 u8 *pmem);
42397-};
42398+} __no_const;
42399
42400 struct io_req {
42401 struct list_head list;
42402diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42403index 1f5088b..0e59820 100644
42404--- a/drivers/staging/sbe-2t3e3/netdev.c
42405+++ b/drivers/staging/sbe-2t3e3/netdev.c
42406@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42407 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42408
42409 if (rlen)
42410- if (copy_to_user(data, &resp, rlen))
42411+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42412 return -EFAULT;
42413
42414 return 0;
42415diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42416index 5dddc4d..34fcb2f 100644
42417--- a/drivers/staging/usbip/vhci.h
42418+++ b/drivers/staging/usbip/vhci.h
42419@@ -83,7 +83,7 @@ struct vhci_hcd {
42420 unsigned resuming:1;
42421 unsigned long re_timeout;
42422
42423- atomic_t seqnum;
42424+ atomic_unchecked_t seqnum;
42425
42426 /*
42427 * NOTE:
42428diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42429index c3aa219..bf8b3de 100644
42430--- a/drivers/staging/usbip/vhci_hcd.c
42431+++ b/drivers/staging/usbip/vhci_hcd.c
42432@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
42433 return;
42434 }
42435
42436- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42437+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42438 if (priv->seqnum == 0xffff)
42439 dev_info(&urb->dev->dev, "seqnum max\n");
42440
42441@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42442 return -ENOMEM;
42443 }
42444
42445- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42446+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42447 if (unlink->seqnum == 0xffff)
42448 pr_info("seqnum max\n");
42449
42450@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
42451 vdev->rhport = rhport;
42452 }
42453
42454- atomic_set(&vhci->seqnum, 0);
42455+ atomic_set_unchecked(&vhci->seqnum, 0);
42456 spin_lock_init(&vhci->lock);
42457
42458 hcd->power_budget = 0; /* no limit */
42459diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42460index ba5f1c0..11d8122 100644
42461--- a/drivers/staging/usbip/vhci_rx.c
42462+++ b/drivers/staging/usbip/vhci_rx.c
42463@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42464 if (!urb) {
42465 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42466 pr_info("max seqnum %d\n",
42467- atomic_read(&the_controller->seqnum));
42468+ atomic_read_unchecked(&the_controller->seqnum));
42469 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42470 return;
42471 }
42472diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42473index 5f13890..36a044b 100644
42474--- a/drivers/staging/vt6655/hostap.c
42475+++ b/drivers/staging/vt6655/hostap.c
42476@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42477 *
42478 */
42479
42480+static net_device_ops_no_const apdev_netdev_ops;
42481+
42482 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42483 {
42484 PSDevice apdev_priv;
42485 struct net_device *dev = pDevice->dev;
42486 int ret;
42487- const struct net_device_ops apdev_netdev_ops = {
42488- .ndo_start_xmit = pDevice->tx_80211,
42489- };
42490
42491 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42492
42493@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42494 *apdev_priv = *pDevice;
42495 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42496
42497+ /* only half broken now */
42498+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42499 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42500
42501 pDevice->apdev->type = ARPHRD_IEEE80211;
42502diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42503index 26a7d0e..897b083 100644
42504--- a/drivers/staging/vt6656/hostap.c
42505+++ b/drivers/staging/vt6656/hostap.c
42506@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42507 *
42508 */
42509
42510+static net_device_ops_no_const apdev_netdev_ops;
42511+
42512 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42513 {
42514 PSDevice apdev_priv;
42515 struct net_device *dev = pDevice->dev;
42516 int ret;
42517- const struct net_device_ops apdev_netdev_ops = {
42518- .ndo_start_xmit = pDevice->tx_80211,
42519- };
42520
42521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42522
42523@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42524 *apdev_priv = *pDevice;
42525 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42526
42527+ /* only half broken now */
42528+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42529 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42530
42531 pDevice->apdev->type = ARPHRD_IEEE80211;
42532diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42533index 56c8e60..1920c63 100644
42534--- a/drivers/staging/zcache/tmem.c
42535+++ b/drivers/staging/zcache/tmem.c
42536@@ -39,7 +39,7 @@
42537 * A tmem host implementation must use this function to register callbacks
42538 * for memory allocation.
42539 */
42540-static struct tmem_hostops tmem_hostops;
42541+static tmem_hostops_no_const tmem_hostops;
42542
42543 static void tmem_objnode_tree_init(void);
42544
42545@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42546 * A tmem host implementation must use this function to register
42547 * callbacks for a page-accessible memory (PAM) implementation
42548 */
42549-static struct tmem_pamops tmem_pamops;
42550+static tmem_pamops_no_const tmem_pamops;
42551
42552 void tmem_register_pamops(struct tmem_pamops *m)
42553 {
42554diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42555index 0d4aa82..f7832d4 100644
42556--- a/drivers/staging/zcache/tmem.h
42557+++ b/drivers/staging/zcache/tmem.h
42558@@ -180,6 +180,7 @@ struct tmem_pamops {
42559 void (*new_obj)(struct tmem_obj *);
42560 int (*replace_in_obj)(void *, struct tmem_obj *);
42561 };
42562+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42563 extern void tmem_register_pamops(struct tmem_pamops *m);
42564
42565 /* memory allocation methods provided by the host implementation */
42566@@ -189,6 +190,7 @@ struct tmem_hostops {
42567 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42568 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42569 };
42570+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42571 extern void tmem_register_hostops(struct tmem_hostops *m);
42572
42573 /* core tmem accessor functions */
42574diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42575index 96f4981..4daaa7e 100644
42576--- a/drivers/target/target_core_device.c
42577+++ b/drivers/target/target_core_device.c
42578@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42579 spin_lock_init(&dev->se_port_lock);
42580 spin_lock_init(&dev->se_tmr_lock);
42581 spin_lock_init(&dev->qf_cmd_lock);
42582- atomic_set(&dev->dev_ordered_id, 0);
42583+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
42584 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42585 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42586 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42587diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42588index bd587b7..173daf3 100644
42589--- a/drivers/target/target_core_transport.c
42590+++ b/drivers/target/target_core_transport.c
42591@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42592 * Used to determine when ORDERED commands should go from
42593 * Dormant to Active status.
42594 */
42595- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42596+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42597 smp_mb__after_atomic_inc();
42598 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42599 cmd->se_ordered_id, cmd->sam_task_attr,
42600diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42601index b09c8d1f..c4225c0 100644
42602--- a/drivers/tty/cyclades.c
42603+++ b/drivers/tty/cyclades.c
42604@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42605 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42606 info->port.count);
42607 #endif
42608- info->port.count++;
42609+ atomic_inc(&info->port.count);
42610 #ifdef CY_DEBUG_COUNT
42611 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42612- current->pid, info->port.count);
42613+ current->pid, atomic_read(&info->port.count));
42614 #endif
42615
42616 /*
42617@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42618 for (j = 0; j < cy_card[i].nports; j++) {
42619 info = &cy_card[i].ports[j];
42620
42621- if (info->port.count) {
42622+ if (atomic_read(&info->port.count)) {
42623 /* XXX is the ldisc num worth this? */
42624 struct tty_struct *tty;
42625 struct tty_ldisc *ld;
42626diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42627index 13ee53b..418d164 100644
42628--- a/drivers/tty/hvc/hvc_console.c
42629+++ b/drivers/tty/hvc/hvc_console.c
42630@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42631
42632 spin_lock_irqsave(&hp->port.lock, flags);
42633 /* Check and then increment for fast path open. */
42634- if (hp->port.count++ > 0) {
42635+ if (atomic_inc_return(&hp->port.count) > 1) {
42636 spin_unlock_irqrestore(&hp->port.lock, flags);
42637 hvc_kick();
42638 return 0;
42639@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42640
42641 spin_lock_irqsave(&hp->port.lock, flags);
42642
42643- if (--hp->port.count == 0) {
42644+ if (atomic_dec_return(&hp->port.count) == 0) {
42645 spin_unlock_irqrestore(&hp->port.lock, flags);
42646 /* We are done with the tty pointer now. */
42647 tty_port_tty_set(&hp->port, NULL);
42648@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42649 */
42650 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42651 } else {
42652- if (hp->port.count < 0)
42653+ if (atomic_read(&hp->port.count) < 0)
42654 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42655- hp->vtermno, hp->port.count);
42656+ hp->vtermno, atomic_read(&hp->port.count));
42657 spin_unlock_irqrestore(&hp->port.lock, flags);
42658 }
42659 }
42660@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42661 * open->hangup case this can be called after the final close so prevent
42662 * that from happening for now.
42663 */
42664- if (hp->port.count <= 0) {
42665+ if (atomic_read(&hp->port.count) <= 0) {
42666 spin_unlock_irqrestore(&hp->port.lock, flags);
42667 return;
42668 }
42669
42670- hp->port.count = 0;
42671+ atomic_set(&hp->port.count, 0);
42672 spin_unlock_irqrestore(&hp->port.lock, flags);
42673 tty_port_tty_set(&hp->port, NULL);
42674
42675@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42676 return -EPIPE;
42677
42678 /* FIXME what's this (unprotected) check for? */
42679- if (hp->port.count <= 0)
42680+ if (atomic_read(&hp->port.count) <= 0)
42681 return -EIO;
42682
42683 spin_lock_irqsave(&hp->lock, flags);
42684diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42685index 8776357..b2d4afd 100644
42686--- a/drivers/tty/hvc/hvcs.c
42687+++ b/drivers/tty/hvc/hvcs.c
42688@@ -83,6 +83,7 @@
42689 #include <asm/hvcserver.h>
42690 #include <asm/uaccess.h>
42691 #include <asm/vio.h>
42692+#include <asm/local.h>
42693
42694 /*
42695 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42696@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42697
42698 spin_lock_irqsave(&hvcsd->lock, flags);
42699
42700- if (hvcsd->port.count > 0) {
42701+ if (atomic_read(&hvcsd->port.count) > 0) {
42702 spin_unlock_irqrestore(&hvcsd->lock, flags);
42703 printk(KERN_INFO "HVCS: vterm state unchanged. "
42704 "The hvcs device node is still in use.\n");
42705@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42706 }
42707 }
42708
42709- hvcsd->port.count = 0;
42710+ atomic_set(&hvcsd->port.count, 0);
42711 hvcsd->port.tty = tty;
42712 tty->driver_data = hvcsd;
42713
42714@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42715 unsigned long flags;
42716
42717 spin_lock_irqsave(&hvcsd->lock, flags);
42718- hvcsd->port.count++;
42719+ atomic_inc(&hvcsd->port.count);
42720 hvcsd->todo_mask |= HVCS_SCHED_READ;
42721 spin_unlock_irqrestore(&hvcsd->lock, flags);
42722
42723@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42724 hvcsd = tty->driver_data;
42725
42726 spin_lock_irqsave(&hvcsd->lock, flags);
42727- if (--hvcsd->port.count == 0) {
42728+ if (atomic_dec_and_test(&hvcsd->port.count)) {
42729
42730 vio_disable_interrupts(hvcsd->vdev);
42731
42732@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42733
42734 free_irq(irq, hvcsd);
42735 return;
42736- } else if (hvcsd->port.count < 0) {
42737+ } else if (atomic_read(&hvcsd->port.count) < 0) {
42738 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42739 " is missmanaged.\n",
42740- hvcsd->vdev->unit_address, hvcsd->port.count);
42741+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42742 }
42743
42744 spin_unlock_irqrestore(&hvcsd->lock, flags);
42745@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42746
42747 spin_lock_irqsave(&hvcsd->lock, flags);
42748 /* Preserve this so that we know how many kref refs to put */
42749- temp_open_count = hvcsd->port.count;
42750+ temp_open_count = atomic_read(&hvcsd->port.count);
42751
42752 /*
42753 * Don't kref put inside the spinlock because the destruction
42754@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42755 tty->driver_data = NULL;
42756 hvcsd->port.tty = NULL;
42757
42758- hvcsd->port.count = 0;
42759+ atomic_set(&hvcsd->port.count, 0);
42760
42761 /* This will drop any buffered data on the floor which is OK in a hangup
42762 * scenario. */
42763@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42764 * the middle of a write operation? This is a crummy place to do this
42765 * but we want to keep it all in the spinlock.
42766 */
42767- if (hvcsd->port.count <= 0) {
42768+ if (atomic_read(&hvcsd->port.count) <= 0) {
42769 spin_unlock_irqrestore(&hvcsd->lock, flags);
42770 return -ENODEV;
42771 }
42772@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42773 {
42774 struct hvcs_struct *hvcsd = tty->driver_data;
42775
42776- if (!hvcsd || hvcsd->port.count <= 0)
42777+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42778 return 0;
42779
42780 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42781diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42782index 2cde13d..645d78f 100644
42783--- a/drivers/tty/ipwireless/tty.c
42784+++ b/drivers/tty/ipwireless/tty.c
42785@@ -29,6 +29,7 @@
42786 #include <linux/tty_driver.h>
42787 #include <linux/tty_flip.h>
42788 #include <linux/uaccess.h>
42789+#include <asm/local.h>
42790
42791 #include "tty.h"
42792 #include "network.h"
42793@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42794 mutex_unlock(&tty->ipw_tty_mutex);
42795 return -ENODEV;
42796 }
42797- if (tty->port.count == 0)
42798+ if (atomic_read(&tty->port.count) == 0)
42799 tty->tx_bytes_queued = 0;
42800
42801- tty->port.count++;
42802+ atomic_inc(&tty->port.count);
42803
42804 tty->port.tty = linux_tty;
42805 linux_tty->driver_data = tty;
42806@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42807
42808 static void do_ipw_close(struct ipw_tty *tty)
42809 {
42810- tty->port.count--;
42811-
42812- if (tty->port.count == 0) {
42813+ if (atomic_dec_return(&tty->port.count) == 0) {
42814 struct tty_struct *linux_tty = tty->port.tty;
42815
42816 if (linux_tty != NULL) {
42817@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42818 return;
42819
42820 mutex_lock(&tty->ipw_tty_mutex);
42821- if (tty->port.count == 0) {
42822+ if (atomic_read(&tty->port.count) == 0) {
42823 mutex_unlock(&tty->ipw_tty_mutex);
42824 return;
42825 }
42826@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42827 return;
42828 }
42829
42830- if (!tty->port.count) {
42831+ if (!atomic_read(&tty->port.count)) {
42832 mutex_unlock(&tty->ipw_tty_mutex);
42833 return;
42834 }
42835@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42836 return -ENODEV;
42837
42838 mutex_lock(&tty->ipw_tty_mutex);
42839- if (!tty->port.count) {
42840+ if (!atomic_read(&tty->port.count)) {
42841 mutex_unlock(&tty->ipw_tty_mutex);
42842 return -EINVAL;
42843 }
42844@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42845 if (!tty)
42846 return -ENODEV;
42847
42848- if (!tty->port.count)
42849+ if (!atomic_read(&tty->port.count))
42850 return -EINVAL;
42851
42852 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42853@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42854 if (!tty)
42855 return 0;
42856
42857- if (!tty->port.count)
42858+ if (!atomic_read(&tty->port.count))
42859 return 0;
42860
42861 return tty->tx_bytes_queued;
42862@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42863 if (!tty)
42864 return -ENODEV;
42865
42866- if (!tty->port.count)
42867+ if (!atomic_read(&tty->port.count))
42868 return -EINVAL;
42869
42870 return get_control_lines(tty);
42871@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
42872 if (!tty)
42873 return -ENODEV;
42874
42875- if (!tty->port.count)
42876+ if (!atomic_read(&tty->port.count))
42877 return -EINVAL;
42878
42879 return set_control_lines(tty, set, clear);
42880@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
42881 if (!tty)
42882 return -ENODEV;
42883
42884- if (!tty->port.count)
42885+ if (!atomic_read(&tty->port.count))
42886 return -EINVAL;
42887
42888 /* FIXME: Exactly how is the tty object locked here .. */
42889@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42890 * are gone */
42891 mutex_lock(&ttyj->ipw_tty_mutex);
42892 }
42893- while (ttyj->port.count)
42894+ while (atomic_read(&ttyj->port.count))
42895 do_ipw_close(ttyj);
42896 ipwireless_disassociate_network_ttys(network,
42897 ttyj->channel_idx);
42898diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42899index f9d2850..b006f04 100644
42900--- a/drivers/tty/moxa.c
42901+++ b/drivers/tty/moxa.c
42902@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42903 }
42904
42905 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42906- ch->port.count++;
42907+ atomic_inc(&ch->port.count);
42908 tty->driver_data = ch;
42909 tty_port_tty_set(&ch->port, tty);
42910 mutex_lock(&ch->port.mutex);
42911diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42912index bfd6771..e0d93c4 100644
42913--- a/drivers/tty/n_gsm.c
42914+++ b/drivers/tty/n_gsm.c
42915@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42916 spin_lock_init(&dlci->lock);
42917 mutex_init(&dlci->mutex);
42918 dlci->fifo = &dlci->_fifo;
42919- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42920+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42921 kfree(dlci);
42922 return NULL;
42923 }
42924@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42925 struct gsm_dlci *dlci = tty->driver_data;
42926 struct tty_port *port = &dlci->port;
42927
42928- port->count++;
42929+ atomic_inc(&port->count);
42930 dlci_get(dlci);
42931 dlci_get(dlci->gsm->dlci[0]);
42932 mux_get(dlci->gsm);
42933diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42934index 19083ef..6e34e97 100644
42935--- a/drivers/tty/n_tty.c
42936+++ b/drivers/tty/n_tty.c
42937@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42938 {
42939 *ops = tty_ldisc_N_TTY;
42940 ops->owner = NULL;
42941- ops->refcount = ops->flags = 0;
42942+ atomic_set(&ops->refcount, 0);
42943+ ops->flags = 0;
42944 }
42945 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42946diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42947index ac35c90..c47deac 100644
42948--- a/drivers/tty/pty.c
42949+++ b/drivers/tty/pty.c
42950@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
42951 panic("Couldn't register Unix98 pts driver");
42952
42953 /* Now create the /dev/ptmx special device */
42954+ pax_open_kernel();
42955 tty_default_fops(&ptmx_fops);
42956- ptmx_fops.open = ptmx_open;
42957+ *(void **)&ptmx_fops.open = ptmx_open;
42958+ pax_close_kernel();
42959
42960 cdev_init(&ptmx_cdev, &ptmx_fops);
42961 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
42962diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
42963index e42009a..566a036 100644
42964--- a/drivers/tty/rocket.c
42965+++ b/drivers/tty/rocket.c
42966@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42967 tty->driver_data = info;
42968 tty_port_tty_set(port, tty);
42969
42970- if (port->count++ == 0) {
42971+ if (atomic_inc_return(&port->count) == 1) {
42972 atomic_inc(&rp_num_ports_open);
42973
42974 #ifdef ROCKET_DEBUG_OPEN
42975@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42976 #endif
42977 }
42978 #ifdef ROCKET_DEBUG_OPEN
42979- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
42980+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
42981 #endif
42982
42983 /*
42984@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
42985 spin_unlock_irqrestore(&info->port.lock, flags);
42986 return;
42987 }
42988- if (info->port.count)
42989+ if (atomic_read(&info->port.count))
42990 atomic_dec(&rp_num_ports_open);
42991 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
42992 spin_unlock_irqrestore(&info->port.lock, flags);
42993diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
42994index 1002054..dd644a8 100644
42995--- a/drivers/tty/serial/kgdboc.c
42996+++ b/drivers/tty/serial/kgdboc.c
42997@@ -24,8 +24,9 @@
42998 #define MAX_CONFIG_LEN 40
42999
43000 static struct kgdb_io kgdboc_io_ops;
43001+static struct kgdb_io kgdboc_io_ops_console;
43002
43003-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43004+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43005 static int configured = -1;
43006
43007 static char config[MAX_CONFIG_LEN];
43008@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43009 kgdboc_unregister_kbd();
43010 if (configured == 1)
43011 kgdb_unregister_io_module(&kgdboc_io_ops);
43012+ else if (configured == 2)
43013+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43014 }
43015
43016 static int configure_kgdboc(void)
43017@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43018 int err;
43019 char *cptr = config;
43020 struct console *cons;
43021+ int is_console = 0;
43022
43023 err = kgdboc_option_setup(config);
43024 if (err || !strlen(config) || isspace(config[0]))
43025 goto noconfig;
43026
43027 err = -ENODEV;
43028- kgdboc_io_ops.is_console = 0;
43029 kgdb_tty_driver = NULL;
43030
43031 kgdboc_use_kms = 0;
43032@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43033 int idx;
43034 if (cons->device && cons->device(cons, &idx) == p &&
43035 idx == tty_line) {
43036- kgdboc_io_ops.is_console = 1;
43037+ is_console = 1;
43038 break;
43039 }
43040 cons = cons->next;
43041@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43042 kgdb_tty_line = tty_line;
43043
43044 do_register:
43045- err = kgdb_register_io_module(&kgdboc_io_ops);
43046+ if (is_console) {
43047+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43048+ configured = 2;
43049+ } else {
43050+ err = kgdb_register_io_module(&kgdboc_io_ops);
43051+ configured = 1;
43052+ }
43053 if (err)
43054 goto noconfig;
43055
43056@@ -205,8 +214,6 @@ do_register:
43057 if (err)
43058 goto nmi_con_failed;
43059
43060- configured = 1;
43061-
43062 return 0;
43063
43064 nmi_con_failed:
43065@@ -223,7 +230,7 @@ noconfig:
43066 static int __init init_kgdboc(void)
43067 {
43068 /* Already configured? */
43069- if (configured == 1)
43070+ if (configured >= 1)
43071 return 0;
43072
43073 return configure_kgdboc();
43074@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43075 if (config[len - 1] == '\n')
43076 config[len - 1] = '\0';
43077
43078- if (configured == 1)
43079+ if (configured >= 1)
43080 cleanup_kgdboc();
43081
43082 /* Go and configure with the new params. */
43083@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43084 .post_exception = kgdboc_post_exp_handler,
43085 };
43086
43087+static struct kgdb_io kgdboc_io_ops_console = {
43088+ .name = "kgdboc",
43089+ .read_char = kgdboc_get_char,
43090+ .write_char = kgdboc_put_char,
43091+ .pre_exception = kgdboc_pre_exp_handler,
43092+ .post_exception = kgdboc_post_exp_handler,
43093+ .is_console = 1
43094+};
43095+
43096 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43097 /* This is only available if kgdboc is a built in for early debugging */
43098 static int __init kgdboc_early_init(char *opt)
43099diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43100index e514b3a..c73d614 100644
43101--- a/drivers/tty/serial/samsung.c
43102+++ b/drivers/tty/serial/samsung.c
43103@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43104 }
43105 }
43106
43107+static int s3c64xx_serial_startup(struct uart_port *port);
43108 static int s3c24xx_serial_startup(struct uart_port *port)
43109 {
43110 struct s3c24xx_uart_port *ourport = to_ourport(port);
43111 int ret;
43112
43113+ /* Startup sequence is different for s3c64xx and higher SoC's */
43114+ if (s3c24xx_serial_has_interrupt_mask(port))
43115+ return s3c64xx_serial_startup(port);
43116+
43117 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43118 port->mapbase, port->membase);
43119
43120@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43121 /* setup info for port */
43122 port->dev = &platdev->dev;
43123
43124- /* Startup sequence is different for s3c64xx and higher SoC's */
43125- if (s3c24xx_serial_has_interrupt_mask(port))
43126- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43127-
43128 port->uartclk = 1;
43129
43130 if (cfg->uart_flags & UPF_CONS_FLOW) {
43131diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43132index 2c7230a..2104f16 100644
43133--- a/drivers/tty/serial/serial_core.c
43134+++ b/drivers/tty/serial/serial_core.c
43135@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
43136 uart_flush_buffer(tty);
43137 uart_shutdown(tty, state);
43138 spin_lock_irqsave(&port->lock, flags);
43139- port->count = 0;
43140+ atomic_set(&port->count, 0);
43141 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43142 spin_unlock_irqrestore(&port->lock, flags);
43143 tty_port_tty_set(port, NULL);
43144@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43145 goto end;
43146 }
43147
43148- port->count++;
43149+ atomic_inc(&port->count);
43150 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43151 retval = -ENXIO;
43152 goto err_dec_count;
43153@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43154 /*
43155 * Make sure the device is in D0 state.
43156 */
43157- if (port->count == 1)
43158+ if (atomic_read(&port->count) == 1)
43159 uart_change_pm(state, 0);
43160
43161 /*
43162@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43163 end:
43164 return retval;
43165 err_dec_count:
43166- port->count--;
43167+ atomic_inc(&port->count);
43168 mutex_unlock(&port->mutex);
43169 goto end;
43170 }
43171diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43172index 9e071f6..f30ae69 100644
43173--- a/drivers/tty/synclink.c
43174+++ b/drivers/tty/synclink.c
43175@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43176
43177 if (debug_level >= DEBUG_LEVEL_INFO)
43178 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43179- __FILE__,__LINE__, info->device_name, info->port.count);
43180+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43181
43182 if (tty_port_close_start(&info->port, tty, filp) == 0)
43183 goto cleanup;
43184@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43185 cleanup:
43186 if (debug_level >= DEBUG_LEVEL_INFO)
43187 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43188- tty->driver->name, info->port.count);
43189+ tty->driver->name, atomic_read(&info->port.count));
43190
43191 } /* end of mgsl_close() */
43192
43193@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43194
43195 mgsl_flush_buffer(tty);
43196 shutdown(info);
43197-
43198- info->port.count = 0;
43199+
43200+ atomic_set(&info->port.count, 0);
43201 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43202 info->port.tty = NULL;
43203
43204@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43205
43206 if (debug_level >= DEBUG_LEVEL_INFO)
43207 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43208- __FILE__,__LINE__, tty->driver->name, port->count );
43209+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43210
43211 spin_lock_irqsave(&info->irq_spinlock, flags);
43212 if (!tty_hung_up_p(filp)) {
43213 extra_count = true;
43214- port->count--;
43215+ atomic_dec(&port->count);
43216 }
43217 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43218 port->blocked_open++;
43219@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43220
43221 if (debug_level >= DEBUG_LEVEL_INFO)
43222 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43223- __FILE__,__LINE__, tty->driver->name, port->count );
43224+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43225
43226 tty_unlock(tty);
43227 schedule();
43228@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43229
43230 /* FIXME: Racy on hangup during close wait */
43231 if (extra_count)
43232- port->count++;
43233+ atomic_inc(&port->count);
43234 port->blocked_open--;
43235
43236 if (debug_level >= DEBUG_LEVEL_INFO)
43237 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43238- __FILE__,__LINE__, tty->driver->name, port->count );
43239+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43240
43241 if (!retval)
43242 port->flags |= ASYNC_NORMAL_ACTIVE;
43243@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43244
43245 if (debug_level >= DEBUG_LEVEL_INFO)
43246 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43247- __FILE__,__LINE__,tty->driver->name, info->port.count);
43248+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43249
43250 /* If port is closing, signal caller to try again */
43251 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43252@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43253 spin_unlock_irqrestore(&info->netlock, flags);
43254 goto cleanup;
43255 }
43256- info->port.count++;
43257+ atomic_inc(&info->port.count);
43258 spin_unlock_irqrestore(&info->netlock, flags);
43259
43260- if (info->port.count == 1) {
43261+ if (atomic_read(&info->port.count) == 1) {
43262 /* 1st open on this device, init hardware */
43263 retval = startup(info);
43264 if (retval < 0)
43265@@ -3451,8 +3451,8 @@ cleanup:
43266 if (retval) {
43267 if (tty->count == 1)
43268 info->port.tty = NULL; /* tty layer will release tty struct */
43269- if(info->port.count)
43270- info->port.count--;
43271+ if (atomic_read(&info->port.count))
43272+ atomic_dec(&info->port.count);
43273 }
43274
43275 return retval;
43276@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43277 unsigned short new_crctype;
43278
43279 /* return error if TTY interface open */
43280- if (info->port.count)
43281+ if (atomic_read(&info->port.count))
43282 return -EBUSY;
43283
43284 switch (encoding)
43285@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
43286
43287 /* arbitrate between network and tty opens */
43288 spin_lock_irqsave(&info->netlock, flags);
43289- if (info->port.count != 0 || info->netcount != 0) {
43290+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43291 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43292 spin_unlock_irqrestore(&info->netlock, flags);
43293 return -EBUSY;
43294@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43295 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43296
43297 /* return error if TTY interface open */
43298- if (info->port.count)
43299+ if (atomic_read(&info->port.count))
43300 return -EBUSY;
43301
43302 if (cmd != SIOCWANDEV)
43303diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43304index aba1e59..877ac33 100644
43305--- a/drivers/tty/synclink_gt.c
43306+++ b/drivers/tty/synclink_gt.c
43307@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43308 tty->driver_data = info;
43309 info->port.tty = tty;
43310
43311- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43312+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43313
43314 /* If port is closing, signal caller to try again */
43315 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43316@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43317 mutex_unlock(&info->port.mutex);
43318 goto cleanup;
43319 }
43320- info->port.count++;
43321+ atomic_inc(&info->port.count);
43322 spin_unlock_irqrestore(&info->netlock, flags);
43323
43324- if (info->port.count == 1) {
43325+ if (atomic_read(&info->port.count) == 1) {
43326 /* 1st open on this device, init hardware */
43327 retval = startup(info);
43328 if (retval < 0) {
43329@@ -716,8 +716,8 @@ cleanup:
43330 if (retval) {
43331 if (tty->count == 1)
43332 info->port.tty = NULL; /* tty layer will release tty struct */
43333- if(info->port.count)
43334- info->port.count--;
43335+ if(atomic_read(&info->port.count))
43336+ atomic_dec(&info->port.count);
43337 }
43338
43339 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43340@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43341
43342 if (sanity_check(info, tty->name, "close"))
43343 return;
43344- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43345+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43346
43347 if (tty_port_close_start(&info->port, tty, filp) == 0)
43348 goto cleanup;
43349@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43350 tty_port_close_end(&info->port, tty);
43351 info->port.tty = NULL;
43352 cleanup:
43353- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
43354+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
43355 }
43356
43357 static void hangup(struct tty_struct *tty)
43358@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
43359 shutdown(info);
43360
43361 spin_lock_irqsave(&info->port.lock, flags);
43362- info->port.count = 0;
43363+ atomic_set(&info->port.count, 0);
43364 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43365 info->port.tty = NULL;
43366 spin_unlock_irqrestore(&info->port.lock, flags);
43367@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43368 unsigned short new_crctype;
43369
43370 /* return error if TTY interface open */
43371- if (info->port.count)
43372+ if (atomic_read(&info->port.count))
43373 return -EBUSY;
43374
43375 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
43376@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
43377
43378 /* arbitrate between network and tty opens */
43379 spin_lock_irqsave(&info->netlock, flags);
43380- if (info->port.count != 0 || info->netcount != 0) {
43381+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43382 DBGINFO(("%s hdlc_open busy\n", dev->name));
43383 spin_unlock_irqrestore(&info->netlock, flags);
43384 return -EBUSY;
43385@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43386 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
43387
43388 /* return error if TTY interface open */
43389- if (info->port.count)
43390+ if (atomic_read(&info->port.count))
43391 return -EBUSY;
43392
43393 if (cmd != SIOCWANDEV)
43394@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43395 if (port == NULL)
43396 continue;
43397 spin_lock(&port->lock);
43398- if ((port->port.count || port->netcount) &&
43399+ if ((atomic_read(&port->port.count) || port->netcount) &&
43400 port->pending_bh && !port->bh_running &&
43401 !port->bh_requested) {
43402 DBGISR(("%s bh queued\n", port->device_name));
43403@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43404 spin_lock_irqsave(&info->lock, flags);
43405 if (!tty_hung_up_p(filp)) {
43406 extra_count = true;
43407- port->count--;
43408+ atomic_dec(&port->count);
43409 }
43410 spin_unlock_irqrestore(&info->lock, flags);
43411 port->blocked_open++;
43412@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43413 remove_wait_queue(&port->open_wait, &wait);
43414
43415 if (extra_count)
43416- port->count++;
43417+ atomic_inc(&port->count);
43418 port->blocked_open--;
43419
43420 if (!retval)
43421diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43422index fd43fb6..34704ad 100644
43423--- a/drivers/tty/synclinkmp.c
43424+++ b/drivers/tty/synclinkmp.c
43425@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43426
43427 if (debug_level >= DEBUG_LEVEL_INFO)
43428 printk("%s(%d):%s open(), old ref count = %d\n",
43429- __FILE__,__LINE__,tty->driver->name, info->port.count);
43430+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43431
43432 /* If port is closing, signal caller to try again */
43433 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43434@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43435 spin_unlock_irqrestore(&info->netlock, flags);
43436 goto cleanup;
43437 }
43438- info->port.count++;
43439+ atomic_inc(&info->port.count);
43440 spin_unlock_irqrestore(&info->netlock, flags);
43441
43442- if (info->port.count == 1) {
43443+ if (atomic_read(&info->port.count) == 1) {
43444 /* 1st open on this device, init hardware */
43445 retval = startup(info);
43446 if (retval < 0)
43447@@ -797,8 +797,8 @@ cleanup:
43448 if (retval) {
43449 if (tty->count == 1)
43450 info->port.tty = NULL; /* tty layer will release tty struct */
43451- if(info->port.count)
43452- info->port.count--;
43453+ if(atomic_read(&info->port.count))
43454+ atomic_dec(&info->port.count);
43455 }
43456
43457 return retval;
43458@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43459
43460 if (debug_level >= DEBUG_LEVEL_INFO)
43461 printk("%s(%d):%s close() entry, count=%d\n",
43462- __FILE__,__LINE__, info->device_name, info->port.count);
43463+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43464
43465 if (tty_port_close_start(&info->port, tty, filp) == 0)
43466 goto cleanup;
43467@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43468 cleanup:
43469 if (debug_level >= DEBUG_LEVEL_INFO)
43470 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43471- tty->driver->name, info->port.count);
43472+ tty->driver->name, atomic_read(&info->port.count));
43473 }
43474
43475 /* Called by tty_hangup() when a hangup is signaled.
43476@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
43477 shutdown(info);
43478
43479 spin_lock_irqsave(&info->port.lock, flags);
43480- info->port.count = 0;
43481+ atomic_set(&info->port.count, 0);
43482 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43483 info->port.tty = NULL;
43484 spin_unlock_irqrestore(&info->port.lock, flags);
43485@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43486 unsigned short new_crctype;
43487
43488 /* return error if TTY interface open */
43489- if (info->port.count)
43490+ if (atomic_read(&info->port.count))
43491 return -EBUSY;
43492
43493 switch (encoding)
43494@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
43495
43496 /* arbitrate between network and tty opens */
43497 spin_lock_irqsave(&info->netlock, flags);
43498- if (info->port.count != 0 || info->netcount != 0) {
43499+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43500 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43501 spin_unlock_irqrestore(&info->netlock, flags);
43502 return -EBUSY;
43503@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43504 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43505
43506 /* return error if TTY interface open */
43507- if (info->port.count)
43508+ if (atomic_read(&info->port.count))
43509 return -EBUSY;
43510
43511 if (cmd != SIOCWANDEV)
43512@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43513 * do not request bottom half processing if the
43514 * device is not open in a normal mode.
43515 */
43516- if ( port && (port->port.count || port->netcount) &&
43517+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43518 port->pending_bh && !port->bh_running &&
43519 !port->bh_requested ) {
43520 if ( debug_level >= DEBUG_LEVEL_ISR )
43521@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43522
43523 if (debug_level >= DEBUG_LEVEL_INFO)
43524 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43525- __FILE__,__LINE__, tty->driver->name, port->count );
43526+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43527
43528 spin_lock_irqsave(&info->lock, flags);
43529 if (!tty_hung_up_p(filp)) {
43530 extra_count = true;
43531- port->count--;
43532+ atomic_dec(&port->count);
43533 }
43534 spin_unlock_irqrestore(&info->lock, flags);
43535 port->blocked_open++;
43536@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43537
43538 if (debug_level >= DEBUG_LEVEL_INFO)
43539 printk("%s(%d):%s block_til_ready() count=%d\n",
43540- __FILE__,__LINE__, tty->driver->name, port->count );
43541+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43542
43543 tty_unlock(tty);
43544 schedule();
43545@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43546 remove_wait_queue(&port->open_wait, &wait);
43547
43548 if (extra_count)
43549- port->count++;
43550+ atomic_inc(&port->count);
43551 port->blocked_open--;
43552
43553 if (debug_level >= DEBUG_LEVEL_INFO)
43554 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43555- __FILE__,__LINE__, tty->driver->name, port->count );
43556+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43557
43558 if (!retval)
43559 port->flags |= ASYNC_NORMAL_ACTIVE;
43560diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43561index b3c4a25..723916f 100644
43562--- a/drivers/tty/sysrq.c
43563+++ b/drivers/tty/sysrq.c
43564@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43565 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43566 size_t count, loff_t *ppos)
43567 {
43568- if (count) {
43569+ if (count && capable(CAP_SYS_ADMIN)) {
43570 char c;
43571
43572 if (get_user(c, buf))
43573diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43574index da9fde8..c07975f 100644
43575--- a/drivers/tty/tty_io.c
43576+++ b/drivers/tty/tty_io.c
43577@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43578
43579 void tty_default_fops(struct file_operations *fops)
43580 {
43581- *fops = tty_fops;
43582+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43583 }
43584
43585 /*
43586diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43587index c578229..45aa9ee 100644
43588--- a/drivers/tty/tty_ldisc.c
43589+++ b/drivers/tty/tty_ldisc.c
43590@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43591 if (atomic_dec_and_test(&ld->users)) {
43592 struct tty_ldisc_ops *ldo = ld->ops;
43593
43594- ldo->refcount--;
43595+ atomic_dec(&ldo->refcount);
43596 module_put(ldo->owner);
43597 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43598
43599@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43600 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43601 tty_ldiscs[disc] = new_ldisc;
43602 new_ldisc->num = disc;
43603- new_ldisc->refcount = 0;
43604+ atomic_set(&new_ldisc->refcount, 0);
43605 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43606
43607 return ret;
43608@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43609 return -EINVAL;
43610
43611 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43612- if (tty_ldiscs[disc]->refcount)
43613+ if (atomic_read(&tty_ldiscs[disc]->refcount))
43614 ret = -EBUSY;
43615 else
43616 tty_ldiscs[disc] = NULL;
43617@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43618 if (ldops) {
43619 ret = ERR_PTR(-EAGAIN);
43620 if (try_module_get(ldops->owner)) {
43621- ldops->refcount++;
43622+ atomic_inc(&ldops->refcount);
43623 ret = ldops;
43624 }
43625 }
43626@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43627 unsigned long flags;
43628
43629 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43630- ldops->refcount--;
43631+ atomic_dec(&ldops->refcount);
43632 module_put(ldops->owner);
43633 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43634 }
43635diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43636index b7ff59d..7c6105e 100644
43637--- a/drivers/tty/tty_port.c
43638+++ b/drivers/tty/tty_port.c
43639@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43640 unsigned long flags;
43641
43642 spin_lock_irqsave(&port->lock, flags);
43643- port->count = 0;
43644+ atomic_set(&port->count, 0);
43645 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43646 if (port->tty) {
43647 set_bit(TTY_IO_ERROR, &port->tty->flags);
43648@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43649 /* The port lock protects the port counts */
43650 spin_lock_irqsave(&port->lock, flags);
43651 if (!tty_hung_up_p(filp))
43652- port->count--;
43653+ atomic_dec(&port->count);
43654 port->blocked_open++;
43655 spin_unlock_irqrestore(&port->lock, flags);
43656
43657@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43658 we must not mess that up further */
43659 spin_lock_irqsave(&port->lock, flags);
43660 if (!tty_hung_up_p(filp))
43661- port->count++;
43662+ atomic_inc(&port->count);
43663 port->blocked_open--;
43664 if (retval == 0)
43665 port->flags |= ASYNC_NORMAL_ACTIVE;
43666@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43667 return 0;
43668 }
43669
43670- if (tty->count == 1 && port->count != 1) {
43671+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
43672 printk(KERN_WARNING
43673 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43674- port->count);
43675- port->count = 1;
43676+ atomic_read(&port->count));
43677+ atomic_set(&port->count, 1);
43678 }
43679- if (--port->count < 0) {
43680+ if (atomic_dec_return(&port->count) < 0) {
43681 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43682- port->count);
43683- port->count = 0;
43684+ atomic_read(&port->count));
43685+ atomic_set(&port->count, 0);
43686 }
43687
43688- if (port->count) {
43689+ if (atomic_read(&port->count)) {
43690 spin_unlock_irqrestore(&port->lock, flags);
43691 if (port->ops->drop)
43692 port->ops->drop(port);
43693@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43694 {
43695 spin_lock_irq(&port->lock);
43696 if (!tty_hung_up_p(filp))
43697- ++port->count;
43698+ atomic_inc(&port->count);
43699 spin_unlock_irq(&port->lock);
43700 tty_port_tty_set(port, tty);
43701
43702diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43703index 681765b..d3ccdf2 100644
43704--- a/drivers/tty/vt/keyboard.c
43705+++ b/drivers/tty/vt/keyboard.c
43706@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43707 kbd->kbdmode == VC_OFF) &&
43708 value != KVAL(K_SAK))
43709 return; /* SAK is allowed even in raw mode */
43710+
43711+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43712+ {
43713+ void *func = fn_handler[value];
43714+ if (func == fn_show_state || func == fn_show_ptregs ||
43715+ func == fn_show_mem)
43716+ return;
43717+ }
43718+#endif
43719+
43720 fn_handler[value](vc);
43721 }
43722
43723@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43724 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43725 return -EFAULT;
43726
43727- if (!capable(CAP_SYS_TTY_CONFIG))
43728- perm = 0;
43729-
43730 switch (cmd) {
43731 case KDGKBENT:
43732 /* Ensure another thread doesn't free it under us */
43733@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43734 spin_unlock_irqrestore(&kbd_event_lock, flags);
43735 return put_user(val, &user_kbe->kb_value);
43736 case KDSKBENT:
43737+ if (!capable(CAP_SYS_TTY_CONFIG))
43738+ perm = 0;
43739+
43740 if (!perm)
43741 return -EPERM;
43742 if (!i && v == K_NOSUCHMAP) {
43743@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43744 int i, j, k;
43745 int ret;
43746
43747- if (!capable(CAP_SYS_TTY_CONFIG))
43748- perm = 0;
43749-
43750 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43751 if (!kbs) {
43752 ret = -ENOMEM;
43753@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43754 kfree(kbs);
43755 return ((p && *p) ? -EOVERFLOW : 0);
43756 case KDSKBSENT:
43757+ if (!capable(CAP_SYS_TTY_CONFIG))
43758+ perm = 0;
43759+
43760 if (!perm) {
43761 ret = -EPERM;
43762 goto reterr;
43763diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43764index 5110f36..8dc0a74 100644
43765--- a/drivers/uio/uio.c
43766+++ b/drivers/uio/uio.c
43767@@ -25,6 +25,7 @@
43768 #include <linux/kobject.h>
43769 #include <linux/cdev.h>
43770 #include <linux/uio_driver.h>
43771+#include <asm/local.h>
43772
43773 #define UIO_MAX_DEVICES (1U << MINORBITS)
43774
43775@@ -32,10 +33,10 @@ struct uio_device {
43776 struct module *owner;
43777 struct device *dev;
43778 int minor;
43779- atomic_t event;
43780+ atomic_unchecked_t event;
43781 struct fasync_struct *async_queue;
43782 wait_queue_head_t wait;
43783- int vma_count;
43784+ local_t vma_count;
43785 struct uio_info *info;
43786 struct kobject *map_dir;
43787 struct kobject *portio_dir;
43788@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43789 struct device_attribute *attr, char *buf)
43790 {
43791 struct uio_device *idev = dev_get_drvdata(dev);
43792- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43793+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43794 }
43795
43796 static struct device_attribute uio_class_attributes[] = {
43797@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43798 {
43799 struct uio_device *idev = info->uio_dev;
43800
43801- atomic_inc(&idev->event);
43802+ atomic_inc_unchecked(&idev->event);
43803 wake_up_interruptible(&idev->wait);
43804 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43805 }
43806@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43807 }
43808
43809 listener->dev = idev;
43810- listener->event_count = atomic_read(&idev->event);
43811+ listener->event_count = atomic_read_unchecked(&idev->event);
43812 filep->private_data = listener;
43813
43814 if (idev->info->open) {
43815@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43816 return -EIO;
43817
43818 poll_wait(filep, &idev->wait, wait);
43819- if (listener->event_count != atomic_read(&idev->event))
43820+ if (listener->event_count != atomic_read_unchecked(&idev->event))
43821 return POLLIN | POLLRDNORM;
43822 return 0;
43823 }
43824@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43825 do {
43826 set_current_state(TASK_INTERRUPTIBLE);
43827
43828- event_count = atomic_read(&idev->event);
43829+ event_count = atomic_read_unchecked(&idev->event);
43830 if (event_count != listener->event_count) {
43831 if (copy_to_user(buf, &event_count, count))
43832 retval = -EFAULT;
43833@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43834 static void uio_vma_open(struct vm_area_struct *vma)
43835 {
43836 struct uio_device *idev = vma->vm_private_data;
43837- idev->vma_count++;
43838+ local_inc(&idev->vma_count);
43839 }
43840
43841 static void uio_vma_close(struct vm_area_struct *vma)
43842 {
43843 struct uio_device *idev = vma->vm_private_data;
43844- idev->vma_count--;
43845+ local_dec(&idev->vma_count);
43846 }
43847
43848 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43849@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43850 idev->owner = owner;
43851 idev->info = info;
43852 init_waitqueue_head(&idev->wait);
43853- atomic_set(&idev->event, 0);
43854+ atomic_set_unchecked(&idev->event, 0);
43855
43856 ret = uio_get_minor(idev);
43857 if (ret)
43858diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43859index b7eb86a..36d28af 100644
43860--- a/drivers/usb/atm/cxacru.c
43861+++ b/drivers/usb/atm/cxacru.c
43862@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43863 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43864 if (ret < 2)
43865 return -EINVAL;
43866- if (index < 0 || index > 0x7f)
43867+ if (index > 0x7f)
43868 return -EINVAL;
43869 pos += tmp;
43870
43871diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43872index 35f10bf..6a38a0b 100644
43873--- a/drivers/usb/atm/usbatm.c
43874+++ b/drivers/usb/atm/usbatm.c
43875@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43876 if (printk_ratelimit())
43877 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43878 __func__, vpi, vci);
43879- atomic_inc(&vcc->stats->rx_err);
43880+ atomic_inc_unchecked(&vcc->stats->rx_err);
43881 return;
43882 }
43883
43884@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43885 if (length > ATM_MAX_AAL5_PDU) {
43886 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43887 __func__, length, vcc);
43888- atomic_inc(&vcc->stats->rx_err);
43889+ atomic_inc_unchecked(&vcc->stats->rx_err);
43890 goto out;
43891 }
43892
43893@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43894 if (sarb->len < pdu_length) {
43895 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43896 __func__, pdu_length, sarb->len, vcc);
43897- atomic_inc(&vcc->stats->rx_err);
43898+ atomic_inc_unchecked(&vcc->stats->rx_err);
43899 goto out;
43900 }
43901
43902 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43903 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43904 __func__, vcc);
43905- atomic_inc(&vcc->stats->rx_err);
43906+ atomic_inc_unchecked(&vcc->stats->rx_err);
43907 goto out;
43908 }
43909
43910@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43911 if (printk_ratelimit())
43912 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43913 __func__, length);
43914- atomic_inc(&vcc->stats->rx_drop);
43915+ atomic_inc_unchecked(&vcc->stats->rx_drop);
43916 goto out;
43917 }
43918
43919@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43920
43921 vcc->push(vcc, skb);
43922
43923- atomic_inc(&vcc->stats->rx);
43924+ atomic_inc_unchecked(&vcc->stats->rx);
43925 out:
43926 skb_trim(sarb, 0);
43927 }
43928@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43929 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43930
43931 usbatm_pop(vcc, skb);
43932- atomic_inc(&vcc->stats->tx);
43933+ atomic_inc_unchecked(&vcc->stats->tx);
43934
43935 skb = skb_dequeue(&instance->sndqueue);
43936 }
43937@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43938 if (!left--)
43939 return sprintf(page,
43940 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43941- atomic_read(&atm_dev->stats.aal5.tx),
43942- atomic_read(&atm_dev->stats.aal5.tx_err),
43943- atomic_read(&atm_dev->stats.aal5.rx),
43944- atomic_read(&atm_dev->stats.aal5.rx_err),
43945- atomic_read(&atm_dev->stats.aal5.rx_drop));
43946+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43947+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43948+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43949+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43950+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43951
43952 if (!left--) {
43953 if (instance->disconnected)
43954diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43955index cbacea9..246cccd 100644
43956--- a/drivers/usb/core/devices.c
43957+++ b/drivers/usb/core/devices.c
43958@@ -126,7 +126,7 @@ static const char format_endpt[] =
43959 * time it gets called.
43960 */
43961 static struct device_connect_event {
43962- atomic_t count;
43963+ atomic_unchecked_t count;
43964 wait_queue_head_t wait;
43965 } device_event = {
43966 .count = ATOMIC_INIT(1),
43967@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
43968
43969 void usbfs_conn_disc_event(void)
43970 {
43971- atomic_add(2, &device_event.count);
43972+ atomic_add_unchecked(2, &device_event.count);
43973 wake_up(&device_event.wait);
43974 }
43975
43976@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
43977
43978 poll_wait(file, &device_event.wait, wait);
43979
43980- event_count = atomic_read(&device_event.count);
43981+ event_count = atomic_read_unchecked(&device_event.count);
43982 if (file->f_version != event_count) {
43983 file->f_version = event_count;
43984 return POLLIN | POLLRDNORM;
43985diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
43986index 8e64adf..9a33a3c 100644
43987--- a/drivers/usb/core/hcd.c
43988+++ b/drivers/usb/core/hcd.c
43989@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43990 */
43991 usb_get_urb(urb);
43992 atomic_inc(&urb->use_count);
43993- atomic_inc(&urb->dev->urbnum);
43994+ atomic_inc_unchecked(&urb->dev->urbnum);
43995 usbmon_urb_submit(&hcd->self, urb);
43996
43997 /* NOTE requirements on root-hub callers (usbfs and the hub
43998@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43999 urb->hcpriv = NULL;
44000 INIT_LIST_HEAD(&urb->urb_list);
44001 atomic_dec(&urb->use_count);
44002- atomic_dec(&urb->dev->urbnum);
44003+ atomic_dec_unchecked(&urb->dev->urbnum);
44004 if (atomic_read(&urb->reject))
44005 wake_up(&usb_kill_urb_queue);
44006 usb_put_urb(urb);
44007diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44008index 131f736..99004c3 100644
44009--- a/drivers/usb/core/message.c
44010+++ b/drivers/usb/core/message.c
44011@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44012 * method can wait for it to complete. Since you don't have a handle on the
44013 * URB used, you can't cancel the request.
44014 */
44015-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44016+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44017 __u8 requesttype, __u16 value, __u16 index, void *data,
44018 __u16 size, int timeout)
44019 {
44020diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44021index 818e4a0..0fc9589 100644
44022--- a/drivers/usb/core/sysfs.c
44023+++ b/drivers/usb/core/sysfs.c
44024@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44025 struct usb_device *udev;
44026
44027 udev = to_usb_device(dev);
44028- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44029+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44030 }
44031 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44032
44033diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44034index f81b925..78d22ec 100644
44035--- a/drivers/usb/core/usb.c
44036+++ b/drivers/usb/core/usb.c
44037@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44038 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44039 dev->state = USB_STATE_ATTACHED;
44040 dev->lpm_disable_count = 1;
44041- atomic_set(&dev->urbnum, 0);
44042+ atomic_set_unchecked(&dev->urbnum, 0);
44043
44044 INIT_LIST_HEAD(&dev->ep0.urb_list);
44045 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44046diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44047index 5e29dde..eca992f 100644
44048--- a/drivers/usb/early/ehci-dbgp.c
44049+++ b/drivers/usb/early/ehci-dbgp.c
44050@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44051
44052 #ifdef CONFIG_KGDB
44053 static struct kgdb_io kgdbdbgp_io_ops;
44054-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44055+static struct kgdb_io kgdbdbgp_io_ops_console;
44056+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44057 #else
44058 #define dbgp_kgdb_mode (0)
44059 #endif
44060@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44061 .write_char = kgdbdbgp_write_char,
44062 };
44063
44064+static struct kgdb_io kgdbdbgp_io_ops_console = {
44065+ .name = "kgdbdbgp",
44066+ .read_char = kgdbdbgp_read_char,
44067+ .write_char = kgdbdbgp_write_char,
44068+ .is_console = 1
44069+};
44070+
44071 static int kgdbdbgp_wait_time;
44072
44073 static int __init kgdbdbgp_parse_config(char *str)
44074@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44075 ptr++;
44076 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44077 }
44078- kgdb_register_io_module(&kgdbdbgp_io_ops);
44079- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44080+ if (early_dbgp_console.index != -1)
44081+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44082+ else
44083+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44084
44085 return 0;
44086 }
44087diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44088index 598dcc1..032dd4f 100644
44089--- a/drivers/usb/gadget/u_serial.c
44090+++ b/drivers/usb/gadget/u_serial.c
44091@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44092 spin_lock_irq(&port->port_lock);
44093
44094 /* already open? Great. */
44095- if (port->port.count) {
44096+ if (atomic_read(&port->port.count)) {
44097 status = 0;
44098- port->port.count++;
44099+ atomic_inc(&port->port.count);
44100
44101 /* currently opening/closing? wait ... */
44102 } else if (port->openclose) {
44103@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44104 tty->driver_data = port;
44105 port->port.tty = tty;
44106
44107- port->port.count = 1;
44108+ atomic_set(&port->port.count, 1);
44109 port->openclose = false;
44110
44111 /* if connected, start the I/O stream */
44112@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44113
44114 spin_lock_irq(&port->port_lock);
44115
44116- if (port->port.count != 1) {
44117- if (port->port.count == 0)
44118+ if (atomic_read(&port->port.count) != 1) {
44119+ if (atomic_read(&port->port.count) == 0)
44120 WARN_ON(1);
44121 else
44122- --port->port.count;
44123+ atomic_dec(&port->port.count);
44124 goto exit;
44125 }
44126
44127@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44128 * and sleep if necessary
44129 */
44130 port->openclose = true;
44131- port->port.count = 0;
44132+ atomic_set(&port->port.count, 0);
44133
44134 gser = port->port_usb;
44135 if (gser && gser->disconnect)
44136@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44137 int cond;
44138
44139 spin_lock_irq(&port->port_lock);
44140- cond = (port->port.count == 0) && !port->openclose;
44141+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44142 spin_unlock_irq(&port->port_lock);
44143 return cond;
44144 }
44145@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44146 /* if it's already open, start I/O ... and notify the serial
44147 * protocol about open/close status (connect/disconnect).
44148 */
44149- if (port->port.count) {
44150+ if (atomic_read(&port->port.count)) {
44151 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44152 gs_start_io(port);
44153 if (gser->connect)
44154@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44155
44156 port->port_usb = NULL;
44157 gser->ioport = NULL;
44158- if (port->port.count > 0 || port->openclose) {
44159+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44160 wake_up_interruptible(&port->drain_wait);
44161 if (port->port.tty)
44162 tty_hangup(port->port.tty);
44163@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44164
44165 /* finally, free any unused/unusable I/O buffers */
44166 spin_lock_irqsave(&port->port_lock, flags);
44167- if (port->port.count == 0 && !port->openclose)
44168+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44169 gs_buf_free(&port->port_write_buf);
44170 gs_free_requests(gser->out, &port->read_pool, NULL);
44171 gs_free_requests(gser->out, &port->read_queue, NULL);
44172diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44173index 5f3bcd3..bfca43f 100644
44174--- a/drivers/usb/serial/console.c
44175+++ b/drivers/usb/serial/console.c
44176@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44177
44178 info->port = port;
44179
44180- ++port->port.count;
44181+ atomic_inc(&port->port.count);
44182 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44183 if (serial->type->set_termios) {
44184 /*
44185@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44186 }
44187 /* Now that any required fake tty operations are completed restore
44188 * the tty port count */
44189- --port->port.count;
44190+ atomic_dec(&port->port.count);
44191 /* The console is special in terms of closing the device so
44192 * indicate this port is now acting as a system console. */
44193 port->port.console = 1;
44194@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44195 free_tty:
44196 kfree(tty);
44197 reset_open_count:
44198- port->port.count = 0;
44199+ atomic_set(&port->port.count, 0);
44200 usb_autopm_put_interface(serial->interface);
44201 error_get_interface:
44202 usb_serial_put(serial);
44203diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44204index 75f70f0..d467e1a 100644
44205--- a/drivers/usb/storage/usb.h
44206+++ b/drivers/usb/storage/usb.h
44207@@ -63,7 +63,7 @@ struct us_unusual_dev {
44208 __u8 useProtocol;
44209 __u8 useTransport;
44210 int (*initFunction)(struct us_data *);
44211-};
44212+} __do_const;
44213
44214
44215 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44216diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44217index d6bea3e..60b250e 100644
44218--- a/drivers/usb/wusbcore/wa-hc.h
44219+++ b/drivers/usb/wusbcore/wa-hc.h
44220@@ -192,7 +192,7 @@ struct wahc {
44221 struct list_head xfer_delayed_list;
44222 spinlock_t xfer_list_lock;
44223 struct work_struct xfer_work;
44224- atomic_t xfer_id_count;
44225+ atomic_unchecked_t xfer_id_count;
44226 };
44227
44228
44229@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44230 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44231 spin_lock_init(&wa->xfer_list_lock);
44232 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44233- atomic_set(&wa->xfer_id_count, 1);
44234+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44235 }
44236
44237 /**
44238diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44239index 57c01ab..8a05959 100644
44240--- a/drivers/usb/wusbcore/wa-xfer.c
44241+++ b/drivers/usb/wusbcore/wa-xfer.c
44242@@ -296,7 +296,7 @@ out:
44243 */
44244 static void wa_xfer_id_init(struct wa_xfer *xfer)
44245 {
44246- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44247+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44248 }
44249
44250 /*
44251diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44252index 8c55011..eed4ae1a 100644
44253--- a/drivers/video/aty/aty128fb.c
44254+++ b/drivers/video/aty/aty128fb.c
44255@@ -149,7 +149,7 @@ enum {
44256 };
44257
44258 /* Must match above enum */
44259-static char * const r128_family[] = {
44260+static const char * const r128_family[] = {
44261 "AGP",
44262 "PCI",
44263 "PRO AGP",
44264diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44265index 4f27fdc..d3537e6 100644
44266--- a/drivers/video/aty/atyfb_base.c
44267+++ b/drivers/video/aty/atyfb_base.c
44268@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44269 par->accel_flags = var->accel_flags; /* hack */
44270
44271 if (var->accel_flags) {
44272- info->fbops->fb_sync = atyfb_sync;
44273+ pax_open_kernel();
44274+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44275+ pax_close_kernel();
44276 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44277 } else {
44278- info->fbops->fb_sync = NULL;
44279+ pax_open_kernel();
44280+ *(void **)&info->fbops->fb_sync = NULL;
44281+ pax_close_kernel();
44282 info->flags |= FBINFO_HWACCEL_DISABLED;
44283 }
44284
44285diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44286index 95ec042..e6affdd 100644
44287--- a/drivers/video/aty/mach64_cursor.c
44288+++ b/drivers/video/aty/mach64_cursor.c
44289@@ -7,6 +7,7 @@
44290 #include <linux/string.h>
44291
44292 #include <asm/io.h>
44293+#include <asm/pgtable.h>
44294
44295 #ifdef __sparc__
44296 #include <asm/fbio.h>
44297@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44298 info->sprite.buf_align = 16; /* and 64 lines tall. */
44299 info->sprite.flags = FB_PIXMAP_IO;
44300
44301- info->fbops->fb_cursor = atyfb_cursor;
44302+ pax_open_kernel();
44303+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44304+ pax_close_kernel();
44305
44306 return 0;
44307 }
44308diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44309index 6c5ed6b..b727c88 100644
44310--- a/drivers/video/backlight/kb3886_bl.c
44311+++ b/drivers/video/backlight/kb3886_bl.c
44312@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44313 static unsigned long kb3886bl_flags;
44314 #define KB3886BL_SUSPENDED 0x01
44315
44316-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44317+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44318 {
44319 .ident = "Sahara Touch-iT",
44320 .matches = {
44321diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44322index 88cad6b..dd746c7 100644
44323--- a/drivers/video/fb_defio.c
44324+++ b/drivers/video/fb_defio.c
44325@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44326
44327 BUG_ON(!fbdefio);
44328 mutex_init(&fbdefio->lock);
44329- info->fbops->fb_mmap = fb_deferred_io_mmap;
44330+ pax_open_kernel();
44331+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44332+ pax_close_kernel();
44333 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
44334 INIT_LIST_HEAD(&fbdefio->pagelist);
44335 if (fbdefio->delay == 0) /* set a default of 1 s */
44336@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
44337 page->mapping = NULL;
44338 }
44339
44340- info->fbops->fb_mmap = NULL;
44341+ *(void **)&info->fbops->fb_mmap = NULL;
44342 mutex_destroy(&fbdefio->lock);
44343 }
44344 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
44345diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
44346index 5c3960d..15cf8fc 100644
44347--- a/drivers/video/fbcmap.c
44348+++ b/drivers/video/fbcmap.c
44349@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
44350 rc = -ENODEV;
44351 goto out;
44352 }
44353- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
44354- !info->fbops->fb_setcmap)) {
44355+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
44356 rc = -EINVAL;
44357 goto out1;
44358 }
44359diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
44360index dc61c12..e29796e 100644
44361--- a/drivers/video/fbmem.c
44362+++ b/drivers/video/fbmem.c
44363@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44364 image->dx += image->width + 8;
44365 }
44366 } else if (rotate == FB_ROTATE_UD) {
44367- for (x = 0; x < num && image->dx >= 0; x++) {
44368+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
44369 info->fbops->fb_imageblit(info, image);
44370 image->dx -= image->width + 8;
44371 }
44372@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44373 image->dy += image->height + 8;
44374 }
44375 } else if (rotate == FB_ROTATE_CCW) {
44376- for (x = 0; x < num && image->dy >= 0; x++) {
44377+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
44378 info->fbops->fb_imageblit(info, image);
44379 image->dy -= image->height + 8;
44380 }
44381@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
44382 return -EFAULT;
44383 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
44384 return -EINVAL;
44385- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
44386+ if (con2fb.framebuffer >= FB_MAX)
44387 return -EINVAL;
44388 if (!registered_fb[con2fb.framebuffer])
44389 request_module("fb%d", con2fb.framebuffer);
44390diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
44391index 7672d2e..b56437f 100644
44392--- a/drivers/video/i810/i810_accel.c
44393+++ b/drivers/video/i810/i810_accel.c
44394@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
44395 }
44396 }
44397 printk("ringbuffer lockup!!!\n");
44398+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
44399 i810_report_error(mmio);
44400 par->dev_flags |= LOCKUP;
44401 info->pixmap.scan_align = 1;
44402diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
44403index 3c14e43..eafa544 100644
44404--- a/drivers/video/logo/logo_linux_clut224.ppm
44405+++ b/drivers/video/logo/logo_linux_clut224.ppm
44406@@ -1,1604 +1,1123 @@
44407 P3
44408-# Standard 224-color Linux logo
44409 80 80
44410 255
44411- 0 0 0 0 0 0 0 0 0 0 0 0
44412- 0 0 0 0 0 0 0 0 0 0 0 0
44413- 0 0 0 0 0 0 0 0 0 0 0 0
44414- 0 0 0 0 0 0 0 0 0 0 0 0
44415- 0 0 0 0 0 0 0 0 0 0 0 0
44416- 0 0 0 0 0 0 0 0 0 0 0 0
44417- 0 0 0 0 0 0 0 0 0 0 0 0
44418- 0 0 0 0 0 0 0 0 0 0 0 0
44419- 0 0 0 0 0 0 0 0 0 0 0 0
44420- 6 6 6 6 6 6 10 10 10 10 10 10
44421- 10 10 10 6 6 6 6 6 6 6 6 6
44422- 0 0 0 0 0 0 0 0 0 0 0 0
44423- 0 0 0 0 0 0 0 0 0 0 0 0
44424- 0 0 0 0 0 0 0 0 0 0 0 0
44425- 0 0 0 0 0 0 0 0 0 0 0 0
44426- 0 0 0 0 0 0 0 0 0 0 0 0
44427- 0 0 0 0 0 0 0 0 0 0 0 0
44428- 0 0 0 0 0 0 0 0 0 0 0 0
44429- 0 0 0 0 0 0 0 0 0 0 0 0
44430- 0 0 0 0 0 0 0 0 0 0 0 0
44431- 0 0 0 0 0 0 0 0 0 0 0 0
44432- 0 0 0 0 0 0 0 0 0 0 0 0
44433- 0 0 0 0 0 0 0 0 0 0 0 0
44434- 0 0 0 0 0 0 0 0 0 0 0 0
44435- 0 0 0 0 0 0 0 0 0 0 0 0
44436- 0 0 0 0 0 0 0 0 0 0 0 0
44437- 0 0 0 0 0 0 0 0 0 0 0 0
44438- 0 0 0 0 0 0 0 0 0 0 0 0
44439- 0 0 0 6 6 6 10 10 10 14 14 14
44440- 22 22 22 26 26 26 30 30 30 34 34 34
44441- 30 30 30 30 30 30 26 26 26 18 18 18
44442- 14 14 14 10 10 10 6 6 6 0 0 0
44443- 0 0 0 0 0 0 0 0 0 0 0 0
44444- 0 0 0 0 0 0 0 0 0 0 0 0
44445- 0 0 0 0 0 0 0 0 0 0 0 0
44446- 0 0 0 0 0 0 0 0 0 0 0 0
44447- 0 0 0 0 0 0 0 0 0 0 0 0
44448- 0 0 0 0 0 0 0 0 0 0 0 0
44449- 0 0 0 0 0 0 0 0 0 0 0 0
44450- 0 0 0 0 0 0 0 0 0 0 0 0
44451- 0 0 0 0 0 0 0 0 0 0 0 0
44452- 0 0 0 0 0 1 0 0 1 0 0 0
44453- 0 0 0 0 0 0 0 0 0 0 0 0
44454- 0 0 0 0 0 0 0 0 0 0 0 0
44455- 0 0 0 0 0 0 0 0 0 0 0 0
44456- 0 0 0 0 0 0 0 0 0 0 0 0
44457- 0 0 0 0 0 0 0 0 0 0 0 0
44458- 0 0 0 0 0 0 0 0 0 0 0 0
44459- 6 6 6 14 14 14 26 26 26 42 42 42
44460- 54 54 54 66 66 66 78 78 78 78 78 78
44461- 78 78 78 74 74 74 66 66 66 54 54 54
44462- 42 42 42 26 26 26 18 18 18 10 10 10
44463- 6 6 6 0 0 0 0 0 0 0 0 0
44464- 0 0 0 0 0 0 0 0 0 0 0 0
44465- 0 0 0 0 0 0 0 0 0 0 0 0
44466- 0 0 0 0 0 0 0 0 0 0 0 0
44467- 0 0 0 0 0 0 0 0 0 0 0 0
44468- 0 0 0 0 0 0 0 0 0 0 0 0
44469- 0 0 0 0 0 0 0 0 0 0 0 0
44470- 0 0 0 0 0 0 0 0 0 0 0 0
44471- 0 0 0 0 0 0 0 0 0 0 0 0
44472- 0 0 1 0 0 0 0 0 0 0 0 0
44473- 0 0 0 0 0 0 0 0 0 0 0 0
44474- 0 0 0 0 0 0 0 0 0 0 0 0
44475- 0 0 0 0 0 0 0 0 0 0 0 0
44476- 0 0 0 0 0 0 0 0 0 0 0 0
44477- 0 0 0 0 0 0 0 0 0 0 0 0
44478- 0 0 0 0 0 0 0 0 0 10 10 10
44479- 22 22 22 42 42 42 66 66 66 86 86 86
44480- 66 66 66 38 38 38 38 38 38 22 22 22
44481- 26 26 26 34 34 34 54 54 54 66 66 66
44482- 86 86 86 70 70 70 46 46 46 26 26 26
44483- 14 14 14 6 6 6 0 0 0 0 0 0
44484- 0 0 0 0 0 0 0 0 0 0 0 0
44485- 0 0 0 0 0 0 0 0 0 0 0 0
44486- 0 0 0 0 0 0 0 0 0 0 0 0
44487- 0 0 0 0 0 0 0 0 0 0 0 0
44488- 0 0 0 0 0 0 0 0 0 0 0 0
44489- 0 0 0 0 0 0 0 0 0 0 0 0
44490- 0 0 0 0 0 0 0 0 0 0 0 0
44491- 0 0 0 0 0 0 0 0 0 0 0 0
44492- 0 0 1 0 0 1 0 0 1 0 0 0
44493- 0 0 0 0 0 0 0 0 0 0 0 0
44494- 0 0 0 0 0 0 0 0 0 0 0 0
44495- 0 0 0 0 0 0 0 0 0 0 0 0
44496- 0 0 0 0 0 0 0 0 0 0 0 0
44497- 0 0 0 0 0 0 0 0 0 0 0 0
44498- 0 0 0 0 0 0 10 10 10 26 26 26
44499- 50 50 50 82 82 82 58 58 58 6 6 6
44500- 2 2 6 2 2 6 2 2 6 2 2 6
44501- 2 2 6 2 2 6 2 2 6 2 2 6
44502- 6 6 6 54 54 54 86 86 86 66 66 66
44503- 38 38 38 18 18 18 6 6 6 0 0 0
44504- 0 0 0 0 0 0 0 0 0 0 0 0
44505- 0 0 0 0 0 0 0 0 0 0 0 0
44506- 0 0 0 0 0 0 0 0 0 0 0 0
44507- 0 0 0 0 0 0 0 0 0 0 0 0
44508- 0 0 0 0 0 0 0 0 0 0 0 0
44509- 0 0 0 0 0 0 0 0 0 0 0 0
44510- 0 0 0 0 0 0 0 0 0 0 0 0
44511- 0 0 0 0 0 0 0 0 0 0 0 0
44512- 0 0 0 0 0 0 0 0 0 0 0 0
44513- 0 0 0 0 0 0 0 0 0 0 0 0
44514- 0 0 0 0 0 0 0 0 0 0 0 0
44515- 0 0 0 0 0 0 0 0 0 0 0 0
44516- 0 0 0 0 0 0 0 0 0 0 0 0
44517- 0 0 0 0 0 0 0 0 0 0 0 0
44518- 0 0 0 6 6 6 22 22 22 50 50 50
44519- 78 78 78 34 34 34 2 2 6 2 2 6
44520- 2 2 6 2 2 6 2 2 6 2 2 6
44521- 2 2 6 2 2 6 2 2 6 2 2 6
44522- 2 2 6 2 2 6 6 6 6 70 70 70
44523- 78 78 78 46 46 46 22 22 22 6 6 6
44524- 0 0 0 0 0 0 0 0 0 0 0 0
44525- 0 0 0 0 0 0 0 0 0 0 0 0
44526- 0 0 0 0 0 0 0 0 0 0 0 0
44527- 0 0 0 0 0 0 0 0 0 0 0 0
44528- 0 0 0 0 0 0 0 0 0 0 0 0
44529- 0 0 0 0 0 0 0 0 0 0 0 0
44530- 0 0 0 0 0 0 0 0 0 0 0 0
44531- 0 0 0 0 0 0 0 0 0 0 0 0
44532- 0 0 1 0 0 1 0 0 1 0 0 0
44533- 0 0 0 0 0 0 0 0 0 0 0 0
44534- 0 0 0 0 0 0 0 0 0 0 0 0
44535- 0 0 0 0 0 0 0 0 0 0 0 0
44536- 0 0 0 0 0 0 0 0 0 0 0 0
44537- 0 0 0 0 0 0 0 0 0 0 0 0
44538- 6 6 6 18 18 18 42 42 42 82 82 82
44539- 26 26 26 2 2 6 2 2 6 2 2 6
44540- 2 2 6 2 2 6 2 2 6 2 2 6
44541- 2 2 6 2 2 6 2 2 6 14 14 14
44542- 46 46 46 34 34 34 6 6 6 2 2 6
44543- 42 42 42 78 78 78 42 42 42 18 18 18
44544- 6 6 6 0 0 0 0 0 0 0 0 0
44545- 0 0 0 0 0 0 0 0 0 0 0 0
44546- 0 0 0 0 0 0 0 0 0 0 0 0
44547- 0 0 0 0 0 0 0 0 0 0 0 0
44548- 0 0 0 0 0 0 0 0 0 0 0 0
44549- 0 0 0 0 0 0 0 0 0 0 0 0
44550- 0 0 0 0 0 0 0 0 0 0 0 0
44551- 0 0 0 0 0 0 0 0 0 0 0 0
44552- 0 0 1 0 0 0 0 0 1 0 0 0
44553- 0 0 0 0 0 0 0 0 0 0 0 0
44554- 0 0 0 0 0 0 0 0 0 0 0 0
44555- 0 0 0 0 0 0 0 0 0 0 0 0
44556- 0 0 0 0 0 0 0 0 0 0 0 0
44557- 0 0 0 0 0 0 0 0 0 0 0 0
44558- 10 10 10 30 30 30 66 66 66 58 58 58
44559- 2 2 6 2 2 6 2 2 6 2 2 6
44560- 2 2 6 2 2 6 2 2 6 2 2 6
44561- 2 2 6 2 2 6 2 2 6 26 26 26
44562- 86 86 86 101 101 101 46 46 46 10 10 10
44563- 2 2 6 58 58 58 70 70 70 34 34 34
44564- 10 10 10 0 0 0 0 0 0 0 0 0
44565- 0 0 0 0 0 0 0 0 0 0 0 0
44566- 0 0 0 0 0 0 0 0 0 0 0 0
44567- 0 0 0 0 0 0 0 0 0 0 0 0
44568- 0 0 0 0 0 0 0 0 0 0 0 0
44569- 0 0 0 0 0 0 0 0 0 0 0 0
44570- 0 0 0 0 0 0 0 0 0 0 0 0
44571- 0 0 0 0 0 0 0 0 0 0 0 0
44572- 0 0 1 0 0 1 0 0 1 0 0 0
44573- 0 0 0 0 0 0 0 0 0 0 0 0
44574- 0 0 0 0 0 0 0 0 0 0 0 0
44575- 0 0 0 0 0 0 0 0 0 0 0 0
44576- 0 0 0 0 0 0 0 0 0 0 0 0
44577- 0 0 0 0 0 0 0 0 0 0 0 0
44578- 14 14 14 42 42 42 86 86 86 10 10 10
44579- 2 2 6 2 2 6 2 2 6 2 2 6
44580- 2 2 6 2 2 6 2 2 6 2 2 6
44581- 2 2 6 2 2 6 2 2 6 30 30 30
44582- 94 94 94 94 94 94 58 58 58 26 26 26
44583- 2 2 6 6 6 6 78 78 78 54 54 54
44584- 22 22 22 6 6 6 0 0 0 0 0 0
44585- 0 0 0 0 0 0 0 0 0 0 0 0
44586- 0 0 0 0 0 0 0 0 0 0 0 0
44587- 0 0 0 0 0 0 0 0 0 0 0 0
44588- 0 0 0 0 0 0 0 0 0 0 0 0
44589- 0 0 0 0 0 0 0 0 0 0 0 0
44590- 0 0 0 0 0 0 0 0 0 0 0 0
44591- 0 0 0 0 0 0 0 0 0 0 0 0
44592- 0 0 0 0 0 0 0 0 0 0 0 0
44593- 0 0 0 0 0 0 0 0 0 0 0 0
44594- 0 0 0 0 0 0 0 0 0 0 0 0
44595- 0 0 0 0 0 0 0 0 0 0 0 0
44596- 0 0 0 0 0 0 0 0 0 0 0 0
44597- 0 0 0 0 0 0 0 0 0 6 6 6
44598- 22 22 22 62 62 62 62 62 62 2 2 6
44599- 2 2 6 2 2 6 2 2 6 2 2 6
44600- 2 2 6 2 2 6 2 2 6 2 2 6
44601- 2 2 6 2 2 6 2 2 6 26 26 26
44602- 54 54 54 38 38 38 18 18 18 10 10 10
44603- 2 2 6 2 2 6 34 34 34 82 82 82
44604- 38 38 38 14 14 14 0 0 0 0 0 0
44605- 0 0 0 0 0 0 0 0 0 0 0 0
44606- 0 0 0 0 0 0 0 0 0 0 0 0
44607- 0 0 0 0 0 0 0 0 0 0 0 0
44608- 0 0 0 0 0 0 0 0 0 0 0 0
44609- 0 0 0 0 0 0 0 0 0 0 0 0
44610- 0 0 0 0 0 0 0 0 0 0 0 0
44611- 0 0 0 0 0 0 0 0 0 0 0 0
44612- 0 0 0 0 0 1 0 0 1 0 0 0
44613- 0 0 0 0 0 0 0 0 0 0 0 0
44614- 0 0 0 0 0 0 0 0 0 0 0 0
44615- 0 0 0 0 0 0 0 0 0 0 0 0
44616- 0 0 0 0 0 0 0 0 0 0 0 0
44617- 0 0 0 0 0 0 0 0 0 6 6 6
44618- 30 30 30 78 78 78 30 30 30 2 2 6
44619- 2 2 6 2 2 6 2 2 6 2 2 6
44620- 2 2 6 2 2 6 2 2 6 2 2 6
44621- 2 2 6 2 2 6 2 2 6 10 10 10
44622- 10 10 10 2 2 6 2 2 6 2 2 6
44623- 2 2 6 2 2 6 2 2 6 78 78 78
44624- 50 50 50 18 18 18 6 6 6 0 0 0
44625- 0 0 0 0 0 0 0 0 0 0 0 0
44626- 0 0 0 0 0 0 0 0 0 0 0 0
44627- 0 0 0 0 0 0 0 0 0 0 0 0
44628- 0 0 0 0 0 0 0 0 0 0 0 0
44629- 0 0 0 0 0 0 0 0 0 0 0 0
44630- 0 0 0 0 0 0 0 0 0 0 0 0
44631- 0 0 0 0 0 0 0 0 0 0 0 0
44632- 0 0 1 0 0 0 0 0 0 0 0 0
44633- 0 0 0 0 0 0 0 0 0 0 0 0
44634- 0 0 0 0 0 0 0 0 0 0 0 0
44635- 0 0 0 0 0 0 0 0 0 0 0 0
44636- 0 0 0 0 0 0 0 0 0 0 0 0
44637- 0 0 0 0 0 0 0 0 0 10 10 10
44638- 38 38 38 86 86 86 14 14 14 2 2 6
44639- 2 2 6 2 2 6 2 2 6 2 2 6
44640- 2 2 6 2 2 6 2 2 6 2 2 6
44641- 2 2 6 2 2 6 2 2 6 2 2 6
44642- 2 2 6 2 2 6 2 2 6 2 2 6
44643- 2 2 6 2 2 6 2 2 6 54 54 54
44644- 66 66 66 26 26 26 6 6 6 0 0 0
44645- 0 0 0 0 0 0 0 0 0 0 0 0
44646- 0 0 0 0 0 0 0 0 0 0 0 0
44647- 0 0 0 0 0 0 0 0 0 0 0 0
44648- 0 0 0 0 0 0 0 0 0 0 0 0
44649- 0 0 0 0 0 0 0 0 0 0 0 0
44650- 0 0 0 0 0 0 0 0 0 0 0 0
44651- 0 0 0 0 0 0 0 0 0 0 0 0
44652- 0 0 0 0 0 1 0 0 1 0 0 0
44653- 0 0 0 0 0 0 0 0 0 0 0 0
44654- 0 0 0 0 0 0 0 0 0 0 0 0
44655- 0 0 0 0 0 0 0 0 0 0 0 0
44656- 0 0 0 0 0 0 0 0 0 0 0 0
44657- 0 0 0 0 0 0 0 0 0 14 14 14
44658- 42 42 42 82 82 82 2 2 6 2 2 6
44659- 2 2 6 6 6 6 10 10 10 2 2 6
44660- 2 2 6 2 2 6 2 2 6 2 2 6
44661- 2 2 6 2 2 6 2 2 6 6 6 6
44662- 14 14 14 10 10 10 2 2 6 2 2 6
44663- 2 2 6 2 2 6 2 2 6 18 18 18
44664- 82 82 82 34 34 34 10 10 10 0 0 0
44665- 0 0 0 0 0 0 0 0 0 0 0 0
44666- 0 0 0 0 0 0 0 0 0 0 0 0
44667- 0 0 0 0 0 0 0 0 0 0 0 0
44668- 0 0 0 0 0 0 0 0 0 0 0 0
44669- 0 0 0 0 0 0 0 0 0 0 0 0
44670- 0 0 0 0 0 0 0 0 0 0 0 0
44671- 0 0 0 0 0 0 0 0 0 0 0 0
44672- 0 0 1 0 0 0 0 0 0 0 0 0
44673- 0 0 0 0 0 0 0 0 0 0 0 0
44674- 0 0 0 0 0 0 0 0 0 0 0 0
44675- 0 0 0 0 0 0 0 0 0 0 0 0
44676- 0 0 0 0 0 0 0 0 0 0 0 0
44677- 0 0 0 0 0 0 0 0 0 14 14 14
44678- 46 46 46 86 86 86 2 2 6 2 2 6
44679- 6 6 6 6 6 6 22 22 22 34 34 34
44680- 6 6 6 2 2 6 2 2 6 2 2 6
44681- 2 2 6 2 2 6 18 18 18 34 34 34
44682- 10 10 10 50 50 50 22 22 22 2 2 6
44683- 2 2 6 2 2 6 2 2 6 10 10 10
44684- 86 86 86 42 42 42 14 14 14 0 0 0
44685- 0 0 0 0 0 0 0 0 0 0 0 0
44686- 0 0 0 0 0 0 0 0 0 0 0 0
44687- 0 0 0 0 0 0 0 0 0 0 0 0
44688- 0 0 0 0 0 0 0 0 0 0 0 0
44689- 0 0 0 0 0 0 0 0 0 0 0 0
44690- 0 0 0 0 0 0 0 0 0 0 0 0
44691- 0 0 0 0 0 0 0 0 0 0 0 0
44692- 0 0 1 0 0 1 0 0 1 0 0 0
44693- 0 0 0 0 0 0 0 0 0 0 0 0
44694- 0 0 0 0 0 0 0 0 0 0 0 0
44695- 0 0 0 0 0 0 0 0 0 0 0 0
44696- 0 0 0 0 0 0 0 0 0 0 0 0
44697- 0 0 0 0 0 0 0 0 0 14 14 14
44698- 46 46 46 86 86 86 2 2 6 2 2 6
44699- 38 38 38 116 116 116 94 94 94 22 22 22
44700- 22 22 22 2 2 6 2 2 6 2 2 6
44701- 14 14 14 86 86 86 138 138 138 162 162 162
44702-154 154 154 38 38 38 26 26 26 6 6 6
44703- 2 2 6 2 2 6 2 2 6 2 2 6
44704- 86 86 86 46 46 46 14 14 14 0 0 0
44705- 0 0 0 0 0 0 0 0 0 0 0 0
44706- 0 0 0 0 0 0 0 0 0 0 0 0
44707- 0 0 0 0 0 0 0 0 0 0 0 0
44708- 0 0 0 0 0 0 0 0 0 0 0 0
44709- 0 0 0 0 0 0 0 0 0 0 0 0
44710- 0 0 0 0 0 0 0 0 0 0 0 0
44711- 0 0 0 0 0 0 0 0 0 0 0 0
44712- 0 0 0 0 0 0 0 0 0 0 0 0
44713- 0 0 0 0 0 0 0 0 0 0 0 0
44714- 0 0 0 0 0 0 0 0 0 0 0 0
44715- 0 0 0 0 0 0 0 0 0 0 0 0
44716- 0 0 0 0 0 0 0 0 0 0 0 0
44717- 0 0 0 0 0 0 0 0 0 14 14 14
44718- 46 46 46 86 86 86 2 2 6 14 14 14
44719-134 134 134 198 198 198 195 195 195 116 116 116
44720- 10 10 10 2 2 6 2 2 6 6 6 6
44721-101 98 89 187 187 187 210 210 210 218 218 218
44722-214 214 214 134 134 134 14 14 14 6 6 6
44723- 2 2 6 2 2 6 2 2 6 2 2 6
44724- 86 86 86 50 50 50 18 18 18 6 6 6
44725- 0 0 0 0 0 0 0 0 0 0 0 0
44726- 0 0 0 0 0 0 0 0 0 0 0 0
44727- 0 0 0 0 0 0 0 0 0 0 0 0
44728- 0 0 0 0 0 0 0 0 0 0 0 0
44729- 0 0 0 0 0 0 0 0 0 0 0 0
44730- 0 0 0 0 0 0 0 0 0 0 0 0
44731- 0 0 0 0 0 0 0 0 1 0 0 0
44732- 0 0 1 0 0 1 0 0 1 0 0 0
44733- 0 0 0 0 0 0 0 0 0 0 0 0
44734- 0 0 0 0 0 0 0 0 0 0 0 0
44735- 0 0 0 0 0 0 0 0 0 0 0 0
44736- 0 0 0 0 0 0 0 0 0 0 0 0
44737- 0 0 0 0 0 0 0 0 0 14 14 14
44738- 46 46 46 86 86 86 2 2 6 54 54 54
44739-218 218 218 195 195 195 226 226 226 246 246 246
44740- 58 58 58 2 2 6 2 2 6 30 30 30
44741-210 210 210 253 253 253 174 174 174 123 123 123
44742-221 221 221 234 234 234 74 74 74 2 2 6
44743- 2 2 6 2 2 6 2 2 6 2 2 6
44744- 70 70 70 58 58 58 22 22 22 6 6 6
44745- 0 0 0 0 0 0 0 0 0 0 0 0
44746- 0 0 0 0 0 0 0 0 0 0 0 0
44747- 0 0 0 0 0 0 0 0 0 0 0 0
44748- 0 0 0 0 0 0 0 0 0 0 0 0
44749- 0 0 0 0 0 0 0 0 0 0 0 0
44750- 0 0 0 0 0 0 0 0 0 0 0 0
44751- 0 0 0 0 0 0 0 0 0 0 0 0
44752- 0 0 0 0 0 0 0 0 0 0 0 0
44753- 0 0 0 0 0 0 0 0 0 0 0 0
44754- 0 0 0 0 0 0 0 0 0 0 0 0
44755- 0 0 0 0 0 0 0 0 0 0 0 0
44756- 0 0 0 0 0 0 0 0 0 0 0 0
44757- 0 0 0 0 0 0 0 0 0 14 14 14
44758- 46 46 46 82 82 82 2 2 6 106 106 106
44759-170 170 170 26 26 26 86 86 86 226 226 226
44760-123 123 123 10 10 10 14 14 14 46 46 46
44761-231 231 231 190 190 190 6 6 6 70 70 70
44762- 90 90 90 238 238 238 158 158 158 2 2 6
44763- 2 2 6 2 2 6 2 2 6 2 2 6
44764- 70 70 70 58 58 58 22 22 22 6 6 6
44765- 0 0 0 0 0 0 0 0 0 0 0 0
44766- 0 0 0 0 0 0 0 0 0 0 0 0
44767- 0 0 0 0 0 0 0 0 0 0 0 0
44768- 0 0 0 0 0 0 0 0 0 0 0 0
44769- 0 0 0 0 0 0 0 0 0 0 0 0
44770- 0 0 0 0 0 0 0 0 0 0 0 0
44771- 0 0 0 0 0 0 0 0 1 0 0 0
44772- 0 0 1 0 0 1 0 0 1 0 0 0
44773- 0 0 0 0 0 0 0 0 0 0 0 0
44774- 0 0 0 0 0 0 0 0 0 0 0 0
44775- 0 0 0 0 0 0 0 0 0 0 0 0
44776- 0 0 0 0 0 0 0 0 0 0 0 0
44777- 0 0 0 0 0 0 0 0 0 14 14 14
44778- 42 42 42 86 86 86 6 6 6 116 116 116
44779-106 106 106 6 6 6 70 70 70 149 149 149
44780-128 128 128 18 18 18 38 38 38 54 54 54
44781-221 221 221 106 106 106 2 2 6 14 14 14
44782- 46 46 46 190 190 190 198 198 198 2 2 6
44783- 2 2 6 2 2 6 2 2 6 2 2 6
44784- 74 74 74 62 62 62 22 22 22 6 6 6
44785- 0 0 0 0 0 0 0 0 0 0 0 0
44786- 0 0 0 0 0 0 0 0 0 0 0 0
44787- 0 0 0 0 0 0 0 0 0 0 0 0
44788- 0 0 0 0 0 0 0 0 0 0 0 0
44789- 0 0 0 0 0 0 0 0 0 0 0 0
44790- 0 0 0 0 0 0 0 0 0 0 0 0
44791- 0 0 0 0 0 0 0 0 1 0 0 0
44792- 0 0 1 0 0 0 0 0 1 0 0 0
44793- 0 0 0 0 0 0 0 0 0 0 0 0
44794- 0 0 0 0 0 0 0 0 0 0 0 0
44795- 0 0 0 0 0 0 0 0 0 0 0 0
44796- 0 0 0 0 0 0 0 0 0 0 0 0
44797- 0 0 0 0 0 0 0 0 0 14 14 14
44798- 42 42 42 94 94 94 14 14 14 101 101 101
44799-128 128 128 2 2 6 18 18 18 116 116 116
44800-118 98 46 121 92 8 121 92 8 98 78 10
44801-162 162 162 106 106 106 2 2 6 2 2 6
44802- 2 2 6 195 195 195 195 195 195 6 6 6
44803- 2 2 6 2 2 6 2 2 6 2 2 6
44804- 74 74 74 62 62 62 22 22 22 6 6 6
44805- 0 0 0 0 0 0 0 0 0 0 0 0
44806- 0 0 0 0 0 0 0 0 0 0 0 0
44807- 0 0 0 0 0 0 0 0 0 0 0 0
44808- 0 0 0 0 0 0 0 0 0 0 0 0
44809- 0 0 0 0 0 0 0 0 0 0 0 0
44810- 0 0 0 0 0 0 0 0 0 0 0 0
44811- 0 0 0 0 0 0 0 0 1 0 0 1
44812- 0 0 1 0 0 0 0 0 1 0 0 0
44813- 0 0 0 0 0 0 0 0 0 0 0 0
44814- 0 0 0 0 0 0 0 0 0 0 0 0
44815- 0 0 0 0 0 0 0 0 0 0 0 0
44816- 0 0 0 0 0 0 0 0 0 0 0 0
44817- 0 0 0 0 0 0 0 0 0 10 10 10
44818- 38 38 38 90 90 90 14 14 14 58 58 58
44819-210 210 210 26 26 26 54 38 6 154 114 10
44820-226 170 11 236 186 11 225 175 15 184 144 12
44821-215 174 15 175 146 61 37 26 9 2 2 6
44822- 70 70 70 246 246 246 138 138 138 2 2 6
44823- 2 2 6 2 2 6 2 2 6 2 2 6
44824- 70 70 70 66 66 66 26 26 26 6 6 6
44825- 0 0 0 0 0 0 0 0 0 0 0 0
44826- 0 0 0 0 0 0 0 0 0 0 0 0
44827- 0 0 0 0 0 0 0 0 0 0 0 0
44828- 0 0 0 0 0 0 0 0 0 0 0 0
44829- 0 0 0 0 0 0 0 0 0 0 0 0
44830- 0 0 0 0 0 0 0 0 0 0 0 0
44831- 0 0 0 0 0 0 0 0 0 0 0 0
44832- 0 0 0 0 0 0 0 0 0 0 0 0
44833- 0 0 0 0 0 0 0 0 0 0 0 0
44834- 0 0 0 0 0 0 0 0 0 0 0 0
44835- 0 0 0 0 0 0 0 0 0 0 0 0
44836- 0 0 0 0 0 0 0 0 0 0 0 0
44837- 0 0 0 0 0 0 0 0 0 10 10 10
44838- 38 38 38 86 86 86 14 14 14 10 10 10
44839-195 195 195 188 164 115 192 133 9 225 175 15
44840-239 182 13 234 190 10 232 195 16 232 200 30
44841-245 207 45 241 208 19 232 195 16 184 144 12
44842-218 194 134 211 206 186 42 42 42 2 2 6
44843- 2 2 6 2 2 6 2 2 6 2 2 6
44844- 50 50 50 74 74 74 30 30 30 6 6 6
44845- 0 0 0 0 0 0 0 0 0 0 0 0
44846- 0 0 0 0 0 0 0 0 0 0 0 0
44847- 0 0 0 0 0 0 0 0 0 0 0 0
44848- 0 0 0 0 0 0 0 0 0 0 0 0
44849- 0 0 0 0 0 0 0 0 0 0 0 0
44850- 0 0 0 0 0 0 0 0 0 0 0 0
44851- 0 0 0 0 0 0 0 0 0 0 0 0
44852- 0 0 0 0 0 0 0 0 0 0 0 0
44853- 0 0 0 0 0 0 0 0 0 0 0 0
44854- 0 0 0 0 0 0 0 0 0 0 0 0
44855- 0 0 0 0 0 0 0 0 0 0 0 0
44856- 0 0 0 0 0 0 0 0 0 0 0 0
44857- 0 0 0 0 0 0 0 0 0 10 10 10
44858- 34 34 34 86 86 86 14 14 14 2 2 6
44859-121 87 25 192 133 9 219 162 10 239 182 13
44860-236 186 11 232 195 16 241 208 19 244 214 54
44861-246 218 60 246 218 38 246 215 20 241 208 19
44862-241 208 19 226 184 13 121 87 25 2 2 6
44863- 2 2 6 2 2 6 2 2 6 2 2 6
44864- 50 50 50 82 82 82 34 34 34 10 10 10
44865- 0 0 0 0 0 0 0 0 0 0 0 0
44866- 0 0 0 0 0 0 0 0 0 0 0 0
44867- 0 0 0 0 0 0 0 0 0 0 0 0
44868- 0 0 0 0 0 0 0 0 0 0 0 0
44869- 0 0 0 0 0 0 0 0 0 0 0 0
44870- 0 0 0 0 0 0 0 0 0 0 0 0
44871- 0 0 0 0 0 0 0 0 0 0 0 0
44872- 0 0 0 0 0 0 0 0 0 0 0 0
44873- 0 0 0 0 0 0 0 0 0 0 0 0
44874- 0 0 0 0 0 0 0 0 0 0 0 0
44875- 0 0 0 0 0 0 0 0 0 0 0 0
44876- 0 0 0 0 0 0 0 0 0 0 0 0
44877- 0 0 0 0 0 0 0 0 0 10 10 10
44878- 34 34 34 82 82 82 30 30 30 61 42 6
44879-180 123 7 206 145 10 230 174 11 239 182 13
44880-234 190 10 238 202 15 241 208 19 246 218 74
44881-246 218 38 246 215 20 246 215 20 246 215 20
44882-226 184 13 215 174 15 184 144 12 6 6 6
44883- 2 2 6 2 2 6 2 2 6 2 2 6
44884- 26 26 26 94 94 94 42 42 42 14 14 14
44885- 0 0 0 0 0 0 0 0 0 0 0 0
44886- 0 0 0 0 0 0 0 0 0 0 0 0
44887- 0 0 0 0 0 0 0 0 0 0 0 0
44888- 0 0 0 0 0 0 0 0 0 0 0 0
44889- 0 0 0 0 0 0 0 0 0 0 0 0
44890- 0 0 0 0 0 0 0 0 0 0 0 0
44891- 0 0 0 0 0 0 0 0 0 0 0 0
44892- 0 0 0 0 0 0 0 0 0 0 0 0
44893- 0 0 0 0 0 0 0 0 0 0 0 0
44894- 0 0 0 0 0 0 0 0 0 0 0 0
44895- 0 0 0 0 0 0 0 0 0 0 0 0
44896- 0 0 0 0 0 0 0 0 0 0 0 0
44897- 0 0 0 0 0 0 0 0 0 10 10 10
44898- 30 30 30 78 78 78 50 50 50 104 69 6
44899-192 133 9 216 158 10 236 178 12 236 186 11
44900-232 195 16 241 208 19 244 214 54 245 215 43
44901-246 215 20 246 215 20 241 208 19 198 155 10
44902-200 144 11 216 158 10 156 118 10 2 2 6
44903- 2 2 6 2 2 6 2 2 6 2 2 6
44904- 6 6 6 90 90 90 54 54 54 18 18 18
44905- 6 6 6 0 0 0 0 0 0 0 0 0
44906- 0 0 0 0 0 0 0 0 0 0 0 0
44907- 0 0 0 0 0 0 0 0 0 0 0 0
44908- 0 0 0 0 0 0 0 0 0 0 0 0
44909- 0 0 0 0 0 0 0 0 0 0 0 0
44910- 0 0 0 0 0 0 0 0 0 0 0 0
44911- 0 0 0 0 0 0 0 0 0 0 0 0
44912- 0 0 0 0 0 0 0 0 0 0 0 0
44913- 0 0 0 0 0 0 0 0 0 0 0 0
44914- 0 0 0 0 0 0 0 0 0 0 0 0
44915- 0 0 0 0 0 0 0 0 0 0 0 0
44916- 0 0 0 0 0 0 0 0 0 0 0 0
44917- 0 0 0 0 0 0 0 0 0 10 10 10
44918- 30 30 30 78 78 78 46 46 46 22 22 22
44919-137 92 6 210 162 10 239 182 13 238 190 10
44920-238 202 15 241 208 19 246 215 20 246 215 20
44921-241 208 19 203 166 17 185 133 11 210 150 10
44922-216 158 10 210 150 10 102 78 10 2 2 6
44923- 6 6 6 54 54 54 14 14 14 2 2 6
44924- 2 2 6 62 62 62 74 74 74 30 30 30
44925- 10 10 10 0 0 0 0 0 0 0 0 0
44926- 0 0 0 0 0 0 0 0 0 0 0 0
44927- 0 0 0 0 0 0 0 0 0 0 0 0
44928- 0 0 0 0 0 0 0 0 0 0 0 0
44929- 0 0 0 0 0 0 0 0 0 0 0 0
44930- 0 0 0 0 0 0 0 0 0 0 0 0
44931- 0 0 0 0 0 0 0 0 0 0 0 0
44932- 0 0 0 0 0 0 0 0 0 0 0 0
44933- 0 0 0 0 0 0 0 0 0 0 0 0
44934- 0 0 0 0 0 0 0 0 0 0 0 0
44935- 0 0 0 0 0 0 0 0 0 0 0 0
44936- 0 0 0 0 0 0 0 0 0 0 0 0
44937- 0 0 0 0 0 0 0 0 0 10 10 10
44938- 34 34 34 78 78 78 50 50 50 6 6 6
44939- 94 70 30 139 102 15 190 146 13 226 184 13
44940-232 200 30 232 195 16 215 174 15 190 146 13
44941-168 122 10 192 133 9 210 150 10 213 154 11
44942-202 150 34 182 157 106 101 98 89 2 2 6
44943- 2 2 6 78 78 78 116 116 116 58 58 58
44944- 2 2 6 22 22 22 90 90 90 46 46 46
44945- 18 18 18 6 6 6 0 0 0 0 0 0
44946- 0 0 0 0 0 0 0 0 0 0 0 0
44947- 0 0 0 0 0 0 0 0 0 0 0 0
44948- 0 0 0 0 0 0 0 0 0 0 0 0
44949- 0 0 0 0 0 0 0 0 0 0 0 0
44950- 0 0 0 0 0 0 0 0 0 0 0 0
44951- 0 0 0 0 0 0 0 0 0 0 0 0
44952- 0 0 0 0 0 0 0 0 0 0 0 0
44953- 0 0 0 0 0 0 0 0 0 0 0 0
44954- 0 0 0 0 0 0 0 0 0 0 0 0
44955- 0 0 0 0 0 0 0 0 0 0 0 0
44956- 0 0 0 0 0 0 0 0 0 0 0 0
44957- 0 0 0 0 0 0 0 0 0 10 10 10
44958- 38 38 38 86 86 86 50 50 50 6 6 6
44959-128 128 128 174 154 114 156 107 11 168 122 10
44960-198 155 10 184 144 12 197 138 11 200 144 11
44961-206 145 10 206 145 10 197 138 11 188 164 115
44962-195 195 195 198 198 198 174 174 174 14 14 14
44963- 2 2 6 22 22 22 116 116 116 116 116 116
44964- 22 22 22 2 2 6 74 74 74 70 70 70
44965- 30 30 30 10 10 10 0 0 0 0 0 0
44966- 0 0 0 0 0 0 0 0 0 0 0 0
44967- 0 0 0 0 0 0 0 0 0 0 0 0
44968- 0 0 0 0 0 0 0 0 0 0 0 0
44969- 0 0 0 0 0 0 0 0 0 0 0 0
44970- 0 0 0 0 0 0 0 0 0 0 0 0
44971- 0 0 0 0 0 0 0 0 0 0 0 0
44972- 0 0 0 0 0 0 0 0 0 0 0 0
44973- 0 0 0 0 0 0 0 0 0 0 0 0
44974- 0 0 0 0 0 0 0 0 0 0 0 0
44975- 0 0 0 0 0 0 0 0 0 0 0 0
44976- 0 0 0 0 0 0 0 0 0 0 0 0
44977- 0 0 0 0 0 0 6 6 6 18 18 18
44978- 50 50 50 101 101 101 26 26 26 10 10 10
44979-138 138 138 190 190 190 174 154 114 156 107 11
44980-197 138 11 200 144 11 197 138 11 192 133 9
44981-180 123 7 190 142 34 190 178 144 187 187 187
44982-202 202 202 221 221 221 214 214 214 66 66 66
44983- 2 2 6 2 2 6 50 50 50 62 62 62
44984- 6 6 6 2 2 6 10 10 10 90 90 90
44985- 50 50 50 18 18 18 6 6 6 0 0 0
44986- 0 0 0 0 0 0 0 0 0 0 0 0
44987- 0 0 0 0 0 0 0 0 0 0 0 0
44988- 0 0 0 0 0 0 0 0 0 0 0 0
44989- 0 0 0 0 0 0 0 0 0 0 0 0
44990- 0 0 0 0 0 0 0 0 0 0 0 0
44991- 0 0 0 0 0 0 0 0 0 0 0 0
44992- 0 0 0 0 0 0 0 0 0 0 0 0
44993- 0 0 0 0 0 0 0 0 0 0 0 0
44994- 0 0 0 0 0 0 0 0 0 0 0 0
44995- 0 0 0 0 0 0 0 0 0 0 0 0
44996- 0 0 0 0 0 0 0 0 0 0 0 0
44997- 0 0 0 0 0 0 10 10 10 34 34 34
44998- 74 74 74 74 74 74 2 2 6 6 6 6
44999-144 144 144 198 198 198 190 190 190 178 166 146
45000-154 121 60 156 107 11 156 107 11 168 124 44
45001-174 154 114 187 187 187 190 190 190 210 210 210
45002-246 246 246 253 253 253 253 253 253 182 182 182
45003- 6 6 6 2 2 6 2 2 6 2 2 6
45004- 2 2 6 2 2 6 2 2 6 62 62 62
45005- 74 74 74 34 34 34 14 14 14 0 0 0
45006- 0 0 0 0 0 0 0 0 0 0 0 0
45007- 0 0 0 0 0 0 0 0 0 0 0 0
45008- 0 0 0 0 0 0 0 0 0 0 0 0
45009- 0 0 0 0 0 0 0 0 0 0 0 0
45010- 0 0 0 0 0 0 0 0 0 0 0 0
45011- 0 0 0 0 0 0 0 0 0 0 0 0
45012- 0 0 0 0 0 0 0 0 0 0 0 0
45013- 0 0 0 0 0 0 0 0 0 0 0 0
45014- 0 0 0 0 0 0 0 0 0 0 0 0
45015- 0 0 0 0 0 0 0 0 0 0 0 0
45016- 0 0 0 0 0 0 0 0 0 0 0 0
45017- 0 0 0 10 10 10 22 22 22 54 54 54
45018- 94 94 94 18 18 18 2 2 6 46 46 46
45019-234 234 234 221 221 221 190 190 190 190 190 190
45020-190 190 190 187 187 187 187 187 187 190 190 190
45021-190 190 190 195 195 195 214 214 214 242 242 242
45022-253 253 253 253 253 253 253 253 253 253 253 253
45023- 82 82 82 2 2 6 2 2 6 2 2 6
45024- 2 2 6 2 2 6 2 2 6 14 14 14
45025- 86 86 86 54 54 54 22 22 22 6 6 6
45026- 0 0 0 0 0 0 0 0 0 0 0 0
45027- 0 0 0 0 0 0 0 0 0 0 0 0
45028- 0 0 0 0 0 0 0 0 0 0 0 0
45029- 0 0 0 0 0 0 0 0 0 0 0 0
45030- 0 0 0 0 0 0 0 0 0 0 0 0
45031- 0 0 0 0 0 0 0 0 0 0 0 0
45032- 0 0 0 0 0 0 0 0 0 0 0 0
45033- 0 0 0 0 0 0 0 0 0 0 0 0
45034- 0 0 0 0 0 0 0 0 0 0 0 0
45035- 0 0 0 0 0 0 0 0 0 0 0 0
45036- 0 0 0 0 0 0 0 0 0 0 0 0
45037- 6 6 6 18 18 18 46 46 46 90 90 90
45038- 46 46 46 18 18 18 6 6 6 182 182 182
45039-253 253 253 246 246 246 206 206 206 190 190 190
45040-190 190 190 190 190 190 190 190 190 190 190 190
45041-206 206 206 231 231 231 250 250 250 253 253 253
45042-253 253 253 253 253 253 253 253 253 253 253 253
45043-202 202 202 14 14 14 2 2 6 2 2 6
45044- 2 2 6 2 2 6 2 2 6 2 2 6
45045- 42 42 42 86 86 86 42 42 42 18 18 18
45046- 6 6 6 0 0 0 0 0 0 0 0 0
45047- 0 0 0 0 0 0 0 0 0 0 0 0
45048- 0 0 0 0 0 0 0 0 0 0 0 0
45049- 0 0 0 0 0 0 0 0 0 0 0 0
45050- 0 0 0 0 0 0 0 0 0 0 0 0
45051- 0 0 0 0 0 0 0 0 0 0 0 0
45052- 0 0 0 0 0 0 0 0 0 0 0 0
45053- 0 0 0 0 0 0 0 0 0 0 0 0
45054- 0 0 0 0 0 0 0 0 0 0 0 0
45055- 0 0 0 0 0 0 0 0 0 0 0 0
45056- 0 0 0 0 0 0 0 0 0 6 6 6
45057- 14 14 14 38 38 38 74 74 74 66 66 66
45058- 2 2 6 6 6 6 90 90 90 250 250 250
45059-253 253 253 253 253 253 238 238 238 198 198 198
45060-190 190 190 190 190 190 195 195 195 221 221 221
45061-246 246 246 253 253 253 253 253 253 253 253 253
45062-253 253 253 253 253 253 253 253 253 253 253 253
45063-253 253 253 82 82 82 2 2 6 2 2 6
45064- 2 2 6 2 2 6 2 2 6 2 2 6
45065- 2 2 6 78 78 78 70 70 70 34 34 34
45066- 14 14 14 6 6 6 0 0 0 0 0 0
45067- 0 0 0 0 0 0 0 0 0 0 0 0
45068- 0 0 0 0 0 0 0 0 0 0 0 0
45069- 0 0 0 0 0 0 0 0 0 0 0 0
45070- 0 0 0 0 0 0 0 0 0 0 0 0
45071- 0 0 0 0 0 0 0 0 0 0 0 0
45072- 0 0 0 0 0 0 0 0 0 0 0 0
45073- 0 0 0 0 0 0 0 0 0 0 0 0
45074- 0 0 0 0 0 0 0 0 0 0 0 0
45075- 0 0 0 0 0 0 0 0 0 0 0 0
45076- 0 0 0 0 0 0 0 0 0 14 14 14
45077- 34 34 34 66 66 66 78 78 78 6 6 6
45078- 2 2 6 18 18 18 218 218 218 253 253 253
45079-253 253 253 253 253 253 253 253 253 246 246 246
45080-226 226 226 231 231 231 246 246 246 253 253 253
45081-253 253 253 253 253 253 253 253 253 253 253 253
45082-253 253 253 253 253 253 253 253 253 253 253 253
45083-253 253 253 178 178 178 2 2 6 2 2 6
45084- 2 2 6 2 2 6 2 2 6 2 2 6
45085- 2 2 6 18 18 18 90 90 90 62 62 62
45086- 30 30 30 10 10 10 0 0 0 0 0 0
45087- 0 0 0 0 0 0 0 0 0 0 0 0
45088- 0 0 0 0 0 0 0 0 0 0 0 0
45089- 0 0 0 0 0 0 0 0 0 0 0 0
45090- 0 0 0 0 0 0 0 0 0 0 0 0
45091- 0 0 0 0 0 0 0 0 0 0 0 0
45092- 0 0 0 0 0 0 0 0 0 0 0 0
45093- 0 0 0 0 0 0 0 0 0 0 0 0
45094- 0 0 0 0 0 0 0 0 0 0 0 0
45095- 0 0 0 0 0 0 0 0 0 0 0 0
45096- 0 0 0 0 0 0 10 10 10 26 26 26
45097- 58 58 58 90 90 90 18 18 18 2 2 6
45098- 2 2 6 110 110 110 253 253 253 253 253 253
45099-253 253 253 253 253 253 253 253 253 253 253 253
45100-250 250 250 253 253 253 253 253 253 253 253 253
45101-253 253 253 253 253 253 253 253 253 253 253 253
45102-253 253 253 253 253 253 253 253 253 253 253 253
45103-253 253 253 231 231 231 18 18 18 2 2 6
45104- 2 2 6 2 2 6 2 2 6 2 2 6
45105- 2 2 6 2 2 6 18 18 18 94 94 94
45106- 54 54 54 26 26 26 10 10 10 0 0 0
45107- 0 0 0 0 0 0 0 0 0 0 0 0
45108- 0 0 0 0 0 0 0 0 0 0 0 0
45109- 0 0 0 0 0 0 0 0 0 0 0 0
45110- 0 0 0 0 0 0 0 0 0 0 0 0
45111- 0 0 0 0 0 0 0 0 0 0 0 0
45112- 0 0 0 0 0 0 0 0 0 0 0 0
45113- 0 0 0 0 0 0 0 0 0 0 0 0
45114- 0 0 0 0 0 0 0 0 0 0 0 0
45115- 0 0 0 0 0 0 0 0 0 0 0 0
45116- 0 0 0 6 6 6 22 22 22 50 50 50
45117- 90 90 90 26 26 26 2 2 6 2 2 6
45118- 14 14 14 195 195 195 250 250 250 253 253 253
45119-253 253 253 253 253 253 253 253 253 253 253 253
45120-253 253 253 253 253 253 253 253 253 253 253 253
45121-253 253 253 253 253 253 253 253 253 253 253 253
45122-253 253 253 253 253 253 253 253 253 253 253 253
45123-250 250 250 242 242 242 54 54 54 2 2 6
45124- 2 2 6 2 2 6 2 2 6 2 2 6
45125- 2 2 6 2 2 6 2 2 6 38 38 38
45126- 86 86 86 50 50 50 22 22 22 6 6 6
45127- 0 0 0 0 0 0 0 0 0 0 0 0
45128- 0 0 0 0 0 0 0 0 0 0 0 0
45129- 0 0 0 0 0 0 0 0 0 0 0 0
45130- 0 0 0 0 0 0 0 0 0 0 0 0
45131- 0 0 0 0 0 0 0 0 0 0 0 0
45132- 0 0 0 0 0 0 0 0 0 0 0 0
45133- 0 0 0 0 0 0 0 0 0 0 0 0
45134- 0 0 0 0 0 0 0 0 0 0 0 0
45135- 0 0 0 0 0 0 0 0 0 0 0 0
45136- 6 6 6 14 14 14 38 38 38 82 82 82
45137- 34 34 34 2 2 6 2 2 6 2 2 6
45138- 42 42 42 195 195 195 246 246 246 253 253 253
45139-253 253 253 253 253 253 253 253 253 250 250 250
45140-242 242 242 242 242 242 250 250 250 253 253 253
45141-253 253 253 253 253 253 253 253 253 253 253 253
45142-253 253 253 250 250 250 246 246 246 238 238 238
45143-226 226 226 231 231 231 101 101 101 6 6 6
45144- 2 2 6 2 2 6 2 2 6 2 2 6
45145- 2 2 6 2 2 6 2 2 6 2 2 6
45146- 38 38 38 82 82 82 42 42 42 14 14 14
45147- 6 6 6 0 0 0 0 0 0 0 0 0
45148- 0 0 0 0 0 0 0 0 0 0 0 0
45149- 0 0 0 0 0 0 0 0 0 0 0 0
45150- 0 0 0 0 0 0 0 0 0 0 0 0
45151- 0 0 0 0 0 0 0 0 0 0 0 0
45152- 0 0 0 0 0 0 0 0 0 0 0 0
45153- 0 0 0 0 0 0 0 0 0 0 0 0
45154- 0 0 0 0 0 0 0 0 0 0 0 0
45155- 0 0 0 0 0 0 0 0 0 0 0 0
45156- 10 10 10 26 26 26 62 62 62 66 66 66
45157- 2 2 6 2 2 6 2 2 6 6 6 6
45158- 70 70 70 170 170 170 206 206 206 234 234 234
45159-246 246 246 250 250 250 250 250 250 238 238 238
45160-226 226 226 231 231 231 238 238 238 250 250 250
45161-250 250 250 250 250 250 246 246 246 231 231 231
45162-214 214 214 206 206 206 202 202 202 202 202 202
45163-198 198 198 202 202 202 182 182 182 18 18 18
45164- 2 2 6 2 2 6 2 2 6 2 2 6
45165- 2 2 6 2 2 6 2 2 6 2 2 6
45166- 2 2 6 62 62 62 66 66 66 30 30 30
45167- 10 10 10 0 0 0 0 0 0 0 0 0
45168- 0 0 0 0 0 0 0 0 0 0 0 0
45169- 0 0 0 0 0 0 0 0 0 0 0 0
45170- 0 0 0 0 0 0 0 0 0 0 0 0
45171- 0 0 0 0 0 0 0 0 0 0 0 0
45172- 0 0 0 0 0 0 0 0 0 0 0 0
45173- 0 0 0 0 0 0 0 0 0 0 0 0
45174- 0 0 0 0 0 0 0 0 0 0 0 0
45175- 0 0 0 0 0 0 0 0 0 0 0 0
45176- 14 14 14 42 42 42 82 82 82 18 18 18
45177- 2 2 6 2 2 6 2 2 6 10 10 10
45178- 94 94 94 182 182 182 218 218 218 242 242 242
45179-250 250 250 253 253 253 253 253 253 250 250 250
45180-234 234 234 253 253 253 253 253 253 253 253 253
45181-253 253 253 253 253 253 253 253 253 246 246 246
45182-238 238 238 226 226 226 210 210 210 202 202 202
45183-195 195 195 195 195 195 210 210 210 158 158 158
45184- 6 6 6 14 14 14 50 50 50 14 14 14
45185- 2 2 6 2 2 6 2 2 6 2 2 6
45186- 2 2 6 6 6 6 86 86 86 46 46 46
45187- 18 18 18 6 6 6 0 0 0 0 0 0
45188- 0 0 0 0 0 0 0 0 0 0 0 0
45189- 0 0 0 0 0 0 0 0 0 0 0 0
45190- 0 0 0 0 0 0 0 0 0 0 0 0
45191- 0 0 0 0 0 0 0 0 0 0 0 0
45192- 0 0 0 0 0 0 0 0 0 0 0 0
45193- 0 0 0 0 0 0 0 0 0 0 0 0
45194- 0 0 0 0 0 0 0 0 0 0 0 0
45195- 0 0 0 0 0 0 0 0 0 6 6 6
45196- 22 22 22 54 54 54 70 70 70 2 2 6
45197- 2 2 6 10 10 10 2 2 6 22 22 22
45198-166 166 166 231 231 231 250 250 250 253 253 253
45199-253 253 253 253 253 253 253 253 253 250 250 250
45200-242 242 242 253 253 253 253 253 253 253 253 253
45201-253 253 253 253 253 253 253 253 253 253 253 253
45202-253 253 253 253 253 253 253 253 253 246 246 246
45203-231 231 231 206 206 206 198 198 198 226 226 226
45204- 94 94 94 2 2 6 6 6 6 38 38 38
45205- 30 30 30 2 2 6 2 2 6 2 2 6
45206- 2 2 6 2 2 6 62 62 62 66 66 66
45207- 26 26 26 10 10 10 0 0 0 0 0 0
45208- 0 0 0 0 0 0 0 0 0 0 0 0
45209- 0 0 0 0 0 0 0 0 0 0 0 0
45210- 0 0 0 0 0 0 0 0 0 0 0 0
45211- 0 0 0 0 0 0 0 0 0 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 10 10 10
45216- 30 30 30 74 74 74 50 50 50 2 2 6
45217- 26 26 26 26 26 26 2 2 6 106 106 106
45218-238 238 238 253 253 253 253 253 253 253 253 253
45219-253 253 253 253 253 253 253 253 253 253 253 253
45220-253 253 253 253 253 253 253 253 253 253 253 253
45221-253 253 253 253 253 253 253 253 253 253 253 253
45222-253 253 253 253 253 253 253 253 253 253 253 253
45223-253 253 253 246 246 246 218 218 218 202 202 202
45224-210 210 210 14 14 14 2 2 6 2 2 6
45225- 30 30 30 22 22 22 2 2 6 2 2 6
45226- 2 2 6 2 2 6 18 18 18 86 86 86
45227- 42 42 42 14 14 14 0 0 0 0 0 0
45228- 0 0 0 0 0 0 0 0 0 0 0 0
45229- 0 0 0 0 0 0 0 0 0 0 0 0
45230- 0 0 0 0 0 0 0 0 0 0 0 0
45231- 0 0 0 0 0 0 0 0 0 0 0 0
45232- 0 0 0 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 14 14 14
45236- 42 42 42 90 90 90 22 22 22 2 2 6
45237- 42 42 42 2 2 6 18 18 18 218 218 218
45238-253 253 253 253 253 253 253 253 253 253 253 253
45239-253 253 253 253 253 253 253 253 253 253 253 253
45240-253 253 253 253 253 253 253 253 253 253 253 253
45241-253 253 253 253 253 253 253 253 253 253 253 253
45242-253 253 253 253 253 253 253 253 253 253 253 253
45243-253 253 253 253 253 253 250 250 250 221 221 221
45244-218 218 218 101 101 101 2 2 6 14 14 14
45245- 18 18 18 38 38 38 10 10 10 2 2 6
45246- 2 2 6 2 2 6 2 2 6 78 78 78
45247- 58 58 58 22 22 22 6 6 6 0 0 0
45248- 0 0 0 0 0 0 0 0 0 0 0 0
45249- 0 0 0 0 0 0 0 0 0 0 0 0
45250- 0 0 0 0 0 0 0 0 0 0 0 0
45251- 0 0 0 0 0 0 0 0 0 0 0 0
45252- 0 0 0 0 0 0 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 6 6 6 18 18 18
45256- 54 54 54 82 82 82 2 2 6 26 26 26
45257- 22 22 22 2 2 6 123 123 123 253 253 253
45258-253 253 253 253 253 253 253 253 253 253 253 253
45259-253 253 253 253 253 253 253 253 253 253 253 253
45260-253 253 253 253 253 253 253 253 253 253 253 253
45261-253 253 253 253 253 253 253 253 253 253 253 253
45262-253 253 253 253 253 253 253 253 253 253 253 253
45263-253 253 253 253 253 253 253 253 253 250 250 250
45264-238 238 238 198 198 198 6 6 6 38 38 38
45265- 58 58 58 26 26 26 38 38 38 2 2 6
45266- 2 2 6 2 2 6 2 2 6 46 46 46
45267- 78 78 78 30 30 30 10 10 10 0 0 0
45268- 0 0 0 0 0 0 0 0 0 0 0 0
45269- 0 0 0 0 0 0 0 0 0 0 0 0
45270- 0 0 0 0 0 0 0 0 0 0 0 0
45271- 0 0 0 0 0 0 0 0 0 0 0 0
45272- 0 0 0 0 0 0 0 0 0 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 0 0 0
45275- 0 0 0 0 0 0 10 10 10 30 30 30
45276- 74 74 74 58 58 58 2 2 6 42 42 42
45277- 2 2 6 22 22 22 231 231 231 253 253 253
45278-253 253 253 253 253 253 253 253 253 253 253 253
45279-253 253 253 253 253 253 253 253 253 250 250 250
45280-253 253 253 253 253 253 253 253 253 253 253 253
45281-253 253 253 253 253 253 253 253 253 253 253 253
45282-253 253 253 253 253 253 253 253 253 253 253 253
45283-253 253 253 253 253 253 253 253 253 253 253 253
45284-253 253 253 246 246 246 46 46 46 38 38 38
45285- 42 42 42 14 14 14 38 38 38 14 14 14
45286- 2 2 6 2 2 6 2 2 6 6 6 6
45287- 86 86 86 46 46 46 14 14 14 0 0 0
45288- 0 0 0 0 0 0 0 0 0 0 0 0
45289- 0 0 0 0 0 0 0 0 0 0 0 0
45290- 0 0 0 0 0 0 0 0 0 0 0 0
45291- 0 0 0 0 0 0 0 0 0 0 0 0
45292- 0 0 0 0 0 0 0 0 0 0 0 0
45293- 0 0 0 0 0 0 0 0 0 0 0 0
45294- 0 0 0 0 0 0 0 0 0 0 0 0
45295- 0 0 0 6 6 6 14 14 14 42 42 42
45296- 90 90 90 18 18 18 18 18 18 26 26 26
45297- 2 2 6 116 116 116 253 253 253 253 253 253
45298-253 253 253 253 253 253 253 253 253 253 253 253
45299-253 253 253 253 253 253 250 250 250 238 238 238
45300-253 253 253 253 253 253 253 253 253 253 253 253
45301-253 253 253 253 253 253 253 253 253 253 253 253
45302-253 253 253 253 253 253 253 253 253 253 253 253
45303-253 253 253 253 253 253 253 253 253 253 253 253
45304-253 253 253 253 253 253 94 94 94 6 6 6
45305- 2 2 6 2 2 6 10 10 10 34 34 34
45306- 2 2 6 2 2 6 2 2 6 2 2 6
45307- 74 74 74 58 58 58 22 22 22 6 6 6
45308- 0 0 0 0 0 0 0 0 0 0 0 0
45309- 0 0 0 0 0 0 0 0 0 0 0 0
45310- 0 0 0 0 0 0 0 0 0 0 0 0
45311- 0 0 0 0 0 0 0 0 0 0 0 0
45312- 0 0 0 0 0 0 0 0 0 0 0 0
45313- 0 0 0 0 0 0 0 0 0 0 0 0
45314- 0 0 0 0 0 0 0 0 0 0 0 0
45315- 0 0 0 10 10 10 26 26 26 66 66 66
45316- 82 82 82 2 2 6 38 38 38 6 6 6
45317- 14 14 14 210 210 210 253 253 253 253 253 253
45318-253 253 253 253 253 253 253 253 253 253 253 253
45319-253 253 253 253 253 253 246 246 246 242 242 242
45320-253 253 253 253 253 253 253 253 253 253 253 253
45321-253 253 253 253 253 253 253 253 253 253 253 253
45322-253 253 253 253 253 253 253 253 253 253 253 253
45323-253 253 253 253 253 253 253 253 253 253 253 253
45324-253 253 253 253 253 253 144 144 144 2 2 6
45325- 2 2 6 2 2 6 2 2 6 46 46 46
45326- 2 2 6 2 2 6 2 2 6 2 2 6
45327- 42 42 42 74 74 74 30 30 30 10 10 10
45328- 0 0 0 0 0 0 0 0 0 0 0 0
45329- 0 0 0 0 0 0 0 0 0 0 0 0
45330- 0 0 0 0 0 0 0 0 0 0 0 0
45331- 0 0 0 0 0 0 0 0 0 0 0 0
45332- 0 0 0 0 0 0 0 0 0 0 0 0
45333- 0 0 0 0 0 0 0 0 0 0 0 0
45334- 0 0 0 0 0 0 0 0 0 0 0 0
45335- 6 6 6 14 14 14 42 42 42 90 90 90
45336- 26 26 26 6 6 6 42 42 42 2 2 6
45337- 74 74 74 250 250 250 253 253 253 253 253 253
45338-253 253 253 253 253 253 253 253 253 253 253 253
45339-253 253 253 253 253 253 242 242 242 242 242 242
45340-253 253 253 253 253 253 253 253 253 253 253 253
45341-253 253 253 253 253 253 253 253 253 253 253 253
45342-253 253 253 253 253 253 253 253 253 253 253 253
45343-253 253 253 253 253 253 253 253 253 253 253 253
45344-253 253 253 253 253 253 182 182 182 2 2 6
45345- 2 2 6 2 2 6 2 2 6 46 46 46
45346- 2 2 6 2 2 6 2 2 6 2 2 6
45347- 10 10 10 86 86 86 38 38 38 10 10 10
45348- 0 0 0 0 0 0 0 0 0 0 0 0
45349- 0 0 0 0 0 0 0 0 0 0 0 0
45350- 0 0 0 0 0 0 0 0 0 0 0 0
45351- 0 0 0 0 0 0 0 0 0 0 0 0
45352- 0 0 0 0 0 0 0 0 0 0 0 0
45353- 0 0 0 0 0 0 0 0 0 0 0 0
45354- 0 0 0 0 0 0 0 0 0 0 0 0
45355- 10 10 10 26 26 26 66 66 66 82 82 82
45356- 2 2 6 22 22 22 18 18 18 2 2 6
45357-149 149 149 253 253 253 253 253 253 253 253 253
45358-253 253 253 253 253 253 253 253 253 253 253 253
45359-253 253 253 253 253 253 234 234 234 242 242 242
45360-253 253 253 253 253 253 253 253 253 253 253 253
45361-253 253 253 253 253 253 253 253 253 253 253 253
45362-253 253 253 253 253 253 253 253 253 253 253 253
45363-253 253 253 253 253 253 253 253 253 253 253 253
45364-253 253 253 253 253 253 206 206 206 2 2 6
45365- 2 2 6 2 2 6 2 2 6 38 38 38
45366- 2 2 6 2 2 6 2 2 6 2 2 6
45367- 6 6 6 86 86 86 46 46 46 14 14 14
45368- 0 0 0 0 0 0 0 0 0 0 0 0
45369- 0 0 0 0 0 0 0 0 0 0 0 0
45370- 0 0 0 0 0 0 0 0 0 0 0 0
45371- 0 0 0 0 0 0 0 0 0 0 0 0
45372- 0 0 0 0 0 0 0 0 0 0 0 0
45373- 0 0 0 0 0 0 0 0 0 0 0 0
45374- 0 0 0 0 0 0 0 0 0 6 6 6
45375- 18 18 18 46 46 46 86 86 86 18 18 18
45376- 2 2 6 34 34 34 10 10 10 6 6 6
45377-210 210 210 253 253 253 253 253 253 253 253 253
45378-253 253 253 253 253 253 253 253 253 253 253 253
45379-253 253 253 253 253 253 234 234 234 242 242 242
45380-253 253 253 253 253 253 253 253 253 253 253 253
45381-253 253 253 253 253 253 253 253 253 253 253 253
45382-253 253 253 253 253 253 253 253 253 253 253 253
45383-253 253 253 253 253 253 253 253 253 253 253 253
45384-253 253 253 253 253 253 221 221 221 6 6 6
45385- 2 2 6 2 2 6 6 6 6 30 30 30
45386- 2 2 6 2 2 6 2 2 6 2 2 6
45387- 2 2 6 82 82 82 54 54 54 18 18 18
45388- 6 6 6 0 0 0 0 0 0 0 0 0
45389- 0 0 0 0 0 0 0 0 0 0 0 0
45390- 0 0 0 0 0 0 0 0 0 0 0 0
45391- 0 0 0 0 0 0 0 0 0 0 0 0
45392- 0 0 0 0 0 0 0 0 0 0 0 0
45393- 0 0 0 0 0 0 0 0 0 0 0 0
45394- 0 0 0 0 0 0 0 0 0 10 10 10
45395- 26 26 26 66 66 66 62 62 62 2 2 6
45396- 2 2 6 38 38 38 10 10 10 26 26 26
45397-238 238 238 253 253 253 253 253 253 253 253 253
45398-253 253 253 253 253 253 253 253 253 253 253 253
45399-253 253 253 253 253 253 231 231 231 238 238 238
45400-253 253 253 253 253 253 253 253 253 253 253 253
45401-253 253 253 253 253 253 253 253 253 253 253 253
45402-253 253 253 253 253 253 253 253 253 253 253 253
45403-253 253 253 253 253 253 253 253 253 253 253 253
45404-253 253 253 253 253 253 231 231 231 6 6 6
45405- 2 2 6 2 2 6 10 10 10 30 30 30
45406- 2 2 6 2 2 6 2 2 6 2 2 6
45407- 2 2 6 66 66 66 58 58 58 22 22 22
45408- 6 6 6 0 0 0 0 0 0 0 0 0
45409- 0 0 0 0 0 0 0 0 0 0 0 0
45410- 0 0 0 0 0 0 0 0 0 0 0 0
45411- 0 0 0 0 0 0 0 0 0 0 0 0
45412- 0 0 0 0 0 0 0 0 0 0 0 0
45413- 0 0 0 0 0 0 0 0 0 0 0 0
45414- 0 0 0 0 0 0 0 0 0 10 10 10
45415- 38 38 38 78 78 78 6 6 6 2 2 6
45416- 2 2 6 46 46 46 14 14 14 42 42 42
45417-246 246 246 253 253 253 253 253 253 253 253 253
45418-253 253 253 253 253 253 253 253 253 253 253 253
45419-253 253 253 253 253 253 231 231 231 242 242 242
45420-253 253 253 253 253 253 253 253 253 253 253 253
45421-253 253 253 253 253 253 253 253 253 253 253 253
45422-253 253 253 253 253 253 253 253 253 253 253 253
45423-253 253 253 253 253 253 253 253 253 253 253 253
45424-253 253 253 253 253 253 234 234 234 10 10 10
45425- 2 2 6 2 2 6 22 22 22 14 14 14
45426- 2 2 6 2 2 6 2 2 6 2 2 6
45427- 2 2 6 66 66 66 62 62 62 22 22 22
45428- 6 6 6 0 0 0 0 0 0 0 0 0
45429- 0 0 0 0 0 0 0 0 0 0 0 0
45430- 0 0 0 0 0 0 0 0 0 0 0 0
45431- 0 0 0 0 0 0 0 0 0 0 0 0
45432- 0 0 0 0 0 0 0 0 0 0 0 0
45433- 0 0 0 0 0 0 0 0 0 0 0 0
45434- 0 0 0 0 0 0 6 6 6 18 18 18
45435- 50 50 50 74 74 74 2 2 6 2 2 6
45436- 14 14 14 70 70 70 34 34 34 62 62 62
45437-250 250 250 253 253 253 253 253 253 253 253 253
45438-253 253 253 253 253 253 253 253 253 253 253 253
45439-253 253 253 253 253 253 231 231 231 246 246 246
45440-253 253 253 253 253 253 253 253 253 253 253 253
45441-253 253 253 253 253 253 253 253 253 253 253 253
45442-253 253 253 253 253 253 253 253 253 253 253 253
45443-253 253 253 253 253 253 253 253 253 253 253 253
45444-253 253 253 253 253 253 234 234 234 14 14 14
45445- 2 2 6 2 2 6 30 30 30 2 2 6
45446- 2 2 6 2 2 6 2 2 6 2 2 6
45447- 2 2 6 66 66 66 62 62 62 22 22 22
45448- 6 6 6 0 0 0 0 0 0 0 0 0
45449- 0 0 0 0 0 0 0 0 0 0 0 0
45450- 0 0 0 0 0 0 0 0 0 0 0 0
45451- 0 0 0 0 0 0 0 0 0 0 0 0
45452- 0 0 0 0 0 0 0 0 0 0 0 0
45453- 0 0 0 0 0 0 0 0 0 0 0 0
45454- 0 0 0 0 0 0 6 6 6 18 18 18
45455- 54 54 54 62 62 62 2 2 6 2 2 6
45456- 2 2 6 30 30 30 46 46 46 70 70 70
45457-250 250 250 253 253 253 253 253 253 253 253 253
45458-253 253 253 253 253 253 253 253 253 253 253 253
45459-253 253 253 253 253 253 231 231 231 246 246 246
45460-253 253 253 253 253 253 253 253 253 253 253 253
45461-253 253 253 253 253 253 253 253 253 253 253 253
45462-253 253 253 253 253 253 253 253 253 253 253 253
45463-253 253 253 253 253 253 253 253 253 253 253 253
45464-253 253 253 253 253 253 226 226 226 10 10 10
45465- 2 2 6 6 6 6 30 30 30 2 2 6
45466- 2 2 6 2 2 6 2 2 6 2 2 6
45467- 2 2 6 66 66 66 58 58 58 22 22 22
45468- 6 6 6 0 0 0 0 0 0 0 0 0
45469- 0 0 0 0 0 0 0 0 0 0 0 0
45470- 0 0 0 0 0 0 0 0 0 0 0 0
45471- 0 0 0 0 0 0 0 0 0 0 0 0
45472- 0 0 0 0 0 0 0 0 0 0 0 0
45473- 0 0 0 0 0 0 0 0 0 0 0 0
45474- 0 0 0 0 0 0 6 6 6 22 22 22
45475- 58 58 58 62 62 62 2 2 6 2 2 6
45476- 2 2 6 2 2 6 30 30 30 78 78 78
45477-250 250 250 253 253 253 253 253 253 253 253 253
45478-253 253 253 253 253 253 253 253 253 253 253 253
45479-253 253 253 253 253 253 231 231 231 246 246 246
45480-253 253 253 253 253 253 253 253 253 253 253 253
45481-253 253 253 253 253 253 253 253 253 253 253 253
45482-253 253 253 253 253 253 253 253 253 253 253 253
45483-253 253 253 253 253 253 253 253 253 253 253 253
45484-253 253 253 253 253 253 206 206 206 2 2 6
45485- 22 22 22 34 34 34 18 14 6 22 22 22
45486- 26 26 26 18 18 18 6 6 6 2 2 6
45487- 2 2 6 82 82 82 54 54 54 18 18 18
45488- 6 6 6 0 0 0 0 0 0 0 0 0
45489- 0 0 0 0 0 0 0 0 0 0 0 0
45490- 0 0 0 0 0 0 0 0 0 0 0 0
45491- 0 0 0 0 0 0 0 0 0 0 0 0
45492- 0 0 0 0 0 0 0 0 0 0 0 0
45493- 0 0 0 0 0 0 0 0 0 0 0 0
45494- 0 0 0 0 0 0 6 6 6 26 26 26
45495- 62 62 62 106 106 106 74 54 14 185 133 11
45496-210 162 10 121 92 8 6 6 6 62 62 62
45497-238 238 238 253 253 253 253 253 253 253 253 253
45498-253 253 253 253 253 253 253 253 253 253 253 253
45499-253 253 253 253 253 253 231 231 231 246 246 246
45500-253 253 253 253 253 253 253 253 253 253 253 253
45501-253 253 253 253 253 253 253 253 253 253 253 253
45502-253 253 253 253 253 253 253 253 253 253 253 253
45503-253 253 253 253 253 253 253 253 253 253 253 253
45504-253 253 253 253 253 253 158 158 158 18 18 18
45505- 14 14 14 2 2 6 2 2 6 2 2 6
45506- 6 6 6 18 18 18 66 66 66 38 38 38
45507- 6 6 6 94 94 94 50 50 50 18 18 18
45508- 6 6 6 0 0 0 0 0 0 0 0 0
45509- 0 0 0 0 0 0 0 0 0 0 0 0
45510- 0 0 0 0 0 0 0 0 0 0 0 0
45511- 0 0 0 0 0 0 0 0 0 0 0 0
45512- 0 0 0 0 0 0 0 0 0 0 0 0
45513- 0 0 0 0 0 0 0 0 0 6 6 6
45514- 10 10 10 10 10 10 18 18 18 38 38 38
45515- 78 78 78 142 134 106 216 158 10 242 186 14
45516-246 190 14 246 190 14 156 118 10 10 10 10
45517- 90 90 90 238 238 238 253 253 253 253 253 253
45518-253 253 253 253 253 253 253 253 253 253 253 253
45519-253 253 253 253 253 253 231 231 231 250 250 250
45520-253 253 253 253 253 253 253 253 253 253 253 253
45521-253 253 253 253 253 253 253 253 253 253 253 253
45522-253 253 253 253 253 253 253 253 253 253 253 253
45523-253 253 253 253 253 253 253 253 253 246 230 190
45524-238 204 91 238 204 91 181 142 44 37 26 9
45525- 2 2 6 2 2 6 2 2 6 2 2 6
45526- 2 2 6 2 2 6 38 38 38 46 46 46
45527- 26 26 26 106 106 106 54 54 54 18 18 18
45528- 6 6 6 0 0 0 0 0 0 0 0 0
45529- 0 0 0 0 0 0 0 0 0 0 0 0
45530- 0 0 0 0 0 0 0 0 0 0 0 0
45531- 0 0 0 0 0 0 0 0 0 0 0 0
45532- 0 0 0 0 0 0 0 0 0 0 0 0
45533- 0 0 0 6 6 6 14 14 14 22 22 22
45534- 30 30 30 38 38 38 50 50 50 70 70 70
45535-106 106 106 190 142 34 226 170 11 242 186 14
45536-246 190 14 246 190 14 246 190 14 154 114 10
45537- 6 6 6 74 74 74 226 226 226 253 253 253
45538-253 253 253 253 253 253 253 253 253 253 253 253
45539-253 253 253 253 253 253 231 231 231 250 250 250
45540-253 253 253 253 253 253 253 253 253 253 253 253
45541-253 253 253 253 253 253 253 253 253 253 253 253
45542-253 253 253 253 253 253 253 253 253 253 253 253
45543-253 253 253 253 253 253 253 253 253 228 184 62
45544-241 196 14 241 208 19 232 195 16 38 30 10
45545- 2 2 6 2 2 6 2 2 6 2 2 6
45546- 2 2 6 6 6 6 30 30 30 26 26 26
45547-203 166 17 154 142 90 66 66 66 26 26 26
45548- 6 6 6 0 0 0 0 0 0 0 0 0
45549- 0 0 0 0 0 0 0 0 0 0 0 0
45550- 0 0 0 0 0 0 0 0 0 0 0 0
45551- 0 0 0 0 0 0 0 0 0 0 0 0
45552- 0 0 0 0 0 0 0 0 0 0 0 0
45553- 6 6 6 18 18 18 38 38 38 58 58 58
45554- 78 78 78 86 86 86 101 101 101 123 123 123
45555-175 146 61 210 150 10 234 174 13 246 186 14
45556-246 190 14 246 190 14 246 190 14 238 190 10
45557-102 78 10 2 2 6 46 46 46 198 198 198
45558-253 253 253 253 253 253 253 253 253 253 253 253
45559-253 253 253 253 253 253 234 234 234 242 242 242
45560-253 253 253 253 253 253 253 253 253 253 253 253
45561-253 253 253 253 253 253 253 253 253 253 253 253
45562-253 253 253 253 253 253 253 253 253 253 253 253
45563-253 253 253 253 253 253 253 253 253 224 178 62
45564-242 186 14 241 196 14 210 166 10 22 18 6
45565- 2 2 6 2 2 6 2 2 6 2 2 6
45566- 2 2 6 2 2 6 6 6 6 121 92 8
45567-238 202 15 232 195 16 82 82 82 34 34 34
45568- 10 10 10 0 0 0 0 0 0 0 0 0
45569- 0 0 0 0 0 0 0 0 0 0 0 0
45570- 0 0 0 0 0 0 0 0 0 0 0 0
45571- 0 0 0 0 0 0 0 0 0 0 0 0
45572- 0 0 0 0 0 0 0 0 0 0 0 0
45573- 14 14 14 38 38 38 70 70 70 154 122 46
45574-190 142 34 200 144 11 197 138 11 197 138 11
45575-213 154 11 226 170 11 242 186 14 246 190 14
45576-246 190 14 246 190 14 246 190 14 246 190 14
45577-225 175 15 46 32 6 2 2 6 22 22 22
45578-158 158 158 250 250 250 253 253 253 253 253 253
45579-253 253 253 253 253 253 253 253 253 253 253 253
45580-253 253 253 253 253 253 253 253 253 253 253 253
45581-253 253 253 253 253 253 253 253 253 253 253 253
45582-253 253 253 253 253 253 253 253 253 253 253 253
45583-253 253 253 250 250 250 242 242 242 224 178 62
45584-239 182 13 236 186 11 213 154 11 46 32 6
45585- 2 2 6 2 2 6 2 2 6 2 2 6
45586- 2 2 6 2 2 6 61 42 6 225 175 15
45587-238 190 10 236 186 11 112 100 78 42 42 42
45588- 14 14 14 0 0 0 0 0 0 0 0 0
45589- 0 0 0 0 0 0 0 0 0 0 0 0
45590- 0 0 0 0 0 0 0 0 0 0 0 0
45591- 0 0 0 0 0 0 0 0 0 0 0 0
45592- 0 0 0 0 0 0 0 0 0 6 6 6
45593- 22 22 22 54 54 54 154 122 46 213 154 11
45594-226 170 11 230 174 11 226 170 11 226 170 11
45595-236 178 12 242 186 14 246 190 14 246 190 14
45596-246 190 14 246 190 14 246 190 14 246 190 14
45597-241 196 14 184 144 12 10 10 10 2 2 6
45598- 6 6 6 116 116 116 242 242 242 253 253 253
45599-253 253 253 253 253 253 253 253 253 253 253 253
45600-253 253 253 253 253 253 253 253 253 253 253 253
45601-253 253 253 253 253 253 253 253 253 253 253 253
45602-253 253 253 253 253 253 253 253 253 253 253 253
45603-253 253 253 231 231 231 198 198 198 214 170 54
45604-236 178 12 236 178 12 210 150 10 137 92 6
45605- 18 14 6 2 2 6 2 2 6 2 2 6
45606- 6 6 6 70 47 6 200 144 11 236 178 12
45607-239 182 13 239 182 13 124 112 88 58 58 58
45608- 22 22 22 6 6 6 0 0 0 0 0 0
45609- 0 0 0 0 0 0 0 0 0 0 0 0
45610- 0 0 0 0 0 0 0 0 0 0 0 0
45611- 0 0 0 0 0 0 0 0 0 0 0 0
45612- 0 0 0 0 0 0 0 0 0 10 10 10
45613- 30 30 30 70 70 70 180 133 36 226 170 11
45614-239 182 13 242 186 14 242 186 14 246 186 14
45615-246 190 14 246 190 14 246 190 14 246 190 14
45616-246 190 14 246 190 14 246 190 14 246 190 14
45617-246 190 14 232 195 16 98 70 6 2 2 6
45618- 2 2 6 2 2 6 66 66 66 221 221 221
45619-253 253 253 253 253 253 253 253 253 253 253 253
45620-253 253 253 253 253 253 253 253 253 253 253 253
45621-253 253 253 253 253 253 253 253 253 253 253 253
45622-253 253 253 253 253 253 253 253 253 253 253 253
45623-253 253 253 206 206 206 198 198 198 214 166 58
45624-230 174 11 230 174 11 216 158 10 192 133 9
45625-163 110 8 116 81 8 102 78 10 116 81 8
45626-167 114 7 197 138 11 226 170 11 239 182 13
45627-242 186 14 242 186 14 162 146 94 78 78 78
45628- 34 34 34 14 14 14 6 6 6 0 0 0
45629- 0 0 0 0 0 0 0 0 0 0 0 0
45630- 0 0 0 0 0 0 0 0 0 0 0 0
45631- 0 0 0 0 0 0 0 0 0 0 0 0
45632- 0 0 0 0 0 0 0 0 0 6 6 6
45633- 30 30 30 78 78 78 190 142 34 226 170 11
45634-239 182 13 246 190 14 246 190 14 246 190 14
45635-246 190 14 246 190 14 246 190 14 246 190 14
45636-246 190 14 246 190 14 246 190 14 246 190 14
45637-246 190 14 241 196 14 203 166 17 22 18 6
45638- 2 2 6 2 2 6 2 2 6 38 38 38
45639-218 218 218 253 253 253 253 253 253 253 253 253
45640-253 253 253 253 253 253 253 253 253 253 253 253
45641-253 253 253 253 253 253 253 253 253 253 253 253
45642-253 253 253 253 253 253 253 253 253 253 253 253
45643-250 250 250 206 206 206 198 198 198 202 162 69
45644-226 170 11 236 178 12 224 166 10 210 150 10
45645-200 144 11 197 138 11 192 133 9 197 138 11
45646-210 150 10 226 170 11 242 186 14 246 190 14
45647-246 190 14 246 186 14 225 175 15 124 112 88
45648- 62 62 62 30 30 30 14 14 14 6 6 6
45649- 0 0 0 0 0 0 0 0 0 0 0 0
45650- 0 0 0 0 0 0 0 0 0 0 0 0
45651- 0 0 0 0 0 0 0 0 0 0 0 0
45652- 0 0 0 0 0 0 0 0 0 10 10 10
45653- 30 30 30 78 78 78 174 135 50 224 166 10
45654-239 182 13 246 190 14 246 190 14 246 190 14
45655-246 190 14 246 190 14 246 190 14 246 190 14
45656-246 190 14 246 190 14 246 190 14 246 190 14
45657-246 190 14 246 190 14 241 196 14 139 102 15
45658- 2 2 6 2 2 6 2 2 6 2 2 6
45659- 78 78 78 250 250 250 253 253 253 253 253 253
45660-253 253 253 253 253 253 253 253 253 253 253 253
45661-253 253 253 253 253 253 253 253 253 253 253 253
45662-253 253 253 253 253 253 253 253 253 253 253 253
45663-250 250 250 214 214 214 198 198 198 190 150 46
45664-219 162 10 236 178 12 234 174 13 224 166 10
45665-216 158 10 213 154 11 213 154 11 216 158 10
45666-226 170 11 239 182 13 246 190 14 246 190 14
45667-246 190 14 246 190 14 242 186 14 206 162 42
45668-101 101 101 58 58 58 30 30 30 14 14 14
45669- 6 6 6 0 0 0 0 0 0 0 0 0
45670- 0 0 0 0 0 0 0 0 0 0 0 0
45671- 0 0 0 0 0 0 0 0 0 0 0 0
45672- 0 0 0 0 0 0 0 0 0 10 10 10
45673- 30 30 30 74 74 74 174 135 50 216 158 10
45674-236 178 12 246 190 14 246 190 14 246 190 14
45675-246 190 14 246 190 14 246 190 14 246 190 14
45676-246 190 14 246 190 14 246 190 14 246 190 14
45677-246 190 14 246 190 14 241 196 14 226 184 13
45678- 61 42 6 2 2 6 2 2 6 2 2 6
45679- 22 22 22 238 238 238 253 253 253 253 253 253
45680-253 253 253 253 253 253 253 253 253 253 253 253
45681-253 253 253 253 253 253 253 253 253 253 253 253
45682-253 253 253 253 253 253 253 253 253 253 253 253
45683-253 253 253 226 226 226 187 187 187 180 133 36
45684-216 158 10 236 178 12 239 182 13 236 178 12
45685-230 174 11 226 170 11 226 170 11 230 174 11
45686-236 178 12 242 186 14 246 190 14 246 190 14
45687-246 190 14 246 190 14 246 186 14 239 182 13
45688-206 162 42 106 106 106 66 66 66 34 34 34
45689- 14 14 14 6 6 6 0 0 0 0 0 0
45690- 0 0 0 0 0 0 0 0 0 0 0 0
45691- 0 0 0 0 0 0 0 0 0 0 0 0
45692- 0 0 0 0 0 0 0 0 0 6 6 6
45693- 26 26 26 70 70 70 163 133 67 213 154 11
45694-236 178 12 246 190 14 246 190 14 246 190 14
45695-246 190 14 246 190 14 246 190 14 246 190 14
45696-246 190 14 246 190 14 246 190 14 246 190 14
45697-246 190 14 246 190 14 246 190 14 241 196 14
45698-190 146 13 18 14 6 2 2 6 2 2 6
45699- 46 46 46 246 246 246 253 253 253 253 253 253
45700-253 253 253 253 253 253 253 253 253 253 253 253
45701-253 253 253 253 253 253 253 253 253 253 253 253
45702-253 253 253 253 253 253 253 253 253 253 253 253
45703-253 253 253 221 221 221 86 86 86 156 107 11
45704-216 158 10 236 178 12 242 186 14 246 186 14
45705-242 186 14 239 182 13 239 182 13 242 186 14
45706-242 186 14 246 186 14 246 190 14 246 190 14
45707-246 190 14 246 190 14 246 190 14 246 190 14
45708-242 186 14 225 175 15 142 122 72 66 66 66
45709- 30 30 30 10 10 10 0 0 0 0 0 0
45710- 0 0 0 0 0 0 0 0 0 0 0 0
45711- 0 0 0 0 0 0 0 0 0 0 0 0
45712- 0 0 0 0 0 0 0 0 0 6 6 6
45713- 26 26 26 70 70 70 163 133 67 210 150 10
45714-236 178 12 246 190 14 246 190 14 246 190 14
45715-246 190 14 246 190 14 246 190 14 246 190 14
45716-246 190 14 246 190 14 246 190 14 246 190 14
45717-246 190 14 246 190 14 246 190 14 246 190 14
45718-232 195 16 121 92 8 34 34 34 106 106 106
45719-221 221 221 253 253 253 253 253 253 253 253 253
45720-253 253 253 253 253 253 253 253 253 253 253 253
45721-253 253 253 253 253 253 253 253 253 253 253 253
45722-253 253 253 253 253 253 253 253 253 253 253 253
45723-242 242 242 82 82 82 18 14 6 163 110 8
45724-216 158 10 236 178 12 242 186 14 246 190 14
45725-246 190 14 246 190 14 246 190 14 246 190 14
45726-246 190 14 246 190 14 246 190 14 246 190 14
45727-246 190 14 246 190 14 246 190 14 246 190 14
45728-246 190 14 246 190 14 242 186 14 163 133 67
45729- 46 46 46 18 18 18 6 6 6 0 0 0
45730- 0 0 0 0 0 0 0 0 0 0 0 0
45731- 0 0 0 0 0 0 0 0 0 0 0 0
45732- 0 0 0 0 0 0 0 0 0 10 10 10
45733- 30 30 30 78 78 78 163 133 67 210 150 10
45734-236 178 12 246 186 14 246 190 14 246 190 14
45735-246 190 14 246 190 14 246 190 14 246 190 14
45736-246 190 14 246 190 14 246 190 14 246 190 14
45737-246 190 14 246 190 14 246 190 14 246 190 14
45738-241 196 14 215 174 15 190 178 144 253 253 253
45739-253 253 253 253 253 253 253 253 253 253 253 253
45740-253 253 253 253 253 253 253 253 253 253 253 253
45741-253 253 253 253 253 253 253 253 253 253 253 253
45742-253 253 253 253 253 253 253 253 253 218 218 218
45743- 58 58 58 2 2 6 22 18 6 167 114 7
45744-216 158 10 236 178 12 246 186 14 246 190 14
45745-246 190 14 246 190 14 246 190 14 246 190 14
45746-246 190 14 246 190 14 246 190 14 246 190 14
45747-246 190 14 246 190 14 246 190 14 246 190 14
45748-246 190 14 246 186 14 242 186 14 190 150 46
45749- 54 54 54 22 22 22 6 6 6 0 0 0
45750- 0 0 0 0 0 0 0 0 0 0 0 0
45751- 0 0 0 0 0 0 0 0 0 0 0 0
45752- 0 0 0 0 0 0 0 0 0 14 14 14
45753- 38 38 38 86 86 86 180 133 36 213 154 11
45754-236 178 12 246 186 14 246 190 14 246 190 14
45755-246 190 14 246 190 14 246 190 14 246 190 14
45756-246 190 14 246 190 14 246 190 14 246 190 14
45757-246 190 14 246 190 14 246 190 14 246 190 14
45758-246 190 14 232 195 16 190 146 13 214 214 214
45759-253 253 253 253 253 253 253 253 253 253 253 253
45760-253 253 253 253 253 253 253 253 253 253 253 253
45761-253 253 253 253 253 253 253 253 253 253 253 253
45762-253 253 253 250 250 250 170 170 170 26 26 26
45763- 2 2 6 2 2 6 37 26 9 163 110 8
45764-219 162 10 239 182 13 246 186 14 246 190 14
45765-246 190 14 246 190 14 246 190 14 246 190 14
45766-246 190 14 246 190 14 246 190 14 246 190 14
45767-246 190 14 246 190 14 246 190 14 246 190 14
45768-246 186 14 236 178 12 224 166 10 142 122 72
45769- 46 46 46 18 18 18 6 6 6 0 0 0
45770- 0 0 0 0 0 0 0 0 0 0 0 0
45771- 0 0 0 0 0 0 0 0 0 0 0 0
45772- 0 0 0 0 0 0 6 6 6 18 18 18
45773- 50 50 50 109 106 95 192 133 9 224 166 10
45774-242 186 14 246 190 14 246 190 14 246 190 14
45775-246 190 14 246 190 14 246 190 14 246 190 14
45776-246 190 14 246 190 14 246 190 14 246 190 14
45777-246 190 14 246 190 14 246 190 14 246 190 14
45778-242 186 14 226 184 13 210 162 10 142 110 46
45779-226 226 226 253 253 253 253 253 253 253 253 253
45780-253 253 253 253 253 253 253 253 253 253 253 253
45781-253 253 253 253 253 253 253 253 253 253 253 253
45782-198 198 198 66 66 66 2 2 6 2 2 6
45783- 2 2 6 2 2 6 50 34 6 156 107 11
45784-219 162 10 239 182 13 246 186 14 246 190 14
45785-246 190 14 246 190 14 246 190 14 246 190 14
45786-246 190 14 246 190 14 246 190 14 246 190 14
45787-246 190 14 246 190 14 246 190 14 242 186 14
45788-234 174 13 213 154 11 154 122 46 66 66 66
45789- 30 30 30 10 10 10 0 0 0 0 0 0
45790- 0 0 0 0 0 0 0 0 0 0 0 0
45791- 0 0 0 0 0 0 0 0 0 0 0 0
45792- 0 0 0 0 0 0 6 6 6 22 22 22
45793- 58 58 58 154 121 60 206 145 10 234 174 13
45794-242 186 14 246 186 14 246 190 14 246 190 14
45795-246 190 14 246 190 14 246 190 14 246 190 14
45796-246 190 14 246 190 14 246 190 14 246 190 14
45797-246 190 14 246 190 14 246 190 14 246 190 14
45798-246 186 14 236 178 12 210 162 10 163 110 8
45799- 61 42 6 138 138 138 218 218 218 250 250 250
45800-253 253 253 253 253 253 253 253 253 250 250 250
45801-242 242 242 210 210 210 144 144 144 66 66 66
45802- 6 6 6 2 2 6 2 2 6 2 2 6
45803- 2 2 6 2 2 6 61 42 6 163 110 8
45804-216 158 10 236 178 12 246 190 14 246 190 14
45805-246 190 14 246 190 14 246 190 14 246 190 14
45806-246 190 14 246 190 14 246 190 14 246 190 14
45807-246 190 14 239 182 13 230 174 11 216 158 10
45808-190 142 34 124 112 88 70 70 70 38 38 38
45809- 18 18 18 6 6 6 0 0 0 0 0 0
45810- 0 0 0 0 0 0 0 0 0 0 0 0
45811- 0 0 0 0 0 0 0 0 0 0 0 0
45812- 0 0 0 0 0 0 6 6 6 22 22 22
45813- 62 62 62 168 124 44 206 145 10 224 166 10
45814-236 178 12 239 182 13 242 186 14 242 186 14
45815-246 186 14 246 190 14 246 190 14 246 190 14
45816-246 190 14 246 190 14 246 190 14 246 190 14
45817-246 190 14 246 190 14 246 190 14 246 190 14
45818-246 190 14 236 178 12 216 158 10 175 118 6
45819- 80 54 7 2 2 6 6 6 6 30 30 30
45820- 54 54 54 62 62 62 50 50 50 38 38 38
45821- 14 14 14 2 2 6 2 2 6 2 2 6
45822- 2 2 6 2 2 6 2 2 6 2 2 6
45823- 2 2 6 6 6 6 80 54 7 167 114 7
45824-213 154 11 236 178 12 246 190 14 246 190 14
45825-246 190 14 246 190 14 246 190 14 246 190 14
45826-246 190 14 242 186 14 239 182 13 239 182 13
45827-230 174 11 210 150 10 174 135 50 124 112 88
45828- 82 82 82 54 54 54 34 34 34 18 18 18
45829- 6 6 6 0 0 0 0 0 0 0 0 0
45830- 0 0 0 0 0 0 0 0 0 0 0 0
45831- 0 0 0 0 0 0 0 0 0 0 0 0
45832- 0 0 0 0 0 0 6 6 6 18 18 18
45833- 50 50 50 158 118 36 192 133 9 200 144 11
45834-216 158 10 219 162 10 224 166 10 226 170 11
45835-230 174 11 236 178 12 239 182 13 239 182 13
45836-242 186 14 246 186 14 246 190 14 246 190 14
45837-246 190 14 246 190 14 246 190 14 246 190 14
45838-246 186 14 230 174 11 210 150 10 163 110 8
45839-104 69 6 10 10 10 2 2 6 2 2 6
45840- 2 2 6 2 2 6 2 2 6 2 2 6
45841- 2 2 6 2 2 6 2 2 6 2 2 6
45842- 2 2 6 2 2 6 2 2 6 2 2 6
45843- 2 2 6 6 6 6 91 60 6 167 114 7
45844-206 145 10 230 174 11 242 186 14 246 190 14
45845-246 190 14 246 190 14 246 186 14 242 186 14
45846-239 182 13 230 174 11 224 166 10 213 154 11
45847-180 133 36 124 112 88 86 86 86 58 58 58
45848- 38 38 38 22 22 22 10 10 10 6 6 6
45849- 0 0 0 0 0 0 0 0 0 0 0 0
45850- 0 0 0 0 0 0 0 0 0 0 0 0
45851- 0 0 0 0 0 0 0 0 0 0 0 0
45852- 0 0 0 0 0 0 0 0 0 14 14 14
45853- 34 34 34 70 70 70 138 110 50 158 118 36
45854-167 114 7 180 123 7 192 133 9 197 138 11
45855-200 144 11 206 145 10 213 154 11 219 162 10
45856-224 166 10 230 174 11 239 182 13 242 186 14
45857-246 186 14 246 186 14 246 186 14 246 186 14
45858-239 182 13 216 158 10 185 133 11 152 99 6
45859-104 69 6 18 14 6 2 2 6 2 2 6
45860- 2 2 6 2 2 6 2 2 6 2 2 6
45861- 2 2 6 2 2 6 2 2 6 2 2 6
45862- 2 2 6 2 2 6 2 2 6 2 2 6
45863- 2 2 6 6 6 6 80 54 7 152 99 6
45864-192 133 9 219 162 10 236 178 12 239 182 13
45865-246 186 14 242 186 14 239 182 13 236 178 12
45866-224 166 10 206 145 10 192 133 9 154 121 60
45867- 94 94 94 62 62 62 42 42 42 22 22 22
45868- 14 14 14 6 6 6 0 0 0 0 0 0
45869- 0 0 0 0 0 0 0 0 0 0 0 0
45870- 0 0 0 0 0 0 0 0 0 0 0 0
45871- 0 0 0 0 0 0 0 0 0 0 0 0
45872- 0 0 0 0 0 0 0 0 0 6 6 6
45873- 18 18 18 34 34 34 58 58 58 78 78 78
45874-101 98 89 124 112 88 142 110 46 156 107 11
45875-163 110 8 167 114 7 175 118 6 180 123 7
45876-185 133 11 197 138 11 210 150 10 219 162 10
45877-226 170 11 236 178 12 236 178 12 234 174 13
45878-219 162 10 197 138 11 163 110 8 130 83 6
45879- 91 60 6 10 10 10 2 2 6 2 2 6
45880- 18 18 18 38 38 38 38 38 38 38 38 38
45881- 38 38 38 38 38 38 38 38 38 38 38 38
45882- 38 38 38 38 38 38 26 26 26 2 2 6
45883- 2 2 6 6 6 6 70 47 6 137 92 6
45884-175 118 6 200 144 11 219 162 10 230 174 11
45885-234 174 13 230 174 11 219 162 10 210 150 10
45886-192 133 9 163 110 8 124 112 88 82 82 82
45887- 50 50 50 30 30 30 14 14 14 6 6 6
45888- 0 0 0 0 0 0 0 0 0 0 0 0
45889- 0 0 0 0 0 0 0 0 0 0 0 0
45890- 0 0 0 0 0 0 0 0 0 0 0 0
45891- 0 0 0 0 0 0 0 0 0 0 0 0
45892- 0 0 0 0 0 0 0 0 0 0 0 0
45893- 6 6 6 14 14 14 22 22 22 34 34 34
45894- 42 42 42 58 58 58 74 74 74 86 86 86
45895-101 98 89 122 102 70 130 98 46 121 87 25
45896-137 92 6 152 99 6 163 110 8 180 123 7
45897-185 133 11 197 138 11 206 145 10 200 144 11
45898-180 123 7 156 107 11 130 83 6 104 69 6
45899- 50 34 6 54 54 54 110 110 110 101 98 89
45900- 86 86 86 82 82 82 78 78 78 78 78 78
45901- 78 78 78 78 78 78 78 78 78 78 78 78
45902- 78 78 78 82 82 82 86 86 86 94 94 94
45903-106 106 106 101 101 101 86 66 34 124 80 6
45904-156 107 11 180 123 7 192 133 9 200 144 11
45905-206 145 10 200 144 11 192 133 9 175 118 6
45906-139 102 15 109 106 95 70 70 70 42 42 42
45907- 22 22 22 10 10 10 0 0 0 0 0 0
45908- 0 0 0 0 0 0 0 0 0 0 0 0
45909- 0 0 0 0 0 0 0 0 0 0 0 0
45910- 0 0 0 0 0 0 0 0 0 0 0 0
45911- 0 0 0 0 0 0 0 0 0 0 0 0
45912- 0 0 0 0 0 0 0 0 0 0 0 0
45913- 0 0 0 0 0 0 6 6 6 10 10 10
45914- 14 14 14 22 22 22 30 30 30 38 38 38
45915- 50 50 50 62 62 62 74 74 74 90 90 90
45916-101 98 89 112 100 78 121 87 25 124 80 6
45917-137 92 6 152 99 6 152 99 6 152 99 6
45918-138 86 6 124 80 6 98 70 6 86 66 30
45919-101 98 89 82 82 82 58 58 58 46 46 46
45920- 38 38 38 34 34 34 34 34 34 34 34 34
45921- 34 34 34 34 34 34 34 34 34 34 34 34
45922- 34 34 34 34 34 34 38 38 38 42 42 42
45923- 54 54 54 82 82 82 94 86 76 91 60 6
45924-134 86 6 156 107 11 167 114 7 175 118 6
45925-175 118 6 167 114 7 152 99 6 121 87 25
45926-101 98 89 62 62 62 34 34 34 18 18 18
45927- 6 6 6 0 0 0 0 0 0 0 0 0
45928- 0 0 0 0 0 0 0 0 0 0 0 0
45929- 0 0 0 0 0 0 0 0 0 0 0 0
45930- 0 0 0 0 0 0 0 0 0 0 0 0
45931- 0 0 0 0 0 0 0 0 0 0 0 0
45932- 0 0 0 0 0 0 0 0 0 0 0 0
45933- 0 0 0 0 0 0 0 0 0 0 0 0
45934- 0 0 0 6 6 6 6 6 6 10 10 10
45935- 18 18 18 22 22 22 30 30 30 42 42 42
45936- 50 50 50 66 66 66 86 86 86 101 98 89
45937-106 86 58 98 70 6 104 69 6 104 69 6
45938-104 69 6 91 60 6 82 62 34 90 90 90
45939- 62 62 62 38 38 38 22 22 22 14 14 14
45940- 10 10 10 10 10 10 10 10 10 10 10 10
45941- 10 10 10 10 10 10 6 6 6 10 10 10
45942- 10 10 10 10 10 10 10 10 10 14 14 14
45943- 22 22 22 42 42 42 70 70 70 89 81 66
45944- 80 54 7 104 69 6 124 80 6 137 92 6
45945-134 86 6 116 81 8 100 82 52 86 86 86
45946- 58 58 58 30 30 30 14 14 14 6 6 6
45947- 0 0 0 0 0 0 0 0 0 0 0 0
45948- 0 0 0 0 0 0 0 0 0 0 0 0
45949- 0 0 0 0 0 0 0 0 0 0 0 0
45950- 0 0 0 0 0 0 0 0 0 0 0 0
45951- 0 0 0 0 0 0 0 0 0 0 0 0
45952- 0 0 0 0 0 0 0 0 0 0 0 0
45953- 0 0 0 0 0 0 0 0 0 0 0 0
45954- 0 0 0 0 0 0 0 0 0 0 0 0
45955- 0 0 0 6 6 6 10 10 10 14 14 14
45956- 18 18 18 26 26 26 38 38 38 54 54 54
45957- 70 70 70 86 86 86 94 86 76 89 81 66
45958- 89 81 66 86 86 86 74 74 74 50 50 50
45959- 30 30 30 14 14 14 6 6 6 0 0 0
45960- 0 0 0 0 0 0 0 0 0 0 0 0
45961- 0 0 0 0 0 0 0 0 0 0 0 0
45962- 0 0 0 0 0 0 0 0 0 0 0 0
45963- 6 6 6 18 18 18 34 34 34 58 58 58
45964- 82 82 82 89 81 66 89 81 66 89 81 66
45965- 94 86 66 94 86 76 74 74 74 50 50 50
45966- 26 26 26 14 14 14 6 6 6 0 0 0
45967- 0 0 0 0 0 0 0 0 0 0 0 0
45968- 0 0 0 0 0 0 0 0 0 0 0 0
45969- 0 0 0 0 0 0 0 0 0 0 0 0
45970- 0 0 0 0 0 0 0 0 0 0 0 0
45971- 0 0 0 0 0 0 0 0 0 0 0 0
45972- 0 0 0 0 0 0 0 0 0 0 0 0
45973- 0 0 0 0 0 0 0 0 0 0 0 0
45974- 0 0 0 0 0 0 0 0 0 0 0 0
45975- 0 0 0 0 0 0 0 0 0 0 0 0
45976- 6 6 6 6 6 6 14 14 14 18 18 18
45977- 30 30 30 38 38 38 46 46 46 54 54 54
45978- 50 50 50 42 42 42 30 30 30 18 18 18
45979- 10 10 10 0 0 0 0 0 0 0 0 0
45980- 0 0 0 0 0 0 0 0 0 0 0 0
45981- 0 0 0 0 0 0 0 0 0 0 0 0
45982- 0 0 0 0 0 0 0 0 0 0 0 0
45983- 0 0 0 6 6 6 14 14 14 26 26 26
45984- 38 38 38 50 50 50 58 58 58 58 58 58
45985- 54 54 54 42 42 42 30 30 30 18 18 18
45986- 10 10 10 0 0 0 0 0 0 0 0 0
45987- 0 0 0 0 0 0 0 0 0 0 0 0
45988- 0 0 0 0 0 0 0 0 0 0 0 0
45989- 0 0 0 0 0 0 0 0 0 0 0 0
45990- 0 0 0 0 0 0 0 0 0 0 0 0
45991- 0 0 0 0 0 0 0 0 0 0 0 0
45992- 0 0 0 0 0 0 0 0 0 0 0 0
45993- 0 0 0 0 0 0 0 0 0 0 0 0
45994- 0 0 0 0 0 0 0 0 0 0 0 0
45995- 0 0 0 0 0 0 0 0 0 0 0 0
45996- 0 0 0 0 0 0 0 0 0 6 6 6
45997- 6 6 6 10 10 10 14 14 14 18 18 18
45998- 18 18 18 14 14 14 10 10 10 6 6 6
45999- 0 0 0 0 0 0 0 0 0 0 0 0
46000- 0 0 0 0 0 0 0 0 0 0 0 0
46001- 0 0 0 0 0 0 0 0 0 0 0 0
46002- 0 0 0 0 0 0 0 0 0 0 0 0
46003- 0 0 0 0 0 0 0 0 0 6 6 6
46004- 14 14 14 18 18 18 22 22 22 22 22 22
46005- 18 18 18 14 14 14 10 10 10 6 6 6
46006- 0 0 0 0 0 0 0 0 0 0 0 0
46007- 0 0 0 0 0 0 0 0 0 0 0 0
46008- 0 0 0 0 0 0 0 0 0 0 0 0
46009- 0 0 0 0 0 0 0 0 0 0 0 0
46010- 0 0 0 0 0 0 0 0 0 0 0 0
46011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46024+4 4 4 4 4 4
46025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46038+4 4 4 4 4 4
46039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46052+4 4 4 4 4 4
46053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46066+4 4 4 4 4 4
46067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46080+4 4 4 4 4 4
46081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46094+4 4 4 4 4 4
46095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46099+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46100+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46104+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46105+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46106+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46108+4 4 4 4 4 4
46109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46113+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46114+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46115+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46118+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46119+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46120+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46121+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46122+4 4 4 4 4 4
46123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46127+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46128+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46129+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46132+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46133+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46134+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46135+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46136+4 4 4 4 4 4
46137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46140+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46141+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46142+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46143+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46145+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46146+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46147+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46148+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46149+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46150+4 4 4 4 4 4
46151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46154+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46155+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46156+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46157+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46158+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46159+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46160+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46161+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46162+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46163+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46164+4 4 4 4 4 4
46165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46168+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46169+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46170+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46171+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46172+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46173+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46174+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46175+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46176+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46177+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46178+4 4 4 4 4 4
46179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46181+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46182+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46183+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46184+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46185+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46186+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46187+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46188+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46189+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46190+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46191+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46192+4 4 4 4 4 4
46193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46195+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46196+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46197+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46198+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46199+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46200+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46201+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46202+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46203+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46204+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46205+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46206+4 4 4 4 4 4
46207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46209+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46210+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46211+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46212+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46213+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46214+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46215+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46216+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46217+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46218+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46219+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46220+4 4 4 4 4 4
46221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46223+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46224+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46225+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46226+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46227+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46228+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46229+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46230+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46231+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46232+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46233+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46234+4 4 4 4 4 4
46235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46236+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46237+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46238+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46239+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46240+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46241+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46242+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46243+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46244+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46245+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46246+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46247+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46248+4 4 4 4 4 4
46249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46250+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46251+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46252+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46253+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46254+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46255+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46256+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46257+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46258+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46259+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46260+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46261+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46262+0 0 0 4 4 4
46263+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46264+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46265+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46266+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46267+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46268+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46269+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46270+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46271+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46272+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46273+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46274+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46275+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46276+2 0 0 0 0 0
46277+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46278+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46279+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46280+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46281+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46282+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46283+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46284+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46285+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46286+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46287+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46288+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46289+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46290+37 38 37 0 0 0
46291+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46292+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46293+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46294+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46295+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46296+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46297+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46298+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46299+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46300+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46301+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46302+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46303+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46304+85 115 134 4 0 0
46305+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46306+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46307+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46308+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46309+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46310+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46311+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46312+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46313+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46314+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46315+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46316+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46317+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46318+60 73 81 4 0 0
46319+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46320+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46321+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46322+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46323+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46324+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46325+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46326+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46327+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46328+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46329+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46330+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46331+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46332+16 19 21 4 0 0
46333+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
46334+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
46335+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
46336+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
46337+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
46338+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
46339+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
46340+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
46341+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
46342+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
46343+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
46344+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
46345+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
46346+4 0 0 4 3 3
46347+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
46348+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
46349+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
46350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
46351+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
46352+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
46353+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
46354+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
46355+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
46356+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
46357+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
46358+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
46359+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
46360+3 2 2 4 4 4
46361+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
46362+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
46363+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
46364+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46365+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
46366+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
46367+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
46368+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
46369+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
46370+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
46371+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
46372+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
46373+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
46374+4 4 4 4 4 4
46375+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
46376+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
46377+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
46378+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
46379+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
46380+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
46381+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
46382+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
46383+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
46384+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
46385+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
46386+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
46387+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
46388+4 4 4 4 4 4
46389+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
46390+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
46391+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
46392+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
46393+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
46394+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46395+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
46396+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
46397+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
46398+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
46399+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
46400+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
46401+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
46402+5 5 5 5 5 5
46403+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
46404+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46405+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46406+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46407+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46408+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46409+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46410+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46411+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46412+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46413+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46414+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46415+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46416+5 5 5 4 4 4
46417+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46418+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46419+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46420+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46421+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46422+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46423+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46424+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46425+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46426+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46427+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46428+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46430+4 4 4 4 4 4
46431+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46432+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46433+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46434+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46435+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46436+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46437+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46438+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46439+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46440+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46441+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46442+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46444+4 4 4 4 4 4
46445+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46446+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46447+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46448+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46449+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46450+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46451+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46452+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46453+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46454+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46455+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46458+4 4 4 4 4 4
46459+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46460+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46461+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46462+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46463+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46464+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46465+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46466+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46467+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46468+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46469+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46472+4 4 4 4 4 4
46473+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46474+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46475+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46476+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46477+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46478+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46479+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46480+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46481+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46482+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46483+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46486+4 4 4 4 4 4
46487+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46488+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46489+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46490+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46491+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46492+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46493+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46494+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46495+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46496+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46497+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46500+4 4 4 4 4 4
46501+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46502+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46503+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46504+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46505+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46506+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46507+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46508+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46509+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46510+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46511+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46514+4 4 4 4 4 4
46515+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46516+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46517+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46518+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46519+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46520+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46521+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46522+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46523+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46524+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46525+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46528+4 4 4 4 4 4
46529+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46530+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46531+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46532+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46533+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46534+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46535+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46536+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46537+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46538+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46539+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46542+4 4 4 4 4 4
46543+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46544+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46545+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46546+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46547+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46548+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46549+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46550+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46551+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46552+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46553+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46556+4 4 4 4 4 4
46557+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46558+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46559+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46560+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46561+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46562+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46563+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46564+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46565+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46566+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46567+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46570+4 4 4 4 4 4
46571+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46572+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46573+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46574+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46575+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46576+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46577+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46578+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46579+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46580+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46581+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46584+4 4 4 4 4 4
46585+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46586+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46587+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46588+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46589+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46590+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46591+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46592+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46593+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46594+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46595+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46598+4 4 4 4 4 4
46599+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46600+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46601+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46602+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46603+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46604+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46605+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46606+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46607+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46608+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46609+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46612+4 4 4 4 4 4
46613+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46614+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46615+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46616+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46617+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46618+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46619+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46620+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46621+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46622+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46623+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46626+4 4 4 4 4 4
46627+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46628+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46629+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46630+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46631+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46632+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46633+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46634+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46635+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46636+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46637+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46640+4 4 4 4 4 4
46641+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46642+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46643+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46644+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46645+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46646+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46647+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46648+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46649+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46650+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46651+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46654+4 4 4 4 4 4
46655+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46656+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46657+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46658+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46659+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46660+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46661+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46662+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46663+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46664+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46665+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46668+4 4 4 4 4 4
46669+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46670+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46671+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46672+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46673+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46674+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46675+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46676+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46677+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46678+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46679+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46682+4 4 4 4 4 4
46683+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46684+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46685+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46686+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46687+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46688+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46689+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46690+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46691+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46692+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46693+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46696+4 4 4 4 4 4
46697+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46698+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46699+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46700+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46701+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46702+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46703+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46704+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46705+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46706+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46707+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46710+4 4 4 4 4 4
46711+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46712+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46713+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46714+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46715+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46716+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46717+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46718+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46719+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46720+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46721+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46724+4 4 4 4 4 4
46725+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46726+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46727+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46728+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46729+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46730+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46731+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46732+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46733+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46734+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46735+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46738+4 4 4 4 4 4
46739+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46740+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46741+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46742+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46743+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46744+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46745+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46746+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46747+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46748+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46749+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46752+4 4 4 4 4 4
46753+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46754+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46755+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46756+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46757+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46758+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46759+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46760+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46761+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46762+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46763+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46766+4 4 4 4 4 4
46767+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46768+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46769+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46770+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46771+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46772+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46773+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46774+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46775+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46776+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46777+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46780+4 4 4 4 4 4
46781+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46782+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46783+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46784+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46785+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46786+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46787+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46788+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46789+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46790+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46791+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46794+4 4 4 4 4 4
46795+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46796+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46797+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46798+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46799+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46800+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46801+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46802+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46803+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46804+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46805+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46808+4 4 4 4 4 4
46809+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46810+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46811+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46812+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46813+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46814+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46815+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46816+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46817+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46818+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46819+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46822+4 4 4 4 4 4
46823+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46824+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46825+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46826+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46827+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46828+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46829+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46830+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46831+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46832+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46836+4 4 4 4 4 4
46837+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46838+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46839+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46840+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46841+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46842+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46843+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46844+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46845+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46846+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46850+4 4 4 4 4 4
46851+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46852+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46853+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46854+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46855+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46856+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46857+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46858+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46859+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46860+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46864+4 4 4 4 4 4
46865+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46866+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46867+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46868+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46869+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46870+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46871+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46872+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46873+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46874+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46878+4 4 4 4 4 4
46879+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46880+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46881+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46882+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46883+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46884+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46885+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46886+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46887+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
46888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46892+4 4 4 4 4 4
46893+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46894+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46895+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46896+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46897+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46898+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46899+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46900+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46901+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
46902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46906+4 4 4 4 4 4
46907+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46908+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46909+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46910+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46911+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46912+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46913+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46914+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46915+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46920+4 4 4 4 4 4
46921+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46922+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46923+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46924+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46925+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46926+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46927+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46928+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
46929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46934+4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46936+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46937+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46938+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46939+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46940+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46941+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46942+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46948+4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46950+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
46951+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46952+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
46953+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
46954+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
46955+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
46956+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
46957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46962+4 4 4 4 4 4
46963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46964+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
46965+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
46966+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
46967+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
46968+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
46969+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
46970+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
46971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46976+4 4 4 4 4 4
46977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46978+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46979+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
46980+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46981+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
46982+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
46983+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
46984+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46990+4 4 4 4 4 4
46991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46993+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46994+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
46995+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
46996+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
46997+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
46998+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47004+4 4 4 4 4 4
47005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47008+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47009+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47010+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47011+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47018+4 4 4 4 4 4
47019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47022+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47023+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47024+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47025+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47032+4 4 4 4 4 4
47033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47036+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47037+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47038+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47039+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47046+4 4 4 4 4 4
47047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47050+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47051+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47052+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47053+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47060+4 4 4 4 4 4
47061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47065+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47066+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47067+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47074+4 4 4 4 4 4
47075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47079+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47080+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47081+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47088+4 4 4 4 4 4
47089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47093+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47094+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47095+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47102+4 4 4 4 4 4
47103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47107+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47108+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47116+4 4 4 4 4 4
47117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47121+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47122+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47130+4 4 4 4 4 4
47131diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47132index fe92eed..106e085 100644
47133--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47134+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47135@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47136 struct mb862xxfb_par *par = info->par;
47137
47138 if (info->var.bits_per_pixel == 32) {
47139- info->fbops->fb_fillrect = cfb_fillrect;
47140- info->fbops->fb_copyarea = cfb_copyarea;
47141- info->fbops->fb_imageblit = cfb_imageblit;
47142+ pax_open_kernel();
47143+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47144+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47145+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47146+ pax_close_kernel();
47147 } else {
47148 outreg(disp, GC_L0EM, 3);
47149- info->fbops->fb_fillrect = mb86290fb_fillrect;
47150- info->fbops->fb_copyarea = mb86290fb_copyarea;
47151- info->fbops->fb_imageblit = mb86290fb_imageblit;
47152+ pax_open_kernel();
47153+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47154+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47155+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47156+ pax_close_kernel();
47157 }
47158 outreg(draw, GDC_REG_DRAW_BASE, 0);
47159 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47160diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47161index ff22871..b129bed 100644
47162--- a/drivers/video/nvidia/nvidia.c
47163+++ b/drivers/video/nvidia/nvidia.c
47164@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47165 info->fix.line_length = (info->var.xres_virtual *
47166 info->var.bits_per_pixel) >> 3;
47167 if (info->var.accel_flags) {
47168- info->fbops->fb_imageblit = nvidiafb_imageblit;
47169- info->fbops->fb_fillrect = nvidiafb_fillrect;
47170- info->fbops->fb_copyarea = nvidiafb_copyarea;
47171- info->fbops->fb_sync = nvidiafb_sync;
47172+ pax_open_kernel();
47173+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47174+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47175+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47176+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47177+ pax_close_kernel();
47178 info->pixmap.scan_align = 4;
47179 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47180 info->flags |= FBINFO_READS_FAST;
47181 NVResetGraphics(info);
47182 } else {
47183- info->fbops->fb_imageblit = cfb_imageblit;
47184- info->fbops->fb_fillrect = cfb_fillrect;
47185- info->fbops->fb_copyarea = cfb_copyarea;
47186- info->fbops->fb_sync = NULL;
47187+ pax_open_kernel();
47188+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47189+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47190+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47191+ *(void **)&info->fbops->fb_sync = NULL;
47192+ pax_close_kernel();
47193 info->pixmap.scan_align = 1;
47194 info->flags |= FBINFO_HWACCEL_DISABLED;
47195 info->flags &= ~FBINFO_READS_FAST;
47196@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47197 info->pixmap.size = 8 * 1024;
47198 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47199
47200- if (!hwcur)
47201- info->fbops->fb_cursor = NULL;
47202+ if (!hwcur) {
47203+ pax_open_kernel();
47204+ *(void **)&info->fbops->fb_cursor = NULL;
47205+ pax_close_kernel();
47206+ }
47207
47208 info->var.accel_flags = (!noaccel);
47209
47210diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47211index 76d9053..dec2bfd 100644
47212--- a/drivers/video/s1d13xxxfb.c
47213+++ b/drivers/video/s1d13xxxfb.c
47214@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47215
47216 switch(prod_id) {
47217 case S1D13506_PROD_ID: /* activate acceleration */
47218- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47219- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47220+ pax_open_kernel();
47221+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47222+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47223+ pax_close_kernel();
47224 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47225 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47226 break;
47227diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47228index 97bd662..39fab85 100644
47229--- a/drivers/video/smscufx.c
47230+++ b/drivers/video/smscufx.c
47231@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47232 fb_deferred_io_cleanup(info);
47233 kfree(info->fbdefio);
47234 info->fbdefio = NULL;
47235- info->fbops->fb_mmap = ufx_ops_mmap;
47236+ pax_open_kernel();
47237+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47238+ pax_close_kernel();
47239 }
47240
47241 pr_debug("released /dev/fb%d user=%d count=%d",
47242diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47243index 86d449e..8e04dc5 100644
47244--- a/drivers/video/udlfb.c
47245+++ b/drivers/video/udlfb.c
47246@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47247 dlfb_urb_completion(urb);
47248
47249 error:
47250- atomic_add(bytes_sent, &dev->bytes_sent);
47251- atomic_add(bytes_identical, &dev->bytes_identical);
47252- atomic_add(width*height*2, &dev->bytes_rendered);
47253+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47254+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47255+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47256 end_cycles = get_cycles();
47257- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47258+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47259 >> 10)), /* Kcycles */
47260 &dev->cpu_kcycles_used);
47261
47262@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47263 dlfb_urb_completion(urb);
47264
47265 error:
47266- atomic_add(bytes_sent, &dev->bytes_sent);
47267- atomic_add(bytes_identical, &dev->bytes_identical);
47268- atomic_add(bytes_rendered, &dev->bytes_rendered);
47269+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47270+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47271+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47272 end_cycles = get_cycles();
47273- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47274+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47275 >> 10)), /* Kcycles */
47276 &dev->cpu_kcycles_used);
47277 }
47278@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47279 fb_deferred_io_cleanup(info);
47280 kfree(info->fbdefio);
47281 info->fbdefio = NULL;
47282- info->fbops->fb_mmap = dlfb_ops_mmap;
47283+ pax_open_kernel();
47284+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47285+ pax_close_kernel();
47286 }
47287
47288 pr_warn("released /dev/fb%d user=%d count=%d\n",
47289@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47290 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47291 struct dlfb_data *dev = fb_info->par;
47292 return snprintf(buf, PAGE_SIZE, "%u\n",
47293- atomic_read(&dev->bytes_rendered));
47294+ atomic_read_unchecked(&dev->bytes_rendered));
47295 }
47296
47297 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47298@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47299 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47300 struct dlfb_data *dev = fb_info->par;
47301 return snprintf(buf, PAGE_SIZE, "%u\n",
47302- atomic_read(&dev->bytes_identical));
47303+ atomic_read_unchecked(&dev->bytes_identical));
47304 }
47305
47306 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47307@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47308 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47309 struct dlfb_data *dev = fb_info->par;
47310 return snprintf(buf, PAGE_SIZE, "%u\n",
47311- atomic_read(&dev->bytes_sent));
47312+ atomic_read_unchecked(&dev->bytes_sent));
47313 }
47314
47315 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47316@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47317 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47318 struct dlfb_data *dev = fb_info->par;
47319 return snprintf(buf, PAGE_SIZE, "%u\n",
47320- atomic_read(&dev->cpu_kcycles_used));
47321+ atomic_read_unchecked(&dev->cpu_kcycles_used));
47322 }
47323
47324 static ssize_t edid_show(
47325@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
47326 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47327 struct dlfb_data *dev = fb_info->par;
47328
47329- atomic_set(&dev->bytes_rendered, 0);
47330- atomic_set(&dev->bytes_identical, 0);
47331- atomic_set(&dev->bytes_sent, 0);
47332- atomic_set(&dev->cpu_kcycles_used, 0);
47333+ atomic_set_unchecked(&dev->bytes_rendered, 0);
47334+ atomic_set_unchecked(&dev->bytes_identical, 0);
47335+ atomic_set_unchecked(&dev->bytes_sent, 0);
47336+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
47337
47338 return count;
47339 }
47340diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
47341index b75db01..ad2f34a 100644
47342--- a/drivers/video/uvesafb.c
47343+++ b/drivers/video/uvesafb.c
47344@@ -19,6 +19,7 @@
47345 #include <linux/io.h>
47346 #include <linux/mutex.h>
47347 #include <linux/slab.h>
47348+#include <linux/moduleloader.h>
47349 #include <video/edid.h>
47350 #include <video/uvesafb.h>
47351 #ifdef CONFIG_X86
47352@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
47353 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
47354 par->pmi_setpal = par->ypan = 0;
47355 } else {
47356+
47357+#ifdef CONFIG_PAX_KERNEXEC
47358+#ifdef CONFIG_MODULES
47359+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
47360+#endif
47361+ if (!par->pmi_code) {
47362+ par->pmi_setpal = par->ypan = 0;
47363+ return 0;
47364+ }
47365+#endif
47366+
47367 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
47368 + task->t.regs.edi);
47369+
47370+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47371+ pax_open_kernel();
47372+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
47373+ pax_close_kernel();
47374+
47375+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
47376+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
47377+#else
47378 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
47379 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
47380+#endif
47381+
47382 printk(KERN_INFO "uvesafb: protected mode interface info at "
47383 "%04x:%04x\n",
47384 (u16)task->t.regs.es, (u16)task->t.regs.edi);
47385@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
47386 par->ypan = ypan;
47387
47388 if (par->pmi_setpal || par->ypan) {
47389+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
47390 if (__supported_pte_mask & _PAGE_NX) {
47391 par->pmi_setpal = par->ypan = 0;
47392 printk(KERN_WARNING "uvesafb: NX protection is actively."
47393 "We have better not to use the PMI.\n");
47394- } else {
47395+ } else
47396+#endif
47397 uvesafb_vbe_getpmi(task, par);
47398- }
47399 }
47400 #else
47401 /* The protected mode interface is not available on non-x86. */
47402@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47403 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
47404
47405 /* Disable blanking if the user requested so. */
47406- if (!blank)
47407- info->fbops->fb_blank = NULL;
47408+ if (!blank) {
47409+ pax_open_kernel();
47410+ *(void **)&info->fbops->fb_blank = NULL;
47411+ pax_close_kernel();
47412+ }
47413
47414 /*
47415 * Find out how much IO memory is required for the mode with
47416@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47417 info->flags = FBINFO_FLAG_DEFAULT |
47418 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47419
47420- if (!par->ypan)
47421- info->fbops->fb_pan_display = NULL;
47422+ if (!par->ypan) {
47423+ pax_open_kernel();
47424+ *(void **)&info->fbops->fb_pan_display = NULL;
47425+ pax_close_kernel();
47426+ }
47427 }
47428
47429 static void uvesafb_init_mtrr(struct fb_info *info)
47430@@ -1836,6 +1866,11 @@ out:
47431 if (par->vbe_modes)
47432 kfree(par->vbe_modes);
47433
47434+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47435+ if (par->pmi_code)
47436+ module_free_exec(NULL, par->pmi_code);
47437+#endif
47438+
47439 framebuffer_release(info);
47440 return err;
47441 }
47442@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47443 kfree(par->vbe_state_orig);
47444 if (par->vbe_state_saved)
47445 kfree(par->vbe_state_saved);
47446+
47447+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47448+ if (par->pmi_code)
47449+ module_free_exec(NULL, par->pmi_code);
47450+#endif
47451+
47452 }
47453
47454 framebuffer_release(info);
47455diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47456index 501b340..d80aa17 100644
47457--- a/drivers/video/vesafb.c
47458+++ b/drivers/video/vesafb.c
47459@@ -9,6 +9,7 @@
47460 */
47461
47462 #include <linux/module.h>
47463+#include <linux/moduleloader.h>
47464 #include <linux/kernel.h>
47465 #include <linux/errno.h>
47466 #include <linux/string.h>
47467@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47468 static int vram_total __initdata; /* Set total amount of memory */
47469 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47470 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47471-static void (*pmi_start)(void) __read_mostly;
47472-static void (*pmi_pal) (void) __read_mostly;
47473+static void (*pmi_start)(void) __read_only;
47474+static void (*pmi_pal) (void) __read_only;
47475 static int depth __read_mostly;
47476 static int vga_compat __read_mostly;
47477 /* --------------------------------------------------------------------- */
47478@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47479 unsigned int size_vmode;
47480 unsigned int size_remap;
47481 unsigned int size_total;
47482+ void *pmi_code = NULL;
47483
47484 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47485 return -ENODEV;
47486@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47487 size_remap = size_total;
47488 vesafb_fix.smem_len = size_remap;
47489
47490-#ifndef __i386__
47491- screen_info.vesapm_seg = 0;
47492-#endif
47493-
47494 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47495 printk(KERN_WARNING
47496 "vesafb: cannot reserve video memory at 0x%lx\n",
47497@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47498 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47499 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47500
47501+#ifdef __i386__
47502+
47503+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47504+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
47505+ if (!pmi_code)
47506+#elif !defined(CONFIG_PAX_KERNEXEC)
47507+ if (0)
47508+#endif
47509+
47510+#endif
47511+ screen_info.vesapm_seg = 0;
47512+
47513 if (screen_info.vesapm_seg) {
47514- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47515- screen_info.vesapm_seg,screen_info.vesapm_off);
47516+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47517+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47518 }
47519
47520 if (screen_info.vesapm_seg < 0xc000)
47521@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47522
47523 if (ypan || pmi_setpal) {
47524 unsigned short *pmi_base;
47525+
47526 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47527- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47528- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47529+
47530+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47531+ pax_open_kernel();
47532+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47533+#else
47534+ pmi_code = pmi_base;
47535+#endif
47536+
47537+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47538+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47539+
47540+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47541+ pmi_start = ktva_ktla(pmi_start);
47542+ pmi_pal = ktva_ktla(pmi_pal);
47543+ pax_close_kernel();
47544+#endif
47545+
47546 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47547 if (pmi_base[3]) {
47548 printk(KERN_INFO "vesafb: pmi: ports = ");
47549@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47550 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47551 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47552
47553- if (!ypan)
47554- info->fbops->fb_pan_display = NULL;
47555+ if (!ypan) {
47556+ pax_open_kernel();
47557+ *(void **)&info->fbops->fb_pan_display = NULL;
47558+ pax_close_kernel();
47559+ }
47560
47561 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47562 err = -ENOMEM;
47563@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47564 info->node, info->fix.id);
47565 return 0;
47566 err:
47567+
47568+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47569+ module_free_exec(NULL, pmi_code);
47570+#endif
47571+
47572 if (info->screen_base)
47573 iounmap(info->screen_base);
47574 framebuffer_release(info);
47575diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47576index 88714ae..16c2e11 100644
47577--- a/drivers/video/via/via_clock.h
47578+++ b/drivers/video/via/via_clock.h
47579@@ -56,7 +56,7 @@ struct via_clock {
47580
47581 void (*set_engine_pll_state)(u8 state);
47582 void (*set_engine_pll)(struct via_pll_config config);
47583-};
47584+} __no_const;
47585
47586
47587 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47588diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47589index fef20db..d28b1ab 100644
47590--- a/drivers/xen/xenfs/xenstored.c
47591+++ b/drivers/xen/xenfs/xenstored.c
47592@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47593 static int xsd_kva_open(struct inode *inode, struct file *file)
47594 {
47595 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47596+#ifdef CONFIG_GRKERNSEC_HIDESYM
47597+ NULL);
47598+#else
47599 xen_store_interface);
47600+#endif
47601+
47602 if (!file->private_data)
47603 return -ENOMEM;
47604 return 0;
47605diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47606index 890bed5..17ae73e 100644
47607--- a/fs/9p/vfs_inode.c
47608+++ b/fs/9p/vfs_inode.c
47609@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47610 void
47611 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47612 {
47613- char *s = nd_get_link(nd);
47614+ const char *s = nd_get_link(nd);
47615
47616 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47617 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47618diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47619index 0efd152..b5802ad 100644
47620--- a/fs/Kconfig.binfmt
47621+++ b/fs/Kconfig.binfmt
47622@@ -89,7 +89,7 @@ config HAVE_AOUT
47623
47624 config BINFMT_AOUT
47625 tristate "Kernel support for a.out and ECOFF binaries"
47626- depends on HAVE_AOUT
47627+ depends on HAVE_AOUT && BROKEN
47628 ---help---
47629 A.out (Assembler.OUTput) is a set of formats for libraries and
47630 executables used in the earliest versions of UNIX. Linux used
47631diff --git a/fs/aio.c b/fs/aio.c
47632index 71f613c..9d01f1f 100644
47633--- a/fs/aio.c
47634+++ b/fs/aio.c
47635@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47636 size += sizeof(struct io_event) * nr_events;
47637 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47638
47639- if (nr_pages < 0)
47640+ if (nr_pages <= 0)
47641 return -EINVAL;
47642
47643 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47644@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47645 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47646 {
47647 ssize_t ret;
47648+ struct iovec iovstack;
47649
47650 #ifdef CONFIG_COMPAT
47651 if (compat)
47652 ret = compat_rw_copy_check_uvector(type,
47653 (struct compat_iovec __user *)kiocb->ki_buf,
47654- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47655+ kiocb->ki_nbytes, 1, &iovstack,
47656 &kiocb->ki_iovec);
47657 else
47658 #endif
47659 ret = rw_copy_check_uvector(type,
47660 (struct iovec __user *)kiocb->ki_buf,
47661- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47662+ kiocb->ki_nbytes, 1, &iovstack,
47663 &kiocb->ki_iovec);
47664 if (ret < 0)
47665 goto out;
47666@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47667 if (ret < 0)
47668 goto out;
47669
47670+ if (kiocb->ki_iovec == &iovstack) {
47671+ kiocb->ki_inline_vec = iovstack;
47672+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
47673+ }
47674 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47675 kiocb->ki_cur_seg = 0;
47676 /* ki_nbytes/left now reflect bytes instead of segs */
47677diff --git a/fs/attr.c b/fs/attr.c
47678index 1449adb..a2038c2 100644
47679--- a/fs/attr.c
47680+++ b/fs/attr.c
47681@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47682 unsigned long limit;
47683
47684 limit = rlimit(RLIMIT_FSIZE);
47685+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47686 if (limit != RLIM_INFINITY && offset > limit)
47687 goto out_sig;
47688 if (offset > inode->i_sb->s_maxbytes)
47689diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47690index 03bc1d3..6205356 100644
47691--- a/fs/autofs4/waitq.c
47692+++ b/fs/autofs4/waitq.c
47693@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47694 {
47695 unsigned long sigpipe, flags;
47696 mm_segment_t fs;
47697- const char *data = (const char *)addr;
47698+ const char __user *data = (const char __force_user *)addr;
47699 ssize_t wr = 0;
47700
47701 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47702@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47703 return 1;
47704 }
47705
47706+#ifdef CONFIG_GRKERNSEC_HIDESYM
47707+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47708+#endif
47709+
47710 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47711 enum autofs_notify notify)
47712 {
47713@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47714
47715 /* If this is a direct mount request create a dummy name */
47716 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47717+#ifdef CONFIG_GRKERNSEC_HIDESYM
47718+ /* this name does get written to userland via autofs4_write() */
47719+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47720+#else
47721 qstr.len = sprintf(name, "%p", dentry);
47722+#endif
47723 else {
47724 qstr.len = autofs4_getpath(sbi, dentry, &name);
47725 if (!qstr.len) {
47726diff --git a/fs/befs/endian.h b/fs/befs/endian.h
47727index 2722387..c8dd2a7 100644
47728--- a/fs/befs/endian.h
47729+++ b/fs/befs/endian.h
47730@@ -11,7 +11,7 @@
47731
47732 #include <asm/byteorder.h>
47733
47734-static inline u64
47735+static inline u64 __intentional_overflow(-1)
47736 fs64_to_cpu(const struct super_block *sb, fs64 n)
47737 {
47738 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47739@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
47740 return (__force fs64)cpu_to_be64(n);
47741 }
47742
47743-static inline u32
47744+static inline u32 __intentional_overflow(-1)
47745 fs32_to_cpu(const struct super_block *sb, fs32 n)
47746 {
47747 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47748diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47749index 2b3bda8..6a2d4be 100644
47750--- a/fs/befs/linuxvfs.c
47751+++ b/fs/befs/linuxvfs.c
47752@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47753 {
47754 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47755 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47756- char *link = nd_get_link(nd);
47757+ const char *link = nd_get_link(nd);
47758 if (!IS_ERR(link))
47759 kfree(link);
47760 }
47761diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47762index 6043567..16a9239 100644
47763--- a/fs/binfmt_aout.c
47764+++ b/fs/binfmt_aout.c
47765@@ -16,6 +16,7 @@
47766 #include <linux/string.h>
47767 #include <linux/fs.h>
47768 #include <linux/file.h>
47769+#include <linux/security.h>
47770 #include <linux/stat.h>
47771 #include <linux/fcntl.h>
47772 #include <linux/ptrace.h>
47773@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47774 #endif
47775 # define START_STACK(u) ((void __user *)u.start_stack)
47776
47777+ memset(&dump, 0, sizeof(dump));
47778+
47779 fs = get_fs();
47780 set_fs(KERNEL_DS);
47781 has_dumped = 1;
47782@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47783
47784 /* If the size of the dump file exceeds the rlimit, then see what would happen
47785 if we wrote the stack, but not the data area. */
47786+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47787 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47788 dump.u_dsize = 0;
47789
47790 /* Make sure we have enough room to write the stack and data areas. */
47791+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47792 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47793 dump.u_ssize = 0;
47794
47795@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47796 rlim = rlimit(RLIMIT_DATA);
47797 if (rlim >= RLIM_INFINITY)
47798 rlim = ~0;
47799+
47800+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47801 if (ex.a_data + ex.a_bss > rlim)
47802 return -ENOMEM;
47803
47804@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47805
47806 install_exec_creds(bprm);
47807
47808+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47809+ current->mm->pax_flags = 0UL;
47810+#endif
47811+
47812+#ifdef CONFIG_PAX_PAGEEXEC
47813+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47814+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47815+
47816+#ifdef CONFIG_PAX_EMUTRAMP
47817+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47818+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47819+#endif
47820+
47821+#ifdef CONFIG_PAX_MPROTECT
47822+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47823+ current->mm->pax_flags |= MF_PAX_MPROTECT;
47824+#endif
47825+
47826+ }
47827+#endif
47828+
47829 if (N_MAGIC(ex) == OMAGIC) {
47830 unsigned long text_addr, map_size;
47831 loff_t pos;
47832@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47833 }
47834
47835 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47836- PROT_READ | PROT_WRITE | PROT_EXEC,
47837+ PROT_READ | PROT_WRITE,
47838 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47839 fd_offset + ex.a_text);
47840 if (error != N_DATADDR(ex)) {
47841diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47842index 0c42cdb..c4f1cf1 100644
47843--- a/fs/binfmt_elf.c
47844+++ b/fs/binfmt_elf.c
47845@@ -33,6 +33,7 @@
47846 #include <linux/elf.h>
47847 #include <linux/utsname.h>
47848 #include <linux/coredump.h>
47849+#include <linux/xattr.h>
47850 #include <asm/uaccess.h>
47851 #include <asm/param.h>
47852 #include <asm/page.h>
47853@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47854 #define elf_core_dump NULL
47855 #endif
47856
47857+#ifdef CONFIG_PAX_MPROTECT
47858+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47859+#endif
47860+
47861 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47862 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47863 #else
47864@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47865 .load_binary = load_elf_binary,
47866 .load_shlib = load_elf_library,
47867 .core_dump = elf_core_dump,
47868+
47869+#ifdef CONFIG_PAX_MPROTECT
47870+ .handle_mprotect= elf_handle_mprotect,
47871+#endif
47872+
47873 .min_coredump = ELF_EXEC_PAGESIZE,
47874 };
47875
47876@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47877
47878 static int set_brk(unsigned long start, unsigned long end)
47879 {
47880+ unsigned long e = end;
47881+
47882 start = ELF_PAGEALIGN(start);
47883 end = ELF_PAGEALIGN(end);
47884 if (end > start) {
47885@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47886 if (BAD_ADDR(addr))
47887 return addr;
47888 }
47889- current->mm->start_brk = current->mm->brk = end;
47890+ current->mm->start_brk = current->mm->brk = e;
47891 return 0;
47892 }
47893
47894@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47895 elf_addr_t __user *u_rand_bytes;
47896 const char *k_platform = ELF_PLATFORM;
47897 const char *k_base_platform = ELF_BASE_PLATFORM;
47898- unsigned char k_rand_bytes[16];
47899+ u32 k_rand_bytes[4];
47900 int items;
47901 elf_addr_t *elf_info;
47902 int ei_index = 0;
47903 const struct cred *cred = current_cred();
47904 struct vm_area_struct *vma;
47905+ unsigned long saved_auxv[AT_VECTOR_SIZE];
47906
47907 /*
47908 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47909@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47910 * Generate 16 random bytes for userspace PRNG seeding.
47911 */
47912 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47913- u_rand_bytes = (elf_addr_t __user *)
47914- STACK_ALLOC(p, sizeof(k_rand_bytes));
47915+ srandom32(k_rand_bytes[0] ^ random32());
47916+ srandom32(k_rand_bytes[1] ^ random32());
47917+ srandom32(k_rand_bytes[2] ^ random32());
47918+ srandom32(k_rand_bytes[3] ^ random32());
47919+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
47920+ u_rand_bytes = (elf_addr_t __user *) p;
47921 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47922 return -EFAULT;
47923
47924@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47925 return -EFAULT;
47926 current->mm->env_end = p;
47927
47928+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47929+
47930 /* Put the elf_info on the stack in the right place. */
47931 sp = (elf_addr_t __user *)envp + 1;
47932- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47933+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47934 return -EFAULT;
47935 return 0;
47936 }
47937@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47938 an ELF header */
47939
47940 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47941- struct file *interpreter, unsigned long *interp_map_addr,
47942- unsigned long no_base)
47943+ struct file *interpreter, unsigned long no_base)
47944 {
47945 struct elf_phdr *elf_phdata;
47946 struct elf_phdr *eppnt;
47947- unsigned long load_addr = 0;
47948+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
47949 int load_addr_set = 0;
47950 unsigned long last_bss = 0, elf_bss = 0;
47951- unsigned long error = ~0UL;
47952+ unsigned long error = -EINVAL;
47953 unsigned long total_size;
47954 int retval, i, size;
47955
47956@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47957 goto out_close;
47958 }
47959
47960+#ifdef CONFIG_PAX_SEGMEXEC
47961+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
47962+ pax_task_size = SEGMEXEC_TASK_SIZE;
47963+#endif
47964+
47965 eppnt = elf_phdata;
47966 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
47967 if (eppnt->p_type == PT_LOAD) {
47968@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47969 map_addr = elf_map(interpreter, load_addr + vaddr,
47970 eppnt, elf_prot, elf_type, total_size);
47971 total_size = 0;
47972- if (!*interp_map_addr)
47973- *interp_map_addr = map_addr;
47974 error = map_addr;
47975 if (BAD_ADDR(map_addr))
47976 goto out_close;
47977@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47978 k = load_addr + eppnt->p_vaddr;
47979 if (BAD_ADDR(k) ||
47980 eppnt->p_filesz > eppnt->p_memsz ||
47981- eppnt->p_memsz > TASK_SIZE ||
47982- TASK_SIZE - eppnt->p_memsz < k) {
47983+ eppnt->p_memsz > pax_task_size ||
47984+ pax_task_size - eppnt->p_memsz < k) {
47985 error = -ENOMEM;
47986 goto out_close;
47987 }
47988@@ -530,6 +551,315 @@ out:
47989 return error;
47990 }
47991
47992+#ifdef CONFIG_PAX_PT_PAX_FLAGS
47993+#ifdef CONFIG_PAX_SOFTMODE
47994+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
47995+{
47996+ unsigned long pax_flags = 0UL;
47997+
47998+#ifdef CONFIG_PAX_PAGEEXEC
47999+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48000+ pax_flags |= MF_PAX_PAGEEXEC;
48001+#endif
48002+
48003+#ifdef CONFIG_PAX_SEGMEXEC
48004+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48005+ pax_flags |= MF_PAX_SEGMEXEC;
48006+#endif
48007+
48008+#ifdef CONFIG_PAX_EMUTRAMP
48009+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48010+ pax_flags |= MF_PAX_EMUTRAMP;
48011+#endif
48012+
48013+#ifdef CONFIG_PAX_MPROTECT
48014+ if (elf_phdata->p_flags & PF_MPROTECT)
48015+ pax_flags |= MF_PAX_MPROTECT;
48016+#endif
48017+
48018+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48019+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48020+ pax_flags |= MF_PAX_RANDMMAP;
48021+#endif
48022+
48023+ return pax_flags;
48024+}
48025+#endif
48026+
48027+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48028+{
48029+ unsigned long pax_flags = 0UL;
48030+
48031+#ifdef CONFIG_PAX_PAGEEXEC
48032+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48033+ pax_flags |= MF_PAX_PAGEEXEC;
48034+#endif
48035+
48036+#ifdef CONFIG_PAX_SEGMEXEC
48037+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48038+ pax_flags |= MF_PAX_SEGMEXEC;
48039+#endif
48040+
48041+#ifdef CONFIG_PAX_EMUTRAMP
48042+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48043+ pax_flags |= MF_PAX_EMUTRAMP;
48044+#endif
48045+
48046+#ifdef CONFIG_PAX_MPROTECT
48047+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48048+ pax_flags |= MF_PAX_MPROTECT;
48049+#endif
48050+
48051+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48052+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48053+ pax_flags |= MF_PAX_RANDMMAP;
48054+#endif
48055+
48056+ return pax_flags;
48057+}
48058+#endif
48059+
48060+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48061+#ifdef CONFIG_PAX_SOFTMODE
48062+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48063+{
48064+ unsigned long pax_flags = 0UL;
48065+
48066+#ifdef CONFIG_PAX_PAGEEXEC
48067+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48068+ pax_flags |= MF_PAX_PAGEEXEC;
48069+#endif
48070+
48071+#ifdef CONFIG_PAX_SEGMEXEC
48072+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48073+ pax_flags |= MF_PAX_SEGMEXEC;
48074+#endif
48075+
48076+#ifdef CONFIG_PAX_EMUTRAMP
48077+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
48078+ pax_flags |= MF_PAX_EMUTRAMP;
48079+#endif
48080+
48081+#ifdef CONFIG_PAX_MPROTECT
48082+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48083+ pax_flags |= MF_PAX_MPROTECT;
48084+#endif
48085+
48086+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48087+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48088+ pax_flags |= MF_PAX_RANDMMAP;
48089+#endif
48090+
48091+ return pax_flags;
48092+}
48093+#endif
48094+
48095+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48096+{
48097+ unsigned long pax_flags = 0UL;
48098+
48099+#ifdef CONFIG_PAX_PAGEEXEC
48100+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48101+ pax_flags |= MF_PAX_PAGEEXEC;
48102+#endif
48103+
48104+#ifdef CONFIG_PAX_SEGMEXEC
48105+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48106+ pax_flags |= MF_PAX_SEGMEXEC;
48107+#endif
48108+
48109+#ifdef CONFIG_PAX_EMUTRAMP
48110+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48111+ pax_flags |= MF_PAX_EMUTRAMP;
48112+#endif
48113+
48114+#ifdef CONFIG_PAX_MPROTECT
48115+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48116+ pax_flags |= MF_PAX_MPROTECT;
48117+#endif
48118+
48119+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48120+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48121+ pax_flags |= MF_PAX_RANDMMAP;
48122+#endif
48123+
48124+ return pax_flags;
48125+}
48126+#endif
48127+
48128+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48129+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48130+{
48131+ unsigned long pax_flags = 0UL;
48132+
48133+#ifdef CONFIG_PAX_EI_PAX
48134+
48135+#ifdef CONFIG_PAX_PAGEEXEC
48136+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48137+ pax_flags |= MF_PAX_PAGEEXEC;
48138+#endif
48139+
48140+#ifdef CONFIG_PAX_SEGMEXEC
48141+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48142+ pax_flags |= MF_PAX_SEGMEXEC;
48143+#endif
48144+
48145+#ifdef CONFIG_PAX_EMUTRAMP
48146+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48147+ pax_flags |= MF_PAX_EMUTRAMP;
48148+#endif
48149+
48150+#ifdef CONFIG_PAX_MPROTECT
48151+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48152+ pax_flags |= MF_PAX_MPROTECT;
48153+#endif
48154+
48155+#ifdef CONFIG_PAX_ASLR
48156+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48157+ pax_flags |= MF_PAX_RANDMMAP;
48158+#endif
48159+
48160+#else
48161+
48162+#ifdef CONFIG_PAX_PAGEEXEC
48163+ pax_flags |= MF_PAX_PAGEEXEC;
48164+#endif
48165+
48166+#ifdef CONFIG_PAX_SEGMEXEC
48167+ pax_flags |= MF_PAX_SEGMEXEC;
48168+#endif
48169+
48170+#ifdef CONFIG_PAX_MPROTECT
48171+ pax_flags |= MF_PAX_MPROTECT;
48172+#endif
48173+
48174+#ifdef CONFIG_PAX_RANDMMAP
48175+ if (randomize_va_space)
48176+ pax_flags |= MF_PAX_RANDMMAP;
48177+#endif
48178+
48179+#endif
48180+
48181+ return pax_flags;
48182+}
48183+
48184+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48185+{
48186+
48187+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48188+ unsigned long i;
48189+
48190+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48191+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48192+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48193+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48194+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48195+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48196+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48197+ return ~0UL;
48198+
48199+#ifdef CONFIG_PAX_SOFTMODE
48200+ if (pax_softmode)
48201+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48202+ else
48203+#endif
48204+
48205+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48206+ break;
48207+ }
48208+#endif
48209+
48210+ return ~0UL;
48211+}
48212+
48213+static unsigned long pax_parse_xattr_pax(struct file * const file)
48214+{
48215+
48216+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48217+ ssize_t xattr_size, i;
48218+ unsigned char xattr_value[5];
48219+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48220+
48221+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
48222+ if (xattr_size <= 0 || xattr_size > 5)
48223+ return ~0UL;
48224+
48225+ for (i = 0; i < xattr_size; i++)
48226+ switch (xattr_value[i]) {
48227+ default:
48228+ return ~0UL;
48229+
48230+#define parse_flag(option1, option2, flag) \
48231+ case option1: \
48232+ if (pax_flags_hardmode & MF_PAX_##flag) \
48233+ return ~0UL; \
48234+ pax_flags_hardmode |= MF_PAX_##flag; \
48235+ break; \
48236+ case option2: \
48237+ if (pax_flags_softmode & MF_PAX_##flag) \
48238+ return ~0UL; \
48239+ pax_flags_softmode |= MF_PAX_##flag; \
48240+ break;
48241+
48242+ parse_flag('p', 'P', PAGEEXEC);
48243+ parse_flag('e', 'E', EMUTRAMP);
48244+ parse_flag('m', 'M', MPROTECT);
48245+ parse_flag('r', 'R', RANDMMAP);
48246+ parse_flag('s', 'S', SEGMEXEC);
48247+
48248+#undef parse_flag
48249+ }
48250+
48251+ if (pax_flags_hardmode & pax_flags_softmode)
48252+ return ~0UL;
48253+
48254+#ifdef CONFIG_PAX_SOFTMODE
48255+ if (pax_softmode)
48256+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48257+ else
48258+#endif
48259+
48260+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48261+#else
48262+ return ~0UL;
48263+#endif
48264+
48265+}
48266+
48267+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48268+{
48269+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48270+
48271+ pax_flags = pax_parse_ei_pax(elf_ex);
48272+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48273+ xattr_pax_flags = pax_parse_xattr_pax(file);
48274+
48275+ if (pt_pax_flags == ~0UL)
48276+ pt_pax_flags = xattr_pax_flags;
48277+ else if (xattr_pax_flags == ~0UL)
48278+ xattr_pax_flags = pt_pax_flags;
48279+ if (pt_pax_flags != xattr_pax_flags)
48280+ return -EINVAL;
48281+ if (pt_pax_flags != ~0UL)
48282+ pax_flags = pt_pax_flags;
48283+
48284+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48285+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48286+ if ((__supported_pte_mask & _PAGE_NX))
48287+ pax_flags &= ~MF_PAX_SEGMEXEC;
48288+ else
48289+ pax_flags &= ~MF_PAX_PAGEEXEC;
48290+ }
48291+#endif
48292+
48293+ if (0 > pax_check_flags(&pax_flags))
48294+ return -EINVAL;
48295+
48296+ current->mm->pax_flags = pax_flags;
48297+ return 0;
48298+}
48299+#endif
48300+
48301 /*
48302 * These are the functions used to load ELF style executables and shared
48303 * libraries. There is no binary dependent code anywhere else.
48304@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48305 {
48306 unsigned int random_variable = 0;
48307
48308+#ifdef CONFIG_PAX_RANDUSTACK
48309+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
48310+ return stack_top - current->mm->delta_stack;
48311+#endif
48312+
48313 if ((current->flags & PF_RANDOMIZE) &&
48314 !(current->personality & ADDR_NO_RANDOMIZE)) {
48315 random_variable = get_random_int() & STACK_RND_MASK;
48316@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
48317 unsigned long load_addr = 0, load_bias = 0;
48318 int load_addr_set = 0;
48319 char * elf_interpreter = NULL;
48320- unsigned long error;
48321+ unsigned long error = 0;
48322 struct elf_phdr *elf_ppnt, *elf_phdata;
48323 unsigned long elf_bss, elf_brk;
48324 int retval, i;
48325@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
48326 unsigned long start_code, end_code, start_data, end_data;
48327 unsigned long reloc_func_desc __maybe_unused = 0;
48328 int executable_stack = EXSTACK_DEFAULT;
48329- unsigned long def_flags = 0;
48330 struct pt_regs *regs = current_pt_regs();
48331 struct {
48332 struct elfhdr elf_ex;
48333 struct elfhdr interp_elf_ex;
48334 } *loc;
48335+ unsigned long pax_task_size = TASK_SIZE;
48336
48337 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
48338 if (!loc) {
48339@@ -715,11 +1050,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
48340 goto out_free_dentry;
48341
48342 /* OK, This is the point of no return */
48343- current->mm->def_flags = def_flags;
48344+
48345+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48346+ current->mm->pax_flags = 0UL;
48347+#endif
48348+
48349+#ifdef CONFIG_PAX_DLRESOLVE
48350+ current->mm->call_dl_resolve = 0UL;
48351+#endif
48352+
48353+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
48354+ current->mm->call_syscall = 0UL;
48355+#endif
48356+
48357+#ifdef CONFIG_PAX_ASLR
48358+ current->mm->delta_mmap = 0UL;
48359+ current->mm->delta_stack = 0UL;
48360+ current->mm->aslr_gap = 0UL;
48361+#endif
48362+
48363+ current->mm->def_flags = 0;
48364+
48365+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48366+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
48367+ send_sig(SIGKILL, current, 0);
48368+ goto out_free_dentry;
48369+ }
48370+#endif
48371+
48372+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
48373+ pax_set_initial_flags(bprm);
48374+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
48375+ if (pax_set_initial_flags_func)
48376+ (pax_set_initial_flags_func)(bprm);
48377+#endif
48378+
48379+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48380+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
48381+ current->mm->context.user_cs_limit = PAGE_SIZE;
48382+ current->mm->def_flags |= VM_PAGEEXEC;
48383+ }
48384+#endif
48385+
48386+#ifdef CONFIG_PAX_SEGMEXEC
48387+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
48388+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
48389+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
48390+ pax_task_size = SEGMEXEC_TASK_SIZE;
48391+ current->mm->def_flags |= VM_NOHUGEPAGE;
48392+ }
48393+#endif
48394+
48395+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
48396+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48397+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
48398+ put_cpu();
48399+ }
48400+#endif
48401
48402 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
48403 may depend on the personality. */
48404 SET_PERSONALITY(loc->elf_ex);
48405+
48406+#ifdef CONFIG_PAX_ASLR
48407+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48408+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
48409+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
48410+ }
48411+#endif
48412+
48413+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48414+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48415+ executable_stack = EXSTACK_DISABLE_X;
48416+ current->personality &= ~READ_IMPLIES_EXEC;
48417+ } else
48418+#endif
48419+
48420 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
48421 current->personality |= READ_IMPLIES_EXEC;
48422
48423@@ -810,6 +1216,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
48424 #else
48425 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
48426 #endif
48427+
48428+#ifdef CONFIG_PAX_RANDMMAP
48429+ /* PaX: randomize base address at the default exe base if requested */
48430+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48431+#ifdef CONFIG_SPARC64
48432+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48433+#else
48434+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48435+#endif
48436+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48437+ elf_flags |= MAP_FIXED;
48438+ }
48439+#endif
48440+
48441 }
48442
48443 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48444@@ -842,9 +1262,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48445 * allowed task size. Note that p_filesz must always be
48446 * <= p_memsz so it is only necessary to check p_memsz.
48447 */
48448- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48449- elf_ppnt->p_memsz > TASK_SIZE ||
48450- TASK_SIZE - elf_ppnt->p_memsz < k) {
48451+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48452+ elf_ppnt->p_memsz > pax_task_size ||
48453+ pax_task_size - elf_ppnt->p_memsz < k) {
48454 /* set_brk can never work. Avoid overflows. */
48455 send_sig(SIGKILL, current, 0);
48456 retval = -EINVAL;
48457@@ -883,17 +1303,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
48458 goto out_free_dentry;
48459 }
48460 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48461- send_sig(SIGSEGV, current, 0);
48462- retval = -EFAULT; /* Nobody gets to see this, but.. */
48463- goto out_free_dentry;
48464+ /*
48465+ * This bss-zeroing can fail if the ELF
48466+ * file specifies odd protections. So
48467+ * we don't check the return value
48468+ */
48469 }
48470
48471+#ifdef CONFIG_PAX_RANDMMAP
48472+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48473+ unsigned long start, size;
48474+
48475+ start = ELF_PAGEALIGN(elf_brk);
48476+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48477+ down_read(&current->mm->mmap_sem);
48478+ retval = -ENOMEM;
48479+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48480+ unsigned long prot = PROT_NONE;
48481+
48482+ up_read(&current->mm->mmap_sem);
48483+// if (current->personality & ADDR_NO_RANDOMIZE)
48484+// prot = PROT_READ;
48485+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
48486+ retval = IS_ERR_VALUE(start) ? start : 0;
48487+ } else
48488+ up_read(&current->mm->mmap_sem);
48489+ if (retval == 0) {
48490+ current->mm->aslr_gap += PAGE_ALIGN(size) >> PAGE_SHIFT;
48491+ retval = set_brk(start + size, start + size + PAGE_SIZE);
48492+ }
48493+ if (retval < 0) {
48494+ send_sig(SIGKILL, current, 0);
48495+ goto out_free_dentry;
48496+ }
48497+ }
48498+#endif
48499+
48500 if (elf_interpreter) {
48501- unsigned long interp_map_addr = 0;
48502-
48503 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48504 interpreter,
48505- &interp_map_addr,
48506 load_bias);
48507 if (!IS_ERR((void *)elf_entry)) {
48508 /*
48509@@ -1115,7 +1563,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48510 * Decide what to dump of a segment, part, all or none.
48511 */
48512 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48513- unsigned long mm_flags)
48514+ unsigned long mm_flags, long signr)
48515 {
48516 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48517
48518@@ -1152,7 +1600,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48519 if (vma->vm_file == NULL)
48520 return 0;
48521
48522- if (FILTER(MAPPED_PRIVATE))
48523+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48524 goto whole;
48525
48526 /*
48527@@ -1374,9 +1822,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48528 {
48529 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48530 int i = 0;
48531- do
48532+ do {
48533 i += 2;
48534- while (auxv[i - 2] != AT_NULL);
48535+ } while (auxv[i - 2] != AT_NULL);
48536 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48537 }
48538
48539@@ -2006,14 +2454,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48540 }
48541
48542 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48543- unsigned long mm_flags)
48544+ struct coredump_params *cprm)
48545 {
48546 struct vm_area_struct *vma;
48547 size_t size = 0;
48548
48549 for (vma = first_vma(current, gate_vma); vma != NULL;
48550 vma = next_vma(vma, gate_vma))
48551- size += vma_dump_size(vma, mm_flags);
48552+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48553 return size;
48554 }
48555
48556@@ -2107,7 +2555,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48557
48558 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48559
48560- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48561+ offset += elf_core_vma_data_size(gate_vma, cprm);
48562 offset += elf_core_extra_data_size();
48563 e_shoff = offset;
48564
48565@@ -2121,10 +2569,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48566 offset = dataoff;
48567
48568 size += sizeof(*elf);
48569+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48570 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48571 goto end_coredump;
48572
48573 size += sizeof(*phdr4note);
48574+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48575 if (size > cprm->limit
48576 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48577 goto end_coredump;
48578@@ -2138,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48579 phdr.p_offset = offset;
48580 phdr.p_vaddr = vma->vm_start;
48581 phdr.p_paddr = 0;
48582- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48583+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48584 phdr.p_memsz = vma->vm_end - vma->vm_start;
48585 offset += phdr.p_filesz;
48586 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48587@@ -2149,6 +2599,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48588 phdr.p_align = ELF_EXEC_PAGESIZE;
48589
48590 size += sizeof(phdr);
48591+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48592 if (size > cprm->limit
48593 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48594 goto end_coredump;
48595@@ -2173,7 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48596 unsigned long addr;
48597 unsigned long end;
48598
48599- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48600+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48601
48602 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48603 struct page *page;
48604@@ -2182,6 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48605 page = get_dump_page(addr);
48606 if (page) {
48607 void *kaddr = kmap(page);
48608+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48609 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48610 !dump_write(cprm->file, kaddr,
48611 PAGE_SIZE);
48612@@ -2199,6 +2651,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48613
48614 if (e_phnum == PN_XNUM) {
48615 size += sizeof(*shdr4extnum);
48616+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48617 if (size > cprm->limit
48618 || !dump_write(cprm->file, shdr4extnum,
48619 sizeof(*shdr4extnum)))
48620@@ -2219,6 +2672,97 @@ out:
48621
48622 #endif /* CONFIG_ELF_CORE */
48623
48624+#ifdef CONFIG_PAX_MPROTECT
48625+/* PaX: non-PIC ELF libraries need relocations on their executable segments
48626+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48627+ * we'll remove VM_MAYWRITE for good on RELRO segments.
48628+ *
48629+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48630+ * basis because we want to allow the common case and not the special ones.
48631+ */
48632+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48633+{
48634+ struct elfhdr elf_h;
48635+ struct elf_phdr elf_p;
48636+ unsigned long i;
48637+ unsigned long oldflags;
48638+ bool is_textrel_rw, is_textrel_rx, is_relro;
48639+
48640+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48641+ return;
48642+
48643+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48644+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48645+
48646+#ifdef CONFIG_PAX_ELFRELOCS
48647+ /* possible TEXTREL */
48648+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48649+ 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);
48650+#else
48651+ is_textrel_rw = false;
48652+ is_textrel_rx = false;
48653+#endif
48654+
48655+ /* possible RELRO */
48656+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48657+
48658+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48659+ return;
48660+
48661+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48662+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48663+
48664+#ifdef CONFIG_PAX_ETEXECRELOCS
48665+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48666+#else
48667+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48668+#endif
48669+
48670+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48671+ !elf_check_arch(&elf_h) ||
48672+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48673+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48674+ return;
48675+
48676+ for (i = 0UL; i < elf_h.e_phnum; i++) {
48677+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48678+ return;
48679+ switch (elf_p.p_type) {
48680+ case PT_DYNAMIC:
48681+ if (!is_textrel_rw && !is_textrel_rx)
48682+ continue;
48683+ i = 0UL;
48684+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48685+ elf_dyn dyn;
48686+
48687+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48688+ return;
48689+ if (dyn.d_tag == DT_NULL)
48690+ return;
48691+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48692+ gr_log_textrel(vma);
48693+ if (is_textrel_rw)
48694+ vma->vm_flags |= VM_MAYWRITE;
48695+ else
48696+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48697+ vma->vm_flags &= ~VM_MAYWRITE;
48698+ return;
48699+ }
48700+ i++;
48701+ }
48702+ return;
48703+
48704+ case PT_GNU_RELRO:
48705+ if (!is_relro)
48706+ continue;
48707+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48708+ vma->vm_flags &= ~VM_MAYWRITE;
48709+ return;
48710+ }
48711+ }
48712+}
48713+#endif
48714+
48715 static int __init init_elf_binfmt(void)
48716 {
48717 register_binfmt(&elf_format);
48718diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48719index b563719..3868998 100644
48720--- a/fs/binfmt_flat.c
48721+++ b/fs/binfmt_flat.c
48722@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48723 realdatastart = (unsigned long) -ENOMEM;
48724 printk("Unable to allocate RAM for process data, errno %d\n",
48725 (int)-realdatastart);
48726+ down_write(&current->mm->mmap_sem);
48727 vm_munmap(textpos, text_len);
48728+ up_write(&current->mm->mmap_sem);
48729 ret = realdatastart;
48730 goto err;
48731 }
48732@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48733 }
48734 if (IS_ERR_VALUE(result)) {
48735 printk("Unable to read data+bss, errno %d\n", (int)-result);
48736+ down_write(&current->mm->mmap_sem);
48737 vm_munmap(textpos, text_len);
48738 vm_munmap(realdatastart, len);
48739+ up_write(&current->mm->mmap_sem);
48740 ret = result;
48741 goto err;
48742 }
48743@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48744 }
48745 if (IS_ERR_VALUE(result)) {
48746 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48747+ down_write(&current->mm->mmap_sem);
48748 vm_munmap(textpos, text_len + data_len + extra +
48749 MAX_SHARED_LIBS * sizeof(unsigned long));
48750+ up_write(&current->mm->mmap_sem);
48751 ret = result;
48752 goto err;
48753 }
48754diff --git a/fs/bio.c b/fs/bio.c
48755index b96fc6c..431d628 100644
48756--- a/fs/bio.c
48757+++ b/fs/bio.c
48758@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48759 /*
48760 * Overflow, abort
48761 */
48762- if (end < start)
48763+ if (end < start || end - start > INT_MAX - nr_pages)
48764 return ERR_PTR(-EINVAL);
48765
48766 nr_pages += end - start;
48767@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48768 /*
48769 * Overflow, abort
48770 */
48771- if (end < start)
48772+ if (end < start || end - start > INT_MAX - nr_pages)
48773 return ERR_PTR(-EINVAL);
48774
48775 nr_pages += end - start;
48776@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48777 const int read = bio_data_dir(bio) == READ;
48778 struct bio_map_data *bmd = bio->bi_private;
48779 int i;
48780- char *p = bmd->sgvecs[0].iov_base;
48781+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48782
48783 __bio_for_each_segment(bvec, bio, i, 0) {
48784 char *addr = page_address(bvec->bv_page);
48785diff --git a/fs/block_dev.c b/fs/block_dev.c
48786index 78edf76..da14f3f 100644
48787--- a/fs/block_dev.c
48788+++ b/fs/block_dev.c
48789@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48790 else if (bdev->bd_contains == bdev)
48791 return true; /* is a whole device which isn't held */
48792
48793- else if (whole->bd_holder == bd_may_claim)
48794+ else if (whole->bd_holder == (void *)bd_may_claim)
48795 return true; /* is a partition of a device that is being partitioned */
48796 else if (whole->bd_holder != NULL)
48797 return false; /* is a partition of a held device */
48798diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48799index eea5da7..88fead70 100644
48800--- a/fs/btrfs/ctree.c
48801+++ b/fs/btrfs/ctree.c
48802@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48803 free_extent_buffer(buf);
48804 add_root_to_dirty_list(root);
48805 } else {
48806- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48807- parent_start = parent->start;
48808- else
48809+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48810+ if (parent)
48811+ parent_start = parent->start;
48812+ else
48813+ parent_start = 0;
48814+ } else
48815 parent_start = 0;
48816
48817 WARN_ON(trans->transid != btrfs_header_generation(parent));
48818diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48819index 659ea81..0f63c1a 100644
48820--- a/fs/btrfs/inode.c
48821+++ b/fs/btrfs/inode.c
48822@@ -7300,7 +7300,7 @@ fail:
48823 return -ENOMEM;
48824 }
48825
48826-static int btrfs_getattr(struct vfsmount *mnt,
48827+int btrfs_getattr(struct vfsmount *mnt,
48828 struct dentry *dentry, struct kstat *stat)
48829 {
48830 struct inode *inode = dentry->d_inode;
48831@@ -7314,6 +7314,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48832 return 0;
48833 }
48834
48835+EXPORT_SYMBOL(btrfs_getattr);
48836+
48837+dev_t get_btrfs_dev_from_inode(struct inode *inode)
48838+{
48839+ return BTRFS_I(inode)->root->anon_dev;
48840+}
48841+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48842+
48843 /*
48844 * If a file is moved, it will inherit the cow and compression flags of the new
48845 * directory.
48846diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48847index 338f259..b657640 100644
48848--- a/fs/btrfs/ioctl.c
48849+++ b/fs/btrfs/ioctl.c
48850@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48851 for (i = 0; i < num_types; i++) {
48852 struct btrfs_space_info *tmp;
48853
48854+ /* Don't copy in more than we allocated */
48855 if (!slot_count)
48856 break;
48857
48858+ slot_count--;
48859+
48860 info = NULL;
48861 rcu_read_lock();
48862 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48863@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48864 memcpy(dest, &space, sizeof(space));
48865 dest++;
48866 space_args.total_spaces++;
48867- slot_count--;
48868 }
48869- if (!slot_count)
48870- break;
48871 }
48872 up_read(&info->groups_sem);
48873 }
48874diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48875index 300e09a..9fe4539 100644
48876--- a/fs/btrfs/relocation.c
48877+++ b/fs/btrfs/relocation.c
48878@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48879 }
48880 spin_unlock(&rc->reloc_root_tree.lock);
48881
48882- BUG_ON((struct btrfs_root *)node->data != root);
48883+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
48884
48885 if (!del) {
48886 spin_lock(&rc->reloc_root_tree.lock);
48887diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48888index d8982e9..29a85fa 100644
48889--- a/fs/btrfs/super.c
48890+++ b/fs/btrfs/super.c
48891@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48892 function, line, errstr);
48893 return;
48894 }
48895- ACCESS_ONCE(trans->transaction->aborted) = errno;
48896+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48897 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48898 }
48899 /*
48900diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48901index 622f469..e8d2d55 100644
48902--- a/fs/cachefiles/bind.c
48903+++ b/fs/cachefiles/bind.c
48904@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48905 args);
48906
48907 /* start by checking things over */
48908- ASSERT(cache->fstop_percent >= 0 &&
48909- cache->fstop_percent < cache->fcull_percent &&
48910+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
48911 cache->fcull_percent < cache->frun_percent &&
48912 cache->frun_percent < 100);
48913
48914- ASSERT(cache->bstop_percent >= 0 &&
48915- cache->bstop_percent < cache->bcull_percent &&
48916+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
48917 cache->bcull_percent < cache->brun_percent &&
48918 cache->brun_percent < 100);
48919
48920diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48921index 0a1467b..6a53245 100644
48922--- a/fs/cachefiles/daemon.c
48923+++ b/fs/cachefiles/daemon.c
48924@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48925 if (n > buflen)
48926 return -EMSGSIZE;
48927
48928- if (copy_to_user(_buffer, buffer, n) != 0)
48929+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48930 return -EFAULT;
48931
48932 return n;
48933@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48934 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48935 return -EIO;
48936
48937- if (datalen < 0 || datalen > PAGE_SIZE - 1)
48938+ if (datalen > PAGE_SIZE - 1)
48939 return -EOPNOTSUPP;
48940
48941 /* drag the command string into the kernel so we can parse it */
48942@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48943 if (args[0] != '%' || args[1] != '\0')
48944 return -EINVAL;
48945
48946- if (fstop < 0 || fstop >= cache->fcull_percent)
48947+ if (fstop >= cache->fcull_percent)
48948 return cachefiles_daemon_range_error(cache, args);
48949
48950 cache->fstop_percent = fstop;
48951@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48952 if (args[0] != '%' || args[1] != '\0')
48953 return -EINVAL;
48954
48955- if (bstop < 0 || bstop >= cache->bcull_percent)
48956+ if (bstop >= cache->bcull_percent)
48957 return cachefiles_daemon_range_error(cache, args);
48958
48959 cache->bstop_percent = bstop;
48960diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48961index 4938251..7e01445 100644
48962--- a/fs/cachefiles/internal.h
48963+++ b/fs/cachefiles/internal.h
48964@@ -59,7 +59,7 @@ struct cachefiles_cache {
48965 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48966 struct rb_root active_nodes; /* active nodes (can't be culled) */
48967 rwlock_t active_lock; /* lock for active_nodes */
48968- atomic_t gravecounter; /* graveyard uniquifier */
48969+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48970 unsigned frun_percent; /* when to stop culling (% files) */
48971 unsigned fcull_percent; /* when to start culling (% files) */
48972 unsigned fstop_percent; /* when to stop allocating (% files) */
48973@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
48974 * proc.c
48975 */
48976 #ifdef CONFIG_CACHEFILES_HISTOGRAM
48977-extern atomic_t cachefiles_lookup_histogram[HZ];
48978-extern atomic_t cachefiles_mkdir_histogram[HZ];
48979-extern atomic_t cachefiles_create_histogram[HZ];
48980+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48981+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48982+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
48983
48984 extern int __init cachefiles_proc_init(void);
48985 extern void cachefiles_proc_cleanup(void);
48986 static inline
48987-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
48988+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
48989 {
48990 unsigned long jif = jiffies - start_jif;
48991 if (jif >= HZ)
48992 jif = HZ - 1;
48993- atomic_inc(&histogram[jif]);
48994+ atomic_inc_unchecked(&histogram[jif]);
48995 }
48996
48997 #else
48998diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
48999index 8c01c5fc..15f982e 100644
49000--- a/fs/cachefiles/namei.c
49001+++ b/fs/cachefiles/namei.c
49002@@ -317,7 +317,7 @@ try_again:
49003 /* first step is to make up a grave dentry in the graveyard */
49004 sprintf(nbuffer, "%08x%08x",
49005 (uint32_t) get_seconds(),
49006- (uint32_t) atomic_inc_return(&cache->gravecounter));
49007+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49008
49009 /* do the multiway lock magic */
49010 trap = lock_rename(cache->graveyard, dir);
49011diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49012index eccd339..4c1d995 100644
49013--- a/fs/cachefiles/proc.c
49014+++ b/fs/cachefiles/proc.c
49015@@ -14,9 +14,9 @@
49016 #include <linux/seq_file.h>
49017 #include "internal.h"
49018
49019-atomic_t cachefiles_lookup_histogram[HZ];
49020-atomic_t cachefiles_mkdir_histogram[HZ];
49021-atomic_t cachefiles_create_histogram[HZ];
49022+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49023+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49024+atomic_unchecked_t cachefiles_create_histogram[HZ];
49025
49026 /*
49027 * display the latency histogram
49028@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49029 return 0;
49030 default:
49031 index = (unsigned long) v - 3;
49032- x = atomic_read(&cachefiles_lookup_histogram[index]);
49033- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49034- z = atomic_read(&cachefiles_create_histogram[index]);
49035+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49036+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49037+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49038 if (x == 0 && y == 0 && z == 0)
49039 return 0;
49040
49041diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49042index 4809922..aab2c39 100644
49043--- a/fs/cachefiles/rdwr.c
49044+++ b/fs/cachefiles/rdwr.c
49045@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49046 old_fs = get_fs();
49047 set_fs(KERNEL_DS);
49048 ret = file->f_op->write(
49049- file, (const void __user *) data, len, &pos);
49050+ file, (const void __force_user *) data, len, &pos);
49051 set_fs(old_fs);
49052 kunmap(page);
49053 if (ret != len)
49054diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49055index 8c1aabe..bbf856a 100644
49056--- a/fs/ceph/dir.c
49057+++ b/fs/ceph/dir.c
49058@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49059 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49060 struct ceph_mds_client *mdsc = fsc->mdsc;
49061 unsigned frag = fpos_frag(filp->f_pos);
49062- int off = fpos_off(filp->f_pos);
49063+ unsigned int off = fpos_off(filp->f_pos);
49064 int err;
49065 u32 ftype;
49066 struct ceph_mds_reply_info_parsed *rinfo;
49067diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49068index d9ea6ed..1e6c8ac 100644
49069--- a/fs/cifs/cifs_debug.c
49070+++ b/fs/cifs/cifs_debug.c
49071@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49072
49073 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49074 #ifdef CONFIG_CIFS_STATS2
49075- atomic_set(&totBufAllocCount, 0);
49076- atomic_set(&totSmBufAllocCount, 0);
49077+ atomic_set_unchecked(&totBufAllocCount, 0);
49078+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49079 #endif /* CONFIG_CIFS_STATS2 */
49080 spin_lock(&cifs_tcp_ses_lock);
49081 list_for_each(tmp1, &cifs_tcp_ses_list) {
49082@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49083 tcon = list_entry(tmp3,
49084 struct cifs_tcon,
49085 tcon_list);
49086- atomic_set(&tcon->num_smbs_sent, 0);
49087+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49088 if (server->ops->clear_stats)
49089 server->ops->clear_stats(tcon);
49090 }
49091@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49092 smBufAllocCount.counter, cifs_min_small);
49093 #ifdef CONFIG_CIFS_STATS2
49094 seq_printf(m, "Total Large %d Small %d Allocations\n",
49095- atomic_read(&totBufAllocCount),
49096- atomic_read(&totSmBufAllocCount));
49097+ atomic_read_unchecked(&totBufAllocCount),
49098+ atomic_read_unchecked(&totSmBufAllocCount));
49099 #endif /* CONFIG_CIFS_STATS2 */
49100
49101 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49102@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49103 if (tcon->need_reconnect)
49104 seq_puts(m, "\tDISCONNECTED ");
49105 seq_printf(m, "\nSMBs: %d",
49106- atomic_read(&tcon->num_smbs_sent));
49107+ atomic_read_unchecked(&tcon->num_smbs_sent));
49108 if (server->ops->print_stats)
49109 server->ops->print_stats(m, tcon);
49110 }
49111diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49112index e328339..322228b 100644
49113--- a/fs/cifs/cifsfs.c
49114+++ b/fs/cifs/cifsfs.c
49115@@ -1002,7 +1002,7 @@ cifs_init_request_bufs(void)
49116 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49117 cifs_req_cachep = kmem_cache_create("cifs_request",
49118 CIFSMaxBufSize + max_hdr_size, 0,
49119- SLAB_HWCACHE_ALIGN, NULL);
49120+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49121 if (cifs_req_cachep == NULL)
49122 return -ENOMEM;
49123
49124@@ -1029,7 +1029,7 @@ cifs_init_request_bufs(void)
49125 efficient to alloc 1 per page off the slab compared to 17K (5page)
49126 alloc of large cifs buffers even when page debugging is on */
49127 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49128- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49129+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49130 NULL);
49131 if (cifs_sm_req_cachep == NULL) {
49132 mempool_destroy(cifs_req_poolp);
49133@@ -1114,8 +1114,8 @@ init_cifs(void)
49134 atomic_set(&bufAllocCount, 0);
49135 atomic_set(&smBufAllocCount, 0);
49136 #ifdef CONFIG_CIFS_STATS2
49137- atomic_set(&totBufAllocCount, 0);
49138- atomic_set(&totSmBufAllocCount, 0);
49139+ atomic_set_unchecked(&totBufAllocCount, 0);
49140+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49141 #endif /* CONFIG_CIFS_STATS2 */
49142
49143 atomic_set(&midCount, 0);
49144diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49145index e6899ce..d6b2920 100644
49146--- a/fs/cifs/cifsglob.h
49147+++ b/fs/cifs/cifsglob.h
49148@@ -751,35 +751,35 @@ struct cifs_tcon {
49149 __u16 Flags; /* optional support bits */
49150 enum statusEnum tidStatus;
49151 #ifdef CONFIG_CIFS_STATS
49152- atomic_t num_smbs_sent;
49153+ atomic_unchecked_t num_smbs_sent;
49154 union {
49155 struct {
49156- atomic_t num_writes;
49157- atomic_t num_reads;
49158- atomic_t num_flushes;
49159- atomic_t num_oplock_brks;
49160- atomic_t num_opens;
49161- atomic_t num_closes;
49162- atomic_t num_deletes;
49163- atomic_t num_mkdirs;
49164- atomic_t num_posixopens;
49165- atomic_t num_posixmkdirs;
49166- atomic_t num_rmdirs;
49167- atomic_t num_renames;
49168- atomic_t num_t2renames;
49169- atomic_t num_ffirst;
49170- atomic_t num_fnext;
49171- atomic_t num_fclose;
49172- atomic_t num_hardlinks;
49173- atomic_t num_symlinks;
49174- atomic_t num_locks;
49175- atomic_t num_acl_get;
49176- atomic_t num_acl_set;
49177+ atomic_unchecked_t num_writes;
49178+ atomic_unchecked_t num_reads;
49179+ atomic_unchecked_t num_flushes;
49180+ atomic_unchecked_t num_oplock_brks;
49181+ atomic_unchecked_t num_opens;
49182+ atomic_unchecked_t num_closes;
49183+ atomic_unchecked_t num_deletes;
49184+ atomic_unchecked_t num_mkdirs;
49185+ atomic_unchecked_t num_posixopens;
49186+ atomic_unchecked_t num_posixmkdirs;
49187+ atomic_unchecked_t num_rmdirs;
49188+ atomic_unchecked_t num_renames;
49189+ atomic_unchecked_t num_t2renames;
49190+ atomic_unchecked_t num_ffirst;
49191+ atomic_unchecked_t num_fnext;
49192+ atomic_unchecked_t num_fclose;
49193+ atomic_unchecked_t num_hardlinks;
49194+ atomic_unchecked_t num_symlinks;
49195+ atomic_unchecked_t num_locks;
49196+ atomic_unchecked_t num_acl_get;
49197+ atomic_unchecked_t num_acl_set;
49198 } cifs_stats;
49199 #ifdef CONFIG_CIFS_SMB2
49200 struct {
49201- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49202- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49203+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49204+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49205 } smb2_stats;
49206 #endif /* CONFIG_CIFS_SMB2 */
49207 } stats;
49208@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49209 }
49210
49211 #ifdef CONFIG_CIFS_STATS
49212-#define cifs_stats_inc atomic_inc
49213+#define cifs_stats_inc atomic_inc_unchecked
49214
49215 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49216 unsigned int bytes)
49217@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49218 /* Various Debug counters */
49219 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49220 #ifdef CONFIG_CIFS_STATS2
49221-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49222-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49223+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49224+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49225 #endif
49226 GLOBAL_EXTERN atomic_t smBufAllocCount;
49227 GLOBAL_EXTERN atomic_t midCount;
49228diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49229index 51dc2fb..1e12a33 100644
49230--- a/fs/cifs/link.c
49231+++ b/fs/cifs/link.c
49232@@ -616,7 +616,7 @@ symlink_exit:
49233
49234 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49235 {
49236- char *p = nd_get_link(nd);
49237+ const char *p = nd_get_link(nd);
49238 if (!IS_ERR(p))
49239 kfree(p);
49240 }
49241diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49242index 3a00c0d..42d901c 100644
49243--- a/fs/cifs/misc.c
49244+++ b/fs/cifs/misc.c
49245@@ -169,7 +169,7 @@ cifs_buf_get(void)
49246 memset(ret_buf, 0, buf_size + 3);
49247 atomic_inc(&bufAllocCount);
49248 #ifdef CONFIG_CIFS_STATS2
49249- atomic_inc(&totBufAllocCount);
49250+ atomic_inc_unchecked(&totBufAllocCount);
49251 #endif /* CONFIG_CIFS_STATS2 */
49252 }
49253
49254@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49255 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49256 atomic_inc(&smBufAllocCount);
49257 #ifdef CONFIG_CIFS_STATS2
49258- atomic_inc(&totSmBufAllocCount);
49259+ atomic_inc_unchecked(&totSmBufAllocCount);
49260 #endif /* CONFIG_CIFS_STATS2 */
49261
49262 }
49263diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49264index 47bc5a8..10decbe 100644
49265--- a/fs/cifs/smb1ops.c
49266+++ b/fs/cifs/smb1ops.c
49267@@ -586,27 +586,27 @@ static void
49268 cifs_clear_stats(struct cifs_tcon *tcon)
49269 {
49270 #ifdef CONFIG_CIFS_STATS
49271- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49272- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49273- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49274- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49275- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49276- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49277- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49278- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49279- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49280- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49281- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49282- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49283- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49284- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49285- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49286- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49287- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49288- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49289- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49290- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49291- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49292+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49293+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49294+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49295+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49296+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49297+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49298+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49299+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49300+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49301+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49302+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49303+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49304+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49305+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49306+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49307+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49308+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49309+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49310+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49311+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49312+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49313 #endif
49314 }
49315
49316@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49317 {
49318 #ifdef CONFIG_CIFS_STATS
49319 seq_printf(m, " Oplocks breaks: %d",
49320- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49321+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49322 seq_printf(m, "\nReads: %d Bytes: %llu",
49323- atomic_read(&tcon->stats.cifs_stats.num_reads),
49324+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49325 (long long)(tcon->bytes_read));
49326 seq_printf(m, "\nWrites: %d Bytes: %llu",
49327- atomic_read(&tcon->stats.cifs_stats.num_writes),
49328+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49329 (long long)(tcon->bytes_written));
49330 seq_printf(m, "\nFlushes: %d",
49331- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49332+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49333 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49334- atomic_read(&tcon->stats.cifs_stats.num_locks),
49335- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49336- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49337+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49338+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49339+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49340 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
49341- atomic_read(&tcon->stats.cifs_stats.num_opens),
49342- atomic_read(&tcon->stats.cifs_stats.num_closes),
49343- atomic_read(&tcon->stats.cifs_stats.num_deletes));
49344+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
49345+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
49346+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
49347 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
49348- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
49349- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
49350+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
49351+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
49352 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
49353- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
49354- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
49355+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
49356+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
49357 seq_printf(m, "\nRenames: %d T2 Renames %d",
49358- atomic_read(&tcon->stats.cifs_stats.num_renames),
49359- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
49360+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
49361+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
49362 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
49363- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
49364- atomic_read(&tcon->stats.cifs_stats.num_fnext),
49365- atomic_read(&tcon->stats.cifs_stats.num_fclose));
49366+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
49367+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
49368+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
49369 #endif
49370 }
49371
49372diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
49373index bceffe7..cd1ae59 100644
49374--- a/fs/cifs/smb2ops.c
49375+++ b/fs/cifs/smb2ops.c
49376@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
49377 #ifdef CONFIG_CIFS_STATS
49378 int i;
49379 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
49380- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49381- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49382+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49383+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49384 }
49385 #endif
49386 }
49387@@ -284,66 +284,66 @@ static void
49388 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49389 {
49390 #ifdef CONFIG_CIFS_STATS
49391- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49392- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49393+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49394+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49395 seq_printf(m, "\nNegotiates: %d sent %d failed",
49396- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
49397- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
49398+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
49399+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
49400 seq_printf(m, "\nSessionSetups: %d sent %d failed",
49401- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
49402- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
49403+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
49404+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
49405 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
49406 seq_printf(m, "\nLogoffs: %d sent %d failed",
49407- atomic_read(&sent[SMB2_LOGOFF_HE]),
49408- atomic_read(&failed[SMB2_LOGOFF_HE]));
49409+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
49410+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
49411 seq_printf(m, "\nTreeConnects: %d sent %d failed",
49412- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
49413- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
49414+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
49415+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
49416 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
49417- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
49418- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
49419+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
49420+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
49421 seq_printf(m, "\nCreates: %d sent %d failed",
49422- atomic_read(&sent[SMB2_CREATE_HE]),
49423- atomic_read(&failed[SMB2_CREATE_HE]));
49424+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
49425+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
49426 seq_printf(m, "\nCloses: %d sent %d failed",
49427- atomic_read(&sent[SMB2_CLOSE_HE]),
49428- atomic_read(&failed[SMB2_CLOSE_HE]));
49429+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49430+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49431 seq_printf(m, "\nFlushes: %d sent %d failed",
49432- atomic_read(&sent[SMB2_FLUSH_HE]),
49433- atomic_read(&failed[SMB2_FLUSH_HE]));
49434+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49435+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49436 seq_printf(m, "\nReads: %d sent %d failed",
49437- atomic_read(&sent[SMB2_READ_HE]),
49438- atomic_read(&failed[SMB2_READ_HE]));
49439+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
49440+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
49441 seq_printf(m, "\nWrites: %d sent %d failed",
49442- atomic_read(&sent[SMB2_WRITE_HE]),
49443- atomic_read(&failed[SMB2_WRITE_HE]));
49444+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49445+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49446 seq_printf(m, "\nLocks: %d sent %d failed",
49447- atomic_read(&sent[SMB2_LOCK_HE]),
49448- atomic_read(&failed[SMB2_LOCK_HE]));
49449+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49450+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49451 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49452- atomic_read(&sent[SMB2_IOCTL_HE]),
49453- atomic_read(&failed[SMB2_IOCTL_HE]));
49454+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49455+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49456 seq_printf(m, "\nCancels: %d sent %d failed",
49457- atomic_read(&sent[SMB2_CANCEL_HE]),
49458- atomic_read(&failed[SMB2_CANCEL_HE]));
49459+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49460+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49461 seq_printf(m, "\nEchos: %d sent %d failed",
49462- atomic_read(&sent[SMB2_ECHO_HE]),
49463- atomic_read(&failed[SMB2_ECHO_HE]));
49464+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49465+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49466 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49467- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49468- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49469+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49470+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49471 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49472- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49473- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49474+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49475+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49476 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49477- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49478- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49479+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49480+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49481 seq_printf(m, "\nSetInfos: %d sent %d failed",
49482- atomic_read(&sent[SMB2_SET_INFO_HE]),
49483- atomic_read(&failed[SMB2_SET_INFO_HE]));
49484+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49485+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49486 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49487- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49488- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49489+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49490+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49491 #endif
49492 }
49493
49494diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49495index 41d9d07..dbb4772 100644
49496--- a/fs/cifs/smb2pdu.c
49497+++ b/fs/cifs/smb2pdu.c
49498@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49499 default:
49500 cERROR(1, "info level %u isn't supported",
49501 srch_inf->info_level);
49502- rc = -EINVAL;
49503- goto qdir_exit;
49504+ return -EINVAL;
49505 }
49506
49507 req->FileIndex = cpu_to_le32(index);
49508diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49509index 958ae0e..505c9d0 100644
49510--- a/fs/coda/cache.c
49511+++ b/fs/coda/cache.c
49512@@ -24,7 +24,7 @@
49513 #include "coda_linux.h"
49514 #include "coda_cache.h"
49515
49516-static atomic_t permission_epoch = ATOMIC_INIT(0);
49517+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49518
49519 /* replace or extend an acl cache hit */
49520 void coda_cache_enter(struct inode *inode, int mask)
49521@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49522 struct coda_inode_info *cii = ITOC(inode);
49523
49524 spin_lock(&cii->c_lock);
49525- cii->c_cached_epoch = atomic_read(&permission_epoch);
49526+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49527 if (cii->c_uid != current_fsuid()) {
49528 cii->c_uid = current_fsuid();
49529 cii->c_cached_perm = mask;
49530@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49531 {
49532 struct coda_inode_info *cii = ITOC(inode);
49533 spin_lock(&cii->c_lock);
49534- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49535+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49536 spin_unlock(&cii->c_lock);
49537 }
49538
49539 /* remove all acl caches */
49540 void coda_cache_clear_all(struct super_block *sb)
49541 {
49542- atomic_inc(&permission_epoch);
49543+ atomic_inc_unchecked(&permission_epoch);
49544 }
49545
49546
49547@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49548 spin_lock(&cii->c_lock);
49549 hit = (mask & cii->c_cached_perm) == mask &&
49550 cii->c_uid == current_fsuid() &&
49551- cii->c_cached_epoch == atomic_read(&permission_epoch);
49552+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49553 spin_unlock(&cii->c_lock);
49554
49555 return hit;
49556diff --git a/fs/compat.c b/fs/compat.c
49557index a06dcbc..dacb6d3 100644
49558--- a/fs/compat.c
49559+++ b/fs/compat.c
49560@@ -54,7 +54,7 @@
49561 #include <asm/ioctls.h>
49562 #include "internal.h"
49563
49564-int compat_log = 1;
49565+int compat_log = 0;
49566
49567 int compat_printk(const char *fmt, ...)
49568 {
49569@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49570
49571 set_fs(KERNEL_DS);
49572 /* The __user pointer cast is valid because of the set_fs() */
49573- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49574+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49575 set_fs(oldfs);
49576 /* truncating is ok because it's a user address */
49577 if (!ret)
49578@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49579 goto out;
49580
49581 ret = -EINVAL;
49582- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49583+ if (nr_segs > UIO_MAXIOV)
49584 goto out;
49585 if (nr_segs > fast_segs) {
49586 ret = -ENOMEM;
49587@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
49588
49589 struct compat_readdir_callback {
49590 struct compat_old_linux_dirent __user *dirent;
49591+ struct file * file;
49592 int result;
49593 };
49594
49595@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49596 buf->result = -EOVERFLOW;
49597 return -EOVERFLOW;
49598 }
49599+
49600+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49601+ return 0;
49602+
49603 buf->result++;
49604 dirent = buf->dirent;
49605 if (!access_ok(VERIFY_WRITE, dirent,
49606@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49607
49608 buf.result = 0;
49609 buf.dirent = dirent;
49610+ buf.file = f.file;
49611
49612 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49613 if (buf.result)
49614@@ -901,6 +907,7 @@ struct compat_linux_dirent {
49615 struct compat_getdents_callback {
49616 struct compat_linux_dirent __user *current_dir;
49617 struct compat_linux_dirent __user *previous;
49618+ struct file * file;
49619 int count;
49620 int error;
49621 };
49622@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49623 buf->error = -EOVERFLOW;
49624 return -EOVERFLOW;
49625 }
49626+
49627+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49628+ return 0;
49629+
49630 dirent = buf->previous;
49631 if (dirent) {
49632 if (__put_user(offset, &dirent->d_off))
49633@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49634 buf.previous = NULL;
49635 buf.count = count;
49636 buf.error = 0;
49637+ buf.file = f.file;
49638
49639 error = vfs_readdir(f.file, compat_filldir, &buf);
49640 if (error >= 0)
49641@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49642 struct compat_getdents_callback64 {
49643 struct linux_dirent64 __user *current_dir;
49644 struct linux_dirent64 __user *previous;
49645+ struct file * file;
49646 int count;
49647 int error;
49648 };
49649@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49650 buf->error = -EINVAL; /* only used if we fail.. */
49651 if (reclen > buf->count)
49652 return -EINVAL;
49653+
49654+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49655+ return 0;
49656+
49657 dirent = buf->previous;
49658
49659 if (dirent) {
49660@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49661 buf.previous = NULL;
49662 buf.count = count;
49663 buf.error = 0;
49664+ buf.file = f.file;
49665
49666 error = vfs_readdir(f.file, compat_filldir64, &buf);
49667 if (error >= 0)
49668 error = buf.error;
49669 lastdirent = buf.previous;
49670 if (lastdirent) {
49671- typeof(lastdirent->d_off) d_off = f.file->f_pos;
49672+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49673 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49674 error = -EFAULT;
49675 else
49676diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49677index a81147e..20bf2b5 100644
49678--- a/fs/compat_binfmt_elf.c
49679+++ b/fs/compat_binfmt_elf.c
49680@@ -30,11 +30,13 @@
49681 #undef elf_phdr
49682 #undef elf_shdr
49683 #undef elf_note
49684+#undef elf_dyn
49685 #undef elf_addr_t
49686 #define elfhdr elf32_hdr
49687 #define elf_phdr elf32_phdr
49688 #define elf_shdr elf32_shdr
49689 #define elf_note elf32_note
49690+#define elf_dyn Elf32_Dyn
49691 #define elf_addr_t Elf32_Addr
49692
49693 /*
49694diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49695index e2f57a0..3c78771 100644
49696--- a/fs/compat_ioctl.c
49697+++ b/fs/compat_ioctl.c
49698@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49699 return -EFAULT;
49700 if (__get_user(udata, &ss32->iomem_base))
49701 return -EFAULT;
49702- ss.iomem_base = compat_ptr(udata);
49703+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49704 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49705 __get_user(ss.port_high, &ss32->port_high))
49706 return -EFAULT;
49707@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49708 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49709 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49710 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49711- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49712+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49713 return -EFAULT;
49714
49715 return ioctl_preallocate(file, p);
49716@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49717 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49718 {
49719 unsigned int a, b;
49720- a = *(unsigned int *)p;
49721- b = *(unsigned int *)q;
49722+ a = *(const unsigned int *)p;
49723+ b = *(const unsigned int *)q;
49724 if (a > b)
49725 return 1;
49726 if (a < b)
49727diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49728index 712b10f..c33c4ca 100644
49729--- a/fs/configfs/dir.c
49730+++ b/fs/configfs/dir.c
49731@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49732 static int configfs_depend_prep(struct dentry *origin,
49733 struct config_item *target)
49734 {
49735- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49736+ struct configfs_dirent *child_sd, *sd;
49737 int ret = 0;
49738
49739- BUG_ON(!origin || !sd);
49740+ BUG_ON(!origin || !origin->d_fsdata);
49741+ sd = origin->d_fsdata;
49742
49743 if (sd->s_element == target) /* Boo-yah */
49744 goto out;
49745@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49746 }
49747 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49748 struct configfs_dirent *next;
49749- const char * name;
49750+ const unsigned char * name;
49751+ char d_name[sizeof(next->s_dentry->d_iname)];
49752 int len;
49753 struct inode *inode = NULL;
49754
49755@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49756 continue;
49757
49758 name = configfs_get_name(next);
49759- len = strlen(name);
49760+ if (next->s_dentry && name == next->s_dentry->d_iname) {
49761+ len = next->s_dentry->d_name.len;
49762+ memcpy(d_name, name, len);
49763+ name = d_name;
49764+ } else
49765+ len = strlen(name);
49766
49767 /*
49768 * We'll have a dentry and an inode for
49769diff --git a/fs/coredump.c b/fs/coredump.c
49770index 1774932..5812106 100644
49771--- a/fs/coredump.c
49772+++ b/fs/coredump.c
49773@@ -52,7 +52,7 @@ struct core_name {
49774 char *corename;
49775 int used, size;
49776 };
49777-static atomic_t call_count = ATOMIC_INIT(1);
49778+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49779
49780 /* The maximal length of core_pattern is also specified in sysctl.c */
49781
49782@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49783 {
49784 char *old_corename = cn->corename;
49785
49786- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49787+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49788 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49789
49790 if (!cn->corename) {
49791@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49792 int pid_in_pattern = 0;
49793 int err = 0;
49794
49795- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49796+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49797 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49798 cn->used = 0;
49799
49800@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49801 pipe = file->f_path.dentry->d_inode->i_pipe;
49802
49803 pipe_lock(pipe);
49804- pipe->readers++;
49805- pipe->writers--;
49806+ atomic_inc(&pipe->readers);
49807+ atomic_dec(&pipe->writers);
49808
49809- while ((pipe->readers > 1) && (!signal_pending(current))) {
49810+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49811 wake_up_interruptible_sync(&pipe->wait);
49812 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49813 pipe_wait(pipe);
49814 }
49815
49816- pipe->readers--;
49817- pipe->writers++;
49818+ atomic_dec(&pipe->readers);
49819+ atomic_inc(&pipe->writers);
49820 pipe_unlock(pipe);
49821
49822 }
49823@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49824 int ispipe;
49825 struct files_struct *displaced;
49826 bool need_nonrelative = false;
49827- static atomic_t core_dump_count = ATOMIC_INIT(0);
49828+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49829+ long signr = siginfo->si_signo;
49830 struct coredump_params cprm = {
49831 .siginfo = siginfo,
49832 .regs = signal_pt_regs(),
49833@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49834 .mm_flags = mm->flags,
49835 };
49836
49837- audit_core_dumps(siginfo->si_signo);
49838+ audit_core_dumps(signr);
49839+
49840+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49841+ gr_handle_brute_attach(cprm.mm_flags);
49842
49843 binfmt = mm->binfmt;
49844 if (!binfmt || !binfmt->core_dump)
49845@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49846 need_nonrelative = true;
49847 }
49848
49849- retval = coredump_wait(siginfo->si_signo, &core_state);
49850+ retval = coredump_wait(signr, &core_state);
49851 if (retval < 0)
49852 goto fail_creds;
49853
49854@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49855 }
49856 cprm.limit = RLIM_INFINITY;
49857
49858- dump_count = atomic_inc_return(&core_dump_count);
49859+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
49860 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49861 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49862 task_tgid_vnr(current), current->comm);
49863@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49864 } else {
49865 struct inode *inode;
49866
49867+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49868+
49869 if (cprm.limit < binfmt->min_coredump)
49870 goto fail_unlock;
49871
49872@@ -640,7 +646,7 @@ close_fail:
49873 filp_close(cprm.file, NULL);
49874 fail_dropcount:
49875 if (ispipe)
49876- atomic_dec(&core_dump_count);
49877+ atomic_dec_unchecked(&core_dump_count);
49878 fail_unlock:
49879 kfree(cn.corename);
49880 fail_corename:
49881@@ -659,7 +665,7 @@ fail:
49882 */
49883 int dump_write(struct file *file, const void *addr, int nr)
49884 {
49885- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49886+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49887 }
49888 EXPORT_SYMBOL(dump_write);
49889
49890diff --git a/fs/dcache.c b/fs/dcache.c
49891index 19153a0..428c2f5 100644
49892--- a/fs/dcache.c
49893+++ b/fs/dcache.c
49894@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49895 mempages -= reserve;
49896
49897 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49898- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49899+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49900
49901 dcache_init();
49902 inode_init();
49903diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49904index a5f12b7..4ee8a6f 100644
49905--- a/fs/debugfs/inode.c
49906+++ b/fs/debugfs/inode.c
49907@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49908 */
49909 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49910 {
49911+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49912+ return __create_file(name, S_IFDIR | S_IRWXU,
49913+#else
49914 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49915+#endif
49916 parent, NULL, NULL);
49917 }
49918 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49919diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49920index cc7709e..7e7211f 100644
49921--- a/fs/ecryptfs/inode.c
49922+++ b/fs/ecryptfs/inode.c
49923@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49924 old_fs = get_fs();
49925 set_fs(get_ds());
49926 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49927- (char __user *)lower_buf,
49928+ (char __force_user *)lower_buf,
49929 PATH_MAX);
49930 set_fs(old_fs);
49931 if (rc < 0)
49932@@ -706,7 +706,7 @@ out:
49933 static void
49934 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49935 {
49936- char *buf = nd_get_link(nd);
49937+ const char *buf = nd_get_link(nd);
49938 if (!IS_ERR(buf)) {
49939 /* Free the char* */
49940 kfree(buf);
49941diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49942index 412e6ed..4292d22 100644
49943--- a/fs/ecryptfs/miscdev.c
49944+++ b/fs/ecryptfs/miscdev.c
49945@@ -315,7 +315,7 @@ check_list:
49946 goto out_unlock_msg_ctx;
49947 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49948 if (msg_ctx->msg) {
49949- if (copy_to_user(&buf[i], packet_length, packet_length_size))
49950+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49951 goto out_unlock_msg_ctx;
49952 i += packet_length_size;
49953 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49954diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49955index b2a34a1..162fa69 100644
49956--- a/fs/ecryptfs/read_write.c
49957+++ b/fs/ecryptfs/read_write.c
49958@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49959 return -EIO;
49960 fs_save = get_fs();
49961 set_fs(get_ds());
49962- rc = vfs_write(lower_file, data, size, &offset);
49963+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49964 set_fs(fs_save);
49965 mark_inode_dirty_sync(ecryptfs_inode);
49966 return rc;
49967@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49968 return -EIO;
49969 fs_save = get_fs();
49970 set_fs(get_ds());
49971- rc = vfs_read(lower_file, data, size, &offset);
49972+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
49973 set_fs(fs_save);
49974 return rc;
49975 }
49976diff --git a/fs/exec.c b/fs/exec.c
49977index 20df02c..860e87f 100644
49978--- a/fs/exec.c
49979+++ b/fs/exec.c
49980@@ -55,6 +55,17 @@
49981 #include <linux/pipe_fs_i.h>
49982 #include <linux/oom.h>
49983 #include <linux/compat.h>
49984+#include <linux/random.h>
49985+#include <linux/seq_file.h>
49986+#include <linux/coredump.h>
49987+#include <linux/mman.h>
49988+
49989+#ifdef CONFIG_PAX_REFCOUNT
49990+#include <linux/kallsyms.h>
49991+#include <linux/kdebug.h>
49992+#endif
49993+
49994+#include <trace/events/fs.h>
49995
49996 #include <asm/uaccess.h>
49997 #include <asm/mmu_context.h>
49998@@ -66,6 +77,18 @@
49999
50000 #include <trace/events/sched.h>
50001
50002+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50003+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50004+{
50005+ 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");
50006+}
50007+#endif
50008+
50009+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50010+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50011+EXPORT_SYMBOL(pax_set_initial_flags_func);
50012+#endif
50013+
50014 int suid_dumpable = 0;
50015
50016 static LIST_HEAD(formats);
50017@@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50018 {
50019 BUG_ON(!fmt);
50020 write_lock(&binfmt_lock);
50021- insert ? list_add(&fmt->lh, &formats) :
50022- list_add_tail(&fmt->lh, &formats);
50023+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50024+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50025 write_unlock(&binfmt_lock);
50026 }
50027
50028@@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
50029 void unregister_binfmt(struct linux_binfmt * fmt)
50030 {
50031 write_lock(&binfmt_lock);
50032- list_del(&fmt->lh);
50033+ pax_list_del((struct list_head *)&fmt->lh);
50034 write_unlock(&binfmt_lock);
50035 }
50036
50037@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50038 int write)
50039 {
50040 struct page *page;
50041- int ret;
50042
50043-#ifdef CONFIG_STACK_GROWSUP
50044- if (write) {
50045- ret = expand_downwards(bprm->vma, pos);
50046- if (ret < 0)
50047- return NULL;
50048- }
50049-#endif
50050- ret = get_user_pages(current, bprm->mm, pos,
50051- 1, write, 1, &page, NULL);
50052- if (ret <= 0)
50053+ if (0 > expand_downwards(bprm->vma, pos))
50054+ return NULL;
50055+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50056 return NULL;
50057
50058 if (write) {
50059@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50060 if (size <= ARG_MAX)
50061 return page;
50062
50063+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50064+ // only allow 512KB for argv+env on suid/sgid binaries
50065+ // to prevent easy ASLR exhaustion
50066+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50067+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50068+ (size > (512 * 1024))) {
50069+ put_page(page);
50070+ return NULL;
50071+ }
50072+#endif
50073+
50074 /*
50075 * Limit to 1/4-th the stack size for the argv+env strings.
50076 * This ensures that:
50077@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50078 vma->vm_end = STACK_TOP_MAX;
50079 vma->vm_start = vma->vm_end - PAGE_SIZE;
50080 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50081+
50082+#ifdef CONFIG_PAX_SEGMEXEC
50083+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50084+#endif
50085+
50086 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50087 INIT_LIST_HEAD(&vma->anon_vma_chain);
50088
50089@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50090 mm->stack_vm = mm->total_vm = 1;
50091 up_write(&mm->mmap_sem);
50092 bprm->p = vma->vm_end - sizeof(void *);
50093+
50094+#ifdef CONFIG_PAX_RANDUSTACK
50095+ if (randomize_va_space)
50096+ bprm->p ^= random32() & ~PAGE_MASK;
50097+#endif
50098+
50099 return 0;
50100 err:
50101 up_write(&mm->mmap_sem);
50102@@ -396,7 +433,7 @@ struct user_arg_ptr {
50103 } ptr;
50104 };
50105
50106-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50107+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50108 {
50109 const char __user *native;
50110
50111@@ -405,14 +442,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50112 compat_uptr_t compat;
50113
50114 if (get_user(compat, argv.ptr.compat + nr))
50115- return ERR_PTR(-EFAULT);
50116+ return (const char __force_user *)ERR_PTR(-EFAULT);
50117
50118 return compat_ptr(compat);
50119 }
50120 #endif
50121
50122 if (get_user(native, argv.ptr.native + nr))
50123- return ERR_PTR(-EFAULT);
50124+ return (const char __force_user *)ERR_PTR(-EFAULT);
50125
50126 return native;
50127 }
50128@@ -431,7 +468,7 @@ static int count(struct user_arg_ptr argv, int max)
50129 if (!p)
50130 break;
50131
50132- if (IS_ERR(p))
50133+ if (IS_ERR((const char __force_kernel *)p))
50134 return -EFAULT;
50135
50136 if (i >= max)
50137@@ -466,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50138
50139 ret = -EFAULT;
50140 str = get_user_arg_ptr(argv, argc);
50141- if (IS_ERR(str))
50142+ if (IS_ERR((const char __force_kernel *)str))
50143 goto out;
50144
50145 len = strnlen_user(str, MAX_ARG_STRLEN);
50146@@ -548,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50147 int r;
50148 mm_segment_t oldfs = get_fs();
50149 struct user_arg_ptr argv = {
50150- .ptr.native = (const char __user *const __user *)__argv,
50151+ .ptr.native = (const char __force_user *const __force_user *)__argv,
50152 };
50153
50154 set_fs(KERNEL_DS);
50155@@ -583,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50156 unsigned long new_end = old_end - shift;
50157 struct mmu_gather tlb;
50158
50159- BUG_ON(new_start > new_end);
50160+ if (new_start >= new_end || new_start < mmap_min_addr)
50161+ return -ENOMEM;
50162
50163 /*
50164 * ensure there are no vmas between where we want to go
50165@@ -592,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50166 if (vma != find_vma(mm, new_start))
50167 return -EFAULT;
50168
50169+#ifdef CONFIG_PAX_SEGMEXEC
50170+ BUG_ON(pax_find_mirror_vma(vma));
50171+#endif
50172+
50173 /*
50174 * cover the whole range: [new_start, old_end)
50175 */
50176@@ -672,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50177 stack_top = arch_align_stack(stack_top);
50178 stack_top = PAGE_ALIGN(stack_top);
50179
50180- if (unlikely(stack_top < mmap_min_addr) ||
50181- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50182- return -ENOMEM;
50183-
50184 stack_shift = vma->vm_end - stack_top;
50185
50186 bprm->p -= stack_shift;
50187@@ -687,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50188 bprm->exec -= stack_shift;
50189
50190 down_write(&mm->mmap_sem);
50191+
50192+ /* Move stack pages down in memory. */
50193+ if (stack_shift) {
50194+ ret = shift_arg_pages(vma, stack_shift);
50195+ if (ret)
50196+ goto out_unlock;
50197+ }
50198+
50199 vm_flags = VM_STACK_FLAGS;
50200
50201+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50202+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50203+ vm_flags &= ~VM_EXEC;
50204+
50205+#ifdef CONFIG_PAX_MPROTECT
50206+ if (mm->pax_flags & MF_PAX_MPROTECT)
50207+ vm_flags &= ~VM_MAYEXEC;
50208+#endif
50209+
50210+ }
50211+#endif
50212+
50213 /*
50214 * Adjust stack execute permissions; explicitly enable for
50215 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50216@@ -707,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50217 goto out_unlock;
50218 BUG_ON(prev != vma);
50219
50220- /* Move stack pages down in memory. */
50221- if (stack_shift) {
50222- ret = shift_arg_pages(vma, stack_shift);
50223- if (ret)
50224- goto out_unlock;
50225- }
50226-
50227 /* mprotect_fixup is overkill to remove the temporary stack flags */
50228 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50229
50230@@ -737,6 +788,30 @@ int setup_arg_pages(struct linux_binprm *bprm,
50231 #endif
50232 current->mm->start_stack = bprm->p;
50233 ret = expand_stack(vma, stack_base);
50234+
50235+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
50236+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50237+ unsigned long size, flags, vm_flags;
50238+
50239+ size = STACK_TOP - vma->vm_end;
50240+ flags = MAP_FIXED | MAP_PRIVATE;
50241+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50242+
50243+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
50244+
50245+#ifdef CONFIG_X86
50246+ if (!ret) {
50247+ current->mm->aslr_gap += size >> PAGE_SHIFT;
50248+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50249+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
50250+ if (!ret)
50251+ current->mm->aslr_gap += size >> PAGE_SHIFT;
50252+ }
50253+#endif
50254+
50255+ }
50256+#endif
50257+
50258 if (ret)
50259 ret = -EFAULT;
50260
50261@@ -772,6 +847,8 @@ struct file *open_exec(const char *name)
50262
50263 fsnotify_open(file);
50264
50265+ trace_open_exec(name);
50266+
50267 err = deny_write_access(file);
50268 if (err)
50269 goto exit;
50270@@ -795,7 +872,7 @@ int kernel_read(struct file *file, loff_t offset,
50271 old_fs = get_fs();
50272 set_fs(get_ds());
50273 /* The cast to a user pointer is valid due to the set_fs() */
50274- result = vfs_read(file, (void __user *)addr, count, &pos);
50275+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50276 set_fs(old_fs);
50277 return result;
50278 }
50279@@ -1247,7 +1324,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50280 }
50281 rcu_read_unlock();
50282
50283- if (p->fs->users > n_fs) {
50284+ if (atomic_read(&p->fs->users) > n_fs) {
50285 bprm->unsafe |= LSM_UNSAFE_SHARE;
50286 } else {
50287 res = -EAGAIN;
50288@@ -1447,6 +1524,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50289
50290 EXPORT_SYMBOL(search_binary_handler);
50291
50292+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50293+static DEFINE_PER_CPU(u64, exec_counter);
50294+static int __init init_exec_counters(void)
50295+{
50296+ unsigned int cpu;
50297+
50298+ for_each_possible_cpu(cpu) {
50299+ per_cpu(exec_counter, cpu) = (u64)cpu;
50300+ }
50301+
50302+ return 0;
50303+}
50304+early_initcall(init_exec_counters);
50305+static inline void increment_exec_counter(void)
50306+{
50307+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50308+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50309+}
50310+#else
50311+static inline void increment_exec_counter(void) {}
50312+#endif
50313+
50314+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50315+ struct user_arg_ptr argv);
50316+
50317 /*
50318 * sys_execve() executes a new program.
50319 */
50320@@ -1454,6 +1556,11 @@ static int do_execve_common(const char *filename,
50321 struct user_arg_ptr argv,
50322 struct user_arg_ptr envp)
50323 {
50324+#ifdef CONFIG_GRKERNSEC
50325+ struct file *old_exec_file;
50326+ struct acl_subject_label *old_acl;
50327+ struct rlimit old_rlim[RLIM_NLIMITS];
50328+#endif
50329 struct linux_binprm *bprm;
50330 struct file *file;
50331 struct files_struct *displaced;
50332@@ -1461,6 +1568,8 @@ static int do_execve_common(const char *filename,
50333 int retval;
50334 const struct cred *cred = current_cred();
50335
50336+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
50337+
50338 /*
50339 * We move the actual failure in case of RLIMIT_NPROC excess from
50340 * set*uid() to execve() because too many poorly written programs
50341@@ -1501,12 +1610,27 @@ static int do_execve_common(const char *filename,
50342 if (IS_ERR(file))
50343 goto out_unmark;
50344
50345+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50346+ retval = -EPERM;
50347+ goto out_file;
50348+ }
50349+
50350 sched_exec();
50351
50352 bprm->file = file;
50353 bprm->filename = filename;
50354 bprm->interp = filename;
50355
50356+ if (gr_process_user_ban()) {
50357+ retval = -EPERM;
50358+ goto out_file;
50359+ }
50360+
50361+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
50362+ retval = -EACCES;
50363+ goto out_file;
50364+ }
50365+
50366 retval = bprm_mm_init(bprm);
50367 if (retval)
50368 goto out_file;
50369@@ -1523,24 +1647,65 @@ static int do_execve_common(const char *filename,
50370 if (retval < 0)
50371 goto out;
50372
50373+#ifdef CONFIG_GRKERNSEC
50374+ old_acl = current->acl;
50375+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
50376+ old_exec_file = current->exec_file;
50377+ get_file(file);
50378+ current->exec_file = file;
50379+#endif
50380+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50381+ /* limit suid stack to 8MB
50382+ * we saved the old limits above and will restore them if this exec fails
50383+ */
50384+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
50385+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
50386+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
50387+#endif
50388+
50389+ if (!gr_tpe_allow(file)) {
50390+ retval = -EACCES;
50391+ goto out_fail;
50392+ }
50393+
50394+ if (gr_check_crash_exec(file)) {
50395+ retval = -EACCES;
50396+ goto out_fail;
50397+ }
50398+
50399+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
50400+ bprm->unsafe);
50401+ if (retval < 0)
50402+ goto out_fail;
50403+
50404 retval = copy_strings_kernel(1, &bprm->filename, bprm);
50405 if (retval < 0)
50406- goto out;
50407+ goto out_fail;
50408
50409 bprm->exec = bprm->p;
50410 retval = copy_strings(bprm->envc, envp, bprm);
50411 if (retval < 0)
50412- goto out;
50413+ goto out_fail;
50414
50415 retval = copy_strings(bprm->argc, argv, bprm);
50416 if (retval < 0)
50417- goto out;
50418+ goto out_fail;
50419+
50420+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
50421+
50422+ gr_handle_exec_args(bprm, argv);
50423
50424 retval = search_binary_handler(bprm);
50425 if (retval < 0)
50426- goto out;
50427+ goto out_fail;
50428+#ifdef CONFIG_GRKERNSEC
50429+ if (old_exec_file)
50430+ fput(old_exec_file);
50431+#endif
50432
50433 /* execve succeeded */
50434+
50435+ increment_exec_counter();
50436 current->fs->in_exec = 0;
50437 current->in_execve = 0;
50438 acct_update_integrals(current);
50439@@ -1549,6 +1714,14 @@ static int do_execve_common(const char *filename,
50440 put_files_struct(displaced);
50441 return retval;
50442
50443+out_fail:
50444+#ifdef CONFIG_GRKERNSEC
50445+ current->acl = old_acl;
50446+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50447+ fput(current->exec_file);
50448+ current->exec_file = old_exec_file;
50449+#endif
50450+
50451 out:
50452 if (bprm->mm) {
50453 acct_arg_size(bprm, 0);
50454@@ -1697,3 +1870,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50455 return error;
50456 }
50457 #endif
50458+
50459+int pax_check_flags(unsigned long *flags)
50460+{
50461+ int retval = 0;
50462+
50463+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50464+ if (*flags & MF_PAX_SEGMEXEC)
50465+ {
50466+ *flags &= ~MF_PAX_SEGMEXEC;
50467+ retval = -EINVAL;
50468+ }
50469+#endif
50470+
50471+ if ((*flags & MF_PAX_PAGEEXEC)
50472+
50473+#ifdef CONFIG_PAX_PAGEEXEC
50474+ && (*flags & MF_PAX_SEGMEXEC)
50475+#endif
50476+
50477+ )
50478+ {
50479+ *flags &= ~MF_PAX_PAGEEXEC;
50480+ retval = -EINVAL;
50481+ }
50482+
50483+ if ((*flags & MF_PAX_MPROTECT)
50484+
50485+#ifdef CONFIG_PAX_MPROTECT
50486+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50487+#endif
50488+
50489+ )
50490+ {
50491+ *flags &= ~MF_PAX_MPROTECT;
50492+ retval = -EINVAL;
50493+ }
50494+
50495+ if ((*flags & MF_PAX_EMUTRAMP)
50496+
50497+#ifdef CONFIG_PAX_EMUTRAMP
50498+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50499+#endif
50500+
50501+ )
50502+ {
50503+ *flags &= ~MF_PAX_EMUTRAMP;
50504+ retval = -EINVAL;
50505+ }
50506+
50507+ return retval;
50508+}
50509+
50510+EXPORT_SYMBOL(pax_check_flags);
50511+
50512+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50513+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50514+{
50515+ struct task_struct *tsk = current;
50516+ struct mm_struct *mm = current->mm;
50517+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50518+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50519+ char *path_exec = NULL;
50520+ char *path_fault = NULL;
50521+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
50522+ siginfo_t info = { };
50523+
50524+ if (buffer_exec && buffer_fault) {
50525+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50526+
50527+ down_read(&mm->mmap_sem);
50528+ vma = mm->mmap;
50529+ while (vma && (!vma_exec || !vma_fault)) {
50530+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50531+ vma_exec = vma;
50532+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50533+ vma_fault = vma;
50534+ vma = vma->vm_next;
50535+ }
50536+ if (vma_exec) {
50537+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50538+ if (IS_ERR(path_exec))
50539+ path_exec = "<path too long>";
50540+ else {
50541+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50542+ if (path_exec) {
50543+ *path_exec = 0;
50544+ path_exec = buffer_exec;
50545+ } else
50546+ path_exec = "<path too long>";
50547+ }
50548+ }
50549+ if (vma_fault) {
50550+ start = vma_fault->vm_start;
50551+ end = vma_fault->vm_end;
50552+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50553+ if (vma_fault->vm_file) {
50554+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50555+ if (IS_ERR(path_fault))
50556+ path_fault = "<path too long>";
50557+ else {
50558+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50559+ if (path_fault) {
50560+ *path_fault = 0;
50561+ path_fault = buffer_fault;
50562+ } else
50563+ path_fault = "<path too long>";
50564+ }
50565+ } else
50566+ path_fault = "<anonymous mapping>";
50567+ }
50568+ up_read(&mm->mmap_sem);
50569+ }
50570+ if (tsk->signal->curr_ip)
50571+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50572+ else
50573+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50574+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
50575+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
50576+ free_page((unsigned long)buffer_exec);
50577+ free_page((unsigned long)buffer_fault);
50578+ pax_report_insns(regs, pc, sp);
50579+ info.si_signo = SIGKILL;
50580+ info.si_errno = 0;
50581+ info.si_code = SI_KERNEL;
50582+ info.si_pid = 0;
50583+ info.si_uid = 0;
50584+ do_coredump(&info);
50585+}
50586+#endif
50587+
50588+#ifdef CONFIG_PAX_REFCOUNT
50589+void pax_report_refcount_overflow(struct pt_regs *regs)
50590+{
50591+ if (current->signal->curr_ip)
50592+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50593+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
50594+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50595+ else
50596+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50597+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50598+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50599+ show_regs(regs);
50600+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50601+}
50602+#endif
50603+
50604+#ifdef CONFIG_PAX_USERCOPY
50605+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50606+static noinline int check_stack_object(const void *obj, unsigned long len)
50607+{
50608+ const void * const stack = task_stack_page(current);
50609+ const void * const stackend = stack + THREAD_SIZE;
50610+
50611+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50612+ const void *frame = NULL;
50613+ const void *oldframe;
50614+#endif
50615+
50616+ if (obj + len < obj)
50617+ return -1;
50618+
50619+ if (obj + len <= stack || stackend <= obj)
50620+ return 0;
50621+
50622+ if (obj < stack || stackend < obj + len)
50623+ return -1;
50624+
50625+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50626+ oldframe = __builtin_frame_address(1);
50627+ if (oldframe)
50628+ frame = __builtin_frame_address(2);
50629+ /*
50630+ low ----------------------------------------------> high
50631+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
50632+ ^----------------^
50633+ allow copies only within here
50634+ */
50635+ while (stack <= frame && frame < stackend) {
50636+ /* if obj + len extends past the last frame, this
50637+ check won't pass and the next frame will be 0,
50638+ causing us to bail out and correctly report
50639+ the copy as invalid
50640+ */
50641+ if (obj + len <= frame)
50642+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50643+ oldframe = frame;
50644+ frame = *(const void * const *)frame;
50645+ }
50646+ return -1;
50647+#else
50648+ return 1;
50649+#endif
50650+}
50651+
50652+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50653+{
50654+ if (current->signal->curr_ip)
50655+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50656+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50657+ else
50658+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50659+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50660+ dump_stack();
50661+ gr_handle_kernel_exploit();
50662+ do_group_exit(SIGKILL);
50663+}
50664+#endif
50665+
50666+void __check_object_size(const void *ptr, unsigned long n, bool to)
50667+{
50668+
50669+#ifdef CONFIG_PAX_USERCOPY
50670+ const char *type;
50671+
50672+ if (!n)
50673+ return;
50674+
50675+ type = check_heap_object(ptr, n);
50676+ if (!type) {
50677+ if (check_stack_object(ptr, n) != -1)
50678+ return;
50679+ type = "<process stack>";
50680+ }
50681+
50682+ pax_report_usercopy(ptr, n, to, type);
50683+#endif
50684+
50685+}
50686+EXPORT_SYMBOL(__check_object_size);
50687+
50688+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50689+void pax_track_stack(void)
50690+{
50691+ unsigned long sp = (unsigned long)&sp;
50692+ if (sp < current_thread_info()->lowest_stack &&
50693+ sp > (unsigned long)task_stack_page(current))
50694+ current_thread_info()->lowest_stack = sp;
50695+}
50696+EXPORT_SYMBOL(pax_track_stack);
50697+#endif
50698+
50699+#ifdef CONFIG_PAX_SIZE_OVERFLOW
50700+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50701+{
50702+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50703+ dump_stack();
50704+ do_group_exit(SIGKILL);
50705+}
50706+EXPORT_SYMBOL(report_size_overflow);
50707+#endif
50708diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50709index 2616d0e..2ffdec9 100644
50710--- a/fs/ext2/balloc.c
50711+++ b/fs/ext2/balloc.c
50712@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50713
50714 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50715 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50716- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50717+ if (free_blocks < root_blocks + 1 &&
50718 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50719 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50720- !in_group_p (sbi->s_resgid))) {
50721+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50722 return 0;
50723 }
50724 return 1;
50725diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50726index 22548f5..41521d8 100644
50727--- a/fs/ext3/balloc.c
50728+++ b/fs/ext3/balloc.c
50729@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50730
50731 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50732 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50733- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50734+ if (free_blocks < root_blocks + 1 &&
50735 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50736 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50737- !in_group_p (sbi->s_resgid))) {
50738+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50739 return 0;
50740 }
50741 return 1;
50742diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50743index 92e68b3..115d987 100644
50744--- a/fs/ext4/balloc.c
50745+++ b/fs/ext4/balloc.c
50746@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50747 /* Hm, nope. Are (enough) root reserved clusters available? */
50748 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50749 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50750- capable(CAP_SYS_RESOURCE) ||
50751- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50752+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50753+ capable_nolog(CAP_SYS_RESOURCE)) {
50754
50755 if (free_clusters >= (nclusters + dirty_clusters))
50756 return 1;
50757diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50758index 8462eb3..4a71af6 100644
50759--- a/fs/ext4/ext4.h
50760+++ b/fs/ext4/ext4.h
50761@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50762 unsigned long s_mb_last_start;
50763
50764 /* stats for buddy allocator */
50765- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50766- atomic_t s_bal_success; /* we found long enough chunks */
50767- atomic_t s_bal_allocated; /* in blocks */
50768- atomic_t s_bal_ex_scanned; /* total extents scanned */
50769- atomic_t s_bal_goals; /* goal hits */
50770- atomic_t s_bal_breaks; /* too long searches */
50771- atomic_t s_bal_2orders; /* 2^order hits */
50772+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50773+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50774+ atomic_unchecked_t s_bal_allocated; /* in blocks */
50775+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50776+ atomic_unchecked_t s_bal_goals; /* goal hits */
50777+ atomic_unchecked_t s_bal_breaks; /* too long searches */
50778+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50779 spinlock_t s_bal_lock;
50780 unsigned long s_mb_buddies_generated;
50781 unsigned long long s_mb_generation_time;
50782- atomic_t s_mb_lost_chunks;
50783- atomic_t s_mb_preallocated;
50784- atomic_t s_mb_discarded;
50785+ atomic_unchecked_t s_mb_lost_chunks;
50786+ atomic_unchecked_t s_mb_preallocated;
50787+ atomic_unchecked_t s_mb_discarded;
50788 atomic_t s_lock_busy;
50789
50790 /* locality groups */
50791diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50792index 28bbf9b..75ca7c1 100644
50793--- a/fs/ext4/mballoc.c
50794+++ b/fs/ext4/mballoc.c
50795@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50796 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50797
50798 if (EXT4_SB(sb)->s_mb_stats)
50799- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50800+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50801
50802 break;
50803 }
50804@@ -2044,7 +2044,7 @@ repeat:
50805 ac->ac_status = AC_STATUS_CONTINUE;
50806 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50807 cr = 3;
50808- atomic_inc(&sbi->s_mb_lost_chunks);
50809+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50810 goto repeat;
50811 }
50812 }
50813@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50814 if (sbi->s_mb_stats) {
50815 ext4_msg(sb, KERN_INFO,
50816 "mballoc: %u blocks %u reqs (%u success)",
50817- atomic_read(&sbi->s_bal_allocated),
50818- atomic_read(&sbi->s_bal_reqs),
50819- atomic_read(&sbi->s_bal_success));
50820+ atomic_read_unchecked(&sbi->s_bal_allocated),
50821+ atomic_read_unchecked(&sbi->s_bal_reqs),
50822+ atomic_read_unchecked(&sbi->s_bal_success));
50823 ext4_msg(sb, KERN_INFO,
50824 "mballoc: %u extents scanned, %u goal hits, "
50825 "%u 2^N hits, %u breaks, %u lost",
50826- atomic_read(&sbi->s_bal_ex_scanned),
50827- atomic_read(&sbi->s_bal_goals),
50828- atomic_read(&sbi->s_bal_2orders),
50829- atomic_read(&sbi->s_bal_breaks),
50830- atomic_read(&sbi->s_mb_lost_chunks));
50831+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50832+ atomic_read_unchecked(&sbi->s_bal_goals),
50833+ atomic_read_unchecked(&sbi->s_bal_2orders),
50834+ atomic_read_unchecked(&sbi->s_bal_breaks),
50835+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50836 ext4_msg(sb, KERN_INFO,
50837 "mballoc: %lu generated and it took %Lu",
50838 sbi->s_mb_buddies_generated,
50839 sbi->s_mb_generation_time);
50840 ext4_msg(sb, KERN_INFO,
50841 "mballoc: %u preallocated, %u discarded",
50842- atomic_read(&sbi->s_mb_preallocated),
50843- atomic_read(&sbi->s_mb_discarded));
50844+ atomic_read_unchecked(&sbi->s_mb_preallocated),
50845+ atomic_read_unchecked(&sbi->s_mb_discarded));
50846 }
50847
50848 free_percpu(sbi->s_locality_groups);
50849@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50850 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50851
50852 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50853- atomic_inc(&sbi->s_bal_reqs);
50854- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50855+ atomic_inc_unchecked(&sbi->s_bal_reqs);
50856+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50857 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50858- atomic_inc(&sbi->s_bal_success);
50859- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50860+ atomic_inc_unchecked(&sbi->s_bal_success);
50861+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50862 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50863 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50864- atomic_inc(&sbi->s_bal_goals);
50865+ atomic_inc_unchecked(&sbi->s_bal_goals);
50866 if (ac->ac_found > sbi->s_mb_max_to_scan)
50867- atomic_inc(&sbi->s_bal_breaks);
50868+ atomic_inc_unchecked(&sbi->s_bal_breaks);
50869 }
50870
50871 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50872@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50873 trace_ext4_mb_new_inode_pa(ac, pa);
50874
50875 ext4_mb_use_inode_pa(ac, pa);
50876- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50877+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50878
50879 ei = EXT4_I(ac->ac_inode);
50880 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50881@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50882 trace_ext4_mb_new_group_pa(ac, pa);
50883
50884 ext4_mb_use_group_pa(ac, pa);
50885- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50886+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50887
50888 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50889 lg = ac->ac_lg;
50890@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50891 * from the bitmap and continue.
50892 */
50893 }
50894- atomic_add(free, &sbi->s_mb_discarded);
50895+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
50896
50897 return err;
50898 }
50899@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50900 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50901 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50902 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50903- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50904+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50905 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50906
50907 return 0;
50908diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50909index 5fa223d..12fa738 100644
50910--- a/fs/ext4/super.c
50911+++ b/fs/ext4/super.c
50912@@ -2429,7 +2429,7 @@ struct ext4_attr {
50913 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50914 const char *, size_t);
50915 int offset;
50916-};
50917+} __do_const;
50918
50919 static int parse_strtoul(const char *buf,
50920 unsigned long max, unsigned long *value)
50921diff --git a/fs/fcntl.c b/fs/fcntl.c
50922index 71a600a..20d87b1 100644
50923--- a/fs/fcntl.c
50924+++ b/fs/fcntl.c
50925@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50926 if (err)
50927 return err;
50928
50929+ if (gr_handle_chroot_fowner(pid, type))
50930+ return -ENOENT;
50931+ if (gr_check_protected_task_fowner(pid, type))
50932+ return -EACCES;
50933+
50934 f_modown(filp, pid, type, force);
50935 return 0;
50936 }
50937diff --git a/fs/fhandle.c b/fs/fhandle.c
50938index 999ff5c..41f4109 100644
50939--- a/fs/fhandle.c
50940+++ b/fs/fhandle.c
50941@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50942 } else
50943 retval = 0;
50944 /* copy the mount id */
50945- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50946- sizeof(*mnt_id)) ||
50947+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50948 copy_to_user(ufh, handle,
50949 sizeof(struct file_handle) + handle_bytes))
50950 retval = -EFAULT;
50951diff --git a/fs/fifo.c b/fs/fifo.c
50952index cf6f434..3d7942c 100644
50953--- a/fs/fifo.c
50954+++ b/fs/fifo.c
50955@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50956 */
50957 filp->f_op = &read_pipefifo_fops;
50958 pipe->r_counter++;
50959- if (pipe->readers++ == 0)
50960+ if (atomic_inc_return(&pipe->readers) == 1)
50961 wake_up_partner(inode);
50962
50963- if (!pipe->writers) {
50964+ if (!atomic_read(&pipe->writers)) {
50965 if ((filp->f_flags & O_NONBLOCK)) {
50966 /* suppress POLLHUP until we have
50967 * seen a writer */
50968@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50969 * errno=ENXIO when there is no process reading the FIFO.
50970 */
50971 ret = -ENXIO;
50972- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50973+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
50974 goto err;
50975
50976 filp->f_op = &write_pipefifo_fops;
50977 pipe->w_counter++;
50978- if (!pipe->writers++)
50979+ if (atomic_inc_return(&pipe->writers) == 1)
50980 wake_up_partner(inode);
50981
50982- if (!pipe->readers) {
50983+ if (!atomic_read(&pipe->readers)) {
50984 if (wait_for_partner(inode, &pipe->r_counter))
50985 goto err_wr;
50986 }
50987@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
50988 */
50989 filp->f_op = &rdwr_pipefifo_fops;
50990
50991- pipe->readers++;
50992- pipe->writers++;
50993+ atomic_inc(&pipe->readers);
50994+ atomic_inc(&pipe->writers);
50995 pipe->r_counter++;
50996 pipe->w_counter++;
50997- if (pipe->readers == 1 || pipe->writers == 1)
50998+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
50999 wake_up_partner(inode);
51000 break;
51001
51002@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51003 return 0;
51004
51005 err_rd:
51006- if (!--pipe->readers)
51007+ if (atomic_dec_and_test(&pipe->readers))
51008 wake_up_interruptible(&pipe->wait);
51009 ret = -ERESTARTSYS;
51010 goto err;
51011
51012 err_wr:
51013- if (!--pipe->writers)
51014+ if (atomic_dec_and_test(&pipe->writers))
51015 wake_up_interruptible(&pipe->wait);
51016 ret = -ERESTARTSYS;
51017 goto err;
51018
51019 err:
51020- if (!pipe->readers && !pipe->writers)
51021+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51022 free_pipe_info(inode);
51023
51024 err_nocleanup:
51025diff --git a/fs/file.c b/fs/file.c
51026index 2b3570b..c57924b 100644
51027--- a/fs/file.c
51028+++ b/fs/file.c
51029@@ -16,6 +16,7 @@
51030 #include <linux/slab.h>
51031 #include <linux/vmalloc.h>
51032 #include <linux/file.h>
51033+#include <linux/security.h>
51034 #include <linux/fdtable.h>
51035 #include <linux/bitops.h>
51036 #include <linux/interrupt.h>
51037@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51038 if (!file)
51039 return __close_fd(files, fd);
51040
51041+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51042 if (fd >= rlimit(RLIMIT_NOFILE))
51043 return -EBADF;
51044
51045@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51046 if (unlikely(oldfd == newfd))
51047 return -EINVAL;
51048
51049+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51050 if (newfd >= rlimit(RLIMIT_NOFILE))
51051 return -EBADF;
51052
51053@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51054 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51055 {
51056 int err;
51057+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51058 if (from >= rlimit(RLIMIT_NOFILE))
51059 return -EINVAL;
51060 err = alloc_fd(from, flags);
51061diff --git a/fs/filesystems.c b/fs/filesystems.c
51062index da165f6..3671bdb 100644
51063--- a/fs/filesystems.c
51064+++ b/fs/filesystems.c
51065@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
51066 int len = dot ? dot - name : strlen(name);
51067
51068 fs = __get_fs_type(name, len);
51069+
51070+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51071+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
51072+#else
51073 if (!fs && (request_module("%.*s", len, name) == 0))
51074+#endif
51075 fs = __get_fs_type(name, len);
51076
51077 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51078diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51079index fe6ca58..65318cf 100644
51080--- a/fs/fs_struct.c
51081+++ b/fs/fs_struct.c
51082@@ -4,6 +4,7 @@
51083 #include <linux/path.h>
51084 #include <linux/slab.h>
51085 #include <linux/fs_struct.h>
51086+#include <linux/grsecurity.h>
51087 #include "internal.h"
51088
51089 /*
51090@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51091 write_seqcount_begin(&fs->seq);
51092 old_root = fs->root;
51093 fs->root = *path;
51094+ gr_set_chroot_entries(current, path);
51095 write_seqcount_end(&fs->seq);
51096 spin_unlock(&fs->lock);
51097 if (old_root.dentry)
51098@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51099 return 1;
51100 }
51101
51102+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51103+{
51104+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51105+ return 0;
51106+ *p = *new;
51107+
51108+ /* This function is only called from pivot_root(). Leave our
51109+ gr_chroot_dentry and is_chrooted flags as-is, so that a
51110+ pivoted root isn't treated as a chroot
51111+ */
51112+ //gr_set_chroot_entries(task, new);
51113+
51114+ return 1;
51115+}
51116+
51117 void chroot_fs_refs(struct path *old_root, struct path *new_root)
51118 {
51119 struct task_struct *g, *p;
51120@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
51121 int hits = 0;
51122 spin_lock(&fs->lock);
51123 write_seqcount_begin(&fs->seq);
51124- hits += replace_path(&fs->root, old_root, new_root);
51125+ hits += replace_root_path(p, &fs->root, old_root, new_root);
51126 hits += replace_path(&fs->pwd, old_root, new_root);
51127 write_seqcount_end(&fs->seq);
51128 while (hits--) {
51129@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
51130 task_lock(tsk);
51131 spin_lock(&fs->lock);
51132 tsk->fs = NULL;
51133- kill = !--fs->users;
51134+ gr_clear_chroot_entries(tsk);
51135+ kill = !atomic_dec_return(&fs->users);
51136 spin_unlock(&fs->lock);
51137 task_unlock(tsk);
51138 if (kill)
51139@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51140 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51141 /* We don't need to lock fs - think why ;-) */
51142 if (fs) {
51143- fs->users = 1;
51144+ atomic_set(&fs->users, 1);
51145 fs->in_exec = 0;
51146 spin_lock_init(&fs->lock);
51147 seqcount_init(&fs->seq);
51148@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51149 spin_lock(&old->lock);
51150 fs->root = old->root;
51151 path_get(&fs->root);
51152+ /* instead of calling gr_set_chroot_entries here,
51153+ we call it from every caller of this function
51154+ */
51155 fs->pwd = old->pwd;
51156 path_get(&fs->pwd);
51157 spin_unlock(&old->lock);
51158@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
51159
51160 task_lock(current);
51161 spin_lock(&fs->lock);
51162- kill = !--fs->users;
51163+ kill = !atomic_dec_return(&fs->users);
51164 current->fs = new_fs;
51165+ gr_set_chroot_entries(current, &new_fs->root);
51166 spin_unlock(&fs->lock);
51167 task_unlock(current);
51168
51169@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51170
51171 int current_umask(void)
51172 {
51173- return current->fs->umask;
51174+ return current->fs->umask | gr_acl_umask();
51175 }
51176 EXPORT_SYMBOL(current_umask);
51177
51178 /* to be mentioned only in INIT_TASK */
51179 struct fs_struct init_fs = {
51180- .users = 1,
51181+ .users = ATOMIC_INIT(1),
51182 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51183 .seq = SEQCNT_ZERO,
51184 .umask = 0022,
51185diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51186index 8dcb114..b1072e2 100644
51187--- a/fs/fscache/cookie.c
51188+++ b/fs/fscache/cookie.c
51189@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51190 parent ? (char *) parent->def->name : "<no-parent>",
51191 def->name, netfs_data);
51192
51193- fscache_stat(&fscache_n_acquires);
51194+ fscache_stat_unchecked(&fscache_n_acquires);
51195
51196 /* if there's no parent cookie, then we don't create one here either */
51197 if (!parent) {
51198- fscache_stat(&fscache_n_acquires_null);
51199+ fscache_stat_unchecked(&fscache_n_acquires_null);
51200 _leave(" [no parent]");
51201 return NULL;
51202 }
51203@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51204 /* allocate and initialise a cookie */
51205 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51206 if (!cookie) {
51207- fscache_stat(&fscache_n_acquires_oom);
51208+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51209 _leave(" [ENOMEM]");
51210 return NULL;
51211 }
51212@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51213
51214 switch (cookie->def->type) {
51215 case FSCACHE_COOKIE_TYPE_INDEX:
51216- fscache_stat(&fscache_n_cookie_index);
51217+ fscache_stat_unchecked(&fscache_n_cookie_index);
51218 break;
51219 case FSCACHE_COOKIE_TYPE_DATAFILE:
51220- fscache_stat(&fscache_n_cookie_data);
51221+ fscache_stat_unchecked(&fscache_n_cookie_data);
51222 break;
51223 default:
51224- fscache_stat(&fscache_n_cookie_special);
51225+ fscache_stat_unchecked(&fscache_n_cookie_special);
51226 break;
51227 }
51228
51229@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51230 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51231 atomic_dec(&parent->n_children);
51232 __fscache_cookie_put(cookie);
51233- fscache_stat(&fscache_n_acquires_nobufs);
51234+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51235 _leave(" = NULL");
51236 return NULL;
51237 }
51238 }
51239
51240- fscache_stat(&fscache_n_acquires_ok);
51241+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51242 _leave(" = %p", cookie);
51243 return cookie;
51244 }
51245@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51246 cache = fscache_select_cache_for_object(cookie->parent);
51247 if (!cache) {
51248 up_read(&fscache_addremove_sem);
51249- fscache_stat(&fscache_n_acquires_no_cache);
51250+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51251 _leave(" = -ENOMEDIUM [no cache]");
51252 return -ENOMEDIUM;
51253 }
51254@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51255 object = cache->ops->alloc_object(cache, cookie);
51256 fscache_stat_d(&fscache_n_cop_alloc_object);
51257 if (IS_ERR(object)) {
51258- fscache_stat(&fscache_n_object_no_alloc);
51259+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51260 ret = PTR_ERR(object);
51261 goto error;
51262 }
51263
51264- fscache_stat(&fscache_n_object_alloc);
51265+ fscache_stat_unchecked(&fscache_n_object_alloc);
51266
51267 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51268
51269@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51270
51271 _enter("{%s}", cookie->def->name);
51272
51273- fscache_stat(&fscache_n_invalidates);
51274+ fscache_stat_unchecked(&fscache_n_invalidates);
51275
51276 /* Only permit invalidation of data files. Invalidating an index will
51277 * require the caller to release all its attachments to the tree rooted
51278@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51279 struct fscache_object *object;
51280 struct hlist_node *_p;
51281
51282- fscache_stat(&fscache_n_updates);
51283+ fscache_stat_unchecked(&fscache_n_updates);
51284
51285 if (!cookie) {
51286- fscache_stat(&fscache_n_updates_null);
51287+ fscache_stat_unchecked(&fscache_n_updates_null);
51288 _leave(" [no cookie]");
51289 return;
51290 }
51291@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51292 struct fscache_object *object;
51293 unsigned long event;
51294
51295- fscache_stat(&fscache_n_relinquishes);
51296+ fscache_stat_unchecked(&fscache_n_relinquishes);
51297 if (retire)
51298- fscache_stat(&fscache_n_relinquishes_retire);
51299+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51300
51301 if (!cookie) {
51302- fscache_stat(&fscache_n_relinquishes_null);
51303+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51304 _leave(" [no cookie]");
51305 return;
51306 }
51307@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51308
51309 /* wait for the cookie to finish being instantiated (or to fail) */
51310 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51311- fscache_stat(&fscache_n_relinquishes_waitcrt);
51312+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51313 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
51314 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
51315 }
51316diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
51317index ee38fef..0a326d4 100644
51318--- a/fs/fscache/internal.h
51319+++ b/fs/fscache/internal.h
51320@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
51321 * stats.c
51322 */
51323 #ifdef CONFIG_FSCACHE_STATS
51324-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51325-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51326+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51327+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51328
51329-extern atomic_t fscache_n_op_pend;
51330-extern atomic_t fscache_n_op_run;
51331-extern atomic_t fscache_n_op_enqueue;
51332-extern atomic_t fscache_n_op_deferred_release;
51333-extern atomic_t fscache_n_op_release;
51334-extern atomic_t fscache_n_op_gc;
51335-extern atomic_t fscache_n_op_cancelled;
51336-extern atomic_t fscache_n_op_rejected;
51337+extern atomic_unchecked_t fscache_n_op_pend;
51338+extern atomic_unchecked_t fscache_n_op_run;
51339+extern atomic_unchecked_t fscache_n_op_enqueue;
51340+extern atomic_unchecked_t fscache_n_op_deferred_release;
51341+extern atomic_unchecked_t fscache_n_op_release;
51342+extern atomic_unchecked_t fscache_n_op_gc;
51343+extern atomic_unchecked_t fscache_n_op_cancelled;
51344+extern atomic_unchecked_t fscache_n_op_rejected;
51345
51346-extern atomic_t fscache_n_attr_changed;
51347-extern atomic_t fscache_n_attr_changed_ok;
51348-extern atomic_t fscache_n_attr_changed_nobufs;
51349-extern atomic_t fscache_n_attr_changed_nomem;
51350-extern atomic_t fscache_n_attr_changed_calls;
51351+extern atomic_unchecked_t fscache_n_attr_changed;
51352+extern atomic_unchecked_t fscache_n_attr_changed_ok;
51353+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
51354+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
51355+extern atomic_unchecked_t fscache_n_attr_changed_calls;
51356
51357-extern atomic_t fscache_n_allocs;
51358-extern atomic_t fscache_n_allocs_ok;
51359-extern atomic_t fscache_n_allocs_wait;
51360-extern atomic_t fscache_n_allocs_nobufs;
51361-extern atomic_t fscache_n_allocs_intr;
51362-extern atomic_t fscache_n_allocs_object_dead;
51363-extern atomic_t fscache_n_alloc_ops;
51364-extern atomic_t fscache_n_alloc_op_waits;
51365+extern atomic_unchecked_t fscache_n_allocs;
51366+extern atomic_unchecked_t fscache_n_allocs_ok;
51367+extern atomic_unchecked_t fscache_n_allocs_wait;
51368+extern atomic_unchecked_t fscache_n_allocs_nobufs;
51369+extern atomic_unchecked_t fscache_n_allocs_intr;
51370+extern atomic_unchecked_t fscache_n_allocs_object_dead;
51371+extern atomic_unchecked_t fscache_n_alloc_ops;
51372+extern atomic_unchecked_t fscache_n_alloc_op_waits;
51373
51374-extern atomic_t fscache_n_retrievals;
51375-extern atomic_t fscache_n_retrievals_ok;
51376-extern atomic_t fscache_n_retrievals_wait;
51377-extern atomic_t fscache_n_retrievals_nodata;
51378-extern atomic_t fscache_n_retrievals_nobufs;
51379-extern atomic_t fscache_n_retrievals_intr;
51380-extern atomic_t fscache_n_retrievals_nomem;
51381-extern atomic_t fscache_n_retrievals_object_dead;
51382-extern atomic_t fscache_n_retrieval_ops;
51383-extern atomic_t fscache_n_retrieval_op_waits;
51384+extern atomic_unchecked_t fscache_n_retrievals;
51385+extern atomic_unchecked_t fscache_n_retrievals_ok;
51386+extern atomic_unchecked_t fscache_n_retrievals_wait;
51387+extern atomic_unchecked_t fscache_n_retrievals_nodata;
51388+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
51389+extern atomic_unchecked_t fscache_n_retrievals_intr;
51390+extern atomic_unchecked_t fscache_n_retrievals_nomem;
51391+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
51392+extern atomic_unchecked_t fscache_n_retrieval_ops;
51393+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
51394
51395-extern atomic_t fscache_n_stores;
51396-extern atomic_t fscache_n_stores_ok;
51397-extern atomic_t fscache_n_stores_again;
51398-extern atomic_t fscache_n_stores_nobufs;
51399-extern atomic_t fscache_n_stores_oom;
51400-extern atomic_t fscache_n_store_ops;
51401-extern atomic_t fscache_n_store_calls;
51402-extern atomic_t fscache_n_store_pages;
51403-extern atomic_t fscache_n_store_radix_deletes;
51404-extern atomic_t fscache_n_store_pages_over_limit;
51405+extern atomic_unchecked_t fscache_n_stores;
51406+extern atomic_unchecked_t fscache_n_stores_ok;
51407+extern atomic_unchecked_t fscache_n_stores_again;
51408+extern atomic_unchecked_t fscache_n_stores_nobufs;
51409+extern atomic_unchecked_t fscache_n_stores_oom;
51410+extern atomic_unchecked_t fscache_n_store_ops;
51411+extern atomic_unchecked_t fscache_n_store_calls;
51412+extern atomic_unchecked_t fscache_n_store_pages;
51413+extern atomic_unchecked_t fscache_n_store_radix_deletes;
51414+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
51415
51416-extern atomic_t fscache_n_store_vmscan_not_storing;
51417-extern atomic_t fscache_n_store_vmscan_gone;
51418-extern atomic_t fscache_n_store_vmscan_busy;
51419-extern atomic_t fscache_n_store_vmscan_cancelled;
51420-extern atomic_t fscache_n_store_vmscan_wait;
51421+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51422+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51423+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51424+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51425+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51426
51427-extern atomic_t fscache_n_marks;
51428-extern atomic_t fscache_n_uncaches;
51429+extern atomic_unchecked_t fscache_n_marks;
51430+extern atomic_unchecked_t fscache_n_uncaches;
51431
51432-extern atomic_t fscache_n_acquires;
51433-extern atomic_t fscache_n_acquires_null;
51434-extern atomic_t fscache_n_acquires_no_cache;
51435-extern atomic_t fscache_n_acquires_ok;
51436-extern atomic_t fscache_n_acquires_nobufs;
51437-extern atomic_t fscache_n_acquires_oom;
51438+extern atomic_unchecked_t fscache_n_acquires;
51439+extern atomic_unchecked_t fscache_n_acquires_null;
51440+extern atomic_unchecked_t fscache_n_acquires_no_cache;
51441+extern atomic_unchecked_t fscache_n_acquires_ok;
51442+extern atomic_unchecked_t fscache_n_acquires_nobufs;
51443+extern atomic_unchecked_t fscache_n_acquires_oom;
51444
51445-extern atomic_t fscache_n_invalidates;
51446-extern atomic_t fscache_n_invalidates_run;
51447+extern atomic_unchecked_t fscache_n_invalidates;
51448+extern atomic_unchecked_t fscache_n_invalidates_run;
51449
51450-extern atomic_t fscache_n_updates;
51451-extern atomic_t fscache_n_updates_null;
51452-extern atomic_t fscache_n_updates_run;
51453+extern atomic_unchecked_t fscache_n_updates;
51454+extern atomic_unchecked_t fscache_n_updates_null;
51455+extern atomic_unchecked_t fscache_n_updates_run;
51456
51457-extern atomic_t fscache_n_relinquishes;
51458-extern atomic_t fscache_n_relinquishes_null;
51459-extern atomic_t fscache_n_relinquishes_waitcrt;
51460-extern atomic_t fscache_n_relinquishes_retire;
51461+extern atomic_unchecked_t fscache_n_relinquishes;
51462+extern atomic_unchecked_t fscache_n_relinquishes_null;
51463+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51464+extern atomic_unchecked_t fscache_n_relinquishes_retire;
51465
51466-extern atomic_t fscache_n_cookie_index;
51467-extern atomic_t fscache_n_cookie_data;
51468-extern atomic_t fscache_n_cookie_special;
51469+extern atomic_unchecked_t fscache_n_cookie_index;
51470+extern atomic_unchecked_t fscache_n_cookie_data;
51471+extern atomic_unchecked_t fscache_n_cookie_special;
51472
51473-extern atomic_t fscache_n_object_alloc;
51474-extern atomic_t fscache_n_object_no_alloc;
51475-extern atomic_t fscache_n_object_lookups;
51476-extern atomic_t fscache_n_object_lookups_negative;
51477-extern atomic_t fscache_n_object_lookups_positive;
51478-extern atomic_t fscache_n_object_lookups_timed_out;
51479-extern atomic_t fscache_n_object_created;
51480-extern atomic_t fscache_n_object_avail;
51481-extern atomic_t fscache_n_object_dead;
51482+extern atomic_unchecked_t fscache_n_object_alloc;
51483+extern atomic_unchecked_t fscache_n_object_no_alloc;
51484+extern atomic_unchecked_t fscache_n_object_lookups;
51485+extern atomic_unchecked_t fscache_n_object_lookups_negative;
51486+extern atomic_unchecked_t fscache_n_object_lookups_positive;
51487+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51488+extern atomic_unchecked_t fscache_n_object_created;
51489+extern atomic_unchecked_t fscache_n_object_avail;
51490+extern atomic_unchecked_t fscache_n_object_dead;
51491
51492-extern atomic_t fscache_n_checkaux_none;
51493-extern atomic_t fscache_n_checkaux_okay;
51494-extern atomic_t fscache_n_checkaux_update;
51495-extern atomic_t fscache_n_checkaux_obsolete;
51496+extern atomic_unchecked_t fscache_n_checkaux_none;
51497+extern atomic_unchecked_t fscache_n_checkaux_okay;
51498+extern atomic_unchecked_t fscache_n_checkaux_update;
51499+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51500
51501 extern atomic_t fscache_n_cop_alloc_object;
51502 extern atomic_t fscache_n_cop_lookup_object;
51503@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51504 atomic_inc(stat);
51505 }
51506
51507+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51508+{
51509+ atomic_inc_unchecked(stat);
51510+}
51511+
51512 static inline void fscache_stat_d(atomic_t *stat)
51513 {
51514 atomic_dec(stat);
51515@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51516
51517 #define __fscache_stat(stat) (NULL)
51518 #define fscache_stat(stat) do {} while (0)
51519+#define fscache_stat_unchecked(stat) do {} while (0)
51520 #define fscache_stat_d(stat) do {} while (0)
51521 #endif
51522
51523diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51524index 50d41c1..10ee117 100644
51525--- a/fs/fscache/object.c
51526+++ b/fs/fscache/object.c
51527@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51528 /* Invalidate an object on disk */
51529 case FSCACHE_OBJECT_INVALIDATING:
51530 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51531- fscache_stat(&fscache_n_invalidates_run);
51532+ fscache_stat_unchecked(&fscache_n_invalidates_run);
51533 fscache_stat(&fscache_n_cop_invalidate_object);
51534 fscache_invalidate_object(object);
51535 fscache_stat_d(&fscache_n_cop_invalidate_object);
51536@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51537 /* update the object metadata on disk */
51538 case FSCACHE_OBJECT_UPDATING:
51539 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51540- fscache_stat(&fscache_n_updates_run);
51541+ fscache_stat_unchecked(&fscache_n_updates_run);
51542 fscache_stat(&fscache_n_cop_update_object);
51543 object->cache->ops->update_object(object);
51544 fscache_stat_d(&fscache_n_cop_update_object);
51545@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51546 spin_lock(&object->lock);
51547 object->state = FSCACHE_OBJECT_DEAD;
51548 spin_unlock(&object->lock);
51549- fscache_stat(&fscache_n_object_dead);
51550+ fscache_stat_unchecked(&fscache_n_object_dead);
51551 goto terminal_transit;
51552
51553 /* handle the parent cache of this object being withdrawn from
51554@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51555 spin_lock(&object->lock);
51556 object->state = FSCACHE_OBJECT_DEAD;
51557 spin_unlock(&object->lock);
51558- fscache_stat(&fscache_n_object_dead);
51559+ fscache_stat_unchecked(&fscache_n_object_dead);
51560 goto terminal_transit;
51561
51562 /* complain about the object being woken up once it is
51563@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51564 parent->cookie->def->name, cookie->def->name,
51565 object->cache->tag->name);
51566
51567- fscache_stat(&fscache_n_object_lookups);
51568+ fscache_stat_unchecked(&fscache_n_object_lookups);
51569 fscache_stat(&fscache_n_cop_lookup_object);
51570 ret = object->cache->ops->lookup_object(object);
51571 fscache_stat_d(&fscache_n_cop_lookup_object);
51572@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51573 if (ret == -ETIMEDOUT) {
51574 /* probably stuck behind another object, so move this one to
51575 * the back of the queue */
51576- fscache_stat(&fscache_n_object_lookups_timed_out);
51577+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51578 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51579 }
51580
51581@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51582
51583 spin_lock(&object->lock);
51584 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51585- fscache_stat(&fscache_n_object_lookups_negative);
51586+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51587
51588 /* transit here to allow write requests to begin stacking up
51589 * and read requests to begin returning ENODATA */
51590@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51591 * result, in which case there may be data available */
51592 spin_lock(&object->lock);
51593 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51594- fscache_stat(&fscache_n_object_lookups_positive);
51595+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51596
51597 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51598
51599@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51600 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51601 } else {
51602 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51603- fscache_stat(&fscache_n_object_created);
51604+ fscache_stat_unchecked(&fscache_n_object_created);
51605
51606 object->state = FSCACHE_OBJECT_AVAILABLE;
51607 spin_unlock(&object->lock);
51608@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51609 fscache_enqueue_dependents(object);
51610
51611 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51612- fscache_stat(&fscache_n_object_avail);
51613+ fscache_stat_unchecked(&fscache_n_object_avail);
51614
51615 _leave("");
51616 }
51617@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51618 enum fscache_checkaux result;
51619
51620 if (!object->cookie->def->check_aux) {
51621- fscache_stat(&fscache_n_checkaux_none);
51622+ fscache_stat_unchecked(&fscache_n_checkaux_none);
51623 return FSCACHE_CHECKAUX_OKAY;
51624 }
51625
51626@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51627 switch (result) {
51628 /* entry okay as is */
51629 case FSCACHE_CHECKAUX_OKAY:
51630- fscache_stat(&fscache_n_checkaux_okay);
51631+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
51632 break;
51633
51634 /* entry requires update */
51635 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51636- fscache_stat(&fscache_n_checkaux_update);
51637+ fscache_stat_unchecked(&fscache_n_checkaux_update);
51638 break;
51639
51640 /* entry requires deletion */
51641 case FSCACHE_CHECKAUX_OBSOLETE:
51642- fscache_stat(&fscache_n_checkaux_obsolete);
51643+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51644 break;
51645
51646 default:
51647diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51648index 762a9ec..2023284 100644
51649--- a/fs/fscache/operation.c
51650+++ b/fs/fscache/operation.c
51651@@ -17,7 +17,7 @@
51652 #include <linux/slab.h>
51653 #include "internal.h"
51654
51655-atomic_t fscache_op_debug_id;
51656+atomic_unchecked_t fscache_op_debug_id;
51657 EXPORT_SYMBOL(fscache_op_debug_id);
51658
51659 /**
51660@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51661 ASSERTCMP(atomic_read(&op->usage), >, 0);
51662 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51663
51664- fscache_stat(&fscache_n_op_enqueue);
51665+ fscache_stat_unchecked(&fscache_n_op_enqueue);
51666 switch (op->flags & FSCACHE_OP_TYPE) {
51667 case FSCACHE_OP_ASYNC:
51668 _debug("queue async");
51669@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51670 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51671 if (op->processor)
51672 fscache_enqueue_operation(op);
51673- fscache_stat(&fscache_n_op_run);
51674+ fscache_stat_unchecked(&fscache_n_op_run);
51675 }
51676
51677 /*
51678@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51679 if (object->n_in_progress > 0) {
51680 atomic_inc(&op->usage);
51681 list_add_tail(&op->pend_link, &object->pending_ops);
51682- fscache_stat(&fscache_n_op_pend);
51683+ fscache_stat_unchecked(&fscache_n_op_pend);
51684 } else if (!list_empty(&object->pending_ops)) {
51685 atomic_inc(&op->usage);
51686 list_add_tail(&op->pend_link, &object->pending_ops);
51687- fscache_stat(&fscache_n_op_pend);
51688+ fscache_stat_unchecked(&fscache_n_op_pend);
51689 fscache_start_operations(object);
51690 } else {
51691 ASSERTCMP(object->n_in_progress, ==, 0);
51692@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51693 object->n_exclusive++; /* reads and writes must wait */
51694 atomic_inc(&op->usage);
51695 list_add_tail(&op->pend_link, &object->pending_ops);
51696- fscache_stat(&fscache_n_op_pend);
51697+ fscache_stat_unchecked(&fscache_n_op_pend);
51698 ret = 0;
51699 } else {
51700 /* If we're in any other state, there must have been an I/O
51701@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51702 if (object->n_exclusive > 0) {
51703 atomic_inc(&op->usage);
51704 list_add_tail(&op->pend_link, &object->pending_ops);
51705- fscache_stat(&fscache_n_op_pend);
51706+ fscache_stat_unchecked(&fscache_n_op_pend);
51707 } else if (!list_empty(&object->pending_ops)) {
51708 atomic_inc(&op->usage);
51709 list_add_tail(&op->pend_link, &object->pending_ops);
51710- fscache_stat(&fscache_n_op_pend);
51711+ fscache_stat_unchecked(&fscache_n_op_pend);
51712 fscache_start_operations(object);
51713 } else {
51714 ASSERTCMP(object->n_exclusive, ==, 0);
51715@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51716 object->n_ops++;
51717 atomic_inc(&op->usage);
51718 list_add_tail(&op->pend_link, &object->pending_ops);
51719- fscache_stat(&fscache_n_op_pend);
51720+ fscache_stat_unchecked(&fscache_n_op_pend);
51721 ret = 0;
51722 } else if (object->state == FSCACHE_OBJECT_DYING ||
51723 object->state == FSCACHE_OBJECT_LC_DYING ||
51724 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51725- fscache_stat(&fscache_n_op_rejected);
51726+ fscache_stat_unchecked(&fscache_n_op_rejected);
51727 op->state = FSCACHE_OP_ST_CANCELLED;
51728 ret = -ENOBUFS;
51729 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51730@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51731 ret = -EBUSY;
51732 if (op->state == FSCACHE_OP_ST_PENDING) {
51733 ASSERT(!list_empty(&op->pend_link));
51734- fscache_stat(&fscache_n_op_cancelled);
51735+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51736 list_del_init(&op->pend_link);
51737 if (do_cancel)
51738 do_cancel(op);
51739@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51740 while (!list_empty(&object->pending_ops)) {
51741 op = list_entry(object->pending_ops.next,
51742 struct fscache_operation, pend_link);
51743- fscache_stat(&fscache_n_op_cancelled);
51744+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51745 list_del_init(&op->pend_link);
51746
51747 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51748@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51749 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51750 op->state = FSCACHE_OP_ST_DEAD;
51751
51752- fscache_stat(&fscache_n_op_release);
51753+ fscache_stat_unchecked(&fscache_n_op_release);
51754
51755 if (op->release) {
51756 op->release(op);
51757@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51758 * lock, and defer it otherwise */
51759 if (!spin_trylock(&object->lock)) {
51760 _debug("defer put");
51761- fscache_stat(&fscache_n_op_deferred_release);
51762+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
51763
51764 cache = object->cache;
51765 spin_lock(&cache->op_gc_list_lock);
51766@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51767
51768 _debug("GC DEFERRED REL OBJ%x OP%x",
51769 object->debug_id, op->debug_id);
51770- fscache_stat(&fscache_n_op_gc);
51771+ fscache_stat_unchecked(&fscache_n_op_gc);
51772
51773 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51774 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51775diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51776index ff000e5..c44ec6d 100644
51777--- a/fs/fscache/page.c
51778+++ b/fs/fscache/page.c
51779@@ -61,7 +61,7 @@ try_again:
51780 val = radix_tree_lookup(&cookie->stores, page->index);
51781 if (!val) {
51782 rcu_read_unlock();
51783- fscache_stat(&fscache_n_store_vmscan_not_storing);
51784+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51785 __fscache_uncache_page(cookie, page);
51786 return true;
51787 }
51788@@ -91,11 +91,11 @@ try_again:
51789 spin_unlock(&cookie->stores_lock);
51790
51791 if (xpage) {
51792- fscache_stat(&fscache_n_store_vmscan_cancelled);
51793- fscache_stat(&fscache_n_store_radix_deletes);
51794+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51795+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51796 ASSERTCMP(xpage, ==, page);
51797 } else {
51798- fscache_stat(&fscache_n_store_vmscan_gone);
51799+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51800 }
51801
51802 wake_up_bit(&cookie->flags, 0);
51803@@ -110,11 +110,11 @@ page_busy:
51804 * sleeping on memory allocation, so we may need to impose a timeout
51805 * too. */
51806 if (!(gfp & __GFP_WAIT)) {
51807- fscache_stat(&fscache_n_store_vmscan_busy);
51808+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51809 return false;
51810 }
51811
51812- fscache_stat(&fscache_n_store_vmscan_wait);
51813+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51814 __fscache_wait_on_page_write(cookie, page);
51815 gfp &= ~__GFP_WAIT;
51816 goto try_again;
51817@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51818 FSCACHE_COOKIE_STORING_TAG);
51819 if (!radix_tree_tag_get(&cookie->stores, page->index,
51820 FSCACHE_COOKIE_PENDING_TAG)) {
51821- fscache_stat(&fscache_n_store_radix_deletes);
51822+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51823 xpage = radix_tree_delete(&cookie->stores, page->index);
51824 }
51825 spin_unlock(&cookie->stores_lock);
51826@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51827
51828 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51829
51830- fscache_stat(&fscache_n_attr_changed_calls);
51831+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51832
51833 if (fscache_object_is_active(object)) {
51834 fscache_stat(&fscache_n_cop_attr_changed);
51835@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51836
51837 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51838
51839- fscache_stat(&fscache_n_attr_changed);
51840+ fscache_stat_unchecked(&fscache_n_attr_changed);
51841
51842 op = kzalloc(sizeof(*op), GFP_KERNEL);
51843 if (!op) {
51844- fscache_stat(&fscache_n_attr_changed_nomem);
51845+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51846 _leave(" = -ENOMEM");
51847 return -ENOMEM;
51848 }
51849@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51850 if (fscache_submit_exclusive_op(object, op) < 0)
51851 goto nobufs;
51852 spin_unlock(&cookie->lock);
51853- fscache_stat(&fscache_n_attr_changed_ok);
51854+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51855 fscache_put_operation(op);
51856 _leave(" = 0");
51857 return 0;
51858@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51859 nobufs:
51860 spin_unlock(&cookie->lock);
51861 kfree(op);
51862- fscache_stat(&fscache_n_attr_changed_nobufs);
51863+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51864 _leave(" = %d", -ENOBUFS);
51865 return -ENOBUFS;
51866 }
51867@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51868 /* allocate a retrieval operation and attempt to submit it */
51869 op = kzalloc(sizeof(*op), GFP_NOIO);
51870 if (!op) {
51871- fscache_stat(&fscache_n_retrievals_nomem);
51872+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51873 return NULL;
51874 }
51875
51876@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51877 return 0;
51878 }
51879
51880- fscache_stat(&fscache_n_retrievals_wait);
51881+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
51882
51883 jif = jiffies;
51884 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51885 fscache_wait_bit_interruptible,
51886 TASK_INTERRUPTIBLE) != 0) {
51887- fscache_stat(&fscache_n_retrievals_intr);
51888+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51889 _leave(" = -ERESTARTSYS");
51890 return -ERESTARTSYS;
51891 }
51892@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51893 */
51894 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51895 struct fscache_retrieval *op,
51896- atomic_t *stat_op_waits,
51897- atomic_t *stat_object_dead)
51898+ atomic_unchecked_t *stat_op_waits,
51899+ atomic_unchecked_t *stat_object_dead)
51900 {
51901 int ret;
51902
51903@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51904 goto check_if_dead;
51905
51906 _debug(">>> WT");
51907- fscache_stat(stat_op_waits);
51908+ fscache_stat_unchecked(stat_op_waits);
51909 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51910 fscache_wait_bit_interruptible,
51911 TASK_INTERRUPTIBLE) != 0) {
51912@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51913
51914 check_if_dead:
51915 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51916- fscache_stat(stat_object_dead);
51917+ fscache_stat_unchecked(stat_object_dead);
51918 _leave(" = -ENOBUFS [cancelled]");
51919 return -ENOBUFS;
51920 }
51921 if (unlikely(fscache_object_is_dead(object))) {
51922 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51923 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51924- fscache_stat(stat_object_dead);
51925+ fscache_stat_unchecked(stat_object_dead);
51926 return -ENOBUFS;
51927 }
51928 return 0;
51929@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51930
51931 _enter("%p,%p,,,", cookie, page);
51932
51933- fscache_stat(&fscache_n_retrievals);
51934+ fscache_stat_unchecked(&fscache_n_retrievals);
51935
51936 if (hlist_empty(&cookie->backing_objects))
51937 goto nobufs;
51938@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51939 goto nobufs_unlock_dec;
51940 spin_unlock(&cookie->lock);
51941
51942- fscache_stat(&fscache_n_retrieval_ops);
51943+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51944
51945 /* pin the netfs read context in case we need to do the actual netfs
51946 * read because we've encountered a cache read failure */
51947@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51948
51949 error:
51950 if (ret == -ENOMEM)
51951- fscache_stat(&fscache_n_retrievals_nomem);
51952+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51953 else if (ret == -ERESTARTSYS)
51954- fscache_stat(&fscache_n_retrievals_intr);
51955+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51956 else if (ret == -ENODATA)
51957- fscache_stat(&fscache_n_retrievals_nodata);
51958+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51959 else if (ret < 0)
51960- fscache_stat(&fscache_n_retrievals_nobufs);
51961+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51962 else
51963- fscache_stat(&fscache_n_retrievals_ok);
51964+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
51965
51966 fscache_put_retrieval(op);
51967 _leave(" = %d", ret);
51968@@ -467,7 +467,7 @@ nobufs_unlock:
51969 spin_unlock(&cookie->lock);
51970 kfree(op);
51971 nobufs:
51972- fscache_stat(&fscache_n_retrievals_nobufs);
51973+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51974 _leave(" = -ENOBUFS");
51975 return -ENOBUFS;
51976 }
51977@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51978
51979 _enter("%p,,%d,,,", cookie, *nr_pages);
51980
51981- fscache_stat(&fscache_n_retrievals);
51982+ fscache_stat_unchecked(&fscache_n_retrievals);
51983
51984 if (hlist_empty(&cookie->backing_objects))
51985 goto nobufs;
51986@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51987 goto nobufs_unlock_dec;
51988 spin_unlock(&cookie->lock);
51989
51990- fscache_stat(&fscache_n_retrieval_ops);
51991+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51992
51993 /* pin the netfs read context in case we need to do the actual netfs
51994 * read because we've encountered a cache read failure */
51995@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51996
51997 error:
51998 if (ret == -ENOMEM)
51999- fscache_stat(&fscache_n_retrievals_nomem);
52000+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52001 else if (ret == -ERESTARTSYS)
52002- fscache_stat(&fscache_n_retrievals_intr);
52003+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52004 else if (ret == -ENODATA)
52005- fscache_stat(&fscache_n_retrievals_nodata);
52006+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52007 else if (ret < 0)
52008- fscache_stat(&fscache_n_retrievals_nobufs);
52009+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52010 else
52011- fscache_stat(&fscache_n_retrievals_ok);
52012+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52013
52014 fscache_put_retrieval(op);
52015 _leave(" = %d", ret);
52016@@ -591,7 +591,7 @@ nobufs_unlock:
52017 spin_unlock(&cookie->lock);
52018 kfree(op);
52019 nobufs:
52020- fscache_stat(&fscache_n_retrievals_nobufs);
52021+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52022 _leave(" = -ENOBUFS");
52023 return -ENOBUFS;
52024 }
52025@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52026
52027 _enter("%p,%p,,,", cookie, page);
52028
52029- fscache_stat(&fscache_n_allocs);
52030+ fscache_stat_unchecked(&fscache_n_allocs);
52031
52032 if (hlist_empty(&cookie->backing_objects))
52033 goto nobufs;
52034@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52035 goto nobufs_unlock;
52036 spin_unlock(&cookie->lock);
52037
52038- fscache_stat(&fscache_n_alloc_ops);
52039+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52040
52041 ret = fscache_wait_for_retrieval_activation(
52042 object, op,
52043@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52044
52045 error:
52046 if (ret == -ERESTARTSYS)
52047- fscache_stat(&fscache_n_allocs_intr);
52048+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52049 else if (ret < 0)
52050- fscache_stat(&fscache_n_allocs_nobufs);
52051+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52052 else
52053- fscache_stat(&fscache_n_allocs_ok);
52054+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52055
52056 fscache_put_retrieval(op);
52057 _leave(" = %d", ret);
52058@@ -677,7 +677,7 @@ nobufs_unlock:
52059 spin_unlock(&cookie->lock);
52060 kfree(op);
52061 nobufs:
52062- fscache_stat(&fscache_n_allocs_nobufs);
52063+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52064 _leave(" = -ENOBUFS");
52065 return -ENOBUFS;
52066 }
52067@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52068
52069 spin_lock(&cookie->stores_lock);
52070
52071- fscache_stat(&fscache_n_store_calls);
52072+ fscache_stat_unchecked(&fscache_n_store_calls);
52073
52074 /* find a page to store */
52075 page = NULL;
52076@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52077 page = results[0];
52078 _debug("gang %d [%lx]", n, page->index);
52079 if (page->index > op->store_limit) {
52080- fscache_stat(&fscache_n_store_pages_over_limit);
52081+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52082 goto superseded;
52083 }
52084
52085@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52086 spin_unlock(&cookie->stores_lock);
52087 spin_unlock(&object->lock);
52088
52089- fscache_stat(&fscache_n_store_pages);
52090+ fscache_stat_unchecked(&fscache_n_store_pages);
52091 fscache_stat(&fscache_n_cop_write_page);
52092 ret = object->cache->ops->write_page(op, page);
52093 fscache_stat_d(&fscache_n_cop_write_page);
52094@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52095 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52096 ASSERT(PageFsCache(page));
52097
52098- fscache_stat(&fscache_n_stores);
52099+ fscache_stat_unchecked(&fscache_n_stores);
52100
52101 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52102 _leave(" = -ENOBUFS [invalidating]");
52103@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52104 spin_unlock(&cookie->stores_lock);
52105 spin_unlock(&object->lock);
52106
52107- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52108+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52109 op->store_limit = object->store_limit;
52110
52111 if (fscache_submit_op(object, &op->op) < 0)
52112@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52113
52114 spin_unlock(&cookie->lock);
52115 radix_tree_preload_end();
52116- fscache_stat(&fscache_n_store_ops);
52117- fscache_stat(&fscache_n_stores_ok);
52118+ fscache_stat_unchecked(&fscache_n_store_ops);
52119+ fscache_stat_unchecked(&fscache_n_stores_ok);
52120
52121 /* the work queue now carries its own ref on the object */
52122 fscache_put_operation(&op->op);
52123@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52124 return 0;
52125
52126 already_queued:
52127- fscache_stat(&fscache_n_stores_again);
52128+ fscache_stat_unchecked(&fscache_n_stores_again);
52129 already_pending:
52130 spin_unlock(&cookie->stores_lock);
52131 spin_unlock(&object->lock);
52132 spin_unlock(&cookie->lock);
52133 radix_tree_preload_end();
52134 kfree(op);
52135- fscache_stat(&fscache_n_stores_ok);
52136+ fscache_stat_unchecked(&fscache_n_stores_ok);
52137 _leave(" = 0");
52138 return 0;
52139
52140@@ -959,14 +959,14 @@ nobufs:
52141 spin_unlock(&cookie->lock);
52142 radix_tree_preload_end();
52143 kfree(op);
52144- fscache_stat(&fscache_n_stores_nobufs);
52145+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52146 _leave(" = -ENOBUFS");
52147 return -ENOBUFS;
52148
52149 nomem_free:
52150 kfree(op);
52151 nomem:
52152- fscache_stat(&fscache_n_stores_oom);
52153+ fscache_stat_unchecked(&fscache_n_stores_oom);
52154 _leave(" = -ENOMEM");
52155 return -ENOMEM;
52156 }
52157@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52158 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52159 ASSERTCMP(page, !=, NULL);
52160
52161- fscache_stat(&fscache_n_uncaches);
52162+ fscache_stat_unchecked(&fscache_n_uncaches);
52163
52164 /* cache withdrawal may beat us to it */
52165 if (!PageFsCache(page))
52166@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52167 struct fscache_cookie *cookie = op->op.object->cookie;
52168
52169 #ifdef CONFIG_FSCACHE_STATS
52170- atomic_inc(&fscache_n_marks);
52171+ atomic_inc_unchecked(&fscache_n_marks);
52172 #endif
52173
52174 _debug("- mark %p{%lx}", page, page->index);
52175diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52176index 8179e8b..5072cc7 100644
52177--- a/fs/fscache/stats.c
52178+++ b/fs/fscache/stats.c
52179@@ -18,99 +18,99 @@
52180 /*
52181 * operation counters
52182 */
52183-atomic_t fscache_n_op_pend;
52184-atomic_t fscache_n_op_run;
52185-atomic_t fscache_n_op_enqueue;
52186-atomic_t fscache_n_op_requeue;
52187-atomic_t fscache_n_op_deferred_release;
52188-atomic_t fscache_n_op_release;
52189-atomic_t fscache_n_op_gc;
52190-atomic_t fscache_n_op_cancelled;
52191-atomic_t fscache_n_op_rejected;
52192+atomic_unchecked_t fscache_n_op_pend;
52193+atomic_unchecked_t fscache_n_op_run;
52194+atomic_unchecked_t fscache_n_op_enqueue;
52195+atomic_unchecked_t fscache_n_op_requeue;
52196+atomic_unchecked_t fscache_n_op_deferred_release;
52197+atomic_unchecked_t fscache_n_op_release;
52198+atomic_unchecked_t fscache_n_op_gc;
52199+atomic_unchecked_t fscache_n_op_cancelled;
52200+atomic_unchecked_t fscache_n_op_rejected;
52201
52202-atomic_t fscache_n_attr_changed;
52203-atomic_t fscache_n_attr_changed_ok;
52204-atomic_t fscache_n_attr_changed_nobufs;
52205-atomic_t fscache_n_attr_changed_nomem;
52206-atomic_t fscache_n_attr_changed_calls;
52207+atomic_unchecked_t fscache_n_attr_changed;
52208+atomic_unchecked_t fscache_n_attr_changed_ok;
52209+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52210+atomic_unchecked_t fscache_n_attr_changed_nomem;
52211+atomic_unchecked_t fscache_n_attr_changed_calls;
52212
52213-atomic_t fscache_n_allocs;
52214-atomic_t fscache_n_allocs_ok;
52215-atomic_t fscache_n_allocs_wait;
52216-atomic_t fscache_n_allocs_nobufs;
52217-atomic_t fscache_n_allocs_intr;
52218-atomic_t fscache_n_allocs_object_dead;
52219-atomic_t fscache_n_alloc_ops;
52220-atomic_t fscache_n_alloc_op_waits;
52221+atomic_unchecked_t fscache_n_allocs;
52222+atomic_unchecked_t fscache_n_allocs_ok;
52223+atomic_unchecked_t fscache_n_allocs_wait;
52224+atomic_unchecked_t fscache_n_allocs_nobufs;
52225+atomic_unchecked_t fscache_n_allocs_intr;
52226+atomic_unchecked_t fscache_n_allocs_object_dead;
52227+atomic_unchecked_t fscache_n_alloc_ops;
52228+atomic_unchecked_t fscache_n_alloc_op_waits;
52229
52230-atomic_t fscache_n_retrievals;
52231-atomic_t fscache_n_retrievals_ok;
52232-atomic_t fscache_n_retrievals_wait;
52233-atomic_t fscache_n_retrievals_nodata;
52234-atomic_t fscache_n_retrievals_nobufs;
52235-atomic_t fscache_n_retrievals_intr;
52236-atomic_t fscache_n_retrievals_nomem;
52237-atomic_t fscache_n_retrievals_object_dead;
52238-atomic_t fscache_n_retrieval_ops;
52239-atomic_t fscache_n_retrieval_op_waits;
52240+atomic_unchecked_t fscache_n_retrievals;
52241+atomic_unchecked_t fscache_n_retrievals_ok;
52242+atomic_unchecked_t fscache_n_retrievals_wait;
52243+atomic_unchecked_t fscache_n_retrievals_nodata;
52244+atomic_unchecked_t fscache_n_retrievals_nobufs;
52245+atomic_unchecked_t fscache_n_retrievals_intr;
52246+atomic_unchecked_t fscache_n_retrievals_nomem;
52247+atomic_unchecked_t fscache_n_retrievals_object_dead;
52248+atomic_unchecked_t fscache_n_retrieval_ops;
52249+atomic_unchecked_t fscache_n_retrieval_op_waits;
52250
52251-atomic_t fscache_n_stores;
52252-atomic_t fscache_n_stores_ok;
52253-atomic_t fscache_n_stores_again;
52254-atomic_t fscache_n_stores_nobufs;
52255-atomic_t fscache_n_stores_oom;
52256-atomic_t fscache_n_store_ops;
52257-atomic_t fscache_n_store_calls;
52258-atomic_t fscache_n_store_pages;
52259-atomic_t fscache_n_store_radix_deletes;
52260-atomic_t fscache_n_store_pages_over_limit;
52261+atomic_unchecked_t fscache_n_stores;
52262+atomic_unchecked_t fscache_n_stores_ok;
52263+atomic_unchecked_t fscache_n_stores_again;
52264+atomic_unchecked_t fscache_n_stores_nobufs;
52265+atomic_unchecked_t fscache_n_stores_oom;
52266+atomic_unchecked_t fscache_n_store_ops;
52267+atomic_unchecked_t fscache_n_store_calls;
52268+atomic_unchecked_t fscache_n_store_pages;
52269+atomic_unchecked_t fscache_n_store_radix_deletes;
52270+atomic_unchecked_t fscache_n_store_pages_over_limit;
52271
52272-atomic_t fscache_n_store_vmscan_not_storing;
52273-atomic_t fscache_n_store_vmscan_gone;
52274-atomic_t fscache_n_store_vmscan_busy;
52275-atomic_t fscache_n_store_vmscan_cancelled;
52276-atomic_t fscache_n_store_vmscan_wait;
52277+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52278+atomic_unchecked_t fscache_n_store_vmscan_gone;
52279+atomic_unchecked_t fscache_n_store_vmscan_busy;
52280+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52281+atomic_unchecked_t fscache_n_store_vmscan_wait;
52282
52283-atomic_t fscache_n_marks;
52284-atomic_t fscache_n_uncaches;
52285+atomic_unchecked_t fscache_n_marks;
52286+atomic_unchecked_t fscache_n_uncaches;
52287
52288-atomic_t fscache_n_acquires;
52289-atomic_t fscache_n_acquires_null;
52290-atomic_t fscache_n_acquires_no_cache;
52291-atomic_t fscache_n_acquires_ok;
52292-atomic_t fscache_n_acquires_nobufs;
52293-atomic_t fscache_n_acquires_oom;
52294+atomic_unchecked_t fscache_n_acquires;
52295+atomic_unchecked_t fscache_n_acquires_null;
52296+atomic_unchecked_t fscache_n_acquires_no_cache;
52297+atomic_unchecked_t fscache_n_acquires_ok;
52298+atomic_unchecked_t fscache_n_acquires_nobufs;
52299+atomic_unchecked_t fscache_n_acquires_oom;
52300
52301-atomic_t fscache_n_invalidates;
52302-atomic_t fscache_n_invalidates_run;
52303+atomic_unchecked_t fscache_n_invalidates;
52304+atomic_unchecked_t fscache_n_invalidates_run;
52305
52306-atomic_t fscache_n_updates;
52307-atomic_t fscache_n_updates_null;
52308-atomic_t fscache_n_updates_run;
52309+atomic_unchecked_t fscache_n_updates;
52310+atomic_unchecked_t fscache_n_updates_null;
52311+atomic_unchecked_t fscache_n_updates_run;
52312
52313-atomic_t fscache_n_relinquishes;
52314-atomic_t fscache_n_relinquishes_null;
52315-atomic_t fscache_n_relinquishes_waitcrt;
52316-atomic_t fscache_n_relinquishes_retire;
52317+atomic_unchecked_t fscache_n_relinquishes;
52318+atomic_unchecked_t fscache_n_relinquishes_null;
52319+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52320+atomic_unchecked_t fscache_n_relinquishes_retire;
52321
52322-atomic_t fscache_n_cookie_index;
52323-atomic_t fscache_n_cookie_data;
52324-atomic_t fscache_n_cookie_special;
52325+atomic_unchecked_t fscache_n_cookie_index;
52326+atomic_unchecked_t fscache_n_cookie_data;
52327+atomic_unchecked_t fscache_n_cookie_special;
52328
52329-atomic_t fscache_n_object_alloc;
52330-atomic_t fscache_n_object_no_alloc;
52331-atomic_t fscache_n_object_lookups;
52332-atomic_t fscache_n_object_lookups_negative;
52333-atomic_t fscache_n_object_lookups_positive;
52334-atomic_t fscache_n_object_lookups_timed_out;
52335-atomic_t fscache_n_object_created;
52336-atomic_t fscache_n_object_avail;
52337-atomic_t fscache_n_object_dead;
52338+atomic_unchecked_t fscache_n_object_alloc;
52339+atomic_unchecked_t fscache_n_object_no_alloc;
52340+atomic_unchecked_t fscache_n_object_lookups;
52341+atomic_unchecked_t fscache_n_object_lookups_negative;
52342+atomic_unchecked_t fscache_n_object_lookups_positive;
52343+atomic_unchecked_t fscache_n_object_lookups_timed_out;
52344+atomic_unchecked_t fscache_n_object_created;
52345+atomic_unchecked_t fscache_n_object_avail;
52346+atomic_unchecked_t fscache_n_object_dead;
52347
52348-atomic_t fscache_n_checkaux_none;
52349-atomic_t fscache_n_checkaux_okay;
52350-atomic_t fscache_n_checkaux_update;
52351-atomic_t fscache_n_checkaux_obsolete;
52352+atomic_unchecked_t fscache_n_checkaux_none;
52353+atomic_unchecked_t fscache_n_checkaux_okay;
52354+atomic_unchecked_t fscache_n_checkaux_update;
52355+atomic_unchecked_t fscache_n_checkaux_obsolete;
52356
52357 atomic_t fscache_n_cop_alloc_object;
52358 atomic_t fscache_n_cop_lookup_object;
52359@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
52360 seq_puts(m, "FS-Cache statistics\n");
52361
52362 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
52363- atomic_read(&fscache_n_cookie_index),
52364- atomic_read(&fscache_n_cookie_data),
52365- atomic_read(&fscache_n_cookie_special));
52366+ atomic_read_unchecked(&fscache_n_cookie_index),
52367+ atomic_read_unchecked(&fscache_n_cookie_data),
52368+ atomic_read_unchecked(&fscache_n_cookie_special));
52369
52370 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
52371- atomic_read(&fscache_n_object_alloc),
52372- atomic_read(&fscache_n_object_no_alloc),
52373- atomic_read(&fscache_n_object_avail),
52374- atomic_read(&fscache_n_object_dead));
52375+ atomic_read_unchecked(&fscache_n_object_alloc),
52376+ atomic_read_unchecked(&fscache_n_object_no_alloc),
52377+ atomic_read_unchecked(&fscache_n_object_avail),
52378+ atomic_read_unchecked(&fscache_n_object_dead));
52379 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
52380- atomic_read(&fscache_n_checkaux_none),
52381- atomic_read(&fscache_n_checkaux_okay),
52382- atomic_read(&fscache_n_checkaux_update),
52383- atomic_read(&fscache_n_checkaux_obsolete));
52384+ atomic_read_unchecked(&fscache_n_checkaux_none),
52385+ atomic_read_unchecked(&fscache_n_checkaux_okay),
52386+ atomic_read_unchecked(&fscache_n_checkaux_update),
52387+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
52388
52389 seq_printf(m, "Pages : mrk=%u unc=%u\n",
52390- atomic_read(&fscache_n_marks),
52391- atomic_read(&fscache_n_uncaches));
52392+ atomic_read_unchecked(&fscache_n_marks),
52393+ atomic_read_unchecked(&fscache_n_uncaches));
52394
52395 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
52396 " oom=%u\n",
52397- atomic_read(&fscache_n_acquires),
52398- atomic_read(&fscache_n_acquires_null),
52399- atomic_read(&fscache_n_acquires_no_cache),
52400- atomic_read(&fscache_n_acquires_ok),
52401- atomic_read(&fscache_n_acquires_nobufs),
52402- atomic_read(&fscache_n_acquires_oom));
52403+ atomic_read_unchecked(&fscache_n_acquires),
52404+ atomic_read_unchecked(&fscache_n_acquires_null),
52405+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
52406+ atomic_read_unchecked(&fscache_n_acquires_ok),
52407+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
52408+ atomic_read_unchecked(&fscache_n_acquires_oom));
52409
52410 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
52411- atomic_read(&fscache_n_object_lookups),
52412- atomic_read(&fscache_n_object_lookups_negative),
52413- atomic_read(&fscache_n_object_lookups_positive),
52414- atomic_read(&fscache_n_object_created),
52415- atomic_read(&fscache_n_object_lookups_timed_out));
52416+ atomic_read_unchecked(&fscache_n_object_lookups),
52417+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
52418+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
52419+ atomic_read_unchecked(&fscache_n_object_created),
52420+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52421
52422 seq_printf(m, "Invals : n=%u run=%u\n",
52423- atomic_read(&fscache_n_invalidates),
52424- atomic_read(&fscache_n_invalidates_run));
52425+ atomic_read_unchecked(&fscache_n_invalidates),
52426+ atomic_read_unchecked(&fscache_n_invalidates_run));
52427
52428 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52429- atomic_read(&fscache_n_updates),
52430- atomic_read(&fscache_n_updates_null),
52431- atomic_read(&fscache_n_updates_run));
52432+ atomic_read_unchecked(&fscache_n_updates),
52433+ atomic_read_unchecked(&fscache_n_updates_null),
52434+ atomic_read_unchecked(&fscache_n_updates_run));
52435
52436 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52437- atomic_read(&fscache_n_relinquishes),
52438- atomic_read(&fscache_n_relinquishes_null),
52439- atomic_read(&fscache_n_relinquishes_waitcrt),
52440- atomic_read(&fscache_n_relinquishes_retire));
52441+ atomic_read_unchecked(&fscache_n_relinquishes),
52442+ atomic_read_unchecked(&fscache_n_relinquishes_null),
52443+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52444+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
52445
52446 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52447- atomic_read(&fscache_n_attr_changed),
52448- atomic_read(&fscache_n_attr_changed_ok),
52449- atomic_read(&fscache_n_attr_changed_nobufs),
52450- atomic_read(&fscache_n_attr_changed_nomem),
52451- atomic_read(&fscache_n_attr_changed_calls));
52452+ atomic_read_unchecked(&fscache_n_attr_changed),
52453+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
52454+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52455+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52456+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
52457
52458 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52459- atomic_read(&fscache_n_allocs),
52460- atomic_read(&fscache_n_allocs_ok),
52461- atomic_read(&fscache_n_allocs_wait),
52462- atomic_read(&fscache_n_allocs_nobufs),
52463- atomic_read(&fscache_n_allocs_intr));
52464+ atomic_read_unchecked(&fscache_n_allocs),
52465+ atomic_read_unchecked(&fscache_n_allocs_ok),
52466+ atomic_read_unchecked(&fscache_n_allocs_wait),
52467+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
52468+ atomic_read_unchecked(&fscache_n_allocs_intr));
52469 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52470- atomic_read(&fscache_n_alloc_ops),
52471- atomic_read(&fscache_n_alloc_op_waits),
52472- atomic_read(&fscache_n_allocs_object_dead));
52473+ atomic_read_unchecked(&fscache_n_alloc_ops),
52474+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
52475+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
52476
52477 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52478 " int=%u oom=%u\n",
52479- atomic_read(&fscache_n_retrievals),
52480- atomic_read(&fscache_n_retrievals_ok),
52481- atomic_read(&fscache_n_retrievals_wait),
52482- atomic_read(&fscache_n_retrievals_nodata),
52483- atomic_read(&fscache_n_retrievals_nobufs),
52484- atomic_read(&fscache_n_retrievals_intr),
52485- atomic_read(&fscache_n_retrievals_nomem));
52486+ atomic_read_unchecked(&fscache_n_retrievals),
52487+ atomic_read_unchecked(&fscache_n_retrievals_ok),
52488+ atomic_read_unchecked(&fscache_n_retrievals_wait),
52489+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
52490+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52491+ atomic_read_unchecked(&fscache_n_retrievals_intr),
52492+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
52493 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52494- atomic_read(&fscache_n_retrieval_ops),
52495- atomic_read(&fscache_n_retrieval_op_waits),
52496- atomic_read(&fscache_n_retrievals_object_dead));
52497+ atomic_read_unchecked(&fscache_n_retrieval_ops),
52498+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52499+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52500
52501 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52502- atomic_read(&fscache_n_stores),
52503- atomic_read(&fscache_n_stores_ok),
52504- atomic_read(&fscache_n_stores_again),
52505- atomic_read(&fscache_n_stores_nobufs),
52506- atomic_read(&fscache_n_stores_oom));
52507+ atomic_read_unchecked(&fscache_n_stores),
52508+ atomic_read_unchecked(&fscache_n_stores_ok),
52509+ atomic_read_unchecked(&fscache_n_stores_again),
52510+ atomic_read_unchecked(&fscache_n_stores_nobufs),
52511+ atomic_read_unchecked(&fscache_n_stores_oom));
52512 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52513- atomic_read(&fscache_n_store_ops),
52514- atomic_read(&fscache_n_store_calls),
52515- atomic_read(&fscache_n_store_pages),
52516- atomic_read(&fscache_n_store_radix_deletes),
52517- atomic_read(&fscache_n_store_pages_over_limit));
52518+ atomic_read_unchecked(&fscache_n_store_ops),
52519+ atomic_read_unchecked(&fscache_n_store_calls),
52520+ atomic_read_unchecked(&fscache_n_store_pages),
52521+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
52522+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52523
52524 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52525- atomic_read(&fscache_n_store_vmscan_not_storing),
52526- atomic_read(&fscache_n_store_vmscan_gone),
52527- atomic_read(&fscache_n_store_vmscan_busy),
52528- atomic_read(&fscache_n_store_vmscan_cancelled),
52529- atomic_read(&fscache_n_store_vmscan_wait));
52530+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52531+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52532+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52533+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52534+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52535
52536 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52537- atomic_read(&fscache_n_op_pend),
52538- atomic_read(&fscache_n_op_run),
52539- atomic_read(&fscache_n_op_enqueue),
52540- atomic_read(&fscache_n_op_cancelled),
52541- atomic_read(&fscache_n_op_rejected));
52542+ atomic_read_unchecked(&fscache_n_op_pend),
52543+ atomic_read_unchecked(&fscache_n_op_run),
52544+ atomic_read_unchecked(&fscache_n_op_enqueue),
52545+ atomic_read_unchecked(&fscache_n_op_cancelled),
52546+ atomic_read_unchecked(&fscache_n_op_rejected));
52547 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52548- atomic_read(&fscache_n_op_deferred_release),
52549- atomic_read(&fscache_n_op_release),
52550- atomic_read(&fscache_n_op_gc));
52551+ atomic_read_unchecked(&fscache_n_op_deferred_release),
52552+ atomic_read_unchecked(&fscache_n_op_release),
52553+ atomic_read_unchecked(&fscache_n_op_gc));
52554
52555 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52556 atomic_read(&fscache_n_cop_alloc_object),
52557diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52558index e397b67..b0d8709 100644
52559--- a/fs/fuse/cuse.c
52560+++ b/fs/fuse/cuse.c
52561@@ -593,10 +593,12 @@ static int __init cuse_init(void)
52562 INIT_LIST_HEAD(&cuse_conntbl[i]);
52563
52564 /* inherit and extend fuse_dev_operations */
52565- cuse_channel_fops = fuse_dev_operations;
52566- cuse_channel_fops.owner = THIS_MODULE;
52567- cuse_channel_fops.open = cuse_channel_open;
52568- cuse_channel_fops.release = cuse_channel_release;
52569+ pax_open_kernel();
52570+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52571+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52572+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
52573+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
52574+ pax_close_kernel();
52575
52576 cuse_class = class_create(THIS_MODULE, "cuse");
52577 if (IS_ERR(cuse_class))
52578diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52579index e83351a..41e3c9c 100644
52580--- a/fs/fuse/dev.c
52581+++ b/fs/fuse/dev.c
52582@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52583 ret = 0;
52584 pipe_lock(pipe);
52585
52586- if (!pipe->readers) {
52587+ if (!atomic_read(&pipe->readers)) {
52588 send_sig(SIGPIPE, current, 0);
52589 if (!ret)
52590 ret = -EPIPE;
52591diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52592index 315e1f8..91f890c 100644
52593--- a/fs/fuse/dir.c
52594+++ b/fs/fuse/dir.c
52595@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52596 return link;
52597 }
52598
52599-static void free_link(char *link)
52600+static void free_link(const char *link)
52601 {
52602 if (!IS_ERR(link))
52603 free_page((unsigned long) link);
52604diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52605index 2b6f569..fcb4d1f 100644
52606--- a/fs/gfs2/inode.c
52607+++ b/fs/gfs2/inode.c
52608@@ -1499,7 +1499,7 @@ out:
52609
52610 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52611 {
52612- char *s = nd_get_link(nd);
52613+ const char *s = nd_get_link(nd);
52614 if (!IS_ERR(s))
52615 kfree(s);
52616 }
52617diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52618index 78bde32..767e906 100644
52619--- a/fs/hugetlbfs/inode.c
52620+++ b/fs/hugetlbfs/inode.c
52621@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52622 struct mm_struct *mm = current->mm;
52623 struct vm_area_struct *vma;
52624 struct hstate *h = hstate_file(file);
52625+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52626 struct vm_unmapped_area_info info;
52627
52628 if (len & ~huge_page_mask(h))
52629@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52630 return addr;
52631 }
52632
52633+#ifdef CONFIG_PAX_RANDMMAP
52634+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52635+#endif
52636+
52637 if (addr) {
52638 addr = ALIGN(addr, huge_page_size(h));
52639 vma = find_vma(mm, addr);
52640- if (TASK_SIZE - len >= addr &&
52641- (!vma || addr + len <= vma->vm_start))
52642+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52643 return addr;
52644 }
52645
52646 info.flags = 0;
52647 info.length = len;
52648 info.low_limit = TASK_UNMAPPED_BASE;
52649+
52650+#ifdef CONFIG_PAX_RANDMMAP
52651+ if (mm->pax_flags & MF_PAX_RANDMMAP)
52652+ info.low_limit += mm->delta_mmap;
52653+#endif
52654+
52655 info.high_limit = TASK_SIZE;
52656 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52657 info.align_offset = 0;
52658@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52659 .kill_sb = kill_litter_super,
52660 };
52661
52662-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52663+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52664
52665 static int can_do_hugetlb_shm(void)
52666 {
52667diff --git a/fs/inode.c b/fs/inode.c
52668index 14084b7..29af1d9 100644
52669--- a/fs/inode.c
52670+++ b/fs/inode.c
52671@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52672
52673 #ifdef CONFIG_SMP
52674 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52675- static atomic_t shared_last_ino;
52676- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52677+ static atomic_unchecked_t shared_last_ino;
52678+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52679
52680 res = next - LAST_INO_BATCH;
52681 }
52682diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52683index 4a6cf28..d3a29d3 100644
52684--- a/fs/jffs2/erase.c
52685+++ b/fs/jffs2/erase.c
52686@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52687 struct jffs2_unknown_node marker = {
52688 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52689 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52690- .totlen = cpu_to_je32(c->cleanmarker_size)
52691+ .totlen = cpu_to_je32(c->cleanmarker_size),
52692+ .hdr_crc = cpu_to_je32(0)
52693 };
52694
52695 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52696diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52697index a6597d6..41b30ec 100644
52698--- a/fs/jffs2/wbuf.c
52699+++ b/fs/jffs2/wbuf.c
52700@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52701 {
52702 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52703 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52704- .totlen = constant_cpu_to_je32(8)
52705+ .totlen = constant_cpu_to_je32(8),
52706+ .hdr_crc = constant_cpu_to_je32(0)
52707 };
52708
52709 /*
52710diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52711index 1a543be..a4e1363 100644
52712--- a/fs/jfs/super.c
52713+++ b/fs/jfs/super.c
52714@@ -225,7 +225,7 @@ static const match_table_t tokens = {
52715 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52716 int *flag)
52717 {
52718- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52719+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52720 char *p;
52721 struct jfs_sb_info *sbi = JFS_SBI(sb);
52722
52723@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52724 /* Don't do anything ;-) */
52725 break;
52726 case Opt_iocharset:
52727- if (nls_map && nls_map != (void *) -1)
52728+ if (nls_map && nls_map != (const void *) -1)
52729 unload_nls(nls_map);
52730 if (!strcmp(args[0].from, "none"))
52731 nls_map = NULL;
52732@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52733
52734 jfs_inode_cachep =
52735 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52736- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52737+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52738 init_once);
52739 if (jfs_inode_cachep == NULL)
52740 return -ENOMEM;
52741diff --git a/fs/libfs.c b/fs/libfs.c
52742index 916da8c..1588998 100644
52743--- a/fs/libfs.c
52744+++ b/fs/libfs.c
52745@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52746
52747 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52748 struct dentry *next;
52749+ char d_name[sizeof(next->d_iname)];
52750+ const unsigned char *name;
52751+
52752 next = list_entry(p, struct dentry, d_u.d_child);
52753 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52754 if (!simple_positive(next)) {
52755@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52756
52757 spin_unlock(&next->d_lock);
52758 spin_unlock(&dentry->d_lock);
52759- if (filldir(dirent, next->d_name.name,
52760+ name = next->d_name.name;
52761+ if (name == next->d_iname) {
52762+ memcpy(d_name, name, next->d_name.len);
52763+ name = d_name;
52764+ }
52765+ if (filldir(dirent, name,
52766 next->d_name.len, filp->f_pos,
52767 next->d_inode->i_ino,
52768 dt_type(next->d_inode)) < 0)
52769diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52770index 52e5120..808936e 100644
52771--- a/fs/lockd/clntproc.c
52772+++ b/fs/lockd/clntproc.c
52773@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52774 /*
52775 * Cookie counter for NLM requests
52776 */
52777-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52778+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52779
52780 void nlmclnt_next_cookie(struct nlm_cookie *c)
52781 {
52782- u32 cookie = atomic_inc_return(&nlm_cookie);
52783+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52784
52785 memcpy(c->data, &cookie, 4);
52786 c->len=4;
52787diff --git a/fs/locks.c b/fs/locks.c
52788index a94e331..060bce3 100644
52789--- a/fs/locks.c
52790+++ b/fs/locks.c
52791@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52792 return;
52793
52794 if (filp->f_op && filp->f_op->flock) {
52795- struct file_lock fl = {
52796+ struct file_lock flock = {
52797 .fl_pid = current->tgid,
52798 .fl_file = filp,
52799 .fl_flags = FL_FLOCK,
52800 .fl_type = F_UNLCK,
52801 .fl_end = OFFSET_MAX,
52802 };
52803- filp->f_op->flock(filp, F_SETLKW, &fl);
52804- if (fl.fl_ops && fl.fl_ops->fl_release_private)
52805- fl.fl_ops->fl_release_private(&fl);
52806+ filp->f_op->flock(filp, F_SETLKW, &flock);
52807+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
52808+ flock.fl_ops->fl_release_private(&flock);
52809 }
52810
52811 lock_flocks();
52812diff --git a/fs/namei.c b/fs/namei.c
52813index ec97aef..6e33759 100644
52814--- a/fs/namei.c
52815+++ b/fs/namei.c
52816@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52817 if (ret != -EACCES)
52818 return ret;
52819
52820+#ifdef CONFIG_GRKERNSEC
52821+ /* we'll block if we have to log due to a denied capability use */
52822+ if (mask & MAY_NOT_BLOCK)
52823+ return -ECHILD;
52824+#endif
52825+
52826 if (S_ISDIR(inode->i_mode)) {
52827 /* DACs are overridable for directories */
52828- if (inode_capable(inode, CAP_DAC_OVERRIDE))
52829- return 0;
52830 if (!(mask & MAY_WRITE))
52831- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52832+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52833+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52834 return 0;
52835+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
52836+ return 0;
52837 return -EACCES;
52838 }
52839 /*
52840+ * Searching includes executable on directories, else just read.
52841+ */
52842+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52843+ if (mask == MAY_READ)
52844+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52845+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52846+ return 0;
52847+
52848+ /*
52849 * Read/write DACs are always overridable.
52850 * Executable DACs are overridable when there is
52851 * at least one exec bit set.
52852@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52853 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52854 return 0;
52855
52856- /*
52857- * Searching includes executable on directories, else just read.
52858- */
52859- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52860- if (mask == MAY_READ)
52861- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52862- return 0;
52863-
52864 return -EACCES;
52865 }
52866
52867@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52868 {
52869 struct dentry *dentry = link->dentry;
52870 int error;
52871- char *s;
52872+ const char *s;
52873
52874 BUG_ON(nd->flags & LOOKUP_RCU);
52875
52876@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52877 if (error)
52878 goto out_put_nd_path;
52879
52880+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
52881+ dentry->d_inode, dentry, nd->path.mnt)) {
52882+ error = -EACCES;
52883+ goto out_put_nd_path;
52884+ }
52885+
52886 nd->last_type = LAST_BIND;
52887 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52888 error = PTR_ERR(*p);
52889@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52890 break;
52891 res = walk_component(nd, path, &nd->last,
52892 nd->last_type, LOOKUP_FOLLOW);
52893+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52894+ res = -EACCES;
52895 put_link(nd, &link, cookie);
52896 } while (res > 0);
52897
52898@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
52899 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52900 {
52901 unsigned long a, b, adata, bdata, mask, hash, len;
52902- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52903+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52904
52905 hash = a = 0;
52906 len = -sizeof(unsigned long);
52907@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
52908 if (err)
52909 break;
52910 err = lookup_last(nd, &path);
52911+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
52912+ err = -EACCES;
52913 put_link(nd, &link, cookie);
52914 }
52915 }
52916@@ -1984,6 +2002,19 @@ static int path_lookupat(int dfd, const char *name,
52917 if (!err)
52918 err = complete_walk(nd);
52919
52920+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
52921+#ifdef CONFIG_GRKERNSEC
52922+ if (flags & LOOKUP_RCU) {
52923+ path_put(&nd->path);
52924+ err = -ECHILD;
52925+ } else
52926+#endif
52927+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52928+ path_put(&nd->path);
52929+ err = -ENOENT;
52930+ }
52931+ }
52932+
52933 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52934 if (!nd->inode->i_op->lookup) {
52935 path_put(&nd->path);
52936@@ -2011,8 +2042,21 @@ static int filename_lookup(int dfd, struct filename *name,
52937 retval = path_lookupat(dfd, name->name,
52938 flags | LOOKUP_REVAL, nd);
52939
52940- if (likely(!retval))
52941+ if (likely(!retval)) {
52942 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52943+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52944+#ifdef CONFIG_GRKERNSEC
52945+ if (flags & LOOKUP_RCU) {
52946+ path_put(&nd->path);
52947+ return -ECHILD;
52948+ }
52949+#endif
52950+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
52951+ path_put(&nd->path);
52952+ return -ENOENT;
52953+ }
52954+ }
52955+ }
52956 return retval;
52957 }
52958
52959@@ -2390,6 +2434,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52960 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52961 return -EPERM;
52962
52963+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52964+ return -EPERM;
52965+ if (gr_handle_rawio(inode))
52966+ return -EPERM;
52967+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52968+ return -EACCES;
52969+
52970 return 0;
52971 }
52972
52973@@ -2611,7 +2662,7 @@ looked_up:
52974 * cleared otherwise prior to returning.
52975 */
52976 static int lookup_open(struct nameidata *nd, struct path *path,
52977- struct file *file,
52978+ struct path *link, struct file *file,
52979 const struct open_flags *op,
52980 bool got_write, int *opened)
52981 {
52982@@ -2646,6 +2697,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52983 /* Negative dentry, just create the file */
52984 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52985 umode_t mode = op->mode;
52986+
52987+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
52988+ error = -EACCES;
52989+ goto out_dput;
52990+ }
52991+
52992+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
52993+ error = -EACCES;
52994+ goto out_dput;
52995+ }
52996+
52997 if (!IS_POSIXACL(dir->d_inode))
52998 mode &= ~current_umask();
52999 /*
53000@@ -2667,6 +2729,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53001 nd->flags & LOOKUP_EXCL);
53002 if (error)
53003 goto out_dput;
53004+ else
53005+ gr_handle_create(dentry, nd->path.mnt);
53006 }
53007 out_no_open:
53008 path->dentry = dentry;
53009@@ -2681,7 +2745,7 @@ out_dput:
53010 /*
53011 * Handle the last step of open()
53012 */
53013-static int do_last(struct nameidata *nd, struct path *path,
53014+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53015 struct file *file, const struct open_flags *op,
53016 int *opened, struct filename *name)
53017 {
53018@@ -2710,16 +2774,44 @@ static int do_last(struct nameidata *nd, struct path *path,
53019 error = complete_walk(nd);
53020 if (error)
53021 return error;
53022+#ifdef CONFIG_GRKERNSEC
53023+ if (nd->flags & LOOKUP_RCU) {
53024+ error = -ECHILD;
53025+ goto out;
53026+ }
53027+#endif
53028+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53029+ error = -ENOENT;
53030+ goto out;
53031+ }
53032 audit_inode(name, nd->path.dentry, 0);
53033 if (open_flag & O_CREAT) {
53034 error = -EISDIR;
53035 goto out;
53036 }
53037+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53038+ error = -EACCES;
53039+ goto out;
53040+ }
53041 goto finish_open;
53042 case LAST_BIND:
53043 error = complete_walk(nd);
53044 if (error)
53045 return error;
53046+#ifdef CONFIG_GRKERNSEC
53047+ if (nd->flags & LOOKUP_RCU) {
53048+ error = -ECHILD;
53049+ goto out;
53050+ }
53051+#endif
53052+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53053+ error = -ENOENT;
53054+ goto out;
53055+ }
53056+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53057+ error = -EACCES;
53058+ goto out;
53059+ }
53060 audit_inode(name, dir, 0);
53061 goto finish_open;
53062 }
53063@@ -2768,7 +2860,7 @@ retry_lookup:
53064 */
53065 }
53066 mutex_lock(&dir->d_inode->i_mutex);
53067- error = lookup_open(nd, path, file, op, got_write, opened);
53068+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53069 mutex_unlock(&dir->d_inode->i_mutex);
53070
53071 if (error <= 0) {
53072@@ -2792,11 +2884,28 @@ retry_lookup:
53073 goto finish_open_created;
53074 }
53075
53076+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53077+ error = -ENOENT;
53078+ goto exit_dput;
53079+ }
53080+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53081+ error = -EACCES;
53082+ goto exit_dput;
53083+ }
53084+
53085 /*
53086 * create/update audit record if it already exists.
53087 */
53088- if (path->dentry->d_inode)
53089+ if (path->dentry->d_inode) {
53090+ /* only check if O_CREAT is specified, all other checks need to go
53091+ into may_open */
53092+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53093+ error = -EACCES;
53094+ goto exit_dput;
53095+ }
53096+
53097 audit_inode(name, path->dentry, 0);
53098+ }
53099
53100 /*
53101 * If atomic_open() acquired write access it is dropped now due to
53102@@ -2837,6 +2946,11 @@ finish_lookup:
53103 }
53104 }
53105 BUG_ON(inode != path->dentry->d_inode);
53106+ /* if we're resolving a symlink to another symlink */
53107+ if (link && gr_handle_symlink_owner(link, inode)) {
53108+ error = -EACCES;
53109+ goto out;
53110+ }
53111 return 1;
53112 }
53113
53114@@ -2846,7 +2960,6 @@ finish_lookup:
53115 save_parent.dentry = nd->path.dentry;
53116 save_parent.mnt = mntget(path->mnt);
53117 nd->path.dentry = path->dentry;
53118-
53119 }
53120 nd->inode = inode;
53121 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53122@@ -2855,6 +2968,22 @@ finish_lookup:
53123 path_put(&save_parent);
53124 return error;
53125 }
53126+
53127+#ifdef CONFIG_GRKERNSEC
53128+ if (nd->flags & LOOKUP_RCU) {
53129+ error = -ECHILD;
53130+ goto out;
53131+ }
53132+#endif
53133+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53134+ error = -ENOENT;
53135+ goto out;
53136+ }
53137+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53138+ error = -EACCES;
53139+ goto out;
53140+ }
53141+
53142 error = -EISDIR;
53143 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53144 goto out;
53145@@ -2953,7 +3082,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53146 if (unlikely(error))
53147 goto out;
53148
53149- error = do_last(nd, &path, file, op, &opened, pathname);
53150+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53151 while (unlikely(error > 0)) { /* trailing symlink */
53152 struct path link = path;
53153 void *cookie;
53154@@ -2971,7 +3100,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53155 error = follow_link(&link, nd, &cookie);
53156 if (unlikely(error))
53157 break;
53158- error = do_last(nd, &path, file, op, &opened, pathname);
53159+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53160 put_link(nd, &link, cookie);
53161 }
53162 out:
53163@@ -3071,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53164 goto unlock;
53165
53166 error = -EEXIST;
53167- if (dentry->d_inode)
53168+ if (dentry->d_inode) {
53169+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53170+ error = -ENOENT;
53171+ }
53172 goto fail;
53173+ }
53174 /*
53175 * Special case - lookup gave negative, but... we had foo/bar/
53176 * From the vfs_mknod() POV we just have a negative dentry -
53177@@ -3124,6 +3257,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53178 }
53179 EXPORT_SYMBOL(user_path_create);
53180
53181+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53182+{
53183+ struct filename *tmp = getname(pathname);
53184+ struct dentry *res;
53185+ if (IS_ERR(tmp))
53186+ return ERR_CAST(tmp);
53187+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53188+ if (IS_ERR(res))
53189+ putname(tmp);
53190+ else
53191+ *to = tmp;
53192+ return res;
53193+}
53194+
53195 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53196 {
53197 int error = may_create(dir, dentry);
53198@@ -3186,6 +3333,17 @@ retry:
53199
53200 if (!IS_POSIXACL(path.dentry->d_inode))
53201 mode &= ~current_umask();
53202+
53203+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53204+ error = -EPERM;
53205+ goto out;
53206+ }
53207+
53208+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53209+ error = -EACCES;
53210+ goto out;
53211+ }
53212+
53213 error = security_path_mknod(&path, dentry, mode, dev);
53214 if (error)
53215 goto out;
53216@@ -3202,6 +3360,8 @@ retry:
53217 break;
53218 }
53219 out:
53220+ if (!error)
53221+ gr_handle_create(dentry, path.mnt);
53222 done_path_create(&path, dentry);
53223 if (retry_estale(error, lookup_flags)) {
53224 lookup_flags |= LOOKUP_REVAL;
53225@@ -3254,9 +3414,16 @@ retry:
53226
53227 if (!IS_POSIXACL(path.dentry->d_inode))
53228 mode &= ~current_umask();
53229+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53230+ error = -EACCES;
53231+ goto out;
53232+ }
53233 error = security_path_mkdir(&path, dentry, mode);
53234 if (!error)
53235 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53236+ if (!error)
53237+ gr_handle_create(dentry, path.mnt);
53238+out:
53239 done_path_create(&path, dentry);
53240 if (retry_estale(error, lookup_flags)) {
53241 lookup_flags |= LOOKUP_REVAL;
53242@@ -3337,6 +3504,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53243 struct filename *name;
53244 struct dentry *dentry;
53245 struct nameidata nd;
53246+ ino_t saved_ino = 0;
53247+ dev_t saved_dev = 0;
53248 unsigned int lookup_flags = 0;
53249 retry:
53250 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53251@@ -3369,10 +3538,21 @@ retry:
53252 error = -ENOENT;
53253 goto exit3;
53254 }
53255+
53256+ saved_ino = dentry->d_inode->i_ino;
53257+ saved_dev = gr_get_dev_from_dentry(dentry);
53258+
53259+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53260+ error = -EACCES;
53261+ goto exit3;
53262+ }
53263+
53264 error = security_path_rmdir(&nd.path, dentry);
53265 if (error)
53266 goto exit3;
53267 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53268+ if (!error && (saved_dev || saved_ino))
53269+ gr_handle_delete(saved_ino, saved_dev);
53270 exit3:
53271 dput(dentry);
53272 exit2:
53273@@ -3438,6 +3618,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53274 struct dentry *dentry;
53275 struct nameidata nd;
53276 struct inode *inode = NULL;
53277+ ino_t saved_ino = 0;
53278+ dev_t saved_dev = 0;
53279 unsigned int lookup_flags = 0;
53280 retry:
53281 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53282@@ -3464,10 +3646,22 @@ retry:
53283 if (!inode)
53284 goto slashes;
53285 ihold(inode);
53286+
53287+ if (inode->i_nlink <= 1) {
53288+ saved_ino = inode->i_ino;
53289+ saved_dev = gr_get_dev_from_dentry(dentry);
53290+ }
53291+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53292+ error = -EACCES;
53293+ goto exit2;
53294+ }
53295+
53296 error = security_path_unlink(&nd.path, dentry);
53297 if (error)
53298 goto exit2;
53299 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53300+ if (!error && (saved_ino || saved_dev))
53301+ gr_handle_delete(saved_ino, saved_dev);
53302 exit2:
53303 dput(dentry);
53304 }
53305@@ -3545,9 +3739,17 @@ retry:
53306 if (IS_ERR(dentry))
53307 goto out_putname;
53308
53309+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53310+ error = -EACCES;
53311+ goto out;
53312+ }
53313+
53314 error = security_path_symlink(&path, dentry, from->name);
53315 if (!error)
53316 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
53317+ if (!error)
53318+ gr_handle_create(dentry, path.mnt);
53319+out:
53320 done_path_create(&path, dentry);
53321 if (retry_estale(error, lookup_flags)) {
53322 lookup_flags |= LOOKUP_REVAL;
53323@@ -3621,6 +3823,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53324 {
53325 struct dentry *new_dentry;
53326 struct path old_path, new_path;
53327+ struct filename *to = NULL;
53328 int how = 0;
53329 int error;
53330
53331@@ -3644,7 +3847,7 @@ retry:
53332 if (error)
53333 return error;
53334
53335- new_dentry = user_path_create(newdfd, newname, &new_path,
53336+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53337 (how & LOOKUP_REVAL));
53338 error = PTR_ERR(new_dentry);
53339 if (IS_ERR(new_dentry))
53340@@ -3656,11 +3859,28 @@ retry:
53341 error = may_linkat(&old_path);
53342 if (unlikely(error))
53343 goto out_dput;
53344+
53345+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
53346+ old_path.dentry->d_inode,
53347+ old_path.dentry->d_inode->i_mode, to)) {
53348+ error = -EACCES;
53349+ goto out_dput;
53350+ }
53351+
53352+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
53353+ old_path.dentry, old_path.mnt, to)) {
53354+ error = -EACCES;
53355+ goto out_dput;
53356+ }
53357+
53358 error = security_path_link(old_path.dentry, &new_path, new_dentry);
53359 if (error)
53360 goto out_dput;
53361 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
53362+ if (!error)
53363+ gr_handle_create(new_dentry, new_path.mnt);
53364 out_dput:
53365+ putname(to);
53366 done_path_create(&new_path, new_dentry);
53367 if (retry_estale(error, how)) {
53368 how |= LOOKUP_REVAL;
53369@@ -3906,12 +4126,21 @@ retry:
53370 if (new_dentry == trap)
53371 goto exit5;
53372
53373+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
53374+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
53375+ to);
53376+ if (error)
53377+ goto exit5;
53378+
53379 error = security_path_rename(&oldnd.path, old_dentry,
53380 &newnd.path, new_dentry);
53381 if (error)
53382 goto exit5;
53383 error = vfs_rename(old_dir->d_inode, old_dentry,
53384 new_dir->d_inode, new_dentry);
53385+ if (!error)
53386+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
53387+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
53388 exit5:
53389 dput(new_dentry);
53390 exit4:
53391@@ -3943,6 +4172,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
53392
53393 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
53394 {
53395+ char tmpbuf[64];
53396+ const char *newlink;
53397 int len;
53398
53399 len = PTR_ERR(link);
53400@@ -3952,7 +4183,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
53401 len = strlen(link);
53402 if (len > (unsigned) buflen)
53403 len = buflen;
53404- if (copy_to_user(buffer, link, len))
53405+
53406+ if (len < sizeof(tmpbuf)) {
53407+ memcpy(tmpbuf, link, len);
53408+ newlink = tmpbuf;
53409+ } else
53410+ newlink = link;
53411+
53412+ if (copy_to_user(buffer, newlink, len))
53413 len = -EFAULT;
53414 out:
53415 return len;
53416diff --git a/fs/namespace.c b/fs/namespace.c
53417index a51054f..f9b53e5 100644
53418--- a/fs/namespace.c
53419+++ b/fs/namespace.c
53420@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
53421 if (!(sb->s_flags & MS_RDONLY))
53422 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53423 up_write(&sb->s_umount);
53424+
53425+ gr_log_remount(mnt->mnt_devname, retval);
53426+
53427 return retval;
53428 }
53429
53430@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
53431 br_write_unlock(&vfsmount_lock);
53432 up_write(&namespace_sem);
53433 release_mounts(&umount_list);
53434+
53435+ gr_log_unmount(mnt->mnt_devname, retval);
53436+
53437 return retval;
53438 }
53439
53440@@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53441 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53442 MS_STRICTATIME);
53443
53444+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53445+ retval = -EPERM;
53446+ goto dput_out;
53447+ }
53448+
53449+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53450+ retval = -EPERM;
53451+ goto dput_out;
53452+ }
53453+
53454 if (flags & MS_REMOUNT)
53455 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53456 data_page);
53457@@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53458 dev_name, data_page);
53459 dput_out:
53460 path_put(&path);
53461+
53462+ gr_log_mount(dev_name, dir_name, retval);
53463+
53464 return retval;
53465 }
53466
53467@@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53468 if (error)
53469 goto out2;
53470
53471+ if (gr_handle_chroot_pivot()) {
53472+ error = -EPERM;
53473+ goto out2;
53474+ }
53475+
53476 get_fs_root(current->fs, &root);
53477 error = lock_mount(&old);
53478 if (error)
53479@@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53480 !nsown_capable(CAP_SYS_ADMIN))
53481 return -EPERM;
53482
53483- if (fs->users != 1)
53484+ if (atomic_read(&fs->users) != 1)
53485 return -EINVAL;
53486
53487 get_mnt_ns(mnt_ns);
53488diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53489index 59461c9..b17c57e 100644
53490--- a/fs/nfs/callback_xdr.c
53491+++ b/fs/nfs/callback_xdr.c
53492@@ -51,7 +51,7 @@ struct callback_op {
53493 callback_decode_arg_t decode_args;
53494 callback_encode_res_t encode_res;
53495 long res_maxsize;
53496-};
53497+} __do_const;
53498
53499 static struct callback_op callback_ops[];
53500
53501diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53502index ebeb94c..ff35337 100644
53503--- a/fs/nfs/inode.c
53504+++ b/fs/nfs/inode.c
53505@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53506 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53507 }
53508
53509-static atomic_long_t nfs_attr_generation_counter;
53510+static atomic_long_unchecked_t nfs_attr_generation_counter;
53511
53512 static unsigned long nfs_read_attr_generation_counter(void)
53513 {
53514- return atomic_long_read(&nfs_attr_generation_counter);
53515+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53516 }
53517
53518 unsigned long nfs_inc_attr_generation_counter(void)
53519 {
53520- return atomic_long_inc_return(&nfs_attr_generation_counter);
53521+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53522 }
53523
53524 void nfs_fattr_init(struct nfs_fattr *fattr)
53525diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53526index 9d1c5db..1e13db8 100644
53527--- a/fs/nfsd/nfs4proc.c
53528+++ b/fs/nfsd/nfs4proc.c
53529@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53530 nfsd4op_rsize op_rsize_bop;
53531 stateid_getter op_get_currentstateid;
53532 stateid_setter op_set_currentstateid;
53533-};
53534+} __do_const;
53535
53536 static struct nfsd4_operation nfsd4_ops[];
53537
53538diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53539index 0dc1158..ccf0338 100644
53540--- a/fs/nfsd/nfs4xdr.c
53541+++ b/fs/nfsd/nfs4xdr.c
53542@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53543
53544 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53545
53546-static nfsd4_dec nfsd4_dec_ops[] = {
53547+static const nfsd4_dec nfsd4_dec_ops[] = {
53548 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53549 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53550 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53551@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53552 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53553 };
53554
53555-static nfsd4_dec nfsd41_dec_ops[] = {
53556+static const nfsd4_dec nfsd41_dec_ops[] = {
53557 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53558 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53559 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53560@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53561 };
53562
53563 struct nfsd4_minorversion_ops {
53564- nfsd4_dec *decoders;
53565+ const nfsd4_dec *decoders;
53566 int nops;
53567 };
53568
53569diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53570index d586117..143d568 100644
53571--- a/fs/nfsd/vfs.c
53572+++ b/fs/nfsd/vfs.c
53573@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53574 } else {
53575 oldfs = get_fs();
53576 set_fs(KERNEL_DS);
53577- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53578+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53579 set_fs(oldfs);
53580 }
53581
53582@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53583
53584 /* Write the data. */
53585 oldfs = get_fs(); set_fs(KERNEL_DS);
53586- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53587+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53588 set_fs(oldfs);
53589 if (host_err < 0)
53590 goto out_nfserr;
53591@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53592 */
53593
53594 oldfs = get_fs(); set_fs(KERNEL_DS);
53595- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53596+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53597 set_fs(oldfs);
53598
53599 if (host_err < 0)
53600diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53601index fea6bd5..8ee9d81 100644
53602--- a/fs/nls/nls_base.c
53603+++ b/fs/nls/nls_base.c
53604@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53605
53606 int register_nls(struct nls_table * nls)
53607 {
53608- struct nls_table ** tmp = &tables;
53609+ struct nls_table *tmp = tables;
53610
53611 if (nls->next)
53612 return -EBUSY;
53613
53614 spin_lock(&nls_lock);
53615- while (*tmp) {
53616- if (nls == *tmp) {
53617+ while (tmp) {
53618+ if (nls == tmp) {
53619 spin_unlock(&nls_lock);
53620 return -EBUSY;
53621 }
53622- tmp = &(*tmp)->next;
53623+ tmp = tmp->next;
53624 }
53625- nls->next = tables;
53626+ pax_open_kernel();
53627+ *(struct nls_table **)&nls->next = tables;
53628+ pax_close_kernel();
53629 tables = nls;
53630 spin_unlock(&nls_lock);
53631 return 0;
53632@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53633
53634 int unregister_nls(struct nls_table * nls)
53635 {
53636- struct nls_table ** tmp = &tables;
53637+ struct nls_table * const * tmp = &tables;
53638
53639 spin_lock(&nls_lock);
53640 while (*tmp) {
53641 if (nls == *tmp) {
53642- *tmp = nls->next;
53643+ pax_open_kernel();
53644+ *(struct nls_table **)tmp = nls->next;
53645+ pax_close_kernel();
53646 spin_unlock(&nls_lock);
53647 return 0;
53648 }
53649diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53650index 7424929..35f6be5 100644
53651--- a/fs/nls/nls_euc-jp.c
53652+++ b/fs/nls/nls_euc-jp.c
53653@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53654 p_nls = load_nls("cp932");
53655
53656 if (p_nls) {
53657- table.charset2upper = p_nls->charset2upper;
53658- table.charset2lower = p_nls->charset2lower;
53659+ pax_open_kernel();
53660+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53661+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53662+ pax_close_kernel();
53663 return register_nls(&table);
53664 }
53665
53666diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53667index e7bc1d7..06bd4bb 100644
53668--- a/fs/nls/nls_koi8-ru.c
53669+++ b/fs/nls/nls_koi8-ru.c
53670@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53671 p_nls = load_nls("koi8-u");
53672
53673 if (p_nls) {
53674- table.charset2upper = p_nls->charset2upper;
53675- table.charset2lower = p_nls->charset2lower;
53676+ pax_open_kernel();
53677+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53678+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53679+ pax_close_kernel();
53680 return register_nls(&table);
53681 }
53682
53683diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53684index 9ff4a5e..deb1f0f 100644
53685--- a/fs/notify/fanotify/fanotify_user.c
53686+++ b/fs/notify/fanotify/fanotify_user.c
53687@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53688
53689 fd = fanotify_event_metadata.fd;
53690 ret = -EFAULT;
53691- if (copy_to_user(buf, &fanotify_event_metadata,
53692- fanotify_event_metadata.event_len))
53693+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53694+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53695 goto out_close_fd;
53696
53697 ret = prepare_for_access_response(group, event, fd);
53698diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53699index 7b51b05..5ea5ef6 100644
53700--- a/fs/notify/notification.c
53701+++ b/fs/notify/notification.c
53702@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53703 * get set to 0 so it will never get 'freed'
53704 */
53705 static struct fsnotify_event *q_overflow_event;
53706-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53707+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53708
53709 /**
53710 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53711@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53712 */
53713 u32 fsnotify_get_cookie(void)
53714 {
53715- return atomic_inc_return(&fsnotify_sync_cookie);
53716+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53717 }
53718 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53719
53720diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53721index 99e3610..02c1068 100644
53722--- a/fs/ntfs/dir.c
53723+++ b/fs/ntfs/dir.c
53724@@ -1329,7 +1329,7 @@ find_next_index_buffer:
53725 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53726 ~(s64)(ndir->itype.index.block_size - 1)));
53727 /* Bounds checks. */
53728- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53729+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53730 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53731 "inode 0x%lx or driver bug.", vdir->i_ino);
53732 goto err_out;
53733diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53734index 5b2d4f0..c6de396 100644
53735--- a/fs/ntfs/file.c
53736+++ b/fs/ntfs/file.c
53737@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53738 #endif /* NTFS_RW */
53739 };
53740
53741-const struct file_operations ntfs_empty_file_ops = {};
53742+const struct file_operations ntfs_empty_file_ops __read_only;
53743
53744-const struct inode_operations ntfs_empty_inode_ops = {};
53745+const struct inode_operations ntfs_empty_inode_ops __read_only;
53746diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53747index a9f78c7..ed8a381 100644
53748--- a/fs/ocfs2/localalloc.c
53749+++ b/fs/ocfs2/localalloc.c
53750@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53751 goto bail;
53752 }
53753
53754- atomic_inc(&osb->alloc_stats.moves);
53755+ atomic_inc_unchecked(&osb->alloc_stats.moves);
53756
53757 bail:
53758 if (handle)
53759diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53760index d355e6e..578d905 100644
53761--- a/fs/ocfs2/ocfs2.h
53762+++ b/fs/ocfs2/ocfs2.h
53763@@ -235,11 +235,11 @@ enum ocfs2_vol_state
53764
53765 struct ocfs2_alloc_stats
53766 {
53767- atomic_t moves;
53768- atomic_t local_data;
53769- atomic_t bitmap_data;
53770- atomic_t bg_allocs;
53771- atomic_t bg_extends;
53772+ atomic_unchecked_t moves;
53773+ atomic_unchecked_t local_data;
53774+ atomic_unchecked_t bitmap_data;
53775+ atomic_unchecked_t bg_allocs;
53776+ atomic_unchecked_t bg_extends;
53777 };
53778
53779 enum ocfs2_local_alloc_state
53780diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53781index b7e74b5..19c6536 100644
53782--- a/fs/ocfs2/suballoc.c
53783+++ b/fs/ocfs2/suballoc.c
53784@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53785 mlog_errno(status);
53786 goto bail;
53787 }
53788- atomic_inc(&osb->alloc_stats.bg_extends);
53789+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53790
53791 /* You should never ask for this much metadata */
53792 BUG_ON(bits_wanted >
53793@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53794 mlog_errno(status);
53795 goto bail;
53796 }
53797- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53798+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53799
53800 *suballoc_loc = res.sr_bg_blkno;
53801 *suballoc_bit_start = res.sr_bit_offset;
53802@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53803 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53804 res->sr_bits);
53805
53806- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53807+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53808
53809 BUG_ON(res->sr_bits != 1);
53810
53811@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53812 mlog_errno(status);
53813 goto bail;
53814 }
53815- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53816+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53817
53818 BUG_ON(res.sr_bits != 1);
53819
53820@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53821 cluster_start,
53822 num_clusters);
53823 if (!status)
53824- atomic_inc(&osb->alloc_stats.local_data);
53825+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
53826 } else {
53827 if (min_clusters > (osb->bitmap_cpg - 1)) {
53828 /* The only paths asking for contiguousness
53829@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53830 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53831 res.sr_bg_blkno,
53832 res.sr_bit_offset);
53833- atomic_inc(&osb->alloc_stats.bitmap_data);
53834+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53835 *num_clusters = res.sr_bits;
53836 }
53837 }
53838diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53839index 0e91ec2..f4b3fc6 100644
53840--- a/fs/ocfs2/super.c
53841+++ b/fs/ocfs2/super.c
53842@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53843 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53844 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53845 "Stats",
53846- atomic_read(&osb->alloc_stats.bitmap_data),
53847- atomic_read(&osb->alloc_stats.local_data),
53848- atomic_read(&osb->alloc_stats.bg_allocs),
53849- atomic_read(&osb->alloc_stats.moves),
53850- atomic_read(&osb->alloc_stats.bg_extends));
53851+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53852+ atomic_read_unchecked(&osb->alloc_stats.local_data),
53853+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53854+ atomic_read_unchecked(&osb->alloc_stats.moves),
53855+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53856
53857 out += snprintf(buf + out, len - out,
53858 "%10s => State: %u Descriptor: %llu Size: %u bits "
53859@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53860 spin_lock_init(&osb->osb_xattr_lock);
53861 ocfs2_init_steal_slots(osb);
53862
53863- atomic_set(&osb->alloc_stats.moves, 0);
53864- atomic_set(&osb->alloc_stats.local_data, 0);
53865- atomic_set(&osb->alloc_stats.bitmap_data, 0);
53866- atomic_set(&osb->alloc_stats.bg_allocs, 0);
53867- atomic_set(&osb->alloc_stats.bg_extends, 0);
53868+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53869+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53870+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53871+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53872+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53873
53874 /* Copy the blockcheck stats from the superblock probe */
53875 osb->osb_ecc_stats = *stats;
53876diff --git a/fs/open.c b/fs/open.c
53877index 9b33c0c..2ffcca2 100644
53878--- a/fs/open.c
53879+++ b/fs/open.c
53880@@ -31,6 +31,8 @@
53881 #include <linux/ima.h>
53882 #include <linux/dnotify.h>
53883
53884+#define CREATE_TRACE_POINTS
53885+#include <trace/events/fs.h>
53886 #include "internal.h"
53887
53888 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53889@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53890 error = locks_verify_truncate(inode, NULL, length);
53891 if (!error)
53892 error = security_path_truncate(path);
53893+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53894+ error = -EACCES;
53895 if (!error)
53896 error = do_truncate(path->dentry, length, 0, NULL);
53897
53898@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53899 error = locks_verify_truncate(inode, f.file, length);
53900 if (!error)
53901 error = security_path_truncate(&f.file->f_path);
53902+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53903+ error = -EACCES;
53904 if (!error)
53905 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53906 sb_end_write(inode->i_sb);
53907@@ -373,6 +379,9 @@ retry:
53908 if (__mnt_is_readonly(path.mnt))
53909 res = -EROFS;
53910
53911+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53912+ res = -EACCES;
53913+
53914 out_path_release:
53915 path_put(&path);
53916 if (retry_estale(res, lookup_flags)) {
53917@@ -404,6 +413,8 @@ retry:
53918 if (error)
53919 goto dput_and_out;
53920
53921+ gr_log_chdir(path.dentry, path.mnt);
53922+
53923 set_fs_pwd(current->fs, &path);
53924
53925 dput_and_out:
53926@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53927 goto out_putf;
53928
53929 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53930+
53931+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53932+ error = -EPERM;
53933+
53934+ if (!error)
53935+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53936+
53937 if (!error)
53938 set_fs_pwd(current->fs, &f.file->f_path);
53939 out_putf:
53940@@ -462,7 +480,13 @@ retry:
53941 if (error)
53942 goto dput_and_out;
53943
53944+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53945+ goto dput_and_out;
53946+
53947 set_fs_root(current->fs, &path);
53948+
53949+ gr_handle_chroot_chdir(&path);
53950+
53951 error = 0;
53952 dput_and_out:
53953 path_put(&path);
53954@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53955 if (error)
53956 return error;
53957 mutex_lock(&inode->i_mutex);
53958+
53959+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53960+ error = -EACCES;
53961+ goto out_unlock;
53962+ }
53963+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53964+ error = -EACCES;
53965+ goto out_unlock;
53966+ }
53967+
53968 error = security_path_chmod(path, mode);
53969 if (error)
53970 goto out_unlock;
53971@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53972 uid = make_kuid(current_user_ns(), user);
53973 gid = make_kgid(current_user_ns(), group);
53974
53975+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
53976+ return -EACCES;
53977+
53978 newattrs.ia_valid = ATTR_CTIME;
53979 if (user != (uid_t) -1) {
53980 if (!uid_valid(uid))
53981@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53982 } else {
53983 fsnotify_open(f);
53984 fd_install(fd, f);
53985+ trace_do_sys_open(tmp->name, flags, mode);
53986 }
53987 }
53988 putname(tmp);
53989diff --git a/fs/pipe.c b/fs/pipe.c
53990index 8e2e73f..1ef1048 100644
53991--- a/fs/pipe.c
53992+++ b/fs/pipe.c
53993@@ -438,9 +438,9 @@ redo:
53994 }
53995 if (bufs) /* More to do? */
53996 continue;
53997- if (!pipe->writers)
53998+ if (!atomic_read(&pipe->writers))
53999 break;
54000- if (!pipe->waiting_writers) {
54001+ if (!atomic_read(&pipe->waiting_writers)) {
54002 /* syscall merging: Usually we must not sleep
54003 * if O_NONBLOCK is set, or if we got some data.
54004 * But if a writer sleeps in kernel space, then
54005@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54006 mutex_lock(&inode->i_mutex);
54007 pipe = inode->i_pipe;
54008
54009- if (!pipe->readers) {
54010+ if (!atomic_read(&pipe->readers)) {
54011 send_sig(SIGPIPE, current, 0);
54012 ret = -EPIPE;
54013 goto out;
54014@@ -553,7 +553,7 @@ redo1:
54015 for (;;) {
54016 int bufs;
54017
54018- if (!pipe->readers) {
54019+ if (!atomic_read(&pipe->readers)) {
54020 send_sig(SIGPIPE, current, 0);
54021 if (!ret)
54022 ret = -EPIPE;
54023@@ -644,9 +644,9 @@ redo2:
54024 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54025 do_wakeup = 0;
54026 }
54027- pipe->waiting_writers++;
54028+ atomic_inc(&pipe->waiting_writers);
54029 pipe_wait(pipe);
54030- pipe->waiting_writers--;
54031+ atomic_dec(&pipe->waiting_writers);
54032 }
54033 out:
54034 mutex_unlock(&inode->i_mutex);
54035@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54036 mask = 0;
54037 if (filp->f_mode & FMODE_READ) {
54038 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54039- if (!pipe->writers && filp->f_version != pipe->w_counter)
54040+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54041 mask |= POLLHUP;
54042 }
54043
54044@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54045 * Most Unices do not set POLLERR for FIFOs but on Linux they
54046 * behave exactly like pipes for poll().
54047 */
54048- if (!pipe->readers)
54049+ if (!atomic_read(&pipe->readers))
54050 mask |= POLLERR;
54051 }
54052
54053@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54054
54055 mutex_lock(&inode->i_mutex);
54056 pipe = inode->i_pipe;
54057- pipe->readers -= decr;
54058- pipe->writers -= decw;
54059+ atomic_sub(decr, &pipe->readers);
54060+ atomic_sub(decw, &pipe->writers);
54061
54062- if (!pipe->readers && !pipe->writers) {
54063+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54064 free_pipe_info(inode);
54065 } else {
54066 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54067@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54068
54069 if (inode->i_pipe) {
54070 ret = 0;
54071- inode->i_pipe->readers++;
54072+ atomic_inc(&inode->i_pipe->readers);
54073 }
54074
54075 mutex_unlock(&inode->i_mutex);
54076@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54077
54078 if (inode->i_pipe) {
54079 ret = 0;
54080- inode->i_pipe->writers++;
54081+ atomic_inc(&inode->i_pipe->writers);
54082 }
54083
54084 mutex_unlock(&inode->i_mutex);
54085@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54086 if (inode->i_pipe) {
54087 ret = 0;
54088 if (filp->f_mode & FMODE_READ)
54089- inode->i_pipe->readers++;
54090+ atomic_inc(&inode->i_pipe->readers);
54091 if (filp->f_mode & FMODE_WRITE)
54092- inode->i_pipe->writers++;
54093+ atomic_inc(&inode->i_pipe->writers);
54094 }
54095
54096 mutex_unlock(&inode->i_mutex);
54097@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54098 inode->i_pipe = NULL;
54099 }
54100
54101-static struct vfsmount *pipe_mnt __read_mostly;
54102+struct vfsmount *pipe_mnt __read_mostly;
54103
54104 /*
54105 * pipefs_dname() is called from d_path().
54106@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54107 goto fail_iput;
54108 inode->i_pipe = pipe;
54109
54110- pipe->readers = pipe->writers = 1;
54111+ atomic_set(&pipe->readers, 1);
54112+ atomic_set(&pipe->writers, 1);
54113 inode->i_fop = &rdwr_pipefifo_fops;
54114
54115 /*
54116diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54117index 15af622..0e9f4467 100644
54118--- a/fs/proc/Kconfig
54119+++ b/fs/proc/Kconfig
54120@@ -30,12 +30,12 @@ config PROC_FS
54121
54122 config PROC_KCORE
54123 bool "/proc/kcore support" if !ARM
54124- depends on PROC_FS && MMU
54125+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54126
54127 config PROC_VMCORE
54128 bool "/proc/vmcore support"
54129- depends on PROC_FS && CRASH_DUMP
54130- default y
54131+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54132+ default n
54133 help
54134 Exports the dump image of crashed kernel in ELF format.
54135
54136@@ -59,8 +59,8 @@ config PROC_SYSCTL
54137 limited in memory.
54138
54139 config PROC_PAGE_MONITOR
54140- default y
54141- depends on PROC_FS && MMU
54142+ default n
54143+ depends on PROC_FS && MMU && !GRKERNSEC
54144 bool "Enable /proc page monitoring" if EXPERT
54145 help
54146 Various /proc files exist to monitor process memory utilization:
54147diff --git a/fs/proc/array.c b/fs/proc/array.c
54148index 6a91e6f..e54dbc14 100644
54149--- a/fs/proc/array.c
54150+++ b/fs/proc/array.c
54151@@ -60,6 +60,7 @@
54152 #include <linux/tty.h>
54153 #include <linux/string.h>
54154 #include <linux/mman.h>
54155+#include <linux/grsecurity.h>
54156 #include <linux/proc_fs.h>
54157 #include <linux/ioport.h>
54158 #include <linux/uaccess.h>
54159@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54160 seq_putc(m, '\n');
54161 }
54162
54163+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54164+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54165+{
54166+ if (p->mm)
54167+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54168+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54169+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54170+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54171+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54172+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54173+ else
54174+ seq_printf(m, "PaX:\t-----\n");
54175+}
54176+#endif
54177+
54178 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54179 struct pid *pid, struct task_struct *task)
54180 {
54181@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54182 task_cpus_allowed(m, task);
54183 cpuset_task_status_allowed(m, task);
54184 task_context_switch_counts(m, task);
54185+
54186+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54187+ task_pax(m, task);
54188+#endif
54189+
54190+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54191+ task_grsec_rbac(m, task);
54192+#endif
54193+
54194 return 0;
54195 }
54196
54197+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54198+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54199+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54200+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54201+#endif
54202+
54203 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54204 struct pid *pid, struct task_struct *task, int whole)
54205 {
54206@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54207 char tcomm[sizeof(task->comm)];
54208 unsigned long flags;
54209
54210+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54211+ if (current->exec_id != m->exec_id) {
54212+ gr_log_badprocpid("stat");
54213+ return 0;
54214+ }
54215+#endif
54216+
54217 state = *get_task_state(task);
54218 vsize = eip = esp = 0;
54219 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54220@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54221 gtime = task->gtime;
54222 }
54223
54224+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54225+ if (PAX_RAND_FLAGS(mm)) {
54226+ eip = 0;
54227+ esp = 0;
54228+ wchan = 0;
54229+ }
54230+#endif
54231+#ifdef CONFIG_GRKERNSEC_HIDESYM
54232+ wchan = 0;
54233+ eip =0;
54234+ esp =0;
54235+#endif
54236+
54237 /* scale priority and nice values from timeslices to -20..20 */
54238 /* to make it look like a "normal" Unix priority/nice value */
54239 priority = task_prio(task);
54240@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54241 seq_put_decimal_ull(m, ' ', vsize);
54242 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
54243 seq_put_decimal_ull(m, ' ', rsslim);
54244+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54245+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
54246+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
54247+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
54248+#else
54249 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
54250 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
54251 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
54252+#endif
54253 seq_put_decimal_ull(m, ' ', esp);
54254 seq_put_decimal_ull(m, ' ', eip);
54255 /* The signal information here is obsolete.
54256@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54257 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
54258 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
54259
54260- if (mm && permitted) {
54261+ if (mm && permitted
54262+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54263+ && !PAX_RAND_FLAGS(mm)
54264+#endif
54265+ ) {
54266 seq_put_decimal_ull(m, ' ', mm->start_data);
54267 seq_put_decimal_ull(m, ' ', mm->end_data);
54268 seq_put_decimal_ull(m, ' ', mm->start_brk);
54269@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54270 struct pid *pid, struct task_struct *task)
54271 {
54272 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
54273- struct mm_struct *mm = get_task_mm(task);
54274+ struct mm_struct *mm;
54275
54276+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54277+ if (current->exec_id != m->exec_id) {
54278+ gr_log_badprocpid("statm");
54279+ return 0;
54280+ }
54281+#endif
54282+ mm = get_task_mm(task);
54283 if (mm) {
54284 size = task_statm(mm, &shared, &text, &data, &resident);
54285 mmput(mm);
54286@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54287 return 0;
54288 }
54289
54290+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54291+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
54292+{
54293+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
54294+}
54295+#endif
54296+
54297 #ifdef CONFIG_CHECKPOINT_RESTORE
54298 static struct pid *
54299 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
54300diff --git a/fs/proc/base.c b/fs/proc/base.c
54301index 9b43ff77..ba3e990 100644
54302--- a/fs/proc/base.c
54303+++ b/fs/proc/base.c
54304@@ -111,6 +111,14 @@ struct pid_entry {
54305 union proc_op op;
54306 };
54307
54308+struct getdents_callback {
54309+ struct linux_dirent __user * current_dir;
54310+ struct linux_dirent __user * previous;
54311+ struct file * file;
54312+ int count;
54313+ int error;
54314+};
54315+
54316 #define NOD(NAME, MODE, IOP, FOP, OP) { \
54317 .name = (NAME), \
54318 .len = sizeof(NAME) - 1, \
54319@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
54320 if (!mm->arg_end)
54321 goto out_mm; /* Shh! No looking before we're done */
54322
54323+ if (gr_acl_handle_procpidmem(task))
54324+ goto out_mm;
54325+
54326 len = mm->arg_end - mm->arg_start;
54327
54328 if (len > PAGE_SIZE)
54329@@ -235,12 +246,28 @@ out:
54330 return res;
54331 }
54332
54333+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54334+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54335+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54336+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54337+#endif
54338+
54339 static int proc_pid_auxv(struct task_struct *task, char *buffer)
54340 {
54341 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
54342 int res = PTR_ERR(mm);
54343 if (mm && !IS_ERR(mm)) {
54344 unsigned int nwords = 0;
54345+
54346+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54347+ /* allow if we're currently ptracing this task */
54348+ if (PAX_RAND_FLAGS(mm) &&
54349+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
54350+ mmput(mm);
54351+ return 0;
54352+ }
54353+#endif
54354+
54355 do {
54356 nwords += 2;
54357 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
54358@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
54359 }
54360
54361
54362-#ifdef CONFIG_KALLSYMS
54363+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54364 /*
54365 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
54366 * Returns the resolved symbol. If that fails, simply return the address.
54367@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
54368 mutex_unlock(&task->signal->cred_guard_mutex);
54369 }
54370
54371-#ifdef CONFIG_STACKTRACE
54372+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54373
54374 #define MAX_STACK_TRACE_DEPTH 64
54375
54376@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
54377 return count;
54378 }
54379
54380-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54381+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54382 static int proc_pid_syscall(struct task_struct *task, char *buffer)
54383 {
54384 long nr;
54385@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
54386 /************************************************************************/
54387
54388 /* permission checks */
54389-static int proc_fd_access_allowed(struct inode *inode)
54390+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
54391 {
54392 struct task_struct *task;
54393 int allowed = 0;
54394@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
54395 */
54396 task = get_proc_task(inode);
54397 if (task) {
54398- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54399+ if (log)
54400+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54401+ else
54402+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54403 put_task_struct(task);
54404 }
54405 return allowed;
54406@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
54407 struct task_struct *task,
54408 int hide_pid_min)
54409 {
54410+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54411+ return false;
54412+
54413+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54414+ rcu_read_lock();
54415+ {
54416+ const struct cred *tmpcred = current_cred();
54417+ const struct cred *cred = __task_cred(task);
54418+
54419+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
54420+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54421+ || in_group_p(grsec_proc_gid)
54422+#endif
54423+ ) {
54424+ rcu_read_unlock();
54425+ return true;
54426+ }
54427+ }
54428+ rcu_read_unlock();
54429+
54430+ if (!pid->hide_pid)
54431+ return false;
54432+#endif
54433+
54434 if (pid->hide_pid < hide_pid_min)
54435 return true;
54436 if (in_group_p(pid->pid_gid))
54437 return true;
54438+
54439 return ptrace_may_access(task, PTRACE_MODE_READ);
54440 }
54441
54442@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54443 put_task_struct(task);
54444
54445 if (!has_perms) {
54446+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54447+ {
54448+#else
54449 if (pid->hide_pid == 2) {
54450+#endif
54451 /*
54452 * Let's make getdents(), stat(), and open()
54453 * consistent with each other. If a process
54454@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54455 if (!task)
54456 return -ESRCH;
54457
54458+ if (gr_acl_handle_procpidmem(task)) {
54459+ put_task_struct(task);
54460+ return -EPERM;
54461+ }
54462+
54463 mm = mm_access(task, mode);
54464 put_task_struct(task);
54465
54466@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54467
54468 file->private_data = mm;
54469
54470+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54471+ file->f_version = current->exec_id;
54472+#endif
54473+
54474 return 0;
54475 }
54476
54477@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54478 ssize_t copied;
54479 char *page;
54480
54481+#ifdef CONFIG_GRKERNSEC
54482+ if (write)
54483+ return -EPERM;
54484+#endif
54485+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54486+ if (file->f_version != current->exec_id) {
54487+ gr_log_badprocpid("mem");
54488+ return 0;
54489+ }
54490+#endif
54491+
54492 if (!mm)
54493 return 0;
54494
54495@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54496 if (!mm)
54497 return 0;
54498
54499+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54500+ if (file->f_version != current->exec_id) {
54501+ gr_log_badprocpid("environ");
54502+ return 0;
54503+ }
54504+#endif
54505+
54506 page = (char *)__get_free_page(GFP_TEMPORARY);
54507 if (!page)
54508 return -ENOMEM;
54509@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54510 int error = -EACCES;
54511
54512 /* Are we allowed to snoop on the tasks file descriptors? */
54513- if (!proc_fd_access_allowed(inode))
54514+ if (!proc_fd_access_allowed(inode, 0))
54515 goto out;
54516
54517 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54518@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54519 struct path path;
54520
54521 /* Are we allowed to snoop on the tasks file descriptors? */
54522- if (!proc_fd_access_allowed(inode))
54523- goto out;
54524+ /* logging this is needed for learning on chromium to work properly,
54525+ but we don't want to flood the logs from 'ps' which does a readlink
54526+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54527+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
54528+ */
54529+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54530+ if (!proc_fd_access_allowed(inode,0))
54531+ goto out;
54532+ } else {
54533+ if (!proc_fd_access_allowed(inode,1))
54534+ goto out;
54535+ }
54536
54537 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54538 if (error)
54539@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54540 rcu_read_lock();
54541 cred = __task_cred(task);
54542 inode->i_uid = cred->euid;
54543+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54544+ inode->i_gid = grsec_proc_gid;
54545+#else
54546 inode->i_gid = cred->egid;
54547+#endif
54548 rcu_read_unlock();
54549 }
54550 security_task_to_inode(task, inode);
54551@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54552 return -ENOENT;
54553 }
54554 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54555+#ifdef CONFIG_GRKERNSEC_PROC_USER
54556+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54557+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54558+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54559+#endif
54560 task_dumpable(task)) {
54561 cred = __task_cred(task);
54562 stat->uid = cred->euid;
54563+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54564+ stat->gid = grsec_proc_gid;
54565+#else
54566 stat->gid = cred->egid;
54567+#endif
54568 }
54569 }
54570 rcu_read_unlock();
54571@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54572
54573 if (task) {
54574 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54575+#ifdef CONFIG_GRKERNSEC_PROC_USER
54576+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54577+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54578+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54579+#endif
54580 task_dumpable(task)) {
54581 rcu_read_lock();
54582 cred = __task_cred(task);
54583 inode->i_uid = cred->euid;
54584+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54585+ inode->i_gid = grsec_proc_gid;
54586+#else
54587 inode->i_gid = cred->egid;
54588+#endif
54589 rcu_read_unlock();
54590 } else {
54591 inode->i_uid = GLOBAL_ROOT_UID;
54592@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54593 if (!task)
54594 goto out_no_task;
54595
54596+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54597+ goto out;
54598+
54599 /*
54600 * Yes, it does not scale. And it should not. Don't add
54601 * new entries into /proc/<tgid>/ without very good reasons.
54602@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54603 if (!task)
54604 goto out_no_task;
54605
54606+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54607+ goto out;
54608+
54609 ret = 0;
54610 i = filp->f_pos;
54611 switch (i) {
54612@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54613 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54614 #endif
54615 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54616-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54617+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54618 INF("syscall", S_IRUGO, proc_pid_syscall),
54619 #endif
54620 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54621@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54622 #ifdef CONFIG_SECURITY
54623 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54624 #endif
54625-#ifdef CONFIG_KALLSYMS
54626+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54627 INF("wchan", S_IRUGO, proc_pid_wchan),
54628 #endif
54629-#ifdef CONFIG_STACKTRACE
54630+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54631 ONE("stack", S_IRUGO, proc_pid_stack),
54632 #endif
54633 #ifdef CONFIG_SCHEDSTATS
54634@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54635 #ifdef CONFIG_HARDWALL
54636 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54637 #endif
54638+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54639+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54640+#endif
54641 #ifdef CONFIG_USER_NS
54642 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54643 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54644@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54645 if (!inode)
54646 goto out;
54647
54648+#ifdef CONFIG_GRKERNSEC_PROC_USER
54649+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54650+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54651+ inode->i_gid = grsec_proc_gid;
54652+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54653+#else
54654 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54655+#endif
54656 inode->i_op = &proc_tgid_base_inode_operations;
54657 inode->i_fop = &proc_tgid_base_operations;
54658 inode->i_flags|=S_IMMUTABLE;
54659@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54660 if (!task)
54661 goto out;
54662
54663+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54664+ goto out_put_task;
54665+
54666 result = proc_pid_instantiate(dir, dentry, task, NULL);
54667+out_put_task:
54668 put_task_struct(task);
54669 out:
54670 return result;
54671@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54672 static int fake_filldir(void *buf, const char *name, int namelen,
54673 loff_t offset, u64 ino, unsigned d_type)
54674 {
54675+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
54676+ __buf->error = -EINVAL;
54677 return 0;
54678 }
54679
54680@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54681 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54682 #endif
54683 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54684-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54685+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54686 INF("syscall", S_IRUGO, proc_pid_syscall),
54687 #endif
54688 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54689@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54690 #ifdef CONFIG_SECURITY
54691 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54692 #endif
54693-#ifdef CONFIG_KALLSYMS
54694+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54695 INF("wchan", S_IRUGO, proc_pid_wchan),
54696 #endif
54697-#ifdef CONFIG_STACKTRACE
54698+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54699 ONE("stack", S_IRUGO, proc_pid_stack),
54700 #endif
54701 #ifdef CONFIG_SCHEDSTATS
54702diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54703index 82676e3..5f8518a 100644
54704--- a/fs/proc/cmdline.c
54705+++ b/fs/proc/cmdline.c
54706@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54707
54708 static int __init proc_cmdline_init(void)
54709 {
54710+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54711+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54712+#else
54713 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54714+#endif
54715 return 0;
54716 }
54717 module_init(proc_cmdline_init);
54718diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54719index b143471..bb105e5 100644
54720--- a/fs/proc/devices.c
54721+++ b/fs/proc/devices.c
54722@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54723
54724 static int __init proc_devices_init(void)
54725 {
54726+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54727+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54728+#else
54729 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54730+#endif
54731 return 0;
54732 }
54733 module_init(proc_devices_init);
54734diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54735index d7a4a28..0201742 100644
54736--- a/fs/proc/fd.c
54737+++ b/fs/proc/fd.c
54738@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54739 if (!task)
54740 return -ENOENT;
54741
54742- files = get_files_struct(task);
54743+ if (!gr_acl_handle_procpidmem(task))
54744+ files = get_files_struct(task);
54745 put_task_struct(task);
54746
54747 if (files) {
54748@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54749 */
54750 int proc_fd_permission(struct inode *inode, int mask)
54751 {
54752+ struct task_struct *task;
54753 int rv = generic_permission(inode, mask);
54754- if (rv == 0)
54755- return 0;
54756+
54757 if (task_pid(current) == proc_pid(inode))
54758 rv = 0;
54759+
54760+ task = get_proc_task(inode);
54761+ if (task == NULL)
54762+ return rv;
54763+
54764+ if (gr_acl_handle_procpidmem(task))
54765+ rv = -EACCES;
54766+
54767+ put_task_struct(task);
54768+
54769 return rv;
54770 }
54771
54772diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54773index 439ae688..c21ac36 100644
54774--- a/fs/proc/inode.c
54775+++ b/fs/proc/inode.c
54776@@ -21,11 +21,17 @@
54777 #include <linux/seq_file.h>
54778 #include <linux/slab.h>
54779 #include <linux/mount.h>
54780+#include <linux/grsecurity.h>
54781
54782 #include <asm/uaccess.h>
54783
54784 #include "internal.h"
54785
54786+#ifdef CONFIG_PROC_SYSCTL
54787+extern const struct inode_operations proc_sys_inode_operations;
54788+extern const struct inode_operations proc_sys_dir_operations;
54789+#endif
54790+
54791 static void proc_evict_inode(struct inode *inode)
54792 {
54793 struct proc_dir_entry *de;
54794@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54795 ns = PROC_I(inode)->ns;
54796 if (ns_ops && ns)
54797 ns_ops->put(ns);
54798+
54799+#ifdef CONFIG_PROC_SYSCTL
54800+ if (inode->i_op == &proc_sys_inode_operations ||
54801+ inode->i_op == &proc_sys_dir_operations)
54802+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54803+#endif
54804+
54805 }
54806
54807 static struct kmem_cache * proc_inode_cachep;
54808@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54809 if (de->mode) {
54810 inode->i_mode = de->mode;
54811 inode->i_uid = de->uid;
54812+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54813+ inode->i_gid = grsec_proc_gid;
54814+#else
54815 inode->i_gid = de->gid;
54816+#endif
54817 }
54818 if (de->size)
54819 inode->i_size = de->size;
54820diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54821index 252544c..04395b9 100644
54822--- a/fs/proc/internal.h
54823+++ b/fs/proc/internal.h
54824@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54825 struct pid *pid, struct task_struct *task);
54826 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54827 struct pid *pid, struct task_struct *task);
54828+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54829+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54830+#endif
54831 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54832
54833 extern const struct file_operations proc_tid_children_operations;
54834diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54835index e96d4f1..8b116ed 100644
54836--- a/fs/proc/kcore.c
54837+++ b/fs/proc/kcore.c
54838@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54839 * the addresses in the elf_phdr on our list.
54840 */
54841 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54842- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54843+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54844+ if (tsz > buflen)
54845 tsz = buflen;
54846-
54847+
54848 while (buflen) {
54849 struct kcore_list *m;
54850
54851@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54852 kfree(elf_buf);
54853 } else {
54854 if (kern_addr_valid(start)) {
54855- unsigned long n;
54856+ char *elf_buf;
54857+ mm_segment_t oldfs;
54858
54859- n = copy_to_user(buffer, (char *)start, tsz);
54860- /*
54861- * We cannot distinguish between fault on source
54862- * and fault on destination. When this happens
54863- * we clear too and hope it will trigger the
54864- * EFAULT again.
54865- */
54866- if (n) {
54867- if (clear_user(buffer + tsz - n,
54868- n))
54869+ elf_buf = kmalloc(tsz, GFP_KERNEL);
54870+ if (!elf_buf)
54871+ return -ENOMEM;
54872+ oldfs = get_fs();
54873+ set_fs(KERNEL_DS);
54874+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54875+ set_fs(oldfs);
54876+ if (copy_to_user(buffer, elf_buf, tsz)) {
54877+ kfree(elf_buf);
54878 return -EFAULT;
54879+ }
54880 }
54881+ set_fs(oldfs);
54882+ kfree(elf_buf);
54883 } else {
54884 if (clear_user(buffer, tsz))
54885 return -EFAULT;
54886@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54887
54888 static int open_kcore(struct inode *inode, struct file *filp)
54889 {
54890+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54891+ return -EPERM;
54892+#endif
54893 if (!capable(CAP_SYS_RAWIO))
54894 return -EPERM;
54895 if (kcore_need_update)
54896diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54897index 80e4645..53e5fcf 100644
54898--- a/fs/proc/meminfo.c
54899+++ b/fs/proc/meminfo.c
54900@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54901 vmi.used >> 10,
54902 vmi.largest_chunk >> 10
54903 #ifdef CONFIG_MEMORY_FAILURE
54904- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54905+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54906 #endif
54907 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54908 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54909diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54910index b1822dd..df622cb 100644
54911--- a/fs/proc/nommu.c
54912+++ b/fs/proc/nommu.c
54913@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54914 if (len < 1)
54915 len = 1;
54916 seq_printf(m, "%*c", len, ' ');
54917- seq_path(m, &file->f_path, "");
54918+ seq_path(m, &file->f_path, "\n\\");
54919 }
54920
54921 seq_putc(m, '\n');
54922diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54923index fe72cd0..21b52ff 100644
54924--- a/fs/proc/proc_net.c
54925+++ b/fs/proc/proc_net.c
54926@@ -23,6 +23,7 @@
54927 #include <linux/nsproxy.h>
54928 #include <net/net_namespace.h>
54929 #include <linux/seq_file.h>
54930+#include <linux/grsecurity.h>
54931
54932 #include "internal.h"
54933
54934@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54935 struct task_struct *task;
54936 struct nsproxy *ns;
54937 struct net *net = NULL;
54938+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54939+ const struct cred *cred = current_cred();
54940+#endif
54941+
54942+#ifdef CONFIG_GRKERNSEC_PROC_USER
54943+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54944+ return net;
54945+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54946+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54947+ return net;
54948+#endif
54949
54950 rcu_read_lock();
54951 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54952diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54953index 1827d88..43b0279 100644
54954--- a/fs/proc/proc_sysctl.c
54955+++ b/fs/proc/proc_sysctl.c
54956@@ -12,11 +12,15 @@
54957 #include <linux/module.h>
54958 #include "internal.h"
54959
54960+extern int gr_handle_chroot_sysctl(const int op);
54961+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54962+ const int op);
54963+
54964 static const struct dentry_operations proc_sys_dentry_operations;
54965 static const struct file_operations proc_sys_file_operations;
54966-static const struct inode_operations proc_sys_inode_operations;
54967+const struct inode_operations proc_sys_inode_operations;
54968 static const struct file_operations proc_sys_dir_file_operations;
54969-static const struct inode_operations proc_sys_dir_operations;
54970+const struct inode_operations proc_sys_dir_operations;
54971
54972 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54973 {
54974@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54975
54976 err = NULL;
54977 d_set_d_op(dentry, &proc_sys_dentry_operations);
54978+
54979+ gr_handle_proc_create(dentry, inode);
54980+
54981 d_add(dentry, inode);
54982
54983 out:
54984@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54985 struct inode *inode = filp->f_path.dentry->d_inode;
54986 struct ctl_table_header *head = grab_header(inode);
54987 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54988+ int op = write ? MAY_WRITE : MAY_READ;
54989 ssize_t error;
54990 size_t res;
54991
54992@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54993 * and won't be until we finish.
54994 */
54995 error = -EPERM;
54996- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54997+ if (sysctl_perm(head, table, op))
54998 goto out;
54999
55000 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55001@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55002 if (!table->proc_handler)
55003 goto out;
55004
55005+#ifdef CONFIG_GRKERNSEC
55006+ error = -EPERM;
55007+ if (gr_handle_chroot_sysctl(op))
55008+ goto out;
55009+ dget(filp->f_path.dentry);
55010+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55011+ dput(filp->f_path.dentry);
55012+ goto out;
55013+ }
55014+ dput(filp->f_path.dentry);
55015+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55016+ goto out;
55017+ if (write && !capable(CAP_SYS_ADMIN))
55018+ goto out;
55019+#endif
55020+
55021 /* careful: calling conventions are nasty here */
55022 res = count;
55023 error = table->proc_handler(table, write, buf, &res, ppos);
55024@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55025 return -ENOMEM;
55026 } else {
55027 d_set_d_op(child, &proc_sys_dentry_operations);
55028+
55029+ gr_handle_proc_create(child, inode);
55030+
55031 d_add(child, inode);
55032 }
55033 } else {
55034@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55035 if ((*pos)++ < file->f_pos)
55036 return 0;
55037
55038+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55039+ return 0;
55040+
55041 if (unlikely(S_ISLNK(table->mode)))
55042 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55043 else
55044@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55045 if (IS_ERR(head))
55046 return PTR_ERR(head);
55047
55048+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55049+ return -ENOENT;
55050+
55051 generic_fillattr(inode, stat);
55052 if (table)
55053 stat->mode = (stat->mode & S_IFMT) | table->mode;
55054@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55055 .llseek = generic_file_llseek,
55056 };
55057
55058-static const struct inode_operations proc_sys_inode_operations = {
55059+const struct inode_operations proc_sys_inode_operations = {
55060 .permission = proc_sys_permission,
55061 .setattr = proc_sys_setattr,
55062 .getattr = proc_sys_getattr,
55063 };
55064
55065-static const struct inode_operations proc_sys_dir_operations = {
55066+const struct inode_operations proc_sys_dir_operations = {
55067 .lookup = proc_sys_lookup,
55068 .permission = proc_sys_permission,
55069 .setattr = proc_sys_setattr,
55070@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55071 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55072 const char *name, int namelen)
55073 {
55074- struct ctl_table *table;
55075+ ctl_table_no_const *table;
55076 struct ctl_dir *new;
55077 struct ctl_node *node;
55078 char *new_name;
55079@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55080 return NULL;
55081
55082 node = (struct ctl_node *)(new + 1);
55083- table = (struct ctl_table *)(node + 1);
55084+ table = (ctl_table_no_const *)(node + 1);
55085 new_name = (char *)(table + 2);
55086 memcpy(new_name, name, namelen);
55087 new_name[namelen] = '\0';
55088@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55089 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55090 struct ctl_table_root *link_root)
55091 {
55092- struct ctl_table *link_table, *entry, *link;
55093+ ctl_table_no_const *link_table, *link;
55094+ struct ctl_table *entry;
55095 struct ctl_table_header *links;
55096 struct ctl_node *node;
55097 char *link_name;
55098@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55099 return NULL;
55100
55101 node = (struct ctl_node *)(links + 1);
55102- link_table = (struct ctl_table *)(node + nr_entries);
55103+ link_table = (ctl_table_no_const *)(node + nr_entries);
55104 link_name = (char *)&link_table[nr_entries + 1];
55105
55106 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55107@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55108 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55109 struct ctl_table *table)
55110 {
55111- struct ctl_table *ctl_table_arg = NULL;
55112- struct ctl_table *entry, *files;
55113+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55114+ struct ctl_table *entry;
55115 int nr_files = 0;
55116 int nr_dirs = 0;
55117 int err = -ENOMEM;
55118@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55119 nr_files++;
55120 }
55121
55122- files = table;
55123 /* If there are mixed files and directories we need a new table */
55124 if (nr_dirs && nr_files) {
55125- struct ctl_table *new;
55126+ ctl_table_no_const *new;
55127 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55128 GFP_KERNEL);
55129 if (!files)
55130@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55131 /* Register everything except a directory full of subdirectories */
55132 if (nr_files || !nr_dirs) {
55133 struct ctl_table_header *header;
55134- header = __register_sysctl_table(set, path, files);
55135+ header = __register_sysctl_table(set, path, files ? files : table);
55136 if (!header) {
55137 kfree(ctl_table_arg);
55138 goto out;
55139diff --git a/fs/proc/root.c b/fs/proc/root.c
55140index c6e9fac..a740964 100644
55141--- a/fs/proc/root.c
55142+++ b/fs/proc/root.c
55143@@ -176,7 +176,15 @@ void __init proc_root_init(void)
55144 #ifdef CONFIG_PROC_DEVICETREE
55145 proc_device_tree_init();
55146 #endif
55147+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55148+#ifdef CONFIG_GRKERNSEC_PROC_USER
55149+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55150+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55151+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55152+#endif
55153+#else
55154 proc_mkdir("bus", NULL);
55155+#endif
55156 proc_sys_init();
55157 }
55158
55159diff --git a/fs/proc/self.c b/fs/proc/self.c
55160index aa5cc3b..c91a5d0 100644
55161--- a/fs/proc/self.c
55162+++ b/fs/proc/self.c
55163@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55164 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55165 void *cookie)
55166 {
55167- char *s = nd_get_link(nd);
55168+ const char *s = nd_get_link(nd);
55169 if (!IS_ERR(s))
55170 kfree(s);
55171 }
55172diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55173index ca5ce7f..02c1cf0 100644
55174--- a/fs/proc/task_mmu.c
55175+++ b/fs/proc/task_mmu.c
55176@@ -11,12 +11,19 @@
55177 #include <linux/rmap.h>
55178 #include <linux/swap.h>
55179 #include <linux/swapops.h>
55180+#include <linux/grsecurity.h>
55181
55182 #include <asm/elf.h>
55183 #include <asm/uaccess.h>
55184 #include <asm/tlbflush.h>
55185 #include "internal.h"
55186
55187+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55188+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55189+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55190+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55191+#endif
55192+
55193 void task_mem(struct seq_file *m, struct mm_struct *mm)
55194 {
55195 unsigned long data, text, lib, swap;
55196@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55197 "VmExe:\t%8lu kB\n"
55198 "VmLib:\t%8lu kB\n"
55199 "VmPTE:\t%8lu kB\n"
55200- "VmSwap:\t%8lu kB\n",
55201- hiwater_vm << (PAGE_SHIFT-10),
55202+ "VmSwap:\t%8lu kB\n"
55203+
55204+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55205+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
55206+#endif
55207+
55208+ ,hiwater_vm << (PAGE_SHIFT-10),
55209 total_vm << (PAGE_SHIFT-10),
55210 mm->locked_vm << (PAGE_SHIFT-10),
55211 mm->pinned_vm << (PAGE_SHIFT-10),
55212@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55213 data << (PAGE_SHIFT-10),
55214 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
55215 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
55216- swap << (PAGE_SHIFT-10));
55217+ swap << (PAGE_SHIFT-10)
55218+
55219+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55220+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55221+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
55222+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
55223+#else
55224+ , mm->context.user_cs_base
55225+ , mm->context.user_cs_limit
55226+#endif
55227+#endif
55228+
55229+ );
55230 }
55231
55232 unsigned long task_vsize(struct mm_struct *mm)
55233@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55234 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
55235 }
55236
55237- /* We don't show the stack guard page in /proc/maps */
55238+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55239+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
55240+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
55241+#else
55242 start = vma->vm_start;
55243- if (stack_guard_page_start(vma, start))
55244- start += PAGE_SIZE;
55245 end = vma->vm_end;
55246- if (stack_guard_page_end(vma, end))
55247- end -= PAGE_SIZE;
55248+#endif
55249
55250 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
55251 start,
55252@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55253 flags & VM_WRITE ? 'w' : '-',
55254 flags & VM_EXEC ? 'x' : '-',
55255 flags & VM_MAYSHARE ? 's' : 'p',
55256+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55257+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
55258+#else
55259 pgoff,
55260+#endif
55261 MAJOR(dev), MINOR(dev), ino, &len);
55262
55263 /*
55264@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55265 */
55266 if (file) {
55267 pad_len_spaces(m, len);
55268- seq_path(m, &file->f_path, "\n");
55269+ seq_path(m, &file->f_path, "\n\\");
55270 goto done;
55271 }
55272
55273@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55274 * Thread stack in /proc/PID/task/TID/maps or
55275 * the main process stack.
55276 */
55277- if (!is_pid || (vma->vm_start <= mm->start_stack &&
55278- vma->vm_end >= mm->start_stack)) {
55279+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
55280+ (vma->vm_start <= mm->start_stack &&
55281+ vma->vm_end >= mm->start_stack)) {
55282 name = "[stack]";
55283 } else {
55284 /* Thread stack in /proc/PID/maps */
55285@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
55286 struct proc_maps_private *priv = m->private;
55287 struct task_struct *task = priv->task;
55288
55289+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55290+ if (current->exec_id != m->exec_id) {
55291+ gr_log_badprocpid("maps");
55292+ return 0;
55293+ }
55294+#endif
55295+
55296 show_map_vma(m, vma, is_pid);
55297
55298 if (m->count < m->size) /* vma is copied successfully */
55299@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55300 .private = &mss,
55301 };
55302
55303+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55304+ if (current->exec_id != m->exec_id) {
55305+ gr_log_badprocpid("smaps");
55306+ return 0;
55307+ }
55308+#endif
55309 memset(&mss, 0, sizeof mss);
55310- mss.vma = vma;
55311- /* mmap_sem is held in m_start */
55312- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55313- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55314-
55315+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55316+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
55317+#endif
55318+ mss.vma = vma;
55319+ /* mmap_sem is held in m_start */
55320+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55321+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55323+ }
55324+#endif
55325 show_map_vma(m, vma, is_pid);
55326
55327 seq_printf(m,
55328@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55329 "KernelPageSize: %8lu kB\n"
55330 "MMUPageSize: %8lu kB\n"
55331 "Locked: %8lu kB\n",
55332+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55333+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
55334+#else
55335 (vma->vm_end - vma->vm_start) >> 10,
55336+#endif
55337 mss.resident >> 10,
55338 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
55339 mss.shared_clean >> 10,
55340@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55341 int n;
55342 char buffer[50];
55343
55344+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55345+ if (current->exec_id != m->exec_id) {
55346+ gr_log_badprocpid("numa_maps");
55347+ return 0;
55348+ }
55349+#endif
55350+
55351 if (!mm)
55352 return 0;
55353
55354@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55355 mpol_to_str(buffer, sizeof(buffer), pol);
55356 mpol_cond_put(pol);
55357
55358+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55359+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
55360+#else
55361 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
55362+#endif
55363
55364 if (file) {
55365 seq_printf(m, " file=");
55366- seq_path(m, &file->f_path, "\n\t= ");
55367+ seq_path(m, &file->f_path, "\n\t\\= ");
55368 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
55369 seq_printf(m, " heap");
55370 } else {
55371diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
55372index 1ccfa53..0848f95 100644
55373--- a/fs/proc/task_nommu.c
55374+++ b/fs/proc/task_nommu.c
55375@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55376 else
55377 bytes += kobjsize(mm);
55378
55379- if (current->fs && current->fs->users > 1)
55380+ if (current->fs && atomic_read(&current->fs->users) > 1)
55381 sbytes += kobjsize(current->fs);
55382 else
55383 bytes += kobjsize(current->fs);
55384@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
55385
55386 if (file) {
55387 pad_len_spaces(m, len);
55388- seq_path(m, &file->f_path, "");
55389+ seq_path(m, &file->f_path, "\n\\");
55390 } else if (mm) {
55391 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
55392
55393diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
55394index b00fcc9..e0c6381 100644
55395--- a/fs/qnx6/qnx6.h
55396+++ b/fs/qnx6/qnx6.h
55397@@ -74,7 +74,7 @@ enum {
55398 BYTESEX_BE,
55399 };
55400
55401-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55402+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55403 {
55404 if (sbi->s_bytesex == BYTESEX_LE)
55405 return le64_to_cpu((__force __le64)n);
55406@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
55407 return (__force __fs64)cpu_to_be64(n);
55408 }
55409
55410-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55411+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55412 {
55413 if (sbi->s_bytesex == BYTESEX_LE)
55414 return le32_to_cpu((__force __le32)n);
55415diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
55416index 16e8abb..2dcf914 100644
55417--- a/fs/quota/netlink.c
55418+++ b/fs/quota/netlink.c
55419@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
55420 void quota_send_warning(struct kqid qid, dev_t dev,
55421 const char warntype)
55422 {
55423- static atomic_t seq;
55424+ static atomic_unchecked_t seq;
55425 struct sk_buff *skb;
55426 void *msg_head;
55427 int ret;
55428@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
55429 "VFS: Not enough memory to send quota warning.\n");
55430 return;
55431 }
55432- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
55433+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
55434 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
55435 if (!msg_head) {
55436 printk(KERN_ERR
55437diff --git a/fs/readdir.c b/fs/readdir.c
55438index 5e69ef5..e5d9099 100644
55439--- a/fs/readdir.c
55440+++ b/fs/readdir.c
55441@@ -17,6 +17,7 @@
55442 #include <linux/security.h>
55443 #include <linux/syscalls.h>
55444 #include <linux/unistd.h>
55445+#include <linux/namei.h>
55446
55447 #include <asm/uaccess.h>
55448
55449@@ -67,6 +68,7 @@ struct old_linux_dirent {
55450
55451 struct readdir_callback {
55452 struct old_linux_dirent __user * dirent;
55453+ struct file * file;
55454 int result;
55455 };
55456
55457@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55458 buf->result = -EOVERFLOW;
55459 return -EOVERFLOW;
55460 }
55461+
55462+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55463+ return 0;
55464+
55465 buf->result++;
55466 dirent = buf->dirent;
55467 if (!access_ok(VERIFY_WRITE, dirent,
55468@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55469
55470 buf.result = 0;
55471 buf.dirent = dirent;
55472+ buf.file = f.file;
55473
55474 error = vfs_readdir(f.file, fillonedir, &buf);
55475 if (buf.result)
55476@@ -139,6 +146,7 @@ struct linux_dirent {
55477 struct getdents_callback {
55478 struct linux_dirent __user * current_dir;
55479 struct linux_dirent __user * previous;
55480+ struct file * file;
55481 int count;
55482 int error;
55483 };
55484@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55485 buf->error = -EOVERFLOW;
55486 return -EOVERFLOW;
55487 }
55488+
55489+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55490+ return 0;
55491+
55492 dirent = buf->previous;
55493 if (dirent) {
55494 if (__put_user(offset, &dirent->d_off))
55495@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55496 buf.previous = NULL;
55497 buf.count = count;
55498 buf.error = 0;
55499+ buf.file = f.file;
55500
55501 error = vfs_readdir(f.file, filldir, &buf);
55502 if (error >= 0)
55503@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55504 struct getdents_callback64 {
55505 struct linux_dirent64 __user * current_dir;
55506 struct linux_dirent64 __user * previous;
55507+ struct file *file;
55508 int count;
55509 int error;
55510 };
55511@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55512 buf->error = -EINVAL; /* only used if we fail.. */
55513 if (reclen > buf->count)
55514 return -EINVAL;
55515+
55516+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55517+ return 0;
55518+
55519 dirent = buf->previous;
55520 if (dirent) {
55521 if (__put_user(offset, &dirent->d_off))
55522@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55523
55524 buf.current_dir = dirent;
55525 buf.previous = NULL;
55526+ buf.file = f.file;
55527 buf.count = count;
55528 buf.error = 0;
55529
55530@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55531 error = buf.error;
55532 lastdirent = buf.previous;
55533 if (lastdirent) {
55534- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55535+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55536 if (__put_user(d_off, &lastdirent->d_off))
55537 error = -EFAULT;
55538 else
55539diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55540index 2b7882b..1c5ef48 100644
55541--- a/fs/reiserfs/do_balan.c
55542+++ b/fs/reiserfs/do_balan.c
55543@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55544 return;
55545 }
55546
55547- atomic_inc(&(fs_generation(tb->tb_sb)));
55548+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55549 do_balance_starts(tb);
55550
55551 /* balance leaf returns 0 except if combining L R and S into
55552diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55553index e60e870..f40ac16 100644
55554--- a/fs/reiserfs/procfs.c
55555+++ b/fs/reiserfs/procfs.c
55556@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55557 "SMALL_TAILS " : "NO_TAILS ",
55558 replay_only(sb) ? "REPLAY_ONLY " : "",
55559 convert_reiserfs(sb) ? "CONV " : "",
55560- atomic_read(&r->s_generation_counter),
55561+ atomic_read_unchecked(&r->s_generation_counter),
55562 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55563 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55564 SF(s_good_search_by_key_reada), SF(s_bmaps),
55565diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55566index 157e474..65a6114 100644
55567--- a/fs/reiserfs/reiserfs.h
55568+++ b/fs/reiserfs/reiserfs.h
55569@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55570 /* Comment? -Hans */
55571 wait_queue_head_t s_wait;
55572 /* To be obsoleted soon by per buffer seals.. -Hans */
55573- atomic_t s_generation_counter; // increased by one every time the
55574+ atomic_unchecked_t s_generation_counter; // increased by one every time the
55575 // tree gets re-balanced
55576 unsigned long s_properties; /* File system properties. Currently holds
55577 on-disk FS format */
55578@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55579 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55580
55581 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55582-#define get_generation(s) atomic_read (&fs_generation(s))
55583+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55584 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55585 #define __fs_changed(gen,s) (gen != get_generation (s))
55586 #define fs_changed(gen,s) \
55587diff --git a/fs/select.c b/fs/select.c
55588index 2ef72d9..f213b17 100644
55589--- a/fs/select.c
55590+++ b/fs/select.c
55591@@ -20,6 +20,7 @@
55592 #include <linux/export.h>
55593 #include <linux/slab.h>
55594 #include <linux/poll.h>
55595+#include <linux/security.h>
55596 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55597 #include <linux/file.h>
55598 #include <linux/fdtable.h>
55599@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55600 struct poll_list *walk = head;
55601 unsigned long todo = nfds;
55602
55603+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55604 if (nfds > rlimit(RLIMIT_NOFILE))
55605 return -EINVAL;
55606
55607diff --git a/fs/seq_file.c b/fs/seq_file.c
55608index f2bc3df..239d4f6 100644
55609--- a/fs/seq_file.c
55610+++ b/fs/seq_file.c
55611@@ -10,6 +10,7 @@
55612 #include <linux/seq_file.h>
55613 #include <linux/slab.h>
55614 #include <linux/cred.h>
55615+#include <linux/sched.h>
55616
55617 #include <asm/uaccess.h>
55618 #include <asm/page.h>
55619@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55620 #ifdef CONFIG_USER_NS
55621 p->user_ns = file->f_cred->user_ns;
55622 #endif
55623+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55624+ p->exec_id = current->exec_id;
55625+#endif
55626
55627 /*
55628 * Wrappers around seq_open(e.g. swaps_open) need to be
55629@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55630 return 0;
55631 }
55632 if (!m->buf) {
55633- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55634+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55635 if (!m->buf)
55636 return -ENOMEM;
55637 }
55638@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55639 Eoverflow:
55640 m->op->stop(m, p);
55641 kfree(m->buf);
55642- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55643+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55644 return !m->buf ? -ENOMEM : -EAGAIN;
55645 }
55646
55647@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55648
55649 /* grab buffer if we didn't have one */
55650 if (!m->buf) {
55651- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55652+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55653 if (!m->buf)
55654 goto Enomem;
55655 }
55656@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55657 goto Fill;
55658 m->op->stop(m, p);
55659 kfree(m->buf);
55660- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55661+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55662 if (!m->buf)
55663 goto Enomem;
55664 m->count = 0;
55665@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55666 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55667 void *data)
55668 {
55669- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55670+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55671 int res = -ENOMEM;
55672
55673 if (op) {
55674diff --git a/fs/splice.c b/fs/splice.c
55675index 6909d89..5b2e8f9 100644
55676--- a/fs/splice.c
55677+++ b/fs/splice.c
55678@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55679 pipe_lock(pipe);
55680
55681 for (;;) {
55682- if (!pipe->readers) {
55683+ if (!atomic_read(&pipe->readers)) {
55684 send_sig(SIGPIPE, current, 0);
55685 if (!ret)
55686 ret = -EPIPE;
55687@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55688 do_wakeup = 0;
55689 }
55690
55691- pipe->waiting_writers++;
55692+ atomic_inc(&pipe->waiting_writers);
55693 pipe_wait(pipe);
55694- pipe->waiting_writers--;
55695+ atomic_dec(&pipe->waiting_writers);
55696 }
55697
55698 pipe_unlock(pipe);
55699@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55700 old_fs = get_fs();
55701 set_fs(get_ds());
55702 /* The cast to a user pointer is valid due to the set_fs() */
55703- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55704+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55705 set_fs(old_fs);
55706
55707 return res;
55708@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55709 old_fs = get_fs();
55710 set_fs(get_ds());
55711 /* The cast to a user pointer is valid due to the set_fs() */
55712- res = vfs_write(file, (const char __user *)buf, count, &pos);
55713+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55714 set_fs(old_fs);
55715
55716 return res;
55717@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55718 goto err;
55719
55720 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55721- vec[i].iov_base = (void __user *) page_address(page);
55722+ vec[i].iov_base = (void __force_user *) page_address(page);
55723 vec[i].iov_len = this_len;
55724 spd.pages[i] = page;
55725 spd.nr_pages++;
55726@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55727 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55728 {
55729 while (!pipe->nrbufs) {
55730- if (!pipe->writers)
55731+ if (!atomic_read(&pipe->writers))
55732 return 0;
55733
55734- if (!pipe->waiting_writers && sd->num_spliced)
55735+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55736 return 0;
55737
55738 if (sd->flags & SPLICE_F_NONBLOCK)
55739@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55740 * out of the pipe right after the splice_to_pipe(). So set
55741 * PIPE_READERS appropriately.
55742 */
55743- pipe->readers = 1;
55744+ atomic_set(&pipe->readers, 1);
55745
55746 current->splice_pipe = pipe;
55747 }
55748@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55749 ret = -ERESTARTSYS;
55750 break;
55751 }
55752- if (!pipe->writers)
55753+ if (!atomic_read(&pipe->writers))
55754 break;
55755- if (!pipe->waiting_writers) {
55756+ if (!atomic_read(&pipe->waiting_writers)) {
55757 if (flags & SPLICE_F_NONBLOCK) {
55758 ret = -EAGAIN;
55759 break;
55760@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55761 pipe_lock(pipe);
55762
55763 while (pipe->nrbufs >= pipe->buffers) {
55764- if (!pipe->readers) {
55765+ if (!atomic_read(&pipe->readers)) {
55766 send_sig(SIGPIPE, current, 0);
55767 ret = -EPIPE;
55768 break;
55769@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55770 ret = -ERESTARTSYS;
55771 break;
55772 }
55773- pipe->waiting_writers++;
55774+ atomic_inc(&pipe->waiting_writers);
55775 pipe_wait(pipe);
55776- pipe->waiting_writers--;
55777+ atomic_dec(&pipe->waiting_writers);
55778 }
55779
55780 pipe_unlock(pipe);
55781@@ -1823,14 +1823,14 @@ retry:
55782 pipe_double_lock(ipipe, opipe);
55783
55784 do {
55785- if (!opipe->readers) {
55786+ if (!atomic_read(&opipe->readers)) {
55787 send_sig(SIGPIPE, current, 0);
55788 if (!ret)
55789 ret = -EPIPE;
55790 break;
55791 }
55792
55793- if (!ipipe->nrbufs && !ipipe->writers)
55794+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55795 break;
55796
55797 /*
55798@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55799 pipe_double_lock(ipipe, opipe);
55800
55801 do {
55802- if (!opipe->readers) {
55803+ if (!atomic_read(&opipe->readers)) {
55804 send_sig(SIGPIPE, current, 0);
55805 if (!ret)
55806 ret = -EPIPE;
55807@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55808 * return EAGAIN if we have the potential of some data in the
55809 * future, otherwise just return 0
55810 */
55811- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55812+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55813 ret = -EAGAIN;
55814
55815 pipe_unlock(ipipe);
55816diff --git a/fs/stat.c b/fs/stat.c
55817index 14f4545..9b7f55b 100644
55818--- a/fs/stat.c
55819+++ b/fs/stat.c
55820@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55821 stat->gid = inode->i_gid;
55822 stat->rdev = inode->i_rdev;
55823 stat->size = i_size_read(inode);
55824- stat->atime = inode->i_atime;
55825- stat->mtime = inode->i_mtime;
55826+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55827+ stat->atime = inode->i_ctime;
55828+ stat->mtime = inode->i_ctime;
55829+ } else {
55830+ stat->atime = inode->i_atime;
55831+ stat->mtime = inode->i_mtime;
55832+ }
55833 stat->ctime = inode->i_ctime;
55834 stat->blksize = (1 << inode->i_blkbits);
55835 stat->blocks = inode->i_blocks;
55836@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55837 if (retval)
55838 return retval;
55839
55840- if (inode->i_op->getattr)
55841- return inode->i_op->getattr(mnt, dentry, stat);
55842+ if (inode->i_op->getattr) {
55843+ retval = inode->i_op->getattr(mnt, dentry, stat);
55844+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55845+ stat->atime = stat->ctime;
55846+ stat->mtime = stat->ctime;
55847+ }
55848+ return retval;
55849+ }
55850
55851 generic_fillattr(inode, stat);
55852 return 0;
55853diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55854index 2fbdff6..5530a61 100644
55855--- a/fs/sysfs/dir.c
55856+++ b/fs/sysfs/dir.c
55857@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55858 struct sysfs_dirent *sd;
55859 int rc;
55860
55861+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55862+ const char *parent_name = parent_sd->s_name;
55863+
55864+ mode = S_IFDIR | S_IRWXU;
55865+
55866+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55867+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55868+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55869+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55870+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55871+#endif
55872+
55873 /* allocate */
55874 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55875 if (!sd)
55876diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55877index 602f56d..6853db8 100644
55878--- a/fs/sysfs/file.c
55879+++ b/fs/sysfs/file.c
55880@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55881
55882 struct sysfs_open_dirent {
55883 atomic_t refcnt;
55884- atomic_t event;
55885+ atomic_unchecked_t event;
55886 wait_queue_head_t poll;
55887 struct list_head buffers; /* goes through sysfs_buffer.list */
55888 };
55889@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55890 if (!sysfs_get_active(attr_sd))
55891 return -ENODEV;
55892
55893- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55894+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55895 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55896
55897 sysfs_put_active(attr_sd);
55898@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55899 return -ENOMEM;
55900
55901 atomic_set(&new_od->refcnt, 0);
55902- atomic_set(&new_od->event, 1);
55903+ atomic_set_unchecked(&new_od->event, 1);
55904 init_waitqueue_head(&new_od->poll);
55905 INIT_LIST_HEAD(&new_od->buffers);
55906 goto retry;
55907@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55908
55909 sysfs_put_active(attr_sd);
55910
55911- if (buffer->event != atomic_read(&od->event))
55912+ if (buffer->event != atomic_read_unchecked(&od->event))
55913 goto trigger;
55914
55915 return DEFAULT_POLLMASK;
55916@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55917
55918 od = sd->s_attr.open;
55919 if (od) {
55920- atomic_inc(&od->event);
55921+ atomic_inc_unchecked(&od->event);
55922 wake_up_interruptible(&od->poll);
55923 }
55924
55925diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55926index 3c9eb56..9dea5be 100644
55927--- a/fs/sysfs/symlink.c
55928+++ b/fs/sysfs/symlink.c
55929@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55930
55931 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55932 {
55933- char *page = nd_get_link(nd);
55934+ const char *page = nd_get_link(nd);
55935 if (!IS_ERR(page))
55936 free_page((unsigned long)page);
55937 }
55938diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
55939index 69d4889..a810bd4 100644
55940--- a/fs/sysv/sysv.h
55941+++ b/fs/sysv/sysv.h
55942@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
55943 #endif
55944 }
55945
55946-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
55947+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
55948 {
55949 if (sbi->s_bytesex == BYTESEX_PDP)
55950 return PDP_swab((__force __u32)n);
55951diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
55952index e18b988..f1d4ad0f 100644
55953--- a/fs/ubifs/io.c
55954+++ b/fs/ubifs/io.c
55955@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
55956 return err;
55957 }
55958
55959-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
55960+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
55961 {
55962 int err;
55963
55964diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55965index c175b4d..8f36a16 100644
55966--- a/fs/udf/misc.c
55967+++ b/fs/udf/misc.c
55968@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55969
55970 u8 udf_tag_checksum(const struct tag *t)
55971 {
55972- u8 *data = (u8 *)t;
55973+ const u8 *data = (const u8 *)t;
55974 u8 checksum = 0;
55975 int i;
55976 for (i = 0; i < sizeof(struct tag); ++i)
55977diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
55978index 8d974c4..b82f6ec 100644
55979--- a/fs/ufs/swab.h
55980+++ b/fs/ufs/swab.h
55981@@ -22,7 +22,7 @@ enum {
55982 BYTESEX_BE
55983 };
55984
55985-static inline u64
55986+static inline u64 __intentional_overflow(-1)
55987 fs64_to_cpu(struct super_block *sbp, __fs64 n)
55988 {
55989 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
55990@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
55991 return (__force __fs64)cpu_to_be64(n);
55992 }
55993
55994-static inline u32
55995+static inline u32 __intentional_overflow(-1)
55996 fs32_to_cpu(struct super_block *sbp, __fs32 n)
55997 {
55998 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
55999diff --git a/fs/utimes.c b/fs/utimes.c
56000index f4fb7ec..3fe03c0 100644
56001--- a/fs/utimes.c
56002+++ b/fs/utimes.c
56003@@ -1,6 +1,7 @@
56004 #include <linux/compiler.h>
56005 #include <linux/file.h>
56006 #include <linux/fs.h>
56007+#include <linux/security.h>
56008 #include <linux/linkage.h>
56009 #include <linux/mount.h>
56010 #include <linux/namei.h>
56011@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56012 goto mnt_drop_write_and_out;
56013 }
56014 }
56015+
56016+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56017+ error = -EACCES;
56018+ goto mnt_drop_write_and_out;
56019+ }
56020+
56021 mutex_lock(&inode->i_mutex);
56022 error = notify_change(path->dentry, &newattrs);
56023 mutex_unlock(&inode->i_mutex);
56024diff --git a/fs/xattr.c b/fs/xattr.c
56025index 3377dff..4feded6 100644
56026--- a/fs/xattr.c
56027+++ b/fs/xattr.c
56028@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56029 * Extended attribute SET operations
56030 */
56031 static long
56032-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56033+setxattr(struct path *path, const char __user *name, const void __user *value,
56034 size_t size, int flags)
56035 {
56036 int error;
56037@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56038 posix_acl_fix_xattr_from_user(kvalue, size);
56039 }
56040
56041- error = vfs_setxattr(d, kname, kvalue, size, flags);
56042+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56043+ error = -EACCES;
56044+ goto out;
56045+ }
56046+
56047+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56048 out:
56049 if (vvalue)
56050 vfree(vvalue);
56051@@ -377,7 +382,7 @@ retry:
56052 return error;
56053 error = mnt_want_write(path.mnt);
56054 if (!error) {
56055- error = setxattr(path.dentry, name, value, size, flags);
56056+ error = setxattr(&path, name, value, size, flags);
56057 mnt_drop_write(path.mnt);
56058 }
56059 path_put(&path);
56060@@ -401,7 +406,7 @@ retry:
56061 return error;
56062 error = mnt_want_write(path.mnt);
56063 if (!error) {
56064- error = setxattr(path.dentry, name, value, size, flags);
56065+ error = setxattr(&path, name, value, size, flags);
56066 mnt_drop_write(path.mnt);
56067 }
56068 path_put(&path);
56069@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56070 const void __user *,value, size_t, size, int, flags)
56071 {
56072 struct fd f = fdget(fd);
56073- struct dentry *dentry;
56074 int error = -EBADF;
56075
56076 if (!f.file)
56077 return error;
56078- dentry = f.file->f_path.dentry;
56079- audit_inode(NULL, dentry, 0);
56080+ audit_inode(NULL, f.file->f_path.dentry, 0);
56081 error = mnt_want_write_file(f.file);
56082 if (!error) {
56083- error = setxattr(dentry, name, value, size, flags);
56084+ error = setxattr(&f.file->f_path, name, value, size, flags);
56085 mnt_drop_write_file(f.file);
56086 }
56087 fdput(f);
56088diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56089index 9fbea87..6b19972 100644
56090--- a/fs/xattr_acl.c
56091+++ b/fs/xattr_acl.c
56092@@ -76,8 +76,8 @@ struct posix_acl *
56093 posix_acl_from_xattr(struct user_namespace *user_ns,
56094 const void *value, size_t size)
56095 {
56096- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
56097- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
56098+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
56099+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
56100 int count;
56101 struct posix_acl *acl;
56102 struct posix_acl_entry *acl_e;
56103diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
56104index 572a858..12a9b0d 100644
56105--- a/fs/xfs/xfs_bmap.c
56106+++ b/fs/xfs/xfs_bmap.c
56107@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
56108 int nmap,
56109 int ret_nmap);
56110 #else
56111-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
56112+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
56113 #endif /* DEBUG */
56114
56115 STATIC int
56116diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
56117index 1b9fc3e..e1bdde0 100644
56118--- a/fs/xfs/xfs_dir2_sf.c
56119+++ b/fs/xfs/xfs_dir2_sf.c
56120@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
56121 }
56122
56123 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
56124- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56125+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
56126+ char name[sfep->namelen];
56127+ memcpy(name, sfep->name, sfep->namelen);
56128+ if (filldir(dirent, name, sfep->namelen,
56129+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
56130+ *offset = off & 0x7fffffff;
56131+ return 0;
56132+ }
56133+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56134 off & 0x7fffffff, ino, DT_UNKNOWN)) {
56135 *offset = off & 0x7fffffff;
56136 return 0;
56137diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
56138index c1c3ef8..0952438 100644
56139--- a/fs/xfs/xfs_ioctl.c
56140+++ b/fs/xfs/xfs_ioctl.c
56141@@ -127,7 +127,7 @@ xfs_find_handle(
56142 }
56143
56144 error = -EFAULT;
56145- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
56146+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
56147 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
56148 goto out_put;
56149
56150diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
56151index d82efaa..0904a8e 100644
56152--- a/fs/xfs/xfs_iops.c
56153+++ b/fs/xfs/xfs_iops.c
56154@@ -395,7 +395,7 @@ xfs_vn_put_link(
56155 struct nameidata *nd,
56156 void *p)
56157 {
56158- char *s = nd_get_link(nd);
56159+ const char *s = nd_get_link(nd);
56160
56161 if (!IS_ERR(s))
56162 kfree(s);
56163diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
56164new file mode 100644
56165index 0000000..92247e4
56166--- /dev/null
56167+++ b/grsecurity/Kconfig
56168@@ -0,0 +1,1021 @@
56169+#
56170+# grecurity configuration
56171+#
56172+menu "Memory Protections"
56173+depends on GRKERNSEC
56174+
56175+config GRKERNSEC_KMEM
56176+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
56177+ default y if GRKERNSEC_CONFIG_AUTO
56178+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
56179+ help
56180+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
56181+ be written to or read from to modify or leak the contents of the running
56182+ kernel. /dev/port will also not be allowed to be opened and support
56183+ for /dev/cpu/*/msr will be removed. If you have module
56184+ support disabled, enabling this will close up five ways that are
56185+ currently used to insert malicious code into the running kernel.
56186+
56187+ Even with all these features enabled, we still highly recommend that
56188+ you use the RBAC system, as it is still possible for an attacker to
56189+ modify the running kernel through privileged I/O granted by ioperm/iopl.
56190+
56191+ If you are not using XFree86, you may be able to stop this additional
56192+ case by enabling the 'Disable privileged I/O' option. Though nothing
56193+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
56194+ but only to video memory, which is the only writing we allow in this
56195+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
56196+ not be allowed to mprotect it with PROT_WRITE later.
56197+ Enabling this feature will prevent the "cpupower" and "powertop" tools
56198+ from working.
56199+
56200+ It is highly recommended that you say Y here if you meet all the
56201+ conditions above.
56202+
56203+config GRKERNSEC_VM86
56204+ bool "Restrict VM86 mode"
56205+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56206+ depends on X86_32
56207+
56208+ help
56209+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
56210+ make use of a special execution mode on 32bit x86 processors called
56211+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
56212+ video cards and will still work with this option enabled. The purpose
56213+ of the option is to prevent exploitation of emulation errors in
56214+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
56215+ Nearly all users should be able to enable this option.
56216+
56217+config GRKERNSEC_IO
56218+ bool "Disable privileged I/O"
56219+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56220+ depends on X86
56221+ select RTC_CLASS
56222+ select RTC_INTF_DEV
56223+ select RTC_DRV_CMOS
56224+
56225+ help
56226+ If you say Y here, all ioperm and iopl calls will return an error.
56227+ Ioperm and iopl can be used to modify the running kernel.
56228+ Unfortunately, some programs need this access to operate properly,
56229+ the most notable of which are XFree86 and hwclock. hwclock can be
56230+ remedied by having RTC support in the kernel, so real-time
56231+ clock support is enabled if this option is enabled, to ensure
56232+ that hwclock operates correctly. XFree86 still will not
56233+ operate correctly with this option enabled, so DO NOT CHOOSE Y
56234+ IF YOU USE XFree86. If you use XFree86 and you still want to
56235+ protect your kernel against modification, use the RBAC system.
56236+
56237+config GRKERNSEC_JIT_HARDEN
56238+ bool "Harden BPF JIT against spray attacks"
56239+ default y if GRKERNSEC_CONFIG_AUTO
56240+ depends on BPF_JIT
56241+ help
56242+ If you say Y here, the native code generated by the kernel's Berkeley
56243+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
56244+ attacks that attempt to fit attacker-beneficial instructions in
56245+ 32bit immediate fields of JIT-generated native instructions. The
56246+ attacker will generally aim to cause an unintended instruction sequence
56247+ of JIT-generated native code to execute by jumping into the middle of
56248+ a generated instruction. This feature effectively randomizes the 32bit
56249+ immediate constants present in the generated code to thwart such attacks.
56250+
56251+ If you're using KERNEXEC, it's recommended that you enable this option
56252+ to supplement the hardening of the kernel.
56253+
56254+config GRKERNSEC_RAND_THREADSTACK
56255+ bool "Insert random gaps between thread stacks"
56256+ default y if GRKERNSEC_CONFIG_AUTO
56257+ depends on PAX_RANDMMAP && !PPC
56258+ help
56259+ If you say Y here, a random-sized gap will be enforced between allocated
56260+ thread stacks. Glibc's NPTL and other threading libraries that
56261+ pass MAP_STACK to the kernel for thread stack allocation are supported.
56262+ The implementation currently provides 8 bits of entropy for the gap.
56263+
56264+ Many distributions do not compile threaded remote services with the
56265+ -fstack-check argument to GCC, causing the variable-sized stack-based
56266+ allocator, alloca(), to not probe the stack on allocation. This
56267+ permits an unbounded alloca() to skip over any guard page and potentially
56268+ modify another thread's stack reliably. An enforced random gap
56269+ reduces the reliability of such an attack and increases the chance
56270+ that such a read/write to another thread's stack instead lands in
56271+ an unmapped area, causing a crash and triggering grsecurity's
56272+ anti-bruteforcing logic.
56273+
56274+config GRKERNSEC_PROC_MEMMAP
56275+ bool "Harden ASLR against information leaks and entropy reduction"
56276+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
56277+ depends on PAX_NOEXEC || PAX_ASLR
56278+ help
56279+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
56280+ give no information about the addresses of its mappings if
56281+ PaX features that rely on random addresses are enabled on the task.
56282+ In addition to sanitizing this information and disabling other
56283+ dangerous sources of information, this option causes reads of sensitive
56284+ /proc/<pid> entries where the file descriptor was opened in a different
56285+ task than the one performing the read. Such attempts are logged.
56286+ This option also limits argv/env strings for suid/sgid binaries
56287+ to 512KB to prevent a complete exhaustion of the stack entropy provided
56288+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
56289+ binaries to prevent alternative mmap layouts from being abused.
56290+
56291+ If you use PaX it is essential that you say Y here as it closes up
56292+ several holes that make full ASLR useless locally.
56293+
56294+config GRKERNSEC_BRUTE
56295+ bool "Deter exploit bruteforcing"
56296+ default y if GRKERNSEC_CONFIG_AUTO
56297+ help
56298+ If you say Y here, attempts to bruteforce exploits against forking
56299+ daemons such as apache or sshd, as well as against suid/sgid binaries
56300+ will be deterred. When a child of a forking daemon is killed by PaX
56301+ or crashes due to an illegal instruction or other suspicious signal,
56302+ the parent process will be delayed 30 seconds upon every subsequent
56303+ fork until the administrator is able to assess the situation and
56304+ restart the daemon.
56305+ In the suid/sgid case, the attempt is logged, the user has all their
56306+ processes terminated, and they are prevented from executing any further
56307+ processes for 15 minutes.
56308+ It is recommended that you also enable signal logging in the auditing
56309+ section so that logs are generated when a process triggers a suspicious
56310+ signal.
56311+ If the sysctl option is enabled, a sysctl option with name
56312+ "deter_bruteforce" is created.
56313+
56314+
56315+config GRKERNSEC_MODHARDEN
56316+ bool "Harden module auto-loading"
56317+ default y if GRKERNSEC_CONFIG_AUTO
56318+ depends on MODULES
56319+ help
56320+ If you say Y here, module auto-loading in response to use of some
56321+ feature implemented by an unloaded module will be restricted to
56322+ root users. Enabling this option helps defend against attacks
56323+ by unprivileged users who abuse the auto-loading behavior to
56324+ cause a vulnerable module to load that is then exploited.
56325+
56326+ If this option prevents a legitimate use of auto-loading for a
56327+ non-root user, the administrator can execute modprobe manually
56328+ with the exact name of the module mentioned in the alert log.
56329+ Alternatively, the administrator can add the module to the list
56330+ of modules loaded at boot by modifying init scripts.
56331+
56332+ Modification of init scripts will most likely be needed on
56333+ Ubuntu servers with encrypted home directory support enabled,
56334+ as the first non-root user logging in will cause the ecb(aes),
56335+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
56336+
56337+config GRKERNSEC_HIDESYM
56338+ bool "Hide kernel symbols"
56339+ default y if GRKERNSEC_CONFIG_AUTO
56340+ select PAX_USERCOPY_SLABS
56341+ help
56342+ If you say Y here, getting information on loaded modules, and
56343+ displaying all kernel symbols through a syscall will be restricted
56344+ to users with CAP_SYS_MODULE. For software compatibility reasons,
56345+ /proc/kallsyms will be restricted to the root user. The RBAC
56346+ system can hide that entry even from root.
56347+
56348+ This option also prevents leaking of kernel addresses through
56349+ several /proc entries.
56350+
56351+ Note that this option is only effective provided the following
56352+ conditions are met:
56353+ 1) The kernel using grsecurity is not precompiled by some distribution
56354+ 2) You have also enabled GRKERNSEC_DMESG
56355+ 3) You are using the RBAC system and hiding other files such as your
56356+ kernel image and System.map. Alternatively, enabling this option
56357+ causes the permissions on /boot, /lib/modules, and the kernel
56358+ source directory to change at compile time to prevent
56359+ reading by non-root users.
56360+ If the above conditions are met, this option will aid in providing a
56361+ useful protection against local kernel exploitation of overflows
56362+ and arbitrary read/write vulnerabilities.
56363+
56364+config GRKERNSEC_KERN_LOCKOUT
56365+ bool "Active kernel exploit response"
56366+ default y if GRKERNSEC_CONFIG_AUTO
56367+ depends on X86 || ARM || PPC || SPARC
56368+ help
56369+ If you say Y here, when a PaX alert is triggered due to suspicious
56370+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
56371+ or an OOPS occurs due to bad memory accesses, instead of just
56372+ terminating the offending process (and potentially allowing
56373+ a subsequent exploit from the same user), we will take one of two
56374+ actions:
56375+ If the user was root, we will panic the system
56376+ If the user was non-root, we will log the attempt, terminate
56377+ all processes owned by the user, then prevent them from creating
56378+ any new processes until the system is restarted
56379+ This deters repeated kernel exploitation/bruteforcing attempts
56380+ and is useful for later forensics.
56381+
56382+endmenu
56383+menu "Role Based Access Control Options"
56384+depends on GRKERNSEC
56385+
56386+config GRKERNSEC_RBAC_DEBUG
56387+ bool
56388+
56389+config GRKERNSEC_NO_RBAC
56390+ bool "Disable RBAC system"
56391+ help
56392+ If you say Y here, the /dev/grsec device will be removed from the kernel,
56393+ preventing the RBAC system from being enabled. You should only say Y
56394+ here if you have no intention of using the RBAC system, so as to prevent
56395+ an attacker with root access from misusing the RBAC system to hide files
56396+ and processes when loadable module support and /dev/[k]mem have been
56397+ locked down.
56398+
56399+config GRKERNSEC_ACL_HIDEKERN
56400+ bool "Hide kernel processes"
56401+ help
56402+ If you say Y here, all kernel threads will be hidden to all
56403+ processes but those whose subject has the "view hidden processes"
56404+ flag.
56405+
56406+config GRKERNSEC_ACL_MAXTRIES
56407+ int "Maximum tries before password lockout"
56408+ default 3
56409+ help
56410+ This option enforces the maximum number of times a user can attempt
56411+ to authorize themselves with the grsecurity RBAC system before being
56412+ denied the ability to attempt authorization again for a specified time.
56413+ The lower the number, the harder it will be to brute-force a password.
56414+
56415+config GRKERNSEC_ACL_TIMEOUT
56416+ int "Time to wait after max password tries, in seconds"
56417+ default 30
56418+ help
56419+ This option specifies the time the user must wait after attempting to
56420+ authorize to the RBAC system with the maximum number of invalid
56421+ passwords. The higher the number, the harder it will be to brute-force
56422+ a password.
56423+
56424+endmenu
56425+menu "Filesystem Protections"
56426+depends on GRKERNSEC
56427+
56428+config GRKERNSEC_PROC
56429+ bool "Proc restrictions"
56430+ default y if GRKERNSEC_CONFIG_AUTO
56431+ help
56432+ If you say Y here, the permissions of the /proc filesystem
56433+ will be altered to enhance system security and privacy. You MUST
56434+ choose either a user only restriction or a user and group restriction.
56435+ Depending upon the option you choose, you can either restrict users to
56436+ see only the processes they themselves run, or choose a group that can
56437+ view all processes and files normally restricted to root if you choose
56438+ the "restrict to user only" option. NOTE: If you're running identd or
56439+ ntpd as a non-root user, you will have to run it as the group you
56440+ specify here.
56441+
56442+config GRKERNSEC_PROC_USER
56443+ bool "Restrict /proc to user only"
56444+ depends on GRKERNSEC_PROC
56445+ help
56446+ If you say Y here, non-root users will only be able to view their own
56447+ processes, and restricts them from viewing network-related information,
56448+ and viewing kernel symbol and module information.
56449+
56450+config GRKERNSEC_PROC_USERGROUP
56451+ bool "Allow special group"
56452+ default y if GRKERNSEC_CONFIG_AUTO
56453+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56454+ help
56455+ If you say Y here, you will be able to select a group that will be
56456+ able to view all processes and network-related information. If you've
56457+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56458+ remain hidden. This option is useful if you want to run identd as
56459+ a non-root user. The group you select may also be chosen at boot time
56460+ via "grsec_proc_gid=" on the kernel commandline.
56461+
56462+config GRKERNSEC_PROC_GID
56463+ int "GID for special group"
56464+ depends on GRKERNSEC_PROC_USERGROUP
56465+ default 1001
56466+
56467+config GRKERNSEC_PROC_ADD
56468+ bool "Additional restrictions"
56469+ default y if GRKERNSEC_CONFIG_AUTO
56470+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56471+ help
56472+ If you say Y here, additional restrictions will be placed on
56473+ /proc that keep normal users from viewing device information and
56474+ slabinfo information that could be useful for exploits.
56475+
56476+config GRKERNSEC_LINK
56477+ bool "Linking restrictions"
56478+ default y if GRKERNSEC_CONFIG_AUTO
56479+ help
56480+ If you say Y here, /tmp race exploits will be prevented, since users
56481+ will no longer be able to follow symlinks owned by other users in
56482+ world-writable +t directories (e.g. /tmp), unless the owner of the
56483+ symlink is the owner of the directory. users will also not be
56484+ able to hardlink to files they do not own. If the sysctl option is
56485+ enabled, a sysctl option with name "linking_restrictions" is created.
56486+
56487+config GRKERNSEC_SYMLINKOWN
56488+ bool "Kernel-enforced SymlinksIfOwnerMatch"
56489+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56490+ help
56491+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
56492+ that prevents it from being used as a security feature. As Apache
56493+ verifies the symlink by performing a stat() against the target of
56494+ the symlink before it is followed, an attacker can setup a symlink
56495+ to point to a same-owned file, then replace the symlink with one
56496+ that targets another user's file just after Apache "validates" the
56497+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
56498+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56499+ will be in place for the group you specify. If the sysctl option
56500+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
56501+ created.
56502+
56503+config GRKERNSEC_SYMLINKOWN_GID
56504+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56505+ depends on GRKERNSEC_SYMLINKOWN
56506+ default 1006
56507+ help
56508+ Setting this GID determines what group kernel-enforced
56509+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56510+ is enabled, a sysctl option with name "symlinkown_gid" is created.
56511+
56512+config GRKERNSEC_FIFO
56513+ bool "FIFO restrictions"
56514+ default y if GRKERNSEC_CONFIG_AUTO
56515+ help
56516+ If you say Y here, users will not be able to write to FIFOs they don't
56517+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56518+ the FIFO is the same owner of the directory it's held in. If the sysctl
56519+ option is enabled, a sysctl option with name "fifo_restrictions" is
56520+ created.
56521+
56522+config GRKERNSEC_SYSFS_RESTRICT
56523+ bool "Sysfs/debugfs restriction"
56524+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56525+ depends on SYSFS
56526+ help
56527+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56528+ any filesystem normally mounted under it (e.g. debugfs) will be
56529+ mostly accessible only by root. These filesystems generally provide access
56530+ to hardware and debug information that isn't appropriate for unprivileged
56531+ users of the system. Sysfs and debugfs have also become a large source
56532+ of new vulnerabilities, ranging from infoleaks to local compromise.
56533+ There has been very little oversight with an eye toward security involved
56534+ in adding new exporters of information to these filesystems, so their
56535+ use is discouraged.
56536+ For reasons of compatibility, a few directories have been whitelisted
56537+ for access by non-root users:
56538+ /sys/fs/selinux
56539+ /sys/fs/fuse
56540+ /sys/devices/system/cpu
56541+
56542+config GRKERNSEC_ROFS
56543+ bool "Runtime read-only mount protection"
56544+ help
56545+ If you say Y here, a sysctl option with name "romount_protect" will
56546+ be created. By setting this option to 1 at runtime, filesystems
56547+ will be protected in the following ways:
56548+ * No new writable mounts will be allowed
56549+ * Existing read-only mounts won't be able to be remounted read/write
56550+ * Write operations will be denied on all block devices
56551+ This option acts independently of grsec_lock: once it is set to 1,
56552+ it cannot be turned off. Therefore, please be mindful of the resulting
56553+ behavior if this option is enabled in an init script on a read-only
56554+ filesystem. This feature is mainly intended for secure embedded systems.
56555+
56556+config GRKERNSEC_DEVICE_SIDECHANNEL
56557+ bool "Eliminate stat/notify-based device sidechannels"
56558+ default y if GRKERNSEC_CONFIG_AUTO
56559+ help
56560+ If you say Y here, timing analyses on block or character
56561+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56562+ will be thwarted for unprivileged users. If a process without
56563+ CAP_MKNOD stats such a device, the last access and last modify times
56564+ will match the device's create time. No access or modify events
56565+ will be triggered through inotify/dnotify/fanotify for such devices.
56566+ This feature will prevent attacks that may at a minimum
56567+ allow an attacker to determine the administrator's password length.
56568+
56569+config GRKERNSEC_CHROOT
56570+ bool "Chroot jail restrictions"
56571+ default y if GRKERNSEC_CONFIG_AUTO
56572+ help
56573+ If you say Y here, you will be able to choose several options that will
56574+ make breaking out of a chrooted jail much more difficult. If you
56575+ encounter no software incompatibilities with the following options, it
56576+ is recommended that you enable each one.
56577+
56578+config GRKERNSEC_CHROOT_MOUNT
56579+ bool "Deny mounts"
56580+ default y if GRKERNSEC_CONFIG_AUTO
56581+ depends on GRKERNSEC_CHROOT
56582+ help
56583+ If you say Y here, processes inside a chroot will not be able to
56584+ mount or remount filesystems. If the sysctl option is enabled, a
56585+ sysctl option with name "chroot_deny_mount" is created.
56586+
56587+config GRKERNSEC_CHROOT_DOUBLE
56588+ bool "Deny double-chroots"
56589+ default y if GRKERNSEC_CONFIG_AUTO
56590+ depends on GRKERNSEC_CHROOT
56591+ help
56592+ If you say Y here, processes inside a chroot will not be able to chroot
56593+ again outside the chroot. This is a widely used method of breaking
56594+ out of a chroot jail and should not be allowed. If the sysctl
56595+ option is enabled, a sysctl option with name
56596+ "chroot_deny_chroot" is created.
56597+
56598+config GRKERNSEC_CHROOT_PIVOT
56599+ bool "Deny pivot_root in chroot"
56600+ default y if GRKERNSEC_CONFIG_AUTO
56601+ depends on GRKERNSEC_CHROOT
56602+ help
56603+ If you say Y here, processes inside a chroot will not be able to use
56604+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56605+ works similar to chroot in that it changes the root filesystem. This
56606+ function could be misused in a chrooted process to attempt to break out
56607+ of the chroot, and therefore should not be allowed. If the sysctl
56608+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56609+ created.
56610+
56611+config GRKERNSEC_CHROOT_CHDIR
56612+ bool "Enforce chdir(\"/\") on all chroots"
56613+ default y if GRKERNSEC_CONFIG_AUTO
56614+ depends on GRKERNSEC_CHROOT
56615+ help
56616+ If you say Y here, the current working directory of all newly-chrooted
56617+ applications will be set to the the root directory of the chroot.
56618+ The man page on chroot(2) states:
56619+ Note that this call does not change the current working
56620+ directory, so that `.' can be outside the tree rooted at
56621+ `/'. In particular, the super-user can escape from a
56622+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56623+
56624+ It is recommended that you say Y here, since it's not known to break
56625+ any software. If the sysctl option is enabled, a sysctl option with
56626+ name "chroot_enforce_chdir" is created.
56627+
56628+config GRKERNSEC_CHROOT_CHMOD
56629+ bool "Deny (f)chmod +s"
56630+ default y if GRKERNSEC_CONFIG_AUTO
56631+ depends on GRKERNSEC_CHROOT
56632+ help
56633+ If you say Y here, processes inside a chroot will not be able to chmod
56634+ or fchmod files to make them have suid or sgid bits. This protects
56635+ against another published method of breaking a chroot. If the sysctl
56636+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56637+ created.
56638+
56639+config GRKERNSEC_CHROOT_FCHDIR
56640+ bool "Deny fchdir out of chroot"
56641+ default y if GRKERNSEC_CONFIG_AUTO
56642+ depends on GRKERNSEC_CHROOT
56643+ help
56644+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56645+ to a file descriptor of the chrooting process that points to a directory
56646+ outside the filesystem will be stopped. If the sysctl option
56647+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56648+
56649+config GRKERNSEC_CHROOT_MKNOD
56650+ bool "Deny mknod"
56651+ default y if GRKERNSEC_CONFIG_AUTO
56652+ depends on GRKERNSEC_CHROOT
56653+ help
56654+ If you say Y here, processes inside a chroot will not be allowed to
56655+ mknod. The problem with using mknod inside a chroot is that it
56656+ would allow an attacker to create a device entry that is the same
56657+ as one on the physical root of your system, which could range from
56658+ anything from the console device to a device for your harddrive (which
56659+ they could then use to wipe the drive or steal data). It is recommended
56660+ that you say Y here, unless you run into software incompatibilities.
56661+ If the sysctl option is enabled, a sysctl option with name
56662+ "chroot_deny_mknod" is created.
56663+
56664+config GRKERNSEC_CHROOT_SHMAT
56665+ bool "Deny shmat() out of chroot"
56666+ default y if GRKERNSEC_CONFIG_AUTO
56667+ depends on GRKERNSEC_CHROOT
56668+ help
56669+ If you say Y here, processes inside a chroot will not be able to attach
56670+ to shared memory segments that were created outside of the chroot jail.
56671+ It is recommended that you say Y here. If the sysctl option is enabled,
56672+ a sysctl option with name "chroot_deny_shmat" is created.
56673+
56674+config GRKERNSEC_CHROOT_UNIX
56675+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
56676+ default y if GRKERNSEC_CONFIG_AUTO
56677+ depends on GRKERNSEC_CHROOT
56678+ help
56679+ If you say Y here, processes inside a chroot will not be able to
56680+ connect to abstract (meaning not belonging to a filesystem) Unix
56681+ domain sockets that were bound outside of a chroot. It is recommended
56682+ that you say Y here. If the sysctl option is enabled, a sysctl option
56683+ with name "chroot_deny_unix" is created.
56684+
56685+config GRKERNSEC_CHROOT_FINDTASK
56686+ bool "Protect outside processes"
56687+ default y if GRKERNSEC_CONFIG_AUTO
56688+ depends on GRKERNSEC_CHROOT
56689+ help
56690+ If you say Y here, processes inside a chroot will not be able to
56691+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56692+ getsid, or view any process outside of the chroot. If the sysctl
56693+ option is enabled, a sysctl option with name "chroot_findtask" is
56694+ created.
56695+
56696+config GRKERNSEC_CHROOT_NICE
56697+ bool "Restrict priority changes"
56698+ default y if GRKERNSEC_CONFIG_AUTO
56699+ depends on GRKERNSEC_CHROOT
56700+ help
56701+ If you say Y here, processes inside a chroot will not be able to raise
56702+ the priority of processes in the chroot, or alter the priority of
56703+ processes outside the chroot. This provides more security than simply
56704+ removing CAP_SYS_NICE from the process' capability set. If the
56705+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56706+ is created.
56707+
56708+config GRKERNSEC_CHROOT_SYSCTL
56709+ bool "Deny sysctl writes"
56710+ default y if GRKERNSEC_CONFIG_AUTO
56711+ depends on GRKERNSEC_CHROOT
56712+ help
56713+ If you say Y here, an attacker in a chroot will not be able to
56714+ write to sysctl entries, either by sysctl(2) or through a /proc
56715+ interface. It is strongly recommended that you say Y here. If the
56716+ sysctl option is enabled, a sysctl option with name
56717+ "chroot_deny_sysctl" is created.
56718+
56719+config GRKERNSEC_CHROOT_CAPS
56720+ bool "Capability restrictions"
56721+ default y if GRKERNSEC_CONFIG_AUTO
56722+ depends on GRKERNSEC_CHROOT
56723+ help
56724+ If you say Y here, the capabilities on all processes within a
56725+ chroot jail will be lowered to stop module insertion, raw i/o,
56726+ system and net admin tasks, rebooting the system, modifying immutable
56727+ files, modifying IPC owned by another, and changing the system time.
56728+ This is left an option because it can break some apps. Disable this
56729+ if your chrooted apps are having problems performing those kinds of
56730+ tasks. If the sysctl option is enabled, a sysctl option with
56731+ name "chroot_caps" is created.
56732+
56733+endmenu
56734+menu "Kernel Auditing"
56735+depends on GRKERNSEC
56736+
56737+config GRKERNSEC_AUDIT_GROUP
56738+ bool "Single group for auditing"
56739+ help
56740+ If you say Y here, the exec and chdir logging features will only operate
56741+ on a group you specify. This option is recommended if you only want to
56742+ watch certain users instead of having a large amount of logs from the
56743+ entire system. If the sysctl option is enabled, a sysctl option with
56744+ name "audit_group" is created.
56745+
56746+config GRKERNSEC_AUDIT_GID
56747+ int "GID for auditing"
56748+ depends on GRKERNSEC_AUDIT_GROUP
56749+ default 1007
56750+
56751+config GRKERNSEC_EXECLOG
56752+ bool "Exec logging"
56753+ help
56754+ If you say Y here, all execve() calls will be logged (since the
56755+ other exec*() calls are frontends to execve(), all execution
56756+ will be logged). Useful for shell-servers that like to keep track
56757+ of their users. If the sysctl option is enabled, a sysctl option with
56758+ name "exec_logging" is created.
56759+ WARNING: This option when enabled will produce a LOT of logs, especially
56760+ on an active system.
56761+
56762+config GRKERNSEC_RESLOG
56763+ bool "Resource logging"
56764+ default y if GRKERNSEC_CONFIG_AUTO
56765+ help
56766+ If you say Y here, all attempts to overstep resource limits will
56767+ be logged with the resource name, the requested size, and the current
56768+ limit. It is highly recommended that you say Y here. If the sysctl
56769+ option is enabled, a sysctl option with name "resource_logging" is
56770+ created. If the RBAC system is enabled, the sysctl value is ignored.
56771+
56772+config GRKERNSEC_CHROOT_EXECLOG
56773+ bool "Log execs within chroot"
56774+ help
56775+ If you say Y here, all executions inside a chroot jail will be logged
56776+ to syslog. This can cause a large amount of logs if certain
56777+ applications (eg. djb's daemontools) are installed on the system, and
56778+ is therefore left as an option. If the sysctl option is enabled, a
56779+ sysctl option with name "chroot_execlog" is created.
56780+
56781+config GRKERNSEC_AUDIT_PTRACE
56782+ bool "Ptrace logging"
56783+ help
56784+ If you say Y here, all attempts to attach to a process via ptrace
56785+ will be logged. If the sysctl option is enabled, a sysctl option
56786+ with name "audit_ptrace" is created.
56787+
56788+config GRKERNSEC_AUDIT_CHDIR
56789+ bool "Chdir logging"
56790+ help
56791+ If you say Y here, all chdir() calls will be logged. If the sysctl
56792+ option is enabled, a sysctl option with name "audit_chdir" is created.
56793+
56794+config GRKERNSEC_AUDIT_MOUNT
56795+ bool "(Un)Mount logging"
56796+ help
56797+ If you say Y here, all mounts and unmounts will be logged. If the
56798+ sysctl option is enabled, a sysctl option with name "audit_mount" is
56799+ created.
56800+
56801+config GRKERNSEC_SIGNAL
56802+ bool "Signal logging"
56803+ default y if GRKERNSEC_CONFIG_AUTO
56804+ help
56805+ If you say Y here, certain important signals will be logged, such as
56806+ SIGSEGV, which will as a result inform you of when a error in a program
56807+ occurred, which in some cases could mean a possible exploit attempt.
56808+ If the sysctl option is enabled, a sysctl option with name
56809+ "signal_logging" is created.
56810+
56811+config GRKERNSEC_FORKFAIL
56812+ bool "Fork failure logging"
56813+ help
56814+ If you say Y here, all failed fork() attempts will be logged.
56815+ This could suggest a fork bomb, or someone attempting to overstep
56816+ their process limit. If the sysctl option is enabled, a sysctl option
56817+ with name "forkfail_logging" is created.
56818+
56819+config GRKERNSEC_TIME
56820+ bool "Time change logging"
56821+ default y if GRKERNSEC_CONFIG_AUTO
56822+ help
56823+ If you say Y here, any changes of the system clock will be logged.
56824+ If the sysctl option is enabled, a sysctl option with name
56825+ "timechange_logging" is created.
56826+
56827+config GRKERNSEC_PROC_IPADDR
56828+ bool "/proc/<pid>/ipaddr support"
56829+ default y if GRKERNSEC_CONFIG_AUTO
56830+ help
56831+ If you say Y here, a new entry will be added to each /proc/<pid>
56832+ directory that contains the IP address of the person using the task.
56833+ The IP is carried across local TCP and AF_UNIX stream sockets.
56834+ This information can be useful for IDS/IPSes to perform remote response
56835+ to a local attack. The entry is readable by only the owner of the
56836+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56837+ the RBAC system), and thus does not create privacy concerns.
56838+
56839+config GRKERNSEC_RWXMAP_LOG
56840+ bool 'Denied RWX mmap/mprotect logging'
56841+ default y if GRKERNSEC_CONFIG_AUTO
56842+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56843+ help
56844+ If you say Y here, calls to mmap() and mprotect() with explicit
56845+ usage of PROT_WRITE and PROT_EXEC together will be logged when
56846+ denied by the PAX_MPROTECT feature. If the sysctl option is
56847+ enabled, a sysctl option with name "rwxmap_logging" is created.
56848+
56849+config GRKERNSEC_AUDIT_TEXTREL
56850+ bool 'ELF text relocations logging (READ HELP)'
56851+ depends on PAX_MPROTECT
56852+ help
56853+ If you say Y here, text relocations will be logged with the filename
56854+ of the offending library or binary. The purpose of the feature is
56855+ to help Linux distribution developers get rid of libraries and
56856+ binaries that need text relocations which hinder the future progress
56857+ of PaX. Only Linux distribution developers should say Y here, and
56858+ never on a production machine, as this option creates an information
56859+ leak that could aid an attacker in defeating the randomization of
56860+ a single memory region. If the sysctl option is enabled, a sysctl
56861+ option with name "audit_textrel" is created.
56862+
56863+endmenu
56864+
56865+menu "Executable Protections"
56866+depends on GRKERNSEC
56867+
56868+config GRKERNSEC_DMESG
56869+ bool "Dmesg(8) restriction"
56870+ default y if GRKERNSEC_CONFIG_AUTO
56871+ help
56872+ If you say Y here, non-root users will not be able to use dmesg(8)
56873+ to view the contents of the kernel's circular log buffer.
56874+ The kernel's log buffer often contains kernel addresses and other
56875+ identifying information useful to an attacker in fingerprinting a
56876+ system for a targeted exploit.
56877+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
56878+ created.
56879+
56880+config GRKERNSEC_HARDEN_PTRACE
56881+ bool "Deter ptrace-based process snooping"
56882+ default y if GRKERNSEC_CONFIG_AUTO
56883+ help
56884+ If you say Y here, TTY sniffers and other malicious monitoring
56885+ programs implemented through ptrace will be defeated. If you
56886+ have been using the RBAC system, this option has already been
56887+ enabled for several years for all users, with the ability to make
56888+ fine-grained exceptions.
56889+
56890+ This option only affects the ability of non-root users to ptrace
56891+ processes that are not a descendent of the ptracing process.
56892+ This means that strace ./binary and gdb ./binary will still work,
56893+ but attaching to arbitrary processes will not. If the sysctl
56894+ option is enabled, a sysctl option with name "harden_ptrace" is
56895+ created.
56896+
56897+config GRKERNSEC_PTRACE_READEXEC
56898+ bool "Require read access to ptrace sensitive binaries"
56899+ default y if GRKERNSEC_CONFIG_AUTO
56900+ help
56901+ If you say Y here, unprivileged users will not be able to ptrace unreadable
56902+ binaries. This option is useful in environments that
56903+ remove the read bits (e.g. file mode 4711) from suid binaries to
56904+ prevent infoleaking of their contents. This option adds
56905+ consistency to the use of that file mode, as the binary could normally
56906+ be read out when run without privileges while ptracing.
56907+
56908+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56909+ is created.
56910+
56911+config GRKERNSEC_SETXID
56912+ bool "Enforce consistent multithreaded privileges"
56913+ default y if GRKERNSEC_CONFIG_AUTO
56914+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56915+ help
56916+ If you say Y here, a change from a root uid to a non-root uid
56917+ in a multithreaded application will cause the resulting uids,
56918+ gids, supplementary groups, and capabilities in that thread
56919+ to be propagated to the other threads of the process. In most
56920+ cases this is unnecessary, as glibc will emulate this behavior
56921+ on behalf of the application. Other libcs do not act in the
56922+ same way, allowing the other threads of the process to continue
56923+ running with root privileges. If the sysctl option is enabled,
56924+ a sysctl option with name "consistent_setxid" is created.
56925+
56926+config GRKERNSEC_TPE
56927+ bool "Trusted Path Execution (TPE)"
56928+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56929+ help
56930+ If you say Y here, you will be able to choose a gid to add to the
56931+ supplementary groups of users you want to mark as "untrusted."
56932+ These users will not be able to execute any files that are not in
56933+ root-owned directories writable only by root. If the sysctl option
56934+ is enabled, a sysctl option with name "tpe" is created.
56935+
56936+config GRKERNSEC_TPE_ALL
56937+ bool "Partially restrict all non-root users"
56938+ depends on GRKERNSEC_TPE
56939+ help
56940+ If you say Y here, all non-root users will be covered under
56941+ a weaker TPE restriction. This is separate from, and in addition to,
56942+ the main TPE options that you have selected elsewhere. Thus, if a
56943+ "trusted" GID is chosen, this restriction applies to even that GID.
56944+ Under this restriction, all non-root users will only be allowed to
56945+ execute files in directories they own that are not group or
56946+ world-writable, or in directories owned by root and writable only by
56947+ root. If the sysctl option is enabled, a sysctl option with name
56948+ "tpe_restrict_all" is created.
56949+
56950+config GRKERNSEC_TPE_INVERT
56951+ bool "Invert GID option"
56952+ depends on GRKERNSEC_TPE
56953+ help
56954+ If you say Y here, the group you specify in the TPE configuration will
56955+ decide what group TPE restrictions will be *disabled* for. This
56956+ option is useful if you want TPE restrictions to be applied to most
56957+ users on the system. If the sysctl option is enabled, a sysctl option
56958+ with name "tpe_invert" is created. Unlike other sysctl options, this
56959+ entry will default to on for backward-compatibility.
56960+
56961+config GRKERNSEC_TPE_GID
56962+ int
56963+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56964+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56965+
56966+config GRKERNSEC_TPE_UNTRUSTED_GID
56967+ int "GID for TPE-untrusted users"
56968+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56969+ default 1005
56970+ help
56971+ Setting this GID determines what group TPE restrictions will be
56972+ *enabled* for. If the sysctl option is enabled, a sysctl option
56973+ with name "tpe_gid" is created.
56974+
56975+config GRKERNSEC_TPE_TRUSTED_GID
56976+ int "GID for TPE-trusted users"
56977+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56978+ default 1005
56979+ help
56980+ Setting this GID determines what group TPE restrictions will be
56981+ *disabled* for. If the sysctl option is enabled, a sysctl option
56982+ with name "tpe_gid" is created.
56983+
56984+endmenu
56985+menu "Network Protections"
56986+depends on GRKERNSEC
56987+
56988+config GRKERNSEC_RANDNET
56989+ bool "Larger entropy pools"
56990+ default y if GRKERNSEC_CONFIG_AUTO
56991+ help
56992+ If you say Y here, the entropy pools used for many features of Linux
56993+ and grsecurity will be doubled in size. Since several grsecurity
56994+ features use additional randomness, it is recommended that you say Y
56995+ here. Saying Y here has a similar effect as modifying
56996+ /proc/sys/kernel/random/poolsize.
56997+
56998+config GRKERNSEC_BLACKHOLE
56999+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57000+ default y if GRKERNSEC_CONFIG_AUTO
57001+ depends on NET
57002+ help
57003+ If you say Y here, neither TCP resets nor ICMP
57004+ destination-unreachable packets will be sent in response to packets
57005+ sent to ports for which no associated listening process exists.
57006+ This feature supports both IPV4 and IPV6 and exempts the
57007+ loopback interface from blackholing. Enabling this feature
57008+ makes a host more resilient to DoS attacks and reduces network
57009+ visibility against scanners.
57010+
57011+ The blackhole feature as-implemented is equivalent to the FreeBSD
57012+ blackhole feature, as it prevents RST responses to all packets, not
57013+ just SYNs. Under most application behavior this causes no
57014+ problems, but applications (like haproxy) may not close certain
57015+ connections in a way that cleanly terminates them on the remote
57016+ end, leaving the remote host in LAST_ACK state. Because of this
57017+ side-effect and to prevent intentional LAST_ACK DoSes, this
57018+ feature also adds automatic mitigation against such attacks.
57019+ The mitigation drastically reduces the amount of time a socket
57020+ can spend in LAST_ACK state. If you're using haproxy and not
57021+ all servers it connects to have this option enabled, consider
57022+ disabling this feature on the haproxy host.
57023+
57024+ If the sysctl option is enabled, two sysctl options with names
57025+ "ip_blackhole" and "lastack_retries" will be created.
57026+ While "ip_blackhole" takes the standard zero/non-zero on/off
57027+ toggle, "lastack_retries" uses the same kinds of values as
57028+ "tcp_retries1" and "tcp_retries2". The default value of 4
57029+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57030+ state.
57031+
57032+config GRKERNSEC_NO_SIMULT_CONNECT
57033+ bool "Disable TCP Simultaneous Connect"
57034+ default y if GRKERNSEC_CONFIG_AUTO
57035+ depends on NET
57036+ help
57037+ If you say Y here, a feature by Willy Tarreau will be enabled that
57038+ removes a weakness in Linux's strict implementation of TCP that
57039+ allows two clients to connect to each other without either entering
57040+ a listening state. The weakness allows an attacker to easily prevent
57041+ a client from connecting to a known server provided the source port
57042+ for the connection is guessed correctly.
57043+
57044+ As the weakness could be used to prevent an antivirus or IPS from
57045+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57046+ it should be eliminated by enabling this option. Though Linux is
57047+ one of few operating systems supporting simultaneous connect, it
57048+ has no legitimate use in practice and is rarely supported by firewalls.
57049+
57050+config GRKERNSEC_SOCKET
57051+ bool "Socket restrictions"
57052+ depends on NET
57053+ help
57054+ If you say Y here, you will be able to choose from several options.
57055+ If you assign a GID on your system and add it to the supplementary
57056+ groups of users you want to restrict socket access to, this patch
57057+ will perform up to three things, based on the option(s) you choose.
57058+
57059+config GRKERNSEC_SOCKET_ALL
57060+ bool "Deny any sockets to group"
57061+ depends on GRKERNSEC_SOCKET
57062+ help
57063+ If you say Y here, you will be able to choose a GID of whose users will
57064+ be unable to connect to other hosts from your machine or run server
57065+ applications from your machine. If the sysctl option is enabled, a
57066+ sysctl option with name "socket_all" is created.
57067+
57068+config GRKERNSEC_SOCKET_ALL_GID
57069+ int "GID to deny all sockets for"
57070+ depends on GRKERNSEC_SOCKET_ALL
57071+ default 1004
57072+ help
57073+ Here you can choose the GID to disable socket access for. Remember to
57074+ add the users you want socket access disabled for to the GID
57075+ specified here. If the sysctl option is enabled, a sysctl option
57076+ with name "socket_all_gid" is created.
57077+
57078+config GRKERNSEC_SOCKET_CLIENT
57079+ bool "Deny client sockets to group"
57080+ depends on GRKERNSEC_SOCKET
57081+ help
57082+ If you say Y here, you will be able to choose a GID of whose users will
57083+ be unable to connect to other hosts from your machine, but will be
57084+ able to run servers. If this option is enabled, all users in the group
57085+ you specify will have to use passive mode when initiating ftp transfers
57086+ from the shell on your machine. If the sysctl option is enabled, a
57087+ sysctl option with name "socket_client" is created.
57088+
57089+config GRKERNSEC_SOCKET_CLIENT_GID
57090+ int "GID to deny client sockets for"
57091+ depends on GRKERNSEC_SOCKET_CLIENT
57092+ default 1003
57093+ help
57094+ Here you can choose the GID to disable client socket access for.
57095+ Remember to add the users you want client socket access disabled for to
57096+ the GID specified here. If the sysctl option is enabled, a sysctl
57097+ option with name "socket_client_gid" is created.
57098+
57099+config GRKERNSEC_SOCKET_SERVER
57100+ bool "Deny server sockets to group"
57101+ depends on GRKERNSEC_SOCKET
57102+ help
57103+ If you say Y here, you will be able to choose a GID of whose users will
57104+ be unable to run server applications from your machine. If the sysctl
57105+ option is enabled, a sysctl option with name "socket_server" is created.
57106+
57107+config GRKERNSEC_SOCKET_SERVER_GID
57108+ int "GID to deny server sockets for"
57109+ depends on GRKERNSEC_SOCKET_SERVER
57110+ default 1002
57111+ help
57112+ Here you can choose the GID to disable server socket access for.
57113+ Remember to add the users you want server socket access disabled for to
57114+ the GID specified here. If the sysctl option is enabled, a sysctl
57115+ option with name "socket_server_gid" is created.
57116+
57117+endmenu
57118+menu "Sysctl Support"
57119+depends on GRKERNSEC && SYSCTL
57120+
57121+config GRKERNSEC_SYSCTL
57122+ bool "Sysctl support"
57123+ default y if GRKERNSEC_CONFIG_AUTO
57124+ help
57125+ If you say Y here, you will be able to change the options that
57126+ grsecurity runs with at bootup, without having to recompile your
57127+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
57128+ to enable (1) or disable (0) various features. All the sysctl entries
57129+ are mutable until the "grsec_lock" entry is set to a non-zero value.
57130+ All features enabled in the kernel configuration are disabled at boot
57131+ if you do not say Y to the "Turn on features by default" option.
57132+ All options should be set at startup, and the grsec_lock entry should
57133+ be set to a non-zero value after all the options are set.
57134+ *THIS IS EXTREMELY IMPORTANT*
57135+
57136+config GRKERNSEC_SYSCTL_DISTRO
57137+ bool "Extra sysctl support for distro makers (READ HELP)"
57138+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
57139+ help
57140+ If you say Y here, additional sysctl options will be created
57141+ for features that affect processes running as root. Therefore,
57142+ it is critical when using this option that the grsec_lock entry be
57143+ enabled after boot. Only distros with prebuilt kernel packages
57144+ with this option enabled that can ensure grsec_lock is enabled
57145+ after boot should use this option.
57146+ *Failure to set grsec_lock after boot makes all grsec features
57147+ this option covers useless*
57148+
57149+ Currently this option creates the following sysctl entries:
57150+ "Disable Privileged I/O": "disable_priv_io"
57151+
57152+config GRKERNSEC_SYSCTL_ON
57153+ bool "Turn on features by default"
57154+ default y if GRKERNSEC_CONFIG_AUTO
57155+ depends on GRKERNSEC_SYSCTL
57156+ help
57157+ If you say Y here, instead of having all features enabled in the
57158+ kernel configuration disabled at boot time, the features will be
57159+ enabled at boot time. It is recommended you say Y here unless
57160+ there is some reason you would want all sysctl-tunable features to
57161+ be disabled by default. As mentioned elsewhere, it is important
57162+ to enable the grsec_lock entry once you have finished modifying
57163+ the sysctl entries.
57164+
57165+endmenu
57166+menu "Logging Options"
57167+depends on GRKERNSEC
57168+
57169+config GRKERNSEC_FLOODTIME
57170+ int "Seconds in between log messages (minimum)"
57171+ default 10
57172+ help
57173+ This option allows you to enforce the number of seconds between
57174+ grsecurity log messages. The default should be suitable for most
57175+ people, however, if you choose to change it, choose a value small enough
57176+ to allow informative logs to be produced, but large enough to
57177+ prevent flooding.
57178+
57179+config GRKERNSEC_FLOODBURST
57180+ int "Number of messages in a burst (maximum)"
57181+ default 6
57182+ help
57183+ This option allows you to choose the maximum number of messages allowed
57184+ within the flood time interval you chose in a separate option. The
57185+ default should be suitable for most people, however if you find that
57186+ many of your logs are being interpreted as flooding, you may want to
57187+ raise this value.
57188+
57189+endmenu
57190diff --git a/grsecurity/Makefile b/grsecurity/Makefile
57191new file mode 100644
57192index 0000000..1b9afa9
57193--- /dev/null
57194+++ b/grsecurity/Makefile
57195@@ -0,0 +1,38 @@
57196+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
57197+# during 2001-2009 it has been completely redesigned by Brad Spengler
57198+# into an RBAC system
57199+#
57200+# All code in this directory and various hooks inserted throughout the kernel
57201+# are copyright Brad Spengler - Open Source Security, Inc., and released
57202+# under the GPL v2 or higher
57203+
57204+KBUILD_CFLAGS += -Werror
57205+
57206+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
57207+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
57208+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
57209+
57210+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
57211+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
57212+ gracl_learn.o grsec_log.o
57213+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
57214+
57215+ifdef CONFIG_NET
57216+obj-y += grsec_sock.o
57217+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
57218+endif
57219+
57220+ifndef CONFIG_GRKERNSEC
57221+obj-y += grsec_disabled.o
57222+endif
57223+
57224+ifdef CONFIG_GRKERNSEC_HIDESYM
57225+extra-y := grsec_hidesym.o
57226+$(obj)/grsec_hidesym.o:
57227+ @-chmod -f 500 /boot
57228+ @-chmod -f 500 /lib/modules
57229+ @-chmod -f 500 /lib64/modules
57230+ @-chmod -f 500 /lib32/modules
57231+ @-chmod -f 700 .
57232+ @echo ' grsec: protected kernel image paths'
57233+endif
57234diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
57235new file mode 100644
57236index 0000000..ab45812
57237--- /dev/null
57238+++ b/grsecurity/gracl.c
57239@@ -0,0 +1,4071 @@
57240+#include <linux/kernel.h>
57241+#include <linux/module.h>
57242+#include <linux/sched.h>
57243+#include <linux/mm.h>
57244+#include <linux/file.h>
57245+#include <linux/fs.h>
57246+#include <linux/namei.h>
57247+#include <linux/mount.h>
57248+#include <linux/tty.h>
57249+#include <linux/proc_fs.h>
57250+#include <linux/lglock.h>
57251+#include <linux/slab.h>
57252+#include <linux/vmalloc.h>
57253+#include <linux/types.h>
57254+#include <linux/sysctl.h>
57255+#include <linux/netdevice.h>
57256+#include <linux/ptrace.h>
57257+#include <linux/gracl.h>
57258+#include <linux/gralloc.h>
57259+#include <linux/security.h>
57260+#include <linux/grinternal.h>
57261+#include <linux/pid_namespace.h>
57262+#include <linux/stop_machine.h>
57263+#include <linux/fdtable.h>
57264+#include <linux/percpu.h>
57265+#include <linux/lglock.h>
57266+#include <linux/hugetlb.h>
57267+#include <linux/posix-timers.h>
57268+#include "../fs/mount.h"
57269+
57270+#include <asm/uaccess.h>
57271+#include <asm/errno.h>
57272+#include <asm/mman.h>
57273+
57274+extern struct lglock vfsmount_lock;
57275+
57276+static struct acl_role_db acl_role_set;
57277+static struct name_db name_set;
57278+static struct inodev_db inodev_set;
57279+
57280+/* for keeping track of userspace pointers used for subjects, so we
57281+ can share references in the kernel as well
57282+*/
57283+
57284+static struct path real_root;
57285+
57286+static struct acl_subj_map_db subj_map_set;
57287+
57288+static struct acl_role_label *default_role;
57289+
57290+static struct acl_role_label *role_list;
57291+
57292+static u16 acl_sp_role_value;
57293+
57294+extern char *gr_shared_page[4];
57295+static DEFINE_MUTEX(gr_dev_mutex);
57296+DEFINE_RWLOCK(gr_inode_lock);
57297+
57298+struct gr_arg *gr_usermode;
57299+
57300+static unsigned int gr_status __read_only = GR_STATUS_INIT;
57301+
57302+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
57303+extern void gr_clear_learn_entries(void);
57304+
57305+unsigned char *gr_system_salt;
57306+unsigned char *gr_system_sum;
57307+
57308+static struct sprole_pw **acl_special_roles = NULL;
57309+static __u16 num_sprole_pws = 0;
57310+
57311+static struct acl_role_label *kernel_role = NULL;
57312+
57313+static unsigned int gr_auth_attempts = 0;
57314+static unsigned long gr_auth_expires = 0UL;
57315+
57316+#ifdef CONFIG_NET
57317+extern struct vfsmount *sock_mnt;
57318+#endif
57319+
57320+extern struct vfsmount *pipe_mnt;
57321+extern struct vfsmount *shm_mnt;
57322+
57323+#ifdef CONFIG_HUGETLBFS
57324+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57325+#endif
57326+
57327+static struct acl_object_label *fakefs_obj_rw;
57328+static struct acl_object_label *fakefs_obj_rwx;
57329+
57330+extern int gr_init_uidset(void);
57331+extern void gr_free_uidset(void);
57332+extern void gr_remove_uid(uid_t uid);
57333+extern int gr_find_uid(uid_t uid);
57334+
57335+__inline__ int
57336+gr_acl_is_enabled(void)
57337+{
57338+ return (gr_status & GR_READY);
57339+}
57340+
57341+#ifdef CONFIG_BTRFS_FS
57342+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57343+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57344+#endif
57345+
57346+static inline dev_t __get_dev(const struct dentry *dentry)
57347+{
57348+#ifdef CONFIG_BTRFS_FS
57349+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57350+ return get_btrfs_dev_from_inode(dentry->d_inode);
57351+ else
57352+#endif
57353+ return dentry->d_inode->i_sb->s_dev;
57354+}
57355+
57356+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57357+{
57358+ return __get_dev(dentry);
57359+}
57360+
57361+static char gr_task_roletype_to_char(struct task_struct *task)
57362+{
57363+ switch (task->role->roletype &
57364+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
57365+ GR_ROLE_SPECIAL)) {
57366+ case GR_ROLE_DEFAULT:
57367+ return 'D';
57368+ case GR_ROLE_USER:
57369+ return 'U';
57370+ case GR_ROLE_GROUP:
57371+ return 'G';
57372+ case GR_ROLE_SPECIAL:
57373+ return 'S';
57374+ }
57375+
57376+ return 'X';
57377+}
57378+
57379+char gr_roletype_to_char(void)
57380+{
57381+ return gr_task_roletype_to_char(current);
57382+}
57383+
57384+__inline__ int
57385+gr_acl_tpe_check(void)
57386+{
57387+ if (unlikely(!(gr_status & GR_READY)))
57388+ return 0;
57389+ if (current->role->roletype & GR_ROLE_TPE)
57390+ return 1;
57391+ else
57392+ return 0;
57393+}
57394+
57395+int
57396+gr_handle_rawio(const struct inode *inode)
57397+{
57398+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57399+ if (inode && S_ISBLK(inode->i_mode) &&
57400+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57401+ !capable(CAP_SYS_RAWIO))
57402+ return 1;
57403+#endif
57404+ return 0;
57405+}
57406+
57407+static int
57408+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
57409+{
57410+ if (likely(lena != lenb))
57411+ return 0;
57412+
57413+ return !memcmp(a, b, lena);
57414+}
57415+
57416+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
57417+{
57418+ *buflen -= namelen;
57419+ if (*buflen < 0)
57420+ return -ENAMETOOLONG;
57421+ *buffer -= namelen;
57422+ memcpy(*buffer, str, namelen);
57423+ return 0;
57424+}
57425+
57426+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
57427+{
57428+ return prepend(buffer, buflen, name->name, name->len);
57429+}
57430+
57431+static int prepend_path(const struct path *path, struct path *root,
57432+ char **buffer, int *buflen)
57433+{
57434+ struct dentry *dentry = path->dentry;
57435+ struct vfsmount *vfsmnt = path->mnt;
57436+ struct mount *mnt = real_mount(vfsmnt);
57437+ bool slash = false;
57438+ int error = 0;
57439+
57440+ while (dentry != root->dentry || vfsmnt != root->mnt) {
57441+ struct dentry * parent;
57442+
57443+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
57444+ /* Global root? */
57445+ if (!mnt_has_parent(mnt)) {
57446+ goto out;
57447+ }
57448+ dentry = mnt->mnt_mountpoint;
57449+ mnt = mnt->mnt_parent;
57450+ vfsmnt = &mnt->mnt;
57451+ continue;
57452+ }
57453+ parent = dentry->d_parent;
57454+ prefetch(parent);
57455+ spin_lock(&dentry->d_lock);
57456+ error = prepend_name(buffer, buflen, &dentry->d_name);
57457+ spin_unlock(&dentry->d_lock);
57458+ if (!error)
57459+ error = prepend(buffer, buflen, "/", 1);
57460+ if (error)
57461+ break;
57462+
57463+ slash = true;
57464+ dentry = parent;
57465+ }
57466+
57467+out:
57468+ if (!error && !slash)
57469+ error = prepend(buffer, buflen, "/", 1);
57470+
57471+ return error;
57472+}
57473+
57474+/* this must be called with vfsmount_lock and rename_lock held */
57475+
57476+static char *__our_d_path(const struct path *path, struct path *root,
57477+ char *buf, int buflen)
57478+{
57479+ char *res = buf + buflen;
57480+ int error;
57481+
57482+ prepend(&res, &buflen, "\0", 1);
57483+ error = prepend_path(path, root, &res, &buflen);
57484+ if (error)
57485+ return ERR_PTR(error);
57486+
57487+ return res;
57488+}
57489+
57490+static char *
57491+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
57492+{
57493+ char *retval;
57494+
57495+ retval = __our_d_path(path, root, buf, buflen);
57496+ if (unlikely(IS_ERR(retval)))
57497+ retval = strcpy(buf, "<path too long>");
57498+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57499+ retval[1] = '\0';
57500+
57501+ return retval;
57502+}
57503+
57504+static char *
57505+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57506+ char *buf, int buflen)
57507+{
57508+ struct path path;
57509+ char *res;
57510+
57511+ path.dentry = (struct dentry *)dentry;
57512+ path.mnt = (struct vfsmount *)vfsmnt;
57513+
57514+ /* we can use real_root.dentry, real_root.mnt, because this is only called
57515+ by the RBAC system */
57516+ res = gen_full_path(&path, &real_root, buf, buflen);
57517+
57518+ return res;
57519+}
57520+
57521+static char *
57522+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57523+ char *buf, int buflen)
57524+{
57525+ char *res;
57526+ struct path path;
57527+ struct path root;
57528+ struct task_struct *reaper = init_pid_ns.child_reaper;
57529+
57530+ path.dentry = (struct dentry *)dentry;
57531+ path.mnt = (struct vfsmount *)vfsmnt;
57532+
57533+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57534+ get_fs_root(reaper->fs, &root);
57535+
57536+ write_seqlock(&rename_lock);
57537+ br_read_lock(&vfsmount_lock);
57538+ res = gen_full_path(&path, &root, buf, buflen);
57539+ br_read_unlock(&vfsmount_lock);
57540+ write_sequnlock(&rename_lock);
57541+
57542+ path_put(&root);
57543+ return res;
57544+}
57545+
57546+static char *
57547+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57548+{
57549+ char *ret;
57550+ write_seqlock(&rename_lock);
57551+ br_read_lock(&vfsmount_lock);
57552+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57553+ PAGE_SIZE);
57554+ br_read_unlock(&vfsmount_lock);
57555+ write_sequnlock(&rename_lock);
57556+ return ret;
57557+}
57558+
57559+static char *
57560+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57561+{
57562+ char *ret;
57563+ char *buf;
57564+ int buflen;
57565+
57566+ write_seqlock(&rename_lock);
57567+ br_read_lock(&vfsmount_lock);
57568+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57569+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57570+ buflen = (int)(ret - buf);
57571+ if (buflen >= 5)
57572+ prepend(&ret, &buflen, "/proc", 5);
57573+ else
57574+ ret = strcpy(buf, "<path too long>");
57575+ br_read_unlock(&vfsmount_lock);
57576+ write_sequnlock(&rename_lock);
57577+ return ret;
57578+}
57579+
57580+char *
57581+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57582+{
57583+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57584+ PAGE_SIZE);
57585+}
57586+
57587+char *
57588+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57589+{
57590+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57591+ PAGE_SIZE);
57592+}
57593+
57594+char *
57595+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57596+{
57597+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57598+ PAGE_SIZE);
57599+}
57600+
57601+char *
57602+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57603+{
57604+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57605+ PAGE_SIZE);
57606+}
57607+
57608+char *
57609+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57610+{
57611+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57612+ PAGE_SIZE);
57613+}
57614+
57615+__inline__ __u32
57616+to_gr_audit(const __u32 reqmode)
57617+{
57618+ /* masks off auditable permission flags, then shifts them to create
57619+ auditing flags, and adds the special case of append auditing if
57620+ we're requesting write */
57621+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57622+}
57623+
57624+struct acl_subject_label *
57625+lookup_subject_map(const struct acl_subject_label *userp)
57626+{
57627+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
57628+ struct subject_map *match;
57629+
57630+ match = subj_map_set.s_hash[index];
57631+
57632+ while (match && match->user != userp)
57633+ match = match->next;
57634+
57635+ if (match != NULL)
57636+ return match->kernel;
57637+ else
57638+ return NULL;
57639+}
57640+
57641+static void
57642+insert_subj_map_entry(struct subject_map *subjmap)
57643+{
57644+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57645+ struct subject_map **curr;
57646+
57647+ subjmap->prev = NULL;
57648+
57649+ curr = &subj_map_set.s_hash[index];
57650+ if (*curr != NULL)
57651+ (*curr)->prev = subjmap;
57652+
57653+ subjmap->next = *curr;
57654+ *curr = subjmap;
57655+
57656+ return;
57657+}
57658+
57659+static struct acl_role_label *
57660+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57661+ const gid_t gid)
57662+{
57663+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57664+ struct acl_role_label *match;
57665+ struct role_allowed_ip *ipp;
57666+ unsigned int x;
57667+ u32 curr_ip = task->signal->curr_ip;
57668+
57669+ task->signal->saved_ip = curr_ip;
57670+
57671+ match = acl_role_set.r_hash[index];
57672+
57673+ while (match) {
57674+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57675+ for (x = 0; x < match->domain_child_num; x++) {
57676+ if (match->domain_children[x] == uid)
57677+ goto found;
57678+ }
57679+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57680+ break;
57681+ match = match->next;
57682+ }
57683+found:
57684+ if (match == NULL) {
57685+ try_group:
57686+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57687+ match = acl_role_set.r_hash[index];
57688+
57689+ while (match) {
57690+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57691+ for (x = 0; x < match->domain_child_num; x++) {
57692+ if (match->domain_children[x] == gid)
57693+ goto found2;
57694+ }
57695+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57696+ break;
57697+ match = match->next;
57698+ }
57699+found2:
57700+ if (match == NULL)
57701+ match = default_role;
57702+ if (match->allowed_ips == NULL)
57703+ return match;
57704+ else {
57705+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57706+ if (likely
57707+ ((ntohl(curr_ip) & ipp->netmask) ==
57708+ (ntohl(ipp->addr) & ipp->netmask)))
57709+ return match;
57710+ }
57711+ match = default_role;
57712+ }
57713+ } else if (match->allowed_ips == NULL) {
57714+ return match;
57715+ } else {
57716+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57717+ if (likely
57718+ ((ntohl(curr_ip) & ipp->netmask) ==
57719+ (ntohl(ipp->addr) & ipp->netmask)))
57720+ return match;
57721+ }
57722+ goto try_group;
57723+ }
57724+
57725+ return match;
57726+}
57727+
57728+struct acl_subject_label *
57729+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57730+ const struct acl_role_label *role)
57731+{
57732+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57733+ struct acl_subject_label *match;
57734+
57735+ match = role->subj_hash[index];
57736+
57737+ while (match && (match->inode != ino || match->device != dev ||
57738+ (match->mode & GR_DELETED))) {
57739+ match = match->next;
57740+ }
57741+
57742+ if (match && !(match->mode & GR_DELETED))
57743+ return match;
57744+ else
57745+ return NULL;
57746+}
57747+
57748+struct acl_subject_label *
57749+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57750+ const struct acl_role_label *role)
57751+{
57752+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57753+ struct acl_subject_label *match;
57754+
57755+ match = role->subj_hash[index];
57756+
57757+ while (match && (match->inode != ino || match->device != dev ||
57758+ !(match->mode & GR_DELETED))) {
57759+ match = match->next;
57760+ }
57761+
57762+ if (match && (match->mode & GR_DELETED))
57763+ return match;
57764+ else
57765+ return NULL;
57766+}
57767+
57768+static struct acl_object_label *
57769+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57770+ const struct acl_subject_label *subj)
57771+{
57772+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57773+ struct acl_object_label *match;
57774+
57775+ match = subj->obj_hash[index];
57776+
57777+ while (match && (match->inode != ino || match->device != dev ||
57778+ (match->mode & GR_DELETED))) {
57779+ match = match->next;
57780+ }
57781+
57782+ if (match && !(match->mode & GR_DELETED))
57783+ return match;
57784+ else
57785+ return NULL;
57786+}
57787+
57788+static struct acl_object_label *
57789+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57790+ const struct acl_subject_label *subj)
57791+{
57792+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57793+ struct acl_object_label *match;
57794+
57795+ match = subj->obj_hash[index];
57796+
57797+ while (match && (match->inode != ino || match->device != dev ||
57798+ !(match->mode & GR_DELETED))) {
57799+ match = match->next;
57800+ }
57801+
57802+ if (match && (match->mode & GR_DELETED))
57803+ return match;
57804+
57805+ match = subj->obj_hash[index];
57806+
57807+ while (match && (match->inode != ino || match->device != dev ||
57808+ (match->mode & GR_DELETED))) {
57809+ match = match->next;
57810+ }
57811+
57812+ if (match && !(match->mode & GR_DELETED))
57813+ return match;
57814+ else
57815+ return NULL;
57816+}
57817+
57818+static struct name_entry *
57819+lookup_name_entry(const char *name)
57820+{
57821+ unsigned int len = strlen(name);
57822+ unsigned int key = full_name_hash(name, len);
57823+ unsigned int index = key % name_set.n_size;
57824+ struct name_entry *match;
57825+
57826+ match = name_set.n_hash[index];
57827+
57828+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57829+ match = match->next;
57830+
57831+ return match;
57832+}
57833+
57834+static struct name_entry *
57835+lookup_name_entry_create(const char *name)
57836+{
57837+ unsigned int len = strlen(name);
57838+ unsigned int key = full_name_hash(name, len);
57839+ unsigned int index = key % name_set.n_size;
57840+ struct name_entry *match;
57841+
57842+ match = name_set.n_hash[index];
57843+
57844+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57845+ !match->deleted))
57846+ match = match->next;
57847+
57848+ if (match && match->deleted)
57849+ return match;
57850+
57851+ match = name_set.n_hash[index];
57852+
57853+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57854+ match->deleted))
57855+ match = match->next;
57856+
57857+ if (match && !match->deleted)
57858+ return match;
57859+ else
57860+ return NULL;
57861+}
57862+
57863+static struct inodev_entry *
57864+lookup_inodev_entry(const ino_t ino, const dev_t dev)
57865+{
57866+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57867+ struct inodev_entry *match;
57868+
57869+ match = inodev_set.i_hash[index];
57870+
57871+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57872+ match = match->next;
57873+
57874+ return match;
57875+}
57876+
57877+static void
57878+insert_inodev_entry(struct inodev_entry *entry)
57879+{
57880+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57881+ inodev_set.i_size);
57882+ struct inodev_entry **curr;
57883+
57884+ entry->prev = NULL;
57885+
57886+ curr = &inodev_set.i_hash[index];
57887+ if (*curr != NULL)
57888+ (*curr)->prev = entry;
57889+
57890+ entry->next = *curr;
57891+ *curr = entry;
57892+
57893+ return;
57894+}
57895+
57896+static void
57897+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57898+{
57899+ unsigned int index =
57900+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57901+ struct acl_role_label **curr;
57902+ struct acl_role_label *tmp, *tmp2;
57903+
57904+ curr = &acl_role_set.r_hash[index];
57905+
57906+ /* simple case, slot is empty, just set it to our role */
57907+ if (*curr == NULL) {
57908+ *curr = role;
57909+ } else {
57910+ /* example:
57911+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
57912+ 2 -> 3
57913+ */
57914+ /* first check to see if we can already be reached via this slot */
57915+ tmp = *curr;
57916+ while (tmp && tmp != role)
57917+ tmp = tmp->next;
57918+ if (tmp == role) {
57919+ /* we don't need to add ourselves to this slot's chain */
57920+ return;
57921+ }
57922+ /* we need to add ourselves to this chain, two cases */
57923+ if (role->next == NULL) {
57924+ /* simple case, append the current chain to our role */
57925+ role->next = *curr;
57926+ *curr = role;
57927+ } else {
57928+ /* 1 -> 2 -> 3 -> 4
57929+ 2 -> 3 -> 4
57930+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57931+ */
57932+ /* trickier case: walk our role's chain until we find
57933+ the role for the start of the current slot's chain */
57934+ tmp = role;
57935+ tmp2 = *curr;
57936+ while (tmp->next && tmp->next != tmp2)
57937+ tmp = tmp->next;
57938+ if (tmp->next == tmp2) {
57939+ /* from example above, we found 3, so just
57940+ replace this slot's chain with ours */
57941+ *curr = role;
57942+ } else {
57943+ /* we didn't find a subset of our role's chain
57944+ in the current slot's chain, so append their
57945+ chain to ours, and set us as the first role in
57946+ the slot's chain
57947+
57948+ we could fold this case with the case above,
57949+ but making it explicit for clarity
57950+ */
57951+ tmp->next = tmp2;
57952+ *curr = role;
57953+ }
57954+ }
57955+ }
57956+
57957+ return;
57958+}
57959+
57960+static void
57961+insert_acl_role_label(struct acl_role_label *role)
57962+{
57963+ int i;
57964+
57965+ if (role_list == NULL) {
57966+ role_list = role;
57967+ role->prev = NULL;
57968+ } else {
57969+ role->prev = role_list;
57970+ role_list = role;
57971+ }
57972+
57973+ /* used for hash chains */
57974+ role->next = NULL;
57975+
57976+ if (role->roletype & GR_ROLE_DOMAIN) {
57977+ for (i = 0; i < role->domain_child_num; i++)
57978+ __insert_acl_role_label(role, role->domain_children[i]);
57979+ } else
57980+ __insert_acl_role_label(role, role->uidgid);
57981+}
57982+
57983+static int
57984+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57985+{
57986+ struct name_entry **curr, *nentry;
57987+ struct inodev_entry *ientry;
57988+ unsigned int len = strlen(name);
57989+ unsigned int key = full_name_hash(name, len);
57990+ unsigned int index = key % name_set.n_size;
57991+
57992+ curr = &name_set.n_hash[index];
57993+
57994+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57995+ curr = &((*curr)->next);
57996+
57997+ if (*curr != NULL)
57998+ return 1;
57999+
58000+ nentry = acl_alloc(sizeof (struct name_entry));
58001+ if (nentry == NULL)
58002+ return 0;
58003+ ientry = acl_alloc(sizeof (struct inodev_entry));
58004+ if (ientry == NULL)
58005+ return 0;
58006+ ientry->nentry = nentry;
58007+
58008+ nentry->key = key;
58009+ nentry->name = name;
58010+ nentry->inode = inode;
58011+ nentry->device = device;
58012+ nentry->len = len;
58013+ nentry->deleted = deleted;
58014+
58015+ nentry->prev = NULL;
58016+ curr = &name_set.n_hash[index];
58017+ if (*curr != NULL)
58018+ (*curr)->prev = nentry;
58019+ nentry->next = *curr;
58020+ *curr = nentry;
58021+
58022+ /* insert us into the table searchable by inode/dev */
58023+ insert_inodev_entry(ientry);
58024+
58025+ return 1;
58026+}
58027+
58028+static void
58029+insert_acl_obj_label(struct acl_object_label *obj,
58030+ struct acl_subject_label *subj)
58031+{
58032+ unsigned int index =
58033+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58034+ struct acl_object_label **curr;
58035+
58036+
58037+ obj->prev = NULL;
58038+
58039+ curr = &subj->obj_hash[index];
58040+ if (*curr != NULL)
58041+ (*curr)->prev = obj;
58042+
58043+ obj->next = *curr;
58044+ *curr = obj;
58045+
58046+ return;
58047+}
58048+
58049+static void
58050+insert_acl_subj_label(struct acl_subject_label *obj,
58051+ struct acl_role_label *role)
58052+{
58053+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58054+ struct acl_subject_label **curr;
58055+
58056+ obj->prev = NULL;
58057+
58058+ curr = &role->subj_hash[index];
58059+ if (*curr != NULL)
58060+ (*curr)->prev = obj;
58061+
58062+ obj->next = *curr;
58063+ *curr = obj;
58064+
58065+ return;
58066+}
58067+
58068+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
58069+
58070+static void *
58071+create_table(__u32 * len, int elementsize)
58072+{
58073+ unsigned int table_sizes[] = {
58074+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
58075+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
58076+ 4194301, 8388593, 16777213, 33554393, 67108859
58077+ };
58078+ void *newtable = NULL;
58079+ unsigned int pwr = 0;
58080+
58081+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
58082+ table_sizes[pwr] <= *len)
58083+ pwr++;
58084+
58085+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
58086+ return newtable;
58087+
58088+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
58089+ newtable =
58090+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
58091+ else
58092+ newtable = vmalloc(table_sizes[pwr] * elementsize);
58093+
58094+ *len = table_sizes[pwr];
58095+
58096+ return newtable;
58097+}
58098+
58099+static int
58100+init_variables(const struct gr_arg *arg)
58101+{
58102+ struct task_struct *reaper = init_pid_ns.child_reaper;
58103+ unsigned int stacksize;
58104+
58105+ subj_map_set.s_size = arg->role_db.num_subjects;
58106+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
58107+ name_set.n_size = arg->role_db.num_objects;
58108+ inodev_set.i_size = arg->role_db.num_objects;
58109+
58110+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
58111+ !name_set.n_size || !inodev_set.i_size)
58112+ return 1;
58113+
58114+ if (!gr_init_uidset())
58115+ return 1;
58116+
58117+ /* set up the stack that holds allocation info */
58118+
58119+ stacksize = arg->role_db.num_pointers + 5;
58120+
58121+ if (!acl_alloc_stack_init(stacksize))
58122+ return 1;
58123+
58124+ /* grab reference for the real root dentry and vfsmount */
58125+ get_fs_root(reaper->fs, &real_root);
58126+
58127+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58128+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
58129+#endif
58130+
58131+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
58132+ if (fakefs_obj_rw == NULL)
58133+ return 1;
58134+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
58135+
58136+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
58137+ if (fakefs_obj_rwx == NULL)
58138+ return 1;
58139+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
58140+
58141+ subj_map_set.s_hash =
58142+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
58143+ acl_role_set.r_hash =
58144+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
58145+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
58146+ inodev_set.i_hash =
58147+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
58148+
58149+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
58150+ !name_set.n_hash || !inodev_set.i_hash)
58151+ return 1;
58152+
58153+ memset(subj_map_set.s_hash, 0,
58154+ sizeof(struct subject_map *) * subj_map_set.s_size);
58155+ memset(acl_role_set.r_hash, 0,
58156+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
58157+ memset(name_set.n_hash, 0,
58158+ sizeof (struct name_entry *) * name_set.n_size);
58159+ memset(inodev_set.i_hash, 0,
58160+ sizeof (struct inodev_entry *) * inodev_set.i_size);
58161+
58162+ return 0;
58163+}
58164+
58165+/* free information not needed after startup
58166+ currently contains user->kernel pointer mappings for subjects
58167+*/
58168+
58169+static void
58170+free_init_variables(void)
58171+{
58172+ __u32 i;
58173+
58174+ if (subj_map_set.s_hash) {
58175+ for (i = 0; i < subj_map_set.s_size; i++) {
58176+ if (subj_map_set.s_hash[i]) {
58177+ kfree(subj_map_set.s_hash[i]);
58178+ subj_map_set.s_hash[i] = NULL;
58179+ }
58180+ }
58181+
58182+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
58183+ PAGE_SIZE)
58184+ kfree(subj_map_set.s_hash);
58185+ else
58186+ vfree(subj_map_set.s_hash);
58187+ }
58188+
58189+ return;
58190+}
58191+
58192+static void
58193+free_variables(void)
58194+{
58195+ struct acl_subject_label *s;
58196+ struct acl_role_label *r;
58197+ struct task_struct *task, *task2;
58198+ unsigned int x;
58199+
58200+ gr_clear_learn_entries();
58201+
58202+ read_lock(&tasklist_lock);
58203+ do_each_thread(task2, task) {
58204+ task->acl_sp_role = 0;
58205+ task->acl_role_id = 0;
58206+ task->acl = NULL;
58207+ task->role = NULL;
58208+ } while_each_thread(task2, task);
58209+ read_unlock(&tasklist_lock);
58210+
58211+ /* release the reference to the real root dentry and vfsmount */
58212+ path_put(&real_root);
58213+ memset(&real_root, 0, sizeof(real_root));
58214+
58215+ /* free all object hash tables */
58216+
58217+ FOR_EACH_ROLE_START(r)
58218+ if (r->subj_hash == NULL)
58219+ goto next_role;
58220+ FOR_EACH_SUBJECT_START(r, s, x)
58221+ if (s->obj_hash == NULL)
58222+ break;
58223+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58224+ kfree(s->obj_hash);
58225+ else
58226+ vfree(s->obj_hash);
58227+ FOR_EACH_SUBJECT_END(s, x)
58228+ FOR_EACH_NESTED_SUBJECT_START(r, s)
58229+ if (s->obj_hash == NULL)
58230+ break;
58231+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58232+ kfree(s->obj_hash);
58233+ else
58234+ vfree(s->obj_hash);
58235+ FOR_EACH_NESTED_SUBJECT_END(s)
58236+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
58237+ kfree(r->subj_hash);
58238+ else
58239+ vfree(r->subj_hash);
58240+ r->subj_hash = NULL;
58241+next_role:
58242+ FOR_EACH_ROLE_END(r)
58243+
58244+ acl_free_all();
58245+
58246+ if (acl_role_set.r_hash) {
58247+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
58248+ PAGE_SIZE)
58249+ kfree(acl_role_set.r_hash);
58250+ else
58251+ vfree(acl_role_set.r_hash);
58252+ }
58253+ if (name_set.n_hash) {
58254+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
58255+ PAGE_SIZE)
58256+ kfree(name_set.n_hash);
58257+ else
58258+ vfree(name_set.n_hash);
58259+ }
58260+
58261+ if (inodev_set.i_hash) {
58262+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
58263+ PAGE_SIZE)
58264+ kfree(inodev_set.i_hash);
58265+ else
58266+ vfree(inodev_set.i_hash);
58267+ }
58268+
58269+ gr_free_uidset();
58270+
58271+ memset(&name_set, 0, sizeof (struct name_db));
58272+ memset(&inodev_set, 0, sizeof (struct inodev_db));
58273+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
58274+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
58275+
58276+ default_role = NULL;
58277+ kernel_role = NULL;
58278+ role_list = NULL;
58279+
58280+ return;
58281+}
58282+
58283+static __u32
58284+count_user_objs(struct acl_object_label *userp)
58285+{
58286+ struct acl_object_label o_tmp;
58287+ __u32 num = 0;
58288+
58289+ while (userp) {
58290+ if (copy_from_user(&o_tmp, userp,
58291+ sizeof (struct acl_object_label)))
58292+ break;
58293+
58294+ userp = o_tmp.prev;
58295+ num++;
58296+ }
58297+
58298+ return num;
58299+}
58300+
58301+static struct acl_subject_label *
58302+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
58303+
58304+static int
58305+copy_user_glob(struct acl_object_label *obj)
58306+{
58307+ struct acl_object_label *g_tmp, **guser;
58308+ unsigned int len;
58309+ char *tmp;
58310+
58311+ if (obj->globbed == NULL)
58312+ return 0;
58313+
58314+ guser = &obj->globbed;
58315+ while (*guser) {
58316+ g_tmp = (struct acl_object_label *)
58317+ acl_alloc(sizeof (struct acl_object_label));
58318+ if (g_tmp == NULL)
58319+ return -ENOMEM;
58320+
58321+ if (copy_from_user(g_tmp, *guser,
58322+ sizeof (struct acl_object_label)))
58323+ return -EFAULT;
58324+
58325+ len = strnlen_user(g_tmp->filename, PATH_MAX);
58326+
58327+ if (!len || len >= PATH_MAX)
58328+ return -EINVAL;
58329+
58330+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58331+ return -ENOMEM;
58332+
58333+ if (copy_from_user(tmp, g_tmp->filename, len))
58334+ return -EFAULT;
58335+ tmp[len-1] = '\0';
58336+ g_tmp->filename = tmp;
58337+
58338+ *guser = g_tmp;
58339+ guser = &(g_tmp->next);
58340+ }
58341+
58342+ return 0;
58343+}
58344+
58345+static int
58346+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
58347+ struct acl_role_label *role)
58348+{
58349+ struct acl_object_label *o_tmp;
58350+ unsigned int len;
58351+ int ret;
58352+ char *tmp;
58353+
58354+ while (userp) {
58355+ if ((o_tmp = (struct acl_object_label *)
58356+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
58357+ return -ENOMEM;
58358+
58359+ if (copy_from_user(o_tmp, userp,
58360+ sizeof (struct acl_object_label)))
58361+ return -EFAULT;
58362+
58363+ userp = o_tmp->prev;
58364+
58365+ len = strnlen_user(o_tmp->filename, PATH_MAX);
58366+
58367+ if (!len || len >= PATH_MAX)
58368+ return -EINVAL;
58369+
58370+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58371+ return -ENOMEM;
58372+
58373+ if (copy_from_user(tmp, o_tmp->filename, len))
58374+ return -EFAULT;
58375+ tmp[len-1] = '\0';
58376+ o_tmp->filename = tmp;
58377+
58378+ insert_acl_obj_label(o_tmp, subj);
58379+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
58380+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
58381+ return -ENOMEM;
58382+
58383+ ret = copy_user_glob(o_tmp);
58384+ if (ret)
58385+ return ret;
58386+
58387+ if (o_tmp->nested) {
58388+ int already_copied;
58389+
58390+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
58391+ if (IS_ERR(o_tmp->nested))
58392+ return PTR_ERR(o_tmp->nested);
58393+
58394+ /* insert into nested subject list if we haven't copied this one yet
58395+ to prevent duplicate entries */
58396+ if (!already_copied) {
58397+ o_tmp->nested->next = role->hash->first;
58398+ role->hash->first = o_tmp->nested;
58399+ }
58400+ }
58401+ }
58402+
58403+ return 0;
58404+}
58405+
58406+static __u32
58407+count_user_subjs(struct acl_subject_label *userp)
58408+{
58409+ struct acl_subject_label s_tmp;
58410+ __u32 num = 0;
58411+
58412+ while (userp) {
58413+ if (copy_from_user(&s_tmp, userp,
58414+ sizeof (struct acl_subject_label)))
58415+ break;
58416+
58417+ userp = s_tmp.prev;
58418+ }
58419+
58420+ return num;
58421+}
58422+
58423+static int
58424+copy_user_allowedips(struct acl_role_label *rolep)
58425+{
58426+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
58427+
58428+ ruserip = rolep->allowed_ips;
58429+
58430+ while (ruserip) {
58431+ rlast = rtmp;
58432+
58433+ if ((rtmp = (struct role_allowed_ip *)
58434+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
58435+ return -ENOMEM;
58436+
58437+ if (copy_from_user(rtmp, ruserip,
58438+ sizeof (struct role_allowed_ip)))
58439+ return -EFAULT;
58440+
58441+ ruserip = rtmp->prev;
58442+
58443+ if (!rlast) {
58444+ rtmp->prev = NULL;
58445+ rolep->allowed_ips = rtmp;
58446+ } else {
58447+ rlast->next = rtmp;
58448+ rtmp->prev = rlast;
58449+ }
58450+
58451+ if (!ruserip)
58452+ rtmp->next = NULL;
58453+ }
58454+
58455+ return 0;
58456+}
58457+
58458+static int
58459+copy_user_transitions(struct acl_role_label *rolep)
58460+{
58461+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
58462+
58463+ unsigned int len;
58464+ char *tmp;
58465+
58466+ rusertp = rolep->transitions;
58467+
58468+ while (rusertp) {
58469+ rlast = rtmp;
58470+
58471+ if ((rtmp = (struct role_transition *)
58472+ acl_alloc(sizeof (struct role_transition))) == NULL)
58473+ return -ENOMEM;
58474+
58475+ if (copy_from_user(rtmp, rusertp,
58476+ sizeof (struct role_transition)))
58477+ return -EFAULT;
58478+
58479+ rusertp = rtmp->prev;
58480+
58481+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
58482+
58483+ if (!len || len >= GR_SPROLE_LEN)
58484+ return -EINVAL;
58485+
58486+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58487+ return -ENOMEM;
58488+
58489+ if (copy_from_user(tmp, rtmp->rolename, len))
58490+ return -EFAULT;
58491+ tmp[len-1] = '\0';
58492+ rtmp->rolename = tmp;
58493+
58494+ if (!rlast) {
58495+ rtmp->prev = NULL;
58496+ rolep->transitions = rtmp;
58497+ } else {
58498+ rlast->next = rtmp;
58499+ rtmp->prev = rlast;
58500+ }
58501+
58502+ if (!rusertp)
58503+ rtmp->next = NULL;
58504+ }
58505+
58506+ return 0;
58507+}
58508+
58509+static struct acl_subject_label *
58510+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58511+{
58512+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58513+ unsigned int len;
58514+ char *tmp;
58515+ __u32 num_objs;
58516+ struct acl_ip_label **i_tmp, *i_utmp2;
58517+ struct gr_hash_struct ghash;
58518+ struct subject_map *subjmap;
58519+ unsigned int i_num;
58520+ int err;
58521+
58522+ if (already_copied != NULL)
58523+ *already_copied = 0;
58524+
58525+ s_tmp = lookup_subject_map(userp);
58526+
58527+ /* we've already copied this subject into the kernel, just return
58528+ the reference to it, and don't copy it over again
58529+ */
58530+ if (s_tmp) {
58531+ if (already_copied != NULL)
58532+ *already_copied = 1;
58533+ return(s_tmp);
58534+ }
58535+
58536+ if ((s_tmp = (struct acl_subject_label *)
58537+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58538+ return ERR_PTR(-ENOMEM);
58539+
58540+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58541+ if (subjmap == NULL)
58542+ return ERR_PTR(-ENOMEM);
58543+
58544+ subjmap->user = userp;
58545+ subjmap->kernel = s_tmp;
58546+ insert_subj_map_entry(subjmap);
58547+
58548+ if (copy_from_user(s_tmp, userp,
58549+ sizeof (struct acl_subject_label)))
58550+ return ERR_PTR(-EFAULT);
58551+
58552+ len = strnlen_user(s_tmp->filename, PATH_MAX);
58553+
58554+ if (!len || len >= PATH_MAX)
58555+ return ERR_PTR(-EINVAL);
58556+
58557+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58558+ return ERR_PTR(-ENOMEM);
58559+
58560+ if (copy_from_user(tmp, s_tmp->filename, len))
58561+ return ERR_PTR(-EFAULT);
58562+ tmp[len-1] = '\0';
58563+ s_tmp->filename = tmp;
58564+
58565+ if (!strcmp(s_tmp->filename, "/"))
58566+ role->root_label = s_tmp;
58567+
58568+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58569+ return ERR_PTR(-EFAULT);
58570+
58571+ /* copy user and group transition tables */
58572+
58573+ if (s_tmp->user_trans_num) {
58574+ uid_t *uidlist;
58575+
58576+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58577+ if (uidlist == NULL)
58578+ return ERR_PTR(-ENOMEM);
58579+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58580+ return ERR_PTR(-EFAULT);
58581+
58582+ s_tmp->user_transitions = uidlist;
58583+ }
58584+
58585+ if (s_tmp->group_trans_num) {
58586+ gid_t *gidlist;
58587+
58588+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58589+ if (gidlist == NULL)
58590+ return ERR_PTR(-ENOMEM);
58591+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58592+ return ERR_PTR(-EFAULT);
58593+
58594+ s_tmp->group_transitions = gidlist;
58595+ }
58596+
58597+ /* set up object hash table */
58598+ num_objs = count_user_objs(ghash.first);
58599+
58600+ s_tmp->obj_hash_size = num_objs;
58601+ s_tmp->obj_hash =
58602+ (struct acl_object_label **)
58603+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58604+
58605+ if (!s_tmp->obj_hash)
58606+ return ERR_PTR(-ENOMEM);
58607+
58608+ memset(s_tmp->obj_hash, 0,
58609+ s_tmp->obj_hash_size *
58610+ sizeof (struct acl_object_label *));
58611+
58612+ /* add in objects */
58613+ err = copy_user_objs(ghash.first, s_tmp, role);
58614+
58615+ if (err)
58616+ return ERR_PTR(err);
58617+
58618+ /* set pointer for parent subject */
58619+ if (s_tmp->parent_subject) {
58620+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58621+
58622+ if (IS_ERR(s_tmp2))
58623+ return s_tmp2;
58624+
58625+ s_tmp->parent_subject = s_tmp2;
58626+ }
58627+
58628+ /* add in ip acls */
58629+
58630+ if (!s_tmp->ip_num) {
58631+ s_tmp->ips = NULL;
58632+ goto insert;
58633+ }
58634+
58635+ i_tmp =
58636+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58637+ sizeof (struct acl_ip_label *));
58638+
58639+ if (!i_tmp)
58640+ return ERR_PTR(-ENOMEM);
58641+
58642+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58643+ *(i_tmp + i_num) =
58644+ (struct acl_ip_label *)
58645+ acl_alloc(sizeof (struct acl_ip_label));
58646+ if (!*(i_tmp + i_num))
58647+ return ERR_PTR(-ENOMEM);
58648+
58649+ if (copy_from_user
58650+ (&i_utmp2, s_tmp->ips + i_num,
58651+ sizeof (struct acl_ip_label *)))
58652+ return ERR_PTR(-EFAULT);
58653+
58654+ if (copy_from_user
58655+ (*(i_tmp + i_num), i_utmp2,
58656+ sizeof (struct acl_ip_label)))
58657+ return ERR_PTR(-EFAULT);
58658+
58659+ if ((*(i_tmp + i_num))->iface == NULL)
58660+ continue;
58661+
58662+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58663+ if (!len || len >= IFNAMSIZ)
58664+ return ERR_PTR(-EINVAL);
58665+ tmp = acl_alloc(len);
58666+ if (tmp == NULL)
58667+ return ERR_PTR(-ENOMEM);
58668+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58669+ return ERR_PTR(-EFAULT);
58670+ (*(i_tmp + i_num))->iface = tmp;
58671+ }
58672+
58673+ s_tmp->ips = i_tmp;
58674+
58675+insert:
58676+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58677+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58678+ return ERR_PTR(-ENOMEM);
58679+
58680+ return s_tmp;
58681+}
58682+
58683+static int
58684+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58685+{
58686+ struct acl_subject_label s_pre;
58687+ struct acl_subject_label * ret;
58688+ int err;
58689+
58690+ while (userp) {
58691+ if (copy_from_user(&s_pre, userp,
58692+ sizeof (struct acl_subject_label)))
58693+ return -EFAULT;
58694+
58695+ ret = do_copy_user_subj(userp, role, NULL);
58696+
58697+ err = PTR_ERR(ret);
58698+ if (IS_ERR(ret))
58699+ return err;
58700+
58701+ insert_acl_subj_label(ret, role);
58702+
58703+ userp = s_pre.prev;
58704+ }
58705+
58706+ return 0;
58707+}
58708+
58709+static int
58710+copy_user_acl(struct gr_arg *arg)
58711+{
58712+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58713+ struct acl_subject_label *subj_list;
58714+ struct sprole_pw *sptmp;
58715+ struct gr_hash_struct *ghash;
58716+ uid_t *domainlist;
58717+ unsigned int r_num;
58718+ unsigned int len;
58719+ char *tmp;
58720+ int err = 0;
58721+ __u16 i;
58722+ __u32 num_subjs;
58723+
58724+ /* we need a default and kernel role */
58725+ if (arg->role_db.num_roles < 2)
58726+ return -EINVAL;
58727+
58728+ /* copy special role authentication info from userspace */
58729+
58730+ num_sprole_pws = arg->num_sprole_pws;
58731+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58732+
58733+ if (!acl_special_roles && num_sprole_pws)
58734+ return -ENOMEM;
58735+
58736+ for (i = 0; i < num_sprole_pws; i++) {
58737+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58738+ if (!sptmp)
58739+ return -ENOMEM;
58740+ if (copy_from_user(sptmp, arg->sprole_pws + i,
58741+ sizeof (struct sprole_pw)))
58742+ return -EFAULT;
58743+
58744+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58745+
58746+ if (!len || len >= GR_SPROLE_LEN)
58747+ return -EINVAL;
58748+
58749+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58750+ return -ENOMEM;
58751+
58752+ if (copy_from_user(tmp, sptmp->rolename, len))
58753+ return -EFAULT;
58754+
58755+ tmp[len-1] = '\0';
58756+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58757+ printk(KERN_ALERT "Copying special role %s\n", tmp);
58758+#endif
58759+ sptmp->rolename = tmp;
58760+ acl_special_roles[i] = sptmp;
58761+ }
58762+
58763+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58764+
58765+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58766+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
58767+
58768+ if (!r_tmp)
58769+ return -ENOMEM;
58770+
58771+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
58772+ sizeof (struct acl_role_label *)))
58773+ return -EFAULT;
58774+
58775+ if (copy_from_user(r_tmp, r_utmp2,
58776+ sizeof (struct acl_role_label)))
58777+ return -EFAULT;
58778+
58779+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58780+
58781+ if (!len || len >= PATH_MAX)
58782+ return -EINVAL;
58783+
58784+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58785+ return -ENOMEM;
58786+
58787+ if (copy_from_user(tmp, r_tmp->rolename, len))
58788+ return -EFAULT;
58789+
58790+ tmp[len-1] = '\0';
58791+ r_tmp->rolename = tmp;
58792+
58793+ if (!strcmp(r_tmp->rolename, "default")
58794+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58795+ default_role = r_tmp;
58796+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58797+ kernel_role = r_tmp;
58798+ }
58799+
58800+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58801+ return -ENOMEM;
58802+
58803+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58804+ return -EFAULT;
58805+
58806+ r_tmp->hash = ghash;
58807+
58808+ num_subjs = count_user_subjs(r_tmp->hash->first);
58809+
58810+ r_tmp->subj_hash_size = num_subjs;
58811+ r_tmp->subj_hash =
58812+ (struct acl_subject_label **)
58813+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58814+
58815+ if (!r_tmp->subj_hash)
58816+ return -ENOMEM;
58817+
58818+ err = copy_user_allowedips(r_tmp);
58819+ if (err)
58820+ return err;
58821+
58822+ /* copy domain info */
58823+ if (r_tmp->domain_children != NULL) {
58824+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58825+ if (domainlist == NULL)
58826+ return -ENOMEM;
58827+
58828+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58829+ return -EFAULT;
58830+
58831+ r_tmp->domain_children = domainlist;
58832+ }
58833+
58834+ err = copy_user_transitions(r_tmp);
58835+ if (err)
58836+ return err;
58837+
58838+ memset(r_tmp->subj_hash, 0,
58839+ r_tmp->subj_hash_size *
58840+ sizeof (struct acl_subject_label *));
58841+
58842+ /* acquire the list of subjects, then NULL out
58843+ the list prior to parsing the subjects for this role,
58844+ as during this parsing the list is replaced with a list
58845+ of *nested* subjects for the role
58846+ */
58847+ subj_list = r_tmp->hash->first;
58848+
58849+ /* set nested subject list to null */
58850+ r_tmp->hash->first = NULL;
58851+
58852+ err = copy_user_subjs(subj_list, r_tmp);
58853+
58854+ if (err)
58855+ return err;
58856+
58857+ insert_acl_role_label(r_tmp);
58858+ }
58859+
58860+ if (default_role == NULL || kernel_role == NULL)
58861+ return -EINVAL;
58862+
58863+ return err;
58864+}
58865+
58866+static int
58867+gracl_init(struct gr_arg *args)
58868+{
58869+ int error = 0;
58870+
58871+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58872+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58873+
58874+ if (init_variables(args)) {
58875+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58876+ error = -ENOMEM;
58877+ free_variables();
58878+ goto out;
58879+ }
58880+
58881+ error = copy_user_acl(args);
58882+ free_init_variables();
58883+ if (error) {
58884+ free_variables();
58885+ goto out;
58886+ }
58887+
58888+ if ((error = gr_set_acls(0))) {
58889+ free_variables();
58890+ goto out;
58891+ }
58892+
58893+ pax_open_kernel();
58894+ gr_status |= GR_READY;
58895+ pax_close_kernel();
58896+
58897+ out:
58898+ return error;
58899+}
58900+
58901+/* derived from glibc fnmatch() 0: match, 1: no match*/
58902+
58903+static int
58904+glob_match(const char *p, const char *n)
58905+{
58906+ char c;
58907+
58908+ while ((c = *p++) != '\0') {
58909+ switch (c) {
58910+ case '?':
58911+ if (*n == '\0')
58912+ return 1;
58913+ else if (*n == '/')
58914+ return 1;
58915+ break;
58916+ case '\\':
58917+ if (*n != c)
58918+ return 1;
58919+ break;
58920+ case '*':
58921+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
58922+ if (*n == '/')
58923+ return 1;
58924+ else if (c == '?') {
58925+ if (*n == '\0')
58926+ return 1;
58927+ else
58928+ ++n;
58929+ }
58930+ }
58931+ if (c == '\0') {
58932+ return 0;
58933+ } else {
58934+ const char *endp;
58935+
58936+ if ((endp = strchr(n, '/')) == NULL)
58937+ endp = n + strlen(n);
58938+
58939+ if (c == '[') {
58940+ for (--p; n < endp; ++n)
58941+ if (!glob_match(p, n))
58942+ return 0;
58943+ } else if (c == '/') {
58944+ while (*n != '\0' && *n != '/')
58945+ ++n;
58946+ if (*n == '/' && !glob_match(p, n + 1))
58947+ return 0;
58948+ } else {
58949+ for (--p; n < endp; ++n)
58950+ if (*n == c && !glob_match(p, n))
58951+ return 0;
58952+ }
58953+
58954+ return 1;
58955+ }
58956+ case '[':
58957+ {
58958+ int not;
58959+ char cold;
58960+
58961+ if (*n == '\0' || *n == '/')
58962+ return 1;
58963+
58964+ not = (*p == '!' || *p == '^');
58965+ if (not)
58966+ ++p;
58967+
58968+ c = *p++;
58969+ for (;;) {
58970+ unsigned char fn = (unsigned char)*n;
58971+
58972+ if (c == '\0')
58973+ return 1;
58974+ else {
58975+ if (c == fn)
58976+ goto matched;
58977+ cold = c;
58978+ c = *p++;
58979+
58980+ if (c == '-' && *p != ']') {
58981+ unsigned char cend = *p++;
58982+
58983+ if (cend == '\0')
58984+ return 1;
58985+
58986+ if (cold <= fn && fn <= cend)
58987+ goto matched;
58988+
58989+ c = *p++;
58990+ }
58991+ }
58992+
58993+ if (c == ']')
58994+ break;
58995+ }
58996+ if (!not)
58997+ return 1;
58998+ break;
58999+ matched:
59000+ while (c != ']') {
59001+ if (c == '\0')
59002+ return 1;
59003+
59004+ c = *p++;
59005+ }
59006+ if (not)
59007+ return 1;
59008+ }
59009+ break;
59010+ default:
59011+ if (c != *n)
59012+ return 1;
59013+ }
59014+
59015+ ++n;
59016+ }
59017+
59018+ if (*n == '\0')
59019+ return 0;
59020+
59021+ if (*n == '/')
59022+ return 0;
59023+
59024+ return 1;
59025+}
59026+
59027+static struct acl_object_label *
59028+chk_glob_label(struct acl_object_label *globbed,
59029+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59030+{
59031+ struct acl_object_label *tmp;
59032+
59033+ if (*path == NULL)
59034+ *path = gr_to_filename_nolock(dentry, mnt);
59035+
59036+ tmp = globbed;
59037+
59038+ while (tmp) {
59039+ if (!glob_match(tmp->filename, *path))
59040+ return tmp;
59041+ tmp = tmp->next;
59042+ }
59043+
59044+ return NULL;
59045+}
59046+
59047+static struct acl_object_label *
59048+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59049+ const ino_t curr_ino, const dev_t curr_dev,
59050+ const struct acl_subject_label *subj, char **path, const int checkglob)
59051+{
59052+ struct acl_subject_label *tmpsubj;
59053+ struct acl_object_label *retval;
59054+ struct acl_object_label *retval2;
59055+
59056+ tmpsubj = (struct acl_subject_label *) subj;
59057+ read_lock(&gr_inode_lock);
59058+ do {
59059+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59060+ if (retval) {
59061+ if (checkglob && retval->globbed) {
59062+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
59063+ if (retval2)
59064+ retval = retval2;
59065+ }
59066+ break;
59067+ }
59068+ } while ((tmpsubj = tmpsubj->parent_subject));
59069+ read_unlock(&gr_inode_lock);
59070+
59071+ return retval;
59072+}
59073+
59074+static __inline__ struct acl_object_label *
59075+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59076+ struct dentry *curr_dentry,
59077+ const struct acl_subject_label *subj, char **path, const int checkglob)
59078+{
59079+ int newglob = checkglob;
59080+ ino_t inode;
59081+ dev_t device;
59082+
59083+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
59084+ as we don't want a / * rule to match instead of the / object
59085+ don't do this for create lookups that call this function though, since they're looking up
59086+ on the parent and thus need globbing checks on all paths
59087+ */
59088+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
59089+ newglob = GR_NO_GLOB;
59090+
59091+ spin_lock(&curr_dentry->d_lock);
59092+ inode = curr_dentry->d_inode->i_ino;
59093+ device = __get_dev(curr_dentry);
59094+ spin_unlock(&curr_dentry->d_lock);
59095+
59096+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
59097+}
59098+
59099+#ifdef CONFIG_HUGETLBFS
59100+static inline bool
59101+is_hugetlbfs_mnt(const struct vfsmount *mnt)
59102+{
59103+ int i;
59104+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
59105+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
59106+ return true;
59107+ }
59108+
59109+ return false;
59110+}
59111+#endif
59112+
59113+static struct acl_object_label *
59114+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59115+ const struct acl_subject_label *subj, char *path, const int checkglob)
59116+{
59117+ struct dentry *dentry = (struct dentry *) l_dentry;
59118+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59119+ struct mount *real_mnt = real_mount(mnt);
59120+ struct acl_object_label *retval;
59121+ struct dentry *parent;
59122+
59123+ write_seqlock(&rename_lock);
59124+ br_read_lock(&vfsmount_lock);
59125+
59126+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
59127+#ifdef CONFIG_NET
59128+ mnt == sock_mnt ||
59129+#endif
59130+#ifdef CONFIG_HUGETLBFS
59131+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
59132+#endif
59133+ /* ignore Eric Biederman */
59134+ IS_PRIVATE(l_dentry->d_inode))) {
59135+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
59136+ goto out;
59137+ }
59138+
59139+ for (;;) {
59140+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59141+ break;
59142+
59143+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59144+ if (!mnt_has_parent(real_mnt))
59145+ break;
59146+
59147+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59148+ if (retval != NULL)
59149+ goto out;
59150+
59151+ dentry = real_mnt->mnt_mountpoint;
59152+ real_mnt = real_mnt->mnt_parent;
59153+ mnt = &real_mnt->mnt;
59154+ continue;
59155+ }
59156+
59157+ parent = dentry->d_parent;
59158+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59159+ if (retval != NULL)
59160+ goto out;
59161+
59162+ dentry = parent;
59163+ }
59164+
59165+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59166+
59167+ /* real_root is pinned so we don't have to hold a reference */
59168+ if (retval == NULL)
59169+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
59170+out:
59171+ br_read_unlock(&vfsmount_lock);
59172+ write_sequnlock(&rename_lock);
59173+
59174+ BUG_ON(retval == NULL);
59175+
59176+ return retval;
59177+}
59178+
59179+static __inline__ struct acl_object_label *
59180+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59181+ const struct acl_subject_label *subj)
59182+{
59183+ char *path = NULL;
59184+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
59185+}
59186+
59187+static __inline__ struct acl_object_label *
59188+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59189+ const struct acl_subject_label *subj)
59190+{
59191+ char *path = NULL;
59192+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
59193+}
59194+
59195+static __inline__ struct acl_object_label *
59196+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59197+ const struct acl_subject_label *subj, char *path)
59198+{
59199+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
59200+}
59201+
59202+static struct acl_subject_label *
59203+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59204+ const struct acl_role_label *role)
59205+{
59206+ struct dentry *dentry = (struct dentry *) l_dentry;
59207+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59208+ struct mount *real_mnt = real_mount(mnt);
59209+ struct acl_subject_label *retval;
59210+ struct dentry *parent;
59211+
59212+ write_seqlock(&rename_lock);
59213+ br_read_lock(&vfsmount_lock);
59214+
59215+ for (;;) {
59216+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59217+ break;
59218+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59219+ if (!mnt_has_parent(real_mnt))
59220+ break;
59221+
59222+ spin_lock(&dentry->d_lock);
59223+ read_lock(&gr_inode_lock);
59224+ retval =
59225+ lookup_acl_subj_label(dentry->d_inode->i_ino,
59226+ __get_dev(dentry), role);
59227+ read_unlock(&gr_inode_lock);
59228+ spin_unlock(&dentry->d_lock);
59229+ if (retval != NULL)
59230+ goto out;
59231+
59232+ dentry = real_mnt->mnt_mountpoint;
59233+ real_mnt = real_mnt->mnt_parent;
59234+ mnt = &real_mnt->mnt;
59235+ continue;
59236+ }
59237+
59238+ spin_lock(&dentry->d_lock);
59239+ read_lock(&gr_inode_lock);
59240+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59241+ __get_dev(dentry), role);
59242+ read_unlock(&gr_inode_lock);
59243+ parent = dentry->d_parent;
59244+ spin_unlock(&dentry->d_lock);
59245+
59246+ if (retval != NULL)
59247+ goto out;
59248+
59249+ dentry = parent;
59250+ }
59251+
59252+ spin_lock(&dentry->d_lock);
59253+ read_lock(&gr_inode_lock);
59254+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59255+ __get_dev(dentry), role);
59256+ read_unlock(&gr_inode_lock);
59257+ spin_unlock(&dentry->d_lock);
59258+
59259+ if (unlikely(retval == NULL)) {
59260+ /* real_root is pinned, we don't need to hold a reference */
59261+ read_lock(&gr_inode_lock);
59262+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
59263+ __get_dev(real_root.dentry), role);
59264+ read_unlock(&gr_inode_lock);
59265+ }
59266+out:
59267+ br_read_unlock(&vfsmount_lock);
59268+ write_sequnlock(&rename_lock);
59269+
59270+ BUG_ON(retval == NULL);
59271+
59272+ return retval;
59273+}
59274+
59275+static void
59276+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
59277+{
59278+ struct task_struct *task = current;
59279+ const struct cred *cred = current_cred();
59280+
59281+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
59282+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59283+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59284+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
59285+
59286+ return;
59287+}
59288+
59289+static void
59290+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
59291+{
59292+ struct task_struct *task = current;
59293+ const struct cred *cred = current_cred();
59294+
59295+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59296+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59297+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59298+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
59299+
59300+ return;
59301+}
59302+
59303+static void
59304+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
59305+{
59306+ struct task_struct *task = current;
59307+ const struct cred *cred = current_cred();
59308+
59309+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59310+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59311+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59312+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
59313+
59314+ return;
59315+}
59316+
59317+__u32
59318+gr_search_file(const struct dentry * dentry, const __u32 mode,
59319+ const struct vfsmount * mnt)
59320+{
59321+ __u32 retval = mode;
59322+ struct acl_subject_label *curracl;
59323+ struct acl_object_label *currobj;
59324+
59325+ if (unlikely(!(gr_status & GR_READY)))
59326+ return (mode & ~GR_AUDITS);
59327+
59328+ curracl = current->acl;
59329+
59330+ currobj = chk_obj_label(dentry, mnt, curracl);
59331+ retval = currobj->mode & mode;
59332+
59333+ /* if we're opening a specified transfer file for writing
59334+ (e.g. /dev/initctl), then transfer our role to init
59335+ */
59336+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
59337+ current->role->roletype & GR_ROLE_PERSIST)) {
59338+ struct task_struct *task = init_pid_ns.child_reaper;
59339+
59340+ if (task->role != current->role) {
59341+ task->acl_sp_role = 0;
59342+ task->acl_role_id = current->acl_role_id;
59343+ task->role = current->role;
59344+ rcu_read_lock();
59345+ read_lock(&grsec_exec_file_lock);
59346+ gr_apply_subject_to_task(task);
59347+ read_unlock(&grsec_exec_file_lock);
59348+ rcu_read_unlock();
59349+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
59350+ }
59351+ }
59352+
59353+ if (unlikely
59354+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
59355+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
59356+ __u32 new_mode = mode;
59357+
59358+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59359+
59360+ retval = new_mode;
59361+
59362+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
59363+ new_mode |= GR_INHERIT;
59364+
59365+ if (!(mode & GR_NOLEARN))
59366+ gr_log_learn(dentry, mnt, new_mode);
59367+ }
59368+
59369+ return retval;
59370+}
59371+
59372+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
59373+ const struct dentry *parent,
59374+ const struct vfsmount *mnt)
59375+{
59376+ struct name_entry *match;
59377+ struct acl_object_label *matchpo;
59378+ struct acl_subject_label *curracl;
59379+ char *path;
59380+
59381+ if (unlikely(!(gr_status & GR_READY)))
59382+ return NULL;
59383+
59384+ preempt_disable();
59385+ path = gr_to_filename_rbac(new_dentry, mnt);
59386+ match = lookup_name_entry_create(path);
59387+
59388+ curracl = current->acl;
59389+
59390+ if (match) {
59391+ read_lock(&gr_inode_lock);
59392+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
59393+ read_unlock(&gr_inode_lock);
59394+
59395+ if (matchpo) {
59396+ preempt_enable();
59397+ return matchpo;
59398+ }
59399+ }
59400+
59401+ // lookup parent
59402+
59403+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
59404+
59405+ preempt_enable();
59406+ return matchpo;
59407+}
59408+
59409+__u32
59410+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
59411+ const struct vfsmount * mnt, const __u32 mode)
59412+{
59413+ struct acl_object_label *matchpo;
59414+ __u32 retval;
59415+
59416+ if (unlikely(!(gr_status & GR_READY)))
59417+ return (mode & ~GR_AUDITS);
59418+
59419+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
59420+
59421+ retval = matchpo->mode & mode;
59422+
59423+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
59424+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59425+ __u32 new_mode = mode;
59426+
59427+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59428+
59429+ gr_log_learn(new_dentry, mnt, new_mode);
59430+ return new_mode;
59431+ }
59432+
59433+ return retval;
59434+}
59435+
59436+__u32
59437+gr_check_link(const struct dentry * new_dentry,
59438+ const struct dentry * parent_dentry,
59439+ const struct vfsmount * parent_mnt,
59440+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
59441+{
59442+ struct acl_object_label *obj;
59443+ __u32 oldmode, newmode;
59444+ __u32 needmode;
59445+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
59446+ GR_DELETE | GR_INHERIT;
59447+
59448+ if (unlikely(!(gr_status & GR_READY)))
59449+ return (GR_CREATE | GR_LINK);
59450+
59451+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
59452+ oldmode = obj->mode;
59453+
59454+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
59455+ newmode = obj->mode;
59456+
59457+ needmode = newmode & checkmodes;
59458+
59459+ // old name for hardlink must have at least the permissions of the new name
59460+ if ((oldmode & needmode) != needmode)
59461+ goto bad;
59462+
59463+ // if old name had restrictions/auditing, make sure the new name does as well
59464+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
59465+
59466+ // don't allow hardlinking of suid/sgid/fcapped files without permission
59467+ if (is_privileged_binary(old_dentry))
59468+ needmode |= GR_SETID;
59469+
59470+ if ((newmode & needmode) != needmode)
59471+ goto bad;
59472+
59473+ // enforce minimum permissions
59474+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
59475+ return newmode;
59476+bad:
59477+ needmode = oldmode;
59478+ if (is_privileged_binary(old_dentry))
59479+ needmode |= GR_SETID;
59480+
59481+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
59482+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
59483+ return (GR_CREATE | GR_LINK);
59484+ } else if (newmode & GR_SUPPRESS)
59485+ return GR_SUPPRESS;
59486+ else
59487+ return 0;
59488+}
59489+
59490+int
59491+gr_check_hidden_task(const struct task_struct *task)
59492+{
59493+ if (unlikely(!(gr_status & GR_READY)))
59494+ return 0;
59495+
59496+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59497+ return 1;
59498+
59499+ return 0;
59500+}
59501+
59502+int
59503+gr_check_protected_task(const struct task_struct *task)
59504+{
59505+ if (unlikely(!(gr_status & GR_READY) || !task))
59506+ return 0;
59507+
59508+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59509+ task->acl != current->acl)
59510+ return 1;
59511+
59512+ return 0;
59513+}
59514+
59515+int
59516+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59517+{
59518+ struct task_struct *p;
59519+ int ret = 0;
59520+
59521+ if (unlikely(!(gr_status & GR_READY) || !pid))
59522+ return ret;
59523+
59524+ read_lock(&tasklist_lock);
59525+ do_each_pid_task(pid, type, p) {
59526+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59527+ p->acl != current->acl) {
59528+ ret = 1;
59529+ goto out;
59530+ }
59531+ } while_each_pid_task(pid, type, p);
59532+out:
59533+ read_unlock(&tasklist_lock);
59534+
59535+ return ret;
59536+}
59537+
59538+void
59539+gr_copy_label(struct task_struct *tsk)
59540+{
59541+ tsk->signal->used_accept = 0;
59542+ tsk->acl_sp_role = 0;
59543+ tsk->acl_role_id = current->acl_role_id;
59544+ tsk->acl = current->acl;
59545+ tsk->role = current->role;
59546+ tsk->signal->curr_ip = current->signal->curr_ip;
59547+ tsk->signal->saved_ip = current->signal->saved_ip;
59548+ if (current->exec_file)
59549+ get_file(current->exec_file);
59550+ tsk->exec_file = current->exec_file;
59551+ tsk->is_writable = current->is_writable;
59552+ if (unlikely(current->signal->used_accept)) {
59553+ current->signal->curr_ip = 0;
59554+ current->signal->saved_ip = 0;
59555+ }
59556+
59557+ return;
59558+}
59559+
59560+static void
59561+gr_set_proc_res(struct task_struct *task)
59562+{
59563+ struct acl_subject_label *proc;
59564+ unsigned short i;
59565+
59566+ proc = task->acl;
59567+
59568+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59569+ return;
59570+
59571+ for (i = 0; i < RLIM_NLIMITS; i++) {
59572+ if (!(proc->resmask & (1 << i)))
59573+ continue;
59574+
59575+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59576+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59577+
59578+ if (i == RLIMIT_CPU)
59579+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
59580+ }
59581+
59582+ return;
59583+}
59584+
59585+extern int __gr_process_user_ban(struct user_struct *user);
59586+
59587+int
59588+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59589+{
59590+ unsigned int i;
59591+ __u16 num;
59592+ uid_t *uidlist;
59593+ uid_t curuid;
59594+ int realok = 0;
59595+ int effectiveok = 0;
59596+ int fsok = 0;
59597+ uid_t globalreal, globaleffective, globalfs;
59598+
59599+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59600+ struct user_struct *user;
59601+
59602+ if (!uid_valid(real))
59603+ goto skipit;
59604+
59605+ /* find user based on global namespace */
59606+
59607+ globalreal = GR_GLOBAL_UID(real);
59608+
59609+ user = find_user(make_kuid(&init_user_ns, globalreal));
59610+ if (user == NULL)
59611+ goto skipit;
59612+
59613+ if (__gr_process_user_ban(user)) {
59614+ /* for find_user */
59615+ free_uid(user);
59616+ return 1;
59617+ }
59618+
59619+ /* for find_user */
59620+ free_uid(user);
59621+
59622+skipit:
59623+#endif
59624+
59625+ if (unlikely(!(gr_status & GR_READY)))
59626+ return 0;
59627+
59628+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59629+ gr_log_learn_uid_change(real, effective, fs);
59630+
59631+ num = current->acl->user_trans_num;
59632+ uidlist = current->acl->user_transitions;
59633+
59634+ if (uidlist == NULL)
59635+ return 0;
59636+
59637+ if (!uid_valid(real)) {
59638+ realok = 1;
59639+ globalreal = (uid_t)-1;
59640+ } else {
59641+ globalreal = GR_GLOBAL_UID(real);
59642+ }
59643+ if (!uid_valid(effective)) {
59644+ effectiveok = 1;
59645+ globaleffective = (uid_t)-1;
59646+ } else {
59647+ globaleffective = GR_GLOBAL_UID(effective);
59648+ }
59649+ if (!uid_valid(fs)) {
59650+ fsok = 1;
59651+ globalfs = (uid_t)-1;
59652+ } else {
59653+ globalfs = GR_GLOBAL_UID(fs);
59654+ }
59655+
59656+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
59657+ for (i = 0; i < num; i++) {
59658+ curuid = uidlist[i];
59659+ if (globalreal == curuid)
59660+ realok = 1;
59661+ if (globaleffective == curuid)
59662+ effectiveok = 1;
59663+ if (globalfs == curuid)
59664+ fsok = 1;
59665+ }
59666+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
59667+ for (i = 0; i < num; i++) {
59668+ curuid = uidlist[i];
59669+ if (globalreal == curuid)
59670+ break;
59671+ if (globaleffective == curuid)
59672+ break;
59673+ if (globalfs == curuid)
59674+ break;
59675+ }
59676+ /* not in deny list */
59677+ if (i == num) {
59678+ realok = 1;
59679+ effectiveok = 1;
59680+ fsok = 1;
59681+ }
59682+ }
59683+
59684+ if (realok && effectiveok && fsok)
59685+ return 0;
59686+ else {
59687+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59688+ return 1;
59689+ }
59690+}
59691+
59692+int
59693+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59694+{
59695+ unsigned int i;
59696+ __u16 num;
59697+ gid_t *gidlist;
59698+ gid_t curgid;
59699+ int realok = 0;
59700+ int effectiveok = 0;
59701+ int fsok = 0;
59702+ gid_t globalreal, globaleffective, globalfs;
59703+
59704+ if (unlikely(!(gr_status & GR_READY)))
59705+ return 0;
59706+
59707+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59708+ gr_log_learn_gid_change(real, effective, fs);
59709+
59710+ num = current->acl->group_trans_num;
59711+ gidlist = current->acl->group_transitions;
59712+
59713+ if (gidlist == NULL)
59714+ return 0;
59715+
59716+ if (!gid_valid(real)) {
59717+ realok = 1;
59718+ globalreal = (gid_t)-1;
59719+ } else {
59720+ globalreal = GR_GLOBAL_GID(real);
59721+ }
59722+ if (!gid_valid(effective)) {
59723+ effectiveok = 1;
59724+ globaleffective = (gid_t)-1;
59725+ } else {
59726+ globaleffective = GR_GLOBAL_GID(effective);
59727+ }
59728+ if (!gid_valid(fs)) {
59729+ fsok = 1;
59730+ globalfs = (gid_t)-1;
59731+ } else {
59732+ globalfs = GR_GLOBAL_GID(fs);
59733+ }
59734+
59735+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
59736+ for (i = 0; i < num; i++) {
59737+ curgid = gidlist[i];
59738+ if (globalreal == curgid)
59739+ realok = 1;
59740+ if (globaleffective == curgid)
59741+ effectiveok = 1;
59742+ if (globalfs == curgid)
59743+ fsok = 1;
59744+ }
59745+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
59746+ for (i = 0; i < num; i++) {
59747+ curgid = gidlist[i];
59748+ if (globalreal == curgid)
59749+ break;
59750+ if (globaleffective == curgid)
59751+ break;
59752+ if (globalfs == curgid)
59753+ break;
59754+ }
59755+ /* not in deny list */
59756+ if (i == num) {
59757+ realok = 1;
59758+ effectiveok = 1;
59759+ fsok = 1;
59760+ }
59761+ }
59762+
59763+ if (realok && effectiveok && fsok)
59764+ return 0;
59765+ else {
59766+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59767+ return 1;
59768+ }
59769+}
59770+
59771+extern int gr_acl_is_capable(const int cap);
59772+
59773+void
59774+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59775+{
59776+ struct acl_role_label *role = task->role;
59777+ struct acl_subject_label *subj = NULL;
59778+ struct acl_object_label *obj;
59779+ struct file *filp;
59780+ uid_t uid;
59781+ gid_t gid;
59782+
59783+ if (unlikely(!(gr_status & GR_READY)))
59784+ return;
59785+
59786+ uid = GR_GLOBAL_UID(kuid);
59787+ gid = GR_GLOBAL_GID(kgid);
59788+
59789+ filp = task->exec_file;
59790+
59791+ /* kernel process, we'll give them the kernel role */
59792+ if (unlikely(!filp)) {
59793+ task->role = kernel_role;
59794+ task->acl = kernel_role->root_label;
59795+ return;
59796+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59797+ role = lookup_acl_role_label(task, uid, gid);
59798+
59799+ /* don't change the role if we're not a privileged process */
59800+ if (role && task->role != role &&
59801+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59802+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59803+ return;
59804+
59805+ /* perform subject lookup in possibly new role
59806+ we can use this result below in the case where role == task->role
59807+ */
59808+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59809+
59810+ /* if we changed uid/gid, but result in the same role
59811+ and are using inheritance, don't lose the inherited subject
59812+ if current subject is other than what normal lookup
59813+ would result in, we arrived via inheritance, don't
59814+ lose subject
59815+ */
59816+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59817+ (subj == task->acl)))
59818+ task->acl = subj;
59819+
59820+ task->role = role;
59821+
59822+ task->is_writable = 0;
59823+
59824+ /* ignore additional mmap checks for processes that are writable
59825+ by the default ACL */
59826+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59827+ if (unlikely(obj->mode & GR_WRITE))
59828+ task->is_writable = 1;
59829+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59830+ if (unlikely(obj->mode & GR_WRITE))
59831+ task->is_writable = 1;
59832+
59833+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59834+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
59835+#endif
59836+
59837+ gr_set_proc_res(task);
59838+
59839+ return;
59840+}
59841+
59842+int
59843+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59844+ const int unsafe_flags)
59845+{
59846+ struct task_struct *task = current;
59847+ struct acl_subject_label *newacl;
59848+ struct acl_object_label *obj;
59849+ __u32 retmode;
59850+
59851+ if (unlikely(!(gr_status & GR_READY)))
59852+ return 0;
59853+
59854+ newacl = chk_subj_label(dentry, mnt, task->role);
59855+
59856+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59857+ did an exec
59858+ */
59859+ rcu_read_lock();
59860+ read_lock(&tasklist_lock);
59861+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59862+ (task->parent->acl->mode & GR_POVERRIDE))) {
59863+ read_unlock(&tasklist_lock);
59864+ rcu_read_unlock();
59865+ goto skip_check;
59866+ }
59867+ read_unlock(&tasklist_lock);
59868+ rcu_read_unlock();
59869+
59870+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59871+ !(task->role->roletype & GR_ROLE_GOD) &&
59872+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59873+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59874+ if (unsafe_flags & LSM_UNSAFE_SHARE)
59875+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59876+ else
59877+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59878+ return -EACCES;
59879+ }
59880+
59881+skip_check:
59882+
59883+ obj = chk_obj_label(dentry, mnt, task->acl);
59884+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59885+
59886+ if (!(task->acl->mode & GR_INHERITLEARN) &&
59887+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59888+ if (obj->nested)
59889+ task->acl = obj->nested;
59890+ else
59891+ task->acl = newacl;
59892+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59893+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59894+
59895+ task->is_writable = 0;
59896+
59897+ /* ignore additional mmap checks for processes that are writable
59898+ by the default ACL */
59899+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
59900+ if (unlikely(obj->mode & GR_WRITE))
59901+ task->is_writable = 1;
59902+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
59903+ if (unlikely(obj->mode & GR_WRITE))
59904+ task->is_writable = 1;
59905+
59906+ gr_set_proc_res(task);
59907+
59908+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59909+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
59910+#endif
59911+ return 0;
59912+}
59913+
59914+/* always called with valid inodev ptr */
59915+static void
59916+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59917+{
59918+ struct acl_object_label *matchpo;
59919+ struct acl_subject_label *matchps;
59920+ struct acl_subject_label *subj;
59921+ struct acl_role_label *role;
59922+ unsigned int x;
59923+
59924+ FOR_EACH_ROLE_START(role)
59925+ FOR_EACH_SUBJECT_START(role, subj, x)
59926+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59927+ matchpo->mode |= GR_DELETED;
59928+ FOR_EACH_SUBJECT_END(subj,x)
59929+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
59930+ /* nested subjects aren't in the role's subj_hash table */
59931+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59932+ matchpo->mode |= GR_DELETED;
59933+ FOR_EACH_NESTED_SUBJECT_END(subj)
59934+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59935+ matchps->mode |= GR_DELETED;
59936+ FOR_EACH_ROLE_END(role)
59937+
59938+ inodev->nentry->deleted = 1;
59939+
59940+ return;
59941+}
59942+
59943+void
59944+gr_handle_delete(const ino_t ino, const dev_t dev)
59945+{
59946+ struct inodev_entry *inodev;
59947+
59948+ if (unlikely(!(gr_status & GR_READY)))
59949+ return;
59950+
59951+ write_lock(&gr_inode_lock);
59952+ inodev = lookup_inodev_entry(ino, dev);
59953+ if (inodev != NULL)
59954+ do_handle_delete(inodev, ino, dev);
59955+ write_unlock(&gr_inode_lock);
59956+
59957+ return;
59958+}
59959+
59960+static void
59961+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59962+ const ino_t newinode, const dev_t newdevice,
59963+ struct acl_subject_label *subj)
59964+{
59965+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59966+ struct acl_object_label *match;
59967+
59968+ match = subj->obj_hash[index];
59969+
59970+ while (match && (match->inode != oldinode ||
59971+ match->device != olddevice ||
59972+ !(match->mode & GR_DELETED)))
59973+ match = match->next;
59974+
59975+ if (match && (match->inode == oldinode)
59976+ && (match->device == olddevice)
59977+ && (match->mode & GR_DELETED)) {
59978+ if (match->prev == NULL) {
59979+ subj->obj_hash[index] = match->next;
59980+ if (match->next != NULL)
59981+ match->next->prev = NULL;
59982+ } else {
59983+ match->prev->next = match->next;
59984+ if (match->next != NULL)
59985+ match->next->prev = match->prev;
59986+ }
59987+ match->prev = NULL;
59988+ match->next = NULL;
59989+ match->inode = newinode;
59990+ match->device = newdevice;
59991+ match->mode &= ~GR_DELETED;
59992+
59993+ insert_acl_obj_label(match, subj);
59994+ }
59995+
59996+ return;
59997+}
59998+
59999+static void
60000+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60001+ const ino_t newinode, const dev_t newdevice,
60002+ struct acl_role_label *role)
60003+{
60004+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60005+ struct acl_subject_label *match;
60006+
60007+ match = role->subj_hash[index];
60008+
60009+ while (match && (match->inode != oldinode ||
60010+ match->device != olddevice ||
60011+ !(match->mode & GR_DELETED)))
60012+ match = match->next;
60013+
60014+ if (match && (match->inode == oldinode)
60015+ && (match->device == olddevice)
60016+ && (match->mode & GR_DELETED)) {
60017+ if (match->prev == NULL) {
60018+ role->subj_hash[index] = match->next;
60019+ if (match->next != NULL)
60020+ match->next->prev = NULL;
60021+ } else {
60022+ match->prev->next = match->next;
60023+ if (match->next != NULL)
60024+ match->next->prev = match->prev;
60025+ }
60026+ match->prev = NULL;
60027+ match->next = NULL;
60028+ match->inode = newinode;
60029+ match->device = newdevice;
60030+ match->mode &= ~GR_DELETED;
60031+
60032+ insert_acl_subj_label(match, role);
60033+ }
60034+
60035+ return;
60036+}
60037+
60038+static void
60039+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60040+ const ino_t newinode, const dev_t newdevice)
60041+{
60042+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60043+ struct inodev_entry *match;
60044+
60045+ match = inodev_set.i_hash[index];
60046+
60047+ while (match && (match->nentry->inode != oldinode ||
60048+ match->nentry->device != olddevice || !match->nentry->deleted))
60049+ match = match->next;
60050+
60051+ if (match && (match->nentry->inode == oldinode)
60052+ && (match->nentry->device == olddevice) &&
60053+ match->nentry->deleted) {
60054+ if (match->prev == NULL) {
60055+ inodev_set.i_hash[index] = match->next;
60056+ if (match->next != NULL)
60057+ match->next->prev = NULL;
60058+ } else {
60059+ match->prev->next = match->next;
60060+ if (match->next != NULL)
60061+ match->next->prev = match->prev;
60062+ }
60063+ match->prev = NULL;
60064+ match->next = NULL;
60065+ match->nentry->inode = newinode;
60066+ match->nentry->device = newdevice;
60067+ match->nentry->deleted = 0;
60068+
60069+ insert_inodev_entry(match);
60070+ }
60071+
60072+ return;
60073+}
60074+
60075+static void
60076+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
60077+{
60078+ struct acl_subject_label *subj;
60079+ struct acl_role_label *role;
60080+ unsigned int x;
60081+
60082+ FOR_EACH_ROLE_START(role)
60083+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
60084+
60085+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60086+ if ((subj->inode == ino) && (subj->device == dev)) {
60087+ subj->inode = ino;
60088+ subj->device = dev;
60089+ }
60090+ /* nested subjects aren't in the role's subj_hash table */
60091+ update_acl_obj_label(matchn->inode, matchn->device,
60092+ ino, dev, subj);
60093+ FOR_EACH_NESTED_SUBJECT_END(subj)
60094+ FOR_EACH_SUBJECT_START(role, subj, x)
60095+ update_acl_obj_label(matchn->inode, matchn->device,
60096+ ino, dev, subj);
60097+ FOR_EACH_SUBJECT_END(subj,x)
60098+ FOR_EACH_ROLE_END(role)
60099+
60100+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
60101+
60102+ return;
60103+}
60104+
60105+static void
60106+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
60107+ const struct vfsmount *mnt)
60108+{
60109+ ino_t ino = dentry->d_inode->i_ino;
60110+ dev_t dev = __get_dev(dentry);
60111+
60112+ __do_handle_create(matchn, ino, dev);
60113+
60114+ return;
60115+}
60116+
60117+void
60118+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60119+{
60120+ struct name_entry *matchn;
60121+
60122+ if (unlikely(!(gr_status & GR_READY)))
60123+ return;
60124+
60125+ preempt_disable();
60126+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
60127+
60128+ if (unlikely((unsigned long)matchn)) {
60129+ write_lock(&gr_inode_lock);
60130+ do_handle_create(matchn, dentry, mnt);
60131+ write_unlock(&gr_inode_lock);
60132+ }
60133+ preempt_enable();
60134+
60135+ return;
60136+}
60137+
60138+void
60139+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60140+{
60141+ struct name_entry *matchn;
60142+
60143+ if (unlikely(!(gr_status & GR_READY)))
60144+ return;
60145+
60146+ preempt_disable();
60147+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
60148+
60149+ if (unlikely((unsigned long)matchn)) {
60150+ write_lock(&gr_inode_lock);
60151+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
60152+ write_unlock(&gr_inode_lock);
60153+ }
60154+ preempt_enable();
60155+
60156+ return;
60157+}
60158+
60159+void
60160+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60161+ struct dentry *old_dentry,
60162+ struct dentry *new_dentry,
60163+ struct vfsmount *mnt, const __u8 replace)
60164+{
60165+ struct name_entry *matchn;
60166+ struct inodev_entry *inodev;
60167+ struct inode *inode = new_dentry->d_inode;
60168+ ino_t old_ino = old_dentry->d_inode->i_ino;
60169+ dev_t old_dev = __get_dev(old_dentry);
60170+
60171+ /* vfs_rename swaps the name and parent link for old_dentry and
60172+ new_dentry
60173+ at this point, old_dentry has the new name, parent link, and inode
60174+ for the renamed file
60175+ if a file is being replaced by a rename, new_dentry has the inode
60176+ and name for the replaced file
60177+ */
60178+
60179+ if (unlikely(!(gr_status & GR_READY)))
60180+ return;
60181+
60182+ preempt_disable();
60183+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
60184+
60185+ /* we wouldn't have to check d_inode if it weren't for
60186+ NFS silly-renaming
60187+ */
60188+
60189+ write_lock(&gr_inode_lock);
60190+ if (unlikely(replace && inode)) {
60191+ ino_t new_ino = inode->i_ino;
60192+ dev_t new_dev = __get_dev(new_dentry);
60193+
60194+ inodev = lookup_inodev_entry(new_ino, new_dev);
60195+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
60196+ do_handle_delete(inodev, new_ino, new_dev);
60197+ }
60198+
60199+ inodev = lookup_inodev_entry(old_ino, old_dev);
60200+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
60201+ do_handle_delete(inodev, old_ino, old_dev);
60202+
60203+ if (unlikely((unsigned long)matchn))
60204+ do_handle_create(matchn, old_dentry, mnt);
60205+
60206+ write_unlock(&gr_inode_lock);
60207+ preempt_enable();
60208+
60209+ return;
60210+}
60211+
60212+static int
60213+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
60214+ unsigned char **sum)
60215+{
60216+ struct acl_role_label *r;
60217+ struct role_allowed_ip *ipp;
60218+ struct role_transition *trans;
60219+ unsigned int i;
60220+ int found = 0;
60221+ u32 curr_ip = current->signal->curr_ip;
60222+
60223+ current->signal->saved_ip = curr_ip;
60224+
60225+ /* check transition table */
60226+
60227+ for (trans = current->role->transitions; trans; trans = trans->next) {
60228+ if (!strcmp(rolename, trans->rolename)) {
60229+ found = 1;
60230+ break;
60231+ }
60232+ }
60233+
60234+ if (!found)
60235+ return 0;
60236+
60237+ /* handle special roles that do not require authentication
60238+ and check ip */
60239+
60240+ FOR_EACH_ROLE_START(r)
60241+ if (!strcmp(rolename, r->rolename) &&
60242+ (r->roletype & GR_ROLE_SPECIAL)) {
60243+ found = 0;
60244+ if (r->allowed_ips != NULL) {
60245+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
60246+ if ((ntohl(curr_ip) & ipp->netmask) ==
60247+ (ntohl(ipp->addr) & ipp->netmask))
60248+ found = 1;
60249+ }
60250+ } else
60251+ found = 2;
60252+ if (!found)
60253+ return 0;
60254+
60255+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
60256+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
60257+ *salt = NULL;
60258+ *sum = NULL;
60259+ return 1;
60260+ }
60261+ }
60262+ FOR_EACH_ROLE_END(r)
60263+
60264+ for (i = 0; i < num_sprole_pws; i++) {
60265+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
60266+ *salt = acl_special_roles[i]->salt;
60267+ *sum = acl_special_roles[i]->sum;
60268+ return 1;
60269+ }
60270+ }
60271+
60272+ return 0;
60273+}
60274+
60275+static void
60276+assign_special_role(char *rolename)
60277+{
60278+ struct acl_object_label *obj;
60279+ struct acl_role_label *r;
60280+ struct acl_role_label *assigned = NULL;
60281+ struct task_struct *tsk;
60282+ struct file *filp;
60283+
60284+ FOR_EACH_ROLE_START(r)
60285+ if (!strcmp(rolename, r->rolename) &&
60286+ (r->roletype & GR_ROLE_SPECIAL)) {
60287+ assigned = r;
60288+ break;
60289+ }
60290+ FOR_EACH_ROLE_END(r)
60291+
60292+ if (!assigned)
60293+ return;
60294+
60295+ read_lock(&tasklist_lock);
60296+ read_lock(&grsec_exec_file_lock);
60297+
60298+ tsk = current->real_parent;
60299+ if (tsk == NULL)
60300+ goto out_unlock;
60301+
60302+ filp = tsk->exec_file;
60303+ if (filp == NULL)
60304+ goto out_unlock;
60305+
60306+ tsk->is_writable = 0;
60307+
60308+ tsk->acl_sp_role = 1;
60309+ tsk->acl_role_id = ++acl_sp_role_value;
60310+ tsk->role = assigned;
60311+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
60312+
60313+ /* ignore additional mmap checks for processes that are writable
60314+ by the default ACL */
60315+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60316+ if (unlikely(obj->mode & GR_WRITE))
60317+ tsk->is_writable = 1;
60318+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
60319+ if (unlikely(obj->mode & GR_WRITE))
60320+ tsk->is_writable = 1;
60321+
60322+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60323+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
60324+#endif
60325+
60326+out_unlock:
60327+ read_unlock(&grsec_exec_file_lock);
60328+ read_unlock(&tasklist_lock);
60329+ return;
60330+}
60331+
60332+int gr_check_secure_terminal(struct task_struct *task)
60333+{
60334+ struct task_struct *p, *p2, *p3;
60335+ struct files_struct *files;
60336+ struct fdtable *fdt;
60337+ struct file *our_file = NULL, *file;
60338+ int i;
60339+
60340+ if (task->signal->tty == NULL)
60341+ return 1;
60342+
60343+ files = get_files_struct(task);
60344+ if (files != NULL) {
60345+ rcu_read_lock();
60346+ fdt = files_fdtable(files);
60347+ for (i=0; i < fdt->max_fds; i++) {
60348+ file = fcheck_files(files, i);
60349+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
60350+ get_file(file);
60351+ our_file = file;
60352+ }
60353+ }
60354+ rcu_read_unlock();
60355+ put_files_struct(files);
60356+ }
60357+
60358+ if (our_file == NULL)
60359+ return 1;
60360+
60361+ read_lock(&tasklist_lock);
60362+ do_each_thread(p2, p) {
60363+ files = get_files_struct(p);
60364+ if (files == NULL ||
60365+ (p->signal && p->signal->tty == task->signal->tty)) {
60366+ if (files != NULL)
60367+ put_files_struct(files);
60368+ continue;
60369+ }
60370+ rcu_read_lock();
60371+ fdt = files_fdtable(files);
60372+ for (i=0; i < fdt->max_fds; i++) {
60373+ file = fcheck_files(files, i);
60374+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
60375+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
60376+ p3 = task;
60377+ while (task_pid_nr(p3) > 0) {
60378+ if (p3 == p)
60379+ break;
60380+ p3 = p3->real_parent;
60381+ }
60382+ if (p3 == p)
60383+ break;
60384+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
60385+ gr_handle_alertkill(p);
60386+ rcu_read_unlock();
60387+ put_files_struct(files);
60388+ read_unlock(&tasklist_lock);
60389+ fput(our_file);
60390+ return 0;
60391+ }
60392+ }
60393+ rcu_read_unlock();
60394+ put_files_struct(files);
60395+ } while_each_thread(p2, p);
60396+ read_unlock(&tasklist_lock);
60397+
60398+ fput(our_file);
60399+ return 1;
60400+}
60401+
60402+static int gr_rbac_disable(void *unused)
60403+{
60404+ pax_open_kernel();
60405+ gr_status &= ~GR_READY;
60406+ pax_close_kernel();
60407+
60408+ return 0;
60409+}
60410+
60411+ssize_t
60412+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
60413+{
60414+ struct gr_arg_wrapper uwrap;
60415+ unsigned char *sprole_salt = NULL;
60416+ unsigned char *sprole_sum = NULL;
60417+ int error = sizeof (struct gr_arg_wrapper);
60418+ int error2 = 0;
60419+
60420+ mutex_lock(&gr_dev_mutex);
60421+
60422+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
60423+ error = -EPERM;
60424+ goto out;
60425+ }
60426+
60427+ if (count != sizeof (struct gr_arg_wrapper)) {
60428+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
60429+ error = -EINVAL;
60430+ goto out;
60431+ }
60432+
60433+
60434+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
60435+ gr_auth_expires = 0;
60436+ gr_auth_attempts = 0;
60437+ }
60438+
60439+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
60440+ error = -EFAULT;
60441+ goto out;
60442+ }
60443+
60444+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
60445+ error = -EINVAL;
60446+ goto out;
60447+ }
60448+
60449+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
60450+ error = -EFAULT;
60451+ goto out;
60452+ }
60453+
60454+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60455+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60456+ time_after(gr_auth_expires, get_seconds())) {
60457+ error = -EBUSY;
60458+ goto out;
60459+ }
60460+
60461+ /* if non-root trying to do anything other than use a special role,
60462+ do not attempt authentication, do not count towards authentication
60463+ locking
60464+ */
60465+
60466+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
60467+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60468+ gr_is_global_nonroot(current_uid())) {
60469+ error = -EPERM;
60470+ goto out;
60471+ }
60472+
60473+ /* ensure pw and special role name are null terminated */
60474+
60475+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
60476+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
60477+
60478+ /* Okay.
60479+ * We have our enough of the argument structure..(we have yet
60480+ * to copy_from_user the tables themselves) . Copy the tables
60481+ * only if we need them, i.e. for loading operations. */
60482+
60483+ switch (gr_usermode->mode) {
60484+ case GR_STATUS:
60485+ if (gr_status & GR_READY) {
60486+ error = 1;
60487+ if (!gr_check_secure_terminal(current))
60488+ error = 3;
60489+ } else
60490+ error = 2;
60491+ goto out;
60492+ case GR_SHUTDOWN:
60493+ if ((gr_status & GR_READY)
60494+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60495+ stop_machine(gr_rbac_disable, NULL, NULL);
60496+ free_variables();
60497+ memset(gr_usermode, 0, sizeof (struct gr_arg));
60498+ memset(gr_system_salt, 0, GR_SALT_LEN);
60499+ memset(gr_system_sum, 0, GR_SHA_LEN);
60500+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60501+ } else if (gr_status & GR_READY) {
60502+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60503+ error = -EPERM;
60504+ } else {
60505+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60506+ error = -EAGAIN;
60507+ }
60508+ break;
60509+ case GR_ENABLE:
60510+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60511+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60512+ else {
60513+ if (gr_status & GR_READY)
60514+ error = -EAGAIN;
60515+ else
60516+ error = error2;
60517+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60518+ }
60519+ break;
60520+ case GR_RELOAD:
60521+ if (!(gr_status & GR_READY)) {
60522+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60523+ error = -EAGAIN;
60524+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60525+ stop_machine(gr_rbac_disable, NULL, NULL);
60526+ free_variables();
60527+ error2 = gracl_init(gr_usermode);
60528+ if (!error2)
60529+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60530+ else {
60531+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60532+ error = error2;
60533+ }
60534+ } else {
60535+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60536+ error = -EPERM;
60537+ }
60538+ break;
60539+ case GR_SEGVMOD:
60540+ if (unlikely(!(gr_status & GR_READY))) {
60541+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60542+ error = -EAGAIN;
60543+ break;
60544+ }
60545+
60546+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60547+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60548+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60549+ struct acl_subject_label *segvacl;
60550+ segvacl =
60551+ lookup_acl_subj_label(gr_usermode->segv_inode,
60552+ gr_usermode->segv_device,
60553+ current->role);
60554+ if (segvacl) {
60555+ segvacl->crashes = 0;
60556+ segvacl->expires = 0;
60557+ }
60558+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60559+ gr_remove_uid(gr_usermode->segv_uid);
60560+ }
60561+ } else {
60562+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60563+ error = -EPERM;
60564+ }
60565+ break;
60566+ case GR_SPROLE:
60567+ case GR_SPROLEPAM:
60568+ if (unlikely(!(gr_status & GR_READY))) {
60569+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60570+ error = -EAGAIN;
60571+ break;
60572+ }
60573+
60574+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60575+ current->role->expires = 0;
60576+ current->role->auth_attempts = 0;
60577+ }
60578+
60579+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60580+ time_after(current->role->expires, get_seconds())) {
60581+ error = -EBUSY;
60582+ goto out;
60583+ }
60584+
60585+ if (lookup_special_role_auth
60586+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60587+ && ((!sprole_salt && !sprole_sum)
60588+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60589+ char *p = "";
60590+ assign_special_role(gr_usermode->sp_role);
60591+ read_lock(&tasklist_lock);
60592+ if (current->real_parent)
60593+ p = current->real_parent->role->rolename;
60594+ read_unlock(&tasklist_lock);
60595+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60596+ p, acl_sp_role_value);
60597+ } else {
60598+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60599+ error = -EPERM;
60600+ if(!(current->role->auth_attempts++))
60601+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60602+
60603+ goto out;
60604+ }
60605+ break;
60606+ case GR_UNSPROLE:
60607+ if (unlikely(!(gr_status & GR_READY))) {
60608+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60609+ error = -EAGAIN;
60610+ break;
60611+ }
60612+
60613+ if (current->role->roletype & GR_ROLE_SPECIAL) {
60614+ char *p = "";
60615+ int i = 0;
60616+
60617+ read_lock(&tasklist_lock);
60618+ if (current->real_parent) {
60619+ p = current->real_parent->role->rolename;
60620+ i = current->real_parent->acl_role_id;
60621+ }
60622+ read_unlock(&tasklist_lock);
60623+
60624+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60625+ gr_set_acls(1);
60626+ } else {
60627+ error = -EPERM;
60628+ goto out;
60629+ }
60630+ break;
60631+ default:
60632+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60633+ error = -EINVAL;
60634+ break;
60635+ }
60636+
60637+ if (error != -EPERM)
60638+ goto out;
60639+
60640+ if(!(gr_auth_attempts++))
60641+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60642+
60643+ out:
60644+ mutex_unlock(&gr_dev_mutex);
60645+ return error;
60646+}
60647+
60648+/* must be called with
60649+ rcu_read_lock();
60650+ read_lock(&tasklist_lock);
60651+ read_lock(&grsec_exec_file_lock);
60652+*/
60653+int gr_apply_subject_to_task(struct task_struct *task)
60654+{
60655+ struct acl_object_label *obj;
60656+ char *tmpname;
60657+ struct acl_subject_label *tmpsubj;
60658+ struct file *filp;
60659+ struct name_entry *nmatch;
60660+
60661+ filp = task->exec_file;
60662+ if (filp == NULL)
60663+ return 0;
60664+
60665+ /* the following is to apply the correct subject
60666+ on binaries running when the RBAC system
60667+ is enabled, when the binaries have been
60668+ replaced or deleted since their execution
60669+ -----
60670+ when the RBAC system starts, the inode/dev
60671+ from exec_file will be one the RBAC system
60672+ is unaware of. It only knows the inode/dev
60673+ of the present file on disk, or the absence
60674+ of it.
60675+ */
60676+ preempt_disable();
60677+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60678+
60679+ nmatch = lookup_name_entry(tmpname);
60680+ preempt_enable();
60681+ tmpsubj = NULL;
60682+ if (nmatch) {
60683+ if (nmatch->deleted)
60684+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60685+ else
60686+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60687+ if (tmpsubj != NULL)
60688+ task->acl = tmpsubj;
60689+ }
60690+ if (tmpsubj == NULL)
60691+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60692+ task->role);
60693+ if (task->acl) {
60694+ task->is_writable = 0;
60695+ /* ignore additional mmap checks for processes that are writable
60696+ by the default ACL */
60697+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60698+ if (unlikely(obj->mode & GR_WRITE))
60699+ task->is_writable = 1;
60700+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60701+ if (unlikely(obj->mode & GR_WRITE))
60702+ task->is_writable = 1;
60703+
60704+ gr_set_proc_res(task);
60705+
60706+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60707+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
60708+#endif
60709+ } else {
60710+ return 1;
60711+ }
60712+
60713+ return 0;
60714+}
60715+
60716+int
60717+gr_set_acls(const int type)
60718+{
60719+ struct task_struct *task, *task2;
60720+ struct acl_role_label *role = current->role;
60721+ __u16 acl_role_id = current->acl_role_id;
60722+ const struct cred *cred;
60723+ int ret;
60724+
60725+ rcu_read_lock();
60726+ read_lock(&tasklist_lock);
60727+ read_lock(&grsec_exec_file_lock);
60728+ do_each_thread(task2, task) {
60729+ /* check to see if we're called from the exit handler,
60730+ if so, only replace ACLs that have inherited the admin
60731+ ACL */
60732+
60733+ if (type && (task->role != role ||
60734+ task->acl_role_id != acl_role_id))
60735+ continue;
60736+
60737+ task->acl_role_id = 0;
60738+ task->acl_sp_role = 0;
60739+
60740+ if (task->exec_file) {
60741+ cred = __task_cred(task);
60742+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60743+ ret = gr_apply_subject_to_task(task);
60744+ if (ret) {
60745+ read_unlock(&grsec_exec_file_lock);
60746+ read_unlock(&tasklist_lock);
60747+ rcu_read_unlock();
60748+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60749+ return ret;
60750+ }
60751+ } else {
60752+ // it's a kernel process
60753+ task->role = kernel_role;
60754+ task->acl = kernel_role->root_label;
60755+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60756+ task->acl->mode &= ~GR_PROCFIND;
60757+#endif
60758+ }
60759+ } while_each_thread(task2, task);
60760+ read_unlock(&grsec_exec_file_lock);
60761+ read_unlock(&tasklist_lock);
60762+ rcu_read_unlock();
60763+
60764+ return 0;
60765+}
60766+
60767+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60768+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60769+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60770+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60771+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60772+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60773+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60774+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60775+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60776+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60777+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60778+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60779+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60780+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60781+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60782+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60783+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60784+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60785+};
60786+
60787+void
60788+gr_learn_resource(const struct task_struct *task,
60789+ const int res, const unsigned long wanted, const int gt)
60790+{
60791+ struct acl_subject_label *acl;
60792+ const struct cred *cred;
60793+
60794+ if (unlikely((gr_status & GR_READY) &&
60795+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60796+ goto skip_reslog;
60797+
60798+ gr_log_resource(task, res, wanted, gt);
60799+skip_reslog:
60800+
60801+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60802+ return;
60803+
60804+ acl = task->acl;
60805+
60806+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60807+ !(acl->resmask & (1 << (unsigned short) res))))
60808+ return;
60809+
60810+ if (wanted >= acl->res[res].rlim_cur) {
60811+ unsigned long res_add;
60812+
60813+ res_add = wanted + res_learn_bumps[res];
60814+
60815+ acl->res[res].rlim_cur = res_add;
60816+
60817+ if (wanted > acl->res[res].rlim_max)
60818+ acl->res[res].rlim_max = res_add;
60819+
60820+ /* only log the subject filename, since resource logging is supported for
60821+ single-subject learning only */
60822+ rcu_read_lock();
60823+ cred = __task_cred(task);
60824+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60825+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60826+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60827+ "", (unsigned long) res, &task->signal->saved_ip);
60828+ rcu_read_unlock();
60829+ }
60830+
60831+ return;
60832+}
60833+EXPORT_SYMBOL(gr_learn_resource);
60834+#endif
60835+
60836+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60837+void
60838+pax_set_initial_flags(struct linux_binprm *bprm)
60839+{
60840+ struct task_struct *task = current;
60841+ struct acl_subject_label *proc;
60842+ unsigned long flags;
60843+
60844+ if (unlikely(!(gr_status & GR_READY)))
60845+ return;
60846+
60847+ flags = pax_get_flags(task);
60848+
60849+ proc = task->acl;
60850+
60851+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60852+ flags &= ~MF_PAX_PAGEEXEC;
60853+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60854+ flags &= ~MF_PAX_SEGMEXEC;
60855+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60856+ flags &= ~MF_PAX_RANDMMAP;
60857+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60858+ flags &= ~MF_PAX_EMUTRAMP;
60859+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60860+ flags &= ~MF_PAX_MPROTECT;
60861+
60862+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60863+ flags |= MF_PAX_PAGEEXEC;
60864+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60865+ flags |= MF_PAX_SEGMEXEC;
60866+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60867+ flags |= MF_PAX_RANDMMAP;
60868+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60869+ flags |= MF_PAX_EMUTRAMP;
60870+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60871+ flags |= MF_PAX_MPROTECT;
60872+
60873+ pax_set_flags(task, flags);
60874+
60875+ return;
60876+}
60877+#endif
60878+
60879+int
60880+gr_handle_proc_ptrace(struct task_struct *task)
60881+{
60882+ struct file *filp;
60883+ struct task_struct *tmp = task;
60884+ struct task_struct *curtemp = current;
60885+ __u32 retmode;
60886+
60887+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60888+ if (unlikely(!(gr_status & GR_READY)))
60889+ return 0;
60890+#endif
60891+
60892+ read_lock(&tasklist_lock);
60893+ read_lock(&grsec_exec_file_lock);
60894+ filp = task->exec_file;
60895+
60896+ while (task_pid_nr(tmp) > 0) {
60897+ if (tmp == curtemp)
60898+ break;
60899+ tmp = tmp->real_parent;
60900+ }
60901+
60902+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60903+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60904+ read_unlock(&grsec_exec_file_lock);
60905+ read_unlock(&tasklist_lock);
60906+ return 1;
60907+ }
60908+
60909+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60910+ if (!(gr_status & GR_READY)) {
60911+ read_unlock(&grsec_exec_file_lock);
60912+ read_unlock(&tasklist_lock);
60913+ return 0;
60914+ }
60915+#endif
60916+
60917+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60918+ read_unlock(&grsec_exec_file_lock);
60919+ read_unlock(&tasklist_lock);
60920+
60921+ if (retmode & GR_NOPTRACE)
60922+ return 1;
60923+
60924+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60925+ && (current->acl != task->acl || (current->acl != current->role->root_label
60926+ && task_pid_nr(current) != task_pid_nr(task))))
60927+ return 1;
60928+
60929+ return 0;
60930+}
60931+
60932+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60933+{
60934+ if (unlikely(!(gr_status & GR_READY)))
60935+ return;
60936+
60937+ if (!(current->role->roletype & GR_ROLE_GOD))
60938+ return;
60939+
60940+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60941+ p->role->rolename, gr_task_roletype_to_char(p),
60942+ p->acl->filename);
60943+}
60944+
60945+int
60946+gr_handle_ptrace(struct task_struct *task, const long request)
60947+{
60948+ struct task_struct *tmp = task;
60949+ struct task_struct *curtemp = current;
60950+ __u32 retmode;
60951+
60952+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60953+ if (unlikely(!(gr_status & GR_READY)))
60954+ return 0;
60955+#endif
60956+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60957+ read_lock(&tasklist_lock);
60958+ while (task_pid_nr(tmp) > 0) {
60959+ if (tmp == curtemp)
60960+ break;
60961+ tmp = tmp->real_parent;
60962+ }
60963+
60964+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60965+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60966+ read_unlock(&tasklist_lock);
60967+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60968+ return 1;
60969+ }
60970+ read_unlock(&tasklist_lock);
60971+ }
60972+
60973+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60974+ if (!(gr_status & GR_READY))
60975+ return 0;
60976+#endif
60977+
60978+ read_lock(&grsec_exec_file_lock);
60979+ if (unlikely(!task->exec_file)) {
60980+ read_unlock(&grsec_exec_file_lock);
60981+ return 0;
60982+ }
60983+
60984+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60985+ read_unlock(&grsec_exec_file_lock);
60986+
60987+ if (retmode & GR_NOPTRACE) {
60988+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60989+ return 1;
60990+ }
60991+
60992+ if (retmode & GR_PTRACERD) {
60993+ switch (request) {
60994+ case PTRACE_SEIZE:
60995+ case PTRACE_POKETEXT:
60996+ case PTRACE_POKEDATA:
60997+ case PTRACE_POKEUSR:
60998+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60999+ case PTRACE_SETREGS:
61000+ case PTRACE_SETFPREGS:
61001+#endif
61002+#ifdef CONFIG_X86
61003+ case PTRACE_SETFPXREGS:
61004+#endif
61005+#ifdef CONFIG_ALTIVEC
61006+ case PTRACE_SETVRREGS:
61007+#endif
61008+ return 1;
61009+ default:
61010+ return 0;
61011+ }
61012+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61013+ !(current->role->roletype & GR_ROLE_GOD) &&
61014+ (current->acl != task->acl)) {
61015+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61016+ return 1;
61017+ }
61018+
61019+ return 0;
61020+}
61021+
61022+static int is_writable_mmap(const struct file *filp)
61023+{
61024+ struct task_struct *task = current;
61025+ struct acl_object_label *obj, *obj2;
61026+
61027+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61028+ !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))) {
61029+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61030+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61031+ task->role->root_label);
61032+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61033+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61034+ return 1;
61035+ }
61036+ }
61037+ return 0;
61038+}
61039+
61040+int
61041+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61042+{
61043+ __u32 mode;
61044+
61045+ if (unlikely(!file || !(prot & PROT_EXEC)))
61046+ return 1;
61047+
61048+ if (is_writable_mmap(file))
61049+ return 0;
61050+
61051+ mode =
61052+ gr_search_file(file->f_path.dentry,
61053+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61054+ file->f_path.mnt);
61055+
61056+ if (!gr_tpe_allow(file))
61057+ return 0;
61058+
61059+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61060+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61061+ return 0;
61062+ } else if (unlikely(!(mode & GR_EXEC))) {
61063+ return 0;
61064+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61065+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61066+ return 1;
61067+ }
61068+
61069+ return 1;
61070+}
61071+
61072+int
61073+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61074+{
61075+ __u32 mode;
61076+
61077+ if (unlikely(!file || !(prot & PROT_EXEC)))
61078+ return 1;
61079+
61080+ if (is_writable_mmap(file))
61081+ return 0;
61082+
61083+ mode =
61084+ gr_search_file(file->f_path.dentry,
61085+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61086+ file->f_path.mnt);
61087+
61088+ if (!gr_tpe_allow(file))
61089+ return 0;
61090+
61091+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61092+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61093+ return 0;
61094+ } else if (unlikely(!(mode & GR_EXEC))) {
61095+ return 0;
61096+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61097+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61098+ return 1;
61099+ }
61100+
61101+ return 1;
61102+}
61103+
61104+void
61105+gr_acl_handle_psacct(struct task_struct *task, const long code)
61106+{
61107+ unsigned long runtime;
61108+ unsigned long cputime;
61109+ unsigned int wday, cday;
61110+ __u8 whr, chr;
61111+ __u8 wmin, cmin;
61112+ __u8 wsec, csec;
61113+ struct timespec timeval;
61114+
61115+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
61116+ !(task->acl->mode & GR_PROCACCT)))
61117+ return;
61118+
61119+ do_posix_clock_monotonic_gettime(&timeval);
61120+ runtime = timeval.tv_sec - task->start_time.tv_sec;
61121+ wday = runtime / (3600 * 24);
61122+ runtime -= wday * (3600 * 24);
61123+ whr = runtime / 3600;
61124+ runtime -= whr * 3600;
61125+ wmin = runtime / 60;
61126+ runtime -= wmin * 60;
61127+ wsec = runtime;
61128+
61129+ cputime = (task->utime + task->stime) / HZ;
61130+ cday = cputime / (3600 * 24);
61131+ cputime -= cday * (3600 * 24);
61132+ chr = cputime / 3600;
61133+ cputime -= chr * 3600;
61134+ cmin = cputime / 60;
61135+ cputime -= cmin * 60;
61136+ csec = cputime;
61137+
61138+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
61139+
61140+ return;
61141+}
61142+
61143+void gr_set_kernel_label(struct task_struct *task)
61144+{
61145+ if (gr_status & GR_READY) {
61146+ task->role = kernel_role;
61147+ task->acl = kernel_role->root_label;
61148+ }
61149+ return;
61150+}
61151+
61152+#ifdef CONFIG_TASKSTATS
61153+int gr_is_taskstats_denied(int pid)
61154+{
61155+ struct task_struct *task;
61156+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61157+ const struct cred *cred;
61158+#endif
61159+ int ret = 0;
61160+
61161+ /* restrict taskstats viewing to un-chrooted root users
61162+ who have the 'view' subject flag if the RBAC system is enabled
61163+ */
61164+
61165+ rcu_read_lock();
61166+ read_lock(&tasklist_lock);
61167+ task = find_task_by_vpid(pid);
61168+ if (task) {
61169+#ifdef CONFIG_GRKERNSEC_CHROOT
61170+ if (proc_is_chrooted(task))
61171+ ret = -EACCES;
61172+#endif
61173+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61174+ cred = __task_cred(task);
61175+#ifdef CONFIG_GRKERNSEC_PROC_USER
61176+ if (gr_is_global_nonroot(cred->uid))
61177+ ret = -EACCES;
61178+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61179+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
61180+ ret = -EACCES;
61181+#endif
61182+#endif
61183+ if (gr_status & GR_READY) {
61184+ if (!(task->acl->mode & GR_VIEW))
61185+ ret = -EACCES;
61186+ }
61187+ } else
61188+ ret = -ENOENT;
61189+
61190+ read_unlock(&tasklist_lock);
61191+ rcu_read_unlock();
61192+
61193+ return ret;
61194+}
61195+#endif
61196+
61197+/* AUXV entries are filled via a descendant of search_binary_handler
61198+ after we've already applied the subject for the target
61199+*/
61200+int gr_acl_enable_at_secure(void)
61201+{
61202+ if (unlikely(!(gr_status & GR_READY)))
61203+ return 0;
61204+
61205+ if (current->acl->mode & GR_ATSECURE)
61206+ return 1;
61207+
61208+ return 0;
61209+}
61210+
61211+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
61212+{
61213+ struct task_struct *task = current;
61214+ struct dentry *dentry = file->f_path.dentry;
61215+ struct vfsmount *mnt = file->f_path.mnt;
61216+ struct acl_object_label *obj, *tmp;
61217+ struct acl_subject_label *subj;
61218+ unsigned int bufsize;
61219+ int is_not_root;
61220+ char *path;
61221+ dev_t dev = __get_dev(dentry);
61222+
61223+ if (unlikely(!(gr_status & GR_READY)))
61224+ return 1;
61225+
61226+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61227+ return 1;
61228+
61229+ /* ignore Eric Biederman */
61230+ if (IS_PRIVATE(dentry->d_inode))
61231+ return 1;
61232+
61233+ subj = task->acl;
61234+ read_lock(&gr_inode_lock);
61235+ do {
61236+ obj = lookup_acl_obj_label(ino, dev, subj);
61237+ if (obj != NULL) {
61238+ read_unlock(&gr_inode_lock);
61239+ return (obj->mode & GR_FIND) ? 1 : 0;
61240+ }
61241+ } while ((subj = subj->parent_subject));
61242+ read_unlock(&gr_inode_lock);
61243+
61244+ /* this is purely an optimization since we're looking for an object
61245+ for the directory we're doing a readdir on
61246+ if it's possible for any globbed object to match the entry we're
61247+ filling into the directory, then the object we find here will be
61248+ an anchor point with attached globbed objects
61249+ */
61250+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
61251+ if (obj->globbed == NULL)
61252+ return (obj->mode & GR_FIND) ? 1 : 0;
61253+
61254+ is_not_root = ((obj->filename[0] == '/') &&
61255+ (obj->filename[1] == '\0')) ? 0 : 1;
61256+ bufsize = PAGE_SIZE - namelen - is_not_root;
61257+
61258+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
61259+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
61260+ return 1;
61261+
61262+ preempt_disable();
61263+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
61264+ bufsize);
61265+
61266+ bufsize = strlen(path);
61267+
61268+ /* if base is "/", don't append an additional slash */
61269+ if (is_not_root)
61270+ *(path + bufsize) = '/';
61271+ memcpy(path + bufsize + is_not_root, name, namelen);
61272+ *(path + bufsize + namelen + is_not_root) = '\0';
61273+
61274+ tmp = obj->globbed;
61275+ while (tmp) {
61276+ if (!glob_match(tmp->filename, path)) {
61277+ preempt_enable();
61278+ return (tmp->mode & GR_FIND) ? 1 : 0;
61279+ }
61280+ tmp = tmp->next;
61281+ }
61282+ preempt_enable();
61283+ return (obj->mode & GR_FIND) ? 1 : 0;
61284+}
61285+
61286+void gr_put_exec_file(struct task_struct *task)
61287+{
61288+ struct file *filp;
61289+
61290+ write_lock(&grsec_exec_file_lock);
61291+ filp = task->exec_file;
61292+ task->exec_file = NULL;
61293+ write_unlock(&grsec_exec_file_lock);
61294+
61295+ if (filp)
61296+ fput(filp);
61297+
61298+ return;
61299+}
61300+
61301+
61302+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
61303+EXPORT_SYMBOL(gr_acl_is_enabled);
61304+#endif
61305+EXPORT_SYMBOL(gr_set_kernel_label);
61306+#ifdef CONFIG_SECURITY
61307+EXPORT_SYMBOL(gr_check_user_change);
61308+EXPORT_SYMBOL(gr_check_group_change);
61309+#endif
61310+
61311diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
61312new file mode 100644
61313index 0000000..34fefda
61314--- /dev/null
61315+++ b/grsecurity/gracl_alloc.c
61316@@ -0,0 +1,105 @@
61317+#include <linux/kernel.h>
61318+#include <linux/mm.h>
61319+#include <linux/slab.h>
61320+#include <linux/vmalloc.h>
61321+#include <linux/gracl.h>
61322+#include <linux/grsecurity.h>
61323+
61324+static unsigned long alloc_stack_next = 1;
61325+static unsigned long alloc_stack_size = 1;
61326+static void **alloc_stack;
61327+
61328+static __inline__ int
61329+alloc_pop(void)
61330+{
61331+ if (alloc_stack_next == 1)
61332+ return 0;
61333+
61334+ kfree(alloc_stack[alloc_stack_next - 2]);
61335+
61336+ alloc_stack_next--;
61337+
61338+ return 1;
61339+}
61340+
61341+static __inline__ int
61342+alloc_push(void *buf)
61343+{
61344+ if (alloc_stack_next >= alloc_stack_size)
61345+ return 1;
61346+
61347+ alloc_stack[alloc_stack_next - 1] = buf;
61348+
61349+ alloc_stack_next++;
61350+
61351+ return 0;
61352+}
61353+
61354+void *
61355+acl_alloc(unsigned long len)
61356+{
61357+ void *ret = NULL;
61358+
61359+ if (!len || len > PAGE_SIZE)
61360+ goto out;
61361+
61362+ ret = kmalloc(len, GFP_KERNEL);
61363+
61364+ if (ret) {
61365+ if (alloc_push(ret)) {
61366+ kfree(ret);
61367+ ret = NULL;
61368+ }
61369+ }
61370+
61371+out:
61372+ return ret;
61373+}
61374+
61375+void *
61376+acl_alloc_num(unsigned long num, unsigned long len)
61377+{
61378+ if (!len || (num > (PAGE_SIZE / len)))
61379+ return NULL;
61380+
61381+ return acl_alloc(num * len);
61382+}
61383+
61384+void
61385+acl_free_all(void)
61386+{
61387+ if (gr_acl_is_enabled() || !alloc_stack)
61388+ return;
61389+
61390+ while (alloc_pop()) ;
61391+
61392+ if (alloc_stack) {
61393+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
61394+ kfree(alloc_stack);
61395+ else
61396+ vfree(alloc_stack);
61397+ }
61398+
61399+ alloc_stack = NULL;
61400+ alloc_stack_size = 1;
61401+ alloc_stack_next = 1;
61402+
61403+ return;
61404+}
61405+
61406+int
61407+acl_alloc_stack_init(unsigned long size)
61408+{
61409+ if ((size * sizeof (void *)) <= PAGE_SIZE)
61410+ alloc_stack =
61411+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
61412+ else
61413+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
61414+
61415+ alloc_stack_size = size;
61416+
61417+ if (!alloc_stack)
61418+ return 0;
61419+ else
61420+ return 1;
61421+}
61422diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
61423new file mode 100644
61424index 0000000..bdd51ea
61425--- /dev/null
61426+++ b/grsecurity/gracl_cap.c
61427@@ -0,0 +1,110 @@
61428+#include <linux/kernel.h>
61429+#include <linux/module.h>
61430+#include <linux/sched.h>
61431+#include <linux/gracl.h>
61432+#include <linux/grsecurity.h>
61433+#include <linux/grinternal.h>
61434+
61435+extern const char *captab_log[];
61436+extern int captab_log_entries;
61437+
61438+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61439+{
61440+ struct acl_subject_label *curracl;
61441+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61442+ kernel_cap_t cap_audit = __cap_empty_set;
61443+
61444+ if (!gr_acl_is_enabled())
61445+ return 1;
61446+
61447+ curracl = task->acl;
61448+
61449+ cap_drop = curracl->cap_lower;
61450+ cap_mask = curracl->cap_mask;
61451+ cap_audit = curracl->cap_invert_audit;
61452+
61453+ while ((curracl = curracl->parent_subject)) {
61454+ /* if the cap isn't specified in the current computed mask but is specified in the
61455+ current level subject, and is lowered in the current level subject, then add
61456+ it to the set of dropped capabilities
61457+ otherwise, add the current level subject's mask to the current computed mask
61458+ */
61459+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61460+ cap_raise(cap_mask, cap);
61461+ if (cap_raised(curracl->cap_lower, cap))
61462+ cap_raise(cap_drop, cap);
61463+ if (cap_raised(curracl->cap_invert_audit, cap))
61464+ cap_raise(cap_audit, cap);
61465+ }
61466+ }
61467+
61468+ if (!cap_raised(cap_drop, cap)) {
61469+ if (cap_raised(cap_audit, cap))
61470+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
61471+ return 1;
61472+ }
61473+
61474+ curracl = task->acl;
61475+
61476+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
61477+ && cap_raised(cred->cap_effective, cap)) {
61478+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61479+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
61480+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
61481+ gr_to_filename(task->exec_file->f_path.dentry,
61482+ task->exec_file->f_path.mnt) : curracl->filename,
61483+ curracl->filename, 0UL,
61484+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
61485+ return 1;
61486+ }
61487+
61488+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
61489+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
61490+
61491+ return 0;
61492+}
61493+
61494+int
61495+gr_acl_is_capable(const int cap)
61496+{
61497+ return gr_task_acl_is_capable(current, current_cred(), cap);
61498+}
61499+
61500+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61501+{
61502+ struct acl_subject_label *curracl;
61503+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61504+
61505+ if (!gr_acl_is_enabled())
61506+ return 1;
61507+
61508+ curracl = task->acl;
61509+
61510+ cap_drop = curracl->cap_lower;
61511+ cap_mask = curracl->cap_mask;
61512+
61513+ while ((curracl = curracl->parent_subject)) {
61514+ /* if the cap isn't specified in the current computed mask but is specified in the
61515+ current level subject, and is lowered in the current level subject, then add
61516+ it to the set of dropped capabilities
61517+ otherwise, add the current level subject's mask to the current computed mask
61518+ */
61519+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61520+ cap_raise(cap_mask, cap);
61521+ if (cap_raised(curracl->cap_lower, cap))
61522+ cap_raise(cap_drop, cap);
61523+ }
61524+ }
61525+
61526+ if (!cap_raised(cap_drop, cap))
61527+ return 1;
61528+
61529+ return 0;
61530+}
61531+
61532+int
61533+gr_acl_is_capable_nolog(const int cap)
61534+{
61535+ return gr_task_acl_is_capable_nolog(current, cap);
61536+}
61537+
61538diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61539new file mode 100644
61540index 0000000..a340c17
61541--- /dev/null
61542+++ b/grsecurity/gracl_fs.c
61543@@ -0,0 +1,431 @@
61544+#include <linux/kernel.h>
61545+#include <linux/sched.h>
61546+#include <linux/types.h>
61547+#include <linux/fs.h>
61548+#include <linux/file.h>
61549+#include <linux/stat.h>
61550+#include <linux/grsecurity.h>
61551+#include <linux/grinternal.h>
61552+#include <linux/gracl.h>
61553+
61554+umode_t
61555+gr_acl_umask(void)
61556+{
61557+ if (unlikely(!gr_acl_is_enabled()))
61558+ return 0;
61559+
61560+ return current->role->umask;
61561+}
61562+
61563+__u32
61564+gr_acl_handle_hidden_file(const struct dentry * dentry,
61565+ const struct vfsmount * mnt)
61566+{
61567+ __u32 mode;
61568+
61569+ if (unlikely(!dentry->d_inode))
61570+ return GR_FIND;
61571+
61572+ mode =
61573+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61574+
61575+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61576+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61577+ return mode;
61578+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61579+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61580+ return 0;
61581+ } else if (unlikely(!(mode & GR_FIND)))
61582+ return 0;
61583+
61584+ return GR_FIND;
61585+}
61586+
61587+__u32
61588+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61589+ int acc_mode)
61590+{
61591+ __u32 reqmode = GR_FIND;
61592+ __u32 mode;
61593+
61594+ if (unlikely(!dentry->d_inode))
61595+ return reqmode;
61596+
61597+ if (acc_mode & MAY_APPEND)
61598+ reqmode |= GR_APPEND;
61599+ else if (acc_mode & MAY_WRITE)
61600+ reqmode |= GR_WRITE;
61601+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61602+ reqmode |= GR_READ;
61603+
61604+ mode =
61605+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61606+ mnt);
61607+
61608+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61609+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61610+ reqmode & GR_READ ? " reading" : "",
61611+ reqmode & GR_WRITE ? " writing" : reqmode &
61612+ GR_APPEND ? " appending" : "");
61613+ return reqmode;
61614+ } else
61615+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61616+ {
61617+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61618+ reqmode & GR_READ ? " reading" : "",
61619+ reqmode & GR_WRITE ? " writing" : reqmode &
61620+ GR_APPEND ? " appending" : "");
61621+ return 0;
61622+ } else if (unlikely((mode & reqmode) != reqmode))
61623+ return 0;
61624+
61625+ return reqmode;
61626+}
61627+
61628+__u32
61629+gr_acl_handle_creat(const struct dentry * dentry,
61630+ const struct dentry * p_dentry,
61631+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61632+ const int imode)
61633+{
61634+ __u32 reqmode = GR_WRITE | GR_CREATE;
61635+ __u32 mode;
61636+
61637+ if (acc_mode & MAY_APPEND)
61638+ reqmode |= GR_APPEND;
61639+ // if a directory was required or the directory already exists, then
61640+ // don't count this open as a read
61641+ if ((acc_mode & MAY_READ) &&
61642+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61643+ reqmode |= GR_READ;
61644+ if ((open_flags & O_CREAT) &&
61645+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61646+ reqmode |= GR_SETID;
61647+
61648+ mode =
61649+ gr_check_create(dentry, p_dentry, p_mnt,
61650+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61651+
61652+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61653+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61654+ reqmode & GR_READ ? " reading" : "",
61655+ reqmode & GR_WRITE ? " writing" : reqmode &
61656+ GR_APPEND ? " appending" : "");
61657+ return reqmode;
61658+ } else
61659+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61660+ {
61661+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61662+ reqmode & GR_READ ? " reading" : "",
61663+ reqmode & GR_WRITE ? " writing" : reqmode &
61664+ GR_APPEND ? " appending" : "");
61665+ return 0;
61666+ } else if (unlikely((mode & reqmode) != reqmode))
61667+ return 0;
61668+
61669+ return reqmode;
61670+}
61671+
61672+__u32
61673+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61674+ const int fmode)
61675+{
61676+ __u32 mode, reqmode = GR_FIND;
61677+
61678+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61679+ reqmode |= GR_EXEC;
61680+ if (fmode & S_IWOTH)
61681+ reqmode |= GR_WRITE;
61682+ if (fmode & S_IROTH)
61683+ reqmode |= GR_READ;
61684+
61685+ mode =
61686+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61687+ mnt);
61688+
61689+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61690+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61691+ reqmode & GR_READ ? " reading" : "",
61692+ reqmode & GR_WRITE ? " writing" : "",
61693+ reqmode & GR_EXEC ? " executing" : "");
61694+ return reqmode;
61695+ } else
61696+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61697+ {
61698+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61699+ reqmode & GR_READ ? " reading" : "",
61700+ reqmode & GR_WRITE ? " writing" : "",
61701+ reqmode & GR_EXEC ? " executing" : "");
61702+ return 0;
61703+ } else if (unlikely((mode & reqmode) != reqmode))
61704+ return 0;
61705+
61706+ return reqmode;
61707+}
61708+
61709+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61710+{
61711+ __u32 mode;
61712+
61713+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61714+
61715+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61716+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61717+ return mode;
61718+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61719+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61720+ return 0;
61721+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61722+ return 0;
61723+
61724+ return (reqmode);
61725+}
61726+
61727+__u32
61728+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61729+{
61730+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61731+}
61732+
61733+__u32
61734+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61735+{
61736+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61737+}
61738+
61739+__u32
61740+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61741+{
61742+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61743+}
61744+
61745+__u32
61746+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61747+{
61748+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61749+}
61750+
61751+__u32
61752+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61753+ umode_t *modeptr)
61754+{
61755+ umode_t mode;
61756+
61757+ *modeptr &= ~gr_acl_umask();
61758+ mode = *modeptr;
61759+
61760+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61761+ return 1;
61762+
61763+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61764+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61765+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61766+ GR_CHMOD_ACL_MSG);
61767+ } else {
61768+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61769+ }
61770+}
61771+
61772+__u32
61773+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61774+{
61775+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61776+}
61777+
61778+__u32
61779+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61780+{
61781+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61782+}
61783+
61784+__u32
61785+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61786+{
61787+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61788+}
61789+
61790+__u32
61791+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61792+{
61793+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61794+ GR_UNIXCONNECT_ACL_MSG);
61795+}
61796+
61797+/* hardlinks require at minimum create and link permission,
61798+ any additional privilege required is based on the
61799+ privilege of the file being linked to
61800+*/
61801+__u32
61802+gr_acl_handle_link(const struct dentry * new_dentry,
61803+ const struct dentry * parent_dentry,
61804+ const struct vfsmount * parent_mnt,
61805+ const struct dentry * old_dentry,
61806+ const struct vfsmount * old_mnt, const struct filename *to)
61807+{
61808+ __u32 mode;
61809+ __u32 needmode = GR_CREATE | GR_LINK;
61810+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61811+
61812+ mode =
61813+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61814+ old_mnt);
61815+
61816+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61817+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61818+ return mode;
61819+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61820+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61821+ return 0;
61822+ } else if (unlikely((mode & needmode) != needmode))
61823+ return 0;
61824+
61825+ return 1;
61826+}
61827+
61828+__u32
61829+gr_acl_handle_symlink(const struct dentry * new_dentry,
61830+ const struct dentry * parent_dentry,
61831+ const struct vfsmount * parent_mnt, const struct filename *from)
61832+{
61833+ __u32 needmode = GR_WRITE | GR_CREATE;
61834+ __u32 mode;
61835+
61836+ mode =
61837+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
61838+ GR_CREATE | GR_AUDIT_CREATE |
61839+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61840+
61841+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61842+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61843+ return mode;
61844+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61845+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61846+ return 0;
61847+ } else if (unlikely((mode & needmode) != needmode))
61848+ return 0;
61849+
61850+ return (GR_WRITE | GR_CREATE);
61851+}
61852+
61853+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)
61854+{
61855+ __u32 mode;
61856+
61857+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61858+
61859+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61860+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61861+ return mode;
61862+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61863+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61864+ return 0;
61865+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61866+ return 0;
61867+
61868+ return (reqmode);
61869+}
61870+
61871+__u32
61872+gr_acl_handle_mknod(const struct dentry * new_dentry,
61873+ const struct dentry * parent_dentry,
61874+ const struct vfsmount * parent_mnt,
61875+ const int mode)
61876+{
61877+ __u32 reqmode = GR_WRITE | GR_CREATE;
61878+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61879+ reqmode |= GR_SETID;
61880+
61881+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61882+ reqmode, GR_MKNOD_ACL_MSG);
61883+}
61884+
61885+__u32
61886+gr_acl_handle_mkdir(const struct dentry *new_dentry,
61887+ const struct dentry *parent_dentry,
61888+ const struct vfsmount *parent_mnt)
61889+{
61890+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61891+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61892+}
61893+
61894+#define RENAME_CHECK_SUCCESS(old, new) \
61895+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61896+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61897+
61898+int
61899+gr_acl_handle_rename(struct dentry *new_dentry,
61900+ struct dentry *parent_dentry,
61901+ const struct vfsmount *parent_mnt,
61902+ struct dentry *old_dentry,
61903+ struct inode *old_parent_inode,
61904+ struct vfsmount *old_mnt, const struct filename *newname)
61905+{
61906+ __u32 comp1, comp2;
61907+ int error = 0;
61908+
61909+ if (unlikely(!gr_acl_is_enabled()))
61910+ return 0;
61911+
61912+ if (!new_dentry->d_inode) {
61913+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61914+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61915+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61916+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61917+ GR_DELETE | GR_AUDIT_DELETE |
61918+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61919+ GR_SUPPRESS, old_mnt);
61920+ } else {
61921+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61922+ GR_CREATE | GR_DELETE |
61923+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61924+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61925+ GR_SUPPRESS, parent_mnt);
61926+ comp2 =
61927+ gr_search_file(old_dentry,
61928+ GR_READ | GR_WRITE | GR_AUDIT_READ |
61929+ GR_DELETE | GR_AUDIT_DELETE |
61930+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61931+ }
61932+
61933+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61934+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61935+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61936+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61937+ && !(comp2 & GR_SUPPRESS)) {
61938+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61939+ error = -EACCES;
61940+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61941+ error = -EACCES;
61942+
61943+ return error;
61944+}
61945+
61946+void
61947+gr_acl_handle_exit(void)
61948+{
61949+ u16 id;
61950+ char *rolename;
61951+
61952+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61953+ !(current->role->roletype & GR_ROLE_PERSIST))) {
61954+ id = current->acl_role_id;
61955+ rolename = current->role->rolename;
61956+ gr_set_acls(1);
61957+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61958+ }
61959+
61960+ gr_put_exec_file(current);
61961+ return;
61962+}
61963+
61964+int
61965+gr_acl_handle_procpidmem(const struct task_struct *task)
61966+{
61967+ if (unlikely(!gr_acl_is_enabled()))
61968+ return 0;
61969+
61970+ if (task != current && task->acl->mode & GR_PROTPROCFD)
61971+ return -EACCES;
61972+
61973+ return 0;
61974+}
61975diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61976new file mode 100644
61977index 0000000..4699807
61978--- /dev/null
61979+++ b/grsecurity/gracl_ip.c
61980@@ -0,0 +1,384 @@
61981+#include <linux/kernel.h>
61982+#include <asm/uaccess.h>
61983+#include <asm/errno.h>
61984+#include <net/sock.h>
61985+#include <linux/file.h>
61986+#include <linux/fs.h>
61987+#include <linux/net.h>
61988+#include <linux/in.h>
61989+#include <linux/skbuff.h>
61990+#include <linux/ip.h>
61991+#include <linux/udp.h>
61992+#include <linux/types.h>
61993+#include <linux/sched.h>
61994+#include <linux/netdevice.h>
61995+#include <linux/inetdevice.h>
61996+#include <linux/gracl.h>
61997+#include <linux/grsecurity.h>
61998+#include <linux/grinternal.h>
61999+
62000+#define GR_BIND 0x01
62001+#define GR_CONNECT 0x02
62002+#define GR_INVERT 0x04
62003+#define GR_BINDOVERRIDE 0x08
62004+#define GR_CONNECTOVERRIDE 0x10
62005+#define GR_SOCK_FAMILY 0x20
62006+
62007+static const char * gr_protocols[IPPROTO_MAX] = {
62008+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62009+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62010+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62011+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62012+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62013+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62014+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62015+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62016+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62017+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62018+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62019+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62020+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62021+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62022+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62023+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62024+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62025+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62026+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62027+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62028+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62029+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62030+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62031+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62032+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62033+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62034+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62035+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62036+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62037+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62038+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62039+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62040+ };
62041+
62042+static const char * gr_socktypes[SOCK_MAX] = {
62043+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62044+ "unknown:7", "unknown:8", "unknown:9", "packet"
62045+ };
62046+
62047+static const char * gr_sockfamilies[AF_MAX+1] = {
62048+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62049+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62050+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62051+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62052+ };
62053+
62054+const char *
62055+gr_proto_to_name(unsigned char proto)
62056+{
62057+ return gr_protocols[proto];
62058+}
62059+
62060+const char *
62061+gr_socktype_to_name(unsigned char type)
62062+{
62063+ return gr_socktypes[type];
62064+}
62065+
62066+const char *
62067+gr_sockfamily_to_name(unsigned char family)
62068+{
62069+ return gr_sockfamilies[family];
62070+}
62071+
62072+int
62073+gr_search_socket(const int domain, const int type, const int protocol)
62074+{
62075+ struct acl_subject_label *curr;
62076+ const struct cred *cred = current_cred();
62077+
62078+ if (unlikely(!gr_acl_is_enabled()))
62079+ goto exit;
62080+
62081+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
62082+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
62083+ goto exit; // let the kernel handle it
62084+
62085+ curr = current->acl;
62086+
62087+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
62088+ /* the family is allowed, if this is PF_INET allow it only if
62089+ the extra sock type/protocol checks pass */
62090+ if (domain == PF_INET)
62091+ goto inet_check;
62092+ goto exit;
62093+ } else {
62094+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62095+ __u32 fakeip = 0;
62096+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62097+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62098+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62099+ gr_to_filename(current->exec_file->f_path.dentry,
62100+ current->exec_file->f_path.mnt) :
62101+ curr->filename, curr->filename,
62102+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
62103+ &current->signal->saved_ip);
62104+ goto exit;
62105+ }
62106+ goto exit_fail;
62107+ }
62108+
62109+inet_check:
62110+ /* the rest of this checking is for IPv4 only */
62111+ if (!curr->ips)
62112+ goto exit;
62113+
62114+ if ((curr->ip_type & (1 << type)) &&
62115+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
62116+ goto exit;
62117+
62118+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62119+ /* we don't place acls on raw sockets , and sometimes
62120+ dgram/ip sockets are opened for ioctl and not
62121+ bind/connect, so we'll fake a bind learn log */
62122+ if (type == SOCK_RAW || type == SOCK_PACKET) {
62123+ __u32 fakeip = 0;
62124+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62125+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62126+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62127+ gr_to_filename(current->exec_file->f_path.dentry,
62128+ current->exec_file->f_path.mnt) :
62129+ curr->filename, curr->filename,
62130+ &fakeip, 0, type,
62131+ protocol, GR_CONNECT, &current->signal->saved_ip);
62132+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
62133+ __u32 fakeip = 0;
62134+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62135+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62136+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62137+ gr_to_filename(current->exec_file->f_path.dentry,
62138+ current->exec_file->f_path.mnt) :
62139+ curr->filename, curr->filename,
62140+ &fakeip, 0, type,
62141+ protocol, GR_BIND, &current->signal->saved_ip);
62142+ }
62143+ /* we'll log when they use connect or bind */
62144+ goto exit;
62145+ }
62146+
62147+exit_fail:
62148+ if (domain == PF_INET)
62149+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
62150+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
62151+ else
62152+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
62153+ gr_socktype_to_name(type), protocol);
62154+
62155+ return 0;
62156+exit:
62157+ return 1;
62158+}
62159+
62160+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)
62161+{
62162+ if ((ip->mode & mode) &&
62163+ (ip_port >= ip->low) &&
62164+ (ip_port <= ip->high) &&
62165+ ((ntohl(ip_addr) & our_netmask) ==
62166+ (ntohl(our_addr) & our_netmask))
62167+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
62168+ && (ip->type & (1 << type))) {
62169+ if (ip->mode & GR_INVERT)
62170+ return 2; // specifically denied
62171+ else
62172+ return 1; // allowed
62173+ }
62174+
62175+ return 0; // not specifically allowed, may continue parsing
62176+}
62177+
62178+static int
62179+gr_search_connectbind(const int full_mode, struct sock *sk,
62180+ struct sockaddr_in *addr, const int type)
62181+{
62182+ char iface[IFNAMSIZ] = {0};
62183+ struct acl_subject_label *curr;
62184+ struct acl_ip_label *ip;
62185+ struct inet_sock *isk;
62186+ struct net_device *dev;
62187+ struct in_device *idev;
62188+ unsigned long i;
62189+ int ret;
62190+ int mode = full_mode & (GR_BIND | GR_CONNECT);
62191+ __u32 ip_addr = 0;
62192+ __u32 our_addr;
62193+ __u32 our_netmask;
62194+ char *p;
62195+ __u16 ip_port = 0;
62196+ const struct cred *cred = current_cred();
62197+
62198+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
62199+ return 0;
62200+
62201+ curr = current->acl;
62202+ isk = inet_sk(sk);
62203+
62204+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
62205+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
62206+ addr->sin_addr.s_addr = curr->inaddr_any_override;
62207+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
62208+ struct sockaddr_in saddr;
62209+ int err;
62210+
62211+ saddr.sin_family = AF_INET;
62212+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
62213+ saddr.sin_port = isk->inet_sport;
62214+
62215+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62216+ if (err)
62217+ return err;
62218+
62219+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62220+ if (err)
62221+ return err;
62222+ }
62223+
62224+ if (!curr->ips)
62225+ return 0;
62226+
62227+ ip_addr = addr->sin_addr.s_addr;
62228+ ip_port = ntohs(addr->sin_port);
62229+
62230+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62231+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62232+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62233+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62234+ gr_to_filename(current->exec_file->f_path.dentry,
62235+ current->exec_file->f_path.mnt) :
62236+ curr->filename, curr->filename,
62237+ &ip_addr, ip_port, type,
62238+ sk->sk_protocol, mode, &current->signal->saved_ip);
62239+ return 0;
62240+ }
62241+
62242+ for (i = 0; i < curr->ip_num; i++) {
62243+ ip = *(curr->ips + i);
62244+ if (ip->iface != NULL) {
62245+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
62246+ p = strchr(iface, ':');
62247+ if (p != NULL)
62248+ *p = '\0';
62249+ dev = dev_get_by_name(sock_net(sk), iface);
62250+ if (dev == NULL)
62251+ continue;
62252+ idev = in_dev_get(dev);
62253+ if (idev == NULL) {
62254+ dev_put(dev);
62255+ continue;
62256+ }
62257+ rcu_read_lock();
62258+ for_ifa(idev) {
62259+ if (!strcmp(ip->iface, ifa->ifa_label)) {
62260+ our_addr = ifa->ifa_address;
62261+ our_netmask = 0xffffffff;
62262+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62263+ if (ret == 1) {
62264+ rcu_read_unlock();
62265+ in_dev_put(idev);
62266+ dev_put(dev);
62267+ return 0;
62268+ } else if (ret == 2) {
62269+ rcu_read_unlock();
62270+ in_dev_put(idev);
62271+ dev_put(dev);
62272+ goto denied;
62273+ }
62274+ }
62275+ } endfor_ifa(idev);
62276+ rcu_read_unlock();
62277+ in_dev_put(idev);
62278+ dev_put(dev);
62279+ } else {
62280+ our_addr = ip->addr;
62281+ our_netmask = ip->netmask;
62282+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62283+ if (ret == 1)
62284+ return 0;
62285+ else if (ret == 2)
62286+ goto denied;
62287+ }
62288+ }
62289+
62290+denied:
62291+ if (mode == GR_BIND)
62292+ 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));
62293+ else if (mode == GR_CONNECT)
62294+ 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));
62295+
62296+ return -EACCES;
62297+}
62298+
62299+int
62300+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
62301+{
62302+ /* always allow disconnection of dgram sockets with connect */
62303+ if (addr->sin_family == AF_UNSPEC)
62304+ return 0;
62305+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
62306+}
62307+
62308+int
62309+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
62310+{
62311+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
62312+}
62313+
62314+int gr_search_listen(struct socket *sock)
62315+{
62316+ struct sock *sk = sock->sk;
62317+ struct sockaddr_in addr;
62318+
62319+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62320+ addr.sin_port = inet_sk(sk)->inet_sport;
62321+
62322+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62323+}
62324+
62325+int gr_search_accept(struct socket *sock)
62326+{
62327+ struct sock *sk = sock->sk;
62328+ struct sockaddr_in addr;
62329+
62330+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62331+ addr.sin_port = inet_sk(sk)->inet_sport;
62332+
62333+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62334+}
62335+
62336+int
62337+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
62338+{
62339+ if (addr)
62340+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
62341+ else {
62342+ struct sockaddr_in sin;
62343+ const struct inet_sock *inet = inet_sk(sk);
62344+
62345+ sin.sin_addr.s_addr = inet->inet_daddr;
62346+ sin.sin_port = inet->inet_dport;
62347+
62348+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62349+ }
62350+}
62351+
62352+int
62353+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
62354+{
62355+ struct sockaddr_in sin;
62356+
62357+ if (unlikely(skb->len < sizeof (struct udphdr)))
62358+ return 0; // skip this packet
62359+
62360+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
62361+ sin.sin_port = udp_hdr(skb)->source;
62362+
62363+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62364+}
62365diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
62366new file mode 100644
62367index 0000000..25f54ef
62368--- /dev/null
62369+++ b/grsecurity/gracl_learn.c
62370@@ -0,0 +1,207 @@
62371+#include <linux/kernel.h>
62372+#include <linux/mm.h>
62373+#include <linux/sched.h>
62374+#include <linux/poll.h>
62375+#include <linux/string.h>
62376+#include <linux/file.h>
62377+#include <linux/types.h>
62378+#include <linux/vmalloc.h>
62379+#include <linux/grinternal.h>
62380+
62381+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
62382+ size_t count, loff_t *ppos);
62383+extern int gr_acl_is_enabled(void);
62384+
62385+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
62386+static int gr_learn_attached;
62387+
62388+/* use a 512k buffer */
62389+#define LEARN_BUFFER_SIZE (512 * 1024)
62390+
62391+static DEFINE_SPINLOCK(gr_learn_lock);
62392+static DEFINE_MUTEX(gr_learn_user_mutex);
62393+
62394+/* we need to maintain two buffers, so that the kernel context of grlearn
62395+ uses a semaphore around the userspace copying, and the other kernel contexts
62396+ use a spinlock when copying into the buffer, since they cannot sleep
62397+*/
62398+static char *learn_buffer;
62399+static char *learn_buffer_user;
62400+static int learn_buffer_len;
62401+static int learn_buffer_user_len;
62402+
62403+static ssize_t
62404+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
62405+{
62406+ DECLARE_WAITQUEUE(wait, current);
62407+ ssize_t retval = 0;
62408+
62409+ add_wait_queue(&learn_wait, &wait);
62410+ set_current_state(TASK_INTERRUPTIBLE);
62411+ do {
62412+ mutex_lock(&gr_learn_user_mutex);
62413+ spin_lock(&gr_learn_lock);
62414+ if (learn_buffer_len)
62415+ break;
62416+ spin_unlock(&gr_learn_lock);
62417+ mutex_unlock(&gr_learn_user_mutex);
62418+ if (file->f_flags & O_NONBLOCK) {
62419+ retval = -EAGAIN;
62420+ goto out;
62421+ }
62422+ if (signal_pending(current)) {
62423+ retval = -ERESTARTSYS;
62424+ goto out;
62425+ }
62426+
62427+ schedule();
62428+ } while (1);
62429+
62430+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
62431+ learn_buffer_user_len = learn_buffer_len;
62432+ retval = learn_buffer_len;
62433+ learn_buffer_len = 0;
62434+
62435+ spin_unlock(&gr_learn_lock);
62436+
62437+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
62438+ retval = -EFAULT;
62439+
62440+ mutex_unlock(&gr_learn_user_mutex);
62441+out:
62442+ set_current_state(TASK_RUNNING);
62443+ remove_wait_queue(&learn_wait, &wait);
62444+ return retval;
62445+}
62446+
62447+static unsigned int
62448+poll_learn(struct file * file, poll_table * wait)
62449+{
62450+ poll_wait(file, &learn_wait, wait);
62451+
62452+ if (learn_buffer_len)
62453+ return (POLLIN | POLLRDNORM);
62454+
62455+ return 0;
62456+}
62457+
62458+void
62459+gr_clear_learn_entries(void)
62460+{
62461+ char *tmp;
62462+
62463+ mutex_lock(&gr_learn_user_mutex);
62464+ spin_lock(&gr_learn_lock);
62465+ tmp = learn_buffer;
62466+ learn_buffer = NULL;
62467+ spin_unlock(&gr_learn_lock);
62468+ if (tmp)
62469+ vfree(tmp);
62470+ if (learn_buffer_user != NULL) {
62471+ vfree(learn_buffer_user);
62472+ learn_buffer_user = NULL;
62473+ }
62474+ learn_buffer_len = 0;
62475+ mutex_unlock(&gr_learn_user_mutex);
62476+
62477+ return;
62478+}
62479+
62480+void
62481+gr_add_learn_entry(const char *fmt, ...)
62482+{
62483+ va_list args;
62484+ unsigned int len;
62485+
62486+ if (!gr_learn_attached)
62487+ return;
62488+
62489+ spin_lock(&gr_learn_lock);
62490+
62491+ /* leave a gap at the end so we know when it's "full" but don't have to
62492+ compute the exact length of the string we're trying to append
62493+ */
62494+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
62495+ spin_unlock(&gr_learn_lock);
62496+ wake_up_interruptible(&learn_wait);
62497+ return;
62498+ }
62499+ if (learn_buffer == NULL) {
62500+ spin_unlock(&gr_learn_lock);
62501+ return;
62502+ }
62503+
62504+ va_start(args, fmt);
62505+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62506+ va_end(args);
62507+
62508+ learn_buffer_len += len + 1;
62509+
62510+ spin_unlock(&gr_learn_lock);
62511+ wake_up_interruptible(&learn_wait);
62512+
62513+ return;
62514+}
62515+
62516+static int
62517+open_learn(struct inode *inode, struct file *file)
62518+{
62519+ if (file->f_mode & FMODE_READ && gr_learn_attached)
62520+ return -EBUSY;
62521+ if (file->f_mode & FMODE_READ) {
62522+ int retval = 0;
62523+ mutex_lock(&gr_learn_user_mutex);
62524+ if (learn_buffer == NULL)
62525+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62526+ if (learn_buffer_user == NULL)
62527+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62528+ if (learn_buffer == NULL) {
62529+ retval = -ENOMEM;
62530+ goto out_error;
62531+ }
62532+ if (learn_buffer_user == NULL) {
62533+ retval = -ENOMEM;
62534+ goto out_error;
62535+ }
62536+ learn_buffer_len = 0;
62537+ learn_buffer_user_len = 0;
62538+ gr_learn_attached = 1;
62539+out_error:
62540+ mutex_unlock(&gr_learn_user_mutex);
62541+ return retval;
62542+ }
62543+ return 0;
62544+}
62545+
62546+static int
62547+close_learn(struct inode *inode, struct file *file)
62548+{
62549+ if (file->f_mode & FMODE_READ) {
62550+ char *tmp = NULL;
62551+ mutex_lock(&gr_learn_user_mutex);
62552+ spin_lock(&gr_learn_lock);
62553+ tmp = learn_buffer;
62554+ learn_buffer = NULL;
62555+ spin_unlock(&gr_learn_lock);
62556+ if (tmp)
62557+ vfree(tmp);
62558+ if (learn_buffer_user != NULL) {
62559+ vfree(learn_buffer_user);
62560+ learn_buffer_user = NULL;
62561+ }
62562+ learn_buffer_len = 0;
62563+ learn_buffer_user_len = 0;
62564+ gr_learn_attached = 0;
62565+ mutex_unlock(&gr_learn_user_mutex);
62566+ }
62567+
62568+ return 0;
62569+}
62570+
62571+const struct file_operations grsec_fops = {
62572+ .read = read_learn,
62573+ .write = write_grsec_handler,
62574+ .open = open_learn,
62575+ .release = close_learn,
62576+ .poll = poll_learn,
62577+};
62578diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62579new file mode 100644
62580index 0000000..39645c9
62581--- /dev/null
62582+++ b/grsecurity/gracl_res.c
62583@@ -0,0 +1,68 @@
62584+#include <linux/kernel.h>
62585+#include <linux/sched.h>
62586+#include <linux/gracl.h>
62587+#include <linux/grinternal.h>
62588+
62589+static const char *restab_log[] = {
62590+ [RLIMIT_CPU] = "RLIMIT_CPU",
62591+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62592+ [RLIMIT_DATA] = "RLIMIT_DATA",
62593+ [RLIMIT_STACK] = "RLIMIT_STACK",
62594+ [RLIMIT_CORE] = "RLIMIT_CORE",
62595+ [RLIMIT_RSS] = "RLIMIT_RSS",
62596+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
62597+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62598+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62599+ [RLIMIT_AS] = "RLIMIT_AS",
62600+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62601+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62602+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62603+ [RLIMIT_NICE] = "RLIMIT_NICE",
62604+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62605+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62606+ [GR_CRASH_RES] = "RLIMIT_CRASH"
62607+};
62608+
62609+void
62610+gr_log_resource(const struct task_struct *task,
62611+ const int res, const unsigned long wanted, const int gt)
62612+{
62613+ const struct cred *cred;
62614+ unsigned long rlim;
62615+
62616+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
62617+ return;
62618+
62619+ // not yet supported resource
62620+ if (unlikely(!restab_log[res]))
62621+ return;
62622+
62623+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62624+ rlim = task_rlimit_max(task, res);
62625+ else
62626+ rlim = task_rlimit(task, res);
62627+
62628+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62629+ return;
62630+
62631+ rcu_read_lock();
62632+ cred = __task_cred(task);
62633+
62634+ if (res == RLIMIT_NPROC &&
62635+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62636+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62637+ goto out_rcu_unlock;
62638+ else if (res == RLIMIT_MEMLOCK &&
62639+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62640+ goto out_rcu_unlock;
62641+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62642+ goto out_rcu_unlock;
62643+ rcu_read_unlock();
62644+
62645+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62646+
62647+ return;
62648+out_rcu_unlock:
62649+ rcu_read_unlock();
62650+ return;
62651+}
62652diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62653new file mode 100644
62654index 0000000..8c8fc9d
62655--- /dev/null
62656+++ b/grsecurity/gracl_segv.c
62657@@ -0,0 +1,303 @@
62658+#include <linux/kernel.h>
62659+#include <linux/mm.h>
62660+#include <asm/uaccess.h>
62661+#include <asm/errno.h>
62662+#include <asm/mman.h>
62663+#include <net/sock.h>
62664+#include <linux/file.h>
62665+#include <linux/fs.h>
62666+#include <linux/net.h>
62667+#include <linux/in.h>
62668+#include <linux/slab.h>
62669+#include <linux/types.h>
62670+#include <linux/sched.h>
62671+#include <linux/timer.h>
62672+#include <linux/gracl.h>
62673+#include <linux/grsecurity.h>
62674+#include <linux/grinternal.h>
62675+
62676+static struct crash_uid *uid_set;
62677+static unsigned short uid_used;
62678+static DEFINE_SPINLOCK(gr_uid_lock);
62679+extern rwlock_t gr_inode_lock;
62680+extern struct acl_subject_label *
62681+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62682+ struct acl_role_label *role);
62683+
62684+#ifdef CONFIG_BTRFS_FS
62685+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62686+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62687+#endif
62688+
62689+static inline dev_t __get_dev(const struct dentry *dentry)
62690+{
62691+#ifdef CONFIG_BTRFS_FS
62692+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62693+ return get_btrfs_dev_from_inode(dentry->d_inode);
62694+ else
62695+#endif
62696+ return dentry->d_inode->i_sb->s_dev;
62697+}
62698+
62699+int
62700+gr_init_uidset(void)
62701+{
62702+ uid_set =
62703+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62704+ uid_used = 0;
62705+
62706+ return uid_set ? 1 : 0;
62707+}
62708+
62709+void
62710+gr_free_uidset(void)
62711+{
62712+ if (uid_set)
62713+ kfree(uid_set);
62714+
62715+ return;
62716+}
62717+
62718+int
62719+gr_find_uid(const uid_t uid)
62720+{
62721+ struct crash_uid *tmp = uid_set;
62722+ uid_t buid;
62723+ int low = 0, high = uid_used - 1, mid;
62724+
62725+ while (high >= low) {
62726+ mid = (low + high) >> 1;
62727+ buid = tmp[mid].uid;
62728+ if (buid == uid)
62729+ return mid;
62730+ if (buid > uid)
62731+ high = mid - 1;
62732+ if (buid < uid)
62733+ low = mid + 1;
62734+ }
62735+
62736+ return -1;
62737+}
62738+
62739+static __inline__ void
62740+gr_insertsort(void)
62741+{
62742+ unsigned short i, j;
62743+ struct crash_uid index;
62744+
62745+ for (i = 1; i < uid_used; i++) {
62746+ index = uid_set[i];
62747+ j = i;
62748+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62749+ uid_set[j] = uid_set[j - 1];
62750+ j--;
62751+ }
62752+ uid_set[j] = index;
62753+ }
62754+
62755+ return;
62756+}
62757+
62758+static __inline__ void
62759+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62760+{
62761+ int loc;
62762+ uid_t uid = GR_GLOBAL_UID(kuid);
62763+
62764+ if (uid_used == GR_UIDTABLE_MAX)
62765+ return;
62766+
62767+ loc = gr_find_uid(uid);
62768+
62769+ if (loc >= 0) {
62770+ uid_set[loc].expires = expires;
62771+ return;
62772+ }
62773+
62774+ uid_set[uid_used].uid = uid;
62775+ uid_set[uid_used].expires = expires;
62776+ uid_used++;
62777+
62778+ gr_insertsort();
62779+
62780+ return;
62781+}
62782+
62783+void
62784+gr_remove_uid(const unsigned short loc)
62785+{
62786+ unsigned short i;
62787+
62788+ for (i = loc + 1; i < uid_used; i++)
62789+ uid_set[i - 1] = uid_set[i];
62790+
62791+ uid_used--;
62792+
62793+ return;
62794+}
62795+
62796+int
62797+gr_check_crash_uid(const kuid_t kuid)
62798+{
62799+ int loc;
62800+ int ret = 0;
62801+ uid_t uid;
62802+
62803+ if (unlikely(!gr_acl_is_enabled()))
62804+ return 0;
62805+
62806+ uid = GR_GLOBAL_UID(kuid);
62807+
62808+ spin_lock(&gr_uid_lock);
62809+ loc = gr_find_uid(uid);
62810+
62811+ if (loc < 0)
62812+ goto out_unlock;
62813+
62814+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
62815+ gr_remove_uid(loc);
62816+ else
62817+ ret = 1;
62818+
62819+out_unlock:
62820+ spin_unlock(&gr_uid_lock);
62821+ return ret;
62822+}
62823+
62824+static __inline__ int
62825+proc_is_setxid(const struct cred *cred)
62826+{
62827+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62828+ !uid_eq(cred->uid, cred->fsuid))
62829+ return 1;
62830+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62831+ !gid_eq(cred->gid, cred->fsgid))
62832+ return 1;
62833+
62834+ return 0;
62835+}
62836+
62837+extern int gr_fake_force_sig(int sig, struct task_struct *t);
62838+
62839+void
62840+gr_handle_crash(struct task_struct *task, const int sig)
62841+{
62842+ struct acl_subject_label *curr;
62843+ struct task_struct *tsk, *tsk2;
62844+ const struct cred *cred;
62845+ const struct cred *cred2;
62846+
62847+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62848+ return;
62849+
62850+ if (unlikely(!gr_acl_is_enabled()))
62851+ return;
62852+
62853+ curr = task->acl;
62854+
62855+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
62856+ return;
62857+
62858+ if (time_before_eq(curr->expires, get_seconds())) {
62859+ curr->expires = 0;
62860+ curr->crashes = 0;
62861+ }
62862+
62863+ curr->crashes++;
62864+
62865+ if (!curr->expires)
62866+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62867+
62868+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62869+ time_after(curr->expires, get_seconds())) {
62870+ rcu_read_lock();
62871+ cred = __task_cred(task);
62872+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62873+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62874+ spin_lock(&gr_uid_lock);
62875+ gr_insert_uid(cred->uid, curr->expires);
62876+ spin_unlock(&gr_uid_lock);
62877+ curr->expires = 0;
62878+ curr->crashes = 0;
62879+ read_lock(&tasklist_lock);
62880+ do_each_thread(tsk2, tsk) {
62881+ cred2 = __task_cred(tsk);
62882+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
62883+ gr_fake_force_sig(SIGKILL, tsk);
62884+ } while_each_thread(tsk2, tsk);
62885+ read_unlock(&tasklist_lock);
62886+ } else {
62887+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62888+ read_lock(&tasklist_lock);
62889+ read_lock(&grsec_exec_file_lock);
62890+ do_each_thread(tsk2, tsk) {
62891+ if (likely(tsk != task)) {
62892+ // if this thread has the same subject as the one that triggered
62893+ // RES_CRASH and it's the same binary, kill it
62894+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62895+ gr_fake_force_sig(SIGKILL, tsk);
62896+ }
62897+ } while_each_thread(tsk2, tsk);
62898+ read_unlock(&grsec_exec_file_lock);
62899+ read_unlock(&tasklist_lock);
62900+ }
62901+ rcu_read_unlock();
62902+ }
62903+
62904+ return;
62905+}
62906+
62907+int
62908+gr_check_crash_exec(const struct file *filp)
62909+{
62910+ struct acl_subject_label *curr;
62911+
62912+ if (unlikely(!gr_acl_is_enabled()))
62913+ return 0;
62914+
62915+ read_lock(&gr_inode_lock);
62916+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62917+ __get_dev(filp->f_path.dentry),
62918+ current->role);
62919+ read_unlock(&gr_inode_lock);
62920+
62921+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62922+ (!curr->crashes && !curr->expires))
62923+ return 0;
62924+
62925+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62926+ time_after(curr->expires, get_seconds()))
62927+ return 1;
62928+ else if (time_before_eq(curr->expires, get_seconds())) {
62929+ curr->crashes = 0;
62930+ curr->expires = 0;
62931+ }
62932+
62933+ return 0;
62934+}
62935+
62936+void
62937+gr_handle_alertkill(struct task_struct *task)
62938+{
62939+ struct acl_subject_label *curracl;
62940+ __u32 curr_ip;
62941+ struct task_struct *p, *p2;
62942+
62943+ if (unlikely(!gr_acl_is_enabled()))
62944+ return;
62945+
62946+ curracl = task->acl;
62947+ curr_ip = task->signal->curr_ip;
62948+
62949+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62950+ read_lock(&tasklist_lock);
62951+ do_each_thread(p2, p) {
62952+ if (p->signal->curr_ip == curr_ip)
62953+ gr_fake_force_sig(SIGKILL, p);
62954+ } while_each_thread(p2, p);
62955+ read_unlock(&tasklist_lock);
62956+ } else if (curracl->mode & GR_KILLPROC)
62957+ gr_fake_force_sig(SIGKILL, task);
62958+
62959+ return;
62960+}
62961diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62962new file mode 100644
62963index 0000000..98011b0
62964--- /dev/null
62965+++ b/grsecurity/gracl_shm.c
62966@@ -0,0 +1,40 @@
62967+#include <linux/kernel.h>
62968+#include <linux/mm.h>
62969+#include <linux/sched.h>
62970+#include <linux/file.h>
62971+#include <linux/ipc.h>
62972+#include <linux/gracl.h>
62973+#include <linux/grsecurity.h>
62974+#include <linux/grinternal.h>
62975+
62976+int
62977+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62978+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
62979+{
62980+ struct task_struct *task;
62981+
62982+ if (!gr_acl_is_enabled())
62983+ return 1;
62984+
62985+ rcu_read_lock();
62986+ read_lock(&tasklist_lock);
62987+
62988+ task = find_task_by_vpid(shm_cprid);
62989+
62990+ if (unlikely(!task))
62991+ task = find_task_by_vpid(shm_lapid);
62992+
62993+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62994+ (task_pid_nr(task) == shm_lapid)) &&
62995+ (task->acl->mode & GR_PROTSHM) &&
62996+ (task->acl != current->acl))) {
62997+ read_unlock(&tasklist_lock);
62998+ rcu_read_unlock();
62999+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63000+ return 0;
63001+ }
63002+ read_unlock(&tasklist_lock);
63003+ rcu_read_unlock();
63004+
63005+ return 1;
63006+}
63007diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63008new file mode 100644
63009index 0000000..bc0be01
63010--- /dev/null
63011+++ b/grsecurity/grsec_chdir.c
63012@@ -0,0 +1,19 @@
63013+#include <linux/kernel.h>
63014+#include <linux/sched.h>
63015+#include <linux/fs.h>
63016+#include <linux/file.h>
63017+#include <linux/grsecurity.h>
63018+#include <linux/grinternal.h>
63019+
63020+void
63021+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63022+{
63023+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63024+ if ((grsec_enable_chdir && grsec_enable_group &&
63025+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63026+ !grsec_enable_group)) {
63027+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63028+ }
63029+#endif
63030+ return;
63031+}
63032diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63033new file mode 100644
63034index 0000000..6d2de57
63035--- /dev/null
63036+++ b/grsecurity/grsec_chroot.c
63037@@ -0,0 +1,357 @@
63038+#include <linux/kernel.h>
63039+#include <linux/module.h>
63040+#include <linux/sched.h>
63041+#include <linux/file.h>
63042+#include <linux/fs.h>
63043+#include <linux/mount.h>
63044+#include <linux/types.h>
63045+#include "../fs/mount.h"
63046+#include <linux/grsecurity.h>
63047+#include <linux/grinternal.h>
63048+
63049+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
63050+{
63051+#ifdef CONFIG_GRKERNSEC
63052+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
63053+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
63054+ task->gr_is_chrooted = 1;
63055+ else
63056+ task->gr_is_chrooted = 0;
63057+
63058+ task->gr_chroot_dentry = path->dentry;
63059+#endif
63060+ return;
63061+}
63062+
63063+void gr_clear_chroot_entries(struct task_struct *task)
63064+{
63065+#ifdef CONFIG_GRKERNSEC
63066+ task->gr_is_chrooted = 0;
63067+ task->gr_chroot_dentry = NULL;
63068+#endif
63069+ return;
63070+}
63071+
63072+int
63073+gr_handle_chroot_unix(const pid_t pid)
63074+{
63075+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63076+ struct task_struct *p;
63077+
63078+ if (unlikely(!grsec_enable_chroot_unix))
63079+ return 1;
63080+
63081+ if (likely(!proc_is_chrooted(current)))
63082+ return 1;
63083+
63084+ rcu_read_lock();
63085+ read_lock(&tasklist_lock);
63086+ p = find_task_by_vpid_unrestricted(pid);
63087+ if (unlikely(p && !have_same_root(current, p))) {
63088+ read_unlock(&tasklist_lock);
63089+ rcu_read_unlock();
63090+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
63091+ return 0;
63092+ }
63093+ read_unlock(&tasklist_lock);
63094+ rcu_read_unlock();
63095+#endif
63096+ return 1;
63097+}
63098+
63099+int
63100+gr_handle_chroot_nice(void)
63101+{
63102+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63103+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
63104+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
63105+ return -EPERM;
63106+ }
63107+#endif
63108+ return 0;
63109+}
63110+
63111+int
63112+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
63113+{
63114+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63115+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
63116+ && proc_is_chrooted(current)) {
63117+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
63118+ return -EACCES;
63119+ }
63120+#endif
63121+ return 0;
63122+}
63123+
63124+int
63125+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
63126+{
63127+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63128+ struct task_struct *p;
63129+ int ret = 0;
63130+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
63131+ return ret;
63132+
63133+ read_lock(&tasklist_lock);
63134+ do_each_pid_task(pid, type, p) {
63135+ if (!have_same_root(current, p)) {
63136+ ret = 1;
63137+ goto out;
63138+ }
63139+ } while_each_pid_task(pid, type, p);
63140+out:
63141+ read_unlock(&tasklist_lock);
63142+ return ret;
63143+#endif
63144+ return 0;
63145+}
63146+
63147+int
63148+gr_pid_is_chrooted(struct task_struct *p)
63149+{
63150+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63151+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
63152+ return 0;
63153+
63154+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
63155+ !have_same_root(current, p)) {
63156+ return 1;
63157+ }
63158+#endif
63159+ return 0;
63160+}
63161+
63162+EXPORT_SYMBOL(gr_pid_is_chrooted);
63163+
63164+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
63165+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
63166+{
63167+ struct path path, currentroot;
63168+ int ret = 0;
63169+
63170+ path.dentry = (struct dentry *)u_dentry;
63171+ path.mnt = (struct vfsmount *)u_mnt;
63172+ get_fs_root(current->fs, &currentroot);
63173+ if (path_is_under(&path, &currentroot))
63174+ ret = 1;
63175+ path_put(&currentroot);
63176+
63177+ return ret;
63178+}
63179+#endif
63180+
63181+int
63182+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
63183+{
63184+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63185+ if (!grsec_enable_chroot_fchdir)
63186+ return 1;
63187+
63188+ if (!proc_is_chrooted(current))
63189+ return 1;
63190+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
63191+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
63192+ return 0;
63193+ }
63194+#endif
63195+ return 1;
63196+}
63197+
63198+int
63199+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63200+ const time_t shm_createtime)
63201+{
63202+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63203+ struct task_struct *p;
63204+ time_t starttime;
63205+
63206+ if (unlikely(!grsec_enable_chroot_shmat))
63207+ return 1;
63208+
63209+ if (likely(!proc_is_chrooted(current)))
63210+ return 1;
63211+
63212+ rcu_read_lock();
63213+ read_lock(&tasklist_lock);
63214+
63215+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
63216+ starttime = p->start_time.tv_sec;
63217+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
63218+ if (have_same_root(current, p)) {
63219+ goto allow;
63220+ } else {
63221+ read_unlock(&tasklist_lock);
63222+ rcu_read_unlock();
63223+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63224+ return 0;
63225+ }
63226+ }
63227+ /* creator exited, pid reuse, fall through to next check */
63228+ }
63229+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
63230+ if (unlikely(!have_same_root(current, p))) {
63231+ read_unlock(&tasklist_lock);
63232+ rcu_read_unlock();
63233+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63234+ return 0;
63235+ }
63236+ }
63237+
63238+allow:
63239+ read_unlock(&tasklist_lock);
63240+ rcu_read_unlock();
63241+#endif
63242+ return 1;
63243+}
63244+
63245+void
63246+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
63247+{
63248+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63249+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
63250+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
63251+#endif
63252+ return;
63253+}
63254+
63255+int
63256+gr_handle_chroot_mknod(const struct dentry *dentry,
63257+ const struct vfsmount *mnt, const int mode)
63258+{
63259+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63260+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
63261+ proc_is_chrooted(current)) {
63262+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
63263+ return -EPERM;
63264+ }
63265+#endif
63266+ return 0;
63267+}
63268+
63269+int
63270+gr_handle_chroot_mount(const struct dentry *dentry,
63271+ const struct vfsmount *mnt, const char *dev_name)
63272+{
63273+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63274+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
63275+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
63276+ return -EPERM;
63277+ }
63278+#endif
63279+ return 0;
63280+}
63281+
63282+int
63283+gr_handle_chroot_pivot(void)
63284+{
63285+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63286+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
63287+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
63288+ return -EPERM;
63289+ }
63290+#endif
63291+ return 0;
63292+}
63293+
63294+int
63295+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
63296+{
63297+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63298+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
63299+ !gr_is_outside_chroot(dentry, mnt)) {
63300+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
63301+ return -EPERM;
63302+ }
63303+#endif
63304+ return 0;
63305+}
63306+
63307+extern const char *captab_log[];
63308+extern int captab_log_entries;
63309+
63310+int
63311+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63312+{
63313+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63314+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63315+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63316+ if (cap_raised(chroot_caps, cap)) {
63317+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
63318+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
63319+ }
63320+ return 0;
63321+ }
63322+ }
63323+#endif
63324+ return 1;
63325+}
63326+
63327+int
63328+gr_chroot_is_capable(const int cap)
63329+{
63330+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63331+ return gr_task_chroot_is_capable(current, current_cred(), cap);
63332+#endif
63333+ return 1;
63334+}
63335+
63336+int
63337+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
63338+{
63339+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63340+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63341+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63342+ if (cap_raised(chroot_caps, cap)) {
63343+ return 0;
63344+ }
63345+ }
63346+#endif
63347+ return 1;
63348+}
63349+
63350+int
63351+gr_chroot_is_capable_nolog(const int cap)
63352+{
63353+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63354+ return gr_task_chroot_is_capable_nolog(current, cap);
63355+#endif
63356+ return 1;
63357+}
63358+
63359+int
63360+gr_handle_chroot_sysctl(const int op)
63361+{
63362+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63363+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
63364+ proc_is_chrooted(current))
63365+ return -EACCES;
63366+#endif
63367+ return 0;
63368+}
63369+
63370+void
63371+gr_handle_chroot_chdir(struct path *path)
63372+{
63373+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63374+ if (grsec_enable_chroot_chdir)
63375+ set_fs_pwd(current->fs, path);
63376+#endif
63377+ return;
63378+}
63379+
63380+int
63381+gr_handle_chroot_chmod(const struct dentry *dentry,
63382+ const struct vfsmount *mnt, const int mode)
63383+{
63384+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63385+ /* allow chmod +s on directories, but not files */
63386+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
63387+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
63388+ proc_is_chrooted(current)) {
63389+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
63390+ return -EPERM;
63391+ }
63392+#endif
63393+ return 0;
63394+}
63395diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
63396new file mode 100644
63397index 0000000..207d409
63398--- /dev/null
63399+++ b/grsecurity/grsec_disabled.c
63400@@ -0,0 +1,434 @@
63401+#include <linux/kernel.h>
63402+#include <linux/module.h>
63403+#include <linux/sched.h>
63404+#include <linux/file.h>
63405+#include <linux/fs.h>
63406+#include <linux/kdev_t.h>
63407+#include <linux/net.h>
63408+#include <linux/in.h>
63409+#include <linux/ip.h>
63410+#include <linux/skbuff.h>
63411+#include <linux/sysctl.h>
63412+
63413+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63414+void
63415+pax_set_initial_flags(struct linux_binprm *bprm)
63416+{
63417+ return;
63418+}
63419+#endif
63420+
63421+#ifdef CONFIG_SYSCTL
63422+__u32
63423+gr_handle_sysctl(const struct ctl_table * table, const int op)
63424+{
63425+ return 0;
63426+}
63427+#endif
63428+
63429+#ifdef CONFIG_TASKSTATS
63430+int gr_is_taskstats_denied(int pid)
63431+{
63432+ return 0;
63433+}
63434+#endif
63435+
63436+int
63437+gr_acl_is_enabled(void)
63438+{
63439+ return 0;
63440+}
63441+
63442+void
63443+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
63444+{
63445+ return;
63446+}
63447+
63448+int
63449+gr_handle_rawio(const struct inode *inode)
63450+{
63451+ return 0;
63452+}
63453+
63454+void
63455+gr_acl_handle_psacct(struct task_struct *task, const long code)
63456+{
63457+ return;
63458+}
63459+
63460+int
63461+gr_handle_ptrace(struct task_struct *task, const long request)
63462+{
63463+ return 0;
63464+}
63465+
63466+int
63467+gr_handle_proc_ptrace(struct task_struct *task)
63468+{
63469+ return 0;
63470+}
63471+
63472+int
63473+gr_set_acls(const int type)
63474+{
63475+ return 0;
63476+}
63477+
63478+int
63479+gr_check_hidden_task(const struct task_struct *tsk)
63480+{
63481+ return 0;
63482+}
63483+
63484+int
63485+gr_check_protected_task(const struct task_struct *task)
63486+{
63487+ return 0;
63488+}
63489+
63490+int
63491+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
63492+{
63493+ return 0;
63494+}
63495+
63496+void
63497+gr_copy_label(struct task_struct *tsk)
63498+{
63499+ return;
63500+}
63501+
63502+void
63503+gr_set_pax_flags(struct task_struct *task)
63504+{
63505+ return;
63506+}
63507+
63508+int
63509+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63510+ const int unsafe_share)
63511+{
63512+ return 0;
63513+}
63514+
63515+void
63516+gr_handle_delete(const ino_t ino, const dev_t dev)
63517+{
63518+ return;
63519+}
63520+
63521+void
63522+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63523+{
63524+ return;
63525+}
63526+
63527+void
63528+gr_handle_crash(struct task_struct *task, const int sig)
63529+{
63530+ return;
63531+}
63532+
63533+int
63534+gr_check_crash_exec(const struct file *filp)
63535+{
63536+ return 0;
63537+}
63538+
63539+int
63540+gr_check_crash_uid(const kuid_t uid)
63541+{
63542+ return 0;
63543+}
63544+
63545+void
63546+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63547+ struct dentry *old_dentry,
63548+ struct dentry *new_dentry,
63549+ struct vfsmount *mnt, const __u8 replace)
63550+{
63551+ return;
63552+}
63553+
63554+int
63555+gr_search_socket(const int family, const int type, const int protocol)
63556+{
63557+ return 1;
63558+}
63559+
63560+int
63561+gr_search_connectbind(const int mode, const struct socket *sock,
63562+ const struct sockaddr_in *addr)
63563+{
63564+ return 0;
63565+}
63566+
63567+void
63568+gr_handle_alertkill(struct task_struct *task)
63569+{
63570+ return;
63571+}
63572+
63573+__u32
63574+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63575+{
63576+ return 1;
63577+}
63578+
63579+__u32
63580+gr_acl_handle_hidden_file(const struct dentry * dentry,
63581+ const struct vfsmount * mnt)
63582+{
63583+ return 1;
63584+}
63585+
63586+__u32
63587+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63588+ int acc_mode)
63589+{
63590+ return 1;
63591+}
63592+
63593+__u32
63594+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63595+{
63596+ return 1;
63597+}
63598+
63599+__u32
63600+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63601+{
63602+ return 1;
63603+}
63604+
63605+int
63606+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63607+ unsigned int *vm_flags)
63608+{
63609+ return 1;
63610+}
63611+
63612+__u32
63613+gr_acl_handle_truncate(const struct dentry * dentry,
63614+ const struct vfsmount * mnt)
63615+{
63616+ return 1;
63617+}
63618+
63619+__u32
63620+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63621+{
63622+ return 1;
63623+}
63624+
63625+__u32
63626+gr_acl_handle_access(const struct dentry * dentry,
63627+ const struct vfsmount * mnt, const int fmode)
63628+{
63629+ return 1;
63630+}
63631+
63632+__u32
63633+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63634+ umode_t *mode)
63635+{
63636+ return 1;
63637+}
63638+
63639+__u32
63640+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63641+{
63642+ return 1;
63643+}
63644+
63645+__u32
63646+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63647+{
63648+ return 1;
63649+}
63650+
63651+void
63652+grsecurity_init(void)
63653+{
63654+ return;
63655+}
63656+
63657+umode_t gr_acl_umask(void)
63658+{
63659+ return 0;
63660+}
63661+
63662+__u32
63663+gr_acl_handle_mknod(const struct dentry * new_dentry,
63664+ const struct dentry * parent_dentry,
63665+ const struct vfsmount * parent_mnt,
63666+ const int mode)
63667+{
63668+ return 1;
63669+}
63670+
63671+__u32
63672+gr_acl_handle_mkdir(const struct dentry * new_dentry,
63673+ const struct dentry * parent_dentry,
63674+ const struct vfsmount * parent_mnt)
63675+{
63676+ return 1;
63677+}
63678+
63679+__u32
63680+gr_acl_handle_symlink(const struct dentry * new_dentry,
63681+ const struct dentry * parent_dentry,
63682+ const struct vfsmount * parent_mnt, const struct filename *from)
63683+{
63684+ return 1;
63685+}
63686+
63687+__u32
63688+gr_acl_handle_link(const struct dentry * new_dentry,
63689+ const struct dentry * parent_dentry,
63690+ const struct vfsmount * parent_mnt,
63691+ const struct dentry * old_dentry,
63692+ const struct vfsmount * old_mnt, const struct filename *to)
63693+{
63694+ return 1;
63695+}
63696+
63697+int
63698+gr_acl_handle_rename(const struct dentry *new_dentry,
63699+ const struct dentry *parent_dentry,
63700+ const struct vfsmount *parent_mnt,
63701+ const struct dentry *old_dentry,
63702+ const struct inode *old_parent_inode,
63703+ const struct vfsmount *old_mnt, const struct filename *newname)
63704+{
63705+ return 0;
63706+}
63707+
63708+int
63709+gr_acl_handle_filldir(const struct file *file, const char *name,
63710+ const int namelen, const ino_t ino)
63711+{
63712+ return 1;
63713+}
63714+
63715+int
63716+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63717+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63718+{
63719+ return 1;
63720+}
63721+
63722+int
63723+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63724+{
63725+ return 0;
63726+}
63727+
63728+int
63729+gr_search_accept(const struct socket *sock)
63730+{
63731+ return 0;
63732+}
63733+
63734+int
63735+gr_search_listen(const struct socket *sock)
63736+{
63737+ return 0;
63738+}
63739+
63740+int
63741+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63742+{
63743+ return 0;
63744+}
63745+
63746+__u32
63747+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63748+{
63749+ return 1;
63750+}
63751+
63752+__u32
63753+gr_acl_handle_creat(const struct dentry * dentry,
63754+ const struct dentry * p_dentry,
63755+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63756+ const int imode)
63757+{
63758+ return 1;
63759+}
63760+
63761+void
63762+gr_acl_handle_exit(void)
63763+{
63764+ return;
63765+}
63766+
63767+int
63768+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63769+{
63770+ return 1;
63771+}
63772+
63773+void
63774+gr_set_role_label(const kuid_t uid, const kgid_t gid)
63775+{
63776+ return;
63777+}
63778+
63779+int
63780+gr_acl_handle_procpidmem(const struct task_struct *task)
63781+{
63782+ return 0;
63783+}
63784+
63785+int
63786+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63787+{
63788+ return 0;
63789+}
63790+
63791+int
63792+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63793+{
63794+ return 0;
63795+}
63796+
63797+void
63798+gr_set_kernel_label(struct task_struct *task)
63799+{
63800+ return;
63801+}
63802+
63803+int
63804+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63805+{
63806+ return 0;
63807+}
63808+
63809+int
63810+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63811+{
63812+ return 0;
63813+}
63814+
63815+int gr_acl_enable_at_secure(void)
63816+{
63817+ return 0;
63818+}
63819+
63820+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63821+{
63822+ return dentry->d_inode->i_sb->s_dev;
63823+}
63824+
63825+void gr_put_exec_file(struct task_struct *task)
63826+{
63827+ return;
63828+}
63829+
63830+EXPORT_SYMBOL(gr_set_kernel_label);
63831+#ifdef CONFIG_SECURITY
63832+EXPORT_SYMBOL(gr_check_user_change);
63833+EXPORT_SYMBOL(gr_check_group_change);
63834+#endif
63835diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63836new file mode 100644
63837index 0000000..387032b
63838--- /dev/null
63839+++ b/grsecurity/grsec_exec.c
63840@@ -0,0 +1,187 @@
63841+#include <linux/kernel.h>
63842+#include <linux/sched.h>
63843+#include <linux/file.h>
63844+#include <linux/binfmts.h>
63845+#include <linux/fs.h>
63846+#include <linux/types.h>
63847+#include <linux/grdefs.h>
63848+#include <linux/grsecurity.h>
63849+#include <linux/grinternal.h>
63850+#include <linux/capability.h>
63851+#include <linux/module.h>
63852+#include <linux/compat.h>
63853+
63854+#include <asm/uaccess.h>
63855+
63856+#ifdef CONFIG_GRKERNSEC_EXECLOG
63857+static char gr_exec_arg_buf[132];
63858+static DEFINE_MUTEX(gr_exec_arg_mutex);
63859+#endif
63860+
63861+struct user_arg_ptr {
63862+#ifdef CONFIG_COMPAT
63863+ bool is_compat;
63864+#endif
63865+ union {
63866+ const char __user *const __user *native;
63867+#ifdef CONFIG_COMPAT
63868+ const compat_uptr_t __user *compat;
63869+#endif
63870+ } ptr;
63871+};
63872+
63873+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63874+
63875+void
63876+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63877+{
63878+#ifdef CONFIG_GRKERNSEC_EXECLOG
63879+ char *grarg = gr_exec_arg_buf;
63880+ unsigned int i, x, execlen = 0;
63881+ char c;
63882+
63883+ if (!((grsec_enable_execlog && grsec_enable_group &&
63884+ in_group_p(grsec_audit_gid))
63885+ || (grsec_enable_execlog && !grsec_enable_group)))
63886+ return;
63887+
63888+ mutex_lock(&gr_exec_arg_mutex);
63889+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
63890+
63891+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
63892+ const char __user *p;
63893+ unsigned int len;
63894+
63895+ p = get_user_arg_ptr(argv, i);
63896+ if (IS_ERR(p))
63897+ goto log;
63898+
63899+ len = strnlen_user(p, 128 - execlen);
63900+ if (len > 128 - execlen)
63901+ len = 128 - execlen;
63902+ else if (len > 0)
63903+ len--;
63904+ if (copy_from_user(grarg + execlen, p, len))
63905+ goto log;
63906+
63907+ /* rewrite unprintable characters */
63908+ for (x = 0; x < len; x++) {
63909+ c = *(grarg + execlen + x);
63910+ if (c < 32 || c > 126)
63911+ *(grarg + execlen + x) = ' ';
63912+ }
63913+
63914+ execlen += len;
63915+ *(grarg + execlen) = ' ';
63916+ *(grarg + execlen + 1) = '\0';
63917+ execlen++;
63918+ }
63919+
63920+ log:
63921+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63922+ bprm->file->f_path.mnt, grarg);
63923+ mutex_unlock(&gr_exec_arg_mutex);
63924+#endif
63925+ return;
63926+}
63927+
63928+#ifdef CONFIG_GRKERNSEC
63929+extern int gr_acl_is_capable(const int cap);
63930+extern int gr_acl_is_capable_nolog(const int cap);
63931+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63932+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63933+extern int gr_chroot_is_capable(const int cap);
63934+extern int gr_chroot_is_capable_nolog(const int cap);
63935+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63936+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63937+#endif
63938+
63939+const char *captab_log[] = {
63940+ "CAP_CHOWN",
63941+ "CAP_DAC_OVERRIDE",
63942+ "CAP_DAC_READ_SEARCH",
63943+ "CAP_FOWNER",
63944+ "CAP_FSETID",
63945+ "CAP_KILL",
63946+ "CAP_SETGID",
63947+ "CAP_SETUID",
63948+ "CAP_SETPCAP",
63949+ "CAP_LINUX_IMMUTABLE",
63950+ "CAP_NET_BIND_SERVICE",
63951+ "CAP_NET_BROADCAST",
63952+ "CAP_NET_ADMIN",
63953+ "CAP_NET_RAW",
63954+ "CAP_IPC_LOCK",
63955+ "CAP_IPC_OWNER",
63956+ "CAP_SYS_MODULE",
63957+ "CAP_SYS_RAWIO",
63958+ "CAP_SYS_CHROOT",
63959+ "CAP_SYS_PTRACE",
63960+ "CAP_SYS_PACCT",
63961+ "CAP_SYS_ADMIN",
63962+ "CAP_SYS_BOOT",
63963+ "CAP_SYS_NICE",
63964+ "CAP_SYS_RESOURCE",
63965+ "CAP_SYS_TIME",
63966+ "CAP_SYS_TTY_CONFIG",
63967+ "CAP_MKNOD",
63968+ "CAP_LEASE",
63969+ "CAP_AUDIT_WRITE",
63970+ "CAP_AUDIT_CONTROL",
63971+ "CAP_SETFCAP",
63972+ "CAP_MAC_OVERRIDE",
63973+ "CAP_MAC_ADMIN",
63974+ "CAP_SYSLOG",
63975+ "CAP_WAKE_ALARM"
63976+};
63977+
63978+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63979+
63980+int gr_is_capable(const int cap)
63981+{
63982+#ifdef CONFIG_GRKERNSEC
63983+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63984+ return 1;
63985+ return 0;
63986+#else
63987+ return 1;
63988+#endif
63989+}
63990+
63991+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63992+{
63993+#ifdef CONFIG_GRKERNSEC
63994+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63995+ return 1;
63996+ return 0;
63997+#else
63998+ return 1;
63999+#endif
64000+}
64001+
64002+int gr_is_capable_nolog(const int cap)
64003+{
64004+#ifdef CONFIG_GRKERNSEC
64005+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64006+ return 1;
64007+ return 0;
64008+#else
64009+ return 1;
64010+#endif
64011+}
64012+
64013+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64014+{
64015+#ifdef CONFIG_GRKERNSEC
64016+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64017+ return 1;
64018+ return 0;
64019+#else
64020+ return 1;
64021+#endif
64022+}
64023+
64024+EXPORT_SYMBOL(gr_is_capable);
64025+EXPORT_SYMBOL(gr_is_capable_nolog);
64026+EXPORT_SYMBOL(gr_task_is_capable);
64027+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64028diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64029new file mode 100644
64030index 0000000..06cc6ea
64031--- /dev/null
64032+++ b/grsecurity/grsec_fifo.c
64033@@ -0,0 +1,24 @@
64034+#include <linux/kernel.h>
64035+#include <linux/sched.h>
64036+#include <linux/fs.h>
64037+#include <linux/file.h>
64038+#include <linux/grinternal.h>
64039+
64040+int
64041+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
64042+ const struct dentry *dir, const int flag, const int acc_mode)
64043+{
64044+#ifdef CONFIG_GRKERNSEC_FIFO
64045+ const struct cred *cred = current_cred();
64046+
64047+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
64048+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
64049+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
64050+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
64051+ if (!inode_permission(dentry->d_inode, acc_mode))
64052+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, GR_GLOBAL_UID(dentry->d_inode->i_uid), GR_GLOBAL_GID(dentry->d_inode->i_gid));
64053+ return -EACCES;
64054+ }
64055+#endif
64056+ return 0;
64057+}
64058diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
64059new file mode 100644
64060index 0000000..8ca18bf
64061--- /dev/null
64062+++ b/grsecurity/grsec_fork.c
64063@@ -0,0 +1,23 @@
64064+#include <linux/kernel.h>
64065+#include <linux/sched.h>
64066+#include <linux/grsecurity.h>
64067+#include <linux/grinternal.h>
64068+#include <linux/errno.h>
64069+
64070+void
64071+gr_log_forkfail(const int retval)
64072+{
64073+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64074+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
64075+ switch (retval) {
64076+ case -EAGAIN:
64077+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
64078+ break;
64079+ case -ENOMEM:
64080+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
64081+ break;
64082+ }
64083+ }
64084+#endif
64085+ return;
64086+}
64087diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
64088new file mode 100644
64089index 0000000..a862e9f
64090--- /dev/null
64091+++ b/grsecurity/grsec_init.c
64092@@ -0,0 +1,283 @@
64093+#include <linux/kernel.h>
64094+#include <linux/sched.h>
64095+#include <linux/mm.h>
64096+#include <linux/gracl.h>
64097+#include <linux/slab.h>
64098+#include <linux/vmalloc.h>
64099+#include <linux/percpu.h>
64100+#include <linux/module.h>
64101+
64102+int grsec_enable_ptrace_readexec;
64103+int grsec_enable_setxid;
64104+int grsec_enable_symlinkown;
64105+kgid_t grsec_symlinkown_gid;
64106+int grsec_enable_brute;
64107+int grsec_enable_link;
64108+int grsec_enable_dmesg;
64109+int grsec_enable_harden_ptrace;
64110+int grsec_enable_fifo;
64111+int grsec_enable_execlog;
64112+int grsec_enable_signal;
64113+int grsec_enable_forkfail;
64114+int grsec_enable_audit_ptrace;
64115+int grsec_enable_time;
64116+int grsec_enable_audit_textrel;
64117+int grsec_enable_group;
64118+kgid_t grsec_audit_gid;
64119+int grsec_enable_chdir;
64120+int grsec_enable_mount;
64121+int grsec_enable_rofs;
64122+int grsec_enable_chroot_findtask;
64123+int grsec_enable_chroot_mount;
64124+int grsec_enable_chroot_shmat;
64125+int grsec_enable_chroot_fchdir;
64126+int grsec_enable_chroot_double;
64127+int grsec_enable_chroot_pivot;
64128+int grsec_enable_chroot_chdir;
64129+int grsec_enable_chroot_chmod;
64130+int grsec_enable_chroot_mknod;
64131+int grsec_enable_chroot_nice;
64132+int grsec_enable_chroot_execlog;
64133+int grsec_enable_chroot_caps;
64134+int grsec_enable_chroot_sysctl;
64135+int grsec_enable_chroot_unix;
64136+int grsec_enable_tpe;
64137+kgid_t grsec_tpe_gid;
64138+int grsec_enable_blackhole;
64139+#ifdef CONFIG_IPV6_MODULE
64140+EXPORT_SYMBOL(grsec_enable_blackhole);
64141+#endif
64142+int grsec_lastack_retries;
64143+int grsec_enable_tpe_all;
64144+int grsec_enable_tpe_invert;
64145+int grsec_enable_socket_all;
64146+kgid_t grsec_socket_all_gid;
64147+int grsec_enable_socket_client;
64148+kgid_t grsec_socket_client_gid;
64149+int grsec_enable_socket_server;
64150+kgid_t grsec_socket_server_gid;
64151+int grsec_resource_logging;
64152+int grsec_disable_privio;
64153+int grsec_enable_log_rwxmaps;
64154+int grsec_lock;
64155+
64156+DEFINE_SPINLOCK(grsec_alert_lock);
64157+unsigned long grsec_alert_wtime = 0;
64158+unsigned long grsec_alert_fyet = 0;
64159+
64160+DEFINE_SPINLOCK(grsec_audit_lock);
64161+
64162+DEFINE_RWLOCK(grsec_exec_file_lock);
64163+
64164+char *gr_shared_page[4];
64165+
64166+char *gr_alert_log_fmt;
64167+char *gr_audit_log_fmt;
64168+char *gr_alert_log_buf;
64169+char *gr_audit_log_buf;
64170+
64171+extern struct gr_arg *gr_usermode;
64172+extern unsigned char *gr_system_salt;
64173+extern unsigned char *gr_system_sum;
64174+
64175+void __init
64176+grsecurity_init(void)
64177+{
64178+ int j;
64179+ /* create the per-cpu shared pages */
64180+
64181+#ifdef CONFIG_X86
64182+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
64183+#endif
64184+
64185+ for (j = 0; j < 4; j++) {
64186+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
64187+ if (gr_shared_page[j] == NULL) {
64188+ panic("Unable to allocate grsecurity shared page");
64189+ return;
64190+ }
64191+ }
64192+
64193+ /* allocate log buffers */
64194+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
64195+ if (!gr_alert_log_fmt) {
64196+ panic("Unable to allocate grsecurity alert log format buffer");
64197+ return;
64198+ }
64199+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
64200+ if (!gr_audit_log_fmt) {
64201+ panic("Unable to allocate grsecurity audit log format buffer");
64202+ return;
64203+ }
64204+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64205+ if (!gr_alert_log_buf) {
64206+ panic("Unable to allocate grsecurity alert log buffer");
64207+ return;
64208+ }
64209+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64210+ if (!gr_audit_log_buf) {
64211+ panic("Unable to allocate grsecurity audit log buffer");
64212+ return;
64213+ }
64214+
64215+ /* allocate memory for authentication structure */
64216+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
64217+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
64218+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
64219+
64220+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
64221+ panic("Unable to allocate grsecurity authentication structure");
64222+ return;
64223+ }
64224+
64225+
64226+#ifdef CONFIG_GRKERNSEC_IO
64227+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
64228+ grsec_disable_privio = 1;
64229+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64230+ grsec_disable_privio = 1;
64231+#else
64232+ grsec_disable_privio = 0;
64233+#endif
64234+#endif
64235+
64236+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64237+ /* for backward compatibility, tpe_invert always defaults to on if
64238+ enabled in the kernel
64239+ */
64240+ grsec_enable_tpe_invert = 1;
64241+#endif
64242+
64243+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64244+#ifndef CONFIG_GRKERNSEC_SYSCTL
64245+ grsec_lock = 1;
64246+#endif
64247+
64248+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64249+ grsec_enable_audit_textrel = 1;
64250+#endif
64251+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64252+ grsec_enable_log_rwxmaps = 1;
64253+#endif
64254+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64255+ grsec_enable_group = 1;
64256+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
64257+#endif
64258+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64259+ grsec_enable_ptrace_readexec = 1;
64260+#endif
64261+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64262+ grsec_enable_chdir = 1;
64263+#endif
64264+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64265+ grsec_enable_harden_ptrace = 1;
64266+#endif
64267+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64268+ grsec_enable_mount = 1;
64269+#endif
64270+#ifdef CONFIG_GRKERNSEC_LINK
64271+ grsec_enable_link = 1;
64272+#endif
64273+#ifdef CONFIG_GRKERNSEC_BRUTE
64274+ grsec_enable_brute = 1;
64275+#endif
64276+#ifdef CONFIG_GRKERNSEC_DMESG
64277+ grsec_enable_dmesg = 1;
64278+#endif
64279+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64280+ grsec_enable_blackhole = 1;
64281+ grsec_lastack_retries = 4;
64282+#endif
64283+#ifdef CONFIG_GRKERNSEC_FIFO
64284+ grsec_enable_fifo = 1;
64285+#endif
64286+#ifdef CONFIG_GRKERNSEC_EXECLOG
64287+ grsec_enable_execlog = 1;
64288+#endif
64289+#ifdef CONFIG_GRKERNSEC_SETXID
64290+ grsec_enable_setxid = 1;
64291+#endif
64292+#ifdef CONFIG_GRKERNSEC_SIGNAL
64293+ grsec_enable_signal = 1;
64294+#endif
64295+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64296+ grsec_enable_forkfail = 1;
64297+#endif
64298+#ifdef CONFIG_GRKERNSEC_TIME
64299+ grsec_enable_time = 1;
64300+#endif
64301+#ifdef CONFIG_GRKERNSEC_RESLOG
64302+ grsec_resource_logging = 1;
64303+#endif
64304+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64305+ grsec_enable_chroot_findtask = 1;
64306+#endif
64307+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64308+ grsec_enable_chroot_unix = 1;
64309+#endif
64310+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64311+ grsec_enable_chroot_mount = 1;
64312+#endif
64313+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64314+ grsec_enable_chroot_fchdir = 1;
64315+#endif
64316+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64317+ grsec_enable_chroot_shmat = 1;
64318+#endif
64319+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64320+ grsec_enable_audit_ptrace = 1;
64321+#endif
64322+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64323+ grsec_enable_chroot_double = 1;
64324+#endif
64325+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64326+ grsec_enable_chroot_pivot = 1;
64327+#endif
64328+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64329+ grsec_enable_chroot_chdir = 1;
64330+#endif
64331+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64332+ grsec_enable_chroot_chmod = 1;
64333+#endif
64334+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64335+ grsec_enable_chroot_mknod = 1;
64336+#endif
64337+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64338+ grsec_enable_chroot_nice = 1;
64339+#endif
64340+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64341+ grsec_enable_chroot_execlog = 1;
64342+#endif
64343+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64344+ grsec_enable_chroot_caps = 1;
64345+#endif
64346+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64347+ grsec_enable_chroot_sysctl = 1;
64348+#endif
64349+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64350+ grsec_enable_symlinkown = 1;
64351+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
64352+#endif
64353+#ifdef CONFIG_GRKERNSEC_TPE
64354+ grsec_enable_tpe = 1;
64355+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
64356+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64357+ grsec_enable_tpe_all = 1;
64358+#endif
64359+#endif
64360+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64361+ grsec_enable_socket_all = 1;
64362+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
64363+#endif
64364+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64365+ grsec_enable_socket_client = 1;
64366+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
64367+#endif
64368+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64369+ grsec_enable_socket_server = 1;
64370+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
64371+#endif
64372+#endif
64373+
64374+ return;
64375+}
64376diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
64377new file mode 100644
64378index 0000000..5e05e20
64379--- /dev/null
64380+++ b/grsecurity/grsec_link.c
64381@@ -0,0 +1,58 @@
64382+#include <linux/kernel.h>
64383+#include <linux/sched.h>
64384+#include <linux/fs.h>
64385+#include <linux/file.h>
64386+#include <linux/grinternal.h>
64387+
64388+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
64389+{
64390+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64391+ const struct inode *link_inode = link->dentry->d_inode;
64392+
64393+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
64394+ /* ignore root-owned links, e.g. /proc/self */
64395+ gr_is_global_nonroot(link_inode->i_uid) && target &&
64396+ !uid_eq(link_inode->i_uid, target->i_uid)) {
64397+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
64398+ return 1;
64399+ }
64400+#endif
64401+ return 0;
64402+}
64403+
64404+int
64405+gr_handle_follow_link(const struct inode *parent,
64406+ const struct inode *inode,
64407+ const struct dentry *dentry, const struct vfsmount *mnt)
64408+{
64409+#ifdef CONFIG_GRKERNSEC_LINK
64410+ const struct cred *cred = current_cred();
64411+
64412+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
64413+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
64414+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
64415+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
64416+ return -EACCES;
64417+ }
64418+#endif
64419+ return 0;
64420+}
64421+
64422+int
64423+gr_handle_hardlink(const struct dentry *dentry,
64424+ const struct vfsmount *mnt,
64425+ struct inode *inode, const int mode, const struct filename *to)
64426+{
64427+#ifdef CONFIG_GRKERNSEC_LINK
64428+ const struct cred *cred = current_cred();
64429+
64430+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
64431+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
64432+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
64433+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
64434+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
64435+ return -EPERM;
64436+ }
64437+#endif
64438+ return 0;
64439+}
64440diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
64441new file mode 100644
64442index 0000000..7c06085
64443--- /dev/null
64444+++ b/grsecurity/grsec_log.c
64445@@ -0,0 +1,326 @@
64446+#include <linux/kernel.h>
64447+#include <linux/sched.h>
64448+#include <linux/file.h>
64449+#include <linux/tty.h>
64450+#include <linux/fs.h>
64451+#include <linux/grinternal.h>
64452+
64453+#ifdef CONFIG_TREE_PREEMPT_RCU
64454+#define DISABLE_PREEMPT() preempt_disable()
64455+#define ENABLE_PREEMPT() preempt_enable()
64456+#else
64457+#define DISABLE_PREEMPT()
64458+#define ENABLE_PREEMPT()
64459+#endif
64460+
64461+#define BEGIN_LOCKS(x) \
64462+ DISABLE_PREEMPT(); \
64463+ rcu_read_lock(); \
64464+ read_lock(&tasklist_lock); \
64465+ read_lock(&grsec_exec_file_lock); \
64466+ if (x != GR_DO_AUDIT) \
64467+ spin_lock(&grsec_alert_lock); \
64468+ else \
64469+ spin_lock(&grsec_audit_lock)
64470+
64471+#define END_LOCKS(x) \
64472+ if (x != GR_DO_AUDIT) \
64473+ spin_unlock(&grsec_alert_lock); \
64474+ else \
64475+ spin_unlock(&grsec_audit_lock); \
64476+ read_unlock(&grsec_exec_file_lock); \
64477+ read_unlock(&tasklist_lock); \
64478+ rcu_read_unlock(); \
64479+ ENABLE_PREEMPT(); \
64480+ if (x == GR_DONT_AUDIT) \
64481+ gr_handle_alertkill(current)
64482+
64483+enum {
64484+ FLOODING,
64485+ NO_FLOODING
64486+};
64487+
64488+extern char *gr_alert_log_fmt;
64489+extern char *gr_audit_log_fmt;
64490+extern char *gr_alert_log_buf;
64491+extern char *gr_audit_log_buf;
64492+
64493+static int gr_log_start(int audit)
64494+{
64495+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
64496+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
64497+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64498+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
64499+ unsigned long curr_secs = get_seconds();
64500+
64501+ if (audit == GR_DO_AUDIT)
64502+ goto set_fmt;
64503+
64504+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
64505+ grsec_alert_wtime = curr_secs;
64506+ grsec_alert_fyet = 0;
64507+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
64508+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
64509+ grsec_alert_fyet++;
64510+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
64511+ grsec_alert_wtime = curr_secs;
64512+ grsec_alert_fyet++;
64513+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64514+ return FLOODING;
64515+ }
64516+ else return FLOODING;
64517+
64518+set_fmt:
64519+#endif
64520+ memset(buf, 0, PAGE_SIZE);
64521+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
64522+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64523+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64524+ } else if (current->signal->curr_ip) {
64525+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64526+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64527+ } else if (gr_acl_is_enabled()) {
64528+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64529+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64530+ } else {
64531+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
64532+ strcpy(buf, fmt);
64533+ }
64534+
64535+ return NO_FLOODING;
64536+}
64537+
64538+static void gr_log_middle(int audit, const char *msg, va_list ap)
64539+ __attribute__ ((format (printf, 2, 0)));
64540+
64541+static void gr_log_middle(int audit, const char *msg, va_list ap)
64542+{
64543+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64544+ unsigned int len = strlen(buf);
64545+
64546+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64547+
64548+ return;
64549+}
64550+
64551+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64552+ __attribute__ ((format (printf, 2, 3)));
64553+
64554+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64555+{
64556+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64557+ unsigned int len = strlen(buf);
64558+ va_list ap;
64559+
64560+ va_start(ap, msg);
64561+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64562+ va_end(ap);
64563+
64564+ return;
64565+}
64566+
64567+static void gr_log_end(int audit, int append_default)
64568+{
64569+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64570+ if (append_default) {
64571+ struct task_struct *task = current;
64572+ struct task_struct *parent = task->real_parent;
64573+ const struct cred *cred = __task_cred(task);
64574+ const struct cred *pcred = __task_cred(parent);
64575+ unsigned int len = strlen(buf);
64576+
64577+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
64578+ }
64579+
64580+ printk("%s\n", buf);
64581+
64582+ return;
64583+}
64584+
64585+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64586+{
64587+ int logtype;
64588+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64589+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64590+ void *voidptr = NULL;
64591+ int num1 = 0, num2 = 0;
64592+ unsigned long ulong1 = 0, ulong2 = 0;
64593+ struct dentry *dentry = NULL;
64594+ struct vfsmount *mnt = NULL;
64595+ struct file *file = NULL;
64596+ struct task_struct *task = NULL;
64597+ const struct cred *cred, *pcred;
64598+ va_list ap;
64599+
64600+ BEGIN_LOCKS(audit);
64601+ logtype = gr_log_start(audit);
64602+ if (logtype == FLOODING) {
64603+ END_LOCKS(audit);
64604+ return;
64605+ }
64606+ va_start(ap, argtypes);
64607+ switch (argtypes) {
64608+ case GR_TTYSNIFF:
64609+ task = va_arg(ap, struct task_struct *);
64610+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
64611+ break;
64612+ case GR_SYSCTL_HIDDEN:
64613+ str1 = va_arg(ap, char *);
64614+ gr_log_middle_varargs(audit, msg, result, str1);
64615+ break;
64616+ case GR_RBAC:
64617+ dentry = va_arg(ap, struct dentry *);
64618+ mnt = va_arg(ap, struct vfsmount *);
64619+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64620+ break;
64621+ case GR_RBAC_STR:
64622+ dentry = va_arg(ap, struct dentry *);
64623+ mnt = va_arg(ap, struct vfsmount *);
64624+ str1 = va_arg(ap, char *);
64625+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64626+ break;
64627+ case GR_STR_RBAC:
64628+ str1 = va_arg(ap, char *);
64629+ dentry = va_arg(ap, struct dentry *);
64630+ mnt = va_arg(ap, struct vfsmount *);
64631+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64632+ break;
64633+ case GR_RBAC_MODE2:
64634+ dentry = va_arg(ap, struct dentry *);
64635+ mnt = va_arg(ap, struct vfsmount *);
64636+ str1 = va_arg(ap, char *);
64637+ str2 = va_arg(ap, char *);
64638+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64639+ break;
64640+ case GR_RBAC_MODE3:
64641+ dentry = va_arg(ap, struct dentry *);
64642+ mnt = va_arg(ap, struct vfsmount *);
64643+ str1 = va_arg(ap, char *);
64644+ str2 = va_arg(ap, char *);
64645+ str3 = va_arg(ap, char *);
64646+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64647+ break;
64648+ case GR_FILENAME:
64649+ dentry = va_arg(ap, struct dentry *);
64650+ mnt = va_arg(ap, struct vfsmount *);
64651+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64652+ break;
64653+ case GR_STR_FILENAME:
64654+ str1 = va_arg(ap, char *);
64655+ dentry = va_arg(ap, struct dentry *);
64656+ mnt = va_arg(ap, struct vfsmount *);
64657+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64658+ break;
64659+ case GR_FILENAME_STR:
64660+ dentry = va_arg(ap, struct dentry *);
64661+ mnt = va_arg(ap, struct vfsmount *);
64662+ str1 = va_arg(ap, char *);
64663+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64664+ break;
64665+ case GR_FILENAME_TWO_INT:
64666+ dentry = va_arg(ap, struct dentry *);
64667+ mnt = va_arg(ap, struct vfsmount *);
64668+ num1 = va_arg(ap, int);
64669+ num2 = va_arg(ap, int);
64670+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64671+ break;
64672+ case GR_FILENAME_TWO_INT_STR:
64673+ dentry = va_arg(ap, struct dentry *);
64674+ mnt = va_arg(ap, struct vfsmount *);
64675+ num1 = va_arg(ap, int);
64676+ num2 = va_arg(ap, int);
64677+ str1 = va_arg(ap, char *);
64678+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64679+ break;
64680+ case GR_TEXTREL:
64681+ file = va_arg(ap, struct file *);
64682+ ulong1 = va_arg(ap, unsigned long);
64683+ ulong2 = va_arg(ap, unsigned long);
64684+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64685+ break;
64686+ case GR_PTRACE:
64687+ task = va_arg(ap, struct task_struct *);
64688+ gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task_pid_nr(task));
64689+ break;
64690+ case GR_RESOURCE:
64691+ task = va_arg(ap, struct task_struct *);
64692+ cred = __task_cred(task);
64693+ pcred = __task_cred(task->real_parent);
64694+ ulong1 = va_arg(ap, unsigned long);
64695+ str1 = va_arg(ap, char *);
64696+ ulong2 = va_arg(ap, unsigned long);
64697+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
64698+ break;
64699+ case GR_CAP:
64700+ task = va_arg(ap, struct task_struct *);
64701+ cred = __task_cred(task);
64702+ pcred = __task_cred(task->real_parent);
64703+ str1 = va_arg(ap, char *);
64704+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
64705+ break;
64706+ case GR_SIG:
64707+ str1 = va_arg(ap, char *);
64708+ voidptr = va_arg(ap, void *);
64709+ gr_log_middle_varargs(audit, msg, str1, voidptr);
64710+ break;
64711+ case GR_SIG2:
64712+ task = va_arg(ap, struct task_struct *);
64713+ cred = __task_cred(task);
64714+ pcred = __task_cred(task->real_parent);
64715+ num1 = va_arg(ap, int);
64716+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
64717+ break;
64718+ case GR_CRASH1:
64719+ task = va_arg(ap, struct task_struct *);
64720+ cred = __task_cred(task);
64721+ pcred = __task_cred(task->real_parent);
64722+ ulong1 = va_arg(ap, unsigned long);
64723+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
64724+ break;
64725+ case GR_CRASH2:
64726+ task = va_arg(ap, struct task_struct *);
64727+ cred = __task_cred(task);
64728+ pcred = __task_cred(task->real_parent);
64729+ ulong1 = va_arg(ap, unsigned long);
64730+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
64731+ break;
64732+ case GR_RWXMAP:
64733+ file = va_arg(ap, struct file *);
64734+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64735+ break;
64736+ case GR_PSACCT:
64737+ {
64738+ unsigned int wday, cday;
64739+ __u8 whr, chr;
64740+ __u8 wmin, cmin;
64741+ __u8 wsec, csec;
64742+ char cur_tty[64] = { 0 };
64743+ char parent_tty[64] = { 0 };
64744+
64745+ task = va_arg(ap, struct task_struct *);
64746+ wday = va_arg(ap, unsigned int);
64747+ cday = va_arg(ap, unsigned int);
64748+ whr = va_arg(ap, int);
64749+ chr = va_arg(ap, int);
64750+ wmin = va_arg(ap, int);
64751+ cmin = va_arg(ap, int);
64752+ wsec = va_arg(ap, int);
64753+ csec = va_arg(ap, int);
64754+ ulong1 = va_arg(ap, unsigned long);
64755+ cred = __task_cred(task);
64756+ pcred = __task_cred(task->real_parent);
64757+
64758+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
64759+ }
64760+ break;
64761+ default:
64762+ gr_log_middle(audit, msg, ap);
64763+ }
64764+ va_end(ap);
64765+ // these don't need DEFAULTSECARGS printed on the end
64766+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64767+ gr_log_end(audit, 0);
64768+ else
64769+ gr_log_end(audit, 1);
64770+ END_LOCKS(audit);
64771+}
64772diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64773new file mode 100644
64774index 0000000..f536303
64775--- /dev/null
64776+++ b/grsecurity/grsec_mem.c
64777@@ -0,0 +1,40 @@
64778+#include <linux/kernel.h>
64779+#include <linux/sched.h>
64780+#include <linux/mm.h>
64781+#include <linux/mman.h>
64782+#include <linux/grinternal.h>
64783+
64784+void
64785+gr_handle_ioperm(void)
64786+{
64787+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64788+ return;
64789+}
64790+
64791+void
64792+gr_handle_iopl(void)
64793+{
64794+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64795+ return;
64796+}
64797+
64798+void
64799+gr_handle_mem_readwrite(u64 from, u64 to)
64800+{
64801+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64802+ return;
64803+}
64804+
64805+void
64806+gr_handle_vm86(void)
64807+{
64808+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64809+ return;
64810+}
64811+
64812+void
64813+gr_log_badprocpid(const char *entry)
64814+{
64815+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64816+ return;
64817+}
64818diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64819new file mode 100644
64820index 0000000..2131422
64821--- /dev/null
64822+++ b/grsecurity/grsec_mount.c
64823@@ -0,0 +1,62 @@
64824+#include <linux/kernel.h>
64825+#include <linux/sched.h>
64826+#include <linux/mount.h>
64827+#include <linux/grsecurity.h>
64828+#include <linux/grinternal.h>
64829+
64830+void
64831+gr_log_remount(const char *devname, const int retval)
64832+{
64833+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64834+ if (grsec_enable_mount && (retval >= 0))
64835+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64836+#endif
64837+ return;
64838+}
64839+
64840+void
64841+gr_log_unmount(const char *devname, const int retval)
64842+{
64843+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64844+ if (grsec_enable_mount && (retval >= 0))
64845+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64846+#endif
64847+ return;
64848+}
64849+
64850+void
64851+gr_log_mount(const char *from, const char *to, const int retval)
64852+{
64853+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64854+ if (grsec_enable_mount && (retval >= 0))
64855+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64856+#endif
64857+ return;
64858+}
64859+
64860+int
64861+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64862+{
64863+#ifdef CONFIG_GRKERNSEC_ROFS
64864+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64865+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64866+ return -EPERM;
64867+ } else
64868+ return 0;
64869+#endif
64870+ return 0;
64871+}
64872+
64873+int
64874+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64875+{
64876+#ifdef CONFIG_GRKERNSEC_ROFS
64877+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64878+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64879+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64880+ return -EPERM;
64881+ } else
64882+ return 0;
64883+#endif
64884+ return 0;
64885+}
64886diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64887new file mode 100644
64888index 0000000..a3b12a0
64889--- /dev/null
64890+++ b/grsecurity/grsec_pax.c
64891@@ -0,0 +1,36 @@
64892+#include <linux/kernel.h>
64893+#include <linux/sched.h>
64894+#include <linux/mm.h>
64895+#include <linux/file.h>
64896+#include <linux/grinternal.h>
64897+#include <linux/grsecurity.h>
64898+
64899+void
64900+gr_log_textrel(struct vm_area_struct * vma)
64901+{
64902+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64903+ if (grsec_enable_audit_textrel)
64904+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64905+#endif
64906+ return;
64907+}
64908+
64909+void
64910+gr_log_rwxmmap(struct file *file)
64911+{
64912+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64913+ if (grsec_enable_log_rwxmaps)
64914+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64915+#endif
64916+ return;
64917+}
64918+
64919+void
64920+gr_log_rwxmprotect(struct file *file)
64921+{
64922+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64923+ if (grsec_enable_log_rwxmaps)
64924+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64925+#endif
64926+ return;
64927+}
64928diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64929new file mode 100644
64930index 0000000..f7f29aa
64931--- /dev/null
64932+++ b/grsecurity/grsec_ptrace.c
64933@@ -0,0 +1,30 @@
64934+#include <linux/kernel.h>
64935+#include <linux/sched.h>
64936+#include <linux/grinternal.h>
64937+#include <linux/security.h>
64938+
64939+void
64940+gr_audit_ptrace(struct task_struct *task)
64941+{
64942+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64943+ if (grsec_enable_audit_ptrace)
64944+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64945+#endif
64946+ return;
64947+}
64948+
64949+int
64950+gr_ptrace_readexec(struct file *file, int unsafe_flags)
64951+{
64952+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64953+ const struct dentry *dentry = file->f_path.dentry;
64954+ const struct vfsmount *mnt = file->f_path.mnt;
64955+
64956+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64957+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64958+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64959+ return -EACCES;
64960+ }
64961+#endif
64962+ return 0;
64963+}
64964diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64965new file mode 100644
64966index 0000000..e09715a
64967--- /dev/null
64968+++ b/grsecurity/grsec_sig.c
64969@@ -0,0 +1,222 @@
64970+#include <linux/kernel.h>
64971+#include <linux/sched.h>
64972+#include <linux/delay.h>
64973+#include <linux/grsecurity.h>
64974+#include <linux/grinternal.h>
64975+#include <linux/hardirq.h>
64976+
64977+char *signames[] = {
64978+ [SIGSEGV] = "Segmentation fault",
64979+ [SIGILL] = "Illegal instruction",
64980+ [SIGABRT] = "Abort",
64981+ [SIGBUS] = "Invalid alignment/Bus error"
64982+};
64983+
64984+void
64985+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64986+{
64987+#ifdef CONFIG_GRKERNSEC_SIGNAL
64988+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64989+ (sig == SIGABRT) || (sig == SIGBUS))) {
64990+ if (task_pid_nr(t) == task_pid_nr(current)) {
64991+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64992+ } else {
64993+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64994+ }
64995+ }
64996+#endif
64997+ return;
64998+}
64999+
65000+int
65001+gr_handle_signal(const struct task_struct *p, const int sig)
65002+{
65003+#ifdef CONFIG_GRKERNSEC
65004+ /* ignore the 0 signal for protected task checks */
65005+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65006+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65007+ return -EPERM;
65008+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65009+ return -EPERM;
65010+ }
65011+#endif
65012+ return 0;
65013+}
65014+
65015+#ifdef CONFIG_GRKERNSEC
65016+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65017+
65018+int gr_fake_force_sig(int sig, struct task_struct *t)
65019+{
65020+ unsigned long int flags;
65021+ int ret, blocked, ignored;
65022+ struct k_sigaction *action;
65023+
65024+ spin_lock_irqsave(&t->sighand->siglock, flags);
65025+ action = &t->sighand->action[sig-1];
65026+ ignored = action->sa.sa_handler == SIG_IGN;
65027+ blocked = sigismember(&t->blocked, sig);
65028+ if (blocked || ignored) {
65029+ action->sa.sa_handler = SIG_DFL;
65030+ if (blocked) {
65031+ sigdelset(&t->blocked, sig);
65032+ recalc_sigpending_and_wake(t);
65033+ }
65034+ }
65035+ if (action->sa.sa_handler == SIG_DFL)
65036+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
65037+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
65038+
65039+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
65040+
65041+ return ret;
65042+}
65043+#endif
65044+
65045+#ifdef CONFIG_GRKERNSEC_BRUTE
65046+#define GR_USER_BAN_TIME (15 * 60)
65047+#define GR_DAEMON_BRUTE_TIME (30 * 60)
65048+
65049+static int __get_dumpable(unsigned long mm_flags)
65050+{
65051+ int ret;
65052+
65053+ ret = mm_flags & MMF_DUMPABLE_MASK;
65054+ return (ret >= 2) ? 2 : ret;
65055+}
65056+#endif
65057+
65058+void gr_handle_brute_attach(unsigned long mm_flags)
65059+{
65060+#ifdef CONFIG_GRKERNSEC_BRUTE
65061+ struct task_struct *p = current;
65062+ kuid_t uid = GLOBAL_ROOT_UID;
65063+ int daemon = 0;
65064+
65065+ if (!grsec_enable_brute)
65066+ return;
65067+
65068+ rcu_read_lock();
65069+ read_lock(&tasklist_lock);
65070+ read_lock(&grsec_exec_file_lock);
65071+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
65072+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
65073+ p->real_parent->brute = 1;
65074+ daemon = 1;
65075+ } else {
65076+ const struct cred *cred = __task_cred(p), *cred2;
65077+ struct task_struct *tsk, *tsk2;
65078+
65079+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
65080+ struct user_struct *user;
65081+
65082+ uid = cred->uid;
65083+
65084+ /* this is put upon execution past expiration */
65085+ user = find_user(uid);
65086+ if (user == NULL)
65087+ goto unlock;
65088+ user->banned = 1;
65089+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
65090+ if (user->ban_expires == ~0UL)
65091+ user->ban_expires--;
65092+
65093+ do_each_thread(tsk2, tsk) {
65094+ cred2 = __task_cred(tsk);
65095+ if (tsk != p && uid_eq(cred2->uid, uid))
65096+ gr_fake_force_sig(SIGKILL, tsk);
65097+ } while_each_thread(tsk2, tsk);
65098+ }
65099+ }
65100+unlock:
65101+ read_unlock(&grsec_exec_file_lock);
65102+ read_unlock(&tasklist_lock);
65103+ rcu_read_unlock();
65104+
65105+ if (gr_is_global_nonroot(uid))
65106+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
65107+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
65108+ else if (daemon)
65109+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
65110+
65111+#endif
65112+ return;
65113+}
65114+
65115+void gr_handle_brute_check(void)
65116+{
65117+#ifdef CONFIG_GRKERNSEC_BRUTE
65118+ struct task_struct *p = current;
65119+
65120+ if (unlikely(p->brute)) {
65121+ if (!grsec_enable_brute)
65122+ p->brute = 0;
65123+ else if (time_before(get_seconds(), p->brute_expires))
65124+ msleep(30 * 1000);
65125+ }
65126+#endif
65127+ return;
65128+}
65129+
65130+void gr_handle_kernel_exploit(void)
65131+{
65132+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
65133+ const struct cred *cred;
65134+ struct task_struct *tsk, *tsk2;
65135+ struct user_struct *user;
65136+ kuid_t uid;
65137+
65138+ if (in_irq() || in_serving_softirq() || in_nmi())
65139+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
65140+
65141+ uid = current_uid();
65142+
65143+ if (gr_is_global_root(uid))
65144+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
65145+ else {
65146+ /* kill all the processes of this user, hold a reference
65147+ to their creds struct, and prevent them from creating
65148+ another process until system reset
65149+ */
65150+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
65151+ GR_GLOBAL_UID(uid));
65152+ /* we intentionally leak this ref */
65153+ user = get_uid(current->cred->user);
65154+ if (user) {
65155+ user->banned = 1;
65156+ user->ban_expires = ~0UL;
65157+ }
65158+
65159+ read_lock(&tasklist_lock);
65160+ do_each_thread(tsk2, tsk) {
65161+ cred = __task_cred(tsk);
65162+ if (uid_eq(cred->uid, uid))
65163+ gr_fake_force_sig(SIGKILL, tsk);
65164+ } while_each_thread(tsk2, tsk);
65165+ read_unlock(&tasklist_lock);
65166+ }
65167+#endif
65168+}
65169+
65170+int __gr_process_user_ban(struct user_struct *user)
65171+{
65172+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65173+ if (unlikely(user->banned)) {
65174+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
65175+ user->banned = 0;
65176+ user->ban_expires = 0;
65177+ free_uid(user);
65178+ } else
65179+ return -EPERM;
65180+ }
65181+#endif
65182+ return 0;
65183+}
65184+
65185+int gr_process_user_ban(void)
65186+{
65187+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65188+ return __gr_process_user_ban(current->cred->user);
65189+#endif
65190+ return 0;
65191+}
65192diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
65193new file mode 100644
65194index 0000000..4030d57
65195--- /dev/null
65196+++ b/grsecurity/grsec_sock.c
65197@@ -0,0 +1,244 @@
65198+#include <linux/kernel.h>
65199+#include <linux/module.h>
65200+#include <linux/sched.h>
65201+#include <linux/file.h>
65202+#include <linux/net.h>
65203+#include <linux/in.h>
65204+#include <linux/ip.h>
65205+#include <net/sock.h>
65206+#include <net/inet_sock.h>
65207+#include <linux/grsecurity.h>
65208+#include <linux/grinternal.h>
65209+#include <linux/gracl.h>
65210+
65211+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
65212+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
65213+
65214+EXPORT_SYMBOL(gr_search_udp_recvmsg);
65215+EXPORT_SYMBOL(gr_search_udp_sendmsg);
65216+
65217+#ifdef CONFIG_UNIX_MODULE
65218+EXPORT_SYMBOL(gr_acl_handle_unix);
65219+EXPORT_SYMBOL(gr_acl_handle_mknod);
65220+EXPORT_SYMBOL(gr_handle_chroot_unix);
65221+EXPORT_SYMBOL(gr_handle_create);
65222+#endif
65223+
65224+#ifdef CONFIG_GRKERNSEC
65225+#define gr_conn_table_size 32749
65226+struct conn_table_entry {
65227+ struct conn_table_entry *next;
65228+ struct signal_struct *sig;
65229+};
65230+
65231+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
65232+DEFINE_SPINLOCK(gr_conn_table_lock);
65233+
65234+extern const char * gr_socktype_to_name(unsigned char type);
65235+extern const char * gr_proto_to_name(unsigned char proto);
65236+extern const char * gr_sockfamily_to_name(unsigned char family);
65237+
65238+static __inline__ int
65239+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
65240+{
65241+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
65242+}
65243+
65244+static __inline__ int
65245+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
65246+ __u16 sport, __u16 dport)
65247+{
65248+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
65249+ sig->gr_sport == sport && sig->gr_dport == dport))
65250+ return 1;
65251+ else
65252+ return 0;
65253+}
65254+
65255+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
65256+{
65257+ struct conn_table_entry **match;
65258+ unsigned int index;
65259+
65260+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65261+ sig->gr_sport, sig->gr_dport,
65262+ gr_conn_table_size);
65263+
65264+ newent->sig = sig;
65265+
65266+ match = &gr_conn_table[index];
65267+ newent->next = *match;
65268+ *match = newent;
65269+
65270+ return;
65271+}
65272+
65273+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
65274+{
65275+ struct conn_table_entry *match, *last = NULL;
65276+ unsigned int index;
65277+
65278+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65279+ sig->gr_sport, sig->gr_dport,
65280+ gr_conn_table_size);
65281+
65282+ match = gr_conn_table[index];
65283+ while (match && !conn_match(match->sig,
65284+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
65285+ sig->gr_dport)) {
65286+ last = match;
65287+ match = match->next;
65288+ }
65289+
65290+ if (match) {
65291+ if (last)
65292+ last->next = match->next;
65293+ else
65294+ gr_conn_table[index] = NULL;
65295+ kfree(match);
65296+ }
65297+
65298+ return;
65299+}
65300+
65301+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
65302+ __u16 sport, __u16 dport)
65303+{
65304+ struct conn_table_entry *match;
65305+ unsigned int index;
65306+
65307+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
65308+
65309+ match = gr_conn_table[index];
65310+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
65311+ match = match->next;
65312+
65313+ if (match)
65314+ return match->sig;
65315+ else
65316+ return NULL;
65317+}
65318+
65319+#endif
65320+
65321+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
65322+{
65323+#ifdef CONFIG_GRKERNSEC
65324+ struct signal_struct *sig = task->signal;
65325+ struct conn_table_entry *newent;
65326+
65327+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
65328+ if (newent == NULL)
65329+ return;
65330+ /* no bh lock needed since we are called with bh disabled */
65331+ spin_lock(&gr_conn_table_lock);
65332+ gr_del_task_from_ip_table_nolock(sig);
65333+ sig->gr_saddr = inet->inet_rcv_saddr;
65334+ sig->gr_daddr = inet->inet_daddr;
65335+ sig->gr_sport = inet->inet_sport;
65336+ sig->gr_dport = inet->inet_dport;
65337+ gr_add_to_task_ip_table_nolock(sig, newent);
65338+ spin_unlock(&gr_conn_table_lock);
65339+#endif
65340+ return;
65341+}
65342+
65343+void gr_del_task_from_ip_table(struct task_struct *task)
65344+{
65345+#ifdef CONFIG_GRKERNSEC
65346+ spin_lock_bh(&gr_conn_table_lock);
65347+ gr_del_task_from_ip_table_nolock(task->signal);
65348+ spin_unlock_bh(&gr_conn_table_lock);
65349+#endif
65350+ return;
65351+}
65352+
65353+void
65354+gr_attach_curr_ip(const struct sock *sk)
65355+{
65356+#ifdef CONFIG_GRKERNSEC
65357+ struct signal_struct *p, *set;
65358+ const struct inet_sock *inet = inet_sk(sk);
65359+
65360+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
65361+ return;
65362+
65363+ set = current->signal;
65364+
65365+ spin_lock_bh(&gr_conn_table_lock);
65366+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
65367+ inet->inet_dport, inet->inet_sport);
65368+ if (unlikely(p != NULL)) {
65369+ set->curr_ip = p->curr_ip;
65370+ set->used_accept = 1;
65371+ gr_del_task_from_ip_table_nolock(p);
65372+ spin_unlock_bh(&gr_conn_table_lock);
65373+ return;
65374+ }
65375+ spin_unlock_bh(&gr_conn_table_lock);
65376+
65377+ set->curr_ip = inet->inet_daddr;
65378+ set->used_accept = 1;
65379+#endif
65380+ return;
65381+}
65382+
65383+int
65384+gr_handle_sock_all(const int family, const int type, const int protocol)
65385+{
65386+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65387+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
65388+ (family != AF_UNIX)) {
65389+ if (family == AF_INET)
65390+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
65391+ else
65392+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
65393+ return -EACCES;
65394+ }
65395+#endif
65396+ return 0;
65397+}
65398+
65399+int
65400+gr_handle_sock_server(const struct sockaddr *sck)
65401+{
65402+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65403+ if (grsec_enable_socket_server &&
65404+ in_group_p(grsec_socket_server_gid) &&
65405+ sck && (sck->sa_family != AF_UNIX) &&
65406+ (sck->sa_family != AF_LOCAL)) {
65407+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65408+ return -EACCES;
65409+ }
65410+#endif
65411+ return 0;
65412+}
65413+
65414+int
65415+gr_handle_sock_server_other(const struct sock *sck)
65416+{
65417+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65418+ if (grsec_enable_socket_server &&
65419+ in_group_p(grsec_socket_server_gid) &&
65420+ sck && (sck->sk_family != AF_UNIX) &&
65421+ (sck->sk_family != AF_LOCAL)) {
65422+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65423+ return -EACCES;
65424+ }
65425+#endif
65426+ return 0;
65427+}
65428+
65429+int
65430+gr_handle_sock_client(const struct sockaddr *sck)
65431+{
65432+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65433+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
65434+ sck && (sck->sa_family != AF_UNIX) &&
65435+ (sck->sa_family != AF_LOCAL)) {
65436+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
65437+ return -EACCES;
65438+ }
65439+#endif
65440+ return 0;
65441+}
65442diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
65443new file mode 100644
65444index 0000000..f55ef0f
65445--- /dev/null
65446+++ b/grsecurity/grsec_sysctl.c
65447@@ -0,0 +1,469 @@
65448+#include <linux/kernel.h>
65449+#include <linux/sched.h>
65450+#include <linux/sysctl.h>
65451+#include <linux/grsecurity.h>
65452+#include <linux/grinternal.h>
65453+
65454+int
65455+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
65456+{
65457+#ifdef CONFIG_GRKERNSEC_SYSCTL
65458+ if (dirname == NULL || name == NULL)
65459+ return 0;
65460+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
65461+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
65462+ return -EACCES;
65463+ }
65464+#endif
65465+ return 0;
65466+}
65467+
65468+#ifdef CONFIG_GRKERNSEC_ROFS
65469+static int __maybe_unused one = 1;
65470+#endif
65471+
65472+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
65473+struct ctl_table grsecurity_table[] = {
65474+#ifdef CONFIG_GRKERNSEC_SYSCTL
65475+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
65476+#ifdef CONFIG_GRKERNSEC_IO
65477+ {
65478+ .procname = "disable_priv_io",
65479+ .data = &grsec_disable_privio,
65480+ .maxlen = sizeof(int),
65481+ .mode = 0600,
65482+ .proc_handler = &proc_dointvec,
65483+ },
65484+#endif
65485+#endif
65486+#ifdef CONFIG_GRKERNSEC_LINK
65487+ {
65488+ .procname = "linking_restrictions",
65489+ .data = &grsec_enable_link,
65490+ .maxlen = sizeof(int),
65491+ .mode = 0600,
65492+ .proc_handler = &proc_dointvec,
65493+ },
65494+#endif
65495+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65496+ {
65497+ .procname = "enforce_symlinksifowner",
65498+ .data = &grsec_enable_symlinkown,
65499+ .maxlen = sizeof(int),
65500+ .mode = 0600,
65501+ .proc_handler = &proc_dointvec,
65502+ },
65503+ {
65504+ .procname = "symlinkown_gid",
65505+ .data = &grsec_symlinkown_gid,
65506+ .maxlen = sizeof(int),
65507+ .mode = 0600,
65508+ .proc_handler = &proc_dointvec,
65509+ },
65510+#endif
65511+#ifdef CONFIG_GRKERNSEC_BRUTE
65512+ {
65513+ .procname = "deter_bruteforce",
65514+ .data = &grsec_enable_brute,
65515+ .maxlen = sizeof(int),
65516+ .mode = 0600,
65517+ .proc_handler = &proc_dointvec,
65518+ },
65519+#endif
65520+#ifdef CONFIG_GRKERNSEC_FIFO
65521+ {
65522+ .procname = "fifo_restrictions",
65523+ .data = &grsec_enable_fifo,
65524+ .maxlen = sizeof(int),
65525+ .mode = 0600,
65526+ .proc_handler = &proc_dointvec,
65527+ },
65528+#endif
65529+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65530+ {
65531+ .procname = "ptrace_readexec",
65532+ .data = &grsec_enable_ptrace_readexec,
65533+ .maxlen = sizeof(int),
65534+ .mode = 0600,
65535+ .proc_handler = &proc_dointvec,
65536+ },
65537+#endif
65538+#ifdef CONFIG_GRKERNSEC_SETXID
65539+ {
65540+ .procname = "consistent_setxid",
65541+ .data = &grsec_enable_setxid,
65542+ .maxlen = sizeof(int),
65543+ .mode = 0600,
65544+ .proc_handler = &proc_dointvec,
65545+ },
65546+#endif
65547+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65548+ {
65549+ .procname = "ip_blackhole",
65550+ .data = &grsec_enable_blackhole,
65551+ .maxlen = sizeof(int),
65552+ .mode = 0600,
65553+ .proc_handler = &proc_dointvec,
65554+ },
65555+ {
65556+ .procname = "lastack_retries",
65557+ .data = &grsec_lastack_retries,
65558+ .maxlen = sizeof(int),
65559+ .mode = 0600,
65560+ .proc_handler = &proc_dointvec,
65561+ },
65562+#endif
65563+#ifdef CONFIG_GRKERNSEC_EXECLOG
65564+ {
65565+ .procname = "exec_logging",
65566+ .data = &grsec_enable_execlog,
65567+ .maxlen = sizeof(int),
65568+ .mode = 0600,
65569+ .proc_handler = &proc_dointvec,
65570+ },
65571+#endif
65572+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65573+ {
65574+ .procname = "rwxmap_logging",
65575+ .data = &grsec_enable_log_rwxmaps,
65576+ .maxlen = sizeof(int),
65577+ .mode = 0600,
65578+ .proc_handler = &proc_dointvec,
65579+ },
65580+#endif
65581+#ifdef CONFIG_GRKERNSEC_SIGNAL
65582+ {
65583+ .procname = "signal_logging",
65584+ .data = &grsec_enable_signal,
65585+ .maxlen = sizeof(int),
65586+ .mode = 0600,
65587+ .proc_handler = &proc_dointvec,
65588+ },
65589+#endif
65590+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65591+ {
65592+ .procname = "forkfail_logging",
65593+ .data = &grsec_enable_forkfail,
65594+ .maxlen = sizeof(int),
65595+ .mode = 0600,
65596+ .proc_handler = &proc_dointvec,
65597+ },
65598+#endif
65599+#ifdef CONFIG_GRKERNSEC_TIME
65600+ {
65601+ .procname = "timechange_logging",
65602+ .data = &grsec_enable_time,
65603+ .maxlen = sizeof(int),
65604+ .mode = 0600,
65605+ .proc_handler = &proc_dointvec,
65606+ },
65607+#endif
65608+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65609+ {
65610+ .procname = "chroot_deny_shmat",
65611+ .data = &grsec_enable_chroot_shmat,
65612+ .maxlen = sizeof(int),
65613+ .mode = 0600,
65614+ .proc_handler = &proc_dointvec,
65615+ },
65616+#endif
65617+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65618+ {
65619+ .procname = "chroot_deny_unix",
65620+ .data = &grsec_enable_chroot_unix,
65621+ .maxlen = sizeof(int),
65622+ .mode = 0600,
65623+ .proc_handler = &proc_dointvec,
65624+ },
65625+#endif
65626+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65627+ {
65628+ .procname = "chroot_deny_mount",
65629+ .data = &grsec_enable_chroot_mount,
65630+ .maxlen = sizeof(int),
65631+ .mode = 0600,
65632+ .proc_handler = &proc_dointvec,
65633+ },
65634+#endif
65635+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65636+ {
65637+ .procname = "chroot_deny_fchdir",
65638+ .data = &grsec_enable_chroot_fchdir,
65639+ .maxlen = sizeof(int),
65640+ .mode = 0600,
65641+ .proc_handler = &proc_dointvec,
65642+ },
65643+#endif
65644+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65645+ {
65646+ .procname = "chroot_deny_chroot",
65647+ .data = &grsec_enable_chroot_double,
65648+ .maxlen = sizeof(int),
65649+ .mode = 0600,
65650+ .proc_handler = &proc_dointvec,
65651+ },
65652+#endif
65653+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65654+ {
65655+ .procname = "chroot_deny_pivot",
65656+ .data = &grsec_enable_chroot_pivot,
65657+ .maxlen = sizeof(int),
65658+ .mode = 0600,
65659+ .proc_handler = &proc_dointvec,
65660+ },
65661+#endif
65662+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65663+ {
65664+ .procname = "chroot_enforce_chdir",
65665+ .data = &grsec_enable_chroot_chdir,
65666+ .maxlen = sizeof(int),
65667+ .mode = 0600,
65668+ .proc_handler = &proc_dointvec,
65669+ },
65670+#endif
65671+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65672+ {
65673+ .procname = "chroot_deny_chmod",
65674+ .data = &grsec_enable_chroot_chmod,
65675+ .maxlen = sizeof(int),
65676+ .mode = 0600,
65677+ .proc_handler = &proc_dointvec,
65678+ },
65679+#endif
65680+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65681+ {
65682+ .procname = "chroot_deny_mknod",
65683+ .data = &grsec_enable_chroot_mknod,
65684+ .maxlen = sizeof(int),
65685+ .mode = 0600,
65686+ .proc_handler = &proc_dointvec,
65687+ },
65688+#endif
65689+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65690+ {
65691+ .procname = "chroot_restrict_nice",
65692+ .data = &grsec_enable_chroot_nice,
65693+ .maxlen = sizeof(int),
65694+ .mode = 0600,
65695+ .proc_handler = &proc_dointvec,
65696+ },
65697+#endif
65698+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65699+ {
65700+ .procname = "chroot_execlog",
65701+ .data = &grsec_enable_chroot_execlog,
65702+ .maxlen = sizeof(int),
65703+ .mode = 0600,
65704+ .proc_handler = &proc_dointvec,
65705+ },
65706+#endif
65707+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65708+ {
65709+ .procname = "chroot_caps",
65710+ .data = &grsec_enable_chroot_caps,
65711+ .maxlen = sizeof(int),
65712+ .mode = 0600,
65713+ .proc_handler = &proc_dointvec,
65714+ },
65715+#endif
65716+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65717+ {
65718+ .procname = "chroot_deny_sysctl",
65719+ .data = &grsec_enable_chroot_sysctl,
65720+ .maxlen = sizeof(int),
65721+ .mode = 0600,
65722+ .proc_handler = &proc_dointvec,
65723+ },
65724+#endif
65725+#ifdef CONFIG_GRKERNSEC_TPE
65726+ {
65727+ .procname = "tpe",
65728+ .data = &grsec_enable_tpe,
65729+ .maxlen = sizeof(int),
65730+ .mode = 0600,
65731+ .proc_handler = &proc_dointvec,
65732+ },
65733+ {
65734+ .procname = "tpe_gid",
65735+ .data = &grsec_tpe_gid,
65736+ .maxlen = sizeof(int),
65737+ .mode = 0600,
65738+ .proc_handler = &proc_dointvec,
65739+ },
65740+#endif
65741+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65742+ {
65743+ .procname = "tpe_invert",
65744+ .data = &grsec_enable_tpe_invert,
65745+ .maxlen = sizeof(int),
65746+ .mode = 0600,
65747+ .proc_handler = &proc_dointvec,
65748+ },
65749+#endif
65750+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65751+ {
65752+ .procname = "tpe_restrict_all",
65753+ .data = &grsec_enable_tpe_all,
65754+ .maxlen = sizeof(int),
65755+ .mode = 0600,
65756+ .proc_handler = &proc_dointvec,
65757+ },
65758+#endif
65759+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65760+ {
65761+ .procname = "socket_all",
65762+ .data = &grsec_enable_socket_all,
65763+ .maxlen = sizeof(int),
65764+ .mode = 0600,
65765+ .proc_handler = &proc_dointvec,
65766+ },
65767+ {
65768+ .procname = "socket_all_gid",
65769+ .data = &grsec_socket_all_gid,
65770+ .maxlen = sizeof(int),
65771+ .mode = 0600,
65772+ .proc_handler = &proc_dointvec,
65773+ },
65774+#endif
65775+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65776+ {
65777+ .procname = "socket_client",
65778+ .data = &grsec_enable_socket_client,
65779+ .maxlen = sizeof(int),
65780+ .mode = 0600,
65781+ .proc_handler = &proc_dointvec,
65782+ },
65783+ {
65784+ .procname = "socket_client_gid",
65785+ .data = &grsec_socket_client_gid,
65786+ .maxlen = sizeof(int),
65787+ .mode = 0600,
65788+ .proc_handler = &proc_dointvec,
65789+ },
65790+#endif
65791+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65792+ {
65793+ .procname = "socket_server",
65794+ .data = &grsec_enable_socket_server,
65795+ .maxlen = sizeof(int),
65796+ .mode = 0600,
65797+ .proc_handler = &proc_dointvec,
65798+ },
65799+ {
65800+ .procname = "socket_server_gid",
65801+ .data = &grsec_socket_server_gid,
65802+ .maxlen = sizeof(int),
65803+ .mode = 0600,
65804+ .proc_handler = &proc_dointvec,
65805+ },
65806+#endif
65807+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65808+ {
65809+ .procname = "audit_group",
65810+ .data = &grsec_enable_group,
65811+ .maxlen = sizeof(int),
65812+ .mode = 0600,
65813+ .proc_handler = &proc_dointvec,
65814+ },
65815+ {
65816+ .procname = "audit_gid",
65817+ .data = &grsec_audit_gid,
65818+ .maxlen = sizeof(int),
65819+ .mode = 0600,
65820+ .proc_handler = &proc_dointvec,
65821+ },
65822+#endif
65823+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65824+ {
65825+ .procname = "audit_chdir",
65826+ .data = &grsec_enable_chdir,
65827+ .maxlen = sizeof(int),
65828+ .mode = 0600,
65829+ .proc_handler = &proc_dointvec,
65830+ },
65831+#endif
65832+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65833+ {
65834+ .procname = "audit_mount",
65835+ .data = &grsec_enable_mount,
65836+ .maxlen = sizeof(int),
65837+ .mode = 0600,
65838+ .proc_handler = &proc_dointvec,
65839+ },
65840+#endif
65841+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65842+ {
65843+ .procname = "audit_textrel",
65844+ .data = &grsec_enable_audit_textrel,
65845+ .maxlen = sizeof(int),
65846+ .mode = 0600,
65847+ .proc_handler = &proc_dointvec,
65848+ },
65849+#endif
65850+#ifdef CONFIG_GRKERNSEC_DMESG
65851+ {
65852+ .procname = "dmesg",
65853+ .data = &grsec_enable_dmesg,
65854+ .maxlen = sizeof(int),
65855+ .mode = 0600,
65856+ .proc_handler = &proc_dointvec,
65857+ },
65858+#endif
65859+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65860+ {
65861+ .procname = "chroot_findtask",
65862+ .data = &grsec_enable_chroot_findtask,
65863+ .maxlen = sizeof(int),
65864+ .mode = 0600,
65865+ .proc_handler = &proc_dointvec,
65866+ },
65867+#endif
65868+#ifdef CONFIG_GRKERNSEC_RESLOG
65869+ {
65870+ .procname = "resource_logging",
65871+ .data = &grsec_resource_logging,
65872+ .maxlen = sizeof(int),
65873+ .mode = 0600,
65874+ .proc_handler = &proc_dointvec,
65875+ },
65876+#endif
65877+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65878+ {
65879+ .procname = "audit_ptrace",
65880+ .data = &grsec_enable_audit_ptrace,
65881+ .maxlen = sizeof(int),
65882+ .mode = 0600,
65883+ .proc_handler = &proc_dointvec,
65884+ },
65885+#endif
65886+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65887+ {
65888+ .procname = "harden_ptrace",
65889+ .data = &grsec_enable_harden_ptrace,
65890+ .maxlen = sizeof(int),
65891+ .mode = 0600,
65892+ .proc_handler = &proc_dointvec,
65893+ },
65894+#endif
65895+ {
65896+ .procname = "grsec_lock",
65897+ .data = &grsec_lock,
65898+ .maxlen = sizeof(int),
65899+ .mode = 0600,
65900+ .proc_handler = &proc_dointvec,
65901+ },
65902+#endif
65903+#ifdef CONFIG_GRKERNSEC_ROFS
65904+ {
65905+ .procname = "romount_protect",
65906+ .data = &grsec_enable_rofs,
65907+ .maxlen = sizeof(int),
65908+ .mode = 0600,
65909+ .proc_handler = &proc_dointvec_minmax,
65910+ .extra1 = &one,
65911+ .extra2 = &one,
65912+ },
65913+#endif
65914+ { }
65915+};
65916+#endif
65917diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65918new file mode 100644
65919index 0000000..0dc13c3
65920--- /dev/null
65921+++ b/grsecurity/grsec_time.c
65922@@ -0,0 +1,16 @@
65923+#include <linux/kernel.h>
65924+#include <linux/sched.h>
65925+#include <linux/grinternal.h>
65926+#include <linux/module.h>
65927+
65928+void
65929+gr_log_timechange(void)
65930+{
65931+#ifdef CONFIG_GRKERNSEC_TIME
65932+ if (grsec_enable_time)
65933+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65934+#endif
65935+ return;
65936+}
65937+
65938+EXPORT_SYMBOL(gr_log_timechange);
65939diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65940new file mode 100644
65941index 0000000..ee57dcf
65942--- /dev/null
65943+++ b/grsecurity/grsec_tpe.c
65944@@ -0,0 +1,73 @@
65945+#include <linux/kernel.h>
65946+#include <linux/sched.h>
65947+#include <linux/file.h>
65948+#include <linux/fs.h>
65949+#include <linux/grinternal.h>
65950+
65951+extern int gr_acl_tpe_check(void);
65952+
65953+int
65954+gr_tpe_allow(const struct file *file)
65955+{
65956+#ifdef CONFIG_GRKERNSEC
65957+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65958+ const struct cred *cred = current_cred();
65959+ char *msg = NULL;
65960+ char *msg2 = NULL;
65961+
65962+ // never restrict root
65963+ if (gr_is_global_root(cred->uid))
65964+ return 1;
65965+
65966+ if (grsec_enable_tpe) {
65967+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65968+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65969+ msg = "not being in trusted group";
65970+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65971+ msg = "being in untrusted group";
65972+#else
65973+ if (in_group_p(grsec_tpe_gid))
65974+ msg = "being in untrusted group";
65975+#endif
65976+ }
65977+ if (!msg && gr_acl_tpe_check())
65978+ msg = "being in untrusted role";
65979+
65980+ // not in any affected group/role
65981+ if (!msg)
65982+ goto next_check;
65983+
65984+ if (gr_is_global_nonroot(inode->i_uid))
65985+ msg2 = "file in non-root-owned directory";
65986+ else if (inode->i_mode & S_IWOTH)
65987+ msg2 = "file in world-writable directory";
65988+ else if (inode->i_mode & S_IWGRP)
65989+ msg2 = "file in group-writable directory";
65990+
65991+ if (msg && msg2) {
65992+ char fullmsg[70] = {0};
65993+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65994+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65995+ return 0;
65996+ }
65997+ msg = NULL;
65998+next_check:
65999+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66000+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66001+ return 1;
66002+
66003+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66004+ msg = "directory not owned by user";
66005+ else if (inode->i_mode & S_IWOTH)
66006+ msg = "file in world-writable directory";
66007+ else if (inode->i_mode & S_IWGRP)
66008+ msg = "file in group-writable directory";
66009+
66010+ if (msg) {
66011+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66012+ return 0;
66013+ }
66014+#endif
66015+#endif
66016+ return 1;
66017+}
66018diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66019new file mode 100644
66020index 0000000..9f7b1ac
66021--- /dev/null
66022+++ b/grsecurity/grsum.c
66023@@ -0,0 +1,61 @@
66024+#include <linux/err.h>
66025+#include <linux/kernel.h>
66026+#include <linux/sched.h>
66027+#include <linux/mm.h>
66028+#include <linux/scatterlist.h>
66029+#include <linux/crypto.h>
66030+#include <linux/gracl.h>
66031+
66032+
66033+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66034+#error "crypto and sha256 must be built into the kernel"
66035+#endif
66036+
66037+int
66038+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
66039+{
66040+ char *p;
66041+ struct crypto_hash *tfm;
66042+ struct hash_desc desc;
66043+ struct scatterlist sg;
66044+ unsigned char temp_sum[GR_SHA_LEN];
66045+ volatile int retval = 0;
66046+ volatile int dummy = 0;
66047+ unsigned int i;
66048+
66049+ sg_init_table(&sg, 1);
66050+
66051+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
66052+ if (IS_ERR(tfm)) {
66053+ /* should never happen, since sha256 should be built in */
66054+ return 1;
66055+ }
66056+
66057+ desc.tfm = tfm;
66058+ desc.flags = 0;
66059+
66060+ crypto_hash_init(&desc);
66061+
66062+ p = salt;
66063+ sg_set_buf(&sg, p, GR_SALT_LEN);
66064+ crypto_hash_update(&desc, &sg, sg.length);
66065+
66066+ p = entry->pw;
66067+ sg_set_buf(&sg, p, strlen(p));
66068+
66069+ crypto_hash_update(&desc, &sg, sg.length);
66070+
66071+ crypto_hash_final(&desc, temp_sum);
66072+
66073+ memset(entry->pw, 0, GR_PW_LEN);
66074+
66075+ for (i = 0; i < GR_SHA_LEN; i++)
66076+ if (sum[i] != temp_sum[i])
66077+ retval = 1;
66078+ else
66079+ dummy = 1; // waste a cycle
66080+
66081+ crypto_free_hash(tfm);
66082+
66083+ return retval;
66084+}
66085diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
66086index 77ff547..181834f 100644
66087--- a/include/asm-generic/4level-fixup.h
66088+++ b/include/asm-generic/4level-fixup.h
66089@@ -13,8 +13,10 @@
66090 #define pmd_alloc(mm, pud, address) \
66091 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
66092 NULL: pmd_offset(pud, address))
66093+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
66094
66095 #define pud_alloc(mm, pgd, address) (pgd)
66096+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
66097 #define pud_offset(pgd, start) (pgd)
66098 #define pud_none(pud) 0
66099 #define pud_bad(pud) 0
66100diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
66101index b7babf0..04ad282 100644
66102--- a/include/asm-generic/atomic-long.h
66103+++ b/include/asm-generic/atomic-long.h
66104@@ -22,6 +22,12 @@
66105
66106 typedef atomic64_t atomic_long_t;
66107
66108+#ifdef CONFIG_PAX_REFCOUNT
66109+typedef atomic64_unchecked_t atomic_long_unchecked_t;
66110+#else
66111+typedef atomic64_t atomic_long_unchecked_t;
66112+#endif
66113+
66114 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
66115
66116 static inline long atomic_long_read(atomic_long_t *l)
66117@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66118 return (long)atomic64_read(v);
66119 }
66120
66121+#ifdef CONFIG_PAX_REFCOUNT
66122+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66123+{
66124+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66125+
66126+ return (long)atomic64_read_unchecked(v);
66127+}
66128+#endif
66129+
66130 static inline void atomic_long_set(atomic_long_t *l, long i)
66131 {
66132 atomic64_t *v = (atomic64_t *)l;
66133@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66134 atomic64_set(v, i);
66135 }
66136
66137+#ifdef CONFIG_PAX_REFCOUNT
66138+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66139+{
66140+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66141+
66142+ atomic64_set_unchecked(v, i);
66143+}
66144+#endif
66145+
66146 static inline void atomic_long_inc(atomic_long_t *l)
66147 {
66148 atomic64_t *v = (atomic64_t *)l;
66149@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66150 atomic64_inc(v);
66151 }
66152
66153+#ifdef CONFIG_PAX_REFCOUNT
66154+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66155+{
66156+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66157+
66158+ atomic64_inc_unchecked(v);
66159+}
66160+#endif
66161+
66162 static inline void atomic_long_dec(atomic_long_t *l)
66163 {
66164 atomic64_t *v = (atomic64_t *)l;
66165@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66166 atomic64_dec(v);
66167 }
66168
66169+#ifdef CONFIG_PAX_REFCOUNT
66170+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66171+{
66172+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66173+
66174+ atomic64_dec_unchecked(v);
66175+}
66176+#endif
66177+
66178 static inline void atomic_long_add(long i, atomic_long_t *l)
66179 {
66180 atomic64_t *v = (atomic64_t *)l;
66181@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66182 atomic64_add(i, v);
66183 }
66184
66185+#ifdef CONFIG_PAX_REFCOUNT
66186+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66187+{
66188+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66189+
66190+ atomic64_add_unchecked(i, v);
66191+}
66192+#endif
66193+
66194 static inline void atomic_long_sub(long i, atomic_long_t *l)
66195 {
66196 atomic64_t *v = (atomic64_t *)l;
66197@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66198 atomic64_sub(i, v);
66199 }
66200
66201+#ifdef CONFIG_PAX_REFCOUNT
66202+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66203+{
66204+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66205+
66206+ atomic64_sub_unchecked(i, v);
66207+}
66208+#endif
66209+
66210 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66211 {
66212 atomic64_t *v = (atomic64_t *)l;
66213@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66214 return (long)atomic64_add_return(i, v);
66215 }
66216
66217+#ifdef CONFIG_PAX_REFCOUNT
66218+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66219+{
66220+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66221+
66222+ return (long)atomic64_add_return_unchecked(i, v);
66223+}
66224+#endif
66225+
66226 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66227 {
66228 atomic64_t *v = (atomic64_t *)l;
66229@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66230 return (long)atomic64_inc_return(v);
66231 }
66232
66233+#ifdef CONFIG_PAX_REFCOUNT
66234+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66235+{
66236+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66237+
66238+ return (long)atomic64_inc_return_unchecked(v);
66239+}
66240+#endif
66241+
66242 static inline long atomic_long_dec_return(atomic_long_t *l)
66243 {
66244 atomic64_t *v = (atomic64_t *)l;
66245@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66246
66247 typedef atomic_t atomic_long_t;
66248
66249+#ifdef CONFIG_PAX_REFCOUNT
66250+typedef atomic_unchecked_t atomic_long_unchecked_t;
66251+#else
66252+typedef atomic_t atomic_long_unchecked_t;
66253+#endif
66254+
66255 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
66256 static inline long atomic_long_read(atomic_long_t *l)
66257 {
66258@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66259 return (long)atomic_read(v);
66260 }
66261
66262+#ifdef CONFIG_PAX_REFCOUNT
66263+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66264+{
66265+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66266+
66267+ return (long)atomic_read_unchecked(v);
66268+}
66269+#endif
66270+
66271 static inline void atomic_long_set(atomic_long_t *l, long i)
66272 {
66273 atomic_t *v = (atomic_t *)l;
66274@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66275 atomic_set(v, i);
66276 }
66277
66278+#ifdef CONFIG_PAX_REFCOUNT
66279+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66280+{
66281+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66282+
66283+ atomic_set_unchecked(v, i);
66284+}
66285+#endif
66286+
66287 static inline void atomic_long_inc(atomic_long_t *l)
66288 {
66289 atomic_t *v = (atomic_t *)l;
66290@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66291 atomic_inc(v);
66292 }
66293
66294+#ifdef CONFIG_PAX_REFCOUNT
66295+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66296+{
66297+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66298+
66299+ atomic_inc_unchecked(v);
66300+}
66301+#endif
66302+
66303 static inline void atomic_long_dec(atomic_long_t *l)
66304 {
66305 atomic_t *v = (atomic_t *)l;
66306@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66307 atomic_dec(v);
66308 }
66309
66310+#ifdef CONFIG_PAX_REFCOUNT
66311+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66312+{
66313+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66314+
66315+ atomic_dec_unchecked(v);
66316+}
66317+#endif
66318+
66319 static inline void atomic_long_add(long i, atomic_long_t *l)
66320 {
66321 atomic_t *v = (atomic_t *)l;
66322@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66323 atomic_add(i, v);
66324 }
66325
66326+#ifdef CONFIG_PAX_REFCOUNT
66327+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66328+{
66329+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66330+
66331+ atomic_add_unchecked(i, v);
66332+}
66333+#endif
66334+
66335 static inline void atomic_long_sub(long i, atomic_long_t *l)
66336 {
66337 atomic_t *v = (atomic_t *)l;
66338@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66339 atomic_sub(i, v);
66340 }
66341
66342+#ifdef CONFIG_PAX_REFCOUNT
66343+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66344+{
66345+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66346+
66347+ atomic_sub_unchecked(i, v);
66348+}
66349+#endif
66350+
66351 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66352 {
66353 atomic_t *v = (atomic_t *)l;
66354@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66355 return (long)atomic_add_return(i, v);
66356 }
66357
66358+#ifdef CONFIG_PAX_REFCOUNT
66359+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66360+{
66361+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66362+
66363+ return (long)atomic_add_return_unchecked(i, v);
66364+}
66365+
66366+#endif
66367+
66368 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66369 {
66370 atomic_t *v = (atomic_t *)l;
66371@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66372 return (long)atomic_inc_return(v);
66373 }
66374
66375+#ifdef CONFIG_PAX_REFCOUNT
66376+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66377+{
66378+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66379+
66380+ return (long)atomic_inc_return_unchecked(v);
66381+}
66382+#endif
66383+
66384 static inline long atomic_long_dec_return(atomic_long_t *l)
66385 {
66386 atomic_t *v = (atomic_t *)l;
66387@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66388
66389 #endif /* BITS_PER_LONG == 64 */
66390
66391+#ifdef CONFIG_PAX_REFCOUNT
66392+static inline void pax_refcount_needs_these_functions(void)
66393+{
66394+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
66395+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
66396+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
66397+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
66398+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
66399+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
66400+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
66401+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
66402+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
66403+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
66404+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
66405+#ifdef CONFIG_X86
66406+ atomic_clear_mask_unchecked(0, NULL);
66407+ atomic_set_mask_unchecked(0, NULL);
66408+#endif
66409+
66410+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
66411+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
66412+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
66413+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
66414+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
66415+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
66416+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
66417+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
66418+}
66419+#else
66420+#define atomic_read_unchecked(v) atomic_read(v)
66421+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
66422+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
66423+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
66424+#define atomic_inc_unchecked(v) atomic_inc(v)
66425+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
66426+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
66427+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
66428+#define atomic_dec_unchecked(v) atomic_dec(v)
66429+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
66430+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
66431+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
66432+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
66433+
66434+#define atomic_long_read_unchecked(v) atomic_long_read(v)
66435+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
66436+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
66437+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
66438+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
66439+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
66440+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
66441+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
66442+#endif
66443+
66444 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
66445diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
66446index 1ced641..c896ee8 100644
66447--- a/include/asm-generic/atomic.h
66448+++ b/include/asm-generic/atomic.h
66449@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
66450 * Atomically clears the bits set in @mask from @v
66451 */
66452 #ifndef atomic_clear_mask
66453-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
66454+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
66455 {
66456 unsigned long flags;
66457
66458diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
66459index b18ce4f..2ee2843 100644
66460--- a/include/asm-generic/atomic64.h
66461+++ b/include/asm-generic/atomic64.h
66462@@ -16,6 +16,8 @@ typedef struct {
66463 long long counter;
66464 } atomic64_t;
66465
66466+typedef atomic64_t atomic64_unchecked_t;
66467+
66468 #define ATOMIC64_INIT(i) { (i) }
66469
66470 extern long long atomic64_read(const atomic64_t *v);
66471@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
66472 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
66473 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
66474
66475+#define atomic64_read_unchecked(v) atomic64_read(v)
66476+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
66477+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
66478+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
66479+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
66480+#define atomic64_inc_unchecked(v) atomic64_inc(v)
66481+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
66482+#define atomic64_dec_unchecked(v) atomic64_dec(v)
66483+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
66484+
66485 #endif /* _ASM_GENERIC_ATOMIC64_H */
66486diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
66487index 1bfcfe5..e04c5c9 100644
66488--- a/include/asm-generic/cache.h
66489+++ b/include/asm-generic/cache.h
66490@@ -6,7 +6,7 @@
66491 * cache lines need to provide their own cache.h.
66492 */
66493
66494-#define L1_CACHE_SHIFT 5
66495-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
66496+#define L1_CACHE_SHIFT 5UL
66497+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
66498
66499 #endif /* __ASM_GENERIC_CACHE_H */
66500diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
66501index 0d68a1e..b74a761 100644
66502--- a/include/asm-generic/emergency-restart.h
66503+++ b/include/asm-generic/emergency-restart.h
66504@@ -1,7 +1,7 @@
66505 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
66506 #define _ASM_GENERIC_EMERGENCY_RESTART_H
66507
66508-static inline void machine_emergency_restart(void)
66509+static inline __noreturn void machine_emergency_restart(void)
66510 {
66511 machine_restart(NULL);
66512 }
66513diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66514index 90f99c7..00ce236 100644
66515--- a/include/asm-generic/kmap_types.h
66516+++ b/include/asm-generic/kmap_types.h
66517@@ -2,9 +2,9 @@
66518 #define _ASM_GENERIC_KMAP_TYPES_H
66519
66520 #ifdef __WITH_KM_FENCE
66521-# define KM_TYPE_NR 41
66522+# define KM_TYPE_NR 42
66523 #else
66524-# define KM_TYPE_NR 20
66525+# define KM_TYPE_NR 21
66526 #endif
66527
66528 #endif
66529diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66530index 9ceb03b..62b0b8f 100644
66531--- a/include/asm-generic/local.h
66532+++ b/include/asm-generic/local.h
66533@@ -23,24 +23,37 @@ typedef struct
66534 atomic_long_t a;
66535 } local_t;
66536
66537+typedef struct {
66538+ atomic_long_unchecked_t a;
66539+} local_unchecked_t;
66540+
66541 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66542
66543 #define local_read(l) atomic_long_read(&(l)->a)
66544+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66545 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66546+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66547 #define local_inc(l) atomic_long_inc(&(l)->a)
66548+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66549 #define local_dec(l) atomic_long_dec(&(l)->a)
66550+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66551 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66552+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66553 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66554+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66555
66556 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66557 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66558 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66559 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66560 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66561+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66562 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66563 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66564+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66565
66566 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66567+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66568 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66569 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66570 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66571diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66572index 725612b..9cc513a 100644
66573--- a/include/asm-generic/pgtable-nopmd.h
66574+++ b/include/asm-generic/pgtable-nopmd.h
66575@@ -1,14 +1,19 @@
66576 #ifndef _PGTABLE_NOPMD_H
66577 #define _PGTABLE_NOPMD_H
66578
66579-#ifndef __ASSEMBLY__
66580-
66581 #include <asm-generic/pgtable-nopud.h>
66582
66583-struct mm_struct;
66584-
66585 #define __PAGETABLE_PMD_FOLDED
66586
66587+#define PMD_SHIFT PUD_SHIFT
66588+#define PTRS_PER_PMD 1
66589+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66590+#define PMD_MASK (~(PMD_SIZE-1))
66591+
66592+#ifndef __ASSEMBLY__
66593+
66594+struct mm_struct;
66595+
66596 /*
66597 * Having the pmd type consist of a pud gets the size right, and allows
66598 * us to conceptually access the pud entry that this pmd is folded into
66599@@ -16,11 +21,6 @@ struct mm_struct;
66600 */
66601 typedef struct { pud_t pud; } pmd_t;
66602
66603-#define PMD_SHIFT PUD_SHIFT
66604-#define PTRS_PER_PMD 1
66605-#define PMD_SIZE (1UL << PMD_SHIFT)
66606-#define PMD_MASK (~(PMD_SIZE-1))
66607-
66608 /*
66609 * The "pud_xxx()" functions here are trivial for a folded two-level
66610 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66611diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66612index 810431d..0ec4804f 100644
66613--- a/include/asm-generic/pgtable-nopud.h
66614+++ b/include/asm-generic/pgtable-nopud.h
66615@@ -1,10 +1,15 @@
66616 #ifndef _PGTABLE_NOPUD_H
66617 #define _PGTABLE_NOPUD_H
66618
66619-#ifndef __ASSEMBLY__
66620-
66621 #define __PAGETABLE_PUD_FOLDED
66622
66623+#define PUD_SHIFT PGDIR_SHIFT
66624+#define PTRS_PER_PUD 1
66625+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66626+#define PUD_MASK (~(PUD_SIZE-1))
66627+
66628+#ifndef __ASSEMBLY__
66629+
66630 /*
66631 * Having the pud type consist of a pgd gets the size right, and allows
66632 * us to conceptually access the pgd entry that this pud is folded into
66633@@ -12,11 +17,6 @@
66634 */
66635 typedef struct { pgd_t pgd; } pud_t;
66636
66637-#define PUD_SHIFT PGDIR_SHIFT
66638-#define PTRS_PER_PUD 1
66639-#define PUD_SIZE (1UL << PUD_SHIFT)
66640-#define PUD_MASK (~(PUD_SIZE-1))
66641-
66642 /*
66643 * The "pgd_xxx()" functions here are trivial for a folded two-level
66644 * setup: the pud is never bad, and a pud always exists (as it's folded
66645@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66646 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66647
66648 #define pgd_populate(mm, pgd, pud) do { } while (0)
66649+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66650 /*
66651 * (puds are folded into pgds so this doesn't get actually called,
66652 * but the define is needed for a generic inline function.)
66653diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66654index 5cf680a..4b74d62 100644
66655--- a/include/asm-generic/pgtable.h
66656+++ b/include/asm-generic/pgtable.h
66657@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66658 }
66659 #endif /* CONFIG_NUMA_BALANCING */
66660
66661+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66662+static inline unsigned long pax_open_kernel(void) { return 0; }
66663+#endif
66664+
66665+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66666+static inline unsigned long pax_close_kernel(void) { return 0; }
66667+#endif
66668+
66669 #endif /* CONFIG_MMU */
66670
66671 #endif /* !__ASSEMBLY__ */
66672diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66673index d1ea7ce..b1ebf2a 100644
66674--- a/include/asm-generic/vmlinux.lds.h
66675+++ b/include/asm-generic/vmlinux.lds.h
66676@@ -218,6 +218,7 @@
66677 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66678 VMLINUX_SYMBOL(__start_rodata) = .; \
66679 *(.rodata) *(.rodata.*) \
66680+ *(.data..read_only) \
66681 *(__vermagic) /* Kernel version magic */ \
66682 . = ALIGN(8); \
66683 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66684@@ -725,17 +726,18 @@
66685 * section in the linker script will go there too. @phdr should have
66686 * a leading colon.
66687 *
66688- * Note that this macros defines __per_cpu_load as an absolute symbol.
66689+ * Note that this macros defines per_cpu_load as an absolute symbol.
66690 * If there is no need to put the percpu section at a predetermined
66691 * address, use PERCPU_SECTION.
66692 */
66693 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66694- VMLINUX_SYMBOL(__per_cpu_load) = .; \
66695- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66696+ per_cpu_load = .; \
66697+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66698 - LOAD_OFFSET) { \
66699+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66700 PERCPU_INPUT(cacheline) \
66701 } phdr \
66702- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66703+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66704
66705 /**
66706 * PERCPU_SECTION - define output section for percpu area, simple version
66707diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66708index 418d270..bfd2794 100644
66709--- a/include/crypto/algapi.h
66710+++ b/include/crypto/algapi.h
66711@@ -34,7 +34,7 @@ struct crypto_type {
66712 unsigned int maskclear;
66713 unsigned int maskset;
66714 unsigned int tfmsize;
66715-};
66716+} __do_const;
66717
66718 struct crypto_instance {
66719 struct crypto_alg alg;
66720diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66721index fad21c9..ab858bc 100644
66722--- a/include/drm/drmP.h
66723+++ b/include/drm/drmP.h
66724@@ -72,6 +72,7 @@
66725 #include <linux/workqueue.h>
66726 #include <linux/poll.h>
66727 #include <asm/pgalloc.h>
66728+#include <asm/local.h>
66729 #include <drm/drm.h>
66730 #include <drm/drm_sarea.h>
66731
66732@@ -293,10 +294,12 @@ do { \
66733 * \param cmd command.
66734 * \param arg argument.
66735 */
66736-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66737+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66738+ struct drm_file *file_priv);
66739+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66740 struct drm_file *file_priv);
66741
66742-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66743+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66744 unsigned long arg);
66745
66746 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66747@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66748 struct drm_ioctl_desc {
66749 unsigned int cmd;
66750 int flags;
66751- drm_ioctl_t *func;
66752+ drm_ioctl_t func;
66753 unsigned int cmd_drv;
66754-};
66755+} __do_const;
66756
66757 /**
66758 * Creates a driver or general drm_ioctl_desc array entry for the given
66759@@ -995,7 +998,7 @@ struct drm_info_list {
66760 int (*show)(struct seq_file*, void*); /** show callback */
66761 u32 driver_features; /**< Required driver features for this entry */
66762 void *data;
66763-};
66764+} __do_const;
66765
66766 /**
66767 * debugfs node structure. This structure represents a debugfs file.
66768@@ -1068,7 +1071,7 @@ struct drm_device {
66769
66770 /** \name Usage Counters */
66771 /*@{ */
66772- int open_count; /**< Outstanding files open */
66773+ local_t open_count; /**< Outstanding files open */
66774 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66775 atomic_t vma_count; /**< Outstanding vma areas open */
66776 int buf_use; /**< Buffers in use -- cannot alloc */
66777@@ -1079,7 +1082,7 @@ struct drm_device {
66778 /*@{ */
66779 unsigned long counters;
66780 enum drm_stat_type types[15];
66781- atomic_t counts[15];
66782+ atomic_unchecked_t counts[15];
66783 /*@} */
66784
66785 struct list_head filelist;
66786diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66787index f43d556..94d9343 100644
66788--- a/include/drm/drm_crtc_helper.h
66789+++ b/include/drm/drm_crtc_helper.h
66790@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66791 struct drm_connector *connector);
66792 /* disable encoder when not in use - more explicit than dpms off */
66793 void (*disable)(struct drm_encoder *encoder);
66794-};
66795+} __no_const;
66796
66797 /**
66798 * drm_connector_helper_funcs - helper operations for connectors
66799diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66800index 72dcbe8..8db58d7 100644
66801--- a/include/drm/ttm/ttm_memory.h
66802+++ b/include/drm/ttm/ttm_memory.h
66803@@ -48,7 +48,7 @@
66804
66805 struct ttm_mem_shrink {
66806 int (*do_shrink) (struct ttm_mem_shrink *);
66807-};
66808+} __no_const;
66809
66810 /**
66811 * struct ttm_mem_global - Global memory accounting structure.
66812diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66813index 4b840e8..155d235 100644
66814--- a/include/keys/asymmetric-subtype.h
66815+++ b/include/keys/asymmetric-subtype.h
66816@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66817 /* Verify the signature on a key of this subtype (optional) */
66818 int (*verify_signature)(const struct key *key,
66819 const struct public_key_signature *sig);
66820-};
66821+} __do_const;
66822
66823 /**
66824 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66825diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66826index c1da539..1dcec55 100644
66827--- a/include/linux/atmdev.h
66828+++ b/include/linux/atmdev.h
66829@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66830 #endif
66831
66832 struct k_atm_aal_stats {
66833-#define __HANDLE_ITEM(i) atomic_t i
66834+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66835 __AAL_STAT_ITEMS
66836 #undef __HANDLE_ITEM
66837 };
66838@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66839 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66840 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66841 struct module *owner;
66842-};
66843+} __do_const ;
66844
66845 struct atmphy_ops {
66846 int (*start)(struct atm_dev *dev);
66847diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66848index 0530b98..96a8ac0 100644
66849--- a/include/linux/binfmts.h
66850+++ b/include/linux/binfmts.h
66851@@ -73,8 +73,9 @@ struct linux_binfmt {
66852 int (*load_binary)(struct linux_binprm *);
66853 int (*load_shlib)(struct file *);
66854 int (*core_dump)(struct coredump_params *cprm);
66855+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66856 unsigned long min_coredump; /* minimal dump size */
66857-};
66858+} __do_const;
66859
66860 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66861
66862diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66863index f94bc83..62b9cfe 100644
66864--- a/include/linux/blkdev.h
66865+++ b/include/linux/blkdev.h
66866@@ -1498,7 +1498,7 @@ struct block_device_operations {
66867 /* this callback is with swap_lock and sometimes page table lock held */
66868 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66869 struct module *owner;
66870-};
66871+} __do_const;
66872
66873 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66874 unsigned long);
66875diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66876index 7c2e030..b72475d 100644
66877--- a/include/linux/blktrace_api.h
66878+++ b/include/linux/blktrace_api.h
66879@@ -23,7 +23,7 @@ struct blk_trace {
66880 struct dentry *dir;
66881 struct dentry *dropped_file;
66882 struct dentry *msg_file;
66883- atomic_t dropped;
66884+ atomic_unchecked_t dropped;
66885 };
66886
66887 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66888diff --git a/include/linux/cache.h b/include/linux/cache.h
66889index 4c57065..4307975 100644
66890--- a/include/linux/cache.h
66891+++ b/include/linux/cache.h
66892@@ -16,6 +16,10 @@
66893 #define __read_mostly
66894 #endif
66895
66896+#ifndef __read_only
66897+#define __read_only __read_mostly
66898+#endif
66899+
66900 #ifndef ____cacheline_aligned
66901 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66902 #endif
66903diff --git a/include/linux/capability.h b/include/linux/capability.h
66904index 98503b7..cc36d18 100644
66905--- a/include/linux/capability.h
66906+++ b/include/linux/capability.h
66907@@ -211,8 +211,13 @@ extern bool capable(int cap);
66908 extern bool ns_capable(struct user_namespace *ns, int cap);
66909 extern bool nsown_capable(int cap);
66910 extern bool inode_capable(const struct inode *inode, int cap);
66911+extern bool capable_nolog(int cap);
66912+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66913+extern bool inode_capable_nolog(const struct inode *inode, int cap);
66914
66915 /* audit system wants to get cap info from files as well */
66916 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66917
66918+extern int is_privileged_binary(const struct dentry *dentry);
66919+
66920 #endif /* !_LINUX_CAPABILITY_H */
66921diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66922index 8609d57..86e4d79 100644
66923--- a/include/linux/cdrom.h
66924+++ b/include/linux/cdrom.h
66925@@ -87,7 +87,6 @@ struct cdrom_device_ops {
66926
66927 /* driver specifications */
66928 const int capability; /* capability flags */
66929- int n_minors; /* number of active minor devices */
66930 /* handle uniform packets for scsi type devices (scsi,atapi) */
66931 int (*generic_packet) (struct cdrom_device_info *,
66932 struct packet_command *);
66933diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66934index 42e55de..1cd0e66 100644
66935--- a/include/linux/cleancache.h
66936+++ b/include/linux/cleancache.h
66937@@ -31,7 +31,7 @@ struct cleancache_ops {
66938 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66939 void (*invalidate_inode)(int, struct cleancache_filekey);
66940 void (*invalidate_fs)(int);
66941-};
66942+} __no_const;
66943
66944 extern struct cleancache_ops
66945 cleancache_register_ops(struct cleancache_ops *ops);
66946diff --git a/include/linux/compat.h b/include/linux/compat.h
66947index dec7e2d..e1d5880 100644
66948--- a/include/linux/compat.h
66949+++ b/include/linux/compat.h
66950@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
66951 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
66952 int version, void __user *uptr);
66953 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
66954- void __user *uptr);
66955+ void __user *uptr) __intentional_overflow(0);
66956 #else
66957 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
66958 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
66959 compat_ssize_t msgsz, int msgflg);
66960 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
66961 compat_ssize_t msgsz, long msgtyp, int msgflg);
66962-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
66963+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
66964 #endif
66965 long compat_sys_msgctl(int first, int second, void __user *uptr);
66966 long compat_sys_shmctl(int first, int second, void __user *uptr);
66967diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66968index 662fd1b..e801992 100644
66969--- a/include/linux/compiler-gcc4.h
66970+++ b/include/linux/compiler-gcc4.h
66971@@ -34,6 +34,21 @@
66972 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66973
66974 #if __GNUC_MINOR__ >= 5
66975+
66976+#ifdef CONSTIFY_PLUGIN
66977+#define __no_const __attribute__((no_const))
66978+#define __do_const __attribute__((do_const))
66979+#endif
66980+
66981+#ifdef SIZE_OVERFLOW_PLUGIN
66982+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66983+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66984+#endif
66985+
66986+#ifdef LATENT_ENTROPY_PLUGIN
66987+#define __latent_entropy __attribute__((latent_entropy))
66988+#endif
66989+
66990 /*
66991 * Mark a position in code as unreachable. This can be used to
66992 * suppress control flow warnings after asm blocks that transfer
66993@@ -49,6 +64,11 @@
66994 #define __noclone __attribute__((__noclone__))
66995
66996 #endif
66997+
66998+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
66999+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67000+#define __bos0(ptr) __bos((ptr), 0)
67001+#define __bos1(ptr) __bos((ptr), 1)
67002 #endif
67003
67004 #if __GNUC_MINOR__ >= 6
67005diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67006index dd852b7..72924c0 100644
67007--- a/include/linux/compiler.h
67008+++ b/include/linux/compiler.h
67009@@ -5,11 +5,14 @@
67010
67011 #ifdef __CHECKER__
67012 # define __user __attribute__((noderef, address_space(1)))
67013+# define __force_user __force __user
67014 # define __kernel __attribute__((address_space(0)))
67015+# define __force_kernel __force __kernel
67016 # define __safe __attribute__((safe))
67017 # define __force __attribute__((force))
67018 # define __nocast __attribute__((nocast))
67019 # define __iomem __attribute__((noderef, address_space(2)))
67020+# define __force_iomem __force __iomem
67021 # define __must_hold(x) __attribute__((context(x,1,1)))
67022 # define __acquires(x) __attribute__((context(x,0,1)))
67023 # define __releases(x) __attribute__((context(x,1,0)))
67024@@ -17,20 +20,48 @@
67025 # define __release(x) __context__(x,-1)
67026 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
67027 # define __percpu __attribute__((noderef, address_space(3)))
67028+# define __force_percpu __force __percpu
67029 #ifdef CONFIG_SPARSE_RCU_POINTER
67030 # define __rcu __attribute__((noderef, address_space(4)))
67031+# define __force_rcu __force __rcu
67032 #else
67033 # define __rcu
67034+# define __force_rcu
67035 #endif
67036 extern void __chk_user_ptr(const volatile void __user *);
67037 extern void __chk_io_ptr(const volatile void __iomem *);
67038+#elif defined(CHECKER_PLUGIN)
67039+//# define __user
67040+//# define __force_user
67041+//# define __kernel
67042+//# define __force_kernel
67043+# define __safe
67044+# define __force
67045+# define __nocast
67046+# define __iomem
67047+# define __force_iomem
67048+# define __chk_user_ptr(x) (void)0
67049+# define __chk_io_ptr(x) (void)0
67050+# define __builtin_warning(x, y...) (1)
67051+# define __acquires(x)
67052+# define __releases(x)
67053+# define __acquire(x) (void)0
67054+# define __release(x) (void)0
67055+# define __cond_lock(x,c) (c)
67056+# define __percpu
67057+# define __force_percpu
67058+# define __rcu
67059+# define __force_rcu
67060 #else
67061 # define __user
67062+# define __force_user
67063 # define __kernel
67064+# define __force_kernel
67065 # define __safe
67066 # define __force
67067 # define __nocast
67068 # define __iomem
67069+# define __force_iomem
67070 # define __chk_user_ptr(x) (void)0
67071 # define __chk_io_ptr(x) (void)0
67072 # define __builtin_warning(x, y...) (1)
67073@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
67074 # define __release(x) (void)0
67075 # define __cond_lock(x,c) (c)
67076 # define __percpu
67077+# define __force_percpu
67078 # define __rcu
67079+# define __force_rcu
67080 #endif
67081
67082 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
67083@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67084 # define __attribute_const__ /* unimplemented */
67085 #endif
67086
67087+#ifndef __no_const
67088+# define __no_const
67089+#endif
67090+
67091+#ifndef __do_const
67092+# define __do_const
67093+#endif
67094+
67095+#ifndef __size_overflow
67096+# define __size_overflow(...)
67097+#endif
67098+
67099+#ifndef __intentional_overflow
67100+# define __intentional_overflow(...)
67101+#endif
67102+
67103+#ifndef __latent_entropy
67104+# define __latent_entropy
67105+#endif
67106+
67107 /*
67108 * Tell gcc if a function is cold. The compiler will assume any path
67109 * directly leading to the call is unlikely.
67110@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67111 #define __cold
67112 #endif
67113
67114+#ifndef __alloc_size
67115+#define __alloc_size(...)
67116+#endif
67117+
67118+#ifndef __bos
67119+#define __bos(ptr, arg)
67120+#endif
67121+
67122+#ifndef __bos0
67123+#define __bos0(ptr)
67124+#endif
67125+
67126+#ifndef __bos1
67127+#define __bos1(ptr)
67128+#endif
67129+
67130 /* Simple shorthand for a section definition */
67131 #ifndef __section
67132 # define __section(S) __attribute__ ((__section__(#S)))
67133@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67134 * use is to mediate communication between process-level code and irq/NMI
67135 * handlers, all running on the same CPU.
67136 */
67137-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
67138+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
67139+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
67140
67141 #endif /* __LINUX_COMPILER_H */
67142diff --git a/include/linux/completion.h b/include/linux/completion.h
67143index 51494e6..0fd1b61 100644
67144--- a/include/linux/completion.h
67145+++ b/include/linux/completion.h
67146@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
67147
67148 extern void wait_for_completion(struct completion *);
67149 extern int wait_for_completion_interruptible(struct completion *x);
67150-extern int wait_for_completion_killable(struct completion *x);
67151+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
67152 extern unsigned long wait_for_completion_timeout(struct completion *x,
67153 unsigned long timeout);
67154 extern long wait_for_completion_interruptible_timeout(
67155- struct completion *x, unsigned long timeout);
67156+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67157 extern long wait_for_completion_killable_timeout(
67158- struct completion *x, unsigned long timeout);
67159+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67160 extern bool try_wait_for_completion(struct completion *x);
67161 extern bool completion_done(struct completion *x);
67162
67163diff --git a/include/linux/configfs.h b/include/linux/configfs.h
67164index 34025df..d94bbbc 100644
67165--- a/include/linux/configfs.h
67166+++ b/include/linux/configfs.h
67167@@ -125,7 +125,7 @@ struct configfs_attribute {
67168 const char *ca_name;
67169 struct module *ca_owner;
67170 umode_t ca_mode;
67171-};
67172+} __do_const;
67173
67174 /*
67175 * Users often need to create attribute structures for their configurable
67176diff --git a/include/linux/cpu.h b/include/linux/cpu.h
67177index ce7a074..01ab8ac 100644
67178--- a/include/linux/cpu.h
67179+++ b/include/linux/cpu.h
67180@@ -115,7 +115,7 @@ enum {
67181 /* Need to know about CPUs going up/down? */
67182 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
67183 #define cpu_notifier(fn, pri) { \
67184- static struct notifier_block fn##_nb __cpuinitdata = \
67185+ static struct notifier_block fn##_nb = \
67186 { .notifier_call = fn, .priority = pri }; \
67187 register_cpu_notifier(&fn##_nb); \
67188 }
67189diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
67190index a55b88e..fba90c5 100644
67191--- a/include/linux/cpufreq.h
67192+++ b/include/linux/cpufreq.h
67193@@ -240,7 +240,7 @@ struct cpufreq_driver {
67194 int (*suspend) (struct cpufreq_policy *policy);
67195 int (*resume) (struct cpufreq_policy *policy);
67196 struct freq_attr **attr;
67197-};
67198+} __do_const;
67199
67200 /* flags */
67201
67202@@ -299,6 +299,7 @@ struct global_attr {
67203 ssize_t (*store)(struct kobject *a, struct attribute *b,
67204 const char *c, size_t count);
67205 };
67206+typedef struct global_attr __no_const global_attr_no_const;
67207
67208 #define define_one_global_ro(_name) \
67209 static struct global_attr _name = \
67210diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
67211index 24cd1037..20a63aae 100644
67212--- a/include/linux/cpuidle.h
67213+++ b/include/linux/cpuidle.h
67214@@ -54,7 +54,8 @@ struct cpuidle_state {
67215 int index);
67216
67217 int (*enter_dead) (struct cpuidle_device *dev, int index);
67218-};
67219+} __do_const;
67220+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
67221
67222 /* Idle State Flags */
67223 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
67224@@ -216,7 +217,7 @@ struct cpuidle_governor {
67225 void (*reflect) (struct cpuidle_device *dev, int index);
67226
67227 struct module *owner;
67228-};
67229+} __do_const;
67230
67231 #ifdef CONFIG_CPU_IDLE
67232
67233diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
67234index 0325602..5e9feff 100644
67235--- a/include/linux/cpumask.h
67236+++ b/include/linux/cpumask.h
67237@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67238 }
67239
67240 /* Valid inputs for n are -1 and 0. */
67241-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67242+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67243 {
67244 return n+1;
67245 }
67246
67247-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67248+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67249 {
67250 return n+1;
67251 }
67252
67253-static inline unsigned int cpumask_next_and(int n,
67254+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
67255 const struct cpumask *srcp,
67256 const struct cpumask *andp)
67257 {
67258@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67259 *
67260 * Returns >= nr_cpu_ids if no further cpus set.
67261 */
67262-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67263+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67264 {
67265 /* -1 is a legal arg here. */
67266 if (n != -1)
67267@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67268 *
67269 * Returns >= nr_cpu_ids if no further cpus unset.
67270 */
67271-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67272+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67273 {
67274 /* -1 is a legal arg here. */
67275 if (n != -1)
67276@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67277 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
67278 }
67279
67280-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
67281+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
67282 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
67283
67284 /**
67285diff --git a/include/linux/cred.h b/include/linux/cred.h
67286index 04421e8..6bce4ef 100644
67287--- a/include/linux/cred.h
67288+++ b/include/linux/cred.h
67289@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
67290 static inline void validate_process_creds(void)
67291 {
67292 }
67293+static inline void validate_task_creds(struct task_struct *task)
67294+{
67295+}
67296 #endif
67297
67298 /**
67299diff --git a/include/linux/crypto.h b/include/linux/crypto.h
67300index b92eadf..b4ecdc1 100644
67301--- a/include/linux/crypto.h
67302+++ b/include/linux/crypto.h
67303@@ -373,7 +373,7 @@ struct cipher_tfm {
67304 const u8 *key, unsigned int keylen);
67305 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67306 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67307-};
67308+} __no_const;
67309
67310 struct hash_tfm {
67311 int (*init)(struct hash_desc *desc);
67312@@ -394,13 +394,13 @@ struct compress_tfm {
67313 int (*cot_decompress)(struct crypto_tfm *tfm,
67314 const u8 *src, unsigned int slen,
67315 u8 *dst, unsigned int *dlen);
67316-};
67317+} __no_const;
67318
67319 struct rng_tfm {
67320 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
67321 unsigned int dlen);
67322 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
67323-};
67324+} __no_const;
67325
67326 #define crt_ablkcipher crt_u.ablkcipher
67327 #define crt_aead crt_u.aead
67328diff --git a/include/linux/ctype.h b/include/linux/ctype.h
67329index 8acfe31..6ffccd63 100644
67330--- a/include/linux/ctype.h
67331+++ b/include/linux/ctype.h
67332@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
67333 * Fast implementation of tolower() for internal usage. Do not use in your
67334 * code.
67335 */
67336-static inline char _tolower(const char c)
67337+static inline unsigned char _tolower(const unsigned char c)
67338 {
67339 return c | 0x20;
67340 }
67341diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
67342index 7925bf0..d5143d2 100644
67343--- a/include/linux/decompress/mm.h
67344+++ b/include/linux/decompress/mm.h
67345@@ -77,7 +77,7 @@ static void free(void *where)
67346 * warnings when not needed (indeed large_malloc / large_free are not
67347 * needed by inflate */
67348
67349-#define malloc(a) kmalloc(a, GFP_KERNEL)
67350+#define malloc(a) kmalloc((a), GFP_KERNEL)
67351 #define free(a) kfree(a)
67352
67353 #define large_malloc(a) vmalloc(a)
67354diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
67355index e83ef39..33e0eb3 100644
67356--- a/include/linux/devfreq.h
67357+++ b/include/linux/devfreq.h
67358@@ -114,7 +114,7 @@ struct devfreq_governor {
67359 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
67360 int (*event_handler)(struct devfreq *devfreq,
67361 unsigned int event, void *data);
67362-};
67363+} __do_const;
67364
67365 /**
67366 * struct devfreq - Device devfreq structure
67367diff --git a/include/linux/device.h b/include/linux/device.h
67368index 43dcda9..7a1fb65 100644
67369--- a/include/linux/device.h
67370+++ b/include/linux/device.h
67371@@ -294,7 +294,7 @@ struct subsys_interface {
67372 struct list_head node;
67373 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
67374 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
67375-};
67376+} __do_const;
67377
67378 int subsys_interface_register(struct subsys_interface *sif);
67379 void subsys_interface_unregister(struct subsys_interface *sif);
67380@@ -474,7 +474,7 @@ struct device_type {
67381 void (*release)(struct device *dev);
67382
67383 const struct dev_pm_ops *pm;
67384-};
67385+} __do_const;
67386
67387 /* interface for exporting device attributes */
67388 struct device_attribute {
67389@@ -484,11 +484,12 @@ struct device_attribute {
67390 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
67391 const char *buf, size_t count);
67392 };
67393+typedef struct device_attribute __no_const device_attribute_no_const;
67394
67395 struct dev_ext_attribute {
67396 struct device_attribute attr;
67397 void *var;
67398-};
67399+} __do_const;
67400
67401 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
67402 char *buf);
67403diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
67404index 94af418..b1ca7a2 100644
67405--- a/include/linux/dma-mapping.h
67406+++ b/include/linux/dma-mapping.h
67407@@ -54,7 +54,7 @@ struct dma_map_ops {
67408 u64 (*get_required_mask)(struct device *dev);
67409 #endif
67410 int is_phys;
67411-};
67412+} __do_const;
67413
67414 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
67415
67416diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
67417index d3201e4..8281e63 100644
67418--- a/include/linux/dmaengine.h
67419+++ b/include/linux/dmaengine.h
67420@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
67421 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
67422 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
67423
67424-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67425+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67426 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
67427-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67428+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67429 struct dma_pinned_list *pinned_list, struct page *page,
67430 unsigned int offset, size_t len);
67431
67432diff --git a/include/linux/efi.h b/include/linux/efi.h
67433index 7a9498a..155713d 100644
67434--- a/include/linux/efi.h
67435+++ b/include/linux/efi.h
67436@@ -733,6 +733,7 @@ struct efivar_operations {
67437 efi_set_variable_t *set_variable;
67438 efi_query_variable_info_t *query_variable_info;
67439 };
67440+typedef struct efivar_operations __no_const efivar_operations_no_const;
67441
67442 struct efivars {
67443 /*
67444diff --git a/include/linux/elf.h b/include/linux/elf.h
67445index 8c9048e..16a4665 100644
67446--- a/include/linux/elf.h
67447+++ b/include/linux/elf.h
67448@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
67449 #define elf_note elf32_note
67450 #define elf_addr_t Elf32_Off
67451 #define Elf_Half Elf32_Half
67452+#define elf_dyn Elf32_Dyn
67453
67454 #else
67455
67456@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
67457 #define elf_note elf64_note
67458 #define elf_addr_t Elf64_Off
67459 #define Elf_Half Elf64_Half
67460+#define elf_dyn Elf64_Dyn
67461
67462 #endif
67463
67464diff --git a/include/linux/err.h b/include/linux/err.h
67465index f2edce2..cc2082c 100644
67466--- a/include/linux/err.h
67467+++ b/include/linux/err.h
67468@@ -19,12 +19,12 @@
67469
67470 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
67471
67472-static inline void * __must_check ERR_PTR(long error)
67473+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
67474 {
67475 return (void *) error;
67476 }
67477
67478-static inline long __must_check PTR_ERR(const void *ptr)
67479+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
67480 {
67481 return (long) ptr;
67482 }
67483diff --git a/include/linux/extcon.h b/include/linux/extcon.h
67484index fcb51c8..bdafcf6 100644
67485--- a/include/linux/extcon.h
67486+++ b/include/linux/extcon.h
67487@@ -134,7 +134,7 @@ struct extcon_dev {
67488 /* /sys/class/extcon/.../mutually_exclusive/... */
67489 struct attribute_group attr_g_muex;
67490 struct attribute **attrs_muex;
67491- struct device_attribute *d_attrs_muex;
67492+ device_attribute_no_const *d_attrs_muex;
67493 };
67494
67495 /**
67496diff --git a/include/linux/fb.h b/include/linux/fb.h
67497index c7a9571..02eeffe 100644
67498--- a/include/linux/fb.h
67499+++ b/include/linux/fb.h
67500@@ -302,7 +302,7 @@ struct fb_ops {
67501 /* called at KDB enter and leave time to prepare the console */
67502 int (*fb_debug_enter)(struct fb_info *info);
67503 int (*fb_debug_leave)(struct fb_info *info);
67504-};
67505+} __do_const;
67506
67507 #ifdef CONFIG_FB_TILEBLITTING
67508 #define FB_TILE_CURSOR_NONE 0
67509diff --git a/include/linux/filter.h b/include/linux/filter.h
67510index c45eabc..baa0be5 100644
67511--- a/include/linux/filter.h
67512+++ b/include/linux/filter.h
67513@@ -20,6 +20,7 @@ struct compat_sock_fprog {
67514
67515 struct sk_buff;
67516 struct sock;
67517+struct bpf_jit_work;
67518
67519 struct sk_filter
67520 {
67521@@ -27,6 +28,9 @@ struct sk_filter
67522 unsigned int len; /* Number of filter blocks */
67523 unsigned int (*bpf_func)(const struct sk_buff *skb,
67524 const struct sock_filter *filter);
67525+#ifdef CONFIG_BPF_JIT
67526+ struct bpf_jit_work *work;
67527+#endif
67528 struct rcu_head rcu;
67529 struct sock_filter insns[0];
67530 };
67531diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
67532index 3044254..9767f41 100644
67533--- a/include/linux/frontswap.h
67534+++ b/include/linux/frontswap.h
67535@@ -11,7 +11,7 @@ struct frontswap_ops {
67536 int (*load)(unsigned, pgoff_t, struct page *);
67537 void (*invalidate_page)(unsigned, pgoff_t);
67538 void (*invalidate_area)(unsigned);
67539-};
67540+} __no_const;
67541
67542 extern bool frontswap_enabled;
67543 extern struct frontswap_ops
67544diff --git a/include/linux/fs.h b/include/linux/fs.h
67545index 7617ee0..b575199 100644
67546--- a/include/linux/fs.h
67547+++ b/include/linux/fs.h
67548@@ -1541,7 +1541,8 @@ struct file_operations {
67549 long (*fallocate)(struct file *file, int mode, loff_t offset,
67550 loff_t len);
67551 int (*show_fdinfo)(struct seq_file *m, struct file *f);
67552-};
67553+} __do_const;
67554+typedef struct file_operations __no_const file_operations_no_const;
67555
67556 struct inode_operations {
67557 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
67558@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
67559 inode->i_flags |= S_NOSEC;
67560 }
67561
67562+static inline bool is_sidechannel_device(const struct inode *inode)
67563+{
67564+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
67565+ umode_t mode = inode->i_mode;
67566+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
67567+#else
67568+ return false;
67569+#endif
67570+}
67571+
67572 #endif /* _LINUX_FS_H */
67573diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
67574index d0ae3a8..0244b34 100644
67575--- a/include/linux/fs_struct.h
67576+++ b/include/linux/fs_struct.h
67577@@ -6,7 +6,7 @@
67578 #include <linux/seqlock.h>
67579
67580 struct fs_struct {
67581- int users;
67582+ atomic_t users;
67583 spinlock_t lock;
67584 seqcount_t seq;
67585 int umask;
67586diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
67587index 5dfa0aa..6acf322 100644
67588--- a/include/linux/fscache-cache.h
67589+++ b/include/linux/fscache-cache.h
67590@@ -112,7 +112,7 @@ struct fscache_operation {
67591 fscache_operation_release_t release;
67592 };
67593
67594-extern atomic_t fscache_op_debug_id;
67595+extern atomic_unchecked_t fscache_op_debug_id;
67596 extern void fscache_op_work_func(struct work_struct *work);
67597
67598 extern void fscache_enqueue_operation(struct fscache_operation *);
67599@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
67600 INIT_WORK(&op->work, fscache_op_work_func);
67601 atomic_set(&op->usage, 1);
67602 op->state = FSCACHE_OP_ST_INITIALISED;
67603- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
67604+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
67605 op->processor = processor;
67606 op->release = release;
67607 INIT_LIST_HEAD(&op->pend_link);
67608diff --git a/include/linux/fscache.h b/include/linux/fscache.h
67609index 7a08623..4c07b0f 100644
67610--- a/include/linux/fscache.h
67611+++ b/include/linux/fscache.h
67612@@ -152,7 +152,7 @@ struct fscache_cookie_def {
67613 * - this is mandatory for any object that may have data
67614 */
67615 void (*now_uncached)(void *cookie_netfs_data);
67616-};
67617+} __do_const;
67618
67619 /*
67620 * fscache cached network filesystem type
67621diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
67622index 0fbfb46..508eb0d 100644
67623--- a/include/linux/fsnotify.h
67624+++ b/include/linux/fsnotify.h
67625@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
67626 struct inode *inode = path->dentry->d_inode;
67627 __u32 mask = FS_ACCESS;
67628
67629+ if (is_sidechannel_device(inode))
67630+ return;
67631+
67632 if (S_ISDIR(inode->i_mode))
67633 mask |= FS_ISDIR;
67634
67635@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
67636 struct inode *inode = path->dentry->d_inode;
67637 __u32 mask = FS_MODIFY;
67638
67639+ if (is_sidechannel_device(inode))
67640+ return;
67641+
67642 if (S_ISDIR(inode->i_mode))
67643 mask |= FS_ISDIR;
67644
67645@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
67646 */
67647 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
67648 {
67649- return kstrdup(name, GFP_KERNEL);
67650+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
67651 }
67652
67653 /*
67654diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
67655index a3d4895..ddd2a50 100644
67656--- a/include/linux/ftrace_event.h
67657+++ b/include/linux/ftrace_event.h
67658@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
67659 extern int trace_add_event_call(struct ftrace_event_call *call);
67660 extern void trace_remove_event_call(struct ftrace_event_call *call);
67661
67662-#define is_signed_type(type) (((type)(-1)) < 0)
67663+#define is_signed_type(type) (((type)(-1)) < (type)1)
67664
67665 int trace_set_clr_event(const char *system, const char *event, int set);
67666
67667diff --git a/include/linux/genhd.h b/include/linux/genhd.h
67668index 79b8bba..86b539e 100644
67669--- a/include/linux/genhd.h
67670+++ b/include/linux/genhd.h
67671@@ -194,7 +194,7 @@ struct gendisk {
67672 struct kobject *slave_dir;
67673
67674 struct timer_rand_state *random;
67675- atomic_t sync_io; /* RAID */
67676+ atomic_unchecked_t sync_io; /* RAID */
67677 struct disk_events *ev;
67678 #ifdef CONFIG_BLK_DEV_INTEGRITY
67679 struct blk_integrity *integrity;
67680diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
67681index 023bc34..b02b46a 100644
67682--- a/include/linux/genl_magic_func.h
67683+++ b/include/linux/genl_magic_func.h
67684@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
67685 },
67686
67687 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
67688-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
67689+static struct genl_ops ZZZ_genl_ops[] = {
67690 #include GENL_MAGIC_INCLUDE_FILE
67691 };
67692
67693diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67694index 0f615eb..5c3832f 100644
67695--- a/include/linux/gfp.h
67696+++ b/include/linux/gfp.h
67697@@ -35,6 +35,13 @@ struct vm_area_struct;
67698 #define ___GFP_NO_KSWAPD 0x400000u
67699 #define ___GFP_OTHER_NODE 0x800000u
67700 #define ___GFP_WRITE 0x1000000u
67701+
67702+#ifdef CONFIG_PAX_USERCOPY_SLABS
67703+#define ___GFP_USERCOPY 0x2000000u
67704+#else
67705+#define ___GFP_USERCOPY 0
67706+#endif
67707+
67708 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67709
67710 /*
67711@@ -92,6 +99,7 @@ struct vm_area_struct;
67712 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67713 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67714 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67715+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67716
67717 /*
67718 * This may seem redundant, but it's a way of annotating false positives vs.
67719@@ -99,7 +107,7 @@ struct vm_area_struct;
67720 */
67721 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67722
67723-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67724+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67725 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67726
67727 /* This equals 0, but use constants in case they ever change */
67728@@ -153,6 +161,8 @@ struct vm_area_struct;
67729 /* 4GB DMA on some platforms */
67730 #define GFP_DMA32 __GFP_DMA32
67731
67732+#define GFP_USERCOPY __GFP_USERCOPY
67733+
67734 /* Convert GFP flags to their corresponding migrate type */
67735 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67736 {
67737diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67738new file mode 100644
67739index 0000000..ebe6d72
67740--- /dev/null
67741+++ b/include/linux/gracl.h
67742@@ -0,0 +1,319 @@
67743+#ifndef GR_ACL_H
67744+#define GR_ACL_H
67745+
67746+#include <linux/grdefs.h>
67747+#include <linux/resource.h>
67748+#include <linux/capability.h>
67749+#include <linux/dcache.h>
67750+#include <asm/resource.h>
67751+
67752+/* Major status information */
67753+
67754+#define GR_VERSION "grsecurity 2.9.1"
67755+#define GRSECURITY_VERSION 0x2901
67756+
67757+enum {
67758+ GR_SHUTDOWN = 0,
67759+ GR_ENABLE = 1,
67760+ GR_SPROLE = 2,
67761+ GR_RELOAD = 3,
67762+ GR_SEGVMOD = 4,
67763+ GR_STATUS = 5,
67764+ GR_UNSPROLE = 6,
67765+ GR_PASSSET = 7,
67766+ GR_SPROLEPAM = 8,
67767+};
67768+
67769+/* Password setup definitions
67770+ * kernel/grhash.c */
67771+enum {
67772+ GR_PW_LEN = 128,
67773+ GR_SALT_LEN = 16,
67774+ GR_SHA_LEN = 32,
67775+};
67776+
67777+enum {
67778+ GR_SPROLE_LEN = 64,
67779+};
67780+
67781+enum {
67782+ GR_NO_GLOB = 0,
67783+ GR_REG_GLOB,
67784+ GR_CREATE_GLOB
67785+};
67786+
67787+#define GR_NLIMITS 32
67788+
67789+/* Begin Data Structures */
67790+
67791+struct sprole_pw {
67792+ unsigned char *rolename;
67793+ unsigned char salt[GR_SALT_LEN];
67794+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67795+};
67796+
67797+struct name_entry {
67798+ __u32 key;
67799+ ino_t inode;
67800+ dev_t device;
67801+ char *name;
67802+ __u16 len;
67803+ __u8 deleted;
67804+ struct name_entry *prev;
67805+ struct name_entry *next;
67806+};
67807+
67808+struct inodev_entry {
67809+ struct name_entry *nentry;
67810+ struct inodev_entry *prev;
67811+ struct inodev_entry *next;
67812+};
67813+
67814+struct acl_role_db {
67815+ struct acl_role_label **r_hash;
67816+ __u32 r_size;
67817+};
67818+
67819+struct inodev_db {
67820+ struct inodev_entry **i_hash;
67821+ __u32 i_size;
67822+};
67823+
67824+struct name_db {
67825+ struct name_entry **n_hash;
67826+ __u32 n_size;
67827+};
67828+
67829+struct crash_uid {
67830+ uid_t uid;
67831+ unsigned long expires;
67832+};
67833+
67834+struct gr_hash_struct {
67835+ void **table;
67836+ void **nametable;
67837+ void *first;
67838+ __u32 table_size;
67839+ __u32 used_size;
67840+ int type;
67841+};
67842+
67843+/* Userspace Grsecurity ACL data structures */
67844+
67845+struct acl_subject_label {
67846+ char *filename;
67847+ ino_t inode;
67848+ dev_t device;
67849+ __u32 mode;
67850+ kernel_cap_t cap_mask;
67851+ kernel_cap_t cap_lower;
67852+ kernel_cap_t cap_invert_audit;
67853+
67854+ struct rlimit res[GR_NLIMITS];
67855+ __u32 resmask;
67856+
67857+ __u8 user_trans_type;
67858+ __u8 group_trans_type;
67859+ uid_t *user_transitions;
67860+ gid_t *group_transitions;
67861+ __u16 user_trans_num;
67862+ __u16 group_trans_num;
67863+
67864+ __u32 sock_families[2];
67865+ __u32 ip_proto[8];
67866+ __u32 ip_type;
67867+ struct acl_ip_label **ips;
67868+ __u32 ip_num;
67869+ __u32 inaddr_any_override;
67870+
67871+ __u32 crashes;
67872+ unsigned long expires;
67873+
67874+ struct acl_subject_label *parent_subject;
67875+ struct gr_hash_struct *hash;
67876+ struct acl_subject_label *prev;
67877+ struct acl_subject_label *next;
67878+
67879+ struct acl_object_label **obj_hash;
67880+ __u32 obj_hash_size;
67881+ __u16 pax_flags;
67882+};
67883+
67884+struct role_allowed_ip {
67885+ __u32 addr;
67886+ __u32 netmask;
67887+
67888+ struct role_allowed_ip *prev;
67889+ struct role_allowed_ip *next;
67890+};
67891+
67892+struct role_transition {
67893+ char *rolename;
67894+
67895+ struct role_transition *prev;
67896+ struct role_transition *next;
67897+};
67898+
67899+struct acl_role_label {
67900+ char *rolename;
67901+ uid_t uidgid;
67902+ __u16 roletype;
67903+
67904+ __u16 auth_attempts;
67905+ unsigned long expires;
67906+
67907+ struct acl_subject_label *root_label;
67908+ struct gr_hash_struct *hash;
67909+
67910+ struct acl_role_label *prev;
67911+ struct acl_role_label *next;
67912+
67913+ struct role_transition *transitions;
67914+ struct role_allowed_ip *allowed_ips;
67915+ uid_t *domain_children;
67916+ __u16 domain_child_num;
67917+
67918+ umode_t umask;
67919+
67920+ struct acl_subject_label **subj_hash;
67921+ __u32 subj_hash_size;
67922+};
67923+
67924+struct user_acl_role_db {
67925+ struct acl_role_label **r_table;
67926+ __u32 num_pointers; /* Number of allocations to track */
67927+ __u32 num_roles; /* Number of roles */
67928+ __u32 num_domain_children; /* Number of domain children */
67929+ __u32 num_subjects; /* Number of subjects */
67930+ __u32 num_objects; /* Number of objects */
67931+};
67932+
67933+struct acl_object_label {
67934+ char *filename;
67935+ ino_t inode;
67936+ dev_t device;
67937+ __u32 mode;
67938+
67939+ struct acl_subject_label *nested;
67940+ struct acl_object_label *globbed;
67941+
67942+ /* next two structures not used */
67943+
67944+ struct acl_object_label *prev;
67945+ struct acl_object_label *next;
67946+};
67947+
67948+struct acl_ip_label {
67949+ char *iface;
67950+ __u32 addr;
67951+ __u32 netmask;
67952+ __u16 low, high;
67953+ __u8 mode;
67954+ __u32 type;
67955+ __u32 proto[8];
67956+
67957+ /* next two structures not used */
67958+
67959+ struct acl_ip_label *prev;
67960+ struct acl_ip_label *next;
67961+};
67962+
67963+struct gr_arg {
67964+ struct user_acl_role_db role_db;
67965+ unsigned char pw[GR_PW_LEN];
67966+ unsigned char salt[GR_SALT_LEN];
67967+ unsigned char sum[GR_SHA_LEN];
67968+ unsigned char sp_role[GR_SPROLE_LEN];
67969+ struct sprole_pw *sprole_pws;
67970+ dev_t segv_device;
67971+ ino_t segv_inode;
67972+ uid_t segv_uid;
67973+ __u16 num_sprole_pws;
67974+ __u16 mode;
67975+};
67976+
67977+struct gr_arg_wrapper {
67978+ struct gr_arg *arg;
67979+ __u32 version;
67980+ __u32 size;
67981+};
67982+
67983+struct subject_map {
67984+ struct acl_subject_label *user;
67985+ struct acl_subject_label *kernel;
67986+ struct subject_map *prev;
67987+ struct subject_map *next;
67988+};
67989+
67990+struct acl_subj_map_db {
67991+ struct subject_map **s_hash;
67992+ __u32 s_size;
67993+};
67994+
67995+/* End Data Structures Section */
67996+
67997+/* Hash functions generated by empirical testing by Brad Spengler
67998+ Makes good use of the low bits of the inode. Generally 0-1 times
67999+ in loop for successful match. 0-3 for unsuccessful match.
68000+ Shift/add algorithm with modulus of table size and an XOR*/
68001+
68002+static __inline__ unsigned int
68003+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68004+{
68005+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68006+}
68007+
68008+ static __inline__ unsigned int
68009+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68010+{
68011+ return ((const unsigned long)userp % sz);
68012+}
68013+
68014+static __inline__ unsigned int
68015+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68016+{
68017+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68018+}
68019+
68020+static __inline__ unsigned int
68021+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68022+{
68023+ return full_name_hash((const unsigned char *)name, len) % sz;
68024+}
68025+
68026+#define FOR_EACH_ROLE_START(role) \
68027+ role = role_list; \
68028+ while (role) {
68029+
68030+#define FOR_EACH_ROLE_END(role) \
68031+ role = role->prev; \
68032+ }
68033+
68034+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68035+ subj = NULL; \
68036+ iter = 0; \
68037+ while (iter < role->subj_hash_size) { \
68038+ if (subj == NULL) \
68039+ subj = role->subj_hash[iter]; \
68040+ if (subj == NULL) { \
68041+ iter++; \
68042+ continue; \
68043+ }
68044+
68045+#define FOR_EACH_SUBJECT_END(subj,iter) \
68046+ subj = subj->next; \
68047+ if (subj == NULL) \
68048+ iter++; \
68049+ }
68050+
68051+
68052+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
68053+ subj = role->hash->first; \
68054+ while (subj != NULL) {
68055+
68056+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
68057+ subj = subj->next; \
68058+ }
68059+
68060+#endif
68061+
68062diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
68063new file mode 100644
68064index 0000000..323ecf2
68065--- /dev/null
68066+++ b/include/linux/gralloc.h
68067@@ -0,0 +1,9 @@
68068+#ifndef __GRALLOC_H
68069+#define __GRALLOC_H
68070+
68071+void acl_free_all(void);
68072+int acl_alloc_stack_init(unsigned long size);
68073+void *acl_alloc(unsigned long len);
68074+void *acl_alloc_num(unsigned long num, unsigned long len);
68075+
68076+#endif
68077diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
68078new file mode 100644
68079index 0000000..be66033
68080--- /dev/null
68081+++ b/include/linux/grdefs.h
68082@@ -0,0 +1,140 @@
68083+#ifndef GRDEFS_H
68084+#define GRDEFS_H
68085+
68086+/* Begin grsecurity status declarations */
68087+
68088+enum {
68089+ GR_READY = 0x01,
68090+ GR_STATUS_INIT = 0x00 // disabled state
68091+};
68092+
68093+/* Begin ACL declarations */
68094+
68095+/* Role flags */
68096+
68097+enum {
68098+ GR_ROLE_USER = 0x0001,
68099+ GR_ROLE_GROUP = 0x0002,
68100+ GR_ROLE_DEFAULT = 0x0004,
68101+ GR_ROLE_SPECIAL = 0x0008,
68102+ GR_ROLE_AUTH = 0x0010,
68103+ GR_ROLE_NOPW = 0x0020,
68104+ GR_ROLE_GOD = 0x0040,
68105+ GR_ROLE_LEARN = 0x0080,
68106+ GR_ROLE_TPE = 0x0100,
68107+ GR_ROLE_DOMAIN = 0x0200,
68108+ GR_ROLE_PAM = 0x0400,
68109+ GR_ROLE_PERSIST = 0x0800
68110+};
68111+
68112+/* ACL Subject and Object mode flags */
68113+enum {
68114+ GR_DELETED = 0x80000000
68115+};
68116+
68117+/* ACL Object-only mode flags */
68118+enum {
68119+ GR_READ = 0x00000001,
68120+ GR_APPEND = 0x00000002,
68121+ GR_WRITE = 0x00000004,
68122+ GR_EXEC = 0x00000008,
68123+ GR_FIND = 0x00000010,
68124+ GR_INHERIT = 0x00000020,
68125+ GR_SETID = 0x00000040,
68126+ GR_CREATE = 0x00000080,
68127+ GR_DELETE = 0x00000100,
68128+ GR_LINK = 0x00000200,
68129+ GR_AUDIT_READ = 0x00000400,
68130+ GR_AUDIT_APPEND = 0x00000800,
68131+ GR_AUDIT_WRITE = 0x00001000,
68132+ GR_AUDIT_EXEC = 0x00002000,
68133+ GR_AUDIT_FIND = 0x00004000,
68134+ GR_AUDIT_INHERIT= 0x00008000,
68135+ GR_AUDIT_SETID = 0x00010000,
68136+ GR_AUDIT_CREATE = 0x00020000,
68137+ GR_AUDIT_DELETE = 0x00040000,
68138+ GR_AUDIT_LINK = 0x00080000,
68139+ GR_PTRACERD = 0x00100000,
68140+ GR_NOPTRACE = 0x00200000,
68141+ GR_SUPPRESS = 0x00400000,
68142+ GR_NOLEARN = 0x00800000,
68143+ GR_INIT_TRANSFER= 0x01000000
68144+};
68145+
68146+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
68147+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
68148+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
68149+
68150+/* ACL subject-only mode flags */
68151+enum {
68152+ GR_KILL = 0x00000001,
68153+ GR_VIEW = 0x00000002,
68154+ GR_PROTECTED = 0x00000004,
68155+ GR_LEARN = 0x00000008,
68156+ GR_OVERRIDE = 0x00000010,
68157+ /* just a placeholder, this mode is only used in userspace */
68158+ GR_DUMMY = 0x00000020,
68159+ GR_PROTSHM = 0x00000040,
68160+ GR_KILLPROC = 0x00000080,
68161+ GR_KILLIPPROC = 0x00000100,
68162+ /* just a placeholder, this mode is only used in userspace */
68163+ GR_NOTROJAN = 0x00000200,
68164+ GR_PROTPROCFD = 0x00000400,
68165+ GR_PROCACCT = 0x00000800,
68166+ GR_RELAXPTRACE = 0x00001000,
68167+ //GR_NESTED = 0x00002000,
68168+ GR_INHERITLEARN = 0x00004000,
68169+ GR_PROCFIND = 0x00008000,
68170+ GR_POVERRIDE = 0x00010000,
68171+ GR_KERNELAUTH = 0x00020000,
68172+ GR_ATSECURE = 0x00040000,
68173+ GR_SHMEXEC = 0x00080000
68174+};
68175+
68176+enum {
68177+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
68178+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
68179+ GR_PAX_ENABLE_MPROTECT = 0x0004,
68180+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
68181+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
68182+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
68183+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
68184+ GR_PAX_DISABLE_MPROTECT = 0x0400,
68185+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
68186+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
68187+};
68188+
68189+enum {
68190+ GR_ID_USER = 0x01,
68191+ GR_ID_GROUP = 0x02,
68192+};
68193+
68194+enum {
68195+ GR_ID_ALLOW = 0x01,
68196+ GR_ID_DENY = 0x02,
68197+};
68198+
68199+#define GR_CRASH_RES 31
68200+#define GR_UIDTABLE_MAX 500
68201+
68202+/* begin resource learning section */
68203+enum {
68204+ GR_RLIM_CPU_BUMP = 60,
68205+ GR_RLIM_FSIZE_BUMP = 50000,
68206+ GR_RLIM_DATA_BUMP = 10000,
68207+ GR_RLIM_STACK_BUMP = 1000,
68208+ GR_RLIM_CORE_BUMP = 10000,
68209+ GR_RLIM_RSS_BUMP = 500000,
68210+ GR_RLIM_NPROC_BUMP = 1,
68211+ GR_RLIM_NOFILE_BUMP = 5,
68212+ GR_RLIM_MEMLOCK_BUMP = 50000,
68213+ GR_RLIM_AS_BUMP = 500000,
68214+ GR_RLIM_LOCKS_BUMP = 2,
68215+ GR_RLIM_SIGPENDING_BUMP = 5,
68216+ GR_RLIM_MSGQUEUE_BUMP = 10000,
68217+ GR_RLIM_NICE_BUMP = 1,
68218+ GR_RLIM_RTPRIO_BUMP = 1,
68219+ GR_RLIM_RTTIME_BUMP = 1000000
68220+};
68221+
68222+#endif
68223diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
68224new file mode 100644
68225index 0000000..9bb6662
68226--- /dev/null
68227+++ b/include/linux/grinternal.h
68228@@ -0,0 +1,215 @@
68229+#ifndef __GRINTERNAL_H
68230+#define __GRINTERNAL_H
68231+
68232+#ifdef CONFIG_GRKERNSEC
68233+
68234+#include <linux/fs.h>
68235+#include <linux/mnt_namespace.h>
68236+#include <linux/nsproxy.h>
68237+#include <linux/gracl.h>
68238+#include <linux/grdefs.h>
68239+#include <linux/grmsg.h>
68240+
68241+void gr_add_learn_entry(const char *fmt, ...)
68242+ __attribute__ ((format (printf, 1, 2)));
68243+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
68244+ const struct vfsmount *mnt);
68245+__u32 gr_check_create(const struct dentry *new_dentry,
68246+ const struct dentry *parent,
68247+ const struct vfsmount *mnt, const __u32 mode);
68248+int gr_check_protected_task(const struct task_struct *task);
68249+__u32 to_gr_audit(const __u32 reqmode);
68250+int gr_set_acls(const int type);
68251+int gr_apply_subject_to_task(struct task_struct *task);
68252+int gr_acl_is_enabled(void);
68253+char gr_roletype_to_char(void);
68254+
68255+void gr_handle_alertkill(struct task_struct *task);
68256+char *gr_to_filename(const struct dentry *dentry,
68257+ const struct vfsmount *mnt);
68258+char *gr_to_filename1(const struct dentry *dentry,
68259+ const struct vfsmount *mnt);
68260+char *gr_to_filename2(const struct dentry *dentry,
68261+ const struct vfsmount *mnt);
68262+char *gr_to_filename3(const struct dentry *dentry,
68263+ const struct vfsmount *mnt);
68264+
68265+extern int grsec_enable_ptrace_readexec;
68266+extern int grsec_enable_harden_ptrace;
68267+extern int grsec_enable_link;
68268+extern int grsec_enable_fifo;
68269+extern int grsec_enable_execve;
68270+extern int grsec_enable_shm;
68271+extern int grsec_enable_execlog;
68272+extern int grsec_enable_signal;
68273+extern int grsec_enable_audit_ptrace;
68274+extern int grsec_enable_forkfail;
68275+extern int grsec_enable_time;
68276+extern int grsec_enable_rofs;
68277+extern int grsec_enable_chroot_shmat;
68278+extern int grsec_enable_chroot_mount;
68279+extern int grsec_enable_chroot_double;
68280+extern int grsec_enable_chroot_pivot;
68281+extern int grsec_enable_chroot_chdir;
68282+extern int grsec_enable_chroot_chmod;
68283+extern int grsec_enable_chroot_mknod;
68284+extern int grsec_enable_chroot_fchdir;
68285+extern int grsec_enable_chroot_nice;
68286+extern int grsec_enable_chroot_execlog;
68287+extern int grsec_enable_chroot_caps;
68288+extern int grsec_enable_chroot_sysctl;
68289+extern int grsec_enable_chroot_unix;
68290+extern int grsec_enable_symlinkown;
68291+extern kgid_t grsec_symlinkown_gid;
68292+extern int grsec_enable_tpe;
68293+extern kgid_t grsec_tpe_gid;
68294+extern int grsec_enable_tpe_all;
68295+extern int grsec_enable_tpe_invert;
68296+extern int grsec_enable_socket_all;
68297+extern kgid_t grsec_socket_all_gid;
68298+extern int grsec_enable_socket_client;
68299+extern kgid_t grsec_socket_client_gid;
68300+extern int grsec_enable_socket_server;
68301+extern kgid_t grsec_socket_server_gid;
68302+extern kgid_t grsec_audit_gid;
68303+extern int grsec_enable_group;
68304+extern int grsec_enable_audit_textrel;
68305+extern int grsec_enable_log_rwxmaps;
68306+extern int grsec_enable_mount;
68307+extern int grsec_enable_chdir;
68308+extern int grsec_resource_logging;
68309+extern int grsec_enable_blackhole;
68310+extern int grsec_lastack_retries;
68311+extern int grsec_enable_brute;
68312+extern int grsec_lock;
68313+
68314+extern spinlock_t grsec_alert_lock;
68315+extern unsigned long grsec_alert_wtime;
68316+extern unsigned long grsec_alert_fyet;
68317+
68318+extern spinlock_t grsec_audit_lock;
68319+
68320+extern rwlock_t grsec_exec_file_lock;
68321+
68322+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
68323+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
68324+ (tsk)->exec_file->f_vfsmnt) : "/")
68325+
68326+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
68327+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
68328+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68329+
68330+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
68331+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
68332+ (tsk)->exec_file->f_vfsmnt) : "/")
68333+
68334+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
68335+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
68336+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68337+
68338+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
68339+
68340+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
68341+
68342+#define GR_CHROOT_CAPS {{ \
68343+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
68344+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
68345+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
68346+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
68347+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
68348+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
68349+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
68350+
68351+#define security_learn(normal_msg,args...) \
68352+({ \
68353+ read_lock(&grsec_exec_file_lock); \
68354+ gr_add_learn_entry(normal_msg "\n", ## args); \
68355+ read_unlock(&grsec_exec_file_lock); \
68356+})
68357+
68358+enum {
68359+ GR_DO_AUDIT,
68360+ GR_DONT_AUDIT,
68361+ /* used for non-audit messages that we shouldn't kill the task on */
68362+ GR_DONT_AUDIT_GOOD
68363+};
68364+
68365+enum {
68366+ GR_TTYSNIFF,
68367+ GR_RBAC,
68368+ GR_RBAC_STR,
68369+ GR_STR_RBAC,
68370+ GR_RBAC_MODE2,
68371+ GR_RBAC_MODE3,
68372+ GR_FILENAME,
68373+ GR_SYSCTL_HIDDEN,
68374+ GR_NOARGS,
68375+ GR_ONE_INT,
68376+ GR_ONE_INT_TWO_STR,
68377+ GR_ONE_STR,
68378+ GR_STR_INT,
68379+ GR_TWO_STR_INT,
68380+ GR_TWO_INT,
68381+ GR_TWO_U64,
68382+ GR_THREE_INT,
68383+ GR_FIVE_INT_TWO_STR,
68384+ GR_TWO_STR,
68385+ GR_THREE_STR,
68386+ GR_FOUR_STR,
68387+ GR_STR_FILENAME,
68388+ GR_FILENAME_STR,
68389+ GR_FILENAME_TWO_INT,
68390+ GR_FILENAME_TWO_INT_STR,
68391+ GR_TEXTREL,
68392+ GR_PTRACE,
68393+ GR_RESOURCE,
68394+ GR_CAP,
68395+ GR_SIG,
68396+ GR_SIG2,
68397+ GR_CRASH1,
68398+ GR_CRASH2,
68399+ GR_PSACCT,
68400+ GR_RWXMAP
68401+};
68402+
68403+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
68404+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
68405+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
68406+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
68407+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
68408+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
68409+#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)
68410+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
68411+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
68412+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
68413+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
68414+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
68415+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
68416+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
68417+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
68418+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
68419+#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)
68420+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
68421+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
68422+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
68423+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
68424+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
68425+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
68426+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
68427+#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)
68428+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
68429+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
68430+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
68431+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
68432+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
68433+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
68434+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
68435+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
68436+#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)
68437+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
68438+
68439+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
68440+
68441+#endif
68442+
68443+#endif
68444diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
68445new file mode 100644
68446index 0000000..2bd4c8d
68447--- /dev/null
68448+++ b/include/linux/grmsg.h
68449@@ -0,0 +1,111 @@
68450+#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"
68451+#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"
68452+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
68453+#define GR_STOPMOD_MSG "denied modification of module state by "
68454+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
68455+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
68456+#define GR_IOPERM_MSG "denied use of ioperm() by "
68457+#define GR_IOPL_MSG "denied use of iopl() by "
68458+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
68459+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
68460+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
68461+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
68462+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
68463+#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"
68464+#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"
68465+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
68466+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
68467+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
68468+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
68469+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
68470+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
68471+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
68472+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
68473+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
68474+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
68475+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
68476+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
68477+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
68478+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
68479+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
68480+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
68481+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
68482+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
68483+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
68484+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
68485+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
68486+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
68487+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
68488+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
68489+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
68490+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
68491+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
68492+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
68493+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
68494+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
68495+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
68496+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
68497+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
68498+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
68499+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
68500+#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"
68501+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
68502+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
68503+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
68504+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
68505+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
68506+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
68507+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
68508+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
68509+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
68510+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
68511+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
68512+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
68513+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
68514+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
68515+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
68516+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
68517+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
68518+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
68519+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
68520+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
68521+#define GR_FAILFORK_MSG "failed fork with errno %s by "
68522+#define GR_NICE_CHROOT_MSG "denied priority change by "
68523+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
68524+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
68525+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
68526+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
68527+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
68528+#define GR_TIME_MSG "time set by "
68529+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
68530+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
68531+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
68532+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
68533+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
68534+#define GR_BIND_MSG "denied bind() by "
68535+#define GR_CONNECT_MSG "denied connect() by "
68536+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
68537+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
68538+#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"
68539+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
68540+#define GR_CAP_ACL_MSG "use of %s denied for "
68541+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
68542+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
68543+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
68544+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
68545+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
68546+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
68547+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
68548+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
68549+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
68550+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
68551+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
68552+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
68553+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
68554+#define GR_VM86_MSG "denied use of vm86 by "
68555+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
68556+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
68557+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
68558+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
68559+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
68560+#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 "
68561diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
68562new file mode 100644
68563index 0000000..8da63a4
68564--- /dev/null
68565+++ b/include/linux/grsecurity.h
68566@@ -0,0 +1,242 @@
68567+#ifndef GR_SECURITY_H
68568+#define GR_SECURITY_H
68569+#include <linux/fs.h>
68570+#include <linux/fs_struct.h>
68571+#include <linux/binfmts.h>
68572+#include <linux/gracl.h>
68573+
68574+/* notify of brain-dead configs */
68575+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68576+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
68577+#endif
68578+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
68579+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
68580+#endif
68581+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
68582+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
68583+#endif
68584+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
68585+#error "CONFIG_PAX enabled, but no PaX options are enabled."
68586+#endif
68587+
68588+void gr_handle_brute_attach(unsigned long mm_flags);
68589+void gr_handle_brute_check(void);
68590+void gr_handle_kernel_exploit(void);
68591+int gr_process_user_ban(void);
68592+
68593+char gr_roletype_to_char(void);
68594+
68595+int gr_acl_enable_at_secure(void);
68596+
68597+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
68598+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
68599+
68600+void gr_del_task_from_ip_table(struct task_struct *p);
68601+
68602+int gr_pid_is_chrooted(struct task_struct *p);
68603+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
68604+int gr_handle_chroot_nice(void);
68605+int gr_handle_chroot_sysctl(const int op);
68606+int gr_handle_chroot_setpriority(struct task_struct *p,
68607+ const int niceval);
68608+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
68609+int gr_handle_chroot_chroot(const struct dentry *dentry,
68610+ const struct vfsmount *mnt);
68611+void gr_handle_chroot_chdir(struct path *path);
68612+int gr_handle_chroot_chmod(const struct dentry *dentry,
68613+ const struct vfsmount *mnt, const int mode);
68614+int gr_handle_chroot_mknod(const struct dentry *dentry,
68615+ const struct vfsmount *mnt, const int mode);
68616+int gr_handle_chroot_mount(const struct dentry *dentry,
68617+ const struct vfsmount *mnt,
68618+ const char *dev_name);
68619+int gr_handle_chroot_pivot(void);
68620+int gr_handle_chroot_unix(const pid_t pid);
68621+
68622+int gr_handle_rawio(const struct inode *inode);
68623+
68624+void gr_handle_ioperm(void);
68625+void gr_handle_iopl(void);
68626+
68627+umode_t gr_acl_umask(void);
68628+
68629+int gr_tpe_allow(const struct file *file);
68630+
68631+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
68632+void gr_clear_chroot_entries(struct task_struct *task);
68633+
68634+void gr_log_forkfail(const int retval);
68635+void gr_log_timechange(void);
68636+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
68637+void gr_log_chdir(const struct dentry *dentry,
68638+ const struct vfsmount *mnt);
68639+void gr_log_chroot_exec(const struct dentry *dentry,
68640+ const struct vfsmount *mnt);
68641+void gr_log_remount(const char *devname, const int retval);
68642+void gr_log_unmount(const char *devname, const int retval);
68643+void gr_log_mount(const char *from, const char *to, const int retval);
68644+void gr_log_textrel(struct vm_area_struct *vma);
68645+void gr_log_rwxmmap(struct file *file);
68646+void gr_log_rwxmprotect(struct file *file);
68647+
68648+int gr_handle_follow_link(const struct inode *parent,
68649+ const struct inode *inode,
68650+ const struct dentry *dentry,
68651+ const struct vfsmount *mnt);
68652+int gr_handle_fifo(const struct dentry *dentry,
68653+ const struct vfsmount *mnt,
68654+ const struct dentry *dir, const int flag,
68655+ const int acc_mode);
68656+int gr_handle_hardlink(const struct dentry *dentry,
68657+ const struct vfsmount *mnt,
68658+ struct inode *inode,
68659+ const int mode, const struct filename *to);
68660+
68661+int gr_is_capable(const int cap);
68662+int gr_is_capable_nolog(const int cap);
68663+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68664+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
68665+
68666+void gr_copy_label(struct task_struct *tsk);
68667+void gr_handle_crash(struct task_struct *task, const int sig);
68668+int gr_handle_signal(const struct task_struct *p, const int sig);
68669+int gr_check_crash_uid(const kuid_t uid);
68670+int gr_check_protected_task(const struct task_struct *task);
68671+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
68672+int gr_acl_handle_mmap(const struct file *file,
68673+ const unsigned long prot);
68674+int gr_acl_handle_mprotect(const struct file *file,
68675+ const unsigned long prot);
68676+int gr_check_hidden_task(const struct task_struct *tsk);
68677+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68678+ const struct vfsmount *mnt);
68679+__u32 gr_acl_handle_utime(const struct dentry *dentry,
68680+ const struct vfsmount *mnt);
68681+__u32 gr_acl_handle_access(const struct dentry *dentry,
68682+ const struct vfsmount *mnt, const int fmode);
68683+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68684+ const struct vfsmount *mnt, umode_t *mode);
68685+__u32 gr_acl_handle_chown(const struct dentry *dentry,
68686+ const struct vfsmount *mnt);
68687+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68688+ const struct vfsmount *mnt);
68689+int gr_handle_ptrace(struct task_struct *task, const long request);
68690+int gr_handle_proc_ptrace(struct task_struct *task);
68691+__u32 gr_acl_handle_execve(const struct dentry *dentry,
68692+ const struct vfsmount *mnt);
68693+int gr_check_crash_exec(const struct file *filp);
68694+int gr_acl_is_enabled(void);
68695+void gr_set_kernel_label(struct task_struct *task);
68696+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68697+ const kgid_t gid);
68698+int gr_set_proc_label(const struct dentry *dentry,
68699+ const struct vfsmount *mnt,
68700+ const int unsafe_flags);
68701+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68702+ const struct vfsmount *mnt);
68703+__u32 gr_acl_handle_open(const struct dentry *dentry,
68704+ const struct vfsmount *mnt, int acc_mode);
68705+__u32 gr_acl_handle_creat(const struct dentry *dentry,
68706+ const struct dentry *p_dentry,
68707+ const struct vfsmount *p_mnt,
68708+ int open_flags, int acc_mode, const int imode);
68709+void gr_handle_create(const struct dentry *dentry,
68710+ const struct vfsmount *mnt);
68711+void gr_handle_proc_create(const struct dentry *dentry,
68712+ const struct inode *inode);
68713+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68714+ const struct dentry *parent_dentry,
68715+ const struct vfsmount *parent_mnt,
68716+ const int mode);
68717+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68718+ const struct dentry *parent_dentry,
68719+ const struct vfsmount *parent_mnt);
68720+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68721+ const struct vfsmount *mnt);
68722+void gr_handle_delete(const ino_t ino, const dev_t dev);
68723+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68724+ const struct vfsmount *mnt);
68725+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68726+ const struct dentry *parent_dentry,
68727+ const struct vfsmount *parent_mnt,
68728+ const struct filename *from);
68729+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68730+ const struct dentry *parent_dentry,
68731+ const struct vfsmount *parent_mnt,
68732+ const struct dentry *old_dentry,
68733+ const struct vfsmount *old_mnt, const struct filename *to);
68734+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68735+int gr_acl_handle_rename(struct dentry *new_dentry,
68736+ struct dentry *parent_dentry,
68737+ const struct vfsmount *parent_mnt,
68738+ struct dentry *old_dentry,
68739+ struct inode *old_parent_inode,
68740+ struct vfsmount *old_mnt, const struct filename *newname);
68741+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68742+ struct dentry *old_dentry,
68743+ struct dentry *new_dentry,
68744+ struct vfsmount *mnt, const __u8 replace);
68745+__u32 gr_check_link(const struct dentry *new_dentry,
68746+ const struct dentry *parent_dentry,
68747+ const struct vfsmount *parent_mnt,
68748+ const struct dentry *old_dentry,
68749+ const struct vfsmount *old_mnt);
68750+int gr_acl_handle_filldir(const struct file *file, const char *name,
68751+ const unsigned int namelen, const ino_t ino);
68752+
68753+__u32 gr_acl_handle_unix(const struct dentry *dentry,
68754+ const struct vfsmount *mnt);
68755+void gr_acl_handle_exit(void);
68756+void gr_acl_handle_psacct(struct task_struct *task, const long code);
68757+int gr_acl_handle_procpidmem(const struct task_struct *task);
68758+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68759+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68760+void gr_audit_ptrace(struct task_struct *task);
68761+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68762+void gr_put_exec_file(struct task_struct *task);
68763+
68764+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68765+
68766+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68767+extern void gr_learn_resource(const struct task_struct *task, const int res,
68768+ const unsigned long wanted, const int gt);
68769+#else
68770+static inline void gr_learn_resource(const struct task_struct *task, const int res,
68771+ const unsigned long wanted, const int gt)
68772+{
68773+}
68774+#endif
68775+
68776+#ifdef CONFIG_GRKERNSEC_RESLOG
68777+extern void gr_log_resource(const struct task_struct *task, const int res,
68778+ const unsigned long wanted, const int gt);
68779+#else
68780+static inline void gr_log_resource(const struct task_struct *task, const int res,
68781+ const unsigned long wanted, const int gt)
68782+{
68783+}
68784+#endif
68785+
68786+#ifdef CONFIG_GRKERNSEC
68787+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68788+void gr_handle_vm86(void);
68789+void gr_handle_mem_readwrite(u64 from, u64 to);
68790+
68791+void gr_log_badprocpid(const char *entry);
68792+
68793+extern int grsec_enable_dmesg;
68794+extern int grsec_disable_privio;
68795+
68796+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68797+extern kgid_t grsec_proc_gid;
68798+#endif
68799+
68800+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68801+extern int grsec_enable_chroot_findtask;
68802+#endif
68803+#ifdef CONFIG_GRKERNSEC_SETXID
68804+extern int grsec_enable_setxid;
68805+#endif
68806+#endif
68807+
68808+#endif
68809diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68810new file mode 100644
68811index 0000000..e7ffaaf
68812--- /dev/null
68813+++ b/include/linux/grsock.h
68814@@ -0,0 +1,19 @@
68815+#ifndef __GRSOCK_H
68816+#define __GRSOCK_H
68817+
68818+extern void gr_attach_curr_ip(const struct sock *sk);
68819+extern int gr_handle_sock_all(const int family, const int type,
68820+ const int protocol);
68821+extern int gr_handle_sock_server(const struct sockaddr *sck);
68822+extern int gr_handle_sock_server_other(const struct sock *sck);
68823+extern int gr_handle_sock_client(const struct sockaddr *sck);
68824+extern int gr_search_connect(struct socket * sock,
68825+ struct sockaddr_in * addr);
68826+extern int gr_search_bind(struct socket * sock,
68827+ struct sockaddr_in * addr);
68828+extern int gr_search_listen(struct socket * sock);
68829+extern int gr_search_accept(struct socket * sock);
68830+extern int gr_search_socket(const int domain, const int type,
68831+ const int protocol);
68832+
68833+#endif
68834diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68835index ef788b5..ac41b7b 100644
68836--- a/include/linux/highmem.h
68837+++ b/include/linux/highmem.h
68838@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68839 kunmap_atomic(kaddr);
68840 }
68841
68842+static inline void sanitize_highpage(struct page *page)
68843+{
68844+ void *kaddr;
68845+ unsigned long flags;
68846+
68847+ local_irq_save(flags);
68848+ kaddr = kmap_atomic(page);
68849+ clear_page(kaddr);
68850+ kunmap_atomic(kaddr);
68851+ local_irq_restore(flags);
68852+}
68853+
68854 static inline void zero_user_segments(struct page *page,
68855 unsigned start1, unsigned end1,
68856 unsigned start2, unsigned end2)
68857diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68858index 1c7b89a..7f52502 100644
68859--- a/include/linux/hwmon-sysfs.h
68860+++ b/include/linux/hwmon-sysfs.h
68861@@ -25,7 +25,8 @@
68862 struct sensor_device_attribute{
68863 struct device_attribute dev_attr;
68864 int index;
68865-};
68866+} __do_const;
68867+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68868 #define to_sensor_dev_attr(_dev_attr) \
68869 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68870
68871@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68872 struct device_attribute dev_attr;
68873 u8 index;
68874 u8 nr;
68875-};
68876+} __do_const;
68877 #define to_sensor_dev_attr_2(_dev_attr) \
68878 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68879
68880diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68881index d0c4db7..61b3577 100644
68882--- a/include/linux/i2c.h
68883+++ b/include/linux/i2c.h
68884@@ -369,6 +369,7 @@ struct i2c_algorithm {
68885 /* To determine what the adapter supports */
68886 u32 (*functionality) (struct i2c_adapter *);
68887 };
68888+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68889
68890 /*
68891 * i2c_adapter is the structure used to identify a physical i2c bus along
68892diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68893index d23c3c2..eb63c81 100644
68894--- a/include/linux/i2o.h
68895+++ b/include/linux/i2o.h
68896@@ -565,7 +565,7 @@ struct i2o_controller {
68897 struct i2o_device *exec; /* Executive */
68898 #if BITS_PER_LONG == 64
68899 spinlock_t context_list_lock; /* lock for context_list */
68900- atomic_t context_list_counter; /* needed for unique contexts */
68901+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68902 struct list_head context_list; /* list of context id's
68903 and pointers */
68904 #endif
68905diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68906index aff7ad8..3942bbd 100644
68907--- a/include/linux/if_pppox.h
68908+++ b/include/linux/if_pppox.h
68909@@ -76,7 +76,7 @@ struct pppox_proto {
68910 int (*ioctl)(struct socket *sock, unsigned int cmd,
68911 unsigned long arg);
68912 struct module *owner;
68913-};
68914+} __do_const;
68915
68916 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68917 extern void unregister_pppox_proto(int proto_num);
68918diff --git a/include/linux/init.h b/include/linux/init.h
68919index 10ed4f4..8e8490d 100644
68920--- a/include/linux/init.h
68921+++ b/include/linux/init.h
68922@@ -39,9 +39,36 @@
68923 * Also note, that this data cannot be "const".
68924 */
68925
68926+#ifdef MODULE
68927+#define add_init_latent_entropy
68928+#define add_devinit_latent_entropy
68929+#define add_cpuinit_latent_entropy
68930+#define add_meminit_latent_entropy
68931+#else
68932+#define add_init_latent_entropy __latent_entropy
68933+
68934+#ifdef CONFIG_HOTPLUG
68935+#define add_devinit_latent_entropy
68936+#else
68937+#define add_devinit_latent_entropy __latent_entropy
68938+#endif
68939+
68940+#ifdef CONFIG_HOTPLUG_CPU
68941+#define add_cpuinit_latent_entropy
68942+#else
68943+#define add_cpuinit_latent_entropy __latent_entropy
68944+#endif
68945+
68946+#ifdef CONFIG_MEMORY_HOTPLUG
68947+#define add_meminit_latent_entropy
68948+#else
68949+#define add_meminit_latent_entropy __latent_entropy
68950+#endif
68951+#endif
68952+
68953 /* These are for everybody (although not all archs will actually
68954 discard it in modules) */
68955-#define __init __section(.init.text) __cold notrace
68956+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68957 #define __initdata __section(.init.data)
68958 #define __initconst __constsection(.init.rodata)
68959 #define __exitdata __section(.exit.data)
68960@@ -94,7 +121,7 @@
68961 #define __exit __section(.exit.text) __exitused __cold notrace
68962
68963 /* Used for HOTPLUG_CPU */
68964-#define __cpuinit __section(.cpuinit.text) __cold notrace
68965+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68966 #define __cpuinitdata __section(.cpuinit.data)
68967 #define __cpuinitconst __constsection(.cpuinit.rodata)
68968 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68969@@ -102,7 +129,7 @@
68970 #define __cpuexitconst __constsection(.cpuexit.rodata)
68971
68972 /* Used for MEMORY_HOTPLUG */
68973-#define __meminit __section(.meminit.text) __cold notrace
68974+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68975 #define __meminitdata __section(.meminit.data)
68976 #define __meminitconst __constsection(.meminit.rodata)
68977 #define __memexit __section(.memexit.text) __exitused __cold notrace
68978diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68979index 6d087c5..401cab8 100644
68980--- a/include/linux/init_task.h
68981+++ b/include/linux/init_task.h
68982@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68983
68984 #define INIT_TASK_COMM "swapper"
68985
68986+#ifdef CONFIG_X86
68987+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68988+#else
68989+#define INIT_TASK_THREAD_INFO
68990+#endif
68991+
68992 /*
68993 * INIT_TASK is used to set up the first task table, touch at
68994 * your own risk!. Base=0, limit=0x1fffff (=2MB)
68995@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
68996 RCU_POINTER_INITIALIZER(cred, &init_cred), \
68997 .comm = INIT_TASK_COMM, \
68998 .thread = INIT_THREAD, \
68999+ INIT_TASK_THREAD_INFO \
69000 .fs = &init_fs, \
69001 .files = &init_files, \
69002 .signal = &init_signals, \
69003diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69004index 5fa5afe..ac55b25 100644
69005--- a/include/linux/interrupt.h
69006+++ b/include/linux/interrupt.h
69007@@ -430,7 +430,7 @@ enum
69008 /* map softirq index to softirq name. update 'softirq_to_name' in
69009 * kernel/softirq.c when adding a new softirq.
69010 */
69011-extern char *softirq_to_name[NR_SOFTIRQS];
69012+extern const char * const softirq_to_name[NR_SOFTIRQS];
69013
69014 /* softirq mask and active fields moved to irq_cpustat_t in
69015 * asm/hardirq.h to get better cache usage. KAO
69016@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69017
69018 struct softirq_action
69019 {
69020- void (*action)(struct softirq_action *);
69021-};
69022+ void (*action)(void);
69023+} __no_const;
69024
69025 asmlinkage void do_softirq(void);
69026 asmlinkage void __do_softirq(void);
69027-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69028+extern void open_softirq(int nr, void (*action)(void));
69029 extern void softirq_init(void);
69030 extern void __raise_softirq_irqoff(unsigned int nr);
69031
69032diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69033index f3b99e1..9b73cee 100644
69034--- a/include/linux/iommu.h
69035+++ b/include/linux/iommu.h
69036@@ -101,7 +101,7 @@ struct iommu_ops {
69037 int (*domain_set_attr)(struct iommu_domain *domain,
69038 enum iommu_attr attr, void *data);
69039 unsigned long pgsize_bitmap;
69040-};
69041+} __do_const;
69042
69043 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
69044 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
69045diff --git a/include/linux/irq.h b/include/linux/irq.h
69046index fdf2c4a..5332486 100644
69047--- a/include/linux/irq.h
69048+++ b/include/linux/irq.h
69049@@ -328,7 +328,8 @@ struct irq_chip {
69050 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
69051
69052 unsigned long flags;
69053-};
69054+} __do_const;
69055+typedef struct irq_chip __no_const irq_chip_no_const;
69056
69057 /*
69058 * irq_chip specific flags
69059diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
69060index 6883e19..06992b1 100644
69061--- a/include/linux/kallsyms.h
69062+++ b/include/linux/kallsyms.h
69063@@ -15,7 +15,8 @@
69064
69065 struct module;
69066
69067-#ifdef CONFIG_KALLSYMS
69068+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
69069+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69070 /* Lookup the address for a symbol. Returns 0 if not found. */
69071 unsigned long kallsyms_lookup_name(const char *name);
69072
69073@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
69074 /* Stupid that this does nothing, but I didn't create this mess. */
69075 #define __print_symbol(fmt, addr)
69076 #endif /*CONFIG_KALLSYMS*/
69077+#else /* when included by kallsyms.c, vsnprintf.c, or
69078+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
69079+extern void __print_symbol(const char *fmt, unsigned long address);
69080+extern int sprint_backtrace(char *buffer, unsigned long address);
69081+extern int sprint_symbol(char *buffer, unsigned long address);
69082+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
69083+const char *kallsyms_lookup(unsigned long addr,
69084+ unsigned long *symbolsize,
69085+ unsigned long *offset,
69086+ char **modname, char *namebuf);
69087+#endif
69088
69089 /* This macro allows us to keep printk typechecking */
69090 static __printf(1, 2)
69091diff --git a/include/linux/key-type.h b/include/linux/key-type.h
69092index 518a53a..5e28358 100644
69093--- a/include/linux/key-type.h
69094+++ b/include/linux/key-type.h
69095@@ -125,7 +125,7 @@ struct key_type {
69096 /* internal fields */
69097 struct list_head link; /* link in types list */
69098 struct lock_class_key lock_class; /* key->sem lock class */
69099-};
69100+} __do_const;
69101
69102 extern struct key_type key_type_keyring;
69103
69104diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
69105index 4dff0c6..1ca9b72 100644
69106--- a/include/linux/kgdb.h
69107+++ b/include/linux/kgdb.h
69108@@ -53,7 +53,7 @@ extern int kgdb_connected;
69109 extern int kgdb_io_module_registered;
69110
69111 extern atomic_t kgdb_setting_breakpoint;
69112-extern atomic_t kgdb_cpu_doing_single_step;
69113+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
69114
69115 extern struct task_struct *kgdb_usethread;
69116 extern struct task_struct *kgdb_contthread;
69117@@ -255,7 +255,7 @@ struct kgdb_arch {
69118 void (*correct_hw_break)(void);
69119
69120 void (*enable_nmi)(bool on);
69121-};
69122+} __do_const;
69123
69124 /**
69125 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
69126@@ -280,7 +280,7 @@ struct kgdb_io {
69127 void (*pre_exception) (void);
69128 void (*post_exception) (void);
69129 int is_console;
69130-};
69131+} __do_const;
69132
69133 extern struct kgdb_arch arch_kgdb_ops;
69134
69135diff --git a/include/linux/kmod.h b/include/linux/kmod.h
69136index 5398d58..5883a34 100644
69137--- a/include/linux/kmod.h
69138+++ b/include/linux/kmod.h
69139@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
69140 * usually useless though. */
69141 extern __printf(2, 3)
69142 int __request_module(bool wait, const char *name, ...);
69143+extern __printf(3, 4)
69144+int ___request_module(bool wait, char *param_name, const char *name, ...);
69145 #define request_module(mod...) __request_module(true, mod)
69146 #define request_module_nowait(mod...) __request_module(false, mod)
69147 #define try_then_request_module(x, mod...) \
69148diff --git a/include/linux/kobject.h b/include/linux/kobject.h
69149index 939b112..ed6ed51 100644
69150--- a/include/linux/kobject.h
69151+++ b/include/linux/kobject.h
69152@@ -111,7 +111,7 @@ struct kobj_type {
69153 struct attribute **default_attrs;
69154 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
69155 const void *(*namespace)(struct kobject *kobj);
69156-};
69157+} __do_const;
69158
69159 struct kobj_uevent_env {
69160 char *envp[UEVENT_NUM_ENVP];
69161@@ -134,6 +134,7 @@ struct kobj_attribute {
69162 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
69163 const char *buf, size_t count);
69164 };
69165+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
69166
69167 extern const struct sysfs_ops kobj_sysfs_ops;
69168
69169diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
69170index f66b065..c2c29b4 100644
69171--- a/include/linux/kobject_ns.h
69172+++ b/include/linux/kobject_ns.h
69173@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
69174 const void *(*netlink_ns)(struct sock *sk);
69175 const void *(*initial_ns)(void);
69176 void (*drop_ns)(void *);
69177-};
69178+} __do_const;
69179
69180 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
69181 int kobj_ns_type_registered(enum kobj_ns_type type);
69182diff --git a/include/linux/kref.h b/include/linux/kref.h
69183index 4972e6e..de4d19b 100644
69184--- a/include/linux/kref.h
69185+++ b/include/linux/kref.h
69186@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
69187 static inline int kref_sub(struct kref *kref, unsigned int count,
69188 void (*release)(struct kref *kref))
69189 {
69190- WARN_ON(release == NULL);
69191+ BUG_ON(release == NULL);
69192
69193 if (atomic_sub_and_test((int) count, &kref->refcount)) {
69194 release(kref);
69195diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
69196index 2c497ab..afe32f5 100644
69197--- a/include/linux/kvm_host.h
69198+++ b/include/linux/kvm_host.h
69199@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
69200 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
69201 void vcpu_put(struct kvm_vcpu *vcpu);
69202
69203-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69204+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69205 struct module *module);
69206 void kvm_exit(void);
69207
69208@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
69209 struct kvm_guest_debug *dbg);
69210 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
69211
69212-int kvm_arch_init(void *opaque);
69213+int kvm_arch_init(const void *opaque);
69214 void kvm_arch_exit(void);
69215
69216 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
69217diff --git a/include/linux/libata.h b/include/linux/libata.h
69218index 649e5f8..ead5194 100644
69219--- a/include/linux/libata.h
69220+++ b/include/linux/libata.h
69221@@ -915,7 +915,7 @@ struct ata_port_operations {
69222 * fields must be pointers.
69223 */
69224 const struct ata_port_operations *inherits;
69225-};
69226+} __do_const;
69227
69228 struct ata_port_info {
69229 unsigned long flags;
69230diff --git a/include/linux/list.h b/include/linux/list.h
69231index cc6d2aa..c10ee83 100644
69232--- a/include/linux/list.h
69233+++ b/include/linux/list.h
69234@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
69235 extern void list_del(struct list_head *entry);
69236 #endif
69237
69238+extern void __pax_list_add(struct list_head *new,
69239+ struct list_head *prev,
69240+ struct list_head *next);
69241+static inline void pax_list_add(struct list_head *new, struct list_head *head)
69242+{
69243+ __pax_list_add(new, head, head->next);
69244+}
69245+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
69246+{
69247+ __pax_list_add(new, head->prev, head);
69248+}
69249+extern void pax_list_del(struct list_head *entry);
69250+
69251 /**
69252 * list_replace - replace old entry by new one
69253 * @old : the element to be replaced
69254@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
69255 INIT_LIST_HEAD(entry);
69256 }
69257
69258+extern void pax_list_del_init(struct list_head *entry);
69259+
69260 /**
69261 * list_move - delete from one list and add as another's head
69262 * @list: the entry to move
69263diff --git a/include/linux/math64.h b/include/linux/math64.h
69264index b8ba855..0148090 100644
69265--- a/include/linux/math64.h
69266+++ b/include/linux/math64.h
69267@@ -14,7 +14,7 @@
69268 * This is commonly provided by 32bit archs to provide an optimized 64bit
69269 * divide.
69270 */
69271-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69272+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69273 {
69274 *remainder = dividend % divisor;
69275 return dividend / divisor;
69276@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
69277 #define div64_long(x,y) div_s64((x),(y))
69278
69279 #ifndef div_u64_rem
69280-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69281+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69282 {
69283 *remainder = do_div(dividend, divisor);
69284 return dividend;
69285@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
69286 * divide.
69287 */
69288 #ifndef div_u64
69289-static inline u64 div_u64(u64 dividend, u32 divisor)
69290+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
69291 {
69292 u32 remainder;
69293 return div_u64_rem(dividend, divisor, &remainder);
69294diff --git a/include/linux/mm.h b/include/linux/mm.h
69295index 66e2f7c..ea88001 100644
69296--- a/include/linux/mm.h
69297+++ b/include/linux/mm.h
69298@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
69299 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
69300 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
69301 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
69302+
69303+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69304+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
69305+#endif
69306+
69307 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
69308
69309 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
69310@@ -231,6 +236,7 @@ struct vm_operations_struct {
69311 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
69312 unsigned long size, pgoff_t pgoff);
69313 };
69314+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
69315
69316 struct mmu_gather;
69317 struct inode;
69318@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
69319 int set_page_dirty_lock(struct page *page);
69320 int clear_page_dirty_for_io(struct page *page);
69321
69322-/* Is the vma a continuation of the stack vma above it? */
69323-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
69324-{
69325- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
69326-}
69327-
69328-static inline int stack_guard_page_start(struct vm_area_struct *vma,
69329- unsigned long addr)
69330-{
69331- return (vma->vm_flags & VM_GROWSDOWN) &&
69332- (vma->vm_start == addr) &&
69333- !vma_growsdown(vma->vm_prev, addr);
69334-}
69335-
69336-/* Is the vma a continuation of the stack vma below it? */
69337-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
69338-{
69339- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
69340-}
69341-
69342-static inline int stack_guard_page_end(struct vm_area_struct *vma,
69343- unsigned long addr)
69344-{
69345- return (vma->vm_flags & VM_GROWSUP) &&
69346- (vma->vm_end == addr) &&
69347- !vma_growsup(vma->vm_next, addr);
69348-}
69349-
69350 extern pid_t
69351 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
69352
69353@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
69354 }
69355 #endif
69356
69357+#ifdef CONFIG_MMU
69358+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
69359+#else
69360+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
69361+{
69362+ return __pgprot(0);
69363+}
69364+#endif
69365+
69366 int vma_wants_writenotify(struct vm_area_struct *vma);
69367
69368 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
69369@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
69370 {
69371 return 0;
69372 }
69373+
69374+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
69375+ unsigned long address)
69376+{
69377+ return 0;
69378+}
69379 #else
69380 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69381+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69382 #endif
69383
69384 #ifdef __PAGETABLE_PMD_FOLDED
69385@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
69386 {
69387 return 0;
69388 }
69389+
69390+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
69391+ unsigned long address)
69392+{
69393+ return 0;
69394+}
69395 #else
69396 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
69397+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
69398 #endif
69399
69400 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
69401@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
69402 NULL: pud_offset(pgd, address);
69403 }
69404
69405+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
69406+{
69407+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
69408+ NULL: pud_offset(pgd, address);
69409+}
69410+
69411 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
69412 {
69413 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
69414 NULL: pmd_offset(pud, address);
69415 }
69416+
69417+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
69418+{
69419+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
69420+ NULL: pmd_offset(pud, address);
69421+}
69422 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
69423
69424 #if USE_SPLIT_PTLOCKS
69425@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
69426 unsigned long, unsigned long,
69427 unsigned long, unsigned long);
69428 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
69429+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
69430
69431 /* These take the mm semaphore themselves */
69432 extern unsigned long vm_brk(unsigned long, unsigned long);
69433@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
69434 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
69435 struct vm_area_struct **pprev);
69436
69437+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
69438+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
69439+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
69440+
69441 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
69442 NULL if none. Assume start_addr < end_addr. */
69443 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
69444@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
69445 return vma;
69446 }
69447
69448-#ifdef CONFIG_MMU
69449-pgprot_t vm_get_page_prot(unsigned long vm_flags);
69450-#else
69451-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
69452-{
69453- return __pgprot(0);
69454-}
69455-#endif
69456-
69457 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
69458 unsigned long change_prot_numa(struct vm_area_struct *vma,
69459 unsigned long start, unsigned long end);
69460@@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
69461 extern int sysctl_memory_failure_early_kill;
69462 extern int sysctl_memory_failure_recovery;
69463 extern void shake_page(struct page *p, int access);
69464-extern atomic_long_t mce_bad_pages;
69465+extern atomic_long_unchecked_t mce_bad_pages;
69466 extern int soft_offline_page(struct page *page, int flags);
69467
69468 extern void dump_page(struct page *page);
69469@@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
69470 static inline bool page_is_guard(struct page *page) { return false; }
69471 #endif /* CONFIG_DEBUG_PAGEALLOC */
69472
69473+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69474+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
69475+#else
69476+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
69477+#endif
69478+
69479 #endif /* __KERNEL__ */
69480 #endif /* _LINUX_MM_H */
69481diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
69482index f8f5162..a039af9 100644
69483--- a/include/linux/mm_types.h
69484+++ b/include/linux/mm_types.h
69485@@ -288,6 +288,8 @@ struct vm_area_struct {
69486 #ifdef CONFIG_NUMA
69487 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
69488 #endif
69489+
69490+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
69491 };
69492
69493 struct core_thread {
69494@@ -362,7 +364,7 @@ struct mm_struct {
69495 unsigned long def_flags;
69496 unsigned long nr_ptes; /* Page table pages */
69497 unsigned long start_code, end_code, start_data, end_data;
69498- unsigned long start_brk, brk, start_stack;
69499+ unsigned long aslr_gap, start_brk, brk, start_stack;
69500 unsigned long arg_start, arg_end, env_start, env_end;
69501
69502 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
69503@@ -436,6 +438,24 @@ struct mm_struct {
69504 int first_nid;
69505 #endif
69506 struct uprobes_state uprobes_state;
69507+
69508+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69509+ unsigned long pax_flags;
69510+#endif
69511+
69512+#ifdef CONFIG_PAX_DLRESOLVE
69513+ unsigned long call_dl_resolve;
69514+#endif
69515+
69516+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
69517+ unsigned long call_syscall;
69518+#endif
69519+
69520+#ifdef CONFIG_PAX_ASLR
69521+ unsigned long delta_mmap; /* randomized offset */
69522+ unsigned long delta_stack; /* randomized offset */
69523+#endif
69524+
69525 };
69526
69527 /* first nid will either be a valid NID or one of these values */
69528diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
69529index c5d5278..f0b68c8 100644
69530--- a/include/linux/mmiotrace.h
69531+++ b/include/linux/mmiotrace.h
69532@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
69533 /* Called from ioremap.c */
69534 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
69535 void __iomem *addr);
69536-extern void mmiotrace_iounmap(volatile void __iomem *addr);
69537+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
69538
69539 /* For anyone to insert markers. Remember trailing newline. */
69540 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
69541@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
69542 {
69543 }
69544
69545-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
69546+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
69547 {
69548 }
69549
69550diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
69551index 73b64a3..6562925 100644
69552--- a/include/linux/mmzone.h
69553+++ b/include/linux/mmzone.h
69554@@ -412,7 +412,7 @@ struct zone {
69555 unsigned long flags; /* zone flags, see below */
69556
69557 /* Zone statistics */
69558- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69559+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69560
69561 /*
69562 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
69563diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
69564index fed3def..c933f99 100644
69565--- a/include/linux/mod_devicetable.h
69566+++ b/include/linux/mod_devicetable.h
69567@@ -12,7 +12,7 @@
69568 typedef unsigned long kernel_ulong_t;
69569 #endif
69570
69571-#define PCI_ANY_ID (~0)
69572+#define PCI_ANY_ID ((__u16)~0)
69573
69574 struct pci_device_id {
69575 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
69576@@ -139,7 +139,7 @@ struct usb_device_id {
69577 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
69578 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
69579
69580-#define HID_ANY_ID (~0)
69581+#define HID_ANY_ID (~0U)
69582 #define HID_BUS_ANY 0xffff
69583 #define HID_GROUP_ANY 0x0000
69584
69585@@ -498,7 +498,7 @@ struct dmi_system_id {
69586 const char *ident;
69587 struct dmi_strmatch matches[4];
69588 void *driver_data;
69589-};
69590+} __do_const;
69591 /*
69592 * struct dmi_device_id appears during expansion of
69593 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
69594diff --git a/include/linux/module.h b/include/linux/module.h
69595index 1375ee3..ced8177 100644
69596--- a/include/linux/module.h
69597+++ b/include/linux/module.h
69598@@ -17,9 +17,11 @@
69599 #include <linux/moduleparam.h>
69600 #include <linux/tracepoint.h>
69601 #include <linux/export.h>
69602+#include <linux/fs.h>
69603
69604 #include <linux/percpu.h>
69605 #include <asm/module.h>
69606+#include <asm/pgtable.h>
69607
69608 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
69609 #define MODULE_SIG_STRING "~Module signature appended~\n"
69610@@ -54,12 +56,13 @@ struct module_attribute {
69611 int (*test)(struct module *);
69612 void (*free)(struct module *);
69613 };
69614+typedef struct module_attribute __no_const module_attribute_no_const;
69615
69616 struct module_version_attribute {
69617 struct module_attribute mattr;
69618 const char *module_name;
69619 const char *version;
69620-} __attribute__ ((__aligned__(sizeof(void *))));
69621+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
69622
69623 extern ssize_t __modver_version_show(struct module_attribute *,
69624 struct module_kobject *, char *);
69625@@ -232,7 +235,7 @@ struct module
69626
69627 /* Sysfs stuff. */
69628 struct module_kobject mkobj;
69629- struct module_attribute *modinfo_attrs;
69630+ module_attribute_no_const *modinfo_attrs;
69631 const char *version;
69632 const char *srcversion;
69633 struct kobject *holders_dir;
69634@@ -281,19 +284,16 @@ struct module
69635 int (*init)(void);
69636
69637 /* If this is non-NULL, vfree after init() returns */
69638- void *module_init;
69639+ void *module_init_rx, *module_init_rw;
69640
69641 /* Here is the actual code + data, vfree'd on unload. */
69642- void *module_core;
69643+ void *module_core_rx, *module_core_rw;
69644
69645 /* Here are the sizes of the init and core sections */
69646- unsigned int init_size, core_size;
69647+ unsigned int init_size_rw, core_size_rw;
69648
69649 /* The size of the executable code in each section. */
69650- unsigned int init_text_size, core_text_size;
69651-
69652- /* Size of RO sections of the module (text+rodata) */
69653- unsigned int init_ro_size, core_ro_size;
69654+ unsigned int init_size_rx, core_size_rx;
69655
69656 /* Arch-specific module values */
69657 struct mod_arch_specific arch;
69658@@ -349,6 +349,10 @@ struct module
69659 #ifdef CONFIG_EVENT_TRACING
69660 struct ftrace_event_call **trace_events;
69661 unsigned int num_trace_events;
69662+ struct file_operations trace_id;
69663+ struct file_operations trace_enable;
69664+ struct file_operations trace_format;
69665+ struct file_operations trace_filter;
69666 #endif
69667 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69668 unsigned int num_ftrace_callsites;
69669@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
69670 bool is_module_percpu_address(unsigned long addr);
69671 bool is_module_text_address(unsigned long addr);
69672
69673+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
69674+{
69675+
69676+#ifdef CONFIG_PAX_KERNEXEC
69677+ if (ktla_ktva(addr) >= (unsigned long)start &&
69678+ ktla_ktva(addr) < (unsigned long)start + size)
69679+ return 1;
69680+#endif
69681+
69682+ return ((void *)addr >= start && (void *)addr < start + size);
69683+}
69684+
69685+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
69686+{
69687+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
69688+}
69689+
69690+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
69691+{
69692+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
69693+}
69694+
69695+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
69696+{
69697+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
69698+}
69699+
69700+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
69701+{
69702+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
69703+}
69704+
69705 static inline int within_module_core(unsigned long addr, struct module *mod)
69706 {
69707- return (unsigned long)mod->module_core <= addr &&
69708- addr < (unsigned long)mod->module_core + mod->core_size;
69709+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69710 }
69711
69712 static inline int within_module_init(unsigned long addr, struct module *mod)
69713 {
69714- return (unsigned long)mod->module_init <= addr &&
69715- addr < (unsigned long)mod->module_init + mod->init_size;
69716+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69717 }
69718
69719 /* Search for module by name: must hold module_mutex. */
69720diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69721index 560ca53..5ee8d73 100644
69722--- a/include/linux/moduleloader.h
69723+++ b/include/linux/moduleloader.h
69724@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69725
69726 /* Allocator used for allocating struct module, core sections and init
69727 sections. Returns NULL on failure. */
69728-void *module_alloc(unsigned long size);
69729+void *module_alloc(unsigned long size) __size_overflow(1);
69730+
69731+#ifdef CONFIG_PAX_KERNEXEC
69732+void *module_alloc_exec(unsigned long size) __size_overflow(1);
69733+#else
69734+#define module_alloc_exec(x) module_alloc(x)
69735+#endif
69736
69737 /* Free memory returned from module_alloc. */
69738 void module_free(struct module *mod, void *module_region);
69739
69740+#ifdef CONFIG_PAX_KERNEXEC
69741+void module_free_exec(struct module *mod, void *module_region);
69742+#else
69743+#define module_free_exec(x, y) module_free((x), (y))
69744+#endif
69745+
69746 /*
69747 * Apply the given relocation to the (simplified) ELF. Return -error
69748 * or 0.
69749@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69750 unsigned int relsec,
69751 struct module *me)
69752 {
69753+#ifdef CONFIG_MODULES
69754 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69755+#endif
69756 return -ENOEXEC;
69757 }
69758 #endif
69759@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69760 unsigned int relsec,
69761 struct module *me)
69762 {
69763+#ifdef CONFIG_MODULES
69764 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69765+#endif
69766 return -ENOEXEC;
69767 }
69768 #endif
69769diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69770index 137b419..fe663ec 100644
69771--- a/include/linux/moduleparam.h
69772+++ b/include/linux/moduleparam.h
69773@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69774 * @len is usually just sizeof(string).
69775 */
69776 #define module_param_string(name, string, len, perm) \
69777- static const struct kparam_string __param_string_##name \
69778+ static const struct kparam_string __param_string_##name __used \
69779 = { len, string }; \
69780 __module_param_call(MODULE_PARAM_PREFIX, name, \
69781 &param_ops_string, \
69782@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69783 */
69784 #define module_param_array_named(name, array, type, nump, perm) \
69785 param_check_##type(name, &(array)[0]); \
69786- static const struct kparam_array __param_arr_##name \
69787+ static const struct kparam_array __param_arr_##name __used \
69788 = { .max = ARRAY_SIZE(array), .num = nump, \
69789 .ops = &param_ops_##type, \
69790 .elemsize = sizeof(array[0]), .elem = array }; \
69791diff --git a/include/linux/namei.h b/include/linux/namei.h
69792index 5a5ff57..5ae5070 100644
69793--- a/include/linux/namei.h
69794+++ b/include/linux/namei.h
69795@@ -19,7 +19,7 @@ struct nameidata {
69796 unsigned seq;
69797 int last_type;
69798 unsigned depth;
69799- char *saved_names[MAX_NESTED_LINKS + 1];
69800+ const char *saved_names[MAX_NESTED_LINKS + 1];
69801 };
69802
69803 /*
69804@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69805
69806 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69807
69808-static inline void nd_set_link(struct nameidata *nd, char *path)
69809+static inline void nd_set_link(struct nameidata *nd, const char *path)
69810 {
69811 nd->saved_names[nd->depth] = path;
69812 }
69813
69814-static inline char *nd_get_link(struct nameidata *nd)
69815+static inline const char *nd_get_link(const struct nameidata *nd)
69816 {
69817 return nd->saved_names[nd->depth];
69818 }
69819diff --git a/include/linux/net.h b/include/linux/net.h
69820index aa16731..514b875 100644
69821--- a/include/linux/net.h
69822+++ b/include/linux/net.h
69823@@ -183,7 +183,7 @@ struct net_proto_family {
69824 int (*create)(struct net *net, struct socket *sock,
69825 int protocol, int kern);
69826 struct module *owner;
69827-};
69828+} __do_const;
69829
69830 struct iovec;
69831 struct kvec;
69832diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69833index 9ef07d0..130a5d9 100644
69834--- a/include/linux/netdevice.h
69835+++ b/include/linux/netdevice.h
69836@@ -1012,6 +1012,7 @@ struct net_device_ops {
69837 u32 pid, u32 seq,
69838 struct net_device *dev);
69839 };
69840+typedef struct net_device_ops __no_const net_device_ops_no_const;
69841
69842 /*
69843 * The DEVICE structure.
69844@@ -1078,7 +1079,7 @@ struct net_device {
69845 int iflink;
69846
69847 struct net_device_stats stats;
69848- atomic_long_t rx_dropped; /* dropped packets by core network
69849+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69850 * Do not use this in drivers.
69851 */
69852
69853diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69854index ee14284..bc65d63 100644
69855--- a/include/linux/netfilter.h
69856+++ b/include/linux/netfilter.h
69857@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69858 #endif
69859 /* Use the module struct to lock set/get code in place */
69860 struct module *owner;
69861-};
69862+} __do_const;
69863
69864 /* Function to register/unregister hook points. */
69865 int nf_register_hook(struct nf_hook_ops *reg);
69866diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69867index 7958e84..ed74d7a 100644
69868--- a/include/linux/netfilter/ipset/ip_set.h
69869+++ b/include/linux/netfilter/ipset/ip_set.h
69870@@ -98,7 +98,7 @@ struct ip_set_type_variant {
69871 /* Return true if "b" set is the same as "a"
69872 * according to the create set parameters */
69873 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69874-};
69875+} __do_const;
69876
69877 /* The core set type structure */
69878 struct ip_set_type {
69879diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69880index 4966dde..7d8ce06 100644
69881--- a/include/linux/netfilter/nfnetlink.h
69882+++ b/include/linux/netfilter/nfnetlink.h
69883@@ -16,7 +16,7 @@ struct nfnl_callback {
69884 const struct nlattr * const cda[]);
69885 const struct nla_policy *policy; /* netlink attribute policy */
69886 const u_int16_t attr_count; /* number of nlattr's */
69887-};
69888+} __do_const;
69889
69890 struct nfnetlink_subsystem {
69891 const char *name;
69892diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69893new file mode 100644
69894index 0000000..33f4af8
69895--- /dev/null
69896+++ b/include/linux/netfilter/xt_gradm.h
69897@@ -0,0 +1,9 @@
69898+#ifndef _LINUX_NETFILTER_XT_GRADM_H
69899+#define _LINUX_NETFILTER_XT_GRADM_H 1
69900+
69901+struct xt_gradm_mtinfo {
69902+ __u16 flags;
69903+ __u16 invflags;
69904+};
69905+
69906+#endif
69907diff --git a/include/linux/nls.h b/include/linux/nls.h
69908index 5dc635f..35f5e11 100644
69909--- a/include/linux/nls.h
69910+++ b/include/linux/nls.h
69911@@ -31,7 +31,7 @@ struct nls_table {
69912 const unsigned char *charset2upper;
69913 struct module *owner;
69914 struct nls_table *next;
69915-};
69916+} __do_const;
69917
69918 /* this value hold the maximum octet of charset */
69919 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69920diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69921index d65746e..62e72c2 100644
69922--- a/include/linux/notifier.h
69923+++ b/include/linux/notifier.h
69924@@ -51,7 +51,8 @@ struct notifier_block {
69925 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69926 struct notifier_block __rcu *next;
69927 int priority;
69928-};
69929+} __do_const;
69930+typedef struct notifier_block __no_const notifier_block_no_const;
69931
69932 struct atomic_notifier_head {
69933 spinlock_t lock;
69934diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69935index a4c5624..79d6d88 100644
69936--- a/include/linux/oprofile.h
69937+++ b/include/linux/oprofile.h
69938@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69939 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69940 char const * name, ulong * val);
69941
69942-/** Create a file for read-only access to an atomic_t. */
69943+/** Create a file for read-only access to an atomic_unchecked_t. */
69944 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69945- char const * name, atomic_t * val);
69946+ char const * name, atomic_unchecked_t * val);
69947
69948 /** create a directory */
69949 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69950diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69951index 45fc162..01a4068 100644
69952--- a/include/linux/pci_hotplug.h
69953+++ b/include/linux/pci_hotplug.h
69954@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69955 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69956 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69957 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69958-};
69959+} __do_const;
69960+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69961
69962 /**
69963 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69964diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69965index a280650..2b67b91 100644
69966--- a/include/linux/perf_event.h
69967+++ b/include/linux/perf_event.h
69968@@ -328,8 +328,8 @@ struct perf_event {
69969
69970 enum perf_event_active_state state;
69971 unsigned int attach_state;
69972- local64_t count;
69973- atomic64_t child_count;
69974+ local64_t count; /* PaX: fix it one day */
69975+ atomic64_unchecked_t child_count;
69976
69977 /*
69978 * These are the total time in nanoseconds that the event
69979@@ -380,8 +380,8 @@ struct perf_event {
69980 * These accumulate total time (in nanoseconds) that children
69981 * events have been enabled and running, respectively.
69982 */
69983- atomic64_t child_total_time_enabled;
69984- atomic64_t child_total_time_running;
69985+ atomic64_unchecked_t child_total_time_enabled;
69986+ atomic64_unchecked_t child_total_time_running;
69987
69988 /*
69989 * Protect attach/detach and child_list:
69990@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
69991 */
69992 #define perf_cpu_notifier(fn) \
69993 do { \
69994- static struct notifier_block fn##_nb __cpuinitdata = \
69995+ static struct notifier_block fn##_nb = \
69996 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
69997 unsigned long cpu = smp_processor_id(); \
69998 unsigned long flags; \
69999diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
70000index ad1a427..6419649 100644
70001--- a/include/linux/pipe_fs_i.h
70002+++ b/include/linux/pipe_fs_i.h
70003@@ -45,9 +45,9 @@ struct pipe_buffer {
70004 struct pipe_inode_info {
70005 wait_queue_head_t wait;
70006 unsigned int nrbufs, curbuf, buffers;
70007- unsigned int readers;
70008- unsigned int writers;
70009- unsigned int waiting_writers;
70010+ atomic_t readers;
70011+ atomic_t writers;
70012+ atomic_t waiting_writers;
70013 unsigned int r_counter;
70014 unsigned int w_counter;
70015 struct page *tmp_page;
70016diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
70017index 5f28cae..3d23723 100644
70018--- a/include/linux/platform_data/usb-ehci-s5p.h
70019+++ b/include/linux/platform_data/usb-ehci-s5p.h
70020@@ -14,7 +14,7 @@
70021 struct s5p_ehci_platdata {
70022 int (*phy_init)(struct platform_device *pdev, int type);
70023 int (*phy_exit)(struct platform_device *pdev, int type);
70024-};
70025+} __no_const;
70026
70027 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
70028
70029diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
70030index c256c59..8ea94c7 100644
70031--- a/include/linux/platform_data/usb-exynos.h
70032+++ b/include/linux/platform_data/usb-exynos.h
70033@@ -14,7 +14,7 @@
70034 struct exynos4_ohci_platdata {
70035 int (*phy_init)(struct platform_device *pdev, int type);
70036 int (*phy_exit)(struct platform_device *pdev, int type);
70037-};
70038+} __no_const;
70039
70040 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
70041
70042diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
70043index 7c1d252..c5c773e 100644
70044--- a/include/linux/pm_domain.h
70045+++ b/include/linux/pm_domain.h
70046@@ -48,7 +48,7 @@ struct gpd_dev_ops {
70047
70048 struct gpd_cpu_data {
70049 unsigned int saved_exit_latency;
70050- struct cpuidle_state *idle_state;
70051+ cpuidle_state_no_const *idle_state;
70052 };
70053
70054 struct generic_pm_domain {
70055diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
70056index f271860..6b3bec5 100644
70057--- a/include/linux/pm_runtime.h
70058+++ b/include/linux/pm_runtime.h
70059@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
70060
70061 static inline void pm_runtime_mark_last_busy(struct device *dev)
70062 {
70063- ACCESS_ONCE(dev->power.last_busy) = jiffies;
70064+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
70065 }
70066
70067 #else /* !CONFIG_PM_RUNTIME */
70068diff --git a/include/linux/pnp.h b/include/linux/pnp.h
70069index 195aafc..49a7bc2 100644
70070--- a/include/linux/pnp.h
70071+++ b/include/linux/pnp.h
70072@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
70073 struct pnp_fixup {
70074 char id[7];
70075 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
70076-};
70077+} __do_const;
70078
70079 /* config parameters */
70080 #define PNP_CONFIG_NORMAL 0x0001
70081diff --git a/include/linux/poison.h b/include/linux/poison.h
70082index 2110a81..13a11bb 100644
70083--- a/include/linux/poison.h
70084+++ b/include/linux/poison.h
70085@@ -19,8 +19,8 @@
70086 * under normal circumstances, used to verify that nobody uses
70087 * non-initialized list entries.
70088 */
70089-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
70090-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
70091+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
70092+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
70093
70094 /********** include/linux/timer.h **********/
70095 /*
70096diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
70097index c0f44c2..1572583 100644
70098--- a/include/linux/power/smartreflex.h
70099+++ b/include/linux/power/smartreflex.h
70100@@ -238,7 +238,7 @@ struct omap_sr_class_data {
70101 int (*notify)(struct omap_sr *sr, u32 status);
70102 u8 notify_flags;
70103 u8 class_type;
70104-};
70105+} __do_const;
70106
70107 /**
70108 * struct omap_sr_nvalue_table - Smartreflex n-target value info
70109diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
70110index 4ea1d37..80f4b33 100644
70111--- a/include/linux/ppp-comp.h
70112+++ b/include/linux/ppp-comp.h
70113@@ -84,7 +84,7 @@ struct compressor {
70114 struct module *owner;
70115 /* Extra skb space needed by the compressor algorithm */
70116 unsigned int comp_extra;
70117-};
70118+} __do_const;
70119
70120 /*
70121 * The return value from decompress routine is the length of the
70122diff --git a/include/linux/printk.h b/include/linux/printk.h
70123index 9afc01e..92c32e8 100644
70124--- a/include/linux/printk.h
70125+++ b/include/linux/printk.h
70126@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
70127 extern int printk_needs_cpu(int cpu);
70128 extern void printk_tick(void);
70129
70130+extern int kptr_restrict;
70131+
70132 #ifdef CONFIG_PRINTK
70133 asmlinkage __printf(5, 0)
70134 int vprintk_emit(int facility, int level,
70135@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
70136
70137 extern int printk_delay_msec;
70138 extern int dmesg_restrict;
70139-extern int kptr_restrict;
70140
70141 void log_buf_kexec_setup(void);
70142 void __init setup_log_buf(int early);
70143diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
70144index 32676b3..8f7a182 100644
70145--- a/include/linux/proc_fs.h
70146+++ b/include/linux/proc_fs.h
70147@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
70148 return proc_create_data(name, mode, parent, proc_fops, NULL);
70149 }
70150
70151+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
70152+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
70153+{
70154+#ifdef CONFIG_GRKERNSEC_PROC_USER
70155+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
70156+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70157+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
70158+#else
70159+ return proc_create_data(name, mode, parent, proc_fops, NULL);
70160+#endif
70161+}
70162+
70163 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
70164 umode_t mode, struct proc_dir_entry *base,
70165 read_proc_t *read_proc, void * data)
70166diff --git a/include/linux/random.h b/include/linux/random.h
70167index d984608..d6f0042 100644
70168--- a/include/linux/random.h
70169+++ b/include/linux/random.h
70170@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
70171 u32 prandom_u32_state(struct rnd_state *);
70172 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
70173
70174+static inline unsigned long pax_get_random_long(void)
70175+{
70176+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
70177+}
70178+
70179 /*
70180 * Handle minimum values for seeds
70181 */
70182diff --git a/include/linux/rculist.h b/include/linux/rculist.h
70183index c92dd28..08f4eab 100644
70184--- a/include/linux/rculist.h
70185+++ b/include/linux/rculist.h
70186@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
70187 struct list_head *prev, struct list_head *next);
70188 #endif
70189
70190+extern void __pax_list_add_rcu(struct list_head *new,
70191+ struct list_head *prev, struct list_head *next);
70192+
70193 /**
70194 * list_add_rcu - add a new entry to rcu-protected list
70195 * @new: new entry to be added
70196@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
70197 __list_add_rcu(new, head, head->next);
70198 }
70199
70200+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
70201+{
70202+ __pax_list_add_rcu(new, head, head->next);
70203+}
70204+
70205 /**
70206 * list_add_tail_rcu - add a new entry to rcu-protected list
70207 * @new: new entry to be added
70208@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
70209 __list_add_rcu(new, head->prev, head);
70210 }
70211
70212+static inline void pax_list_add_tail_rcu(struct list_head *new,
70213+ struct list_head *head)
70214+{
70215+ __pax_list_add_rcu(new, head->prev, head);
70216+}
70217+
70218 /**
70219 * list_del_rcu - deletes entry from list without re-initialization
70220 * @entry: the element to delete from the list.
70221@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
70222 entry->prev = LIST_POISON2;
70223 }
70224
70225+extern void pax_list_del_rcu(struct list_head *entry);
70226+
70227 /**
70228 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
70229 * @n: the element to delete from the hash list.
70230diff --git a/include/linux/reboot.h b/include/linux/reboot.h
70231index 23b3630..e1bc12b 100644
70232--- a/include/linux/reboot.h
70233+++ b/include/linux/reboot.h
70234@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
70235 * Architecture-specific implementations of sys_reboot commands.
70236 */
70237
70238-extern void machine_restart(char *cmd);
70239-extern void machine_halt(void);
70240-extern void machine_power_off(void);
70241+extern void machine_restart(char *cmd) __noreturn;
70242+extern void machine_halt(void) __noreturn;
70243+extern void machine_power_off(void) __noreturn;
70244
70245 extern void machine_shutdown(void);
70246 struct pt_regs;
70247@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
70248 */
70249
70250 extern void kernel_restart_prepare(char *cmd);
70251-extern void kernel_restart(char *cmd);
70252-extern void kernel_halt(void);
70253-extern void kernel_power_off(void);
70254+extern void kernel_restart(char *cmd) __noreturn;
70255+extern void kernel_halt(void) __noreturn;
70256+extern void kernel_power_off(void) __noreturn;
70257
70258 extern int C_A_D; /* for sysctl */
70259 void ctrl_alt_del(void);
70260@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
70261 * Emergency restart, callable from an interrupt handler.
70262 */
70263
70264-extern void emergency_restart(void);
70265+extern void emergency_restart(void) __noreturn;
70266 #include <asm/emergency-restart.h>
70267
70268 #endif /* _LINUX_REBOOT_H */
70269diff --git a/include/linux/regset.h b/include/linux/regset.h
70270index 8e0c9fe..ac4d221 100644
70271--- a/include/linux/regset.h
70272+++ b/include/linux/regset.h
70273@@ -161,7 +161,8 @@ struct user_regset {
70274 unsigned int align;
70275 unsigned int bias;
70276 unsigned int core_note_type;
70277-};
70278+} __do_const;
70279+typedef struct user_regset __no_const user_regset_no_const;
70280
70281 /**
70282 * struct user_regset_view - available regsets
70283diff --git a/include/linux/relay.h b/include/linux/relay.h
70284index 91cacc3..b55ff74 100644
70285--- a/include/linux/relay.h
70286+++ b/include/linux/relay.h
70287@@ -160,7 +160,7 @@ struct rchan_callbacks
70288 * The callback should return 0 if successful, negative if not.
70289 */
70290 int (*remove_buf_file)(struct dentry *dentry);
70291-};
70292+} __no_const;
70293
70294 /*
70295 * CONFIG_RELAY kernel API, kernel/relay.c
70296diff --git a/include/linux/rio.h b/include/linux/rio.h
70297index a3e7842..d973ca6 100644
70298--- a/include/linux/rio.h
70299+++ b/include/linux/rio.h
70300@@ -339,7 +339,7 @@ struct rio_ops {
70301 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
70302 u64 rstart, u32 size, u32 flags);
70303 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
70304-};
70305+} __no_const;
70306
70307 #define RIO_RESOURCE_MEM 0x00000100
70308 #define RIO_RESOURCE_DOORBELL 0x00000200
70309diff --git a/include/linux/rmap.h b/include/linux/rmap.h
70310index c20635c..2f5def4 100644
70311--- a/include/linux/rmap.h
70312+++ b/include/linux/rmap.h
70313@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
70314 void anon_vma_init(void); /* create anon_vma_cachep */
70315 int anon_vma_prepare(struct vm_area_struct *);
70316 void unlink_anon_vmas(struct vm_area_struct *);
70317-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
70318-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
70319+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
70320+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
70321
70322 static inline void anon_vma_merge(struct vm_area_struct *vma,
70323 struct vm_area_struct *next)
70324diff --git a/include/linux/sched.h b/include/linux/sched.h
70325index d211247..eac6c2c 100644
70326--- a/include/linux/sched.h
70327+++ b/include/linux/sched.h
70328@@ -61,6 +61,7 @@ struct bio_list;
70329 struct fs_struct;
70330 struct perf_event_context;
70331 struct blk_plug;
70332+struct linux_binprm;
70333
70334 /*
70335 * List of flags we want to share for kernel threads,
70336@@ -327,7 +328,7 @@ extern char __sched_text_start[], __sched_text_end[];
70337 extern int in_sched_functions(unsigned long addr);
70338
70339 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
70340-extern signed long schedule_timeout(signed long timeout);
70341+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
70342 extern signed long schedule_timeout_interruptible(signed long timeout);
70343 extern signed long schedule_timeout_killable(signed long timeout);
70344 extern signed long schedule_timeout_uninterruptible(signed long timeout);
70345@@ -354,10 +355,23 @@ struct user_namespace;
70346 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
70347
70348 extern int sysctl_max_map_count;
70349+extern unsigned long sysctl_heap_stack_gap;
70350
70351 #include <linux/aio.h>
70352
70353 #ifdef CONFIG_MMU
70354+
70355+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
70356+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
70357+#else
70358+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
70359+{
70360+ return 0;
70361+}
70362+#endif
70363+
70364+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
70365+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
70366 extern void arch_pick_mmap_layout(struct mm_struct *mm);
70367 extern unsigned long
70368 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
70369@@ -639,6 +653,17 @@ struct signal_struct {
70370 #ifdef CONFIG_TASKSTATS
70371 struct taskstats *stats;
70372 #endif
70373+
70374+#ifdef CONFIG_GRKERNSEC
70375+ u32 curr_ip;
70376+ u32 saved_ip;
70377+ u32 gr_saddr;
70378+ u32 gr_daddr;
70379+ u16 gr_sport;
70380+ u16 gr_dport;
70381+ u8 used_accept:1;
70382+#endif
70383+
70384 #ifdef CONFIG_AUDIT
70385 unsigned audit_tty;
70386 struct tty_audit_buf *tty_audit_buf;
70387@@ -717,6 +742,11 @@ struct user_struct {
70388 struct key *session_keyring; /* UID's default session keyring */
70389 #endif
70390
70391+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
70392+ unsigned int banned;
70393+ unsigned long ban_expires;
70394+#endif
70395+
70396 /* Hash table maintenance information */
70397 struct hlist_node uidhash_node;
70398 kuid_t uid;
70399@@ -1116,7 +1146,7 @@ struct sched_class {
70400 #ifdef CONFIG_FAIR_GROUP_SCHED
70401 void (*task_move_group) (struct task_struct *p, int on_rq);
70402 #endif
70403-};
70404+} __do_const;
70405
70406 struct load_weight {
70407 unsigned long weight, inv_weight;
70408@@ -1360,8 +1390,8 @@ struct task_struct {
70409 struct list_head thread_group;
70410
70411 struct completion *vfork_done; /* for vfork() */
70412- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
70413- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70414+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
70415+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70416
70417 cputime_t utime, stime, utimescaled, stimescaled;
70418 cputime_t gtime;
70419@@ -1377,11 +1407,6 @@ struct task_struct {
70420 struct task_cputime cputime_expires;
70421 struct list_head cpu_timers[3];
70422
70423-/* process credentials */
70424- const struct cred __rcu *real_cred; /* objective and real subjective task
70425- * credentials (COW) */
70426- const struct cred __rcu *cred; /* effective (overridable) subjective task
70427- * credentials (COW) */
70428 char comm[TASK_COMM_LEN]; /* executable name excluding path
70429 - access with [gs]et_task_comm (which lock
70430 it with task_lock())
70431@@ -1398,6 +1423,10 @@ struct task_struct {
70432 #endif
70433 /* CPU-specific state of this task */
70434 struct thread_struct thread;
70435+/* thread_info moved to task_struct */
70436+#ifdef CONFIG_X86
70437+ struct thread_info tinfo;
70438+#endif
70439 /* filesystem information */
70440 struct fs_struct *fs;
70441 /* open file information */
70442@@ -1471,6 +1500,10 @@ struct task_struct {
70443 gfp_t lockdep_reclaim_gfp;
70444 #endif
70445
70446+/* process credentials */
70447+ const struct cred __rcu *real_cred; /* objective and real subjective task
70448+ * credentials (COW) */
70449+
70450 /* journalling filesystem info */
70451 void *journal_info;
70452
70453@@ -1509,6 +1542,10 @@ struct task_struct {
70454 /* cg_list protected by css_set_lock and tsk->alloc_lock */
70455 struct list_head cg_list;
70456 #endif
70457+
70458+ const struct cred __rcu *cred; /* effective (overridable) subjective task
70459+ * credentials (COW) */
70460+
70461 #ifdef CONFIG_FUTEX
70462 struct robust_list_head __user *robust_list;
70463 #ifdef CONFIG_COMPAT
70464@@ -1605,8 +1642,74 @@ struct task_struct {
70465 #ifdef CONFIG_UPROBES
70466 struct uprobe_task *utask;
70467 #endif
70468+
70469+#ifdef CONFIG_GRKERNSEC
70470+ /* grsecurity */
70471+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70472+ u64 exec_id;
70473+#endif
70474+#ifdef CONFIG_GRKERNSEC_SETXID
70475+ const struct cred *delayed_cred;
70476+#endif
70477+ struct dentry *gr_chroot_dentry;
70478+ struct acl_subject_label *acl;
70479+ struct acl_role_label *role;
70480+ struct file *exec_file;
70481+ unsigned long brute_expires;
70482+ u16 acl_role_id;
70483+ /* is this the task that authenticated to the special role */
70484+ u8 acl_sp_role;
70485+ u8 is_writable;
70486+ u8 brute;
70487+ u8 gr_is_chrooted;
70488+#endif
70489+
70490 };
70491
70492+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
70493+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
70494+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
70495+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
70496+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
70497+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
70498+
70499+#ifdef CONFIG_PAX_SOFTMODE
70500+extern int pax_softmode;
70501+#endif
70502+
70503+extern int pax_check_flags(unsigned long *);
70504+
70505+/* if tsk != current then task_lock must be held on it */
70506+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70507+static inline unsigned long pax_get_flags(struct task_struct *tsk)
70508+{
70509+ if (likely(tsk->mm))
70510+ return tsk->mm->pax_flags;
70511+ else
70512+ return 0UL;
70513+}
70514+
70515+/* if tsk != current then task_lock must be held on it */
70516+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
70517+{
70518+ if (likely(tsk->mm)) {
70519+ tsk->mm->pax_flags = flags;
70520+ return 0;
70521+ }
70522+ return -EINVAL;
70523+}
70524+#endif
70525+
70526+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70527+extern void pax_set_initial_flags(struct linux_binprm *bprm);
70528+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
70529+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
70530+#endif
70531+
70532+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
70533+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
70534+extern void pax_report_refcount_overflow(struct pt_regs *regs);
70535+
70536 /* Future-safe accessor for struct task_struct's cpus_allowed. */
70537 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
70538
70539@@ -1696,7 +1799,7 @@ struct pid_namespace;
70540 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
70541 struct pid_namespace *ns);
70542
70543-static inline pid_t task_pid_nr(struct task_struct *tsk)
70544+static inline pid_t task_pid_nr(const struct task_struct *tsk)
70545 {
70546 return tsk->pid;
70547 }
70548@@ -2155,7 +2258,9 @@ void yield(void);
70549 extern struct exec_domain default_exec_domain;
70550
70551 union thread_union {
70552+#ifndef CONFIG_X86
70553 struct thread_info thread_info;
70554+#endif
70555 unsigned long stack[THREAD_SIZE/sizeof(long)];
70556 };
70557
70558@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
70559 */
70560
70561 extern struct task_struct *find_task_by_vpid(pid_t nr);
70562+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
70563 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
70564 struct pid_namespace *ns);
70565
70566@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
70567 extern void exit_itimers(struct signal_struct *);
70568 extern void flush_itimer_signals(void);
70569
70570-extern void do_group_exit(int);
70571+extern __noreturn void do_group_exit(int);
70572
70573 extern int allow_signal(int);
70574 extern int disallow_signal(int);
70575@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
70576
70577 #endif
70578
70579-static inline int object_is_on_stack(void *obj)
70580+static inline int object_starts_on_stack(void *obj)
70581 {
70582- void *stack = task_stack_page(current);
70583+ const void *stack = task_stack_page(current);
70584
70585 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
70586 }
70587diff --git a/include/linux/security.h b/include/linux/security.h
70588index eee7478..290f7ba 100644
70589--- a/include/linux/security.h
70590+++ b/include/linux/security.h
70591@@ -26,6 +26,7 @@
70592 #include <linux/capability.h>
70593 #include <linux/slab.h>
70594 #include <linux/err.h>
70595+#include <linux/grsecurity.h>
70596
70597 struct linux_binprm;
70598 struct cred;
70599diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
70600index 68a04a3..866e6a1 100644
70601--- a/include/linux/seq_file.h
70602+++ b/include/linux/seq_file.h
70603@@ -26,6 +26,9 @@ struct seq_file {
70604 struct mutex lock;
70605 const struct seq_operations *op;
70606 int poll_event;
70607+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70608+ u64 exec_id;
70609+#endif
70610 #ifdef CONFIG_USER_NS
70611 struct user_namespace *user_ns;
70612 #endif
70613@@ -38,6 +41,7 @@ struct seq_operations {
70614 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
70615 int (*show) (struct seq_file *m, void *v);
70616 };
70617+typedef struct seq_operations __no_const seq_operations_no_const;
70618
70619 #define SEQ_SKIP 1
70620
70621diff --git a/include/linux/shm.h b/include/linux/shm.h
70622index 429c199..4d42e38 100644
70623--- a/include/linux/shm.h
70624+++ b/include/linux/shm.h
70625@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
70626
70627 /* The task created the shm object. NULL if the task is dead. */
70628 struct task_struct *shm_creator;
70629+#ifdef CONFIG_GRKERNSEC
70630+ time_t shm_createtime;
70631+ pid_t shm_lapid;
70632+#endif
70633 };
70634
70635 /* shm_mode upper byte flags */
70636diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
70637index 320e976..fd52553 100644
70638--- a/include/linux/skbuff.h
70639+++ b/include/linux/skbuff.h
70640@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
70641 extern struct sk_buff *__alloc_skb(unsigned int size,
70642 gfp_t priority, int flags, int node);
70643 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
70644-static inline struct sk_buff *alloc_skb(unsigned int size,
70645+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
70646 gfp_t priority)
70647 {
70648 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
70649@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
70650 */
70651 static inline int skb_queue_empty(const struct sk_buff_head *list)
70652 {
70653- return list->next == (struct sk_buff *)list;
70654+ return list->next == (const struct sk_buff *)list;
70655 }
70656
70657 /**
70658@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
70659 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70660 const struct sk_buff *skb)
70661 {
70662- return skb->next == (struct sk_buff *)list;
70663+ return skb->next == (const struct sk_buff *)list;
70664 }
70665
70666 /**
70667@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70668 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
70669 const struct sk_buff *skb)
70670 {
70671- return skb->prev == (struct sk_buff *)list;
70672+ return skb->prev == (const struct sk_buff *)list;
70673 }
70674
70675 /**
70676@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
70677 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
70678 */
70679 #ifndef NET_SKB_PAD
70680-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
70681+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
70682 #endif
70683
70684 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
70685@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
70686 int noblock, int *err);
70687 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
70688 struct poll_table_struct *wait);
70689-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
70690+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
70691 int offset, struct iovec *to,
70692 int size);
70693 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
70694diff --git a/include/linux/slab.h b/include/linux/slab.h
70695index 5d168d7..720bff3 100644
70696--- a/include/linux/slab.h
70697+++ b/include/linux/slab.h
70698@@ -12,13 +12,20 @@
70699 #include <linux/gfp.h>
70700 #include <linux/types.h>
70701 #include <linux/workqueue.h>
70702-
70703+#include <linux/err.h>
70704
70705 /*
70706 * Flags to pass to kmem_cache_create().
70707 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
70708 */
70709 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
70710+
70711+#ifdef CONFIG_PAX_USERCOPY_SLABS
70712+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
70713+#else
70714+#define SLAB_USERCOPY 0x00000000UL
70715+#endif
70716+
70717 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70718 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70719 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70720@@ -89,10 +96,13 @@
70721 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70722 * Both make kfree a no-op.
70723 */
70724-#define ZERO_SIZE_PTR ((void *)16)
70725+#define ZERO_SIZE_PTR \
70726+({ \
70727+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70728+ (void *)(-MAX_ERRNO-1L); \
70729+})
70730
70731-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70732- (unsigned long)ZERO_SIZE_PTR)
70733+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70734
70735 /*
70736 * Common fields provided in kmem_cache by all slab allocators
70737@@ -112,7 +122,7 @@ struct kmem_cache {
70738 unsigned int align; /* Alignment as calculated */
70739 unsigned long flags; /* Active flags on the slab */
70740 const char *name; /* Slab name for sysfs */
70741- int refcount; /* Use counter */
70742+ atomic_t refcount; /* Use counter */
70743 void (*ctor)(void *); /* Called on object slot creation */
70744 struct list_head list; /* List of all slab caches on the system */
70745 };
70746@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70747 void kfree(const void *);
70748 void kzfree(const void *);
70749 size_t ksize(const void *);
70750+const char *check_heap_object(const void *ptr, unsigned long n);
70751+bool is_usercopy_object(const void *ptr);
70752
70753 /*
70754 * Allocator specific definitions. These are mainly used to establish optimized
70755@@ -311,6 +323,7 @@ size_t ksize(const void *);
70756 * for general use, and so are not documented here. For a full list of
70757 * potential flags, always refer to linux/gfp.h.
70758 */
70759+
70760 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70761 {
70762 if (size != 0 && n > SIZE_MAX / size)
70763@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70764 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70765 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70766 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70767-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70768+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70769 #define kmalloc_track_caller(size, flags) \
70770 __kmalloc_track_caller(size, flags, _RET_IP_)
70771 #else
70772@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70773 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70774 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70775 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70776-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70777+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70778 #define kmalloc_node_track_caller(size, flags, node) \
70779 __kmalloc_node_track_caller(size, flags, node, \
70780 _RET_IP_)
70781diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70782index 8bb6e0e..8eb0dbe 100644
70783--- a/include/linux/slab_def.h
70784+++ b/include/linux/slab_def.h
70785@@ -52,7 +52,7 @@ struct kmem_cache {
70786 /* 4) cache creation/removal */
70787 const char *name;
70788 struct list_head list;
70789- int refcount;
70790+ atomic_t refcount;
70791 int object_size;
70792 int align;
70793
70794@@ -68,10 +68,10 @@ struct kmem_cache {
70795 unsigned long node_allocs;
70796 unsigned long node_frees;
70797 unsigned long node_overflow;
70798- atomic_t allochit;
70799- atomic_t allocmiss;
70800- atomic_t freehit;
70801- atomic_t freemiss;
70802+ atomic_unchecked_t allochit;
70803+ atomic_unchecked_t allocmiss;
70804+ atomic_unchecked_t freehit;
70805+ atomic_unchecked_t freemiss;
70806
70807 /*
70808 * If debugging is enabled, then the allocator can add additional
70809@@ -111,11 +111,16 @@ struct cache_sizes {
70810 #ifdef CONFIG_ZONE_DMA
70811 struct kmem_cache *cs_dmacachep;
70812 #endif
70813+
70814+#ifdef CONFIG_PAX_USERCOPY_SLABS
70815+ struct kmem_cache *cs_usercopycachep;
70816+#endif
70817+
70818 };
70819 extern struct cache_sizes malloc_sizes[];
70820
70821 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70822-void *__kmalloc(size_t size, gfp_t flags);
70823+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70824
70825 #ifdef CONFIG_TRACING
70826 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70827@@ -152,6 +157,13 @@ found:
70828 cachep = malloc_sizes[i].cs_dmacachep;
70829 else
70830 #endif
70831+
70832+#ifdef CONFIG_PAX_USERCOPY_SLABS
70833+ if (flags & GFP_USERCOPY)
70834+ cachep = malloc_sizes[i].cs_usercopycachep;
70835+ else
70836+#endif
70837+
70838 cachep = malloc_sizes[i].cs_cachep;
70839
70840 ret = kmem_cache_alloc_trace(cachep, flags, size);
70841@@ -162,7 +174,7 @@ found:
70842 }
70843
70844 #ifdef CONFIG_NUMA
70845-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70846+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70847 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70848
70849 #ifdef CONFIG_TRACING
70850@@ -205,6 +217,13 @@ found:
70851 cachep = malloc_sizes[i].cs_dmacachep;
70852 else
70853 #endif
70854+
70855+#ifdef CONFIG_PAX_USERCOPY_SLABS
70856+ if (flags & GFP_USERCOPY)
70857+ cachep = malloc_sizes[i].cs_usercopycachep;
70858+ else
70859+#endif
70860+
70861 cachep = malloc_sizes[i].cs_cachep;
70862
70863 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70864diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70865index f28e14a..7831211 100644
70866--- a/include/linux/slob_def.h
70867+++ b/include/linux/slob_def.h
70868@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70869 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70870 }
70871
70872-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70873+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70874
70875 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70876 {
70877@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70878 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70879 }
70880
70881-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70882+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70883 {
70884 return kmalloc(size, flags);
70885 }
70886diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70887index 9db4825..ed42fb5 100644
70888--- a/include/linux/slub_def.h
70889+++ b/include/linux/slub_def.h
70890@@ -91,7 +91,7 @@ struct kmem_cache {
70891 struct kmem_cache_order_objects max;
70892 struct kmem_cache_order_objects min;
70893 gfp_t allocflags; /* gfp flags to use on each alloc */
70894- int refcount; /* Refcount for slab cache destroy */
70895+ atomic_t refcount; /* Refcount for slab cache destroy */
70896 void (*ctor)(void *);
70897 int inuse; /* Offset to metadata */
70898 int align; /* Alignment */
70899@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70900 * Sorry that the following has to be that ugly but some versions of GCC
70901 * have trouble with constant propagation and loops.
70902 */
70903-static __always_inline int kmalloc_index(size_t size)
70904+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70905 {
70906 if (!size)
70907 return 0;
70908@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70909 }
70910
70911 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70912-void *__kmalloc(size_t size, gfp_t flags);
70913+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70914
70915 static __always_inline void *
70916 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70917@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70918 }
70919 #endif
70920
70921-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70922+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70923 {
70924 unsigned int order = get_order(size);
70925 return kmalloc_order_trace(size, flags, order);
70926@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70927 }
70928
70929 #ifdef CONFIG_NUMA
70930-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70931+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70932 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70933
70934 #ifdef CONFIG_TRACING
70935diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70936index e8d702e..0a56eb4 100644
70937--- a/include/linux/sock_diag.h
70938+++ b/include/linux/sock_diag.h
70939@@ -10,7 +10,7 @@ struct sock;
70940 struct sock_diag_handler {
70941 __u8 family;
70942 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70943-};
70944+} __do_const;
70945
70946 int sock_diag_register(const struct sock_diag_handler *h);
70947 void sock_diag_unregister(const struct sock_diag_handler *h);
70948diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70949index 680f9a3..f13aeb0 100644
70950--- a/include/linux/sonet.h
70951+++ b/include/linux/sonet.h
70952@@ -7,7 +7,7 @@
70953 #include <uapi/linux/sonet.h>
70954
70955 struct k_sonet_stats {
70956-#define __HANDLE_ITEM(i) atomic_t i
70957+#define __HANDLE_ITEM(i) atomic_unchecked_t i
70958 __SONET_ITEMS
70959 #undef __HANDLE_ITEM
70960 };
70961diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70962index 34206b8..3db7f1c 100644
70963--- a/include/linux/sunrpc/clnt.h
70964+++ b/include/linux/sunrpc/clnt.h
70965@@ -96,7 +96,7 @@ struct rpc_procinfo {
70966 unsigned int p_timer; /* Which RTT timer to use */
70967 u32 p_statidx; /* Which procedure to account */
70968 const char * p_name; /* name of procedure */
70969-};
70970+} __do_const;
70971
70972 #ifdef __KERNEL__
70973
70974@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70975 {
70976 switch (sap->sa_family) {
70977 case AF_INET:
70978- return ntohs(((struct sockaddr_in *)sap)->sin_port);
70979+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70980 case AF_INET6:
70981- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70982+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70983 }
70984 return 0;
70985 }
70986@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70987 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70988 const struct sockaddr *src)
70989 {
70990- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70991+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
70992 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
70993
70994 dsin->sin_family = ssin->sin_family;
70995@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
70996 if (sa->sa_family != AF_INET6)
70997 return 0;
70998
70999- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
71000+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
71001 }
71002
71003 #endif /* __KERNEL__ */
71004diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
71005index 676ddf5..4c519a1 100644
71006--- a/include/linux/sunrpc/svc.h
71007+++ b/include/linux/sunrpc/svc.h
71008@@ -410,7 +410,7 @@ struct svc_procedure {
71009 unsigned int pc_count; /* call count */
71010 unsigned int pc_cachetype; /* cache info (NFS) */
71011 unsigned int pc_xdrressize; /* maximum size of XDR reply */
71012-};
71013+} __do_const;
71014
71015 /*
71016 * Function prototypes.
71017diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
71018index 0b8e3e6..33e0a01 100644
71019--- a/include/linux/sunrpc/svc_rdma.h
71020+++ b/include/linux/sunrpc/svc_rdma.h
71021@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
71022 extern unsigned int svcrdma_max_requests;
71023 extern unsigned int svcrdma_max_req_size;
71024
71025-extern atomic_t rdma_stat_recv;
71026-extern atomic_t rdma_stat_read;
71027-extern atomic_t rdma_stat_write;
71028-extern atomic_t rdma_stat_sq_starve;
71029-extern atomic_t rdma_stat_rq_starve;
71030-extern atomic_t rdma_stat_rq_poll;
71031-extern atomic_t rdma_stat_rq_prod;
71032-extern atomic_t rdma_stat_sq_poll;
71033-extern atomic_t rdma_stat_sq_prod;
71034+extern atomic_unchecked_t rdma_stat_recv;
71035+extern atomic_unchecked_t rdma_stat_read;
71036+extern atomic_unchecked_t rdma_stat_write;
71037+extern atomic_unchecked_t rdma_stat_sq_starve;
71038+extern atomic_unchecked_t rdma_stat_rq_starve;
71039+extern atomic_unchecked_t rdma_stat_rq_poll;
71040+extern atomic_unchecked_t rdma_stat_rq_prod;
71041+extern atomic_unchecked_t rdma_stat_sq_poll;
71042+extern atomic_unchecked_t rdma_stat_sq_prod;
71043
71044 #define RPCRDMA_VERSION 1
71045
71046diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
71047index dd74084a..7f509d5 100644
71048--- a/include/linux/sunrpc/svcauth.h
71049+++ b/include/linux/sunrpc/svcauth.h
71050@@ -109,7 +109,7 @@ struct auth_ops {
71051 int (*release)(struct svc_rqst *rq);
71052 void (*domain_release)(struct auth_domain *);
71053 int (*set_client)(struct svc_rqst *rq);
71054-};
71055+} __do_const;
71056
71057 #define SVC_GARBAGE 1
71058 #define SVC_SYSERR 2
71059diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
71060index 071d62c..4ccc7ac 100644
71061--- a/include/linux/swiotlb.h
71062+++ b/include/linux/swiotlb.h
71063@@ -59,7 +59,8 @@ extern void
71064
71065 extern void
71066 swiotlb_free_coherent(struct device *hwdev, size_t size,
71067- void *vaddr, dma_addr_t dma_handle);
71068+ void *vaddr, dma_addr_t dma_handle,
71069+ struct dma_attrs *attrs);
71070
71071 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
71072 unsigned long offset, size_t size,
71073diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
71074index 27b3b0b..e093dd9 100644
71075--- a/include/linux/syscore_ops.h
71076+++ b/include/linux/syscore_ops.h
71077@@ -16,7 +16,7 @@ struct syscore_ops {
71078 int (*suspend)(void);
71079 void (*resume)(void);
71080 void (*shutdown)(void);
71081-};
71082+} __do_const;
71083
71084 extern void register_syscore_ops(struct syscore_ops *ops);
71085 extern void unregister_syscore_ops(struct syscore_ops *ops);
71086diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
71087index 14a8ff2..af52bad 100644
71088--- a/include/linux/sysctl.h
71089+++ b/include/linux/sysctl.h
71090@@ -34,13 +34,13 @@ struct ctl_table_root;
71091 struct ctl_table_header;
71092 struct ctl_dir;
71093
71094-typedef struct ctl_table ctl_table;
71095-
71096 typedef int proc_handler (struct ctl_table *ctl, int write,
71097 void __user *buffer, size_t *lenp, loff_t *ppos);
71098
71099 extern int proc_dostring(struct ctl_table *, int,
71100 void __user *, size_t *, loff_t *);
71101+extern int proc_dostring_modpriv(struct ctl_table *, int,
71102+ void __user *, size_t *, loff_t *);
71103 extern int proc_dointvec(struct ctl_table *, int,
71104 void __user *, size_t *, loff_t *);
71105 extern int proc_dointvec_minmax(struct ctl_table *, int,
71106@@ -115,7 +115,9 @@ struct ctl_table
71107 struct ctl_table_poll *poll;
71108 void *extra1;
71109 void *extra2;
71110-};
71111+} __do_const;
71112+typedef struct ctl_table __no_const ctl_table_no_const;
71113+typedef struct ctl_table ctl_table;
71114
71115 struct ctl_node {
71116 struct rb_node node;
71117diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
71118index 381f06d..dc16cc7 100644
71119--- a/include/linux/sysfs.h
71120+++ b/include/linux/sysfs.h
71121@@ -31,7 +31,8 @@ struct attribute {
71122 struct lock_class_key *key;
71123 struct lock_class_key skey;
71124 #endif
71125-};
71126+} __do_const;
71127+typedef struct attribute __no_const attribute_no_const;
71128
71129 /**
71130 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
71131@@ -59,8 +60,8 @@ struct attribute_group {
71132 umode_t (*is_visible)(struct kobject *,
71133 struct attribute *, int);
71134 struct attribute **attrs;
71135-};
71136-
71137+} __do_const;
71138+typedef struct attribute_group __no_const attribute_group_no_const;
71139
71140
71141 /**
71142@@ -107,7 +108,8 @@ struct bin_attribute {
71143 char *, loff_t, size_t);
71144 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
71145 struct vm_area_struct *vma);
71146-};
71147+} __do_const;
71148+typedef struct bin_attribute __no_const bin_attribute_no_const;
71149
71150 /**
71151 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
71152diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
71153index 7faf933..4657127 100644
71154--- a/include/linux/sysrq.h
71155+++ b/include/linux/sysrq.h
71156@@ -15,7 +15,9 @@
71157 #define _LINUX_SYSRQ_H
71158
71159 #include <linux/errno.h>
71160+#include <linux/compiler.h>
71161 #include <linux/types.h>
71162+#include <linux/compiler.h>
71163
71164 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
71165 #define SYSRQ_DEFAULT_ENABLE 1
71166@@ -36,7 +38,7 @@ struct sysrq_key_op {
71167 char *help_msg;
71168 char *action_msg;
71169 int enable_mask;
71170-};
71171+} __do_const;
71172
71173 #ifdef CONFIG_MAGIC_SYSRQ
71174
71175diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
71176index e7e0473..39b7b52 100644
71177--- a/include/linux/thread_info.h
71178+++ b/include/linux/thread_info.h
71179@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
71180 #error "no set_restore_sigmask() provided and default one won't work"
71181 #endif
71182
71183+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
71184+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
71185+{
71186+#ifndef CONFIG_PAX_USERCOPY_DEBUG
71187+ if (!__builtin_constant_p(n))
71188+#endif
71189+ __check_object_size(ptr, n, to);
71190+}
71191+
71192 #endif /* __KERNEL__ */
71193
71194 #endif /* _LINUX_THREAD_INFO_H */
71195diff --git a/include/linux/tty.h b/include/linux/tty.h
71196index 8db1b56..c16a040 100644
71197--- a/include/linux/tty.h
71198+++ b/include/linux/tty.h
71199@@ -194,7 +194,7 @@ struct tty_port {
71200 const struct tty_port_operations *ops; /* Port operations */
71201 spinlock_t lock; /* Lock protecting tty field */
71202 int blocked_open; /* Waiting to open */
71203- int count; /* Usage count */
71204+ atomic_t count; /* Usage count */
71205 wait_queue_head_t open_wait; /* Open waiters */
71206 wait_queue_head_t close_wait; /* Close waiters */
71207 wait_queue_head_t delta_msr_wait; /* Modem status change */
71208@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
71209 struct tty_struct *tty, struct file *filp);
71210 static inline int tty_port_users(struct tty_port *port)
71211 {
71212- return port->count + port->blocked_open;
71213+ return atomic_read(&port->count) + port->blocked_open;
71214 }
71215
71216 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
71217diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
71218index dd976cf..e272742 100644
71219--- a/include/linux/tty_driver.h
71220+++ b/include/linux/tty_driver.h
71221@@ -284,7 +284,7 @@ struct tty_operations {
71222 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
71223 #endif
71224 const struct file_operations *proc_fops;
71225-};
71226+} __do_const;
71227
71228 struct tty_driver {
71229 int magic; /* magic number for this structure */
71230diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
71231index fb79dd8d..07d4773 100644
71232--- a/include/linux/tty_ldisc.h
71233+++ b/include/linux/tty_ldisc.h
71234@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
71235
71236 struct module *owner;
71237
71238- int refcount;
71239+ atomic_t refcount;
71240 };
71241
71242 struct tty_ldisc {
71243diff --git a/include/linux/types.h b/include/linux/types.h
71244index 4d118ba..c3ee9bf 100644
71245--- a/include/linux/types.h
71246+++ b/include/linux/types.h
71247@@ -176,10 +176,26 @@ typedef struct {
71248 int counter;
71249 } atomic_t;
71250
71251+#ifdef CONFIG_PAX_REFCOUNT
71252+typedef struct {
71253+ int counter;
71254+} atomic_unchecked_t;
71255+#else
71256+typedef atomic_t atomic_unchecked_t;
71257+#endif
71258+
71259 #ifdef CONFIG_64BIT
71260 typedef struct {
71261 long counter;
71262 } atomic64_t;
71263+
71264+#ifdef CONFIG_PAX_REFCOUNT
71265+typedef struct {
71266+ long counter;
71267+} atomic64_unchecked_t;
71268+#else
71269+typedef atomic64_t atomic64_unchecked_t;
71270+#endif
71271 #endif
71272
71273 struct list_head {
71274diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
71275index 5ca0951..ab496a5 100644
71276--- a/include/linux/uaccess.h
71277+++ b/include/linux/uaccess.h
71278@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
71279 long ret; \
71280 mm_segment_t old_fs = get_fs(); \
71281 \
71282- set_fs(KERNEL_DS); \
71283 pagefault_disable(); \
71284- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
71285- pagefault_enable(); \
71286+ set_fs(KERNEL_DS); \
71287+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
71288 set_fs(old_fs); \
71289+ pagefault_enable(); \
71290 ret; \
71291 })
71292
71293diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
71294index 8e522cbc..aa8572d 100644
71295--- a/include/linux/uidgid.h
71296+++ b/include/linux/uidgid.h
71297@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
71298
71299 #endif /* CONFIG_USER_NS */
71300
71301+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
71302+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
71303+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
71304+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
71305+
71306 #endif /* _LINUX_UIDGID_H */
71307diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
71308index 99c1b4d..562e6f3 100644
71309--- a/include/linux/unaligned/access_ok.h
71310+++ b/include/linux/unaligned/access_ok.h
71311@@ -4,34 +4,34 @@
71312 #include <linux/kernel.h>
71313 #include <asm/byteorder.h>
71314
71315-static inline u16 get_unaligned_le16(const void *p)
71316+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
71317 {
71318- return le16_to_cpup((__le16 *)p);
71319+ return le16_to_cpup((const __le16 *)p);
71320 }
71321
71322-static inline u32 get_unaligned_le32(const void *p)
71323+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
71324 {
71325- return le32_to_cpup((__le32 *)p);
71326+ return le32_to_cpup((const __le32 *)p);
71327 }
71328
71329-static inline u64 get_unaligned_le64(const void *p)
71330+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
71331 {
71332- return le64_to_cpup((__le64 *)p);
71333+ return le64_to_cpup((const __le64 *)p);
71334 }
71335
71336-static inline u16 get_unaligned_be16(const void *p)
71337+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
71338 {
71339- return be16_to_cpup((__be16 *)p);
71340+ return be16_to_cpup((const __be16 *)p);
71341 }
71342
71343-static inline u32 get_unaligned_be32(const void *p)
71344+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
71345 {
71346- return be32_to_cpup((__be32 *)p);
71347+ return be32_to_cpup((const __be32 *)p);
71348 }
71349
71350-static inline u64 get_unaligned_be64(const void *p)
71351+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
71352 {
71353- return be64_to_cpup((__be64 *)p);
71354+ return be64_to_cpup((const __be64 *)p);
71355 }
71356
71357 static inline void put_unaligned_le16(u16 val, void *p)
71358diff --git a/include/linux/usb.h b/include/linux/usb.h
71359index 4d22d0f..8d0e8f8 100644
71360--- a/include/linux/usb.h
71361+++ b/include/linux/usb.h
71362@@ -554,7 +554,7 @@ struct usb_device {
71363 int maxchild;
71364
71365 u32 quirks;
71366- atomic_t urbnum;
71367+ atomic_unchecked_t urbnum;
71368
71369 unsigned long active_duration;
71370
71371@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
71372
71373 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
71374 __u8 request, __u8 requesttype, __u16 value, __u16 index,
71375- void *data, __u16 size, int timeout);
71376+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
71377 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
71378 void *data, int len, int *actual_length, int timeout);
71379 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
71380diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
71381index c5d36c6..108f4f9 100644
71382--- a/include/linux/usb/renesas_usbhs.h
71383+++ b/include/linux/usb/renesas_usbhs.h
71384@@ -39,7 +39,7 @@ enum {
71385 */
71386 struct renesas_usbhs_driver_callback {
71387 int (*notify_hotplug)(struct platform_device *pdev);
71388-};
71389+} __no_const;
71390
71391 /*
71392 * callback functions for platform
71393diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
71394index b9bd2e6..4ce0093 100644
71395--- a/include/linux/user_namespace.h
71396+++ b/include/linux/user_namespace.h
71397@@ -21,7 +21,7 @@ struct user_namespace {
71398 struct uid_gid_map uid_map;
71399 struct uid_gid_map gid_map;
71400 struct uid_gid_map projid_map;
71401- struct kref kref;
71402+ atomic_t count;
71403 struct user_namespace *parent;
71404 kuid_t owner;
71405 kgid_t group;
71406@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
71407 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
71408 {
71409 if (ns)
71410- kref_get(&ns->kref);
71411+ atomic_inc(&ns->count);
71412 return ns;
71413 }
71414
71415 extern int create_user_ns(struct cred *new);
71416 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
71417-extern void free_user_ns(struct kref *kref);
71418+extern void free_user_ns(struct user_namespace *ns);
71419
71420 static inline void put_user_ns(struct user_namespace *ns)
71421 {
71422- if (ns)
71423- kref_put(&ns->kref, free_user_ns);
71424+ if (ns && atomic_dec_and_test(&ns->count))
71425+ free_user_ns(ns);
71426 }
71427
71428 struct seq_operations;
71429diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
71430index 6f8fbcf..8259001 100644
71431--- a/include/linux/vermagic.h
71432+++ b/include/linux/vermagic.h
71433@@ -25,9 +25,35 @@
71434 #define MODULE_ARCH_VERMAGIC ""
71435 #endif
71436
71437+#ifdef CONFIG_PAX_REFCOUNT
71438+#define MODULE_PAX_REFCOUNT "REFCOUNT "
71439+#else
71440+#define MODULE_PAX_REFCOUNT ""
71441+#endif
71442+
71443+#ifdef CONSTIFY_PLUGIN
71444+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
71445+#else
71446+#define MODULE_CONSTIFY_PLUGIN ""
71447+#endif
71448+
71449+#ifdef STACKLEAK_PLUGIN
71450+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
71451+#else
71452+#define MODULE_STACKLEAK_PLUGIN ""
71453+#endif
71454+
71455+#ifdef CONFIG_GRKERNSEC
71456+#define MODULE_GRSEC "GRSEC "
71457+#else
71458+#define MODULE_GRSEC ""
71459+#endif
71460+
71461 #define VERMAGIC_STRING \
71462 UTS_RELEASE " " \
71463 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
71464 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
71465- MODULE_ARCH_VERMAGIC
71466+ MODULE_ARCH_VERMAGIC \
71467+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
71468+ MODULE_GRSEC
71469
71470diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
71471index 6071e91..ca6a489 100644
71472--- a/include/linux/vmalloc.h
71473+++ b/include/linux/vmalloc.h
71474@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
71475 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
71476 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
71477 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
71478+
71479+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71480+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
71481+#endif
71482+
71483 /* bits [20..32] reserved for arch specific ioremap internals */
71484
71485 /*
71486@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
71487 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
71488 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
71489 unsigned long start, unsigned long end, gfp_t gfp_mask,
71490- pgprot_t prot, int node, const void *caller);
71491+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
71492 extern void vfree(const void *addr);
71493
71494 extern void *vmap(struct page **pages, unsigned int count,
71495@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
71496 extern void free_vm_area(struct vm_struct *area);
71497
71498 /* for /dev/kmem */
71499-extern long vread(char *buf, char *addr, unsigned long count);
71500-extern long vwrite(char *buf, char *addr, unsigned long count);
71501+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
71502+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
71503
71504 /*
71505 * Internals. Dont't use..
71506diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
71507index a13291f..af51fa3 100644
71508--- a/include/linux/vmstat.h
71509+++ b/include/linux/vmstat.h
71510@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
71511 /*
71512 * Zone based page accounting with per cpu differentials.
71513 */
71514-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71515+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71516
71517 static inline void zone_page_state_add(long x, struct zone *zone,
71518 enum zone_stat_item item)
71519 {
71520- atomic_long_add(x, &zone->vm_stat[item]);
71521- atomic_long_add(x, &vm_stat[item]);
71522+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
71523+ atomic_long_add_unchecked(x, &vm_stat[item]);
71524 }
71525
71526 static inline unsigned long global_page_state(enum zone_stat_item item)
71527 {
71528- long x = atomic_long_read(&vm_stat[item]);
71529+ long x = atomic_long_read_unchecked(&vm_stat[item]);
71530 #ifdef CONFIG_SMP
71531 if (x < 0)
71532 x = 0;
71533@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
71534 static inline unsigned long zone_page_state(struct zone *zone,
71535 enum zone_stat_item item)
71536 {
71537- long x = atomic_long_read(&zone->vm_stat[item]);
71538+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71539 #ifdef CONFIG_SMP
71540 if (x < 0)
71541 x = 0;
71542@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
71543 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
71544 enum zone_stat_item item)
71545 {
71546- long x = atomic_long_read(&zone->vm_stat[item]);
71547+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71548
71549 #ifdef CONFIG_SMP
71550 int cpu;
71551@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
71552
71553 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
71554 {
71555- atomic_long_inc(&zone->vm_stat[item]);
71556- atomic_long_inc(&vm_stat[item]);
71557+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
71558+ atomic_long_inc_unchecked(&vm_stat[item]);
71559 }
71560
71561 static inline void __inc_zone_page_state(struct page *page,
71562@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
71563
71564 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
71565 {
71566- atomic_long_dec(&zone->vm_stat[item]);
71567- atomic_long_dec(&vm_stat[item]);
71568+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
71569+ atomic_long_dec_unchecked(&vm_stat[item]);
71570 }
71571
71572 static inline void __dec_zone_page_state(struct page *page,
71573diff --git a/include/linux/xattr.h b/include/linux/xattr.h
71574index fdbafc6..b7ffd47 100644
71575--- a/include/linux/xattr.h
71576+++ b/include/linux/xattr.h
71577@@ -28,7 +28,7 @@ struct xattr_handler {
71578 size_t size, int handler_flags);
71579 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
71580 size_t size, int flags, int handler_flags);
71581-};
71582+} __do_const;
71583
71584 struct xattr {
71585 char *name;
71586diff --git a/include/linux/zlib.h b/include/linux/zlib.h
71587index 9c5a6b4..09c9438 100644
71588--- a/include/linux/zlib.h
71589+++ b/include/linux/zlib.h
71590@@ -31,6 +31,7 @@
71591 #define _ZLIB_H
71592
71593 #include <linux/zconf.h>
71594+#include <linux/compiler.h>
71595
71596 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
71597 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
71598@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
71599
71600 /* basic functions */
71601
71602-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
71603+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
71604 /*
71605 Returns the number of bytes that needs to be allocated for a per-
71606 stream workspace with the specified parameters. A pointer to this
71607diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
71608index 95d1c91..6798cca 100644
71609--- a/include/media/v4l2-dev.h
71610+++ b/include/media/v4l2-dev.h
71611@@ -76,7 +76,7 @@ struct v4l2_file_operations {
71612 int (*mmap) (struct file *, struct vm_area_struct *);
71613 int (*open) (struct file *);
71614 int (*release) (struct file *);
71615-};
71616+} __do_const;
71617
71618 /*
71619 * Newer version of video_device, handled by videodev2.c
71620diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
71621index 4118ad1..cb7e25f 100644
71622--- a/include/media/v4l2-ioctl.h
71623+++ b/include/media/v4l2-ioctl.h
71624@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
71625 bool valid_prio, int cmd, void *arg);
71626 };
71627
71628-
71629 /* v4l debugging and diagnostics */
71630
71631 /* Debug bitmask flags to be used on V4L2 */
71632diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
71633index adcbb20..62c2559 100644
71634--- a/include/net/9p/transport.h
71635+++ b/include/net/9p/transport.h
71636@@ -57,7 +57,7 @@ struct p9_trans_module {
71637 int (*cancel) (struct p9_client *, struct p9_req_t *req);
71638 int (*zc_request)(struct p9_client *, struct p9_req_t *,
71639 char *, char *, int , int, int, int);
71640-};
71641+} __do_const;
71642
71643 void v9fs_register_trans(struct p9_trans_module *m);
71644 void v9fs_unregister_trans(struct p9_trans_module *m);
71645diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
71646index 7588ef4..e62d35f 100644
71647--- a/include/net/bluetooth/l2cap.h
71648+++ b/include/net/bluetooth/l2cap.h
71649@@ -552,7 +552,7 @@ struct l2cap_ops {
71650 void (*defer) (struct l2cap_chan *chan);
71651 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
71652 unsigned long len, int nb);
71653-};
71654+} __do_const;
71655
71656 struct l2cap_conn {
71657 struct hci_conn *hcon;
71658diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
71659index 9e5425b..8136ffc 100644
71660--- a/include/net/caif/cfctrl.h
71661+++ b/include/net/caif/cfctrl.h
71662@@ -52,7 +52,7 @@ struct cfctrl_rsp {
71663 void (*radioset_rsp)(void);
71664 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
71665 struct cflayer *client_layer);
71666-};
71667+} __no_const;
71668
71669 /* Link Setup Parameters for CAIF-Links. */
71670 struct cfctrl_link_param {
71671@@ -101,8 +101,8 @@ struct cfctrl_request_info {
71672 struct cfctrl {
71673 struct cfsrvl serv;
71674 struct cfctrl_rsp res;
71675- atomic_t req_seq_no;
71676- atomic_t rsp_seq_no;
71677+ atomic_unchecked_t req_seq_no;
71678+ atomic_unchecked_t rsp_seq_no;
71679 struct list_head list;
71680 /* Protects from simultaneous access to first_req list */
71681 spinlock_t info_list_lock;
71682diff --git a/include/net/flow.h b/include/net/flow.h
71683index 628e11b..4c475df 100644
71684--- a/include/net/flow.h
71685+++ b/include/net/flow.h
71686@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
71687
71688 extern void flow_cache_flush(void);
71689 extern void flow_cache_flush_deferred(void);
71690-extern atomic_t flow_cache_genid;
71691+extern atomic_unchecked_t flow_cache_genid;
71692
71693 #endif
71694diff --git a/include/net/genetlink.h b/include/net/genetlink.h
71695index bdfbe68..4402ebe 100644
71696--- a/include/net/genetlink.h
71697+++ b/include/net/genetlink.h
71698@@ -118,7 +118,7 @@ struct genl_ops {
71699 struct netlink_callback *cb);
71700 int (*done)(struct netlink_callback *cb);
71701 struct list_head ops_list;
71702-};
71703+} __do_const;
71704
71705 extern int genl_register_family(struct genl_family *family);
71706 extern int genl_register_family_with_ops(struct genl_family *family,
71707diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
71708index e5062c9..48a9a4b 100644
71709--- a/include/net/gro_cells.h
71710+++ b/include/net/gro_cells.h
71711@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
71712 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
71713
71714 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
71715- atomic_long_inc(&dev->rx_dropped);
71716+ atomic_long_inc_unchecked(&dev->rx_dropped);
71717 kfree_skb(skb);
71718 return;
71719 }
71720@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
71721 int i;
71722
71723 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
71724- gcells->cells = kcalloc(sizeof(struct gro_cell),
71725- gcells->gro_cells_mask + 1,
71726+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
71727+ sizeof(struct gro_cell),
71728 GFP_KERNEL);
71729 if (!gcells->cells)
71730 return -ENOMEM;
71731diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
71732index 1832927..ce39aea 100644
71733--- a/include/net/inet_connection_sock.h
71734+++ b/include/net/inet_connection_sock.h
71735@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
71736 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
71737 int (*bind_conflict)(const struct sock *sk,
71738 const struct inet_bind_bucket *tb, bool relax);
71739-};
71740+} __do_const;
71741
71742 /** inet_connection_sock - INET connection oriented sock
71743 *
71744diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
71745index 53f464d..ba76aaa 100644
71746--- a/include/net/inetpeer.h
71747+++ b/include/net/inetpeer.h
71748@@ -47,8 +47,8 @@ struct inet_peer {
71749 */
71750 union {
71751 struct {
71752- atomic_t rid; /* Frag reception counter */
71753- atomic_t ip_id_count; /* IP ID for the next packet */
71754+ atomic_unchecked_t rid; /* Frag reception counter */
71755+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71756 };
71757 struct rcu_head rcu;
71758 struct inet_peer *gc_next;
71759@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71760 more++;
71761 inet_peer_refcheck(p);
71762 do {
71763- old = atomic_read(&p->ip_id_count);
71764+ old = atomic_read_unchecked(&p->ip_id_count);
71765 new = old + more;
71766 if (!new)
71767 new = 1;
71768- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71769+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71770 return new;
71771 }
71772
71773diff --git a/include/net/ip.h b/include/net/ip.h
71774index a68f838..74518ab 100644
71775--- a/include/net/ip.h
71776+++ b/include/net/ip.h
71777@@ -202,7 +202,7 @@ extern struct local_ports {
71778 } sysctl_local_ports;
71779 extern void inet_get_local_port_range(int *low, int *high);
71780
71781-extern unsigned long *sysctl_local_reserved_ports;
71782+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71783 static inline int inet_is_reserved_local_port(int port)
71784 {
71785 return test_bit(port, sysctl_local_reserved_ports);
71786diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71787index 9497be1..5a4fafe 100644
71788--- a/include/net/ip_fib.h
71789+++ b/include/net/ip_fib.h
71790@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71791
71792 #define FIB_RES_SADDR(net, res) \
71793 ((FIB_RES_NH(res).nh_saddr_genid == \
71794- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71795+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71796 FIB_RES_NH(res).nh_saddr : \
71797 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71798 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71799diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71800index 68c69d5..bdab192 100644
71801--- a/include/net/ip_vs.h
71802+++ b/include/net/ip_vs.h
71803@@ -599,7 +599,7 @@ struct ip_vs_conn {
71804 struct ip_vs_conn *control; /* Master control connection */
71805 atomic_t n_control; /* Number of controlled ones */
71806 struct ip_vs_dest *dest; /* real server */
71807- atomic_t in_pkts; /* incoming packet counter */
71808+ atomic_unchecked_t in_pkts; /* incoming packet counter */
71809
71810 /* packet transmitter for different forwarding methods. If it
71811 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71812@@ -737,7 +737,7 @@ struct ip_vs_dest {
71813 __be16 port; /* port number of the server */
71814 union nf_inet_addr addr; /* IP address of the server */
71815 volatile unsigned int flags; /* dest status flags */
71816- atomic_t conn_flags; /* flags to copy to conn */
71817+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
71818 atomic_t weight; /* server weight */
71819
71820 atomic_t refcnt; /* reference counter */
71821@@ -980,11 +980,11 @@ struct netns_ipvs {
71822 /* ip_vs_lblc */
71823 int sysctl_lblc_expiration;
71824 struct ctl_table_header *lblc_ctl_header;
71825- struct ctl_table *lblc_ctl_table;
71826+ ctl_table_no_const *lblc_ctl_table;
71827 /* ip_vs_lblcr */
71828 int sysctl_lblcr_expiration;
71829 struct ctl_table_header *lblcr_ctl_header;
71830- struct ctl_table *lblcr_ctl_table;
71831+ ctl_table_no_const *lblcr_ctl_table;
71832 /* ip_vs_est */
71833 struct list_head est_list; /* estimator list */
71834 spinlock_t est_lock;
71835diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71836index 80ffde3..968b0f4 100644
71837--- a/include/net/irda/ircomm_tty.h
71838+++ b/include/net/irda/ircomm_tty.h
71839@@ -35,6 +35,7 @@
71840 #include <linux/termios.h>
71841 #include <linux/timer.h>
71842 #include <linux/tty.h> /* struct tty_struct */
71843+#include <asm/local.h>
71844
71845 #include <net/irda/irias_object.h>
71846 #include <net/irda/ircomm_core.h>
71847diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71848index cc7c197..9f2da2a 100644
71849--- a/include/net/iucv/af_iucv.h
71850+++ b/include/net/iucv/af_iucv.h
71851@@ -141,7 +141,7 @@ struct iucv_sock {
71852 struct iucv_sock_list {
71853 struct hlist_head head;
71854 rwlock_t lock;
71855- atomic_t autobind_name;
71856+ atomic_unchecked_t autobind_name;
71857 };
71858
71859 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71860diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71861index df83f69..9b640b8 100644
71862--- a/include/net/llc_c_ac.h
71863+++ b/include/net/llc_c_ac.h
71864@@ -87,7 +87,7 @@
71865 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
71866 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
71867
71868-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71869+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71870
71871 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
71872 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71873diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71874index 6ca3113..f8026dd 100644
71875--- a/include/net/llc_c_ev.h
71876+++ b/include/net/llc_c_ev.h
71877@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71878 return (struct llc_conn_state_ev *)skb->cb;
71879 }
71880
71881-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71882-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71883+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71884+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71885
71886 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71887 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71888diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71889index 0e79cfb..f46db31 100644
71890--- a/include/net/llc_c_st.h
71891+++ b/include/net/llc_c_st.h
71892@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71893 u8 next_state;
71894 llc_conn_ev_qfyr_t *ev_qualifiers;
71895 llc_conn_action_t *ev_actions;
71896-};
71897+} __do_const;
71898
71899 struct llc_conn_state {
71900 u8 current_state;
71901diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71902index 37a3bbd..55a4241 100644
71903--- a/include/net/llc_s_ac.h
71904+++ b/include/net/llc_s_ac.h
71905@@ -23,7 +23,7 @@
71906 #define SAP_ACT_TEST_IND 9
71907
71908 /* All action functions must look like this */
71909-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71910+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71911
71912 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71913 struct sk_buff *skb);
71914diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71915index 567c681..cd73ac0 100644
71916--- a/include/net/llc_s_st.h
71917+++ b/include/net/llc_s_st.h
71918@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71919 llc_sap_ev_t ev;
71920 u8 next_state;
71921 llc_sap_action_t *ev_actions;
71922-};
71923+} __do_const;
71924
71925 struct llc_sap_state {
71926 u8 curr_state;
71927diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71928index ee50c5e..1bc3b1a 100644
71929--- a/include/net/mac80211.h
71930+++ b/include/net/mac80211.h
71931@@ -3996,7 +3996,7 @@ struct rate_control_ops {
71932 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71933 struct dentry *dir);
71934 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71935-};
71936+} __do_const;
71937
71938 static inline int rate_supported(struct ieee80211_sta *sta,
71939 enum ieee80211_band band,
71940diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71941index 0dab173..1b76af0 100644
71942--- a/include/net/neighbour.h
71943+++ b/include/net/neighbour.h
71944@@ -123,7 +123,7 @@ struct neigh_ops {
71945 void (*error_report)(struct neighbour *, struct sk_buff *);
71946 int (*output)(struct neighbour *, struct sk_buff *);
71947 int (*connected_output)(struct neighbour *, struct sk_buff *);
71948-};
71949+} __do_const;
71950
71951 struct pneigh_entry {
71952 struct pneigh_entry *next;
71953diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71954index de644bc..351fd4e 100644
71955--- a/include/net/net_namespace.h
71956+++ b/include/net/net_namespace.h
71957@@ -115,7 +115,7 @@ struct net {
71958 #endif
71959 struct netns_ipvs *ipvs;
71960 struct sock *diag_nlsk;
71961- atomic_t rt_genid;
71962+ atomic_unchecked_t rt_genid;
71963 };
71964
71965 /*
71966@@ -282,7 +282,7 @@ struct pernet_operations {
71967 void (*exit_batch)(struct list_head *net_exit_list);
71968 int *id;
71969 size_t size;
71970-};
71971+} __do_const;
71972
71973 /*
71974 * Use these carefully. If you implement a network device and it
71975@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71976
71977 static inline int rt_genid(struct net *net)
71978 {
71979- return atomic_read(&net->rt_genid);
71980+ return atomic_read_unchecked(&net->rt_genid);
71981 }
71982
71983 static inline void rt_genid_bump(struct net *net)
71984 {
71985- atomic_inc(&net->rt_genid);
71986+ atomic_inc_unchecked(&net->rt_genid);
71987 }
71988
71989 #endif /* __NET_NET_NAMESPACE_H */
71990diff --git a/include/net/netdma.h b/include/net/netdma.h
71991index 8ba8ce2..99b7fff 100644
71992--- a/include/net/netdma.h
71993+++ b/include/net/netdma.h
71994@@ -24,7 +24,7 @@
71995 #include <linux/dmaengine.h>
71996 #include <linux/skbuff.h>
71997
71998-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71999+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72000 struct sk_buff *skb, int offset, struct iovec *to,
72001 size_t len, struct dma_pinned_list *pinned_list);
72002
72003diff --git a/include/net/netlink.h b/include/net/netlink.h
72004index 9690b0f..87aded7 100644
72005--- a/include/net/netlink.h
72006+++ b/include/net/netlink.h
72007@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
72008 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
72009 {
72010 if (mark)
72011- skb_trim(skb, (unsigned char *) mark - skb->data);
72012+ skb_trim(skb, (const unsigned char *) mark - skb->data);
72013 }
72014
72015 /**
72016diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
72017index 923cb20..deae816 100644
72018--- a/include/net/netns/conntrack.h
72019+++ b/include/net/netns/conntrack.h
72020@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
72021 struct nf_proto_net {
72022 #ifdef CONFIG_SYSCTL
72023 struct ctl_table_header *ctl_table_header;
72024- struct ctl_table *ctl_table;
72025+ ctl_table_no_const *ctl_table;
72026 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
72027 struct ctl_table_header *ctl_compat_header;
72028- struct ctl_table *ctl_compat_table;
72029+ ctl_table_no_const *ctl_compat_table;
72030 #endif
72031 #endif
72032 unsigned int users;
72033@@ -58,7 +58,7 @@ struct nf_ip_net {
72034 struct nf_icmp_net icmpv6;
72035 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
72036 struct ctl_table_header *ctl_table_header;
72037- struct ctl_table *ctl_table;
72038+ ctl_table_no_const *ctl_table;
72039 #endif
72040 };
72041
72042diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
72043index 2ae2b83..dbdc85e 100644
72044--- a/include/net/netns/ipv4.h
72045+++ b/include/net/netns/ipv4.h
72046@@ -64,7 +64,7 @@ struct netns_ipv4 {
72047 kgid_t sysctl_ping_group_range[2];
72048 long sysctl_tcp_mem[3];
72049
72050- atomic_t dev_addr_genid;
72051+ atomic_unchecked_t dev_addr_genid;
72052
72053 #ifdef CONFIG_IP_MROUTE
72054 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
72055diff --git a/include/net/protocol.h b/include/net/protocol.h
72056index 047c047..b9dad15 100644
72057--- a/include/net/protocol.h
72058+++ b/include/net/protocol.h
72059@@ -44,7 +44,7 @@ struct net_protocol {
72060 void (*err_handler)(struct sk_buff *skb, u32 info);
72061 unsigned int no_policy:1,
72062 netns_ok:1;
72063-};
72064+} __do_const;
72065
72066 #if IS_ENABLED(CONFIG_IPV6)
72067 struct inet6_protocol {
72068@@ -57,7 +57,7 @@ struct inet6_protocol {
72069 u8 type, u8 code, int offset,
72070 __be32 info);
72071 unsigned int flags; /* INET6_PROTO_xxx */
72072-};
72073+} __do_const;
72074
72075 #define INET6_PROTO_NOPOLICY 0x1
72076 #define INET6_PROTO_FINAL 0x2
72077diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
72078index 5a15fab..d799ea7 100644
72079--- a/include/net/rtnetlink.h
72080+++ b/include/net/rtnetlink.h
72081@@ -81,7 +81,7 @@ struct rtnl_link_ops {
72082 const struct net_device *dev);
72083 unsigned int (*get_num_tx_queues)(void);
72084 unsigned int (*get_num_rx_queues)(void);
72085-};
72086+} __do_const;
72087
72088 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
72089 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
72090diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
72091index 7fdf298..197e9f7 100644
72092--- a/include/net/sctp/sctp.h
72093+++ b/include/net/sctp/sctp.h
72094@@ -330,9 +330,9 @@ do { \
72095
72096 #else /* SCTP_DEBUG */
72097
72098-#define SCTP_DEBUG_PRINTK(whatever...)
72099-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
72100-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
72101+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
72102+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
72103+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
72104 #define SCTP_ENABLE_DEBUG
72105 #define SCTP_DISABLE_DEBUG
72106 #define SCTP_ASSERT(expr, str, func)
72107diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
72108index 2a82d13..62a31c2 100644
72109--- a/include/net/sctp/sm.h
72110+++ b/include/net/sctp/sm.h
72111@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
72112 typedef struct {
72113 sctp_state_fn_t *fn;
72114 const char *name;
72115-} sctp_sm_table_entry_t;
72116+} __do_const sctp_sm_table_entry_t;
72117
72118 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
72119 * currently in use.
72120@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
72121 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
72122
72123 /* Extern declarations for major data structures. */
72124-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72125+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72126
72127
72128 /* Get the size of a DATA chunk payload. */
72129diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
72130index fdeb85a..1329d95 100644
72131--- a/include/net/sctp/structs.h
72132+++ b/include/net/sctp/structs.h
72133@@ -517,7 +517,7 @@ struct sctp_pf {
72134 struct sctp_association *asoc);
72135 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
72136 struct sctp_af *af;
72137-};
72138+} __do_const;
72139
72140
72141 /* Structure to track chunk fragments that have been acked, but peer
72142diff --git a/include/net/sock.h b/include/net/sock.h
72143index 25afaa0..8bb0070 100644
72144--- a/include/net/sock.h
72145+++ b/include/net/sock.h
72146@@ -322,7 +322,7 @@ struct sock {
72147 #ifdef CONFIG_RPS
72148 __u32 sk_rxhash;
72149 #endif
72150- atomic_t sk_drops;
72151+ atomic_unchecked_t sk_drops;
72152 int sk_rcvbuf;
72153
72154 struct sk_filter __rcu *sk_filter;
72155@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
72156 }
72157
72158 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
72159- char __user *from, char *to,
72160+ char __user *from, unsigned char *to,
72161 int copy, int offset)
72162 {
72163 if (skb->ip_summed == CHECKSUM_NONE) {
72164@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
72165 }
72166 }
72167
72168-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72169+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72170
72171 /**
72172 * sk_page_frag - return an appropriate page_frag
72173diff --git a/include/net/tcp.h b/include/net/tcp.h
72174index aed42c7..43890c6 100644
72175--- a/include/net/tcp.h
72176+++ b/include/net/tcp.h
72177@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
72178 extern void tcp_xmit_retransmit_queue(struct sock *);
72179 extern void tcp_simple_retransmit(struct sock *);
72180 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
72181-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72182+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72183
72184 extern void tcp_send_probe0(struct sock *);
72185 extern void tcp_send_partial(struct sock *);
72186@@ -701,8 +701,8 @@ struct tcp_skb_cb {
72187 struct inet6_skb_parm h6;
72188 #endif
72189 } header; /* For incoming frames */
72190- __u32 seq; /* Starting sequence number */
72191- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
72192+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
72193+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
72194 __u32 when; /* used to compute rtt's */
72195 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
72196
72197@@ -716,7 +716,7 @@ struct tcp_skb_cb {
72198
72199 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
72200 /* 1 byte hole */
72201- __u32 ack_seq; /* Sequence number ACK'd */
72202+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
72203 };
72204
72205 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
72206diff --git a/include/net/xfrm.h b/include/net/xfrm.h
72207index 63445ed..d6fc34f 100644
72208--- a/include/net/xfrm.h
72209+++ b/include/net/xfrm.h
72210@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
72211 struct net_device *dev,
72212 const struct flowi *fl);
72213 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
72214-};
72215+} __do_const;
72216
72217 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
72218 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
72219@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
72220 struct sk_buff *skb);
72221 int (*transport_finish)(struct sk_buff *skb,
72222 int async);
72223-};
72224+} __do_const;
72225
72226 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
72227 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
72228@@ -423,7 +423,7 @@ struct xfrm_mode {
72229 struct module *owner;
72230 unsigned int encap;
72231 int flags;
72232-};
72233+} __do_const;
72234
72235 /* Flags for xfrm_mode. */
72236 enum {
72237@@ -514,7 +514,7 @@ struct xfrm_policy {
72238 struct timer_list timer;
72239
72240 struct flow_cache_object flo;
72241- atomic_t genid;
72242+ atomic_unchecked_t genid;
72243 u32 priority;
72244 u32 index;
72245 struct xfrm_mark mark;
72246diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
72247index 1a046b1..ee0bef0 100644
72248--- a/include/rdma/iw_cm.h
72249+++ b/include/rdma/iw_cm.h
72250@@ -122,7 +122,7 @@ struct iw_cm_verbs {
72251 int backlog);
72252
72253 int (*destroy_listen)(struct iw_cm_id *cm_id);
72254-};
72255+} __no_const;
72256
72257 /**
72258 * iw_create_cm_id - Create an IW CM identifier.
72259diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
72260index 399162b..b337f1a 100644
72261--- a/include/scsi/libfc.h
72262+++ b/include/scsi/libfc.h
72263@@ -762,6 +762,7 @@ struct libfc_function_template {
72264 */
72265 void (*disc_stop_final) (struct fc_lport *);
72266 };
72267+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
72268
72269 /**
72270 * struct fc_disc - Discovery context
72271@@ -866,7 +867,7 @@ struct fc_lport {
72272 struct fc_vport *vport;
72273
72274 /* Operational Information */
72275- struct libfc_function_template tt;
72276+ libfc_function_template_no_const tt;
72277 u8 link_up;
72278 u8 qfull;
72279 enum fc_lport_state state;
72280diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
72281index e65c62e..aa2e5a2 100644
72282--- a/include/scsi/scsi_device.h
72283+++ b/include/scsi/scsi_device.h
72284@@ -170,9 +170,9 @@ struct scsi_device {
72285 unsigned int max_device_blocked; /* what device_blocked counts down from */
72286 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
72287
72288- atomic_t iorequest_cnt;
72289- atomic_t iodone_cnt;
72290- atomic_t ioerr_cnt;
72291+ atomic_unchecked_t iorequest_cnt;
72292+ atomic_unchecked_t iodone_cnt;
72293+ atomic_unchecked_t ioerr_cnt;
72294
72295 struct device sdev_gendev,
72296 sdev_dev;
72297diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
72298index b797e8f..8e2c3aa 100644
72299--- a/include/scsi/scsi_transport_fc.h
72300+++ b/include/scsi/scsi_transport_fc.h
72301@@ -751,7 +751,8 @@ struct fc_function_template {
72302 unsigned long show_host_system_hostname:1;
72303
72304 unsigned long disable_target_scan:1;
72305-};
72306+} __do_const;
72307+typedef struct fc_function_template __no_const fc_function_template_no_const;
72308
72309
72310 /**
72311diff --git a/include/sound/soc.h b/include/sound/soc.h
72312index bc56738..a4be132 100644
72313--- a/include/sound/soc.h
72314+++ b/include/sound/soc.h
72315@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
72316 /* probe ordering - for components with runtime dependencies */
72317 int probe_order;
72318 int remove_order;
72319-};
72320+} __do_const;
72321
72322 /* SoC platform interface */
72323 struct snd_soc_platform_driver {
72324@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
72325 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
72326 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
72327 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
72328-};
72329+} __do_const;
72330
72331 struct snd_soc_platform {
72332 const char *name;
72333diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
72334index 663e34a..91b306a 100644
72335--- a/include/target/target_core_base.h
72336+++ b/include/target/target_core_base.h
72337@@ -654,7 +654,7 @@ struct se_device {
72338 spinlock_t stats_lock;
72339 /* Active commands on this virtual SE device */
72340 atomic_t simple_cmds;
72341- atomic_t dev_ordered_id;
72342+ atomic_unchecked_t dev_ordered_id;
72343 atomic_t dev_ordered_sync;
72344 atomic_t dev_qf_count;
72345 int export_count;
72346diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
72347new file mode 100644
72348index 0000000..fb634b7
72349--- /dev/null
72350+++ b/include/trace/events/fs.h
72351@@ -0,0 +1,53 @@
72352+#undef TRACE_SYSTEM
72353+#define TRACE_SYSTEM fs
72354+
72355+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
72356+#define _TRACE_FS_H
72357+
72358+#include <linux/fs.h>
72359+#include <linux/tracepoint.h>
72360+
72361+TRACE_EVENT(do_sys_open,
72362+
72363+ TP_PROTO(const char *filename, int flags, int mode),
72364+
72365+ TP_ARGS(filename, flags, mode),
72366+
72367+ TP_STRUCT__entry(
72368+ __string( filename, filename )
72369+ __field( int, flags )
72370+ __field( int, mode )
72371+ ),
72372+
72373+ TP_fast_assign(
72374+ __assign_str(filename, filename);
72375+ __entry->flags = flags;
72376+ __entry->mode = mode;
72377+ ),
72378+
72379+ TP_printk("\"%s\" %x %o",
72380+ __get_str(filename), __entry->flags, __entry->mode)
72381+);
72382+
72383+TRACE_EVENT(open_exec,
72384+
72385+ TP_PROTO(const char *filename),
72386+
72387+ TP_ARGS(filename),
72388+
72389+ TP_STRUCT__entry(
72390+ __string( filename, filename )
72391+ ),
72392+
72393+ TP_fast_assign(
72394+ __assign_str(filename, filename);
72395+ ),
72396+
72397+ TP_printk("\"%s\"",
72398+ __get_str(filename))
72399+);
72400+
72401+#endif /* _TRACE_FS_H */
72402+
72403+/* This part must be outside protection */
72404+#include <trace/define_trace.h>
72405diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
72406index 1c09820..7f5ec79 100644
72407--- a/include/trace/events/irq.h
72408+++ b/include/trace/events/irq.h
72409@@ -36,7 +36,7 @@ struct softirq_action;
72410 */
72411 TRACE_EVENT(irq_handler_entry,
72412
72413- TP_PROTO(int irq, struct irqaction *action),
72414+ TP_PROTO(int irq, const struct irqaction *action),
72415
72416 TP_ARGS(irq, action),
72417
72418@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
72419 */
72420 TRACE_EVENT(irq_handler_exit,
72421
72422- TP_PROTO(int irq, struct irqaction *action, int ret),
72423+ TP_PROTO(int irq, const struct irqaction *action, int ret),
72424
72425 TP_ARGS(irq, action, ret),
72426
72427diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
72428index 7caf44c..23c6f27 100644
72429--- a/include/uapi/linux/a.out.h
72430+++ b/include/uapi/linux/a.out.h
72431@@ -39,6 +39,14 @@ enum machine_type {
72432 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
72433 };
72434
72435+/* Constants for the N_FLAGS field */
72436+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72437+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
72438+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
72439+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
72440+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72441+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72442+
72443 #if !defined (N_MAGIC)
72444 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
72445 #endif
72446diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
72447index d876736..ccce5c0 100644
72448--- a/include/uapi/linux/byteorder/little_endian.h
72449+++ b/include/uapi/linux/byteorder/little_endian.h
72450@@ -42,51 +42,51 @@
72451
72452 static inline __le64 __cpu_to_le64p(const __u64 *p)
72453 {
72454- return (__force __le64)*p;
72455+ return (__force const __le64)*p;
72456 }
72457-static inline __u64 __le64_to_cpup(const __le64 *p)
72458+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
72459 {
72460- return (__force __u64)*p;
72461+ return (__force const __u64)*p;
72462 }
72463 static inline __le32 __cpu_to_le32p(const __u32 *p)
72464 {
72465- return (__force __le32)*p;
72466+ return (__force const __le32)*p;
72467 }
72468 static inline __u32 __le32_to_cpup(const __le32 *p)
72469 {
72470- return (__force __u32)*p;
72471+ return (__force const __u32)*p;
72472 }
72473 static inline __le16 __cpu_to_le16p(const __u16 *p)
72474 {
72475- return (__force __le16)*p;
72476+ return (__force const __le16)*p;
72477 }
72478 static inline __u16 __le16_to_cpup(const __le16 *p)
72479 {
72480- return (__force __u16)*p;
72481+ return (__force const __u16)*p;
72482 }
72483 static inline __be64 __cpu_to_be64p(const __u64 *p)
72484 {
72485- return (__force __be64)__swab64p(p);
72486+ return (__force const __be64)__swab64p(p);
72487 }
72488 static inline __u64 __be64_to_cpup(const __be64 *p)
72489 {
72490- return __swab64p((__u64 *)p);
72491+ return __swab64p((const __u64 *)p);
72492 }
72493 static inline __be32 __cpu_to_be32p(const __u32 *p)
72494 {
72495- return (__force __be32)__swab32p(p);
72496+ return (__force const __be32)__swab32p(p);
72497 }
72498-static inline __u32 __be32_to_cpup(const __be32 *p)
72499+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
72500 {
72501- return __swab32p((__u32 *)p);
72502+ return __swab32p((const __u32 *)p);
72503 }
72504 static inline __be16 __cpu_to_be16p(const __u16 *p)
72505 {
72506- return (__force __be16)__swab16p(p);
72507+ return (__force const __be16)__swab16p(p);
72508 }
72509 static inline __u16 __be16_to_cpup(const __be16 *p)
72510 {
72511- return __swab16p((__u16 *)p);
72512+ return __swab16p((const __u16 *)p);
72513 }
72514 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
72515 #define __le64_to_cpus(x) do { (void)(x); } while (0)
72516diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
72517index 126a817..d522bd1 100644
72518--- a/include/uapi/linux/elf.h
72519+++ b/include/uapi/linux/elf.h
72520@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
72521 #define PT_GNU_EH_FRAME 0x6474e550
72522
72523 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
72524+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
72525+
72526+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
72527+
72528+/* Constants for the e_flags field */
72529+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72530+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
72531+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
72532+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
72533+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72534+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72535
72536 /*
72537 * Extended Numbering
72538@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
72539 #define DT_DEBUG 21
72540 #define DT_TEXTREL 22
72541 #define DT_JMPREL 23
72542+#define DT_FLAGS 30
72543+ #define DF_TEXTREL 0x00000004
72544 #define DT_ENCODING 32
72545 #define OLD_DT_LOOS 0x60000000
72546 #define DT_LOOS 0x6000000d
72547@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
72548 #define PF_W 0x2
72549 #define PF_X 0x1
72550
72551+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
72552+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
72553+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
72554+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
72555+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
72556+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
72557+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
72558+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
72559+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
72560+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
72561+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
72562+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
72563+
72564 typedef struct elf32_phdr{
72565 Elf32_Word p_type;
72566 Elf32_Off p_offset;
72567@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
72568 #define EI_OSABI 7
72569 #define EI_PAD 8
72570
72571+#define EI_PAX 14
72572+
72573 #define ELFMAG0 0x7f /* EI_MAG */
72574 #define ELFMAG1 'E'
72575 #define ELFMAG2 'L'
72576diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
72577index aa169c4..6a2771d 100644
72578--- a/include/uapi/linux/personality.h
72579+++ b/include/uapi/linux/personality.h
72580@@ -30,6 +30,7 @@ enum {
72581 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
72582 ADDR_NO_RANDOMIZE | \
72583 ADDR_COMPAT_LAYOUT | \
72584+ ADDR_LIMIT_3GB | \
72585 MMAP_PAGE_ZERO)
72586
72587 /*
72588diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
72589index 7530e74..e714828 100644
72590--- a/include/uapi/linux/screen_info.h
72591+++ b/include/uapi/linux/screen_info.h
72592@@ -43,7 +43,8 @@ struct screen_info {
72593 __u16 pages; /* 0x32 */
72594 __u16 vesa_attributes; /* 0x34 */
72595 __u32 capabilities; /* 0x36 */
72596- __u8 _reserved[6]; /* 0x3a */
72597+ __u16 vesapm_size; /* 0x3a */
72598+ __u8 _reserved[4]; /* 0x3c */
72599 } __attribute__((packed));
72600
72601 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
72602diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
72603index 0e011eb..82681b1 100644
72604--- a/include/uapi/linux/swab.h
72605+++ b/include/uapi/linux/swab.h
72606@@ -43,7 +43,7 @@
72607 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
72608 */
72609
72610-static inline __attribute_const__ __u16 __fswab16(__u16 val)
72611+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
72612 {
72613 #ifdef __HAVE_BUILTIN_BSWAP16__
72614 return __builtin_bswap16(val);
72615@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
72616 #endif
72617 }
72618
72619-static inline __attribute_const__ __u32 __fswab32(__u32 val)
72620+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
72621 {
72622 #ifdef __HAVE_BUILTIN_BSWAP32__
72623 return __builtin_bswap32(val);
72624@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
72625 #endif
72626 }
72627
72628-static inline __attribute_const__ __u64 __fswab64(__u64 val)
72629+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
72630 {
72631 #ifdef __HAVE_BUILTIN_BSWAP64__
72632 return __builtin_bswap64(val);
72633diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
72634index 6d67213..8dab561 100644
72635--- a/include/uapi/linux/sysctl.h
72636+++ b/include/uapi/linux/sysctl.h
72637@@ -155,7 +155,11 @@ enum
72638 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
72639 };
72640
72641-
72642+#ifdef CONFIG_PAX_SOFTMODE
72643+enum {
72644+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
72645+};
72646+#endif
72647
72648 /* CTL_VM names: */
72649 enum
72650diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
72651index 26607bd..588b65f 100644
72652--- a/include/uapi/linux/xattr.h
72653+++ b/include/uapi/linux/xattr.h
72654@@ -60,5 +60,9 @@
72655 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
72656 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
72657
72658+/* User namespace */
72659+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
72660+#define XATTR_PAX_FLAGS_SUFFIX "flags"
72661+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
72662
72663 #endif /* _UAPI_LINUX_XATTR_H */
72664diff --git a/include/video/udlfb.h b/include/video/udlfb.h
72665index f9466fa..f4e2b81 100644
72666--- a/include/video/udlfb.h
72667+++ b/include/video/udlfb.h
72668@@ -53,10 +53,10 @@ struct dlfb_data {
72669 u32 pseudo_palette[256];
72670 int blank_mode; /*one of FB_BLANK_ */
72671 /* blit-only rendering path metrics, exposed through sysfs */
72672- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72673- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
72674- atomic_t bytes_sent; /* to usb, after compression including overhead */
72675- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
72676+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72677+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
72678+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
72679+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
72680 };
72681
72682 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
72683diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
72684index 0993a22..32ba2fe 100644
72685--- a/include/video/uvesafb.h
72686+++ b/include/video/uvesafb.h
72687@@ -177,6 +177,7 @@ struct uvesafb_par {
72688 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
72689 u8 pmi_setpal; /* PMI for palette changes */
72690 u16 *pmi_base; /* protected mode interface location */
72691+ u8 *pmi_code; /* protected mode code location */
72692 void *pmi_start;
72693 void *pmi_pal;
72694 u8 *vbe_state_orig; /*
72695diff --git a/init/Kconfig b/init/Kconfig
72696index be8b7f5..1eeca9b 100644
72697--- a/init/Kconfig
72698+++ b/init/Kconfig
72699@@ -990,6 +990,7 @@ endif # CGROUPS
72700
72701 config CHECKPOINT_RESTORE
72702 bool "Checkpoint/restore support" if EXPERT
72703+ depends on !GRKERNSEC
72704 default n
72705 help
72706 Enables additional kernel features in a sake of checkpoint/restore.
72707@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
72708
72709 config COMPAT_BRK
72710 bool "Disable heap randomization"
72711- default y
72712+ default n
72713 help
72714 Randomizing heap placement makes heap exploits harder, but it
72715 also breaks ancient binaries (including anything libc5 based).
72716@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
72717 config STOP_MACHINE
72718 bool
72719 default y
72720- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
72721+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
72722 help
72723 Need stop_machine() primitive.
72724
72725diff --git a/init/Makefile b/init/Makefile
72726index 7bc47ee..6da2dc7 100644
72727--- a/init/Makefile
72728+++ b/init/Makefile
72729@@ -2,6 +2,9 @@
72730 # Makefile for the linux kernel.
72731 #
72732
72733+ccflags-y := $(GCC_PLUGINS_CFLAGS)
72734+asflags-y := $(GCC_PLUGINS_AFLAGS)
72735+
72736 obj-y := main.o version.o mounts.o
72737 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
72738 obj-y += noinitramfs.o
72739diff --git a/init/do_mounts.c b/init/do_mounts.c
72740index 1d1b634..a1c810f 100644
72741--- a/init/do_mounts.c
72742+++ b/init/do_mounts.c
72743@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
72744 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
72745 {
72746 struct super_block *s;
72747- int err = sys_mount(name, "/root", fs, flags, data);
72748+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
72749 if (err)
72750 return err;
72751
72752- sys_chdir("/root");
72753+ sys_chdir((const char __force_user *)"/root");
72754 s = current->fs->pwd.dentry->d_sb;
72755 ROOT_DEV = s->s_dev;
72756 printk(KERN_INFO
72757@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
72758 va_start(args, fmt);
72759 vsprintf(buf, fmt, args);
72760 va_end(args);
72761- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
72762+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
72763 if (fd >= 0) {
72764 sys_ioctl(fd, FDEJECT, 0);
72765 sys_close(fd);
72766 }
72767 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
72768- fd = sys_open("/dev/console", O_RDWR, 0);
72769+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
72770 if (fd >= 0) {
72771 sys_ioctl(fd, TCGETS, (long)&termios);
72772 termios.c_lflag &= ~ICANON;
72773 sys_ioctl(fd, TCSETSF, (long)&termios);
72774- sys_read(fd, &c, 1);
72775+ sys_read(fd, (char __user *)&c, 1);
72776 termios.c_lflag |= ICANON;
72777 sys_ioctl(fd, TCSETSF, (long)&termios);
72778 sys_close(fd);
72779@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
72780 mount_root();
72781 out:
72782 devtmpfs_mount("dev");
72783- sys_mount(".", "/", NULL, MS_MOVE, NULL);
72784- sys_chroot(".");
72785+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72786+ sys_chroot((const char __force_user *)".");
72787 }
72788diff --git a/init/do_mounts.h b/init/do_mounts.h
72789index f5b978a..69dbfe8 100644
72790--- a/init/do_mounts.h
72791+++ b/init/do_mounts.h
72792@@ -15,15 +15,15 @@ extern int root_mountflags;
72793
72794 static inline int create_dev(char *name, dev_t dev)
72795 {
72796- sys_unlink(name);
72797- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72798+ sys_unlink((char __force_user *)name);
72799+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72800 }
72801
72802 #if BITS_PER_LONG == 32
72803 static inline u32 bstat(char *name)
72804 {
72805 struct stat64 stat;
72806- if (sys_stat64(name, &stat) != 0)
72807+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72808 return 0;
72809 if (!S_ISBLK(stat.st_mode))
72810 return 0;
72811@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72812 static inline u32 bstat(char *name)
72813 {
72814 struct stat stat;
72815- if (sys_newstat(name, &stat) != 0)
72816+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72817 return 0;
72818 if (!S_ISBLK(stat.st_mode))
72819 return 0;
72820diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72821index f9acf71..1e19144 100644
72822--- a/init/do_mounts_initrd.c
72823+++ b/init/do_mounts_initrd.c
72824@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72825 create_dev("/dev/root.old", Root_RAM0);
72826 /* mount initrd on rootfs' /root */
72827 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72828- sys_mkdir("/old", 0700);
72829- sys_chdir("/old");
72830+ sys_mkdir((const char __force_user *)"/old", 0700);
72831+ sys_chdir((const char __force_user *)"/old");
72832
72833 /*
72834 * In case that a resume from disk is carried out by linuxrc or one of
72835@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72836 current->flags &= ~PF_FREEZER_SKIP;
72837
72838 /* move initrd to rootfs' /old */
72839- sys_mount("..", ".", NULL, MS_MOVE, NULL);
72840+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72841 /* switch root and cwd back to / of rootfs */
72842- sys_chroot("..");
72843+ sys_chroot((const char __force_user *)"..");
72844
72845 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72846- sys_chdir("/old");
72847+ sys_chdir((const char __force_user *)"/old");
72848 return;
72849 }
72850
72851- sys_chdir("/");
72852+ sys_chdir((const char __force_user *)"/");
72853 ROOT_DEV = new_decode_dev(real_root_dev);
72854 mount_root();
72855
72856 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
72857- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
72858+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
72859 if (!error)
72860 printk("okay\n");
72861 else {
72862- int fd = sys_open("/dev/root.old", O_RDWR, 0);
72863+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
72864 if (error == -ENOENT)
72865 printk("/initrd does not exist. Ignored.\n");
72866 else
72867 printk("failed\n");
72868 printk(KERN_NOTICE "Unmounting old root\n");
72869- sys_umount("/old", MNT_DETACH);
72870+ sys_umount((char __force_user *)"/old", MNT_DETACH);
72871 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
72872 if (fd < 0) {
72873 error = fd;
72874@@ -120,11 +120,11 @@ int __init initrd_load(void)
72875 * mounted in the normal path.
72876 */
72877 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
72878- sys_unlink("/initrd.image");
72879+ sys_unlink((const char __force_user *)"/initrd.image");
72880 handle_initrd();
72881 return 1;
72882 }
72883 }
72884- sys_unlink("/initrd.image");
72885+ sys_unlink((const char __force_user *)"/initrd.image");
72886 return 0;
72887 }
72888diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
72889index 8cb6db5..d729f50 100644
72890--- a/init/do_mounts_md.c
72891+++ b/init/do_mounts_md.c
72892@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
72893 partitioned ? "_d" : "", minor,
72894 md_setup_args[ent].device_names);
72895
72896- fd = sys_open(name, 0, 0);
72897+ fd = sys_open((char __force_user *)name, 0, 0);
72898 if (fd < 0) {
72899 printk(KERN_ERR "md: open failed - cannot start "
72900 "array %s\n", name);
72901@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
72902 * array without it
72903 */
72904 sys_close(fd);
72905- fd = sys_open(name, 0, 0);
72906+ fd = sys_open((char __force_user *)name, 0, 0);
72907 sys_ioctl(fd, BLKRRPART, 0);
72908 }
72909 sys_close(fd);
72910@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72911
72912 wait_for_device_probe();
72913
72914- fd = sys_open("/dev/md0", 0, 0);
72915+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72916 if (fd >= 0) {
72917 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72918 sys_close(fd);
72919diff --git a/init/init_task.c b/init/init_task.c
72920index 8b2f399..f0797c9 100644
72921--- a/init/init_task.c
72922+++ b/init/init_task.c
72923@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72924 * Initial thread structure. Alignment of this is handled by a special
72925 * linker map entry.
72926 */
72927+#ifdef CONFIG_X86
72928+union thread_union init_thread_union __init_task_data;
72929+#else
72930 union thread_union init_thread_union __init_task_data =
72931 { INIT_THREAD_INFO(init_task) };
72932+#endif
72933diff --git a/init/initramfs.c b/init/initramfs.c
72934index 84c6bf1..8899338 100644
72935--- a/init/initramfs.c
72936+++ b/init/initramfs.c
72937@@ -84,7 +84,7 @@ static void __init free_hash(void)
72938 }
72939 }
72940
72941-static long __init do_utime(char *filename, time_t mtime)
72942+static long __init do_utime(char __force_user *filename, time_t mtime)
72943 {
72944 struct timespec t[2];
72945
72946@@ -119,7 +119,7 @@ static void __init dir_utime(void)
72947 struct dir_entry *de, *tmp;
72948 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72949 list_del(&de->list);
72950- do_utime(de->name, de->mtime);
72951+ do_utime((char __force_user *)de->name, de->mtime);
72952 kfree(de->name);
72953 kfree(de);
72954 }
72955@@ -281,7 +281,7 @@ static int __init maybe_link(void)
72956 if (nlink >= 2) {
72957 char *old = find_link(major, minor, ino, mode, collected);
72958 if (old)
72959- return (sys_link(old, collected) < 0) ? -1 : 1;
72960+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72961 }
72962 return 0;
72963 }
72964@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72965 {
72966 struct stat st;
72967
72968- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72969+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72970 if (S_ISDIR(st.st_mode))
72971- sys_rmdir(path);
72972+ sys_rmdir((char __force_user *)path);
72973 else
72974- sys_unlink(path);
72975+ sys_unlink((char __force_user *)path);
72976 }
72977 }
72978
72979@@ -315,7 +315,7 @@ static int __init do_name(void)
72980 int openflags = O_WRONLY|O_CREAT;
72981 if (ml != 1)
72982 openflags |= O_TRUNC;
72983- wfd = sys_open(collected, openflags, mode);
72984+ wfd = sys_open((char __force_user *)collected, openflags, mode);
72985
72986 if (wfd >= 0) {
72987 sys_fchown(wfd, uid, gid);
72988@@ -327,17 +327,17 @@ static int __init do_name(void)
72989 }
72990 }
72991 } else if (S_ISDIR(mode)) {
72992- sys_mkdir(collected, mode);
72993- sys_chown(collected, uid, gid);
72994- sys_chmod(collected, mode);
72995+ sys_mkdir((char __force_user *)collected, mode);
72996+ sys_chown((char __force_user *)collected, uid, gid);
72997+ sys_chmod((char __force_user *)collected, mode);
72998 dir_add(collected, mtime);
72999 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
73000 S_ISFIFO(mode) || S_ISSOCK(mode)) {
73001 if (maybe_link() == 0) {
73002- sys_mknod(collected, mode, rdev);
73003- sys_chown(collected, uid, gid);
73004- sys_chmod(collected, mode);
73005- do_utime(collected, mtime);
73006+ sys_mknod((char __force_user *)collected, mode, rdev);
73007+ sys_chown((char __force_user *)collected, uid, gid);
73008+ sys_chmod((char __force_user *)collected, mode);
73009+ do_utime((char __force_user *)collected, mtime);
73010 }
73011 }
73012 return 0;
73013@@ -346,15 +346,15 @@ static int __init do_name(void)
73014 static int __init do_copy(void)
73015 {
73016 if (count >= body_len) {
73017- sys_write(wfd, victim, body_len);
73018+ sys_write(wfd, (char __force_user *)victim, body_len);
73019 sys_close(wfd);
73020- do_utime(vcollected, mtime);
73021+ do_utime((char __force_user *)vcollected, mtime);
73022 kfree(vcollected);
73023 eat(body_len);
73024 state = SkipIt;
73025 return 0;
73026 } else {
73027- sys_write(wfd, victim, count);
73028+ sys_write(wfd, (char __force_user *)victim, count);
73029 body_len -= count;
73030 eat(count);
73031 return 1;
73032@@ -365,9 +365,9 @@ static int __init do_symlink(void)
73033 {
73034 collected[N_ALIGN(name_len) + body_len] = '\0';
73035 clean_path(collected, 0);
73036- sys_symlink(collected + N_ALIGN(name_len), collected);
73037- sys_lchown(collected, uid, gid);
73038- do_utime(collected, mtime);
73039+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
73040+ sys_lchown((char __force_user *)collected, uid, gid);
73041+ do_utime((char __force_user *)collected, mtime);
73042 state = SkipIt;
73043 next_state = Reset;
73044 return 0;
73045diff --git a/init/main.c b/init/main.c
73046index cee4b5c..360e10a 100644
73047--- a/init/main.c
73048+++ b/init/main.c
73049@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
73050 extern void tc_init(void);
73051 #endif
73052
73053+extern void grsecurity_init(void);
73054+
73055 /*
73056 * Debug helper: via this flag we know that we are in 'early bootup code'
73057 * where only the boot processor is running with IRQ disabled. This means
73058@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
73059
73060 __setup("reset_devices", set_reset_devices);
73061
73062+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73063+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
73064+static int __init setup_grsec_proc_gid(char *str)
73065+{
73066+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
73067+ return 1;
73068+}
73069+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
73070+#endif
73071+
73072+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
73073+extern char pax_enter_kernel_user[];
73074+extern char pax_exit_kernel_user[];
73075+extern pgdval_t clone_pgd_mask;
73076+#endif
73077+
73078+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
73079+static int __init setup_pax_nouderef(char *str)
73080+{
73081+#ifdef CONFIG_X86_32
73082+ unsigned int cpu;
73083+ struct desc_struct *gdt;
73084+
73085+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
73086+ gdt = get_cpu_gdt_table(cpu);
73087+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
73088+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
73089+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
73090+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
73091+ }
73092+ loadsegment(ds, __KERNEL_DS);
73093+ loadsegment(es, __KERNEL_DS);
73094+ loadsegment(ss, __KERNEL_DS);
73095+#else
73096+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
73097+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
73098+ clone_pgd_mask = ~(pgdval_t)0UL;
73099+#endif
73100+
73101+ return 0;
73102+}
73103+early_param("pax_nouderef", setup_pax_nouderef);
73104+#endif
73105+
73106+#ifdef CONFIG_PAX_SOFTMODE
73107+int pax_softmode;
73108+
73109+static int __init setup_pax_softmode(char *str)
73110+{
73111+ get_option(&str, &pax_softmode);
73112+ return 1;
73113+}
73114+__setup("pax_softmode=", setup_pax_softmode);
73115+#endif
73116+
73117 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
73118 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
73119 static const char *panic_later, *panic_param;
73120@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
73121 {
73122 int count = preempt_count();
73123 int ret;
73124+ const char *msg1 = "", *msg2 = "";
73125
73126 if (initcall_debug)
73127 ret = do_one_initcall_debug(fn);
73128@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
73129 sprintf(msgbuf, "error code %d ", ret);
73130
73131 if (preempt_count() != count) {
73132- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
73133+ msg1 = " preemption imbalance";
73134 preempt_count() = count;
73135 }
73136 if (irqs_disabled()) {
73137- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
73138+ msg2 = " disabled interrupts";
73139 local_irq_enable();
73140 }
73141- if (msgbuf[0]) {
73142- printk("initcall %pF returned with %s\n", fn, msgbuf);
73143+ if (msgbuf[0] || *msg1 || *msg2) {
73144+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
73145 }
73146
73147 return ret;
73148@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
73149 level, level,
73150 &repair_env_string);
73151
73152- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
73153+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
73154 do_one_initcall(*fn);
73155+
73156+#ifdef LATENT_ENTROPY_PLUGIN
73157+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73158+#endif
73159+
73160+ }
73161 }
73162
73163 static void __init do_initcalls(void)
73164@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
73165 {
73166 initcall_t *fn;
73167
73168- for (fn = __initcall_start; fn < __initcall0_start; fn++)
73169+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
73170 do_one_initcall(*fn);
73171+
73172+#ifdef LATENT_ENTROPY_PLUGIN
73173+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73174+#endif
73175+
73176+ }
73177 }
73178
73179 static int run_init_process(const char *init_filename)
73180@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
73181 do_basic_setup();
73182
73183 /* Open the /dev/console on the rootfs, this should never fail */
73184- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
73185+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
73186 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
73187
73188 (void) sys_dup(0);
73189@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
73190 if (!ramdisk_execute_command)
73191 ramdisk_execute_command = "/init";
73192
73193- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
73194+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
73195 ramdisk_execute_command = NULL;
73196 prepare_namespace();
73197 }
73198
73199+ grsecurity_init();
73200+
73201 /*
73202 * Ok, we have completed the initial bootup, and
73203 * we're essentially up and running. Get rid of the
73204diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
73205index 130dfec..cc88451 100644
73206--- a/ipc/ipc_sysctl.c
73207+++ b/ipc/ipc_sysctl.c
73208@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
73209 static int proc_ipc_dointvec(ctl_table *table, int write,
73210 void __user *buffer, size_t *lenp, loff_t *ppos)
73211 {
73212- struct ctl_table ipc_table;
73213+ ctl_table_no_const ipc_table;
73214
73215 memcpy(&ipc_table, table, sizeof(ipc_table));
73216 ipc_table.data = get_ipc(table);
73217@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
73218 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
73219 void __user *buffer, size_t *lenp, loff_t *ppos)
73220 {
73221- struct ctl_table ipc_table;
73222+ ctl_table_no_const ipc_table;
73223
73224 memcpy(&ipc_table, table, sizeof(ipc_table));
73225 ipc_table.data = get_ipc(table);
73226@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
73227 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73228 void __user *buffer, size_t *lenp, loff_t *ppos)
73229 {
73230- struct ctl_table ipc_table;
73231+ ctl_table_no_const ipc_table;
73232 size_t lenp_bef = *lenp;
73233 int rc;
73234
73235@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73236 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
73237 void __user *buffer, size_t *lenp, loff_t *ppos)
73238 {
73239- struct ctl_table ipc_table;
73240+ ctl_table_no_const ipc_table;
73241 memcpy(&ipc_table, table, sizeof(ipc_table));
73242 ipc_table.data = get_ipc(table);
73243
73244@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
73245 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
73246 void __user *buffer, size_t *lenp, loff_t *ppos)
73247 {
73248- struct ctl_table ipc_table;
73249+ ctl_table_no_const ipc_table;
73250 size_t lenp_bef = *lenp;
73251 int oldval;
73252 int rc;
73253diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
73254index 383d638..943fdbb 100644
73255--- a/ipc/mq_sysctl.c
73256+++ b/ipc/mq_sysctl.c
73257@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
73258 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
73259 void __user *buffer, size_t *lenp, loff_t *ppos)
73260 {
73261- struct ctl_table mq_table;
73262+ ctl_table_no_const mq_table;
73263 memcpy(&mq_table, table, sizeof(mq_table));
73264 mq_table.data = get_mq(table);
73265
73266diff --git a/ipc/mqueue.c b/ipc/mqueue.c
73267index 71a3ca1..cc330ee 100644
73268--- a/ipc/mqueue.c
73269+++ b/ipc/mqueue.c
73270@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
73271 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
73272 info->attr.mq_msgsize);
73273
73274+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
73275 spin_lock(&mq_lock);
73276 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
73277 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
73278diff --git a/ipc/msg.c b/ipc/msg.c
73279index 31cd1bf..362ea07 100644
73280--- a/ipc/msg.c
73281+++ b/ipc/msg.c
73282@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
73283 return security_msg_queue_associate(msq, msgflg);
73284 }
73285
73286+static struct ipc_ops msg_ops = {
73287+ .getnew = newque,
73288+ .associate = msg_security,
73289+ .more_checks = NULL
73290+};
73291+
73292 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
73293 {
73294 struct ipc_namespace *ns;
73295- struct ipc_ops msg_ops;
73296 struct ipc_params msg_params;
73297
73298 ns = current->nsproxy->ipc_ns;
73299
73300- msg_ops.getnew = newque;
73301- msg_ops.associate = msg_security;
73302- msg_ops.more_checks = NULL;
73303-
73304 msg_params.key = key;
73305 msg_params.flg = msgflg;
73306
73307diff --git a/ipc/sem.c b/ipc/sem.c
73308index 58d31f1..cce7a55 100644
73309--- a/ipc/sem.c
73310+++ b/ipc/sem.c
73311@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
73312 return 0;
73313 }
73314
73315+static struct ipc_ops sem_ops = {
73316+ .getnew = newary,
73317+ .associate = sem_security,
73318+ .more_checks = sem_more_checks
73319+};
73320+
73321 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73322 {
73323 struct ipc_namespace *ns;
73324- struct ipc_ops sem_ops;
73325 struct ipc_params sem_params;
73326
73327 ns = current->nsproxy->ipc_ns;
73328@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73329 if (nsems < 0 || nsems > ns->sc_semmsl)
73330 return -EINVAL;
73331
73332- sem_ops.getnew = newary;
73333- sem_ops.associate = sem_security;
73334- sem_ops.more_checks = sem_more_checks;
73335-
73336 sem_params.key = key;
73337 sem_params.flg = semflg;
73338 sem_params.u.nsems = nsems;
73339diff --git a/ipc/shm.c b/ipc/shm.c
73340index 4fa6d8f..55cff14 100644
73341--- a/ipc/shm.c
73342+++ b/ipc/shm.c
73343@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
73344 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
73345 #endif
73346
73347+#ifdef CONFIG_GRKERNSEC
73348+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73349+ const time_t shm_createtime, const kuid_t cuid,
73350+ const int shmid);
73351+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73352+ const time_t shm_createtime);
73353+#endif
73354+
73355 void shm_init_ns(struct ipc_namespace *ns)
73356 {
73357 ns->shm_ctlmax = SHMMAX;
73358@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
73359 shp->shm_lprid = 0;
73360 shp->shm_atim = shp->shm_dtim = 0;
73361 shp->shm_ctim = get_seconds();
73362+#ifdef CONFIG_GRKERNSEC
73363+ {
73364+ struct timespec timeval;
73365+ do_posix_clock_monotonic_gettime(&timeval);
73366+
73367+ shp->shm_createtime = timeval.tv_sec;
73368+ }
73369+#endif
73370 shp->shm_segsz = size;
73371 shp->shm_nattch = 0;
73372 shp->shm_file = file;
73373@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
73374 return 0;
73375 }
73376
73377+static struct ipc_ops shm_ops = {
73378+ .getnew = newseg,
73379+ .associate = shm_security,
73380+ .more_checks = shm_more_checks
73381+};
73382+
73383 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
73384 {
73385 struct ipc_namespace *ns;
73386- struct ipc_ops shm_ops;
73387 struct ipc_params shm_params;
73388
73389 ns = current->nsproxy->ipc_ns;
73390
73391- shm_ops.getnew = newseg;
73392- shm_ops.associate = shm_security;
73393- shm_ops.more_checks = shm_more_checks;
73394-
73395 shm_params.key = key;
73396 shm_params.flg = shmflg;
73397 shm_params.u.size = size;
73398@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73399 f_mode = FMODE_READ | FMODE_WRITE;
73400 }
73401 if (shmflg & SHM_EXEC) {
73402+
73403+#ifdef CONFIG_PAX_MPROTECT
73404+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
73405+ goto out;
73406+#endif
73407+
73408 prot |= PROT_EXEC;
73409 acc_mode |= S_IXUGO;
73410 }
73411@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73412 if (err)
73413 goto out_unlock;
73414
73415+#ifdef CONFIG_GRKERNSEC
73416+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
73417+ shp->shm_perm.cuid, shmid) ||
73418+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
73419+ err = -EACCES;
73420+ goto out_unlock;
73421+ }
73422+#endif
73423+
73424 path = shp->shm_file->f_path;
73425 path_get(&path);
73426 shp->shm_nattch++;
73427+#ifdef CONFIG_GRKERNSEC
73428+ shp->shm_lapid = current->pid;
73429+#endif
73430 size = i_size_read(path.dentry->d_inode);
73431 shm_unlock(shp);
73432
73433diff --git a/kernel/acct.c b/kernel/acct.c
73434index 051e071..15e0920 100644
73435--- a/kernel/acct.c
73436+++ b/kernel/acct.c
73437@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
73438 */
73439 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
73440 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
73441- file->f_op->write(file, (char *)&ac,
73442+ file->f_op->write(file, (char __force_user *)&ac,
73443 sizeof(acct_t), &file->f_pos);
73444 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
73445 set_fs(fs);
73446diff --git a/kernel/audit.c b/kernel/audit.c
73447index d596e53..dbef3c3 100644
73448--- a/kernel/audit.c
73449+++ b/kernel/audit.c
73450@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
73451 3) suppressed due to audit_rate_limit
73452 4) suppressed due to audit_backlog_limit
73453 */
73454-static atomic_t audit_lost = ATOMIC_INIT(0);
73455+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
73456
73457 /* The netlink socket. */
73458 static struct sock *audit_sock;
73459@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
73460 unsigned long now;
73461 int print;
73462
73463- atomic_inc(&audit_lost);
73464+ atomic_inc_unchecked(&audit_lost);
73465
73466 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
73467
73468@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
73469 printk(KERN_WARNING
73470 "audit: audit_lost=%d audit_rate_limit=%d "
73471 "audit_backlog_limit=%d\n",
73472- atomic_read(&audit_lost),
73473+ atomic_read_unchecked(&audit_lost),
73474 audit_rate_limit,
73475 audit_backlog_limit);
73476 audit_panic(message);
73477@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
73478 status_set.pid = audit_pid;
73479 status_set.rate_limit = audit_rate_limit;
73480 status_set.backlog_limit = audit_backlog_limit;
73481- status_set.lost = atomic_read(&audit_lost);
73482+ status_set.lost = atomic_read_unchecked(&audit_lost);
73483 status_set.backlog = skb_queue_len(&audit_skb_queue);
73484 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
73485 &status_set, sizeof(status_set));
73486diff --git a/kernel/auditsc.c b/kernel/auditsc.c
73487index a371f85..da826c1 100644
73488--- a/kernel/auditsc.c
73489+++ b/kernel/auditsc.c
73490@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
73491 }
73492
73493 /* global counter which is incremented every time something logs in */
73494-static atomic_t session_id = ATOMIC_INIT(0);
73495+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
73496
73497 /**
73498 * audit_set_loginuid - set current task's audit_context loginuid
73499@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
73500 return -EPERM;
73501 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
73502
73503- sessionid = atomic_inc_return(&session_id);
73504+ sessionid = atomic_inc_return_unchecked(&session_id);
73505 if (context && context->in_syscall) {
73506 struct audit_buffer *ab;
73507
73508diff --git a/kernel/capability.c b/kernel/capability.c
73509index 493d972..f87dfbd 100644
73510--- a/kernel/capability.c
73511+++ b/kernel/capability.c
73512@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
73513 * before modification is attempted and the application
73514 * fails.
73515 */
73516+ if (tocopy > ARRAY_SIZE(kdata))
73517+ return -EFAULT;
73518+
73519 if (copy_to_user(dataptr, kdata, tocopy
73520 * sizeof(struct __user_cap_data_struct))) {
73521 return -EFAULT;
73522@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
73523 int ret;
73524
73525 rcu_read_lock();
73526- ret = security_capable(__task_cred(t), ns, cap);
73527+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
73528+ gr_task_is_capable(t, __task_cred(t), cap);
73529 rcu_read_unlock();
73530
73531- return (ret == 0);
73532+ return ret;
73533 }
73534
73535 /**
73536@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
73537 int ret;
73538
73539 rcu_read_lock();
73540- ret = security_capable_noaudit(__task_cred(t), ns, cap);
73541+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
73542 rcu_read_unlock();
73543
73544- return (ret == 0);
73545+ return ret;
73546 }
73547
73548 /**
73549@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
73550 BUG();
73551 }
73552
73553- if (security_capable(current_cred(), ns, cap) == 0) {
73554+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
73555 current->flags |= PF_SUPERPRIV;
73556 return true;
73557 }
73558@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
73559 }
73560 EXPORT_SYMBOL(ns_capable);
73561
73562+bool ns_capable_nolog(struct user_namespace *ns, int cap)
73563+{
73564+ if (unlikely(!cap_valid(cap))) {
73565+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
73566+ BUG();
73567+ }
73568+
73569+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
73570+ current->flags |= PF_SUPERPRIV;
73571+ return true;
73572+ }
73573+ return false;
73574+}
73575+EXPORT_SYMBOL(ns_capable_nolog);
73576+
73577 /**
73578 * capable - Determine if the current task has a superior capability in effect
73579 * @cap: The capability to be tested for
73580@@ -408,6 +427,12 @@ bool capable(int cap)
73581 }
73582 EXPORT_SYMBOL(capable);
73583
73584+bool capable_nolog(int cap)
73585+{
73586+ return ns_capable_nolog(&init_user_ns, cap);
73587+}
73588+EXPORT_SYMBOL(capable_nolog);
73589+
73590 /**
73591 * nsown_capable - Check superior capability to one's own user_ns
73592 * @cap: The capability in question
73593@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
73594
73595 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73596 }
73597+
73598+bool inode_capable_nolog(const struct inode *inode, int cap)
73599+{
73600+ struct user_namespace *ns = current_user_ns();
73601+
73602+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73603+}
73604diff --git a/kernel/cgroup.c b/kernel/cgroup.c
73605index 1e23664..570a83d 100644
73606--- a/kernel/cgroup.c
73607+++ b/kernel/cgroup.c
73608@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
73609 struct css_set *cg = link->cg;
73610 struct task_struct *task;
73611 int count = 0;
73612- seq_printf(seq, "css_set %p\n", cg);
73613+ seq_printf(seq, "css_set %pK\n", cg);
73614 list_for_each_entry(task, &cg->tasks, cg_list) {
73615 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
73616 seq_puts(seq, " ...\n");
73617diff --git a/kernel/compat.c b/kernel/compat.c
73618index 36700e9..73d770c 100644
73619--- a/kernel/compat.c
73620+++ b/kernel/compat.c
73621@@ -13,6 +13,7 @@
73622
73623 #include <linux/linkage.h>
73624 #include <linux/compat.h>
73625+#include <linux/module.h>
73626 #include <linux/errno.h>
73627 #include <linux/time.h>
73628 #include <linux/signal.h>
73629@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
73630 mm_segment_t oldfs;
73631 long ret;
73632
73633- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
73634+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
73635 oldfs = get_fs();
73636 set_fs(KERNEL_DS);
73637 ret = hrtimer_nanosleep_restart(restart);
73638@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
73639 oldfs = get_fs();
73640 set_fs(KERNEL_DS);
73641 ret = hrtimer_nanosleep(&tu,
73642- rmtp ? (struct timespec __user *)&rmt : NULL,
73643+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
73644 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
73645 set_fs(oldfs);
73646
73647@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
73648 mm_segment_t old_fs = get_fs();
73649
73650 set_fs(KERNEL_DS);
73651- ret = sys_sigpending((old_sigset_t __user *) &s);
73652+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
73653 set_fs(old_fs);
73654 if (ret == 0)
73655 ret = put_user(s, set);
73656@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
73657 mm_segment_t old_fs = get_fs();
73658
73659 set_fs(KERNEL_DS);
73660- ret = sys_old_getrlimit(resource, &r);
73661+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
73662 set_fs(old_fs);
73663
73664 if (!ret) {
73665@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
73666 mm_segment_t old_fs = get_fs();
73667
73668 set_fs(KERNEL_DS);
73669- ret = sys_getrusage(who, (struct rusage __user *) &r);
73670+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
73671 set_fs(old_fs);
73672
73673 if (ret)
73674@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
73675 set_fs (KERNEL_DS);
73676 ret = sys_wait4(pid,
73677 (stat_addr ?
73678- (unsigned int __user *) &status : NULL),
73679- options, (struct rusage __user *) &r);
73680+ (unsigned int __force_user *) &status : NULL),
73681+ options, (struct rusage __force_user *) &r);
73682 set_fs (old_fs);
73683
73684 if (ret > 0) {
73685@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
73686 memset(&info, 0, sizeof(info));
73687
73688 set_fs(KERNEL_DS);
73689- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
73690- uru ? (struct rusage __user *)&ru : NULL);
73691+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
73692+ uru ? (struct rusage __force_user *)&ru : NULL);
73693 set_fs(old_fs);
73694
73695 if ((ret < 0) || (info.si_signo == 0))
73696@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
73697 oldfs = get_fs();
73698 set_fs(KERNEL_DS);
73699 err = sys_timer_settime(timer_id, flags,
73700- (struct itimerspec __user *) &newts,
73701- (struct itimerspec __user *) &oldts);
73702+ (struct itimerspec __force_user *) &newts,
73703+ (struct itimerspec __force_user *) &oldts);
73704 set_fs(oldfs);
73705 if (!err && old && put_compat_itimerspec(old, &oldts))
73706 return -EFAULT;
73707@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
73708 oldfs = get_fs();
73709 set_fs(KERNEL_DS);
73710 err = sys_timer_gettime(timer_id,
73711- (struct itimerspec __user *) &ts);
73712+ (struct itimerspec __force_user *) &ts);
73713 set_fs(oldfs);
73714 if (!err && put_compat_itimerspec(setting, &ts))
73715 return -EFAULT;
73716@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
73717 oldfs = get_fs();
73718 set_fs(KERNEL_DS);
73719 err = sys_clock_settime(which_clock,
73720- (struct timespec __user *) &ts);
73721+ (struct timespec __force_user *) &ts);
73722 set_fs(oldfs);
73723 return err;
73724 }
73725@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
73726 oldfs = get_fs();
73727 set_fs(KERNEL_DS);
73728 err = sys_clock_gettime(which_clock,
73729- (struct timespec __user *) &ts);
73730+ (struct timespec __force_user *) &ts);
73731 set_fs(oldfs);
73732 if (!err && put_compat_timespec(&ts, tp))
73733 return -EFAULT;
73734@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
73735
73736 oldfs = get_fs();
73737 set_fs(KERNEL_DS);
73738- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
73739+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
73740 set_fs(oldfs);
73741
73742 err = compat_put_timex(utp, &txc);
73743@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
73744 oldfs = get_fs();
73745 set_fs(KERNEL_DS);
73746 err = sys_clock_getres(which_clock,
73747- (struct timespec __user *) &ts);
73748+ (struct timespec __force_user *) &ts);
73749 set_fs(oldfs);
73750 if (!err && tp && put_compat_timespec(&ts, tp))
73751 return -EFAULT;
73752@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
73753 long err;
73754 mm_segment_t oldfs;
73755 struct timespec tu;
73756- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
73757+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
73758
73759- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
73760+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
73761 oldfs = get_fs();
73762 set_fs(KERNEL_DS);
73763 err = clock_nanosleep_restart(restart);
73764@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
73765 oldfs = get_fs();
73766 set_fs(KERNEL_DS);
73767 err = sys_clock_nanosleep(which_clock, flags,
73768- (struct timespec __user *) &in,
73769- (struct timespec __user *) &out);
73770+ (struct timespec __force_user *) &in,
73771+ (struct timespec __force_user *) &out);
73772 set_fs(oldfs);
73773
73774 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
73775diff --git a/kernel/configs.c b/kernel/configs.c
73776index 42e8fa0..9e7406b 100644
73777--- a/kernel/configs.c
73778+++ b/kernel/configs.c
73779@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
73780 struct proc_dir_entry *entry;
73781
73782 /* create the current config file */
73783+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
73784+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
73785+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73786+ &ikconfig_file_ops);
73787+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73788+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73789+ &ikconfig_file_ops);
73790+#endif
73791+#else
73792 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73793 &ikconfig_file_ops);
73794+#endif
73795+
73796 if (!entry)
73797 return -ENOMEM;
73798
73799diff --git a/kernel/cred.c b/kernel/cred.c
73800index e0573a4..3874e41 100644
73801--- a/kernel/cred.c
73802+++ b/kernel/cred.c
73803@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73804 validate_creds(cred);
73805 alter_cred_subscribers(cred, -1);
73806 put_cred(cred);
73807+
73808+#ifdef CONFIG_GRKERNSEC_SETXID
73809+ cred = (struct cred *) tsk->delayed_cred;
73810+ if (cred != NULL) {
73811+ tsk->delayed_cred = NULL;
73812+ validate_creds(cred);
73813+ alter_cred_subscribers(cred, -1);
73814+ put_cred(cred);
73815+ }
73816+#endif
73817 }
73818
73819 /**
73820@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73821 * Always returns 0 thus allowing this function to be tail-called at the end
73822 * of, say, sys_setgid().
73823 */
73824-int commit_creds(struct cred *new)
73825+static int __commit_creds(struct cred *new)
73826 {
73827 struct task_struct *task = current;
73828 const struct cred *old = task->real_cred;
73829@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73830
73831 get_cred(new); /* we will require a ref for the subj creds too */
73832
73833+ gr_set_role_label(task, new->uid, new->gid);
73834+
73835 /* dumpability changes */
73836 if (!uid_eq(old->euid, new->euid) ||
73837 !gid_eq(old->egid, new->egid) ||
73838@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73839 put_cred(old);
73840 return 0;
73841 }
73842+#ifdef CONFIG_GRKERNSEC_SETXID
73843+extern int set_user(struct cred *new);
73844+
73845+void gr_delayed_cred_worker(void)
73846+{
73847+ const struct cred *new = current->delayed_cred;
73848+ struct cred *ncred;
73849+
73850+ current->delayed_cred = NULL;
73851+
73852+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73853+ // from doing get_cred on it when queueing this
73854+ put_cred(new);
73855+ return;
73856+ } else if (new == NULL)
73857+ return;
73858+
73859+ ncred = prepare_creds();
73860+ if (!ncred)
73861+ goto die;
73862+ // uids
73863+ ncred->uid = new->uid;
73864+ ncred->euid = new->euid;
73865+ ncred->suid = new->suid;
73866+ ncred->fsuid = new->fsuid;
73867+ // gids
73868+ ncred->gid = new->gid;
73869+ ncred->egid = new->egid;
73870+ ncred->sgid = new->sgid;
73871+ ncred->fsgid = new->fsgid;
73872+ // groups
73873+ if (set_groups(ncred, new->group_info) < 0) {
73874+ abort_creds(ncred);
73875+ goto die;
73876+ }
73877+ // caps
73878+ ncred->securebits = new->securebits;
73879+ ncred->cap_inheritable = new->cap_inheritable;
73880+ ncred->cap_permitted = new->cap_permitted;
73881+ ncred->cap_effective = new->cap_effective;
73882+ ncred->cap_bset = new->cap_bset;
73883+
73884+ if (set_user(ncred)) {
73885+ abort_creds(ncred);
73886+ goto die;
73887+ }
73888+
73889+ // from doing get_cred on it when queueing this
73890+ put_cred(new);
73891+
73892+ __commit_creds(ncred);
73893+ return;
73894+die:
73895+ // from doing get_cred on it when queueing this
73896+ put_cred(new);
73897+ do_group_exit(SIGKILL);
73898+}
73899+#endif
73900+
73901+int commit_creds(struct cred *new)
73902+{
73903+#ifdef CONFIG_GRKERNSEC_SETXID
73904+ int ret;
73905+ int schedule_it = 0;
73906+ struct task_struct *t;
73907+
73908+ /* we won't get called with tasklist_lock held for writing
73909+ and interrupts disabled as the cred struct in that case is
73910+ init_cred
73911+ */
73912+ if (grsec_enable_setxid && !current_is_single_threaded() &&
73913+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73914+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73915+ schedule_it = 1;
73916+ }
73917+ ret = __commit_creds(new);
73918+ if (schedule_it) {
73919+ rcu_read_lock();
73920+ read_lock(&tasklist_lock);
73921+ for (t = next_thread(current); t != current;
73922+ t = next_thread(t)) {
73923+ if (t->delayed_cred == NULL) {
73924+ t->delayed_cred = get_cred(new);
73925+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73926+ set_tsk_need_resched(t);
73927+ }
73928+ }
73929+ read_unlock(&tasklist_lock);
73930+ rcu_read_unlock();
73931+ }
73932+ return ret;
73933+#else
73934+ return __commit_creds(new);
73935+#endif
73936+}
73937+
73938 EXPORT_SYMBOL(commit_creds);
73939
73940 /**
73941diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73942index 9a61738..c5c8f3a 100644
73943--- a/kernel/debug/debug_core.c
73944+++ b/kernel/debug/debug_core.c
73945@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73946 */
73947 static atomic_t masters_in_kgdb;
73948 static atomic_t slaves_in_kgdb;
73949-static atomic_t kgdb_break_tasklet_var;
73950+static atomic_unchecked_t kgdb_break_tasklet_var;
73951 atomic_t kgdb_setting_breakpoint;
73952
73953 struct task_struct *kgdb_usethread;
73954@@ -132,7 +132,7 @@ int kgdb_single_step;
73955 static pid_t kgdb_sstep_pid;
73956
73957 /* to keep track of the CPU which is doing the single stepping*/
73958-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73959+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73960
73961 /*
73962 * If you are debugging a problem where roundup (the collection of
73963@@ -540,7 +540,7 @@ return_normal:
73964 * kernel will only try for the value of sstep_tries before
73965 * giving up and continuing on.
73966 */
73967- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73968+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73969 (kgdb_info[cpu].task &&
73970 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73971 atomic_set(&kgdb_active, -1);
73972@@ -634,8 +634,8 @@ cpu_master_loop:
73973 }
73974
73975 kgdb_restore:
73976- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73977- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73978+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73979+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73980 if (kgdb_info[sstep_cpu].task)
73981 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73982 else
73983@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73984 static void kgdb_tasklet_bpt(unsigned long ing)
73985 {
73986 kgdb_breakpoint();
73987- atomic_set(&kgdb_break_tasklet_var, 0);
73988+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73989 }
73990
73991 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
73992
73993 void kgdb_schedule_breakpoint(void)
73994 {
73995- if (atomic_read(&kgdb_break_tasklet_var) ||
73996+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
73997 atomic_read(&kgdb_active) != -1 ||
73998 atomic_read(&kgdb_setting_breakpoint))
73999 return;
74000- atomic_inc(&kgdb_break_tasklet_var);
74001+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
74002 tasklet_schedule(&kgdb_tasklet_breakpoint);
74003 }
74004 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
74005diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
74006index 8875254..7cf4928 100644
74007--- a/kernel/debug/kdb/kdb_main.c
74008+++ b/kernel/debug/kdb/kdb_main.c
74009@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
74010 continue;
74011
74012 kdb_printf("%-20s%8u 0x%p ", mod->name,
74013- mod->core_size, (void *)mod);
74014+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
74015 #ifdef CONFIG_MODULE_UNLOAD
74016 kdb_printf("%4ld ", module_refcount(mod));
74017 #endif
74018@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
74019 kdb_printf(" (Loading)");
74020 else
74021 kdb_printf(" (Live)");
74022- kdb_printf(" 0x%p", mod->module_core);
74023+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
74024
74025 #ifdef CONFIG_MODULE_UNLOAD
74026 {
74027diff --git a/kernel/events/core.c b/kernel/events/core.c
74028index 7b6646a..3cb1135 100644
74029--- a/kernel/events/core.c
74030+++ b/kernel/events/core.c
74031@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
74032 return 0;
74033 }
74034
74035-static atomic64_t perf_event_id;
74036+static atomic64_unchecked_t perf_event_id;
74037
74038 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
74039 enum event_type_t event_type);
74040@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
74041
74042 static inline u64 perf_event_count(struct perf_event *event)
74043 {
74044- return local64_read(&event->count) + atomic64_read(&event->child_count);
74045+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
74046 }
74047
74048 static u64 perf_event_read(struct perf_event *event)
74049@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
74050 mutex_lock(&event->child_mutex);
74051 total += perf_event_read(event);
74052 *enabled += event->total_time_enabled +
74053- atomic64_read(&event->child_total_time_enabled);
74054+ atomic64_read_unchecked(&event->child_total_time_enabled);
74055 *running += event->total_time_running +
74056- atomic64_read(&event->child_total_time_running);
74057+ atomic64_read_unchecked(&event->child_total_time_running);
74058
74059 list_for_each_entry(child, &event->child_list, child_list) {
74060 total += perf_event_read(child);
74061@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
74062 userpg->offset -= local64_read(&event->hw.prev_count);
74063
74064 userpg->time_enabled = enabled +
74065- atomic64_read(&event->child_total_time_enabled);
74066+ atomic64_read_unchecked(&event->child_total_time_enabled);
74067
74068 userpg->time_running = running +
74069- atomic64_read(&event->child_total_time_running);
74070+ atomic64_read_unchecked(&event->child_total_time_running);
74071
74072 arch_perf_update_userpage(userpg, now);
74073
74074@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
74075 values[n++] = perf_event_count(event);
74076 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
74077 values[n++] = enabled +
74078- atomic64_read(&event->child_total_time_enabled);
74079+ atomic64_read_unchecked(&event->child_total_time_enabled);
74080 }
74081 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
74082 values[n++] = running +
74083- atomic64_read(&event->child_total_time_running);
74084+ atomic64_read_unchecked(&event->child_total_time_running);
74085 }
74086 if (read_format & PERF_FORMAT_ID)
74087 values[n++] = primary_event_id(event);
74088@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
74089 * need to add enough zero bytes after the string to handle
74090 * the 64bit alignment we do later.
74091 */
74092- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
74093+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
74094 if (!buf) {
74095 name = strncpy(tmp, "//enomem", sizeof(tmp));
74096 goto got_name;
74097 }
74098- name = d_path(&file->f_path, buf, PATH_MAX);
74099+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
74100 if (IS_ERR(name)) {
74101 name = strncpy(tmp, "//toolong", sizeof(tmp));
74102 goto got_name;
74103@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
74104 event->parent = parent_event;
74105
74106 event->ns = get_pid_ns(task_active_pid_ns(current));
74107- event->id = atomic64_inc_return(&perf_event_id);
74108+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
74109
74110 event->state = PERF_EVENT_STATE_INACTIVE;
74111
74112@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
74113 /*
74114 * Add back the child's count to the parent's count:
74115 */
74116- atomic64_add(child_val, &parent_event->child_count);
74117- atomic64_add(child_event->total_time_enabled,
74118+ atomic64_add_unchecked(child_val, &parent_event->child_count);
74119+ atomic64_add_unchecked(child_event->total_time_enabled,
74120 &parent_event->child_total_time_enabled);
74121- atomic64_add(child_event->total_time_running,
74122+ atomic64_add_unchecked(child_event->total_time_running,
74123 &parent_event->child_total_time_running);
74124
74125 /*
74126diff --git a/kernel/exit.c b/kernel/exit.c
74127index b4df219..f13c02d 100644
74128--- a/kernel/exit.c
74129+++ b/kernel/exit.c
74130@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
74131 struct task_struct *leader;
74132 int zap_leader;
74133 repeat:
74134+#ifdef CONFIG_NET
74135+ gr_del_task_from_ip_table(p);
74136+#endif
74137+
74138 /* don't need to get the RCU readlock here - the process is dead and
74139 * can't be modifying its own credentials. But shut RCU-lockdep up */
74140 rcu_read_lock();
74141@@ -338,7 +342,7 @@ int allow_signal(int sig)
74142 * know it'll be handled, so that they don't get converted to
74143 * SIGKILL or just silently dropped.
74144 */
74145- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
74146+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
74147 recalc_sigpending();
74148 spin_unlock_irq(&current->sighand->siglock);
74149 return 0;
74150@@ -708,6 +712,8 @@ void do_exit(long code)
74151 struct task_struct *tsk = current;
74152 int group_dead;
74153
74154+ set_fs(USER_DS);
74155+
74156 profile_task_exit(tsk);
74157
74158 WARN_ON(blk_needs_flush_plug(tsk));
74159@@ -724,7 +730,6 @@ void do_exit(long code)
74160 * mm_release()->clear_child_tid() from writing to a user-controlled
74161 * kernel address.
74162 */
74163- set_fs(USER_DS);
74164
74165 ptrace_event(PTRACE_EVENT_EXIT, code);
74166
74167@@ -783,6 +788,9 @@ void do_exit(long code)
74168 tsk->exit_code = code;
74169 taskstats_exit(tsk, group_dead);
74170
74171+ gr_acl_handle_psacct(tsk, code);
74172+ gr_acl_handle_exit();
74173+
74174 exit_mm(tsk);
74175
74176 if (group_dead)
74177@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
74178 * Take down every thread in the group. This is called by fatal signals
74179 * as well as by sys_exit_group (below).
74180 */
74181-void
74182+__noreturn void
74183 do_group_exit(int exit_code)
74184 {
74185 struct signal_struct *sig = current->signal;
74186diff --git a/kernel/fork.c b/kernel/fork.c
74187index 5630e52..0cee608 100644
74188--- a/kernel/fork.c
74189+++ b/kernel/fork.c
74190@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
74191 *stackend = STACK_END_MAGIC; /* for overflow detection */
74192
74193 #ifdef CONFIG_CC_STACKPROTECTOR
74194- tsk->stack_canary = get_random_int();
74195+ tsk->stack_canary = pax_get_random_long();
74196 #endif
74197
74198 /*
74199@@ -344,13 +344,81 @@ free_tsk:
74200 }
74201
74202 #ifdef CONFIG_MMU
74203+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
74204+{
74205+ struct vm_area_struct *tmp;
74206+ unsigned long charge;
74207+ struct mempolicy *pol;
74208+ struct file *file;
74209+
74210+ charge = 0;
74211+ if (mpnt->vm_flags & VM_ACCOUNT) {
74212+ unsigned long len = vma_pages(mpnt);
74213+
74214+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74215+ goto fail_nomem;
74216+ charge = len;
74217+ }
74218+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74219+ if (!tmp)
74220+ goto fail_nomem;
74221+ *tmp = *mpnt;
74222+ tmp->vm_mm = mm;
74223+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
74224+ pol = mpol_dup(vma_policy(mpnt));
74225+ if (IS_ERR(pol))
74226+ goto fail_nomem_policy;
74227+ vma_set_policy(tmp, pol);
74228+ if (anon_vma_fork(tmp, mpnt))
74229+ goto fail_nomem_anon_vma_fork;
74230+ tmp->vm_flags &= ~VM_LOCKED;
74231+ tmp->vm_next = tmp->vm_prev = NULL;
74232+ tmp->vm_mirror = NULL;
74233+ file = tmp->vm_file;
74234+ if (file) {
74235+ struct inode *inode = file->f_path.dentry->d_inode;
74236+ struct address_space *mapping = file->f_mapping;
74237+
74238+ get_file(file);
74239+ if (tmp->vm_flags & VM_DENYWRITE)
74240+ atomic_dec(&inode->i_writecount);
74241+ mutex_lock(&mapping->i_mmap_mutex);
74242+ if (tmp->vm_flags & VM_SHARED)
74243+ mapping->i_mmap_writable++;
74244+ flush_dcache_mmap_lock(mapping);
74245+ /* insert tmp into the share list, just after mpnt */
74246+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74247+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
74248+ else
74249+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
74250+ flush_dcache_mmap_unlock(mapping);
74251+ mutex_unlock(&mapping->i_mmap_mutex);
74252+ }
74253+
74254+ /*
74255+ * Clear hugetlb-related page reserves for children. This only
74256+ * affects MAP_PRIVATE mappings. Faults generated by the child
74257+ * are not guaranteed to succeed, even if read-only
74258+ */
74259+ if (is_vm_hugetlb_page(tmp))
74260+ reset_vma_resv_huge_pages(tmp);
74261+
74262+ return tmp;
74263+
74264+fail_nomem_anon_vma_fork:
74265+ mpol_put(pol);
74266+fail_nomem_policy:
74267+ kmem_cache_free(vm_area_cachep, tmp);
74268+fail_nomem:
74269+ vm_unacct_memory(charge);
74270+ return NULL;
74271+}
74272+
74273 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74274 {
74275 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
74276 struct rb_node **rb_link, *rb_parent;
74277 int retval;
74278- unsigned long charge;
74279- struct mempolicy *pol;
74280
74281 uprobe_start_dup_mmap();
74282 down_write(&oldmm->mmap_sem);
74283@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74284 mm->locked_vm = 0;
74285 mm->mmap = NULL;
74286 mm->mmap_cache = NULL;
74287- mm->free_area_cache = oldmm->mmap_base;
74288- mm->cached_hole_size = ~0UL;
74289+ mm->free_area_cache = oldmm->free_area_cache;
74290+ mm->cached_hole_size = oldmm->cached_hole_size;
74291 mm->map_count = 0;
74292 cpumask_clear(mm_cpumask(mm));
74293 mm->mm_rb = RB_ROOT;
74294@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74295
74296 prev = NULL;
74297 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
74298- struct file *file;
74299-
74300 if (mpnt->vm_flags & VM_DONTCOPY) {
74301 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
74302 -vma_pages(mpnt));
74303 continue;
74304 }
74305- charge = 0;
74306- if (mpnt->vm_flags & VM_ACCOUNT) {
74307- unsigned long len = vma_pages(mpnt);
74308-
74309- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74310- goto fail_nomem;
74311- charge = len;
74312- }
74313- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74314- if (!tmp)
74315- goto fail_nomem;
74316- *tmp = *mpnt;
74317- INIT_LIST_HEAD(&tmp->anon_vma_chain);
74318- pol = mpol_dup(vma_policy(mpnt));
74319- retval = PTR_ERR(pol);
74320- if (IS_ERR(pol))
74321- goto fail_nomem_policy;
74322- vma_set_policy(tmp, pol);
74323- tmp->vm_mm = mm;
74324- if (anon_vma_fork(tmp, mpnt))
74325- goto fail_nomem_anon_vma_fork;
74326- tmp->vm_flags &= ~VM_LOCKED;
74327- tmp->vm_next = tmp->vm_prev = NULL;
74328- file = tmp->vm_file;
74329- if (file) {
74330- struct inode *inode = file->f_path.dentry->d_inode;
74331- struct address_space *mapping = file->f_mapping;
74332-
74333- get_file(file);
74334- if (tmp->vm_flags & VM_DENYWRITE)
74335- atomic_dec(&inode->i_writecount);
74336- mutex_lock(&mapping->i_mmap_mutex);
74337- if (tmp->vm_flags & VM_SHARED)
74338- mapping->i_mmap_writable++;
74339- flush_dcache_mmap_lock(mapping);
74340- /* insert tmp into the share list, just after mpnt */
74341- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74342- vma_nonlinear_insert(tmp,
74343- &mapping->i_mmap_nonlinear);
74344- else
74345- vma_interval_tree_insert_after(tmp, mpnt,
74346- &mapping->i_mmap);
74347- flush_dcache_mmap_unlock(mapping);
74348- mutex_unlock(&mapping->i_mmap_mutex);
74349+ tmp = dup_vma(mm, oldmm, mpnt);
74350+ if (!tmp) {
74351+ retval = -ENOMEM;
74352+ goto out;
74353 }
74354
74355 /*
74356@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74357 if (retval)
74358 goto out;
74359 }
74360+
74361+#ifdef CONFIG_PAX_SEGMEXEC
74362+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
74363+ struct vm_area_struct *mpnt_m;
74364+
74365+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
74366+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
74367+
74368+ if (!mpnt->vm_mirror)
74369+ continue;
74370+
74371+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
74372+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
74373+ mpnt->vm_mirror = mpnt_m;
74374+ } else {
74375+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
74376+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
74377+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
74378+ mpnt->vm_mirror->vm_mirror = mpnt;
74379+ }
74380+ }
74381+ BUG_ON(mpnt_m);
74382+ }
74383+#endif
74384+
74385 /* a new mm has just been created */
74386 arch_dup_mmap(oldmm, mm);
74387 retval = 0;
74388@@ -472,14 +523,6 @@ out:
74389 up_write(&oldmm->mmap_sem);
74390 uprobe_end_dup_mmap();
74391 return retval;
74392-fail_nomem_anon_vma_fork:
74393- mpol_put(pol);
74394-fail_nomem_policy:
74395- kmem_cache_free(vm_area_cachep, tmp);
74396-fail_nomem:
74397- retval = -ENOMEM;
74398- vm_unacct_memory(charge);
74399- goto out;
74400 }
74401
74402 static inline int mm_alloc_pgd(struct mm_struct *mm)
74403@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
74404 return ERR_PTR(err);
74405
74406 mm = get_task_mm(task);
74407- if (mm && mm != current->mm &&
74408- !ptrace_may_access(task, mode)) {
74409+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
74410+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
74411 mmput(mm);
74412 mm = ERR_PTR(-EACCES);
74413 }
74414@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
74415 spin_unlock(&fs->lock);
74416 return -EAGAIN;
74417 }
74418- fs->users++;
74419+ atomic_inc(&fs->users);
74420 spin_unlock(&fs->lock);
74421 return 0;
74422 }
74423 tsk->fs = copy_fs_struct(fs);
74424 if (!tsk->fs)
74425 return -ENOMEM;
74426+ /* Carry through gr_chroot_dentry and is_chrooted instead
74427+ of recomputing it here. Already copied when the task struct
74428+ is duplicated. This allows pivot_root to not be treated as
74429+ a chroot
74430+ */
74431+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
74432+
74433 return 0;
74434 }
74435
74436@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74437 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
74438 #endif
74439 retval = -EAGAIN;
74440+
74441+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
74442+
74443 if (atomic_read(&p->real_cred->user->processes) >=
74444 task_rlimit(p, RLIMIT_NPROC)) {
74445 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
74446@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74447 goto bad_fork_free_pid;
74448 }
74449
74450+ /* synchronizes with gr_set_acls()
74451+ we need to call this past the point of no return for fork()
74452+ */
74453+ gr_copy_label(p);
74454+
74455 if (clone_flags & CLONE_THREAD) {
74456 current->signal->nr_threads++;
74457 atomic_inc(&current->signal->live);
74458@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
74459 bad_fork_free:
74460 free_task(p);
74461 fork_out:
74462+ gr_log_forkfail(retval);
74463+
74464 return ERR_PTR(retval);
74465 }
74466
74467@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
74468 return -EINVAL;
74469 }
74470
74471+#ifdef CONFIG_GRKERNSEC
74472+ if (clone_flags & CLONE_NEWUSER) {
74473+ /*
74474+ * This doesn't really inspire confidence:
74475+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
74476+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
74477+ * Increases kernel attack surface in areas developers
74478+ * previously cared little about ("low importance due
74479+ * to requiring "root" capability")
74480+ * To be removed when this code receives *proper* review
74481+ */
74482+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
74483+ !capable(CAP_SETGID))
74484+ return -EPERM;
74485+ }
74486+#endif
74487+
74488 /*
74489 * Determine whether and which event to report to ptracer. When
74490 * called from kernel_thread or CLONE_UNTRACED is explicitly
74491@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
74492 if (clone_flags & CLONE_PARENT_SETTID)
74493 put_user(nr, parent_tidptr);
74494
74495+ gr_handle_brute_check();
74496+
74497 if (clone_flags & CLONE_VFORK) {
74498 p->vfork_done = &vfork;
74499 init_completion(&vfork);
74500@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
74501 return 0;
74502
74503 /* don't need lock here; in the worst case we'll do useless copy */
74504- if (fs->users == 1)
74505+ if (atomic_read(&fs->users) == 1)
74506 return 0;
74507
74508 *new_fsp = copy_fs_struct(fs);
74509@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
74510 fs = current->fs;
74511 spin_lock(&fs->lock);
74512 current->fs = new_fs;
74513- if (--fs->users)
74514+ gr_set_chroot_entries(current, &current->fs->root);
74515+ if (atomic_dec_return(&fs->users))
74516 new_fs = NULL;
74517 else
74518 new_fs = fs;
74519diff --git a/kernel/futex.c b/kernel/futex.c
74520index 8879430..31696f1 100644
74521--- a/kernel/futex.c
74522+++ b/kernel/futex.c
74523@@ -54,6 +54,7 @@
74524 #include <linux/mount.h>
74525 #include <linux/pagemap.h>
74526 #include <linux/syscalls.h>
74527+#include <linux/ptrace.h>
74528 #include <linux/signal.h>
74529 #include <linux/export.h>
74530 #include <linux/magic.h>
74531@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
74532 struct page *page, *page_head;
74533 int err, ro = 0;
74534
74535+#ifdef CONFIG_PAX_SEGMEXEC
74536+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
74537+ return -EFAULT;
74538+#endif
74539+
74540 /*
74541 * The futex address must be "naturally" aligned.
74542 */
74543@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
74544 {
74545 u32 curval;
74546 int i;
74547+ mm_segment_t oldfs;
74548
74549 /*
74550 * This will fail and we want it. Some arch implementations do
74551@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
74552 * implementation, the non-functional ones will return
74553 * -ENOSYS.
74554 */
74555+ oldfs = get_fs();
74556+ set_fs(USER_DS);
74557 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
74558 futex_cmpxchg_enabled = 1;
74559+ set_fs(oldfs);
74560
74561 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
74562 plist_head_init(&futex_queues[i].chain);
74563diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
74564index 9b22d03..6295b62 100644
74565--- a/kernel/gcov/base.c
74566+++ b/kernel/gcov/base.c
74567@@ -102,11 +102,6 @@ void gcov_enable_events(void)
74568 }
74569
74570 #ifdef CONFIG_MODULES
74571-static inline int within(void *addr, void *start, unsigned long size)
74572-{
74573- return ((addr >= start) && (addr < start + size));
74574-}
74575-
74576 /* Update list and generate events when modules are unloaded. */
74577 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74578 void *data)
74579@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74580 prev = NULL;
74581 /* Remove entries located in module from linked list. */
74582 for (info = gcov_info_head; info; info = info->next) {
74583- if (within(info, mod->module_core, mod->core_size)) {
74584+ if (within_module_core_rw((unsigned long)info, mod)) {
74585 if (prev)
74586 prev->next = info->next;
74587 else
74588diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
74589index cdd5607..c3fc919 100644
74590--- a/kernel/hrtimer.c
74591+++ b/kernel/hrtimer.c
74592@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
74593 local_irq_restore(flags);
74594 }
74595
74596-static void run_hrtimer_softirq(struct softirq_action *h)
74597+static void run_hrtimer_softirq(void)
74598 {
74599 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
74600
74601@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
74602 return NOTIFY_OK;
74603 }
74604
74605-static struct notifier_block __cpuinitdata hrtimers_nb = {
74606+static struct notifier_block hrtimers_nb = {
74607 .notifier_call = hrtimer_cpu_notify,
74608 };
74609
74610diff --git a/kernel/jump_label.c b/kernel/jump_label.c
74611index 60f48fa..7f3a770 100644
74612--- a/kernel/jump_label.c
74613+++ b/kernel/jump_label.c
74614@@ -13,6 +13,7 @@
74615 #include <linux/sort.h>
74616 #include <linux/err.h>
74617 #include <linux/static_key.h>
74618+#include <linux/mm.h>
74619
74620 #ifdef HAVE_JUMP_LABEL
74621
74622@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
74623
74624 size = (((unsigned long)stop - (unsigned long)start)
74625 / sizeof(struct jump_entry));
74626+ pax_open_kernel();
74627 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
74628+ pax_close_kernel();
74629 }
74630
74631 static void jump_label_update(struct static_key *key, int enable);
74632@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
74633 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
74634 struct jump_entry *iter;
74635
74636+ pax_open_kernel();
74637 for (iter = iter_start; iter < iter_stop; iter++) {
74638 if (within_module_init(iter->code, mod))
74639 iter->code = 0;
74640 }
74641+ pax_close_kernel();
74642 }
74643
74644 static int
74645diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
74646index 2169fee..706ccca 100644
74647--- a/kernel/kallsyms.c
74648+++ b/kernel/kallsyms.c
74649@@ -11,6 +11,9 @@
74650 * Changed the compression method from stem compression to "table lookup"
74651 * compression (see scripts/kallsyms.c for a more complete description)
74652 */
74653+#ifdef CONFIG_GRKERNSEC_HIDESYM
74654+#define __INCLUDED_BY_HIDESYM 1
74655+#endif
74656 #include <linux/kallsyms.h>
74657 #include <linux/module.h>
74658 #include <linux/init.h>
74659@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
74660
74661 static inline int is_kernel_inittext(unsigned long addr)
74662 {
74663+ if (system_state != SYSTEM_BOOTING)
74664+ return 0;
74665+
74666 if (addr >= (unsigned long)_sinittext
74667 && addr <= (unsigned long)_einittext)
74668 return 1;
74669 return 0;
74670 }
74671
74672+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74673+#ifdef CONFIG_MODULES
74674+static inline int is_module_text(unsigned long addr)
74675+{
74676+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
74677+ return 1;
74678+
74679+ addr = ktla_ktva(addr);
74680+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
74681+}
74682+#else
74683+static inline int is_module_text(unsigned long addr)
74684+{
74685+ return 0;
74686+}
74687+#endif
74688+#endif
74689+
74690 static inline int is_kernel_text(unsigned long addr)
74691 {
74692 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
74693@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
74694
74695 static inline int is_kernel(unsigned long addr)
74696 {
74697+
74698+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74699+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
74700+ return 1;
74701+
74702+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
74703+#else
74704 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
74705+#endif
74706+
74707 return 1;
74708 return in_gate_area_no_mm(addr);
74709 }
74710
74711 static int is_ksym_addr(unsigned long addr)
74712 {
74713+
74714+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74715+ if (is_module_text(addr))
74716+ return 0;
74717+#endif
74718+
74719 if (all_var)
74720 return is_kernel(addr);
74721
74722@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
74723
74724 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
74725 {
74726- iter->name[0] = '\0';
74727 iter->nameoff = get_symbol_offset(new_pos);
74728 iter->pos = new_pos;
74729 }
74730@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
74731 {
74732 struct kallsym_iter *iter = m->private;
74733
74734+#ifdef CONFIG_GRKERNSEC_HIDESYM
74735+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
74736+ return 0;
74737+#endif
74738+
74739 /* Some debugging symbols have no name. Ignore them. */
74740 if (!iter->name[0])
74741 return 0;
74742@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
74743 */
74744 type = iter->exported ? toupper(iter->type) :
74745 tolower(iter->type);
74746+
74747 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
74748 type, iter->name, iter->module_name);
74749 } else
74750@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
74751 struct kallsym_iter *iter;
74752 int ret;
74753
74754- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
74755+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
74756 if (!iter)
74757 return -ENOMEM;
74758 reset_iter(iter, 0);
74759diff --git a/kernel/kcmp.c b/kernel/kcmp.c
74760index e30ac0f..3528cac 100644
74761--- a/kernel/kcmp.c
74762+++ b/kernel/kcmp.c
74763@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
74764 struct task_struct *task1, *task2;
74765 int ret;
74766
74767+#ifdef CONFIG_GRKERNSEC
74768+ return -ENOSYS;
74769+#endif
74770+
74771 rcu_read_lock();
74772
74773 /*
74774diff --git a/kernel/kexec.c b/kernel/kexec.c
74775index 5e4bd78..00c5b91 100644
74776--- a/kernel/kexec.c
74777+++ b/kernel/kexec.c
74778@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
74779 unsigned long flags)
74780 {
74781 struct compat_kexec_segment in;
74782- struct kexec_segment out, __user *ksegments;
74783+ struct kexec_segment out;
74784+ struct kexec_segment __user *ksegments;
74785 unsigned long i, result;
74786
74787 /* Don't allow clients that don't understand the native
74788diff --git a/kernel/kmod.c b/kernel/kmod.c
74789index 0023a87..9c0c068 100644
74790--- a/kernel/kmod.c
74791+++ b/kernel/kmod.c
74792@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74793 kfree(info->argv);
74794 }
74795
74796-static int call_modprobe(char *module_name, int wait)
74797+static int call_modprobe(char *module_name, char *module_param, int wait)
74798 {
74799 static char *envp[] = {
74800 "HOME=/",
74801@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74802 NULL
74803 };
74804
74805- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74806+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74807 if (!argv)
74808 goto out;
74809
74810@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74811 argv[1] = "-q";
74812 argv[2] = "--";
74813 argv[3] = module_name; /* check free_modprobe_argv() */
74814- argv[4] = NULL;
74815+ argv[4] = module_param;
74816+ argv[5] = NULL;
74817
74818 return call_usermodehelper_fns(modprobe_path, argv, envp,
74819 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74820@@ -120,9 +121,8 @@ out:
74821 * If module auto-loading support is disabled then this function
74822 * becomes a no-operation.
74823 */
74824-int __request_module(bool wait, const char *fmt, ...)
74825+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74826 {
74827- va_list args;
74828 char module_name[MODULE_NAME_LEN];
74829 unsigned int max_modprobes;
74830 int ret;
74831@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74832 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74833 static int kmod_loop_msg;
74834
74835- va_start(args, fmt);
74836- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74837- va_end(args);
74838+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74839 if (ret >= MODULE_NAME_LEN)
74840 return -ENAMETOOLONG;
74841
74842@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
74843 if (ret)
74844 return ret;
74845
74846+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74847+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74848+ /* hack to workaround consolekit/udisks stupidity */
74849+ read_lock(&tasklist_lock);
74850+ if (!strcmp(current->comm, "mount") &&
74851+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
74852+ read_unlock(&tasklist_lock);
74853+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
74854+ return -EPERM;
74855+ }
74856+ read_unlock(&tasklist_lock);
74857+ }
74858+#endif
74859+
74860 /* If modprobe needs a service that is in a module, we get a recursive
74861 * loop. Limit the number of running kmod threads to max_threads/2 or
74862 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
74863@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
74864
74865 trace_module_request(module_name, wait, _RET_IP_);
74866
74867- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74868+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74869
74870 atomic_dec(&kmod_concurrent);
74871 return ret;
74872 }
74873+
74874+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
74875+{
74876+ va_list args;
74877+ int ret;
74878+
74879+ va_start(args, fmt);
74880+ ret = ____request_module(wait, module_param, fmt, args);
74881+ va_end(args);
74882+
74883+ return ret;
74884+}
74885+
74886+int __request_module(bool wait, const char *fmt, ...)
74887+{
74888+ va_list args;
74889+ int ret;
74890+
74891+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74892+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74893+ char module_param[MODULE_NAME_LEN];
74894+
74895+ memset(module_param, 0, sizeof(module_param));
74896+
74897+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74898+
74899+ va_start(args, fmt);
74900+ ret = ____request_module(wait, module_param, fmt, args);
74901+ va_end(args);
74902+
74903+ return ret;
74904+ }
74905+#endif
74906+
74907+ va_start(args, fmt);
74908+ ret = ____request_module(wait, NULL, fmt, args);
74909+ va_end(args);
74910+
74911+ return ret;
74912+}
74913+
74914 EXPORT_SYMBOL(__request_module);
74915 #endif /* CONFIG_MODULES */
74916
74917@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74918 *
74919 * Thus the __user pointer cast is valid here.
74920 */
74921- sys_wait4(pid, (int __user *)&ret, 0, NULL);
74922+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74923
74924 /*
74925 * If ret is 0, either ____call_usermodehelper failed and the
74926@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74927 static int proc_cap_handler(struct ctl_table *table, int write,
74928 void __user *buffer, size_t *lenp, loff_t *ppos)
74929 {
74930- struct ctl_table t;
74931+ ctl_table_no_const t;
74932 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74933 kernel_cap_t new_cap;
74934 int err, i;
74935diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74936index 098f396..fe85ff1 100644
74937--- a/kernel/kprobes.c
74938+++ b/kernel/kprobes.c
74939@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74940 * kernel image and loaded module images reside. This is required
74941 * so x86_64 can correctly handle the %rip-relative fixups.
74942 */
74943- kip->insns = module_alloc(PAGE_SIZE);
74944+ kip->insns = module_alloc_exec(PAGE_SIZE);
74945 if (!kip->insns) {
74946 kfree(kip);
74947 return NULL;
74948@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74949 */
74950 if (!list_is_singular(&kip->list)) {
74951 list_del(&kip->list);
74952- module_free(NULL, kip->insns);
74953+ module_free_exec(NULL, kip->insns);
74954 kfree(kip);
74955 }
74956 return 1;
74957@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74958 {
74959 int i, err = 0;
74960 unsigned long offset = 0, size = 0;
74961- char *modname, namebuf[128];
74962+ char *modname, namebuf[KSYM_NAME_LEN];
74963 const char *symbol_name;
74964 void *addr;
74965 struct kprobe_blackpoint *kb;
74966@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74967 kprobe_type = "k";
74968
74969 if (sym)
74970- seq_printf(pi, "%p %s %s+0x%x %s ",
74971+ seq_printf(pi, "%pK %s %s+0x%x %s ",
74972 p->addr, kprobe_type, sym, offset,
74973 (modname ? modname : " "));
74974 else
74975- seq_printf(pi, "%p %s %p ",
74976+ seq_printf(pi, "%pK %s %pK ",
74977 p->addr, kprobe_type, p->addr);
74978
74979 if (!pp)
74980@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74981 const char *sym = NULL;
74982 unsigned int i = *(loff_t *) v;
74983 unsigned long offset = 0;
74984- char *modname, namebuf[128];
74985+ char *modname, namebuf[KSYM_NAME_LEN];
74986
74987 head = &kprobe_table[i];
74988 preempt_disable();
74989diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74990index 6ada93c..dce7d5d 100644
74991--- a/kernel/ksysfs.c
74992+++ b/kernel/ksysfs.c
74993@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
74994 {
74995 if (count+1 > UEVENT_HELPER_PATH_LEN)
74996 return -ENOENT;
74997+ if (!capable(CAP_SYS_ADMIN))
74998+ return -EPERM;
74999 memcpy(uevent_helper, buf, count);
75000 uevent_helper[count] = '\0';
75001 if (count && uevent_helper[count-1] == '\n')
75002@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
75003 return count;
75004 }
75005
75006-static struct bin_attribute notes_attr = {
75007+static bin_attribute_no_const notes_attr __read_only = {
75008 .attr = {
75009 .name = "notes",
75010 .mode = S_IRUGO,
75011diff --git a/kernel/lockdep.c b/kernel/lockdep.c
75012index 7981e5b..7f2105c 100644
75013--- a/kernel/lockdep.c
75014+++ b/kernel/lockdep.c
75015@@ -590,6 +590,10 @@ static int static_obj(void *obj)
75016 end = (unsigned long) &_end,
75017 addr = (unsigned long) obj;
75018
75019+#ifdef CONFIG_PAX_KERNEXEC
75020+ start = ktla_ktva(start);
75021+#endif
75022+
75023 /*
75024 * static variable?
75025 */
75026@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
75027 if (!static_obj(lock->key)) {
75028 debug_locks_off();
75029 printk("INFO: trying to register non-static key.\n");
75030+ printk("lock:%pS key:%pS.\n", lock, lock->key);
75031 printk("the code is fine but needs lockdep annotation.\n");
75032 printk("turning off the locking correctness validator.\n");
75033 dump_stack();
75034@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
75035 if (!class)
75036 return 0;
75037 }
75038- atomic_inc((atomic_t *)&class->ops);
75039+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
75040 if (very_verbose(class)) {
75041 printk("\nacquire class [%p] %s", class->key, class->name);
75042 if (class->name_version > 1)
75043diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
75044index b2c71c5..7b88d63 100644
75045--- a/kernel/lockdep_proc.c
75046+++ b/kernel/lockdep_proc.c
75047@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
75048 return 0;
75049 }
75050
75051- seq_printf(m, "%p", class->key);
75052+ seq_printf(m, "%pK", class->key);
75053 #ifdef CONFIG_DEBUG_LOCKDEP
75054 seq_printf(m, " OPS:%8ld", class->ops);
75055 #endif
75056@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
75057
75058 list_for_each_entry(entry, &class->locks_after, entry) {
75059 if (entry->distance == 1) {
75060- seq_printf(m, " -> [%p] ", entry->class->key);
75061+ seq_printf(m, " -> [%pK] ", entry->class->key);
75062 print_name(m, entry->class);
75063 seq_puts(m, "\n");
75064 }
75065@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
75066 if (!class->key)
75067 continue;
75068
75069- seq_printf(m, "[%p] ", class->key);
75070+ seq_printf(m, "[%pK] ", class->key);
75071 print_name(m, class);
75072 seq_puts(m, "\n");
75073 }
75074@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75075 if (!i)
75076 seq_line(m, '-', 40-namelen, namelen);
75077
75078- snprintf(ip, sizeof(ip), "[<%p>]",
75079+ snprintf(ip, sizeof(ip), "[<%pK>]",
75080 (void *)class->contention_point[i]);
75081 seq_printf(m, "%40s %14lu %29s %pS\n",
75082 name, stats->contention_point[i],
75083@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75084 if (!i)
75085 seq_line(m, '-', 40-namelen, namelen);
75086
75087- snprintf(ip, sizeof(ip), "[<%p>]",
75088+ snprintf(ip, sizeof(ip), "[<%pK>]",
75089 (void *)class->contending_point[i]);
75090 seq_printf(m, "%40s %14lu %29s %pS\n",
75091 name, stats->contending_point[i],
75092diff --git a/kernel/module.c b/kernel/module.c
75093index eab0827..f488603 100644
75094--- a/kernel/module.c
75095+++ b/kernel/module.c
75096@@ -61,6 +61,7 @@
75097 #include <linux/pfn.h>
75098 #include <linux/bsearch.h>
75099 #include <linux/fips.h>
75100+#include <linux/grsecurity.h>
75101 #include <uapi/linux/module.h>
75102 #include "module-internal.h"
75103
75104@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
75105
75106 /* Bounds of module allocation, for speeding __module_address.
75107 * Protected by module_mutex. */
75108-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
75109+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
75110+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
75111
75112 int register_module_notifier(struct notifier_block * nb)
75113 {
75114@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75115 return true;
75116
75117 list_for_each_entry_rcu(mod, &modules, list) {
75118- struct symsearch arr[] = {
75119+ struct symsearch modarr[] = {
75120 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
75121 NOT_GPL_ONLY, false },
75122 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
75123@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75124 if (mod->state == MODULE_STATE_UNFORMED)
75125 continue;
75126
75127- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
75128+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
75129 return true;
75130 }
75131 return false;
75132@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
75133 static int percpu_modalloc(struct module *mod,
75134 unsigned long size, unsigned long align)
75135 {
75136- if (align > PAGE_SIZE) {
75137+ if (align-1 >= PAGE_SIZE) {
75138 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
75139 mod->name, align, PAGE_SIZE);
75140 align = PAGE_SIZE;
75141@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
75142 static ssize_t show_coresize(struct module_attribute *mattr,
75143 struct module_kobject *mk, char *buffer)
75144 {
75145- return sprintf(buffer, "%u\n", mk->mod->core_size);
75146+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
75147 }
75148
75149 static struct module_attribute modinfo_coresize =
75150@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
75151 static ssize_t show_initsize(struct module_attribute *mattr,
75152 struct module_kobject *mk, char *buffer)
75153 {
75154- return sprintf(buffer, "%u\n", mk->mod->init_size);
75155+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
75156 }
75157
75158 static struct module_attribute modinfo_initsize =
75159@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
75160 */
75161 #ifdef CONFIG_SYSFS
75162
75163-#ifdef CONFIG_KALLSYMS
75164+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75165 static inline bool sect_empty(const Elf_Shdr *sect)
75166 {
75167 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
75168@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
75169 {
75170 unsigned int notes, loaded, i;
75171 struct module_notes_attrs *notes_attrs;
75172- struct bin_attribute *nattr;
75173+ bin_attribute_no_const *nattr;
75174
75175 /* failed to create section attributes, so can't create notes */
75176 if (!mod->sect_attrs)
75177@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
75178 static int module_add_modinfo_attrs(struct module *mod)
75179 {
75180 struct module_attribute *attr;
75181- struct module_attribute *temp_attr;
75182+ module_attribute_no_const *temp_attr;
75183 int error = 0;
75184 int i;
75185
75186@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
75187
75188 static void unset_module_core_ro_nx(struct module *mod)
75189 {
75190- set_page_attributes(mod->module_core + mod->core_text_size,
75191- mod->module_core + mod->core_size,
75192+ set_page_attributes(mod->module_core_rw,
75193+ mod->module_core_rw + mod->core_size_rw,
75194 set_memory_x);
75195- set_page_attributes(mod->module_core,
75196- mod->module_core + mod->core_ro_size,
75197+ set_page_attributes(mod->module_core_rx,
75198+ mod->module_core_rx + mod->core_size_rx,
75199 set_memory_rw);
75200 }
75201
75202 static void unset_module_init_ro_nx(struct module *mod)
75203 {
75204- set_page_attributes(mod->module_init + mod->init_text_size,
75205- mod->module_init + mod->init_size,
75206+ set_page_attributes(mod->module_init_rw,
75207+ mod->module_init_rw + mod->init_size_rw,
75208 set_memory_x);
75209- set_page_attributes(mod->module_init,
75210- mod->module_init + mod->init_ro_size,
75211+ set_page_attributes(mod->module_init_rx,
75212+ mod->module_init_rx + mod->init_size_rx,
75213 set_memory_rw);
75214 }
75215
75216@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
75217 list_for_each_entry_rcu(mod, &modules, list) {
75218 if (mod->state == MODULE_STATE_UNFORMED)
75219 continue;
75220- if ((mod->module_core) && (mod->core_text_size)) {
75221- set_page_attributes(mod->module_core,
75222- mod->module_core + mod->core_text_size,
75223+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75224+ set_page_attributes(mod->module_core_rx,
75225+ mod->module_core_rx + mod->core_size_rx,
75226 set_memory_rw);
75227 }
75228- if ((mod->module_init) && (mod->init_text_size)) {
75229- set_page_attributes(mod->module_init,
75230- mod->module_init + mod->init_text_size,
75231+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75232+ set_page_attributes(mod->module_init_rx,
75233+ mod->module_init_rx + mod->init_size_rx,
75234 set_memory_rw);
75235 }
75236 }
75237@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
75238 list_for_each_entry_rcu(mod, &modules, list) {
75239 if (mod->state == MODULE_STATE_UNFORMED)
75240 continue;
75241- if ((mod->module_core) && (mod->core_text_size)) {
75242- set_page_attributes(mod->module_core,
75243- mod->module_core + mod->core_text_size,
75244+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75245+ set_page_attributes(mod->module_core_rx,
75246+ mod->module_core_rx + mod->core_size_rx,
75247 set_memory_ro);
75248 }
75249- if ((mod->module_init) && (mod->init_text_size)) {
75250- set_page_attributes(mod->module_init,
75251- mod->module_init + mod->init_text_size,
75252+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75253+ set_page_attributes(mod->module_init_rx,
75254+ mod->module_init_rx + mod->init_size_rx,
75255 set_memory_ro);
75256 }
75257 }
75258@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
75259
75260 /* This may be NULL, but that's OK */
75261 unset_module_init_ro_nx(mod);
75262- module_free(mod, mod->module_init);
75263+ module_free(mod, mod->module_init_rw);
75264+ module_free_exec(mod, mod->module_init_rx);
75265 kfree(mod->args);
75266 percpu_modfree(mod);
75267
75268 /* Free lock-classes: */
75269- lockdep_free_key_range(mod->module_core, mod->core_size);
75270+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
75271+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
75272
75273 /* Finally, free the core (containing the module structure) */
75274 unset_module_core_ro_nx(mod);
75275- module_free(mod, mod->module_core);
75276+ module_free_exec(mod, mod->module_core_rx);
75277+ module_free(mod, mod->module_core_rw);
75278
75279 #ifdef CONFIG_MPU
75280 update_protections(current->mm);
75281@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75282 int ret = 0;
75283 const struct kernel_symbol *ksym;
75284
75285+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75286+ int is_fs_load = 0;
75287+ int register_filesystem_found = 0;
75288+ char *p;
75289+
75290+ p = strstr(mod->args, "grsec_modharden_fs");
75291+ if (p) {
75292+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
75293+ /* copy \0 as well */
75294+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
75295+ is_fs_load = 1;
75296+ }
75297+#endif
75298+
75299 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
75300 const char *name = info->strtab + sym[i].st_name;
75301
75302+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75303+ /* it's a real shame this will never get ripped and copied
75304+ upstream! ;(
75305+ */
75306+ if (is_fs_load && !strcmp(name, "register_filesystem"))
75307+ register_filesystem_found = 1;
75308+#endif
75309+
75310 switch (sym[i].st_shndx) {
75311 case SHN_COMMON:
75312 /* We compiled with -fno-common. These are not
75313@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75314 ksym = resolve_symbol_wait(mod, info, name);
75315 /* Ok if resolved. */
75316 if (ksym && !IS_ERR(ksym)) {
75317+ pax_open_kernel();
75318 sym[i].st_value = ksym->value;
75319+ pax_close_kernel();
75320 break;
75321 }
75322
75323@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75324 secbase = (unsigned long)mod_percpu(mod);
75325 else
75326 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
75327+ pax_open_kernel();
75328 sym[i].st_value += secbase;
75329+ pax_close_kernel();
75330 break;
75331 }
75332 }
75333
75334+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75335+ if (is_fs_load && !register_filesystem_found) {
75336+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
75337+ ret = -EPERM;
75338+ }
75339+#endif
75340+
75341 return ret;
75342 }
75343
75344@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
75345 || s->sh_entsize != ~0UL
75346 || strstarts(sname, ".init"))
75347 continue;
75348- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
75349+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75350+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
75351+ else
75352+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
75353 pr_debug("\t%s\n", sname);
75354 }
75355- switch (m) {
75356- case 0: /* executable */
75357- mod->core_size = debug_align(mod->core_size);
75358- mod->core_text_size = mod->core_size;
75359- break;
75360- case 1: /* RO: text and ro-data */
75361- mod->core_size = debug_align(mod->core_size);
75362- mod->core_ro_size = mod->core_size;
75363- break;
75364- case 3: /* whole core */
75365- mod->core_size = debug_align(mod->core_size);
75366- break;
75367- }
75368 }
75369
75370 pr_debug("Init section allocation order:\n");
75371@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
75372 || s->sh_entsize != ~0UL
75373 || !strstarts(sname, ".init"))
75374 continue;
75375- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
75376- | INIT_OFFSET_MASK);
75377+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75378+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
75379+ else
75380+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
75381+ s->sh_entsize |= INIT_OFFSET_MASK;
75382 pr_debug("\t%s\n", sname);
75383 }
75384- switch (m) {
75385- case 0: /* executable */
75386- mod->init_size = debug_align(mod->init_size);
75387- mod->init_text_size = mod->init_size;
75388- break;
75389- case 1: /* RO: text and ro-data */
75390- mod->init_size = debug_align(mod->init_size);
75391- mod->init_ro_size = mod->init_size;
75392- break;
75393- case 3: /* whole init */
75394- mod->init_size = debug_align(mod->init_size);
75395- break;
75396- }
75397 }
75398 }
75399
75400@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75401
75402 /* Put symbol section at end of init part of module. */
75403 symsect->sh_flags |= SHF_ALLOC;
75404- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
75405+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
75406 info->index.sym) | INIT_OFFSET_MASK;
75407 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
75408
75409@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75410 }
75411
75412 /* Append room for core symbols at end of core part. */
75413- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
75414- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
75415- mod->core_size += strtab_size;
75416+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
75417+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
75418+ mod->core_size_rx += strtab_size;
75419
75420 /* Put string table section at end of init part of module. */
75421 strsect->sh_flags |= SHF_ALLOC;
75422- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
75423+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
75424 info->index.str) | INIT_OFFSET_MASK;
75425 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
75426 }
75427@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75428 /* Make sure we get permanent strtab: don't use info->strtab. */
75429 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
75430
75431+ pax_open_kernel();
75432+
75433 /* Set types up while we still have access to sections. */
75434 for (i = 0; i < mod->num_symtab; i++)
75435 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
75436
75437- mod->core_symtab = dst = mod->module_core + info->symoffs;
75438- mod->core_strtab = s = mod->module_core + info->stroffs;
75439+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
75440+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
75441 src = mod->symtab;
75442 for (ndst = i = 0; i < mod->num_symtab; i++) {
75443 if (i == 0 ||
75444@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75445 }
75446 }
75447 mod->core_num_syms = ndst;
75448+
75449+ pax_close_kernel();
75450 }
75451 #else
75452 static inline void layout_symtab(struct module *mod, struct load_info *info)
75453@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
75454 return vmalloc_exec(size);
75455 }
75456
75457-static void *module_alloc_update_bounds(unsigned long size)
75458+static void *module_alloc_update_bounds_rw(unsigned long size)
75459 {
75460 void *ret = module_alloc(size);
75461
75462 if (ret) {
75463 mutex_lock(&module_mutex);
75464 /* Update module bounds. */
75465- if ((unsigned long)ret < module_addr_min)
75466- module_addr_min = (unsigned long)ret;
75467- if ((unsigned long)ret + size > module_addr_max)
75468- module_addr_max = (unsigned long)ret + size;
75469+ if ((unsigned long)ret < module_addr_min_rw)
75470+ module_addr_min_rw = (unsigned long)ret;
75471+ if ((unsigned long)ret + size > module_addr_max_rw)
75472+ module_addr_max_rw = (unsigned long)ret + size;
75473+ mutex_unlock(&module_mutex);
75474+ }
75475+ return ret;
75476+}
75477+
75478+static void *module_alloc_update_bounds_rx(unsigned long size)
75479+{
75480+ void *ret = module_alloc_exec(size);
75481+
75482+ if (ret) {
75483+ mutex_lock(&module_mutex);
75484+ /* Update module bounds. */
75485+ if ((unsigned long)ret < module_addr_min_rx)
75486+ module_addr_min_rx = (unsigned long)ret;
75487+ if ((unsigned long)ret + size > module_addr_max_rx)
75488+ module_addr_max_rx = (unsigned long)ret + size;
75489 mutex_unlock(&module_mutex);
75490 }
75491 return ret;
75492@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
75493 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75494 {
75495 const char *modmagic = get_modinfo(info, "vermagic");
75496+ const char *license = get_modinfo(info, "license");
75497 int err;
75498
75499+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
75500+ if (!license || !license_is_gpl_compatible(license))
75501+ return -ENOEXEC;
75502+#endif
75503+
75504 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
75505 modmagic = NULL;
75506
75507@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75508 }
75509
75510 /* Set up license info based on the info section */
75511- set_license(mod, get_modinfo(info, "license"));
75512+ set_license(mod, license);
75513
75514 return 0;
75515 }
75516@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
75517 void *ptr;
75518
75519 /* Do the allocs. */
75520- ptr = module_alloc_update_bounds(mod->core_size);
75521+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
75522 /*
75523 * The pointer to this block is stored in the module structure
75524 * which is inside the block. Just mark it as not being a
75525@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
75526 if (!ptr)
75527 return -ENOMEM;
75528
75529- memset(ptr, 0, mod->core_size);
75530- mod->module_core = ptr;
75531+ memset(ptr, 0, mod->core_size_rw);
75532+ mod->module_core_rw = ptr;
75533
75534- if (mod->init_size) {
75535- ptr = module_alloc_update_bounds(mod->init_size);
75536+ if (mod->init_size_rw) {
75537+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
75538 /*
75539 * The pointer to this block is stored in the module structure
75540 * which is inside the block. This block doesn't need to be
75541@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
75542 */
75543 kmemleak_ignore(ptr);
75544 if (!ptr) {
75545- module_free(mod, mod->module_core);
75546+ module_free(mod, mod->module_core_rw);
75547 return -ENOMEM;
75548 }
75549- memset(ptr, 0, mod->init_size);
75550- mod->module_init = ptr;
75551+ memset(ptr, 0, mod->init_size_rw);
75552+ mod->module_init_rw = ptr;
75553 } else
75554- mod->module_init = NULL;
75555+ mod->module_init_rw = NULL;
75556+
75557+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
75558+ kmemleak_not_leak(ptr);
75559+ if (!ptr) {
75560+ if (mod->module_init_rw)
75561+ module_free(mod, mod->module_init_rw);
75562+ module_free(mod, mod->module_core_rw);
75563+ return -ENOMEM;
75564+ }
75565+
75566+ pax_open_kernel();
75567+ memset(ptr, 0, mod->core_size_rx);
75568+ pax_close_kernel();
75569+ mod->module_core_rx = ptr;
75570+
75571+ if (mod->init_size_rx) {
75572+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
75573+ kmemleak_ignore(ptr);
75574+ if (!ptr && mod->init_size_rx) {
75575+ module_free_exec(mod, mod->module_core_rx);
75576+ if (mod->module_init_rw)
75577+ module_free(mod, mod->module_init_rw);
75578+ module_free(mod, mod->module_core_rw);
75579+ return -ENOMEM;
75580+ }
75581+
75582+ pax_open_kernel();
75583+ memset(ptr, 0, mod->init_size_rx);
75584+ pax_close_kernel();
75585+ mod->module_init_rx = ptr;
75586+ } else
75587+ mod->module_init_rx = NULL;
75588
75589 /* Transfer each section which specifies SHF_ALLOC */
75590 pr_debug("final section addresses:\n");
75591@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
75592 if (!(shdr->sh_flags & SHF_ALLOC))
75593 continue;
75594
75595- if (shdr->sh_entsize & INIT_OFFSET_MASK)
75596- dest = mod->module_init
75597- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75598- else
75599- dest = mod->module_core + shdr->sh_entsize;
75600+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
75601+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75602+ dest = mod->module_init_rw
75603+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75604+ else
75605+ dest = mod->module_init_rx
75606+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75607+ } else {
75608+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75609+ dest = mod->module_core_rw + shdr->sh_entsize;
75610+ else
75611+ dest = mod->module_core_rx + shdr->sh_entsize;
75612+ }
75613+
75614+ if (shdr->sh_type != SHT_NOBITS) {
75615+
75616+#ifdef CONFIG_PAX_KERNEXEC
75617+#ifdef CONFIG_X86_64
75618+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
75619+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
75620+#endif
75621+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
75622+ pax_open_kernel();
75623+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75624+ pax_close_kernel();
75625+ } else
75626+#endif
75627
75628- if (shdr->sh_type != SHT_NOBITS)
75629 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75630+ }
75631 /* Update sh_addr to point to copy in image. */
75632- shdr->sh_addr = (unsigned long)dest;
75633+
75634+#ifdef CONFIG_PAX_KERNEXEC
75635+ if (shdr->sh_flags & SHF_EXECINSTR)
75636+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
75637+ else
75638+#endif
75639+
75640+ shdr->sh_addr = (unsigned long)dest;
75641 pr_debug("\t0x%lx %s\n",
75642 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
75643 }
75644@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
75645 * Do it before processing of module parameters, so the module
75646 * can provide parameter accessor functions of its own.
75647 */
75648- if (mod->module_init)
75649- flush_icache_range((unsigned long)mod->module_init,
75650- (unsigned long)mod->module_init
75651- + mod->init_size);
75652- flush_icache_range((unsigned long)mod->module_core,
75653- (unsigned long)mod->module_core + mod->core_size);
75654+ if (mod->module_init_rx)
75655+ flush_icache_range((unsigned long)mod->module_init_rx,
75656+ (unsigned long)mod->module_init_rx
75657+ + mod->init_size_rx);
75658+ flush_icache_range((unsigned long)mod->module_core_rx,
75659+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
75660
75661 set_fs(old_fs);
75662 }
75663@@ -2983,8 +3088,10 @@ out:
75664 static void module_deallocate(struct module *mod, struct load_info *info)
75665 {
75666 percpu_modfree(mod);
75667- module_free(mod, mod->module_init);
75668- module_free(mod, mod->module_core);
75669+ module_free_exec(mod, mod->module_init_rx);
75670+ module_free_exec(mod, mod->module_core_rx);
75671+ module_free(mod, mod->module_init_rw);
75672+ module_free(mod, mod->module_core_rw);
75673 }
75674
75675 int __weak module_finalize(const Elf_Ehdr *hdr,
75676@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
75677 static int post_relocation(struct module *mod, const struct load_info *info)
75678 {
75679 /* Sort exception table now relocations are done. */
75680+ pax_open_kernel();
75681 sort_extable(mod->extable, mod->extable + mod->num_exentries);
75682+ pax_close_kernel();
75683
75684 /* Copy relocated percpu area over. */
75685 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
75686@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
75687 MODULE_STATE_COMING, mod);
75688
75689 /* Set RO and NX regions for core */
75690- set_section_ro_nx(mod->module_core,
75691- mod->core_text_size,
75692- mod->core_ro_size,
75693- mod->core_size);
75694+ set_section_ro_nx(mod->module_core_rx,
75695+ mod->core_size_rx,
75696+ mod->core_size_rx,
75697+ mod->core_size_rx);
75698
75699 /* Set RO and NX regions for init */
75700- set_section_ro_nx(mod->module_init,
75701- mod->init_text_size,
75702- mod->init_ro_size,
75703- mod->init_size);
75704+ set_section_ro_nx(mod->module_init_rx,
75705+ mod->init_size_rx,
75706+ mod->init_size_rx,
75707+ mod->init_size_rx);
75708
75709 do_mod_ctors(mod);
75710 /* Start the module */
75711@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
75712 mod->strtab = mod->core_strtab;
75713 #endif
75714 unset_module_init_ro_nx(mod);
75715- module_free(mod, mod->module_init);
75716- mod->module_init = NULL;
75717- mod->init_size = 0;
75718- mod->init_ro_size = 0;
75719- mod->init_text_size = 0;
75720+ module_free(mod, mod->module_init_rw);
75721+ module_free_exec(mod, mod->module_init_rx);
75722+ mod->module_init_rw = NULL;
75723+ mod->module_init_rx = NULL;
75724+ mod->init_size_rw = 0;
75725+ mod->init_size_rx = 0;
75726 mutex_unlock(&module_mutex);
75727 wake_up_all(&module_wq);
75728
75729@@ -3209,9 +3319,38 @@ again:
75730 if (err)
75731 goto free_unload;
75732
75733+ /* Now copy in args */
75734+ mod->args = strndup_user(uargs, ~0UL >> 1);
75735+ if (IS_ERR(mod->args)) {
75736+ err = PTR_ERR(mod->args);
75737+ goto free_unload;
75738+ }
75739+
75740 /* Set up MODINFO_ATTR fields */
75741 setup_modinfo(mod, info);
75742
75743+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75744+ {
75745+ char *p, *p2;
75746+
75747+ if (strstr(mod->args, "grsec_modharden_netdev")) {
75748+ 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);
75749+ err = -EPERM;
75750+ goto free_modinfo;
75751+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
75752+ p += sizeof("grsec_modharden_normal") - 1;
75753+ p2 = strstr(p, "_");
75754+ if (p2) {
75755+ *p2 = '\0';
75756+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
75757+ *p2 = '_';
75758+ }
75759+ err = -EPERM;
75760+ goto free_modinfo;
75761+ }
75762+ }
75763+#endif
75764+
75765 /* Fix up syms, so that st_value is a pointer to location. */
75766 err = simplify_symbols(mod, info);
75767 if (err < 0)
75768@@ -3227,13 +3366,6 @@ again:
75769
75770 flush_module_icache(mod);
75771
75772- /* Now copy in args */
75773- mod->args = strndup_user(uargs, ~0UL >> 1);
75774- if (IS_ERR(mod->args)) {
75775- err = PTR_ERR(mod->args);
75776- goto free_arch_cleanup;
75777- }
75778-
75779 dynamic_debug_setup(info->debug, info->num_debug);
75780
75781 mutex_lock(&module_mutex);
75782@@ -3278,11 +3410,10 @@ again:
75783 mutex_unlock(&module_mutex);
75784 dynamic_debug_remove(info->debug);
75785 synchronize_sched();
75786- kfree(mod->args);
75787- free_arch_cleanup:
75788 module_arch_cleanup(mod);
75789 free_modinfo:
75790 free_modinfo(mod);
75791+ kfree(mod->args);
75792 free_unload:
75793 module_unload_free(mod);
75794 unlink_mod:
75795@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75796 unsigned long nextval;
75797
75798 /* At worse, next value is at end of module */
75799- if (within_module_init(addr, mod))
75800- nextval = (unsigned long)mod->module_init+mod->init_text_size;
75801+ if (within_module_init_rx(addr, mod))
75802+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75803+ else if (within_module_init_rw(addr, mod))
75804+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75805+ else if (within_module_core_rx(addr, mod))
75806+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75807+ else if (within_module_core_rw(addr, mod))
75808+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75809 else
75810- nextval = (unsigned long)mod->module_core+mod->core_text_size;
75811+ return NULL;
75812
75813 /* Scan for closest preceding symbol, and next symbol. (ELF
75814 starts real symbols at 1). */
75815@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75816 return 0;
75817
75818 seq_printf(m, "%s %u",
75819- mod->name, mod->init_size + mod->core_size);
75820+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75821 print_unload_info(m, mod);
75822
75823 /* Informative for users. */
75824@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75825 mod->state == MODULE_STATE_COMING ? "Loading":
75826 "Live");
75827 /* Used by oprofile and other similar tools. */
75828- seq_printf(m, " 0x%pK", mod->module_core);
75829+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75830
75831 /* Taints info */
75832 if (mod->taints)
75833@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75834
75835 static int __init proc_modules_init(void)
75836 {
75837+#ifndef CONFIG_GRKERNSEC_HIDESYM
75838+#ifdef CONFIG_GRKERNSEC_PROC_USER
75839+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75840+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75841+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
75842+#else
75843 proc_create("modules", 0, NULL, &proc_modules_operations);
75844+#endif
75845+#else
75846+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75847+#endif
75848 return 0;
75849 }
75850 module_init(proc_modules_init);
75851@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
75852 {
75853 struct module *mod;
75854
75855- if (addr < module_addr_min || addr > module_addr_max)
75856+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
75857+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
75858 return NULL;
75859
75860 list_for_each_entry_rcu(mod, &modules, list) {
75861 if (mod->state == MODULE_STATE_UNFORMED)
75862 continue;
75863- if (within_module_core(addr, mod)
75864- || within_module_init(addr, mod))
75865+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
75866 return mod;
75867 }
75868 return NULL;
75869@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
75870 */
75871 struct module *__module_text_address(unsigned long addr)
75872 {
75873- struct module *mod = __module_address(addr);
75874+ struct module *mod;
75875+
75876+#ifdef CONFIG_X86_32
75877+ addr = ktla_ktva(addr);
75878+#endif
75879+
75880+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
75881+ return NULL;
75882+
75883+ mod = __module_address(addr);
75884+
75885 if (mod) {
75886 /* Make sure it's within the text section. */
75887- if (!within(addr, mod->module_init, mod->init_text_size)
75888- && !within(addr, mod->module_core, mod->core_text_size))
75889+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
75890 mod = NULL;
75891 }
75892 return mod;
75893diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
75894index 7e3443f..b2a1e6b 100644
75895--- a/kernel/mutex-debug.c
75896+++ b/kernel/mutex-debug.c
75897@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75898 }
75899
75900 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75901- struct thread_info *ti)
75902+ struct task_struct *task)
75903 {
75904 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75905
75906 /* Mark the current thread as blocked on the lock: */
75907- ti->task->blocked_on = waiter;
75908+ task->blocked_on = waiter;
75909 }
75910
75911 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75912- struct thread_info *ti)
75913+ struct task_struct *task)
75914 {
75915 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75916- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75917- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75918- ti->task->blocked_on = NULL;
75919+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
75920+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75921+ task->blocked_on = NULL;
75922
75923 list_del_init(&waiter->list);
75924 waiter->task = NULL;
75925diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75926index 0799fd3..d06ae3b 100644
75927--- a/kernel/mutex-debug.h
75928+++ b/kernel/mutex-debug.h
75929@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75930 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75931 extern void debug_mutex_add_waiter(struct mutex *lock,
75932 struct mutex_waiter *waiter,
75933- struct thread_info *ti);
75934+ struct task_struct *task);
75935 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75936- struct thread_info *ti);
75937+ struct task_struct *task);
75938 extern void debug_mutex_unlock(struct mutex *lock);
75939 extern void debug_mutex_init(struct mutex *lock, const char *name,
75940 struct lock_class_key *key);
75941diff --git a/kernel/mutex.c b/kernel/mutex.c
75942index a307cc9..27fd2e9 100644
75943--- a/kernel/mutex.c
75944+++ b/kernel/mutex.c
75945@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75946 spin_lock_mutex(&lock->wait_lock, flags);
75947
75948 debug_mutex_lock_common(lock, &waiter);
75949- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75950+ debug_mutex_add_waiter(lock, &waiter, task);
75951
75952 /* add waiting tasks to the end of the waitqueue (FIFO): */
75953 list_add_tail(&waiter.list, &lock->wait_list);
75954@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75955 * TASK_UNINTERRUPTIBLE case.)
75956 */
75957 if (unlikely(signal_pending_state(state, task))) {
75958- mutex_remove_waiter(lock, &waiter,
75959- task_thread_info(task));
75960+ mutex_remove_waiter(lock, &waiter, task);
75961 mutex_release(&lock->dep_map, 1, ip);
75962 spin_unlock_mutex(&lock->wait_lock, flags);
75963
75964@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75965 done:
75966 lock_acquired(&lock->dep_map, ip);
75967 /* got the lock - rejoice! */
75968- mutex_remove_waiter(lock, &waiter, current_thread_info());
75969+ mutex_remove_waiter(lock, &waiter, task);
75970 mutex_set_owner(lock);
75971
75972 /* set it to 0 if there are no waiters left: */
75973diff --git a/kernel/notifier.c b/kernel/notifier.c
75974index 2d5cc4c..d9ea600 100644
75975--- a/kernel/notifier.c
75976+++ b/kernel/notifier.c
75977@@ -5,6 +5,7 @@
75978 #include <linux/rcupdate.h>
75979 #include <linux/vmalloc.h>
75980 #include <linux/reboot.h>
75981+#include <linux/mm.h>
75982
75983 /*
75984 * Notifier list for kernel code which wants to be called
75985@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75986 while ((*nl) != NULL) {
75987 if (n->priority > (*nl)->priority)
75988 break;
75989- nl = &((*nl)->next);
75990+ nl = (struct notifier_block **)&((*nl)->next);
75991 }
75992- n->next = *nl;
75993+ pax_open_kernel();
75994+ *(const void **)&n->next = *nl;
75995 rcu_assign_pointer(*nl, n);
75996+ pax_close_kernel();
75997 return 0;
75998 }
75999
76000@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
76001 return 0;
76002 if (n->priority > (*nl)->priority)
76003 break;
76004- nl = &((*nl)->next);
76005+ nl = (struct notifier_block **)&((*nl)->next);
76006 }
76007- n->next = *nl;
76008+ pax_open_kernel();
76009+ *(const void **)&n->next = *nl;
76010 rcu_assign_pointer(*nl, n);
76011+ pax_close_kernel();
76012 return 0;
76013 }
76014
76015@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
76016 {
76017 while ((*nl) != NULL) {
76018 if ((*nl) == n) {
76019+ pax_open_kernel();
76020 rcu_assign_pointer(*nl, n->next);
76021+ pax_close_kernel();
76022 return 0;
76023 }
76024- nl = &((*nl)->next);
76025+ nl = (struct notifier_block **)&((*nl)->next);
76026 }
76027 return -ENOENT;
76028 }
76029diff --git a/kernel/panic.c b/kernel/panic.c
76030index e1b2822..5edc1d9 100644
76031--- a/kernel/panic.c
76032+++ b/kernel/panic.c
76033@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
76034 const char *board;
76035
76036 printk(KERN_WARNING "------------[ cut here ]------------\n");
76037- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
76038+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
76039 board = dmi_get_system_info(DMI_PRODUCT_NAME);
76040 if (board)
76041 printk(KERN_WARNING "Hardware name: %s\n", board);
76042@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
76043 */
76044 void __stack_chk_fail(void)
76045 {
76046- panic("stack-protector: Kernel stack is corrupted in: %p\n",
76047+ dump_stack();
76048+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
76049 __builtin_return_address(0));
76050 }
76051 EXPORT_SYMBOL(__stack_chk_fail);
76052diff --git a/kernel/pid.c b/kernel/pid.c
76053index f2c6a68..4922d97 100644
76054--- a/kernel/pid.c
76055+++ b/kernel/pid.c
76056@@ -33,6 +33,7 @@
76057 #include <linux/rculist.h>
76058 #include <linux/bootmem.h>
76059 #include <linux/hash.h>
76060+#include <linux/security.h>
76061 #include <linux/pid_namespace.h>
76062 #include <linux/init_task.h>
76063 #include <linux/syscalls.h>
76064@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
76065
76066 int pid_max = PID_MAX_DEFAULT;
76067
76068-#define RESERVED_PIDS 300
76069+#define RESERVED_PIDS 500
76070
76071 int pid_max_min = RESERVED_PIDS + 1;
76072 int pid_max_max = PID_MAX_LIMIT;
76073@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
76074 */
76075 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
76076 {
76077+ struct task_struct *task;
76078+
76079 rcu_lockdep_assert(rcu_read_lock_held(),
76080 "find_task_by_pid_ns() needs rcu_read_lock()"
76081 " protection");
76082- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76083+
76084+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76085+
76086+ if (gr_pid_is_chrooted(task))
76087+ return NULL;
76088+
76089+ return task;
76090 }
76091
76092 struct task_struct *find_task_by_vpid(pid_t vnr)
76093@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
76094 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
76095 }
76096
76097+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
76098+{
76099+ rcu_lockdep_assert(rcu_read_lock_held(),
76100+ "find_task_by_pid_ns() needs rcu_read_lock()"
76101+ " protection");
76102+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
76103+}
76104+
76105 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
76106 {
76107 struct pid *pid;
76108diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
76109index c1c3dc1..bbeaf31 100644
76110--- a/kernel/pid_namespace.c
76111+++ b/kernel/pid_namespace.c
76112@@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
76113 void __user *buffer, size_t *lenp, loff_t *ppos)
76114 {
76115 struct pid_namespace *pid_ns = task_active_pid_ns(current);
76116- struct ctl_table tmp = *table;
76117+ ctl_table_no_const tmp = *table;
76118
76119 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
76120 return -EPERM;
76121diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
76122index 942ca27..111e609 100644
76123--- a/kernel/posix-cpu-timers.c
76124+++ b/kernel/posix-cpu-timers.c
76125@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
76126
76127 static __init int init_posix_cpu_timers(void)
76128 {
76129- struct k_clock process = {
76130+ static struct k_clock process = {
76131 .clock_getres = process_cpu_clock_getres,
76132 .clock_get = process_cpu_clock_get,
76133 .timer_create = process_cpu_timer_create,
76134 .nsleep = process_cpu_nsleep,
76135 .nsleep_restart = process_cpu_nsleep_restart,
76136 };
76137- struct k_clock thread = {
76138+ static struct k_clock thread = {
76139 .clock_getres = thread_cpu_clock_getres,
76140 .clock_get = thread_cpu_clock_get,
76141 .timer_create = thread_cpu_timer_create,
76142diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
76143index e885be1..380fe76 100644
76144--- a/kernel/posix-timers.c
76145+++ b/kernel/posix-timers.c
76146@@ -43,6 +43,7 @@
76147 #include <linux/idr.h>
76148 #include <linux/posix-clock.h>
76149 #include <linux/posix-timers.h>
76150+#include <linux/grsecurity.h>
76151 #include <linux/syscalls.h>
76152 #include <linux/wait.h>
76153 #include <linux/workqueue.h>
76154@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
76155 * which we beg off on and pass to do_sys_settimeofday().
76156 */
76157
76158-static struct k_clock posix_clocks[MAX_CLOCKS];
76159+static struct k_clock *posix_clocks[MAX_CLOCKS];
76160
76161 /*
76162 * These ones are defined below.
76163@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
76164 */
76165 static __init int init_posix_timers(void)
76166 {
76167- struct k_clock clock_realtime = {
76168+ static struct k_clock clock_realtime = {
76169 .clock_getres = hrtimer_get_res,
76170 .clock_get = posix_clock_realtime_get,
76171 .clock_set = posix_clock_realtime_set,
76172@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
76173 .timer_get = common_timer_get,
76174 .timer_del = common_timer_del,
76175 };
76176- struct k_clock clock_monotonic = {
76177+ static struct k_clock clock_monotonic = {
76178 .clock_getres = hrtimer_get_res,
76179 .clock_get = posix_ktime_get_ts,
76180 .nsleep = common_nsleep,
76181@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
76182 .timer_get = common_timer_get,
76183 .timer_del = common_timer_del,
76184 };
76185- struct k_clock clock_monotonic_raw = {
76186+ static struct k_clock clock_monotonic_raw = {
76187 .clock_getres = hrtimer_get_res,
76188 .clock_get = posix_get_monotonic_raw,
76189 };
76190- struct k_clock clock_realtime_coarse = {
76191+ static struct k_clock clock_realtime_coarse = {
76192 .clock_getres = posix_get_coarse_res,
76193 .clock_get = posix_get_realtime_coarse,
76194 };
76195- struct k_clock clock_monotonic_coarse = {
76196+ static struct k_clock clock_monotonic_coarse = {
76197 .clock_getres = posix_get_coarse_res,
76198 .clock_get = posix_get_monotonic_coarse,
76199 };
76200- struct k_clock clock_boottime = {
76201+ static struct k_clock clock_boottime = {
76202 .clock_getres = hrtimer_get_res,
76203 .clock_get = posix_get_boottime,
76204 .nsleep = common_nsleep,
76205@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
76206 return;
76207 }
76208
76209- posix_clocks[clock_id] = *new_clock;
76210+ posix_clocks[clock_id] = new_clock;
76211 }
76212 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
76213
76214@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
76215 return (id & CLOCKFD_MASK) == CLOCKFD ?
76216 &clock_posix_dynamic : &clock_posix_cpu;
76217
76218- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
76219+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
76220 return NULL;
76221- return &posix_clocks[id];
76222+ return posix_clocks[id];
76223 }
76224
76225 static int common_timer_create(struct k_itimer *new_timer)
76226@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
76227 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
76228 return -EFAULT;
76229
76230+ /* only the CLOCK_REALTIME clock can be set, all other clocks
76231+ have their clock_set fptr set to a nosettime dummy function
76232+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
76233+ call common_clock_set, which calls do_sys_settimeofday, which
76234+ we hook
76235+ */
76236+
76237 return kc->clock_set(which_clock, &new_tp);
76238 }
76239
76240diff --git a/kernel/power/process.c b/kernel/power/process.c
76241index d5a258b..4271191 100644
76242--- a/kernel/power/process.c
76243+++ b/kernel/power/process.c
76244@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
76245 u64 elapsed_csecs64;
76246 unsigned int elapsed_csecs;
76247 bool wakeup = false;
76248+ bool timedout = false;
76249
76250 do_gettimeofday(&start);
76251
76252@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
76253
76254 while (true) {
76255 todo = 0;
76256+ if (time_after(jiffies, end_time))
76257+ timedout = true;
76258 read_lock(&tasklist_lock);
76259 do_each_thread(g, p) {
76260 if (p == current || !freeze_task(p))
76261 continue;
76262
76263- if (!freezer_should_skip(p))
76264+ if (!freezer_should_skip(p)) {
76265 todo++;
76266+ if (timedout) {
76267+ printk(KERN_ERR "Task refusing to freeze:\n");
76268+ sched_show_task(p);
76269+ }
76270+ }
76271 } while_each_thread(g, p);
76272 read_unlock(&tasklist_lock);
76273
76274@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
76275 todo += wq_busy;
76276 }
76277
76278- if (!todo || time_after(jiffies, end_time))
76279+ if (!todo || timedout)
76280 break;
76281
76282 if (pm_wakeup_pending()) {
76283diff --git a/kernel/printk.c b/kernel/printk.c
76284index 267ce78..2487112 100644
76285--- a/kernel/printk.c
76286+++ b/kernel/printk.c
76287@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
76288 return ret;
76289 }
76290
76291+static int check_syslog_permissions(int type, bool from_file);
76292+
76293 static int devkmsg_open(struct inode *inode, struct file *file)
76294 {
76295 struct devkmsg_user *user;
76296 int err;
76297
76298+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
76299+ if (err)
76300+ return err;
76301+
76302 /* write-only does not need any file context */
76303 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
76304 return 0;
76305@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
76306 if (dmesg_restrict)
76307 return 1;
76308 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
76309- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76310+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76311 }
76312
76313 static int check_syslog_permissions(int type, bool from_file)
76314@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
76315 if (from_file && type != SYSLOG_ACTION_OPEN)
76316 return 0;
76317
76318+#ifdef CONFIG_GRKERNSEC_DMESG
76319+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
76320+ return -EPERM;
76321+#endif
76322+
76323 if (syslog_action_restricted(type)) {
76324 if (capable(CAP_SYSLOG))
76325 return 0;
76326diff --git a/kernel/profile.c b/kernel/profile.c
76327index 1f39181..86093471 100644
76328--- a/kernel/profile.c
76329+++ b/kernel/profile.c
76330@@ -40,7 +40,7 @@ struct profile_hit {
76331 /* Oprofile timer tick hook */
76332 static int (*timer_hook)(struct pt_regs *) __read_mostly;
76333
76334-static atomic_t *prof_buffer;
76335+static atomic_unchecked_t *prof_buffer;
76336 static unsigned long prof_len, prof_shift;
76337
76338 int prof_on __read_mostly;
76339@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
76340 hits[i].pc = 0;
76341 continue;
76342 }
76343- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76344+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76345 hits[i].hits = hits[i].pc = 0;
76346 }
76347 }
76348@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76349 * Add the current hit(s) and flush the write-queue out
76350 * to the global buffer:
76351 */
76352- atomic_add(nr_hits, &prof_buffer[pc]);
76353+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
76354 for (i = 0; i < NR_PROFILE_HIT; ++i) {
76355- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76356+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76357 hits[i].pc = hits[i].hits = 0;
76358 }
76359 out:
76360@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76361 {
76362 unsigned long pc;
76363 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
76364- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76365+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76366 }
76367 #endif /* !CONFIG_SMP */
76368
76369@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
76370 return -EFAULT;
76371 buf++; p++; count--; read++;
76372 }
76373- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
76374+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
76375 if (copy_to_user(buf, (void *)pnt, count))
76376 return -EFAULT;
76377 read += count;
76378@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
76379 }
76380 #endif
76381 profile_discard_flip_buffers();
76382- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
76383+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
76384 return count;
76385 }
76386
76387diff --git a/kernel/ptrace.c b/kernel/ptrace.c
76388index 6cbeaae..363c48a 100644
76389--- a/kernel/ptrace.c
76390+++ b/kernel/ptrace.c
76391@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
76392 if (seize)
76393 flags |= PT_SEIZED;
76394 rcu_read_lock();
76395- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76396+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76397 flags |= PT_PTRACE_CAP;
76398 rcu_read_unlock();
76399 task->ptrace = flags;
76400@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
76401 break;
76402 return -EIO;
76403 }
76404- if (copy_to_user(dst, buf, retval))
76405+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
76406 return -EFAULT;
76407 copied += retval;
76408 src += retval;
76409@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
76410 bool seized = child->ptrace & PT_SEIZED;
76411 int ret = -EIO;
76412 siginfo_t siginfo, *si;
76413- void __user *datavp = (void __user *) data;
76414+ void __user *datavp = (__force void __user *) data;
76415 unsigned long __user *datalp = datavp;
76416 unsigned long flags;
76417
76418@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
76419 goto out;
76420 }
76421
76422+ if (gr_handle_ptrace(child, request)) {
76423+ ret = -EPERM;
76424+ goto out_put_task_struct;
76425+ }
76426+
76427 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76428 ret = ptrace_attach(child, request, addr, data);
76429 /*
76430 * Some architectures need to do book-keeping after
76431 * a ptrace attach.
76432 */
76433- if (!ret)
76434+ if (!ret) {
76435 arch_ptrace_attach(child);
76436+ gr_audit_ptrace(child);
76437+ }
76438 goto out_put_task_struct;
76439 }
76440
76441@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
76442 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
76443 if (copied != sizeof(tmp))
76444 return -EIO;
76445- return put_user(tmp, (unsigned long __user *)data);
76446+ return put_user(tmp, (__force unsigned long __user *)data);
76447 }
76448
76449 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
76450@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76451 goto out;
76452 }
76453
76454+ if (gr_handle_ptrace(child, request)) {
76455+ ret = -EPERM;
76456+ goto out_put_task_struct;
76457+ }
76458+
76459 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76460 ret = ptrace_attach(child, request, addr, data);
76461 /*
76462 * Some architectures need to do book-keeping after
76463 * a ptrace attach.
76464 */
76465- if (!ret)
76466+ if (!ret) {
76467 arch_ptrace_attach(child);
76468+ gr_audit_ptrace(child);
76469+ }
76470 goto out_put_task_struct;
76471 }
76472
76473diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
76474index e7dce58..ad0d7b7 100644
76475--- a/kernel/rcutiny.c
76476+++ b/kernel/rcutiny.c
76477@@ -46,7 +46,7 @@
76478 struct rcu_ctrlblk;
76479 static void invoke_rcu_callbacks(void);
76480 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
76481-static void rcu_process_callbacks(struct softirq_action *unused);
76482+static void rcu_process_callbacks(void);
76483 static void __call_rcu(struct rcu_head *head,
76484 void (*func)(struct rcu_head *rcu),
76485 struct rcu_ctrlblk *rcp);
76486@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
76487 rcu_is_callbacks_kthread()));
76488 }
76489
76490-static void rcu_process_callbacks(struct softirq_action *unused)
76491+static void rcu_process_callbacks(void)
76492 {
76493 __rcu_process_callbacks(&rcu_sched_ctrlblk);
76494 __rcu_process_callbacks(&rcu_bh_ctrlblk);
76495diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
76496index f85016a..91cb03b 100644
76497--- a/kernel/rcutiny_plugin.h
76498+++ b/kernel/rcutiny_plugin.h
76499@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
76500 have_rcu_kthread_work = morework;
76501 local_irq_restore(flags);
76502 if (work)
76503- rcu_process_callbacks(NULL);
76504+ rcu_process_callbacks();
76505 schedule_timeout_interruptible(1); /* Leave CPU for others. */
76506 }
76507
76508diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
76509index 31dea01..ad91ffb 100644
76510--- a/kernel/rcutorture.c
76511+++ b/kernel/rcutorture.c
76512@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
76513 { 0 };
76514 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
76515 { 0 };
76516-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76517-static atomic_t n_rcu_torture_alloc;
76518-static atomic_t n_rcu_torture_alloc_fail;
76519-static atomic_t n_rcu_torture_free;
76520-static atomic_t n_rcu_torture_mberror;
76521-static atomic_t n_rcu_torture_error;
76522+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76523+static atomic_unchecked_t n_rcu_torture_alloc;
76524+static atomic_unchecked_t n_rcu_torture_alloc_fail;
76525+static atomic_unchecked_t n_rcu_torture_free;
76526+static atomic_unchecked_t n_rcu_torture_mberror;
76527+static atomic_unchecked_t n_rcu_torture_error;
76528 static long n_rcu_torture_barrier_error;
76529 static long n_rcu_torture_boost_ktrerror;
76530 static long n_rcu_torture_boost_rterror;
76531@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
76532
76533 spin_lock_bh(&rcu_torture_lock);
76534 if (list_empty(&rcu_torture_freelist)) {
76535- atomic_inc(&n_rcu_torture_alloc_fail);
76536+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
76537 spin_unlock_bh(&rcu_torture_lock);
76538 return NULL;
76539 }
76540- atomic_inc(&n_rcu_torture_alloc);
76541+ atomic_inc_unchecked(&n_rcu_torture_alloc);
76542 p = rcu_torture_freelist.next;
76543 list_del_init(p);
76544 spin_unlock_bh(&rcu_torture_lock);
76545@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
76546 static void
76547 rcu_torture_free(struct rcu_torture *p)
76548 {
76549- atomic_inc(&n_rcu_torture_free);
76550+ atomic_inc_unchecked(&n_rcu_torture_free);
76551 spin_lock_bh(&rcu_torture_lock);
76552 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
76553 spin_unlock_bh(&rcu_torture_lock);
76554@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
76555 i = rp->rtort_pipe_count;
76556 if (i > RCU_TORTURE_PIPE_LEN)
76557 i = RCU_TORTURE_PIPE_LEN;
76558- atomic_inc(&rcu_torture_wcount[i]);
76559+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76560 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76561 rp->rtort_mbtest = 0;
76562 rcu_torture_free(rp);
76563@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
76564 i = rp->rtort_pipe_count;
76565 if (i > RCU_TORTURE_PIPE_LEN)
76566 i = RCU_TORTURE_PIPE_LEN;
76567- atomic_inc(&rcu_torture_wcount[i]);
76568+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76569 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76570 rp->rtort_mbtest = 0;
76571 list_del(&rp->rtort_free);
76572@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
76573 i = old_rp->rtort_pipe_count;
76574 if (i > RCU_TORTURE_PIPE_LEN)
76575 i = RCU_TORTURE_PIPE_LEN;
76576- atomic_inc(&rcu_torture_wcount[i]);
76577+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76578 old_rp->rtort_pipe_count++;
76579 cur_ops->deferred_free(old_rp);
76580 }
76581@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
76582 }
76583 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76584 if (p->rtort_mbtest == 0)
76585- atomic_inc(&n_rcu_torture_mberror);
76586+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76587 spin_lock(&rand_lock);
76588 cur_ops->read_delay(&rand);
76589 n_rcu_torture_timers++;
76590@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
76591 }
76592 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76593 if (p->rtort_mbtest == 0)
76594- atomic_inc(&n_rcu_torture_mberror);
76595+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76596 cur_ops->read_delay(&rand);
76597 preempt_disable();
76598 pipe_count = p->rtort_pipe_count;
76599@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
76600 rcu_torture_current,
76601 rcu_torture_current_version,
76602 list_empty(&rcu_torture_freelist),
76603- atomic_read(&n_rcu_torture_alloc),
76604- atomic_read(&n_rcu_torture_alloc_fail),
76605- atomic_read(&n_rcu_torture_free));
76606+ atomic_read_unchecked(&n_rcu_torture_alloc),
76607+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
76608+ atomic_read_unchecked(&n_rcu_torture_free));
76609 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
76610- atomic_read(&n_rcu_torture_mberror),
76611+ atomic_read_unchecked(&n_rcu_torture_mberror),
76612 n_rcu_torture_boost_ktrerror,
76613 n_rcu_torture_boost_rterror);
76614 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
76615@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
76616 n_barrier_attempts,
76617 n_rcu_torture_barrier_error);
76618 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
76619- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
76620+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
76621 n_rcu_torture_barrier_error != 0 ||
76622 n_rcu_torture_boost_ktrerror != 0 ||
76623 n_rcu_torture_boost_rterror != 0 ||
76624 n_rcu_torture_boost_failure != 0 ||
76625 i > 1) {
76626 cnt += sprintf(&page[cnt], "!!! ");
76627- atomic_inc(&n_rcu_torture_error);
76628+ atomic_inc_unchecked(&n_rcu_torture_error);
76629 WARN_ON_ONCE(1);
76630 }
76631 cnt += sprintf(&page[cnt], "Reader Pipe: ");
76632@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
76633 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
76634 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76635 cnt += sprintf(&page[cnt], " %d",
76636- atomic_read(&rcu_torture_wcount[i]));
76637+ atomic_read_unchecked(&rcu_torture_wcount[i]));
76638 }
76639 cnt += sprintf(&page[cnt], "\n");
76640 if (cur_ops->stats)
76641@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
76642
76643 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
76644
76645- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76646+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76647 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
76648 else if (n_online_successes != n_online_attempts ||
76649 n_offline_successes != n_offline_attempts)
76650@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
76651
76652 rcu_torture_current = NULL;
76653 rcu_torture_current_version = 0;
76654- atomic_set(&n_rcu_torture_alloc, 0);
76655- atomic_set(&n_rcu_torture_alloc_fail, 0);
76656- atomic_set(&n_rcu_torture_free, 0);
76657- atomic_set(&n_rcu_torture_mberror, 0);
76658- atomic_set(&n_rcu_torture_error, 0);
76659+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
76660+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
76661+ atomic_set_unchecked(&n_rcu_torture_free, 0);
76662+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
76663+ atomic_set_unchecked(&n_rcu_torture_error, 0);
76664 n_rcu_torture_barrier_error = 0;
76665 n_rcu_torture_boost_ktrerror = 0;
76666 n_rcu_torture_boost_rterror = 0;
76667 n_rcu_torture_boost_failure = 0;
76668 n_rcu_torture_boosts = 0;
76669 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
76670- atomic_set(&rcu_torture_wcount[i], 0);
76671+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
76672 for_each_possible_cpu(cpu) {
76673 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76674 per_cpu(rcu_torture_count, cpu)[i] = 0;
76675diff --git a/kernel/rcutree.c b/kernel/rcutree.c
76676index e441b77..dd54f17 100644
76677--- a/kernel/rcutree.c
76678+++ b/kernel/rcutree.c
76679@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
76680 rcu_prepare_for_idle(smp_processor_id());
76681 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76682 smp_mb__before_atomic_inc(); /* See above. */
76683- atomic_inc(&rdtp->dynticks);
76684+ atomic_inc_unchecked(&rdtp->dynticks);
76685 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
76686- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76687+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76688
76689 /*
76690 * It is illegal to enter an extended quiescent state while
76691@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
76692 int user)
76693 {
76694 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
76695- atomic_inc(&rdtp->dynticks);
76696+ atomic_inc_unchecked(&rdtp->dynticks);
76697 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76698 smp_mb__after_atomic_inc(); /* See above. */
76699- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76700+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76701 rcu_cleanup_after_idle(smp_processor_id());
76702 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
76703 if (!user && !is_idle_task(current)) {
76704@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
76705 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
76706
76707 if (rdtp->dynticks_nmi_nesting == 0 &&
76708- (atomic_read(&rdtp->dynticks) & 0x1))
76709+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
76710 return;
76711 rdtp->dynticks_nmi_nesting++;
76712 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
76713- atomic_inc(&rdtp->dynticks);
76714+ atomic_inc_unchecked(&rdtp->dynticks);
76715 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76716 smp_mb__after_atomic_inc(); /* See above. */
76717- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76718+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76719 }
76720
76721 /**
76722@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
76723 return;
76724 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76725 smp_mb__before_atomic_inc(); /* See above. */
76726- atomic_inc(&rdtp->dynticks);
76727+ atomic_inc_unchecked(&rdtp->dynticks);
76728 smp_mb__after_atomic_inc(); /* Force delay to next write. */
76729- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76730+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76731 }
76732
76733 /**
76734@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
76735 int ret;
76736
76737 preempt_disable();
76738- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76739+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76740 preempt_enable();
76741 return ret;
76742 }
76743@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
76744 */
76745 static int dyntick_save_progress_counter(struct rcu_data *rdp)
76746 {
76747- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
76748+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76749 return (rdp->dynticks_snap & 0x1) == 0;
76750 }
76751
76752@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
76753 unsigned int curr;
76754 unsigned int snap;
76755
76756- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
76757+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76758 snap = (unsigned int)rdp->dynticks_snap;
76759
76760 /*
76761@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
76762 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
76763 */
76764 if (till_stall_check < 3) {
76765- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
76766+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
76767 till_stall_check = 3;
76768 } else if (till_stall_check > 300) {
76769- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
76770+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
76771 till_stall_check = 300;
76772 }
76773 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
76774@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
76775 rsp->qlen += rdp->qlen;
76776 rdp->n_cbs_orphaned += rdp->qlen;
76777 rdp->qlen_lazy = 0;
76778- ACCESS_ONCE(rdp->qlen) = 0;
76779+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76780 }
76781
76782 /*
76783@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
76784 }
76785 smp_mb(); /* List handling before counting for rcu_barrier(). */
76786 rdp->qlen_lazy -= count_lazy;
76787- ACCESS_ONCE(rdp->qlen) -= count;
76788+ ACCESS_ONCE_RW(rdp->qlen) -= count;
76789 rdp->n_cbs_invoked += count;
76790
76791 /* Reinstate batch limit if we have worked down the excess. */
76792@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76793 /*
76794 * Do RCU core processing for the current CPU.
76795 */
76796-static void rcu_process_callbacks(struct softirq_action *unused)
76797+static void rcu_process_callbacks(void)
76798 {
76799 struct rcu_state *rsp;
76800
76801@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76802 local_irq_restore(flags);
76803 return;
76804 }
76805- ACCESS_ONCE(rdp->qlen)++;
76806+ ACCESS_ONCE_RW(rdp->qlen)++;
76807 if (lazy)
76808 rdp->qlen_lazy++;
76809 else
76810@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76811 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76812 * course be required on a 64-bit system.
76813 */
76814- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76815+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76816 (ulong)atomic_long_read(&rsp->expedited_done) +
76817 ULONG_MAX / 8)) {
76818 synchronize_sched();
76819- atomic_long_inc(&rsp->expedited_wrap);
76820+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
76821 return;
76822 }
76823
76824@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76825 * Take a ticket. Note that atomic_inc_return() implies a
76826 * full memory barrier.
76827 */
76828- snap = atomic_long_inc_return(&rsp->expedited_start);
76829+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76830 firstsnap = snap;
76831 get_online_cpus();
76832 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
76833@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
76834 synchronize_sched_expedited_cpu_stop,
76835 NULL) == -EAGAIN) {
76836 put_online_cpus();
76837- atomic_long_inc(&rsp->expedited_tryfail);
76838+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
76839
76840 /* Check to see if someone else did our work for us. */
76841 s = atomic_long_read(&rsp->expedited_done);
76842 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76843 /* ensure test happens before caller kfree */
76844 smp_mb__before_atomic_inc(); /* ^^^ */
76845- atomic_long_inc(&rsp->expedited_workdone1);
76846+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
76847 return;
76848 }
76849
76850@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
76851 udelay(trycount * num_online_cpus());
76852 } else {
76853 wait_rcu_gp(call_rcu_sched);
76854- atomic_long_inc(&rsp->expedited_normal);
76855+ atomic_long_inc_unchecked(&rsp->expedited_normal);
76856 return;
76857 }
76858
76859@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
76860 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76861 /* ensure test happens before caller kfree */
76862 smp_mb__before_atomic_inc(); /* ^^^ */
76863- atomic_long_inc(&rsp->expedited_workdone2);
76864+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
76865 return;
76866 }
76867
76868@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
76869 * period works for us.
76870 */
76871 get_online_cpus();
76872- snap = atomic_long_read(&rsp->expedited_start);
76873+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
76874 smp_mb(); /* ensure read is before try_stop_cpus(). */
76875 }
76876- atomic_long_inc(&rsp->expedited_stoppedcpus);
76877+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
76878
76879 /*
76880 * Everyone up to our most recent fetch is covered by our grace
76881@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
76882 * than we did already did their update.
76883 */
76884 do {
76885- atomic_long_inc(&rsp->expedited_done_tries);
76886+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
76887 s = atomic_long_read(&rsp->expedited_done);
76888 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
76889 /* ensure test happens before caller kfree */
76890 smp_mb__before_atomic_inc(); /* ^^^ */
76891- atomic_long_inc(&rsp->expedited_done_lost);
76892+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
76893 break;
76894 }
76895 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76896- atomic_long_inc(&rsp->expedited_done_exit);
76897+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76898
76899 put_online_cpus();
76900 }
76901@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76902 * ACCESS_ONCE() to prevent the compiler from speculating
76903 * the increment to precede the early-exit check.
76904 */
76905- ACCESS_ONCE(rsp->n_barrier_done)++;
76906+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76907 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76908 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76909 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76910@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76911
76912 /* Increment ->n_barrier_done to prevent duplicate work. */
76913 smp_mb(); /* Keep increment after above mechanism. */
76914- ACCESS_ONCE(rsp->n_barrier_done)++;
76915+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76916 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76917 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76918 smp_mb(); /* Keep increment before caller's subsequent code. */
76919@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76920 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76921 init_callback_list(rdp);
76922 rdp->qlen_lazy = 0;
76923- ACCESS_ONCE(rdp->qlen) = 0;
76924+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76925 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76926 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76927- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76928+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76929 #ifdef CONFIG_RCU_USER_QS
76930 WARN_ON_ONCE(rdp->dynticks->in_user);
76931 #endif
76932@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76933 rdp->blimit = blimit;
76934 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76935 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76936- atomic_set(&rdp->dynticks->dynticks,
76937- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76938+ atomic_set_unchecked(&rdp->dynticks->dynticks,
76939+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76940 rcu_prepare_for_idle_init(cpu);
76941 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76942
76943diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76944index 4b69291..704c92e 100644
76945--- a/kernel/rcutree.h
76946+++ b/kernel/rcutree.h
76947@@ -86,7 +86,7 @@ struct rcu_dynticks {
76948 long long dynticks_nesting; /* Track irq/process nesting level. */
76949 /* Process level is worth LLONG_MAX/2. */
76950 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76951- atomic_t dynticks; /* Even value for idle, else odd. */
76952+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76953 #ifdef CONFIG_RCU_FAST_NO_HZ
76954 int dyntick_drain; /* Prepare-for-idle state variable. */
76955 unsigned long dyntick_holdoff;
76956@@ -423,17 +423,17 @@ struct rcu_state {
76957 /* _rcu_barrier(). */
76958 /* End of fields guarded by barrier_mutex. */
76959
76960- atomic_long_t expedited_start; /* Starting ticket. */
76961- atomic_long_t expedited_done; /* Done ticket. */
76962- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76963- atomic_long_t expedited_tryfail; /* # acquisition failures. */
76964- atomic_long_t expedited_workdone1; /* # done by others #1. */
76965- atomic_long_t expedited_workdone2; /* # done by others #2. */
76966- atomic_long_t expedited_normal; /* # fallbacks to normal. */
76967- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76968- atomic_long_t expedited_done_tries; /* # tries to update _done. */
76969- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76970- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76971+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76972+ atomic_long_t expedited_done; /* Done ticket. */
76973+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76974+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76975+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76976+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76977+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76978+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76979+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76980+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76981+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76982
76983 unsigned long jiffies_force_qs; /* Time at which to invoke */
76984 /* force_quiescent_state(). */
76985diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
76986index c1cc7e1..f62e436 100644
76987--- a/kernel/rcutree_plugin.h
76988+++ b/kernel/rcutree_plugin.h
76989@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
76990
76991 /* Clean up and exit. */
76992 smp_mb(); /* ensure expedited GP seen before counter increment. */
76993- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
76994+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
76995 unlock_mb_ret:
76996 mutex_unlock(&sync_rcu_preempt_exp_mutex);
76997 mb_ret:
76998@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
76999 free_cpumask_var(cm);
77000 }
77001
77002-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
77003+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
77004 .store = &rcu_cpu_kthread_task,
77005 .thread_should_run = rcu_cpu_kthread_should_run,
77006 .thread_fn = rcu_cpu_kthread,
77007@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
77008 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
77009 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
77010 cpu, ticks_value, ticks_title,
77011- atomic_read(&rdtp->dynticks) & 0xfff,
77012+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
77013 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
77014 fast_no_hz);
77015 }
77016@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
77017
77018 /* Enqueue the callback on the nocb list and update counts. */
77019 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
77020- ACCESS_ONCE(*old_rhpp) = rhp;
77021+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
77022 atomic_long_add(rhcount, &rdp->nocb_q_count);
77023 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
77024
77025@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
77026 * Extract queued callbacks, update counts, and wait
77027 * for a grace period to elapse.
77028 */
77029- ACCESS_ONCE(rdp->nocb_head) = NULL;
77030+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
77031 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
77032 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
77033 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
77034- ACCESS_ONCE(rdp->nocb_p_count) += c;
77035- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
77036+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
77037+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
77038 wait_rcu_gp(rdp->rsp->call_remote);
77039
77040 /* Each pass through the following loop invokes a callback. */
77041@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
77042 list = next;
77043 }
77044 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
77045- ACCESS_ONCE(rdp->nocb_p_count) -= c;
77046- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
77047+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
77048+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
77049 rdp->n_nocbs_invoked += c;
77050 }
77051 return 0;
77052@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
77053 rdp = per_cpu_ptr(rsp->rda, cpu);
77054 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
77055 BUG_ON(IS_ERR(t));
77056- ACCESS_ONCE(rdp->nocb_kthread) = t;
77057+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
77058 }
77059 }
77060
77061diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
77062index 0d095dc..1985b19 100644
77063--- a/kernel/rcutree_trace.c
77064+++ b/kernel/rcutree_trace.c
77065@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
77066 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
77067 rdp->passed_quiesce, rdp->qs_pending);
77068 seq_printf(m, " dt=%d/%llx/%d df=%lu",
77069- atomic_read(&rdp->dynticks->dynticks),
77070+ atomic_read_unchecked(&rdp->dynticks->dynticks),
77071 rdp->dynticks->dynticks_nesting,
77072 rdp->dynticks->dynticks_nmi_nesting,
77073 rdp->dynticks_fqs);
77074@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
77075 struct rcu_state *rsp = (struct rcu_state *)m->private;
77076
77077 seq_printf(m, "s=%lu d=%lu w=%lu tf=%lu wd1=%lu wd2=%lu n=%lu sc=%lu dt=%lu dl=%lu dx=%lu\n",
77078- atomic_long_read(&rsp->expedited_start),
77079+ atomic_long_read_unchecked(&rsp->expedited_start),
77080 atomic_long_read(&rsp->expedited_done),
77081- atomic_long_read(&rsp->expedited_wrap),
77082- atomic_long_read(&rsp->expedited_tryfail),
77083- atomic_long_read(&rsp->expedited_workdone1),
77084- atomic_long_read(&rsp->expedited_workdone2),
77085- atomic_long_read(&rsp->expedited_normal),
77086- atomic_long_read(&rsp->expedited_stoppedcpus),
77087- atomic_long_read(&rsp->expedited_done_tries),
77088- atomic_long_read(&rsp->expedited_done_lost),
77089- atomic_long_read(&rsp->expedited_done_exit));
77090+ atomic_long_read_unchecked(&rsp->expedited_wrap),
77091+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
77092+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
77093+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
77094+ atomic_long_read_unchecked(&rsp->expedited_normal),
77095+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
77096+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
77097+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
77098+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
77099 return 0;
77100 }
77101
77102diff --git a/kernel/resource.c b/kernel/resource.c
77103index 73f35d4..4684fc4 100644
77104--- a/kernel/resource.c
77105+++ b/kernel/resource.c
77106@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
77107
77108 static int __init ioresources_init(void)
77109 {
77110+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77111+#ifdef CONFIG_GRKERNSEC_PROC_USER
77112+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
77113+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
77114+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77115+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
77116+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
77117+#endif
77118+#else
77119 proc_create("ioports", 0, NULL, &proc_ioports_operations);
77120 proc_create("iomem", 0, NULL, &proc_iomem_operations);
77121+#endif
77122 return 0;
77123 }
77124 __initcall(ioresources_init);
77125diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
77126index 98ec494..4241d6d 100644
77127--- a/kernel/rtmutex-tester.c
77128+++ b/kernel/rtmutex-tester.c
77129@@ -20,7 +20,7 @@
77130 #define MAX_RT_TEST_MUTEXES 8
77131
77132 static spinlock_t rttest_lock;
77133-static atomic_t rttest_event;
77134+static atomic_unchecked_t rttest_event;
77135
77136 struct test_thread_data {
77137 int opcode;
77138@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77139
77140 case RTTEST_LOCKCONT:
77141 td->mutexes[td->opdata] = 1;
77142- td->event = atomic_add_return(1, &rttest_event);
77143+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77144 return 0;
77145
77146 case RTTEST_RESET:
77147@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77148 return 0;
77149
77150 case RTTEST_RESETEVENT:
77151- atomic_set(&rttest_event, 0);
77152+ atomic_set_unchecked(&rttest_event, 0);
77153 return 0;
77154
77155 default:
77156@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77157 return ret;
77158
77159 td->mutexes[id] = 1;
77160- td->event = atomic_add_return(1, &rttest_event);
77161+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77162 rt_mutex_lock(&mutexes[id]);
77163- td->event = atomic_add_return(1, &rttest_event);
77164+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77165 td->mutexes[id] = 4;
77166 return 0;
77167
77168@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77169 return ret;
77170
77171 td->mutexes[id] = 1;
77172- td->event = atomic_add_return(1, &rttest_event);
77173+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77174 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
77175- td->event = atomic_add_return(1, &rttest_event);
77176+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77177 td->mutexes[id] = ret ? 0 : 4;
77178 return ret ? -EINTR : 0;
77179
77180@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77181 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
77182 return ret;
77183
77184- td->event = atomic_add_return(1, &rttest_event);
77185+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77186 rt_mutex_unlock(&mutexes[id]);
77187- td->event = atomic_add_return(1, &rttest_event);
77188+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77189 td->mutexes[id] = 0;
77190 return 0;
77191
77192@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77193 break;
77194
77195 td->mutexes[dat] = 2;
77196- td->event = atomic_add_return(1, &rttest_event);
77197+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77198 break;
77199
77200 default:
77201@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77202 return;
77203
77204 td->mutexes[dat] = 3;
77205- td->event = atomic_add_return(1, &rttest_event);
77206+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77207 break;
77208
77209 case RTTEST_LOCKNOWAIT:
77210@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77211 return;
77212
77213 td->mutexes[dat] = 1;
77214- td->event = atomic_add_return(1, &rttest_event);
77215+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77216 return;
77217
77218 default:
77219diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
77220index 0984a21..939f183 100644
77221--- a/kernel/sched/auto_group.c
77222+++ b/kernel/sched/auto_group.c
77223@@ -11,7 +11,7 @@
77224
77225 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
77226 static struct autogroup autogroup_default;
77227-static atomic_t autogroup_seq_nr;
77228+static atomic_unchecked_t autogroup_seq_nr;
77229
77230 void __init autogroup_init(struct task_struct *init_task)
77231 {
77232@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
77233
77234 kref_init(&ag->kref);
77235 init_rwsem(&ag->lock);
77236- ag->id = atomic_inc_return(&autogroup_seq_nr);
77237+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
77238 ag->tg = tg;
77239 #ifdef CONFIG_RT_GROUP_SCHED
77240 /*
77241diff --git a/kernel/sched/core.c b/kernel/sched/core.c
77242index 26058d0..e315889 100644
77243--- a/kernel/sched/core.c
77244+++ b/kernel/sched/core.c
77245@@ -3367,7 +3367,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
77246 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77247 * positive (at least 1, or number of jiffies left till timeout) if completed.
77248 */
77249-long __sched
77250+long __sched __intentional_overflow(-1)
77251 wait_for_completion_interruptible_timeout(struct completion *x,
77252 unsigned long timeout)
77253 {
77254@@ -3384,7 +3384,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
77255 *
77256 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
77257 */
77258-int __sched wait_for_completion_killable(struct completion *x)
77259+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
77260 {
77261 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
77262 if (t == -ERESTARTSYS)
77263@@ -3405,7 +3405,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
77264 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77265 * positive (at least 1, or number of jiffies left till timeout) if completed.
77266 */
77267-long __sched
77268+long __sched __intentional_overflow(-1)
77269 wait_for_completion_killable_timeout(struct completion *x,
77270 unsigned long timeout)
77271 {
77272@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
77273 /* convert nice value [19,-20] to rlimit style value [1,40] */
77274 int nice_rlim = 20 - nice;
77275
77276+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
77277+
77278 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
77279 capable(CAP_SYS_NICE));
77280 }
77281@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
77282 if (nice > 19)
77283 nice = 19;
77284
77285- if (increment < 0 && !can_nice(current, nice))
77286+ if (increment < 0 && (!can_nice(current, nice) ||
77287+ gr_handle_chroot_nice()))
77288 return -EPERM;
77289
77290 retval = security_task_setnice(current, nice);
77291@@ -3818,6 +3821,7 @@ recheck:
77292 unsigned long rlim_rtprio =
77293 task_rlimit(p, RLIMIT_RTPRIO);
77294
77295+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
77296 /* can't set/change the rt policy */
77297 if (policy != p->policy && !rlim_rtprio)
77298 return -EPERM;
77299@@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
77300
77301 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
77302
77303-static struct ctl_table sd_ctl_dir[] = {
77304+static ctl_table_no_const sd_ctl_dir[] __read_only = {
77305 {
77306 .procname = "sched_domain",
77307 .mode = 0555,
77308@@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
77309 {}
77310 };
77311
77312-static struct ctl_table *sd_alloc_ctl_entry(int n)
77313+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
77314 {
77315- struct ctl_table *entry =
77316+ ctl_table_no_const *entry =
77317 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
77318
77319 return entry;
77320 }
77321
77322-static void sd_free_ctl_entry(struct ctl_table **tablep)
77323+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
77324 {
77325- struct ctl_table *entry;
77326+ ctl_table_no_const *entry;
77327
77328 /*
77329 * In the intermediate directories, both the child directory and
77330@@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
77331 * will always be set. In the lowest directory the names are
77332 * static strings and all have proc handlers.
77333 */
77334- for (entry = *tablep; entry->mode; entry++) {
77335- if (entry->child)
77336- sd_free_ctl_entry(&entry->child);
77337+ for (entry = tablep; entry->mode; entry++) {
77338+ if (entry->child) {
77339+ sd_free_ctl_entry(entry->child);
77340+ pax_open_kernel();
77341+ entry->child = NULL;
77342+ pax_close_kernel();
77343+ }
77344 if (entry->proc_handler == NULL)
77345 kfree(entry->procname);
77346 }
77347
77348- kfree(*tablep);
77349- *tablep = NULL;
77350+ kfree(tablep);
77351 }
77352
77353 static int min_load_idx = 0;
77354 static int max_load_idx = CPU_LOAD_IDX_MAX;
77355
77356 static void
77357-set_table_entry(struct ctl_table *entry,
77358+set_table_entry(ctl_table_no_const *entry,
77359 const char *procname, void *data, int maxlen,
77360 umode_t mode, proc_handler *proc_handler,
77361 bool load_idx)
77362@@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
77363 static struct ctl_table *
77364 sd_alloc_ctl_domain_table(struct sched_domain *sd)
77365 {
77366- struct ctl_table *table = sd_alloc_ctl_entry(13);
77367+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
77368
77369 if (table == NULL)
77370 return NULL;
77371@@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
77372 return table;
77373 }
77374
77375-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
77376+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
77377 {
77378- struct ctl_table *entry, *table;
77379+ ctl_table_no_const *entry, *table;
77380 struct sched_domain *sd;
77381 int domain_num = 0, i;
77382 char buf[32];
77383@@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
77384 static void register_sched_domain_sysctl(void)
77385 {
77386 int i, cpu_num = num_possible_cpus();
77387- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
77388+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
77389 char buf[32];
77390
77391 WARN_ON(sd_ctl_dir[0].child);
77392+ pax_open_kernel();
77393 sd_ctl_dir[0].child = entry;
77394+ pax_close_kernel();
77395
77396 if (entry == NULL)
77397 return;
77398@@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
77399 if (sd_sysctl_header)
77400 unregister_sysctl_table(sd_sysctl_header);
77401 sd_sysctl_header = NULL;
77402- if (sd_ctl_dir[0].child)
77403- sd_free_ctl_entry(&sd_ctl_dir[0].child);
77404+ if (sd_ctl_dir[0].child) {
77405+ sd_free_ctl_entry(sd_ctl_dir[0].child);
77406+ pax_open_kernel();
77407+ sd_ctl_dir[0].child = NULL;
77408+ pax_close_kernel();
77409+ }
77410 }
77411 #else
77412 static void register_sched_domain_sysctl(void)
77413@@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
77414 * happens before everything else. This has to be lower priority than
77415 * the notifier in the perf_event subsystem, though.
77416 */
77417-static struct notifier_block __cpuinitdata migration_notifier = {
77418+static struct notifier_block migration_notifier = {
77419 .notifier_call = migration_call,
77420 .priority = CPU_PRI_MIGRATION,
77421 };
77422diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
77423index 81fa536..6ccf96a 100644
77424--- a/kernel/sched/fair.c
77425+++ b/kernel/sched/fair.c
77426@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
77427
77428 static void reset_ptenuma_scan(struct task_struct *p)
77429 {
77430- ACCESS_ONCE(p->mm->numa_scan_seq)++;
77431+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
77432 p->mm->numa_scan_offset = 0;
77433 }
77434
77435@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
77436 */
77437 static int select_idle_sibling(struct task_struct *p, int target)
77438 {
77439- int cpu = smp_processor_id();
77440- int prev_cpu = task_cpu(p);
77441 struct sched_domain *sd;
77442 struct sched_group *sg;
77443- int i;
77444+ int i = task_cpu(p);
77445
77446- /*
77447- * If the task is going to be woken-up on this cpu and if it is
77448- * already idle, then it is the right target.
77449- */
77450- if (target == cpu && idle_cpu(cpu))
77451- return cpu;
77452+ if (idle_cpu(target))
77453+ return target;
77454
77455 /*
77456- * If the task is going to be woken-up on the cpu where it previously
77457- * ran and if it is currently idle, then it the right target.
77458+ * If the prevous cpu is cache affine and idle, don't be stupid.
77459 */
77460- if (target == prev_cpu && idle_cpu(prev_cpu))
77461- return prev_cpu;
77462+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
77463+ return i;
77464
77465 /*
77466 * Otherwise, iterate the domains and find an elegible idle cpu.
77467@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
77468 goto next;
77469
77470 for_each_cpu(i, sched_group_cpus(sg)) {
77471- if (!idle_cpu(i))
77472+ if (i == target || !idle_cpu(i))
77473 goto next;
77474 }
77475
77476@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
77477 * run_rebalance_domains is triggered when needed from the scheduler tick.
77478 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
77479 */
77480-static void run_rebalance_domains(struct softirq_action *h)
77481+static void run_rebalance_domains(void)
77482 {
77483 int this_cpu = smp_processor_id();
77484 struct rq *this_rq = cpu_rq(this_cpu);
77485diff --git a/kernel/signal.c b/kernel/signal.c
77486index 7591ccc..8988390 100644
77487--- a/kernel/signal.c
77488+++ b/kernel/signal.c
77489@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
77490
77491 int print_fatal_signals __read_mostly;
77492
77493-static void __user *sig_handler(struct task_struct *t, int sig)
77494+static __sighandler_t sig_handler(struct task_struct *t, int sig)
77495 {
77496 return t->sighand->action[sig - 1].sa.sa_handler;
77497 }
77498
77499-static int sig_handler_ignored(void __user *handler, int sig)
77500+static int sig_handler_ignored(__sighandler_t handler, int sig)
77501 {
77502 /* Is it explicitly or implicitly ignored? */
77503 return handler == SIG_IGN ||
77504@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
77505
77506 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
77507 {
77508- void __user *handler;
77509+ __sighandler_t handler;
77510
77511 handler = sig_handler(t, sig);
77512
77513@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
77514 atomic_inc(&user->sigpending);
77515 rcu_read_unlock();
77516
77517+ if (!override_rlimit)
77518+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
77519+
77520 if (override_rlimit ||
77521 atomic_read(&user->sigpending) <=
77522 task_rlimit(t, RLIMIT_SIGPENDING)) {
77523@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
77524
77525 int unhandled_signal(struct task_struct *tsk, int sig)
77526 {
77527- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
77528+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
77529 if (is_global_init(tsk))
77530 return 1;
77531 if (handler != SIG_IGN && handler != SIG_DFL)
77532@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
77533 }
77534 }
77535
77536+ /* allow glibc communication via tgkill to other threads in our
77537+ thread group */
77538+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
77539+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
77540+ && gr_handle_signal(t, sig))
77541+ return -EPERM;
77542+
77543 return security_task_kill(t, info, sig, 0);
77544 }
77545
77546@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77547 return send_signal(sig, info, p, 1);
77548 }
77549
77550-static int
77551+int
77552 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77553 {
77554 return send_signal(sig, info, t, 0);
77555@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77556 unsigned long int flags;
77557 int ret, blocked, ignored;
77558 struct k_sigaction *action;
77559+ int is_unhandled = 0;
77560
77561 spin_lock_irqsave(&t->sighand->siglock, flags);
77562 action = &t->sighand->action[sig-1];
77563@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77564 }
77565 if (action->sa.sa_handler == SIG_DFL)
77566 t->signal->flags &= ~SIGNAL_UNKILLABLE;
77567+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
77568+ is_unhandled = 1;
77569 ret = specific_send_sig_info(sig, info, t);
77570 spin_unlock_irqrestore(&t->sighand->siglock, flags);
77571
77572+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
77573+ normal operation */
77574+ if (is_unhandled) {
77575+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
77576+ gr_handle_crash(t, sig);
77577+ }
77578+
77579 return ret;
77580 }
77581
77582@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77583 ret = check_kill_permission(sig, info, p);
77584 rcu_read_unlock();
77585
77586- if (!ret && sig)
77587+ if (!ret && sig) {
77588 ret = do_send_sig_info(sig, info, p, true);
77589+ if (!ret)
77590+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
77591+ }
77592
77593 return ret;
77594 }
77595@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
77596 int error = -ESRCH;
77597
77598 rcu_read_lock();
77599- p = find_task_by_vpid(pid);
77600+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77601+ /* allow glibc communication via tgkill to other threads in our
77602+ thread group */
77603+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
77604+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
77605+ p = find_task_by_vpid_unrestricted(pid);
77606+ else
77607+#endif
77608+ p = find_task_by_vpid(pid);
77609 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
77610 error = check_kill_permission(sig, info, p);
77611 /*
77612@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
77613 }
77614 seg = get_fs();
77615 set_fs(KERNEL_DS);
77616- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
77617- (stack_t __force __user *) &uoss,
77618+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
77619+ (stack_t __force_user *) &uoss,
77620 compat_user_stack_pointer());
77621 set_fs(seg);
77622 if (ret >= 0 && uoss_ptr) {
77623diff --git a/kernel/smp.c b/kernel/smp.c
77624index 69f38bd..77bbf12 100644
77625--- a/kernel/smp.c
77626+++ b/kernel/smp.c
77627@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
77628 return NOTIFY_OK;
77629 }
77630
77631-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
77632+static struct notifier_block hotplug_cfd_notifier = {
77633 .notifier_call = hotplug_cfd,
77634 };
77635
77636diff --git a/kernel/smpboot.c b/kernel/smpboot.c
77637index d6c5fc0..530560c 100644
77638--- a/kernel/smpboot.c
77639+++ b/kernel/smpboot.c
77640@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
77641 }
77642 smpboot_unpark_thread(plug_thread, cpu);
77643 }
77644- list_add(&plug_thread->list, &hotplug_threads);
77645+ pax_list_add(&plug_thread->list, &hotplug_threads);
77646 out:
77647 mutex_unlock(&smpboot_threads_lock);
77648 return ret;
77649@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
77650 {
77651 get_online_cpus();
77652 mutex_lock(&smpboot_threads_lock);
77653- list_del(&plug_thread->list);
77654+ pax_list_del(&plug_thread->list);
77655 smpboot_destroy_threads(plug_thread);
77656 mutex_unlock(&smpboot_threads_lock);
77657 put_online_cpus();
77658diff --git a/kernel/softirq.c b/kernel/softirq.c
77659index ed567ba..e71dabf 100644
77660--- a/kernel/softirq.c
77661+++ b/kernel/softirq.c
77662@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
77663 EXPORT_SYMBOL(irq_stat);
77664 #endif
77665
77666-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
77667+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
77668
77669 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
77670
77671-char *softirq_to_name[NR_SOFTIRQS] = {
77672+const char * const softirq_to_name[NR_SOFTIRQS] = {
77673 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
77674 "TASKLET", "SCHED", "HRTIMER", "RCU"
77675 };
77676@@ -244,7 +244,7 @@ restart:
77677 kstat_incr_softirqs_this_cpu(vec_nr);
77678
77679 trace_softirq_entry(vec_nr);
77680- h->action(h);
77681+ h->action();
77682 trace_softirq_exit(vec_nr);
77683 if (unlikely(prev_count != preempt_count())) {
77684 printk(KERN_ERR "huh, entered softirq %u %s %p"
77685@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
77686 or_softirq_pending(1UL << nr);
77687 }
77688
77689-void open_softirq(int nr, void (*action)(struct softirq_action *))
77690+void __init open_softirq(int nr, void (*action)(void))
77691 {
77692 softirq_vec[nr].action = action;
77693 }
77694@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
77695
77696 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
77697
77698-static void tasklet_action(struct softirq_action *a)
77699+static void tasklet_action(void)
77700 {
77701 struct tasklet_struct *list;
77702
77703@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
77704 }
77705 }
77706
77707-static void tasklet_hi_action(struct softirq_action *a)
77708+static void tasklet_hi_action(void)
77709 {
77710 struct tasklet_struct *list;
77711
77712@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
77713 return NOTIFY_OK;
77714 }
77715
77716-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
77717+static struct notifier_block remote_softirq_cpu_notifier = {
77718 .notifier_call = remote_softirq_cpu_notify,
77719 };
77720
77721@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
77722 return NOTIFY_OK;
77723 }
77724
77725-static struct notifier_block __cpuinitdata cpu_nfb = {
77726+static struct notifier_block cpu_nfb = {
77727 .notifier_call = cpu_callback
77728 };
77729
77730-static struct smp_hotplug_thread softirq_threads = {
77731+static struct smp_hotplug_thread softirq_threads __read_only = {
77732 .store = &ksoftirqd,
77733 .thread_should_run = ksoftirqd_should_run,
77734 .thread_fn = run_ksoftirqd,
77735diff --git a/kernel/srcu.c b/kernel/srcu.c
77736index 2b85982..d52ab26 100644
77737--- a/kernel/srcu.c
77738+++ b/kernel/srcu.c
77739@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
77740 preempt_disable();
77741 idx = rcu_dereference_index_check(sp->completed,
77742 rcu_read_lock_sched_held()) & 0x1;
77743- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77744+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77745 smp_mb(); /* B */ /* Avoid leaking the critical section. */
77746- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77747+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77748 preempt_enable();
77749 return idx;
77750 }
77751@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
77752 {
77753 preempt_disable();
77754 smp_mb(); /* C */ /* Avoid leaking the critical section. */
77755- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77756+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77757 preempt_enable();
77758 }
77759 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
77760diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
77761index 2f194e9..2c05ea9 100644
77762--- a/kernel/stop_machine.c
77763+++ b/kernel/stop_machine.c
77764@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
77765 * cpu notifiers. It currently shares the same priority as sched
77766 * migration_notifier.
77767 */
77768-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
77769+static struct notifier_block cpu_stop_cpu_notifier = {
77770 .notifier_call = cpu_stop_cpu_callback,
77771 .priority = 10,
77772 };
77773diff --git a/kernel/sys.c b/kernel/sys.c
77774index 265b376..4e42ef5 100644
77775--- a/kernel/sys.c
77776+++ b/kernel/sys.c
77777@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
77778 error = -EACCES;
77779 goto out;
77780 }
77781+
77782+ if (gr_handle_chroot_setpriority(p, niceval)) {
77783+ error = -EACCES;
77784+ goto out;
77785+ }
77786+
77787 no_nice = security_task_setnice(p, niceval);
77788 if (no_nice) {
77789 error = no_nice;
77790@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
77791 goto error;
77792 }
77793
77794+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
77795+ goto error;
77796+
77797 if (rgid != (gid_t) -1 ||
77798 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
77799 new->sgid = new->egid;
77800@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
77801 old = current_cred();
77802
77803 retval = -EPERM;
77804+
77805+ if (gr_check_group_change(kgid, kgid, kgid))
77806+ goto error;
77807+
77808 if (nsown_capable(CAP_SETGID))
77809 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77810 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77811@@ -647,7 +660,7 @@ error:
77812 /*
77813 * change the user struct in a credentials set to match the new UID
77814 */
77815-static int set_user(struct cred *new)
77816+int set_user(struct cred *new)
77817 {
77818 struct user_struct *new_user;
77819
77820@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77821 goto error;
77822 }
77823
77824+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77825+ goto error;
77826+
77827 if (!uid_eq(new->uid, old->uid)) {
77828 retval = set_user(new);
77829 if (retval < 0)
77830@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77831 old = current_cred();
77832
77833 retval = -EPERM;
77834+
77835+ if (gr_check_crash_uid(kuid))
77836+ goto error;
77837+ if (gr_check_user_change(kuid, kuid, kuid))
77838+ goto error;
77839+
77840 if (nsown_capable(CAP_SETUID)) {
77841 new->suid = new->uid = kuid;
77842 if (!uid_eq(kuid, old->uid)) {
77843@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
77844 goto error;
77845 }
77846
77847+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
77848+ goto error;
77849+
77850 if (ruid != (uid_t) -1) {
77851 new->uid = kruid;
77852 if (!uid_eq(kruid, old->uid)) {
77853@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
77854 goto error;
77855 }
77856
77857+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
77858+ goto error;
77859+
77860 if (rgid != (gid_t) -1)
77861 new->gid = krgid;
77862 if (egid != (gid_t) -1)
77863@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77864 if (!uid_valid(kuid))
77865 return old_fsuid;
77866
77867+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
77868+ goto error;
77869+
77870 new = prepare_creds();
77871 if (!new)
77872 return old_fsuid;
77873@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77874 }
77875 }
77876
77877+error:
77878 abort_creds(new);
77879 return old_fsuid;
77880
77881@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
77882 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
77883 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
77884 nsown_capable(CAP_SETGID)) {
77885+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
77886+ goto error;
77887+
77888 if (!gid_eq(kgid, old->fsgid)) {
77889 new->fsgid = kgid;
77890 goto change_okay;
77891 }
77892 }
77893
77894+error:
77895 abort_creds(new);
77896 return old_fsgid;
77897
77898@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
77899 return -EFAULT;
77900
77901 down_read(&uts_sem);
77902- error = __copy_to_user(&name->sysname, &utsname()->sysname,
77903+ error = __copy_to_user(name->sysname, &utsname()->sysname,
77904 __OLD_UTS_LEN);
77905 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
77906- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
77907+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
77908 __OLD_UTS_LEN);
77909 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
77910- error |= __copy_to_user(&name->release, &utsname()->release,
77911+ error |= __copy_to_user(name->release, &utsname()->release,
77912 __OLD_UTS_LEN);
77913 error |= __put_user(0, name->release + __OLD_UTS_LEN);
77914- error |= __copy_to_user(&name->version, &utsname()->version,
77915+ error |= __copy_to_user(name->version, &utsname()->version,
77916 __OLD_UTS_LEN);
77917 error |= __put_user(0, name->version + __OLD_UTS_LEN);
77918- error |= __copy_to_user(&name->machine, &utsname()->machine,
77919+ error |= __copy_to_user(name->machine, &utsname()->machine,
77920 __OLD_UTS_LEN);
77921 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77922 up_read(&uts_sem);
77923@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77924 error = get_dumpable(me->mm);
77925 break;
77926 case PR_SET_DUMPABLE:
77927- if (arg2 < 0 || arg2 > 1) {
77928+ if (arg2 > 1) {
77929 error = -EINVAL;
77930 break;
77931 }
77932diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77933index c88878d..e4fa5d1 100644
77934--- a/kernel/sysctl.c
77935+++ b/kernel/sysctl.c
77936@@ -92,7 +92,6 @@
77937
77938
77939 #if defined(CONFIG_SYSCTL)
77940-
77941 /* External variables not in a header file. */
77942 extern int sysctl_overcommit_memory;
77943 extern int sysctl_overcommit_ratio;
77944@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77945 void __user *buffer, size_t *lenp, loff_t *ppos);
77946 #endif
77947
77948-#ifdef CONFIG_PRINTK
77949 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77950 void __user *buffer, size_t *lenp, loff_t *ppos);
77951-#endif
77952
77953 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77954 void __user *buffer, size_t *lenp, loff_t *ppos);
77955@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77956
77957 #endif
77958
77959+extern struct ctl_table grsecurity_table[];
77960+
77961 static struct ctl_table kern_table[];
77962 static struct ctl_table vm_table[];
77963 static struct ctl_table fs_table[];
77964@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77965 int sysctl_legacy_va_layout;
77966 #endif
77967
77968+#ifdef CONFIG_PAX_SOFTMODE
77969+static ctl_table pax_table[] = {
77970+ {
77971+ .procname = "softmode",
77972+ .data = &pax_softmode,
77973+ .maxlen = sizeof(unsigned int),
77974+ .mode = 0600,
77975+ .proc_handler = &proc_dointvec,
77976+ },
77977+
77978+ { }
77979+};
77980+#endif
77981+
77982 /* The default sysctl tables: */
77983
77984 static struct ctl_table sysctl_base_table[] = {
77985@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
77986 #endif
77987
77988 static struct ctl_table kern_table[] = {
77989+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
77990+ {
77991+ .procname = "grsecurity",
77992+ .mode = 0500,
77993+ .child = grsecurity_table,
77994+ },
77995+#endif
77996+
77997+#ifdef CONFIG_PAX_SOFTMODE
77998+ {
77999+ .procname = "pax",
78000+ .mode = 0500,
78001+ .child = pax_table,
78002+ },
78003+#endif
78004+
78005 {
78006 .procname = "sched_child_runs_first",
78007 .data = &sysctl_sched_child_runs_first,
78008@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
78009 .data = &modprobe_path,
78010 .maxlen = KMOD_PATH_LEN,
78011 .mode = 0644,
78012- .proc_handler = proc_dostring,
78013+ .proc_handler = proc_dostring_modpriv,
78014 },
78015 {
78016 .procname = "modules_disabled",
78017@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
78018 .extra1 = &zero,
78019 .extra2 = &one,
78020 },
78021+#endif
78022 {
78023 .procname = "kptr_restrict",
78024 .data = &kptr_restrict,
78025 .maxlen = sizeof(int),
78026 .mode = 0644,
78027 .proc_handler = proc_dointvec_minmax_sysadmin,
78028+#ifdef CONFIG_GRKERNSEC_HIDESYM
78029+ .extra1 = &two,
78030+#else
78031 .extra1 = &zero,
78032+#endif
78033 .extra2 = &two,
78034 },
78035-#endif
78036 {
78037 .procname = "ngroups_max",
78038 .data = &ngroups_max,
78039@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
78040 .proc_handler = proc_dointvec_minmax,
78041 .extra1 = &zero,
78042 },
78043+ {
78044+ .procname = "heap_stack_gap",
78045+ .data = &sysctl_heap_stack_gap,
78046+ .maxlen = sizeof(sysctl_heap_stack_gap),
78047+ .mode = 0644,
78048+ .proc_handler = proc_doulongvec_minmax,
78049+ },
78050 #else
78051 {
78052 .procname = "nr_trim_pages",
78053@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
78054 buffer, lenp, ppos);
78055 }
78056
78057+int proc_dostring_modpriv(struct ctl_table *table, int write,
78058+ void __user *buffer, size_t *lenp, loff_t *ppos)
78059+{
78060+ if (write && !capable(CAP_SYS_MODULE))
78061+ return -EPERM;
78062+
78063+ return _proc_do_string(table->data, table->maxlen, write,
78064+ buffer, lenp, ppos);
78065+}
78066+
78067 static size_t proc_skip_spaces(char **buf)
78068 {
78069 size_t ret;
78070@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
78071 len = strlen(tmp);
78072 if (len > *size)
78073 len = *size;
78074+ if (len > sizeof(tmp))
78075+ len = sizeof(tmp);
78076 if (copy_to_user(*buf, tmp, len))
78077 return -EFAULT;
78078 *size -= len;
78079@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
78080 static int proc_taint(struct ctl_table *table, int write,
78081 void __user *buffer, size_t *lenp, loff_t *ppos)
78082 {
78083- struct ctl_table t;
78084+ ctl_table_no_const t;
78085 unsigned long tmptaint = get_taint();
78086 int err;
78087
78088@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
78089 return err;
78090 }
78091
78092-#ifdef CONFIG_PRINTK
78093 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78094 void __user *buffer, size_t *lenp, loff_t *ppos)
78095 {
78096@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78097
78098 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
78099 }
78100-#endif
78101
78102 struct do_proc_dointvec_minmax_conv_param {
78103 int *min;
78104@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
78105 *i = val;
78106 } else {
78107 val = convdiv * (*i) / convmul;
78108- if (!first)
78109+ if (!first) {
78110 err = proc_put_char(&buffer, &left, '\t');
78111+ if (err)
78112+ break;
78113+ }
78114 err = proc_put_long(&buffer, &left, val, false);
78115 if (err)
78116 break;
78117@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
78118 return -ENOSYS;
78119 }
78120
78121+int proc_dostring_modpriv(struct ctl_table *table, int write,
78122+ void __user *buffer, size_t *lenp, loff_t *ppos)
78123+{
78124+ return -ENOSYS;
78125+}
78126+
78127 int proc_dointvec(struct ctl_table *table, int write,
78128 void __user *buffer, size_t *lenp, loff_t *ppos)
78129 {
78130@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
78131 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
78132 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
78133 EXPORT_SYMBOL(proc_dostring);
78134+EXPORT_SYMBOL(proc_dostring_modpriv);
78135 EXPORT_SYMBOL(proc_doulongvec_minmax);
78136 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
78137diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
78138index 0ddf3a0..a199f50 100644
78139--- a/kernel/sysctl_binary.c
78140+++ b/kernel/sysctl_binary.c
78141@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
78142 int i;
78143
78144 set_fs(KERNEL_DS);
78145- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78146+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78147 set_fs(old_fs);
78148 if (result < 0)
78149 goto out_kfree;
78150@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
78151 }
78152
78153 set_fs(KERNEL_DS);
78154- result = vfs_write(file, buffer, str - buffer, &pos);
78155+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78156 set_fs(old_fs);
78157 if (result < 0)
78158 goto out_kfree;
78159@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
78160 int i;
78161
78162 set_fs(KERNEL_DS);
78163- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78164+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78165 set_fs(old_fs);
78166 if (result < 0)
78167 goto out_kfree;
78168@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
78169 }
78170
78171 set_fs(KERNEL_DS);
78172- result = vfs_write(file, buffer, str - buffer, &pos);
78173+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78174 set_fs(old_fs);
78175 if (result < 0)
78176 goto out_kfree;
78177@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
78178 int i;
78179
78180 set_fs(KERNEL_DS);
78181- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78182+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78183 set_fs(old_fs);
78184 if (result < 0)
78185 goto out;
78186@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78187 __le16 dnaddr;
78188
78189 set_fs(KERNEL_DS);
78190- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78191+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78192 set_fs(old_fs);
78193 if (result < 0)
78194 goto out;
78195@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78196 le16_to_cpu(dnaddr) & 0x3ff);
78197
78198 set_fs(KERNEL_DS);
78199- result = vfs_write(file, buf, len, &pos);
78200+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
78201 set_fs(old_fs);
78202 if (result < 0)
78203 goto out;
78204diff --git a/kernel/taskstats.c b/kernel/taskstats.c
78205index 145bb4d..b2aa969 100644
78206--- a/kernel/taskstats.c
78207+++ b/kernel/taskstats.c
78208@@ -28,9 +28,12 @@
78209 #include <linux/fs.h>
78210 #include <linux/file.h>
78211 #include <linux/pid_namespace.h>
78212+#include <linux/grsecurity.h>
78213 #include <net/genetlink.h>
78214 #include <linux/atomic.h>
78215
78216+extern int gr_is_taskstats_denied(int pid);
78217+
78218 /*
78219 * Maximum length of a cpumask that can be specified in
78220 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
78221@@ -570,6 +573,9 @@ err:
78222
78223 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
78224 {
78225+ if (gr_is_taskstats_denied(current->pid))
78226+ return -EACCES;
78227+
78228 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
78229 return cmd_attr_register_cpumask(info);
78230 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
78231diff --git a/kernel/time.c b/kernel/time.c
78232index d226c6a..2f0d217 100644
78233--- a/kernel/time.c
78234+++ b/kernel/time.c
78235@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
78236 return error;
78237
78238 if (tz) {
78239+ /* we log in do_settimeofday called below, so don't log twice
78240+ */
78241+ if (!tv)
78242+ gr_log_timechange();
78243+
78244 sys_tz = *tz;
78245 update_vsyscall_tz();
78246 if (firsttime) {
78247@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
78248 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
78249 * value to a scaled second value.
78250 */
78251-unsigned long
78252+unsigned long __intentional_overflow(-1)
78253 timespec_to_jiffies(const struct timespec *value)
78254 {
78255 unsigned long sec = value->tv_sec;
78256diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
78257index f11d83b..d016d91 100644
78258--- a/kernel/time/alarmtimer.c
78259+++ b/kernel/time/alarmtimer.c
78260@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
78261 struct platform_device *pdev;
78262 int error = 0;
78263 int i;
78264- struct k_clock alarm_clock = {
78265+ static struct k_clock alarm_clock = {
78266 .clock_getres = alarm_clock_getres,
78267 .clock_get = alarm_clock_get,
78268 .timer_create = alarm_timer_create,
78269diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
78270index f113755..ec24223 100644
78271--- a/kernel/time/tick-broadcast.c
78272+++ b/kernel/time/tick-broadcast.c
78273@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
78274 * then clear the broadcast bit.
78275 */
78276 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
78277- int cpu = smp_processor_id();
78278+ cpu = smp_processor_id();
78279
78280 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
78281 tick_broadcast_clear_oneshot(cpu);
78282diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
78283index cbc6acb..3a77191 100644
78284--- a/kernel/time/timekeeping.c
78285+++ b/kernel/time/timekeeping.c
78286@@ -15,6 +15,7 @@
78287 #include <linux/init.h>
78288 #include <linux/mm.h>
78289 #include <linux/sched.h>
78290+#include <linux/grsecurity.h>
78291 #include <linux/syscore_ops.h>
78292 #include <linux/clocksource.h>
78293 #include <linux/jiffies.h>
78294@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
78295 if (!timespec_valid_strict(tv))
78296 return -EINVAL;
78297
78298+ gr_log_timechange();
78299+
78300 write_seqlock_irqsave(&tk->lock, flags);
78301
78302 timekeeping_forward_now(tk);
78303diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
78304index af5a7e9..715611a 100644
78305--- a/kernel/time/timer_list.c
78306+++ b/kernel/time/timer_list.c
78307@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
78308
78309 static void print_name_offset(struct seq_file *m, void *sym)
78310 {
78311+#ifdef CONFIG_GRKERNSEC_HIDESYM
78312+ SEQ_printf(m, "<%p>", NULL);
78313+#else
78314 char symname[KSYM_NAME_LEN];
78315
78316 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
78317 SEQ_printf(m, "<%pK>", sym);
78318 else
78319 SEQ_printf(m, "%s", symname);
78320+#endif
78321 }
78322
78323 static void
78324@@ -112,7 +116,11 @@ next_one:
78325 static void
78326 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
78327 {
78328+#ifdef CONFIG_GRKERNSEC_HIDESYM
78329+ SEQ_printf(m, " .base: %p\n", NULL);
78330+#else
78331 SEQ_printf(m, " .base: %pK\n", base);
78332+#endif
78333 SEQ_printf(m, " .index: %d\n",
78334 base->index);
78335 SEQ_printf(m, " .resolution: %Lu nsecs\n",
78336@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
78337 {
78338 struct proc_dir_entry *pe;
78339
78340+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78341+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
78342+#else
78343 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
78344+#endif
78345 if (!pe)
78346 return -ENOMEM;
78347 return 0;
78348diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
78349index 0b537f2..40d6c20 100644
78350--- a/kernel/time/timer_stats.c
78351+++ b/kernel/time/timer_stats.c
78352@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
78353 static unsigned long nr_entries;
78354 static struct entry entries[MAX_ENTRIES];
78355
78356-static atomic_t overflow_count;
78357+static atomic_unchecked_t overflow_count;
78358
78359 /*
78360 * The entries are in a hash-table, for fast lookup:
78361@@ -140,7 +140,7 @@ static void reset_entries(void)
78362 nr_entries = 0;
78363 memset(entries, 0, sizeof(entries));
78364 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
78365- atomic_set(&overflow_count, 0);
78366+ atomic_set_unchecked(&overflow_count, 0);
78367 }
78368
78369 static struct entry *alloc_entry(void)
78370@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78371 if (likely(entry))
78372 entry->count++;
78373 else
78374- atomic_inc(&overflow_count);
78375+ atomic_inc_unchecked(&overflow_count);
78376
78377 out_unlock:
78378 raw_spin_unlock_irqrestore(lock, flags);
78379@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78380
78381 static void print_name_offset(struct seq_file *m, unsigned long addr)
78382 {
78383+#ifdef CONFIG_GRKERNSEC_HIDESYM
78384+ seq_printf(m, "<%p>", NULL);
78385+#else
78386 char symname[KSYM_NAME_LEN];
78387
78388 if (lookup_symbol_name(addr, symname) < 0)
78389- seq_printf(m, "<%p>", (void *)addr);
78390+ seq_printf(m, "<%pK>", (void *)addr);
78391 else
78392 seq_printf(m, "%s", symname);
78393+#endif
78394 }
78395
78396 static int tstats_show(struct seq_file *m, void *v)
78397@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
78398
78399 seq_puts(m, "Timer Stats Version: v0.2\n");
78400 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
78401- if (atomic_read(&overflow_count))
78402+ if (atomic_read_unchecked(&overflow_count))
78403 seq_printf(m, "Overflow: %d entries\n",
78404- atomic_read(&overflow_count));
78405+ atomic_read_unchecked(&overflow_count));
78406
78407 for (i = 0; i < nr_entries; i++) {
78408 entry = entries + i;
78409@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
78410 {
78411 struct proc_dir_entry *pe;
78412
78413+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78414+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
78415+#else
78416 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
78417+#endif
78418 if (!pe)
78419 return -ENOMEM;
78420 return 0;
78421diff --git a/kernel/timer.c b/kernel/timer.c
78422index 367d008..5dee98f 100644
78423--- a/kernel/timer.c
78424+++ b/kernel/timer.c
78425@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
78426 /*
78427 * This function runs timers and the timer-tq in bottom half context.
78428 */
78429-static void run_timer_softirq(struct softirq_action *h)
78430+static void run_timer_softirq(void)
78431 {
78432 struct tvec_base *base = __this_cpu_read(tvec_bases);
78433
78434@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
78435 *
78436 * In all cases the return value is guaranteed to be non-negative.
78437 */
78438-signed long __sched schedule_timeout(signed long timeout)
78439+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
78440 {
78441 struct timer_list timer;
78442 unsigned long expire;
78443@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
78444 return NOTIFY_OK;
78445 }
78446
78447-static struct notifier_block __cpuinitdata timers_nb = {
78448+static struct notifier_block timers_nb = {
78449 .notifier_call = timer_cpu_notify,
78450 };
78451
78452diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
78453index c0bd030..62a1927 100644
78454--- a/kernel/trace/blktrace.c
78455+++ b/kernel/trace/blktrace.c
78456@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
78457 struct blk_trace *bt = filp->private_data;
78458 char buf[16];
78459
78460- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
78461+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
78462
78463 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
78464 }
78465@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
78466 return 1;
78467
78468 bt = buf->chan->private_data;
78469- atomic_inc(&bt->dropped);
78470+ atomic_inc_unchecked(&bt->dropped);
78471 return 0;
78472 }
78473
78474@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
78475
78476 bt->dir = dir;
78477 bt->dev = dev;
78478- atomic_set(&bt->dropped, 0);
78479+ atomic_set_unchecked(&bt->dropped, 0);
78480
78481 ret = -EIO;
78482 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
78483diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
78484index 43defd1..76da436 100644
78485--- a/kernel/trace/ftrace.c
78486+++ b/kernel/trace/ftrace.c
78487@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
78488 if (unlikely(ftrace_disabled))
78489 return 0;
78490
78491+ ret = ftrace_arch_code_modify_prepare();
78492+ FTRACE_WARN_ON(ret);
78493+ if (ret)
78494+ return 0;
78495+
78496 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
78497+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
78498 if (ret) {
78499 ftrace_bug(ret, ip);
78500- return 0;
78501 }
78502- return 1;
78503+ return ret ? 0 : 1;
78504 }
78505
78506 /*
78507@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
78508
78509 int
78510 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
78511- void *data)
78512+ void *data)
78513 {
78514 struct ftrace_func_probe *entry;
78515 struct ftrace_page *pg;
78516@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
78517 if (!count)
78518 return 0;
78519
78520+ pax_open_kernel();
78521 sort(start, count, sizeof(*start),
78522 ftrace_cmp_ips, ftrace_swap_ips);
78523+ pax_close_kernel();
78524
78525 start_pg = ftrace_allocate_pages(count);
78526 if (!start_pg)
78527@@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
78528 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
78529
78530 static int ftrace_graph_active;
78531-static struct notifier_block ftrace_suspend_notifier;
78532-
78533 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
78534 {
78535 return 0;
78536@@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
78537 return NOTIFY_DONE;
78538 }
78539
78540+static struct notifier_block ftrace_suspend_notifier = {
78541+ .notifier_call = ftrace_suspend_notifier_call
78542+};
78543+
78544 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78545 trace_func_graph_ent_t entryfunc)
78546 {
78547@@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78548 goto out;
78549 }
78550
78551- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
78552 register_pm_notifier(&ftrace_suspend_notifier);
78553
78554 ftrace_graph_active++;
78555diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
78556index ce8514f..8233573 100644
78557--- a/kernel/trace/ring_buffer.c
78558+++ b/kernel/trace/ring_buffer.c
78559@@ -346,9 +346,9 @@ struct buffer_data_page {
78560 */
78561 struct buffer_page {
78562 struct list_head list; /* list of buffer pages */
78563- local_t write; /* index for next write */
78564+ local_unchecked_t write; /* index for next write */
78565 unsigned read; /* index for next read */
78566- local_t entries; /* entries on this page */
78567+ local_unchecked_t entries; /* entries on this page */
78568 unsigned long real_end; /* real end of data */
78569 struct buffer_data_page *page; /* Actual data page */
78570 };
78571@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
78572 unsigned long last_overrun;
78573 local_t entries_bytes;
78574 local_t entries;
78575- local_t overrun;
78576- local_t commit_overrun;
78577+ local_unchecked_t overrun;
78578+ local_unchecked_t commit_overrun;
78579 local_t dropped_events;
78580 local_t committing;
78581 local_t commits;
78582@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78583 *
78584 * We add a counter to the write field to denote this.
78585 */
78586- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
78587- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
78588+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
78589+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
78590
78591 /*
78592 * Just make sure we have seen our old_write and synchronize
78593@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78594 * cmpxchg to only update if an interrupt did not already
78595 * do it for us. If the cmpxchg fails, we don't care.
78596 */
78597- (void)local_cmpxchg(&next_page->write, old_write, val);
78598- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
78599+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
78600+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
78601
78602 /*
78603 * No need to worry about races with clearing out the commit.
78604@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
78605
78606 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
78607 {
78608- return local_read(&bpage->entries) & RB_WRITE_MASK;
78609+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
78610 }
78611
78612 static inline unsigned long rb_page_write(struct buffer_page *bpage)
78613 {
78614- return local_read(&bpage->write) & RB_WRITE_MASK;
78615+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
78616 }
78617
78618 static int
78619@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
78620 * bytes consumed in ring buffer from here.
78621 * Increment overrun to account for the lost events.
78622 */
78623- local_add(page_entries, &cpu_buffer->overrun);
78624+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
78625 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78626 }
78627
78628@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
78629 * it is our responsibility to update
78630 * the counters.
78631 */
78632- local_add(entries, &cpu_buffer->overrun);
78633+ local_add_unchecked(entries, &cpu_buffer->overrun);
78634 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78635
78636 /*
78637@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78638 if (tail == BUF_PAGE_SIZE)
78639 tail_page->real_end = 0;
78640
78641- local_sub(length, &tail_page->write);
78642+ local_sub_unchecked(length, &tail_page->write);
78643 return;
78644 }
78645
78646@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78647 rb_event_set_padding(event);
78648
78649 /* Set the write back to the previous setting */
78650- local_sub(length, &tail_page->write);
78651+ local_sub_unchecked(length, &tail_page->write);
78652 return;
78653 }
78654
78655@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78656
78657 /* Set write to end of buffer */
78658 length = (tail + length) - BUF_PAGE_SIZE;
78659- local_sub(length, &tail_page->write);
78660+ local_sub_unchecked(length, &tail_page->write);
78661 }
78662
78663 /*
78664@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78665 * about it.
78666 */
78667 if (unlikely(next_page == commit_page)) {
78668- local_inc(&cpu_buffer->commit_overrun);
78669+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78670 goto out_reset;
78671 }
78672
78673@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78674 cpu_buffer->tail_page) &&
78675 (cpu_buffer->commit_page ==
78676 cpu_buffer->reader_page))) {
78677- local_inc(&cpu_buffer->commit_overrun);
78678+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78679 goto out_reset;
78680 }
78681 }
78682@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78683 length += RB_LEN_TIME_EXTEND;
78684
78685 tail_page = cpu_buffer->tail_page;
78686- write = local_add_return(length, &tail_page->write);
78687+ write = local_add_return_unchecked(length, &tail_page->write);
78688
78689 /* set write to only the index of the write */
78690 write &= RB_WRITE_MASK;
78691@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78692 kmemcheck_annotate_bitfield(event, bitfield);
78693 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
78694
78695- local_inc(&tail_page->entries);
78696+ local_inc_unchecked(&tail_page->entries);
78697
78698 /*
78699 * If this is the first commit on the page, then update
78700@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78701
78702 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
78703 unsigned long write_mask =
78704- local_read(&bpage->write) & ~RB_WRITE_MASK;
78705+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
78706 unsigned long event_length = rb_event_length(event);
78707 /*
78708 * This is on the tail page. It is possible that
78709@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78710 */
78711 old_index += write_mask;
78712 new_index += write_mask;
78713- index = local_cmpxchg(&bpage->write, old_index, new_index);
78714+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
78715 if (index == old_index) {
78716 /* update counters */
78717 local_sub(event_length, &cpu_buffer->entries_bytes);
78718@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78719
78720 /* Do the likely case first */
78721 if (likely(bpage->page == (void *)addr)) {
78722- local_dec(&bpage->entries);
78723+ local_dec_unchecked(&bpage->entries);
78724 return;
78725 }
78726
78727@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78728 start = bpage;
78729 do {
78730 if (bpage->page == (void *)addr) {
78731- local_dec(&bpage->entries);
78732+ local_dec_unchecked(&bpage->entries);
78733 return;
78734 }
78735 rb_inc_page(cpu_buffer, &bpage);
78736@@ -2926,7 +2926,7 @@ static inline unsigned long
78737 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
78738 {
78739 return local_read(&cpu_buffer->entries) -
78740- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
78741+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
78742 }
78743
78744 /**
78745@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
78746 return 0;
78747
78748 cpu_buffer = buffer->buffers[cpu];
78749- ret = local_read(&cpu_buffer->overrun);
78750+ ret = local_read_unchecked(&cpu_buffer->overrun);
78751
78752 return ret;
78753 }
78754@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
78755 return 0;
78756
78757 cpu_buffer = buffer->buffers[cpu];
78758- ret = local_read(&cpu_buffer->commit_overrun);
78759+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
78760
78761 return ret;
78762 }
78763@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
78764 /* if you care about this being correct, lock the buffer */
78765 for_each_buffer_cpu(buffer, cpu) {
78766 cpu_buffer = buffer->buffers[cpu];
78767- overruns += local_read(&cpu_buffer->overrun);
78768+ overruns += local_read_unchecked(&cpu_buffer->overrun);
78769 }
78770
78771 return overruns;
78772@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78773 /*
78774 * Reset the reader page to size zero.
78775 */
78776- local_set(&cpu_buffer->reader_page->write, 0);
78777- local_set(&cpu_buffer->reader_page->entries, 0);
78778+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78779+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78780 local_set(&cpu_buffer->reader_page->page->commit, 0);
78781 cpu_buffer->reader_page->real_end = 0;
78782
78783@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78784 * want to compare with the last_overrun.
78785 */
78786 smp_mb();
78787- overwrite = local_read(&(cpu_buffer->overrun));
78788+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
78789
78790 /*
78791 * Here's the tricky part.
78792@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78793
78794 cpu_buffer->head_page
78795 = list_entry(cpu_buffer->pages, struct buffer_page, list);
78796- local_set(&cpu_buffer->head_page->write, 0);
78797- local_set(&cpu_buffer->head_page->entries, 0);
78798+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
78799+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
78800 local_set(&cpu_buffer->head_page->page->commit, 0);
78801
78802 cpu_buffer->head_page->read = 0;
78803@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78804
78805 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
78806 INIT_LIST_HEAD(&cpu_buffer->new_pages);
78807- local_set(&cpu_buffer->reader_page->write, 0);
78808- local_set(&cpu_buffer->reader_page->entries, 0);
78809+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78810+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78811 local_set(&cpu_buffer->reader_page->page->commit, 0);
78812 cpu_buffer->reader_page->read = 0;
78813
78814 local_set(&cpu_buffer->entries_bytes, 0);
78815- local_set(&cpu_buffer->overrun, 0);
78816- local_set(&cpu_buffer->commit_overrun, 0);
78817+ local_set_unchecked(&cpu_buffer->overrun, 0);
78818+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
78819 local_set(&cpu_buffer->dropped_events, 0);
78820 local_set(&cpu_buffer->entries, 0);
78821 local_set(&cpu_buffer->committing, 0);
78822@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78823 rb_init_page(bpage);
78824 bpage = reader->page;
78825 reader->page = *data_page;
78826- local_set(&reader->write, 0);
78827- local_set(&reader->entries, 0);
78828+ local_set_unchecked(&reader->write, 0);
78829+ local_set_unchecked(&reader->entries, 0);
78830 reader->read = 0;
78831 *data_page = bpage;
78832
78833diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
78834index 3c13e46..883d039 100644
78835--- a/kernel/trace/trace.c
78836+++ b/kernel/trace/trace.c
78837@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
78838 };
78839 #endif
78840
78841-static struct dentry *d_tracer;
78842-
78843 struct dentry *tracing_init_dentry(void)
78844 {
78845+ static struct dentry *d_tracer;
78846 static int once;
78847
78848 if (d_tracer)
78849@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
78850 return d_tracer;
78851 }
78852
78853-static struct dentry *d_percpu;
78854-
78855 struct dentry *tracing_dentry_percpu(void)
78856 {
78857+ static struct dentry *d_percpu;
78858 static int once;
78859 struct dentry *d_tracer;
78860
78861diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
78862index 880073d..42db7c3 100644
78863--- a/kernel/trace/trace_events.c
78864+++ b/kernel/trace/trace_events.c
78865@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
78866 struct ftrace_module_file_ops {
78867 struct list_head list;
78868 struct module *mod;
78869- struct file_operations id;
78870- struct file_operations enable;
78871- struct file_operations format;
78872- struct file_operations filter;
78873 };
78874
78875 static struct ftrace_module_file_ops *
78876@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
78877
78878 file_ops->mod = mod;
78879
78880- file_ops->id = ftrace_event_id_fops;
78881- file_ops->id.owner = mod;
78882-
78883- file_ops->enable = ftrace_enable_fops;
78884- file_ops->enable.owner = mod;
78885-
78886- file_ops->filter = ftrace_event_filter_fops;
78887- file_ops->filter.owner = mod;
78888-
78889- file_ops->format = ftrace_event_format_fops;
78890- file_ops->format.owner = mod;
78891+ pax_open_kernel();
78892+ mod->trace_id.owner = mod;
78893+ mod->trace_enable.owner = mod;
78894+ mod->trace_filter.owner = mod;
78895+ mod->trace_format.owner = mod;
78896+ pax_close_kernel();
78897
78898 list_add(&file_ops->list, &ftrace_module_file_list);
78899
78900@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
78901
78902 for_each_event(call, start, end) {
78903 __trace_add_event_call(*call, mod,
78904- &file_ops->id, &file_ops->enable,
78905- &file_ops->filter, &file_ops->format);
78906+ &mod->trace_id, &mod->trace_enable,
78907+ &mod->trace_filter, &mod->trace_format);
78908 }
78909 }
78910
78911diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
78912index fd3c8aa..5f324a6 100644
78913--- a/kernel/trace/trace_mmiotrace.c
78914+++ b/kernel/trace/trace_mmiotrace.c
78915@@ -24,7 +24,7 @@ struct header_iter {
78916 static struct trace_array *mmio_trace_array;
78917 static bool overrun_detected;
78918 static unsigned long prev_overruns;
78919-static atomic_t dropped_count;
78920+static atomic_unchecked_t dropped_count;
78921
78922 static void mmio_reset_data(struct trace_array *tr)
78923 {
78924@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
78925
78926 static unsigned long count_overruns(struct trace_iterator *iter)
78927 {
78928- unsigned long cnt = atomic_xchg(&dropped_count, 0);
78929+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
78930 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
78931
78932 if (over > prev_overruns)
78933@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
78934 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
78935 sizeof(*entry), 0, pc);
78936 if (!event) {
78937- atomic_inc(&dropped_count);
78938+ atomic_inc_unchecked(&dropped_count);
78939 return;
78940 }
78941 entry = ring_buffer_event_data(event);
78942@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78943 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78944 sizeof(*entry), 0, pc);
78945 if (!event) {
78946- atomic_inc(&dropped_count);
78947+ atomic_inc_unchecked(&dropped_count);
78948 return;
78949 }
78950 entry = ring_buffer_event_data(event);
78951diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78952index 194d796..76edb8f 100644
78953--- a/kernel/trace/trace_output.c
78954+++ b/kernel/trace/trace_output.c
78955@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78956
78957 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78958 if (!IS_ERR(p)) {
78959- p = mangle_path(s->buffer + s->len, p, "\n");
78960+ p = mangle_path(s->buffer + s->len, p, "\n\\");
78961 if (p) {
78962 s->len = p - s->buffer;
78963 return 1;
78964@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78965 goto out;
78966 }
78967
78968+ pax_open_kernel();
78969 if (event->funcs->trace == NULL)
78970- event->funcs->trace = trace_nop_print;
78971+ *(void **)&event->funcs->trace = trace_nop_print;
78972 if (event->funcs->raw == NULL)
78973- event->funcs->raw = trace_nop_print;
78974+ *(void **)&event->funcs->raw = trace_nop_print;
78975 if (event->funcs->hex == NULL)
78976- event->funcs->hex = trace_nop_print;
78977+ *(void **)&event->funcs->hex = trace_nop_print;
78978 if (event->funcs->binary == NULL)
78979- event->funcs->binary = trace_nop_print;
78980+ *(void **)&event->funcs->binary = trace_nop_print;
78981+ pax_close_kernel();
78982
78983 key = event->type & (EVENT_HASHSIZE - 1);
78984
78985diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
78986index 42ca822..cdcacc6 100644
78987--- a/kernel/trace/trace_stack.c
78988+++ b/kernel/trace/trace_stack.c
78989@@ -52,7 +52,7 @@ static inline void check_stack(void)
78990 return;
78991
78992 /* we do not handle interrupt stacks yet */
78993- if (!object_is_on_stack(&this_size))
78994+ if (!object_starts_on_stack(&this_size))
78995 return;
78996
78997 local_irq_save(flags);
78998diff --git a/kernel/user.c b/kernel/user.c
78999index 33acb5e..57ebfd4 100644
79000--- a/kernel/user.c
79001+++ b/kernel/user.c
79002@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
79003 .count = 4294967295U,
79004 },
79005 },
79006- .kref = {
79007- .refcount = ATOMIC_INIT(3),
79008- },
79009+ .count = ATOMIC_INIT(3),
79010 .owner = GLOBAL_ROOT_UID,
79011 .group = GLOBAL_ROOT_GID,
79012 .proc_inum = PROC_USER_INIT_INO,
79013diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
79014index dbfe36a7..2a3c1df 100644
79015--- a/kernel/user_namespace.c
79016+++ b/kernel/user_namespace.c
79017@@ -79,7 +79,7 @@ int create_user_ns(struct cred *new)
79018 return ret;
79019 }
79020
79021- kref_init(&ns->kref);
79022+ atomic_set(&ns->count, 1);
79023 /* Leave the new->user_ns reference with the new user namespace. */
79024 ns->parent = parent_ns;
79025 ns->owner = owner;
79026@@ -105,15 +105,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
79027 return create_user_ns(cred);
79028 }
79029
79030-void free_user_ns(struct kref *kref)
79031+void free_user_ns(struct user_namespace *ns)
79032 {
79033- struct user_namespace *parent, *ns =
79034- container_of(kref, struct user_namespace, kref);
79035+ struct user_namespace *parent;
79036
79037- parent = ns->parent;
79038- proc_free_inum(ns->proc_inum);
79039- kmem_cache_free(user_ns_cachep, ns);
79040- put_user_ns(parent);
79041+ do {
79042+ parent = ns->parent;
79043+ proc_free_inum(ns->proc_inum);
79044+ kmem_cache_free(user_ns_cachep, ns);
79045+ ns = parent;
79046+ } while (atomic_dec_and_test(&parent->count));
79047 }
79048 EXPORT_SYMBOL(free_user_ns);
79049
79050@@ -804,7 +805,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
79051 if (atomic_read(&current->mm->mm_users) > 1)
79052 return -EINVAL;
79053
79054- if (current->fs->users != 1)
79055+ if (atomic_read(&current->fs->users) != 1)
79056 return -EINVAL;
79057
79058 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
79059diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
79060index 63da38c..639904e 100644
79061--- a/kernel/utsname_sysctl.c
79062+++ b/kernel/utsname_sysctl.c
79063@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
79064 static int proc_do_uts_string(ctl_table *table, int write,
79065 void __user *buffer, size_t *lenp, loff_t *ppos)
79066 {
79067- struct ctl_table uts_table;
79068+ ctl_table_no_const uts_table;
79069 int r;
79070 memcpy(&uts_table, table, sizeof(uts_table));
79071 uts_table.data = get_uts(table, write);
79072diff --git a/kernel/watchdog.c b/kernel/watchdog.c
79073index 75a2ab3..5961da7 100644
79074--- a/kernel/watchdog.c
79075+++ b/kernel/watchdog.c
79076@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
79077 }
79078 #endif /* CONFIG_SYSCTL */
79079
79080-static struct smp_hotplug_thread watchdog_threads = {
79081+static struct smp_hotplug_thread watchdog_threads __read_only = {
79082 .store = &softlockup_watchdog,
79083 .thread_should_run = watchdog_should_run,
79084 .thread_fn = watchdog,
79085diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
79086index 67604e5..fe94fb1 100644
79087--- a/lib/Kconfig.debug
79088+++ b/lib/Kconfig.debug
79089@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
79090
79091 config DEBUG_LOCK_ALLOC
79092 bool "Lock debugging: detect incorrect freeing of live locks"
79093- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79094+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79095 select DEBUG_SPINLOCK
79096 select DEBUG_MUTEXES
79097 select LOCKDEP
79098@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
79099
79100 config PROVE_LOCKING
79101 bool "Lock debugging: prove locking correctness"
79102- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79103+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79104 select LOCKDEP
79105 select DEBUG_SPINLOCK
79106 select DEBUG_MUTEXES
79107@@ -670,7 +670,7 @@ config LOCKDEP
79108
79109 config LOCK_STAT
79110 bool "Lock usage statistics"
79111- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79112+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79113 select LOCKDEP
79114 select DEBUG_SPINLOCK
79115 select DEBUG_MUTEXES
79116@@ -1278,6 +1278,7 @@ config LATENCYTOP
79117 depends on DEBUG_KERNEL
79118 depends on STACKTRACE_SUPPORT
79119 depends on PROC_FS
79120+ depends on !GRKERNSEC_HIDESYM
79121 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
79122 select KALLSYMS
79123 select KALLSYMS_ALL
79124@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
79125
79126 config PROVIDE_OHCI1394_DMA_INIT
79127 bool "Remote debugging over FireWire early on boot"
79128- depends on PCI && X86
79129+ depends on PCI && X86 && !GRKERNSEC
79130 help
79131 If you want to debug problems which hang or crash the kernel early
79132 on boot and the crashing machine has a FireWire port, you can use
79133@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
79134
79135 config FIREWIRE_OHCI_REMOTE_DMA
79136 bool "Remote debugging over FireWire with firewire-ohci"
79137- depends on FIREWIRE_OHCI
79138+ depends on FIREWIRE_OHCI && !GRKERNSEC
79139 help
79140 This option lets you use the FireWire bus for remote debugging
79141 with help of the firewire-ohci driver. It enables unfiltered
79142diff --git a/lib/Makefile b/lib/Makefile
79143index 02ed6c0..bd243da 100644
79144--- a/lib/Makefile
79145+++ b/lib/Makefile
79146@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
79147
79148 obj-$(CONFIG_BTREE) += btree.o
79149 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
79150-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
79151+obj-y += list_debug.o
79152 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
79153
79154 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
79155diff --git a/lib/bitmap.c b/lib/bitmap.c
79156index 06f7e4f..f3cf2b0 100644
79157--- a/lib/bitmap.c
79158+++ b/lib/bitmap.c
79159@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
79160 {
79161 int c, old_c, totaldigits, ndigits, nchunks, nbits;
79162 u32 chunk;
79163- const char __user __force *ubuf = (const char __user __force *)buf;
79164+ const char __user *ubuf = (const char __force_user *)buf;
79165
79166 bitmap_zero(maskp, nmaskbits);
79167
79168@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
79169 {
79170 if (!access_ok(VERIFY_READ, ubuf, ulen))
79171 return -EFAULT;
79172- return __bitmap_parse((const char __force *)ubuf,
79173+ return __bitmap_parse((const char __force_kernel *)ubuf,
79174 ulen, 1, maskp, nmaskbits);
79175
79176 }
79177@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
79178 {
79179 unsigned a, b;
79180 int c, old_c, totaldigits;
79181- const char __user __force *ubuf = (const char __user __force *)buf;
79182+ const char __user *ubuf = (const char __force_user *)buf;
79183 int exp_digit, in_range;
79184
79185 totaldigits = c = 0;
79186@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
79187 {
79188 if (!access_ok(VERIFY_READ, ubuf, ulen))
79189 return -EFAULT;
79190- return __bitmap_parselist((const char __force *)ubuf,
79191+ return __bitmap_parselist((const char __force_kernel *)ubuf,
79192 ulen, 1, maskp, nmaskbits);
79193 }
79194 EXPORT_SYMBOL(bitmap_parselist_user);
79195diff --git a/lib/bug.c b/lib/bug.c
79196index d0cdf14..4d07bd2 100644
79197--- a/lib/bug.c
79198+++ b/lib/bug.c
79199@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
79200 return BUG_TRAP_TYPE_NONE;
79201
79202 bug = find_bug(bugaddr);
79203+ if (!bug)
79204+ return BUG_TRAP_TYPE_NONE;
79205
79206 file = NULL;
79207 line = 0;
79208diff --git a/lib/debugobjects.c b/lib/debugobjects.c
79209index d11808c..dc2d6f8 100644
79210--- a/lib/debugobjects.c
79211+++ b/lib/debugobjects.c
79212@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
79213 if (limit > 4)
79214 return;
79215
79216- is_on_stack = object_is_on_stack(addr);
79217+ is_on_stack = object_starts_on_stack(addr);
79218 if (is_on_stack == onstack)
79219 return;
79220
79221diff --git a/lib/devres.c b/lib/devres.c
79222index 80b9c76..9e32279 100644
79223--- a/lib/devres.c
79224+++ b/lib/devres.c
79225@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
79226 void devm_iounmap(struct device *dev, void __iomem *addr)
79227 {
79228 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
79229- (void *)addr));
79230+ (void __force *)addr));
79231 iounmap(addr);
79232 }
79233 EXPORT_SYMBOL(devm_iounmap);
79234@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
79235 {
79236 ioport_unmap(addr);
79237 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
79238- devm_ioport_map_match, (void *)addr));
79239+ devm_ioport_map_match, (void __force *)addr));
79240 }
79241 EXPORT_SYMBOL(devm_ioport_unmap);
79242
79243diff --git a/lib/div64.c b/lib/div64.c
79244index a163b6c..9618fa5 100644
79245--- a/lib/div64.c
79246+++ b/lib/div64.c
79247@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
79248 EXPORT_SYMBOL(__div64_32);
79249
79250 #ifndef div_s64_rem
79251-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79252+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79253 {
79254 u64 quotient;
79255
79256@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
79257 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
79258 */
79259 #ifndef div64_u64
79260-u64 div64_u64(u64 dividend, u64 divisor)
79261+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79262 {
79263 u32 high = divisor >> 32;
79264 u64 quot;
79265diff --git a/lib/dma-debug.c b/lib/dma-debug.c
79266index 5e396ac..58d5de1 100644
79267--- a/lib/dma-debug.c
79268+++ b/lib/dma-debug.c
79269@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
79270
79271 void dma_debug_add_bus(struct bus_type *bus)
79272 {
79273- struct notifier_block *nb;
79274+ notifier_block_no_const *nb;
79275
79276 if (global_disable)
79277 return;
79278@@ -942,7 +942,7 @@ out:
79279
79280 static void check_for_stack(struct device *dev, void *addr)
79281 {
79282- if (object_is_on_stack(addr))
79283+ if (object_starts_on_stack(addr))
79284 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
79285 "stack [addr=%p]\n", addr);
79286 }
79287diff --git a/lib/inflate.c b/lib/inflate.c
79288index 013a761..c28f3fc 100644
79289--- a/lib/inflate.c
79290+++ b/lib/inflate.c
79291@@ -269,7 +269,7 @@ static void free(void *where)
79292 malloc_ptr = free_mem_ptr;
79293 }
79294 #else
79295-#define malloc(a) kmalloc(a, GFP_KERNEL)
79296+#define malloc(a) kmalloc((a), GFP_KERNEL)
79297 #define free(a) kfree(a)
79298 #endif
79299
79300diff --git a/lib/ioremap.c b/lib/ioremap.c
79301index 0c9216c..863bd89 100644
79302--- a/lib/ioremap.c
79303+++ b/lib/ioremap.c
79304@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
79305 unsigned long next;
79306
79307 phys_addr -= addr;
79308- pmd = pmd_alloc(&init_mm, pud, addr);
79309+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79310 if (!pmd)
79311 return -ENOMEM;
79312 do {
79313@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
79314 unsigned long next;
79315
79316 phys_addr -= addr;
79317- pud = pud_alloc(&init_mm, pgd, addr);
79318+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79319 if (!pud)
79320 return -ENOMEM;
79321 do {
79322diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
79323index bd2bea9..6b3c95e 100644
79324--- a/lib/is_single_threaded.c
79325+++ b/lib/is_single_threaded.c
79326@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
79327 struct task_struct *p, *t;
79328 bool ret;
79329
79330+ if (!mm)
79331+ return true;
79332+
79333 if (atomic_read(&task->signal->live) != 1)
79334 return false;
79335
79336diff --git a/lib/kobject.c b/lib/kobject.c
79337index e07ee1f..998489d 100644
79338--- a/lib/kobject.c
79339+++ b/lib/kobject.c
79340@@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
79341
79342
79343 static DEFINE_SPINLOCK(kobj_ns_type_lock);
79344-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
79345+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
79346
79347-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79348+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79349 {
79350 enum kobj_ns_type type = ops->type;
79351 int error;
79352diff --git a/lib/list_debug.c b/lib/list_debug.c
79353index c24c2f7..0475b78 100644
79354--- a/lib/list_debug.c
79355+++ b/lib/list_debug.c
79356@@ -11,7 +11,9 @@
79357 #include <linux/bug.h>
79358 #include <linux/kernel.h>
79359 #include <linux/rculist.h>
79360+#include <linux/mm.h>
79361
79362+#ifdef CONFIG_DEBUG_LIST
79363 /*
79364 * Insert a new entry between two known consecutive entries.
79365 *
79366@@ -19,21 +21,32 @@
79367 * the prev/next entries already!
79368 */
79369
79370-void __list_add(struct list_head *new,
79371- struct list_head *prev,
79372- struct list_head *next)
79373+static bool __list_add_debug(struct list_head *new,
79374+ struct list_head *prev,
79375+ struct list_head *next)
79376 {
79377- WARN(next->prev != prev,
79378+ if (WARN(next->prev != prev,
79379 "list_add corruption. next->prev should be "
79380 "prev (%p), but was %p. (next=%p).\n",
79381- prev, next->prev, next);
79382- WARN(prev->next != next,
79383+ prev, next->prev, next) ||
79384+ WARN(prev->next != next,
79385 "list_add corruption. prev->next should be "
79386 "next (%p), but was %p. (prev=%p).\n",
79387- next, prev->next, prev);
79388- WARN(new == prev || new == next,
79389+ next, prev->next, prev) ||
79390+ WARN(new == prev || new == next,
79391 "list_add double add: new=%p, prev=%p, next=%p.\n",
79392- new, prev, next);
79393+ new, prev, next))
79394+ return false;
79395+ return true;
79396+}
79397+
79398+void __list_add(struct list_head *new,
79399+ struct list_head *prev,
79400+ struct list_head *next)
79401+{
79402+ if (!__list_add_debug(new, prev, next))
79403+ return;
79404+
79405 next->prev = new;
79406 new->next = next;
79407 new->prev = prev;
79408@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
79409 }
79410 EXPORT_SYMBOL(__list_add);
79411
79412-void __list_del_entry(struct list_head *entry)
79413+static bool __list_del_entry_debug(struct list_head *entry)
79414 {
79415 struct list_head *prev, *next;
79416
79417@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
79418 WARN(next->prev != entry,
79419 "list_del corruption. next->prev should be %p, "
79420 "but was %p\n", entry, next->prev))
79421+ return false;
79422+ return true;
79423+}
79424+
79425+void __list_del_entry(struct list_head *entry)
79426+{
79427+ if (!__list_del_entry_debug(entry))
79428 return;
79429
79430- __list_del(prev, next);
79431+ __list_del(entry->prev, entry->next);
79432 }
79433 EXPORT_SYMBOL(__list_del_entry);
79434
79435@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
79436 void __list_add_rcu(struct list_head *new,
79437 struct list_head *prev, struct list_head *next)
79438 {
79439- WARN(next->prev != prev,
79440- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
79441- prev, next->prev, next);
79442- WARN(prev->next != next,
79443- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
79444- next, prev->next, prev);
79445+ if (!__list_add_debug(new, prev, next))
79446+ return;
79447+
79448 new->next = next;
79449 new->prev = prev;
79450 rcu_assign_pointer(list_next_rcu(prev), new);
79451 next->prev = new;
79452 }
79453 EXPORT_SYMBOL(__list_add_rcu);
79454+#endif
79455+
79456+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
79457+{
79458+#ifdef CONFIG_DEBUG_LIST
79459+ if (!__list_add_debug(new, prev, next))
79460+ return;
79461+#endif
79462+
79463+ pax_open_kernel();
79464+ next->prev = new;
79465+ new->next = next;
79466+ new->prev = prev;
79467+ prev->next = new;
79468+ pax_close_kernel();
79469+}
79470+EXPORT_SYMBOL(__pax_list_add);
79471+
79472+void pax_list_del(struct list_head *entry)
79473+{
79474+#ifdef CONFIG_DEBUG_LIST
79475+ if (!__list_del_entry_debug(entry))
79476+ return;
79477+#endif
79478+
79479+ pax_open_kernel();
79480+ __list_del(entry->prev, entry->next);
79481+ entry->next = LIST_POISON1;
79482+ entry->prev = LIST_POISON2;
79483+ pax_close_kernel();
79484+}
79485+EXPORT_SYMBOL(pax_list_del);
79486+
79487+void pax_list_del_init(struct list_head *entry)
79488+{
79489+ pax_open_kernel();
79490+ __list_del(entry->prev, entry->next);
79491+ INIT_LIST_HEAD(entry);
79492+ pax_close_kernel();
79493+}
79494+EXPORT_SYMBOL(pax_list_del_init);
79495+
79496+void __pax_list_add_rcu(struct list_head *new,
79497+ struct list_head *prev, struct list_head *next)
79498+{
79499+#ifdef CONFIG_DEBUG_LIST
79500+ if (!__list_add_debug(new, prev, next))
79501+ return;
79502+#endif
79503+
79504+ pax_open_kernel();
79505+ new->next = next;
79506+ new->prev = prev;
79507+ rcu_assign_pointer(list_next_rcu(prev), new);
79508+ next->prev = new;
79509+ pax_close_kernel();
79510+}
79511+EXPORT_SYMBOL(__pax_list_add_rcu);
79512+
79513+void pax_list_del_rcu(struct list_head *entry)
79514+{
79515+#ifdef CONFIG_DEBUG_LIST
79516+ if (!__list_del_entry_debug(entry))
79517+ return;
79518+#endif
79519+
79520+ pax_open_kernel();
79521+ __list_del(entry->prev, entry->next);
79522+ entry->next = LIST_POISON1;
79523+ entry->prev = LIST_POISON2;
79524+ pax_close_kernel();
79525+}
79526+EXPORT_SYMBOL(pax_list_del_rcu);
79527diff --git a/lib/radix-tree.c b/lib/radix-tree.c
79528index e796429..6e38f9f 100644
79529--- a/lib/radix-tree.c
79530+++ b/lib/radix-tree.c
79531@@ -92,7 +92,7 @@ struct radix_tree_preload {
79532 int nr;
79533 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
79534 };
79535-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
79536+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
79537
79538 static inline void *ptr_to_indirect(void *ptr)
79539 {
79540diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
79541index bb2b201..46abaf9 100644
79542--- a/lib/strncpy_from_user.c
79543+++ b/lib/strncpy_from_user.c
79544@@ -21,7 +21,7 @@
79545 */
79546 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
79547 {
79548- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79549+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79550 long res = 0;
79551
79552 /*
79553diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
79554index a28df52..3d55877 100644
79555--- a/lib/strnlen_user.c
79556+++ b/lib/strnlen_user.c
79557@@ -26,7 +26,7 @@
79558 */
79559 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
79560 {
79561- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79562+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79563 long align, res = 0;
79564 unsigned long c;
79565
79566diff --git a/lib/swiotlb.c b/lib/swiotlb.c
79567index 196b069..358f342 100644
79568--- a/lib/swiotlb.c
79569+++ b/lib/swiotlb.c
79570@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
79571
79572 void
79573 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
79574- dma_addr_t dev_addr)
79575+ dma_addr_t dev_addr, struct dma_attrs *attrs)
79576 {
79577 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
79578
79579diff --git a/lib/vsprintf.c b/lib/vsprintf.c
79580index fab33a9..3b5fe68 100644
79581--- a/lib/vsprintf.c
79582+++ b/lib/vsprintf.c
79583@@ -16,6 +16,9 @@
79584 * - scnprintf and vscnprintf
79585 */
79586
79587+#ifdef CONFIG_GRKERNSEC_HIDESYM
79588+#define __INCLUDED_BY_HIDESYM 1
79589+#endif
79590 #include <stdarg.h>
79591 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
79592 #include <linux/types.h>
79593@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
79594 char sym[KSYM_SYMBOL_LEN];
79595 if (ext == 'B')
79596 sprint_backtrace(sym, value);
79597- else if (ext != 'f' && ext != 's')
79598+ else if (ext != 'f' && ext != 's' && ext != 'a')
79599 sprint_symbol(sym, value);
79600 else
79601 sprint_symbol_no_offset(sym, value);
79602@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
79603 return number(buf, end, *(const netdev_features_t *)addr, spec);
79604 }
79605
79606+#ifdef CONFIG_GRKERNSEC_HIDESYM
79607+int kptr_restrict __read_mostly = 2;
79608+#else
79609 int kptr_restrict __read_mostly;
79610+#endif
79611
79612 /*
79613 * Show a '%p' thing. A kernel extension is that the '%p' is followed
79614@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
79615 * - 'S' For symbolic direct pointers with offset
79616 * - 's' For symbolic direct pointers without offset
79617 * - 'B' For backtraced symbolic direct pointers with offset
79618+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
79619+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
79620 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
79621 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
79622 * - 'M' For a 6-byte MAC address, it prints the address in the
79623@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79624
79625 if (!ptr && *fmt != 'K') {
79626 /*
79627- * Print (null) with the same width as a pointer so it makes
79628+ * Print (nil) with the same width as a pointer so it makes
79629 * tabular output look nice.
79630 */
79631 if (spec.field_width == -1)
79632 spec.field_width = default_width;
79633- return string(buf, end, "(null)", spec);
79634+ return string(buf, end, "(nil)", spec);
79635 }
79636
79637 switch (*fmt) {
79638@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79639 /* Fallthrough */
79640 case 'S':
79641 case 's':
79642+#ifdef CONFIG_GRKERNSEC_HIDESYM
79643+ break;
79644+#else
79645+ return symbol_string(buf, end, ptr, spec, *fmt);
79646+#endif
79647+ case 'A':
79648+ case 'a':
79649 case 'B':
79650 return symbol_string(buf, end, ptr, spec, *fmt);
79651 case 'R':
79652@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79653 va_end(va);
79654 return buf;
79655 }
79656+ case 'P':
79657+ break;
79658 case 'K':
79659 /*
79660 * %pK cannot be used in IRQ context because its test
79661@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79662 }
79663 break;
79664 }
79665+
79666+#ifdef CONFIG_GRKERNSEC_HIDESYM
79667+ /* 'P' = approved pointers to copy to userland,
79668+ as in the /proc/kallsyms case, as we make it display nothing
79669+ for non-root users, and the real contents for root users
79670+ Also ignore 'K' pointers, since we force their NULLing for non-root users
79671+ above
79672+ */
79673+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
79674+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
79675+ dump_stack();
79676+ ptr = NULL;
79677+ }
79678+#endif
79679+
79680 spec.flags |= SMALL;
79681 if (spec.field_width == -1) {
79682 spec.field_width = default_width;
79683@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79684 typeof(type) value; \
79685 if (sizeof(type) == 8) { \
79686 args = PTR_ALIGN(args, sizeof(u32)); \
79687- *(u32 *)&value = *(u32 *)args; \
79688- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
79689+ *(u32 *)&value = *(const u32 *)args; \
79690+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
79691 } else { \
79692 args = PTR_ALIGN(args, sizeof(type)); \
79693- value = *(typeof(type) *)args; \
79694+ value = *(const typeof(type) *)args; \
79695 } \
79696 args += sizeof(type); \
79697 value; \
79698@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79699 case FORMAT_TYPE_STR: {
79700 const char *str_arg = args;
79701 args += strlen(str_arg) + 1;
79702- str = string(str, end, (char *)str_arg, spec);
79703+ str = string(str, end, str_arg, spec);
79704 break;
79705 }
79706
79707diff --git a/localversion-grsec b/localversion-grsec
79708new file mode 100644
79709index 0000000..7cd6065
79710--- /dev/null
79711+++ b/localversion-grsec
79712@@ -0,0 +1 @@
79713+-grsec
79714diff --git a/mm/Kconfig b/mm/Kconfig
79715index 278e3ab..87c384d 100644
79716--- a/mm/Kconfig
79717+++ b/mm/Kconfig
79718@@ -286,10 +286,10 @@ config KSM
79719 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
79720
79721 config DEFAULT_MMAP_MIN_ADDR
79722- int "Low address space to protect from user allocation"
79723+ int "Low address space to protect from user allocation"
79724 depends on MMU
79725- default 4096
79726- help
79727+ default 65536
79728+ help
79729 This is the portion of low virtual memory which should be protected
79730 from userspace allocation. Keeping a user from writing to low pages
79731 can help reduce the impact of kernel NULL pointer bugs.
79732@@ -320,7 +320,7 @@ config MEMORY_FAILURE
79733
79734 config HWPOISON_INJECT
79735 tristate "HWPoison pages injector"
79736- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
79737+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
79738 select PROC_PAGE_MONITOR
79739
79740 config NOMMU_INITIAL_TRIM_EXCESS
79741diff --git a/mm/filemap.c b/mm/filemap.c
79742index 83efee7..3f99381 100644
79743--- a/mm/filemap.c
79744+++ b/mm/filemap.c
79745@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
79746 struct address_space *mapping = file->f_mapping;
79747
79748 if (!mapping->a_ops->readpage)
79749- return -ENOEXEC;
79750+ return -ENODEV;
79751 file_accessed(file);
79752 vma->vm_ops = &generic_file_vm_ops;
79753 return 0;
79754@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
79755 *pos = i_size_read(inode);
79756
79757 if (limit != RLIM_INFINITY) {
79758+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
79759 if (*pos >= limit) {
79760 send_sig(SIGXFSZ, current, 0);
79761 return -EFBIG;
79762diff --git a/mm/fremap.c b/mm/fremap.c
79763index a0aaf0e..20325c3 100644
79764--- a/mm/fremap.c
79765+++ b/mm/fremap.c
79766@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
79767 retry:
79768 vma = find_vma(mm, start);
79769
79770+#ifdef CONFIG_PAX_SEGMEXEC
79771+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
79772+ goto out;
79773+#endif
79774+
79775 /*
79776 * Make sure the vma is shared, that it supports prefaulting,
79777 * and that the remapped range is valid and fully within
79778diff --git a/mm/highmem.c b/mm/highmem.c
79779index b32b70c..e512eb0 100644
79780--- a/mm/highmem.c
79781+++ b/mm/highmem.c
79782@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
79783 * So no dangers, even with speculative execution.
79784 */
79785 page = pte_page(pkmap_page_table[i]);
79786+ pax_open_kernel();
79787 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
79788-
79789+ pax_close_kernel();
79790 set_page_address(page, NULL);
79791 need_flush = 1;
79792 }
79793@@ -198,9 +199,11 @@ start:
79794 }
79795 }
79796 vaddr = PKMAP_ADDR(last_pkmap_nr);
79797+
79798+ pax_open_kernel();
79799 set_pte_at(&init_mm, vaddr,
79800 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
79801-
79802+ pax_close_kernel();
79803 pkmap_count[last_pkmap_nr] = 1;
79804 set_page_address(page, (void *)vaddr);
79805
79806diff --git a/mm/hugetlb.c b/mm/hugetlb.c
79807index 546db81..34830af 100644
79808--- a/mm/hugetlb.c
79809+++ b/mm/hugetlb.c
79810@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
79811 struct hstate *h = &default_hstate;
79812 unsigned long tmp;
79813 int ret;
79814+ ctl_table_no_const hugetlb_table;
79815
79816 tmp = h->max_huge_pages;
79817
79818 if (write && h->order >= MAX_ORDER)
79819 return -EINVAL;
79820
79821- table->data = &tmp;
79822- table->maxlen = sizeof(unsigned long);
79823- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79824+ hugetlb_table = *table;
79825+ hugetlb_table.data = &tmp;
79826+ hugetlb_table.maxlen = sizeof(unsigned long);
79827+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79828 if (ret)
79829 goto out;
79830
79831@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
79832 struct hstate *h = &default_hstate;
79833 unsigned long tmp;
79834 int ret;
79835+ ctl_table_no_const hugetlb_table;
79836
79837 tmp = h->nr_overcommit_huge_pages;
79838
79839 if (write && h->order >= MAX_ORDER)
79840 return -EINVAL;
79841
79842- table->data = &tmp;
79843- table->maxlen = sizeof(unsigned long);
79844- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79845+ hugetlb_table = *table;
79846+ hugetlb_table.data = &tmp;
79847+ hugetlb_table.maxlen = sizeof(unsigned long);
79848+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79849 if (ret)
79850 goto out;
79851
79852@@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
79853 return 1;
79854 }
79855
79856+#ifdef CONFIG_PAX_SEGMEXEC
79857+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
79858+{
79859+ struct mm_struct *mm = vma->vm_mm;
79860+ struct vm_area_struct *vma_m;
79861+ unsigned long address_m;
79862+ pte_t *ptep_m;
79863+
79864+ vma_m = pax_find_mirror_vma(vma);
79865+ if (!vma_m)
79866+ return;
79867+
79868+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79869+ address_m = address + SEGMEXEC_TASK_SIZE;
79870+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
79871+ get_page(page_m);
79872+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
79873+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
79874+}
79875+#endif
79876+
79877 /*
79878 * Hugetlb_cow() should be called with page lock of the original hugepage held.
79879 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
79880@@ -2629,6 +2654,11 @@ retry_avoidcopy:
79881 make_huge_pte(vma, new_page, 1));
79882 page_remove_rmap(old_page);
79883 hugepage_add_new_anon_rmap(new_page, vma, address);
79884+
79885+#ifdef CONFIG_PAX_SEGMEXEC
79886+ pax_mirror_huge_pte(vma, address, new_page);
79887+#endif
79888+
79889 /* Make the old page be freed below */
79890 new_page = old_page;
79891 }
79892@@ -2788,6 +2818,10 @@ retry:
79893 && (vma->vm_flags & VM_SHARED)));
79894 set_huge_pte_at(mm, address, ptep, new_pte);
79895
79896+#ifdef CONFIG_PAX_SEGMEXEC
79897+ pax_mirror_huge_pte(vma, address, page);
79898+#endif
79899+
79900 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
79901 /* Optimization, do the COW without a second fault */
79902 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
79903@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79904 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
79905 struct hstate *h = hstate_vma(vma);
79906
79907+#ifdef CONFIG_PAX_SEGMEXEC
79908+ struct vm_area_struct *vma_m;
79909+#endif
79910+
79911 address &= huge_page_mask(h);
79912
79913 ptep = huge_pte_offset(mm, address);
79914@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79915 VM_FAULT_SET_HINDEX(hstate_index(h));
79916 }
79917
79918+#ifdef CONFIG_PAX_SEGMEXEC
79919+ vma_m = pax_find_mirror_vma(vma);
79920+ if (vma_m) {
79921+ unsigned long address_m;
79922+
79923+ if (vma->vm_start > vma_m->vm_start) {
79924+ address_m = address;
79925+ address -= SEGMEXEC_TASK_SIZE;
79926+ vma = vma_m;
79927+ h = hstate_vma(vma);
79928+ } else
79929+ address_m = address + SEGMEXEC_TASK_SIZE;
79930+
79931+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
79932+ return VM_FAULT_OOM;
79933+ address_m &= HPAGE_MASK;
79934+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
79935+ }
79936+#endif
79937+
79938 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
79939 if (!ptep)
79940 return VM_FAULT_OOM;
79941diff --git a/mm/internal.h b/mm/internal.h
79942index 9ba2110..eaf0674 100644
79943--- a/mm/internal.h
79944+++ b/mm/internal.h
79945@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
79946 * in mm/page_alloc.c
79947 */
79948 extern void __free_pages_bootmem(struct page *page, unsigned int order);
79949+extern void free_compound_page(struct page *page);
79950 extern void prep_compound_page(struct page *page, unsigned long order);
79951 #ifdef CONFIG_MEMORY_FAILURE
79952 extern bool is_free_buddy_page(struct page *page);
79953diff --git a/mm/kmemleak.c b/mm/kmemleak.c
79954index 752a705..6c3102e 100644
79955--- a/mm/kmemleak.c
79956+++ b/mm/kmemleak.c
79957@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
79958
79959 for (i = 0; i < object->trace_len; i++) {
79960 void *ptr = (void *)object->trace[i];
79961- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
79962+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
79963 }
79964 }
79965
79966@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
79967 return -ENOMEM;
79968 }
79969
79970- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79971+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79972 &kmemleak_fops);
79973 if (!dentry)
79974 pr_warning("Failed to create the debugfs kmemleak file\n");
79975diff --git a/mm/maccess.c b/mm/maccess.c
79976index d53adf9..03a24bf 100644
79977--- a/mm/maccess.c
79978+++ b/mm/maccess.c
79979@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79980 set_fs(KERNEL_DS);
79981 pagefault_disable();
79982 ret = __copy_from_user_inatomic(dst,
79983- (__force const void __user *)src, size);
79984+ (const void __force_user *)src, size);
79985 pagefault_enable();
79986 set_fs(old_fs);
79987
79988@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
79989
79990 set_fs(KERNEL_DS);
79991 pagefault_disable();
79992- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
79993+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
79994 pagefault_enable();
79995 set_fs(old_fs);
79996
79997diff --git a/mm/madvise.c b/mm/madvise.c
79998index 03dfa5c..b032917 100644
79999--- a/mm/madvise.c
80000+++ b/mm/madvise.c
80001@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
80002 pgoff_t pgoff;
80003 unsigned long new_flags = vma->vm_flags;
80004
80005+#ifdef CONFIG_PAX_SEGMEXEC
80006+ struct vm_area_struct *vma_m;
80007+#endif
80008+
80009 switch (behavior) {
80010 case MADV_NORMAL:
80011 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
80012@@ -123,6 +127,13 @@ success:
80013 /*
80014 * vm_flags is protected by the mmap_sem held in write mode.
80015 */
80016+
80017+#ifdef CONFIG_PAX_SEGMEXEC
80018+ vma_m = pax_find_mirror_vma(vma);
80019+ if (vma_m)
80020+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
80021+#endif
80022+
80023 vma->vm_flags = new_flags;
80024
80025 out:
80026@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80027 struct vm_area_struct ** prev,
80028 unsigned long start, unsigned long end)
80029 {
80030+
80031+#ifdef CONFIG_PAX_SEGMEXEC
80032+ struct vm_area_struct *vma_m;
80033+#endif
80034+
80035 *prev = vma;
80036 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
80037 return -EINVAL;
80038@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80039 zap_page_range(vma, start, end - start, &details);
80040 } else
80041 zap_page_range(vma, start, end - start, NULL);
80042+
80043+#ifdef CONFIG_PAX_SEGMEXEC
80044+ vma_m = pax_find_mirror_vma(vma);
80045+ if (vma_m) {
80046+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
80047+ struct zap_details details = {
80048+ .nonlinear_vma = vma_m,
80049+ .last_index = ULONG_MAX,
80050+ };
80051+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
80052+ } else
80053+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
80054+ }
80055+#endif
80056+
80057 return 0;
80058 }
80059
80060@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
80061 if (end < start)
80062 goto out;
80063
80064+#ifdef CONFIG_PAX_SEGMEXEC
80065+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
80066+ if (end > SEGMEXEC_TASK_SIZE)
80067+ goto out;
80068+ } else
80069+#endif
80070+
80071+ if (end > TASK_SIZE)
80072+ goto out;
80073+
80074 error = 0;
80075 if (end == start)
80076 goto out;
80077diff --git a/mm/memory-failure.c b/mm/memory-failure.c
80078index c6e4dd3..1f41988 100644
80079--- a/mm/memory-failure.c
80080+++ b/mm/memory-failure.c
80081@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
80082
80083 int sysctl_memory_failure_recovery __read_mostly = 1;
80084
80085-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
80086+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
80087
80088 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
80089
80090@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
80091 pfn, t->comm, t->pid);
80092 si.si_signo = SIGBUS;
80093 si.si_errno = 0;
80094- si.si_addr = (void *)addr;
80095+ si.si_addr = (void __user *)addr;
80096 #ifdef __ARCH_SI_TRAPNO
80097 si.si_trapno = trapno;
80098 #endif
80099@@ -760,7 +760,7 @@ static struct page_state {
80100 unsigned long res;
80101 char *msg;
80102 int (*action)(struct page *p, unsigned long pfn);
80103-} error_states[] = {
80104+} __do_const error_states[] = {
80105 { reserved, reserved, "reserved kernel", me_kernel },
80106 /*
80107 * free pages are specially detected outside this table:
80108@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80109 }
80110
80111 nr_pages = 1 << compound_trans_order(hpage);
80112- atomic_long_add(nr_pages, &mce_bad_pages);
80113+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
80114
80115 /*
80116 * We need/can do nothing about count=0 pages.
80117@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80118 if (!PageHWPoison(hpage)
80119 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
80120 || (p != hpage && TestSetPageHWPoison(hpage))) {
80121- atomic_long_sub(nr_pages, &mce_bad_pages);
80122+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80123 return 0;
80124 }
80125 set_page_hwpoison_huge_page(hpage);
80126@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80127 }
80128 if (hwpoison_filter(p)) {
80129 if (TestClearPageHWPoison(p))
80130- atomic_long_sub(nr_pages, &mce_bad_pages);
80131+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80132 unlock_page(hpage);
80133 put_page(hpage);
80134 return 0;
80135@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
80136 return 0;
80137 }
80138 if (TestClearPageHWPoison(p))
80139- atomic_long_sub(nr_pages, &mce_bad_pages);
80140+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80141 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
80142 return 0;
80143 }
80144@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
80145 */
80146 if (TestClearPageHWPoison(page)) {
80147 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
80148- atomic_long_sub(nr_pages, &mce_bad_pages);
80149+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80150 freeit = 1;
80151 if (PageHuge(page))
80152 clear_page_hwpoison_huge_page(page);
80153@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
80154 }
80155 done:
80156 if (!PageHWPoison(hpage))
80157- atomic_long_add(1 << compound_trans_order(hpage),
80158+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80159 &mce_bad_pages);
80160 set_page_hwpoison_huge_page(hpage);
80161 dequeue_hwpoisoned_huge_page(hpage);
80162@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
80163 return ret;
80164
80165 done:
80166- atomic_long_add(1, &mce_bad_pages);
80167+ atomic_long_add_unchecked(1, &mce_bad_pages);
80168 SetPageHWPoison(page);
80169 /* keep elevated page count for bad page */
80170 return ret;
80171diff --git a/mm/memory.c b/mm/memory.c
80172index bb1369f..efb96b5 100644
80173--- a/mm/memory.c
80174+++ b/mm/memory.c
80175@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80176 free_pte_range(tlb, pmd, addr);
80177 } while (pmd++, addr = next, addr != end);
80178
80179+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
80180 start &= PUD_MASK;
80181 if (start < floor)
80182 return;
80183@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80184 pmd = pmd_offset(pud, start);
80185 pud_clear(pud);
80186 pmd_free_tlb(tlb, pmd, start);
80187+#endif
80188+
80189 }
80190
80191 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80192@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80193 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
80194 } while (pud++, addr = next, addr != end);
80195
80196+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
80197 start &= PGDIR_MASK;
80198 if (start < floor)
80199 return;
80200@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80201 pud = pud_offset(pgd, start);
80202 pgd_clear(pgd);
80203 pud_free_tlb(tlb, pud, start);
80204+#endif
80205+
80206 }
80207
80208 /*
80209@@ -1618,12 +1624,6 @@ no_page_table:
80210 return page;
80211 }
80212
80213-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
80214-{
80215- return stack_guard_page_start(vma, addr) ||
80216- stack_guard_page_end(vma, addr+PAGE_SIZE);
80217-}
80218-
80219 /**
80220 * __get_user_pages() - pin user pages in memory
80221 * @tsk: task_struct of target task
80222@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80223
80224 i = 0;
80225
80226- do {
80227+ while (nr_pages) {
80228 struct vm_area_struct *vma;
80229
80230- vma = find_extend_vma(mm, start);
80231+ vma = find_vma(mm, start);
80232 if (!vma && in_gate_area(mm, start)) {
80233 unsigned long pg = start & PAGE_MASK;
80234 pgd_t *pgd;
80235@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80236 goto next_page;
80237 }
80238
80239- if (!vma ||
80240+ if (!vma || start < vma->vm_start ||
80241 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
80242 !(vm_flags & vma->vm_flags))
80243 return i ? : -EFAULT;
80244@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80245 int ret;
80246 unsigned int fault_flags = 0;
80247
80248- /* For mlock, just skip the stack guard page. */
80249- if (foll_flags & FOLL_MLOCK) {
80250- if (stack_guard_page(vma, start))
80251- goto next_page;
80252- }
80253 if (foll_flags & FOLL_WRITE)
80254 fault_flags |= FAULT_FLAG_WRITE;
80255 if (nonblocking)
80256@@ -1865,7 +1860,7 @@ next_page:
80257 start += PAGE_SIZE;
80258 nr_pages--;
80259 } while (nr_pages && start < vma->vm_end);
80260- } while (nr_pages);
80261+ }
80262 return i;
80263 }
80264 EXPORT_SYMBOL(__get_user_pages);
80265@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
80266 page_add_file_rmap(page);
80267 set_pte_at(mm, addr, pte, mk_pte(page, prot));
80268
80269+#ifdef CONFIG_PAX_SEGMEXEC
80270+ pax_mirror_file_pte(vma, addr, page, ptl);
80271+#endif
80272+
80273 retval = 0;
80274 pte_unmap_unlock(pte, ptl);
80275 return retval;
80276@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
80277 if (!page_count(page))
80278 return -EINVAL;
80279 if (!(vma->vm_flags & VM_MIXEDMAP)) {
80280+
80281+#ifdef CONFIG_PAX_SEGMEXEC
80282+ struct vm_area_struct *vma_m;
80283+#endif
80284+
80285 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
80286 BUG_ON(vma->vm_flags & VM_PFNMAP);
80287 vma->vm_flags |= VM_MIXEDMAP;
80288+
80289+#ifdef CONFIG_PAX_SEGMEXEC
80290+ vma_m = pax_find_mirror_vma(vma);
80291+ if (vma_m)
80292+ vma_m->vm_flags |= VM_MIXEDMAP;
80293+#endif
80294+
80295 }
80296 return insert_page(vma, addr, page, vma->vm_page_prot);
80297 }
80298@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
80299 unsigned long pfn)
80300 {
80301 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
80302+ BUG_ON(vma->vm_mirror);
80303
80304 if (addr < vma->vm_start || addr >= vma->vm_end)
80305 return -EFAULT;
80306@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
80307
80308 BUG_ON(pud_huge(*pud));
80309
80310- pmd = pmd_alloc(mm, pud, addr);
80311+ pmd = (mm == &init_mm) ?
80312+ pmd_alloc_kernel(mm, pud, addr) :
80313+ pmd_alloc(mm, pud, addr);
80314 if (!pmd)
80315 return -ENOMEM;
80316 do {
80317@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
80318 unsigned long next;
80319 int err;
80320
80321- pud = pud_alloc(mm, pgd, addr);
80322+ pud = (mm == &init_mm) ?
80323+ pud_alloc_kernel(mm, pgd, addr) :
80324+ pud_alloc(mm, pgd, addr);
80325 if (!pud)
80326 return -ENOMEM;
80327 do {
80328@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
80329 copy_user_highpage(dst, src, va, vma);
80330 }
80331
80332+#ifdef CONFIG_PAX_SEGMEXEC
80333+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
80334+{
80335+ struct mm_struct *mm = vma->vm_mm;
80336+ spinlock_t *ptl;
80337+ pte_t *pte, entry;
80338+
80339+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
80340+ entry = *pte;
80341+ if (!pte_present(entry)) {
80342+ if (!pte_none(entry)) {
80343+ BUG_ON(pte_file(entry));
80344+ free_swap_and_cache(pte_to_swp_entry(entry));
80345+ pte_clear_not_present_full(mm, address, pte, 0);
80346+ }
80347+ } else {
80348+ struct page *page;
80349+
80350+ flush_cache_page(vma, address, pte_pfn(entry));
80351+ entry = ptep_clear_flush(vma, address, pte);
80352+ BUG_ON(pte_dirty(entry));
80353+ page = vm_normal_page(vma, address, entry);
80354+ if (page) {
80355+ update_hiwater_rss(mm);
80356+ if (PageAnon(page))
80357+ dec_mm_counter_fast(mm, MM_ANONPAGES);
80358+ else
80359+ dec_mm_counter_fast(mm, MM_FILEPAGES);
80360+ page_remove_rmap(page);
80361+ page_cache_release(page);
80362+ }
80363+ }
80364+ pte_unmap_unlock(pte, ptl);
80365+}
80366+
80367+/* PaX: if vma is mirrored, synchronize the mirror's PTE
80368+ *
80369+ * the ptl of the lower mapped page is held on entry and is not released on exit
80370+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
80371+ */
80372+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80373+{
80374+ struct mm_struct *mm = vma->vm_mm;
80375+ unsigned long address_m;
80376+ spinlock_t *ptl_m;
80377+ struct vm_area_struct *vma_m;
80378+ pmd_t *pmd_m;
80379+ pte_t *pte_m, entry_m;
80380+
80381+ BUG_ON(!page_m || !PageAnon(page_m));
80382+
80383+ vma_m = pax_find_mirror_vma(vma);
80384+ if (!vma_m)
80385+ return;
80386+
80387+ BUG_ON(!PageLocked(page_m));
80388+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80389+ address_m = address + SEGMEXEC_TASK_SIZE;
80390+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80391+ pte_m = pte_offset_map(pmd_m, address_m);
80392+ ptl_m = pte_lockptr(mm, pmd_m);
80393+ if (ptl != ptl_m) {
80394+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80395+ if (!pte_none(*pte_m))
80396+ goto out;
80397+ }
80398+
80399+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80400+ page_cache_get(page_m);
80401+ page_add_anon_rmap(page_m, vma_m, address_m);
80402+ inc_mm_counter_fast(mm, MM_ANONPAGES);
80403+ set_pte_at(mm, address_m, pte_m, entry_m);
80404+ update_mmu_cache(vma_m, address_m, entry_m);
80405+out:
80406+ if (ptl != ptl_m)
80407+ spin_unlock(ptl_m);
80408+ pte_unmap(pte_m);
80409+ unlock_page(page_m);
80410+}
80411+
80412+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80413+{
80414+ struct mm_struct *mm = vma->vm_mm;
80415+ unsigned long address_m;
80416+ spinlock_t *ptl_m;
80417+ struct vm_area_struct *vma_m;
80418+ pmd_t *pmd_m;
80419+ pte_t *pte_m, entry_m;
80420+
80421+ BUG_ON(!page_m || PageAnon(page_m));
80422+
80423+ vma_m = pax_find_mirror_vma(vma);
80424+ if (!vma_m)
80425+ return;
80426+
80427+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80428+ address_m = address + SEGMEXEC_TASK_SIZE;
80429+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80430+ pte_m = pte_offset_map(pmd_m, address_m);
80431+ ptl_m = pte_lockptr(mm, pmd_m);
80432+ if (ptl != ptl_m) {
80433+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80434+ if (!pte_none(*pte_m))
80435+ goto out;
80436+ }
80437+
80438+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80439+ page_cache_get(page_m);
80440+ page_add_file_rmap(page_m);
80441+ inc_mm_counter_fast(mm, MM_FILEPAGES);
80442+ set_pte_at(mm, address_m, pte_m, entry_m);
80443+ update_mmu_cache(vma_m, address_m, entry_m);
80444+out:
80445+ if (ptl != ptl_m)
80446+ spin_unlock(ptl_m);
80447+ pte_unmap(pte_m);
80448+}
80449+
80450+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
80451+{
80452+ struct mm_struct *mm = vma->vm_mm;
80453+ unsigned long address_m;
80454+ spinlock_t *ptl_m;
80455+ struct vm_area_struct *vma_m;
80456+ pmd_t *pmd_m;
80457+ pte_t *pte_m, entry_m;
80458+
80459+ vma_m = pax_find_mirror_vma(vma);
80460+ if (!vma_m)
80461+ return;
80462+
80463+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80464+ address_m = address + SEGMEXEC_TASK_SIZE;
80465+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80466+ pte_m = pte_offset_map(pmd_m, address_m);
80467+ ptl_m = pte_lockptr(mm, pmd_m);
80468+ if (ptl != ptl_m) {
80469+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80470+ if (!pte_none(*pte_m))
80471+ goto out;
80472+ }
80473+
80474+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
80475+ set_pte_at(mm, address_m, pte_m, entry_m);
80476+out:
80477+ if (ptl != ptl_m)
80478+ spin_unlock(ptl_m);
80479+ pte_unmap(pte_m);
80480+}
80481+
80482+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
80483+{
80484+ struct page *page_m;
80485+ pte_t entry;
80486+
80487+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
80488+ goto out;
80489+
80490+ entry = *pte;
80491+ page_m = vm_normal_page(vma, address, entry);
80492+ if (!page_m)
80493+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
80494+ else if (PageAnon(page_m)) {
80495+ if (pax_find_mirror_vma(vma)) {
80496+ pte_unmap_unlock(pte, ptl);
80497+ lock_page(page_m);
80498+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
80499+ if (pte_same(entry, *pte))
80500+ pax_mirror_anon_pte(vma, address, page_m, ptl);
80501+ else
80502+ unlock_page(page_m);
80503+ }
80504+ } else
80505+ pax_mirror_file_pte(vma, address, page_m, ptl);
80506+
80507+out:
80508+ pte_unmap_unlock(pte, ptl);
80509+}
80510+#endif
80511+
80512 /*
80513 * This routine handles present pages, when users try to write
80514 * to a shared page. It is done by copying the page to a new address
80515@@ -2725,6 +2921,12 @@ gotten:
80516 */
80517 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80518 if (likely(pte_same(*page_table, orig_pte))) {
80519+
80520+#ifdef CONFIG_PAX_SEGMEXEC
80521+ if (pax_find_mirror_vma(vma))
80522+ BUG_ON(!trylock_page(new_page));
80523+#endif
80524+
80525 if (old_page) {
80526 if (!PageAnon(old_page)) {
80527 dec_mm_counter_fast(mm, MM_FILEPAGES);
80528@@ -2776,6 +2978,10 @@ gotten:
80529 page_remove_rmap(old_page);
80530 }
80531
80532+#ifdef CONFIG_PAX_SEGMEXEC
80533+ pax_mirror_anon_pte(vma, address, new_page, ptl);
80534+#endif
80535+
80536 /* Free the old page.. */
80537 new_page = old_page;
80538 ret |= VM_FAULT_WRITE;
80539@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80540 swap_free(entry);
80541 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
80542 try_to_free_swap(page);
80543+
80544+#ifdef CONFIG_PAX_SEGMEXEC
80545+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
80546+#endif
80547+
80548 unlock_page(page);
80549 if (swapcache) {
80550 /*
80551@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80552
80553 /* No need to invalidate - it was non-present before */
80554 update_mmu_cache(vma, address, page_table);
80555+
80556+#ifdef CONFIG_PAX_SEGMEXEC
80557+ pax_mirror_anon_pte(vma, address, page, ptl);
80558+#endif
80559+
80560 unlock:
80561 pte_unmap_unlock(page_table, ptl);
80562 out:
80563@@ -3093,40 +3309,6 @@ out_release:
80564 }
80565
80566 /*
80567- * This is like a special single-page "expand_{down|up}wards()",
80568- * except we must first make sure that 'address{-|+}PAGE_SIZE'
80569- * doesn't hit another vma.
80570- */
80571-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
80572-{
80573- address &= PAGE_MASK;
80574- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
80575- struct vm_area_struct *prev = vma->vm_prev;
80576-
80577- /*
80578- * Is there a mapping abutting this one below?
80579- *
80580- * That's only ok if it's the same stack mapping
80581- * that has gotten split..
80582- */
80583- if (prev && prev->vm_end == address)
80584- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
80585-
80586- expand_downwards(vma, address - PAGE_SIZE);
80587- }
80588- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
80589- struct vm_area_struct *next = vma->vm_next;
80590-
80591- /* As VM_GROWSDOWN but s/below/above/ */
80592- if (next && next->vm_start == address + PAGE_SIZE)
80593- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
80594-
80595- expand_upwards(vma, address + PAGE_SIZE);
80596- }
80597- return 0;
80598-}
80599-
80600-/*
80601 * We enter with non-exclusive mmap_sem (to exclude vma changes,
80602 * but allow concurrent faults), and pte mapped but not yet locked.
80603 * We return with mmap_sem still held, but pte unmapped and unlocked.
80604@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80605 unsigned long address, pte_t *page_table, pmd_t *pmd,
80606 unsigned int flags)
80607 {
80608- struct page *page;
80609+ struct page *page = NULL;
80610 spinlock_t *ptl;
80611 pte_t entry;
80612
80613- pte_unmap(page_table);
80614-
80615- /* Check if we need to add a guard page to the stack */
80616- if (check_stack_guard_page(vma, address) < 0)
80617- return VM_FAULT_SIGBUS;
80618-
80619- /* Use the zero-page for reads */
80620 if (!(flags & FAULT_FLAG_WRITE)) {
80621 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
80622 vma->vm_page_prot));
80623- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80624+ ptl = pte_lockptr(mm, pmd);
80625+ spin_lock(ptl);
80626 if (!pte_none(*page_table))
80627 goto unlock;
80628 goto setpte;
80629 }
80630
80631 /* Allocate our own private page. */
80632+ pte_unmap(page_table);
80633+
80634 if (unlikely(anon_vma_prepare(vma)))
80635 goto oom;
80636 page = alloc_zeroed_user_highpage_movable(vma, address);
80637@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80638 if (!pte_none(*page_table))
80639 goto release;
80640
80641+#ifdef CONFIG_PAX_SEGMEXEC
80642+ if (pax_find_mirror_vma(vma))
80643+ BUG_ON(!trylock_page(page));
80644+#endif
80645+
80646 inc_mm_counter_fast(mm, MM_ANONPAGES);
80647 page_add_new_anon_rmap(page, vma, address);
80648 setpte:
80649@@ -3181,6 +3364,12 @@ setpte:
80650
80651 /* No need to invalidate - it was non-present before */
80652 update_mmu_cache(vma, address, page_table);
80653+
80654+#ifdef CONFIG_PAX_SEGMEXEC
80655+ if (page)
80656+ pax_mirror_anon_pte(vma, address, page, ptl);
80657+#endif
80658+
80659 unlock:
80660 pte_unmap_unlock(page_table, ptl);
80661 return 0;
80662@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80663 */
80664 /* Only go through if we didn't race with anybody else... */
80665 if (likely(pte_same(*page_table, orig_pte))) {
80666+
80667+#ifdef CONFIG_PAX_SEGMEXEC
80668+ if (anon && pax_find_mirror_vma(vma))
80669+ BUG_ON(!trylock_page(page));
80670+#endif
80671+
80672 flush_icache_page(vma, page);
80673 entry = mk_pte(page, vma->vm_page_prot);
80674 if (flags & FAULT_FLAG_WRITE)
80675@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80676
80677 /* no need to invalidate: a not-present page won't be cached */
80678 update_mmu_cache(vma, address, page_table);
80679+
80680+#ifdef CONFIG_PAX_SEGMEXEC
80681+ if (anon)
80682+ pax_mirror_anon_pte(vma, address, page, ptl);
80683+ else
80684+ pax_mirror_file_pte(vma, address, page, ptl);
80685+#endif
80686+
80687 } else {
80688 if (cow_page)
80689 mem_cgroup_uncharge_page(cow_page);
80690@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
80691 if (flags & FAULT_FLAG_WRITE)
80692 flush_tlb_fix_spurious_fault(vma, address);
80693 }
80694+
80695+#ifdef CONFIG_PAX_SEGMEXEC
80696+ pax_mirror_pte(vma, address, pte, pmd, ptl);
80697+ return 0;
80698+#endif
80699+
80700 unlock:
80701 pte_unmap_unlock(pte, ptl);
80702 return 0;
80703@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80704 pmd_t *pmd;
80705 pte_t *pte;
80706
80707+#ifdef CONFIG_PAX_SEGMEXEC
80708+ struct vm_area_struct *vma_m;
80709+#endif
80710+
80711 __set_current_state(TASK_RUNNING);
80712
80713 count_vm_event(PGFAULT);
80714@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80715 if (unlikely(is_vm_hugetlb_page(vma)))
80716 return hugetlb_fault(mm, vma, address, flags);
80717
80718+#ifdef CONFIG_PAX_SEGMEXEC
80719+ vma_m = pax_find_mirror_vma(vma);
80720+ if (vma_m) {
80721+ unsigned long address_m;
80722+ pgd_t *pgd_m;
80723+ pud_t *pud_m;
80724+ pmd_t *pmd_m;
80725+
80726+ if (vma->vm_start > vma_m->vm_start) {
80727+ address_m = address;
80728+ address -= SEGMEXEC_TASK_SIZE;
80729+ vma = vma_m;
80730+ } else
80731+ address_m = address + SEGMEXEC_TASK_SIZE;
80732+
80733+ pgd_m = pgd_offset(mm, address_m);
80734+ pud_m = pud_alloc(mm, pgd_m, address_m);
80735+ if (!pud_m)
80736+ return VM_FAULT_OOM;
80737+ pmd_m = pmd_alloc(mm, pud_m, address_m);
80738+ if (!pmd_m)
80739+ return VM_FAULT_OOM;
80740+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
80741+ return VM_FAULT_OOM;
80742+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
80743+ }
80744+#endif
80745+
80746 retry:
80747 pgd = pgd_offset(mm, address);
80748 pud = pud_alloc(mm, pgd, address);
80749@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80750 spin_unlock(&mm->page_table_lock);
80751 return 0;
80752 }
80753+
80754+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80755+{
80756+ pud_t *new = pud_alloc_one(mm, address);
80757+ if (!new)
80758+ return -ENOMEM;
80759+
80760+ smp_wmb(); /* See comment in __pte_alloc */
80761+
80762+ spin_lock(&mm->page_table_lock);
80763+ if (pgd_present(*pgd)) /* Another has populated it */
80764+ pud_free(mm, new);
80765+ else
80766+ pgd_populate_kernel(mm, pgd, new);
80767+ spin_unlock(&mm->page_table_lock);
80768+ return 0;
80769+}
80770 #endif /* __PAGETABLE_PUD_FOLDED */
80771
80772 #ifndef __PAGETABLE_PMD_FOLDED
80773@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80774 spin_unlock(&mm->page_table_lock);
80775 return 0;
80776 }
80777+
80778+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80779+{
80780+ pmd_t *new = pmd_alloc_one(mm, address);
80781+ if (!new)
80782+ return -ENOMEM;
80783+
80784+ smp_wmb(); /* See comment in __pte_alloc */
80785+
80786+ spin_lock(&mm->page_table_lock);
80787+#ifndef __ARCH_HAS_4LEVEL_HACK
80788+ if (pud_present(*pud)) /* Another has populated it */
80789+ pmd_free(mm, new);
80790+ else
80791+ pud_populate_kernel(mm, pud, new);
80792+#else
80793+ if (pgd_present(*pud)) /* Another has populated it */
80794+ pmd_free(mm, new);
80795+ else
80796+ pgd_populate_kernel(mm, pud, new);
80797+#endif /* __ARCH_HAS_4LEVEL_HACK */
80798+ spin_unlock(&mm->page_table_lock);
80799+ return 0;
80800+}
80801 #endif /* __PAGETABLE_PMD_FOLDED */
80802
80803 int make_pages_present(unsigned long addr, unsigned long end)
80804@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
80805 gate_vma.vm_start = FIXADDR_USER_START;
80806 gate_vma.vm_end = FIXADDR_USER_END;
80807 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
80808- gate_vma.vm_page_prot = __P101;
80809+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
80810
80811 return 0;
80812 }
80813diff --git a/mm/mempolicy.c b/mm/mempolicy.c
80814index 3df6d12..a11056a 100644
80815--- a/mm/mempolicy.c
80816+++ b/mm/mempolicy.c
80817@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80818 unsigned long vmstart;
80819 unsigned long vmend;
80820
80821+#ifdef CONFIG_PAX_SEGMEXEC
80822+ struct vm_area_struct *vma_m;
80823+#endif
80824+
80825 vma = find_vma(mm, start);
80826 if (!vma || vma->vm_start > start)
80827 return -EFAULT;
80828@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80829 if (err)
80830 goto out;
80831 }
80832+
80833 err = vma_replace_policy(vma, new_pol);
80834 if (err)
80835 goto out;
80836+
80837+#ifdef CONFIG_PAX_SEGMEXEC
80838+ vma_m = pax_find_mirror_vma(vma);
80839+ if (vma_m) {
80840+ err = vma_replace_policy(vma_m, new_pol);
80841+ if (err)
80842+ goto out;
80843+ }
80844+#endif
80845+
80846 }
80847
80848 out:
80849@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
80850
80851 if (end < start)
80852 return -EINVAL;
80853+
80854+#ifdef CONFIG_PAX_SEGMEXEC
80855+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80856+ if (end > SEGMEXEC_TASK_SIZE)
80857+ return -EINVAL;
80858+ } else
80859+#endif
80860+
80861+ if (end > TASK_SIZE)
80862+ return -EINVAL;
80863+
80864 if (end == start)
80865 return 0;
80866
80867@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80868 */
80869 tcred = __task_cred(task);
80870 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80871- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80872- !capable(CAP_SYS_NICE)) {
80873+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80874 rcu_read_unlock();
80875 err = -EPERM;
80876 goto out_put;
80877@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80878 goto out;
80879 }
80880
80881+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80882+ if (mm != current->mm &&
80883+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
80884+ mmput(mm);
80885+ err = -EPERM;
80886+ goto out;
80887+ }
80888+#endif
80889+
80890 err = do_migrate_pages(mm, old, new,
80891 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
80892
80893diff --git a/mm/migrate.c b/mm/migrate.c
80894index 2fd8b4a..d70358f 100644
80895--- a/mm/migrate.c
80896+++ b/mm/migrate.c
80897@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
80898 */
80899 tcred = __task_cred(task);
80900 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80901- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80902- !capable(CAP_SYS_NICE)) {
80903+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80904 rcu_read_unlock();
80905 err = -EPERM;
80906 goto out;
80907diff --git a/mm/mlock.c b/mm/mlock.c
80908index c9bd528..da8d069 100644
80909--- a/mm/mlock.c
80910+++ b/mm/mlock.c
80911@@ -13,6 +13,7 @@
80912 #include <linux/pagemap.h>
80913 #include <linux/mempolicy.h>
80914 #include <linux/syscalls.h>
80915+#include <linux/security.h>
80916 #include <linux/sched.h>
80917 #include <linux/export.h>
80918 #include <linux/rmap.h>
80919@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
80920 {
80921 unsigned long nstart, end, tmp;
80922 struct vm_area_struct * vma, * prev;
80923- int error;
80924+ int error = 0;
80925
80926 VM_BUG_ON(start & ~PAGE_MASK);
80927 VM_BUG_ON(len != PAGE_ALIGN(len));
80928@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
80929 return -EINVAL;
80930 if (end == start)
80931 return 0;
80932+ if (end > TASK_SIZE)
80933+ return -EINVAL;
80934+
80935 vma = find_vma(current->mm, start);
80936 if (!vma || vma->vm_start > start)
80937 return -ENOMEM;
80938@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
80939 for (nstart = start ; ; ) {
80940 vm_flags_t newflags;
80941
80942+#ifdef CONFIG_PAX_SEGMEXEC
80943+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80944+ break;
80945+#endif
80946+
80947 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
80948
80949 newflags = vma->vm_flags | VM_LOCKED;
80950@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
80951 lock_limit >>= PAGE_SHIFT;
80952
80953 /* check against resource limits */
80954+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
80955 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
80956 error = do_mlock(start, len, 1);
80957 up_write(&current->mm->mmap_sem);
80958@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
80959 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
80960 vm_flags_t newflags;
80961
80962+#ifdef CONFIG_PAX_SEGMEXEC
80963+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80964+ break;
80965+#endif
80966+
80967+ BUG_ON(vma->vm_end > TASK_SIZE);
80968 newflags = vma->vm_flags | VM_LOCKED;
80969 if (!(flags & MCL_CURRENT))
80970 newflags &= ~VM_LOCKED;
80971@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80972 lock_limit >>= PAGE_SHIFT;
80973
80974 ret = -ENOMEM;
80975+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80976 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80977 capable(CAP_IPC_LOCK))
80978 ret = do_mlockall(flags);
80979diff --git a/mm/mmap.c b/mm/mmap.c
80980index 8832b87..20500c1 100644
80981--- a/mm/mmap.c
80982+++ b/mm/mmap.c
80983@@ -32,6 +32,7 @@
80984 #include <linux/khugepaged.h>
80985 #include <linux/uprobes.h>
80986 #include <linux/rbtree_augmented.h>
80987+#include <linux/random.h>
80988
80989 #include <asm/uaccess.h>
80990 #include <asm/cacheflush.h>
80991@@ -48,6 +49,16 @@
80992 #define arch_rebalance_pgtables(addr, len) (addr)
80993 #endif
80994
80995+static inline void verify_mm_writelocked(struct mm_struct *mm)
80996+{
80997+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
80998+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80999+ up_read(&mm->mmap_sem);
81000+ BUG();
81001+ }
81002+#endif
81003+}
81004+
81005 static void unmap_region(struct mm_struct *mm,
81006 struct vm_area_struct *vma, struct vm_area_struct *prev,
81007 unsigned long start, unsigned long end);
81008@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
81009 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
81010 *
81011 */
81012-pgprot_t protection_map[16] = {
81013+pgprot_t protection_map[16] __read_only = {
81014 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
81015 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
81016 };
81017
81018-pgprot_t vm_get_page_prot(unsigned long vm_flags)
81019+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
81020 {
81021- return __pgprot(pgprot_val(protection_map[vm_flags &
81022+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
81023 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
81024 pgprot_val(arch_vm_get_page_prot(vm_flags)));
81025+
81026+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81027+ if (!(__supported_pte_mask & _PAGE_NX) &&
81028+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
81029+ (vm_flags & (VM_READ | VM_WRITE)))
81030+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
81031+#endif
81032+
81033+ return prot;
81034 }
81035 EXPORT_SYMBOL(vm_get_page_prot);
81036
81037 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
81038 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
81039 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
81040+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
81041 /*
81042 * Make sure vm_committed_as in one cacheline and not cacheline shared with
81043 * other variables. It can be updated by several CPUs frequently.
81044@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
81045 struct vm_area_struct *next = vma->vm_next;
81046
81047 might_sleep();
81048+ BUG_ON(vma->vm_mirror);
81049 if (vma->vm_ops && vma->vm_ops->close)
81050 vma->vm_ops->close(vma);
81051 if (vma->vm_file)
81052@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
81053 * not page aligned -Ram Gupta
81054 */
81055 rlim = rlimit(RLIMIT_DATA);
81056+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
81057 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
81058 (mm->end_data - mm->start_data) > rlim)
81059 goto out;
81060@@ -888,6 +911,12 @@ static int
81061 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
81062 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81063 {
81064+
81065+#ifdef CONFIG_PAX_SEGMEXEC
81066+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
81067+ return 0;
81068+#endif
81069+
81070 if (is_mergeable_vma(vma, file, vm_flags) &&
81071 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81072 if (vma->vm_pgoff == vm_pgoff)
81073@@ -907,6 +936,12 @@ static int
81074 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81075 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81076 {
81077+
81078+#ifdef CONFIG_PAX_SEGMEXEC
81079+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
81080+ return 0;
81081+#endif
81082+
81083 if (is_mergeable_vma(vma, file, vm_flags) &&
81084 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81085 pgoff_t vm_pglen;
81086@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81087 struct vm_area_struct *vma_merge(struct mm_struct *mm,
81088 struct vm_area_struct *prev, unsigned long addr,
81089 unsigned long end, unsigned long vm_flags,
81090- struct anon_vma *anon_vma, struct file *file,
81091+ struct anon_vma *anon_vma, struct file *file,
81092 pgoff_t pgoff, struct mempolicy *policy)
81093 {
81094 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
81095 struct vm_area_struct *area, *next;
81096 int err;
81097
81098+#ifdef CONFIG_PAX_SEGMEXEC
81099+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
81100+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
81101+
81102+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
81103+#endif
81104+
81105 /*
81106 * We later require that vma->vm_flags == vm_flags,
81107 * so this tests vma->vm_flags & VM_SPECIAL, too.
81108@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81109 if (next && next->vm_end == end) /* cases 6, 7, 8 */
81110 next = next->vm_next;
81111
81112+#ifdef CONFIG_PAX_SEGMEXEC
81113+ if (prev)
81114+ prev_m = pax_find_mirror_vma(prev);
81115+ if (area)
81116+ area_m = pax_find_mirror_vma(area);
81117+ if (next)
81118+ next_m = pax_find_mirror_vma(next);
81119+#endif
81120+
81121 /*
81122 * Can it merge with the predecessor?
81123 */
81124@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81125 /* cases 1, 6 */
81126 err = vma_adjust(prev, prev->vm_start,
81127 next->vm_end, prev->vm_pgoff, NULL);
81128- } else /* cases 2, 5, 7 */
81129+
81130+#ifdef CONFIG_PAX_SEGMEXEC
81131+ if (!err && prev_m)
81132+ err = vma_adjust(prev_m, prev_m->vm_start,
81133+ next_m->vm_end, prev_m->vm_pgoff, NULL);
81134+#endif
81135+
81136+ } else { /* cases 2, 5, 7 */
81137 err = vma_adjust(prev, prev->vm_start,
81138 end, prev->vm_pgoff, NULL);
81139+
81140+#ifdef CONFIG_PAX_SEGMEXEC
81141+ if (!err && prev_m)
81142+ err = vma_adjust(prev_m, prev_m->vm_start,
81143+ end_m, prev_m->vm_pgoff, NULL);
81144+#endif
81145+
81146+ }
81147 if (err)
81148 return NULL;
81149 khugepaged_enter_vma_merge(prev);
81150@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81151 mpol_equal(policy, vma_policy(next)) &&
81152 can_vma_merge_before(next, vm_flags,
81153 anon_vma, file, pgoff+pglen)) {
81154- if (prev && addr < prev->vm_end) /* case 4 */
81155+ if (prev && addr < prev->vm_end) { /* case 4 */
81156 err = vma_adjust(prev, prev->vm_start,
81157 addr, prev->vm_pgoff, NULL);
81158- else /* cases 3, 8 */
81159+
81160+#ifdef CONFIG_PAX_SEGMEXEC
81161+ if (!err && prev_m)
81162+ err = vma_adjust(prev_m, prev_m->vm_start,
81163+ addr_m, prev_m->vm_pgoff, NULL);
81164+#endif
81165+
81166+ } else { /* cases 3, 8 */
81167 err = vma_adjust(area, addr, next->vm_end,
81168 next->vm_pgoff - pglen, NULL);
81169+
81170+#ifdef CONFIG_PAX_SEGMEXEC
81171+ if (!err && area_m)
81172+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
81173+ next_m->vm_pgoff - pglen, NULL);
81174+#endif
81175+
81176+ }
81177 if (err)
81178 return NULL;
81179 khugepaged_enter_vma_merge(area);
81180@@ -1120,16 +1201,13 @@ none:
81181 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81182 struct file *file, long pages)
81183 {
81184- const unsigned long stack_flags
81185- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
81186-
81187 mm->total_vm += pages;
81188
81189 if (file) {
81190 mm->shared_vm += pages;
81191 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
81192 mm->exec_vm += pages;
81193- } else if (flags & stack_flags)
81194+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
81195 mm->stack_vm += pages;
81196 }
81197 #endif /* CONFIG_PROC_FS */
81198@@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81199 * (the exception is when the underlying filesystem is noexec
81200 * mounted, in which case we dont add PROT_EXEC.)
81201 */
81202- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81203+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81204 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
81205 prot |= PROT_EXEC;
81206
81207@@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81208 /* Obtain the address to map to. we verify (or select) it and ensure
81209 * that it represents a valid section of the address space.
81210 */
81211- addr = get_unmapped_area(file, addr, len, pgoff, flags);
81212+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
81213 if (addr & ~PAGE_MASK)
81214 return addr;
81215
81216@@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81217 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
81218 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
81219
81220+#ifdef CONFIG_PAX_MPROTECT
81221+ if (mm->pax_flags & MF_PAX_MPROTECT) {
81222+#ifndef CONFIG_PAX_MPROTECT_COMPAT
81223+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
81224+ gr_log_rwxmmap(file);
81225+
81226+#ifdef CONFIG_PAX_EMUPLT
81227+ vm_flags &= ~VM_EXEC;
81228+#else
81229+ return -EPERM;
81230+#endif
81231+
81232+ }
81233+
81234+ if (!(vm_flags & VM_EXEC))
81235+ vm_flags &= ~VM_MAYEXEC;
81236+#else
81237+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81238+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81239+#endif
81240+ else
81241+ vm_flags &= ~VM_MAYWRITE;
81242+ }
81243+#endif
81244+
81245+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81246+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
81247+ vm_flags &= ~VM_PAGEEXEC;
81248+#endif
81249+
81250 if (flags & MAP_LOCKED)
81251 if (!can_do_mlock())
81252 return -EPERM;
81253@@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81254 locked += mm->locked_vm;
81255 lock_limit = rlimit(RLIMIT_MEMLOCK);
81256 lock_limit >>= PAGE_SHIFT;
81257+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81258 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
81259 return -EAGAIN;
81260 }
81261@@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81262 }
81263 }
81264
81265+ if (!gr_acl_handle_mmap(file, prot))
81266+ return -EACCES;
81267+
81268 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
81269 }
81270
81271@@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
81272 vm_flags_t vm_flags = vma->vm_flags;
81273
81274 /* If it was private or non-writable, the write bit is already clear */
81275- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
81276+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
81277 return 0;
81278
81279 /* The backer wishes to know when pages are first written to? */
81280@@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
81281 unsigned long charged = 0;
81282 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
81283
81284+#ifdef CONFIG_PAX_SEGMEXEC
81285+ struct vm_area_struct *vma_m = NULL;
81286+#endif
81287+
81288+ /*
81289+ * mm->mmap_sem is required to protect against another thread
81290+ * changing the mappings in case we sleep.
81291+ */
81292+ verify_mm_writelocked(mm);
81293+
81294 /* Clear old maps */
81295 error = -ENOMEM;
81296-munmap_back:
81297 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81298 if (do_munmap(mm, addr, len))
81299 return -ENOMEM;
81300- goto munmap_back;
81301+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81302 }
81303
81304 /* Check against address space limit. */
81305@@ -1460,6 +1581,16 @@ munmap_back:
81306 goto unacct_error;
81307 }
81308
81309+#ifdef CONFIG_PAX_SEGMEXEC
81310+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
81311+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81312+ if (!vma_m) {
81313+ error = -ENOMEM;
81314+ goto free_vma;
81315+ }
81316+ }
81317+#endif
81318+
81319 vma->vm_mm = mm;
81320 vma->vm_start = addr;
81321 vma->vm_end = addr + len;
81322@@ -1484,6 +1615,13 @@ munmap_back:
81323 if (error)
81324 goto unmap_and_free_vma;
81325
81326+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81327+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
81328+ vma->vm_flags |= VM_PAGEEXEC;
81329+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81330+ }
81331+#endif
81332+
81333 /* Can addr have changed??
81334 *
81335 * Answer: Yes, several device drivers can do it in their
81336@@ -1522,6 +1660,11 @@ munmap_back:
81337 vma_link(mm, vma, prev, rb_link, rb_parent);
81338 file = vma->vm_file;
81339
81340+#ifdef CONFIG_PAX_SEGMEXEC
81341+ if (vma_m)
81342+ BUG_ON(pax_mirror_vma(vma_m, vma));
81343+#endif
81344+
81345 /* Once vma denies write, undo our temporary denial count */
81346 if (correct_wcount)
81347 atomic_inc(&inode->i_writecount);
81348@@ -1529,6 +1672,7 @@ out:
81349 perf_event_mmap(vma);
81350
81351 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
81352+ track_exec_limit(mm, addr, addr + len, vm_flags);
81353 if (vm_flags & VM_LOCKED) {
81354 if (!mlock_vma_pages_range(vma, addr, addr + len))
81355 mm->locked_vm += (len >> PAGE_SHIFT);
81356@@ -1550,6 +1694,12 @@ unmap_and_free_vma:
81357 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
81358 charged = 0;
81359 free_vma:
81360+
81361+#ifdef CONFIG_PAX_SEGMEXEC
81362+ if (vma_m)
81363+ kmem_cache_free(vm_area_cachep, vma_m);
81364+#endif
81365+
81366 kmem_cache_free(vm_area_cachep, vma);
81367 unacct_error:
81368 if (charged)
81369@@ -1557,6 +1707,62 @@ unacct_error:
81370 return error;
81371 }
81372
81373+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81374+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81375+{
81376+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
81377+ return (random32() & 0xFF) << PAGE_SHIFT;
81378+
81379+ return 0;
81380+}
81381+#endif
81382+
81383+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
81384+{
81385+ if (!vma) {
81386+#ifdef CONFIG_STACK_GROWSUP
81387+ if (addr > sysctl_heap_stack_gap)
81388+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
81389+ else
81390+ vma = find_vma(current->mm, 0);
81391+ if (vma && (vma->vm_flags & VM_GROWSUP))
81392+ return false;
81393+#endif
81394+ return true;
81395+ }
81396+
81397+ if (addr + len > vma->vm_start)
81398+ return false;
81399+
81400+ if (vma->vm_flags & VM_GROWSDOWN)
81401+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
81402+#ifdef CONFIG_STACK_GROWSUP
81403+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
81404+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
81405+#endif
81406+ else if (offset)
81407+ return offset <= vma->vm_start - addr - len;
81408+
81409+ return true;
81410+}
81411+
81412+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
81413+{
81414+ if (vma->vm_start < len)
81415+ return -ENOMEM;
81416+
81417+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
81418+ if (offset <= vma->vm_start - len)
81419+ return vma->vm_start - len - offset;
81420+ else
81421+ return -ENOMEM;
81422+ }
81423+
81424+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
81425+ return vma->vm_start - len - sysctl_heap_stack_gap;
81426+ return -ENOMEM;
81427+}
81428+
81429 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
81430 {
81431 /*
81432@@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81433 struct mm_struct *mm = current->mm;
81434 struct vm_area_struct *vma;
81435 struct vm_unmapped_area_info info;
81436+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81437
81438 if (len > TASK_SIZE)
81439 return -ENOMEM;
81440@@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81441 if (flags & MAP_FIXED)
81442 return addr;
81443
81444+#ifdef CONFIG_PAX_RANDMMAP
81445+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81446+#endif
81447+
81448 if (addr) {
81449 addr = PAGE_ALIGN(addr);
81450 vma = find_vma(mm, addr);
81451- if (TASK_SIZE - len >= addr &&
81452- (!vma || addr + len <= vma->vm_start))
81453+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81454 return addr;
81455 }
81456
81457 info.flags = 0;
81458 info.length = len;
81459 info.low_limit = TASK_UNMAPPED_BASE;
81460+
81461+#ifdef CONFIG_PAX_RANDMMAP
81462+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81463+ info.low_limit += mm->delta_mmap;
81464+#endif
81465+
81466 info.high_limit = TASK_SIZE;
81467 info.align_mask = 0;
81468 return vm_unmapped_area(&info);
81469@@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81470
81471 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
81472 {
81473+
81474+#ifdef CONFIG_PAX_SEGMEXEC
81475+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81476+ return;
81477+#endif
81478+
81479 /*
81480 * Is this a new hole at the lowest possible address?
81481 */
81482- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
81483+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
81484 mm->free_area_cache = addr;
81485 }
81486
81487@@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81488 struct mm_struct *mm = current->mm;
81489 unsigned long addr = addr0;
81490 struct vm_unmapped_area_info info;
81491+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81492
81493 /* requested length too big for entire address space */
81494 if (len > TASK_SIZE)
81495@@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81496 if (flags & MAP_FIXED)
81497 return addr;
81498
81499+#ifdef CONFIG_PAX_RANDMMAP
81500+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81501+#endif
81502+
81503 /* requesting a specific address */
81504 if (addr) {
81505 addr = PAGE_ALIGN(addr);
81506 vma = find_vma(mm, addr);
81507- if (TASK_SIZE - len >= addr &&
81508- (!vma || addr + len <= vma->vm_start))
81509+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81510 return addr;
81511 }
81512
81513@@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81514 VM_BUG_ON(addr != -ENOMEM);
81515 info.flags = 0;
81516 info.low_limit = TASK_UNMAPPED_BASE;
81517+
81518+#ifdef CONFIG_PAX_RANDMMAP
81519+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81520+ info.low_limit += mm->delta_mmap;
81521+#endif
81522+
81523 info.high_limit = TASK_SIZE;
81524 addr = vm_unmapped_area(&info);
81525 }
81526@@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81527
81528 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81529 {
81530+
81531+#ifdef CONFIG_PAX_SEGMEXEC
81532+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81533+ return;
81534+#endif
81535+
81536 /*
81537 * Is this a new hole at the highest possible address?
81538 */
81539@@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81540 mm->free_area_cache = addr;
81541
81542 /* dont allow allocations above current base */
81543- if (mm->free_area_cache > mm->mmap_base)
81544+ if (mm->free_area_cache > mm->mmap_base) {
81545 mm->free_area_cache = mm->mmap_base;
81546+ mm->cached_hole_size = ~0UL;
81547+ }
81548 }
81549
81550 unsigned long
81551@@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
81552 return vma;
81553 }
81554
81555+#ifdef CONFIG_PAX_SEGMEXEC
81556+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
81557+{
81558+ struct vm_area_struct *vma_m;
81559+
81560+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
81561+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
81562+ BUG_ON(vma->vm_mirror);
81563+ return NULL;
81564+ }
81565+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
81566+ vma_m = vma->vm_mirror;
81567+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
81568+ BUG_ON(vma->vm_file != vma_m->vm_file);
81569+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
81570+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
81571+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
81572+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
81573+ return vma_m;
81574+}
81575+#endif
81576+
81577 /*
81578 * Verify that the stack growth is acceptable and
81579 * update accounting. This is shared with both the
81580@@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81581 return -ENOMEM;
81582
81583 /* Stack limit test */
81584+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
81585 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
81586 return -ENOMEM;
81587
81588@@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81589 locked = mm->locked_vm + grow;
81590 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
81591 limit >>= PAGE_SHIFT;
81592+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81593 if (locked > limit && !capable(CAP_IPC_LOCK))
81594 return -ENOMEM;
81595 }
81596@@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81597 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
81598 * vma is the last one with address > vma->vm_end. Have to extend vma.
81599 */
81600+#ifndef CONFIG_IA64
81601+static
81602+#endif
81603 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81604 {
81605 int error;
81606+ bool locknext;
81607
81608 if (!(vma->vm_flags & VM_GROWSUP))
81609 return -EFAULT;
81610
81611+ /* Also guard against wrapping around to address 0. */
81612+ if (address < PAGE_ALIGN(address+1))
81613+ address = PAGE_ALIGN(address+1);
81614+ else
81615+ return -ENOMEM;
81616+
81617 /*
81618 * We must make sure the anon_vma is allocated
81619 * so that the anon_vma locking is not a noop.
81620 */
81621 if (unlikely(anon_vma_prepare(vma)))
81622 return -ENOMEM;
81623+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
81624+ if (locknext && anon_vma_prepare(vma->vm_next))
81625+ return -ENOMEM;
81626 vma_lock_anon_vma(vma);
81627+ if (locknext)
81628+ vma_lock_anon_vma(vma->vm_next);
81629
81630 /*
81631 * vma->vm_start/vm_end cannot change under us because the caller
81632 * is required to hold the mmap_sem in read mode. We need the
81633- * anon_vma lock to serialize against concurrent expand_stacks.
81634- * Also guard against wrapping around to address 0.
81635+ * anon_vma locks to serialize against concurrent expand_stacks
81636+ * and expand_upwards.
81637 */
81638- if (address < PAGE_ALIGN(address+4))
81639- address = PAGE_ALIGN(address+4);
81640- else {
81641- vma_unlock_anon_vma(vma);
81642- return -ENOMEM;
81643- }
81644 error = 0;
81645
81646 /* Somebody else might have raced and expanded it already */
81647- if (address > vma->vm_end) {
81648+ 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)
81649+ error = -ENOMEM;
81650+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
81651 unsigned long size, grow;
81652
81653 size = address - vma->vm_start;
81654@@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81655 }
81656 }
81657 }
81658+ if (locknext)
81659+ vma_unlock_anon_vma(vma->vm_next);
81660 vma_unlock_anon_vma(vma);
81661 khugepaged_enter_vma_merge(vma);
81662 validate_mm(vma->vm_mm);
81663@@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
81664 unsigned long address)
81665 {
81666 int error;
81667+ bool lockprev = false;
81668+ struct vm_area_struct *prev;
81669
81670 /*
81671 * We must make sure the anon_vma is allocated
81672@@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
81673 if (error)
81674 return error;
81675
81676+ prev = vma->vm_prev;
81677+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
81678+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
81679+#endif
81680+ if (lockprev && anon_vma_prepare(prev))
81681+ return -ENOMEM;
81682+ if (lockprev)
81683+ vma_lock_anon_vma(prev);
81684+
81685 vma_lock_anon_vma(vma);
81686
81687 /*
81688@@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
81689 */
81690
81691 /* Somebody else might have raced and expanded it already */
81692- if (address < vma->vm_start) {
81693+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
81694+ error = -ENOMEM;
81695+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
81696 unsigned long size, grow;
81697
81698+#ifdef CONFIG_PAX_SEGMEXEC
81699+ struct vm_area_struct *vma_m;
81700+
81701+ vma_m = pax_find_mirror_vma(vma);
81702+#endif
81703+
81704 size = vma->vm_end - address;
81705 grow = (vma->vm_start - address) >> PAGE_SHIFT;
81706
81707@@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
81708 vma->vm_pgoff -= grow;
81709 anon_vma_interval_tree_post_update_vma(vma);
81710 vma_gap_update(vma);
81711+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
81712+
81713+#ifdef CONFIG_PAX_SEGMEXEC
81714+ if (vma_m) {
81715+ anon_vma_interval_tree_pre_update_vma(vma_m);
81716+ vma_m->vm_start -= grow << PAGE_SHIFT;
81717+ vma_m->vm_pgoff -= grow;
81718+ anon_vma_interval_tree_post_update_vma(vma_m);
81719+ vma_gap_update(vma_m);
81720+ }
81721+#endif
81722+
81723 spin_unlock(&vma->vm_mm->page_table_lock);
81724
81725 perf_event_mmap(vma);
81726@@ -2263,6 +2571,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
81727 do {
81728 long nrpages = vma_pages(vma);
81729
81730+#ifdef CONFIG_PAX_SEGMEXEC
81731+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
81732+ vma = remove_vma(vma);
81733+ continue;
81734+ }
81735+#endif
81736+
81737 if (vma->vm_flags & VM_ACCOUNT)
81738 nr_accounted += nrpages;
81739 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
81740@@ -2308,6 +2623,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
81741 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
81742 vma->vm_prev = NULL;
81743 do {
81744+
81745+#ifdef CONFIG_PAX_SEGMEXEC
81746+ if (vma->vm_mirror) {
81747+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
81748+ vma->vm_mirror->vm_mirror = NULL;
81749+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
81750+ vma->vm_mirror = NULL;
81751+ }
81752+#endif
81753+
81754 vma_rb_erase(vma, &mm->mm_rb);
81755 mm->map_count--;
81756 tail_vma = vma;
81757@@ -2339,14 +2664,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81758 struct vm_area_struct *new;
81759 int err = -ENOMEM;
81760
81761+#ifdef CONFIG_PAX_SEGMEXEC
81762+ struct vm_area_struct *vma_m, *new_m = NULL;
81763+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
81764+#endif
81765+
81766 if (is_vm_hugetlb_page(vma) && (addr &
81767 ~(huge_page_mask(hstate_vma(vma)))))
81768 return -EINVAL;
81769
81770+#ifdef CONFIG_PAX_SEGMEXEC
81771+ vma_m = pax_find_mirror_vma(vma);
81772+#endif
81773+
81774 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81775 if (!new)
81776 goto out_err;
81777
81778+#ifdef CONFIG_PAX_SEGMEXEC
81779+ if (vma_m) {
81780+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81781+ if (!new_m) {
81782+ kmem_cache_free(vm_area_cachep, new);
81783+ goto out_err;
81784+ }
81785+ }
81786+#endif
81787+
81788 /* most fields are the same, copy all, and then fixup */
81789 *new = *vma;
81790
81791@@ -2359,6 +2703,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81792 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
81793 }
81794
81795+#ifdef CONFIG_PAX_SEGMEXEC
81796+ if (vma_m) {
81797+ *new_m = *vma_m;
81798+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
81799+ new_m->vm_mirror = new;
81800+ new->vm_mirror = new_m;
81801+
81802+ if (new_below)
81803+ new_m->vm_end = addr_m;
81804+ else {
81805+ new_m->vm_start = addr_m;
81806+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
81807+ }
81808+ }
81809+#endif
81810+
81811 pol = mpol_dup(vma_policy(vma));
81812 if (IS_ERR(pol)) {
81813 err = PTR_ERR(pol);
81814@@ -2381,6 +2741,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81815 else
81816 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
81817
81818+#ifdef CONFIG_PAX_SEGMEXEC
81819+ if (!err && vma_m) {
81820+ if (anon_vma_clone(new_m, vma_m))
81821+ goto out_free_mpol;
81822+
81823+ mpol_get(pol);
81824+ vma_set_policy(new_m, pol);
81825+
81826+ if (new_m->vm_file)
81827+ get_file(new_m->vm_file);
81828+
81829+ if (new_m->vm_ops && new_m->vm_ops->open)
81830+ new_m->vm_ops->open(new_m);
81831+
81832+ if (new_below)
81833+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
81834+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
81835+ else
81836+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
81837+
81838+ if (err) {
81839+ if (new_m->vm_ops && new_m->vm_ops->close)
81840+ new_m->vm_ops->close(new_m);
81841+ if (new_m->vm_file)
81842+ fput(new_m->vm_file);
81843+ mpol_put(pol);
81844+ }
81845+ }
81846+#endif
81847+
81848 /* Success. */
81849 if (!err)
81850 return 0;
81851@@ -2390,10 +2780,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81852 new->vm_ops->close(new);
81853 if (new->vm_file)
81854 fput(new->vm_file);
81855- unlink_anon_vmas(new);
81856 out_free_mpol:
81857 mpol_put(pol);
81858 out_free_vma:
81859+
81860+#ifdef CONFIG_PAX_SEGMEXEC
81861+ if (new_m) {
81862+ unlink_anon_vmas(new_m);
81863+ kmem_cache_free(vm_area_cachep, new_m);
81864+ }
81865+#endif
81866+
81867+ unlink_anon_vmas(new);
81868 kmem_cache_free(vm_area_cachep, new);
81869 out_err:
81870 return err;
81871@@ -2406,6 +2804,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81872 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81873 unsigned long addr, int new_below)
81874 {
81875+
81876+#ifdef CONFIG_PAX_SEGMEXEC
81877+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81878+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
81879+ if (mm->map_count >= sysctl_max_map_count-1)
81880+ return -ENOMEM;
81881+ } else
81882+#endif
81883+
81884 if (mm->map_count >= sysctl_max_map_count)
81885 return -ENOMEM;
81886
81887@@ -2417,11 +2824,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81888 * work. This now handles partial unmappings.
81889 * Jeremy Fitzhardinge <jeremy@goop.org>
81890 */
81891+#ifdef CONFIG_PAX_SEGMEXEC
81892 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81893 {
81894+ int ret = __do_munmap(mm, start, len);
81895+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
81896+ return ret;
81897+
81898+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
81899+}
81900+
81901+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81902+#else
81903+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81904+#endif
81905+{
81906 unsigned long end;
81907 struct vm_area_struct *vma, *prev, *last;
81908
81909+ /*
81910+ * mm->mmap_sem is required to protect against another thread
81911+ * changing the mappings in case we sleep.
81912+ */
81913+ verify_mm_writelocked(mm);
81914+
81915 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
81916 return -EINVAL;
81917
81918@@ -2496,6 +2922,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81919 /* Fix up all other VM information */
81920 remove_vma_list(mm, vma);
81921
81922+ track_exec_limit(mm, start, end, 0UL);
81923+
81924 return 0;
81925 }
81926
81927@@ -2504,6 +2932,13 @@ int vm_munmap(unsigned long start, size_t len)
81928 int ret;
81929 struct mm_struct *mm = current->mm;
81930
81931+
81932+#ifdef CONFIG_PAX_SEGMEXEC
81933+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
81934+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
81935+ return -EINVAL;
81936+#endif
81937+
81938 down_write(&mm->mmap_sem);
81939 ret = do_munmap(mm, start, len);
81940 up_write(&mm->mmap_sem);
81941@@ -2517,16 +2952,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
81942 return vm_munmap(addr, len);
81943 }
81944
81945-static inline void verify_mm_writelocked(struct mm_struct *mm)
81946-{
81947-#ifdef CONFIG_DEBUG_VM
81948- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81949- WARN_ON(1);
81950- up_read(&mm->mmap_sem);
81951- }
81952-#endif
81953-}
81954-
81955 /*
81956 * this is really a simplified "do_mmap". it only handles
81957 * anonymous maps. eventually we may be able to do some
81958@@ -2540,6 +2965,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81959 struct rb_node ** rb_link, * rb_parent;
81960 pgoff_t pgoff = addr >> PAGE_SHIFT;
81961 int error;
81962+ unsigned long charged;
81963
81964 len = PAGE_ALIGN(len);
81965 if (!len)
81966@@ -2547,16 +2973,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81967
81968 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
81969
81970+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
81971+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
81972+ flags &= ~VM_EXEC;
81973+
81974+#ifdef CONFIG_PAX_MPROTECT
81975+ if (mm->pax_flags & MF_PAX_MPROTECT)
81976+ flags &= ~VM_MAYEXEC;
81977+#endif
81978+
81979+ }
81980+#endif
81981+
81982 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
81983 if (error & ~PAGE_MASK)
81984 return error;
81985
81986+ charged = len >> PAGE_SHIFT;
81987+
81988 /*
81989 * mlock MCL_FUTURE?
81990 */
81991 if (mm->def_flags & VM_LOCKED) {
81992 unsigned long locked, lock_limit;
81993- locked = len >> PAGE_SHIFT;
81994+ locked = charged;
81995 locked += mm->locked_vm;
81996 lock_limit = rlimit(RLIMIT_MEMLOCK);
81997 lock_limit >>= PAGE_SHIFT;
81998@@ -2573,21 +3013,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81999 /*
82000 * Clear old maps. this also does some error checking for us
82001 */
82002- munmap_back:
82003 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82004 if (do_munmap(mm, addr, len))
82005 return -ENOMEM;
82006- goto munmap_back;
82007+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82008 }
82009
82010 /* Check against address space limits *after* clearing old maps... */
82011- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82012+ if (!may_expand_vm(mm, charged))
82013 return -ENOMEM;
82014
82015 if (mm->map_count > sysctl_max_map_count)
82016 return -ENOMEM;
82017
82018- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
82019+ if (security_vm_enough_memory_mm(mm, charged))
82020 return -ENOMEM;
82021
82022 /* Can we just expand an old private anonymous mapping? */
82023@@ -2601,7 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82024 */
82025 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82026 if (!vma) {
82027- vm_unacct_memory(len >> PAGE_SHIFT);
82028+ vm_unacct_memory(charged);
82029 return -ENOMEM;
82030 }
82031
82032@@ -2615,11 +3054,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82033 vma_link(mm, vma, prev, rb_link, rb_parent);
82034 out:
82035 perf_event_mmap(vma);
82036- mm->total_vm += len >> PAGE_SHIFT;
82037+ mm->total_vm += charged;
82038 if (flags & VM_LOCKED) {
82039 if (!mlock_vma_pages_range(vma, addr, addr + len))
82040- mm->locked_vm += (len >> PAGE_SHIFT);
82041+ mm->locked_vm += charged;
82042 }
82043+ track_exec_limit(mm, addr, addr + len, flags);
82044 return addr;
82045 }
82046
82047@@ -2677,6 +3117,7 @@ void exit_mmap(struct mm_struct *mm)
82048 while (vma) {
82049 if (vma->vm_flags & VM_ACCOUNT)
82050 nr_accounted += vma_pages(vma);
82051+ vma->vm_mirror = NULL;
82052 vma = remove_vma(vma);
82053 }
82054 vm_unacct_memory(nr_accounted);
82055@@ -2693,6 +3134,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82056 struct vm_area_struct *prev;
82057 struct rb_node **rb_link, *rb_parent;
82058
82059+#ifdef CONFIG_PAX_SEGMEXEC
82060+ struct vm_area_struct *vma_m = NULL;
82061+#endif
82062+
82063+ if (security_mmap_addr(vma->vm_start))
82064+ return -EPERM;
82065+
82066 /*
82067 * The vm_pgoff of a purely anonymous vma should be irrelevant
82068 * until its first write fault, when page's anon_vma and index
82069@@ -2716,7 +3164,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82070 security_vm_enough_memory_mm(mm, vma_pages(vma)))
82071 return -ENOMEM;
82072
82073+#ifdef CONFIG_PAX_SEGMEXEC
82074+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
82075+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82076+ if (!vma_m)
82077+ return -ENOMEM;
82078+ }
82079+#endif
82080+
82081 vma_link(mm, vma, prev, rb_link, rb_parent);
82082+
82083+#ifdef CONFIG_PAX_SEGMEXEC
82084+ if (vma_m)
82085+ BUG_ON(pax_mirror_vma(vma_m, vma));
82086+#endif
82087+
82088 return 0;
82089 }
82090
82091@@ -2736,6 +3198,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82092 struct mempolicy *pol;
82093 bool faulted_in_anon_vma = true;
82094
82095+ BUG_ON(vma->vm_mirror);
82096+
82097 /*
82098 * If anonymous vma has not yet been faulted, update new pgoff
82099 * to match new location, to increase its chance of merging.
82100@@ -2802,6 +3266,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82101 return NULL;
82102 }
82103
82104+#ifdef CONFIG_PAX_SEGMEXEC
82105+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
82106+{
82107+ struct vm_area_struct *prev_m;
82108+ struct rb_node **rb_link_m, *rb_parent_m;
82109+ struct mempolicy *pol_m;
82110+
82111+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
82112+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
82113+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
82114+ *vma_m = *vma;
82115+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
82116+ if (anon_vma_clone(vma_m, vma))
82117+ return -ENOMEM;
82118+ pol_m = vma_policy(vma_m);
82119+ mpol_get(pol_m);
82120+ vma_set_policy(vma_m, pol_m);
82121+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
82122+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
82123+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
82124+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
82125+ if (vma_m->vm_file)
82126+ get_file(vma_m->vm_file);
82127+ if (vma_m->vm_ops && vma_m->vm_ops->open)
82128+ vma_m->vm_ops->open(vma_m);
82129+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
82130+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
82131+ vma_m->vm_mirror = vma;
82132+ vma->vm_mirror = vma_m;
82133+ return 0;
82134+}
82135+#endif
82136+
82137 /*
82138 * Return true if the calling process may expand its vm space by the passed
82139 * number of pages
82140@@ -2813,6 +3310,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
82141
82142 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
82143
82144+#ifdef CONFIG_PAX_RANDMMAP
82145+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82146+ cur -= mm->aslr_gap;
82147+#endif
82148+
82149+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
82150 if (cur + npages > lim)
82151 return 0;
82152 return 1;
82153@@ -2883,6 +3386,22 @@ int install_special_mapping(struct mm_struct *mm,
82154 vma->vm_start = addr;
82155 vma->vm_end = addr + len;
82156
82157+#ifdef CONFIG_PAX_MPROTECT
82158+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82159+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82160+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
82161+ return -EPERM;
82162+ if (!(vm_flags & VM_EXEC))
82163+ vm_flags &= ~VM_MAYEXEC;
82164+#else
82165+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82166+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82167+#endif
82168+ else
82169+ vm_flags &= ~VM_MAYWRITE;
82170+ }
82171+#endif
82172+
82173 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
82174 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82175
82176diff --git a/mm/mprotect.c b/mm/mprotect.c
82177index 94722a4..9837984 100644
82178--- a/mm/mprotect.c
82179+++ b/mm/mprotect.c
82180@@ -23,10 +23,17 @@
82181 #include <linux/mmu_notifier.h>
82182 #include <linux/migrate.h>
82183 #include <linux/perf_event.h>
82184+
82185+#ifdef CONFIG_PAX_MPROTECT
82186+#include <linux/elf.h>
82187+#include <linux/binfmts.h>
82188+#endif
82189+
82190 #include <asm/uaccess.h>
82191 #include <asm/pgtable.h>
82192 #include <asm/cacheflush.h>
82193 #include <asm/tlbflush.h>
82194+#include <asm/mmu_context.h>
82195
82196 #ifndef pgprot_modify
82197 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
82198@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
82199 return pages;
82200 }
82201
82202+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82203+/* called while holding the mmap semaphor for writing except stack expansion */
82204+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
82205+{
82206+ unsigned long oldlimit, newlimit = 0UL;
82207+
82208+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
82209+ return;
82210+
82211+ spin_lock(&mm->page_table_lock);
82212+ oldlimit = mm->context.user_cs_limit;
82213+ if ((prot & VM_EXEC) && oldlimit < end)
82214+ /* USER_CS limit moved up */
82215+ newlimit = end;
82216+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
82217+ /* USER_CS limit moved down */
82218+ newlimit = start;
82219+
82220+ if (newlimit) {
82221+ mm->context.user_cs_limit = newlimit;
82222+
82223+#ifdef CONFIG_SMP
82224+ wmb();
82225+ cpus_clear(mm->context.cpu_user_cs_mask);
82226+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
82227+#endif
82228+
82229+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
82230+ }
82231+ spin_unlock(&mm->page_table_lock);
82232+ if (newlimit == end) {
82233+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
82234+
82235+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
82236+ if (is_vm_hugetlb_page(vma))
82237+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
82238+ else
82239+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
82240+ }
82241+}
82242+#endif
82243+
82244 int
82245 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82246 unsigned long start, unsigned long end, unsigned long newflags)
82247@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82248 int error;
82249 int dirty_accountable = 0;
82250
82251+#ifdef CONFIG_PAX_SEGMEXEC
82252+ struct vm_area_struct *vma_m = NULL;
82253+ unsigned long start_m, end_m;
82254+
82255+ start_m = start + SEGMEXEC_TASK_SIZE;
82256+ end_m = end + SEGMEXEC_TASK_SIZE;
82257+#endif
82258+
82259 if (newflags == oldflags) {
82260 *pprev = vma;
82261 return 0;
82262 }
82263
82264+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
82265+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
82266+
82267+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
82268+ return -ENOMEM;
82269+
82270+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
82271+ return -ENOMEM;
82272+ }
82273+
82274 /*
82275 * If we make a private mapping writable we increase our commit;
82276 * but (without finer accounting) cannot reduce our commit if we
82277@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82278 }
82279 }
82280
82281+#ifdef CONFIG_PAX_SEGMEXEC
82282+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
82283+ if (start != vma->vm_start) {
82284+ error = split_vma(mm, vma, start, 1);
82285+ if (error)
82286+ goto fail;
82287+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
82288+ *pprev = (*pprev)->vm_next;
82289+ }
82290+
82291+ if (end != vma->vm_end) {
82292+ error = split_vma(mm, vma, end, 0);
82293+ if (error)
82294+ goto fail;
82295+ }
82296+
82297+ if (pax_find_mirror_vma(vma)) {
82298+ error = __do_munmap(mm, start_m, end_m - start_m);
82299+ if (error)
82300+ goto fail;
82301+ } else {
82302+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82303+ if (!vma_m) {
82304+ error = -ENOMEM;
82305+ goto fail;
82306+ }
82307+ vma->vm_flags = newflags;
82308+ error = pax_mirror_vma(vma_m, vma);
82309+ if (error) {
82310+ vma->vm_flags = oldflags;
82311+ goto fail;
82312+ }
82313+ }
82314+ }
82315+#endif
82316+
82317 /*
82318 * First try to merge with previous and/or next vma.
82319 */
82320@@ -296,9 +399,21 @@ success:
82321 * vm_flags and vm_page_prot are protected by the mmap_sem
82322 * held in write mode.
82323 */
82324+
82325+#ifdef CONFIG_PAX_SEGMEXEC
82326+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
82327+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
82328+#endif
82329+
82330 vma->vm_flags = newflags;
82331+
82332+#ifdef CONFIG_PAX_MPROTECT
82333+ if (mm->binfmt && mm->binfmt->handle_mprotect)
82334+ mm->binfmt->handle_mprotect(vma, newflags);
82335+#endif
82336+
82337 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
82338- vm_get_page_prot(newflags));
82339+ vm_get_page_prot(vma->vm_flags));
82340
82341 if (vma_wants_writenotify(vma)) {
82342 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
82343@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82344 end = start + len;
82345 if (end <= start)
82346 return -ENOMEM;
82347+
82348+#ifdef CONFIG_PAX_SEGMEXEC
82349+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
82350+ if (end > SEGMEXEC_TASK_SIZE)
82351+ return -EINVAL;
82352+ } else
82353+#endif
82354+
82355+ if (end > TASK_SIZE)
82356+ return -EINVAL;
82357+
82358 if (!arch_validate_prot(prot))
82359 return -EINVAL;
82360
82361@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82362 /*
82363 * Does the application expect PROT_READ to imply PROT_EXEC:
82364 */
82365- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82366+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82367 prot |= PROT_EXEC;
82368
82369 vm_flags = calc_vm_prot_bits(prot);
82370@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82371 if (start > vma->vm_start)
82372 prev = vma;
82373
82374+#ifdef CONFIG_PAX_MPROTECT
82375+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
82376+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
82377+#endif
82378+
82379 for (nstart = start ; ; ) {
82380 unsigned long newflags;
82381
82382@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82383
82384 /* newflags >> 4 shift VM_MAY% in place of VM_% */
82385 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
82386+ if (prot & (PROT_WRITE | PROT_EXEC))
82387+ gr_log_rwxmprotect(vma->vm_file);
82388+
82389+ error = -EACCES;
82390+ goto out;
82391+ }
82392+
82393+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
82394 error = -EACCES;
82395 goto out;
82396 }
82397@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82398 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
82399 if (error)
82400 goto out;
82401+
82402+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
82403+
82404 nstart = tmp;
82405
82406 if (nstart < prev->vm_end)
82407diff --git a/mm/mremap.c b/mm/mremap.c
82408index e1031e1..1f2a0a1 100644
82409--- a/mm/mremap.c
82410+++ b/mm/mremap.c
82411@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
82412 continue;
82413 pte = ptep_get_and_clear(mm, old_addr, old_pte);
82414 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
82415+
82416+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82417+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
82418+ pte = pte_exprotect(pte);
82419+#endif
82420+
82421 set_pte_at(mm, new_addr, new_pte, pte);
82422 }
82423
82424@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
82425 if (is_vm_hugetlb_page(vma))
82426 goto Einval;
82427
82428+#ifdef CONFIG_PAX_SEGMEXEC
82429+ if (pax_find_mirror_vma(vma))
82430+ goto Einval;
82431+#endif
82432+
82433 /* We can't remap across vm area boundaries */
82434 if (old_len > vma->vm_end - addr)
82435 goto Efault;
82436@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
82437 unsigned long ret = -EINVAL;
82438 unsigned long charged = 0;
82439 unsigned long map_flags;
82440+ unsigned long pax_task_size = TASK_SIZE;
82441
82442 if (new_addr & ~PAGE_MASK)
82443 goto out;
82444
82445- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
82446+#ifdef CONFIG_PAX_SEGMEXEC
82447+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82448+ pax_task_size = SEGMEXEC_TASK_SIZE;
82449+#endif
82450+
82451+ pax_task_size -= PAGE_SIZE;
82452+
82453+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
82454 goto out;
82455
82456 /* Check if the location we're moving into overlaps the
82457 * old location at all, and fail if it does.
82458 */
82459- if ((new_addr <= addr) && (new_addr+new_len) > addr)
82460- goto out;
82461-
82462- if ((addr <= new_addr) && (addr+old_len) > new_addr)
82463+ if (addr + old_len > new_addr && new_addr + new_len > addr)
82464 goto out;
82465
82466 ret = do_munmap(mm, new_addr, new_len);
82467@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82468 struct vm_area_struct *vma;
82469 unsigned long ret = -EINVAL;
82470 unsigned long charged = 0;
82471+ unsigned long pax_task_size = TASK_SIZE;
82472
82473 down_write(&current->mm->mmap_sem);
82474
82475@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82476 if (!new_len)
82477 goto out;
82478
82479+#ifdef CONFIG_PAX_SEGMEXEC
82480+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82481+ pax_task_size = SEGMEXEC_TASK_SIZE;
82482+#endif
82483+
82484+ pax_task_size -= PAGE_SIZE;
82485+
82486+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
82487+ old_len > pax_task_size || addr > pax_task_size-old_len)
82488+ goto out;
82489+
82490 if (flags & MREMAP_FIXED) {
82491 if (flags & MREMAP_MAYMOVE)
82492 ret = mremap_to(addr, old_len, new_addr, new_len);
82493@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82494 addr + new_len);
82495 }
82496 ret = addr;
82497+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
82498 goto out;
82499 }
82500 }
82501@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82502 goto out;
82503 }
82504
82505+ map_flags = vma->vm_flags;
82506 ret = move_vma(vma, addr, old_len, new_len, new_addr);
82507+ if (!(ret & ~PAGE_MASK)) {
82508+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
82509+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
82510+ }
82511 }
82512 out:
82513 if (ret & ~PAGE_MASK)
82514diff --git a/mm/nommu.c b/mm/nommu.c
82515index 79c3cac..4d357e0 100644
82516--- a/mm/nommu.c
82517+++ b/mm/nommu.c
82518@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
82519 int sysctl_overcommit_ratio = 50; /* default is 50% */
82520 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
82521 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
82522-int heap_stack_gap = 0;
82523
82524 atomic_long_t mmap_pages_allocated;
82525
82526@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
82527 EXPORT_SYMBOL(find_vma);
82528
82529 /*
82530- * find a VMA
82531- * - we don't extend stack VMAs under NOMMU conditions
82532- */
82533-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
82534-{
82535- return find_vma(mm, addr);
82536-}
82537-
82538-/*
82539 * expand a stack to a given address
82540 * - not supported under NOMMU conditions
82541 */
82542@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82543
82544 /* most fields are the same, copy all, and then fixup */
82545 *new = *vma;
82546+ INIT_LIST_HEAD(&new->anon_vma_chain);
82547 *region = *vma->vm_region;
82548 new->vm_region = region;
82549
82550diff --git a/mm/page-writeback.c b/mm/page-writeback.c
82551index 0713bfb..b95bb87 100644
82552--- a/mm/page-writeback.c
82553+++ b/mm/page-writeback.c
82554@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
82555 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
82556 * - the bdi dirty thresh drops quickly due to change of JBOD workload
82557 */
82558-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
82559+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
82560 unsigned long thresh,
82561 unsigned long bg_thresh,
82562 unsigned long dirty,
82563@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
82564 }
82565 }
82566
82567-static struct notifier_block __cpuinitdata ratelimit_nb = {
82568+static struct notifier_block ratelimit_nb = {
82569 .notifier_call = ratelimit_handler,
82570 .next = NULL,
82571 };
82572diff --git a/mm/page_alloc.c b/mm/page_alloc.c
82573index 6a83cd3..3ab04ef 100644
82574--- a/mm/page_alloc.c
82575+++ b/mm/page_alloc.c
82576@@ -58,6 +58,7 @@
82577 #include <linux/prefetch.h>
82578 #include <linux/migrate.h>
82579 #include <linux/page-debug-flags.h>
82580+#include <linux/random.h>
82581
82582 #include <asm/tlbflush.h>
82583 #include <asm/div64.h>
82584@@ -338,7 +339,7 @@ out:
82585 * This usage means that zero-order pages may not be compound.
82586 */
82587
82588-static void free_compound_page(struct page *page)
82589+void free_compound_page(struct page *page)
82590 {
82591 __free_pages_ok(page, compound_order(page));
82592 }
82593@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82594 int i;
82595 int bad = 0;
82596
82597+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82598+ unsigned long index = 1UL << order;
82599+#endif
82600+
82601 trace_mm_page_free(page, order);
82602 kmemcheck_free_shadow(page, order);
82603
82604@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82605 debug_check_no_obj_freed(page_address(page),
82606 PAGE_SIZE << order);
82607 }
82608+
82609+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82610+ for (; index; --index)
82611+ sanitize_highpage(page + index - 1);
82612+#endif
82613+
82614 arch_free_page(page, order);
82615 kernel_map_pages(page, 1 << order, 0);
82616
82617@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
82618 local_irq_restore(flags);
82619 }
82620
82621+#ifdef CONFIG_PAX_LATENT_ENTROPY
82622+bool __meminitdata extra_latent_entropy;
82623+
82624+static int __init setup_pax_extra_latent_entropy(char *str)
82625+{
82626+ extra_latent_entropy = true;
82627+ return 0;
82628+}
82629+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
82630+
82631+volatile u64 latent_entropy;
82632+#endif
82633+
82634 /*
82635 * Read access to zone->managed_pages is safe because it's unsigned long,
82636 * but we still need to serialize writers. Currently all callers of
82637@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
82638 set_page_count(p, 0);
82639 }
82640
82641+#ifdef CONFIG_PAX_LATENT_ENTROPY
82642+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
82643+ u64 hash = 0;
82644+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
82645+ const u64 *data = lowmem_page_address(page);
82646+
82647+ for (index = 0; index < end; index++)
82648+ hash ^= hash + data[index];
82649+ latent_entropy ^= hash;
82650+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82651+ }
82652+#endif
82653+
82654 page_zone(page)->managed_pages += 1 << order;
82655 set_page_refcounted(page);
82656 __free_pages(page, order);
82657@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
82658 arch_alloc_page(page, order);
82659 kernel_map_pages(page, 1 << order, 1);
82660
82661+#ifndef CONFIG_PAX_MEMORY_SANITIZE
82662 if (gfp_flags & __GFP_ZERO)
82663 prep_zero_page(page, order, gfp_flags);
82664+#endif
82665
82666 if (order && (gfp_flags & __GFP_COMP))
82667 prep_compound_page(page, order);
82668@@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
82669 unsigned long pfn;
82670
82671 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
82672+#ifdef CONFIG_X86_32
82673+ /* boot failures in VMware 8 on 32bit vanilla since
82674+ this change */
82675+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
82676+#else
82677 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
82678+#endif
82679 return 1;
82680 }
82681 return 0;
82682diff --git a/mm/percpu.c b/mm/percpu.c
82683index 8c8e08f..73a5cda 100644
82684--- a/mm/percpu.c
82685+++ b/mm/percpu.c
82686@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
82687 static unsigned int pcpu_high_unit_cpu __read_mostly;
82688
82689 /* the address of the first chunk which starts with the kernel static area */
82690-void *pcpu_base_addr __read_mostly;
82691+void *pcpu_base_addr __read_only;
82692 EXPORT_SYMBOL_GPL(pcpu_base_addr);
82693
82694 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
82695diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
82696index fd26d04..0cea1b0 100644
82697--- a/mm/process_vm_access.c
82698+++ b/mm/process_vm_access.c
82699@@ -13,6 +13,7 @@
82700 #include <linux/uio.h>
82701 #include <linux/sched.h>
82702 #include <linux/highmem.h>
82703+#include <linux/security.h>
82704 #include <linux/ptrace.h>
82705 #include <linux/slab.h>
82706 #include <linux/syscalls.h>
82707@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82708 size_t iov_l_curr_offset = 0;
82709 ssize_t iov_len;
82710
82711+ return -ENOSYS; // PaX: until properly audited
82712+
82713 /*
82714 * Work out how many pages of struct pages we're going to need
82715 * when eventually calling get_user_pages
82716 */
82717 for (i = 0; i < riovcnt; i++) {
82718 iov_len = rvec[i].iov_len;
82719- if (iov_len > 0) {
82720- nr_pages_iov = ((unsigned long)rvec[i].iov_base
82721- + iov_len)
82722- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
82723- / PAGE_SIZE + 1;
82724- nr_pages = max(nr_pages, nr_pages_iov);
82725- }
82726+ if (iov_len <= 0)
82727+ continue;
82728+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
82729+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
82730+ nr_pages = max(nr_pages, nr_pages_iov);
82731 }
82732
82733 if (nr_pages == 0)
82734@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82735 goto free_proc_pages;
82736 }
82737
82738+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
82739+ rc = -EPERM;
82740+ goto put_task_struct;
82741+ }
82742+
82743 mm = mm_access(task, PTRACE_MODE_ATTACH);
82744 if (!mm || IS_ERR(mm)) {
82745 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
82746diff --git a/mm/rmap.c b/mm/rmap.c
82747index 2c78f8c..9e9c624 100644
82748--- a/mm/rmap.c
82749+++ b/mm/rmap.c
82750@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82751 struct anon_vma *anon_vma = vma->anon_vma;
82752 struct anon_vma_chain *avc;
82753
82754+#ifdef CONFIG_PAX_SEGMEXEC
82755+ struct anon_vma_chain *avc_m = NULL;
82756+#endif
82757+
82758 might_sleep();
82759 if (unlikely(!anon_vma)) {
82760 struct mm_struct *mm = vma->vm_mm;
82761@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82762 if (!avc)
82763 goto out_enomem;
82764
82765+#ifdef CONFIG_PAX_SEGMEXEC
82766+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
82767+ if (!avc_m)
82768+ goto out_enomem_free_avc;
82769+#endif
82770+
82771 anon_vma = find_mergeable_anon_vma(vma);
82772 allocated = NULL;
82773 if (!anon_vma) {
82774@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82775 /* page_table_lock to protect against threads */
82776 spin_lock(&mm->page_table_lock);
82777 if (likely(!vma->anon_vma)) {
82778+
82779+#ifdef CONFIG_PAX_SEGMEXEC
82780+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
82781+
82782+ if (vma_m) {
82783+ BUG_ON(vma_m->anon_vma);
82784+ vma_m->anon_vma = anon_vma;
82785+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
82786+ avc_m = NULL;
82787+ }
82788+#endif
82789+
82790 vma->anon_vma = anon_vma;
82791 anon_vma_chain_link(vma, avc, anon_vma);
82792 allocated = NULL;
82793@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82794
82795 if (unlikely(allocated))
82796 put_anon_vma(allocated);
82797+
82798+#ifdef CONFIG_PAX_SEGMEXEC
82799+ if (unlikely(avc_m))
82800+ anon_vma_chain_free(avc_m);
82801+#endif
82802+
82803 if (unlikely(avc))
82804 anon_vma_chain_free(avc);
82805 }
82806 return 0;
82807
82808 out_enomem_free_avc:
82809+
82810+#ifdef CONFIG_PAX_SEGMEXEC
82811+ if (avc_m)
82812+ anon_vma_chain_free(avc_m);
82813+#endif
82814+
82815 anon_vma_chain_free(avc);
82816 out_enomem:
82817 return -ENOMEM;
82818@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
82819 * Attach the anon_vmas from src to dst.
82820 * Returns 0 on success, -ENOMEM on failure.
82821 */
82822-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82823+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
82824 {
82825 struct anon_vma_chain *avc, *pavc;
82826 struct anon_vma *root = NULL;
82827@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82828 * the corresponding VMA in the parent process is attached to.
82829 * Returns 0 on success, non-zero on failure.
82830 */
82831-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
82832+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
82833 {
82834 struct anon_vma_chain *avc;
82835 struct anon_vma *anon_vma;
82836diff --git a/mm/shmem.c b/mm/shmem.c
82837index efd0b3a..994b702 100644
82838--- a/mm/shmem.c
82839+++ b/mm/shmem.c
82840@@ -31,7 +31,7 @@
82841 #include <linux/export.h>
82842 #include <linux/swap.h>
82843
82844-static struct vfsmount *shm_mnt;
82845+struct vfsmount *shm_mnt;
82846
82847 #ifdef CONFIG_SHMEM
82848 /*
82849@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
82850 #define BOGO_DIRENT_SIZE 20
82851
82852 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
82853-#define SHORT_SYMLINK_LEN 128
82854+#define SHORT_SYMLINK_LEN 64
82855
82856 /*
82857 * shmem_fallocate and shmem_writepage communicate via inode->i_private
82858@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
82859 static int shmem_xattr_validate(const char *name)
82860 {
82861 struct { const char *prefix; size_t len; } arr[] = {
82862+
82863+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82864+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
82865+#endif
82866+
82867 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
82868 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
82869 };
82870@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
82871 if (err)
82872 return err;
82873
82874+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82875+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
82876+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
82877+ return -EOPNOTSUPP;
82878+ if (size > 8)
82879+ return -EINVAL;
82880+ }
82881+#endif
82882+
82883 return simple_xattr_set(&info->xattrs, name, value, size, flags);
82884 }
82885
82886@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
82887 int err = -ENOMEM;
82888
82889 /* Round up to L1_CACHE_BYTES to resist false sharing */
82890- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
82891- L1_CACHE_BYTES), GFP_KERNEL);
82892+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
82893 if (!sbinfo)
82894 return -ENOMEM;
82895
82896diff --git a/mm/slab.c b/mm/slab.c
82897index e7667a3..b62c169 100644
82898--- a/mm/slab.c
82899+++ b/mm/slab.c
82900@@ -306,7 +306,7 @@ struct kmem_list3 {
82901 * Need this for bootstrapping a per node allocator.
82902 */
82903 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
82904-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
82905+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
82906 #define CACHE_CACHE 0
82907 #define SIZE_AC MAX_NUMNODES
82908 #define SIZE_L3 (2 * MAX_NUMNODES)
82909@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
82910 if ((x)->max_freeable < i) \
82911 (x)->max_freeable = i; \
82912 } while (0)
82913-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
82914-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
82915-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
82916-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
82917+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
82918+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
82919+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
82920+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
82921 #else
82922 #define STATS_INC_ACTIVE(x) do { } while (0)
82923 #define STATS_DEC_ACTIVE(x) do { } while (0)
82924@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
82925 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
82926 */
82927 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
82928- const struct slab *slab, void *obj)
82929+ const struct slab *slab, const void *obj)
82930 {
82931 u32 offset = (obj - slab->s_mem);
82932 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
82933@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
82934 struct cache_names {
82935 char *name;
82936 char *name_dma;
82937+ char *name_usercopy;
82938 };
82939
82940 static struct cache_names __initdata cache_names[] = {
82941-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
82942+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
82943 #include <linux/kmalloc_sizes.h>
82944- {NULL,}
82945+ {NULL}
82946 #undef CACHE
82947 };
82948
82949@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
82950 if (unlikely(gfpflags & GFP_DMA))
82951 return csizep->cs_dmacachep;
82952 #endif
82953+
82954+#ifdef CONFIG_PAX_USERCOPY_SLABS
82955+ if (unlikely(gfpflags & GFP_USERCOPY))
82956+ return csizep->cs_usercopycachep;
82957+#endif
82958+
82959 return csizep->cs_cachep;
82960 }
82961
82962@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
82963 return notifier_from_errno(err);
82964 }
82965
82966-static struct notifier_block __cpuinitdata cpucache_notifier = {
82967+static struct notifier_block cpucache_notifier = {
82968 &cpuup_callback, NULL, 0
82969 };
82970
82971@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
82972 */
82973
82974 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
82975- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
82976+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82977
82978 if (INDEX_AC != INDEX_L3)
82979 sizes[INDEX_L3].cs_cachep =
82980 create_kmalloc_cache(names[INDEX_L3].name,
82981- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
82982+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82983
82984 slab_early_init = 0;
82985
82986@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
82987 */
82988 if (!sizes->cs_cachep)
82989 sizes->cs_cachep = create_kmalloc_cache(names->name,
82990- sizes->cs_size, ARCH_KMALLOC_FLAGS);
82991+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82992
82993 #ifdef CONFIG_ZONE_DMA
82994 sizes->cs_dmacachep = create_kmalloc_cache(
82995 names->name_dma, sizes->cs_size,
82996 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
82997 #endif
82998+
82999+#ifdef CONFIG_PAX_USERCOPY_SLABS
83000+ sizes->cs_usercopycachep = create_kmalloc_cache(
83001+ names->name_usercopy, sizes->cs_size,
83002+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83003+#endif
83004+
83005 sizes++;
83006 names++;
83007 }
83008@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
83009 }
83010 /* cpu stats */
83011 {
83012- unsigned long allochit = atomic_read(&cachep->allochit);
83013- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
83014- unsigned long freehit = atomic_read(&cachep->freehit);
83015- unsigned long freemiss = atomic_read(&cachep->freemiss);
83016+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
83017+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
83018+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
83019+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
83020
83021 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
83022 allochit, allocmiss, freehit, freemiss);
83023@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
83024 static int __init slab_proc_init(void)
83025 {
83026 #ifdef CONFIG_DEBUG_SLAB_LEAK
83027- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
83028+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
83029 #endif
83030 return 0;
83031 }
83032 module_init(slab_proc_init);
83033 #endif
83034
83035+bool is_usercopy_object(const void *ptr)
83036+{
83037+ struct page *page;
83038+ struct kmem_cache *cachep;
83039+
83040+ if (ZERO_OR_NULL_PTR(ptr))
83041+ return false;
83042+
83043+ if (!slab_is_available())
83044+ return false;
83045+
83046+ if (!virt_addr_valid(ptr))
83047+ return false;
83048+
83049+ page = virt_to_head_page(ptr);
83050+
83051+ if (!PageSlab(page))
83052+ return false;
83053+
83054+ cachep = page->slab_cache;
83055+ return cachep->flags & SLAB_USERCOPY;
83056+}
83057+
83058+#ifdef CONFIG_PAX_USERCOPY
83059+const char *check_heap_object(const void *ptr, unsigned long n)
83060+{
83061+ struct page *page;
83062+ struct kmem_cache *cachep;
83063+ struct slab *slabp;
83064+ unsigned int objnr;
83065+ unsigned long offset;
83066+
83067+ if (ZERO_OR_NULL_PTR(ptr))
83068+ return "<null>";
83069+
83070+ if (!virt_addr_valid(ptr))
83071+ return NULL;
83072+
83073+ page = virt_to_head_page(ptr);
83074+
83075+ if (!PageSlab(page))
83076+ return NULL;
83077+
83078+ cachep = page->slab_cache;
83079+ if (!(cachep->flags & SLAB_USERCOPY))
83080+ return cachep->name;
83081+
83082+ slabp = page->slab_page;
83083+ objnr = obj_to_index(cachep, slabp, ptr);
83084+ BUG_ON(objnr >= cachep->num);
83085+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
83086+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
83087+ return NULL;
83088+
83089+ return cachep->name;
83090+}
83091+#endif
83092+
83093 /**
83094 * ksize - get the actual amount of memory allocated for a given object
83095 * @objp: Pointer to the object
83096diff --git a/mm/slab.h b/mm/slab.h
83097index 34a98d6..73633d1 100644
83098--- a/mm/slab.h
83099+++ b/mm/slab.h
83100@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83101
83102 /* Legal flag mask for kmem_cache_create(), for various configurations */
83103 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
83104- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
83105+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
83106
83107 #if defined(CONFIG_DEBUG_SLAB)
83108 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
83109@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
83110 return s;
83111
83112 page = virt_to_head_page(x);
83113+
83114+ BUG_ON(!PageSlab(page));
83115+
83116 cachep = page->slab_cache;
83117 if (slab_equal_or_root(cachep, s))
83118 return cachep;
83119diff --git a/mm/slab_common.c b/mm/slab_common.c
83120index 3f3cd97..93b0236 100644
83121--- a/mm/slab_common.c
83122+++ b/mm/slab_common.c
83123@@ -22,7 +22,7 @@
83124
83125 #include "slab.h"
83126
83127-enum slab_state slab_state;
83128+enum slab_state slab_state __read_only;
83129 LIST_HEAD(slab_caches);
83130 DEFINE_MUTEX(slab_mutex);
83131 struct kmem_cache *kmem_cache;
83132@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
83133
83134 err = __kmem_cache_create(s, flags);
83135 if (!err) {
83136- s->refcount = 1;
83137+ atomic_set(&s->refcount, 1);
83138 list_add(&s->list, &slab_caches);
83139 memcg_cache_list_add(memcg, s);
83140 } else {
83141@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
83142
83143 get_online_cpus();
83144 mutex_lock(&slab_mutex);
83145- s->refcount--;
83146- if (!s->refcount) {
83147+ if (atomic_dec_and_test(&s->refcount)) {
83148 list_del(&s->list);
83149
83150 if (!__kmem_cache_shutdown(s)) {
83151@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
83152 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
83153 name, size, err);
83154
83155- s->refcount = -1; /* Exempt from merging for now */
83156+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
83157 }
83158
83159 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83160@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83161
83162 create_boot_cache(s, name, size, flags);
83163 list_add(&s->list, &slab_caches);
83164- s->refcount = 1;
83165+ atomic_set(&s->refcount, 1);
83166 return s;
83167 }
83168
83169diff --git a/mm/slob.c b/mm/slob.c
83170index a99fdf7..f5b6577 100644
83171--- a/mm/slob.c
83172+++ b/mm/slob.c
83173@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
83174 /*
83175 * Return the size of a slob block.
83176 */
83177-static slobidx_t slob_units(slob_t *s)
83178+static slobidx_t slob_units(const slob_t *s)
83179 {
83180 if (s->units > 0)
83181 return s->units;
83182@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
83183 /*
83184 * Return the next free slob block pointer after this one.
83185 */
83186-static slob_t *slob_next(slob_t *s)
83187+static slob_t *slob_next(const slob_t *s)
83188 {
83189 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
83190 slobidx_t next;
83191@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
83192 /*
83193 * Returns true if s is the last free block in its page.
83194 */
83195-static int slob_last(slob_t *s)
83196+static int slob_last(const slob_t *s)
83197 {
83198 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
83199 }
83200
83201-static void *slob_new_pages(gfp_t gfp, int order, int node)
83202+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
83203 {
83204- void *page;
83205+ struct page *page;
83206
83207 #ifdef CONFIG_NUMA
83208 if (node != NUMA_NO_NODE)
83209@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
83210 if (!page)
83211 return NULL;
83212
83213- return page_address(page);
83214+ __SetPageSlab(page);
83215+ return page;
83216 }
83217
83218-static void slob_free_pages(void *b, int order)
83219+static void slob_free_pages(struct page *sp, int order)
83220 {
83221 if (current->reclaim_state)
83222 current->reclaim_state->reclaimed_slab += 1 << order;
83223- free_pages((unsigned long)b, order);
83224+ __ClearPageSlab(sp);
83225+ reset_page_mapcount(sp);
83226+ sp->private = 0;
83227+ __free_pages(sp, order);
83228 }
83229
83230 /*
83231@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
83232
83233 /* Not enough space: must allocate a new page */
83234 if (!b) {
83235- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83236- if (!b)
83237+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83238+ if (!sp)
83239 return NULL;
83240- sp = virt_to_page(b);
83241- __SetPageSlab(sp);
83242+ b = page_address(sp);
83243
83244 spin_lock_irqsave(&slob_lock, flags);
83245 sp->units = SLOB_UNITS(PAGE_SIZE);
83246 sp->freelist = b;
83247+ sp->private = 0;
83248 INIT_LIST_HEAD(&sp->list);
83249 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
83250 set_slob_page_free(sp, slob_list);
83251@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
83252 if (slob_page_free(sp))
83253 clear_slob_page_free(sp);
83254 spin_unlock_irqrestore(&slob_lock, flags);
83255- __ClearPageSlab(sp);
83256- reset_page_mapcount(sp);
83257- slob_free_pages(b, 0);
83258+ slob_free_pages(sp, 0);
83259 return;
83260 }
83261
83262@@ -424,11 +426,10 @@ out:
83263 */
83264
83265 static __always_inline void *
83266-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83267+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
83268 {
83269- unsigned int *m;
83270- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83271- void *ret;
83272+ slob_t *m;
83273+ void *ret = NULL;
83274
83275 gfp &= gfp_allowed_mask;
83276
83277@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83278
83279 if (!m)
83280 return NULL;
83281- *m = size;
83282+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
83283+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
83284+ m[0].units = size;
83285+ m[1].units = align;
83286 ret = (void *)m + align;
83287
83288 trace_kmalloc_node(caller, ret,
83289 size, size + align, gfp, node);
83290 } else {
83291 unsigned int order = get_order(size);
83292+ struct page *page;
83293
83294 if (likely(order))
83295 gfp |= __GFP_COMP;
83296- ret = slob_new_pages(gfp, order, node);
83297+ page = slob_new_pages(gfp, order, node);
83298+ if (page) {
83299+ ret = page_address(page);
83300+ page->private = size;
83301+ }
83302
83303 trace_kmalloc_node(caller, ret,
83304 size, PAGE_SIZE << order, gfp, node);
83305 }
83306
83307- kmemleak_alloc(ret, size, 1, gfp);
83308+ return ret;
83309+}
83310+
83311+static __always_inline void *
83312+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83313+{
83314+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83315+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
83316+
83317+ if (!ZERO_OR_NULL_PTR(ret))
83318+ kmemleak_alloc(ret, size, 1, gfp);
83319 return ret;
83320 }
83321
83322@@ -494,33 +513,110 @@ void kfree(const void *block)
83323 kmemleak_free(block);
83324
83325 sp = virt_to_page(block);
83326- if (PageSlab(sp)) {
83327+ VM_BUG_ON(!PageSlab(sp));
83328+ if (!sp->private) {
83329 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83330- unsigned int *m = (unsigned int *)(block - align);
83331- slob_free(m, *m + align);
83332- } else
83333+ slob_t *m = (slob_t *)(block - align);
83334+ slob_free(m, m[0].units + align);
83335+ } else {
83336+ __ClearPageSlab(sp);
83337+ reset_page_mapcount(sp);
83338+ sp->private = 0;
83339 __free_pages(sp, compound_order(sp));
83340+ }
83341 }
83342 EXPORT_SYMBOL(kfree);
83343
83344+bool is_usercopy_object(const void *ptr)
83345+{
83346+ if (!slab_is_available())
83347+ return false;
83348+
83349+ // PAX: TODO
83350+
83351+ return false;
83352+}
83353+
83354+#ifdef CONFIG_PAX_USERCOPY
83355+const char *check_heap_object(const void *ptr, unsigned long n)
83356+{
83357+ struct page *page;
83358+ const slob_t *free;
83359+ const void *base;
83360+ unsigned long flags;
83361+
83362+ if (ZERO_OR_NULL_PTR(ptr))
83363+ return "<null>";
83364+
83365+ if (!virt_addr_valid(ptr))
83366+ return NULL;
83367+
83368+ page = virt_to_head_page(ptr);
83369+ if (!PageSlab(page))
83370+ return NULL;
83371+
83372+ if (page->private) {
83373+ base = page;
83374+ if (base <= ptr && n <= page->private - (ptr - base))
83375+ return NULL;
83376+ return "<slob>";
83377+ }
83378+
83379+ /* some tricky double walking to find the chunk */
83380+ spin_lock_irqsave(&slob_lock, flags);
83381+ base = (void *)((unsigned long)ptr & PAGE_MASK);
83382+ free = page->freelist;
83383+
83384+ while (!slob_last(free) && (void *)free <= ptr) {
83385+ base = free + slob_units(free);
83386+ free = slob_next(free);
83387+ }
83388+
83389+ while (base < (void *)free) {
83390+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
83391+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
83392+ int offset;
83393+
83394+ if (ptr < base + align)
83395+ break;
83396+
83397+ offset = ptr - base - align;
83398+ if (offset >= m) {
83399+ base += size;
83400+ continue;
83401+ }
83402+
83403+ if (n > m - offset)
83404+ break;
83405+
83406+ spin_unlock_irqrestore(&slob_lock, flags);
83407+ return NULL;
83408+ }
83409+
83410+ spin_unlock_irqrestore(&slob_lock, flags);
83411+ return "<slob>";
83412+}
83413+#endif
83414+
83415 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
83416 size_t ksize(const void *block)
83417 {
83418 struct page *sp;
83419 int align;
83420- unsigned int *m;
83421+ slob_t *m;
83422
83423 BUG_ON(!block);
83424 if (unlikely(block == ZERO_SIZE_PTR))
83425 return 0;
83426
83427 sp = virt_to_page(block);
83428- if (unlikely(!PageSlab(sp)))
83429- return PAGE_SIZE << compound_order(sp);
83430+ VM_BUG_ON(!PageSlab(sp));
83431+ if (sp->private)
83432+ return sp->private;
83433
83434 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83435- m = (unsigned int *)(block - align);
83436- return SLOB_UNITS(*m) * SLOB_UNIT;
83437+ m = (slob_t *)(block - align);
83438+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
83439 }
83440 EXPORT_SYMBOL(ksize);
83441
83442@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
83443
83444 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
83445 {
83446- void *b;
83447+ void *b = NULL;
83448
83449 flags &= gfp_allowed_mask;
83450
83451 lockdep_trace_alloc(flags);
83452
83453+#ifdef CONFIG_PAX_USERCOPY_SLABS
83454+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
83455+#else
83456 if (c->size < PAGE_SIZE) {
83457 b = slob_alloc(c->size, flags, c->align, node);
83458 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83459 SLOB_UNITS(c->size) * SLOB_UNIT,
83460 flags, node);
83461 } else {
83462- b = slob_new_pages(flags, get_order(c->size), node);
83463+ struct page *sp;
83464+
83465+ sp = slob_new_pages(flags, get_order(c->size), node);
83466+ if (sp) {
83467+ b = page_address(sp);
83468+ sp->private = c->size;
83469+ }
83470 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83471 PAGE_SIZE << get_order(c->size),
83472 flags, node);
83473 }
83474+#endif
83475
83476 if (c->ctor)
83477 c->ctor(b);
83478@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
83479
83480 static void __kmem_cache_free(void *b, int size)
83481 {
83482- if (size < PAGE_SIZE)
83483+ struct page *sp;
83484+
83485+ sp = virt_to_page(b);
83486+ BUG_ON(!PageSlab(sp));
83487+ if (!sp->private)
83488 slob_free(b, size);
83489 else
83490- slob_free_pages(b, get_order(size));
83491+ slob_free_pages(sp, get_order(size));
83492 }
83493
83494 static void kmem_rcu_free(struct rcu_head *head)
83495@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
83496
83497 void kmem_cache_free(struct kmem_cache *c, void *b)
83498 {
83499+ int size = c->size;
83500+
83501+#ifdef CONFIG_PAX_USERCOPY_SLABS
83502+ if (size + c->align < PAGE_SIZE) {
83503+ size += c->align;
83504+ b -= c->align;
83505+ }
83506+#endif
83507+
83508 kmemleak_free_recursive(b, c->flags);
83509 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
83510 struct slob_rcu *slob_rcu;
83511- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
83512- slob_rcu->size = c->size;
83513+ slob_rcu = b + (size - sizeof(struct slob_rcu));
83514+ slob_rcu->size = size;
83515 call_rcu(&slob_rcu->head, kmem_rcu_free);
83516 } else {
83517- __kmem_cache_free(b, c->size);
83518+ __kmem_cache_free(b, size);
83519 }
83520
83521+#ifdef CONFIG_PAX_USERCOPY_SLABS
83522+ trace_kfree(_RET_IP_, b);
83523+#else
83524 trace_kmem_cache_free(_RET_IP_, b);
83525+#endif
83526+
83527 }
83528 EXPORT_SYMBOL(kmem_cache_free);
83529
83530diff --git a/mm/slub.c b/mm/slub.c
83531index ba2ca53..00b1f4e 100644
83532--- a/mm/slub.c
83533+++ b/mm/slub.c
83534@@ -197,7 +197,7 @@ struct track {
83535
83536 enum track_item { TRACK_ALLOC, TRACK_FREE };
83537
83538-#ifdef CONFIG_SYSFS
83539+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83540 static int sysfs_slab_add(struct kmem_cache *);
83541 static int sysfs_slab_alias(struct kmem_cache *, const char *);
83542 static void sysfs_slab_remove(struct kmem_cache *);
83543@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
83544 if (!t->addr)
83545 return;
83546
83547- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
83548+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
83549 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
83550 #ifdef CONFIG_STACKTRACE
83551 {
83552@@ -2653,7 +2653,7 @@ static int slub_min_objects;
83553 * Merge control. If this is set then no merging of slab caches will occur.
83554 * (Could be removed. This was introduced to pacify the merge skeptics.)
83555 */
83556-static int slub_nomerge;
83557+static int slub_nomerge = 1;
83558
83559 /*
83560 * Calculate the order of allocation given an slab object size.
83561@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
83562 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
83563 #endif
83564
83565+#ifdef CONFIG_PAX_USERCOPY_SLABS
83566+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
83567+#endif
83568+
83569 static int __init setup_slub_min_order(char *str)
83570 {
83571 get_option(&str, &slub_min_order);
83572@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
83573 return kmalloc_dma_caches[index];
83574
83575 #endif
83576+
83577+#ifdef CONFIG_PAX_USERCOPY_SLABS
83578+ if (flags & SLAB_USERCOPY)
83579+ return kmalloc_usercopy_caches[index];
83580+
83581+#endif
83582+
83583 return kmalloc_caches[index];
83584 }
83585
83586@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
83587 EXPORT_SYMBOL(__kmalloc_node);
83588 #endif
83589
83590+bool is_usercopy_object(const void *ptr)
83591+{
83592+ struct page *page;
83593+ struct kmem_cache *s;
83594+
83595+ if (ZERO_OR_NULL_PTR(ptr))
83596+ return false;
83597+
83598+ if (!slab_is_available())
83599+ return false;
83600+
83601+ if (!virt_addr_valid(ptr))
83602+ return false;
83603+
83604+ page = virt_to_head_page(ptr);
83605+
83606+ if (!PageSlab(page))
83607+ return false;
83608+
83609+ s = page->slab_cache;
83610+ return s->flags & SLAB_USERCOPY;
83611+}
83612+
83613+#ifdef CONFIG_PAX_USERCOPY
83614+const char *check_heap_object(const void *ptr, unsigned long n)
83615+{
83616+ struct page *page;
83617+ struct kmem_cache *s;
83618+ unsigned long offset;
83619+
83620+ if (ZERO_OR_NULL_PTR(ptr))
83621+ return "<null>";
83622+
83623+ if (!virt_addr_valid(ptr))
83624+ return NULL;
83625+
83626+ page = virt_to_head_page(ptr);
83627+
83628+ if (!PageSlab(page))
83629+ return NULL;
83630+
83631+ s = page->slab_cache;
83632+ if (!(s->flags & SLAB_USERCOPY))
83633+ return s->name;
83634+
83635+ offset = (ptr - page_address(page)) % s->size;
83636+ if (offset <= s->object_size && n <= s->object_size - offset)
83637+ return NULL;
83638+
83639+ return s->name;
83640+}
83641+#endif
83642+
83643 size_t ksize(const void *object)
83644 {
83645 struct page *page;
83646@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
83647
83648 /* Caches that are not of the two-to-the-power-of size */
83649 if (KMALLOC_MIN_SIZE <= 32) {
83650- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
83651+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
83652 caches++;
83653 }
83654
83655 if (KMALLOC_MIN_SIZE <= 64) {
83656- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
83657+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
83658 caches++;
83659 }
83660
83661 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
83662- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
83663+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
83664 caches++;
83665 }
83666
83667@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
83668 }
83669 }
83670 #endif
83671+
83672+#ifdef CONFIG_PAX_USERCOPY_SLABS
83673+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
83674+ struct kmem_cache *s = kmalloc_caches[i];
83675+
83676+ if (s && s->size) {
83677+ char *name = kasprintf(GFP_NOWAIT,
83678+ "usercopy-kmalloc-%d", s->object_size);
83679+
83680+ BUG_ON(!name);
83681+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
83682+ s->object_size, SLAB_USERCOPY);
83683+ }
83684+ }
83685+#endif
83686+
83687 printk(KERN_INFO
83688 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
83689 " CPUs=%d, Nodes=%d\n",
83690@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
83691 /*
83692 * We may have set a slab to be unmergeable during bootstrap.
83693 */
83694- if (s->refcount < 0)
83695+ if (atomic_read(&s->refcount) < 0)
83696 return 1;
83697
83698 return 0;
83699@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83700
83701 s = find_mergeable(memcg, size, align, flags, name, ctor);
83702 if (s) {
83703- s->refcount++;
83704+ atomic_inc(&s->refcount);
83705 /*
83706 * Adjust the object sizes so that we clear
83707 * the complete object on kzalloc.
83708@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83709 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
83710
83711 if (sysfs_slab_alias(s, name)) {
83712- s->refcount--;
83713+ atomic_dec(&s->refcount);
83714 s = NULL;
83715 }
83716 }
83717@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
83718 return NOTIFY_OK;
83719 }
83720
83721-static struct notifier_block __cpuinitdata slab_notifier = {
83722+static struct notifier_block slab_notifier = {
83723 .notifier_call = slab_cpuup_callback
83724 };
83725
83726@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
83727 }
83728 #endif
83729
83730-#ifdef CONFIG_SYSFS
83731+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83732 static int count_inuse(struct page *page)
83733 {
83734 return page->inuse;
83735@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
83736 validate_slab_cache(kmalloc_caches[9]);
83737 }
83738 #else
83739-#ifdef CONFIG_SYSFS
83740+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83741 static void resiliency_test(void) {};
83742 #endif
83743 #endif
83744
83745-#ifdef CONFIG_SYSFS
83746+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83747 enum slab_stat_type {
83748 SL_ALL, /* All slabs */
83749 SL_PARTIAL, /* Only partially allocated slabs */
83750@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
83751
83752 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
83753 {
83754- return sprintf(buf, "%d\n", s->refcount - 1);
83755+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
83756 }
83757 SLAB_ATTR_RO(aliases);
83758
83759@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
83760 return name;
83761 }
83762
83763+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83764 static int sysfs_slab_add(struct kmem_cache *s)
83765 {
83766 int err;
83767@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
83768 kobject_del(&s->kobj);
83769 kobject_put(&s->kobj);
83770 }
83771+#endif
83772
83773 /*
83774 * Need to buffer aliases during bootup until sysfs becomes
83775@@ -5336,6 +5418,7 @@ struct saved_alias {
83776
83777 static struct saved_alias *alias_list;
83778
83779+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83780 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83781 {
83782 struct saved_alias *al;
83783@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83784 alias_list = al;
83785 return 0;
83786 }
83787+#endif
83788
83789 static int __init slab_sysfs_init(void)
83790 {
83791diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
83792index 1b7e22a..3fcd4f3 100644
83793--- a/mm/sparse-vmemmap.c
83794+++ b/mm/sparse-vmemmap.c
83795@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
83796 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83797 if (!p)
83798 return NULL;
83799- pud_populate(&init_mm, pud, p);
83800+ pud_populate_kernel(&init_mm, pud, p);
83801 }
83802 return pud;
83803 }
83804@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
83805 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83806 if (!p)
83807 return NULL;
83808- pgd_populate(&init_mm, pgd, p);
83809+ pgd_populate_kernel(&init_mm, pgd, p);
83810 }
83811 return pgd;
83812 }
83813diff --git a/mm/sparse.c b/mm/sparse.c
83814index 6b5fb76..db0c190 100644
83815--- a/mm/sparse.c
83816+++ b/mm/sparse.c
83817@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
83818
83819 for (i = 0; i < PAGES_PER_SECTION; i++) {
83820 if (PageHWPoison(&memmap[i])) {
83821- atomic_long_sub(1, &mce_bad_pages);
83822+ atomic_long_sub_unchecked(1, &mce_bad_pages);
83823 ClearPageHWPoison(&memmap[i]);
83824 }
83825 }
83826diff --git a/mm/swap.c b/mm/swap.c
83827index 6310dc2..3662b3f 100644
83828--- a/mm/swap.c
83829+++ b/mm/swap.c
83830@@ -30,6 +30,7 @@
83831 #include <linux/backing-dev.h>
83832 #include <linux/memcontrol.h>
83833 #include <linux/gfp.h>
83834+#include <linux/hugetlb.h>
83835
83836 #include "internal.h"
83837
83838@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
83839
83840 __page_cache_release(page);
83841 dtor = get_compound_page_dtor(page);
83842+ if (!PageHuge(page))
83843+ BUG_ON(dtor != free_compound_page);
83844 (*dtor)(page);
83845 }
83846
83847diff --git a/mm/swapfile.c b/mm/swapfile.c
83848index e97a0e5..b50e796 100644
83849--- a/mm/swapfile.c
83850+++ b/mm/swapfile.c
83851@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
83852
83853 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
83854 /* Activity counter to indicate that a swapon or swapoff has occurred */
83855-static atomic_t proc_poll_event = ATOMIC_INIT(0);
83856+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
83857
83858 static inline unsigned char swap_count(unsigned char ent)
83859 {
83860@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
83861 }
83862 filp_close(swap_file, NULL);
83863 err = 0;
83864- atomic_inc(&proc_poll_event);
83865+ atomic_inc_unchecked(&proc_poll_event);
83866 wake_up_interruptible(&proc_poll_wait);
83867
83868 out_dput:
83869@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
83870
83871 poll_wait(file, &proc_poll_wait, wait);
83872
83873- if (seq->poll_event != atomic_read(&proc_poll_event)) {
83874- seq->poll_event = atomic_read(&proc_poll_event);
83875+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
83876+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83877 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
83878 }
83879
83880@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
83881 return ret;
83882
83883 seq = file->private_data;
83884- seq->poll_event = atomic_read(&proc_poll_event);
83885+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83886 return 0;
83887 }
83888
83889@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
83890 (frontswap_map) ? "FS" : "");
83891
83892 mutex_unlock(&swapon_mutex);
83893- atomic_inc(&proc_poll_event);
83894+ atomic_inc_unchecked(&proc_poll_event);
83895 wake_up_interruptible(&proc_poll_wait);
83896
83897 if (S_ISREG(inode->i_mode))
83898diff --git a/mm/util.c b/mm/util.c
83899index c55e26b..3f913a9 100644
83900--- a/mm/util.c
83901+++ b/mm/util.c
83902@@ -292,6 +292,12 @@ done:
83903 void arch_pick_mmap_layout(struct mm_struct *mm)
83904 {
83905 mm->mmap_base = TASK_UNMAPPED_BASE;
83906+
83907+#ifdef CONFIG_PAX_RANDMMAP
83908+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83909+ mm->mmap_base += mm->delta_mmap;
83910+#endif
83911+
83912 mm->get_unmapped_area = arch_get_unmapped_area;
83913 mm->unmap_area = arch_unmap_area;
83914 }
83915diff --git a/mm/vmalloc.c b/mm/vmalloc.c
83916index 5123a16..f234a48 100644
83917--- a/mm/vmalloc.c
83918+++ b/mm/vmalloc.c
83919@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
83920
83921 pte = pte_offset_kernel(pmd, addr);
83922 do {
83923- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83924- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83925+
83926+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83927+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
83928+ BUG_ON(!pte_exec(*pte));
83929+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
83930+ continue;
83931+ }
83932+#endif
83933+
83934+ {
83935+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83936+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83937+ }
83938 } while (pte++, addr += PAGE_SIZE, addr != end);
83939 }
83940
83941@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
83942 pte = pte_alloc_kernel(pmd, addr);
83943 if (!pte)
83944 return -ENOMEM;
83945+
83946+ pax_open_kernel();
83947 do {
83948 struct page *page = pages[*nr];
83949
83950- if (WARN_ON(!pte_none(*pte)))
83951+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83952+ if (pgprot_val(prot) & _PAGE_NX)
83953+#endif
83954+
83955+ if (!pte_none(*pte)) {
83956+ pax_close_kernel();
83957+ WARN_ON(1);
83958 return -EBUSY;
83959- if (WARN_ON(!page))
83960+ }
83961+ if (!page) {
83962+ pax_close_kernel();
83963+ WARN_ON(1);
83964 return -ENOMEM;
83965+ }
83966 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
83967 (*nr)++;
83968 } while (pte++, addr += PAGE_SIZE, addr != end);
83969+ pax_close_kernel();
83970 return 0;
83971 }
83972
83973@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
83974 pmd_t *pmd;
83975 unsigned long next;
83976
83977- pmd = pmd_alloc(&init_mm, pud, addr);
83978+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
83979 if (!pmd)
83980 return -ENOMEM;
83981 do {
83982@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
83983 pud_t *pud;
83984 unsigned long next;
83985
83986- pud = pud_alloc(&init_mm, pgd, addr);
83987+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
83988 if (!pud)
83989 return -ENOMEM;
83990 do {
83991@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
83992 * and fall back on vmalloc() if that fails. Others
83993 * just put it in the vmalloc space.
83994 */
83995-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
83996+#ifdef CONFIG_MODULES
83997+#ifdef MODULES_VADDR
83998 unsigned long addr = (unsigned long)x;
83999 if (addr >= MODULES_VADDR && addr < MODULES_END)
84000 return 1;
84001 #endif
84002+
84003+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84004+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
84005+ return 1;
84006+#endif
84007+
84008+#endif
84009+
84010 return is_vmalloc_addr(x);
84011 }
84012
84013@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
84014
84015 if (!pgd_none(*pgd)) {
84016 pud_t *pud = pud_offset(pgd, addr);
84017+#ifdef CONFIG_X86
84018+ if (!pud_large(*pud))
84019+#endif
84020 if (!pud_none(*pud)) {
84021 pmd_t *pmd = pmd_offset(pud, addr);
84022+#ifdef CONFIG_X86
84023+ if (!pmd_large(*pmd))
84024+#endif
84025 if (!pmd_none(*pmd)) {
84026 pte_t *ptep, pte;
84027
84028@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
84029 * Allocate a region of KVA of the specified size and alignment, within the
84030 * vstart and vend.
84031 */
84032-static struct vmap_area *alloc_vmap_area(unsigned long size,
84033+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
84034 unsigned long align,
84035 unsigned long vstart, unsigned long vend,
84036 int node, gfp_t gfp_mask)
84037@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
84038 struct vm_struct *area;
84039
84040 BUG_ON(in_interrupt());
84041+
84042+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84043+ if (flags & VM_KERNEXEC) {
84044+ if (start != VMALLOC_START || end != VMALLOC_END)
84045+ return NULL;
84046+ start = (unsigned long)MODULES_EXEC_VADDR;
84047+ end = (unsigned long)MODULES_EXEC_END;
84048+ }
84049+#endif
84050+
84051 if (flags & VM_IOREMAP) {
84052 int bit = fls(size);
84053
84054@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
84055 if (count > totalram_pages)
84056 return NULL;
84057
84058+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84059+ if (!(pgprot_val(prot) & _PAGE_NX))
84060+ flags |= VM_KERNEXEC;
84061+#endif
84062+
84063 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
84064 __builtin_return_address(0));
84065 if (!area)
84066@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
84067 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
84068 goto fail;
84069
84070+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84071+ if (!(pgprot_val(prot) & _PAGE_NX))
84072+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
84073+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
84074+ else
84075+#endif
84076+
84077 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
84078 start, end, node, gfp_mask, caller);
84079 if (!area)
84080@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
84081 * For tight control over page level allocator and protection flags
84082 * use __vmalloc() instead.
84083 */
84084-
84085 void *vmalloc_exec(unsigned long size)
84086 {
84087- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
84088+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
84089 -1, __builtin_return_address(0));
84090 }
84091
84092@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
84093 unsigned long uaddr = vma->vm_start;
84094 unsigned long usize = vma->vm_end - vma->vm_start;
84095
84096+ BUG_ON(vma->vm_mirror);
84097+
84098 if ((PAGE_SIZE-1) & (unsigned long)addr)
84099 return -EINVAL;
84100
84101@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
84102 v->addr, v->addr + v->size, v->size);
84103
84104 if (v->caller)
84105+#ifdef CONFIG_GRKERNSEC_HIDESYM
84106+ seq_printf(m, " %pK", v->caller);
84107+#else
84108 seq_printf(m, " %pS", v->caller);
84109+#endif
84110
84111 if (v->nr_pages)
84112 seq_printf(m, " pages=%d", v->nr_pages);
84113diff --git a/mm/vmstat.c b/mm/vmstat.c
84114index 9800306..76b4b27 100644
84115--- a/mm/vmstat.c
84116+++ b/mm/vmstat.c
84117@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
84118 *
84119 * vm_stat contains the global counters
84120 */
84121-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84122+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84123 EXPORT_SYMBOL(vm_stat);
84124
84125 #ifdef CONFIG_SMP
84126@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
84127 v = p->vm_stat_diff[i];
84128 p->vm_stat_diff[i] = 0;
84129 local_irq_restore(flags);
84130- atomic_long_add(v, &zone->vm_stat[i]);
84131+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84132 global_diff[i] += v;
84133 #ifdef CONFIG_NUMA
84134 /* 3 seconds idle till flush */
84135@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
84136
84137 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
84138 if (global_diff[i])
84139- atomic_long_add(global_diff[i], &vm_stat[i]);
84140+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
84141 }
84142
84143 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84144@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84145 if (pset->vm_stat_diff[i]) {
84146 int v = pset->vm_stat_diff[i];
84147 pset->vm_stat_diff[i] = 0;
84148- atomic_long_add(v, &zone->vm_stat[i]);
84149- atomic_long_add(v, &vm_stat[i]);
84150+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84151+ atomic_long_add_unchecked(v, &vm_stat[i]);
84152 }
84153 }
84154 #endif
84155@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
84156 return NOTIFY_OK;
84157 }
84158
84159-static struct notifier_block __cpuinitdata vmstat_notifier =
84160+static struct notifier_block vmstat_notifier =
84161 { &vmstat_cpuup_callback, NULL, 0 };
84162 #endif
84163
84164@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
84165 start_cpu_timer(cpu);
84166 #endif
84167 #ifdef CONFIG_PROC_FS
84168- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
84169- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
84170- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
84171- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
84172+ {
84173+ mode_t gr_mode = S_IRUGO;
84174+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84175+ gr_mode = S_IRUSR;
84176+#endif
84177+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
84178+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
84179+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84180+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
84181+#else
84182+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
84183+#endif
84184+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
84185+ }
84186 #endif
84187 return 0;
84188 }
84189diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
84190index a292e80..785ee68 100644
84191--- a/net/8021q/vlan.c
84192+++ b/net/8021q/vlan.c
84193@@ -485,7 +485,7 @@ out:
84194 return NOTIFY_DONE;
84195 }
84196
84197-static struct notifier_block vlan_notifier_block __read_mostly = {
84198+static struct notifier_block vlan_notifier_block = {
84199 .notifier_call = vlan_device_event,
84200 };
84201
84202@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
84203 err = -EPERM;
84204 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
84205 break;
84206- if ((args.u.name_type >= 0) &&
84207- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
84208+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
84209 struct vlan_net *vn;
84210
84211 vn = net_generic(net, vlan_net_id);
84212diff --git a/net/9p/mod.c b/net/9p/mod.c
84213index 6ab36ae..6f1841b 100644
84214--- a/net/9p/mod.c
84215+++ b/net/9p/mod.c
84216@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
84217 void v9fs_register_trans(struct p9_trans_module *m)
84218 {
84219 spin_lock(&v9fs_trans_lock);
84220- list_add_tail(&m->list, &v9fs_trans_list);
84221+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
84222 spin_unlock(&v9fs_trans_lock);
84223 }
84224 EXPORT_SYMBOL(v9fs_register_trans);
84225@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
84226 void v9fs_unregister_trans(struct p9_trans_module *m)
84227 {
84228 spin_lock(&v9fs_trans_lock);
84229- list_del_init(&m->list);
84230+ pax_list_del_init((struct list_head *)&m->list);
84231 spin_unlock(&v9fs_trans_lock);
84232 }
84233 EXPORT_SYMBOL(v9fs_unregister_trans);
84234diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
84235index 02efb25..41541a9 100644
84236--- a/net/9p/trans_fd.c
84237+++ b/net/9p/trans_fd.c
84238@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
84239 oldfs = get_fs();
84240 set_fs(get_ds());
84241 /* The cast to a user pointer is valid due to the set_fs() */
84242- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
84243+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
84244 set_fs(oldfs);
84245
84246 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
84247diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
84248index 876fbe8..8bbea9f 100644
84249--- a/net/atm/atm_misc.c
84250+++ b/net/atm/atm_misc.c
84251@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
84252 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
84253 return 1;
84254 atm_return(vcc, truesize);
84255- atomic_inc(&vcc->stats->rx_drop);
84256+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84257 return 0;
84258 }
84259 EXPORT_SYMBOL(atm_charge);
84260@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
84261 }
84262 }
84263 atm_return(vcc, guess);
84264- atomic_inc(&vcc->stats->rx_drop);
84265+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84266 return NULL;
84267 }
84268 EXPORT_SYMBOL(atm_alloc_charge);
84269@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
84270
84271 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84272 {
84273-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84274+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84275 __SONET_ITEMS
84276 #undef __HANDLE_ITEM
84277 }
84278@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
84279
84280 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84281 {
84282-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84283+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
84284 __SONET_ITEMS
84285 #undef __HANDLE_ITEM
84286 }
84287diff --git a/net/atm/lec.h b/net/atm/lec.h
84288index a86aff9..3a0d6f6 100644
84289--- a/net/atm/lec.h
84290+++ b/net/atm/lec.h
84291@@ -48,7 +48,7 @@ struct lane2_ops {
84292 const u8 *tlvs, u32 sizeoftlvs);
84293 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
84294 const u8 *tlvs, u32 sizeoftlvs);
84295-};
84296+} __no_const;
84297
84298 /*
84299 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
84300diff --git a/net/atm/proc.c b/net/atm/proc.c
84301index 0d020de..011c7bb 100644
84302--- a/net/atm/proc.c
84303+++ b/net/atm/proc.c
84304@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
84305 const struct k_atm_aal_stats *stats)
84306 {
84307 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
84308- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
84309- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
84310- atomic_read(&stats->rx_drop));
84311+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
84312+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
84313+ atomic_read_unchecked(&stats->rx_drop));
84314 }
84315
84316 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
84317diff --git a/net/atm/resources.c b/net/atm/resources.c
84318index 0447d5d..3cf4728 100644
84319--- a/net/atm/resources.c
84320+++ b/net/atm/resources.c
84321@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
84322 static void copy_aal_stats(struct k_atm_aal_stats *from,
84323 struct atm_aal_stats *to)
84324 {
84325-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84326+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84327 __AAL_STAT_ITEMS
84328 #undef __HANDLE_ITEM
84329 }
84330@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
84331 static void subtract_aal_stats(struct k_atm_aal_stats *from,
84332 struct atm_aal_stats *to)
84333 {
84334-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84335+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
84336 __AAL_STAT_ITEMS
84337 #undef __HANDLE_ITEM
84338 }
84339diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
84340index d5744b7..506bae3 100644
84341--- a/net/ax25/sysctl_net_ax25.c
84342+++ b/net/ax25/sysctl_net_ax25.c
84343@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
84344 {
84345 char path[sizeof("net/ax25/") + IFNAMSIZ];
84346 int k;
84347- struct ctl_table *table;
84348+ ctl_table_no_const *table;
84349
84350 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
84351 if (!table)
84352diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
84353index 7d02ebd..4d4cc01 100644
84354--- a/net/batman-adv/bat_iv_ogm.c
84355+++ b/net/batman-adv/bat_iv_ogm.c
84356@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
84357
84358 /* randomize initial seqno to avoid collision */
84359 get_random_bytes(&random_seqno, sizeof(random_seqno));
84360- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84361+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84362
84363 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
84364 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
84365@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
84366 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
84367
84368 /* change sequence number to network order */
84369- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
84370+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
84371 batadv_ogm_packet->seqno = htonl(seqno);
84372- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
84373+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
84374
84375 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
84376 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
84377@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
84378 return;
84379
84380 /* could be changed by schedule_own_packet() */
84381- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
84382+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
84383
84384 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
84385 has_directlink_flag = 1;
84386diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
84387index f1d37cd..4190879 100644
84388--- a/net/batman-adv/hard-interface.c
84389+++ b/net/batman-adv/hard-interface.c
84390@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
84391 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
84392 dev_add_pack(&hard_iface->batman_adv_ptype);
84393
84394- atomic_set(&hard_iface->frag_seqno, 1);
84395+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
84396 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
84397 hard_iface->net_dev->name);
84398
84399@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
84400 /* This can't be called via a bat_priv callback because
84401 * we have no bat_priv yet.
84402 */
84403- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
84404+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
84405 hard_iface->bat_iv.ogm_buff = NULL;
84406
84407 return hard_iface;
84408diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
84409index 6b548fd..fc32c8d 100644
84410--- a/net/batman-adv/soft-interface.c
84411+++ b/net/batman-adv/soft-interface.c
84412@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
84413 primary_if->net_dev->dev_addr, ETH_ALEN);
84414
84415 /* set broadcast sequence number */
84416- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
84417+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
84418 bcast_packet->seqno = htonl(seqno);
84419
84420 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
84421@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
84422 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
84423
84424 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
84425- atomic_set(&bat_priv->bcast_seqno, 1);
84426+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
84427 atomic_set(&bat_priv->tt.vn, 0);
84428 atomic_set(&bat_priv->tt.local_changes, 0);
84429 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
84430diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
84431index ae9ac9a..11e0fe7 100644
84432--- a/net/batman-adv/types.h
84433+++ b/net/batman-adv/types.h
84434@@ -48,7 +48,7 @@
84435 struct batadv_hard_iface_bat_iv {
84436 unsigned char *ogm_buff;
84437 int ogm_buff_len;
84438- atomic_t ogm_seqno;
84439+ atomic_unchecked_t ogm_seqno;
84440 };
84441
84442 struct batadv_hard_iface {
84443@@ -56,7 +56,7 @@ struct batadv_hard_iface {
84444 int16_t if_num;
84445 char if_status;
84446 struct net_device *net_dev;
84447- atomic_t frag_seqno;
84448+ atomic_unchecked_t frag_seqno;
84449 struct kobject *hardif_obj;
84450 atomic_t refcount;
84451 struct packet_type batman_adv_ptype;
84452@@ -284,7 +284,7 @@ struct batadv_priv {
84453 atomic_t orig_interval; /* uint */
84454 atomic_t hop_penalty; /* uint */
84455 atomic_t log_level; /* uint */
84456- atomic_t bcast_seqno;
84457+ atomic_unchecked_t bcast_seqno;
84458 atomic_t bcast_queue_left;
84459 atomic_t batman_queue_left;
84460 char num_ifaces;
84461diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
84462index 10aff49..ea8e021 100644
84463--- a/net/batman-adv/unicast.c
84464+++ b/net/batman-adv/unicast.c
84465@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
84466 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
84467 frag2->flags = large_tail;
84468
84469- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
84470+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
84471 frag1->seqno = htons(seqno - 1);
84472 frag2->seqno = htons(seqno);
84473
84474diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
84475index 07f0739..3c42e34 100644
84476--- a/net/bluetooth/hci_sock.c
84477+++ b/net/bluetooth/hci_sock.c
84478@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
84479 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
84480 }
84481
84482- len = min_t(unsigned int, len, sizeof(uf));
84483+ len = min((size_t)len, sizeof(uf));
84484 if (copy_from_user(&uf, optval, len)) {
84485 err = -EFAULT;
84486 break;
84487diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
84488index 22e6583..426e2f3 100644
84489--- a/net/bluetooth/l2cap_core.c
84490+++ b/net/bluetooth/l2cap_core.c
84491@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
84492 break;
84493
84494 case L2CAP_CONF_RFC:
84495- if (olen == sizeof(rfc))
84496- memcpy(&rfc, (void *)val, olen);
84497+ if (olen != sizeof(rfc))
84498+ break;
84499+
84500+ memcpy(&rfc, (void *)val, olen);
84501
84502 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
84503 rfc.mode != chan->mode)
84504diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
84505index 1bcfb84..dad9f98 100644
84506--- a/net/bluetooth/l2cap_sock.c
84507+++ b/net/bluetooth/l2cap_sock.c
84508@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84509 struct sock *sk = sock->sk;
84510 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
84511 struct l2cap_options opts;
84512- int len, err = 0;
84513+ int err = 0;
84514+ size_t len = optlen;
84515 u32 opt;
84516
84517 BT_DBG("sk %p", sk);
84518@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84519 opts.max_tx = chan->max_tx;
84520 opts.txwin_size = chan->tx_win;
84521
84522- len = min_t(unsigned int, sizeof(opts), optlen);
84523+ len = min(sizeof(opts), len);
84524 if (copy_from_user((char *) &opts, optval, len)) {
84525 err = -EFAULT;
84526 break;
84527@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84528 struct bt_security sec;
84529 struct bt_power pwr;
84530 struct l2cap_conn *conn;
84531- int len, err = 0;
84532+ int err = 0;
84533+ size_t len = optlen;
84534 u32 opt;
84535
84536 BT_DBG("sk %p", sk);
84537@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84538
84539 sec.level = BT_SECURITY_LOW;
84540
84541- len = min_t(unsigned int, sizeof(sec), optlen);
84542+ len = min(sizeof(sec), len);
84543 if (copy_from_user((char *) &sec, optval, len)) {
84544 err = -EFAULT;
84545 break;
84546@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84547
84548 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
84549
84550- len = min_t(unsigned int, sizeof(pwr), optlen);
84551+ len = min(sizeof(pwr), len);
84552 if (copy_from_user((char *) &pwr, optval, len)) {
84553 err = -EFAULT;
84554 break;
84555diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
84556index ce3f665..2c7d08f 100644
84557--- a/net/bluetooth/rfcomm/sock.c
84558+++ b/net/bluetooth/rfcomm/sock.c
84559@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84560 struct sock *sk = sock->sk;
84561 struct bt_security sec;
84562 int err = 0;
84563- size_t len;
84564+ size_t len = optlen;
84565 u32 opt;
84566
84567 BT_DBG("sk %p", sk);
84568@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84569
84570 sec.level = BT_SECURITY_LOW;
84571
84572- len = min_t(unsigned int, sizeof(sec), optlen);
84573+ len = min(sizeof(sec), len);
84574 if (copy_from_user((char *) &sec, optval, len)) {
84575 err = -EFAULT;
84576 break;
84577diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
84578index bd6fd0f..6492cba 100644
84579--- a/net/bluetooth/rfcomm/tty.c
84580+++ b/net/bluetooth/rfcomm/tty.c
84581@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
84582 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
84583
84584 spin_lock_irqsave(&dev->port.lock, flags);
84585- if (dev->port.count > 0) {
84586+ if (atomic_read(&dev->port.count) > 0) {
84587 spin_unlock_irqrestore(&dev->port.lock, flags);
84588 return;
84589 }
84590@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
84591 return -ENODEV;
84592
84593 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
84594- dev->channel, dev->port.count);
84595+ dev->channel, atomic_read(&dev->port.count));
84596
84597 spin_lock_irqsave(&dev->port.lock, flags);
84598- if (++dev->port.count > 1) {
84599+ if (atomic_inc_return(&dev->port.count) > 1) {
84600 spin_unlock_irqrestore(&dev->port.lock, flags);
84601 return 0;
84602 }
84603@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
84604 return;
84605
84606 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
84607- dev->port.count);
84608+ atomic_read(&dev->port.count));
84609
84610 spin_lock_irqsave(&dev->port.lock, flags);
84611- if (!--dev->port.count) {
84612+ if (!atomic_dec_return(&dev->port.count)) {
84613 spin_unlock_irqrestore(&dev->port.lock, flags);
84614 if (dev->tty_dev->parent)
84615 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
84616diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
84617index 5fe2ff3..121d696 100644
84618--- a/net/bridge/netfilter/ebtables.c
84619+++ b/net/bridge/netfilter/ebtables.c
84620@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
84621 tmp.valid_hooks = t->table->valid_hooks;
84622 }
84623 mutex_unlock(&ebt_mutex);
84624- if (copy_to_user(user, &tmp, *len) != 0){
84625+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
84626 BUGPRINT("c2u Didn't work\n");
84627 ret = -EFAULT;
84628 break;
84629@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84630 goto out;
84631 tmp.valid_hooks = t->valid_hooks;
84632
84633- if (copy_to_user(user, &tmp, *len) != 0) {
84634+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84635 ret = -EFAULT;
84636 break;
84637 }
84638@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84639 tmp.entries_size = t->table->entries_size;
84640 tmp.valid_hooks = t->table->valid_hooks;
84641
84642- if (copy_to_user(user, &tmp, *len) != 0) {
84643+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84644 ret = -EFAULT;
84645 break;
84646 }
84647diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
84648index a376ec1..1fbd6be 100644
84649--- a/net/caif/cfctrl.c
84650+++ b/net/caif/cfctrl.c
84651@@ -10,6 +10,7 @@
84652 #include <linux/spinlock.h>
84653 #include <linux/slab.h>
84654 #include <linux/pkt_sched.h>
84655+#include <linux/sched.h>
84656 #include <net/caif/caif_layer.h>
84657 #include <net/caif/cfpkt.h>
84658 #include <net/caif/cfctrl.h>
84659@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
84660 memset(&dev_info, 0, sizeof(dev_info));
84661 dev_info.id = 0xff;
84662 cfsrvl_init(&this->serv, 0, &dev_info, false);
84663- atomic_set(&this->req_seq_no, 1);
84664- atomic_set(&this->rsp_seq_no, 1);
84665+ atomic_set_unchecked(&this->req_seq_no, 1);
84666+ atomic_set_unchecked(&this->rsp_seq_no, 1);
84667 this->serv.layer.receive = cfctrl_recv;
84668 sprintf(this->serv.layer.name, "ctrl");
84669 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
84670@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
84671 struct cfctrl_request_info *req)
84672 {
84673 spin_lock_bh(&ctrl->info_list_lock);
84674- atomic_inc(&ctrl->req_seq_no);
84675- req->sequence_no = atomic_read(&ctrl->req_seq_no);
84676+ atomic_inc_unchecked(&ctrl->req_seq_no);
84677+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
84678 list_add_tail(&req->list, &ctrl->list);
84679 spin_unlock_bh(&ctrl->info_list_lock);
84680 }
84681@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
84682 if (p != first)
84683 pr_warn("Requests are not received in order\n");
84684
84685- atomic_set(&ctrl->rsp_seq_no,
84686+ atomic_set_unchecked(&ctrl->rsp_seq_no,
84687 p->sequence_no);
84688 list_del(&p->list);
84689 goto out;
84690diff --git a/net/can/af_can.c b/net/can/af_can.c
84691index ddac1ee..3ee0a78 100644
84692--- a/net/can/af_can.c
84693+++ b/net/can/af_can.c
84694@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
84695 };
84696
84697 /* notifier block for netdevice event */
84698-static struct notifier_block can_netdev_notifier __read_mostly = {
84699+static struct notifier_block can_netdev_notifier = {
84700 .notifier_call = can_notifier,
84701 };
84702
84703diff --git a/net/can/gw.c b/net/can/gw.c
84704index 574dda78e..3d2b3da 100644
84705--- a/net/can/gw.c
84706+++ b/net/can/gw.c
84707@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
84708 MODULE_ALIAS("can-gw");
84709
84710 static HLIST_HEAD(cgw_list);
84711-static struct notifier_block notifier;
84712
84713 static struct kmem_cache *cgw_cache __read_mostly;
84714
84715@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
84716 return err;
84717 }
84718
84719+static struct notifier_block notifier = {
84720+ .notifier_call = cgw_notifier
84721+};
84722+
84723 static __init int cgw_module_init(void)
84724 {
84725 printk(banner);
84726@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
84727 return -ENOMEM;
84728
84729 /* set notifier */
84730- notifier.notifier_call = cgw_notifier;
84731 register_netdevice_notifier(&notifier);
84732
84733 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
84734diff --git a/net/compat.c b/net/compat.c
84735index 79ae884..17c5c09 100644
84736--- a/net/compat.c
84737+++ b/net/compat.c
84738@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
84739 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
84740 __get_user(kmsg->msg_flags, &umsg->msg_flags))
84741 return -EFAULT;
84742- kmsg->msg_name = compat_ptr(tmp1);
84743- kmsg->msg_iov = compat_ptr(tmp2);
84744- kmsg->msg_control = compat_ptr(tmp3);
84745+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
84746+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
84747+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
84748 return 0;
84749 }
84750
84751@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84752
84753 if (kern_msg->msg_namelen) {
84754 if (mode == VERIFY_READ) {
84755- int err = move_addr_to_kernel(kern_msg->msg_name,
84756+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
84757 kern_msg->msg_namelen,
84758 kern_address);
84759 if (err < 0)
84760@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84761 kern_msg->msg_name = NULL;
84762
84763 tot_len = iov_from_user_compat_to_kern(kern_iov,
84764- (struct compat_iovec __user *)kern_msg->msg_iov,
84765+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
84766 kern_msg->msg_iovlen);
84767 if (tot_len >= 0)
84768 kern_msg->msg_iov = kern_iov;
84769@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84770
84771 #define CMSG_COMPAT_FIRSTHDR(msg) \
84772 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
84773- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
84774+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
84775 (struct compat_cmsghdr __user *)NULL)
84776
84777 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
84778 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
84779 (ucmlen) <= (unsigned long) \
84780 ((mhdr)->msg_controllen - \
84781- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
84782+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
84783
84784 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
84785 struct compat_cmsghdr __user *cmsg, int cmsg_len)
84786 {
84787 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
84788- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
84789+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
84790 msg->msg_controllen)
84791 return NULL;
84792 return (struct compat_cmsghdr __user *)ptr;
84793@@ -219,7 +219,7 @@ Efault:
84794
84795 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
84796 {
84797- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84798+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84799 struct compat_cmsghdr cmhdr;
84800 struct compat_timeval ctv;
84801 struct compat_timespec cts[3];
84802@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
84803
84804 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
84805 {
84806- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84807+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84808 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
84809 int fdnum = scm->fp->count;
84810 struct file **fp = scm->fp->fp;
84811@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
84812 return -EFAULT;
84813 old_fs = get_fs();
84814 set_fs(KERNEL_DS);
84815- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
84816+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
84817 set_fs(old_fs);
84818
84819 return err;
84820@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
84821 len = sizeof(ktime);
84822 old_fs = get_fs();
84823 set_fs(KERNEL_DS);
84824- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
84825+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
84826 set_fs(old_fs);
84827
84828 if (!err) {
84829@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84830 case MCAST_JOIN_GROUP:
84831 case MCAST_LEAVE_GROUP:
84832 {
84833- struct compat_group_req __user *gr32 = (void *)optval;
84834+ struct compat_group_req __user *gr32 = (void __user *)optval;
84835 struct group_req __user *kgr =
84836 compat_alloc_user_space(sizeof(struct group_req));
84837 u32 interface;
84838@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84839 case MCAST_BLOCK_SOURCE:
84840 case MCAST_UNBLOCK_SOURCE:
84841 {
84842- struct compat_group_source_req __user *gsr32 = (void *)optval;
84843+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
84844 struct group_source_req __user *kgsr = compat_alloc_user_space(
84845 sizeof(struct group_source_req));
84846 u32 interface;
84847@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84848 }
84849 case MCAST_MSFILTER:
84850 {
84851- struct compat_group_filter __user *gf32 = (void *)optval;
84852+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84853 struct group_filter __user *kgf;
84854 u32 interface, fmode, numsrc;
84855
84856@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
84857 char __user *optval, int __user *optlen,
84858 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
84859 {
84860- struct compat_group_filter __user *gf32 = (void *)optval;
84861+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84862 struct group_filter __user *kgf;
84863 int __user *koptlen;
84864 u32 interface, fmode, numsrc;
84865@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
84866
84867 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
84868 return -EINVAL;
84869- if (copy_from_user(a, args, nas[call]))
84870+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
84871 return -EFAULT;
84872 a0 = a[0];
84873 a1 = a[1];
84874diff --git a/net/core/datagram.c b/net/core/datagram.c
84875index 368f9c3..f82d4a3 100644
84876--- a/net/core/datagram.c
84877+++ b/net/core/datagram.c
84878@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
84879 }
84880
84881 kfree_skb(skb);
84882- atomic_inc(&sk->sk_drops);
84883+ atomic_inc_unchecked(&sk->sk_drops);
84884 sk_mem_reclaim_partial(sk);
84885
84886 return err;
84887diff --git a/net/core/dev.c b/net/core/dev.c
84888index 1339f77..6fd27dc 100644
84889--- a/net/core/dev.c
84890+++ b/net/core/dev.c
84891@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
84892 if (no_module && capable(CAP_NET_ADMIN))
84893 no_module = request_module("netdev-%s", name);
84894 if (no_module && capable(CAP_SYS_MODULE)) {
84895+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84896+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
84897+#else
84898 if (!request_module("%s", name))
84899 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
84900 name);
84901+#endif
84902 }
84903 }
84904 EXPORT_SYMBOL(dev_load);
84905@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84906 {
84907 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
84908 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
84909- atomic_long_inc(&dev->rx_dropped);
84910+ atomic_long_inc_unchecked(&dev->rx_dropped);
84911 kfree_skb(skb);
84912 return NET_RX_DROP;
84913 }
84914@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84915 nf_reset(skb);
84916
84917 if (unlikely(!is_skb_forwardable(dev, skb))) {
84918- atomic_long_inc(&dev->rx_dropped);
84919+ atomic_long_inc_unchecked(&dev->rx_dropped);
84920 kfree_skb(skb);
84921 return NET_RX_DROP;
84922 }
84923@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
84924
84925 struct dev_gso_cb {
84926 void (*destructor)(struct sk_buff *skb);
84927-};
84928+} __no_const;
84929
84930 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
84931
84932@@ -3053,7 +3057,7 @@ enqueue:
84933
84934 local_irq_restore(flags);
84935
84936- atomic_long_inc(&skb->dev->rx_dropped);
84937+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84938 kfree_skb(skb);
84939 return NET_RX_DROP;
84940 }
84941@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
84942 }
84943 EXPORT_SYMBOL(netif_rx_ni);
84944
84945-static void net_tx_action(struct softirq_action *h)
84946+static void net_tx_action(void)
84947 {
84948 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84949
84950@@ -3457,7 +3461,7 @@ ncls:
84951 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
84952 } else {
84953 drop:
84954- atomic_long_inc(&skb->dev->rx_dropped);
84955+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84956 kfree_skb(skb);
84957 /* Jamal, now you will not able to escape explaining
84958 * me how you were going to use this. :-)
84959@@ -4040,7 +4044,7 @@ void netif_napi_del(struct napi_struct *napi)
84960 }
84961 EXPORT_SYMBOL(netif_napi_del);
84962
84963-static void net_rx_action(struct softirq_action *h)
84964+static void net_rx_action(void)
84965 {
84966 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84967 unsigned long time_limit = jiffies + 2;
84968@@ -4524,8 +4528,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
84969 else
84970 seq_printf(seq, "%04x", ntohs(pt->type));
84971
84972+#ifdef CONFIG_GRKERNSEC_HIDESYM
84973+ seq_printf(seq, " %-8s %p\n",
84974+ pt->dev ? pt->dev->name : "", NULL);
84975+#else
84976 seq_printf(seq, " %-8s %pF\n",
84977 pt->dev ? pt->dev->name : "", pt->func);
84978+#endif
84979 }
84980
84981 return 0;
84982@@ -6097,7 +6106,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
84983 } else {
84984 netdev_stats_to_stats64(storage, &dev->stats);
84985 }
84986- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
84987+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
84988 return storage;
84989 }
84990 EXPORT_SYMBOL(dev_get_stats);
84991diff --git a/net/core/flow.c b/net/core/flow.c
84992index b0901ee..7d3c2ca 100644
84993--- a/net/core/flow.c
84994+++ b/net/core/flow.c
84995@@ -61,7 +61,7 @@ struct flow_cache {
84996 struct timer_list rnd_timer;
84997 };
84998
84999-atomic_t flow_cache_genid = ATOMIC_INIT(0);
85000+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
85001 EXPORT_SYMBOL(flow_cache_genid);
85002 static struct flow_cache flow_cache_global;
85003 static struct kmem_cache *flow_cachep __read_mostly;
85004@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
85005
85006 static int flow_entry_valid(struct flow_cache_entry *fle)
85007 {
85008- if (atomic_read(&flow_cache_genid) != fle->genid)
85009+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
85010 return 0;
85011 if (fle->object && !fle->object->ops->check(fle->object))
85012 return 0;
85013@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
85014 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
85015 fcp->hash_count++;
85016 }
85017- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
85018+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
85019 flo = fle->object;
85020 if (!flo)
85021 goto ret_object;
85022@@ -280,7 +280,7 @@ nocache:
85023 }
85024 flo = resolver(net, key, family, dir, flo, ctx);
85025 if (fle) {
85026- fle->genid = atomic_read(&flow_cache_genid);
85027+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
85028 if (!IS_ERR(flo))
85029 fle->object = flo;
85030 else
85031diff --git a/net/core/iovec.c b/net/core/iovec.c
85032index 7e7aeb0..2a998cb 100644
85033--- a/net/core/iovec.c
85034+++ b/net/core/iovec.c
85035@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85036 if (m->msg_namelen) {
85037 if (mode == VERIFY_READ) {
85038 void __user *namep;
85039- namep = (void __user __force *) m->msg_name;
85040+ namep = (void __force_user *) m->msg_name;
85041 err = move_addr_to_kernel(namep, m->msg_namelen,
85042 address);
85043 if (err < 0)
85044@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85045 }
85046
85047 size = m->msg_iovlen * sizeof(struct iovec);
85048- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
85049+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
85050 return -EFAULT;
85051
85052 m->msg_iov = iov;
85053diff --git a/net/core/neighbour.c b/net/core/neighbour.c
85054index c815f28..e6403f2 100644
85055--- a/net/core/neighbour.c
85056+++ b/net/core/neighbour.c
85057@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
85058 size_t *lenp, loff_t *ppos)
85059 {
85060 int size, ret;
85061- ctl_table tmp = *ctl;
85062+ ctl_table_no_const tmp = *ctl;
85063
85064 tmp.extra1 = &zero;
85065 tmp.extra2 = &unres_qlen_max;
85066diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
85067index 28c5f5a..7edf2e2 100644
85068--- a/net/core/net-sysfs.c
85069+++ b/net/core/net-sysfs.c
85070@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
85071 }
85072 EXPORT_SYMBOL(netdev_class_remove_file);
85073
85074-int netdev_kobject_init(void)
85075+int __init netdev_kobject_init(void)
85076 {
85077 kobj_ns_type_register(&net_ns_type_operations);
85078 return class_register(&net_class);
85079diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
85080index 8acce01..2e306bb 100644
85081--- a/net/core/net_namespace.c
85082+++ b/net/core/net_namespace.c
85083@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
85084 int error;
85085 LIST_HEAD(net_exit_list);
85086
85087- list_add_tail(&ops->list, list);
85088+ pax_list_add_tail((struct list_head *)&ops->list, list);
85089 if (ops->init || (ops->id && ops->size)) {
85090 for_each_net(net) {
85091 error = ops_init(ops, net);
85092@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
85093
85094 out_undo:
85095 /* If I have an error cleanup all namespaces I initialized */
85096- list_del(&ops->list);
85097+ pax_list_del((struct list_head *)&ops->list);
85098 ops_exit_list(ops, &net_exit_list);
85099 ops_free_list(ops, &net_exit_list);
85100 return error;
85101@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
85102 struct net *net;
85103 LIST_HEAD(net_exit_list);
85104
85105- list_del(&ops->list);
85106+ pax_list_del((struct list_head *)&ops->list);
85107 for_each_net(net)
85108 list_add_tail(&net->exit_list, &net_exit_list);
85109 ops_exit_list(ops, &net_exit_list);
85110@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
85111 mutex_lock(&net_mutex);
85112 error = register_pernet_operations(&pernet_list, ops);
85113 if (!error && (first_device == &pernet_list))
85114- first_device = &ops->list;
85115+ first_device = (struct list_head *)&ops->list;
85116 mutex_unlock(&net_mutex);
85117 return error;
85118 }
85119diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
85120index 798f920..e2261f5 100644
85121--- a/net/core/rtnetlink.c
85122+++ b/net/core/rtnetlink.c
85123@@ -58,7 +58,7 @@ struct rtnl_link {
85124 rtnl_doit_func doit;
85125 rtnl_dumpit_func dumpit;
85126 rtnl_calcit_func calcit;
85127-};
85128+} __no_const;
85129
85130 static DEFINE_MUTEX(rtnl_mutex);
85131
85132@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
85133 if (rtnl_link_ops_get(ops->kind))
85134 return -EEXIST;
85135
85136- if (!ops->dellink)
85137- ops->dellink = unregister_netdevice_queue;
85138+ if (!ops->dellink) {
85139+ pax_open_kernel();
85140+ *(void **)&ops->dellink = unregister_netdevice_queue;
85141+ pax_close_kernel();
85142+ }
85143
85144- list_add_tail(&ops->list, &link_ops);
85145+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
85146 return 0;
85147 }
85148 EXPORT_SYMBOL_GPL(__rtnl_link_register);
85149@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
85150 for_each_net(net) {
85151 __rtnl_kill_links(net, ops);
85152 }
85153- list_del(&ops->list);
85154+ pax_list_del((struct list_head *)&ops->list);
85155 }
85156 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
85157
85158diff --git a/net/core/scm.c b/net/core/scm.c
85159index 905dcc6..14ee2d6 100644
85160--- a/net/core/scm.c
85161+++ b/net/core/scm.c
85162@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
85163 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85164 {
85165 struct cmsghdr __user *cm
85166- = (__force struct cmsghdr __user *)msg->msg_control;
85167+ = (struct cmsghdr __force_user *)msg->msg_control;
85168 struct cmsghdr cmhdr;
85169 int cmlen = CMSG_LEN(len);
85170 int err;
85171@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85172 err = -EFAULT;
85173 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
85174 goto out;
85175- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
85176+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
85177 goto out;
85178 cmlen = CMSG_SPACE(len);
85179 if (msg->msg_controllen < cmlen)
85180@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
85181 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85182 {
85183 struct cmsghdr __user *cm
85184- = (__force struct cmsghdr __user*)msg->msg_control;
85185+ = (struct cmsghdr __force_user *)msg->msg_control;
85186
85187 int fdmax = 0;
85188 int fdnum = scm->fp->count;
85189@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85190 if (fdnum < fdmax)
85191 fdmax = fdnum;
85192
85193- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
85194+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
85195 i++, cmfptr++)
85196 {
85197 struct socket *sock;
85198diff --git a/net/core/sock.c b/net/core/sock.c
85199index bc131d4..029e378 100644
85200--- a/net/core/sock.c
85201+++ b/net/core/sock.c
85202@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85203 struct sk_buff_head *list = &sk->sk_receive_queue;
85204
85205 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
85206- atomic_inc(&sk->sk_drops);
85207+ atomic_inc_unchecked(&sk->sk_drops);
85208 trace_sock_rcvqueue_full(sk, skb);
85209 return -ENOMEM;
85210 }
85211@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85212 return err;
85213
85214 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
85215- atomic_inc(&sk->sk_drops);
85216+ atomic_inc_unchecked(&sk->sk_drops);
85217 return -ENOBUFS;
85218 }
85219
85220@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85221 skb_dst_force(skb);
85222
85223 spin_lock_irqsave(&list->lock, flags);
85224- skb->dropcount = atomic_read(&sk->sk_drops);
85225+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
85226 __skb_queue_tail(list, skb);
85227 spin_unlock_irqrestore(&list->lock, flags);
85228
85229@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85230 skb->dev = NULL;
85231
85232 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
85233- atomic_inc(&sk->sk_drops);
85234+ atomic_inc_unchecked(&sk->sk_drops);
85235 goto discard_and_relse;
85236 }
85237 if (nested)
85238@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85239 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
85240 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
85241 bh_unlock_sock(sk);
85242- atomic_inc(&sk->sk_drops);
85243+ atomic_inc_unchecked(&sk->sk_drops);
85244 goto discard_and_relse;
85245 }
85246
85247@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85248 struct timeval tm;
85249 } v;
85250
85251- int lv = sizeof(int);
85252- int len;
85253+ unsigned int lv = sizeof(int);
85254+ unsigned int len;
85255
85256 if (get_user(len, optlen))
85257 return -EFAULT;
85258- if (len < 0)
85259+ if (len > INT_MAX)
85260 return -EINVAL;
85261
85262 memset(&v, 0, sizeof(v));
85263@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85264
85265 case SO_PEERNAME:
85266 {
85267- char address[128];
85268+ char address[_K_SS_MAXSIZE];
85269
85270 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
85271 return -ENOTCONN;
85272- if (lv < len)
85273+ if (lv < len || sizeof address < len)
85274 return -EINVAL;
85275 if (copy_to_user(optval, address, len))
85276 return -EFAULT;
85277@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85278
85279 if (len > lv)
85280 len = lv;
85281- if (copy_to_user(optval, &v, len))
85282+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
85283 return -EFAULT;
85284 lenout:
85285 if (put_user(len, optlen))
85286@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
85287 */
85288 smp_wmb();
85289 atomic_set(&sk->sk_refcnt, 1);
85290- atomic_set(&sk->sk_drops, 0);
85291+ atomic_set_unchecked(&sk->sk_drops, 0);
85292 }
85293 EXPORT_SYMBOL(sock_init_data);
85294
85295diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
85296index 750f44f..922399c 100644
85297--- a/net/core/sock_diag.c
85298+++ b/net/core/sock_diag.c
85299@@ -9,26 +9,33 @@
85300 #include <linux/inet_diag.h>
85301 #include <linux/sock_diag.h>
85302
85303-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
85304+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
85305 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
85306 static DEFINE_MUTEX(sock_diag_table_mutex);
85307
85308 int sock_diag_check_cookie(void *sk, __u32 *cookie)
85309 {
85310+#ifndef CONFIG_GRKERNSEC_HIDESYM
85311 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
85312 cookie[1] != INET_DIAG_NOCOOKIE) &&
85313 ((u32)(unsigned long)sk != cookie[0] ||
85314 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
85315 return -ESTALE;
85316 else
85317+#endif
85318 return 0;
85319 }
85320 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
85321
85322 void sock_diag_save_cookie(void *sk, __u32 *cookie)
85323 {
85324+#ifdef CONFIG_GRKERNSEC_HIDESYM
85325+ cookie[0] = 0;
85326+ cookie[1] = 0;
85327+#else
85328 cookie[0] = (u32)(unsigned long)sk;
85329 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
85330+#endif
85331 }
85332 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
85333
85334@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
85335 mutex_lock(&sock_diag_table_mutex);
85336 if (sock_diag_handlers[hndl->family])
85337 err = -EBUSY;
85338- else
85339+ else {
85340+ pax_open_kernel();
85341 sock_diag_handlers[hndl->family] = hndl;
85342+ pax_close_kernel();
85343+ }
85344 mutex_unlock(&sock_diag_table_mutex);
85345
85346 return err;
85347@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
85348
85349 mutex_lock(&sock_diag_table_mutex);
85350 BUG_ON(sock_diag_handlers[family] != hnld);
85351+ pax_open_kernel();
85352 sock_diag_handlers[family] = NULL;
85353+ pax_close_kernel();
85354 mutex_unlock(&sock_diag_table_mutex);
85355 }
85356 EXPORT_SYMBOL_GPL(sock_diag_unregister);
85357
85358-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
85359-{
85360- if (sock_diag_handlers[family] == NULL)
85361- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85362- NETLINK_SOCK_DIAG, family);
85363-
85364- mutex_lock(&sock_diag_table_mutex);
85365- return sock_diag_handlers[family];
85366-}
85367-
85368-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
85369-{
85370- mutex_unlock(&sock_diag_table_mutex);
85371-}
85372-
85373 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85374 {
85375 int err;
85376@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85377 if (req->sdiag_family >= AF_MAX)
85378 return -EINVAL;
85379
85380- hndl = sock_diag_lock_handler(req->sdiag_family);
85381+ if (sock_diag_handlers[req->sdiag_family] == NULL)
85382+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85383+ NETLINK_SOCK_DIAG, req->sdiag_family);
85384+
85385+ mutex_lock(&sock_diag_table_mutex);
85386+ hndl = sock_diag_handlers[req->sdiag_family];
85387 if (hndl == NULL)
85388 err = -ENOENT;
85389 else
85390 err = hndl->dump(skb, nlh);
85391- sock_diag_unlock_handler(hndl);
85392+ mutex_unlock(&sock_diag_table_mutex);
85393
85394 return err;
85395 }
85396diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
85397index d1b0804..4aed0a5 100644
85398--- a/net/core/sysctl_net_core.c
85399+++ b/net/core/sysctl_net_core.c
85400@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
85401 {
85402 unsigned int orig_size, size;
85403 int ret, i;
85404- ctl_table tmp = {
85405+ ctl_table_no_const tmp = {
85406 .data = &size,
85407 .maxlen = sizeof(size),
85408 .mode = table->mode
85409@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
85410
85411 static __net_init int sysctl_core_net_init(struct net *net)
85412 {
85413- struct ctl_table *tbl;
85414+ ctl_table_no_const *tbl = NULL;
85415
85416 net->core.sysctl_somaxconn = SOMAXCONN;
85417
85418- tbl = netns_core_table;
85419 if (!net_eq(net, &init_net)) {
85420- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
85421+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
85422 if (tbl == NULL)
85423 goto err_dup;
85424
85425@@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
85426 if (net->user_ns != &init_user_ns) {
85427 tbl[0].procname = NULL;
85428 }
85429- }
85430-
85431- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85432+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85433+ } else
85434+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
85435 if (net->core.sysctl_hdr == NULL)
85436 goto err_reg;
85437
85438 return 0;
85439
85440 err_reg:
85441- if (tbl != netns_core_table)
85442+ if (tbl)
85443 kfree(tbl);
85444 err_dup:
85445 return -ENOMEM;
85446@@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
85447 kfree(tbl);
85448 }
85449
85450-static __net_initdata struct pernet_operations sysctl_core_ops = {
85451+static __net_initconst struct pernet_operations sysctl_core_ops = {
85452 .init = sysctl_core_net_init,
85453 .exit = sysctl_core_net_exit,
85454 };
85455diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
85456index 307c322..78a4c6f 100644
85457--- a/net/decnet/af_decnet.c
85458+++ b/net/decnet/af_decnet.c
85459@@ -468,6 +468,7 @@ static struct proto dn_proto = {
85460 .sysctl_rmem = sysctl_decnet_rmem,
85461 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
85462 .obj_size = sizeof(struct dn_sock),
85463+ .slab_flags = SLAB_USERCOPY,
85464 };
85465
85466 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
85467diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
85468index a55eecc..dd8428c 100644
85469--- a/net/decnet/sysctl_net_decnet.c
85470+++ b/net/decnet/sysctl_net_decnet.c
85471@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
85472
85473 if (len > *lenp) len = *lenp;
85474
85475- if (copy_to_user(buffer, addr, len))
85476+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
85477 return -EFAULT;
85478
85479 *lenp = len;
85480@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
85481
85482 if (len > *lenp) len = *lenp;
85483
85484- if (copy_to_user(buffer, devname, len))
85485+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
85486 return -EFAULT;
85487
85488 *lenp = len;
85489diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
85490index fcf104e..95552d4 100644
85491--- a/net/ipv4/af_inet.c
85492+++ b/net/ipv4/af_inet.c
85493@@ -1717,13 +1717,9 @@ static int __init inet_init(void)
85494
85495 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
85496
85497- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
85498- if (!sysctl_local_reserved_ports)
85499- goto out;
85500-
85501 rc = proto_register(&tcp_prot, 1);
85502 if (rc)
85503- goto out_free_reserved_ports;
85504+ goto out;
85505
85506 rc = proto_register(&udp_prot, 1);
85507 if (rc)
85508@@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
85509 proto_unregister(&udp_prot);
85510 out_unregister_tcp_proto:
85511 proto_unregister(&tcp_prot);
85512-out_free_reserved_ports:
85513- kfree(sysctl_local_reserved_ports);
85514 goto out;
85515 }
85516
85517diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
85518index a69b4e4..dbccba5 100644
85519--- a/net/ipv4/ah4.c
85520+++ b/net/ipv4/ah4.c
85521@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
85522 return;
85523
85524 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85525- atomic_inc(&flow_cache_genid);
85526+ atomic_inc_unchecked(&flow_cache_genid);
85527 rt_genid_bump(net);
85528
85529 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
85530diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
85531index a8e4f26..25e5f40 100644
85532--- a/net/ipv4/devinet.c
85533+++ b/net/ipv4/devinet.c
85534@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
85535 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
85536 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
85537
85538-static struct devinet_sysctl_table {
85539+static const struct devinet_sysctl_table {
85540 struct ctl_table_header *sysctl_header;
85541 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
85542 } devinet_sysctl = {
85543@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
85544 int err;
85545 struct ipv4_devconf *all, *dflt;
85546 #ifdef CONFIG_SYSCTL
85547- struct ctl_table *tbl = ctl_forward_entry;
85548+ ctl_table_no_const *tbl = NULL;
85549 struct ctl_table_header *forw_hdr;
85550 #endif
85551
85552@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
85553 goto err_alloc_dflt;
85554
85555 #ifdef CONFIG_SYSCTL
85556- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
85557+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
85558 if (tbl == NULL)
85559 goto err_alloc_ctl;
85560
85561@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
85562 goto err_reg_dflt;
85563
85564 err = -ENOMEM;
85565- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85566+ if (!net_eq(net, &init_net))
85567+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85568+ else
85569+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
85570 if (forw_hdr == NULL)
85571 goto err_reg_ctl;
85572 net->ipv4.forw_hdr = forw_hdr;
85573@@ -1935,8 +1938,7 @@ err_reg_ctl:
85574 err_reg_dflt:
85575 __devinet_sysctl_unregister(all);
85576 err_reg_all:
85577- if (tbl != ctl_forward_entry)
85578- kfree(tbl);
85579+ kfree(tbl);
85580 err_alloc_ctl:
85581 #endif
85582 if (dflt != &ipv4_devconf_dflt)
85583diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
85584index 3b4f0cd..8cb864c 100644
85585--- a/net/ipv4/esp4.c
85586+++ b/net/ipv4/esp4.c
85587@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
85588 return;
85589
85590 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85591- atomic_inc(&flow_cache_genid);
85592+ atomic_inc_unchecked(&flow_cache_genid);
85593 rt_genid_bump(net);
85594
85595 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
85596diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
85597index 5cd75e2..f57ef39 100644
85598--- a/net/ipv4/fib_frontend.c
85599+++ b/net/ipv4/fib_frontend.c
85600@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
85601 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85602 fib_sync_up(dev);
85603 #endif
85604- atomic_inc(&net->ipv4.dev_addr_genid);
85605+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85606 rt_cache_flush(dev_net(dev));
85607 break;
85608 case NETDEV_DOWN:
85609 fib_del_ifaddr(ifa, NULL);
85610- atomic_inc(&net->ipv4.dev_addr_genid);
85611+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85612 if (ifa->ifa_dev->ifa_list == NULL) {
85613 /* Last address was deleted from this interface.
85614 * Disable IP.
85615@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
85616 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85617 fib_sync_up(dev);
85618 #endif
85619- atomic_inc(&net->ipv4.dev_addr_genid);
85620+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85621 rt_cache_flush(net);
85622 break;
85623 case NETDEV_DOWN:
85624diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
85625index 4797a80..2bd54e9 100644
85626--- a/net/ipv4/fib_semantics.c
85627+++ b/net/ipv4/fib_semantics.c
85628@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
85629 nh->nh_saddr = inet_select_addr(nh->nh_dev,
85630 nh->nh_gw,
85631 nh->nh_parent->fib_scope);
85632- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
85633+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
85634
85635 return nh->nh_saddr;
85636 }
85637diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
85638index d0670f0..744ac80 100644
85639--- a/net/ipv4/inet_connection_sock.c
85640+++ b/net/ipv4/inet_connection_sock.c
85641@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
85642 .range = { 32768, 61000 },
85643 };
85644
85645-unsigned long *sysctl_local_reserved_ports;
85646+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
85647 EXPORT_SYMBOL(sysctl_local_reserved_ports);
85648
85649 void inet_get_local_port_range(int *low, int *high)
85650diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
85651index fa3ae81..0dbe6b8 100644
85652--- a/net/ipv4/inet_hashtables.c
85653+++ b/net/ipv4/inet_hashtables.c
85654@@ -18,12 +18,15 @@
85655 #include <linux/sched.h>
85656 #include <linux/slab.h>
85657 #include <linux/wait.h>
85658+#include <linux/security.h>
85659
85660 #include <net/inet_connection_sock.h>
85661 #include <net/inet_hashtables.h>
85662 #include <net/secure_seq.h>
85663 #include <net/ip.h>
85664
85665+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
85666+
85667 /*
85668 * Allocate and initialize a new local port bind bucket.
85669 * The bindhash mutex for snum's hash chain must be held here.
85670@@ -540,6 +543,8 @@ ok:
85671 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
85672 spin_unlock(&head->lock);
85673
85674+ gr_update_task_in_ip_table(current, inet_sk(sk));
85675+
85676 if (tw) {
85677 inet_twsk_deschedule(tw, death_row);
85678 while (twrefcnt) {
85679diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
85680index 000e3d2..5472da3 100644
85681--- a/net/ipv4/inetpeer.c
85682+++ b/net/ipv4/inetpeer.c
85683@@ -503,8 +503,8 @@ relookup:
85684 if (p) {
85685 p->daddr = *daddr;
85686 atomic_set(&p->refcnt, 1);
85687- atomic_set(&p->rid, 0);
85688- atomic_set(&p->ip_id_count,
85689+ atomic_set_unchecked(&p->rid, 0);
85690+ atomic_set_unchecked(&p->ip_id_count,
85691 (daddr->family == AF_INET) ?
85692 secure_ip_id(daddr->addr.a4) :
85693 secure_ipv6_id(daddr->addr.a6));
85694diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
85695index eb9d63a..31c5372 100644
85696--- a/net/ipv4/ip_fragment.c
85697+++ b/net/ipv4/ip_fragment.c
85698@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
85699 return 0;
85700
85701 start = qp->rid;
85702- end = atomic_inc_return(&peer->rid);
85703+ end = atomic_inc_return_unchecked(&peer->rid);
85704 qp->rid = end;
85705
85706 rc = qp->q.fragments && (end - start) > max;
85707@@ -789,12 +789,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
85708
85709 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85710 {
85711- struct ctl_table *table;
85712+ ctl_table_no_const *table = NULL;
85713 struct ctl_table_header *hdr;
85714
85715- table = ip4_frags_ns_ctl_table;
85716 if (!net_eq(net, &init_net)) {
85717- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85718+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85719 if (table == NULL)
85720 goto err_alloc;
85721
85722@@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85723 /* Don't export sysctls to unprivileged users */
85724 if (net->user_ns != &init_user_ns)
85725 table[0].procname = NULL;
85726- }
85727+ hdr = register_net_sysctl(net, "net/ipv4", table);
85728+ } else
85729+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
85730
85731- hdr = register_net_sysctl(net, "net/ipv4", table);
85732 if (hdr == NULL)
85733 goto err_reg;
85734
85735@@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85736 return 0;
85737
85738 err_reg:
85739- if (!net_eq(net, &init_net))
85740- kfree(table);
85741+ kfree(table);
85742 err_alloc:
85743 return -ENOMEM;
85744 }
85745diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
85746index e81b1ca..6f3b5b9 100644
85747--- a/net/ipv4/ip_gre.c
85748+++ b/net/ipv4/ip_gre.c
85749@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85750 module_param(log_ecn_error, bool, 0644);
85751 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85752
85753-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85754+static struct rtnl_link_ops ipgre_link_ops;
85755 static int ipgre_tunnel_init(struct net_device *dev);
85756 static void ipgre_tunnel_setup(struct net_device *dev);
85757 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85758@@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85759 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85760 };
85761
85762-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85763+static struct rtnl_link_ops ipgre_link_ops = {
85764 .kind = "gre",
85765 .maxtype = IFLA_GRE_MAX,
85766 .policy = ipgre_policy,
85767@@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85768 .fill_info = ipgre_fill_info,
85769 };
85770
85771-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85772+static struct rtnl_link_ops ipgre_tap_ops = {
85773 .kind = "gretap",
85774 .maxtype = IFLA_GRE_MAX,
85775 .policy = ipgre_policy,
85776diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85777index d9c4f11..02b82db 100644
85778--- a/net/ipv4/ip_sockglue.c
85779+++ b/net/ipv4/ip_sockglue.c
85780@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85781 len = min_t(unsigned int, len, opt->optlen);
85782 if (put_user(len, optlen))
85783 return -EFAULT;
85784- if (copy_to_user(optval, opt->__data, len))
85785+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85786+ copy_to_user(optval, opt->__data, len))
85787 return -EFAULT;
85788 return 0;
85789 }
85790@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85791 if (sk->sk_type != SOCK_STREAM)
85792 return -ENOPROTOOPT;
85793
85794- msg.msg_control = optval;
85795+ msg.msg_control = (void __force_kernel *)optval;
85796 msg.msg_controllen = len;
85797 msg.msg_flags = flags;
85798
85799diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85800index c3a4233..1412161 100644
85801--- a/net/ipv4/ip_vti.c
85802+++ b/net/ipv4/ip_vti.c
85803@@ -47,7 +47,7 @@
85804 #define HASH_SIZE 16
85805 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
85806
85807-static struct rtnl_link_ops vti_link_ops __read_mostly;
85808+static struct rtnl_link_ops vti_link_ops;
85809
85810 static int vti_net_id __read_mostly;
85811 struct vti_net {
85812@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
85813 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
85814 };
85815
85816-static struct rtnl_link_ops vti_link_ops __read_mostly = {
85817+static struct rtnl_link_ops vti_link_ops = {
85818 .kind = "vti",
85819 .maxtype = IFLA_VTI_MAX,
85820 .policy = vti_policy,
85821diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
85822index 9a46dae..5f793a0 100644
85823--- a/net/ipv4/ipcomp.c
85824+++ b/net/ipv4/ipcomp.c
85825@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
85826 return;
85827
85828 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85829- atomic_inc(&flow_cache_genid);
85830+ atomic_inc_unchecked(&flow_cache_genid);
85831 rt_genid_bump(net);
85832
85833 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
85834diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
85835index a2e50ae..e152b7c 100644
85836--- a/net/ipv4/ipconfig.c
85837+++ b/net/ipv4/ipconfig.c
85838@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
85839
85840 mm_segment_t oldfs = get_fs();
85841 set_fs(get_ds());
85842- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85843+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85844 set_fs(oldfs);
85845 return res;
85846 }
85847@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
85848
85849 mm_segment_t oldfs = get_fs();
85850 set_fs(get_ds());
85851- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85852+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85853 set_fs(oldfs);
85854 return res;
85855 }
85856@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
85857
85858 mm_segment_t oldfs = get_fs();
85859 set_fs(get_ds());
85860- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
85861+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
85862 set_fs(oldfs);
85863 return res;
85864 }
85865diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
85866index 191fc24..1b3b804 100644
85867--- a/net/ipv4/ipip.c
85868+++ b/net/ipv4/ipip.c
85869@@ -138,7 +138,7 @@ struct ipip_net {
85870 static int ipip_tunnel_init(struct net_device *dev);
85871 static void ipip_tunnel_setup(struct net_device *dev);
85872 static void ipip_dev_free(struct net_device *dev);
85873-static struct rtnl_link_ops ipip_link_ops __read_mostly;
85874+static struct rtnl_link_ops ipip_link_ops;
85875
85876 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
85877 struct rtnl_link_stats64 *tot)
85878@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
85879 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
85880 };
85881
85882-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
85883+static struct rtnl_link_ops ipip_link_ops = {
85884 .kind = "ipip",
85885 .maxtype = IFLA_IPTUN_MAX,
85886 .policy = ipip_policy,
85887diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
85888index 3ea4127..849297b 100644
85889--- a/net/ipv4/netfilter/arp_tables.c
85890+++ b/net/ipv4/netfilter/arp_tables.c
85891@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
85892 #endif
85893
85894 static int get_info(struct net *net, void __user *user,
85895- const int *len, int compat)
85896+ int len, int compat)
85897 {
85898 char name[XT_TABLE_MAXNAMELEN];
85899 struct xt_table *t;
85900 int ret;
85901
85902- if (*len != sizeof(struct arpt_getinfo)) {
85903- duprintf("length %u != %Zu\n", *len,
85904+ if (len != sizeof(struct arpt_getinfo)) {
85905+ duprintf("length %u != %Zu\n", len,
85906 sizeof(struct arpt_getinfo));
85907 return -EINVAL;
85908 }
85909@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
85910 info.size = private->size;
85911 strcpy(info.name, name);
85912
85913- if (copy_to_user(user, &info, *len) != 0)
85914+ if (copy_to_user(user, &info, len) != 0)
85915 ret = -EFAULT;
85916 else
85917 ret = 0;
85918@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
85919
85920 switch (cmd) {
85921 case ARPT_SO_GET_INFO:
85922- ret = get_info(sock_net(sk), user, len, 1);
85923+ ret = get_info(sock_net(sk), user, *len, 1);
85924 break;
85925 case ARPT_SO_GET_ENTRIES:
85926 ret = compat_get_entries(sock_net(sk), user, len);
85927@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
85928
85929 switch (cmd) {
85930 case ARPT_SO_GET_INFO:
85931- ret = get_info(sock_net(sk), user, len, 0);
85932+ ret = get_info(sock_net(sk), user, *len, 0);
85933 break;
85934
85935 case ARPT_SO_GET_ENTRIES:
85936diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
85937index 17c5e06..1b91206 100644
85938--- a/net/ipv4/netfilter/ip_tables.c
85939+++ b/net/ipv4/netfilter/ip_tables.c
85940@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
85941 #endif
85942
85943 static int get_info(struct net *net, void __user *user,
85944- const int *len, int compat)
85945+ int len, int compat)
85946 {
85947 char name[XT_TABLE_MAXNAMELEN];
85948 struct xt_table *t;
85949 int ret;
85950
85951- if (*len != sizeof(struct ipt_getinfo)) {
85952- duprintf("length %u != %zu\n", *len,
85953+ if (len != sizeof(struct ipt_getinfo)) {
85954+ duprintf("length %u != %zu\n", len,
85955 sizeof(struct ipt_getinfo));
85956 return -EINVAL;
85957 }
85958@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
85959 info.size = private->size;
85960 strcpy(info.name, name);
85961
85962- if (copy_to_user(user, &info, *len) != 0)
85963+ if (copy_to_user(user, &info, len) != 0)
85964 ret = -EFAULT;
85965 else
85966 ret = 0;
85967@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85968
85969 switch (cmd) {
85970 case IPT_SO_GET_INFO:
85971- ret = get_info(sock_net(sk), user, len, 1);
85972+ ret = get_info(sock_net(sk), user, *len, 1);
85973 break;
85974 case IPT_SO_GET_ENTRIES:
85975 ret = compat_get_entries(sock_net(sk), user, len);
85976@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85977
85978 switch (cmd) {
85979 case IPT_SO_GET_INFO:
85980- ret = get_info(sock_net(sk), user, len, 0);
85981+ ret = get_info(sock_net(sk), user, *len, 0);
85982 break;
85983
85984 case IPT_SO_GET_ENTRIES:
85985diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
85986index dc454cc..5bb917f 100644
85987--- a/net/ipv4/ping.c
85988+++ b/net/ipv4/ping.c
85989@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
85990 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85991 0, sock_i_ino(sp),
85992 atomic_read(&sp->sk_refcnt), sp,
85993- atomic_read(&sp->sk_drops), len);
85994+ atomic_read_unchecked(&sp->sk_drops), len);
85995 }
85996
85997 static int ping_seq_show(struct seq_file *seq, void *v)
85998diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
85999index 6f08991..55867ad 100644
86000--- a/net/ipv4/raw.c
86001+++ b/net/ipv4/raw.c
86002@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
86003 int raw_rcv(struct sock *sk, struct sk_buff *skb)
86004 {
86005 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
86006- atomic_inc(&sk->sk_drops);
86007+ atomic_inc_unchecked(&sk->sk_drops);
86008 kfree_skb(skb);
86009 return NET_RX_DROP;
86010 }
86011@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
86012
86013 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
86014 {
86015+ struct icmp_filter filter;
86016+
86017 if (optlen > sizeof(struct icmp_filter))
86018 optlen = sizeof(struct icmp_filter);
86019- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
86020+ if (copy_from_user(&filter, optval, optlen))
86021 return -EFAULT;
86022+ raw_sk(sk)->filter = filter;
86023 return 0;
86024 }
86025
86026 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
86027 {
86028 int len, ret = -EFAULT;
86029+ struct icmp_filter filter;
86030
86031 if (get_user(len, optlen))
86032 goto out;
86033@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
86034 if (len > sizeof(struct icmp_filter))
86035 len = sizeof(struct icmp_filter);
86036 ret = -EFAULT;
86037- if (put_user(len, optlen) ||
86038- copy_to_user(optval, &raw_sk(sk)->filter, len))
86039+ filter = raw_sk(sk)->filter;
86040+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
86041 goto out;
86042 ret = 0;
86043 out: return ret;
86044@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86045 0, 0L, 0,
86046 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86047 0, sock_i_ino(sp),
86048- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86049+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86050 }
86051
86052 static int raw_seq_show(struct seq_file *seq, void *v)
86053diff --git a/net/ipv4/route.c b/net/ipv4/route.c
86054index a0fcc47..32e2c89 100644
86055--- a/net/ipv4/route.c
86056+++ b/net/ipv4/route.c
86057@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
86058 .maxlen = sizeof(int),
86059 .mode = 0200,
86060 .proc_handler = ipv4_sysctl_rtcache_flush,
86061+ .extra1 = &init_net,
86062 },
86063 { },
86064 };
86065
86066 static __net_init int sysctl_route_net_init(struct net *net)
86067 {
86068- struct ctl_table *tbl;
86069+ ctl_table_no_const *tbl = NULL;
86070
86071- tbl = ipv4_route_flush_table;
86072 if (!net_eq(net, &init_net)) {
86073- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86074+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86075 if (tbl == NULL)
86076 goto err_dup;
86077
86078 /* Don't export sysctls to unprivileged users */
86079 if (net->user_ns != &init_user_ns)
86080 tbl[0].procname = NULL;
86081- }
86082- tbl[0].extra1 = net;
86083+ tbl[0].extra1 = net;
86084+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86085+ } else
86086+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
86087
86088- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86089 if (net->ipv4.route_hdr == NULL)
86090 goto err_reg;
86091 return 0;
86092
86093 err_reg:
86094- if (tbl != ipv4_route_flush_table)
86095- kfree(tbl);
86096+ kfree(tbl);
86097 err_dup:
86098 return -ENOMEM;
86099 }
86100@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
86101
86102 static __net_init int rt_genid_init(struct net *net)
86103 {
86104- atomic_set(&net->rt_genid, 0);
86105+ atomic_set_unchecked(&net->rt_genid, 0);
86106 get_random_bytes(&net->ipv4.dev_addr_genid,
86107 sizeof(net->ipv4.dev_addr_genid));
86108 return 0;
86109diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
86110index d84400b..62e066e 100644
86111--- a/net/ipv4/sysctl_net_ipv4.c
86112+++ b/net/ipv4/sysctl_net_ipv4.c
86113@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
86114 {
86115 int ret;
86116 int range[2];
86117- ctl_table tmp = {
86118+ ctl_table_no_const tmp = {
86119 .data = &range,
86120 .maxlen = sizeof(range),
86121 .mode = table->mode,
86122@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
86123 int ret;
86124 gid_t urange[2];
86125 kgid_t low, high;
86126- ctl_table tmp = {
86127+ ctl_table_no_const tmp = {
86128 .data = &urange,
86129 .maxlen = sizeof(urange),
86130 .mode = table->mode,
86131@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
86132 void __user *buffer, size_t *lenp, loff_t *ppos)
86133 {
86134 char val[TCP_CA_NAME_MAX];
86135- ctl_table tbl = {
86136+ ctl_table_no_const tbl = {
86137 .data = val,
86138 .maxlen = TCP_CA_NAME_MAX,
86139 };
86140@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
86141 void __user *buffer, size_t *lenp,
86142 loff_t *ppos)
86143 {
86144- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
86145+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
86146 int ret;
86147
86148 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86149@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
86150 void __user *buffer, size_t *lenp,
86151 loff_t *ppos)
86152 {
86153- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
86154+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
86155 int ret;
86156
86157 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86158@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86159 struct mem_cgroup *memcg;
86160 #endif
86161
86162- ctl_table tmp = {
86163+ ctl_table_no_const tmp = {
86164 .data = &vec,
86165 .maxlen = sizeof(vec),
86166 .mode = ctl->mode,
86167 };
86168
86169 if (!write) {
86170- ctl->data = &net->ipv4.sysctl_tcp_mem;
86171- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
86172+ ctl_table_no_const tcp_mem = *ctl;
86173+
86174+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
86175+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
86176 }
86177
86178 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
86179@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86180 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
86181 size_t *lenp, loff_t *ppos)
86182 {
86183- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86184+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86185 struct tcp_fastopen_context *ctxt;
86186 int ret;
86187 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
86188@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
86189 },
86190 {
86191 .procname = "ip_local_reserved_ports",
86192- .data = NULL, /* initialized in sysctl_ipv4_init */
86193+ .data = sysctl_local_reserved_ports,
86194 .maxlen = 65536,
86195 .mode = 0644,
86196 .proc_handler = proc_do_large_bitmap,
86197@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
86198
86199 static __net_init int ipv4_sysctl_init_net(struct net *net)
86200 {
86201- struct ctl_table *table;
86202+ ctl_table_no_const *table = NULL;
86203
86204- table = ipv4_net_table;
86205 if (!net_eq(net, &init_net)) {
86206- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
86207+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
86208 if (table == NULL)
86209 goto err_alloc;
86210
86211@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
86212
86213 tcp_init_mem(net);
86214
86215- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86216+ if (!net_eq(net, &init_net))
86217+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86218+ else
86219+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
86220 if (net->ipv4.ipv4_hdr == NULL)
86221 goto err_reg;
86222
86223 return 0;
86224
86225 err_reg:
86226- if (!net_eq(net, &init_net))
86227- kfree(table);
86228+ kfree(table);
86229 err_alloc:
86230 return -ENOMEM;
86231 }
86232@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
86233 static __init int sysctl_ipv4_init(void)
86234 {
86235 struct ctl_table_header *hdr;
86236- struct ctl_table *i;
86237-
86238- for (i = ipv4_table; i->procname; i++) {
86239- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
86240- i->data = sysctl_local_reserved_ports;
86241- break;
86242- }
86243- }
86244- if (!i->procname)
86245- return -EINVAL;
86246
86247 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
86248 if (hdr == NULL)
86249diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
86250index 66702d3..31ff8f9 100644
86251--- a/net/ipv4/tcp_input.c
86252+++ b/net/ipv4/tcp_input.c
86253@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
86254 * simplifies code)
86255 */
86256 static void
86257-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86258+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86259 struct sk_buff *head, struct sk_buff *tail,
86260 u32 start, u32 end)
86261 {
86262@@ -5850,6 +5850,7 @@ discard:
86263 tcp_paws_reject(&tp->rx_opt, 0))
86264 goto discard_and_undo;
86265
86266+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
86267 if (th->syn) {
86268 /* We see SYN without ACK. It is attempt of
86269 * simultaneous connect with crossed SYNs.
86270@@ -5900,6 +5901,7 @@ discard:
86271 goto discard;
86272 #endif
86273 }
86274+#endif
86275 /* "fifth, if neither of the SYN or RST bits is set then
86276 * drop the segment and return."
86277 */
86278@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
86279 goto discard;
86280
86281 if (th->syn) {
86282- if (th->fin)
86283+ if (th->fin || th->urg || th->psh)
86284 goto discard;
86285 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
86286 return 1;
86287diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
86288index eadb693..e8f7251 100644
86289--- a/net/ipv4/tcp_ipv4.c
86290+++ b/net/ipv4/tcp_ipv4.c
86291@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
86292 EXPORT_SYMBOL(sysctl_tcp_low_latency);
86293
86294
86295+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86296+extern int grsec_enable_blackhole;
86297+#endif
86298+
86299 #ifdef CONFIG_TCP_MD5SIG
86300 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
86301 __be32 daddr, __be32 saddr, const struct tcphdr *th);
86302@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
86303 return 0;
86304
86305 reset:
86306+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86307+ if (!grsec_enable_blackhole)
86308+#endif
86309 tcp_v4_send_reset(rsk, skb);
86310 discard:
86311 kfree_skb(skb);
86312@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
86313 TCP_SKB_CB(skb)->sacked = 0;
86314
86315 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86316- if (!sk)
86317+ if (!sk) {
86318+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86319+ ret = 1;
86320+#endif
86321 goto no_tcp_socket;
86322-
86323+ }
86324 process:
86325- if (sk->sk_state == TCP_TIME_WAIT)
86326+ if (sk->sk_state == TCP_TIME_WAIT) {
86327+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86328+ ret = 2;
86329+#endif
86330 goto do_time_wait;
86331+ }
86332
86333 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
86334 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86335@@ -2050,6 +2064,10 @@ no_tcp_socket:
86336 bad_packet:
86337 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86338 } else {
86339+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86340+ if (!grsec_enable_blackhole || (ret == 1 &&
86341+ (skb->dev->flags & IFF_LOOPBACK)))
86342+#endif
86343 tcp_v4_send_reset(NULL, skb);
86344 }
86345
86346diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
86347index f35f2df..ccb5ca6 100644
86348--- a/net/ipv4/tcp_minisocks.c
86349+++ b/net/ipv4/tcp_minisocks.c
86350@@ -27,6 +27,10 @@
86351 #include <net/inet_common.h>
86352 #include <net/xfrm.h>
86353
86354+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86355+extern int grsec_enable_blackhole;
86356+#endif
86357+
86358 int sysctl_tcp_syncookies __read_mostly = 1;
86359 EXPORT_SYMBOL(sysctl_tcp_syncookies);
86360
86361@@ -742,7 +746,10 @@ embryonic_reset:
86362 * avoid becoming vulnerable to outside attack aiming at
86363 * resetting legit local connections.
86364 */
86365- req->rsk_ops->send_reset(sk, skb);
86366+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86367+ if (!grsec_enable_blackhole)
86368+#endif
86369+ req->rsk_ops->send_reset(sk, skb);
86370 } else if (fastopen) { /* received a valid RST pkt */
86371 reqsk_fastopen_remove(sk, req, true);
86372 tcp_reset(sk);
86373diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
86374index 4526fe6..1a34e43 100644
86375--- a/net/ipv4/tcp_probe.c
86376+++ b/net/ipv4/tcp_probe.c
86377@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
86378 if (cnt + width >= len)
86379 break;
86380
86381- if (copy_to_user(buf + cnt, tbuf, width))
86382+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
86383 return -EFAULT;
86384 cnt += width;
86385 }
86386diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
86387index b78aac3..e18230b 100644
86388--- a/net/ipv4/tcp_timer.c
86389+++ b/net/ipv4/tcp_timer.c
86390@@ -22,6 +22,10 @@
86391 #include <linux/gfp.h>
86392 #include <net/tcp.h>
86393
86394+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86395+extern int grsec_lastack_retries;
86396+#endif
86397+
86398 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
86399 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
86400 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
86401@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
86402 }
86403 }
86404
86405+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86406+ if ((sk->sk_state == TCP_LAST_ACK) &&
86407+ (grsec_lastack_retries > 0) &&
86408+ (grsec_lastack_retries < retry_until))
86409+ retry_until = grsec_lastack_retries;
86410+#endif
86411+
86412 if (retransmits_timed_out(sk, retry_until,
86413 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
86414 /* Has it gone just too far? */
86415diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
86416index 1f4d405..3524677 100644
86417--- a/net/ipv4/udp.c
86418+++ b/net/ipv4/udp.c
86419@@ -87,6 +87,7 @@
86420 #include <linux/types.h>
86421 #include <linux/fcntl.h>
86422 #include <linux/module.h>
86423+#include <linux/security.h>
86424 #include <linux/socket.h>
86425 #include <linux/sockios.h>
86426 #include <linux/igmp.h>
86427@@ -111,6 +112,10 @@
86428 #include <trace/events/skb.h>
86429 #include "udp_impl.h"
86430
86431+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86432+extern int grsec_enable_blackhole;
86433+#endif
86434+
86435 struct udp_table udp_table __read_mostly;
86436 EXPORT_SYMBOL(udp_table);
86437
86438@@ -569,6 +574,9 @@ found:
86439 return s;
86440 }
86441
86442+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
86443+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
86444+
86445 /*
86446 * This routine is called by the ICMP module when it gets some
86447 * sort of error condition. If err < 0 then the socket should
86448@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
86449 dport = usin->sin_port;
86450 if (dport == 0)
86451 return -EINVAL;
86452+
86453+ err = gr_search_udp_sendmsg(sk, usin);
86454+ if (err)
86455+ return err;
86456 } else {
86457 if (sk->sk_state != TCP_ESTABLISHED)
86458 return -EDESTADDRREQ;
86459+
86460+ err = gr_search_udp_sendmsg(sk, NULL);
86461+ if (err)
86462+ return err;
86463+
86464 daddr = inet->inet_daddr;
86465 dport = inet->inet_dport;
86466 /* Open fast path for connected socket.
86467@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
86468 udp_lib_checksum_complete(skb)) {
86469 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86470 IS_UDPLITE(sk));
86471- atomic_inc(&sk->sk_drops);
86472+ atomic_inc_unchecked(&sk->sk_drops);
86473 __skb_unlink(skb, rcvq);
86474 __skb_queue_tail(&list_kill, skb);
86475 }
86476@@ -1194,6 +1211,10 @@ try_again:
86477 if (!skb)
86478 goto out;
86479
86480+ err = gr_search_udp_recvmsg(sk, skb);
86481+ if (err)
86482+ goto out_free;
86483+
86484 ulen = skb->len - sizeof(struct udphdr);
86485 copied = len;
86486 if (copied > ulen)
86487@@ -1227,7 +1248,7 @@ try_again:
86488 if (unlikely(err)) {
86489 trace_kfree_skb(skb, udp_recvmsg);
86490 if (!peeked) {
86491- atomic_inc(&sk->sk_drops);
86492+ atomic_inc_unchecked(&sk->sk_drops);
86493 UDP_INC_STATS_USER(sock_net(sk),
86494 UDP_MIB_INERRORS, is_udplite);
86495 }
86496@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86497
86498 drop:
86499 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86500- atomic_inc(&sk->sk_drops);
86501+ atomic_inc_unchecked(&sk->sk_drops);
86502 kfree_skb(skb);
86503 return -1;
86504 }
86505@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86506 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86507
86508 if (!skb1) {
86509- atomic_inc(&sk->sk_drops);
86510+ atomic_inc_unchecked(&sk->sk_drops);
86511 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86512 IS_UDPLITE(sk));
86513 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86514@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86515 goto csum_error;
86516
86517 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86518+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86519+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86520+#endif
86521 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
86522
86523 /*
86524@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
86525 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86526 0, sock_i_ino(sp),
86527 atomic_read(&sp->sk_refcnt), sp,
86528- atomic_read(&sp->sk_drops), len);
86529+ atomic_read_unchecked(&sp->sk_drops), len);
86530 }
86531
86532 int udp4_seq_show(struct seq_file *seq, void *v)
86533diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
86534index 1b5d8cb..ffb0833 100644
86535--- a/net/ipv6/addrconf.c
86536+++ b/net/ipv6/addrconf.c
86537@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
86538 p.iph.ihl = 5;
86539 p.iph.protocol = IPPROTO_IPV6;
86540 p.iph.ttl = 64;
86541- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
86542+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
86543
86544 if (ops->ndo_do_ioctl) {
86545 mm_segment_t oldfs = get_fs();
86546@@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
86547 int *valp = ctl->data;
86548 int val = *valp;
86549 loff_t pos = *ppos;
86550- ctl_table lctl;
86551+ ctl_table_no_const lctl;
86552 int ret;
86553
86554 /*
86555@@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
86556 int *valp = ctl->data;
86557 int val = *valp;
86558 loff_t pos = *ppos;
86559- ctl_table lctl;
86560+ ctl_table_no_const lctl;
86561 int ret;
86562
86563 /*
86564diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
86565index fff5bdd..15194fb 100644
86566--- a/net/ipv6/icmp.c
86567+++ b/net/ipv6/icmp.c
86568@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
86569
86570 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
86571 {
86572- struct ctl_table *table;
86573+ ctl_table_no_const *table;
86574
86575 table = kmemdup(ipv6_icmp_table_template,
86576 sizeof(ipv6_icmp_table_template),
86577diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
86578index 131dd09..f7ed64f 100644
86579--- a/net/ipv6/ip6_gre.c
86580+++ b/net/ipv6/ip6_gre.c
86581@@ -73,7 +73,7 @@ struct ip6gre_net {
86582 struct net_device *fb_tunnel_dev;
86583 };
86584
86585-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
86586+static struct rtnl_link_ops ip6gre_link_ops;
86587 static int ip6gre_tunnel_init(struct net_device *dev);
86588 static void ip6gre_tunnel_setup(struct net_device *dev);
86589 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
86590@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
86591 }
86592
86593
86594-static struct inet6_protocol ip6gre_protocol __read_mostly = {
86595+static struct inet6_protocol ip6gre_protocol = {
86596 .handler = ip6gre_rcv,
86597 .err_handler = ip6gre_err,
86598 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
86599@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
86600 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
86601 };
86602
86603-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86604+static struct rtnl_link_ops ip6gre_link_ops = {
86605 .kind = "ip6gre",
86606 .maxtype = IFLA_GRE_MAX,
86607 .policy = ip6gre_policy,
86608@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86609 .fill_info = ip6gre_fill_info,
86610 };
86611
86612-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
86613+static struct rtnl_link_ops ip6gre_tap_ops = {
86614 .kind = "ip6gretap",
86615 .maxtype = IFLA_GRE_MAX,
86616 .policy = ip6gre_policy,
86617diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
86618index a14f28b..b4b8956 100644
86619--- a/net/ipv6/ip6_tunnel.c
86620+++ b/net/ipv6/ip6_tunnel.c
86621@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
86622
86623 static int ip6_tnl_dev_init(struct net_device *dev);
86624 static void ip6_tnl_dev_setup(struct net_device *dev);
86625-static struct rtnl_link_ops ip6_link_ops __read_mostly;
86626+static struct rtnl_link_ops ip6_link_ops;
86627
86628 static int ip6_tnl_net_id __read_mostly;
86629 struct ip6_tnl_net {
86630@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
86631 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
86632 };
86633
86634-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
86635+static struct rtnl_link_ops ip6_link_ops = {
86636 .kind = "ip6tnl",
86637 .maxtype = IFLA_IPTUN_MAX,
86638 .policy = ip6_tnl_policy,
86639diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
86640index d1e2e8e..51c19ae 100644
86641--- a/net/ipv6/ipv6_sockglue.c
86642+++ b/net/ipv6/ipv6_sockglue.c
86643@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
86644 if (sk->sk_type != SOCK_STREAM)
86645 return -ENOPROTOOPT;
86646
86647- msg.msg_control = optval;
86648+ msg.msg_control = (void __force_kernel *)optval;
86649 msg.msg_controllen = len;
86650 msg.msg_flags = flags;
86651
86652diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
86653index 125a90d..2a11f36 100644
86654--- a/net/ipv6/netfilter/ip6_tables.c
86655+++ b/net/ipv6/netfilter/ip6_tables.c
86656@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
86657 #endif
86658
86659 static int get_info(struct net *net, void __user *user,
86660- const int *len, int compat)
86661+ int len, int compat)
86662 {
86663 char name[XT_TABLE_MAXNAMELEN];
86664 struct xt_table *t;
86665 int ret;
86666
86667- if (*len != sizeof(struct ip6t_getinfo)) {
86668- duprintf("length %u != %zu\n", *len,
86669+ if (len != sizeof(struct ip6t_getinfo)) {
86670+ duprintf("length %u != %zu\n", len,
86671 sizeof(struct ip6t_getinfo));
86672 return -EINVAL;
86673 }
86674@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
86675 info.size = private->size;
86676 strcpy(info.name, name);
86677
86678- if (copy_to_user(user, &info, *len) != 0)
86679+ if (copy_to_user(user, &info, len) != 0)
86680 ret = -EFAULT;
86681 else
86682 ret = 0;
86683@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86684
86685 switch (cmd) {
86686 case IP6T_SO_GET_INFO:
86687- ret = get_info(sock_net(sk), user, len, 1);
86688+ ret = get_info(sock_net(sk), user, *len, 1);
86689 break;
86690 case IP6T_SO_GET_ENTRIES:
86691 ret = compat_get_entries(sock_net(sk), user, len);
86692@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86693
86694 switch (cmd) {
86695 case IP6T_SO_GET_INFO:
86696- ret = get_info(sock_net(sk), user, len, 0);
86697+ ret = get_info(sock_net(sk), user, *len, 0);
86698 break;
86699
86700 case IP6T_SO_GET_ENTRIES:
86701diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
86702index 3dacecc..2939087 100644
86703--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
86704+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
86705@@ -87,12 +87,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
86706
86707 static int nf_ct_frag6_sysctl_register(struct net *net)
86708 {
86709- struct ctl_table *table;
86710+ ctl_table_no_const *table = NULL;
86711 struct ctl_table_header *hdr;
86712
86713- table = nf_ct_frag6_sysctl_table;
86714 if (!net_eq(net, &init_net)) {
86715- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
86716+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
86717 GFP_KERNEL);
86718 if (table == NULL)
86719 goto err_alloc;
86720@@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86721 table[0].data = &net->ipv6.frags.high_thresh;
86722 table[1].data = &net->ipv6.frags.low_thresh;
86723 table[2].data = &net->ipv6.frags.timeout;
86724- }
86725-
86726- hdr = register_net_sysctl(net, "net/netfilter", table);
86727+ hdr = register_net_sysctl(net, "net/netfilter", table);
86728+ } else
86729+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
86730 if (hdr == NULL)
86731 goto err_reg;
86732
86733@@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86734 return 0;
86735
86736 err_reg:
86737- if (!net_eq(net, &init_net))
86738- kfree(table);
86739+ kfree(table);
86740 err_alloc:
86741 return -ENOMEM;
86742 }
86743diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
86744index 70fa814..d70c28c 100644
86745--- a/net/ipv6/raw.c
86746+++ b/net/ipv6/raw.c
86747@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
86748 {
86749 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86750 skb_checksum_complete(skb)) {
86751- atomic_inc(&sk->sk_drops);
86752+ atomic_inc_unchecked(&sk->sk_drops);
86753 kfree_skb(skb);
86754 return NET_RX_DROP;
86755 }
86756@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86757 struct raw6_sock *rp = raw6_sk(sk);
86758
86759 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86760- atomic_inc(&sk->sk_drops);
86761+ atomic_inc_unchecked(&sk->sk_drops);
86762 kfree_skb(skb);
86763 return NET_RX_DROP;
86764 }
86765@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86766
86767 if (inet->hdrincl) {
86768 if (skb_checksum_complete(skb)) {
86769- atomic_inc(&sk->sk_drops);
86770+ atomic_inc_unchecked(&sk->sk_drops);
86771 kfree_skb(skb);
86772 return NET_RX_DROP;
86773 }
86774@@ -604,7 +604,7 @@ out:
86775 return err;
86776 }
86777
86778-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86779+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86780 struct flowi6 *fl6, struct dst_entry **dstp,
86781 unsigned int flags)
86782 {
86783@@ -916,12 +916,15 @@ do_confirm:
86784 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86785 char __user *optval, int optlen)
86786 {
86787+ struct icmp6_filter filter;
86788+
86789 switch (optname) {
86790 case ICMPV6_FILTER:
86791 if (optlen > sizeof(struct icmp6_filter))
86792 optlen = sizeof(struct icmp6_filter);
86793- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86794+ if (copy_from_user(&filter, optval, optlen))
86795 return -EFAULT;
86796+ raw6_sk(sk)->filter = filter;
86797 return 0;
86798 default:
86799 return -ENOPROTOOPT;
86800@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86801 char __user *optval, int __user *optlen)
86802 {
86803 int len;
86804+ struct icmp6_filter filter;
86805
86806 switch (optname) {
86807 case ICMPV6_FILTER:
86808@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86809 len = sizeof(struct icmp6_filter);
86810 if (put_user(len, optlen))
86811 return -EFAULT;
86812- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
86813+ filter = raw6_sk(sk)->filter;
86814+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
86815 return -EFAULT;
86816 return 0;
86817 default:
86818@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86819 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86820 0,
86821 sock_i_ino(sp),
86822- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86823+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86824 }
86825
86826 static int raw6_seq_show(struct seq_file *seq, void *v)
86827diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
86828index e5253ec..0410257 100644
86829--- a/net/ipv6/reassembly.c
86830+++ b/net/ipv6/reassembly.c
86831@@ -604,12 +604,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
86832
86833 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86834 {
86835- struct ctl_table *table;
86836+ ctl_table_no_const *table = NULL;
86837 struct ctl_table_header *hdr;
86838
86839- table = ip6_frags_ns_ctl_table;
86840 if (!net_eq(net, &init_net)) {
86841- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86842+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86843 if (table == NULL)
86844 goto err_alloc;
86845
86846@@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86847 /* Don't export sysctls to unprivileged users */
86848 if (net->user_ns != &init_user_ns)
86849 table[0].procname = NULL;
86850- }
86851+ hdr = register_net_sysctl(net, "net/ipv6", table);
86852+ } else
86853+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
86854
86855- hdr = register_net_sysctl(net, "net/ipv6", table);
86856 if (hdr == NULL)
86857 goto err_reg;
86858
86859@@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86860 return 0;
86861
86862 err_reg:
86863- if (!net_eq(net, &init_net))
86864- kfree(table);
86865+ kfree(table);
86866 err_alloc:
86867 return -ENOMEM;
86868 }
86869diff --git a/net/ipv6/route.c b/net/ipv6/route.c
86870index 5845613..3af8fc7 100644
86871--- a/net/ipv6/route.c
86872+++ b/net/ipv6/route.c
86873@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
86874
86875 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
86876 {
86877- struct ctl_table *table;
86878+ ctl_table_no_const *table;
86879
86880 table = kmemdup(ipv6_route_table_template,
86881 sizeof(ipv6_route_table_template),
86882diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
86883index cfba99b..20ca511 100644
86884--- a/net/ipv6/sit.c
86885+++ b/net/ipv6/sit.c
86886@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86887 static int ipip6_tunnel_init(struct net_device *dev);
86888 static void ipip6_tunnel_setup(struct net_device *dev);
86889 static void ipip6_dev_free(struct net_device *dev);
86890-static struct rtnl_link_ops sit_link_ops __read_mostly;
86891+static struct rtnl_link_ops sit_link_ops;
86892
86893 static int sit_net_id __read_mostly;
86894 struct sit_net {
86895@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
86896 #endif
86897 };
86898
86899-static struct rtnl_link_ops sit_link_ops __read_mostly = {
86900+static struct rtnl_link_ops sit_link_ops = {
86901 .kind = "sit",
86902 .maxtype = IFLA_IPTUN_MAX,
86903 .policy = ipip6_policy,
86904diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
86905index e85c48b..b8268d3 100644
86906--- a/net/ipv6/sysctl_net_ipv6.c
86907+++ b/net/ipv6/sysctl_net_ipv6.c
86908@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
86909
86910 static int __net_init ipv6_sysctl_net_init(struct net *net)
86911 {
86912- struct ctl_table *ipv6_table;
86913+ ctl_table_no_const *ipv6_table;
86914 struct ctl_table *ipv6_route_table;
86915 struct ctl_table *ipv6_icmp_table;
86916 int err;
86917diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
86918index 4f435371..5de9da7 100644
86919--- a/net/ipv6/tcp_ipv6.c
86920+++ b/net/ipv6/tcp_ipv6.c
86921@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
86922 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
86923 }
86924
86925+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86926+extern int grsec_enable_blackhole;
86927+#endif
86928+
86929 static void tcp_v6_hash(struct sock *sk)
86930 {
86931 if (sk->sk_state != TCP_CLOSE) {
86932@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
86933 return 0;
86934
86935 reset:
86936+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86937+ if (!grsec_enable_blackhole)
86938+#endif
86939 tcp_v6_send_reset(sk, skb);
86940 discard:
86941 if (opt_skb)
86942@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
86943 TCP_SKB_CB(skb)->sacked = 0;
86944
86945 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86946- if (!sk)
86947+ if (!sk) {
86948+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86949+ ret = 1;
86950+#endif
86951 goto no_tcp_socket;
86952+ }
86953
86954 process:
86955- if (sk->sk_state == TCP_TIME_WAIT)
86956+ if (sk->sk_state == TCP_TIME_WAIT) {
86957+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86958+ ret = 2;
86959+#endif
86960 goto do_time_wait;
86961+ }
86962
86963 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
86964 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86965@@ -1568,6 +1583,10 @@ no_tcp_socket:
86966 bad_packet:
86967 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86968 } else {
86969+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86970+ if (!grsec_enable_blackhole || (ret == 1 &&
86971+ (skb->dev->flags & IFF_LOOPBACK)))
86972+#endif
86973 tcp_v6_send_reset(NULL, skb);
86974 }
86975
86976diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
86977index fb08329..2d6919e 100644
86978--- a/net/ipv6/udp.c
86979+++ b/net/ipv6/udp.c
86980@@ -51,6 +51,10 @@
86981 #include <trace/events/skb.h>
86982 #include "udp_impl.h"
86983
86984+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86985+extern int grsec_enable_blackhole;
86986+#endif
86987+
86988 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
86989 {
86990 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
86991@@ -395,7 +399,7 @@ try_again:
86992 if (unlikely(err)) {
86993 trace_kfree_skb(skb, udpv6_recvmsg);
86994 if (!peeked) {
86995- atomic_inc(&sk->sk_drops);
86996+ atomic_inc_unchecked(&sk->sk_drops);
86997 if (is_udp4)
86998 UDP_INC_STATS_USER(sock_net(sk),
86999 UDP_MIB_INERRORS,
87000@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87001 return rc;
87002 drop:
87003 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87004- atomic_inc(&sk->sk_drops);
87005+ atomic_inc_unchecked(&sk->sk_drops);
87006 kfree_skb(skb);
87007 return -1;
87008 }
87009@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87010 if (likely(skb1 == NULL))
87011 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87012 if (!skb1) {
87013- atomic_inc(&sk->sk_drops);
87014+ atomic_inc_unchecked(&sk->sk_drops);
87015 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87016 IS_UDPLITE(sk));
87017 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87018@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87019 goto discard;
87020
87021 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87022+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87023+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87024+#endif
87025 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
87026
87027 kfree_skb(skb);
87028@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
87029 0,
87030 sock_i_ino(sp),
87031 atomic_read(&sp->sk_refcnt), sp,
87032- atomic_read(&sp->sk_drops));
87033+ atomic_read_unchecked(&sp->sk_drops));
87034 }
87035
87036 int udp6_seq_show(struct seq_file *seq, void *v)
87037diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
87038index b833677..4d04105 100644
87039--- a/net/irda/af_irda.c
87040+++ b/net/irda/af_irda.c
87041@@ -2584,8 +2584,10 @@ bed:
87042 NULL, NULL, NULL);
87043
87044 /* Check if the we got some results */
87045- if (!self->cachedaddr)
87046- return -EAGAIN; /* Didn't find any devices */
87047+ if (!self->cachedaddr) {
87048+ err = -EAGAIN; /* Didn't find any devices */
87049+ goto out;
87050+ }
87051 daddr = self->cachedaddr;
87052 /* Cleanup */
87053 self->cachedaddr = 0;
87054diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
87055index a68c88c..d55b0c5 100644
87056--- a/net/irda/ircomm/ircomm_tty.c
87057+++ b/net/irda/ircomm/ircomm_tty.c
87058@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87059 add_wait_queue(&port->open_wait, &wait);
87060
87061 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
87062- __FILE__, __LINE__, tty->driver->name, port->count);
87063+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87064
87065 spin_lock_irqsave(&port->lock, flags);
87066 if (!tty_hung_up_p(filp)) {
87067 extra_count = 1;
87068- port->count--;
87069+ atomic_dec(&port->count);
87070 }
87071 spin_unlock_irqrestore(&port->lock, flags);
87072 port->blocked_open++;
87073@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87074 }
87075
87076 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
87077- __FILE__, __LINE__, tty->driver->name, port->count);
87078+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87079
87080 schedule();
87081 }
87082@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87083 if (extra_count) {
87084 /* ++ is not atomic, so this should be protected - Jean II */
87085 spin_lock_irqsave(&port->lock, flags);
87086- port->count++;
87087+ atomic_inc(&port->count);
87088 spin_unlock_irqrestore(&port->lock, flags);
87089 }
87090 port->blocked_open--;
87091
87092 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
87093- __FILE__, __LINE__, tty->driver->name, port->count);
87094+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87095
87096 if (!retval)
87097 port->flags |= ASYNC_NORMAL_ACTIVE;
87098@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
87099
87100 /* ++ is not atomic, so this should be protected - Jean II */
87101 spin_lock_irqsave(&self->port.lock, flags);
87102- self->port.count++;
87103+ atomic_inc(&self->port.count);
87104 spin_unlock_irqrestore(&self->port.lock, flags);
87105 tty_port_tty_set(&self->port, tty);
87106
87107 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
87108- self->line, self->port.count);
87109+ self->line, atomic_read(&self->port.count));
87110
87111 /* Not really used by us, but lets do it anyway */
87112 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
87113@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
87114 tty_kref_put(port->tty);
87115 }
87116 port->tty = NULL;
87117- port->count = 0;
87118+ atomic_set(&port->count, 0);
87119 spin_unlock_irqrestore(&port->lock, flags);
87120
87121 wake_up_interruptible(&port->open_wait);
87122@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
87123 seq_putc(m, '\n');
87124
87125 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
87126- seq_printf(m, "Open count: %d\n", self->port.count);
87127+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
87128 seq_printf(m, "Max data size: %d\n", self->max_data_size);
87129 seq_printf(m, "Max header size: %d\n", self->max_header_size);
87130
87131diff --git a/net/irda/iriap.c b/net/irda/iriap.c
87132index e71e85b..29340a9 100644
87133--- a/net/irda/iriap.c
87134+++ b/net/irda/iriap.c
87135@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
87136 /* case CS_ISO_8859_9: */
87137 /* case CS_UNICODE: */
87138 default:
87139- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
87140- __func__, ias_charset_types[charset]);
87141+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
87142+ __func__, charset,
87143+ charset < ARRAY_SIZE(ias_charset_types) ?
87144+ ias_charset_types[charset] :
87145+ "(unknown)");
87146
87147 /* Aborting, close connection! */
87148 iriap_disconnect_request(self);
87149diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
87150index cd6f7a9..e63fe89 100644
87151--- a/net/iucv/af_iucv.c
87152+++ b/net/iucv/af_iucv.c
87153@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
87154
87155 write_lock_bh(&iucv_sk_list.lock);
87156
87157- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
87158+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87159 while (__iucv_get_sock_by_name(name)) {
87160 sprintf(name, "%08x",
87161- atomic_inc_return(&iucv_sk_list.autobind_name));
87162+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87163 }
87164
87165 write_unlock_bh(&iucv_sk_list.lock);
87166diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
87167index df08250..02021fe 100644
87168--- a/net/iucv/iucv.c
87169+++ b/net/iucv/iucv.c
87170@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
87171 return NOTIFY_OK;
87172 }
87173
87174-static struct notifier_block __refdata iucv_cpu_notifier = {
87175+static struct notifier_block iucv_cpu_notifier = {
87176 .notifier_call = iucv_cpu_notify,
87177 };
87178
87179diff --git a/net/key/af_key.c b/net/key/af_key.c
87180index 5b426a6..970032b 100644
87181--- a/net/key/af_key.c
87182+++ b/net/key/af_key.c
87183@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
87184 static u32 get_acqseq(void)
87185 {
87186 u32 res;
87187- static atomic_t acqseq;
87188+ static atomic_unchecked_t acqseq;
87189
87190 do {
87191- res = atomic_inc_return(&acqseq);
87192+ res = atomic_inc_return_unchecked(&acqseq);
87193 } while (!res);
87194 return res;
87195 }
87196diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
87197index 0479c64..d031db6 100644
87198--- a/net/mac80211/cfg.c
87199+++ b/net/mac80211/cfg.c
87200@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
87201 ret = ieee80211_vif_use_channel(sdata, chandef,
87202 IEEE80211_CHANCTX_EXCLUSIVE);
87203 }
87204- } else if (local->open_count == local->monitors) {
87205+ } else if (local_read(&local->open_count) == local->monitors) {
87206 local->_oper_channel = chandef->chan;
87207 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
87208 ieee80211_hw_config(local, 0);
87209@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
87210 else
87211 local->probe_req_reg--;
87212
87213- if (!local->open_count)
87214+ if (!local_read(&local->open_count))
87215 break;
87216
87217 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
87218diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
87219index 2ed065c..948177f 100644
87220--- a/net/mac80211/ieee80211_i.h
87221+++ b/net/mac80211/ieee80211_i.h
87222@@ -28,6 +28,7 @@
87223 #include <net/ieee80211_radiotap.h>
87224 #include <net/cfg80211.h>
87225 #include <net/mac80211.h>
87226+#include <asm/local.h>
87227 #include "key.h"
87228 #include "sta_info.h"
87229 #include "debug.h"
87230@@ -909,7 +910,7 @@ struct ieee80211_local {
87231 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
87232 spinlock_t queue_stop_reason_lock;
87233
87234- int open_count;
87235+ local_t open_count;
87236 int monitors, cooked_mntrs;
87237 /* number of interfaces with corresponding FIF_ flags */
87238 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
87239diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
87240index 8be854e..ad72a69 100644
87241--- a/net/mac80211/iface.c
87242+++ b/net/mac80211/iface.c
87243@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87244 break;
87245 }
87246
87247- if (local->open_count == 0) {
87248+ if (local_read(&local->open_count) == 0) {
87249 res = drv_start(local);
87250 if (res)
87251 goto err_del_bss;
87252@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87253 break;
87254 }
87255
87256- if (local->monitors == 0 && local->open_count == 0) {
87257+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
87258 res = ieee80211_add_virtual_monitor(local);
87259 if (res)
87260 goto err_stop;
87261@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87262 mutex_unlock(&local->mtx);
87263
87264 if (coming_up)
87265- local->open_count++;
87266+ local_inc(&local->open_count);
87267
87268 if (hw_reconf_flags)
87269 ieee80211_hw_config(local, hw_reconf_flags);
87270@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87271 err_del_interface:
87272 drv_remove_interface(local, sdata);
87273 err_stop:
87274- if (!local->open_count)
87275+ if (!local_read(&local->open_count))
87276 drv_stop(local);
87277 err_del_bss:
87278 sdata->bss = NULL;
87279@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87280 }
87281
87282 if (going_down)
87283- local->open_count--;
87284+ local_dec(&local->open_count);
87285
87286 switch (sdata->vif.type) {
87287 case NL80211_IFTYPE_AP_VLAN:
87288@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87289
87290 ieee80211_recalc_ps(local, -1);
87291
87292- if (local->open_count == 0) {
87293+ if (local_read(&local->open_count) == 0) {
87294 if (local->ops->napi_poll)
87295 napi_disable(&local->napi);
87296 ieee80211_clear_tx_pending(local);
87297@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87298 }
87299 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
87300
87301- if (local->monitors == local->open_count && local->monitors > 0)
87302+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
87303 ieee80211_add_virtual_monitor(local);
87304 }
87305
87306diff --git a/net/mac80211/main.c b/net/mac80211/main.c
87307index 1b087ff..bf600e9 100644
87308--- a/net/mac80211/main.c
87309+++ b/net/mac80211/main.c
87310@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
87311 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
87312 IEEE80211_CONF_CHANGE_POWER);
87313
87314- if (changed && local->open_count) {
87315+ if (changed && local_read(&local->open_count)) {
87316 ret = drv_config(local, changed);
87317 /*
87318 * Goal:
87319diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
87320index 79a48f3..5e185c9 100644
87321--- a/net/mac80211/pm.c
87322+++ b/net/mac80211/pm.c
87323@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87324 struct sta_info *sta;
87325 struct ieee80211_chanctx *ctx;
87326
87327- if (!local->open_count)
87328+ if (!local_read(&local->open_count))
87329 goto suspend;
87330
87331 ieee80211_scan_cancel(local);
87332@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87333 cancel_work_sync(&local->dynamic_ps_enable_work);
87334 del_timer_sync(&local->dynamic_ps_timer);
87335
87336- local->wowlan = wowlan && local->open_count;
87337+ local->wowlan = wowlan && local_read(&local->open_count);
87338 if (local->wowlan) {
87339 int err = drv_suspend(local, wowlan);
87340 if (err < 0) {
87341@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87342 mutex_unlock(&local->chanctx_mtx);
87343
87344 /* stop hardware - this must stop RX */
87345- if (local->open_count)
87346+ if (local_read(&local->open_count))
87347 ieee80211_stop_device(local);
87348
87349 suspend:
87350diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
87351index dd88381..eef4dd6 100644
87352--- a/net/mac80211/rate.c
87353+++ b/net/mac80211/rate.c
87354@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
87355
87356 ASSERT_RTNL();
87357
87358- if (local->open_count)
87359+ if (local_read(&local->open_count))
87360 return -EBUSY;
87361
87362 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
87363diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
87364index c97a065..ff61928 100644
87365--- a/net/mac80211/rc80211_pid_debugfs.c
87366+++ b/net/mac80211/rc80211_pid_debugfs.c
87367@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
87368
87369 spin_unlock_irqrestore(&events->lock, status);
87370
87371- if (copy_to_user(buf, pb, p))
87372+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
87373 return -EFAULT;
87374
87375 return p;
87376diff --git a/net/mac80211/util.c b/net/mac80211/util.c
87377index f11e8c5..08d0013 100644
87378--- a/net/mac80211/util.c
87379+++ b/net/mac80211/util.c
87380@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
87381 }
87382 #endif
87383 /* everything else happens only if HW was up & running */
87384- if (!local->open_count)
87385+ if (!local_read(&local->open_count))
87386 goto wake_up;
87387
87388 /*
87389diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
87390index 49e96df..63a51c3 100644
87391--- a/net/netfilter/Kconfig
87392+++ b/net/netfilter/Kconfig
87393@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
87394
87395 To compile it as a module, choose M here. If unsure, say N.
87396
87397+config NETFILTER_XT_MATCH_GRADM
87398+ tristate '"gradm" match support'
87399+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
87400+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
87401+ ---help---
87402+ The gradm match allows to match on grsecurity RBAC being enabled.
87403+ It is useful when iptables rules are applied early on bootup to
87404+ prevent connections to the machine (except from a trusted host)
87405+ while the RBAC system is disabled.
87406+
87407 config NETFILTER_XT_MATCH_HASHLIMIT
87408 tristate '"hashlimit" match support'
87409 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
87410diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
87411index 3259697..54d5393 100644
87412--- a/net/netfilter/Makefile
87413+++ b/net/netfilter/Makefile
87414@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
87415 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
87416 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
87417 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
87418+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
87419 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
87420 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
87421 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
87422diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
87423index 6d6d8f2..a676749 100644
87424--- a/net/netfilter/ipset/ip_set_core.c
87425+++ b/net/netfilter/ipset/ip_set_core.c
87426@@ -1800,7 +1800,7 @@ done:
87427 return ret;
87428 }
87429
87430-static struct nf_sockopt_ops so_set __read_mostly = {
87431+static struct nf_sockopt_ops so_set = {
87432 .pf = PF_INET,
87433 .get_optmin = SO_IP_SET,
87434 .get_optmax = SO_IP_SET + 1,
87435diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
87436index 30e764a..c3b6a9d 100644
87437--- a/net/netfilter/ipvs/ip_vs_conn.c
87438+++ b/net/netfilter/ipvs/ip_vs_conn.c
87439@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
87440 /* Increase the refcnt counter of the dest */
87441 atomic_inc(&dest->refcnt);
87442
87443- conn_flags = atomic_read(&dest->conn_flags);
87444+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
87445 if (cp->protocol != IPPROTO_UDP)
87446 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
87447 flags = cp->flags;
87448@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
87449 atomic_set(&cp->refcnt, 1);
87450
87451 atomic_set(&cp->n_control, 0);
87452- atomic_set(&cp->in_pkts, 0);
87453+ atomic_set_unchecked(&cp->in_pkts, 0);
87454
87455 atomic_inc(&ipvs->conn_count);
87456 if (flags & IP_VS_CONN_F_NO_CPORT)
87457@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
87458
87459 /* Don't drop the entry if its number of incoming packets is not
87460 located in [0, 8] */
87461- i = atomic_read(&cp->in_pkts);
87462+ i = atomic_read_unchecked(&cp->in_pkts);
87463 if (i > 8 || i < 0) return 0;
87464
87465 if (!todrop_rate[i]) return 0;
87466diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
87467index 47edf5a..235b07d 100644
87468--- a/net/netfilter/ipvs/ip_vs_core.c
87469+++ b/net/netfilter/ipvs/ip_vs_core.c
87470@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
87471 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
87472 /* do not touch skb anymore */
87473
87474- atomic_inc(&cp->in_pkts);
87475+ atomic_inc_unchecked(&cp->in_pkts);
87476 ip_vs_conn_put(cp);
87477 return ret;
87478 }
87479@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
87480 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
87481 pkts = sysctl_sync_threshold(ipvs);
87482 else
87483- pkts = atomic_add_return(1, &cp->in_pkts);
87484+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87485
87486 if (ipvs->sync_state & IP_VS_STATE_MASTER)
87487 ip_vs_sync_conn(net, cp, pkts);
87488diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
87489index ec664cb..7f34a77 100644
87490--- a/net/netfilter/ipvs/ip_vs_ctl.c
87491+++ b/net/netfilter/ipvs/ip_vs_ctl.c
87492@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
87493 ip_vs_rs_hash(ipvs, dest);
87494 write_unlock_bh(&ipvs->rs_lock);
87495 }
87496- atomic_set(&dest->conn_flags, conn_flags);
87497+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
87498
87499 /* bind the service */
87500 if (!dest->svc) {
87501@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
87502 * align with netns init in ip_vs_control_net_init()
87503 */
87504
87505-static struct ctl_table vs_vars[] = {
87506+static ctl_table_no_const vs_vars[] __read_only = {
87507 {
87508 .procname = "amemthresh",
87509 .maxlen = sizeof(int),
87510@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87511 " %-7s %-6d %-10d %-10d\n",
87512 &dest->addr.in6,
87513 ntohs(dest->port),
87514- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87515+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87516 atomic_read(&dest->weight),
87517 atomic_read(&dest->activeconns),
87518 atomic_read(&dest->inactconns));
87519@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87520 "%-7s %-6d %-10d %-10d\n",
87521 ntohl(dest->addr.ip),
87522 ntohs(dest->port),
87523- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87524+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87525 atomic_read(&dest->weight),
87526 atomic_read(&dest->activeconns),
87527 atomic_read(&dest->inactconns));
87528@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
87529
87530 entry.addr = dest->addr.ip;
87531 entry.port = dest->port;
87532- entry.conn_flags = atomic_read(&dest->conn_flags);
87533+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
87534 entry.weight = atomic_read(&dest->weight);
87535 entry.u_threshold = dest->u_threshold;
87536 entry.l_threshold = dest->l_threshold;
87537@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
87538 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
87539 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
87540 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
87541- (atomic_read(&dest->conn_flags) &
87542+ (atomic_read_unchecked(&dest->conn_flags) &
87543 IP_VS_CONN_F_FWD_MASK)) ||
87544 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
87545 atomic_read(&dest->weight)) ||
87546@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
87547 {
87548 int idx;
87549 struct netns_ipvs *ipvs = net_ipvs(net);
87550- struct ctl_table *tbl;
87551+ ctl_table_no_const *tbl;
87552
87553 atomic_set(&ipvs->dropentry, 0);
87554 spin_lock_init(&ipvs->dropentry_lock);
87555diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
87556index fdd89b9..bd96aa9 100644
87557--- a/net/netfilter/ipvs/ip_vs_lblc.c
87558+++ b/net/netfilter/ipvs/ip_vs_lblc.c
87559@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
87560 * IPVS LBLC sysctl table
87561 */
87562 #ifdef CONFIG_SYSCTL
87563-static ctl_table vs_vars_table[] = {
87564+static ctl_table_no_const vs_vars_table[] __read_only = {
87565 {
87566 .procname = "lblc_expiration",
87567 .data = NULL,
87568diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
87569index c03b6a3..8ce3681 100644
87570--- a/net/netfilter/ipvs/ip_vs_lblcr.c
87571+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
87572@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
87573 * IPVS LBLCR sysctl table
87574 */
87575
87576-static ctl_table vs_vars_table[] = {
87577+static ctl_table_no_const vs_vars_table[] __read_only = {
87578 {
87579 .procname = "lblcr_expiration",
87580 .data = NULL,
87581diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
87582index 44fd10c..2a163b3 100644
87583--- a/net/netfilter/ipvs/ip_vs_sync.c
87584+++ b/net/netfilter/ipvs/ip_vs_sync.c
87585@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
87586 cp = cp->control;
87587 if (cp) {
87588 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87589- pkts = atomic_add_return(1, &cp->in_pkts);
87590+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87591 else
87592 pkts = sysctl_sync_threshold(ipvs);
87593 ip_vs_sync_conn(net, cp->control, pkts);
87594@@ -758,7 +758,7 @@ control:
87595 if (!cp)
87596 return;
87597 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87598- pkts = atomic_add_return(1, &cp->in_pkts);
87599+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87600 else
87601 pkts = sysctl_sync_threshold(ipvs);
87602 goto sloop;
87603@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
87604
87605 if (opt)
87606 memcpy(&cp->in_seq, opt, sizeof(*opt));
87607- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87608+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87609 cp->state = state;
87610 cp->old_state = cp->state;
87611 /*
87612diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
87613index ee6b7a9..f9a89f6 100644
87614--- a/net/netfilter/ipvs/ip_vs_xmit.c
87615+++ b/net/netfilter/ipvs/ip_vs_xmit.c
87616@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
87617 else
87618 rc = NF_ACCEPT;
87619 /* do not touch skb anymore */
87620- atomic_inc(&cp->in_pkts);
87621+ atomic_inc_unchecked(&cp->in_pkts);
87622 goto out;
87623 }
87624
87625@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
87626 else
87627 rc = NF_ACCEPT;
87628 /* do not touch skb anymore */
87629- atomic_inc(&cp->in_pkts);
87630+ atomic_inc_unchecked(&cp->in_pkts);
87631 goto out;
87632 }
87633
87634diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
87635index 7df424e..a527b02 100644
87636--- a/net/netfilter/nf_conntrack_acct.c
87637+++ b/net/netfilter/nf_conntrack_acct.c
87638@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
87639 #ifdef CONFIG_SYSCTL
87640 static int nf_conntrack_acct_init_sysctl(struct net *net)
87641 {
87642- struct ctl_table *table;
87643+ ctl_table_no_const *table;
87644
87645 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
87646 GFP_KERNEL);
87647diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
87648index e4a0c4f..c263f28 100644
87649--- a/net/netfilter/nf_conntrack_core.c
87650+++ b/net/netfilter/nf_conntrack_core.c
87651@@ -1529,6 +1529,10 @@ err_extend:
87652 #define DYING_NULLS_VAL ((1<<30)+1)
87653 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
87654
87655+#ifdef CONFIG_GRKERNSEC_HIDESYM
87656+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
87657+#endif
87658+
87659 static int nf_conntrack_init_net(struct net *net)
87660 {
87661 int ret;
87662@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
87663 goto err_stat;
87664 }
87665
87666+#ifdef CONFIG_GRKERNSEC_HIDESYM
87667+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
87668+#else
87669 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
87670+#endif
87671 if (!net->ct.slabname) {
87672 ret = -ENOMEM;
87673 goto err_slabname;
87674diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
87675index faa978f..1afb18f 100644
87676--- a/net/netfilter/nf_conntrack_ecache.c
87677+++ b/net/netfilter/nf_conntrack_ecache.c
87678@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
87679 #ifdef CONFIG_SYSCTL
87680 static int nf_conntrack_event_init_sysctl(struct net *net)
87681 {
87682- struct ctl_table *table;
87683+ ctl_table_no_const *table;
87684
87685 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
87686 GFP_KERNEL);
87687diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
87688index 884f2b3..d53b33a 100644
87689--- a/net/netfilter/nf_conntrack_helper.c
87690+++ b/net/netfilter/nf_conntrack_helper.c
87691@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
87692
87693 static int nf_conntrack_helper_init_sysctl(struct net *net)
87694 {
87695- struct ctl_table *table;
87696+ ctl_table_no_const *table;
87697
87698 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
87699 GFP_KERNEL);
87700diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
87701index 51e928d..72a413a 100644
87702--- a/net/netfilter/nf_conntrack_proto.c
87703+++ b/net/netfilter/nf_conntrack_proto.c
87704@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
87705
87706 static void
87707 nf_ct_unregister_sysctl(struct ctl_table_header **header,
87708- struct ctl_table **table,
87709+ ctl_table_no_const **table,
87710 unsigned int users)
87711 {
87712 if (users > 0)
87713diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
87714index e7185c6..4ad6c9c 100644
87715--- a/net/netfilter/nf_conntrack_standalone.c
87716+++ b/net/netfilter/nf_conntrack_standalone.c
87717@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
87718
87719 static int nf_conntrack_standalone_init_sysctl(struct net *net)
87720 {
87721- struct ctl_table *table;
87722+ ctl_table_no_const *table;
87723
87724 if (net_eq(net, &init_net)) {
87725 nf_ct_netfilter_header =
87726diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
87727index 7ea8026..bc9512d 100644
87728--- a/net/netfilter/nf_conntrack_timestamp.c
87729+++ b/net/netfilter/nf_conntrack_timestamp.c
87730@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
87731 #ifdef CONFIG_SYSCTL
87732 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
87733 {
87734- struct ctl_table *table;
87735+ ctl_table_no_const *table;
87736
87737 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
87738 GFP_KERNEL);
87739diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
87740index 9e31269..bc4c1b7 100644
87741--- a/net/netfilter/nf_log.c
87742+++ b/net/netfilter/nf_log.c
87743@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
87744
87745 #ifdef CONFIG_SYSCTL
87746 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
87747-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
87748+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
87749 static struct ctl_table_header *nf_log_dir_header;
87750
87751 static int nf_log_proc_dostring(ctl_table *table, int write,
87752@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
87753 rcu_assign_pointer(nf_loggers[tindex], logger);
87754 mutex_unlock(&nf_log_mutex);
87755 } else {
87756+ ctl_table_no_const nf_log_table = *table;
87757+
87758 mutex_lock(&nf_log_mutex);
87759 logger = rcu_dereference_protected(nf_loggers[tindex],
87760 lockdep_is_held(&nf_log_mutex));
87761 if (!logger)
87762- table->data = "NONE";
87763+ nf_log_table.data = "NONE";
87764 else
87765- table->data = logger->name;
87766- r = proc_dostring(table, write, buffer, lenp, ppos);
87767+ nf_log_table.data = logger->name;
87768+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87769 mutex_unlock(&nf_log_mutex);
87770 }
87771
87772diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87773index f042ae5..30ea486 100644
87774--- a/net/netfilter/nf_sockopt.c
87775+++ b/net/netfilter/nf_sockopt.c
87776@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87777 }
87778 }
87779
87780- list_add(&reg->list, &nf_sockopts);
87781+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87782 out:
87783 mutex_unlock(&nf_sockopt_mutex);
87784 return ret;
87785@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87786 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87787 {
87788 mutex_lock(&nf_sockopt_mutex);
87789- list_del(&reg->list);
87790+ pax_list_del((struct list_head *)&reg->list);
87791 mutex_unlock(&nf_sockopt_mutex);
87792 }
87793 EXPORT_SYMBOL(nf_unregister_sockopt);
87794diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87795index 92fd8ec..3f6ea4b 100644
87796--- a/net/netfilter/nfnetlink_log.c
87797+++ b/net/netfilter/nfnetlink_log.c
87798@@ -72,7 +72,7 @@ struct nfulnl_instance {
87799 };
87800
87801 static DEFINE_SPINLOCK(instances_lock);
87802-static atomic_t global_seq;
87803+static atomic_unchecked_t global_seq;
87804
87805 #define INSTANCE_BUCKETS 16
87806 static struct hlist_head instance_table[INSTANCE_BUCKETS];
87807@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
87808 /* global sequence number */
87809 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
87810 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
87811- htonl(atomic_inc_return(&global_seq))))
87812+ htonl(atomic_inc_return_unchecked(&global_seq))))
87813 goto nla_put_failure;
87814
87815 if (data_len) {
87816diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
87817new file mode 100644
87818index 0000000..c566332
87819--- /dev/null
87820+++ b/net/netfilter/xt_gradm.c
87821@@ -0,0 +1,51 @@
87822+/*
87823+ * gradm match for netfilter
87824