]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.4-201303221826.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.4-201303221826.patch
CommitLineData
e1c04c9a
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..1a60561 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,49 @@ 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+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3731+ if (current->signal->curr_ip)
3732+ 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),
3733+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3734+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3735+ else
3736+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3737+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3738+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3739+ goto die;
3740+ }
3741+#endif
3742+
3743+#ifdef CONFIG_PAX_REFCOUNT
3744+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3745+ unsigned int bkpt;
3746+
3747+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3748+ current->thread.error_code = ifsr;
3749+ current->thread.trap_no = 0;
3750+ pax_report_refcount_overflow(regs);
3751+ fixup_exception(regs);
3752+ return;
3753+ }
3754+ }
3755+#endif
3756+
3757 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3758 return;
3759
3760+die:
3761 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3762 inf->name, ifsr, addr);
3763
3764diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3765index cf08bdf..772656c 100644
3766--- a/arch/arm/mm/fault.h
3767+++ b/arch/arm/mm/fault.h
3768@@ -3,6 +3,7 @@
3769
3770 /*
3771 * Fault status register encodings. We steal bit 31 for our own purposes.
3772+ * Set when the FSR value is from an instruction fault.
3773 */
3774 #define FSR_LNX_PF (1 << 31)
3775 #define FSR_WRITE (1 << 11)
3776@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3777 }
3778 #endif
3779
3780+/* valid for LPAE and !LPAE */
3781+static inline int is_xn_fault(unsigned int fsr)
3782+{
3783+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3784+}
3785+
3786+static inline int is_domain_fault(unsigned int fsr)
3787+{
3788+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3789+}
3790+
3791 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3792 unsigned long search_exception_table(unsigned long addr);
3793
3794diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3795index ad722f1..763fdd3 100644
3796--- a/arch/arm/mm/init.c
3797+++ b/arch/arm/mm/init.c
3798@@ -30,6 +30,8 @@
3799 #include <asm/setup.h>
3800 #include <asm/tlb.h>
3801 #include <asm/fixmap.h>
3802+#include <asm/system_info.h>
3803+#include <asm/cp15.h>
3804
3805 #include <asm/mach/arch.h>
3806 #include <asm/mach/map.h>
3807@@ -736,7 +738,46 @@ void free_initmem(void)
3808 {
3809 #ifdef CONFIG_HAVE_TCM
3810 extern char __tcm_start, __tcm_end;
3811+#endif
3812
3813+#ifdef CONFIG_PAX_KERNEXEC
3814+ unsigned long addr;
3815+ pgd_t *pgd;
3816+ pud_t *pud;
3817+ pmd_t *pmd;
3818+ int cpu_arch = cpu_architecture();
3819+ unsigned int cr = get_cr();
3820+
3821+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3822+ /* make pages tables, etc before .text NX */
3823+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3824+ pgd = pgd_offset_k(addr);
3825+ pud = pud_offset(pgd, addr);
3826+ pmd = pmd_offset(pud, addr);
3827+ __section_update(pmd, addr, PMD_SECT_XN);
3828+ }
3829+ /* make init NX */
3830+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3831+ pgd = pgd_offset_k(addr);
3832+ pud = pud_offset(pgd, addr);
3833+ pmd = pmd_offset(pud, addr);
3834+ __section_update(pmd, addr, PMD_SECT_XN);
3835+ }
3836+ /* make kernel code/rodata RX */
3837+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3838+ pgd = pgd_offset_k(addr);
3839+ pud = pud_offset(pgd, addr);
3840+ pmd = pmd_offset(pud, addr);
3841+#ifdef CONFIG_ARM_LPAE
3842+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3843+#else
3844+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3845+#endif
3846+ }
3847+ }
3848+#endif
3849+
3850+#ifdef CONFIG_HAVE_TCM
3851 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3852 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3853 __phys_to_pfn(__pa(&__tcm_end)),
3854diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3855index 88fd86c..7a224ce 100644
3856--- a/arch/arm/mm/ioremap.c
3857+++ b/arch/arm/mm/ioremap.c
3858@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3859 unsigned int mtype;
3860
3861 if (cached)
3862- mtype = MT_MEMORY;
3863+ mtype = MT_MEMORY_RX;
3864 else
3865- mtype = MT_MEMORY_NONCACHED;
3866+ mtype = MT_MEMORY_NONCACHED_RX;
3867
3868 return __arm_ioremap_caller(phys_addr, size, mtype,
3869 __builtin_return_address(0));
3870diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3871index 10062ce..aa96dd7 100644
3872--- a/arch/arm/mm/mmap.c
3873+++ b/arch/arm/mm/mmap.c
3874@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3875 struct vm_area_struct *vma;
3876 int do_align = 0;
3877 int aliasing = cache_is_vipt_aliasing();
3878+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3879 struct vm_unmapped_area_info info;
3880
3881 /*
3882@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3883 if (len > TASK_SIZE)
3884 return -ENOMEM;
3885
3886+#ifdef CONFIG_PAX_RANDMMAP
3887+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3888+#endif
3889+
3890 if (addr) {
3891 if (do_align)
3892 addr = COLOUR_ALIGN(addr, pgoff);
3893@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3894 addr = PAGE_ALIGN(addr);
3895
3896 vma = find_vma(mm, addr);
3897- if (TASK_SIZE - len >= addr &&
3898- (!vma || addr + len <= vma->vm_start))
3899+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3900 return addr;
3901 }
3902
3903@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3904 unsigned long addr = addr0;
3905 int do_align = 0;
3906 int aliasing = cache_is_vipt_aliasing();
3907+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3908 struct vm_unmapped_area_info info;
3909
3910 /*
3911@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3912 return addr;
3913 }
3914
3915+#ifdef CONFIG_PAX_RANDMMAP
3916+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3917+#endif
3918+
3919 /* requesting a specific address */
3920 if (addr) {
3921 if (do_align)
3922@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3923 else
3924 addr = PAGE_ALIGN(addr);
3925 vma = find_vma(mm, addr);
3926- if (TASK_SIZE - len >= addr &&
3927- (!vma || addr + len <= vma->vm_start))
3928+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3929 return addr;
3930 }
3931
3932@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3933 VM_BUG_ON(addr != -ENOMEM);
3934 info.flags = 0;
3935 info.low_limit = mm->mmap_base;
3936+
3937+#ifdef CONFIG_PAX_RANDMMAP
3938+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3939+ info.low_limit += mm->delta_mmap;
3940+#endif
3941+
3942 info.high_limit = TASK_SIZE;
3943 addr = vm_unmapped_area(&info);
3944 }
3945@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3946 {
3947 unsigned long random_factor = 0UL;
3948
3949+#ifdef CONFIG_PAX_RANDMMAP
3950+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3951+#endif
3952+
3953 /* 8 bits of randomness in 20 address space bits */
3954 if ((current->flags & PF_RANDOMIZE) &&
3955 !(current->personality & ADDR_NO_RANDOMIZE))
3956@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3957
3958 if (mmap_is_legacy()) {
3959 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3960+
3961+#ifdef CONFIG_PAX_RANDMMAP
3962+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3963+ mm->mmap_base += mm->delta_mmap;
3964+#endif
3965+
3966 mm->get_unmapped_area = arch_get_unmapped_area;
3967 mm->unmap_area = arch_unmap_area;
3968 } else {
3969 mm->mmap_base = mmap_base(random_factor);
3970+
3971+#ifdef CONFIG_PAX_RANDMMAP
3972+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3973+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3974+#endif
3975+
3976 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3977 mm->unmap_area = arch_unmap_area_topdown;
3978 }
3979diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3980index ce328c7..35b88dc 100644
3981--- a/arch/arm/mm/mmu.c
3982+++ b/arch/arm/mm/mmu.c
3983@@ -35,6 +35,23 @@
3984
3985 #include "mm.h"
3986
3987+
3988+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3989+void modify_domain(unsigned int dom, unsigned int type)
3990+{
3991+ struct thread_info *thread = current_thread_info();
3992+ unsigned int domain = thread->cpu_domain;
3993+ /*
3994+ * DOMAIN_MANAGER might be defined to some other value,
3995+ * use the arch-defined constant
3996+ */
3997+ domain &= ~domain_val(dom, 3);
3998+ thread->cpu_domain = domain | domain_val(dom, type);
3999+ set_domain(thread->cpu_domain);
4000+}
4001+EXPORT_SYMBOL(modify_domain);
4002+#endif
4003+
4004 /*
4005 * empty_zero_page is a special page that is used for
4006 * zero-initialized data and COW.
4007@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
4008 }
4009 #endif
4010
4011-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4012+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4013 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4014
4015-static struct mem_type mem_types[] = {
4016+#ifdef CONFIG_PAX_KERNEXEC
4017+#define L_PTE_KERNEXEC L_PTE_RDONLY
4018+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4019+#else
4020+#define L_PTE_KERNEXEC L_PTE_DIRTY
4021+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4022+#endif
4023+
4024+static struct mem_type mem_types[] __read_only = {
4025 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4026 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4027 L_PTE_SHARED,
4028@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
4029 [MT_UNCACHED] = {
4030 .prot_pte = PROT_PTE_DEVICE,
4031 .prot_l1 = PMD_TYPE_TABLE,
4032- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4033+ .prot_sect = PROT_SECT_DEVICE,
4034 .domain = DOMAIN_IO,
4035 },
4036 [MT_CACHECLEAN] = {
4037- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4038+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4039 .domain = DOMAIN_KERNEL,
4040 },
4041 #ifndef CONFIG_ARM_LPAE
4042 [MT_MINICLEAN] = {
4043- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4044+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4045 .domain = DOMAIN_KERNEL,
4046 },
4047 #endif
4048@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
4049 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4050 L_PTE_RDONLY,
4051 .prot_l1 = PMD_TYPE_TABLE,
4052- .domain = DOMAIN_USER,
4053+ .domain = DOMAIN_VECTORS,
4054 },
4055 [MT_HIGH_VECTORS] = {
4056 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4057- L_PTE_USER | L_PTE_RDONLY,
4058+ L_PTE_RDONLY,
4059 .prot_l1 = PMD_TYPE_TABLE,
4060- .domain = DOMAIN_USER,
4061+ .domain = DOMAIN_VECTORS,
4062 },
4063- [MT_MEMORY] = {
4064+ [MT_MEMORY_RWX] = {
4065 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4066 .prot_l1 = PMD_TYPE_TABLE,
4067 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4068 .domain = DOMAIN_KERNEL,
4069 },
4070+ [MT_MEMORY_RW] = {
4071+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4072+ .prot_l1 = PMD_TYPE_TABLE,
4073+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4074+ .domain = DOMAIN_KERNEL,
4075+ },
4076+ [MT_MEMORY_RX] = {
4077+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4078+ .prot_l1 = PMD_TYPE_TABLE,
4079+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4080+ .domain = DOMAIN_KERNEL,
4081+ },
4082 [MT_ROM] = {
4083- .prot_sect = PMD_TYPE_SECT,
4084+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4085 .domain = DOMAIN_KERNEL,
4086 },
4087- [MT_MEMORY_NONCACHED] = {
4088+ [MT_MEMORY_NONCACHED_RW] = {
4089 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4090 L_PTE_MT_BUFFERABLE,
4091 .prot_l1 = PMD_TYPE_TABLE,
4092 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4093 .domain = DOMAIN_KERNEL,
4094 },
4095+ [MT_MEMORY_NONCACHED_RX] = {
4096+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4097+ L_PTE_MT_BUFFERABLE,
4098+ .prot_l1 = PMD_TYPE_TABLE,
4099+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4100+ .domain = DOMAIN_KERNEL,
4101+ },
4102 [MT_MEMORY_DTCM] = {
4103- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4104- L_PTE_XN,
4105+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4106 .prot_l1 = PMD_TYPE_TABLE,
4107- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4108+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4109 .domain = DOMAIN_KERNEL,
4110 },
4111 [MT_MEMORY_ITCM] = {
4112@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
4113 },
4114 [MT_MEMORY_SO] = {
4115 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4116- L_PTE_MT_UNCACHED | L_PTE_XN,
4117+ L_PTE_MT_UNCACHED,
4118 .prot_l1 = PMD_TYPE_TABLE,
4119 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4120- PMD_SECT_UNCACHED | PMD_SECT_XN,
4121+ PMD_SECT_UNCACHED,
4122 .domain = DOMAIN_KERNEL,
4123 },
4124 [MT_MEMORY_DMA_READY] = {
4125@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
4126 * to prevent speculative instruction fetches.
4127 */
4128 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4129+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4130 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4131+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4132 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4133+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4134 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4135+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4136+
4137+ /* Mark other regions on ARMv6+ as execute-never */
4138+
4139+#ifdef CONFIG_PAX_KERNEXEC
4140+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4141+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4142+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4143+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4144+#ifndef CONFIG_ARM_LPAE
4145+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4146+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4147+#endif
4148+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4149+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4150+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4151+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4152+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4153+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4154+#endif
4155+
4156+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4157+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4158 }
4159 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4160 /*
4161@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
4162 * from SVC mode and no access from userspace.
4163 */
4164 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4165+#ifdef CONFIG_PAX_KERNEXEC
4166+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4167+#endif
4168 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4169 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4170 #endif
4171@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
4172 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4173 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4174 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4175- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4176- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4177+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4178+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4179+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4180+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4181+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4182+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4183 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4184- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4185- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4186+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4187+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4188+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4189+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4190 }
4191 }
4192
4193@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
4194 if (cpu_arch >= CPU_ARCH_ARMv6) {
4195 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4196 /* Non-cacheable Normal is XCB = 001 */
4197- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4198+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4199+ PMD_SECT_BUFFERED;
4200+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4201 PMD_SECT_BUFFERED;
4202 } else {
4203 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4204- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4205+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4206+ PMD_SECT_TEX(1);
4207+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4208 PMD_SECT_TEX(1);
4209 }
4210 } else {
4211- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4212+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4213+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4214 }
4215
4216 #ifdef CONFIG_ARM_LPAE
4217@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
4218 vecs_pgprot |= PTE_EXT_AF;
4219 #endif
4220
4221+ user_pgprot |= __supported_pte_mask;
4222+
4223 for (i = 0; i < 16; i++) {
4224 pteval_t v = pgprot_val(protection_map[i]);
4225 protection_map[i] = __pgprot(v | user_pgprot);
4226@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4227
4228 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4229 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4230- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4231- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4232+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4233+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4234+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4235+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4236+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4237+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4238 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4239- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4240+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4241+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4242 mem_types[MT_ROM].prot_sect |= cp->pmd;
4243
4244 switch (cp->pmd) {
4245@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4246 * called function. This means you can't use any function or debugging
4247 * method which may touch any device, otherwise the kernel _will_ crash.
4248 */
4249+
4250+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4251+
4252 static void __init devicemaps_init(struct machine_desc *mdesc)
4253 {
4254 struct map_desc map;
4255 unsigned long addr;
4256- void *vectors;
4257
4258- /*
4259- * Allocate the vector page early.
4260- */
4261- vectors = early_alloc(PAGE_SIZE);
4262-
4263- early_trap_init(vectors);
4264+ early_trap_init(&vectors);
4265
4266 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4267 pmd_clear(pmd_off_k(addr));
4268@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4269 * location (0xffff0000). If we aren't using high-vectors, also
4270 * create a mapping at the low-vectors virtual address.
4271 */
4272- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4273+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4274 map.virtual = 0xffff0000;
4275 map.length = PAGE_SIZE;
4276 map.type = MT_HIGH_VECTORS;
4277@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4278 map.pfn = __phys_to_pfn(start);
4279 map.virtual = __phys_to_virt(start);
4280 map.length = end - start;
4281- map.type = MT_MEMORY;
4282
4283+#ifdef CONFIG_PAX_KERNEXEC
4284+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4285+ struct map_desc kernel;
4286+ struct map_desc initmap;
4287+
4288+ /* when freeing initmem we will make this RW */
4289+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4290+ initmap.virtual = (unsigned long)__init_begin;
4291+ initmap.length = _sdata - __init_begin;
4292+ initmap.type = MT_MEMORY_RWX;
4293+ create_mapping(&initmap);
4294+
4295+ /* when freeing initmem we will make this RX */
4296+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4297+ kernel.virtual = (unsigned long)_stext;
4298+ kernel.length = __init_begin - _stext;
4299+ kernel.type = MT_MEMORY_RWX;
4300+ create_mapping(&kernel);
4301+
4302+ if (map.virtual < (unsigned long)_stext) {
4303+ map.length = (unsigned long)_stext - map.virtual;
4304+ map.type = MT_MEMORY_RWX;
4305+ create_mapping(&map);
4306+ }
4307+
4308+ map.pfn = __phys_to_pfn(__pa(_sdata));
4309+ map.virtual = (unsigned long)_sdata;
4310+ map.length = end - __pa(_sdata);
4311+ }
4312+#endif
4313+
4314+ map.type = MT_MEMORY_RW;
4315 create_mapping(&map);
4316 }
4317 }
4318diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4319index 6d98c13..3cfb174 100644
4320--- a/arch/arm/mm/proc-v7-2level.S
4321+++ b/arch/arm/mm/proc-v7-2level.S
4322@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4323 tst r1, #L_PTE_XN
4324 orrne r3, r3, #PTE_EXT_XN
4325
4326+ tst r1, #L_PTE_PXN
4327+ orrne r3, r3, #PTE_EXT_PXN
4328+
4329 tst r1, #L_PTE_YOUNG
4330 tstne r1, #L_PTE_VALID
4331 #ifndef CONFIG_CPU_USE_DOMAINS
4332diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4333index a5bc92d..0bb4730 100644
4334--- a/arch/arm/plat-omap/sram.c
4335+++ b/arch/arm/plat-omap/sram.c
4336@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4337 * Looks like we need to preserve some bootloader code at the
4338 * beginning of SRAM for jumping to flash for reboot to work...
4339 */
4340+ pax_open_kernel();
4341 memset_io(omap_sram_base + omap_sram_skip, 0,
4342 omap_sram_size - omap_sram_skip);
4343+ pax_close_kernel();
4344 }
4345diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4346index f5144cd..71f6d1f 100644
4347--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4348+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4349@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4350 int (*started)(unsigned ch);
4351 int (*flush)(unsigned ch);
4352 int (*stop)(unsigned ch);
4353-};
4354+} __no_const;
4355
4356 extern void *samsung_dmadev_get_ops(void);
4357 extern void *s3c_dma_get_ops(void);
4358diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4359index 0c3ba9f..95722b3 100644
4360--- a/arch/arm64/kernel/debug-monitors.c
4361+++ b/arch/arm64/kernel/debug-monitors.c
4362@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4363 return NOTIFY_OK;
4364 }
4365
4366-static struct notifier_block __cpuinitdata os_lock_nb = {
4367+static struct notifier_block os_lock_nb = {
4368 .notifier_call = os_lock_notify,
4369 };
4370
4371diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4372index 5ab825c..96aaec8 100644
4373--- a/arch/arm64/kernel/hw_breakpoint.c
4374+++ b/arch/arm64/kernel/hw_breakpoint.c
4375@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4376 return NOTIFY_OK;
4377 }
4378
4379-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4380+static struct notifier_block hw_breakpoint_reset_nb = {
4381 .notifier_call = hw_breakpoint_reset_notify,
4382 };
4383
4384diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4385index c3a58a1..78fbf54 100644
4386--- a/arch/avr32/include/asm/cache.h
4387+++ b/arch/avr32/include/asm/cache.h
4388@@ -1,8 +1,10 @@
4389 #ifndef __ASM_AVR32_CACHE_H
4390 #define __ASM_AVR32_CACHE_H
4391
4392+#include <linux/const.h>
4393+
4394 #define L1_CACHE_SHIFT 5
4395-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4396+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4397
4398 /*
4399 * Memory returned by kmalloc() may be used for DMA, so we must make
4400diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4401index e2c3287..6c4f98c 100644
4402--- a/arch/avr32/include/asm/elf.h
4403+++ b/arch/avr32/include/asm/elf.h
4404@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4405 the loader. We need to make sure that it is out of the way of the program
4406 that it will "exec", and that there is sufficient room for the brk. */
4407
4408-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4409+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4410
4411+#ifdef CONFIG_PAX_ASLR
4412+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4413+
4414+#define PAX_DELTA_MMAP_LEN 15
4415+#define PAX_DELTA_STACK_LEN 15
4416+#endif
4417
4418 /* This yields a mask that user programs can use to figure out what
4419 instruction set this CPU supports. This could be done in user space,
4420diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4421index 479330b..53717a8 100644
4422--- a/arch/avr32/include/asm/kmap_types.h
4423+++ b/arch/avr32/include/asm/kmap_types.h
4424@@ -2,9 +2,9 @@
4425 #define __ASM_AVR32_KMAP_TYPES_H
4426
4427 #ifdef CONFIG_DEBUG_HIGHMEM
4428-# define KM_TYPE_NR 29
4429+# define KM_TYPE_NR 30
4430 #else
4431-# define KM_TYPE_NR 14
4432+# define KM_TYPE_NR 15
4433 #endif
4434
4435 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4436diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4437index b2f2d2d..d1c85cb 100644
4438--- a/arch/avr32/mm/fault.c
4439+++ b/arch/avr32/mm/fault.c
4440@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4441
4442 int exception_trace = 1;
4443
4444+#ifdef CONFIG_PAX_PAGEEXEC
4445+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4446+{
4447+ unsigned long i;
4448+
4449+ printk(KERN_ERR "PAX: bytes at PC: ");
4450+ for (i = 0; i < 20; i++) {
4451+ unsigned char c;
4452+ if (get_user(c, (unsigned char *)pc+i))
4453+ printk(KERN_CONT "???????? ");
4454+ else
4455+ printk(KERN_CONT "%02x ", c);
4456+ }
4457+ printk("\n");
4458+}
4459+#endif
4460+
4461 /*
4462 * This routine handles page faults. It determines the address and the
4463 * problem, and then passes it off to one of the appropriate routines.
4464@@ -174,6 +191,16 @@ bad_area:
4465 up_read(&mm->mmap_sem);
4466
4467 if (user_mode(regs)) {
4468+
4469+#ifdef CONFIG_PAX_PAGEEXEC
4470+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4471+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4472+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4473+ do_group_exit(SIGKILL);
4474+ }
4475+ }
4476+#endif
4477+
4478 if (exception_trace && printk_ratelimit())
4479 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4480 "sp %08lx ecr %lu\n",
4481diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4482index 568885a..f8008df 100644
4483--- a/arch/blackfin/include/asm/cache.h
4484+++ b/arch/blackfin/include/asm/cache.h
4485@@ -7,6 +7,7 @@
4486 #ifndef __ARCH_BLACKFIN_CACHE_H
4487 #define __ARCH_BLACKFIN_CACHE_H
4488
4489+#include <linux/const.h>
4490 #include <linux/linkage.h> /* for asmlinkage */
4491
4492 /*
4493@@ -14,7 +15,7 @@
4494 * Blackfin loads 32 bytes for cache
4495 */
4496 #define L1_CACHE_SHIFT 5
4497-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4498+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4499 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4500
4501 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4502diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4503index aea2718..3639a60 100644
4504--- a/arch/cris/include/arch-v10/arch/cache.h
4505+++ b/arch/cris/include/arch-v10/arch/cache.h
4506@@ -1,8 +1,9 @@
4507 #ifndef _ASM_ARCH_CACHE_H
4508 #define _ASM_ARCH_CACHE_H
4509
4510+#include <linux/const.h>
4511 /* Etrax 100LX have 32-byte cache-lines. */
4512-#define L1_CACHE_BYTES 32
4513 #define L1_CACHE_SHIFT 5
4514+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4515
4516 #endif /* _ASM_ARCH_CACHE_H */
4517diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4518index 7caf25d..ee65ac5 100644
4519--- a/arch/cris/include/arch-v32/arch/cache.h
4520+++ b/arch/cris/include/arch-v32/arch/cache.h
4521@@ -1,11 +1,12 @@
4522 #ifndef _ASM_CRIS_ARCH_CACHE_H
4523 #define _ASM_CRIS_ARCH_CACHE_H
4524
4525+#include <linux/const.h>
4526 #include <arch/hwregs/dma.h>
4527
4528 /* A cache-line is 32 bytes. */
4529-#define L1_CACHE_BYTES 32
4530 #define L1_CACHE_SHIFT 5
4531+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4532
4533 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4534
4535diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4536index b86329d..6709906 100644
4537--- a/arch/frv/include/asm/atomic.h
4538+++ b/arch/frv/include/asm/atomic.h
4539@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4540 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4541 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4542
4543+#define atomic64_read_unchecked(v) atomic64_read(v)
4544+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4545+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4546+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4547+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4548+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4549+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4550+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4551+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4552+
4553 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4554 {
4555 int c, old;
4556diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4557index 2797163..c2a401d 100644
4558--- a/arch/frv/include/asm/cache.h
4559+++ b/arch/frv/include/asm/cache.h
4560@@ -12,10 +12,11 @@
4561 #ifndef __ASM_CACHE_H
4562 #define __ASM_CACHE_H
4563
4564+#include <linux/const.h>
4565
4566 /* bytes per L1 cache line */
4567 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4568-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4569+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4570
4571 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4572 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4573diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4574index 43901f2..0d8b865 100644
4575--- a/arch/frv/include/asm/kmap_types.h
4576+++ b/arch/frv/include/asm/kmap_types.h
4577@@ -2,6 +2,6 @@
4578 #ifndef _ASM_KMAP_TYPES_H
4579 #define _ASM_KMAP_TYPES_H
4580
4581-#define KM_TYPE_NR 17
4582+#define KM_TYPE_NR 18
4583
4584 #endif
4585diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4586index 385fd30..3aaf4fe 100644
4587--- a/arch/frv/mm/elf-fdpic.c
4588+++ b/arch/frv/mm/elf-fdpic.c
4589@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4590 {
4591 struct vm_area_struct *vma;
4592 unsigned long limit;
4593+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4594
4595 if (len > TASK_SIZE)
4596 return -ENOMEM;
4597@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4598 if (addr) {
4599 addr = PAGE_ALIGN(addr);
4600 vma = find_vma(current->mm, addr);
4601- if (TASK_SIZE - len >= addr &&
4602- (!vma || addr + len <= vma->vm_start))
4603+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4604 goto success;
4605 }
4606
4607@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4608 for (; vma; vma = vma->vm_next) {
4609 if (addr > limit)
4610 break;
4611- if (addr + len <= vma->vm_start)
4612+ if (check_heap_stack_gap(vma, addr, len, offset))
4613 goto success;
4614 addr = vma->vm_end;
4615 }
4616@@ -104,7 +104,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 }
4625diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4626index f4ca594..adc72fd6 100644
4627--- a/arch/hexagon/include/asm/cache.h
4628+++ b/arch/hexagon/include/asm/cache.h
4629@@ -21,9 +21,11 @@
4630 #ifndef __ASM_CACHE_H
4631 #define __ASM_CACHE_H
4632
4633+#include <linux/const.h>
4634+
4635 /* Bytes per L1 cache line */
4636-#define L1_CACHE_SHIFT (5)
4637-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4638+#define L1_CACHE_SHIFT 5
4639+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4640
4641 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4642 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4643diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4644index 6e6fe18..a6ae668 100644
4645--- a/arch/ia64/include/asm/atomic.h
4646+++ b/arch/ia64/include/asm/atomic.h
4647@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4648 #define atomic64_inc(v) atomic64_add(1, (v))
4649 #define atomic64_dec(v) atomic64_sub(1, (v))
4650
4651+#define atomic64_read_unchecked(v) atomic64_read(v)
4652+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4653+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4654+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4655+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4656+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4657+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4658+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4659+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4660+
4661 /* Atomic operations are already serializing */
4662 #define smp_mb__before_atomic_dec() barrier()
4663 #define smp_mb__after_atomic_dec() barrier()
4664diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4665index 988254a..e1ee885 100644
4666--- a/arch/ia64/include/asm/cache.h
4667+++ b/arch/ia64/include/asm/cache.h
4668@@ -1,6 +1,7 @@
4669 #ifndef _ASM_IA64_CACHE_H
4670 #define _ASM_IA64_CACHE_H
4671
4672+#include <linux/const.h>
4673
4674 /*
4675 * Copyright (C) 1998-2000 Hewlett-Packard Co
4676@@ -9,7 +10,7 @@
4677
4678 /* Bytes per L1 (data) cache line. */
4679 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4680-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4681+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4682
4683 #ifdef CONFIG_SMP
4684 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4685diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4686index b5298eb..67c6e62 100644
4687--- a/arch/ia64/include/asm/elf.h
4688+++ b/arch/ia64/include/asm/elf.h
4689@@ -42,6 +42,13 @@
4690 */
4691 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4692
4693+#ifdef CONFIG_PAX_ASLR
4694+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4695+
4696+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4697+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4698+#endif
4699+
4700 #define PT_IA_64_UNWIND 0x70000001
4701
4702 /* IA-64 relocations: */
4703diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4704index 96a8d92..617a1cf 100644
4705--- a/arch/ia64/include/asm/pgalloc.h
4706+++ b/arch/ia64/include/asm/pgalloc.h
4707@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4708 pgd_val(*pgd_entry) = __pa(pud);
4709 }
4710
4711+static inline void
4712+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4713+{
4714+ pgd_populate(mm, pgd_entry, pud);
4715+}
4716+
4717 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4718 {
4719 return quicklist_alloc(0, GFP_KERNEL, NULL);
4720@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4721 pud_val(*pud_entry) = __pa(pmd);
4722 }
4723
4724+static inline void
4725+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4726+{
4727+ pud_populate(mm, pud_entry, pmd);
4728+}
4729+
4730 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4731 {
4732 return quicklist_alloc(0, GFP_KERNEL, NULL);
4733diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4734index 815810c..d60bd4c 100644
4735--- a/arch/ia64/include/asm/pgtable.h
4736+++ b/arch/ia64/include/asm/pgtable.h
4737@@ -12,7 +12,7 @@
4738 * David Mosberger-Tang <davidm@hpl.hp.com>
4739 */
4740
4741-
4742+#include <linux/const.h>
4743 #include <asm/mman.h>
4744 #include <asm/page.h>
4745 #include <asm/processor.h>
4746@@ -142,6 +142,17 @@
4747 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4748 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4749 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4750+
4751+#ifdef CONFIG_PAX_PAGEEXEC
4752+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4753+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4754+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4755+#else
4756+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4757+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4758+# define PAGE_COPY_NOEXEC PAGE_COPY
4759+#endif
4760+
4761 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4762 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4763 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4764diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4765index 54ff557..70c88b7 100644
4766--- a/arch/ia64/include/asm/spinlock.h
4767+++ b/arch/ia64/include/asm/spinlock.h
4768@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4769 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4770
4771 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4772- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4773+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4774 }
4775
4776 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4777diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4778index 449c8c0..50cdf87 100644
4779--- a/arch/ia64/include/asm/uaccess.h
4780+++ b/arch/ia64/include/asm/uaccess.h
4781@@ -42,6 +42,8 @@
4782 #include <asm/pgtable.h>
4783 #include <asm/io.h>
4784
4785+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4786+
4787 /*
4788 * For historical reasons, the following macros are grossly misnamed:
4789 */
4790@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4791 static inline unsigned long
4792 __copy_to_user (void __user *to, const void *from, unsigned long count)
4793 {
4794+ if (count > INT_MAX)
4795+ return count;
4796+
4797+ if (!__builtin_constant_p(count))
4798+ check_object_size(from, count, true);
4799+
4800 return __copy_user(to, (__force void __user *) from, count);
4801 }
4802
4803 static inline unsigned long
4804 __copy_from_user (void *to, const void __user *from, unsigned long count)
4805 {
4806+ if (count > INT_MAX)
4807+ return count;
4808+
4809+ if (!__builtin_constant_p(count))
4810+ check_object_size(to, count, false);
4811+
4812 return __copy_user((__force void __user *) to, from, count);
4813 }
4814
4815@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4816 ({ \
4817 void __user *__cu_to = (to); \
4818 const void *__cu_from = (from); \
4819- long __cu_len = (n); \
4820+ unsigned long __cu_len = (n); \
4821 \
4822- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4823+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4824+ if (!__builtin_constant_p(n)) \
4825+ check_object_size(__cu_from, __cu_len, true); \
4826 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4827+ } \
4828 __cu_len; \
4829 })
4830
4831@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4832 ({ \
4833 void *__cu_to = (to); \
4834 const void __user *__cu_from = (from); \
4835- long __cu_len = (n); \
4836+ unsigned long __cu_len = (n); \
4837 \
4838 __chk_user_ptr(__cu_from); \
4839- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4840+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4841+ if (!__builtin_constant_p(n)) \
4842+ check_object_size(__cu_to, __cu_len, false); \
4843 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4844+ } \
4845 __cu_len; \
4846 })
4847
4848diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4849index 2d67317..07d8bfa 100644
4850--- a/arch/ia64/kernel/err_inject.c
4851+++ b/arch/ia64/kernel/err_inject.c
4852@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4853 return NOTIFY_OK;
4854 }
4855
4856-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4857+static struct notifier_block err_inject_cpu_notifier =
4858 {
4859 .notifier_call = err_inject_cpu_callback,
4860 };
4861diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4862index 65bf9cd..794f06b 100644
4863--- a/arch/ia64/kernel/mca.c
4864+++ b/arch/ia64/kernel/mca.c
4865@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4866 return NOTIFY_OK;
4867 }
4868
4869-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4870+static struct notifier_block mca_cpu_notifier = {
4871 .notifier_call = mca_cpu_callback
4872 };
4873
4874diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4875index 24603be..948052d 100644
4876--- a/arch/ia64/kernel/module.c
4877+++ b/arch/ia64/kernel/module.c
4878@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4879 void
4880 module_free (struct module *mod, void *module_region)
4881 {
4882- if (mod && mod->arch.init_unw_table &&
4883- module_region == mod->module_init) {
4884+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4885 unw_remove_unwind_table(mod->arch.init_unw_table);
4886 mod->arch.init_unw_table = NULL;
4887 }
4888@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4889 }
4890
4891 static inline int
4892+in_init_rx (const struct module *mod, uint64_t addr)
4893+{
4894+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4895+}
4896+
4897+static inline int
4898+in_init_rw (const struct module *mod, uint64_t addr)
4899+{
4900+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4901+}
4902+
4903+static inline int
4904 in_init (const struct module *mod, uint64_t addr)
4905 {
4906- return addr - (uint64_t) mod->module_init < mod->init_size;
4907+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4908+}
4909+
4910+static inline int
4911+in_core_rx (const struct module *mod, uint64_t addr)
4912+{
4913+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4914+}
4915+
4916+static inline int
4917+in_core_rw (const struct module *mod, uint64_t addr)
4918+{
4919+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4920 }
4921
4922 static inline int
4923 in_core (const struct module *mod, uint64_t addr)
4924 {
4925- return addr - (uint64_t) mod->module_core < mod->core_size;
4926+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4927 }
4928
4929 static inline int
4930@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4931 break;
4932
4933 case RV_BDREL:
4934- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4935+ if (in_init_rx(mod, val))
4936+ val -= (uint64_t) mod->module_init_rx;
4937+ else if (in_init_rw(mod, val))
4938+ val -= (uint64_t) mod->module_init_rw;
4939+ else if (in_core_rx(mod, val))
4940+ val -= (uint64_t) mod->module_core_rx;
4941+ else if (in_core_rw(mod, val))
4942+ val -= (uint64_t) mod->module_core_rw;
4943 break;
4944
4945 case RV_LTV:
4946@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4947 * addresses have been selected...
4948 */
4949 uint64_t gp;
4950- if (mod->core_size > MAX_LTOFF)
4951+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4952 /*
4953 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4954 * at the end of the module.
4955 */
4956- gp = mod->core_size - MAX_LTOFF / 2;
4957+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4958 else
4959- gp = mod->core_size / 2;
4960- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4961+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4962+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4963 mod->arch.gp = gp;
4964 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4965 }
4966diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4967index 77597e5..6f28f3f 100644
4968--- a/arch/ia64/kernel/palinfo.c
4969+++ b/arch/ia64/kernel/palinfo.c
4970@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4971 return NOTIFY_OK;
4972 }
4973
4974-static struct notifier_block __refdata palinfo_cpu_notifier =
4975+static struct notifier_block palinfo_cpu_notifier =
4976 {
4977 .notifier_call = palinfo_cpu_callback,
4978 .priority = 0,
4979diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4980index 79802e5..1a89ec5 100644
4981--- a/arch/ia64/kernel/salinfo.c
4982+++ b/arch/ia64/kernel/salinfo.c
4983@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4984 return NOTIFY_OK;
4985 }
4986
4987-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4988+static struct notifier_block salinfo_cpu_notifier =
4989 {
4990 .notifier_call = salinfo_cpu_callback,
4991 .priority = 0,
4992diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4993index d9439ef..d0cac6b 100644
4994--- a/arch/ia64/kernel/sys_ia64.c
4995+++ b/arch/ia64/kernel/sys_ia64.c
4996@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4997 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4998 struct mm_struct *mm = current->mm;
4999 struct vm_area_struct *vma;
5000+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5001
5002 if (len > RGN_MAP_LIMIT)
5003 return -ENOMEM;
5004@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5005 if (REGION_NUMBER(addr) == RGN_HPAGE)
5006 addr = 0;
5007 #endif
5008+
5009+#ifdef CONFIG_PAX_RANDMMAP
5010+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5011+ addr = mm->free_area_cache;
5012+ else
5013+#endif
5014+
5015 if (!addr)
5016 addr = mm->free_area_cache;
5017
5018@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5019 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
5020 /* At this point: (!vma || addr < vma->vm_end). */
5021 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
5022- if (start_addr != TASK_UNMAPPED_BASE) {
5023+ if (start_addr != mm->mmap_base) {
5024 /* Start a new search --- just in case we missed some holes. */
5025- addr = TASK_UNMAPPED_BASE;
5026+ addr = mm->mmap_base;
5027 goto full_search;
5028 }
5029 return -ENOMEM;
5030 }
5031- if (!vma || addr + len <= vma->vm_start) {
5032+ if (check_heap_stack_gap(vma, addr, len, offset)) {
5033 /* Remember the address where we stopped this search: */
5034 mm->free_area_cache = addr + len;
5035 return addr;
5036diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5037index dc00b2c..cce53c2 100644
5038--- a/arch/ia64/kernel/topology.c
5039+++ b/arch/ia64/kernel/topology.c
5040@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5041 return NOTIFY_OK;
5042 }
5043
5044-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5045+static struct notifier_block cache_cpu_notifier =
5046 {
5047 .notifier_call = cache_cpu_callback
5048 };
5049diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5050index 0ccb28f..8992469 100644
5051--- a/arch/ia64/kernel/vmlinux.lds.S
5052+++ b/arch/ia64/kernel/vmlinux.lds.S
5053@@ -198,7 +198,7 @@ SECTIONS {
5054 /* Per-cpu data: */
5055 . = ALIGN(PERCPU_PAGE_SIZE);
5056 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5057- __phys_per_cpu_start = __per_cpu_load;
5058+ __phys_per_cpu_start = per_cpu_load;
5059 /*
5060 * ensure percpu data fits
5061 * into percpu page size
5062diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5063index 6cf0341..d352594 100644
5064--- a/arch/ia64/mm/fault.c
5065+++ b/arch/ia64/mm/fault.c
5066@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5067 return pte_present(pte);
5068 }
5069
5070+#ifdef CONFIG_PAX_PAGEEXEC
5071+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5072+{
5073+ unsigned long i;
5074+
5075+ printk(KERN_ERR "PAX: bytes at PC: ");
5076+ for (i = 0; i < 8; i++) {
5077+ unsigned int c;
5078+ if (get_user(c, (unsigned int *)pc+i))
5079+ printk(KERN_CONT "???????? ");
5080+ else
5081+ printk(KERN_CONT "%08x ", c);
5082+ }
5083+ printk("\n");
5084+}
5085+#endif
5086+
5087 # define VM_READ_BIT 0
5088 # define VM_WRITE_BIT 1
5089 # define VM_EXEC_BIT 2
5090@@ -149,8 +166,21 @@ retry:
5091 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5092 goto bad_area;
5093
5094- if ((vma->vm_flags & mask) != mask)
5095+ if ((vma->vm_flags & mask) != mask) {
5096+
5097+#ifdef CONFIG_PAX_PAGEEXEC
5098+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5099+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5100+ goto bad_area;
5101+
5102+ up_read(&mm->mmap_sem);
5103+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5104+ do_group_exit(SIGKILL);
5105+ }
5106+#endif
5107+
5108 goto bad_area;
5109+ }
5110
5111 /*
5112 * If for any reason at all we couldn't handle the fault, make
5113diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5114index 5ca674b..127c3cb 100644
5115--- a/arch/ia64/mm/hugetlbpage.c
5116+++ b/arch/ia64/mm/hugetlbpage.c
5117@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5118 unsigned long pgoff, unsigned long flags)
5119 {
5120 struct vm_area_struct *vmm;
5121+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5122
5123 if (len > RGN_MAP_LIMIT)
5124 return -ENOMEM;
5125@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5126 /* At this point: (!vmm || addr < vmm->vm_end). */
5127 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
5128 return -ENOMEM;
5129- if (!vmm || (addr + len) <= vmm->vm_start)
5130+ if (check_heap_stack_gap(vmm, addr, len, offset))
5131 return addr;
5132 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
5133 }
5134diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5135index b755ea9..b9a969e 100644
5136--- a/arch/ia64/mm/init.c
5137+++ b/arch/ia64/mm/init.c
5138@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5139 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5140 vma->vm_end = vma->vm_start + PAGE_SIZE;
5141 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5142+
5143+#ifdef CONFIG_PAX_PAGEEXEC
5144+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5145+ vma->vm_flags &= ~VM_EXEC;
5146+
5147+#ifdef CONFIG_PAX_MPROTECT
5148+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5149+ vma->vm_flags &= ~VM_MAYEXEC;
5150+#endif
5151+
5152+ }
5153+#endif
5154+
5155 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5156 down_write(&current->mm->mmap_sem);
5157 if (insert_vm_struct(current->mm, vma)) {
5158diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5159index 40b3ee9..8c2c112 100644
5160--- a/arch/m32r/include/asm/cache.h
5161+++ b/arch/m32r/include/asm/cache.h
5162@@ -1,8 +1,10 @@
5163 #ifndef _ASM_M32R_CACHE_H
5164 #define _ASM_M32R_CACHE_H
5165
5166+#include <linux/const.h>
5167+
5168 /* L1 cache line size */
5169 #define L1_CACHE_SHIFT 4
5170-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5171+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5172
5173 #endif /* _ASM_M32R_CACHE_H */
5174diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5175index 82abd15..d95ae5d 100644
5176--- a/arch/m32r/lib/usercopy.c
5177+++ b/arch/m32r/lib/usercopy.c
5178@@ -14,6 +14,9 @@
5179 unsigned long
5180 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5181 {
5182+ if ((long)n < 0)
5183+ return n;
5184+
5185 prefetch(from);
5186 if (access_ok(VERIFY_WRITE, to, n))
5187 __copy_user(to,from,n);
5188@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5189 unsigned long
5190 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5191 {
5192+ if ((long)n < 0)
5193+ return n;
5194+
5195 prefetchw(to);
5196 if (access_ok(VERIFY_READ, from, n))
5197 __copy_user_zeroing(to,from,n);
5198diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5199index 0395c51..5f26031 100644
5200--- a/arch/m68k/include/asm/cache.h
5201+++ b/arch/m68k/include/asm/cache.h
5202@@ -4,9 +4,11 @@
5203 #ifndef __ARCH_M68K_CACHE_H
5204 #define __ARCH_M68K_CACHE_H
5205
5206+#include <linux/const.h>
5207+
5208 /* bytes per L1 cache line */
5209 #define L1_CACHE_SHIFT 4
5210-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5211+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5212
5213 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5214
5215diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5216index 4efe96a..60e8699 100644
5217--- a/arch/microblaze/include/asm/cache.h
5218+++ b/arch/microblaze/include/asm/cache.h
5219@@ -13,11 +13,12 @@
5220 #ifndef _ASM_MICROBLAZE_CACHE_H
5221 #define _ASM_MICROBLAZE_CACHE_H
5222
5223+#include <linux/const.h>
5224 #include <asm/registers.h>
5225
5226 #define L1_CACHE_SHIFT 5
5227 /* word-granular cache in microblaze */
5228-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5229+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5230
5231 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5232
5233diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5234index 01cc6ba..bcb7a5d 100644
5235--- a/arch/mips/include/asm/atomic.h
5236+++ b/arch/mips/include/asm/atomic.h
5237@@ -21,6 +21,10 @@
5238 #include <asm/cmpxchg.h>
5239 #include <asm/war.h>
5240
5241+#ifdef CONFIG_GENERIC_ATOMIC64
5242+#include <asm-generic/atomic64.h>
5243+#endif
5244+
5245 #define ATOMIC_INIT(i) { (i) }
5246
5247 /*
5248@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5249 */
5250 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5251
5252+#define atomic64_read_unchecked(v) atomic64_read(v)
5253+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5254+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5255+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5256+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5257+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5258+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5259+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5260+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5261+
5262 #endif /* CONFIG_64BIT */
5263
5264 /*
5265diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5266index b4db69f..8f3b093 100644
5267--- a/arch/mips/include/asm/cache.h
5268+++ b/arch/mips/include/asm/cache.h
5269@@ -9,10 +9,11 @@
5270 #ifndef _ASM_CACHE_H
5271 #define _ASM_CACHE_H
5272
5273+#include <linux/const.h>
5274 #include <kmalloc.h>
5275
5276 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5277-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5278+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5279
5280 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5281 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5282diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5283index 455c0ac..ad65fbe 100644
5284--- a/arch/mips/include/asm/elf.h
5285+++ b/arch/mips/include/asm/elf.h
5286@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5287 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5288 #endif
5289
5290+#ifdef CONFIG_PAX_ASLR
5291+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5292+
5293+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5294+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5295+#endif
5296+
5297 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5298 struct linux_binprm;
5299 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5300 int uses_interp);
5301
5302-struct mm_struct;
5303-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5304-#define arch_randomize_brk arch_randomize_brk
5305-
5306 #endif /* _ASM_ELF_H */
5307diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5308index c1f6afa..38cc6e9 100644
5309--- a/arch/mips/include/asm/exec.h
5310+++ b/arch/mips/include/asm/exec.h
5311@@ -12,6 +12,6 @@
5312 #ifndef _ASM_EXEC_H
5313 #define _ASM_EXEC_H
5314
5315-extern unsigned long arch_align_stack(unsigned long sp);
5316+#define arch_align_stack(x) ((x) & ~0xfUL)
5317
5318 #endif /* _ASM_EXEC_H */
5319diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5320index dbaec94..6a14935 100644
5321--- a/arch/mips/include/asm/page.h
5322+++ b/arch/mips/include/asm/page.h
5323@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5324 #ifdef CONFIG_CPU_MIPS32
5325 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5326 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5327- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5328+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5329 #else
5330 typedef struct { unsigned long long pte; } pte_t;
5331 #define pte_val(x) ((x).pte)
5332diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5333index 881d18b..cea38bc 100644
5334--- a/arch/mips/include/asm/pgalloc.h
5335+++ b/arch/mips/include/asm/pgalloc.h
5336@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5337 {
5338 set_pud(pud, __pud((unsigned long)pmd));
5339 }
5340+
5341+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5342+{
5343+ pud_populate(mm, pud, pmd);
5344+}
5345 #endif
5346
5347 /*
5348diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5349index b2050b9..d71bb1b 100644
5350--- a/arch/mips/include/asm/thread_info.h
5351+++ b/arch/mips/include/asm/thread_info.h
5352@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5353 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5354 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5355 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5356+/* li takes a 32bit immediate */
5357+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5358 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5359
5360 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5361@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5362 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5363 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5364 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5365+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5366+
5367+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5368
5369 /* work to do in syscall_trace_leave() */
5370-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5371+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5372
5373 /* work to do on interrupt/exception return */
5374 #define _TIF_WORK_MASK \
5375 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5376 /* work to do on any return to u-space */
5377-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5378+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5379
5380 #endif /* __KERNEL__ */
5381
5382diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5383index 9fdd8bc..4bd7f1a 100644
5384--- a/arch/mips/kernel/binfmt_elfn32.c
5385+++ b/arch/mips/kernel/binfmt_elfn32.c
5386@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5387 #undef ELF_ET_DYN_BASE
5388 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5389
5390+#ifdef CONFIG_PAX_ASLR
5391+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5392+
5393+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5394+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5395+#endif
5396+
5397 #include <asm/processor.h>
5398 #include <linux/module.h>
5399 #include <linux/elfcore.h>
5400diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5401index ff44823..97f8906 100644
5402--- a/arch/mips/kernel/binfmt_elfo32.c
5403+++ b/arch/mips/kernel/binfmt_elfo32.c
5404@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5405 #undef ELF_ET_DYN_BASE
5406 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5407
5408+#ifdef CONFIG_PAX_ASLR
5409+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5410+
5411+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5412+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5413+#endif
5414+
5415 #include <asm/processor.h>
5416
5417 /*
5418diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5419index a11c6f9..be5e164 100644
5420--- a/arch/mips/kernel/process.c
5421+++ b/arch/mips/kernel/process.c
5422@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5423 out:
5424 return pc;
5425 }
5426-
5427-/*
5428- * Don't forget that the stack pointer must be aligned on a 8 bytes
5429- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5430- */
5431-unsigned long arch_align_stack(unsigned long sp)
5432-{
5433- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5434- sp -= get_random_int() & ~PAGE_MASK;
5435-
5436- return sp & ALMASK;
5437-}
5438diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5439index 4812c6d..2069554 100644
5440--- a/arch/mips/kernel/ptrace.c
5441+++ b/arch/mips/kernel/ptrace.c
5442@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5443 return arch;
5444 }
5445
5446+#ifdef CONFIG_GRKERNSEC_SETXID
5447+extern void gr_delayed_cred_worker(void);
5448+#endif
5449+
5450 /*
5451 * Notification of system call entry/exit
5452 * - triggered by current->work.syscall_trace
5453@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5454 /* do the secure computing check first */
5455 secure_computing_strict(regs->regs[2]);
5456
5457+#ifdef CONFIG_GRKERNSEC_SETXID
5458+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5459+ gr_delayed_cred_worker();
5460+#endif
5461+
5462 if (!(current->ptrace & PT_PTRACED))
5463 goto out;
5464
5465diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5466index d20a4bc..7096ae5 100644
5467--- a/arch/mips/kernel/scall32-o32.S
5468+++ b/arch/mips/kernel/scall32-o32.S
5469@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5470
5471 stack_done:
5472 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5473- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5474+ li t1, _TIF_SYSCALL_WORK
5475 and t0, t1
5476 bnez t0, syscall_trace_entry # -> yes
5477
5478diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5479index b64f642..0fe6eab 100644
5480--- a/arch/mips/kernel/scall64-64.S
5481+++ b/arch/mips/kernel/scall64-64.S
5482@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5483
5484 sd a3, PT_R26(sp) # save a3 for syscall restarting
5485
5486- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5487+ li t1, _TIF_SYSCALL_WORK
5488 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5489 and t0, t1, t0
5490 bnez t0, syscall_trace_entry
5491diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5492index c29ac19..c592d05 100644
5493--- a/arch/mips/kernel/scall64-n32.S
5494+++ b/arch/mips/kernel/scall64-n32.S
5495@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5496
5497 sd a3, PT_R26(sp) # save a3 for syscall restarting
5498
5499- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5500+ li t1, _TIF_SYSCALL_WORK
5501 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5502 and t0, t1, t0
5503 bnez t0, n32_syscall_trace_entry
5504diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5505index cf3e75e..72e93fe 100644
5506--- a/arch/mips/kernel/scall64-o32.S
5507+++ b/arch/mips/kernel/scall64-o32.S
5508@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5509 PTR 4b, bad_stack
5510 .previous
5511
5512- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5513+ li t1, _TIF_SYSCALL_WORK
5514 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5515 and t0, t1, t0
5516 bnez t0, trace_a_syscall
5517diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5518index ddcec1e..c7f983e 100644
5519--- a/arch/mips/mm/fault.c
5520+++ b/arch/mips/mm/fault.c
5521@@ -27,6 +27,23 @@
5522 #include <asm/highmem.h> /* For VMALLOC_END */
5523 #include <linux/kdebug.h>
5524
5525+#ifdef CONFIG_PAX_PAGEEXEC
5526+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5527+{
5528+ unsigned long i;
5529+
5530+ printk(KERN_ERR "PAX: bytes at PC: ");
5531+ for (i = 0; i < 5; i++) {
5532+ unsigned int c;
5533+ if (get_user(c, (unsigned int *)pc+i))
5534+ printk(KERN_CONT "???????? ");
5535+ else
5536+ printk(KERN_CONT "%08x ", c);
5537+ }
5538+ printk("\n");
5539+}
5540+#endif
5541+
5542 /*
5543 * This routine handles page faults. It determines the address,
5544 * and the problem, and then passes it off to one of the appropriate
5545diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5546index 7e5fe27..479a219 100644
5547--- a/arch/mips/mm/mmap.c
5548+++ b/arch/mips/mm/mmap.c
5549@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5550 struct vm_area_struct *vma;
5551 unsigned long addr = addr0;
5552 int do_color_align;
5553+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5554 struct vm_unmapped_area_info info;
5555
5556 if (unlikely(len > TASK_SIZE))
5557@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5558 do_color_align = 1;
5559
5560 /* requesting a specific address */
5561+
5562+#ifdef CONFIG_PAX_RANDMMAP
5563+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5564+#endif
5565+
5566 if (addr) {
5567 if (do_color_align)
5568 addr = COLOUR_ALIGN(addr, pgoff);
5569@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5570 addr = PAGE_ALIGN(addr);
5571
5572 vma = find_vma(mm, addr);
5573- if (TASK_SIZE - len >= addr &&
5574- (!vma || addr + len <= vma->vm_start))
5575+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5576 return addr;
5577 }
5578
5579@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5580 {
5581 unsigned long random_factor = 0UL;
5582
5583+#ifdef CONFIG_PAX_RANDMMAP
5584+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5585+#endif
5586+
5587 if (current->flags & PF_RANDOMIZE) {
5588 random_factor = get_random_int();
5589 random_factor = random_factor << PAGE_SHIFT;
5590@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5591
5592 if (mmap_is_legacy()) {
5593 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5594+
5595+#ifdef CONFIG_PAX_RANDMMAP
5596+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5597+ mm->mmap_base += mm->delta_mmap;
5598+#endif
5599+
5600 mm->get_unmapped_area = arch_get_unmapped_area;
5601 mm->unmap_area = arch_unmap_area;
5602 } else {
5603 mm->mmap_base = mmap_base(random_factor);
5604+
5605+#ifdef CONFIG_PAX_RANDMMAP
5606+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5607+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5608+#endif
5609+
5610 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5611 mm->unmap_area = arch_unmap_area_topdown;
5612 }
5613 }
5614
5615-static inline unsigned long brk_rnd(void)
5616-{
5617- unsigned long rnd = get_random_int();
5618-
5619- rnd = rnd << PAGE_SHIFT;
5620- /* 8MB for 32bit, 256MB for 64bit */
5621- if (TASK_IS_32BIT_ADDR)
5622- rnd = rnd & 0x7ffffful;
5623- else
5624- rnd = rnd & 0xffffffful;
5625-
5626- return rnd;
5627-}
5628-
5629-unsigned long arch_randomize_brk(struct mm_struct *mm)
5630-{
5631- unsigned long base = mm->brk;
5632- unsigned long ret;
5633-
5634- ret = PAGE_ALIGN(base + brk_rnd());
5635-
5636- if (ret < mm->brk)
5637- return mm->brk;
5638-
5639- return ret;
5640-}
5641-
5642 int __virt_addr_valid(const volatile void *kaddr)
5643 {
5644 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5645diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5646index 967d144..db12197 100644
5647--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5648+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5649@@ -11,12 +11,14 @@
5650 #ifndef _ASM_PROC_CACHE_H
5651 #define _ASM_PROC_CACHE_H
5652
5653+#include <linux/const.h>
5654+
5655 /* L1 cache */
5656
5657 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5658 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5659-#define L1_CACHE_BYTES 16 /* bytes per entry */
5660 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5661+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5662 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5663
5664 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5665diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5666index bcb5df2..84fabd2 100644
5667--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5668+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5669@@ -16,13 +16,15 @@
5670 #ifndef _ASM_PROC_CACHE_H
5671 #define _ASM_PROC_CACHE_H
5672
5673+#include <linux/const.h>
5674+
5675 /*
5676 * L1 cache
5677 */
5678 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5679 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5680-#define L1_CACHE_BYTES 32 /* bytes per entry */
5681 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5682+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5683 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5684
5685 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5686diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5687index 4ce7a01..449202a 100644
5688--- a/arch/openrisc/include/asm/cache.h
5689+++ b/arch/openrisc/include/asm/cache.h
5690@@ -19,11 +19,13 @@
5691 #ifndef __ASM_OPENRISC_CACHE_H
5692 #define __ASM_OPENRISC_CACHE_H
5693
5694+#include <linux/const.h>
5695+
5696 /* FIXME: How can we replace these with values from the CPU...
5697 * they shouldn't be hard-coded!
5698 */
5699
5700-#define L1_CACHE_BYTES 16
5701 #define L1_CACHE_SHIFT 4
5702+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5703
5704 #endif /* __ASM_OPENRISC_CACHE_H */
5705diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5706index af9cf30..2aae9b2 100644
5707--- a/arch/parisc/include/asm/atomic.h
5708+++ b/arch/parisc/include/asm/atomic.h
5709@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5710
5711 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5712
5713+#define atomic64_read_unchecked(v) atomic64_read(v)
5714+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5715+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5716+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5717+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5718+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5719+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5720+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5721+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5722+
5723 #endif /* !CONFIG_64BIT */
5724
5725
5726diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5727index 47f11c7..3420df2 100644
5728--- a/arch/parisc/include/asm/cache.h
5729+++ b/arch/parisc/include/asm/cache.h
5730@@ -5,6 +5,7 @@
5731 #ifndef __ARCH_PARISC_CACHE_H
5732 #define __ARCH_PARISC_CACHE_H
5733
5734+#include <linux/const.h>
5735
5736 /*
5737 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5738@@ -15,13 +16,13 @@
5739 * just ruin performance.
5740 */
5741 #ifdef CONFIG_PA20
5742-#define L1_CACHE_BYTES 64
5743 #define L1_CACHE_SHIFT 6
5744 #else
5745-#define L1_CACHE_BYTES 32
5746 #define L1_CACHE_SHIFT 5
5747 #endif
5748
5749+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5750+
5751 #ifndef __ASSEMBLY__
5752
5753 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5754diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5755index 19f6cb1..6c78cf2 100644
5756--- a/arch/parisc/include/asm/elf.h
5757+++ b/arch/parisc/include/asm/elf.h
5758@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5759
5760 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5761
5762+#ifdef CONFIG_PAX_ASLR
5763+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5764+
5765+#define PAX_DELTA_MMAP_LEN 16
5766+#define PAX_DELTA_STACK_LEN 16
5767+#endif
5768+
5769 /* This yields a mask that user programs can use to figure out what
5770 instruction set this CPU supports. This could be done in user space,
5771 but it's not easy, and we've already done it here. */
5772diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5773index fc987a1..6e068ef 100644
5774--- a/arch/parisc/include/asm/pgalloc.h
5775+++ b/arch/parisc/include/asm/pgalloc.h
5776@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5777 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5778 }
5779
5780+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5781+{
5782+ pgd_populate(mm, pgd, pmd);
5783+}
5784+
5785 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5786 {
5787 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5788@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5789 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5790 #define pmd_free(mm, x) do { } while (0)
5791 #define pgd_populate(mm, pmd, pte) BUG()
5792+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5793
5794 #endif
5795
5796diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5797index 7df49fa..38b62bf 100644
5798--- a/arch/parisc/include/asm/pgtable.h
5799+++ b/arch/parisc/include/asm/pgtable.h
5800@@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5801 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5802 #define PAGE_COPY PAGE_EXECREAD
5803 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5804+
5805+#ifdef CONFIG_PAX_PAGEEXEC
5806+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5807+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5808+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5809+#else
5810+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5811+# define PAGE_COPY_NOEXEC PAGE_COPY
5812+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5813+#endif
5814+
5815 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5816 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5817 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5818diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5819index 4ba2c93..f5e3974 100644
5820--- a/arch/parisc/include/asm/uaccess.h
5821+++ b/arch/parisc/include/asm/uaccess.h
5822@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5823 const void __user *from,
5824 unsigned long n)
5825 {
5826- int sz = __compiletime_object_size(to);
5827+ size_t sz = __compiletime_object_size(to);
5828 int ret = -EFAULT;
5829
5830- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5831+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5832 ret = __copy_from_user(to, from, n);
5833 else
5834 copy_from_user_overflow();
5835diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5836index 2a625fb..9908930 100644
5837--- a/arch/parisc/kernel/module.c
5838+++ b/arch/parisc/kernel/module.c
5839@@ -98,16 +98,38 @@
5840
5841 /* three functions to determine where in the module core
5842 * or init pieces the location is */
5843+static inline int in_init_rx(struct module *me, void *loc)
5844+{
5845+ return (loc >= me->module_init_rx &&
5846+ loc < (me->module_init_rx + me->init_size_rx));
5847+}
5848+
5849+static inline int in_init_rw(struct module *me, void *loc)
5850+{
5851+ return (loc >= me->module_init_rw &&
5852+ loc < (me->module_init_rw + me->init_size_rw));
5853+}
5854+
5855 static inline int in_init(struct module *me, void *loc)
5856 {
5857- return (loc >= me->module_init &&
5858- loc <= (me->module_init + me->init_size));
5859+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5860+}
5861+
5862+static inline int in_core_rx(struct module *me, void *loc)
5863+{
5864+ return (loc >= me->module_core_rx &&
5865+ loc < (me->module_core_rx + me->core_size_rx));
5866+}
5867+
5868+static inline int in_core_rw(struct module *me, void *loc)
5869+{
5870+ return (loc >= me->module_core_rw &&
5871+ loc < (me->module_core_rw + me->core_size_rw));
5872 }
5873
5874 static inline int in_core(struct module *me, void *loc)
5875 {
5876- return (loc >= me->module_core &&
5877- loc <= (me->module_core + me->core_size));
5878+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5879 }
5880
5881 static inline int in_local(struct module *me, void *loc)
5882@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5883 }
5884
5885 /* align things a bit */
5886- me->core_size = ALIGN(me->core_size, 16);
5887- me->arch.got_offset = me->core_size;
5888- me->core_size += gots * sizeof(struct got_entry);
5889+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5890+ me->arch.got_offset = me->core_size_rw;
5891+ me->core_size_rw += gots * sizeof(struct got_entry);
5892
5893- me->core_size = ALIGN(me->core_size, 16);
5894- me->arch.fdesc_offset = me->core_size;
5895- me->core_size += fdescs * sizeof(Elf_Fdesc);
5896+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5897+ me->arch.fdesc_offset = me->core_size_rw;
5898+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5899
5900 me->arch.got_max = gots;
5901 me->arch.fdesc_max = fdescs;
5902@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5903
5904 BUG_ON(value == 0);
5905
5906- got = me->module_core + me->arch.got_offset;
5907+ got = me->module_core_rw + me->arch.got_offset;
5908 for (i = 0; got[i].addr; i++)
5909 if (got[i].addr == value)
5910 goto out;
5911@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5912 #ifdef CONFIG_64BIT
5913 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5914 {
5915- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5916+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5917
5918 if (!value) {
5919 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5920@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5921
5922 /* Create new one */
5923 fdesc->addr = value;
5924- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5925+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5926 return (Elf_Addr)fdesc;
5927 }
5928 #endif /* CONFIG_64BIT */
5929@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5930
5931 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5932 end = table + sechdrs[me->arch.unwind_section].sh_size;
5933- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5934+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5935
5936 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5937 me->arch.unwind_section, table, end, gp);
5938diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5939index f76c108..92bad82 100644
5940--- a/arch/parisc/kernel/sys_parisc.c
5941+++ b/arch/parisc/kernel/sys_parisc.c
5942@@ -33,9 +33,11 @@
5943 #include <linux/utsname.h>
5944 #include <linux/personality.h>
5945
5946-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5947+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5948+ unsigned long flags)
5949 {
5950 struct vm_area_struct *vma;
5951+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5952
5953 addr = PAGE_ALIGN(addr);
5954
5955@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5956 /* At this point: (!vma || addr < vma->vm_end). */
5957 if (TASK_SIZE - len < addr)
5958 return -ENOMEM;
5959- if (!vma || addr + len <= vma->vm_start)
5960+ if (check_heap_stack_gap(vma, addr, len, offset))
5961 return addr;
5962 addr = vma->vm_end;
5963 }
5964@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5965 return offset & 0x3FF000;
5966 }
5967
5968-static unsigned long get_shared_area(struct address_space *mapping,
5969- unsigned long addr, unsigned long len, unsigned long pgoff)
5970+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5971+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5972 {
5973 struct vm_area_struct *vma;
5974 int offset = mapping ? get_offset(mapping) : 0;
5975+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5976
5977 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5978
5979@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5980 /* At this point: (!vma || addr < vma->vm_end). */
5981 if (TASK_SIZE - len < addr)
5982 return -ENOMEM;
5983- if (!vma || addr + len <= vma->vm_start)
5984+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
5985 return addr;
5986 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5987 if (addr < vma->vm_end) /* handle wraparound */
5988@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5989 if (flags & MAP_FIXED)
5990 return addr;
5991 if (!addr)
5992- addr = TASK_UNMAPPED_BASE;
5993+ addr = current->mm->mmap_base;
5994
5995 if (filp) {
5996- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5997+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5998 } else if(flags & MAP_SHARED) {
5999- addr = get_shared_area(NULL, addr, len, pgoff);
6000+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6001 } else {
6002- addr = get_unshared_area(addr, len);
6003+ addr = get_unshared_area(filp, addr, len, flags);
6004 }
6005 return addr;
6006 }
6007diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6008index 45ba99f..8e22c33 100644
6009--- a/arch/parisc/kernel/traps.c
6010+++ b/arch/parisc/kernel/traps.c
6011@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6012
6013 down_read(&current->mm->mmap_sem);
6014 vma = find_vma(current->mm,regs->iaoq[0]);
6015- if (vma && (regs->iaoq[0] >= vma->vm_start)
6016- && (vma->vm_flags & VM_EXEC)) {
6017-
6018+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6019 fault_address = regs->iaoq[0];
6020 fault_space = regs->iasq[0];
6021
6022diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6023index 18162ce..94de376 100644
6024--- a/arch/parisc/mm/fault.c
6025+++ b/arch/parisc/mm/fault.c
6026@@ -15,6 +15,7 @@
6027 #include <linux/sched.h>
6028 #include <linux/interrupt.h>
6029 #include <linux/module.h>
6030+#include <linux/unistd.h>
6031
6032 #include <asm/uaccess.h>
6033 #include <asm/traps.h>
6034@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6035 static unsigned long
6036 parisc_acctyp(unsigned long code, unsigned int inst)
6037 {
6038- if (code == 6 || code == 16)
6039+ if (code == 6 || code == 7 || code == 16)
6040 return VM_EXEC;
6041
6042 switch (inst & 0xf0000000) {
6043@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6044 }
6045 #endif
6046
6047+#ifdef CONFIG_PAX_PAGEEXEC
6048+/*
6049+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6050+ *
6051+ * returns 1 when task should be killed
6052+ * 2 when rt_sigreturn trampoline was detected
6053+ * 3 when unpatched PLT trampoline was detected
6054+ */
6055+static int pax_handle_fetch_fault(struct pt_regs *regs)
6056+{
6057+
6058+#ifdef CONFIG_PAX_EMUPLT
6059+ int err;
6060+
6061+ do { /* PaX: unpatched PLT emulation */
6062+ unsigned int bl, depwi;
6063+
6064+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6065+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6066+
6067+ if (err)
6068+ break;
6069+
6070+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6071+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6072+
6073+ err = get_user(ldw, (unsigned int *)addr);
6074+ err |= get_user(bv, (unsigned int *)(addr+4));
6075+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6076+
6077+ if (err)
6078+ break;
6079+
6080+ if (ldw == 0x0E801096U &&
6081+ bv == 0xEAC0C000U &&
6082+ ldw2 == 0x0E881095U)
6083+ {
6084+ unsigned int resolver, map;
6085+
6086+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6087+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6088+ if (err)
6089+ break;
6090+
6091+ regs->gr[20] = instruction_pointer(regs)+8;
6092+ regs->gr[21] = map;
6093+ regs->gr[22] = resolver;
6094+ regs->iaoq[0] = resolver | 3UL;
6095+ regs->iaoq[1] = regs->iaoq[0] + 4;
6096+ return 3;
6097+ }
6098+ }
6099+ } while (0);
6100+#endif
6101+
6102+#ifdef CONFIG_PAX_EMUTRAMP
6103+
6104+#ifndef CONFIG_PAX_EMUSIGRT
6105+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6106+ return 1;
6107+#endif
6108+
6109+ do { /* PaX: rt_sigreturn emulation */
6110+ unsigned int ldi1, ldi2, bel, nop;
6111+
6112+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6113+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6114+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6115+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6116+
6117+ if (err)
6118+ break;
6119+
6120+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6121+ ldi2 == 0x3414015AU &&
6122+ bel == 0xE4008200U &&
6123+ nop == 0x08000240U)
6124+ {
6125+ regs->gr[25] = (ldi1 & 2) >> 1;
6126+ regs->gr[20] = __NR_rt_sigreturn;
6127+ regs->gr[31] = regs->iaoq[1] + 16;
6128+ regs->sr[0] = regs->iasq[1];
6129+ regs->iaoq[0] = 0x100UL;
6130+ regs->iaoq[1] = regs->iaoq[0] + 4;
6131+ regs->iasq[0] = regs->sr[2];
6132+ regs->iasq[1] = regs->sr[2];
6133+ return 2;
6134+ }
6135+ } while (0);
6136+#endif
6137+
6138+ return 1;
6139+}
6140+
6141+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6142+{
6143+ unsigned long i;
6144+
6145+ printk(KERN_ERR "PAX: bytes at PC: ");
6146+ for (i = 0; i < 5; i++) {
6147+ unsigned int c;
6148+ if (get_user(c, (unsigned int *)pc+i))
6149+ printk(KERN_CONT "???????? ");
6150+ else
6151+ printk(KERN_CONT "%08x ", c);
6152+ }
6153+ printk("\n");
6154+}
6155+#endif
6156+
6157 int fixup_exception(struct pt_regs *regs)
6158 {
6159 const struct exception_table_entry *fix;
6160@@ -192,8 +303,33 @@ good_area:
6161
6162 acc_type = parisc_acctyp(code,regs->iir);
6163
6164- if ((vma->vm_flags & acc_type) != acc_type)
6165+ if ((vma->vm_flags & acc_type) != acc_type) {
6166+
6167+#ifdef CONFIG_PAX_PAGEEXEC
6168+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6169+ (address & ~3UL) == instruction_pointer(regs))
6170+ {
6171+ up_read(&mm->mmap_sem);
6172+ switch (pax_handle_fetch_fault(regs)) {
6173+
6174+#ifdef CONFIG_PAX_EMUPLT
6175+ case 3:
6176+ return;
6177+#endif
6178+
6179+#ifdef CONFIG_PAX_EMUTRAMP
6180+ case 2:
6181+ return;
6182+#endif
6183+
6184+ }
6185+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6186+ do_group_exit(SIGKILL);
6187+ }
6188+#endif
6189+
6190 goto bad_area;
6191+ }
6192
6193 /*
6194 * If for any reason at all we couldn't handle the fault, make
6195diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6196index e3b1d41..8e81edf 100644
6197--- a/arch/powerpc/include/asm/atomic.h
6198+++ b/arch/powerpc/include/asm/atomic.h
6199@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6200 return t1;
6201 }
6202
6203+#define atomic64_read_unchecked(v) atomic64_read(v)
6204+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6205+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6206+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6207+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6208+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6209+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6210+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6211+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6212+
6213 #endif /* __powerpc64__ */
6214
6215 #endif /* __KERNEL__ */
6216diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6217index 9e495c9..b6878e5 100644
6218--- a/arch/powerpc/include/asm/cache.h
6219+++ b/arch/powerpc/include/asm/cache.h
6220@@ -3,6 +3,7 @@
6221
6222 #ifdef __KERNEL__
6223
6224+#include <linux/const.h>
6225
6226 /* bytes per L1 cache line */
6227 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6228@@ -22,7 +23,7 @@
6229 #define L1_CACHE_SHIFT 7
6230 #endif
6231
6232-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6233+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6234
6235 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6236
6237diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6238index 6abf0a1..459d0f1 100644
6239--- a/arch/powerpc/include/asm/elf.h
6240+++ b/arch/powerpc/include/asm/elf.h
6241@@ -28,8 +28,19 @@
6242 the loader. We need to make sure that it is out of the way of the program
6243 that it will "exec", and that there is sufficient room for the brk. */
6244
6245-extern unsigned long randomize_et_dyn(unsigned long base);
6246-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6247+#define ELF_ET_DYN_BASE (0x20000000)
6248+
6249+#ifdef CONFIG_PAX_ASLR
6250+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6251+
6252+#ifdef __powerpc64__
6253+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6254+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6255+#else
6256+#define PAX_DELTA_MMAP_LEN 15
6257+#define PAX_DELTA_STACK_LEN 15
6258+#endif
6259+#endif
6260
6261 /*
6262 * Our registers are always unsigned longs, whether we're a 32 bit
6263@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6264 (0x7ff >> (PAGE_SHIFT - 12)) : \
6265 (0x3ffff >> (PAGE_SHIFT - 12)))
6266
6267-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6268-#define arch_randomize_brk arch_randomize_brk
6269-
6270-
6271 #ifdef CONFIG_SPU_BASE
6272 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6273 #define NT_SPU 1
6274diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6275index 8196e9c..d83a9f3 100644
6276--- a/arch/powerpc/include/asm/exec.h
6277+++ b/arch/powerpc/include/asm/exec.h
6278@@ -4,6 +4,6 @@
6279 #ifndef _ASM_POWERPC_EXEC_H
6280 #define _ASM_POWERPC_EXEC_H
6281
6282-extern unsigned long arch_align_stack(unsigned long sp);
6283+#define arch_align_stack(x) ((x) & ~0xfUL)
6284
6285 #endif /* _ASM_POWERPC_EXEC_H */
6286diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6287index 5acabbd..7ea14fa 100644
6288--- a/arch/powerpc/include/asm/kmap_types.h
6289+++ b/arch/powerpc/include/asm/kmap_types.h
6290@@ -10,7 +10,7 @@
6291 * 2 of the License, or (at your option) any later version.
6292 */
6293
6294-#define KM_TYPE_NR 16
6295+#define KM_TYPE_NR 17
6296
6297 #endif /* __KERNEL__ */
6298 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6299diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6300index 8565c25..2865190 100644
6301--- a/arch/powerpc/include/asm/mman.h
6302+++ b/arch/powerpc/include/asm/mman.h
6303@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6304 }
6305 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6306
6307-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6308+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6309 {
6310 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6311 }
6312diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6313index f072e97..b436dee 100644
6314--- a/arch/powerpc/include/asm/page.h
6315+++ b/arch/powerpc/include/asm/page.h
6316@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6317 * and needs to be executable. This means the whole heap ends
6318 * up being executable.
6319 */
6320-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6321- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6322+#define VM_DATA_DEFAULT_FLAGS32 \
6323+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6324+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6325
6326 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6327 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6328@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6329 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6330 #endif
6331
6332+#define ktla_ktva(addr) (addr)
6333+#define ktva_ktla(addr) (addr)
6334+
6335 /*
6336 * Use the top bit of the higher-level page table entries to indicate whether
6337 * the entries we point to contain hugepages. This works because we know that
6338diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6339index cd915d6..c10cee8 100644
6340--- a/arch/powerpc/include/asm/page_64.h
6341+++ b/arch/powerpc/include/asm/page_64.h
6342@@ -154,15 +154,18 @@ do { \
6343 * stack by default, so in the absence of a PT_GNU_STACK program header
6344 * we turn execute permission off.
6345 */
6346-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6347- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6348+#define VM_STACK_DEFAULT_FLAGS32 \
6349+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6350+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6351
6352 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6353 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6354
6355+#ifndef CONFIG_PAX_PAGEEXEC
6356 #define VM_STACK_DEFAULT_FLAGS \
6357 (is_32bit_task() ? \
6358 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6359+#endif
6360
6361 #include <asm-generic/getorder.h>
6362
6363diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6364index 292725c..f87ae14 100644
6365--- a/arch/powerpc/include/asm/pgalloc-64.h
6366+++ b/arch/powerpc/include/asm/pgalloc-64.h
6367@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6368 #ifndef CONFIG_PPC_64K_PAGES
6369
6370 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6371+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6372
6373 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6374 {
6375@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6376 pud_set(pud, (unsigned long)pmd);
6377 }
6378
6379+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6380+{
6381+ pud_populate(mm, pud, pmd);
6382+}
6383+
6384 #define pmd_populate(mm, pmd, pte_page) \
6385 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6386 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6387@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6388 #else /* CONFIG_PPC_64K_PAGES */
6389
6390 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6391+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6392
6393 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6394 pte_t *pte)
6395diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6396index a9cbd3b..3b67efa 100644
6397--- a/arch/powerpc/include/asm/pgtable.h
6398+++ b/arch/powerpc/include/asm/pgtable.h
6399@@ -2,6 +2,7 @@
6400 #define _ASM_POWERPC_PGTABLE_H
6401 #ifdef __KERNEL__
6402
6403+#include <linux/const.h>
6404 #ifndef __ASSEMBLY__
6405 #include <asm/processor.h> /* For TASK_SIZE */
6406 #include <asm/mmu.h>
6407diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6408index 4aad413..85d86bf 100644
6409--- a/arch/powerpc/include/asm/pte-hash32.h
6410+++ b/arch/powerpc/include/asm/pte-hash32.h
6411@@ -21,6 +21,7 @@
6412 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6413 #define _PAGE_USER 0x004 /* usermode access allowed */
6414 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6415+#define _PAGE_EXEC _PAGE_GUARDED
6416 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6417 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6418 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6419diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6420index 3d5c9dc..62f8414 100644
6421--- a/arch/powerpc/include/asm/reg.h
6422+++ b/arch/powerpc/include/asm/reg.h
6423@@ -215,6 +215,7 @@
6424 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6425 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6426 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6427+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6428 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6429 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6430 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6431diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6432index 406b7b9..af63426 100644
6433--- a/arch/powerpc/include/asm/thread_info.h
6434+++ b/arch/powerpc/include/asm/thread_info.h
6435@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6436 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6437 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6438 #define TIF_SINGLESTEP 8 /* singlestepping active */
6439-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6440 #define TIF_SECCOMP 10 /* secure computing */
6441 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6442 #define TIF_NOERROR 12 /* Force successful syscall return */
6443@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6444 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6445 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6446 for stack store? */
6447+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6448+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6449+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6450
6451 /* as above, but as bit values */
6452 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6453@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6454 #define _TIF_UPROBE (1<<TIF_UPROBE)
6455 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6456 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6457+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6458 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6459- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6460+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6461+ _TIF_GRSEC_SETXID)
6462
6463 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6464 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6465diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6466index 4db4959..335e00c 100644
6467--- a/arch/powerpc/include/asm/uaccess.h
6468+++ b/arch/powerpc/include/asm/uaccess.h
6469@@ -13,6 +13,8 @@
6470 #define VERIFY_READ 0
6471 #define VERIFY_WRITE 1
6472
6473+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6474+
6475 /*
6476 * The fs value determines whether argument validity checking should be
6477 * performed or not. If get_fs() == USER_DS, checking is performed, with
6478@@ -318,52 +320,6 @@ do { \
6479 extern unsigned long __copy_tofrom_user(void __user *to,
6480 const void __user *from, unsigned long size);
6481
6482-#ifndef __powerpc64__
6483-
6484-static inline unsigned long copy_from_user(void *to,
6485- const void __user *from, unsigned long n)
6486-{
6487- unsigned long over;
6488-
6489- if (access_ok(VERIFY_READ, from, n))
6490- return __copy_tofrom_user((__force void __user *)to, from, n);
6491- if ((unsigned long)from < TASK_SIZE) {
6492- over = (unsigned long)from + n - TASK_SIZE;
6493- return __copy_tofrom_user((__force void __user *)to, from,
6494- n - over) + over;
6495- }
6496- return n;
6497-}
6498-
6499-static inline unsigned long copy_to_user(void __user *to,
6500- const void *from, unsigned long n)
6501-{
6502- unsigned long over;
6503-
6504- if (access_ok(VERIFY_WRITE, to, n))
6505- return __copy_tofrom_user(to, (__force void __user *)from, n);
6506- if ((unsigned long)to < TASK_SIZE) {
6507- over = (unsigned long)to + n - TASK_SIZE;
6508- return __copy_tofrom_user(to, (__force void __user *)from,
6509- n - over) + over;
6510- }
6511- return n;
6512-}
6513-
6514-#else /* __powerpc64__ */
6515-
6516-#define __copy_in_user(to, from, size) \
6517- __copy_tofrom_user((to), (from), (size))
6518-
6519-extern unsigned long copy_from_user(void *to, const void __user *from,
6520- unsigned long n);
6521-extern unsigned long copy_to_user(void __user *to, const void *from,
6522- unsigned long n);
6523-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6524- unsigned long n);
6525-
6526-#endif /* __powerpc64__ */
6527-
6528 static inline unsigned long __copy_from_user_inatomic(void *to,
6529 const void __user *from, unsigned long n)
6530 {
6531@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6532 if (ret == 0)
6533 return 0;
6534 }
6535+
6536+ if (!__builtin_constant_p(n))
6537+ check_object_size(to, n, false);
6538+
6539 return __copy_tofrom_user((__force void __user *)to, from, n);
6540 }
6541
6542@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6543 if (ret == 0)
6544 return 0;
6545 }
6546+
6547+ if (!__builtin_constant_p(n))
6548+ check_object_size(from, n, true);
6549+
6550 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6551 }
6552
6553@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6554 return __copy_to_user_inatomic(to, from, size);
6555 }
6556
6557+#ifndef __powerpc64__
6558+
6559+static inline unsigned long __must_check copy_from_user(void *to,
6560+ const void __user *from, unsigned long n)
6561+{
6562+ unsigned long over;
6563+
6564+ if ((long)n < 0)
6565+ return n;
6566+
6567+ if (access_ok(VERIFY_READ, from, n)) {
6568+ if (!__builtin_constant_p(n))
6569+ check_object_size(to, n, false);
6570+ return __copy_tofrom_user((__force void __user *)to, from, n);
6571+ }
6572+ if ((unsigned long)from < TASK_SIZE) {
6573+ over = (unsigned long)from + n - TASK_SIZE;
6574+ if (!__builtin_constant_p(n - over))
6575+ check_object_size(to, n - over, false);
6576+ return __copy_tofrom_user((__force void __user *)to, from,
6577+ n - over) + over;
6578+ }
6579+ return n;
6580+}
6581+
6582+static inline unsigned long __must_check copy_to_user(void __user *to,
6583+ const void *from, unsigned long n)
6584+{
6585+ unsigned long over;
6586+
6587+ if ((long)n < 0)
6588+ return n;
6589+
6590+ if (access_ok(VERIFY_WRITE, to, n)) {
6591+ if (!__builtin_constant_p(n))
6592+ check_object_size(from, n, true);
6593+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6594+ }
6595+ if ((unsigned long)to < TASK_SIZE) {
6596+ over = (unsigned long)to + n - TASK_SIZE;
6597+ if (!__builtin_constant_p(n))
6598+ check_object_size(from, n - over, true);
6599+ return __copy_tofrom_user(to, (__force void __user *)from,
6600+ n - over) + over;
6601+ }
6602+ return n;
6603+}
6604+
6605+#else /* __powerpc64__ */
6606+
6607+#define __copy_in_user(to, from, size) \
6608+ __copy_tofrom_user((to), (from), (size))
6609+
6610+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6611+{
6612+ if ((long)n < 0 || n > INT_MAX)
6613+ return n;
6614+
6615+ if (!__builtin_constant_p(n))
6616+ check_object_size(to, n, false);
6617+
6618+ if (likely(access_ok(VERIFY_READ, from, n)))
6619+ n = __copy_from_user(to, from, n);
6620+ else
6621+ memset(to, 0, n);
6622+ return n;
6623+}
6624+
6625+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6626+{
6627+ if ((long)n < 0 || n > INT_MAX)
6628+ return n;
6629+
6630+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6631+ if (!__builtin_constant_p(n))
6632+ check_object_size(from, n, true);
6633+ n = __copy_to_user(to, from, n);
6634+ }
6635+ return n;
6636+}
6637+
6638+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6639+ unsigned long n);
6640+
6641+#endif /* __powerpc64__ */
6642+
6643 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6644
6645 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6646diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6647index 4684e33..acc4d19e 100644
6648--- a/arch/powerpc/kernel/exceptions-64e.S
6649+++ b/arch/powerpc/kernel/exceptions-64e.S
6650@@ -715,6 +715,7 @@ storage_fault_common:
6651 std r14,_DAR(r1)
6652 std r15,_DSISR(r1)
6653 addi r3,r1,STACK_FRAME_OVERHEAD
6654+ bl .save_nvgprs
6655 mr r4,r14
6656 mr r5,r15
6657 ld r14,PACA_EXGEN+EX_R14(r13)
6658@@ -723,8 +724,7 @@ storage_fault_common:
6659 cmpdi r3,0
6660 bne- 1f
6661 b .ret_from_except_lite
6662-1: bl .save_nvgprs
6663- mr r5,r3
6664+1: mr r5,r3
6665 addi r3,r1,STACK_FRAME_OVERHEAD
6666 ld r4,_DAR(r1)
6667 bl .bad_page_fault
6668diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6669index 3684cbd..bc89eab 100644
6670--- a/arch/powerpc/kernel/exceptions-64s.S
6671+++ b/arch/powerpc/kernel/exceptions-64s.S
6672@@ -1206,10 +1206,10 @@ handle_page_fault:
6673 11: ld r4,_DAR(r1)
6674 ld r5,_DSISR(r1)
6675 addi r3,r1,STACK_FRAME_OVERHEAD
6676+ bl .save_nvgprs
6677 bl .do_page_fault
6678 cmpdi r3,0
6679 beq+ 12f
6680- bl .save_nvgprs
6681 mr r5,r3
6682 addi r3,r1,STACK_FRAME_OVERHEAD
6683 lwz r4,_DAR(r1)
6684diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6685index 2e3200c..72095ce 100644
6686--- a/arch/powerpc/kernel/module_32.c
6687+++ b/arch/powerpc/kernel/module_32.c
6688@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6689 me->arch.core_plt_section = i;
6690 }
6691 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6692- printk("Module doesn't contain .plt or .init.plt sections.\n");
6693+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6694 return -ENOEXEC;
6695 }
6696
6697@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6698
6699 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6700 /* Init, or core PLT? */
6701- if (location >= mod->module_core
6702- && location < mod->module_core + mod->core_size)
6703+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6704+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6705 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6706- else
6707+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6708+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6709 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6710+ else {
6711+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6712+ return ~0UL;
6713+ }
6714
6715 /* Find this entry, or if that fails, the next avail. entry */
6716 while (entry->jump[0]) {
6717diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6718index 8143067..21ae55b 100644
6719--- a/arch/powerpc/kernel/process.c
6720+++ b/arch/powerpc/kernel/process.c
6721@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6722 * Lookup NIP late so we have the best change of getting the
6723 * above info out without failing
6724 */
6725- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6726- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6727+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6728+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6729 #endif
6730 show_stack(current, (unsigned long *) regs->gpr[1]);
6731 if (!user_mode(regs))
6732@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6733 newsp = stack[0];
6734 ip = stack[STACK_FRAME_LR_SAVE];
6735 if (!firstframe || ip != lr) {
6736- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6737+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6738 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6739 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6740- printk(" (%pS)",
6741+ printk(" (%pA)",
6742 (void *)current->ret_stack[curr_frame].ret);
6743 curr_frame--;
6744 }
6745@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6746 struct pt_regs *regs = (struct pt_regs *)
6747 (sp + STACK_FRAME_OVERHEAD);
6748 lr = regs->link;
6749- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6750+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6751 regs->trap, (void *)regs->nip, (void *)lr);
6752 firstframe = 1;
6753 }
6754@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6755 mtspr(SPRN_CTRLT, ctrl);
6756 }
6757 #endif /* CONFIG_PPC64 */
6758-
6759-unsigned long arch_align_stack(unsigned long sp)
6760-{
6761- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6762- sp -= get_random_int() & ~PAGE_MASK;
6763- return sp & ~0xf;
6764-}
6765-
6766-static inline unsigned long brk_rnd(void)
6767-{
6768- unsigned long rnd = 0;
6769-
6770- /* 8MB for 32bit, 1GB for 64bit */
6771- if (is_32bit_task())
6772- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6773- else
6774- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6775-
6776- return rnd << PAGE_SHIFT;
6777-}
6778-
6779-unsigned long arch_randomize_brk(struct mm_struct *mm)
6780-{
6781- unsigned long base = mm->brk;
6782- unsigned long ret;
6783-
6784-#ifdef CONFIG_PPC_STD_MMU_64
6785- /*
6786- * If we are using 1TB segments and we are allowed to randomise
6787- * the heap, we can put it above 1TB so it is backed by a 1TB
6788- * segment. Otherwise the heap will be in the bottom 1TB
6789- * which always uses 256MB segments and this may result in a
6790- * performance penalty.
6791- */
6792- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6793- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6794-#endif
6795-
6796- ret = PAGE_ALIGN(base + brk_rnd());
6797-
6798- if (ret < mm->brk)
6799- return mm->brk;
6800-
6801- return ret;
6802-}
6803-
6804-unsigned long randomize_et_dyn(unsigned long base)
6805-{
6806- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6807-
6808- if (ret < base)
6809- return base;
6810-
6811- return ret;
6812-}
6813diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6814index c497000..8fde506 100644
6815--- a/arch/powerpc/kernel/ptrace.c
6816+++ b/arch/powerpc/kernel/ptrace.c
6817@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6818 return ret;
6819 }
6820
6821+#ifdef CONFIG_GRKERNSEC_SETXID
6822+extern void gr_delayed_cred_worker(void);
6823+#endif
6824+
6825 /*
6826 * We must return the syscall number to actually look up in the table.
6827 * This can be -1L to skip running any syscall at all.
6828@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6829
6830 secure_computing_strict(regs->gpr[0]);
6831
6832+#ifdef CONFIG_GRKERNSEC_SETXID
6833+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6834+ gr_delayed_cred_worker();
6835+#endif
6836+
6837 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6838 tracehook_report_syscall_entry(regs))
6839 /*
6840@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6841 {
6842 int step;
6843
6844+#ifdef CONFIG_GRKERNSEC_SETXID
6845+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6846+ gr_delayed_cred_worker();
6847+#endif
6848+
6849 audit_syscall_exit(regs);
6850
6851 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6852diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6853index 804e323..79181c1 100644
6854--- a/arch/powerpc/kernel/signal_32.c
6855+++ b/arch/powerpc/kernel/signal_32.c
6856@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6857 /* Save user registers on the stack */
6858 frame = &rt_sf->uc.uc_mcontext;
6859 addr = frame;
6860- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6861+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6862 if (save_user_regs(regs, frame, 0, 1))
6863 goto badframe;
6864 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6865diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6866index 1ca045d..139c3f7 100644
6867--- a/arch/powerpc/kernel/signal_64.c
6868+++ b/arch/powerpc/kernel/signal_64.c
6869@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6870 current->thread.fpscr.val = 0;
6871
6872 /* Set up to return from userspace. */
6873- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6874+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6875 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6876 } else {
6877 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6878diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6879index 3ce1f86..c30e629 100644
6880--- a/arch/powerpc/kernel/sysfs.c
6881+++ b/arch/powerpc/kernel/sysfs.c
6882@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6883 return NOTIFY_OK;
6884 }
6885
6886-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6887+static struct notifier_block sysfs_cpu_nb = {
6888 .notifier_call = sysfs_cpu_notify,
6889 };
6890
6891diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6892index 3251840..3f7c77a 100644
6893--- a/arch/powerpc/kernel/traps.c
6894+++ b/arch/powerpc/kernel/traps.c
6895@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6896 return flags;
6897 }
6898
6899+extern void gr_handle_kernel_exploit(void);
6900+
6901 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6902 int signr)
6903 {
6904@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6905 panic("Fatal exception in interrupt");
6906 if (panic_on_oops)
6907 panic("Fatal exception");
6908+
6909+ gr_handle_kernel_exploit();
6910+
6911 do_exit(signr);
6912 }
6913
6914diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6915index 1b2076f..835e4be 100644
6916--- a/arch/powerpc/kernel/vdso.c
6917+++ b/arch/powerpc/kernel/vdso.c
6918@@ -34,6 +34,7 @@
6919 #include <asm/firmware.h>
6920 #include <asm/vdso.h>
6921 #include <asm/vdso_datapage.h>
6922+#include <asm/mman.h>
6923
6924 #include "setup.h"
6925
6926@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6927 vdso_base = VDSO32_MBASE;
6928 #endif
6929
6930- current->mm->context.vdso_base = 0;
6931+ current->mm->context.vdso_base = ~0UL;
6932
6933 /* vDSO has a problem and was disabled, just don't "enable" it for the
6934 * process
6935@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6936 vdso_base = get_unmapped_area(NULL, vdso_base,
6937 (vdso_pages << PAGE_SHIFT) +
6938 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6939- 0, 0);
6940+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6941 if (IS_ERR_VALUE(vdso_base)) {
6942 rc = vdso_base;
6943 goto fail_mmapsem;
6944diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6945index 5eea6f3..5d10396 100644
6946--- a/arch/powerpc/lib/usercopy_64.c
6947+++ b/arch/powerpc/lib/usercopy_64.c
6948@@ -9,22 +9,6 @@
6949 #include <linux/module.h>
6950 #include <asm/uaccess.h>
6951
6952-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6953-{
6954- if (likely(access_ok(VERIFY_READ, from, n)))
6955- n = __copy_from_user(to, from, n);
6956- else
6957- memset(to, 0, n);
6958- return n;
6959-}
6960-
6961-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6962-{
6963- if (likely(access_ok(VERIFY_WRITE, to, n)))
6964- n = __copy_to_user(to, from, n);
6965- return n;
6966-}
6967-
6968 unsigned long copy_in_user(void __user *to, const void __user *from,
6969 unsigned long n)
6970 {
6971@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6972 return n;
6973 }
6974
6975-EXPORT_SYMBOL(copy_from_user);
6976-EXPORT_SYMBOL(copy_to_user);
6977 EXPORT_SYMBOL(copy_in_user);
6978
6979diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6980index 3a8489a..6a63b3b 100644
6981--- a/arch/powerpc/mm/fault.c
6982+++ b/arch/powerpc/mm/fault.c
6983@@ -32,6 +32,10 @@
6984 #include <linux/perf_event.h>
6985 #include <linux/magic.h>
6986 #include <linux/ratelimit.h>
6987+#include <linux/slab.h>
6988+#include <linux/pagemap.h>
6989+#include <linux/compiler.h>
6990+#include <linux/unistd.h>
6991
6992 #include <asm/firmware.h>
6993 #include <asm/page.h>
6994@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6995 }
6996 #endif
6997
6998+#ifdef CONFIG_PAX_PAGEEXEC
6999+/*
7000+ * PaX: decide what to do with offenders (regs->nip = fault address)
7001+ *
7002+ * returns 1 when task should be killed
7003+ */
7004+static int pax_handle_fetch_fault(struct pt_regs *regs)
7005+{
7006+ return 1;
7007+}
7008+
7009+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7010+{
7011+ unsigned long i;
7012+
7013+ printk(KERN_ERR "PAX: bytes at PC: ");
7014+ for (i = 0; i < 5; i++) {
7015+ unsigned int c;
7016+ if (get_user(c, (unsigned int __user *)pc+i))
7017+ printk(KERN_CONT "???????? ");
7018+ else
7019+ printk(KERN_CONT "%08x ", c);
7020+ }
7021+ printk("\n");
7022+}
7023+#endif
7024+
7025 /*
7026 * Check whether the instruction at regs->nip is a store using
7027 * an update addressing form which will update r1.
7028@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7029 * indicate errors in DSISR but can validly be set in SRR1.
7030 */
7031 if (trap == 0x400)
7032- error_code &= 0x48200000;
7033+ error_code &= 0x58200000;
7034 else
7035 is_write = error_code & DSISR_ISSTORE;
7036 #else
7037@@ -364,7 +395,7 @@ good_area:
7038 * "undefined". Of those that can be set, this is the only
7039 * one which seems bad.
7040 */
7041- if (error_code & 0x10000000)
7042+ if (error_code & DSISR_GUARDED)
7043 /* Guarded storage error. */
7044 goto bad_area;
7045 #endif /* CONFIG_8xx */
7046@@ -379,7 +410,7 @@ good_area:
7047 * processors use the same I/D cache coherency mechanism
7048 * as embedded.
7049 */
7050- if (error_code & DSISR_PROTFAULT)
7051+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7052 goto bad_area;
7053 #endif /* CONFIG_PPC_STD_MMU */
7054
7055@@ -462,6 +493,23 @@ bad_area:
7056 bad_area_nosemaphore:
7057 /* User mode accesses cause a SIGSEGV */
7058 if (user_mode(regs)) {
7059+
7060+#ifdef CONFIG_PAX_PAGEEXEC
7061+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7062+#ifdef CONFIG_PPC_STD_MMU
7063+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7064+#else
7065+ if (is_exec && regs->nip == address) {
7066+#endif
7067+ switch (pax_handle_fetch_fault(regs)) {
7068+ }
7069+
7070+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7071+ do_group_exit(SIGKILL);
7072+ }
7073+ }
7074+#endif
7075+
7076 _exception(SIGSEGV, regs, code, address);
7077 return 0;
7078 }
7079diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7080index 67a42ed..cd463e0 100644
7081--- a/arch/powerpc/mm/mmap_64.c
7082+++ b/arch/powerpc/mm/mmap_64.c
7083@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7084 {
7085 unsigned long rnd = 0;
7086
7087+#ifdef CONFIG_PAX_RANDMMAP
7088+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7089+#endif
7090+
7091 if (current->flags & PF_RANDOMIZE) {
7092 /* 8MB for 32bit, 1GB for 64bit */
7093 if (is_32bit_task())
7094@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7095 */
7096 if (mmap_is_legacy()) {
7097 mm->mmap_base = TASK_UNMAPPED_BASE;
7098+
7099+#ifdef CONFIG_PAX_RANDMMAP
7100+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7101+ mm->mmap_base += mm->delta_mmap;
7102+#endif
7103+
7104 mm->get_unmapped_area = arch_get_unmapped_area;
7105 mm->unmap_area = arch_unmap_area;
7106 } else {
7107 mm->mmap_base = mmap_base();
7108+
7109+#ifdef CONFIG_PAX_RANDMMAP
7110+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7111+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7112+#endif
7113+
7114 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7115 mm->unmap_area = arch_unmap_area_topdown;
7116 }
7117diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7118index e779642..e5bb889 100644
7119--- a/arch/powerpc/mm/mmu_context_nohash.c
7120+++ b/arch/powerpc/mm/mmu_context_nohash.c
7121@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7122 return NOTIFY_OK;
7123 }
7124
7125-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7126+static struct notifier_block mmu_context_cpu_nb = {
7127 .notifier_call = mmu_context_cpu_notify,
7128 };
7129
7130diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7131index bba87ca..c346a33 100644
7132--- a/arch/powerpc/mm/numa.c
7133+++ b/arch/powerpc/mm/numa.c
7134@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7135 return ret;
7136 }
7137
7138-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7139+static struct notifier_block ppc64_numa_nb = {
7140 .notifier_call = cpu_numa_callback,
7141 .priority = 1 /* Must run before sched domains notifier. */
7142 };
7143diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7144index cf9dada..241529f 100644
7145--- a/arch/powerpc/mm/slice.c
7146+++ b/arch/powerpc/mm/slice.c
7147@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7148 if ((mm->task_size - len) < addr)
7149 return 0;
7150 vma = find_vma(mm, addr);
7151- return (!vma || (addr + len) <= vma->vm_start);
7152+ return check_heap_stack_gap(vma, addr, len, 0);
7153 }
7154
7155 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7156@@ -272,7 +272,7 @@ full_search:
7157 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7158 continue;
7159 }
7160- if (!vma || addr + len <= vma->vm_start) {
7161+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7162 /*
7163 * Remember the place where we stopped the search:
7164 */
7165@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7166 }
7167 }
7168
7169- addr = mm->mmap_base;
7170- while (addr > len) {
7171+ if (mm->mmap_base < len)
7172+ addr = -ENOMEM;
7173+ else
7174+ addr = mm->mmap_base - len;
7175+
7176+ while (!IS_ERR_VALUE(addr)) {
7177 /* Go down by chunk size */
7178- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7179+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7180
7181 /* Check for hit with different page size */
7182 mask = slice_range_to_mask(addr, len);
7183@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7184 * return with success:
7185 */
7186 vma = find_vma(mm, addr);
7187- if (!vma || (addr + len) <= vma->vm_start) {
7188+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7189 /* remember the address as a hint for next time */
7190 if (use_cache)
7191 mm->free_area_cache = addr;
7192@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7193 mm->cached_hole_size = vma->vm_start - addr;
7194
7195 /* try just below the current vma->vm_start */
7196- addr = vma->vm_start;
7197+ addr = skip_heap_stack_gap(vma, len, 0);
7198 }
7199
7200 /*
7201@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7202 if (fixed && addr > (mm->task_size - len))
7203 return -EINVAL;
7204
7205+#ifdef CONFIG_PAX_RANDMMAP
7206+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7207+ addr = 0;
7208+#endif
7209+
7210 /* If hint, make sure it matches our alignment restrictions */
7211 if (!fixed && addr) {
7212 addr = _ALIGN_UP(addr, 1ul << pshift);
7213diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7214index bdb738a..49c9f95 100644
7215--- a/arch/powerpc/platforms/powermac/smp.c
7216+++ b/arch/powerpc/platforms/powermac/smp.c
7217@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7218 return NOTIFY_OK;
7219 }
7220
7221-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7222+static struct notifier_block smp_core99_cpu_nb = {
7223 .notifier_call = smp_core99_cpu_notify,
7224 };
7225 #endif /* CONFIG_HOTPLUG_CPU */
7226diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7227index c797832..ce575c8 100644
7228--- a/arch/s390/include/asm/atomic.h
7229+++ b/arch/s390/include/asm/atomic.h
7230@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7231 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7232 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7233
7234+#define atomic64_read_unchecked(v) atomic64_read(v)
7235+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7236+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7237+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7238+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7239+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7240+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7241+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7242+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7243+
7244 #define smp_mb__before_atomic_dec() smp_mb()
7245 #define smp_mb__after_atomic_dec() smp_mb()
7246 #define smp_mb__before_atomic_inc() smp_mb()
7247diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7248index 4d7ccac..d03d0ad 100644
7249--- a/arch/s390/include/asm/cache.h
7250+++ b/arch/s390/include/asm/cache.h
7251@@ -9,8 +9,10 @@
7252 #ifndef __ARCH_S390_CACHE_H
7253 #define __ARCH_S390_CACHE_H
7254
7255-#define L1_CACHE_BYTES 256
7256+#include <linux/const.h>
7257+
7258 #define L1_CACHE_SHIFT 8
7259+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7260 #define NET_SKB_PAD 32
7261
7262 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7263diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7264index 178ff96..8c93bd1 100644
7265--- a/arch/s390/include/asm/elf.h
7266+++ b/arch/s390/include/asm/elf.h
7267@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7268 the loader. We need to make sure that it is out of the way of the program
7269 that it will "exec", and that there is sufficient room for the brk. */
7270
7271-extern unsigned long randomize_et_dyn(unsigned long base);
7272-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7273+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7274+
7275+#ifdef CONFIG_PAX_ASLR
7276+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7277+
7278+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7279+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7280+#endif
7281
7282 /* This yields a mask that user programs can use to figure out what
7283 instruction set this CPU supports. */
7284@@ -210,9 +216,6 @@ struct linux_binprm;
7285 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7286 int arch_setup_additional_pages(struct linux_binprm *, int);
7287
7288-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7289-#define arch_randomize_brk arch_randomize_brk
7290-
7291 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7292
7293 #endif
7294diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7295index c4a93d6..4d2a9b4 100644
7296--- a/arch/s390/include/asm/exec.h
7297+++ b/arch/s390/include/asm/exec.h
7298@@ -7,6 +7,6 @@
7299 #ifndef __ASM_EXEC_H
7300 #define __ASM_EXEC_H
7301
7302-extern unsigned long arch_align_stack(unsigned long sp);
7303+#define arch_align_stack(x) ((x) & ~0xfUL)
7304
7305 #endif /* __ASM_EXEC_H */
7306diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7307index 34268df..ea97318 100644
7308--- a/arch/s390/include/asm/uaccess.h
7309+++ b/arch/s390/include/asm/uaccess.h
7310@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7311 copy_to_user(void __user *to, const void *from, unsigned long n)
7312 {
7313 might_fault();
7314+
7315+ if ((long)n < 0)
7316+ return n;
7317+
7318 if (access_ok(VERIFY_WRITE, to, n))
7319 n = __copy_to_user(to, from, n);
7320 return n;
7321@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7322 static inline unsigned long __must_check
7323 __copy_from_user(void *to, const void __user *from, unsigned long n)
7324 {
7325+ if ((long)n < 0)
7326+ return n;
7327+
7328 if (__builtin_constant_p(n) && (n <= 256))
7329 return uaccess.copy_from_user_small(n, from, to);
7330 else
7331@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7332 static inline unsigned long __must_check
7333 copy_from_user(void *to, const void __user *from, unsigned long n)
7334 {
7335- unsigned int sz = __compiletime_object_size(to);
7336+ size_t sz = __compiletime_object_size(to);
7337
7338 might_fault();
7339- if (unlikely(sz != -1 && sz < n)) {
7340+
7341+ if ((long)n < 0)
7342+ return n;
7343+
7344+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7345 copy_from_user_overflow();
7346 return n;
7347 }
7348diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7349index 4610dea..cf0af21 100644
7350--- a/arch/s390/kernel/module.c
7351+++ b/arch/s390/kernel/module.c
7352@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7353
7354 /* Increase core size by size of got & plt and set start
7355 offsets for got and plt. */
7356- me->core_size = ALIGN(me->core_size, 4);
7357- me->arch.got_offset = me->core_size;
7358- me->core_size += me->arch.got_size;
7359- me->arch.plt_offset = me->core_size;
7360- me->core_size += me->arch.plt_size;
7361+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7362+ me->arch.got_offset = me->core_size_rw;
7363+ me->core_size_rw += me->arch.got_size;
7364+ me->arch.plt_offset = me->core_size_rx;
7365+ me->core_size_rx += me->arch.plt_size;
7366 return 0;
7367 }
7368
7369@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7370 if (info->got_initialized == 0) {
7371 Elf_Addr *gotent;
7372
7373- gotent = me->module_core + me->arch.got_offset +
7374+ gotent = me->module_core_rw + me->arch.got_offset +
7375 info->got_offset;
7376 *gotent = val;
7377 info->got_initialized = 1;
7378@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7379 else if (r_type == R_390_GOTENT ||
7380 r_type == R_390_GOTPLTENT)
7381 *(unsigned int *) loc =
7382- (val + (Elf_Addr) me->module_core - loc) >> 1;
7383+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7384 else if (r_type == R_390_GOT64 ||
7385 r_type == R_390_GOTPLT64)
7386 *(unsigned long *) loc = val;
7387@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7388 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7389 if (info->plt_initialized == 0) {
7390 unsigned int *ip;
7391- ip = me->module_core + me->arch.plt_offset +
7392+ ip = me->module_core_rx + me->arch.plt_offset +
7393 info->plt_offset;
7394 #ifndef CONFIG_64BIT
7395 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7396@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7397 val - loc + 0xffffUL < 0x1ffffeUL) ||
7398 (r_type == R_390_PLT32DBL &&
7399 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7400- val = (Elf_Addr) me->module_core +
7401+ val = (Elf_Addr) me->module_core_rx +
7402 me->arch.plt_offset +
7403 info->plt_offset;
7404 val += rela->r_addend - loc;
7405@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7406 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7407 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7408 val = val + rela->r_addend -
7409- ((Elf_Addr) me->module_core + me->arch.got_offset);
7410+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7411 if (r_type == R_390_GOTOFF16)
7412 *(unsigned short *) loc = val;
7413 else if (r_type == R_390_GOTOFF32)
7414@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7415 break;
7416 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7417 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7418- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7419+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7420 rela->r_addend - loc;
7421 if (r_type == R_390_GOTPC)
7422 *(unsigned int *) loc = val;
7423diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7424index 536d645..4a5bd9e 100644
7425--- a/arch/s390/kernel/process.c
7426+++ b/arch/s390/kernel/process.c
7427@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7428 }
7429 return 0;
7430 }
7431-
7432-unsigned long arch_align_stack(unsigned long sp)
7433-{
7434- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7435- sp -= get_random_int() & ~PAGE_MASK;
7436- return sp & ~0xf;
7437-}
7438-
7439-static inline unsigned long brk_rnd(void)
7440-{
7441- /* 8MB for 32bit, 1GB for 64bit */
7442- if (is_32bit_task())
7443- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7444- else
7445- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7446-}
7447-
7448-unsigned long arch_randomize_brk(struct mm_struct *mm)
7449-{
7450- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7451-
7452- if (ret < mm->brk)
7453- return mm->brk;
7454- return ret;
7455-}
7456-
7457-unsigned long randomize_et_dyn(unsigned long base)
7458-{
7459- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7460-
7461- if (!(current->flags & PF_RANDOMIZE))
7462- return base;
7463- if (ret < base)
7464- return base;
7465- return ret;
7466-}
7467diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7468index c59a5ef..3fae59c 100644
7469--- a/arch/s390/mm/mmap.c
7470+++ b/arch/s390/mm/mmap.c
7471@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7472 */
7473 if (mmap_is_legacy()) {
7474 mm->mmap_base = TASK_UNMAPPED_BASE;
7475+
7476+#ifdef CONFIG_PAX_RANDMMAP
7477+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7478+ mm->mmap_base += mm->delta_mmap;
7479+#endif
7480+
7481 mm->get_unmapped_area = arch_get_unmapped_area;
7482 mm->unmap_area = arch_unmap_area;
7483 } else {
7484 mm->mmap_base = mmap_base();
7485+
7486+#ifdef CONFIG_PAX_RANDMMAP
7487+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7488+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7489+#endif
7490+
7491 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7492 mm->unmap_area = arch_unmap_area_topdown;
7493 }
7494@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7495 */
7496 if (mmap_is_legacy()) {
7497 mm->mmap_base = TASK_UNMAPPED_BASE;
7498+
7499+#ifdef CONFIG_PAX_RANDMMAP
7500+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7501+ mm->mmap_base += mm->delta_mmap;
7502+#endif
7503+
7504 mm->get_unmapped_area = s390_get_unmapped_area;
7505 mm->unmap_area = arch_unmap_area;
7506 } else {
7507 mm->mmap_base = mmap_base();
7508+
7509+#ifdef CONFIG_PAX_RANDMMAP
7510+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7511+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7512+#endif
7513+
7514 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7515 mm->unmap_area = arch_unmap_area_topdown;
7516 }
7517diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7518index ae3d59f..f65f075 100644
7519--- a/arch/score/include/asm/cache.h
7520+++ b/arch/score/include/asm/cache.h
7521@@ -1,7 +1,9 @@
7522 #ifndef _ASM_SCORE_CACHE_H
7523 #define _ASM_SCORE_CACHE_H
7524
7525+#include <linux/const.h>
7526+
7527 #define L1_CACHE_SHIFT 4
7528-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7529+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7530
7531 #endif /* _ASM_SCORE_CACHE_H */
7532diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7533index f9f3cd5..58ff438 100644
7534--- a/arch/score/include/asm/exec.h
7535+++ b/arch/score/include/asm/exec.h
7536@@ -1,6 +1,6 @@
7537 #ifndef _ASM_SCORE_EXEC_H
7538 #define _ASM_SCORE_EXEC_H
7539
7540-extern unsigned long arch_align_stack(unsigned long sp);
7541+#define arch_align_stack(x) (x)
7542
7543 #endif /* _ASM_SCORE_EXEC_H */
7544diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7545index 7956846..5f37677 100644
7546--- a/arch/score/kernel/process.c
7547+++ b/arch/score/kernel/process.c
7548@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7549
7550 return task_pt_regs(task)->cp0_epc;
7551 }
7552-
7553-unsigned long arch_align_stack(unsigned long sp)
7554-{
7555- return sp;
7556-}
7557diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7558index ef9e555..331bd29 100644
7559--- a/arch/sh/include/asm/cache.h
7560+++ b/arch/sh/include/asm/cache.h
7561@@ -9,10 +9,11 @@
7562 #define __ASM_SH_CACHE_H
7563 #ifdef __KERNEL__
7564
7565+#include <linux/const.h>
7566 #include <linux/init.h>
7567 #include <cpu/cache.h>
7568
7569-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7570+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7571
7572 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7573
7574diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7575index 03f2b55..b027032 100644
7576--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7577+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7578@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7579 return NOTIFY_OK;
7580 }
7581
7582-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7583+static struct notifier_block shx3_cpu_notifier = {
7584 .notifier_call = shx3_cpu_callback,
7585 };
7586
7587diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7588index 6777177..cb5e44f 100644
7589--- a/arch/sh/mm/mmap.c
7590+++ b/arch/sh/mm/mmap.c
7591@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7592 struct mm_struct *mm = current->mm;
7593 struct vm_area_struct *vma;
7594 int do_colour_align;
7595+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7596 struct vm_unmapped_area_info info;
7597
7598 if (flags & MAP_FIXED) {
7599@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7600 if (filp || (flags & MAP_SHARED))
7601 do_colour_align = 1;
7602
7603+#ifdef CONFIG_PAX_RANDMMAP
7604+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7605+#endif
7606+
7607 if (addr) {
7608 if (do_colour_align)
7609 addr = COLOUR_ALIGN(addr, pgoff);
7610@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7611 addr = PAGE_ALIGN(addr);
7612
7613 vma = find_vma(mm, addr);
7614- if (TASK_SIZE - len >= addr &&
7615- (!vma || addr + len <= vma->vm_start))
7616+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7617 return addr;
7618 }
7619
7620 info.flags = 0;
7621 info.length = len;
7622- info.low_limit = TASK_UNMAPPED_BASE;
7623+ info.low_limit = mm->mmap_base;
7624 info.high_limit = TASK_SIZE;
7625 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7626 info.align_offset = pgoff << PAGE_SHIFT;
7627@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7628 struct mm_struct *mm = current->mm;
7629 unsigned long addr = addr0;
7630 int do_colour_align;
7631+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7632 struct vm_unmapped_area_info info;
7633
7634 if (flags & MAP_FIXED) {
7635@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7636 if (filp || (flags & MAP_SHARED))
7637 do_colour_align = 1;
7638
7639+#ifdef CONFIG_PAX_RANDMMAP
7640+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7641+#endif
7642+
7643 /* requesting a specific address */
7644 if (addr) {
7645 if (do_colour_align)
7646@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7647 addr = PAGE_ALIGN(addr);
7648
7649 vma = find_vma(mm, addr);
7650- if (TASK_SIZE - len >= addr &&
7651- (!vma || addr + len <= vma->vm_start))
7652+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7653 return addr;
7654 }
7655
7656@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7657 VM_BUG_ON(addr != -ENOMEM);
7658 info.flags = 0;
7659 info.low_limit = TASK_UNMAPPED_BASE;
7660+
7661+#ifdef CONFIG_PAX_RANDMMAP
7662+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7663+ info.low_limit += mm->delta_mmap;
7664+#endif
7665+
7666 info.high_limit = TASK_SIZE;
7667 addr = vm_unmapped_area(&info);
7668 }
7669diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7670index be56a24..443328f 100644
7671--- a/arch/sparc/include/asm/atomic_64.h
7672+++ b/arch/sparc/include/asm/atomic_64.h
7673@@ -14,18 +14,40 @@
7674 #define ATOMIC64_INIT(i) { (i) }
7675
7676 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7677+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7678+{
7679+ return v->counter;
7680+}
7681 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7682+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7683+{
7684+ return v->counter;
7685+}
7686
7687 #define atomic_set(v, i) (((v)->counter) = i)
7688+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7689+{
7690+ v->counter = i;
7691+}
7692 #define atomic64_set(v, i) (((v)->counter) = i)
7693+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7694+{
7695+ v->counter = i;
7696+}
7697
7698 extern void atomic_add(int, atomic_t *);
7699+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7700 extern void atomic64_add(long, atomic64_t *);
7701+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7702 extern void atomic_sub(int, atomic_t *);
7703+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7704 extern void atomic64_sub(long, atomic64_t *);
7705+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7706
7707 extern int atomic_add_ret(int, atomic_t *);
7708+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7709 extern long atomic64_add_ret(long, atomic64_t *);
7710+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7711 extern int atomic_sub_ret(int, atomic_t *);
7712 extern long atomic64_sub_ret(long, atomic64_t *);
7713
7714@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7715 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7716
7717 #define atomic_inc_return(v) atomic_add_ret(1, v)
7718+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7719+{
7720+ return atomic_add_ret_unchecked(1, v);
7721+}
7722 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7723+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7724+{
7725+ return atomic64_add_ret_unchecked(1, v);
7726+}
7727
7728 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7729 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7730
7731 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7732+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7733+{
7734+ return atomic_add_ret_unchecked(i, v);
7735+}
7736 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7737+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7738+{
7739+ return atomic64_add_ret_unchecked(i, v);
7740+}
7741
7742 /*
7743 * atomic_inc_and_test - increment and test
7744@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7745 * other cases.
7746 */
7747 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7748+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7749+{
7750+ return atomic_inc_return_unchecked(v) == 0;
7751+}
7752 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7753
7754 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7755@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7756 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7757
7758 #define atomic_inc(v) atomic_add(1, v)
7759+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7760+{
7761+ atomic_add_unchecked(1, v);
7762+}
7763 #define atomic64_inc(v) atomic64_add(1, v)
7764+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7765+{
7766+ atomic64_add_unchecked(1, v);
7767+}
7768
7769 #define atomic_dec(v) atomic_sub(1, v)
7770+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7771+{
7772+ atomic_sub_unchecked(1, v);
7773+}
7774 #define atomic64_dec(v) atomic64_sub(1, v)
7775+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7776+{
7777+ atomic64_sub_unchecked(1, v);
7778+}
7779
7780 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7781 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7782
7783 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7784+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7785+{
7786+ return cmpxchg(&v->counter, old, new);
7787+}
7788 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7789+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7790+{
7791+ return xchg(&v->counter, new);
7792+}
7793
7794 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7795 {
7796- int c, old;
7797+ int c, old, new;
7798 c = atomic_read(v);
7799 for (;;) {
7800- if (unlikely(c == (u)))
7801+ if (unlikely(c == u))
7802 break;
7803- old = atomic_cmpxchg((v), c, c + (a));
7804+
7805+ asm volatile("addcc %2, %0, %0\n"
7806+
7807+#ifdef CONFIG_PAX_REFCOUNT
7808+ "tvs %%icc, 6\n"
7809+#endif
7810+
7811+ : "=r" (new)
7812+ : "0" (c), "ir" (a)
7813+ : "cc");
7814+
7815+ old = atomic_cmpxchg(v, c, new);
7816 if (likely(old == c))
7817 break;
7818 c = old;
7819@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7820 #define atomic64_cmpxchg(v, o, n) \
7821 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7822 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7823+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7824+{
7825+ return xchg(&v->counter, new);
7826+}
7827
7828 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7829 {
7830- long c, old;
7831+ long c, old, new;
7832 c = atomic64_read(v);
7833 for (;;) {
7834- if (unlikely(c == (u)))
7835+ if (unlikely(c == u))
7836 break;
7837- old = atomic64_cmpxchg((v), c, c + (a));
7838+
7839+ asm volatile("addcc %2, %0, %0\n"
7840+
7841+#ifdef CONFIG_PAX_REFCOUNT
7842+ "tvs %%xcc, 6\n"
7843+#endif
7844+
7845+ : "=r" (new)
7846+ : "0" (c), "ir" (a)
7847+ : "cc");
7848+
7849+ old = atomic64_cmpxchg(v, c, new);
7850 if (likely(old == c))
7851 break;
7852 c = old;
7853 }
7854- return c != (u);
7855+ return c != u;
7856 }
7857
7858 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7859diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7860index 5bb6991..5c2132e 100644
7861--- a/arch/sparc/include/asm/cache.h
7862+++ b/arch/sparc/include/asm/cache.h
7863@@ -7,10 +7,12 @@
7864 #ifndef _SPARC_CACHE_H
7865 #define _SPARC_CACHE_H
7866
7867+#include <linux/const.h>
7868+
7869 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7870
7871 #define L1_CACHE_SHIFT 5
7872-#define L1_CACHE_BYTES 32
7873+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7874
7875 #ifdef CONFIG_SPARC32
7876 #define SMP_CACHE_BYTES_SHIFT 5
7877diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7878index ac74a2c..a9e58af 100644
7879--- a/arch/sparc/include/asm/elf_32.h
7880+++ b/arch/sparc/include/asm/elf_32.h
7881@@ -114,6 +114,13 @@ typedef struct {
7882
7883 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7884
7885+#ifdef CONFIG_PAX_ASLR
7886+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7887+
7888+#define PAX_DELTA_MMAP_LEN 16
7889+#define PAX_DELTA_STACK_LEN 16
7890+#endif
7891+
7892 /* This yields a mask that user programs can use to figure out what
7893 instruction set this cpu supports. This can NOT be done in userspace
7894 on Sparc. */
7895diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7896index 370ca1e..d4f4a98 100644
7897--- a/arch/sparc/include/asm/elf_64.h
7898+++ b/arch/sparc/include/asm/elf_64.h
7899@@ -189,6 +189,13 @@ typedef struct {
7900 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7901 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7902
7903+#ifdef CONFIG_PAX_ASLR
7904+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7905+
7906+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7907+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7908+#endif
7909+
7910 extern unsigned long sparc64_elf_hwcap;
7911 #define ELF_HWCAP sparc64_elf_hwcap
7912
7913diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7914index 9b1c36d..209298b 100644
7915--- a/arch/sparc/include/asm/pgalloc_32.h
7916+++ b/arch/sparc/include/asm/pgalloc_32.h
7917@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7918 }
7919
7920 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7921+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7922
7923 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7924 unsigned long address)
7925diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7926index bcfe063..b333142 100644
7927--- a/arch/sparc/include/asm/pgalloc_64.h
7928+++ b/arch/sparc/include/asm/pgalloc_64.h
7929@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7930 }
7931
7932 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7933+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7934
7935 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7936 {
7937diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7938index 6fc1348..390c50a 100644
7939--- a/arch/sparc/include/asm/pgtable_32.h
7940+++ b/arch/sparc/include/asm/pgtable_32.h
7941@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7942 #define PAGE_SHARED SRMMU_PAGE_SHARED
7943 #define PAGE_COPY SRMMU_PAGE_COPY
7944 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7945+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7946+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7947+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7948 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7949
7950 /* Top-level page directory - dummy used by init-mm.
7951@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7952
7953 /* xwr */
7954 #define __P000 PAGE_NONE
7955-#define __P001 PAGE_READONLY
7956-#define __P010 PAGE_COPY
7957-#define __P011 PAGE_COPY
7958+#define __P001 PAGE_READONLY_NOEXEC
7959+#define __P010 PAGE_COPY_NOEXEC
7960+#define __P011 PAGE_COPY_NOEXEC
7961 #define __P100 PAGE_READONLY
7962 #define __P101 PAGE_READONLY
7963 #define __P110 PAGE_COPY
7964 #define __P111 PAGE_COPY
7965
7966 #define __S000 PAGE_NONE
7967-#define __S001 PAGE_READONLY
7968-#define __S010 PAGE_SHARED
7969-#define __S011 PAGE_SHARED
7970+#define __S001 PAGE_READONLY_NOEXEC
7971+#define __S010 PAGE_SHARED_NOEXEC
7972+#define __S011 PAGE_SHARED_NOEXEC
7973 #define __S100 PAGE_READONLY
7974 #define __S101 PAGE_READONLY
7975 #define __S110 PAGE_SHARED
7976diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7977index 79da178..c2eede8 100644
7978--- a/arch/sparc/include/asm/pgtsrmmu.h
7979+++ b/arch/sparc/include/asm/pgtsrmmu.h
7980@@ -115,6 +115,11 @@
7981 SRMMU_EXEC | SRMMU_REF)
7982 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7983 SRMMU_EXEC | SRMMU_REF)
7984+
7985+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7986+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7987+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7988+
7989 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7990 SRMMU_DIRTY | SRMMU_REF)
7991
7992diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7993index 9689176..63c18ea 100644
7994--- a/arch/sparc/include/asm/spinlock_64.h
7995+++ b/arch/sparc/include/asm/spinlock_64.h
7996@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7997
7998 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7999
8000-static void inline arch_read_lock(arch_rwlock_t *lock)
8001+static inline void arch_read_lock(arch_rwlock_t *lock)
8002 {
8003 unsigned long tmp1, tmp2;
8004
8005 __asm__ __volatile__ (
8006 "1: ldsw [%2], %0\n"
8007 " brlz,pn %0, 2f\n"
8008-"4: add %0, 1, %1\n"
8009+"4: addcc %0, 1, %1\n"
8010+
8011+#ifdef CONFIG_PAX_REFCOUNT
8012+" tvs %%icc, 6\n"
8013+#endif
8014+
8015 " cas [%2], %0, %1\n"
8016 " cmp %0, %1\n"
8017 " bne,pn %%icc, 1b\n"
8018@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8019 " .previous"
8020 : "=&r" (tmp1), "=&r" (tmp2)
8021 : "r" (lock)
8022- : "memory");
8023+ : "memory", "cc");
8024 }
8025
8026-static int inline arch_read_trylock(arch_rwlock_t *lock)
8027+static inline int arch_read_trylock(arch_rwlock_t *lock)
8028 {
8029 int tmp1, tmp2;
8030
8031@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8032 "1: ldsw [%2], %0\n"
8033 " brlz,a,pn %0, 2f\n"
8034 " mov 0, %0\n"
8035-" add %0, 1, %1\n"
8036+" addcc %0, 1, %1\n"
8037+
8038+#ifdef CONFIG_PAX_REFCOUNT
8039+" tvs %%icc, 6\n"
8040+#endif
8041+
8042 " cas [%2], %0, %1\n"
8043 " cmp %0, %1\n"
8044 " bne,pn %%icc, 1b\n"
8045@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8046 return tmp1;
8047 }
8048
8049-static void inline arch_read_unlock(arch_rwlock_t *lock)
8050+static inline void arch_read_unlock(arch_rwlock_t *lock)
8051 {
8052 unsigned long tmp1, tmp2;
8053
8054 __asm__ __volatile__(
8055 "1: lduw [%2], %0\n"
8056-" sub %0, 1, %1\n"
8057+" subcc %0, 1, %1\n"
8058+
8059+#ifdef CONFIG_PAX_REFCOUNT
8060+" tvs %%icc, 6\n"
8061+#endif
8062+
8063 " cas [%2], %0, %1\n"
8064 " cmp %0, %1\n"
8065 " bne,pn %%xcc, 1b\n"
8066@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8067 : "memory");
8068 }
8069
8070-static void inline arch_write_lock(arch_rwlock_t *lock)
8071+static inline void arch_write_lock(arch_rwlock_t *lock)
8072 {
8073 unsigned long mask, tmp1, tmp2;
8074
8075@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8076 : "memory");
8077 }
8078
8079-static void inline arch_write_unlock(arch_rwlock_t *lock)
8080+static inline void arch_write_unlock(arch_rwlock_t *lock)
8081 {
8082 __asm__ __volatile__(
8083 " stw %%g0, [%0]"
8084@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8085 : "memory");
8086 }
8087
8088-static int inline arch_write_trylock(arch_rwlock_t *lock)
8089+static inline int arch_write_trylock(arch_rwlock_t *lock)
8090 {
8091 unsigned long mask, tmp1, tmp2, result;
8092
8093diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8094index 25849ae..924c54b 100644
8095--- a/arch/sparc/include/asm/thread_info_32.h
8096+++ b/arch/sparc/include/asm/thread_info_32.h
8097@@ -49,6 +49,8 @@ struct thread_info {
8098 unsigned long w_saved;
8099
8100 struct restart_block restart_block;
8101+
8102+ unsigned long lowest_stack;
8103 };
8104
8105 /*
8106diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8107index 269bd92..e46a9b8 100644
8108--- a/arch/sparc/include/asm/thread_info_64.h
8109+++ b/arch/sparc/include/asm/thread_info_64.h
8110@@ -63,6 +63,8 @@ struct thread_info {
8111 struct pt_regs *kern_una_regs;
8112 unsigned int kern_una_insn;
8113
8114+ unsigned long lowest_stack;
8115+
8116 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8117 };
8118
8119@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8120 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8121 /* flag bit 6 is available */
8122 #define TIF_32BIT 7 /* 32-bit binary */
8123-/* flag bit 8 is available */
8124+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8125 #define TIF_SECCOMP 9 /* secure computing */
8126 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8127 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8128+
8129 /* NOTE: Thread flags >= 12 should be ones we have no interest
8130 * in using in assembly, else we can't use the mask as
8131 * an immediate value in instructions such as andcc.
8132@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8133 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8134 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8135 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8136+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8137
8138 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8139 _TIF_DO_NOTIFY_RESUME_MASK | \
8140 _TIF_NEED_RESCHED)
8141 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8142
8143+#define _TIF_WORK_SYSCALL \
8144+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8145+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8146+
8147+
8148 /*
8149 * Thread-synchronous status.
8150 *
8151diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8152index 0167d26..9acd8ed 100644
8153--- a/arch/sparc/include/asm/uaccess.h
8154+++ b/arch/sparc/include/asm/uaccess.h
8155@@ -1,5 +1,13 @@
8156 #ifndef ___ASM_SPARC_UACCESS_H
8157 #define ___ASM_SPARC_UACCESS_H
8158+
8159+#ifdef __KERNEL__
8160+#ifndef __ASSEMBLY__
8161+#include <linux/types.h>
8162+extern void check_object_size(const void *ptr, unsigned long n, bool to);
8163+#endif
8164+#endif
8165+
8166 #if defined(__sparc__) && defined(__arch64__)
8167 #include <asm/uaccess_64.h>
8168 #else
8169diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8170index 53a28dd..50c38c3 100644
8171--- a/arch/sparc/include/asm/uaccess_32.h
8172+++ b/arch/sparc/include/asm/uaccess_32.h
8173@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8174
8175 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8176 {
8177- if (n && __access_ok((unsigned long) to, n))
8178+ if ((long)n < 0)
8179+ return n;
8180+
8181+ if (n && __access_ok((unsigned long) to, n)) {
8182+ if (!__builtin_constant_p(n))
8183+ check_object_size(from, n, true);
8184 return __copy_user(to, (__force void __user *) from, n);
8185- else
8186+ } else
8187 return n;
8188 }
8189
8190 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8191 {
8192+ if ((long)n < 0)
8193+ return n;
8194+
8195+ if (!__builtin_constant_p(n))
8196+ check_object_size(from, n, true);
8197+
8198 return __copy_user(to, (__force void __user *) from, n);
8199 }
8200
8201 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8202 {
8203- if (n && __access_ok((unsigned long) from, n))
8204+ if ((long)n < 0)
8205+ return n;
8206+
8207+ if (n && __access_ok((unsigned long) from, n)) {
8208+ if (!__builtin_constant_p(n))
8209+ check_object_size(to, n, false);
8210 return __copy_user((__force void __user *) to, from, n);
8211- else
8212+ } else
8213 return n;
8214 }
8215
8216 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8217 {
8218+ if ((long)n < 0)
8219+ return n;
8220+
8221 return __copy_user((__force void __user *) to, from, n);
8222 }
8223
8224diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8225index e562d3c..191f176 100644
8226--- a/arch/sparc/include/asm/uaccess_64.h
8227+++ b/arch/sparc/include/asm/uaccess_64.h
8228@@ -10,6 +10,7 @@
8229 #include <linux/compiler.h>
8230 #include <linux/string.h>
8231 #include <linux/thread_info.h>
8232+#include <linux/kernel.h>
8233 #include <asm/asi.h>
8234 #include <asm/spitfire.h>
8235 #include <asm-generic/uaccess-unaligned.h>
8236@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8237 static inline unsigned long __must_check
8238 copy_from_user(void *to, const void __user *from, unsigned long size)
8239 {
8240- unsigned long ret = ___copy_from_user(to, from, size);
8241+ unsigned long ret;
8242
8243+ if ((long)size < 0 || size > INT_MAX)
8244+ return size;
8245+
8246+ if (!__builtin_constant_p(size))
8247+ check_object_size(to, size, false);
8248+
8249+ ret = ___copy_from_user(to, from, size);
8250 if (unlikely(ret))
8251 ret = copy_from_user_fixup(to, from, size);
8252
8253@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8254 static inline unsigned long __must_check
8255 copy_to_user(void __user *to, const void *from, unsigned long size)
8256 {
8257- unsigned long ret = ___copy_to_user(to, from, size);
8258+ unsigned long ret;
8259
8260+ if ((long)size < 0 || size > INT_MAX)
8261+ return size;
8262+
8263+ if (!__builtin_constant_p(size))
8264+ check_object_size(from, size, true);
8265+
8266+ ret = ___copy_to_user(to, from, size);
8267 if (unlikely(ret))
8268 ret = copy_to_user_fixup(to, from, size);
8269 return ret;
8270diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8271index 6cf591b..b49e65a 100644
8272--- a/arch/sparc/kernel/Makefile
8273+++ b/arch/sparc/kernel/Makefile
8274@@ -3,7 +3,7 @@
8275 #
8276
8277 asflags-y := -ansi
8278-ccflags-y := -Werror
8279+#ccflags-y := -Werror
8280
8281 extra-y := head_$(BITS).o
8282
8283diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8284index be8e862..5b50b12 100644
8285--- a/arch/sparc/kernel/process_32.c
8286+++ b/arch/sparc/kernel/process_32.c
8287@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8288
8289 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8290 r->psr, r->pc, r->npc, r->y, print_tainted());
8291- printk("PC: <%pS>\n", (void *) r->pc);
8292+ printk("PC: <%pA>\n", (void *) r->pc);
8293 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8294 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8295 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8296 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8297 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8298 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8299- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8300+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8301
8302 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8303 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8304@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8305 rw = (struct reg_window32 *) fp;
8306 pc = rw->ins[7];
8307 printk("[%08lx : ", pc);
8308- printk("%pS ] ", (void *) pc);
8309+ printk("%pA ] ", (void *) pc);
8310 fp = rw->ins[6];
8311 } while (++count < 16);
8312 printk("\n");
8313diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8314index cdb80b2..5ca141d 100644
8315--- a/arch/sparc/kernel/process_64.c
8316+++ b/arch/sparc/kernel/process_64.c
8317@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8318 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8319 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8320 if (regs->tstate & TSTATE_PRIV)
8321- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8322+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8323 }
8324
8325 void show_regs(struct pt_regs *regs)
8326 {
8327 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8328 regs->tpc, regs->tnpc, regs->y, print_tainted());
8329- printk("TPC: <%pS>\n", (void *) regs->tpc);
8330+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8331 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8332 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8333 regs->u_regs[3]);
8334@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8335 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8336 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8337 regs->u_regs[15]);
8338- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8339+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8340 show_regwindow(regs);
8341 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8342 }
8343@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8344 ((tp && tp->task) ? tp->task->pid : -1));
8345
8346 if (gp->tstate & TSTATE_PRIV) {
8347- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8348+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8349 (void *) gp->tpc,
8350 (void *) gp->o7,
8351 (void *) gp->i7,
8352diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8353index 7ff45e4..a58f271 100644
8354--- a/arch/sparc/kernel/ptrace_64.c
8355+++ b/arch/sparc/kernel/ptrace_64.c
8356@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8357 return ret;
8358 }
8359
8360+#ifdef CONFIG_GRKERNSEC_SETXID
8361+extern void gr_delayed_cred_worker(void);
8362+#endif
8363+
8364 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8365 {
8366 int ret = 0;
8367@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8368 /* do the secure computing check first */
8369 secure_computing_strict(regs->u_regs[UREG_G1]);
8370
8371+#ifdef CONFIG_GRKERNSEC_SETXID
8372+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8373+ gr_delayed_cred_worker();
8374+#endif
8375+
8376 if (test_thread_flag(TIF_SYSCALL_TRACE))
8377 ret = tracehook_report_syscall_entry(regs);
8378
8379@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8380
8381 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8382 {
8383+#ifdef CONFIG_GRKERNSEC_SETXID
8384+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8385+ gr_delayed_cred_worker();
8386+#endif
8387+
8388 audit_syscall_exit(regs);
8389
8390 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8391diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8392index 2da0bdc..79128d2 100644
8393--- a/arch/sparc/kernel/sys_sparc_32.c
8394+++ b/arch/sparc/kernel/sys_sparc_32.c
8395@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8396 if (len > TASK_SIZE - PAGE_SIZE)
8397 return -ENOMEM;
8398 if (!addr)
8399- addr = TASK_UNMAPPED_BASE;
8400+ addr = current->mm->mmap_base;
8401
8402 info.flags = 0;
8403 info.length = len;
8404diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8405index 708bc29..f0129cb 100644
8406--- a/arch/sparc/kernel/sys_sparc_64.c
8407+++ b/arch/sparc/kernel/sys_sparc_64.c
8408@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8409 struct vm_area_struct * vma;
8410 unsigned long task_size = TASK_SIZE;
8411 int do_color_align;
8412+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8413 struct vm_unmapped_area_info info;
8414
8415 if (flags & MAP_FIXED) {
8416 /* We do not accept a shared mapping if it would violate
8417 * cache aliasing constraints.
8418 */
8419- if ((flags & MAP_SHARED) &&
8420+ if ((filp || (flags & MAP_SHARED)) &&
8421 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8422 return -EINVAL;
8423 return addr;
8424@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8425 if (filp || (flags & MAP_SHARED))
8426 do_color_align = 1;
8427
8428+#ifdef CONFIG_PAX_RANDMMAP
8429+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8430+#endif
8431+
8432 if (addr) {
8433 if (do_color_align)
8434 addr = COLOR_ALIGN(addr, pgoff);
8435@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8436 addr = PAGE_ALIGN(addr);
8437
8438 vma = find_vma(mm, addr);
8439- if (task_size - len >= addr &&
8440- (!vma || addr + len <= vma->vm_start))
8441+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8442 return addr;
8443 }
8444
8445 info.flags = 0;
8446 info.length = len;
8447- info.low_limit = TASK_UNMAPPED_BASE;
8448+ info.low_limit = mm->mmap_base;
8449 info.high_limit = min(task_size, VA_EXCLUDE_START);
8450 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8451 info.align_offset = pgoff << PAGE_SHIFT;
8452@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8453 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8454 VM_BUG_ON(addr != -ENOMEM);
8455 info.low_limit = VA_EXCLUDE_END;
8456+
8457+#ifdef CONFIG_PAX_RANDMMAP
8458+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8459+ info.low_limit += mm->delta_mmap;
8460+#endif
8461+
8462 info.high_limit = task_size;
8463 addr = vm_unmapped_area(&info);
8464 }
8465@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8466 unsigned long task_size = STACK_TOP32;
8467 unsigned long addr = addr0;
8468 int do_color_align;
8469+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8470 struct vm_unmapped_area_info info;
8471
8472 /* This should only ever run for 32-bit processes. */
8473@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8474 /* We do not accept a shared mapping if it would violate
8475 * cache aliasing constraints.
8476 */
8477- if ((flags & MAP_SHARED) &&
8478+ if ((filp || (flags & MAP_SHARED)) &&
8479 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8480 return -EINVAL;
8481 return addr;
8482@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8483 if (filp || (flags & MAP_SHARED))
8484 do_color_align = 1;
8485
8486+#ifdef CONFIG_PAX_RANDMMAP
8487+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8488+#endif
8489+
8490 /* requesting a specific address */
8491 if (addr) {
8492 if (do_color_align)
8493@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8494 addr = PAGE_ALIGN(addr);
8495
8496 vma = find_vma(mm, addr);
8497- if (task_size - len >= addr &&
8498- (!vma || addr + len <= vma->vm_start))
8499+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8500 return addr;
8501 }
8502
8503@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8504 VM_BUG_ON(addr != -ENOMEM);
8505 info.flags = 0;
8506 info.low_limit = TASK_UNMAPPED_BASE;
8507+
8508+#ifdef CONFIG_PAX_RANDMMAP
8509+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8510+ info.low_limit += mm->delta_mmap;
8511+#endif
8512+
8513 info.high_limit = STACK_TOP32;
8514 addr = vm_unmapped_area(&info);
8515 }
8516@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8517 {
8518 unsigned long rnd = 0UL;
8519
8520+#ifdef CONFIG_PAX_RANDMMAP
8521+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8522+#endif
8523+
8524 if (current->flags & PF_RANDOMIZE) {
8525 unsigned long val = get_random_int();
8526 if (test_thread_flag(TIF_32BIT))
8527@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8528 gap == RLIM_INFINITY ||
8529 sysctl_legacy_va_layout) {
8530 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8531+
8532+#ifdef CONFIG_PAX_RANDMMAP
8533+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8534+ mm->mmap_base += mm->delta_mmap;
8535+#endif
8536+
8537 mm->get_unmapped_area = arch_get_unmapped_area;
8538 mm->unmap_area = arch_unmap_area;
8539 } else {
8540@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8541 gap = (task_size / 6 * 5);
8542
8543 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8544+
8545+#ifdef CONFIG_PAX_RANDMMAP
8546+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8547+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8548+#endif
8549+
8550 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8551 mm->unmap_area = arch_unmap_area_topdown;
8552 }
8553diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8554index e0fed77..604a7e5 100644
8555--- a/arch/sparc/kernel/syscalls.S
8556+++ b/arch/sparc/kernel/syscalls.S
8557@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8558 #endif
8559 .align 32
8560 1: ldx [%g6 + TI_FLAGS], %l5
8561- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8562+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8563 be,pt %icc, rtrap
8564 nop
8565 call syscall_trace_leave
8566@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8567
8568 srl %i5, 0, %o5 ! IEU1
8569 srl %i2, 0, %o2 ! IEU0 Group
8570- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8571+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8572 bne,pn %icc, linux_syscall_trace32 ! CTI
8573 mov %i0, %l5 ! IEU1
8574 call %l7 ! CTI Group brk forced
8575@@ -213,7 +213,7 @@ linux_sparc_syscall:
8576
8577 mov %i3, %o3 ! IEU1
8578 mov %i4, %o4 ! 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_trace ! CTI Group
8582 mov %i0, %l5 ! IEU0
8583 2: call %l7 ! CTI Group brk forced
8584@@ -229,7 +229,7 @@ ret_sys_call:
8585
8586 cmp %o0, -ERESTART_RESTARTBLOCK
8587 bgeu,pn %xcc, 1f
8588- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8589+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8590 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8591
8592 2:
8593diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8594index 654e8aa..45f431b 100644
8595--- a/arch/sparc/kernel/sysfs.c
8596+++ b/arch/sparc/kernel/sysfs.c
8597@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8598 return NOTIFY_OK;
8599 }
8600
8601-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8602+static struct notifier_block sysfs_cpu_nb = {
8603 .notifier_call = sysfs_cpu_notify,
8604 };
8605
8606diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8607index a5785ea..405c5f7 100644
8608--- a/arch/sparc/kernel/traps_32.c
8609+++ b/arch/sparc/kernel/traps_32.c
8610@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8611 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8612 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8613
8614+extern void gr_handle_kernel_exploit(void);
8615+
8616 void die_if_kernel(char *str, struct pt_regs *regs)
8617 {
8618 static int die_counter;
8619@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8620 count++ < 30 &&
8621 (((unsigned long) rw) >= PAGE_OFFSET) &&
8622 !(((unsigned long) rw) & 0x7)) {
8623- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8624+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8625 (void *) rw->ins[7]);
8626 rw = (struct reg_window32 *)rw->ins[6];
8627 }
8628 }
8629 printk("Instruction DUMP:");
8630 instruction_dump ((unsigned long *) regs->pc);
8631- if(regs->psr & PSR_PS)
8632+ if(regs->psr & PSR_PS) {
8633+ gr_handle_kernel_exploit();
8634 do_exit(SIGKILL);
8635+ }
8636 do_exit(SIGSEGV);
8637 }
8638
8639diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8640index e7ecf15..6520e65 100644
8641--- a/arch/sparc/kernel/traps_64.c
8642+++ b/arch/sparc/kernel/traps_64.c
8643@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8644 i + 1,
8645 p->trapstack[i].tstate, p->trapstack[i].tpc,
8646 p->trapstack[i].tnpc, p->trapstack[i].tt);
8647- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8648+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8649 }
8650 }
8651
8652@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8653
8654 lvl -= 0x100;
8655 if (regs->tstate & TSTATE_PRIV) {
8656+
8657+#ifdef CONFIG_PAX_REFCOUNT
8658+ if (lvl == 6)
8659+ pax_report_refcount_overflow(regs);
8660+#endif
8661+
8662 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8663 die_if_kernel(buffer, regs);
8664 }
8665@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8666 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8667 {
8668 char buffer[32];
8669-
8670+
8671 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8672 0, lvl, SIGTRAP) == NOTIFY_STOP)
8673 return;
8674
8675+#ifdef CONFIG_PAX_REFCOUNT
8676+ if (lvl == 6)
8677+ pax_report_refcount_overflow(regs);
8678+#endif
8679+
8680 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8681
8682 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8683@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8684 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8685 printk("%s" "ERROR(%d): ",
8686 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8687- printk("TPC<%pS>\n", (void *) regs->tpc);
8688+ printk("TPC<%pA>\n", (void *) regs->tpc);
8689 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8690 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8691 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8692@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8693 smp_processor_id(),
8694 (type & 0x1) ? 'I' : 'D',
8695 regs->tpc);
8696- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8697+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8698 panic("Irrecoverable Cheetah+ parity error.");
8699 }
8700
8701@@ -1757,7 +1768,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_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8706+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8707 }
8708
8709 struct sun4v_error_entry {
8710@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8711
8712 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8713 regs->tpc, tl);
8714- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8715+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8716 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8717- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8718+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8719 (void *) regs->u_regs[UREG_I7]);
8720 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8721 "pte[%lx] error[%lx]\n",
8722@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8723
8724 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8725 regs->tpc, tl);
8726- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8727+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8728 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8729- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8730+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8731 (void *) regs->u_regs[UREG_I7]);
8732 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8733 "pte[%lx] error[%lx]\n",
8734@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8735 fp = (unsigned long)sf->fp + STACK_BIAS;
8736 }
8737
8738- printk(" [%016lx] %pS\n", pc, (void *) pc);
8739+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8740 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8741 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8742 int index = tsk->curr_ret_stack;
8743 if (tsk->ret_stack && index >= graph) {
8744 pc = tsk->ret_stack[index - graph].ret;
8745- printk(" [%016lx] %pS\n", pc, (void *) pc);
8746+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8747 graph++;
8748 }
8749 }
8750@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8751 return (struct reg_window *) (fp + STACK_BIAS);
8752 }
8753
8754+extern void gr_handle_kernel_exploit(void);
8755+
8756 void die_if_kernel(char *str, struct pt_regs *regs)
8757 {
8758 static int die_counter;
8759@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8760 while (rw &&
8761 count++ < 30 &&
8762 kstack_valid(tp, (unsigned long) rw)) {
8763- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8764+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8765 (void *) rw->ins[7]);
8766
8767 rw = kernel_stack_up(rw);
8768@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8769 }
8770 user_instruction_dump ((unsigned int __user *) regs->tpc);
8771 }
8772- if (regs->tstate & TSTATE_PRIV)
8773+ if (regs->tstate & TSTATE_PRIV) {
8774+ gr_handle_kernel_exploit();
8775 do_exit(SIGKILL);
8776+ }
8777 do_exit(SIGSEGV);
8778 }
8779 EXPORT_SYMBOL(die_if_kernel);
8780diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8781index 8201c25e..072a2a7 100644
8782--- a/arch/sparc/kernel/unaligned_64.c
8783+++ b/arch/sparc/kernel/unaligned_64.c
8784@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8785 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8786
8787 if (__ratelimit(&ratelimit)) {
8788- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8789+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8790 regs->tpc, (void *) regs->tpc);
8791 }
8792 }
8793diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8794index 8410065f2..4fd4ca22 100644
8795--- a/arch/sparc/lib/Makefile
8796+++ b/arch/sparc/lib/Makefile
8797@@ -2,7 +2,7 @@
8798 #
8799
8800 asflags-y := -ansi -DST_DIV0=0x02
8801-ccflags-y := -Werror
8802+#ccflags-y := -Werror
8803
8804 lib-$(CONFIG_SPARC32) += ashrdi3.o
8805 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8806diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8807index 85c233d..68500e0 100644
8808--- a/arch/sparc/lib/atomic_64.S
8809+++ b/arch/sparc/lib/atomic_64.S
8810@@ -17,7 +17,12 @@
8811 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8812 BACKOFF_SETUP(%o2)
8813 1: lduw [%o1], %g1
8814- add %g1, %o0, %g7
8815+ addcc %g1, %o0, %g7
8816+
8817+#ifdef CONFIG_PAX_REFCOUNT
8818+ tvs %icc, 6
8819+#endif
8820+
8821 cas [%o1], %g1, %g7
8822 cmp %g1, %g7
8823 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8824@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8825 2: BACKOFF_SPIN(%o2, %o3, 1b)
8826 ENDPROC(atomic_add)
8827
8828+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8829+ BACKOFF_SETUP(%o2)
8830+1: lduw [%o1], %g1
8831+ add %g1, %o0, %g7
8832+ cas [%o1], %g1, %g7
8833+ cmp %g1, %g7
8834+ bne,pn %icc, 2f
8835+ nop
8836+ retl
8837+ nop
8838+2: BACKOFF_SPIN(%o2, %o3, 1b)
8839+ENDPROC(atomic_add_unchecked)
8840+
8841 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8842 BACKOFF_SETUP(%o2)
8843 1: lduw [%o1], %g1
8844- sub %g1, %o0, %g7
8845+ subcc %g1, %o0, %g7
8846+
8847+#ifdef CONFIG_PAX_REFCOUNT
8848+ tvs %icc, 6
8849+#endif
8850+
8851 cas [%o1], %g1, %g7
8852 cmp %g1, %g7
8853 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8854@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8855 2: BACKOFF_SPIN(%o2, %o3, 1b)
8856 ENDPROC(atomic_sub)
8857
8858+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8859+ BACKOFF_SETUP(%o2)
8860+1: lduw [%o1], %g1
8861+ sub %g1, %o0, %g7
8862+ cas [%o1], %g1, %g7
8863+ cmp %g1, %g7
8864+ bne,pn %icc, 2f
8865+ nop
8866+ retl
8867+ nop
8868+2: BACKOFF_SPIN(%o2, %o3, 1b)
8869+ENDPROC(atomic_sub_unchecked)
8870+
8871 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8872 BACKOFF_SETUP(%o2)
8873 1: lduw [%o1], %g1
8874- add %g1, %o0, %g7
8875+ addcc %g1, %o0, %g7
8876+
8877+#ifdef CONFIG_PAX_REFCOUNT
8878+ tvs %icc, 6
8879+#endif
8880+
8881 cas [%o1], %g1, %g7
8882 cmp %g1, %g7
8883 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8884@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8885 2: BACKOFF_SPIN(%o2, %o3, 1b)
8886 ENDPROC(atomic_add_ret)
8887
8888+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8889+ BACKOFF_SETUP(%o2)
8890+1: lduw [%o1], %g1
8891+ addcc %g1, %o0, %g7
8892+ cas [%o1], %g1, %g7
8893+ cmp %g1, %g7
8894+ bne,pn %icc, 2f
8895+ add %g7, %o0, %g7
8896+ sra %g7, 0, %o0
8897+ retl
8898+ nop
8899+2: BACKOFF_SPIN(%o2, %o3, 1b)
8900+ENDPROC(atomic_add_ret_unchecked)
8901+
8902 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8903 BACKOFF_SETUP(%o2)
8904 1: lduw [%o1], %g1
8905- sub %g1, %o0, %g7
8906+ subcc %g1, %o0, %g7
8907+
8908+#ifdef CONFIG_PAX_REFCOUNT
8909+ tvs %icc, 6
8910+#endif
8911+
8912 cas [%o1], %g1, %g7
8913 cmp %g1, %g7
8914 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8915@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8916 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8917 BACKOFF_SETUP(%o2)
8918 1: ldx [%o1], %g1
8919- add %g1, %o0, %g7
8920+ addcc %g1, %o0, %g7
8921+
8922+#ifdef CONFIG_PAX_REFCOUNT
8923+ tvs %xcc, 6
8924+#endif
8925+
8926 casx [%o1], %g1, %g7
8927 cmp %g1, %g7
8928 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8929@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8930 2: BACKOFF_SPIN(%o2, %o3, 1b)
8931 ENDPROC(atomic64_add)
8932
8933+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8934+ BACKOFF_SETUP(%o2)
8935+1: ldx [%o1], %g1
8936+ addcc %g1, %o0, %g7
8937+ casx [%o1], %g1, %g7
8938+ cmp %g1, %g7
8939+ bne,pn %xcc, 2f
8940+ nop
8941+ retl
8942+ nop
8943+2: BACKOFF_SPIN(%o2, %o3, 1b)
8944+ENDPROC(atomic64_add_unchecked)
8945+
8946 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8947 BACKOFF_SETUP(%o2)
8948 1: ldx [%o1], %g1
8949- sub %g1, %o0, %g7
8950+ subcc %g1, %o0, %g7
8951+
8952+#ifdef CONFIG_PAX_REFCOUNT
8953+ tvs %xcc, 6
8954+#endif
8955+
8956 casx [%o1], %g1, %g7
8957 cmp %g1, %g7
8958 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8959@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8960 2: BACKOFF_SPIN(%o2, %o3, 1b)
8961 ENDPROC(atomic64_sub)
8962
8963+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8964+ BACKOFF_SETUP(%o2)
8965+1: ldx [%o1], %g1
8966+ subcc %g1, %o0, %g7
8967+ casx [%o1], %g1, %g7
8968+ cmp %g1, %g7
8969+ bne,pn %xcc, 2f
8970+ nop
8971+ retl
8972+ nop
8973+2: BACKOFF_SPIN(%o2, %o3, 1b)
8974+ENDPROC(atomic64_sub_unchecked)
8975+
8976 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8977 BACKOFF_SETUP(%o2)
8978 1: ldx [%o1], %g1
8979- add %g1, %o0, %g7
8980+ addcc %g1, %o0, %g7
8981+
8982+#ifdef CONFIG_PAX_REFCOUNT
8983+ tvs %xcc, 6
8984+#endif
8985+
8986 casx [%o1], %g1, %g7
8987 cmp %g1, %g7
8988 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8989@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8990 2: BACKOFF_SPIN(%o2, %o3, 1b)
8991 ENDPROC(atomic64_add_ret)
8992
8993+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8994+ BACKOFF_SETUP(%o2)
8995+1: ldx [%o1], %g1
8996+ addcc %g1, %o0, %g7
8997+ casx [%o1], %g1, %g7
8998+ cmp %g1, %g7
8999+ bne,pn %xcc, 2f
9000+ add %g7, %o0, %g7
9001+ mov %g7, %o0
9002+ retl
9003+ nop
9004+2: BACKOFF_SPIN(%o2, %o3, 1b)
9005+ENDPROC(atomic64_add_ret_unchecked)
9006+
9007 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9008 BACKOFF_SETUP(%o2)
9009 1: ldx [%o1], %g1
9010- sub %g1, %o0, %g7
9011+ subcc %g1, %o0, %g7
9012+
9013+#ifdef CONFIG_PAX_REFCOUNT
9014+ tvs %xcc, 6
9015+#endif
9016+
9017 casx [%o1], %g1, %g7
9018 cmp %g1, %g7
9019 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9020diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9021index 0c4e35e..745d3e4 100644
9022--- a/arch/sparc/lib/ksyms.c
9023+++ b/arch/sparc/lib/ksyms.c
9024@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9025
9026 /* Atomic counter implementation. */
9027 EXPORT_SYMBOL(atomic_add);
9028+EXPORT_SYMBOL(atomic_add_unchecked);
9029 EXPORT_SYMBOL(atomic_add_ret);
9030+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9031 EXPORT_SYMBOL(atomic_sub);
9032+EXPORT_SYMBOL(atomic_sub_unchecked);
9033 EXPORT_SYMBOL(atomic_sub_ret);
9034 EXPORT_SYMBOL(atomic64_add);
9035+EXPORT_SYMBOL(atomic64_add_unchecked);
9036 EXPORT_SYMBOL(atomic64_add_ret);
9037+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9038 EXPORT_SYMBOL(atomic64_sub);
9039+EXPORT_SYMBOL(atomic64_sub_unchecked);
9040 EXPORT_SYMBOL(atomic64_sub_ret);
9041 EXPORT_SYMBOL(atomic64_dec_if_positive);
9042
9043diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9044index 30c3ecc..736f015 100644
9045--- a/arch/sparc/mm/Makefile
9046+++ b/arch/sparc/mm/Makefile
9047@@ -2,7 +2,7 @@
9048 #
9049
9050 asflags-y := -ansi
9051-ccflags-y := -Werror
9052+#ccflags-y := -Werror
9053
9054 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9055 obj-y += fault_$(BITS).o
9056diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9057index e98bfda..ea8d221 100644
9058--- a/arch/sparc/mm/fault_32.c
9059+++ b/arch/sparc/mm/fault_32.c
9060@@ -21,6 +21,9 @@
9061 #include <linux/perf_event.h>
9062 #include <linux/interrupt.h>
9063 #include <linux/kdebug.h>
9064+#include <linux/slab.h>
9065+#include <linux/pagemap.h>
9066+#include <linux/compiler.h>
9067
9068 #include <asm/page.h>
9069 #include <asm/pgtable.h>
9070@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9071 return safe_compute_effective_address(regs, insn);
9072 }
9073
9074+#ifdef CONFIG_PAX_PAGEEXEC
9075+#ifdef CONFIG_PAX_DLRESOLVE
9076+static void pax_emuplt_close(struct vm_area_struct *vma)
9077+{
9078+ vma->vm_mm->call_dl_resolve = 0UL;
9079+}
9080+
9081+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9082+{
9083+ unsigned int *kaddr;
9084+
9085+ vmf->page = alloc_page(GFP_HIGHUSER);
9086+ if (!vmf->page)
9087+ return VM_FAULT_OOM;
9088+
9089+ kaddr = kmap(vmf->page);
9090+ memset(kaddr, 0, PAGE_SIZE);
9091+ kaddr[0] = 0x9DE3BFA8U; /* save */
9092+ flush_dcache_page(vmf->page);
9093+ kunmap(vmf->page);
9094+ return VM_FAULT_MAJOR;
9095+}
9096+
9097+static const struct vm_operations_struct pax_vm_ops = {
9098+ .close = pax_emuplt_close,
9099+ .fault = pax_emuplt_fault
9100+};
9101+
9102+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9103+{
9104+ int ret;
9105+
9106+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9107+ vma->vm_mm = current->mm;
9108+ vma->vm_start = addr;
9109+ vma->vm_end = addr + PAGE_SIZE;
9110+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9111+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9112+ vma->vm_ops = &pax_vm_ops;
9113+
9114+ ret = insert_vm_struct(current->mm, vma);
9115+ if (ret)
9116+ return ret;
9117+
9118+ ++current->mm->total_vm;
9119+ return 0;
9120+}
9121+#endif
9122+
9123+/*
9124+ * PaX: decide what to do with offenders (regs->pc = fault address)
9125+ *
9126+ * returns 1 when task should be killed
9127+ * 2 when patched PLT trampoline was detected
9128+ * 3 when unpatched PLT trampoline was detected
9129+ */
9130+static int pax_handle_fetch_fault(struct pt_regs *regs)
9131+{
9132+
9133+#ifdef CONFIG_PAX_EMUPLT
9134+ int err;
9135+
9136+ do { /* PaX: patched PLT emulation #1 */
9137+ unsigned int sethi1, sethi2, jmpl;
9138+
9139+ err = get_user(sethi1, (unsigned int *)regs->pc);
9140+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9141+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9142+
9143+ if (err)
9144+ break;
9145+
9146+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9147+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9148+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9149+ {
9150+ unsigned int addr;
9151+
9152+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9153+ addr = regs->u_regs[UREG_G1];
9154+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9155+ regs->pc = addr;
9156+ regs->npc = addr+4;
9157+ return 2;
9158+ }
9159+ } while (0);
9160+
9161+ do { /* PaX: patched PLT emulation #2 */
9162+ unsigned int ba;
9163+
9164+ err = get_user(ba, (unsigned int *)regs->pc);
9165+
9166+ if (err)
9167+ break;
9168+
9169+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9170+ unsigned int addr;
9171+
9172+ if ((ba & 0xFFC00000U) == 0x30800000U)
9173+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9174+ else
9175+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9176+ regs->pc = addr;
9177+ regs->npc = addr+4;
9178+ return 2;
9179+ }
9180+ } while (0);
9181+
9182+ do { /* PaX: patched PLT emulation #3 */
9183+ unsigned int sethi, bajmpl, nop;
9184+
9185+ err = get_user(sethi, (unsigned int *)regs->pc);
9186+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9187+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9188+
9189+ if (err)
9190+ break;
9191+
9192+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9193+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9194+ nop == 0x01000000U)
9195+ {
9196+ unsigned int addr;
9197+
9198+ addr = (sethi & 0x003FFFFFU) << 10;
9199+ regs->u_regs[UREG_G1] = addr;
9200+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9201+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9202+ else
9203+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9204+ regs->pc = addr;
9205+ regs->npc = addr+4;
9206+ return 2;
9207+ }
9208+ } while (0);
9209+
9210+ do { /* PaX: unpatched PLT emulation step 1 */
9211+ unsigned int sethi, ba, nop;
9212+
9213+ err = get_user(sethi, (unsigned int *)regs->pc);
9214+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9215+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9216+
9217+ if (err)
9218+ break;
9219+
9220+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9221+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9222+ nop == 0x01000000U)
9223+ {
9224+ unsigned int addr, save, call;
9225+
9226+ if ((ba & 0xFFC00000U) == 0x30800000U)
9227+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9228+ else
9229+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9230+
9231+ err = get_user(save, (unsigned int *)addr);
9232+ err |= get_user(call, (unsigned int *)(addr+4));
9233+ err |= get_user(nop, (unsigned int *)(addr+8));
9234+ if (err)
9235+ break;
9236+
9237+#ifdef CONFIG_PAX_DLRESOLVE
9238+ if (save == 0x9DE3BFA8U &&
9239+ (call & 0xC0000000U) == 0x40000000U &&
9240+ nop == 0x01000000U)
9241+ {
9242+ struct vm_area_struct *vma;
9243+ unsigned long call_dl_resolve;
9244+
9245+ down_read(&current->mm->mmap_sem);
9246+ call_dl_resolve = current->mm->call_dl_resolve;
9247+ up_read(&current->mm->mmap_sem);
9248+ if (likely(call_dl_resolve))
9249+ goto emulate;
9250+
9251+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9252+
9253+ down_write(&current->mm->mmap_sem);
9254+ if (current->mm->call_dl_resolve) {
9255+ call_dl_resolve = current->mm->call_dl_resolve;
9256+ up_write(&current->mm->mmap_sem);
9257+ if (vma)
9258+ kmem_cache_free(vm_area_cachep, vma);
9259+ goto emulate;
9260+ }
9261+
9262+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9263+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9264+ up_write(&current->mm->mmap_sem);
9265+ if (vma)
9266+ kmem_cache_free(vm_area_cachep, vma);
9267+ return 1;
9268+ }
9269+
9270+ if (pax_insert_vma(vma, call_dl_resolve)) {
9271+ up_write(&current->mm->mmap_sem);
9272+ kmem_cache_free(vm_area_cachep, vma);
9273+ return 1;
9274+ }
9275+
9276+ current->mm->call_dl_resolve = call_dl_resolve;
9277+ up_write(&current->mm->mmap_sem);
9278+
9279+emulate:
9280+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9281+ regs->pc = call_dl_resolve;
9282+ regs->npc = addr+4;
9283+ return 3;
9284+ }
9285+#endif
9286+
9287+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9288+ if ((save & 0xFFC00000U) == 0x05000000U &&
9289+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9290+ nop == 0x01000000U)
9291+ {
9292+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9293+ regs->u_regs[UREG_G2] = addr + 4;
9294+ addr = (save & 0x003FFFFFU) << 10;
9295+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9296+ regs->pc = addr;
9297+ regs->npc = addr+4;
9298+ return 3;
9299+ }
9300+ }
9301+ } while (0);
9302+
9303+ do { /* PaX: unpatched PLT emulation step 2 */
9304+ unsigned int save, call, nop;
9305+
9306+ err = get_user(save, (unsigned int *)(regs->pc-4));
9307+ err |= get_user(call, (unsigned int *)regs->pc);
9308+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9309+ if (err)
9310+ break;
9311+
9312+ if (save == 0x9DE3BFA8U &&
9313+ (call & 0xC0000000U) == 0x40000000U &&
9314+ nop == 0x01000000U)
9315+ {
9316+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9317+
9318+ regs->u_regs[UREG_RETPC] = regs->pc;
9319+ regs->pc = dl_resolve;
9320+ regs->npc = dl_resolve+4;
9321+ return 3;
9322+ }
9323+ } while (0);
9324+#endif
9325+
9326+ return 1;
9327+}
9328+
9329+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9330+{
9331+ unsigned long i;
9332+
9333+ printk(KERN_ERR "PAX: bytes at PC: ");
9334+ for (i = 0; i < 8; i++) {
9335+ unsigned int c;
9336+ if (get_user(c, (unsigned int *)pc+i))
9337+ printk(KERN_CONT "???????? ");
9338+ else
9339+ printk(KERN_CONT "%08x ", c);
9340+ }
9341+ printk("\n");
9342+}
9343+#endif
9344+
9345 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9346 int text_fault)
9347 {
9348@@ -230,6 +504,24 @@ good_area:
9349 if (!(vma->vm_flags & VM_WRITE))
9350 goto bad_area;
9351 } else {
9352+
9353+#ifdef CONFIG_PAX_PAGEEXEC
9354+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9355+ up_read(&mm->mmap_sem);
9356+ switch (pax_handle_fetch_fault(regs)) {
9357+
9358+#ifdef CONFIG_PAX_EMUPLT
9359+ case 2:
9360+ case 3:
9361+ return;
9362+#endif
9363+
9364+ }
9365+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9366+ do_group_exit(SIGKILL);
9367+ }
9368+#endif
9369+
9370 /* Allow reads even for write-only mappings */
9371 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9372 goto bad_area;
9373diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9374index 5062ff3..e0b75f3 100644
9375--- a/arch/sparc/mm/fault_64.c
9376+++ b/arch/sparc/mm/fault_64.c
9377@@ -21,6 +21,9 @@
9378 #include <linux/kprobes.h>
9379 #include <linux/kdebug.h>
9380 #include <linux/percpu.h>
9381+#include <linux/slab.h>
9382+#include <linux/pagemap.h>
9383+#include <linux/compiler.h>
9384
9385 #include <asm/page.h>
9386 #include <asm/pgtable.h>
9387@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9388 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9389 regs->tpc);
9390 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9391- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9392+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9393 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9394 dump_stack();
9395 unhandled_fault(regs->tpc, current, regs);
9396@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9397 show_regs(regs);
9398 }
9399
9400+#ifdef CONFIG_PAX_PAGEEXEC
9401+#ifdef CONFIG_PAX_DLRESOLVE
9402+static void pax_emuplt_close(struct vm_area_struct *vma)
9403+{
9404+ vma->vm_mm->call_dl_resolve = 0UL;
9405+}
9406+
9407+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9408+{
9409+ unsigned int *kaddr;
9410+
9411+ vmf->page = alloc_page(GFP_HIGHUSER);
9412+ if (!vmf->page)
9413+ return VM_FAULT_OOM;
9414+
9415+ kaddr = kmap(vmf->page);
9416+ memset(kaddr, 0, PAGE_SIZE);
9417+ kaddr[0] = 0x9DE3BFA8U; /* save */
9418+ flush_dcache_page(vmf->page);
9419+ kunmap(vmf->page);
9420+ return VM_FAULT_MAJOR;
9421+}
9422+
9423+static const struct vm_operations_struct pax_vm_ops = {
9424+ .close = pax_emuplt_close,
9425+ .fault = pax_emuplt_fault
9426+};
9427+
9428+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9429+{
9430+ int ret;
9431+
9432+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9433+ vma->vm_mm = current->mm;
9434+ vma->vm_start = addr;
9435+ vma->vm_end = addr + PAGE_SIZE;
9436+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9437+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9438+ vma->vm_ops = &pax_vm_ops;
9439+
9440+ ret = insert_vm_struct(current->mm, vma);
9441+ if (ret)
9442+ return ret;
9443+
9444+ ++current->mm->total_vm;
9445+ return 0;
9446+}
9447+#endif
9448+
9449+/*
9450+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9451+ *
9452+ * returns 1 when task should be killed
9453+ * 2 when patched PLT trampoline was detected
9454+ * 3 when unpatched PLT trampoline was detected
9455+ */
9456+static int pax_handle_fetch_fault(struct pt_regs *regs)
9457+{
9458+
9459+#ifdef CONFIG_PAX_EMUPLT
9460+ int err;
9461+
9462+ do { /* PaX: patched PLT emulation #1 */
9463+ unsigned int sethi1, sethi2, jmpl;
9464+
9465+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9466+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9467+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9468+
9469+ if (err)
9470+ break;
9471+
9472+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9473+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9474+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9475+ {
9476+ unsigned long addr;
9477+
9478+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9479+ addr = regs->u_regs[UREG_G1];
9480+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9481+
9482+ if (test_thread_flag(TIF_32BIT))
9483+ addr &= 0xFFFFFFFFUL;
9484+
9485+ regs->tpc = addr;
9486+ regs->tnpc = addr+4;
9487+ return 2;
9488+ }
9489+ } while (0);
9490+
9491+ do { /* PaX: patched PLT emulation #2 */
9492+ unsigned int ba;
9493+
9494+ err = get_user(ba, (unsigned int *)regs->tpc);
9495+
9496+ if (err)
9497+ break;
9498+
9499+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9500+ unsigned long addr;
9501+
9502+ if ((ba & 0xFFC00000U) == 0x30800000U)
9503+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9504+ else
9505+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9506+
9507+ if (test_thread_flag(TIF_32BIT))
9508+ addr &= 0xFFFFFFFFUL;
9509+
9510+ regs->tpc = addr;
9511+ regs->tnpc = addr+4;
9512+ return 2;
9513+ }
9514+ } while (0);
9515+
9516+ do { /* PaX: patched PLT emulation #3 */
9517+ unsigned int sethi, bajmpl, nop;
9518+
9519+ err = get_user(sethi, (unsigned int *)regs->tpc);
9520+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9521+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9522+
9523+ if (err)
9524+ break;
9525+
9526+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9527+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9528+ nop == 0x01000000U)
9529+ {
9530+ unsigned long addr;
9531+
9532+ addr = (sethi & 0x003FFFFFU) << 10;
9533+ regs->u_regs[UREG_G1] = addr;
9534+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9535+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9536+ else
9537+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9538+
9539+ if (test_thread_flag(TIF_32BIT))
9540+ addr &= 0xFFFFFFFFUL;
9541+
9542+ regs->tpc = addr;
9543+ regs->tnpc = addr+4;
9544+ return 2;
9545+ }
9546+ } while (0);
9547+
9548+ do { /* PaX: patched PLT emulation #4 */
9549+ unsigned int sethi, mov1, call, mov2;
9550+
9551+ err = get_user(sethi, (unsigned int *)regs->tpc);
9552+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9553+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9554+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9555+
9556+ if (err)
9557+ break;
9558+
9559+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9560+ mov1 == 0x8210000FU &&
9561+ (call & 0xC0000000U) == 0x40000000U &&
9562+ mov2 == 0x9E100001U)
9563+ {
9564+ unsigned long addr;
9565+
9566+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9567+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9568+
9569+ if (test_thread_flag(TIF_32BIT))
9570+ addr &= 0xFFFFFFFFUL;
9571+
9572+ regs->tpc = addr;
9573+ regs->tnpc = addr+4;
9574+ return 2;
9575+ }
9576+ } while (0);
9577+
9578+ do { /* PaX: patched PLT emulation #5 */
9579+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9580+
9581+ err = get_user(sethi, (unsigned int *)regs->tpc);
9582+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9583+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9584+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9585+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9586+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9587+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9588+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9589+
9590+ if (err)
9591+ break;
9592+
9593+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9594+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9595+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9596+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9597+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9598+ sllx == 0x83287020U &&
9599+ jmpl == 0x81C04005U &&
9600+ nop == 0x01000000U)
9601+ {
9602+ unsigned long addr;
9603+
9604+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9605+ regs->u_regs[UREG_G1] <<= 32;
9606+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9607+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9608+ regs->tpc = addr;
9609+ regs->tnpc = addr+4;
9610+ return 2;
9611+ }
9612+ } while (0);
9613+
9614+ do { /* PaX: patched PLT emulation #6 */
9615+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9616+
9617+ err = get_user(sethi, (unsigned int *)regs->tpc);
9618+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9619+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9620+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9621+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9622+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9623+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9624+
9625+ if (err)
9626+ break;
9627+
9628+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9629+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9630+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9631+ sllx == 0x83287020U &&
9632+ (or & 0xFFFFE000U) == 0x8A116000U &&
9633+ jmpl == 0x81C04005U &&
9634+ nop == 0x01000000U)
9635+ {
9636+ unsigned long addr;
9637+
9638+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9639+ regs->u_regs[UREG_G1] <<= 32;
9640+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9641+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9642+ regs->tpc = addr;
9643+ regs->tnpc = addr+4;
9644+ return 2;
9645+ }
9646+ } while (0);
9647+
9648+ do { /* PaX: unpatched PLT emulation step 1 */
9649+ unsigned int sethi, ba, nop;
9650+
9651+ err = get_user(sethi, (unsigned int *)regs->tpc);
9652+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9653+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9654+
9655+ if (err)
9656+ break;
9657+
9658+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9659+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9660+ nop == 0x01000000U)
9661+ {
9662+ unsigned long addr;
9663+ unsigned int save, call;
9664+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9665+
9666+ if ((ba & 0xFFC00000U) == 0x30800000U)
9667+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9668+ else
9669+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9670+
9671+ if (test_thread_flag(TIF_32BIT))
9672+ addr &= 0xFFFFFFFFUL;
9673+
9674+ err = get_user(save, (unsigned int *)addr);
9675+ err |= get_user(call, (unsigned int *)(addr+4));
9676+ err |= get_user(nop, (unsigned int *)(addr+8));
9677+ if (err)
9678+ break;
9679+
9680+#ifdef CONFIG_PAX_DLRESOLVE
9681+ if (save == 0x9DE3BFA8U &&
9682+ (call & 0xC0000000U) == 0x40000000U &&
9683+ nop == 0x01000000U)
9684+ {
9685+ struct vm_area_struct *vma;
9686+ unsigned long call_dl_resolve;
9687+
9688+ down_read(&current->mm->mmap_sem);
9689+ call_dl_resolve = current->mm->call_dl_resolve;
9690+ up_read(&current->mm->mmap_sem);
9691+ if (likely(call_dl_resolve))
9692+ goto emulate;
9693+
9694+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9695+
9696+ down_write(&current->mm->mmap_sem);
9697+ if (current->mm->call_dl_resolve) {
9698+ call_dl_resolve = current->mm->call_dl_resolve;
9699+ up_write(&current->mm->mmap_sem);
9700+ if (vma)
9701+ kmem_cache_free(vm_area_cachep, vma);
9702+ goto emulate;
9703+ }
9704+
9705+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9706+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9707+ up_write(&current->mm->mmap_sem);
9708+ if (vma)
9709+ kmem_cache_free(vm_area_cachep, vma);
9710+ return 1;
9711+ }
9712+
9713+ if (pax_insert_vma(vma, call_dl_resolve)) {
9714+ up_write(&current->mm->mmap_sem);
9715+ kmem_cache_free(vm_area_cachep, vma);
9716+ return 1;
9717+ }
9718+
9719+ current->mm->call_dl_resolve = call_dl_resolve;
9720+ up_write(&current->mm->mmap_sem);
9721+
9722+emulate:
9723+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9724+ regs->tpc = call_dl_resolve;
9725+ regs->tnpc = addr+4;
9726+ return 3;
9727+ }
9728+#endif
9729+
9730+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9731+ if ((save & 0xFFC00000U) == 0x05000000U &&
9732+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9733+ nop == 0x01000000U)
9734+ {
9735+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9736+ regs->u_regs[UREG_G2] = addr + 4;
9737+ addr = (save & 0x003FFFFFU) << 10;
9738+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9739+
9740+ if (test_thread_flag(TIF_32BIT))
9741+ addr &= 0xFFFFFFFFUL;
9742+
9743+ regs->tpc = addr;
9744+ regs->tnpc = addr+4;
9745+ return 3;
9746+ }
9747+
9748+ /* PaX: 64-bit PLT stub */
9749+ err = get_user(sethi1, (unsigned int *)addr);
9750+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9751+ err |= get_user(or1, (unsigned int *)(addr+8));
9752+ err |= get_user(or2, (unsigned int *)(addr+12));
9753+ err |= get_user(sllx, (unsigned int *)(addr+16));
9754+ err |= get_user(add, (unsigned int *)(addr+20));
9755+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9756+ err |= get_user(nop, (unsigned int *)(addr+28));
9757+ if (err)
9758+ break;
9759+
9760+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9761+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9762+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9763+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9764+ sllx == 0x89293020U &&
9765+ add == 0x8A010005U &&
9766+ jmpl == 0x89C14000U &&
9767+ nop == 0x01000000U)
9768+ {
9769+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9770+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9771+ regs->u_regs[UREG_G4] <<= 32;
9772+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9773+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9774+ regs->u_regs[UREG_G4] = addr + 24;
9775+ addr = regs->u_regs[UREG_G5];
9776+ regs->tpc = addr;
9777+ regs->tnpc = addr+4;
9778+ return 3;
9779+ }
9780+ }
9781+ } while (0);
9782+
9783+#ifdef CONFIG_PAX_DLRESOLVE
9784+ do { /* PaX: unpatched PLT emulation step 2 */
9785+ unsigned int save, call, nop;
9786+
9787+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9788+ err |= get_user(call, (unsigned int *)regs->tpc);
9789+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9790+ if (err)
9791+ break;
9792+
9793+ if (save == 0x9DE3BFA8U &&
9794+ (call & 0xC0000000U) == 0x40000000U &&
9795+ nop == 0x01000000U)
9796+ {
9797+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9798+
9799+ if (test_thread_flag(TIF_32BIT))
9800+ dl_resolve &= 0xFFFFFFFFUL;
9801+
9802+ regs->u_regs[UREG_RETPC] = regs->tpc;
9803+ regs->tpc = dl_resolve;
9804+ regs->tnpc = dl_resolve+4;
9805+ return 3;
9806+ }
9807+ } while (0);
9808+#endif
9809+
9810+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9811+ unsigned int sethi, ba, nop;
9812+
9813+ err = get_user(sethi, (unsigned int *)regs->tpc);
9814+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9815+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9816+
9817+ if (err)
9818+ break;
9819+
9820+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9821+ (ba & 0xFFF00000U) == 0x30600000U &&
9822+ nop == 0x01000000U)
9823+ {
9824+ unsigned long addr;
9825+
9826+ addr = (sethi & 0x003FFFFFU) << 10;
9827+ regs->u_regs[UREG_G1] = addr;
9828+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9829+
9830+ if (test_thread_flag(TIF_32BIT))
9831+ addr &= 0xFFFFFFFFUL;
9832+
9833+ regs->tpc = addr;
9834+ regs->tnpc = addr+4;
9835+ return 2;
9836+ }
9837+ } while (0);
9838+
9839+#endif
9840+
9841+ return 1;
9842+}
9843+
9844+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9845+{
9846+ unsigned long i;
9847+
9848+ printk(KERN_ERR "PAX: bytes at PC: ");
9849+ for (i = 0; i < 8; i++) {
9850+ unsigned int c;
9851+ if (get_user(c, (unsigned int *)pc+i))
9852+ printk(KERN_CONT "???????? ");
9853+ else
9854+ printk(KERN_CONT "%08x ", c);
9855+ }
9856+ printk("\n");
9857+}
9858+#endif
9859+
9860 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9861 {
9862 struct mm_struct *mm = current->mm;
9863@@ -341,6 +804,29 @@ retry:
9864 if (!vma)
9865 goto bad_area;
9866
9867+#ifdef CONFIG_PAX_PAGEEXEC
9868+ /* PaX: detect ITLB misses on non-exec pages */
9869+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9870+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9871+ {
9872+ if (address != regs->tpc)
9873+ goto good_area;
9874+
9875+ up_read(&mm->mmap_sem);
9876+ switch (pax_handle_fetch_fault(regs)) {
9877+
9878+#ifdef CONFIG_PAX_EMUPLT
9879+ case 2:
9880+ case 3:
9881+ return;
9882+#endif
9883+
9884+ }
9885+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9886+ do_group_exit(SIGKILL);
9887+ }
9888+#endif
9889+
9890 /* Pure DTLB misses do not tell us whether the fault causing
9891 * load/store/atomic was a write or not, it only says that there
9892 * was no match. So in such a case we (carefully) read the
9893diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9894index d2b5944..bd813f2 100644
9895--- a/arch/sparc/mm/hugetlbpage.c
9896+++ b/arch/sparc/mm/hugetlbpage.c
9897@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9898
9899 info.flags = 0;
9900 info.length = len;
9901- info.low_limit = TASK_UNMAPPED_BASE;
9902+ info.low_limit = mm->mmap_base;
9903 info.high_limit = min(task_size, VA_EXCLUDE_START);
9904 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9905 info.align_offset = 0;
9906@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9907 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9908 VM_BUG_ON(addr != -ENOMEM);
9909 info.low_limit = VA_EXCLUDE_END;
9910+
9911+#ifdef CONFIG_PAX_RANDMMAP
9912+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9913+ info.low_limit += mm->delta_mmap;
9914+#endif
9915+
9916 info.high_limit = task_size;
9917 addr = vm_unmapped_area(&info);
9918 }
9919@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9920 VM_BUG_ON(addr != -ENOMEM);
9921 info.flags = 0;
9922 info.low_limit = TASK_UNMAPPED_BASE;
9923+
9924+#ifdef CONFIG_PAX_RANDMMAP
9925+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9926+ info.low_limit += mm->delta_mmap;
9927+#endif
9928+
9929 info.high_limit = STACK_TOP32;
9930 addr = vm_unmapped_area(&info);
9931 }
9932@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9933 struct mm_struct *mm = current->mm;
9934 struct vm_area_struct *vma;
9935 unsigned long task_size = TASK_SIZE;
9936+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9937
9938 if (test_thread_flag(TIF_32BIT))
9939 task_size = STACK_TOP32;
9940@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9941 return addr;
9942 }
9943
9944+#ifdef CONFIG_PAX_RANDMMAP
9945+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9946+#endif
9947+
9948 if (addr) {
9949 addr = ALIGN(addr, HPAGE_SIZE);
9950 vma = find_vma(mm, addr);
9951- if (task_size - len >= addr &&
9952- (!vma || addr + len <= vma->vm_start))
9953+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9954 return addr;
9955 }
9956 if (mm->get_unmapped_area == arch_get_unmapped_area)
9957diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9958index f4500c6..889656c 100644
9959--- a/arch/tile/include/asm/atomic_64.h
9960+++ b/arch/tile/include/asm/atomic_64.h
9961@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9962
9963 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9964
9965+#define atomic64_read_unchecked(v) atomic64_read(v)
9966+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9967+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9968+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9969+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9970+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9971+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9972+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9973+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9974+
9975 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9976 #define smp_mb__before_atomic_dec() smp_mb()
9977 #define smp_mb__after_atomic_dec() smp_mb()
9978diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9979index a9a5299..0fce79e 100644
9980--- a/arch/tile/include/asm/cache.h
9981+++ b/arch/tile/include/asm/cache.h
9982@@ -15,11 +15,12 @@
9983 #ifndef _ASM_TILE_CACHE_H
9984 #define _ASM_TILE_CACHE_H
9985
9986+#include <linux/const.h>
9987 #include <arch/chip.h>
9988
9989 /* bytes per L1 data cache line */
9990 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9991-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9992+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9993
9994 /* bytes per L2 cache line */
9995 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9996diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9997index 9ab078a..d6635c2 100644
9998--- a/arch/tile/include/asm/uaccess.h
9999+++ b/arch/tile/include/asm/uaccess.h
10000@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10001 const void __user *from,
10002 unsigned long n)
10003 {
10004- int sz = __compiletime_object_size(to);
10005+ size_t sz = __compiletime_object_size(to);
10006
10007- if (likely(sz == -1 || sz >= n))
10008+ if (likely(sz == (size_t)-1 || sz >= n))
10009 n = _copy_from_user(to, from, n);
10010 else
10011 copy_from_user_overflow();
10012diff --git a/arch/um/Makefile b/arch/um/Makefile
10013index 133f7de..1d6f2f1 100644
10014--- a/arch/um/Makefile
10015+++ b/arch/um/Makefile
10016@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10017 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10018 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10019
10020+ifdef CONSTIFY_PLUGIN
10021+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10022+endif
10023+
10024 #This will adjust *FLAGS accordingly to the platform.
10025 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10026
10027diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10028index 19e1bdd..3665b77 100644
10029--- a/arch/um/include/asm/cache.h
10030+++ b/arch/um/include/asm/cache.h
10031@@ -1,6 +1,7 @@
10032 #ifndef __UM_CACHE_H
10033 #define __UM_CACHE_H
10034
10035+#include <linux/const.h>
10036
10037 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10038 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10039@@ -12,6 +13,6 @@
10040 # define L1_CACHE_SHIFT 5
10041 #endif
10042
10043-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10044+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10045
10046 #endif
10047diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10048index 2e0a6b1..a64d0f5 100644
10049--- a/arch/um/include/asm/kmap_types.h
10050+++ b/arch/um/include/asm/kmap_types.h
10051@@ -8,6 +8,6 @@
10052
10053 /* No more #include "asm/arch/kmap_types.h" ! */
10054
10055-#define KM_TYPE_NR 14
10056+#define KM_TYPE_NR 15
10057
10058 #endif
10059diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10060index 5ff53d9..5850cdf 100644
10061--- a/arch/um/include/asm/page.h
10062+++ b/arch/um/include/asm/page.h
10063@@ -14,6 +14,9 @@
10064 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10065 #define PAGE_MASK (~(PAGE_SIZE-1))
10066
10067+#define ktla_ktva(addr) (addr)
10068+#define ktva_ktla(addr) (addr)
10069+
10070 #ifndef __ASSEMBLY__
10071
10072 struct page;
10073diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10074index 0032f92..cd151e0 100644
10075--- a/arch/um/include/asm/pgtable-3level.h
10076+++ b/arch/um/include/asm/pgtable-3level.h
10077@@ -58,6 +58,7 @@
10078 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10079 #define pud_populate(mm, pud, pmd) \
10080 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10081+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10082
10083 #ifdef CONFIG_64BIT
10084 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10085diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10086index b462b13..e7a19aa 100644
10087--- a/arch/um/kernel/process.c
10088+++ b/arch/um/kernel/process.c
10089@@ -386,22 +386,6 @@ int singlestepping(void * t)
10090 return 2;
10091 }
10092
10093-/*
10094- * Only x86 and x86_64 have an arch_align_stack().
10095- * All other arches have "#define arch_align_stack(x) (x)"
10096- * in their asm/system.h
10097- * As this is included in UML from asm-um/system-generic.h,
10098- * we can use it to behave as the subarch does.
10099- */
10100-#ifndef arch_align_stack
10101-unsigned long arch_align_stack(unsigned long sp)
10102-{
10103- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10104- sp -= get_random_int() % 8192;
10105- return sp & ~0xf;
10106-}
10107-#endif
10108-
10109 unsigned long get_wchan(struct task_struct *p)
10110 {
10111 unsigned long stack_page, sp, ip;
10112diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10113index ad8f795..2c7eec6 100644
10114--- a/arch/unicore32/include/asm/cache.h
10115+++ b/arch/unicore32/include/asm/cache.h
10116@@ -12,8 +12,10 @@
10117 #ifndef __UNICORE_CACHE_H__
10118 #define __UNICORE_CACHE_H__
10119
10120-#define L1_CACHE_SHIFT (5)
10121-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10122+#include <linux/const.h>
10123+
10124+#define L1_CACHE_SHIFT 5
10125+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10126
10127 /*
10128 * Memory returned by kmalloc() may be used for DMA, so we must make
10129diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10130index 0694d09..b58b3aa 100644
10131--- a/arch/x86/Kconfig
10132+++ b/arch/x86/Kconfig
10133@@ -238,7 +238,7 @@ config X86_HT
10134
10135 config X86_32_LAZY_GS
10136 def_bool y
10137- depends on X86_32 && !CC_STACKPROTECTOR
10138+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10139
10140 config ARCH_HWEIGHT_CFLAGS
10141 string
10142@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
10143
10144 config X86_MSR
10145 tristate "/dev/cpu/*/msr - Model-specific register support"
10146+ depends on !GRKERNSEC_KMEM
10147 ---help---
10148 This device gives privileged processes access to the x86
10149 Model-Specific Registers (MSRs). It is a character device with
10150@@ -1054,7 +1055,7 @@ choice
10151
10152 config NOHIGHMEM
10153 bool "off"
10154- depends on !X86_NUMAQ
10155+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10156 ---help---
10157 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10158 However, the address space of 32-bit x86 processors is only 4
10159@@ -1091,7 +1092,7 @@ config NOHIGHMEM
10160
10161 config HIGHMEM4G
10162 bool "4GB"
10163- depends on !X86_NUMAQ
10164+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10165 ---help---
10166 Select this if you have a 32-bit processor and between 1 and 4
10167 gigabytes of physical RAM.
10168@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
10169 hex
10170 default 0xB0000000 if VMSPLIT_3G_OPT
10171 default 0x80000000 if VMSPLIT_2G
10172- default 0x78000000 if VMSPLIT_2G_OPT
10173+ default 0x70000000 if VMSPLIT_2G_OPT
10174 default 0x40000000 if VMSPLIT_1G
10175 default 0xC0000000
10176 depends on X86_32
10177@@ -1542,6 +1543,7 @@ config SECCOMP
10178
10179 config CC_STACKPROTECTOR
10180 bool "Enable -fstack-protector buffer overflow detection"
10181+ depends on X86_64 || !PAX_MEMORY_UDEREF
10182 ---help---
10183 This option turns on the -fstack-protector GCC feature. This
10184 feature puts, at the beginning of functions, a canary value on
10185@@ -1599,6 +1601,7 @@ config KEXEC_JUMP
10186 config PHYSICAL_START
10187 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
10188 default "0x1000000"
10189+ range 0x400000 0x40000000
10190 ---help---
10191 This gives the physical address where the kernel is loaded.
10192
10193@@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
10194 config PHYSICAL_ALIGN
10195 hex "Alignment value to which kernel should be aligned" if X86_32
10196 default "0x1000000"
10197+ range 0x400000 0x1000000 if PAX_KERNEXEC
10198 range 0x2000 0x1000000
10199 ---help---
10200 This value puts the alignment restrictions on physical address
10201@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
10202 If unsure, say N.
10203
10204 config COMPAT_VDSO
10205- def_bool y
10206+ def_bool n
10207 prompt "Compat VDSO support"
10208 depends on X86_32 || IA32_EMULATION
10209+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10210 ---help---
10211 Map the 32-bit VDSO to the predictable old-style address too.
10212
10213diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10214index c026cca..14657ae 100644
10215--- a/arch/x86/Kconfig.cpu
10216+++ b/arch/x86/Kconfig.cpu
10217@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10218
10219 config X86_F00F_BUG
10220 def_bool y
10221- depends on M586MMX || M586TSC || M586 || M486
10222+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10223
10224 config X86_INVD_BUG
10225 def_bool y
10226@@ -327,7 +327,7 @@ config X86_INVD_BUG
10227
10228 config X86_ALIGNMENT_16
10229 def_bool y
10230- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10231+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10232
10233 config X86_INTEL_USERCOPY
10234 def_bool y
10235@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10236 # generates cmov.
10237 config X86_CMOV
10238 def_bool y
10239- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10240+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10241
10242 config X86_MINIMUM_CPU_FAMILY
10243 int
10244diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10245index b322f12..652d0d9 100644
10246--- a/arch/x86/Kconfig.debug
10247+++ b/arch/x86/Kconfig.debug
10248@@ -84,7 +84,7 @@ config X86_PTDUMP
10249 config DEBUG_RODATA
10250 bool "Write protect kernel read-only data structures"
10251 default y
10252- depends on DEBUG_KERNEL
10253+ depends on DEBUG_KERNEL && BROKEN
10254 ---help---
10255 Mark the kernel read-only data as write-protected in the pagetables,
10256 in order to catch accidental (and incorrect) writes to such const
10257@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10258
10259 config DEBUG_SET_MODULE_RONX
10260 bool "Set loadable kernel module data as NX and text as RO"
10261- depends on MODULES
10262+ depends on MODULES && BROKEN
10263 ---help---
10264 This option helps catch unintended modifications to loadable
10265 kernel module's text and read-only data. It also prevents execution
10266@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10267
10268 config DEBUG_STRICT_USER_COPY_CHECKS
10269 bool "Strict copy size checks"
10270- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10271+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10272 ---help---
10273 Enabling this option turns a certain set of sanity checks for user
10274 copy operations into compile time failures.
10275diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10276index e71fc42..7829607 100644
10277--- a/arch/x86/Makefile
10278+++ b/arch/x86/Makefile
10279@@ -50,6 +50,7 @@ else
10280 UTS_MACHINE := x86_64
10281 CHECKFLAGS += -D__x86_64__ -m64
10282
10283+ biarch := $(call cc-option,-m64)
10284 KBUILD_AFLAGS += -m64
10285 KBUILD_CFLAGS += -m64
10286
10287@@ -230,3 +231,12 @@ define archhelp
10288 echo ' FDARGS="..." arguments for the booted kernel'
10289 echo ' FDINITRD=file initrd for the booted kernel'
10290 endef
10291+
10292+define OLD_LD
10293+
10294+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10295+*** Please upgrade your binutils to 2.18 or newer
10296+endef
10297+
10298+archprepare:
10299+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10300diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10301index 379814b..add62ce 100644
10302--- a/arch/x86/boot/Makefile
10303+++ b/arch/x86/boot/Makefile
10304@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10305 $(call cc-option, -fno-stack-protector) \
10306 $(call cc-option, -mpreferred-stack-boundary=2)
10307 KBUILD_CFLAGS += $(call cc-option, -m32)
10308+ifdef CONSTIFY_PLUGIN
10309+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10310+endif
10311 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10312 GCOV_PROFILE := n
10313
10314diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10315index 878e4b9..20537ab 100644
10316--- a/arch/x86/boot/bitops.h
10317+++ b/arch/x86/boot/bitops.h
10318@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10319 u8 v;
10320 const u32 *p = (const u32 *)addr;
10321
10322- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10323+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10324 return v;
10325 }
10326
10327@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10328
10329 static inline void set_bit(int nr, void *addr)
10330 {
10331- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10332+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10333 }
10334
10335 #endif /* BOOT_BITOPS_H */
10336diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10337index 18997e5..83d9c67 100644
10338--- a/arch/x86/boot/boot.h
10339+++ b/arch/x86/boot/boot.h
10340@@ -85,7 +85,7 @@ static inline void io_delay(void)
10341 static inline u16 ds(void)
10342 {
10343 u16 seg;
10344- asm("movw %%ds,%0" : "=rm" (seg));
10345+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10346 return seg;
10347 }
10348
10349@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10350 static inline int memcmp(const void *s1, const void *s2, size_t len)
10351 {
10352 u8 diff;
10353- asm("repe; cmpsb; setnz %0"
10354+ asm volatile("repe; cmpsb; setnz %0"
10355 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10356 return diff;
10357 }
10358diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10359index 8a84501..b2d165f 100644
10360--- a/arch/x86/boot/compressed/Makefile
10361+++ b/arch/x86/boot/compressed/Makefile
10362@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10363 KBUILD_CFLAGS += $(cflags-y)
10364 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10365 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10366+ifdef CONSTIFY_PLUGIN
10367+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10368+endif
10369
10370 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10371 GCOV_PROFILE := n
10372diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10373index c205035..5853587 100644
10374--- a/arch/x86/boot/compressed/eboot.c
10375+++ b/arch/x86/boot/compressed/eboot.c
10376@@ -150,7 +150,6 @@ again:
10377 *addr = max_addr;
10378 }
10379
10380-free_pool:
10381 efi_call_phys1(sys_table->boottime->free_pool, map);
10382
10383 fail:
10384@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10385 if (i == map_size / desc_size)
10386 status = EFI_NOT_FOUND;
10387
10388-free_pool:
10389 efi_call_phys1(sys_table->boottime->free_pool, map);
10390 fail:
10391 return status;
10392diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10393index 1e3184f..0d11e2e 100644
10394--- a/arch/x86/boot/compressed/head_32.S
10395+++ b/arch/x86/boot/compressed/head_32.S
10396@@ -118,7 +118,7 @@ preferred_addr:
10397 notl %eax
10398 andl %eax, %ebx
10399 #else
10400- movl $LOAD_PHYSICAL_ADDR, %ebx
10401+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10402 #endif
10403
10404 /* Target address to relocate to for decompression */
10405@@ -204,7 +204,7 @@ relocated:
10406 * and where it was actually loaded.
10407 */
10408 movl %ebp, %ebx
10409- subl $LOAD_PHYSICAL_ADDR, %ebx
10410+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10411 jz 2f /* Nothing to be done if loaded at compiled addr. */
10412 /*
10413 * Process relocations.
10414@@ -212,8 +212,7 @@ relocated:
10415
10416 1: subl $4, %edi
10417 movl (%edi), %ecx
10418- testl %ecx, %ecx
10419- jz 2f
10420+ jecxz 2f
10421 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10422 jmp 1b
10423 2:
10424diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10425index f5d1aaa..cce11dc 100644
10426--- a/arch/x86/boot/compressed/head_64.S
10427+++ b/arch/x86/boot/compressed/head_64.S
10428@@ -91,7 +91,7 @@ ENTRY(startup_32)
10429 notl %eax
10430 andl %eax, %ebx
10431 #else
10432- movl $LOAD_PHYSICAL_ADDR, %ebx
10433+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10434 #endif
10435
10436 /* Target address to relocate to for decompression */
10437@@ -273,7 +273,7 @@ preferred_addr:
10438 notq %rax
10439 andq %rax, %rbp
10440 #else
10441- movq $LOAD_PHYSICAL_ADDR, %rbp
10442+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10443 #endif
10444
10445 /* Target address to relocate to for decompression */
10446diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10447index 88f7ff6..ed695dd 100644
10448--- a/arch/x86/boot/compressed/misc.c
10449+++ b/arch/x86/boot/compressed/misc.c
10450@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10451 case PT_LOAD:
10452 #ifdef CONFIG_RELOCATABLE
10453 dest = output;
10454- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10455+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10456 #else
10457 dest = (void *)(phdr->p_paddr);
10458 #endif
10459@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10460 error("Destination address too large");
10461 #endif
10462 #ifndef CONFIG_RELOCATABLE
10463- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10464+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10465 error("Wrong destination address");
10466 #endif
10467
10468diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10469index 4d3ff03..e4972ff 100644
10470--- a/arch/x86/boot/cpucheck.c
10471+++ b/arch/x86/boot/cpucheck.c
10472@@ -74,7 +74,7 @@ static int has_fpu(void)
10473 u16 fcw = -1, fsw = -1;
10474 u32 cr0;
10475
10476- asm("movl %%cr0,%0" : "=r" (cr0));
10477+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10478 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10479 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10480 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10481@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10482 {
10483 u32 f0, f1;
10484
10485- asm("pushfl ; "
10486+ asm volatile("pushfl ; "
10487 "pushfl ; "
10488 "popl %0 ; "
10489 "movl %0,%1 ; "
10490@@ -115,7 +115,7 @@ static void get_flags(void)
10491 set_bit(X86_FEATURE_FPU, cpu.flags);
10492
10493 if (has_eflag(X86_EFLAGS_ID)) {
10494- asm("cpuid"
10495+ asm volatile("cpuid"
10496 : "=a" (max_intel_level),
10497 "=b" (cpu_vendor[0]),
10498 "=d" (cpu_vendor[1]),
10499@@ -124,7 +124,7 @@ static void get_flags(void)
10500
10501 if (max_intel_level >= 0x00000001 &&
10502 max_intel_level <= 0x0000ffff) {
10503- asm("cpuid"
10504+ asm volatile("cpuid"
10505 : "=a" (tfms),
10506 "=c" (cpu.flags[4]),
10507 "=d" (cpu.flags[0])
10508@@ -136,7 +136,7 @@ static void get_flags(void)
10509 cpu.model += ((tfms >> 16) & 0xf) << 4;
10510 }
10511
10512- asm("cpuid"
10513+ asm volatile("cpuid"
10514 : "=a" (max_amd_level)
10515 : "a" (0x80000000)
10516 : "ebx", "ecx", "edx");
10517@@ -144,7 +144,7 @@ static void get_flags(void)
10518 if (max_amd_level >= 0x80000001 &&
10519 max_amd_level <= 0x8000ffff) {
10520 u32 eax = 0x80000001;
10521- asm("cpuid"
10522+ asm volatile("cpuid"
10523 : "+a" (eax),
10524 "=c" (cpu.flags[6]),
10525 "=d" (cpu.flags[1])
10526@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10527 u32 ecx = MSR_K7_HWCR;
10528 u32 eax, edx;
10529
10530- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10531+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10532 eax &= ~(1 << 15);
10533- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10534+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10535
10536 get_flags(); /* Make sure it really did something */
10537 err = check_flags();
10538@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10539 u32 ecx = MSR_VIA_FCR;
10540 u32 eax, edx;
10541
10542- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10543+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10544 eax |= (1<<1)|(1<<7);
10545- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10546+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10547
10548 set_bit(X86_FEATURE_CX8, cpu.flags);
10549 err = check_flags();
10550@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10551 u32 eax, edx;
10552 u32 level = 1;
10553
10554- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10555- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10556- asm("cpuid"
10557+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10558+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10559+ asm volatile("cpuid"
10560 : "+a" (level), "=d" (cpu.flags[0])
10561 : : "ecx", "ebx");
10562- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10563+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10564
10565 err = check_flags();
10566 }
10567diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10568index 944ce59..87ee37a 100644
10569--- a/arch/x86/boot/header.S
10570+++ b/arch/x86/boot/header.S
10571@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10572 # single linked list of
10573 # struct setup_data
10574
10575-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10576+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10577
10578 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10579+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10580+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10581+#else
10582 #define VO_INIT_SIZE (VO__end - VO__text)
10583+#endif
10584 #if ZO_INIT_SIZE > VO_INIT_SIZE
10585 #define INIT_SIZE ZO_INIT_SIZE
10586 #else
10587diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10588index db75d07..8e6d0af 100644
10589--- a/arch/x86/boot/memory.c
10590+++ b/arch/x86/boot/memory.c
10591@@ -19,7 +19,7 @@
10592
10593 static int detect_memory_e820(void)
10594 {
10595- int count = 0;
10596+ unsigned int count = 0;
10597 struct biosregs ireg, oreg;
10598 struct e820entry *desc = boot_params.e820_map;
10599 static struct e820entry buf; /* static so it is zeroed */
10600diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10601index 11e8c6e..fdbb1ed 100644
10602--- a/arch/x86/boot/video-vesa.c
10603+++ b/arch/x86/boot/video-vesa.c
10604@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10605
10606 boot_params.screen_info.vesapm_seg = oreg.es;
10607 boot_params.screen_info.vesapm_off = oreg.di;
10608+ boot_params.screen_info.vesapm_size = oreg.cx;
10609 }
10610
10611 /*
10612diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10613index 43eda28..5ab5fdb 100644
10614--- a/arch/x86/boot/video.c
10615+++ b/arch/x86/boot/video.c
10616@@ -96,7 +96,7 @@ static void store_mode_params(void)
10617 static unsigned int get_entry(void)
10618 {
10619 char entry_buf[4];
10620- int i, len = 0;
10621+ unsigned int i, len = 0;
10622 int key;
10623 unsigned int v;
10624
10625diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10626index 5b577d5..3c1fed4 100644
10627--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10628+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10629@@ -8,6 +8,8 @@
10630 * including this sentence is retained in full.
10631 */
10632
10633+#include <asm/alternative-asm.h>
10634+
10635 .extern crypto_ft_tab
10636 .extern crypto_it_tab
10637 .extern crypto_fl_tab
10638@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10639 je B192; \
10640 leaq 32(r9),r9;
10641
10642+#define ret pax_force_retaddr 0, 1; ret
10643+
10644 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10645 movq r1,r2; \
10646 movq r3,r4; \
10647diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10648index 3470624..201259d 100644
10649--- a/arch/x86/crypto/aesni-intel_asm.S
10650+++ b/arch/x86/crypto/aesni-intel_asm.S
10651@@ -31,6 +31,7 @@
10652
10653 #include <linux/linkage.h>
10654 #include <asm/inst.h>
10655+#include <asm/alternative-asm.h>
10656
10657 #ifdef __x86_64__
10658 .data
10659@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10660 pop %r14
10661 pop %r13
10662 pop %r12
10663+ pax_force_retaddr 0, 1
10664 ret
10665+ENDPROC(aesni_gcm_dec)
10666
10667
10668 /*****************************************************************************
10669@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10670 pop %r14
10671 pop %r13
10672 pop %r12
10673+ pax_force_retaddr 0, 1
10674 ret
10675+ENDPROC(aesni_gcm_enc)
10676
10677 #endif
10678
10679@@ -1714,6 +1719,7 @@ _key_expansion_256a:
10680 pxor %xmm1, %xmm0
10681 movaps %xmm0, (TKEYP)
10682 add $0x10, TKEYP
10683+ pax_force_retaddr_bts
10684 ret
10685
10686 .align 4
10687@@ -1738,6 +1744,7 @@ _key_expansion_192a:
10688 shufps $0b01001110, %xmm2, %xmm1
10689 movaps %xmm1, 0x10(TKEYP)
10690 add $0x20, TKEYP
10691+ pax_force_retaddr_bts
10692 ret
10693
10694 .align 4
10695@@ -1757,6 +1764,7 @@ _key_expansion_192b:
10696
10697 movaps %xmm0, (TKEYP)
10698 add $0x10, TKEYP
10699+ pax_force_retaddr_bts
10700 ret
10701
10702 .align 4
10703@@ -1769,6 +1777,7 @@ _key_expansion_256b:
10704 pxor %xmm1, %xmm2
10705 movaps %xmm2, (TKEYP)
10706 add $0x10, TKEYP
10707+ pax_force_retaddr_bts
10708 ret
10709
10710 /*
10711@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10712 #ifndef __x86_64__
10713 popl KEYP
10714 #endif
10715+ pax_force_retaddr 0, 1
10716 ret
10717+ENDPROC(aesni_set_key)
10718
10719 /*
10720 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10721@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10722 popl KLEN
10723 popl KEYP
10724 #endif
10725+ pax_force_retaddr 0, 1
10726 ret
10727+ENDPROC(aesni_enc)
10728
10729 /*
10730 * _aesni_enc1: internal ABI
10731@@ -1959,6 +1972,7 @@ _aesni_enc1:
10732 AESENC KEY STATE
10733 movaps 0x70(TKEYP), KEY
10734 AESENCLAST KEY STATE
10735+ pax_force_retaddr_bts
10736 ret
10737
10738 /*
10739@@ -2067,6 +2081,7 @@ _aesni_enc4:
10740 AESENCLAST KEY STATE2
10741 AESENCLAST KEY STATE3
10742 AESENCLAST KEY STATE4
10743+ pax_force_retaddr_bts
10744 ret
10745
10746 /*
10747@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10748 popl KLEN
10749 popl KEYP
10750 #endif
10751+ pax_force_retaddr 0, 1
10752 ret
10753+ENDPROC(aesni_dec)
10754
10755 /*
10756 * _aesni_dec1: internal ABI
10757@@ -2146,6 +2163,7 @@ _aesni_dec1:
10758 AESDEC KEY STATE
10759 movaps 0x70(TKEYP), KEY
10760 AESDECLAST KEY STATE
10761+ pax_force_retaddr_bts
10762 ret
10763
10764 /*
10765@@ -2254,6 +2272,7 @@ _aesni_dec4:
10766 AESDECLAST KEY STATE2
10767 AESDECLAST KEY STATE3
10768 AESDECLAST KEY STATE4
10769+ pax_force_retaddr_bts
10770 ret
10771
10772 /*
10773@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10774 popl KEYP
10775 popl LEN
10776 #endif
10777+ pax_force_retaddr 0, 1
10778 ret
10779+ENDPROC(aesni_ecb_enc)
10780
10781 /*
10782 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10783@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10784 popl KEYP
10785 popl LEN
10786 #endif
10787+ pax_force_retaddr 0, 1
10788 ret
10789+ENDPROC(aesni_ecb_dec)
10790
10791 /*
10792 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10793@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10794 popl LEN
10795 popl IVP
10796 #endif
10797+ pax_force_retaddr 0, 1
10798 ret
10799+ENDPROC(aesni_cbc_enc)
10800
10801 /*
10802 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10803@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10804 popl LEN
10805 popl IVP
10806 #endif
10807+ pax_force_retaddr 0, 1
10808 ret
10809+ENDPROC(aesni_cbc_dec)
10810
10811 #ifdef __x86_64__
10812 .align 16
10813@@ -2526,6 +2553,7 @@ _aesni_inc_init:
10814 mov $1, TCTR_LOW
10815 MOVQ_R64_XMM TCTR_LOW INC
10816 MOVQ_R64_XMM CTR TCTR_LOW
10817+ pax_force_retaddr_bts
10818 ret
10819
10820 /*
10821@@ -2554,6 +2582,7 @@ _aesni_inc:
10822 .Linc_low:
10823 movaps CTR, IV
10824 PSHUFB_XMM BSWAP_MASK IV
10825+ pax_force_retaddr_bts
10826 ret
10827
10828 /*
10829@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10830 .Lctr_enc_ret:
10831 movups IV, (IVP)
10832 .Lctr_enc_just_ret:
10833+ pax_force_retaddr 0, 1
10834 ret
10835+ENDPROC(aesni_ctr_enc)
10836 #endif
10837diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10838index 391d245..67f35c2 100644
10839--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10840+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10841@@ -20,6 +20,8 @@
10842 *
10843 */
10844
10845+#include <asm/alternative-asm.h>
10846+
10847 .file "blowfish-x86_64-asm.S"
10848 .text
10849
10850@@ -151,9 +153,11 @@ __blowfish_enc_blk:
10851 jnz __enc_xor;
10852
10853 write_block();
10854+ pax_force_retaddr 0, 1
10855 ret;
10856 __enc_xor:
10857 xor_block();
10858+ pax_force_retaddr 0, 1
10859 ret;
10860
10861 .align 8
10862@@ -188,6 +192,7 @@ blowfish_dec_blk:
10863
10864 movq %r11, %rbp;
10865
10866+ pax_force_retaddr 0, 1
10867 ret;
10868
10869 /**********************************************************************
10870@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10871
10872 popq %rbx;
10873 popq %rbp;
10874+ pax_force_retaddr 0, 1
10875 ret;
10876
10877 __enc_xor4:
10878@@ -349,6 +355,7 @@ __enc_xor4:
10879
10880 popq %rbx;
10881 popq %rbp;
10882+ pax_force_retaddr 0, 1
10883 ret;
10884
10885 .align 8
10886@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10887 popq %rbx;
10888 popq %rbp;
10889
10890+ pax_force_retaddr 0, 1
10891 ret;
10892
10893diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10894index 0b33743..7a56206 100644
10895--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10896+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10897@@ -20,6 +20,8 @@
10898 *
10899 */
10900
10901+#include <asm/alternative-asm.h>
10902+
10903 .file "camellia-x86_64-asm_64.S"
10904 .text
10905
10906@@ -229,12 +231,14 @@ __enc_done:
10907 enc_outunpack(mov, RT1);
10908
10909 movq RRBP, %rbp;
10910+ pax_force_retaddr 0, 1
10911 ret;
10912
10913 __enc_xor:
10914 enc_outunpack(xor, RT1);
10915
10916 movq RRBP, %rbp;
10917+ pax_force_retaddr 0, 1
10918 ret;
10919
10920 .global camellia_dec_blk;
10921@@ -275,6 +279,7 @@ __dec_rounds16:
10922 dec_outunpack();
10923
10924 movq RRBP, %rbp;
10925+ pax_force_retaddr 0, 1
10926 ret;
10927
10928 /**********************************************************************
10929@@ -468,6 +473,7 @@ __enc2_done:
10930
10931 movq RRBP, %rbp;
10932 popq %rbx;
10933+ pax_force_retaddr 0, 1
10934 ret;
10935
10936 __enc2_xor:
10937@@ -475,6 +481,7 @@ __enc2_xor:
10938
10939 movq RRBP, %rbp;
10940 popq %rbx;
10941+ pax_force_retaddr 0, 1
10942 ret;
10943
10944 .global camellia_dec_blk_2way;
10945@@ -517,4 +524,5 @@ __dec2_rounds16:
10946
10947 movq RRBP, %rbp;
10948 movq RXOR, %rbx;
10949+ pax_force_retaddr 0, 1
10950 ret;
10951diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10952index 15b00ac..2071784 100644
10953--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10954+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10955@@ -23,6 +23,8 @@
10956 *
10957 */
10958
10959+#include <asm/alternative-asm.h>
10960+
10961 .file "cast5-avx-x86_64-asm_64.S"
10962
10963 .extern cast_s1
10964@@ -281,6 +283,7 @@ __skip_enc:
10965 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10966 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10967
10968+ pax_force_retaddr 0, 1
10969 ret;
10970
10971 .align 16
10972@@ -353,6 +356,7 @@ __dec_tail:
10973 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10974 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10975
10976+ pax_force_retaddr 0, 1
10977 ret;
10978
10979 __skip_dec:
10980@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10981 vmovdqu RR4, (6*4*4)(%r11);
10982 vmovdqu RL4, (7*4*4)(%r11);
10983
10984+ pax_force_retaddr
10985 ret;
10986
10987 .align 16
10988@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10989 vmovdqu RR4, (6*4*4)(%r11);
10990 vmovdqu RL4, (7*4*4)(%r11);
10991
10992+ pax_force_retaddr
10993 ret;
10994
10995 .align 16
10996@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10997
10998 popq %r12;
10999
11000+ pax_force_retaddr
11001 ret;
11002
11003 .align 16
11004@@ -555,4 +562,5 @@ cast5_ctr_16way:
11005
11006 popq %r12;
11007
11008+ pax_force_retaddr
11009 ret;
11010diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11011index 2569d0d..637c289 100644
11012--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11013+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11014@@ -23,6 +23,8 @@
11015 *
11016 */
11017
11018+#include <asm/alternative-asm.h>
11019+
11020 #include "glue_helper-asm-avx.S"
11021
11022 .file "cast6-avx-x86_64-asm_64.S"
11023@@ -294,6 +296,7 @@ __cast6_enc_blk8:
11024 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11025 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11026
11027+ pax_force_retaddr 0, 1
11028 ret;
11029
11030 .align 8
11031@@ -340,6 +343,7 @@ __cast6_dec_blk8:
11032 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11033 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11034
11035+ pax_force_retaddr 0, 1
11036 ret;
11037
11038 .align 8
11039@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
11040
11041 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11042
11043+ pax_force_retaddr
11044 ret;
11045
11046 .align 8
11047@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
11048
11049 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11050
11051+ pax_force_retaddr
11052 ret;
11053
11054 .align 8
11055@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
11056
11057 popq %r12;
11058
11059+ pax_force_retaddr
11060 ret;
11061
11062 .align 8
11063@@ -436,4 +443,5 @@ cast6_ctr_8way:
11064
11065 popq %r12;
11066
11067+ pax_force_retaddr
11068 ret;
11069diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11070index 6214a9b..1f4fc9a 100644
11071--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11072+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11073@@ -1,3 +1,5 @@
11074+#include <asm/alternative-asm.h>
11075+
11076 # enter ECRYPT_encrypt_bytes
11077 .text
11078 .p2align 5
11079@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
11080 add %r11,%rsp
11081 mov %rdi,%rax
11082 mov %rsi,%rdx
11083+ pax_force_retaddr 0, 1
11084 ret
11085 # bytesatleast65:
11086 ._bytesatleast65:
11087@@ -891,6 +894,7 @@ ECRYPT_keysetup:
11088 add %r11,%rsp
11089 mov %rdi,%rax
11090 mov %rsi,%rdx
11091+ pax_force_retaddr
11092 ret
11093 # enter ECRYPT_ivsetup
11094 .text
11095@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
11096 add %r11,%rsp
11097 mov %rdi,%rax
11098 mov %rsi,%rdx
11099+ pax_force_retaddr
11100 ret
11101diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11102index 02b0e9f..cf4cf5c 100644
11103--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11104+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11105@@ -24,6 +24,8 @@
11106 *
11107 */
11108
11109+#include <asm/alternative-asm.h>
11110+
11111 #include "glue_helper-asm-avx.S"
11112
11113 .file "serpent-avx-x86_64-asm_64.S"
11114@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
11115 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11116 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11117
11118+ pax_force_retaddr
11119 ret;
11120
11121 .align 8
11122@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
11123 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11124 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11125
11126+ pax_force_retaddr
11127 ret;
11128
11129 .align 8
11130@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
11131
11132 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11133
11134+ pax_force_retaddr
11135 ret;
11136
11137 .align 8
11138@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
11139
11140 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11141
11142+ pax_force_retaddr
11143 ret;
11144
11145 .align 8
11146@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
11147
11148 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11149
11150+ pax_force_retaddr
11151 ret;
11152
11153 .align 8
11154@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
11155
11156 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11157
11158+ pax_force_retaddr
11159 ret;
11160diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11161index 3ee1ff0..cbc568b 100644
11162--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11163+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11164@@ -24,6 +24,8 @@
11165 *
11166 */
11167
11168+#include <asm/alternative-asm.h>
11169+
11170 .file "serpent-sse2-x86_64-asm_64.S"
11171 .text
11172
11173@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
11174 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11175 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11176
11177+ pax_force_retaddr
11178 ret;
11179
11180 __enc_xor8:
11181 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11182 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11183
11184+ pax_force_retaddr
11185 ret;
11186
11187 .align 8
11188@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
11189 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11190 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11191
11192+ pax_force_retaddr
11193 ret;
11194diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11195index 49d6987..df66bd4 100644
11196--- a/arch/x86/crypto/sha1_ssse3_asm.S
11197+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11198@@ -28,6 +28,8 @@
11199 * (at your option) any later version.
11200 */
11201
11202+#include <asm/alternative-asm.h>
11203+
11204 #define CTX %rdi // arg1
11205 #define BUF %rsi // arg2
11206 #define CNT %rdx // arg3
11207@@ -104,6 +106,7 @@
11208 pop %r12
11209 pop %rbp
11210 pop %rbx
11211+ pax_force_retaddr 0, 1
11212 ret
11213
11214 .size \name, .-\name
11215diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11216index ebac16b..8092eb9 100644
11217--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11218+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11219@@ -23,6 +23,8 @@
11220 *
11221 */
11222
11223+#include <asm/alternative-asm.h>
11224+
11225 #include "glue_helper-asm-avx.S"
11226
11227 .file "twofish-avx-x86_64-asm_64.S"
11228@@ -283,6 +285,7 @@ __twofish_enc_blk8:
11229 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11230 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11231
11232+ pax_force_retaddr 0, 1
11233 ret;
11234
11235 .align 8
11236@@ -324,6 +327,7 @@ __twofish_dec_blk8:
11237 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11238 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11239
11240+ pax_force_retaddr 0, 1
11241 ret;
11242
11243 .align 8
11244@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11245
11246 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11247
11248+ pax_force_retaddr 0, 1
11249 ret;
11250
11251 .align 8
11252@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11253
11254 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11255
11256+ pax_force_retaddr 0, 1
11257 ret;
11258
11259 .align 8
11260@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11261
11262 popq %r12;
11263
11264+ pax_force_retaddr 0, 1
11265 ret;
11266
11267 .align 8
11268@@ -420,4 +427,5 @@ twofish_ctr_8way:
11269
11270 popq %r12;
11271
11272+ pax_force_retaddr 0, 1
11273 ret;
11274diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11275index 5b012a2..36d5364 100644
11276--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11277+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11278@@ -20,6 +20,8 @@
11279 *
11280 */
11281
11282+#include <asm/alternative-asm.h>
11283+
11284 .file "twofish-x86_64-asm-3way.S"
11285 .text
11286
11287@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11288 popq %r13;
11289 popq %r14;
11290 popq %r15;
11291+ pax_force_retaddr 0, 1
11292 ret;
11293
11294 __enc_xor3:
11295@@ -271,6 +274,7 @@ __enc_xor3:
11296 popq %r13;
11297 popq %r14;
11298 popq %r15;
11299+ pax_force_retaddr 0, 1
11300 ret;
11301
11302 .global twofish_dec_blk_3way
11303@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11304 popq %r13;
11305 popq %r14;
11306 popq %r15;
11307+ pax_force_retaddr 0, 1
11308 ret;
11309
11310diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11311index 7bcf3fc..f53832f 100644
11312--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11313+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11314@@ -21,6 +21,7 @@
11315 .text
11316
11317 #include <asm/asm-offsets.h>
11318+#include <asm/alternative-asm.h>
11319
11320 #define a_offset 0
11321 #define b_offset 4
11322@@ -268,6 +269,7 @@ twofish_enc_blk:
11323
11324 popq R1
11325 movq $1,%rax
11326+ pax_force_retaddr 0, 1
11327 ret
11328
11329 twofish_dec_blk:
11330@@ -319,4 +321,5 @@ twofish_dec_blk:
11331
11332 popq R1
11333 movq $1,%rax
11334+ pax_force_retaddr 0, 1
11335 ret
11336diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11337index a703af1..f5b9c36 100644
11338--- a/arch/x86/ia32/ia32_aout.c
11339+++ b/arch/x86/ia32/ia32_aout.c
11340@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11341 unsigned long dump_start, dump_size;
11342 struct user32 dump;
11343
11344+ memset(&dump, 0, sizeof(dump));
11345+
11346 fs = get_fs();
11347 set_fs(KERNEL_DS);
11348 has_dumped = 1;
11349diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11350index a1daf4a..f8c4537 100644
11351--- a/arch/x86/ia32/ia32_signal.c
11352+++ b/arch/x86/ia32/ia32_signal.c
11353@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11354 sp -= frame_size;
11355 /* Align the stack pointer according to the i386 ABI,
11356 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11357- sp = ((sp + 4) & -16ul) - 4;
11358+ sp = ((sp - 12) & -16ul) - 4;
11359 return (void __user *) sp;
11360 }
11361
11362@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11363 * These are actually not used anymore, but left because some
11364 * gdb versions depend on them as a marker.
11365 */
11366- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11367+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11368 } put_user_catch(err);
11369
11370 if (err)
11371@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11372 0xb8,
11373 __NR_ia32_rt_sigreturn,
11374 0x80cd,
11375- 0,
11376+ 0
11377 };
11378
11379 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11380@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11381
11382 if (ka->sa.sa_flags & SA_RESTORER)
11383 restorer = ka->sa.sa_restorer;
11384+ else if (current->mm->context.vdso)
11385+ /* Return stub is in 32bit vsyscall page */
11386+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11387 else
11388- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11389- rt_sigreturn);
11390+ restorer = &frame->retcode;
11391 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11392
11393 /*
11394 * Not actually used anymore, but left because some gdb
11395 * versions need it.
11396 */
11397- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11398+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11399 } put_user_catch(err);
11400
11401 err |= copy_siginfo_to_user32(&frame->info, info);
11402diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11403index 142c4ce..19b683f 100644
11404--- a/arch/x86/ia32/ia32entry.S
11405+++ b/arch/x86/ia32/ia32entry.S
11406@@ -15,8 +15,10 @@
11407 #include <asm/irqflags.h>
11408 #include <asm/asm.h>
11409 #include <asm/smap.h>
11410+#include <asm/pgtable.h>
11411 #include <linux/linkage.h>
11412 #include <linux/err.h>
11413+#include <asm/alternative-asm.h>
11414
11415 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11416 #include <linux/elf-em.h>
11417@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11418 ENDPROC(native_irq_enable_sysexit)
11419 #endif
11420
11421+ .macro pax_enter_kernel_user
11422+ pax_set_fptr_mask
11423+#ifdef CONFIG_PAX_MEMORY_UDEREF
11424+ call pax_enter_kernel_user
11425+#endif
11426+ .endm
11427+
11428+ .macro pax_exit_kernel_user
11429+#ifdef CONFIG_PAX_MEMORY_UDEREF
11430+ call pax_exit_kernel_user
11431+#endif
11432+#ifdef CONFIG_PAX_RANDKSTACK
11433+ pushq %rax
11434+ pushq %r11
11435+ call pax_randomize_kstack
11436+ popq %r11
11437+ popq %rax
11438+#endif
11439+ .endm
11440+
11441+.macro pax_erase_kstack
11442+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11443+ call pax_erase_kstack
11444+#endif
11445+.endm
11446+
11447 /*
11448 * 32bit SYSENTER instruction entry.
11449 *
11450@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11451 CFI_REGISTER rsp,rbp
11452 SWAPGS_UNSAFE_STACK
11453 movq PER_CPU_VAR(kernel_stack), %rsp
11454- addq $(KERNEL_STACK_OFFSET),%rsp
11455- /*
11456- * No need to follow this irqs on/off section: the syscall
11457- * disabled irqs, here we enable it straight after entry:
11458- */
11459- ENABLE_INTERRUPTS(CLBR_NONE)
11460 movl %ebp,%ebp /* zero extension */
11461 pushq_cfi $__USER32_DS
11462 /*CFI_REL_OFFSET ss,0*/
11463@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11464 CFI_REL_OFFSET rsp,0
11465 pushfq_cfi
11466 /*CFI_REL_OFFSET rflags,0*/
11467- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11468- CFI_REGISTER rip,r10
11469+ orl $X86_EFLAGS_IF,(%rsp)
11470+ GET_THREAD_INFO(%r11)
11471+ movl TI_sysenter_return(%r11), %r11d
11472+ CFI_REGISTER rip,r11
11473 pushq_cfi $__USER32_CS
11474 /*CFI_REL_OFFSET cs,0*/
11475 movl %eax, %eax
11476- pushq_cfi %r10
11477+ pushq_cfi %r11
11478 CFI_REL_OFFSET rip,0
11479 pushq_cfi %rax
11480 cld
11481 SAVE_ARGS 0,1,0
11482+ pax_enter_kernel_user
11483+
11484+#ifdef CONFIG_PAX_RANDKSTACK
11485+ pax_erase_kstack
11486+#endif
11487+
11488+ /*
11489+ * No need to follow this irqs on/off section: the syscall
11490+ * disabled irqs, here we enable it straight after entry:
11491+ */
11492+ ENABLE_INTERRUPTS(CLBR_NONE)
11493 /* no need to do an access_ok check here because rbp has been
11494 32bit zero extended */
11495+
11496+#ifdef CONFIG_PAX_MEMORY_UDEREF
11497+ mov $PAX_USER_SHADOW_BASE,%r11
11498+ add %r11,%rbp
11499+#endif
11500+
11501 ASM_STAC
11502 1: movl (%rbp),%ebp
11503 _ASM_EXTABLE(1b,ia32_badarg)
11504 ASM_CLAC
11505- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11506- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11507+ GET_THREAD_INFO(%r11)
11508+ orl $TS_COMPAT,TI_status(%r11)
11509+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11510 CFI_REMEMBER_STATE
11511 jnz sysenter_tracesys
11512 cmpq $(IA32_NR_syscalls-1),%rax
11513@@ -162,12 +204,15 @@ sysenter_do_call:
11514 sysenter_dispatch:
11515 call *ia32_sys_call_table(,%rax,8)
11516 movq %rax,RAX-ARGOFFSET(%rsp)
11517+ GET_THREAD_INFO(%r11)
11518 DISABLE_INTERRUPTS(CLBR_NONE)
11519 TRACE_IRQS_OFF
11520- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11521+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11522 jnz sysexit_audit
11523 sysexit_from_sys_call:
11524- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11525+ pax_exit_kernel_user
11526+ pax_erase_kstack
11527+ andl $~TS_COMPAT,TI_status(%r11)
11528 /* clear IF, that popfq doesn't enable interrupts early */
11529 andl $~0x200,EFLAGS-R11(%rsp)
11530 movl RIP-R11(%rsp),%edx /* User %eip */
11531@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11532 movl %eax,%esi /* 2nd arg: syscall number */
11533 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11534 call __audit_syscall_entry
11535+
11536+ pax_erase_kstack
11537+
11538 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11539 cmpq $(IA32_NR_syscalls-1),%rax
11540 ja ia32_badsys
11541@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11542 .endm
11543
11544 .macro auditsys_exit exit
11545- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11546+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11547 jnz ia32_ret_from_sys_call
11548 TRACE_IRQS_ON
11549 ENABLE_INTERRUPTS(CLBR_NONE)
11550@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11551 1: setbe %al /* 1 if error, 0 if not */
11552 movzbl %al,%edi /* zero-extend that into %edi */
11553 call __audit_syscall_exit
11554+ GET_THREAD_INFO(%r11)
11555 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11556 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11557 DISABLE_INTERRUPTS(CLBR_NONE)
11558 TRACE_IRQS_OFF
11559- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11560+ testl %edi,TI_flags(%r11)
11561 jz \exit
11562 CLEAR_RREGS -ARGOFFSET
11563 jmp int_with_check
11564@@ -237,7 +286,7 @@ sysexit_audit:
11565
11566 sysenter_tracesys:
11567 #ifdef CONFIG_AUDITSYSCALL
11568- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11569+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11570 jz sysenter_auditsys
11571 #endif
11572 SAVE_REST
11573@@ -249,6 +298,9 @@ sysenter_tracesys:
11574 RESTORE_REST
11575 cmpq $(IA32_NR_syscalls-1),%rax
11576 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11577+
11578+ pax_erase_kstack
11579+
11580 jmp sysenter_do_call
11581 CFI_ENDPROC
11582 ENDPROC(ia32_sysenter_target)
11583@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11584 ENTRY(ia32_cstar_target)
11585 CFI_STARTPROC32 simple
11586 CFI_SIGNAL_FRAME
11587- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11588+ CFI_DEF_CFA rsp,0
11589 CFI_REGISTER rip,rcx
11590 /*CFI_REGISTER rflags,r11*/
11591 SWAPGS_UNSAFE_STACK
11592 movl %esp,%r8d
11593 CFI_REGISTER rsp,r8
11594 movq PER_CPU_VAR(kernel_stack),%rsp
11595+ SAVE_ARGS 8*6,0,0
11596+ pax_enter_kernel_user
11597+
11598+#ifdef CONFIG_PAX_RANDKSTACK
11599+ pax_erase_kstack
11600+#endif
11601+
11602 /*
11603 * No need to follow this irqs on/off section: the syscall
11604 * disabled irqs and here we enable it straight after entry:
11605 */
11606 ENABLE_INTERRUPTS(CLBR_NONE)
11607- SAVE_ARGS 8,0,0
11608 movl %eax,%eax /* zero extension */
11609 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11610 movq %rcx,RIP-ARGOFFSET(%rsp)
11611@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11612 /* no need to do an access_ok check here because r8 has been
11613 32bit zero extended */
11614 /* hardware stack frame is complete now */
11615+
11616+#ifdef CONFIG_PAX_MEMORY_UDEREF
11617+ mov $PAX_USER_SHADOW_BASE,%r11
11618+ add %r11,%r8
11619+#endif
11620+
11621 ASM_STAC
11622 1: movl (%r8),%r9d
11623 _ASM_EXTABLE(1b,ia32_badarg)
11624 ASM_CLAC
11625- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11626- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11627+ GET_THREAD_INFO(%r11)
11628+ orl $TS_COMPAT,TI_status(%r11)
11629+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11630 CFI_REMEMBER_STATE
11631 jnz cstar_tracesys
11632 cmpq $IA32_NR_syscalls-1,%rax
11633@@ -319,12 +384,15 @@ cstar_do_call:
11634 cstar_dispatch:
11635 call *ia32_sys_call_table(,%rax,8)
11636 movq %rax,RAX-ARGOFFSET(%rsp)
11637+ GET_THREAD_INFO(%r11)
11638 DISABLE_INTERRUPTS(CLBR_NONE)
11639 TRACE_IRQS_OFF
11640- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11641+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11642 jnz sysretl_audit
11643 sysretl_from_sys_call:
11644- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11645+ pax_exit_kernel_user
11646+ pax_erase_kstack
11647+ andl $~TS_COMPAT,TI_status(%r11)
11648 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11649 movl RIP-ARGOFFSET(%rsp),%ecx
11650 CFI_REGISTER rip,rcx
11651@@ -352,7 +420,7 @@ sysretl_audit:
11652
11653 cstar_tracesys:
11654 #ifdef CONFIG_AUDITSYSCALL
11655- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11656+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11657 jz cstar_auditsys
11658 #endif
11659 xchgl %r9d,%ebp
11660@@ -366,6 +434,9 @@ cstar_tracesys:
11661 xchgl %ebp,%r9d
11662 cmpq $(IA32_NR_syscalls-1),%rax
11663 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11664+
11665+ pax_erase_kstack
11666+
11667 jmp cstar_do_call
11668 END(ia32_cstar_target)
11669
11670@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11671 CFI_REL_OFFSET rip,RIP-RIP
11672 PARAVIRT_ADJUST_EXCEPTION_FRAME
11673 SWAPGS
11674- /*
11675- * No need to follow this irqs on/off section: the syscall
11676- * disabled irqs and here we enable it straight after entry:
11677- */
11678- ENABLE_INTERRUPTS(CLBR_NONE)
11679 movl %eax,%eax
11680 pushq_cfi %rax
11681 cld
11682 /* note the registers are not zero extended to the sf.
11683 this could be a problem. */
11684 SAVE_ARGS 0,1,0
11685- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11686- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11687+ pax_enter_kernel_user
11688+
11689+#ifdef CONFIG_PAX_RANDKSTACK
11690+ pax_erase_kstack
11691+#endif
11692+
11693+ /*
11694+ * No need to follow this irqs on/off section: the syscall
11695+ * disabled irqs and here we enable it straight after entry:
11696+ */
11697+ ENABLE_INTERRUPTS(CLBR_NONE)
11698+ GET_THREAD_INFO(%r11)
11699+ orl $TS_COMPAT,TI_status(%r11)
11700+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11701 jnz ia32_tracesys
11702 cmpq $(IA32_NR_syscalls-1),%rax
11703 ja ia32_badsys
11704@@ -442,6 +520,9 @@ ia32_tracesys:
11705 RESTORE_REST
11706 cmpq $(IA32_NR_syscalls-1),%rax
11707 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11708+
11709+ pax_erase_kstack
11710+
11711 jmp ia32_do_call
11712 END(ia32_syscall)
11713
11714diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11715index d0b689b..34be51d 100644
11716--- a/arch/x86/ia32/sys_ia32.c
11717+++ b/arch/x86/ia32/sys_ia32.c
11718@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11719 */
11720 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11721 {
11722- typeof(ubuf->st_uid) uid = 0;
11723- typeof(ubuf->st_gid) gid = 0;
11724+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11725+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11726 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11727 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11728 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11729@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11730 mm_segment_t old_fs = get_fs();
11731
11732 set_fs(KERNEL_DS);
11733- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11734+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11735 set_fs(old_fs);
11736 if (put_compat_timespec(&t, interval))
11737 return -EFAULT;
11738@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11739 mm_segment_t old_fs = get_fs();
11740
11741 set_fs(KERNEL_DS);
11742- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11743+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11744 set_fs(old_fs);
11745 if (!ret) {
11746 switch (_NSIG_WORDS) {
11747@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11748 if (copy_siginfo_from_user32(&info, uinfo))
11749 return -EFAULT;
11750 set_fs(KERNEL_DS);
11751- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11752+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11753 set_fs(old_fs);
11754 return ret;
11755 }
11756@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11757 return -EFAULT;
11758
11759 set_fs(KERNEL_DS);
11760- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11761+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11762 count);
11763 set_fs(old_fs);
11764
11765diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11766index 372231c..a5aa1a1 100644
11767--- a/arch/x86/include/asm/alternative-asm.h
11768+++ b/arch/x86/include/asm/alternative-asm.h
11769@@ -18,6 +18,45 @@
11770 .endm
11771 #endif
11772
11773+#ifdef KERNEXEC_PLUGIN
11774+ .macro pax_force_retaddr_bts rip=0
11775+ btsq $63,\rip(%rsp)
11776+ .endm
11777+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11778+ .macro pax_force_retaddr rip=0, reload=0
11779+ btsq $63,\rip(%rsp)
11780+ .endm
11781+ .macro pax_force_fptr ptr
11782+ btsq $63,\ptr
11783+ .endm
11784+ .macro pax_set_fptr_mask
11785+ .endm
11786+#endif
11787+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11788+ .macro pax_force_retaddr rip=0, reload=0
11789+ .if \reload
11790+ pax_set_fptr_mask
11791+ .endif
11792+ orq %r10,\rip(%rsp)
11793+ .endm
11794+ .macro pax_force_fptr ptr
11795+ orq %r10,\ptr
11796+ .endm
11797+ .macro pax_set_fptr_mask
11798+ movabs $0x8000000000000000,%r10
11799+ .endm
11800+#endif
11801+#else
11802+ .macro pax_force_retaddr rip=0, reload=0
11803+ .endm
11804+ .macro pax_force_fptr ptr
11805+ .endm
11806+ .macro pax_force_retaddr_bts rip=0
11807+ .endm
11808+ .macro pax_set_fptr_mask
11809+ .endm
11810+#endif
11811+
11812 .macro altinstruction_entry orig alt feature orig_len alt_len
11813 .long \orig - .
11814 .long \alt - .
11815diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11816index 58ed6d9..f1cbe58 100644
11817--- a/arch/x86/include/asm/alternative.h
11818+++ b/arch/x86/include/asm/alternative.h
11819@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11820 ".pushsection .discard,\"aw\",@progbits\n" \
11821 DISCARD_ENTRY(1) \
11822 ".popsection\n" \
11823- ".pushsection .altinstr_replacement, \"ax\"\n" \
11824+ ".pushsection .altinstr_replacement, \"a\"\n" \
11825 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11826 ".popsection"
11827
11828@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11829 DISCARD_ENTRY(1) \
11830 DISCARD_ENTRY(2) \
11831 ".popsection\n" \
11832- ".pushsection .altinstr_replacement, \"ax\"\n" \
11833+ ".pushsection .altinstr_replacement, \"a\"\n" \
11834 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11835 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11836 ".popsection"
11837diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11838index 3388034..050f0b9 100644
11839--- a/arch/x86/include/asm/apic.h
11840+++ b/arch/x86/include/asm/apic.h
11841@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11842
11843 #ifdef CONFIG_X86_LOCAL_APIC
11844
11845-extern unsigned int apic_verbosity;
11846+extern int apic_verbosity;
11847 extern int local_apic_timer_c2_ok;
11848
11849 extern int disable_apic;
11850diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11851index 20370c6..a2eb9b0 100644
11852--- a/arch/x86/include/asm/apm.h
11853+++ b/arch/x86/include/asm/apm.h
11854@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11855 __asm__ __volatile__(APM_DO_ZERO_SEGS
11856 "pushl %%edi\n\t"
11857 "pushl %%ebp\n\t"
11858- "lcall *%%cs:apm_bios_entry\n\t"
11859+ "lcall *%%ss:apm_bios_entry\n\t"
11860 "setc %%al\n\t"
11861 "popl %%ebp\n\t"
11862 "popl %%edi\n\t"
11863@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_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 %%bl\n\t"
11870 "popl %%ebp\n\t"
11871 "popl %%edi\n\t"
11872diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11873index 722aa3b..3a0bb27 100644
11874--- a/arch/x86/include/asm/atomic.h
11875+++ b/arch/x86/include/asm/atomic.h
11876@@ -22,7 +22,18 @@
11877 */
11878 static inline int atomic_read(const atomic_t *v)
11879 {
11880- return (*(volatile int *)&(v)->counter);
11881+ return (*(volatile const int *)&(v)->counter);
11882+}
11883+
11884+/**
11885+ * atomic_read_unchecked - read atomic variable
11886+ * @v: pointer of type atomic_unchecked_t
11887+ *
11888+ * Atomically reads the value of @v.
11889+ */
11890+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11891+{
11892+ return (*(volatile const int *)&(v)->counter);
11893 }
11894
11895 /**
11896@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11897 }
11898
11899 /**
11900+ * atomic_set_unchecked - set atomic variable
11901+ * @v: pointer of type atomic_unchecked_t
11902+ * @i: required value
11903+ *
11904+ * Atomically sets the value of @v to @i.
11905+ */
11906+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11907+{
11908+ v->counter = i;
11909+}
11910+
11911+/**
11912 * atomic_add - add integer to atomic variable
11913 * @i: integer value to add
11914 * @v: pointer of type atomic_t
11915@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11916 */
11917 static inline void atomic_add(int i, atomic_t *v)
11918 {
11919- asm volatile(LOCK_PREFIX "addl %1,%0"
11920+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11921+
11922+#ifdef CONFIG_PAX_REFCOUNT
11923+ "jno 0f\n"
11924+ LOCK_PREFIX "subl %1,%0\n"
11925+ "int $4\n0:\n"
11926+ _ASM_EXTABLE(0b, 0b)
11927+#endif
11928+
11929+ : "+m" (v->counter)
11930+ : "ir" (i));
11931+}
11932+
11933+/**
11934+ * atomic_add_unchecked - add integer to atomic variable
11935+ * @i: integer value to add
11936+ * @v: pointer of type atomic_unchecked_t
11937+ *
11938+ * Atomically adds @i to @v.
11939+ */
11940+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11941+{
11942+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11943 : "+m" (v->counter)
11944 : "ir" (i));
11945 }
11946@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11947 */
11948 static inline void atomic_sub(int i, atomic_t *v)
11949 {
11950- asm volatile(LOCK_PREFIX "subl %1,%0"
11951+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11952+
11953+#ifdef CONFIG_PAX_REFCOUNT
11954+ "jno 0f\n"
11955+ LOCK_PREFIX "addl %1,%0\n"
11956+ "int $4\n0:\n"
11957+ _ASM_EXTABLE(0b, 0b)
11958+#endif
11959+
11960+ : "+m" (v->counter)
11961+ : "ir" (i));
11962+}
11963+
11964+/**
11965+ * atomic_sub_unchecked - subtract integer from atomic variable
11966+ * @i: integer value to subtract
11967+ * @v: pointer of type atomic_unchecked_t
11968+ *
11969+ * Atomically subtracts @i from @v.
11970+ */
11971+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11972+{
11973+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11974 : "+m" (v->counter)
11975 : "ir" (i));
11976 }
11977@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11978 {
11979 unsigned char c;
11980
11981- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11982+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
11983+
11984+#ifdef CONFIG_PAX_REFCOUNT
11985+ "jno 0f\n"
11986+ LOCK_PREFIX "addl %2,%0\n"
11987+ "int $4\n0:\n"
11988+ _ASM_EXTABLE(0b, 0b)
11989+#endif
11990+
11991+ "sete %1\n"
11992 : "+m" (v->counter), "=qm" (c)
11993 : "ir" (i) : "memory");
11994 return c;
11995@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11996 */
11997 static inline void atomic_inc(atomic_t *v)
11998 {
11999- asm volatile(LOCK_PREFIX "incl %0"
12000+ asm volatile(LOCK_PREFIX "incl %0\n"
12001+
12002+#ifdef CONFIG_PAX_REFCOUNT
12003+ "jno 0f\n"
12004+ LOCK_PREFIX "decl %0\n"
12005+ "int $4\n0:\n"
12006+ _ASM_EXTABLE(0b, 0b)
12007+#endif
12008+
12009+ : "+m" (v->counter));
12010+}
12011+
12012+/**
12013+ * atomic_inc_unchecked - increment atomic variable
12014+ * @v: pointer of type atomic_unchecked_t
12015+ *
12016+ * Atomically increments @v by 1.
12017+ */
12018+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12019+{
12020+ asm volatile(LOCK_PREFIX "incl %0\n"
12021 : "+m" (v->counter));
12022 }
12023
12024@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12025 */
12026 static inline void atomic_dec(atomic_t *v)
12027 {
12028- asm volatile(LOCK_PREFIX "decl %0"
12029+ asm volatile(LOCK_PREFIX "decl %0\n"
12030+
12031+#ifdef CONFIG_PAX_REFCOUNT
12032+ "jno 0f\n"
12033+ LOCK_PREFIX "incl %0\n"
12034+ "int $4\n0:\n"
12035+ _ASM_EXTABLE(0b, 0b)
12036+#endif
12037+
12038+ : "+m" (v->counter));
12039+}
12040+
12041+/**
12042+ * atomic_dec_unchecked - decrement atomic variable
12043+ * @v: pointer of type atomic_unchecked_t
12044+ *
12045+ * Atomically decrements @v by 1.
12046+ */
12047+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12048+{
12049+ asm volatile(LOCK_PREFIX "decl %0\n"
12050 : "+m" (v->counter));
12051 }
12052
12053@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12054 {
12055 unsigned char c;
12056
12057- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12058+ asm volatile(LOCK_PREFIX "decl %0\n"
12059+
12060+#ifdef CONFIG_PAX_REFCOUNT
12061+ "jno 0f\n"
12062+ LOCK_PREFIX "incl %0\n"
12063+ "int $4\n0:\n"
12064+ _ASM_EXTABLE(0b, 0b)
12065+#endif
12066+
12067+ "sete %1\n"
12068 : "+m" (v->counter), "=qm" (c)
12069 : : "memory");
12070 return c != 0;
12071@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12072 {
12073 unsigned char c;
12074
12075- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12076+ asm volatile(LOCK_PREFIX "incl %0\n"
12077+
12078+#ifdef CONFIG_PAX_REFCOUNT
12079+ "jno 0f\n"
12080+ LOCK_PREFIX "decl %0\n"
12081+ "int $4\n0:\n"
12082+ _ASM_EXTABLE(0b, 0b)
12083+#endif
12084+
12085+ "sete %1\n"
12086+ : "+m" (v->counter), "=qm" (c)
12087+ : : "memory");
12088+ return c != 0;
12089+}
12090+
12091+/**
12092+ * atomic_inc_and_test_unchecked - increment and test
12093+ * @v: pointer of type atomic_unchecked_t
12094+ *
12095+ * Atomically increments @v by 1
12096+ * and returns true if the result is zero, or false for all
12097+ * other cases.
12098+ */
12099+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12100+{
12101+ unsigned char c;
12102+
12103+ asm volatile(LOCK_PREFIX "incl %0\n"
12104+ "sete %1\n"
12105 : "+m" (v->counter), "=qm" (c)
12106 : : "memory");
12107 return c != 0;
12108@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12109 {
12110 unsigned char c;
12111
12112- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12113+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12114+
12115+#ifdef CONFIG_PAX_REFCOUNT
12116+ "jno 0f\n"
12117+ LOCK_PREFIX "subl %2,%0\n"
12118+ "int $4\n0:\n"
12119+ _ASM_EXTABLE(0b, 0b)
12120+#endif
12121+
12122+ "sets %1\n"
12123 : "+m" (v->counter), "=qm" (c)
12124 : "ir" (i) : "memory");
12125 return c;
12126@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12127 */
12128 static inline int atomic_add_return(int i, atomic_t *v)
12129 {
12130+ return i + xadd_check_overflow(&v->counter, i);
12131+}
12132+
12133+/**
12134+ * atomic_add_return_unchecked - add integer and return
12135+ * @i: integer value to add
12136+ * @v: pointer of type atomic_unchecked_t
12137+ *
12138+ * Atomically adds @i to @v and returns @i + @v
12139+ */
12140+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12141+{
12142 return i + xadd(&v->counter, i);
12143 }
12144
12145@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12146 }
12147
12148 #define atomic_inc_return(v) (atomic_add_return(1, v))
12149+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12150+{
12151+ return atomic_add_return_unchecked(1, v);
12152+}
12153 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12154
12155 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12156@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12157 return cmpxchg(&v->counter, old, new);
12158 }
12159
12160+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12161+{
12162+ return cmpxchg(&v->counter, old, new);
12163+}
12164+
12165 static inline int atomic_xchg(atomic_t *v, int new)
12166 {
12167 return xchg(&v->counter, new);
12168 }
12169
12170+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12171+{
12172+ return xchg(&v->counter, new);
12173+}
12174+
12175 /**
12176 * __atomic_add_unless - add unless the number is already a given value
12177 * @v: pointer of type atomic_t
12178@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12179 */
12180 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12181 {
12182- int c, old;
12183+ int c, old, new;
12184 c = atomic_read(v);
12185 for (;;) {
12186- if (unlikely(c == (u)))
12187+ if (unlikely(c == u))
12188 break;
12189- old = atomic_cmpxchg((v), c, c + (a));
12190+
12191+ asm volatile("addl %2,%0\n"
12192+
12193+#ifdef CONFIG_PAX_REFCOUNT
12194+ "jno 0f\n"
12195+ "subl %2,%0\n"
12196+ "int $4\n0:\n"
12197+ _ASM_EXTABLE(0b, 0b)
12198+#endif
12199+
12200+ : "=r" (new)
12201+ : "0" (c), "ir" (a));
12202+
12203+ old = atomic_cmpxchg(v, c, new);
12204 if (likely(old == c))
12205 break;
12206 c = old;
12207@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12208 }
12209
12210 /**
12211+ * atomic_inc_not_zero_hint - increment if not null
12212+ * @v: pointer of type atomic_t
12213+ * @hint: probable value of the atomic before the increment
12214+ *
12215+ * This version of atomic_inc_not_zero() gives a hint of probable
12216+ * value of the atomic. This helps processor to not read the memory
12217+ * before doing the atomic read/modify/write cycle, lowering
12218+ * number of bus transactions on some arches.
12219+ *
12220+ * Returns: 0 if increment was not done, 1 otherwise.
12221+ */
12222+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12223+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12224+{
12225+ int val, c = hint, new;
12226+
12227+ /* sanity test, should be removed by compiler if hint is a constant */
12228+ if (!hint)
12229+ return __atomic_add_unless(v, 1, 0);
12230+
12231+ do {
12232+ asm volatile("incl %0\n"
12233+
12234+#ifdef CONFIG_PAX_REFCOUNT
12235+ "jno 0f\n"
12236+ "decl %0\n"
12237+ "int $4\n0:\n"
12238+ _ASM_EXTABLE(0b, 0b)
12239+#endif
12240+
12241+ : "=r" (new)
12242+ : "0" (c));
12243+
12244+ val = atomic_cmpxchg(v, c, new);
12245+ if (val == c)
12246+ return 1;
12247+ c = val;
12248+ } while (c);
12249+
12250+ return 0;
12251+}
12252+
12253+/**
12254 * atomic_inc_short - increment of a short integer
12255 * @v: pointer to type int
12256 *
12257@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12258 #endif
12259
12260 /* These are x86-specific, used by some header files */
12261-#define atomic_clear_mask(mask, addr) \
12262- asm volatile(LOCK_PREFIX "andl %0,%1" \
12263- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12264+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12265+{
12266+ asm volatile(LOCK_PREFIX "andl %1,%0"
12267+ : "+m" (v->counter)
12268+ : "r" (~(mask))
12269+ : "memory");
12270+}
12271
12272-#define atomic_set_mask(mask, addr) \
12273- asm volatile(LOCK_PREFIX "orl %0,%1" \
12274- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12275- : "memory")
12276+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12277+{
12278+ asm volatile(LOCK_PREFIX "andl %1,%0"
12279+ : "+m" (v->counter)
12280+ : "r" (~(mask))
12281+ : "memory");
12282+}
12283+
12284+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12285+{
12286+ asm volatile(LOCK_PREFIX "orl %1,%0"
12287+ : "+m" (v->counter)
12288+ : "r" (mask)
12289+ : "memory");
12290+}
12291+
12292+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12293+{
12294+ asm volatile(LOCK_PREFIX "orl %1,%0"
12295+ : "+m" (v->counter)
12296+ : "r" (mask)
12297+ : "memory");
12298+}
12299
12300 /* Atomic operations are already serializing on x86 */
12301 #define smp_mb__before_atomic_dec() barrier()
12302diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12303index b154de7..aadebd8 100644
12304--- a/arch/x86/include/asm/atomic64_32.h
12305+++ b/arch/x86/include/asm/atomic64_32.h
12306@@ -12,6 +12,14 @@ typedef struct {
12307 u64 __aligned(8) counter;
12308 } atomic64_t;
12309
12310+#ifdef CONFIG_PAX_REFCOUNT
12311+typedef struct {
12312+ u64 __aligned(8) counter;
12313+} atomic64_unchecked_t;
12314+#else
12315+typedef atomic64_t atomic64_unchecked_t;
12316+#endif
12317+
12318 #define ATOMIC64_INIT(val) { (val) }
12319
12320 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12321@@ -37,21 +45,31 @@ typedef struct {
12322 ATOMIC64_DECL_ONE(sym##_386)
12323
12324 ATOMIC64_DECL_ONE(add_386);
12325+ATOMIC64_DECL_ONE(add_unchecked_386);
12326 ATOMIC64_DECL_ONE(sub_386);
12327+ATOMIC64_DECL_ONE(sub_unchecked_386);
12328 ATOMIC64_DECL_ONE(inc_386);
12329+ATOMIC64_DECL_ONE(inc_unchecked_386);
12330 ATOMIC64_DECL_ONE(dec_386);
12331+ATOMIC64_DECL_ONE(dec_unchecked_386);
12332 #endif
12333
12334 #define alternative_atomic64(f, out, in...) \
12335 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12336
12337 ATOMIC64_DECL(read);
12338+ATOMIC64_DECL(read_unchecked);
12339 ATOMIC64_DECL(set);
12340+ATOMIC64_DECL(set_unchecked);
12341 ATOMIC64_DECL(xchg);
12342 ATOMIC64_DECL(add_return);
12343+ATOMIC64_DECL(add_return_unchecked);
12344 ATOMIC64_DECL(sub_return);
12345+ATOMIC64_DECL(sub_return_unchecked);
12346 ATOMIC64_DECL(inc_return);
12347+ATOMIC64_DECL(inc_return_unchecked);
12348 ATOMIC64_DECL(dec_return);
12349+ATOMIC64_DECL(dec_return_unchecked);
12350 ATOMIC64_DECL(dec_if_positive);
12351 ATOMIC64_DECL(inc_not_zero);
12352 ATOMIC64_DECL(add_unless);
12353@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12354 }
12355
12356 /**
12357+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12358+ * @p: pointer to type atomic64_unchecked_t
12359+ * @o: expected value
12360+ * @n: new value
12361+ *
12362+ * Atomically sets @v to @n if it was equal to @o and returns
12363+ * the old value.
12364+ */
12365+
12366+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12367+{
12368+ return cmpxchg64(&v->counter, o, n);
12369+}
12370+
12371+/**
12372 * atomic64_xchg - xchg atomic64 variable
12373 * @v: pointer to type atomic64_t
12374 * @n: value to assign
12375@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12376 }
12377
12378 /**
12379+ * atomic64_set_unchecked - set atomic64 variable
12380+ * @v: pointer to type atomic64_unchecked_t
12381+ * @n: value to assign
12382+ *
12383+ * Atomically sets the value of @v to @n.
12384+ */
12385+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12386+{
12387+ unsigned high = (unsigned)(i >> 32);
12388+ unsigned low = (unsigned)i;
12389+ alternative_atomic64(set, /* no output */,
12390+ "S" (v), "b" (low), "c" (high)
12391+ : "eax", "edx", "memory");
12392+}
12393+
12394+/**
12395 * atomic64_read - read atomic64 variable
12396 * @v: pointer to type atomic64_t
12397 *
12398@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12399 }
12400
12401 /**
12402+ * atomic64_read_unchecked - read atomic64 variable
12403+ * @v: pointer to type atomic64_unchecked_t
12404+ *
12405+ * Atomically reads the value of @v and returns it.
12406+ */
12407+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12408+{
12409+ long long r;
12410+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12411+ return r;
12412+ }
12413+
12414+/**
12415 * atomic64_add_return - add and return
12416 * @i: integer value to add
12417 * @v: pointer to type atomic64_t
12418@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12419 return i;
12420 }
12421
12422+/**
12423+ * atomic64_add_return_unchecked - add and return
12424+ * @i: integer value to add
12425+ * @v: pointer to type atomic64_unchecked_t
12426+ *
12427+ * Atomically adds @i to @v and returns @i + *@v
12428+ */
12429+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12430+{
12431+ alternative_atomic64(add_return_unchecked,
12432+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12433+ ASM_NO_INPUT_CLOBBER("memory"));
12434+ return i;
12435+}
12436+
12437 /*
12438 * Other variants with different arithmetic operators:
12439 */
12440@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12441 return a;
12442 }
12443
12444+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12445+{
12446+ long long a;
12447+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12448+ "S" (v) : "memory", "ecx");
12449+ return a;
12450+}
12451+
12452 static inline long long atomic64_dec_return(atomic64_t *v)
12453 {
12454 long long a;
12455@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12456 }
12457
12458 /**
12459+ * atomic64_add_unchecked - add integer to atomic64 variable
12460+ * @i: integer value to add
12461+ * @v: pointer to type atomic64_unchecked_t
12462+ *
12463+ * Atomically adds @i to @v.
12464+ */
12465+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12466+{
12467+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12468+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12469+ ASM_NO_INPUT_CLOBBER("memory"));
12470+ return i;
12471+}
12472+
12473+/**
12474 * atomic64_sub - subtract the atomic64 variable
12475 * @i: integer value to subtract
12476 * @v: pointer to type atomic64_t
12477diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12478index 0e1cbfc..5623683 100644
12479--- a/arch/x86/include/asm/atomic64_64.h
12480+++ b/arch/x86/include/asm/atomic64_64.h
12481@@ -18,7 +18,19 @@
12482 */
12483 static inline long atomic64_read(const atomic64_t *v)
12484 {
12485- return (*(volatile long *)&(v)->counter);
12486+ return (*(volatile const long *)&(v)->counter);
12487+}
12488+
12489+/**
12490+ * atomic64_read_unchecked - read atomic64 variable
12491+ * @v: pointer of type atomic64_unchecked_t
12492+ *
12493+ * Atomically reads the value of @v.
12494+ * Doesn't imply a read memory barrier.
12495+ */
12496+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12497+{
12498+ return (*(volatile const long *)&(v)->counter);
12499 }
12500
12501 /**
12502@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12503 }
12504
12505 /**
12506+ * atomic64_set_unchecked - set atomic64 variable
12507+ * @v: pointer to type atomic64_unchecked_t
12508+ * @i: required value
12509+ *
12510+ * Atomically sets the value of @v to @i.
12511+ */
12512+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12513+{
12514+ v->counter = i;
12515+}
12516+
12517+/**
12518 * atomic64_add - add integer to atomic64 variable
12519 * @i: integer value to add
12520 * @v: pointer to type atomic64_t
12521@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12522 */
12523 static inline void atomic64_add(long i, atomic64_t *v)
12524 {
12525+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12526+
12527+#ifdef CONFIG_PAX_REFCOUNT
12528+ "jno 0f\n"
12529+ LOCK_PREFIX "subq %1,%0\n"
12530+ "int $4\n0:\n"
12531+ _ASM_EXTABLE(0b, 0b)
12532+#endif
12533+
12534+ : "=m" (v->counter)
12535+ : "er" (i), "m" (v->counter));
12536+}
12537+
12538+/**
12539+ * atomic64_add_unchecked - add integer to atomic64 variable
12540+ * @i: integer value to add
12541+ * @v: pointer to type atomic64_unchecked_t
12542+ *
12543+ * Atomically adds @i to @v.
12544+ */
12545+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12546+{
12547 asm volatile(LOCK_PREFIX "addq %1,%0"
12548 : "=m" (v->counter)
12549 : "er" (i), "m" (v->counter));
12550@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12551 */
12552 static inline void atomic64_sub(long i, atomic64_t *v)
12553 {
12554- asm volatile(LOCK_PREFIX "subq %1,%0"
12555+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12556+
12557+#ifdef CONFIG_PAX_REFCOUNT
12558+ "jno 0f\n"
12559+ LOCK_PREFIX "addq %1,%0\n"
12560+ "int $4\n0:\n"
12561+ _ASM_EXTABLE(0b, 0b)
12562+#endif
12563+
12564+ : "=m" (v->counter)
12565+ : "er" (i), "m" (v->counter));
12566+}
12567+
12568+/**
12569+ * atomic64_sub_unchecked - subtract the atomic64 variable
12570+ * @i: integer value to subtract
12571+ * @v: pointer to type atomic64_unchecked_t
12572+ *
12573+ * Atomically subtracts @i from @v.
12574+ */
12575+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12576+{
12577+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12578 : "=m" (v->counter)
12579 : "er" (i), "m" (v->counter));
12580 }
12581@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12582 {
12583 unsigned char c;
12584
12585- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12586+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12587+
12588+#ifdef CONFIG_PAX_REFCOUNT
12589+ "jno 0f\n"
12590+ LOCK_PREFIX "addq %2,%0\n"
12591+ "int $4\n0:\n"
12592+ _ASM_EXTABLE(0b, 0b)
12593+#endif
12594+
12595+ "sete %1\n"
12596 : "=m" (v->counter), "=qm" (c)
12597 : "er" (i), "m" (v->counter) : "memory");
12598 return c;
12599@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12600 */
12601 static inline void atomic64_inc(atomic64_t *v)
12602 {
12603+ asm volatile(LOCK_PREFIX "incq %0\n"
12604+
12605+#ifdef CONFIG_PAX_REFCOUNT
12606+ "jno 0f\n"
12607+ LOCK_PREFIX "decq %0\n"
12608+ "int $4\n0:\n"
12609+ _ASM_EXTABLE(0b, 0b)
12610+#endif
12611+
12612+ : "=m" (v->counter)
12613+ : "m" (v->counter));
12614+}
12615+
12616+/**
12617+ * atomic64_inc_unchecked - increment atomic64 variable
12618+ * @v: pointer to type atomic64_unchecked_t
12619+ *
12620+ * Atomically increments @v by 1.
12621+ */
12622+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12623+{
12624 asm volatile(LOCK_PREFIX "incq %0"
12625 : "=m" (v->counter)
12626 : "m" (v->counter));
12627@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12628 */
12629 static inline void atomic64_dec(atomic64_t *v)
12630 {
12631- asm volatile(LOCK_PREFIX "decq %0"
12632+ asm volatile(LOCK_PREFIX "decq %0\n"
12633+
12634+#ifdef CONFIG_PAX_REFCOUNT
12635+ "jno 0f\n"
12636+ LOCK_PREFIX "incq %0\n"
12637+ "int $4\n0:\n"
12638+ _ASM_EXTABLE(0b, 0b)
12639+#endif
12640+
12641+ : "=m" (v->counter)
12642+ : "m" (v->counter));
12643+}
12644+
12645+/**
12646+ * atomic64_dec_unchecked - decrement atomic64 variable
12647+ * @v: pointer to type atomic64_t
12648+ *
12649+ * Atomically decrements @v by 1.
12650+ */
12651+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12652+{
12653+ asm volatile(LOCK_PREFIX "decq %0\n"
12654 : "=m" (v->counter)
12655 : "m" (v->counter));
12656 }
12657@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12658 {
12659 unsigned char c;
12660
12661- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12662+ asm volatile(LOCK_PREFIX "decq %0\n"
12663+
12664+#ifdef CONFIG_PAX_REFCOUNT
12665+ "jno 0f\n"
12666+ LOCK_PREFIX "incq %0\n"
12667+ "int $4\n0:\n"
12668+ _ASM_EXTABLE(0b, 0b)
12669+#endif
12670+
12671+ "sete %1\n"
12672 : "=m" (v->counter), "=qm" (c)
12673 : "m" (v->counter) : "memory");
12674 return c != 0;
12675@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12676 {
12677 unsigned char c;
12678
12679- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12680+ asm volatile(LOCK_PREFIX "incq %0\n"
12681+
12682+#ifdef CONFIG_PAX_REFCOUNT
12683+ "jno 0f\n"
12684+ LOCK_PREFIX "decq %0\n"
12685+ "int $4\n0:\n"
12686+ _ASM_EXTABLE(0b, 0b)
12687+#endif
12688+
12689+ "sete %1\n"
12690 : "=m" (v->counter), "=qm" (c)
12691 : "m" (v->counter) : "memory");
12692 return c != 0;
12693@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12694 {
12695 unsigned char c;
12696
12697- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12698+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12699+
12700+#ifdef CONFIG_PAX_REFCOUNT
12701+ "jno 0f\n"
12702+ LOCK_PREFIX "subq %2,%0\n"
12703+ "int $4\n0:\n"
12704+ _ASM_EXTABLE(0b, 0b)
12705+#endif
12706+
12707+ "sets %1\n"
12708 : "=m" (v->counter), "=qm" (c)
12709 : "er" (i), "m" (v->counter) : "memory");
12710 return c;
12711@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12712 */
12713 static inline long atomic64_add_return(long i, atomic64_t *v)
12714 {
12715+ return i + xadd_check_overflow(&v->counter, i);
12716+}
12717+
12718+/**
12719+ * atomic64_add_return_unchecked - add and return
12720+ * @i: integer value to add
12721+ * @v: pointer to type atomic64_unchecked_t
12722+ *
12723+ * Atomically adds @i to @v and returns @i + @v
12724+ */
12725+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12726+{
12727 return i + xadd(&v->counter, i);
12728 }
12729
12730@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12731 }
12732
12733 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12734+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12735+{
12736+ return atomic64_add_return_unchecked(1, v);
12737+}
12738 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12739
12740 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12741@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12742 return cmpxchg(&v->counter, old, new);
12743 }
12744
12745+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12746+{
12747+ return cmpxchg(&v->counter, old, new);
12748+}
12749+
12750 static inline long atomic64_xchg(atomic64_t *v, long new)
12751 {
12752 return xchg(&v->counter, new);
12753@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12754 */
12755 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12756 {
12757- long c, old;
12758+ long c, old, new;
12759 c = atomic64_read(v);
12760 for (;;) {
12761- if (unlikely(c == (u)))
12762+ if (unlikely(c == u))
12763 break;
12764- old = atomic64_cmpxchg((v), c, c + (a));
12765+
12766+ asm volatile("add %2,%0\n"
12767+
12768+#ifdef CONFIG_PAX_REFCOUNT
12769+ "jno 0f\n"
12770+ "sub %2,%0\n"
12771+ "int $4\n0:\n"
12772+ _ASM_EXTABLE(0b, 0b)
12773+#endif
12774+
12775+ : "=r" (new)
12776+ : "0" (c), "ir" (a));
12777+
12778+ old = atomic64_cmpxchg(v, c, new);
12779 if (likely(old == c))
12780 break;
12781 c = old;
12782 }
12783- return c != (u);
12784+ return c != u;
12785 }
12786
12787 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12788diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12789index 6dfd019..28e188d 100644
12790--- a/arch/x86/include/asm/bitops.h
12791+++ b/arch/x86/include/asm/bitops.h
12792@@ -40,7 +40,7 @@
12793 * a mask operation on a byte.
12794 */
12795 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12796-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12797+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12798 #define CONST_MASK(nr) (1 << ((nr) & 7))
12799
12800 /**
12801@@ -486,7 +486,7 @@ static inline int fls(int x)
12802 * at position 64.
12803 */
12804 #ifdef CONFIG_X86_64
12805-static __always_inline int fls64(__u64 x)
12806+static __always_inline long fls64(__u64 x)
12807 {
12808 int bitpos = -1;
12809 /*
12810diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12811index 4fa687a..60f2d39 100644
12812--- a/arch/x86/include/asm/boot.h
12813+++ b/arch/x86/include/asm/boot.h
12814@@ -6,10 +6,15 @@
12815 #include <uapi/asm/boot.h>
12816
12817 /* Physical address where kernel should be loaded. */
12818-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12819+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12820 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12821 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12822
12823+#ifndef __ASSEMBLY__
12824+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12825+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12826+#endif
12827+
12828 /* Minimum kernel alignment, as a power of two */
12829 #ifdef CONFIG_X86_64
12830 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12831diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12832index 48f99f1..d78ebf9 100644
12833--- a/arch/x86/include/asm/cache.h
12834+++ b/arch/x86/include/asm/cache.h
12835@@ -5,12 +5,13 @@
12836
12837 /* L1 cache line size */
12838 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12839-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12840+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12841
12842 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12843+#define __read_only __attribute__((__section__(".data..read_only")))
12844
12845 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12846-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12847+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12848
12849 #ifdef CONFIG_X86_VSMP
12850 #ifdef CONFIG_SMP
12851diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12852index 9863ee3..4a1f8e1 100644
12853--- a/arch/x86/include/asm/cacheflush.h
12854+++ b/arch/x86/include/asm/cacheflush.h
12855@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12856 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12857
12858 if (pg_flags == _PGMT_DEFAULT)
12859- return -1;
12860+ return ~0UL;
12861 else if (pg_flags == _PGMT_WC)
12862 return _PAGE_CACHE_WC;
12863 else if (pg_flags == _PGMT_UC_MINUS)
12864diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12865index 46fc474..b02b0f9 100644
12866--- a/arch/x86/include/asm/checksum_32.h
12867+++ b/arch/x86/include/asm/checksum_32.h
12868@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12869 int len, __wsum sum,
12870 int *src_err_ptr, int *dst_err_ptr);
12871
12872+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12873+ int len, __wsum sum,
12874+ int *src_err_ptr, int *dst_err_ptr);
12875+
12876+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12877+ int len, __wsum sum,
12878+ int *src_err_ptr, int *dst_err_ptr);
12879+
12880 /*
12881 * Note: when you get a NULL pointer exception here this means someone
12882 * passed in an incorrect kernel address to one of these functions.
12883@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12884 int *err_ptr)
12885 {
12886 might_sleep();
12887- return csum_partial_copy_generic((__force void *)src, dst,
12888+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12889 len, sum, err_ptr, NULL);
12890 }
12891
12892@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12893 {
12894 might_sleep();
12895 if (access_ok(VERIFY_WRITE, dst, len))
12896- return csum_partial_copy_generic(src, (__force void *)dst,
12897+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12898 len, sum, NULL, err_ptr);
12899
12900 if (len)
12901diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12902index 8d871ea..c1a0dc9 100644
12903--- a/arch/x86/include/asm/cmpxchg.h
12904+++ b/arch/x86/include/asm/cmpxchg.h
12905@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12906 __compiletime_error("Bad argument size for cmpxchg");
12907 extern void __xadd_wrong_size(void)
12908 __compiletime_error("Bad argument size for xadd");
12909+extern void __xadd_check_overflow_wrong_size(void)
12910+ __compiletime_error("Bad argument size for xadd_check_overflow");
12911 extern void __add_wrong_size(void)
12912 __compiletime_error("Bad argument size for add");
12913+extern void __add_check_overflow_wrong_size(void)
12914+ __compiletime_error("Bad argument size for add_check_overflow");
12915
12916 /*
12917 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12918@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12919 __ret; \
12920 })
12921
12922+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12923+ ({ \
12924+ __typeof__ (*(ptr)) __ret = (arg); \
12925+ switch (sizeof(*(ptr))) { \
12926+ case __X86_CASE_L: \
12927+ asm volatile (lock #op "l %0, %1\n" \
12928+ "jno 0f\n" \
12929+ "mov %0,%1\n" \
12930+ "int $4\n0:\n" \
12931+ _ASM_EXTABLE(0b, 0b) \
12932+ : "+r" (__ret), "+m" (*(ptr)) \
12933+ : : "memory", "cc"); \
12934+ break; \
12935+ case __X86_CASE_Q: \
12936+ asm volatile (lock #op "q %q0, %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+ default: \
12945+ __ ## op ## _check_overflow_wrong_size(); \
12946+ } \
12947+ __ret; \
12948+ })
12949+
12950 /*
12951 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12952 * Since this is generally used to protect other memory information, we
12953@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12954 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12955 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12956
12957+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12958+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12959+
12960 #define __add(ptr, inc, lock) \
12961 ({ \
12962 __typeof__ (*(ptr)) __ret = (inc); \
12963diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12964index 2d9075e..b75a844 100644
12965--- a/arch/x86/include/asm/cpufeature.h
12966+++ b/arch/x86/include/asm/cpufeature.h
12967@@ -206,7 +206,7 @@
12968 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12969 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12970 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12971-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12972+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12973 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12974 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12975 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12976@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12977 ".section .discard,\"aw\",@progbits\n"
12978 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12979 ".previous\n"
12980- ".section .altinstr_replacement,\"ax\"\n"
12981+ ".section .altinstr_replacement,\"a\"\n"
12982 "3: movb $1,%0\n"
12983 "4:\n"
12984 ".previous\n"
12985diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12986index 8bf1c06..b6ae785 100644
12987--- a/arch/x86/include/asm/desc.h
12988+++ b/arch/x86/include/asm/desc.h
12989@@ -4,6 +4,7 @@
12990 #include <asm/desc_defs.h>
12991 #include <asm/ldt.h>
12992 #include <asm/mmu.h>
12993+#include <asm/pgtable.h>
12994
12995 #include <linux/smp.h>
12996 #include <linux/percpu.h>
12997@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12998
12999 desc->type = (info->read_exec_only ^ 1) << 1;
13000 desc->type |= info->contents << 2;
13001+ desc->type |= info->seg_not_present ^ 1;
13002
13003 desc->s = 1;
13004 desc->dpl = 0x3;
13005@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13006 }
13007
13008 extern struct desc_ptr idt_descr;
13009-extern gate_desc idt_table[];
13010 extern struct desc_ptr nmi_idt_descr;
13011-extern gate_desc nmi_idt_table[];
13012-
13013-struct gdt_page {
13014- struct desc_struct gdt[GDT_ENTRIES];
13015-} __attribute__((aligned(PAGE_SIZE)));
13016-
13017-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13018+extern gate_desc idt_table[256];
13019+extern gate_desc nmi_idt_table[256];
13020
13021+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13022 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13023 {
13024- return per_cpu(gdt_page, cpu).gdt;
13025+ return cpu_gdt_table[cpu];
13026 }
13027
13028 #ifdef CONFIG_X86_64
13029@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13030 unsigned long base, unsigned dpl, unsigned flags,
13031 unsigned short seg)
13032 {
13033- gate->a = (seg << 16) | (base & 0xffff);
13034- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13035+ gate->gate.offset_low = base;
13036+ gate->gate.seg = seg;
13037+ gate->gate.reserved = 0;
13038+ gate->gate.type = type;
13039+ gate->gate.s = 0;
13040+ gate->gate.dpl = dpl;
13041+ gate->gate.p = 1;
13042+ gate->gate.offset_high = base >> 16;
13043 }
13044
13045 #endif
13046@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13047
13048 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13049 {
13050+ pax_open_kernel();
13051 memcpy(&idt[entry], gate, sizeof(*gate));
13052+ pax_close_kernel();
13053 }
13054
13055 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13056 {
13057+ pax_open_kernel();
13058 memcpy(&ldt[entry], desc, 8);
13059+ pax_close_kernel();
13060 }
13061
13062 static inline void
13063@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13064 default: size = sizeof(*gdt); break;
13065 }
13066
13067+ pax_open_kernel();
13068 memcpy(&gdt[entry], desc, size);
13069+ pax_close_kernel();
13070 }
13071
13072 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13073@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13074
13075 static inline void native_load_tr_desc(void)
13076 {
13077+ pax_open_kernel();
13078 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13079+ pax_close_kernel();
13080 }
13081
13082 static inline void native_load_gdt(const struct desc_ptr *dtr)
13083@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13084 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13085 unsigned int i;
13086
13087+ pax_open_kernel();
13088 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13089 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13090+ pax_close_kernel();
13091 }
13092
13093 #define _LDT_empty(info) \
13094@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13095 preempt_enable();
13096 }
13097
13098-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13099+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13100 {
13101 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13102 }
13103@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13104 }
13105
13106 #ifdef CONFIG_X86_64
13107-static inline void set_nmi_gate(int gate, void *addr)
13108+static inline void set_nmi_gate(int gate, const void *addr)
13109 {
13110 gate_desc s;
13111
13112@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13113 }
13114 #endif
13115
13116-static inline void _set_gate(int gate, unsigned type, void *addr,
13117+static inline void _set_gate(int gate, unsigned type, const void *addr,
13118 unsigned dpl, unsigned ist, unsigned seg)
13119 {
13120 gate_desc s;
13121@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13122 * Pentium F0 0F bugfix can have resulted in the mapped
13123 * IDT being write-protected.
13124 */
13125-static inline void set_intr_gate(unsigned int n, void *addr)
13126+static inline void set_intr_gate(unsigned int n, const void *addr)
13127 {
13128 BUG_ON((unsigned)n > 0xFF);
13129 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13130@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13131 /*
13132 * This routine sets up an interrupt gate at directory privilege level 3.
13133 */
13134-static inline void set_system_intr_gate(unsigned int n, void *addr)
13135+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13136 {
13137 BUG_ON((unsigned)n > 0xFF);
13138 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13139 }
13140
13141-static inline void set_system_trap_gate(unsigned int n, void *addr)
13142+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13143 {
13144 BUG_ON((unsigned)n > 0xFF);
13145 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13146 }
13147
13148-static inline void set_trap_gate(unsigned int n, void *addr)
13149+static inline void set_trap_gate(unsigned int n, const void *addr)
13150 {
13151 BUG_ON((unsigned)n > 0xFF);
13152 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13153@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13154 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13155 {
13156 BUG_ON((unsigned)n > 0xFF);
13157- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13158+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13159 }
13160
13161-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13162+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13163 {
13164 BUG_ON((unsigned)n > 0xFF);
13165 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13166 }
13167
13168-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13169+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13170 {
13171 BUG_ON((unsigned)n > 0xFF);
13172 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13173 }
13174
13175+#ifdef CONFIG_X86_32
13176+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13177+{
13178+ struct desc_struct d;
13179+
13180+ if (likely(limit))
13181+ limit = (limit - 1UL) >> PAGE_SHIFT;
13182+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13183+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13184+}
13185+#endif
13186+
13187 #endif /* _ASM_X86_DESC_H */
13188diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13189index 278441f..b95a174 100644
13190--- a/arch/x86/include/asm/desc_defs.h
13191+++ b/arch/x86/include/asm/desc_defs.h
13192@@ -31,6 +31,12 @@ struct desc_struct {
13193 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13194 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13195 };
13196+ struct {
13197+ u16 offset_low;
13198+ u16 seg;
13199+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13200+ unsigned offset_high: 16;
13201+ } gate;
13202 };
13203 } __attribute__((packed));
13204
13205diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13206index ced283a..ffe04cc 100644
13207--- a/arch/x86/include/asm/div64.h
13208+++ b/arch/x86/include/asm/div64.h
13209@@ -39,7 +39,7 @@
13210 __mod; \
13211 })
13212
13213-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13214+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13215 {
13216 union {
13217 u64 v64;
13218diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13219index 9c999c1..3860cb8 100644
13220--- a/arch/x86/include/asm/elf.h
13221+++ b/arch/x86/include/asm/elf.h
13222@@ -243,7 +243,25 @@ extern int force_personality32;
13223 the loader. We need to make sure that it is out of the way of the program
13224 that it will "exec", and that there is sufficient room for the brk. */
13225
13226+#ifdef CONFIG_PAX_SEGMEXEC
13227+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13228+#else
13229 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13230+#endif
13231+
13232+#ifdef CONFIG_PAX_ASLR
13233+#ifdef CONFIG_X86_32
13234+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13235+
13236+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13237+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13238+#else
13239+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13240+
13241+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13242+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13243+#endif
13244+#endif
13245
13246 /* This yields a mask that user programs can use to figure out what
13247 instruction set this CPU supports. This could be done in user space,
13248@@ -296,16 +314,12 @@ do { \
13249
13250 #define ARCH_DLINFO \
13251 do { \
13252- if (vdso_enabled) \
13253- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13254- (unsigned long)current->mm->context.vdso); \
13255+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13256 } while (0)
13257
13258 #define ARCH_DLINFO_X32 \
13259 do { \
13260- if (vdso_enabled) \
13261- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13262- (unsigned long)current->mm->context.vdso); \
13263+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13264 } while (0)
13265
13266 #define AT_SYSINFO 32
13267@@ -320,7 +334,7 @@ else \
13268
13269 #endif /* !CONFIG_X86_32 */
13270
13271-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13272+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13273
13274 #define VDSO_ENTRY \
13275 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13276@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13277 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13278 #define compat_arch_setup_additional_pages syscall32_setup_pages
13279
13280-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13281-#define arch_randomize_brk arch_randomize_brk
13282-
13283 /*
13284 * True on X86_32 or when emulating IA32 on X86_64
13285 */
13286diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13287index 75ce3f4..882e801 100644
13288--- a/arch/x86/include/asm/emergency-restart.h
13289+++ b/arch/x86/include/asm/emergency-restart.h
13290@@ -13,6 +13,6 @@ enum reboot_type {
13291
13292 extern enum reboot_type reboot_type;
13293
13294-extern void machine_emergency_restart(void);
13295+extern void machine_emergency_restart(void) __noreturn;
13296
13297 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13298diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13299index 41ab26e..a88c9e6 100644
13300--- a/arch/x86/include/asm/fpu-internal.h
13301+++ b/arch/x86/include/asm/fpu-internal.h
13302@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13303 ({ \
13304 int err; \
13305 asm volatile(ASM_STAC "\n" \
13306- "1:" #insn "\n\t" \
13307+ "1:" \
13308+ __copyuser_seg \
13309+ #insn "\n\t" \
13310 "2: " ASM_CLAC "\n" \
13311 ".section .fixup,\"ax\"\n" \
13312 "3: movl $-1,%[err]\n" \
13313@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13314 "emms\n\t" /* clear stack tags */
13315 "fildl %P[addr]", /* set F?P to defined value */
13316 X86_FEATURE_FXSAVE_LEAK,
13317- [addr] "m" (tsk->thread.fpu.has_fpu));
13318+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13319
13320 return fpu_restore_checking(&tsk->thread.fpu);
13321 }
13322diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13323index be27ba1..8f13ff9 100644
13324--- a/arch/x86/include/asm/futex.h
13325+++ b/arch/x86/include/asm/futex.h
13326@@ -12,6 +12,7 @@
13327 #include <asm/smap.h>
13328
13329 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13330+ typecheck(u32 __user *, uaddr); \
13331 asm volatile("\t" ASM_STAC "\n" \
13332 "1:\t" insn "\n" \
13333 "2:\t" ASM_CLAC "\n" \
13334@@ -20,15 +21,16 @@
13335 "\tjmp\t2b\n" \
13336 "\t.previous\n" \
13337 _ASM_EXTABLE(1b, 3b) \
13338- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13339+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13340 : "i" (-EFAULT), "0" (oparg), "1" (0))
13341
13342 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13343+ typecheck(u32 __user *, uaddr); \
13344 asm volatile("\t" ASM_STAC "\n" \
13345 "1:\tmovl %2, %0\n" \
13346 "\tmovl\t%0, %3\n" \
13347 "\t" insn "\n" \
13348- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13349+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13350 "\tjnz\t1b\n" \
13351 "3:\t" ASM_CLAC "\n" \
13352 "\t.section .fixup,\"ax\"\n" \
13353@@ -38,7 +40,7 @@
13354 _ASM_EXTABLE(1b, 4b) \
13355 _ASM_EXTABLE(2b, 4b) \
13356 : "=&a" (oldval), "=&r" (ret), \
13357- "+m" (*uaddr), "=&r" (tem) \
13358+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13359 : "r" (oparg), "i" (-EFAULT), "1" (0))
13360
13361 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13362@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13363
13364 switch (op) {
13365 case FUTEX_OP_SET:
13366- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13367+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13368 break;
13369 case FUTEX_OP_ADD:
13370- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13371+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13372 uaddr, oparg);
13373 break;
13374 case FUTEX_OP_OR:
13375@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13376 return -EFAULT;
13377
13378 asm volatile("\t" ASM_STAC "\n"
13379- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13380+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13381 "2:\t" ASM_CLAC "\n"
13382 "\t.section .fixup, \"ax\"\n"
13383 "3:\tmov %3, %0\n"
13384 "\tjmp 2b\n"
13385 "\t.previous\n"
13386 _ASM_EXTABLE(1b, 3b)
13387- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13388+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13389 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13390 : "memory"
13391 );
13392diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13393index eb92a6e..b98b2f4 100644
13394--- a/arch/x86/include/asm/hw_irq.h
13395+++ b/arch/x86/include/asm/hw_irq.h
13396@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13397 extern void enable_IO_APIC(void);
13398
13399 /* Statistics */
13400-extern atomic_t irq_err_count;
13401-extern atomic_t irq_mis_count;
13402+extern atomic_unchecked_t irq_err_count;
13403+extern atomic_unchecked_t irq_mis_count;
13404
13405 /* EISA */
13406 extern void eisa_set_level_irq(unsigned int irq);
13407diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13408index a203659..9889f1c 100644
13409--- a/arch/x86/include/asm/i8259.h
13410+++ b/arch/x86/include/asm/i8259.h
13411@@ -62,7 +62,7 @@ struct legacy_pic {
13412 void (*init)(int auto_eoi);
13413 int (*irq_pending)(unsigned int irq);
13414 void (*make_irq)(unsigned int irq);
13415-};
13416+} __do_const;
13417
13418 extern struct legacy_pic *legacy_pic;
13419 extern struct legacy_pic null_legacy_pic;
13420diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13421index d8e8eef..1765f78 100644
13422--- a/arch/x86/include/asm/io.h
13423+++ b/arch/x86/include/asm/io.h
13424@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13425 "m" (*(volatile type __force *)addr) barrier); }
13426
13427 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13428-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13429-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13430+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13431+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13432
13433 build_mmio_read(__readb, "b", unsigned char, "=q", )
13434-build_mmio_read(__readw, "w", unsigned short, "=r", )
13435-build_mmio_read(__readl, "l", unsigned int, "=r", )
13436+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13437+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13438
13439 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13440 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13441@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13442 return ioremap_nocache(offset, size);
13443 }
13444
13445-extern void iounmap(volatile void __iomem *addr);
13446+extern void iounmap(const volatile void __iomem *addr);
13447
13448 extern void set_iounmap_nonlazy(void);
13449
13450@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13451
13452 #include <linux/vmalloc.h>
13453
13454+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13455+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13456+{
13457+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13458+}
13459+
13460+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13461+{
13462+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13463+}
13464+
13465 /*
13466 * Convert a virtual cached pointer to an uncached pointer
13467 */
13468diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13469index bba3cf8..06bc8da 100644
13470--- a/arch/x86/include/asm/irqflags.h
13471+++ b/arch/x86/include/asm/irqflags.h
13472@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13473 sti; \
13474 sysexit
13475
13476+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13477+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13478+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13479+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13480+
13481 #else
13482 #define INTERRUPT_RETURN iret
13483 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13484diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13485index d3ddd17..c9fb0cc 100644
13486--- a/arch/x86/include/asm/kprobes.h
13487+++ b/arch/x86/include/asm/kprobes.h
13488@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13489 #define RELATIVEJUMP_SIZE 5
13490 #define RELATIVECALL_OPCODE 0xe8
13491 #define RELATIVE_ADDR_SIZE 4
13492-#define MAX_STACK_SIZE 64
13493-#define MIN_STACK_SIZE(ADDR) \
13494- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13495- THREAD_SIZE - (unsigned long)(ADDR))) \
13496- ? (MAX_STACK_SIZE) \
13497- : (((unsigned long)current_thread_info()) + \
13498- THREAD_SIZE - (unsigned long)(ADDR)))
13499+#define MAX_STACK_SIZE 64UL
13500+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13501
13502 #define flush_insn_slot(p) do { } while (0)
13503
13504diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
13505index dc87b65..85039f9 100644
13506--- a/arch/x86/include/asm/kvm_host.h
13507+++ b/arch/x86/include/asm/kvm_host.h
13508@@ -419,8 +419,8 @@ struct kvm_vcpu_arch {
13509 gpa_t time;
13510 struct pvclock_vcpu_time_info hv_clock;
13511 unsigned int hw_tsc_khz;
13512- unsigned int time_offset;
13513- struct page *time_page;
13514+ struct gfn_to_hva_cache pv_time;
13515+ bool pv_time_enabled;
13516 /* set guest stopped flag in pvclock flags field */
13517 bool pvclock_set_guest_stopped_request;
13518
13519diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13520index 2d89e39..baee879 100644
13521--- a/arch/x86/include/asm/local.h
13522+++ b/arch/x86/include/asm/local.h
13523@@ -10,33 +10,97 @@ typedef struct {
13524 atomic_long_t a;
13525 } local_t;
13526
13527+typedef struct {
13528+ atomic_long_unchecked_t a;
13529+} local_unchecked_t;
13530+
13531 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13532
13533 #define local_read(l) atomic_long_read(&(l)->a)
13534+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13535 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13536+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13537
13538 static inline void local_inc(local_t *l)
13539 {
13540- asm volatile(_ASM_INC "%0"
13541+ asm volatile(_ASM_INC "%0\n"
13542+
13543+#ifdef CONFIG_PAX_REFCOUNT
13544+ "jno 0f\n"
13545+ _ASM_DEC "%0\n"
13546+ "int $4\n0:\n"
13547+ _ASM_EXTABLE(0b, 0b)
13548+#endif
13549+
13550+ : "+m" (l->a.counter));
13551+}
13552+
13553+static inline void local_inc_unchecked(local_unchecked_t *l)
13554+{
13555+ asm volatile(_ASM_INC "%0\n"
13556 : "+m" (l->a.counter));
13557 }
13558
13559 static inline void local_dec(local_t *l)
13560 {
13561- asm volatile(_ASM_DEC "%0"
13562+ asm volatile(_ASM_DEC "%0\n"
13563+
13564+#ifdef CONFIG_PAX_REFCOUNT
13565+ "jno 0f\n"
13566+ _ASM_INC "%0\n"
13567+ "int $4\n0:\n"
13568+ _ASM_EXTABLE(0b, 0b)
13569+#endif
13570+
13571+ : "+m" (l->a.counter));
13572+}
13573+
13574+static inline void local_dec_unchecked(local_unchecked_t *l)
13575+{
13576+ asm volatile(_ASM_DEC "%0\n"
13577 : "+m" (l->a.counter));
13578 }
13579
13580 static inline void local_add(long i, local_t *l)
13581 {
13582- asm volatile(_ASM_ADD "%1,%0"
13583+ asm volatile(_ASM_ADD "%1,%0\n"
13584+
13585+#ifdef CONFIG_PAX_REFCOUNT
13586+ "jno 0f\n"
13587+ _ASM_SUB "%1,%0\n"
13588+ "int $4\n0:\n"
13589+ _ASM_EXTABLE(0b, 0b)
13590+#endif
13591+
13592+ : "+m" (l->a.counter)
13593+ : "ir" (i));
13594+}
13595+
13596+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13597+{
13598+ asm volatile(_ASM_ADD "%1,%0\n"
13599 : "+m" (l->a.counter)
13600 : "ir" (i));
13601 }
13602
13603 static inline void local_sub(long i, local_t *l)
13604 {
13605- asm volatile(_ASM_SUB "%1,%0"
13606+ asm volatile(_ASM_SUB "%1,%0\n"
13607+
13608+#ifdef CONFIG_PAX_REFCOUNT
13609+ "jno 0f\n"
13610+ _ASM_ADD "%1,%0\n"
13611+ "int $4\n0:\n"
13612+ _ASM_EXTABLE(0b, 0b)
13613+#endif
13614+
13615+ : "+m" (l->a.counter)
13616+ : "ir" (i));
13617+}
13618+
13619+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13620+{
13621+ asm volatile(_ASM_SUB "%1,%0\n"
13622 : "+m" (l->a.counter)
13623 : "ir" (i));
13624 }
13625@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13626 {
13627 unsigned char c;
13628
13629- asm volatile(_ASM_SUB "%2,%0; sete %1"
13630+ asm volatile(_ASM_SUB "%2,%0\n"
13631+
13632+#ifdef CONFIG_PAX_REFCOUNT
13633+ "jno 0f\n"
13634+ _ASM_ADD "%2,%0\n"
13635+ "int $4\n0:\n"
13636+ _ASM_EXTABLE(0b, 0b)
13637+#endif
13638+
13639+ "sete %1\n"
13640 : "+m" (l->a.counter), "=qm" (c)
13641 : "ir" (i) : "memory");
13642 return c;
13643@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13644 {
13645 unsigned char c;
13646
13647- asm volatile(_ASM_DEC "%0; sete %1"
13648+ asm volatile(_ASM_DEC "%0\n"
13649+
13650+#ifdef CONFIG_PAX_REFCOUNT
13651+ "jno 0f\n"
13652+ _ASM_INC "%0\n"
13653+ "int $4\n0:\n"
13654+ _ASM_EXTABLE(0b, 0b)
13655+#endif
13656+
13657+ "sete %1\n"
13658 : "+m" (l->a.counter), "=qm" (c)
13659 : : "memory");
13660 return c != 0;
13661@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13662 {
13663 unsigned char c;
13664
13665- asm volatile(_ASM_INC "%0; sete %1"
13666+ asm volatile(_ASM_INC "%0\n"
13667+
13668+#ifdef CONFIG_PAX_REFCOUNT
13669+ "jno 0f\n"
13670+ _ASM_DEC "%0\n"
13671+ "int $4\n0:\n"
13672+ _ASM_EXTABLE(0b, 0b)
13673+#endif
13674+
13675+ "sete %1\n"
13676 : "+m" (l->a.counter), "=qm" (c)
13677 : : "memory");
13678 return c != 0;
13679@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13680 {
13681 unsigned char c;
13682
13683- asm volatile(_ASM_ADD "%2,%0; sets %1"
13684+ asm volatile(_ASM_ADD "%2,%0\n"
13685+
13686+#ifdef CONFIG_PAX_REFCOUNT
13687+ "jno 0f\n"
13688+ _ASM_SUB "%2,%0\n"
13689+ "int $4\n0:\n"
13690+ _ASM_EXTABLE(0b, 0b)
13691+#endif
13692+
13693+ "sets %1\n"
13694 : "+m" (l->a.counter), "=qm" (c)
13695 : "ir" (i) : "memory");
13696 return c;
13697@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13698 static inline long local_add_return(long i, local_t *l)
13699 {
13700 long __i = i;
13701+ asm volatile(_ASM_XADD "%0, %1\n"
13702+
13703+#ifdef CONFIG_PAX_REFCOUNT
13704+ "jno 0f\n"
13705+ _ASM_MOV "%0,%1\n"
13706+ "int $4\n0:\n"
13707+ _ASM_EXTABLE(0b, 0b)
13708+#endif
13709+
13710+ : "+r" (i), "+m" (l->a.counter)
13711+ : : "memory");
13712+ return i + __i;
13713+}
13714+
13715+/**
13716+ * local_add_return_unchecked - add and return
13717+ * @i: integer value to add
13718+ * @l: pointer to type local_unchecked_t
13719+ *
13720+ * Atomically adds @i to @l and returns @i + @l
13721+ */
13722+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13723+{
13724+ long __i = i;
13725 asm volatile(_ASM_XADD "%0, %1;"
13726 : "+r" (i), "+m" (l->a.counter)
13727 : : "memory");
13728@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13729
13730 #define local_cmpxchg(l, o, n) \
13731 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13732+#define local_cmpxchg_unchecked(l, o, n) \
13733+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13734 /* Always has a lock prefix */
13735 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13736
13737diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13738new file mode 100644
13739index 0000000..2bfd3ba
13740--- /dev/null
13741+++ b/arch/x86/include/asm/mman.h
13742@@ -0,0 +1,15 @@
13743+#ifndef _X86_MMAN_H
13744+#define _X86_MMAN_H
13745+
13746+#include <uapi/asm/mman.h>
13747+
13748+#ifdef __KERNEL__
13749+#ifndef __ASSEMBLY__
13750+#ifdef CONFIG_X86_32
13751+#define arch_mmap_check i386_mmap_check
13752+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13753+#endif
13754+#endif
13755+#endif
13756+
13757+#endif /* X86_MMAN_H */
13758diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13759index 5f55e69..e20bfb1 100644
13760--- a/arch/x86/include/asm/mmu.h
13761+++ b/arch/x86/include/asm/mmu.h
13762@@ -9,7 +9,7 @@
13763 * we put the segment information here.
13764 */
13765 typedef struct {
13766- void *ldt;
13767+ struct desc_struct *ldt;
13768 int size;
13769
13770 #ifdef CONFIG_X86_64
13771@@ -18,7 +18,19 @@ typedef struct {
13772 #endif
13773
13774 struct mutex lock;
13775- void *vdso;
13776+ unsigned long vdso;
13777+
13778+#ifdef CONFIG_X86_32
13779+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13780+ unsigned long user_cs_base;
13781+ unsigned long user_cs_limit;
13782+
13783+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13784+ cpumask_t cpu_user_cs_mask;
13785+#endif
13786+
13787+#endif
13788+#endif
13789 } mm_context_t;
13790
13791 #ifdef CONFIG_SMP
13792diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13793index cdbf367..adb37ac 100644
13794--- a/arch/x86/include/asm/mmu_context.h
13795+++ b/arch/x86/include/asm/mmu_context.h
13796@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13797
13798 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13799 {
13800+
13801+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13802+ unsigned int i;
13803+ pgd_t *pgd;
13804+
13805+ pax_open_kernel();
13806+ pgd = get_cpu_pgd(smp_processor_id());
13807+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13808+ set_pgd_batched(pgd+i, native_make_pgd(0));
13809+ pax_close_kernel();
13810+#endif
13811+
13812 #ifdef CONFIG_SMP
13813 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13814 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13815@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13816 struct task_struct *tsk)
13817 {
13818 unsigned cpu = smp_processor_id();
13819+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13820+ int tlbstate = TLBSTATE_OK;
13821+#endif
13822
13823 if (likely(prev != next)) {
13824 #ifdef CONFIG_SMP
13825+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13826+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13827+#endif
13828 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13829 this_cpu_write(cpu_tlbstate.active_mm, next);
13830 #endif
13831 cpumask_set_cpu(cpu, mm_cpumask(next));
13832
13833 /* Re-load page tables */
13834+#ifdef CONFIG_PAX_PER_CPU_PGD
13835+ pax_open_kernel();
13836+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13837+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13838+ pax_close_kernel();
13839+ load_cr3(get_cpu_pgd(cpu));
13840+#else
13841 load_cr3(next->pgd);
13842+#endif
13843
13844 /* stop flush ipis for the previous mm */
13845 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13846@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13847 */
13848 if (unlikely(prev->context.ldt != next->context.ldt))
13849 load_LDT_nolock(&next->context);
13850- }
13851+
13852+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13853+ if (!(__supported_pte_mask & _PAGE_NX)) {
13854+ smp_mb__before_clear_bit();
13855+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13856+ smp_mb__after_clear_bit();
13857+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13858+ }
13859+#endif
13860+
13861+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13862+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13863+ prev->context.user_cs_limit != next->context.user_cs_limit))
13864+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13865 #ifdef CONFIG_SMP
13866+ else if (unlikely(tlbstate != TLBSTATE_OK))
13867+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13868+#endif
13869+#endif
13870+
13871+ }
13872 else {
13873+
13874+#ifdef CONFIG_PAX_PER_CPU_PGD
13875+ pax_open_kernel();
13876+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13877+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13878+ pax_close_kernel();
13879+ load_cr3(get_cpu_pgd(cpu));
13880+#endif
13881+
13882+#ifdef CONFIG_SMP
13883 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13884 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13885
13886@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13887 * tlb flush IPI delivery. We must reload CR3
13888 * to make sure to use no freed page tables.
13889 */
13890+
13891+#ifndef CONFIG_PAX_PER_CPU_PGD
13892 load_cr3(next->pgd);
13893+#endif
13894+
13895 load_LDT_nolock(&next->context);
13896+
13897+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13898+ if (!(__supported_pte_mask & _PAGE_NX))
13899+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13900+#endif
13901+
13902+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13903+#ifdef CONFIG_PAX_PAGEEXEC
13904+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13905+#endif
13906+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13907+#endif
13908+
13909 }
13910+#endif
13911 }
13912-#endif
13913 }
13914
13915 #define activate_mm(prev, next) \
13916diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13917index e3b7819..b257c64 100644
13918--- a/arch/x86/include/asm/module.h
13919+++ b/arch/x86/include/asm/module.h
13920@@ -5,6 +5,7 @@
13921
13922 #ifdef CONFIG_X86_64
13923 /* X86_64 does not define MODULE_PROC_FAMILY */
13924+#define MODULE_PROC_FAMILY ""
13925 #elif defined CONFIG_M486
13926 #define MODULE_PROC_FAMILY "486 "
13927 #elif defined CONFIG_M586
13928@@ -57,8 +58,20 @@
13929 #error unknown processor family
13930 #endif
13931
13932-#ifdef CONFIG_X86_32
13933-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13934+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13935+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13936+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13937+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13938+#else
13939+#define MODULE_PAX_KERNEXEC ""
13940 #endif
13941
13942+#ifdef CONFIG_PAX_MEMORY_UDEREF
13943+#define MODULE_PAX_UDEREF "UDEREF "
13944+#else
13945+#define MODULE_PAX_UDEREF ""
13946+#endif
13947+
13948+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13949+
13950 #endif /* _ASM_X86_MODULE_H */
13951diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
13952index c0fa356..07a498a 100644
13953--- a/arch/x86/include/asm/nmi.h
13954+++ b/arch/x86/include/asm/nmi.h
13955@@ -42,11 +42,11 @@ struct nmiaction {
13956 nmi_handler_t handler;
13957 unsigned long flags;
13958 const char *name;
13959-};
13960+} __do_const;
13961
13962 #define register_nmi_handler(t, fn, fg, n, init...) \
13963 ({ \
13964- static struct nmiaction init fn##_na = { \
13965+ static const struct nmiaction init fn##_na = { \
13966 .handler = (fn), \
13967 .name = (n), \
13968 .flags = (fg), \
13969@@ -54,7 +54,7 @@ struct nmiaction {
13970 __register_nmi_handler((t), &fn##_na); \
13971 })
13972
13973-int __register_nmi_handler(unsigned int, struct nmiaction *);
13974+int __register_nmi_handler(unsigned int, const struct nmiaction *);
13975
13976 void unregister_nmi_handler(unsigned int, const char *);
13977
13978diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13979index 320f7bb..e89f8f8 100644
13980--- a/arch/x86/include/asm/page_64_types.h
13981+++ b/arch/x86/include/asm/page_64_types.h
13982@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13983
13984 /* duplicated to the one in bootmem.h */
13985 extern unsigned long max_pfn;
13986-extern unsigned long phys_base;
13987+extern const unsigned long phys_base;
13988
13989 extern unsigned long __phys_addr(unsigned long);
13990 #define __phys_reloc_hide(x) (x)
13991diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13992index 5edd174..c395822 100644
13993--- a/arch/x86/include/asm/paravirt.h
13994+++ b/arch/x86/include/asm/paravirt.h
13995@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
13996 return (pmd_t) { ret };
13997 }
13998
13999-static inline pmdval_t pmd_val(pmd_t pmd)
14000+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14001 {
14002 pmdval_t ret;
14003
14004@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14005 val);
14006 }
14007
14008+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14009+{
14010+ pgdval_t val = native_pgd_val(pgd);
14011+
14012+ if (sizeof(pgdval_t) > sizeof(long))
14013+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14014+ val, (u64)val >> 32);
14015+ else
14016+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14017+ val);
14018+}
14019+
14020 static inline void pgd_clear(pgd_t *pgdp)
14021 {
14022 set_pgd(pgdp, __pgd(0));
14023@@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14024 pv_mmu_ops.set_fixmap(idx, phys, flags);
14025 }
14026
14027+#ifdef CONFIG_PAX_KERNEXEC
14028+static inline unsigned long pax_open_kernel(void)
14029+{
14030+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14031+}
14032+
14033+static inline unsigned long pax_close_kernel(void)
14034+{
14035+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14036+}
14037+#else
14038+static inline unsigned long pax_open_kernel(void) { return 0; }
14039+static inline unsigned long pax_close_kernel(void) { return 0; }
14040+#endif
14041+
14042 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14043
14044 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14045@@ -927,7 +954,7 @@ extern void default_banner(void);
14046
14047 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14048 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14049-#define PARA_INDIRECT(addr) *%cs:addr
14050+#define PARA_INDIRECT(addr) *%ss:addr
14051 #endif
14052
14053 #define INTERRUPT_RETURN \
14054@@ -1002,6 +1029,21 @@ extern void default_banner(void);
14055 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14056 CLBR_NONE, \
14057 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14058+
14059+#define GET_CR0_INTO_RDI \
14060+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14061+ mov %rax,%rdi
14062+
14063+#define SET_RDI_INTO_CR0 \
14064+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14065+
14066+#define GET_CR3_INTO_RDI \
14067+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14068+ mov %rax,%rdi
14069+
14070+#define SET_RDI_INTO_CR3 \
14071+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14072+
14073 #endif /* CONFIG_X86_32 */
14074
14075 #endif /* __ASSEMBLY__ */
14076diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14077index 142236e..5446ffbc 100644
14078--- a/arch/x86/include/asm/paravirt_types.h
14079+++ b/arch/x86/include/asm/paravirt_types.h
14080@@ -84,7 +84,7 @@ struct pv_init_ops {
14081 */
14082 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14083 unsigned long addr, unsigned len);
14084-};
14085+} __no_const;
14086
14087
14088 struct pv_lazy_ops {
14089@@ -97,7 +97,7 @@ struct pv_time_ops {
14090 unsigned long long (*sched_clock)(void);
14091 unsigned long long (*steal_clock)(int cpu);
14092 unsigned long (*get_tsc_khz)(void);
14093-};
14094+} __no_const;
14095
14096 struct pv_cpu_ops {
14097 /* hooks for various privileged instructions */
14098@@ -191,7 +191,7 @@ struct pv_cpu_ops {
14099
14100 void (*start_context_switch)(struct task_struct *prev);
14101 void (*end_context_switch)(struct task_struct *next);
14102-};
14103+} __no_const;
14104
14105 struct pv_irq_ops {
14106 /*
14107@@ -222,7 +222,7 @@ struct pv_apic_ops {
14108 unsigned long start_eip,
14109 unsigned long start_esp);
14110 #endif
14111-};
14112+} __no_const;
14113
14114 struct pv_mmu_ops {
14115 unsigned long (*read_cr2)(void);
14116@@ -312,6 +312,7 @@ struct pv_mmu_ops {
14117 struct paravirt_callee_save make_pud;
14118
14119 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14120+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14121 #endif /* PAGETABLE_LEVELS == 4 */
14122 #endif /* PAGETABLE_LEVELS >= 3 */
14123
14124@@ -323,6 +324,12 @@ struct pv_mmu_ops {
14125 an mfn. We can tell which is which from the index. */
14126 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14127 phys_addr_t phys, pgprot_t flags);
14128+
14129+#ifdef CONFIG_PAX_KERNEXEC
14130+ unsigned long (*pax_open_kernel)(void);
14131+ unsigned long (*pax_close_kernel)(void);
14132+#endif
14133+
14134 };
14135
14136 struct arch_spinlock;
14137@@ -333,7 +340,7 @@ struct pv_lock_ops {
14138 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14139 int (*spin_trylock)(struct arch_spinlock *lock);
14140 void (*spin_unlock)(struct arch_spinlock *lock);
14141-};
14142+} __no_const;
14143
14144 /* This contains all the paravirt structures: we get a convenient
14145 * number for each function using the offset which we use to indicate
14146diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14147index b4389a4..7024269 100644
14148--- a/arch/x86/include/asm/pgalloc.h
14149+++ b/arch/x86/include/asm/pgalloc.h
14150@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14151 pmd_t *pmd, pte_t *pte)
14152 {
14153 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14154+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14155+}
14156+
14157+static inline void pmd_populate_user(struct mm_struct *mm,
14158+ pmd_t *pmd, pte_t *pte)
14159+{
14160+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14161 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14162 }
14163
14164@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14165
14166 #ifdef CONFIG_X86_PAE
14167 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14168+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14169+{
14170+ pud_populate(mm, pudp, pmd);
14171+}
14172 #else /* !CONFIG_X86_PAE */
14173 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14174 {
14175 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14176 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14177 }
14178+
14179+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14180+{
14181+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14182+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14183+}
14184 #endif /* CONFIG_X86_PAE */
14185
14186 #if PAGETABLE_LEVELS > 3
14187@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14188 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14189 }
14190
14191+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14192+{
14193+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14194+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14195+}
14196+
14197 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14198 {
14199 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14200diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14201index f2b489c..4f7e2e5 100644
14202--- a/arch/x86/include/asm/pgtable-2level.h
14203+++ b/arch/x86/include/asm/pgtable-2level.h
14204@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14205
14206 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14207 {
14208+ pax_open_kernel();
14209 *pmdp = pmd;
14210+ pax_close_kernel();
14211 }
14212
14213 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14214diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14215index 4cc9f2b..5fd9226 100644
14216--- a/arch/x86/include/asm/pgtable-3level.h
14217+++ b/arch/x86/include/asm/pgtable-3level.h
14218@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14219
14220 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14221 {
14222+ pax_open_kernel();
14223 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14224+ pax_close_kernel();
14225 }
14226
14227 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14228 {
14229+ pax_open_kernel();
14230 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14231+ pax_close_kernel();
14232 }
14233
14234 /*
14235diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14236index 1c1a955..50f828c 100644
14237--- a/arch/x86/include/asm/pgtable.h
14238+++ b/arch/x86/include/asm/pgtable.h
14239@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14240
14241 #ifndef __PAGETABLE_PUD_FOLDED
14242 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14243+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14244 #define pgd_clear(pgd) native_pgd_clear(pgd)
14245 #endif
14246
14247@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14248
14249 #define arch_end_context_switch(prev) do {} while(0)
14250
14251+#define pax_open_kernel() native_pax_open_kernel()
14252+#define pax_close_kernel() native_pax_close_kernel()
14253 #endif /* CONFIG_PARAVIRT */
14254
14255+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14256+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14257+
14258+#ifdef CONFIG_PAX_KERNEXEC
14259+static inline unsigned long native_pax_open_kernel(void)
14260+{
14261+ unsigned long cr0;
14262+
14263+ preempt_disable();
14264+ barrier();
14265+ cr0 = read_cr0() ^ X86_CR0_WP;
14266+ BUG_ON(cr0 & X86_CR0_WP);
14267+ write_cr0(cr0);
14268+ return cr0 ^ X86_CR0_WP;
14269+}
14270+
14271+static inline unsigned long native_pax_close_kernel(void)
14272+{
14273+ unsigned long cr0;
14274+
14275+ cr0 = read_cr0() ^ X86_CR0_WP;
14276+ BUG_ON(!(cr0 & X86_CR0_WP));
14277+ write_cr0(cr0);
14278+ barrier();
14279+ preempt_enable_no_resched();
14280+ return cr0 ^ X86_CR0_WP;
14281+}
14282+#else
14283+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14284+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14285+#endif
14286+
14287 /*
14288 * The following only work if pte_present() is true.
14289 * Undefined behaviour if not..
14290 */
14291+static inline int pte_user(pte_t pte)
14292+{
14293+ return pte_val(pte) & _PAGE_USER;
14294+}
14295+
14296 static inline int pte_dirty(pte_t pte)
14297 {
14298 return pte_flags(pte) & _PAGE_DIRTY;
14299@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14300 return pte_clear_flags(pte, _PAGE_RW);
14301 }
14302
14303+static inline pte_t pte_mkread(pte_t pte)
14304+{
14305+ return __pte(pte_val(pte) | _PAGE_USER);
14306+}
14307+
14308 static inline pte_t pte_mkexec(pte_t pte)
14309 {
14310- return pte_clear_flags(pte, _PAGE_NX);
14311+#ifdef CONFIG_X86_PAE
14312+ if (__supported_pte_mask & _PAGE_NX)
14313+ return pte_clear_flags(pte, _PAGE_NX);
14314+ else
14315+#endif
14316+ return pte_set_flags(pte, _PAGE_USER);
14317+}
14318+
14319+static inline pte_t pte_exprotect(pte_t pte)
14320+{
14321+#ifdef CONFIG_X86_PAE
14322+ if (__supported_pte_mask & _PAGE_NX)
14323+ return pte_set_flags(pte, _PAGE_NX);
14324+ else
14325+#endif
14326+ return pte_clear_flags(pte, _PAGE_USER);
14327 }
14328
14329 static inline pte_t pte_mkdirty(pte_t pte)
14330@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14331 #endif
14332
14333 #ifndef __ASSEMBLY__
14334+
14335+#ifdef CONFIG_PAX_PER_CPU_PGD
14336+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14337+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14338+{
14339+ return cpu_pgd[cpu];
14340+}
14341+#endif
14342+
14343 #include <linux/mm_types.h>
14344
14345 static inline int pte_none(pte_t pte)
14346@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14347
14348 static inline int pgd_bad(pgd_t pgd)
14349 {
14350- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14351+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14352 }
14353
14354 static inline int pgd_none(pgd_t pgd)
14355@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14356 * pgd_offset() returns a (pgd_t *)
14357 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14358 */
14359-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14360+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14361+
14362+#ifdef CONFIG_PAX_PER_CPU_PGD
14363+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14364+#endif
14365+
14366 /*
14367 * a shortcut which implies the use of the kernel's pgd, instead
14368 * of a process's
14369@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14370 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14371 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14372
14373+#ifdef CONFIG_X86_32
14374+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14375+#else
14376+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14377+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14378+
14379+#ifdef CONFIG_PAX_MEMORY_UDEREF
14380+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14381+#else
14382+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14383+#endif
14384+
14385+#endif
14386+
14387 #ifndef __ASSEMBLY__
14388
14389 extern int direct_gbpages;
14390@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14391 * dst and src can be on the same page, but the range must not overlap,
14392 * and must not cross a page boundary.
14393 */
14394-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14395+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14396 {
14397- memcpy(dst, src, count * sizeof(pgd_t));
14398+ pax_open_kernel();
14399+ while (count--)
14400+ *dst++ = *src++;
14401+ pax_close_kernel();
14402 }
14403
14404+#ifdef CONFIG_PAX_PER_CPU_PGD
14405+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14406+#endif
14407+
14408+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14409+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14410+#else
14411+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14412+#endif
14413
14414 #include <asm-generic/pgtable.h>
14415 #endif /* __ASSEMBLY__ */
14416diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14417index 8faa215..a8a17ea 100644
14418--- a/arch/x86/include/asm/pgtable_32.h
14419+++ b/arch/x86/include/asm/pgtable_32.h
14420@@ -25,9 +25,6 @@
14421 struct mm_struct;
14422 struct vm_area_struct;
14423
14424-extern pgd_t swapper_pg_dir[1024];
14425-extern pgd_t initial_page_table[1024];
14426-
14427 static inline void pgtable_cache_init(void) { }
14428 static inline void check_pgt_cache(void) { }
14429 void paging_init(void);
14430@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14431 # include <asm/pgtable-2level.h>
14432 #endif
14433
14434+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14435+extern pgd_t initial_page_table[PTRS_PER_PGD];
14436+#ifdef CONFIG_X86_PAE
14437+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14438+#endif
14439+
14440 #if defined(CONFIG_HIGHPTE)
14441 #define pte_offset_map(dir, address) \
14442 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14443@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14444 /* Clear a kernel PTE and flush it from the TLB */
14445 #define kpte_clear_flush(ptep, vaddr) \
14446 do { \
14447+ pax_open_kernel(); \
14448 pte_clear(&init_mm, (vaddr), (ptep)); \
14449+ pax_close_kernel(); \
14450 __flush_tlb_one((vaddr)); \
14451 } while (0)
14452
14453@@ -75,6 +80,9 @@ do { \
14454
14455 #endif /* !__ASSEMBLY__ */
14456
14457+#define HAVE_ARCH_UNMAPPED_AREA
14458+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14459+
14460 /*
14461 * kern_addr_valid() is (1) for FLATMEM and (0) for
14462 * SPARSEMEM and DISCONTIGMEM
14463diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14464index ed5903b..c7fe163 100644
14465--- a/arch/x86/include/asm/pgtable_32_types.h
14466+++ b/arch/x86/include/asm/pgtable_32_types.h
14467@@ -8,7 +8,7 @@
14468 */
14469 #ifdef CONFIG_X86_PAE
14470 # include <asm/pgtable-3level_types.h>
14471-# define PMD_SIZE (1UL << PMD_SHIFT)
14472+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14473 # define PMD_MASK (~(PMD_SIZE - 1))
14474 #else
14475 # include <asm/pgtable-2level_types.h>
14476@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14477 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14478 #endif
14479
14480+#ifdef CONFIG_PAX_KERNEXEC
14481+#ifndef __ASSEMBLY__
14482+extern unsigned char MODULES_EXEC_VADDR[];
14483+extern unsigned char MODULES_EXEC_END[];
14484+#endif
14485+#include <asm/boot.h>
14486+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14487+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14488+#else
14489+#define ktla_ktva(addr) (addr)
14490+#define ktva_ktla(addr) (addr)
14491+#endif
14492+
14493 #define MODULES_VADDR VMALLOC_START
14494 #define MODULES_END VMALLOC_END
14495 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14496diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14497index 47356f9..deb94a2 100644
14498--- a/arch/x86/include/asm/pgtable_64.h
14499+++ b/arch/x86/include/asm/pgtable_64.h
14500@@ -16,10 +16,14 @@
14501
14502 extern pud_t level3_kernel_pgt[512];
14503 extern pud_t level3_ident_pgt[512];
14504+extern pud_t level3_vmalloc_start_pgt[512];
14505+extern pud_t level3_vmalloc_end_pgt[512];
14506+extern pud_t level3_vmemmap_pgt[512];
14507+extern pud_t level2_vmemmap_pgt[512];
14508 extern pmd_t level2_kernel_pgt[512];
14509 extern pmd_t level2_fixmap_pgt[512];
14510-extern pmd_t level2_ident_pgt[512];
14511-extern pgd_t init_level4_pgt[];
14512+extern pmd_t level2_ident_pgt[512*2];
14513+extern pgd_t init_level4_pgt[512];
14514
14515 #define swapper_pg_dir init_level4_pgt
14516
14517@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14518
14519 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14520 {
14521+ pax_open_kernel();
14522 *pmdp = pmd;
14523+ pax_close_kernel();
14524 }
14525
14526 static inline void native_pmd_clear(pmd_t *pmd)
14527@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14528
14529 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14530 {
14531+ pax_open_kernel();
14532 *pudp = pud;
14533+ pax_close_kernel();
14534 }
14535
14536 static inline void native_pud_clear(pud_t *pud)
14537@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14538
14539 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14540 {
14541+ pax_open_kernel();
14542+ *pgdp = pgd;
14543+ pax_close_kernel();
14544+}
14545+
14546+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14547+{
14548 *pgdp = pgd;
14549 }
14550
14551diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14552index 766ea16..5b96cb3 100644
14553--- a/arch/x86/include/asm/pgtable_64_types.h
14554+++ b/arch/x86/include/asm/pgtable_64_types.h
14555@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14556 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14557 #define MODULES_END _AC(0xffffffffff000000, UL)
14558 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14559+#define MODULES_EXEC_VADDR MODULES_VADDR
14560+#define MODULES_EXEC_END MODULES_END
14561+
14562+#define ktla_ktva(addr) (addr)
14563+#define ktva_ktla(addr) (addr)
14564
14565 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14566diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14567index 3c32db8..1ddccf5 100644
14568--- a/arch/x86/include/asm/pgtable_types.h
14569+++ b/arch/x86/include/asm/pgtable_types.h
14570@@ -16,13 +16,12 @@
14571 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14572 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14573 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14574-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14575+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14576 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14577 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14578 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14579-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14580-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14581-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14582+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14583+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14584 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14585
14586 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14587@@ -40,7 +39,6 @@
14588 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14589 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14590 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14591-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14592 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14593 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14594 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14595@@ -57,8 +55,10 @@
14596
14597 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14598 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14599-#else
14600+#elif defined(CONFIG_KMEMCHECK)
14601 #define _PAGE_NX (_AT(pteval_t, 0))
14602+#else
14603+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14604 #endif
14605
14606 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14607@@ -116,6 +116,9 @@
14608 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14609 _PAGE_ACCESSED)
14610
14611+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14612+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14613+
14614 #define __PAGE_KERNEL_EXEC \
14615 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14616 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14617@@ -126,7 +129,7 @@
14618 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14619 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14620 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14621-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14622+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14623 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14624 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14625 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14626@@ -188,8 +191,8 @@
14627 * bits are combined, this will alow user to access the high address mapped
14628 * VDSO in the presence of CONFIG_COMPAT_VDSO
14629 */
14630-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14631-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14632+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14633+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14634 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14635 #endif
14636
14637@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14638 {
14639 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14640 }
14641+#endif
14642
14643+#if PAGETABLE_LEVELS == 3
14644+#include <asm-generic/pgtable-nopud.h>
14645+#endif
14646+
14647+#if PAGETABLE_LEVELS == 2
14648+#include <asm-generic/pgtable-nopmd.h>
14649+#endif
14650+
14651+#ifndef __ASSEMBLY__
14652 #if PAGETABLE_LEVELS > 3
14653 typedef struct { pudval_t pud; } pud_t;
14654
14655@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14656 return pud.pud;
14657 }
14658 #else
14659-#include <asm-generic/pgtable-nopud.h>
14660-
14661 static inline pudval_t native_pud_val(pud_t pud)
14662 {
14663 return native_pgd_val(pud.pgd);
14664@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14665 return pmd.pmd;
14666 }
14667 #else
14668-#include <asm-generic/pgtable-nopmd.h>
14669-
14670 static inline pmdval_t native_pmd_val(pmd_t pmd)
14671 {
14672 return native_pgd_val(pmd.pud.pgd);
14673@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14674
14675 extern pteval_t __supported_pte_mask;
14676 extern void set_nx(void);
14677-extern int nx_enabled;
14678
14679 #define pgprot_writecombine pgprot_writecombine
14680 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14681diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14682index 888184b..a07ac89 100644
14683--- a/arch/x86/include/asm/processor.h
14684+++ b/arch/x86/include/asm/processor.h
14685@@ -287,7 +287,7 @@ struct tss_struct {
14686
14687 } ____cacheline_aligned;
14688
14689-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14690+extern struct tss_struct init_tss[NR_CPUS];
14691
14692 /*
14693 * Save the original ist values for checking stack pointers during debugging
14694@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14695 */
14696 #define TASK_SIZE PAGE_OFFSET
14697 #define TASK_SIZE_MAX TASK_SIZE
14698+
14699+#ifdef CONFIG_PAX_SEGMEXEC
14700+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14701+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14702+#else
14703 #define STACK_TOP TASK_SIZE
14704-#define STACK_TOP_MAX STACK_TOP
14705+#endif
14706+
14707+#define STACK_TOP_MAX TASK_SIZE
14708
14709 #define INIT_THREAD { \
14710- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14711+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14712 .vm86_info = NULL, \
14713 .sysenter_cs = __KERNEL_CS, \
14714 .io_bitmap_ptr = NULL, \
14715@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14716 */
14717 #define INIT_TSS { \
14718 .x86_tss = { \
14719- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14720+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14721 .ss0 = __KERNEL_DS, \
14722 .ss1 = __KERNEL_CS, \
14723 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14724@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14725 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14726
14727 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14728-#define KSTK_TOP(info) \
14729-({ \
14730- unsigned long *__ptr = (unsigned long *)(info); \
14731- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14732-})
14733+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14734
14735 /*
14736 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14737@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14738 #define task_pt_regs(task) \
14739 ({ \
14740 struct pt_regs *__regs__; \
14741- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14742+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14743 __regs__ - 1; \
14744 })
14745
14746@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14747 /*
14748 * User space process size. 47bits minus one guard page.
14749 */
14750-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14751+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14752
14753 /* This decides where the kernel will search for a free chunk of vm
14754 * space during mmap's.
14755 */
14756 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14757- 0xc0000000 : 0xFFFFe000)
14758+ 0xc0000000 : 0xFFFFf000)
14759
14760 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14761 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14762@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14763 #define STACK_TOP_MAX TASK_SIZE_MAX
14764
14765 #define INIT_THREAD { \
14766- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14767+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14768 }
14769
14770 #define INIT_TSS { \
14771- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14772+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14773 }
14774
14775 /*
14776@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14777 */
14778 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14779
14780+#ifdef CONFIG_PAX_SEGMEXEC
14781+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14782+#endif
14783+
14784 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14785
14786 /* Get/set a process' ability to use the timestamp counter instruction */
14787@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14788 #define cpu_has_amd_erratum(x) (false)
14789 #endif /* CONFIG_CPU_SUP_AMD */
14790
14791-extern unsigned long arch_align_stack(unsigned long sp);
14792+#define arch_align_stack(x) ((x) & ~0xfUL)
14793 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14794
14795 void default_idle(void);
14796 bool set_pm_idle_to_default(void);
14797
14798-void stop_this_cpu(void *dummy);
14799+void stop_this_cpu(void *dummy) __noreturn;
14800
14801 #endif /* _ASM_X86_PROCESSOR_H */
14802diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14803index 942a086..6c26446 100644
14804--- a/arch/x86/include/asm/ptrace.h
14805+++ b/arch/x86/include/asm/ptrace.h
14806@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14807 }
14808
14809 /*
14810- * user_mode_vm(regs) determines whether a register set came from user mode.
14811+ * user_mode(regs) determines whether a register set came from user mode.
14812 * This is true if V8086 mode was enabled OR if the register set was from
14813 * protected mode with RPL-3 CS value. This tricky test checks that with
14814 * one comparison. Many places in the kernel can bypass this full check
14815- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14816+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14817+ * be used.
14818 */
14819-static inline int user_mode(struct pt_regs *regs)
14820+static inline int user_mode_novm(struct pt_regs *regs)
14821 {
14822 #ifdef CONFIG_X86_32
14823 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14824 #else
14825- return !!(regs->cs & 3);
14826+ return !!(regs->cs & SEGMENT_RPL_MASK);
14827 #endif
14828 }
14829
14830-static inline int user_mode_vm(struct pt_regs *regs)
14831+static inline int user_mode(struct pt_regs *regs)
14832 {
14833 #ifdef CONFIG_X86_32
14834 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14835 USER_RPL;
14836 #else
14837- return user_mode(regs);
14838+ return user_mode_novm(regs);
14839 #endif
14840 }
14841
14842@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14843 #ifdef CONFIG_X86_64
14844 static inline bool user_64bit_mode(struct pt_regs *regs)
14845 {
14846+ unsigned long cs = regs->cs & 0xffff;
14847 #ifndef CONFIG_PARAVIRT
14848 /*
14849 * On non-paravirt systems, this is the only long mode CPL 3
14850 * selector. We do not allow long mode selectors in the LDT.
14851 */
14852- return regs->cs == __USER_CS;
14853+ return cs == __USER_CS;
14854 #else
14855 /* Headers are too twisted for this to go in paravirt.h. */
14856- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14857+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14858 #endif
14859 }
14860
14861@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14862 * Traps from the kernel do not save sp and ss.
14863 * Use the helper function to retrieve sp.
14864 */
14865- if (offset == offsetof(struct pt_regs, sp) &&
14866- regs->cs == __KERNEL_CS)
14867- return kernel_stack_pointer(regs);
14868+ if (offset == offsetof(struct pt_regs, sp)) {
14869+ unsigned long cs = regs->cs & 0xffff;
14870+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14871+ return kernel_stack_pointer(regs);
14872+ }
14873 #endif
14874 return *(unsigned long *)((unsigned long)regs + offset);
14875 }
14876diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14877index fe1ec5b..dc5c3fe 100644
14878--- a/arch/x86/include/asm/realmode.h
14879+++ b/arch/x86/include/asm/realmode.h
14880@@ -22,16 +22,14 @@ struct real_mode_header {
14881 #endif
14882 /* APM/BIOS reboot */
14883 u32 machine_real_restart_asm;
14884-#ifdef CONFIG_X86_64
14885 u32 machine_real_restart_seg;
14886-#endif
14887 };
14888
14889 /* This must match data at trampoline_32/64.S */
14890 struct trampoline_header {
14891 #ifdef CONFIG_X86_32
14892 u32 start;
14893- u16 gdt_pad;
14894+ u16 boot_cs;
14895 u16 gdt_limit;
14896 u32 gdt_base;
14897 #else
14898diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14899index a82c4f1..ac45053 100644
14900--- a/arch/x86/include/asm/reboot.h
14901+++ b/arch/x86/include/asm/reboot.h
14902@@ -6,13 +6,13 @@
14903 struct pt_regs;
14904
14905 struct machine_ops {
14906- void (*restart)(char *cmd);
14907- void (*halt)(void);
14908- void (*power_off)(void);
14909+ void (* __noreturn restart)(char *cmd);
14910+ void (* __noreturn halt)(void);
14911+ void (* __noreturn power_off)(void);
14912 void (*shutdown)(void);
14913 void (*crash_shutdown)(struct pt_regs *);
14914- void (*emergency_restart)(void);
14915-};
14916+ void (* __noreturn emergency_restart)(void);
14917+} __no_const;
14918
14919 extern struct machine_ops machine_ops;
14920
14921diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14922index 2dbe4a7..ce1db00 100644
14923--- a/arch/x86/include/asm/rwsem.h
14924+++ b/arch/x86/include/asm/rwsem.h
14925@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14926 {
14927 asm volatile("# beginning down_read\n\t"
14928 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14929+
14930+#ifdef CONFIG_PAX_REFCOUNT
14931+ "jno 0f\n"
14932+ LOCK_PREFIX _ASM_DEC "(%1)\n"
14933+ "int $4\n0:\n"
14934+ _ASM_EXTABLE(0b, 0b)
14935+#endif
14936+
14937 /* adds 0x00000001 */
14938 " jns 1f\n"
14939 " call call_rwsem_down_read_failed\n"
14940@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14941 "1:\n\t"
14942 " mov %1,%2\n\t"
14943 " add %3,%2\n\t"
14944+
14945+#ifdef CONFIG_PAX_REFCOUNT
14946+ "jno 0f\n"
14947+ "sub %3,%2\n"
14948+ "int $4\n0:\n"
14949+ _ASM_EXTABLE(0b, 0b)
14950+#endif
14951+
14952 " jle 2f\n\t"
14953 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14954 " jnz 1b\n\t"
14955@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14956 long tmp;
14957 asm volatile("# beginning down_write\n\t"
14958 LOCK_PREFIX " xadd %1,(%2)\n\t"
14959+
14960+#ifdef CONFIG_PAX_REFCOUNT
14961+ "jno 0f\n"
14962+ "mov %1,(%2)\n"
14963+ "int $4\n0:\n"
14964+ _ASM_EXTABLE(0b, 0b)
14965+#endif
14966+
14967 /* adds 0xffff0001, returns the old value */
14968 " test %1,%1\n\t"
14969 /* was the count 0 before? */
14970@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14971 long tmp;
14972 asm volatile("# beginning __up_read\n\t"
14973 LOCK_PREFIX " xadd %1,(%2)\n\t"
14974+
14975+#ifdef CONFIG_PAX_REFCOUNT
14976+ "jno 0f\n"
14977+ "mov %1,(%2)\n"
14978+ "int $4\n0:\n"
14979+ _ASM_EXTABLE(0b, 0b)
14980+#endif
14981+
14982 /* subtracts 1, returns the old value */
14983 " jns 1f\n\t"
14984 " call call_rwsem_wake\n" /* expects old value in %edx */
14985@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14986 long tmp;
14987 asm volatile("# beginning __up_write\n\t"
14988 LOCK_PREFIX " xadd %1,(%2)\n\t"
14989+
14990+#ifdef CONFIG_PAX_REFCOUNT
14991+ "jno 0f\n"
14992+ "mov %1,(%2)\n"
14993+ "int $4\n0:\n"
14994+ _ASM_EXTABLE(0b, 0b)
14995+#endif
14996+
14997 /* subtracts 0xffff0001, returns the old value */
14998 " jns 1f\n\t"
14999 " call call_rwsem_wake\n" /* expects old value in %edx */
15000@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15001 {
15002 asm volatile("# beginning __downgrade_write\n\t"
15003 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15004+
15005+#ifdef CONFIG_PAX_REFCOUNT
15006+ "jno 0f\n"
15007+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15008+ "int $4\n0:\n"
15009+ _ASM_EXTABLE(0b, 0b)
15010+#endif
15011+
15012 /*
15013 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15014 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15015@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15016 */
15017 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15018 {
15019- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15020+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15021+
15022+#ifdef CONFIG_PAX_REFCOUNT
15023+ "jno 0f\n"
15024+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15025+ "int $4\n0:\n"
15026+ _ASM_EXTABLE(0b, 0b)
15027+#endif
15028+
15029 : "+m" (sem->count)
15030 : "er" (delta));
15031 }
15032@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15033 */
15034 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15035 {
15036- return delta + xadd(&sem->count, delta);
15037+ return delta + xadd_check_overflow(&sem->count, delta);
15038 }
15039
15040 #endif /* __KERNEL__ */
15041diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15042index c48a950..c6d7468 100644
15043--- a/arch/x86/include/asm/segment.h
15044+++ b/arch/x86/include/asm/segment.h
15045@@ -64,10 +64,15 @@
15046 * 26 - ESPFIX small SS
15047 * 27 - per-cpu [ offset to per-cpu data area ]
15048 * 28 - stack_canary-20 [ for stack protector ]
15049- * 29 - unused
15050- * 30 - unused
15051+ * 29 - PCI BIOS CS
15052+ * 30 - PCI BIOS DS
15053 * 31 - TSS for double fault handler
15054 */
15055+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15056+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15057+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15058+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15059+
15060 #define GDT_ENTRY_TLS_MIN 6
15061 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15062
15063@@ -79,6 +84,8 @@
15064
15065 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15066
15067+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15068+
15069 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15070
15071 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15072@@ -104,6 +111,12 @@
15073 #define __KERNEL_STACK_CANARY 0
15074 #endif
15075
15076+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15077+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15078+
15079+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15080+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15081+
15082 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15083
15084 /*
15085@@ -141,7 +154,7 @@
15086 */
15087
15088 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15089-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15090+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15091
15092
15093 #else
15094@@ -165,6 +178,8 @@
15095 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15096 #define __USER32_DS __USER_DS
15097
15098+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15099+
15100 #define GDT_ENTRY_TSS 8 /* needs two entries */
15101 #define GDT_ENTRY_LDT 10 /* needs two entries */
15102 #define GDT_ENTRY_TLS_MIN 12
15103@@ -185,6 +200,7 @@
15104 #endif
15105
15106 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15107+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15108 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15109 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15110 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15111@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15112 {
15113 unsigned long __limit;
15114 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15115- return __limit + 1;
15116+ return __limit;
15117 }
15118
15119 #endif /* !__ASSEMBLY__ */
15120diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15121index b073aae..39f9bdd 100644
15122--- a/arch/x86/include/asm/smp.h
15123+++ b/arch/x86/include/asm/smp.h
15124@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15125 /* cpus sharing the last level cache: */
15126 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15127 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15128-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15129+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15130
15131 static inline struct cpumask *cpu_sibling_mask(int cpu)
15132 {
15133@@ -79,7 +79,7 @@ struct smp_ops {
15134
15135 void (*send_call_func_ipi)(const struct cpumask *mask);
15136 void (*send_call_func_single_ipi)(int cpu);
15137-};
15138+} __no_const;
15139
15140 /* Globals due to paravirt */
15141 extern void set_cpu_sibling_map(int cpu);
15142@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15143 extern int safe_smp_processor_id(void);
15144
15145 #elif defined(CONFIG_X86_64_SMP)
15146-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15147-
15148-#define stack_smp_processor_id() \
15149-({ \
15150- struct thread_info *ti; \
15151- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15152- ti->cpu; \
15153-})
15154+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15155+#define stack_smp_processor_id() raw_smp_processor_id()
15156 #define safe_smp_processor_id() smp_processor_id()
15157
15158 #endif
15159diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15160index 33692ea..350a534 100644
15161--- a/arch/x86/include/asm/spinlock.h
15162+++ b/arch/x86/include/asm/spinlock.h
15163@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15164 static inline void arch_read_lock(arch_rwlock_t *rw)
15165 {
15166 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15167+
15168+#ifdef CONFIG_PAX_REFCOUNT
15169+ "jno 0f\n"
15170+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15171+ "int $4\n0:\n"
15172+ _ASM_EXTABLE(0b, 0b)
15173+#endif
15174+
15175 "jns 1f\n"
15176 "call __read_lock_failed\n\t"
15177 "1:\n"
15178@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15179 static inline void arch_write_lock(arch_rwlock_t *rw)
15180 {
15181 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15182+
15183+#ifdef CONFIG_PAX_REFCOUNT
15184+ "jno 0f\n"
15185+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15186+ "int $4\n0:\n"
15187+ _ASM_EXTABLE(0b, 0b)
15188+#endif
15189+
15190 "jz 1f\n"
15191 "call __write_lock_failed\n\t"
15192 "1:\n"
15193@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15194
15195 static inline void arch_read_unlock(arch_rwlock_t *rw)
15196 {
15197- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15198+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15199+
15200+#ifdef CONFIG_PAX_REFCOUNT
15201+ "jno 0f\n"
15202+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15203+ "int $4\n0:\n"
15204+ _ASM_EXTABLE(0b, 0b)
15205+#endif
15206+
15207 :"+m" (rw->lock) : : "memory");
15208 }
15209
15210 static inline void arch_write_unlock(arch_rwlock_t *rw)
15211 {
15212- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15213+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15214+
15215+#ifdef CONFIG_PAX_REFCOUNT
15216+ "jno 0f\n"
15217+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15218+ "int $4\n0:\n"
15219+ _ASM_EXTABLE(0b, 0b)
15220+#endif
15221+
15222 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15223 }
15224
15225diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15226index 6a99859..03cb807 100644
15227--- a/arch/x86/include/asm/stackprotector.h
15228+++ b/arch/x86/include/asm/stackprotector.h
15229@@ -47,7 +47,7 @@
15230 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15231 */
15232 #define GDT_STACK_CANARY_INIT \
15233- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15234+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15235
15236 /*
15237 * Initialize the stackprotector canary value.
15238@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15239
15240 static inline void load_stack_canary_segment(void)
15241 {
15242-#ifdef CONFIG_X86_32
15243+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15244 asm volatile ("mov %0, %%gs" : : "r" (0));
15245 #endif
15246 }
15247diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15248index 70bbe39..4ae2bd4 100644
15249--- a/arch/x86/include/asm/stacktrace.h
15250+++ b/arch/x86/include/asm/stacktrace.h
15251@@ -11,28 +11,20 @@
15252
15253 extern int kstack_depth_to_print;
15254
15255-struct thread_info;
15256+struct task_struct;
15257 struct stacktrace_ops;
15258
15259-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15260- unsigned long *stack,
15261- unsigned long bp,
15262- const struct stacktrace_ops *ops,
15263- void *data,
15264- unsigned long *end,
15265- int *graph);
15266+typedef unsigned long walk_stack_t(struct task_struct *task,
15267+ void *stack_start,
15268+ unsigned long *stack,
15269+ unsigned long bp,
15270+ const struct stacktrace_ops *ops,
15271+ void *data,
15272+ unsigned long *end,
15273+ int *graph);
15274
15275-extern unsigned long
15276-print_context_stack(struct thread_info *tinfo,
15277- unsigned long *stack, unsigned long bp,
15278- const struct stacktrace_ops *ops, void *data,
15279- unsigned long *end, int *graph);
15280-
15281-extern unsigned long
15282-print_context_stack_bp(struct thread_info *tinfo,
15283- unsigned long *stack, unsigned long bp,
15284- const struct stacktrace_ops *ops, void *data,
15285- unsigned long *end, int *graph);
15286+extern walk_stack_t print_context_stack;
15287+extern walk_stack_t print_context_stack_bp;
15288
15289 /* Generic stack tracer with callbacks */
15290
15291@@ -40,7 +32,7 @@ struct stacktrace_ops {
15292 void (*address)(void *data, unsigned long address, int reliable);
15293 /* On negative return stop dumping */
15294 int (*stack)(void *data, char *name);
15295- walk_stack_t walk_stack;
15296+ walk_stack_t *walk_stack;
15297 };
15298
15299 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15300diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15301index 4ec45b3..a4f0a8a 100644
15302--- a/arch/x86/include/asm/switch_to.h
15303+++ b/arch/x86/include/asm/switch_to.h
15304@@ -108,7 +108,7 @@ do { \
15305 "call __switch_to\n\t" \
15306 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15307 __switch_canary \
15308- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15309+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15310 "movq %%rax,%%rdi\n\t" \
15311 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15312 "jnz ret_from_fork\n\t" \
15313@@ -119,7 +119,7 @@ do { \
15314 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15315 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15316 [_tif_fork] "i" (_TIF_FORK), \
15317- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15318+ [thread_info] "m" (current_tinfo), \
15319 [current_task] "m" (current_task) \
15320 __switch_canary_iparam \
15321 : "memory", "cc" __EXTRA_CLOBBER)
15322diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15323index 2d946e6..e453ec4 100644
15324--- a/arch/x86/include/asm/thread_info.h
15325+++ b/arch/x86/include/asm/thread_info.h
15326@@ -10,6 +10,7 @@
15327 #include <linux/compiler.h>
15328 #include <asm/page.h>
15329 #include <asm/types.h>
15330+#include <asm/percpu.h>
15331
15332 /*
15333 * low level task data that entry.S needs immediate access to
15334@@ -24,7 +25,6 @@ struct exec_domain;
15335 #include <linux/atomic.h>
15336
15337 struct thread_info {
15338- struct task_struct *task; /* main task structure */
15339 struct exec_domain *exec_domain; /* execution domain */
15340 __u32 flags; /* low level flags */
15341 __u32 status; /* thread synchronous flags */
15342@@ -34,19 +34,13 @@ struct thread_info {
15343 mm_segment_t addr_limit;
15344 struct restart_block restart_block;
15345 void __user *sysenter_return;
15346-#ifdef CONFIG_X86_32
15347- unsigned long previous_esp; /* ESP of the previous stack in
15348- case of nested (IRQ) stacks
15349- */
15350- __u8 supervisor_stack[0];
15351-#endif
15352+ unsigned long lowest_stack;
15353 unsigned int sig_on_uaccess_error:1;
15354 unsigned int uaccess_err:1; /* uaccess failed */
15355 };
15356
15357-#define INIT_THREAD_INFO(tsk) \
15358+#define INIT_THREAD_INFO \
15359 { \
15360- .task = &tsk, \
15361 .exec_domain = &default_exec_domain, \
15362 .flags = 0, \
15363 .cpu = 0, \
15364@@ -57,7 +51,7 @@ struct thread_info {
15365 }, \
15366 }
15367
15368-#define init_thread_info (init_thread_union.thread_info)
15369+#define init_thread_info (init_thread_union.stack)
15370 #define init_stack (init_thread_union.stack)
15371
15372 #else /* !__ASSEMBLY__ */
15373@@ -98,6 +92,7 @@ struct thread_info {
15374 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15375 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15376 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15377+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15378
15379 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15380 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15381@@ -122,17 +117,18 @@ struct thread_info {
15382 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15383 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15384 #define _TIF_X32 (1 << TIF_X32)
15385+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15386
15387 /* work to do in syscall_trace_enter() */
15388 #define _TIF_WORK_SYSCALL_ENTRY \
15389 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15390 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15391- _TIF_NOHZ)
15392+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15393
15394 /* work to do in syscall_trace_leave() */
15395 #define _TIF_WORK_SYSCALL_EXIT \
15396 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15397- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15398+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15399
15400 /* work to do on interrupt/exception return */
15401 #define _TIF_WORK_MASK \
15402@@ -143,7 +139,7 @@ struct thread_info {
15403 /* work to do on any return to user space */
15404 #define _TIF_ALLWORK_MASK \
15405 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15406- _TIF_NOHZ)
15407+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15408
15409 /* Only used for 64 bit */
15410 #define _TIF_DO_NOTIFY_MASK \
15411@@ -159,45 +155,40 @@ struct thread_info {
15412
15413 #define PREEMPT_ACTIVE 0x10000000
15414
15415-#ifdef CONFIG_X86_32
15416-
15417-#define STACK_WARN (THREAD_SIZE/8)
15418-/*
15419- * macros/functions for gaining access to the thread information structure
15420- *
15421- * preempt_count needs to be 1 initially, until the scheduler is functional.
15422- */
15423-#ifndef __ASSEMBLY__
15424-
15425-
15426-/* how to get the current stack pointer from C */
15427-register unsigned long current_stack_pointer asm("esp") __used;
15428-
15429-/* how to get the thread information struct from C */
15430-static inline struct thread_info *current_thread_info(void)
15431-{
15432- return (struct thread_info *)
15433- (current_stack_pointer & ~(THREAD_SIZE - 1));
15434-}
15435-
15436-#else /* !__ASSEMBLY__ */
15437-
15438+#ifdef __ASSEMBLY__
15439 /* how to get the thread information struct from ASM */
15440 #define GET_THREAD_INFO(reg) \
15441- movl $-THREAD_SIZE, reg; \
15442- andl %esp, reg
15443+ mov PER_CPU_VAR(current_tinfo), reg
15444
15445 /* use this one if reg already contains %esp */
15446-#define GET_THREAD_INFO_WITH_ESP(reg) \
15447- andl $-THREAD_SIZE, reg
15448+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15449+#else
15450+/* how to get the thread information struct from C */
15451+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15452+
15453+static __always_inline struct thread_info *current_thread_info(void)
15454+{
15455+ return this_cpu_read_stable(current_tinfo);
15456+}
15457+#endif
15458+
15459+#ifdef CONFIG_X86_32
15460+
15461+#define STACK_WARN (THREAD_SIZE/8)
15462+/*
15463+ * macros/functions for gaining access to the thread information structure
15464+ *
15465+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15466+ */
15467+#ifndef __ASSEMBLY__
15468+
15469+/* how to get the current stack pointer from C */
15470+register unsigned long current_stack_pointer asm("esp") __used;
15471
15472 #endif
15473
15474 #else /* X86_32 */
15475
15476-#include <asm/percpu.h>
15477-#define KERNEL_STACK_OFFSET (5*8)
15478-
15479 /*
15480 * macros/functions for gaining access to the thread information structure
15481 * preempt_count needs to be 1 initially, until the scheduler is functional.
15482@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15483 #ifndef __ASSEMBLY__
15484 DECLARE_PER_CPU(unsigned long, kernel_stack);
15485
15486-static inline struct thread_info *current_thread_info(void)
15487-{
15488- struct thread_info *ti;
15489- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15490- KERNEL_STACK_OFFSET - THREAD_SIZE);
15491- return ti;
15492-}
15493-
15494-#else /* !__ASSEMBLY__ */
15495-
15496-/* how to get the thread information struct from ASM */
15497-#define GET_THREAD_INFO(reg) \
15498- movq PER_CPU_VAR(kernel_stack),reg ; \
15499- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15500-
15501-/*
15502- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15503- * a certain register (to be used in assembler memory operands).
15504- */
15505-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15506-
15507+/* how to get the current stack pointer from C */
15508+register unsigned long current_stack_pointer asm("rsp") __used;
15509 #endif
15510
15511 #endif /* !X86_32 */
15512@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15513 extern void arch_task_cache_init(void);
15514 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15515 extern void arch_release_task_struct(struct task_struct *tsk);
15516+
15517+#define __HAVE_THREAD_FUNCTIONS
15518+#define task_thread_info(task) (&(task)->tinfo)
15519+#define task_stack_page(task) ((task)->stack)
15520+#define setup_thread_stack(p, org) do {} while (0)
15521+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15522+
15523 #endif
15524 #endif /* _ASM_X86_THREAD_INFO_H */
15525diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15526index 1709801..0a60f2f 100644
15527--- a/arch/x86/include/asm/uaccess.h
15528+++ b/arch/x86/include/asm/uaccess.h
15529@@ -7,6 +7,7 @@
15530 #include <linux/compiler.h>
15531 #include <linux/thread_info.h>
15532 #include <linux/string.h>
15533+#include <linux/sched.h>
15534 #include <asm/asm.h>
15535 #include <asm/page.h>
15536 #include <asm/smap.h>
15537@@ -29,7 +30,12 @@
15538
15539 #define get_ds() (KERNEL_DS)
15540 #define get_fs() (current_thread_info()->addr_limit)
15541+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15542+void __set_fs(mm_segment_t x);
15543+void set_fs(mm_segment_t x);
15544+#else
15545 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15546+#endif
15547
15548 #define segment_eq(a, b) ((a).seg == (b).seg)
15549
15550@@ -77,8 +83,33 @@
15551 * checks that the pointer is in the user space range - after calling
15552 * this function, memory access functions may still return -EFAULT.
15553 */
15554-#define access_ok(type, addr, size) \
15555- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15556+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15557+#define access_ok(type, addr, size) \
15558+({ \
15559+ long __size = size; \
15560+ unsigned long __addr = (unsigned long)addr; \
15561+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15562+ unsigned long __end_ao = __addr + __size - 1; \
15563+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15564+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15565+ while(__addr_ao <= __end_ao) { \
15566+ char __c_ao; \
15567+ __addr_ao += PAGE_SIZE; \
15568+ if (__size > PAGE_SIZE) \
15569+ cond_resched(); \
15570+ if (__get_user(__c_ao, (char __user *)__addr)) \
15571+ break; \
15572+ if (type != VERIFY_WRITE) { \
15573+ __addr = __addr_ao; \
15574+ continue; \
15575+ } \
15576+ if (__put_user(__c_ao, (char __user *)__addr)) \
15577+ break; \
15578+ __addr = __addr_ao; \
15579+ } \
15580+ } \
15581+ __ret_ao; \
15582+})
15583
15584 /*
15585 * The exception table consists of pairs of addresses relative to the
15586@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15587 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15588 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15589
15590-
15591+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15592+#define __copyuser_seg "gs;"
15593+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15594+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15595+#else
15596+#define __copyuser_seg
15597+#define __COPYUSER_SET_ES
15598+#define __COPYUSER_RESTORE_ES
15599+#endif
15600
15601 #ifdef CONFIG_X86_32
15602 #define __put_user_asm_u64(x, addr, err, errret) \
15603 asm volatile(ASM_STAC "\n" \
15604- "1: movl %%eax,0(%2)\n" \
15605- "2: movl %%edx,4(%2)\n" \
15606+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15607+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15608 "3: " ASM_CLAC "\n" \
15609 ".section .fixup,\"ax\"\n" \
15610 "4: movl %3,%0\n" \
15611@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15612
15613 #define __put_user_asm_ex_u64(x, addr) \
15614 asm volatile(ASM_STAC "\n" \
15615- "1: movl %%eax,0(%1)\n" \
15616- "2: movl %%edx,4(%1)\n" \
15617+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15618+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15619 "3: " ASM_CLAC "\n" \
15620 _ASM_EXTABLE_EX(1b, 2b) \
15621 _ASM_EXTABLE_EX(2b, 3b) \
15622@@ -259,7 +298,7 @@ extern void __put_user_8(void);
15623 __typeof__(*(ptr)) __pu_val; \
15624 __chk_user_ptr(ptr); \
15625 might_fault(); \
15626- __pu_val = x; \
15627+ __pu_val = (x); \
15628 switch (sizeof(*(ptr))) { \
15629 case 1: \
15630 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15631@@ -358,7 +397,7 @@ do { \
15632
15633 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15634 asm volatile(ASM_STAC "\n" \
15635- "1: mov"itype" %2,%"rtype"1\n" \
15636+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15637 "2: " ASM_CLAC "\n" \
15638 ".section .fixup,\"ax\"\n" \
15639 "3: mov %3,%0\n" \
15640@@ -366,7 +405,7 @@ do { \
15641 " jmp 2b\n" \
15642 ".previous\n" \
15643 _ASM_EXTABLE(1b, 3b) \
15644- : "=r" (err), ltype(x) \
15645+ : "=r" (err), ltype (x) \
15646 : "m" (__m(addr)), "i" (errret), "0" (err))
15647
15648 #define __get_user_size_ex(x, ptr, size) \
15649@@ -391,7 +430,7 @@ do { \
15650 } while (0)
15651
15652 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15653- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15654+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15655 "2:\n" \
15656 _ASM_EXTABLE_EX(1b, 2b) \
15657 : ltype(x) : "m" (__m(addr)))
15658@@ -408,13 +447,24 @@ do { \
15659 int __gu_err; \
15660 unsigned long __gu_val; \
15661 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15662- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15663+ (x) = (__typeof__(*(ptr)))__gu_val; \
15664 __gu_err; \
15665 })
15666
15667 /* FIXME: this hack is definitely wrong -AK */
15668 struct __large_struct { unsigned long buf[100]; };
15669-#define __m(x) (*(struct __large_struct __user *)(x))
15670+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15671+#define ____m(x) \
15672+({ \
15673+ unsigned long ____x = (unsigned long)(x); \
15674+ if (____x < PAX_USER_SHADOW_BASE) \
15675+ ____x += PAX_USER_SHADOW_BASE; \
15676+ (void __user *)____x; \
15677+})
15678+#else
15679+#define ____m(x) (x)
15680+#endif
15681+#define __m(x) (*(struct __large_struct __user *)____m(x))
15682
15683 /*
15684 * Tell gcc we read from memory instead of writing: this is because
15685@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15686 */
15687 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15688 asm volatile(ASM_STAC "\n" \
15689- "1: mov"itype" %"rtype"1,%2\n" \
15690+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15691 "2: " ASM_CLAC "\n" \
15692 ".section .fixup,\"ax\"\n" \
15693 "3: mov %3,%0\n" \
15694@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15695 ".previous\n" \
15696 _ASM_EXTABLE(1b, 3b) \
15697 : "=r"(err) \
15698- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15699+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15700
15701 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15702- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15703+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15704 "2:\n" \
15705 _ASM_EXTABLE_EX(1b, 2b) \
15706 : : ltype(x), "m" (__m(addr)))
15707@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15708 * On error, the variable @x is set to zero.
15709 */
15710
15711+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15712+#define __get_user(x, ptr) get_user((x), (ptr))
15713+#else
15714 #define __get_user(x, ptr) \
15715 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15716+#endif
15717
15718 /**
15719 * __put_user: - Write a simple value into user space, with less checking.
15720@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15721 * Returns zero on success, or -EFAULT on error.
15722 */
15723
15724+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15725+#define __put_user(x, ptr) put_user((x), (ptr))
15726+#else
15727 #define __put_user(x, ptr) \
15728 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15729+#endif
15730
15731 #define __get_user_unaligned __get_user
15732 #define __put_user_unaligned __put_user
15733@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15734 #define get_user_ex(x, ptr) do { \
15735 unsigned long __gue_val; \
15736 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15737- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15738+ (x) = (__typeof__(*(ptr)))__gue_val; \
15739 } while (0)
15740
15741 #define put_user_try uaccess_try
15742@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15743 extern __must_check long strlen_user(const char __user *str);
15744 extern __must_check long strnlen_user(const char __user *str, long n);
15745
15746-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15747-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15748+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15749+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15750
15751 /*
15752 * movsl can be slow when source and dest are not both 8-byte aligned
15753diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15754index 7f760a9..04b1c65 100644
15755--- a/arch/x86/include/asm/uaccess_32.h
15756+++ b/arch/x86/include/asm/uaccess_32.h
15757@@ -11,15 +11,15 @@
15758 #include <asm/page.h>
15759
15760 unsigned long __must_check __copy_to_user_ll
15761- (void __user *to, const void *from, unsigned long n);
15762+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15763 unsigned long __must_check __copy_from_user_ll
15764- (void *to, const void __user *from, unsigned long n);
15765+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15766 unsigned long __must_check __copy_from_user_ll_nozero
15767- (void *to, const void __user *from, unsigned long n);
15768+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15769 unsigned long __must_check __copy_from_user_ll_nocache
15770- (void *to, const void __user *from, unsigned long n);
15771+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15772 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15773- (void *to, const void __user *from, unsigned long n);
15774+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15775
15776 /**
15777 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15778@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15779 static __always_inline unsigned long __must_check
15780 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15781 {
15782+ if ((long)n < 0)
15783+ return n;
15784+
15785+ check_object_size(from, n, true);
15786+
15787 if (__builtin_constant_p(n)) {
15788 unsigned long ret;
15789
15790@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15791 __copy_to_user(void __user *to, const void *from, unsigned long n)
15792 {
15793 might_fault();
15794+
15795 return __copy_to_user_inatomic(to, from, n);
15796 }
15797
15798 static __always_inline unsigned long
15799 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15800 {
15801+ if ((long)n < 0)
15802+ return n;
15803+
15804 /* Avoid zeroing the tail if the copy fails..
15805 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15806 * but as the zeroing behaviour is only significant when n is not
15807@@ -137,6 +146,12 @@ static __always_inline unsigned long
15808 __copy_from_user(void *to, const void __user *from, unsigned long n)
15809 {
15810 might_fault();
15811+
15812+ if ((long)n < 0)
15813+ return n;
15814+
15815+ check_object_size(to, n, false);
15816+
15817 if (__builtin_constant_p(n)) {
15818 unsigned long ret;
15819
15820@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15821 const void __user *from, unsigned long n)
15822 {
15823 might_fault();
15824+
15825+ if ((long)n < 0)
15826+ return n;
15827+
15828 if (__builtin_constant_p(n)) {
15829 unsigned long ret;
15830
15831@@ -181,15 +200,19 @@ static __always_inline unsigned long
15832 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15833 unsigned long n)
15834 {
15835- return __copy_from_user_ll_nocache_nozero(to, from, n);
15836+ if ((long)n < 0)
15837+ return n;
15838+
15839+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15840 }
15841
15842-unsigned long __must_check copy_to_user(void __user *to,
15843- const void *from, unsigned long n);
15844-unsigned long __must_check _copy_from_user(void *to,
15845- const void __user *from,
15846- unsigned long n);
15847-
15848+extern void copy_to_user_overflow(void)
15849+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15850+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15851+#else
15852+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15853+#endif
15854+;
15855
15856 extern void copy_from_user_overflow(void)
15857 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15858@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15859 #endif
15860 ;
15861
15862-static inline unsigned long __must_check copy_from_user(void *to,
15863- const void __user *from,
15864- unsigned long n)
15865+/**
15866+ * copy_to_user: - Copy a block of data into user space.
15867+ * @to: Destination address, in user space.
15868+ * @from: Source address, in kernel space.
15869+ * @n: Number of bytes to copy.
15870+ *
15871+ * Context: User context only. This function may sleep.
15872+ *
15873+ * Copy data from kernel space to user space.
15874+ *
15875+ * Returns number of bytes that could not be copied.
15876+ * On success, this will be zero.
15877+ */
15878+static inline unsigned long __must_check
15879+copy_to_user(void __user *to, const void *from, unsigned long n)
15880 {
15881- int sz = __compiletime_object_size(to);
15882+ size_t sz = __compiletime_object_size(from);
15883
15884- if (likely(sz == -1 || sz >= n))
15885- n = _copy_from_user(to, from, n);
15886- else
15887+ if (unlikely(sz != (size_t)-1 && sz < n))
15888+ copy_to_user_overflow();
15889+ else if (access_ok(VERIFY_WRITE, to, n))
15890+ n = __copy_to_user(to, from, n);
15891+ return n;
15892+}
15893+
15894+/**
15895+ * copy_from_user: - Copy a block of data from user space.
15896+ * @to: Destination address, in kernel space.
15897+ * @from: Source address, in user space.
15898+ * @n: Number of bytes to copy.
15899+ *
15900+ * Context: User context only. This function may sleep.
15901+ *
15902+ * Copy data from user space to kernel space.
15903+ *
15904+ * Returns number of bytes that could not be copied.
15905+ * On success, this will be zero.
15906+ *
15907+ * If some data could not be copied, this function will pad the copied
15908+ * data to the requested size using zero bytes.
15909+ */
15910+static inline unsigned long __must_check
15911+copy_from_user(void *to, const void __user *from, unsigned long n)
15912+{
15913+ size_t sz = __compiletime_object_size(to);
15914+
15915+ check_object_size(to, n, false);
15916+
15917+ if (unlikely(sz != (size_t)-1 && sz < n))
15918 copy_from_user_overflow();
15919-
15920+ else if (access_ok(VERIFY_READ, from, n))
15921+ n = __copy_from_user(to, from, n);
15922+ else if ((long)n > 0)
15923+ memset(to, 0, n);
15924 return n;
15925 }
15926
15927diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15928index 142810c..747941a 100644
15929--- a/arch/x86/include/asm/uaccess_64.h
15930+++ b/arch/x86/include/asm/uaccess_64.h
15931@@ -10,6 +10,9 @@
15932 #include <asm/alternative.h>
15933 #include <asm/cpufeature.h>
15934 #include <asm/page.h>
15935+#include <asm/pgtable.h>
15936+
15937+#define set_fs(x) (current_thread_info()->addr_limit = (x))
15938
15939 /*
15940 * Copy To/From Userspace
15941@@ -17,13 +20,13 @@
15942
15943 /* Handles exceptions in both to and from, but doesn't do access_ok */
15944 __must_check unsigned long
15945-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15946+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15947 __must_check unsigned long
15948-copy_user_generic_string(void *to, const void *from, unsigned len);
15949+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15950 __must_check unsigned long
15951-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15952+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15953
15954-static __always_inline __must_check unsigned long
15955+static __always_inline __must_check __size_overflow(3) unsigned long
15956 copy_user_generic(void *to, const void *from, unsigned len)
15957 {
15958 unsigned ret;
15959@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15960 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15961 "=d" (len)),
15962 "1" (to), "2" (from), "3" (len)
15963- : "memory", "rcx", "r8", "r9", "r10", "r11");
15964+ : "memory", "rcx", "r8", "r9", "r11");
15965 return ret;
15966 }
15967
15968+static __always_inline __must_check unsigned long
15969+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15970+static __always_inline __must_check unsigned long
15971+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15972 __must_check unsigned long
15973-_copy_to_user(void __user *to, const void *from, unsigned len);
15974-__must_check unsigned long
15975-_copy_from_user(void *to, const void __user *from, unsigned len);
15976-__must_check unsigned long
15977-copy_in_user(void __user *to, const void __user *from, unsigned len);
15978+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15979+
15980+extern void copy_to_user_overflow(void)
15981+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15982+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15983+#else
15984+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15985+#endif
15986+;
15987+
15988+extern void copy_from_user_overflow(void)
15989+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15990+ __compiletime_error("copy_from_user() buffer size is not provably correct")
15991+#else
15992+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
15993+#endif
15994+;
15995
15996 static inline unsigned long __must_check copy_from_user(void *to,
15997 const void __user *from,
15998 unsigned long n)
15999 {
16000- int sz = __compiletime_object_size(to);
16001-
16002 might_fault();
16003- if (likely(sz == -1 || sz >= n))
16004- n = _copy_from_user(to, from, n);
16005-#ifdef CONFIG_DEBUG_VM
16006- else
16007- WARN(1, "Buffer overflow detected!\n");
16008-#endif
16009+
16010+ check_object_size(to, n, false);
16011+
16012+ if (access_ok(VERIFY_READ, from, n))
16013+ n = __copy_from_user(to, from, n);
16014+ else if (n < INT_MAX)
16015+ memset(to, 0, n);
16016 return n;
16017 }
16018
16019 static __always_inline __must_check
16020-int copy_to_user(void __user *dst, const void *src, unsigned size)
16021+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16022 {
16023 might_fault();
16024
16025- return _copy_to_user(dst, src, size);
16026+ if (access_ok(VERIFY_WRITE, dst, size))
16027+ size = __copy_to_user(dst, src, size);
16028+ return size;
16029 }
16030
16031 static __always_inline __must_check
16032-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16033+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16034 {
16035- int ret = 0;
16036+ size_t sz = __compiletime_object_size(dst);
16037+ unsigned ret = 0;
16038
16039 might_fault();
16040+
16041+ if (size > INT_MAX)
16042+ return size;
16043+
16044+ check_object_size(dst, size, false);
16045+
16046+#ifdef CONFIG_PAX_MEMORY_UDEREF
16047+ if (!__access_ok(VERIFY_READ, src, size))
16048+ return size;
16049+#endif
16050+
16051+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16052+ copy_from_user_overflow();
16053+ return size;
16054+ }
16055+
16056 if (!__builtin_constant_p(size))
16057- return copy_user_generic(dst, (__force void *)src, size);
16058+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16059 switch (size) {
16060- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16061+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16062 ret, "b", "b", "=q", 1);
16063 return ret;
16064- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16065+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16066 ret, "w", "w", "=r", 2);
16067 return ret;
16068- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16069+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16070 ret, "l", "k", "=r", 4);
16071 return ret;
16072- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16073+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16074 ret, "q", "", "=r", 8);
16075 return ret;
16076 case 10:
16077- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16078+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16079 ret, "q", "", "=r", 10);
16080 if (unlikely(ret))
16081 return ret;
16082 __get_user_asm(*(u16 *)(8 + (char *)dst),
16083- (u16 __user *)(8 + (char __user *)src),
16084+ (const u16 __user *)(8 + (const char __user *)src),
16085 ret, "w", "w", "=r", 2);
16086 return ret;
16087 case 16:
16088- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16089+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16090 ret, "q", "", "=r", 16);
16091 if (unlikely(ret))
16092 return ret;
16093 __get_user_asm(*(u64 *)(8 + (char *)dst),
16094- (u64 __user *)(8 + (char __user *)src),
16095+ (const u64 __user *)(8 + (const char __user *)src),
16096 ret, "q", "", "=r", 8);
16097 return ret;
16098 default:
16099- return copy_user_generic(dst, (__force void *)src, size);
16100+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16101 }
16102 }
16103
16104 static __always_inline __must_check
16105-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16106+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16107 {
16108- int ret = 0;
16109+ size_t sz = __compiletime_object_size(src);
16110+ unsigned ret = 0;
16111
16112 might_fault();
16113+
16114+ if (size > INT_MAX)
16115+ return size;
16116+
16117+ check_object_size(src, size, true);
16118+
16119+#ifdef CONFIG_PAX_MEMORY_UDEREF
16120+ if (!__access_ok(VERIFY_WRITE, dst, size))
16121+ return size;
16122+#endif
16123+
16124+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16125+ copy_to_user_overflow();
16126+ return size;
16127+ }
16128+
16129 if (!__builtin_constant_p(size))
16130- return copy_user_generic((__force void *)dst, src, size);
16131+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16132 switch (size) {
16133- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16134+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16135 ret, "b", "b", "iq", 1);
16136 return ret;
16137- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16138+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16139 ret, "w", "w", "ir", 2);
16140 return ret;
16141- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16142+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16143 ret, "l", "k", "ir", 4);
16144 return ret;
16145- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16146+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16147 ret, "q", "", "er", 8);
16148 return ret;
16149 case 10:
16150- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16151+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16152 ret, "q", "", "er", 10);
16153 if (unlikely(ret))
16154 return ret;
16155 asm("":::"memory");
16156- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16157+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16158 ret, "w", "w", "ir", 2);
16159 return ret;
16160 case 16:
16161- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16162+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16163 ret, "q", "", "er", 16);
16164 if (unlikely(ret))
16165 return ret;
16166 asm("":::"memory");
16167- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16168+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16169 ret, "q", "", "er", 8);
16170 return ret;
16171 default:
16172- return copy_user_generic((__force void *)dst, src, size);
16173+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16174 }
16175 }
16176
16177 static __always_inline __must_check
16178-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16179+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16180 {
16181- int ret = 0;
16182+ unsigned ret = 0;
16183
16184 might_fault();
16185+
16186+ if (size > INT_MAX)
16187+ return size;
16188+
16189+#ifdef CONFIG_PAX_MEMORY_UDEREF
16190+ if (!__access_ok(VERIFY_READ, src, size))
16191+ return size;
16192+ if (!__access_ok(VERIFY_WRITE, dst, size))
16193+ return size;
16194+#endif
16195+
16196 if (!__builtin_constant_p(size))
16197- return copy_user_generic((__force void *)dst,
16198- (__force void *)src, size);
16199+ return copy_user_generic((__force_kernel void *)____m(dst),
16200+ (__force_kernel const void *)____m(src), size);
16201 switch (size) {
16202 case 1: {
16203 u8 tmp;
16204- __get_user_asm(tmp, (u8 __user *)src,
16205+ __get_user_asm(tmp, (const u8 __user *)src,
16206 ret, "b", "b", "=q", 1);
16207 if (likely(!ret))
16208 __put_user_asm(tmp, (u8 __user *)dst,
16209@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16210 }
16211 case 2: {
16212 u16 tmp;
16213- __get_user_asm(tmp, (u16 __user *)src,
16214+ __get_user_asm(tmp, (const u16 __user *)src,
16215 ret, "w", "w", "=r", 2);
16216 if (likely(!ret))
16217 __put_user_asm(tmp, (u16 __user *)dst,
16218@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16219
16220 case 4: {
16221 u32 tmp;
16222- __get_user_asm(tmp, (u32 __user *)src,
16223+ __get_user_asm(tmp, (const u32 __user *)src,
16224 ret, "l", "k", "=r", 4);
16225 if (likely(!ret))
16226 __put_user_asm(tmp, (u32 __user *)dst,
16227@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16228 }
16229 case 8: {
16230 u64 tmp;
16231- __get_user_asm(tmp, (u64 __user *)src,
16232+ __get_user_asm(tmp, (const u64 __user *)src,
16233 ret, "q", "", "=r", 8);
16234 if (likely(!ret))
16235 __put_user_asm(tmp, (u64 __user *)dst,
16236@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16237 return ret;
16238 }
16239 default:
16240- return copy_user_generic((__force void *)dst,
16241- (__force void *)src, size);
16242+ return copy_user_generic((__force_kernel void *)____m(dst),
16243+ (__force_kernel const void *)____m(src), size);
16244 }
16245 }
16246
16247 static __must_check __always_inline int
16248-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16249+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16250 {
16251- return copy_user_generic(dst, (__force const void *)src, size);
16252+ if (size > INT_MAX)
16253+ return size;
16254+
16255+#ifdef CONFIG_PAX_MEMORY_UDEREF
16256+ if (!__access_ok(VERIFY_READ, src, size))
16257+ return size;
16258+#endif
16259+
16260+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16261 }
16262
16263-static __must_check __always_inline int
16264-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16265+static __must_check __always_inline unsigned long
16266+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16267 {
16268- return copy_user_generic((__force void *)dst, src, size);
16269+ if (size > INT_MAX)
16270+ return size;
16271+
16272+#ifdef CONFIG_PAX_MEMORY_UDEREF
16273+ if (!__access_ok(VERIFY_WRITE, dst, size))
16274+ return size;
16275+#endif
16276+
16277+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16278 }
16279
16280-extern long __copy_user_nocache(void *dst, const void __user *src,
16281- unsigned size, int zerorest);
16282+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16283+ unsigned long size, int zerorest) __size_overflow(3);
16284
16285-static inline int
16286-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16287+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16288 {
16289 might_sleep();
16290+
16291+ if (size > INT_MAX)
16292+ return size;
16293+
16294+#ifdef CONFIG_PAX_MEMORY_UDEREF
16295+ if (!__access_ok(VERIFY_READ, src, size))
16296+ return size;
16297+#endif
16298+
16299 return __copy_user_nocache(dst, src, size, 1);
16300 }
16301
16302-static inline int
16303-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16304- unsigned size)
16305+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16306+ unsigned long size)
16307 {
16308+ if (size > INT_MAX)
16309+ return size;
16310+
16311+#ifdef CONFIG_PAX_MEMORY_UDEREF
16312+ if (!__access_ok(VERIFY_READ, src, size))
16313+ return size;
16314+#endif
16315+
16316 return __copy_user_nocache(dst, src, size, 0);
16317 }
16318
16319-unsigned long
16320-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16321+extern unsigned long
16322+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16323
16324 #endif /* _ASM_X86_UACCESS_64_H */
16325diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16326index 5b238981..77fdd78 100644
16327--- a/arch/x86/include/asm/word-at-a-time.h
16328+++ b/arch/x86/include/asm/word-at-a-time.h
16329@@ -11,7 +11,7 @@
16330 * and shift, for example.
16331 */
16332 struct word_at_a_time {
16333- const unsigned long one_bits, high_bits;
16334+ unsigned long one_bits, high_bits;
16335 };
16336
16337 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16338diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16339index 5769349..a3d3e2a 100644
16340--- a/arch/x86/include/asm/x86_init.h
16341+++ b/arch/x86/include/asm/x86_init.h
16342@@ -141,7 +141,7 @@ struct x86_init_ops {
16343 struct x86_init_timers timers;
16344 struct x86_init_iommu iommu;
16345 struct x86_init_pci pci;
16346-};
16347+} __no_const;
16348
16349 /**
16350 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16351@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16352 void (*setup_percpu_clockev)(void);
16353 void (*early_percpu_clock_init)(void);
16354 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16355-};
16356+} __no_const;
16357
16358 /**
16359 * struct x86_platform_ops - platform specific runtime functions
16360@@ -178,7 +178,7 @@ struct x86_platform_ops {
16361 void (*save_sched_clock_state)(void);
16362 void (*restore_sched_clock_state)(void);
16363 void (*apic_post_init)(void);
16364-};
16365+} __no_const;
16366
16367 struct pci_dev;
16368
16369@@ -187,14 +187,14 @@ struct x86_msi_ops {
16370 void (*teardown_msi_irq)(unsigned int irq);
16371 void (*teardown_msi_irqs)(struct pci_dev *dev);
16372 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16373-};
16374+} __no_const;
16375
16376 struct x86_io_apic_ops {
16377 void (*init) (void);
16378 unsigned int (*read) (unsigned int apic, unsigned int reg);
16379 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16380 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16381-};
16382+} __no_const;
16383
16384 extern struct x86_init_ops x86_init;
16385 extern struct x86_cpuinit_ops x86_cpuinit;
16386diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16387index 0415cda..b43d877 100644
16388--- a/arch/x86/include/asm/xsave.h
16389+++ b/arch/x86/include/asm/xsave.h
16390@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16391 return -EFAULT;
16392
16393 __asm__ __volatile__(ASM_STAC "\n"
16394- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16395+ "1:"
16396+ __copyuser_seg
16397+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16398 "2: " ASM_CLAC "\n"
16399 ".section .fixup,\"ax\"\n"
16400 "3: movl $-1,%[err]\n"
16401@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16402 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16403 {
16404 int err;
16405- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16406+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16407 u32 lmask = mask;
16408 u32 hmask = mask >> 32;
16409
16410 __asm__ __volatile__(ASM_STAC "\n"
16411- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16412+ "1:"
16413+ __copyuser_seg
16414+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16415 "2: " ASM_CLAC "\n"
16416 ".section .fixup,\"ax\"\n"
16417 "3: movl $-1,%[err]\n"
16418diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16419index bbae024..e1528f9 100644
16420--- a/arch/x86/include/uapi/asm/e820.h
16421+++ b/arch/x86/include/uapi/asm/e820.h
16422@@ -63,7 +63,7 @@ struct e820map {
16423 #define ISA_START_ADDRESS 0xa0000
16424 #define ISA_END_ADDRESS 0x100000
16425
16426-#define BIOS_BEGIN 0x000a0000
16427+#define BIOS_BEGIN 0x000c0000
16428 #define BIOS_END 0x00100000
16429
16430 #define BIOS_ROM_BASE 0xffe00000
16431diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16432index 34e923a..0c6bb6e 100644
16433--- a/arch/x86/kernel/Makefile
16434+++ b/arch/x86/kernel/Makefile
16435@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16436 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16437 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16438 obj-y += probe_roms.o
16439-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16440+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16441 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16442 obj-y += syscall_$(BITS).o
16443 obj-$(CONFIG_X86_64) += vsyscall_64.o
16444diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16445index bacf4b0..4ede72e 100644
16446--- a/arch/x86/kernel/acpi/boot.c
16447+++ b/arch/x86/kernel/acpi/boot.c
16448@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16449 * If your system is blacklisted here, but you find that acpi=force
16450 * works for you, please contact linux-acpi@vger.kernel.org
16451 */
16452-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16453+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16454 /*
16455 * Boxes that need ACPI disabled
16456 */
16457@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16458 };
16459
16460 /* second table for DMI checks that should run after early-quirks */
16461-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16462+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16463 /*
16464 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16465 * which includes some code which overrides all temperature
16466diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16467index d5e0d71..6533e08 100644
16468--- a/arch/x86/kernel/acpi/sleep.c
16469+++ b/arch/x86/kernel/acpi/sleep.c
16470@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16471 #else /* CONFIG_64BIT */
16472 #ifdef CONFIG_SMP
16473 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16474+
16475+ pax_open_kernel();
16476 early_gdt_descr.address =
16477 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16478+ pax_close_kernel();
16479+
16480 initial_gs = per_cpu_offset(smp_processor_id());
16481 #endif
16482 initial_code = (unsigned long)wakeup_long64;
16483diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16484index 13ab720..95d5442 100644
16485--- a/arch/x86/kernel/acpi/wakeup_32.S
16486+++ b/arch/x86/kernel/acpi/wakeup_32.S
16487@@ -30,13 +30,11 @@ wakeup_pmode_return:
16488 # and restore the stack ... but you need gdt for this to work
16489 movl saved_context_esp, %esp
16490
16491- movl %cs:saved_magic, %eax
16492- cmpl $0x12345678, %eax
16493+ cmpl $0x12345678, saved_magic
16494 jne bogus_magic
16495
16496 # jump to place where we left off
16497- movl saved_eip, %eax
16498- jmp *%eax
16499+ jmp *(saved_eip)
16500
16501 bogus_magic:
16502 jmp bogus_magic
16503diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16504index ef5ccca..bd83949 100644
16505--- a/arch/x86/kernel/alternative.c
16506+++ b/arch/x86/kernel/alternative.c
16507@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16508 */
16509 for (a = start; a < end; a++) {
16510 instr = (u8 *)&a->instr_offset + a->instr_offset;
16511+
16512+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16513+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16514+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16515+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16516+#endif
16517+
16518 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16519 BUG_ON(a->replacementlen > a->instrlen);
16520 BUG_ON(a->instrlen > sizeof(insnbuf));
16521@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16522 for (poff = start; poff < end; poff++) {
16523 u8 *ptr = (u8 *)poff + *poff;
16524
16525+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16526+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16527+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16528+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16529+#endif
16530+
16531 if (!*poff || ptr < text || ptr >= text_end)
16532 continue;
16533 /* turn DS segment override prefix into lock prefix */
16534- if (*ptr == 0x3e)
16535+ if (*ktla_ktva(ptr) == 0x3e)
16536 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16537 }
16538 mutex_unlock(&text_mutex);
16539@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16540 for (poff = start; poff < end; poff++) {
16541 u8 *ptr = (u8 *)poff + *poff;
16542
16543+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16544+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16545+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16546+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16547+#endif
16548+
16549 if (!*poff || ptr < text || ptr >= text_end)
16550 continue;
16551 /* turn lock prefix into DS segment override prefix */
16552- if (*ptr == 0xf0)
16553+ if (*ktla_ktva(ptr) == 0xf0)
16554 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16555 }
16556 mutex_unlock(&text_mutex);
16557@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16558
16559 BUG_ON(p->len > MAX_PATCH_LEN);
16560 /* prep the buffer with the original instructions */
16561- memcpy(insnbuf, p->instr, p->len);
16562+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16563 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16564 (unsigned long)p->instr, p->len);
16565
16566@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16567 if (!uniproc_patched || num_possible_cpus() == 1)
16568 free_init_pages("SMP alternatives",
16569 (unsigned long)__smp_locks,
16570- (unsigned long)__smp_locks_end);
16571+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16572 #endif
16573
16574 apply_paravirt(__parainstructions, __parainstructions_end);
16575@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16576 * instructions. And on the local CPU you need to be protected again NMI or MCE
16577 * handlers seeing an inconsistent instruction while you patch.
16578 */
16579-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16580+void *__kprobes text_poke_early(void *addr, const void *opcode,
16581 size_t len)
16582 {
16583 unsigned long flags;
16584 local_irq_save(flags);
16585- memcpy(addr, opcode, len);
16586+
16587+ pax_open_kernel();
16588+ memcpy(ktla_ktva(addr), opcode, len);
16589 sync_core();
16590+ pax_close_kernel();
16591+
16592 local_irq_restore(flags);
16593 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16594 that causes hangs on some VIA CPUs. */
16595@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16596 */
16597 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16598 {
16599- unsigned long flags;
16600- char *vaddr;
16601+ unsigned char *vaddr = ktla_ktva(addr);
16602 struct page *pages[2];
16603- int i;
16604+ size_t i;
16605
16606 if (!core_kernel_text((unsigned long)addr)) {
16607- pages[0] = vmalloc_to_page(addr);
16608- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16609+ pages[0] = vmalloc_to_page(vaddr);
16610+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16611 } else {
16612- pages[0] = virt_to_page(addr);
16613+ pages[0] = virt_to_page(vaddr);
16614 WARN_ON(!PageReserved(pages[0]));
16615- pages[1] = virt_to_page(addr + PAGE_SIZE);
16616+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16617 }
16618 BUG_ON(!pages[0]);
16619- local_irq_save(flags);
16620- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16621- if (pages[1])
16622- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16623- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16624- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16625- clear_fixmap(FIX_TEXT_POKE0);
16626- if (pages[1])
16627- clear_fixmap(FIX_TEXT_POKE1);
16628- local_flush_tlb();
16629- sync_core();
16630- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16631- that causes hangs on some VIA CPUs. */
16632+ text_poke_early(addr, opcode, len);
16633 for (i = 0; i < len; i++)
16634- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16635- local_irq_restore(flags);
16636+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16637 return addr;
16638 }
16639
16640diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16641index cbf5121..812b537 100644
16642--- a/arch/x86/kernel/apic/apic.c
16643+++ b/arch/x86/kernel/apic/apic.c
16644@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16645 /*
16646 * Debug level, exported for io_apic.c
16647 */
16648-unsigned int apic_verbosity;
16649+int apic_verbosity;
16650
16651 int pic_mode;
16652
16653@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16654 apic_write(APIC_ESR, 0);
16655 v1 = apic_read(APIC_ESR);
16656 ack_APIC_irq();
16657- atomic_inc(&irq_err_count);
16658+ atomic_inc_unchecked(&irq_err_count);
16659
16660 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16661 smp_processor_id(), v0 , v1);
16662diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16663index 00c77cf..2dc6a2d 100644
16664--- a/arch/x86/kernel/apic/apic_flat_64.c
16665+++ b/arch/x86/kernel/apic/apic_flat_64.c
16666@@ -157,7 +157,7 @@ static int flat_probe(void)
16667 return 1;
16668 }
16669
16670-static struct apic apic_flat = {
16671+static struct apic apic_flat __read_only = {
16672 .name = "flat",
16673 .probe = flat_probe,
16674 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16675@@ -271,7 +271,7 @@ static int physflat_probe(void)
16676 return 0;
16677 }
16678
16679-static struct apic apic_physflat = {
16680+static struct apic apic_physflat __read_only = {
16681
16682 .name = "physical flat",
16683 .probe = physflat_probe,
16684diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16685index e145f28..2752888 100644
16686--- a/arch/x86/kernel/apic/apic_noop.c
16687+++ b/arch/x86/kernel/apic/apic_noop.c
16688@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16689 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16690 }
16691
16692-struct apic apic_noop = {
16693+struct apic apic_noop __read_only = {
16694 .name = "noop",
16695 .probe = noop_probe,
16696 .acpi_madt_oem_check = NULL,
16697diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16698index d50e364..543bee3 100644
16699--- a/arch/x86/kernel/apic/bigsmp_32.c
16700+++ b/arch/x86/kernel/apic/bigsmp_32.c
16701@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16702 return dmi_bigsmp;
16703 }
16704
16705-static struct apic apic_bigsmp = {
16706+static struct apic apic_bigsmp __read_only = {
16707
16708 .name = "bigsmp",
16709 .probe = probe_bigsmp,
16710diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16711index 0874799..a7a7892 100644
16712--- a/arch/x86/kernel/apic/es7000_32.c
16713+++ b/arch/x86/kernel/apic/es7000_32.c
16714@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16715 return ret && es7000_apic_is_cluster();
16716 }
16717
16718-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16719-static struct apic __refdata apic_es7000_cluster = {
16720+static struct apic apic_es7000_cluster __read_only = {
16721
16722 .name = "es7000",
16723 .probe = probe_es7000,
16724@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16725 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16726 };
16727
16728-static struct apic __refdata apic_es7000 = {
16729+static struct apic apic_es7000 __read_only = {
16730
16731 .name = "es7000",
16732 .probe = probe_es7000,
16733diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16734index b739d39..aebc14c 100644
16735--- a/arch/x86/kernel/apic/io_apic.c
16736+++ b/arch/x86/kernel/apic/io_apic.c
16737@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16738 }
16739 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16740
16741-void lock_vector_lock(void)
16742+void lock_vector_lock(void) __acquires(vector_lock)
16743 {
16744 /* Used to the online set of cpus does not change
16745 * during assign_irq_vector.
16746@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16747 raw_spin_lock(&vector_lock);
16748 }
16749
16750-void unlock_vector_lock(void)
16751+void unlock_vector_lock(void) __releases(vector_lock)
16752 {
16753 raw_spin_unlock(&vector_lock);
16754 }
16755@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16756 ack_APIC_irq();
16757 }
16758
16759-atomic_t irq_mis_count;
16760+atomic_unchecked_t irq_mis_count;
16761
16762 #ifdef CONFIG_GENERIC_PENDING_IRQ
16763 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16764@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16765 * at the cpu.
16766 */
16767 if (!(v & (1 << (i & 0x1f)))) {
16768- atomic_inc(&irq_mis_count);
16769+ atomic_inc_unchecked(&irq_mis_count);
16770
16771 eoi_ioapic_irq(irq, cfg);
16772 }
16773@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
16774
16775 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
16776 {
16777- chip->irq_print_chip = ir_print_prefix;
16778- chip->irq_ack = ir_ack_apic_edge;
16779- chip->irq_eoi = ir_ack_apic_level;
16780+ pax_open_kernel();
16781+ *(void **)&chip->irq_print_chip = ir_print_prefix;
16782+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
16783+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
16784
16785- chip->irq_set_affinity = set_remapped_irq_affinity;
16786+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
16787+ pax_close_kernel();
16788 }
16789 #endif /* CONFIG_IRQ_REMAP */
16790
16791diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16792index d661ee9..791fd33 100644
16793--- a/arch/x86/kernel/apic/numaq_32.c
16794+++ b/arch/x86/kernel/apic/numaq_32.c
16795@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16796 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16797 }
16798
16799-/* Use __refdata to keep false positive warning calm. */
16800-static struct apic __refdata apic_numaq = {
16801+static struct apic apic_numaq __read_only = {
16802
16803 .name = "NUMAQ",
16804 .probe = probe_numaq,
16805diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16806index eb35ef9..f184a21 100644
16807--- a/arch/x86/kernel/apic/probe_32.c
16808+++ b/arch/x86/kernel/apic/probe_32.c
16809@@ -72,7 +72,7 @@ static int probe_default(void)
16810 return 1;
16811 }
16812
16813-static struct apic apic_default = {
16814+static struct apic apic_default __read_only = {
16815
16816 .name = "default",
16817 .probe = probe_default,
16818diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16819index 77c95c0..434f8a4 100644
16820--- a/arch/x86/kernel/apic/summit_32.c
16821+++ b/arch/x86/kernel/apic/summit_32.c
16822@@ -486,7 +486,7 @@ void setup_summit(void)
16823 }
16824 #endif
16825
16826-static struct apic apic_summit = {
16827+static struct apic apic_summit __read_only = {
16828
16829 .name = "summit",
16830 .probe = probe_summit,
16831diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16832index c88baa4..757aee1 100644
16833--- a/arch/x86/kernel/apic/x2apic_cluster.c
16834+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16835@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16836 return notifier_from_errno(err);
16837 }
16838
16839-static struct notifier_block __refdata x2apic_cpu_notifier = {
16840+static struct notifier_block x2apic_cpu_notifier = {
16841 .notifier_call = update_clusterinfo,
16842 };
16843
16844@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16845 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16846 }
16847
16848-static struct apic apic_x2apic_cluster = {
16849+static struct apic apic_x2apic_cluster __read_only = {
16850
16851 .name = "cluster x2apic",
16852 .probe = x2apic_cluster_probe,
16853diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16854index 562a76d..a003c0f 100644
16855--- a/arch/x86/kernel/apic/x2apic_phys.c
16856+++ b/arch/x86/kernel/apic/x2apic_phys.c
16857@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16858 return apic == &apic_x2apic_phys;
16859 }
16860
16861-static struct apic apic_x2apic_phys = {
16862+static struct apic apic_x2apic_phys __read_only = {
16863
16864 .name = "physical x2apic",
16865 .probe = x2apic_phys_probe,
16866diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16867index 8cfade9..b9d04fc 100644
16868--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16869+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16870@@ -333,7 +333,7 @@ static int uv_probe(void)
16871 return apic == &apic_x2apic_uv_x;
16872 }
16873
16874-static struct apic __refdata apic_x2apic_uv_x = {
16875+static struct apic apic_x2apic_uv_x __read_only = {
16876
16877 .name = "UV large system",
16878 .probe = uv_probe,
16879diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16880index d65464e..1035d31 100644
16881--- a/arch/x86/kernel/apm_32.c
16882+++ b/arch/x86/kernel/apm_32.c
16883@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16884 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16885 * even though they are called in protected mode.
16886 */
16887-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16888+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16889 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16890
16891 static const char driver_version[] = "1.16ac"; /* no spaces */
16892@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16893 BUG_ON(cpu != 0);
16894 gdt = get_cpu_gdt_table(cpu);
16895 save_desc_40 = gdt[0x40 / 8];
16896+
16897+ pax_open_kernel();
16898 gdt[0x40 / 8] = bad_bios_desc;
16899+ pax_close_kernel();
16900
16901 apm_irq_save(flags);
16902 APM_DO_SAVE_SEGS;
16903@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16904 &call->esi);
16905 APM_DO_RESTORE_SEGS;
16906 apm_irq_restore(flags);
16907+
16908+ pax_open_kernel();
16909 gdt[0x40 / 8] = save_desc_40;
16910+ pax_close_kernel();
16911+
16912 put_cpu();
16913
16914 return call->eax & 0xff;
16915@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16916 BUG_ON(cpu != 0);
16917 gdt = get_cpu_gdt_table(cpu);
16918 save_desc_40 = gdt[0x40 / 8];
16919+
16920+ pax_open_kernel();
16921 gdt[0x40 / 8] = bad_bios_desc;
16922+ pax_close_kernel();
16923
16924 apm_irq_save(flags);
16925 APM_DO_SAVE_SEGS;
16926@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16927 &call->eax);
16928 APM_DO_RESTORE_SEGS;
16929 apm_irq_restore(flags);
16930+
16931+ pax_open_kernel();
16932 gdt[0x40 / 8] = save_desc_40;
16933+ pax_close_kernel();
16934+
16935 put_cpu();
16936 return error;
16937 }
16938@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16939 * code to that CPU.
16940 */
16941 gdt = get_cpu_gdt_table(0);
16942+
16943+ pax_open_kernel();
16944 set_desc_base(&gdt[APM_CS >> 3],
16945 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16946 set_desc_base(&gdt[APM_CS_16 >> 3],
16947 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16948 set_desc_base(&gdt[APM_DS >> 3],
16949 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16950+ pax_close_kernel();
16951
16952 proc_create("apm", 0, NULL, &apm_file_ops);
16953
16954diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16955index 2861082..6d4718e 100644
16956--- a/arch/x86/kernel/asm-offsets.c
16957+++ b/arch/x86/kernel/asm-offsets.c
16958@@ -33,6 +33,8 @@ void common(void) {
16959 OFFSET(TI_status, thread_info, status);
16960 OFFSET(TI_addr_limit, thread_info, addr_limit);
16961 OFFSET(TI_preempt_count, thread_info, preempt_count);
16962+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16963+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16964
16965 BLANK();
16966 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16967@@ -53,8 +55,26 @@ void common(void) {
16968 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16969 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16970 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16971+
16972+#ifdef CONFIG_PAX_KERNEXEC
16973+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16974 #endif
16975
16976+#ifdef CONFIG_PAX_MEMORY_UDEREF
16977+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16978+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16979+#ifdef CONFIG_X86_64
16980+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16981+#endif
16982+#endif
16983+
16984+#endif
16985+
16986+ BLANK();
16987+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16988+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16989+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16990+
16991 #ifdef CONFIG_XEN
16992 BLANK();
16993 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16994diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16995index 1b4754f..fbb4227 100644
16996--- a/arch/x86/kernel/asm-offsets_64.c
16997+++ b/arch/x86/kernel/asm-offsets_64.c
16998@@ -76,6 +76,7 @@ int main(void)
16999 BLANK();
17000 #undef ENTRY
17001
17002+ DEFINE(TSS_size, sizeof(struct tss_struct));
17003 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17004 BLANK();
17005
17006diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17007index a0e067d..9c7db16 100644
17008--- a/arch/x86/kernel/cpu/Makefile
17009+++ b/arch/x86/kernel/cpu/Makefile
17010@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17011 CFLAGS_REMOVE_perf_event.o = -pg
17012 endif
17013
17014-# Make sure load_percpu_segment has no stackprotector
17015-nostackp := $(call cc-option, -fno-stack-protector)
17016-CFLAGS_common.o := $(nostackp)
17017-
17018 obj-y := intel_cacheinfo.o scattered.o topology.o
17019 obj-y += proc.o capflags.o powerflags.o common.o
17020 obj-y += vmware.o hypervisor.o mshyperv.o
17021diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17022index 15239ff..e23e04e 100644
17023--- a/arch/x86/kernel/cpu/amd.c
17024+++ b/arch/x86/kernel/cpu/amd.c
17025@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17026 unsigned int size)
17027 {
17028 /* AMD errata T13 (order #21922) */
17029- if ((c->x86 == 6)) {
17030+ if (c->x86 == 6) {
17031 /* Duron Rev A0 */
17032 if (c->x86_model == 3 && c->x86_mask == 0)
17033 size = 64;
17034diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17035index 9c3ab43..51e6366 100644
17036--- a/arch/x86/kernel/cpu/common.c
17037+++ b/arch/x86/kernel/cpu/common.c
17038@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17039
17040 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17041
17042-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17043-#ifdef CONFIG_X86_64
17044- /*
17045- * We need valid kernel segments for data and code in long mode too
17046- * IRET will check the segment types kkeil 2000/10/28
17047- * Also sysret mandates a special GDT layout
17048- *
17049- * TLS descriptors are currently at a different place compared to i386.
17050- * Hopefully nobody expects them at a fixed place (Wine?)
17051- */
17052- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17053- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17054- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17055- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17056- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17057- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17058-#else
17059- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17060- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17061- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17062- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17063- /*
17064- * Segments used for calling PnP BIOS have byte granularity.
17065- * They code segments and data segments have fixed 64k limits,
17066- * the transfer segment sizes are set at run time.
17067- */
17068- /* 32-bit code */
17069- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17070- /* 16-bit code */
17071- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17072- /* 16-bit data */
17073- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17074- /* 16-bit data */
17075- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17076- /* 16-bit data */
17077- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17078- /*
17079- * The APM segments have byte granularity and their bases
17080- * are set at run time. All have 64k limits.
17081- */
17082- /* 32-bit code */
17083- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17084- /* 16-bit code */
17085- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17086- /* data */
17087- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17088-
17089- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17090- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17091- GDT_STACK_CANARY_INIT
17092-#endif
17093-} };
17094-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17095-
17096 static int __init x86_xsave_setup(char *s)
17097 {
17098 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17099@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
17100 {
17101 struct desc_ptr gdt_descr;
17102
17103- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17104+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17105 gdt_descr.size = GDT_SIZE - 1;
17106 load_gdt(&gdt_descr);
17107 /* Reload the per-cpu base */
17108@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17109 /* Filter out anything that depends on CPUID levels we don't have */
17110 filter_cpuid_features(c, true);
17111
17112+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17113+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17114+#endif
17115+
17116 /* If the model name is still unset, do table lookup. */
17117 if (!c->x86_model_id[0]) {
17118 const char *p;
17119@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
17120 }
17121 __setup("clearcpuid=", setup_disablecpuid);
17122
17123+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17124+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17125+
17126 #ifdef CONFIG_X86_64
17127 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17128-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17129- (unsigned long) nmi_idt_table };
17130+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17131
17132 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17133 irq_stack_union) __aligned(PAGE_SIZE);
17134@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17135 EXPORT_PER_CPU_SYMBOL(current_task);
17136
17137 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17138- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17139+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17140 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17141
17142 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17143@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
17144 int i;
17145
17146 cpu = stack_smp_processor_id();
17147- t = &per_cpu(init_tss, cpu);
17148+ t = init_tss + cpu;
17149 oist = &per_cpu(orig_ist, cpu);
17150
17151 #ifdef CONFIG_NUMA
17152@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
17153 switch_to_new_gdt(cpu);
17154 loadsegment(fs, 0);
17155
17156- load_idt((const struct desc_ptr *)&idt_descr);
17157+ load_idt(&idt_descr);
17158
17159 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17160 syscall_init();
17161@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
17162 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17163 barrier();
17164
17165- x86_configure_nx();
17166 enable_x2apic();
17167
17168 /*
17169@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
17170 {
17171 int cpu = smp_processor_id();
17172 struct task_struct *curr = current;
17173- struct tss_struct *t = &per_cpu(init_tss, cpu);
17174+ struct tss_struct *t = init_tss + cpu;
17175 struct thread_struct *thread = &curr->thread;
17176
17177 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
17178diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17179index fcaabd0..7b55a26 100644
17180--- a/arch/x86/kernel/cpu/intel.c
17181+++ b/arch/x86/kernel/cpu/intel.c
17182@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17183 * Update the IDT descriptor and reload the IDT so that
17184 * it uses the read-only mapped virtual address.
17185 */
17186- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17187+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17188 load_idt(&idt_descr);
17189 }
17190 #endif
17191diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17192index 84c1309..39b7224 100644
17193--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17194+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17195@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17196 };
17197
17198 #ifdef CONFIG_AMD_NB
17199+static struct attribute *default_attrs_amd_nb[] = {
17200+ &type.attr,
17201+ &level.attr,
17202+ &coherency_line_size.attr,
17203+ &physical_line_partition.attr,
17204+ &ways_of_associativity.attr,
17205+ &number_of_sets.attr,
17206+ &size.attr,
17207+ &shared_cpu_map.attr,
17208+ &shared_cpu_list.attr,
17209+ NULL,
17210+ NULL,
17211+ NULL,
17212+ NULL
17213+};
17214+
17215 static struct attribute ** __cpuinit amd_l3_attrs(void)
17216 {
17217 static struct attribute **attrs;
17218@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17219
17220 n = ARRAY_SIZE(default_attrs);
17221
17222- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17223- n += 2;
17224-
17225- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17226- n += 1;
17227-
17228- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17229- if (attrs == NULL)
17230- return attrs = default_attrs;
17231-
17232- for (n = 0; default_attrs[n]; n++)
17233- attrs[n] = default_attrs[n];
17234+ attrs = default_attrs_amd_nb;
17235
17236 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17237 attrs[n++] = &cache_disable_0.attr;
17238@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17239 .default_attrs = default_attrs,
17240 };
17241
17242+#ifdef CONFIG_AMD_NB
17243+static struct kobj_type ktype_cache_amd_nb = {
17244+ .sysfs_ops = &sysfs_ops,
17245+ .default_attrs = default_attrs_amd_nb,
17246+};
17247+#endif
17248+
17249 static struct kobj_type ktype_percpu_entry = {
17250 .sysfs_ops = &sysfs_ops,
17251 };
17252@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17253 return retval;
17254 }
17255
17256+#ifdef CONFIG_AMD_NB
17257+ amd_l3_attrs();
17258+#endif
17259+
17260 for (i = 0; i < num_cache_leaves; i++) {
17261+ struct kobj_type *ktype;
17262+
17263 this_object = INDEX_KOBJECT_PTR(cpu, i);
17264 this_object->cpu = cpu;
17265 this_object->index = i;
17266
17267 this_leaf = CPUID4_INFO_IDX(cpu, i);
17268
17269- ktype_cache.default_attrs = default_attrs;
17270+ ktype = &ktype_cache;
17271 #ifdef CONFIG_AMD_NB
17272 if (this_leaf->base.nb)
17273- ktype_cache.default_attrs = amd_l3_attrs();
17274+ ktype = &ktype_cache_amd_nb;
17275 #endif
17276 retval = kobject_init_and_add(&(this_object->kobj),
17277- &ktype_cache,
17278+ ktype,
17279 per_cpu(ici_cache_kobject, cpu),
17280 "index%1lu", i);
17281 if (unlikely(retval)) {
17282@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17283 return NOTIFY_OK;
17284 }
17285
17286-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17287+static struct notifier_block cacheinfo_cpu_notifier = {
17288 .notifier_call = cacheinfo_cpu_callback,
17289 };
17290
17291diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17292index 80dbda8..be16652 100644
17293--- a/arch/x86/kernel/cpu/mcheck/mce.c
17294+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17295@@ -45,6 +45,7 @@
17296 #include <asm/processor.h>
17297 #include <asm/mce.h>
17298 #include <asm/msr.h>
17299+#include <asm/local.h>
17300
17301 #include "mce-internal.h"
17302
17303@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17304 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17305 m->cs, m->ip);
17306
17307- if (m->cs == __KERNEL_CS)
17308+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17309 print_symbol("{%s}", m->ip);
17310 pr_cont("\n");
17311 }
17312@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17313
17314 #define PANIC_TIMEOUT 5 /* 5 seconds */
17315
17316-static atomic_t mce_paniced;
17317+static atomic_unchecked_t mce_paniced;
17318
17319 static int fake_panic;
17320-static atomic_t mce_fake_paniced;
17321+static atomic_unchecked_t mce_fake_paniced;
17322
17323 /* Panic in progress. Enable interrupts and wait for final IPI */
17324 static void wait_for_panic(void)
17325@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17326 /*
17327 * Make sure only one CPU runs in machine check panic
17328 */
17329- if (atomic_inc_return(&mce_paniced) > 1)
17330+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17331 wait_for_panic();
17332 barrier();
17333
17334@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17335 console_verbose();
17336 } else {
17337 /* Don't log too much for fake panic */
17338- if (atomic_inc_return(&mce_fake_paniced) > 1)
17339+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17340 return;
17341 }
17342 /* First print corrected ones that are still unlogged */
17343@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17344 * might have been modified by someone else.
17345 */
17346 rmb();
17347- if (atomic_read(&mce_paniced))
17348+ if (atomic_read_unchecked(&mce_paniced))
17349 wait_for_panic();
17350 if (!mca_cfg.monarch_timeout)
17351 goto out;
17352@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17353 }
17354
17355 /* Call the installed machine check handler for this CPU setup. */
17356-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17357+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17358 unexpected_machine_check;
17359
17360 /*
17361@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17362 return;
17363 }
17364
17365+ pax_open_kernel();
17366 machine_check_vector = do_machine_check;
17367+ pax_close_kernel();
17368
17369 __mcheck_cpu_init_generic();
17370 __mcheck_cpu_init_vendor(c);
17371@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17372 */
17373
17374 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17375-static int mce_chrdev_open_count; /* #times opened */
17376+static local_t mce_chrdev_open_count; /* #times opened */
17377 static int mce_chrdev_open_exclu; /* already open exclusive? */
17378
17379 static int mce_chrdev_open(struct inode *inode, struct file *file)
17380@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17381 spin_lock(&mce_chrdev_state_lock);
17382
17383 if (mce_chrdev_open_exclu ||
17384- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17385+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17386 spin_unlock(&mce_chrdev_state_lock);
17387
17388 return -EBUSY;
17389@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17390
17391 if (file->f_flags & O_EXCL)
17392 mce_chrdev_open_exclu = 1;
17393- mce_chrdev_open_count++;
17394+ local_inc(&mce_chrdev_open_count);
17395
17396 spin_unlock(&mce_chrdev_state_lock);
17397
17398@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17399 {
17400 spin_lock(&mce_chrdev_state_lock);
17401
17402- mce_chrdev_open_count--;
17403+ local_dec(&mce_chrdev_open_count);
17404 mce_chrdev_open_exclu = 0;
17405
17406 spin_unlock(&mce_chrdev_state_lock);
17407@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17408 return NOTIFY_OK;
17409 }
17410
17411-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17412+static struct notifier_block mce_cpu_notifier = {
17413 .notifier_call = mce_cpu_callback,
17414 };
17415
17416@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17417
17418 for (i = 0; i < mca_cfg.banks; i++) {
17419 struct mce_bank *b = &mce_banks[i];
17420- struct device_attribute *a = &b->attr;
17421+ device_attribute_no_const *a = &b->attr;
17422
17423 sysfs_attr_init(&a->attr);
17424 a->attr.name = b->attrname;
17425@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17426 static void mce_reset(void)
17427 {
17428 cpu_missing = 0;
17429- atomic_set(&mce_fake_paniced, 0);
17430+ atomic_set_unchecked(&mce_fake_paniced, 0);
17431 atomic_set(&mce_executing, 0);
17432 atomic_set(&mce_callin, 0);
17433 atomic_set(&global_nwo, 0);
17434diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17435index 2d5454c..51987eb 100644
17436--- a/arch/x86/kernel/cpu/mcheck/p5.c
17437+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17438@@ -11,6 +11,7 @@
17439 #include <asm/processor.h>
17440 #include <asm/mce.h>
17441 #include <asm/msr.h>
17442+#include <asm/pgtable.h>
17443
17444 /* By default disabled */
17445 int mce_p5_enabled __read_mostly;
17446@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17447 if (!cpu_has(c, X86_FEATURE_MCE))
17448 return;
17449
17450+ pax_open_kernel();
17451 machine_check_vector = pentium_machine_check;
17452+ pax_close_kernel();
17453 /* Make sure the vector pointer is visible before we enable MCEs: */
17454 wmb();
17455
17456diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17457index 47a1870..8c019a7 100644
17458--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17459+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17460@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17461 return notifier_from_errno(err);
17462 }
17463
17464-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17465+static struct notifier_block thermal_throttle_cpu_notifier =
17466 {
17467 .notifier_call = thermal_throttle_cpu_callback,
17468 };
17469diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17470index 2d7998f..17c9de1 100644
17471--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17472+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17473@@ -10,6 +10,7 @@
17474 #include <asm/processor.h>
17475 #include <asm/mce.h>
17476 #include <asm/msr.h>
17477+#include <asm/pgtable.h>
17478
17479 /* Machine check handler for WinChip C6: */
17480 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17481@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17482 {
17483 u32 lo, hi;
17484
17485+ pax_open_kernel();
17486 machine_check_vector = winchip_machine_check;
17487+ pax_close_kernel();
17488 /* Make sure the vector pointer is visible before we enable MCEs: */
17489 wmb();
17490
17491diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17492index 726bf96..81f0526 100644
17493--- a/arch/x86/kernel/cpu/mtrr/main.c
17494+++ b/arch/x86/kernel/cpu/mtrr/main.c
17495@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17496 u64 size_or_mask, size_and_mask;
17497 static bool mtrr_aps_delayed_init;
17498
17499-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17500+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17501
17502 const struct mtrr_ops *mtrr_if;
17503
17504diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17505index df5e41f..816c719 100644
17506--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17507+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17508@@ -25,7 +25,7 @@ struct mtrr_ops {
17509 int (*validate_add_page)(unsigned long base, unsigned long size,
17510 unsigned int type);
17511 int (*have_wrcomb)(void);
17512-};
17513+} __do_const;
17514
17515 extern int generic_get_free_region(unsigned long base, unsigned long size,
17516 int replace_reg);
17517diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17518index 6774c17..72c1b22 100644
17519--- a/arch/x86/kernel/cpu/perf_event.c
17520+++ b/arch/x86/kernel/cpu/perf_event.c
17521@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17522 pr_info("no hardware sampling interrupt available.\n");
17523 }
17524
17525-static struct attribute_group x86_pmu_format_group = {
17526+static attribute_group_no_const x86_pmu_format_group = {
17527 .name = "format",
17528 .attrs = NULL,
17529 };
17530@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17531 struct perf_pmu_events_attr {
17532 struct device_attribute attr;
17533 u64 id;
17534-};
17535+} __do_const;
17536
17537 /*
17538 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17539@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17540 NULL,
17541 };
17542
17543-static struct attribute_group x86_pmu_events_group = {
17544+static attribute_group_no_const x86_pmu_events_group = {
17545 .name = "events",
17546 .attrs = events_attr,
17547 };
17548@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17549 if (idx > GDT_ENTRIES)
17550 return 0;
17551
17552- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17553+ desc = get_cpu_gdt_table(smp_processor_id());
17554 }
17555
17556 return get_desc_base(desc + idx);
17557@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17558 break;
17559
17560 perf_callchain_store(entry, frame.return_address);
17561- fp = frame.next_frame;
17562+ fp = (const void __force_user *)frame.next_frame;
17563 }
17564 }
17565
17566diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17567index 4914e94..60b06e3 100644
17568--- a/arch/x86/kernel/cpu/perf_event_intel.c
17569+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17570@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17571 * v2 and above have a perf capabilities MSR
17572 */
17573 if (version > 1) {
17574- u64 capabilities;
17575+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17576
17577- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17578- x86_pmu.intel_cap.capabilities = capabilities;
17579+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17580+ x86_pmu.intel_cap.capabilities = capabilities;
17581 }
17582
17583 intel_ds_init();
17584diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17585index b43200d..d235b3e 100644
17586--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17587+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17588@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17589 static int __init uncore_type_init(struct intel_uncore_type *type)
17590 {
17591 struct intel_uncore_pmu *pmus;
17592- struct attribute_group *events_group;
17593+ attribute_group_no_const *attr_group;
17594 struct attribute **attrs;
17595 int i, j;
17596
17597@@ -2455,19 +2455,19 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
17598 while (type->event_descs[i].attr.attr.name)
17599 i++;
17600
17601- events_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
17602- sizeof(*events_group), GFP_KERNEL);
17603- if (!events_group)
17604+ attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
17605+ sizeof(*attr_group), GFP_KERNEL);
17606+ if (!attr_group)
17607 goto fail;
17608
17609- attrs = (struct attribute **)(events_group + 1);
17610- events_group->name = "events";
17611- events_group->attrs = attrs;
17612+ attrs = (struct attribute **)(attr_group + 1);
17613+ attr_group->name = "events";
17614+ attr_group->attrs = attrs;
17615
17616 for (j = 0; j < i; j++)
17617 attrs[j] = &type->event_descs[j].attr.attr;
17618
17619- type->events_group = events_group;
17620+ type->events_group = attr_group;
17621 }
17622
17623 type->pmu_group = &uncore_pmu_attr_group;
17624@@ -2826,7 +2826,7 @@ static int
17625 return NOTIFY_OK;
17626 }
17627
17628-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17629+static struct notifier_block uncore_cpu_nb = {
17630 .notifier_call = uncore_cpu_notifier,
17631 /*
17632 * to migrate uncore events, our notifier should be executed
17633diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17634index e68a455..975a932 100644
17635--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17636+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17637@@ -428,7 +428,7 @@ struct intel_uncore_box {
17638 struct uncore_event_desc {
17639 struct kobj_attribute attr;
17640 const char *config;
17641-};
17642+} __do_const;
17643
17644 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17645 { \
17646diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17647index 60c7891..9e911d3 100644
17648--- a/arch/x86/kernel/cpuid.c
17649+++ b/arch/x86/kernel/cpuid.c
17650@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17651 return notifier_from_errno(err);
17652 }
17653
17654-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17655+static struct notifier_block cpuid_class_cpu_notifier =
17656 {
17657 .notifier_call = cpuid_class_cpu_callback,
17658 };
17659diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17660index 74467fe..18793d5 100644
17661--- a/arch/x86/kernel/crash.c
17662+++ b/arch/x86/kernel/crash.c
17663@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17664 {
17665 #ifdef CONFIG_X86_32
17666 struct pt_regs fixed_regs;
17667-#endif
17668
17669-#ifdef CONFIG_X86_32
17670- if (!user_mode_vm(regs)) {
17671+ if (!user_mode(regs)) {
17672 crash_fixup_ss_esp(&fixed_regs, regs);
17673 regs = &fixed_regs;
17674 }
17675diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17676index 37250fe..bf2ec74 100644
17677--- a/arch/x86/kernel/doublefault_32.c
17678+++ b/arch/x86/kernel/doublefault_32.c
17679@@ -11,7 +11,7 @@
17680
17681 #define DOUBLEFAULT_STACKSIZE (1024)
17682 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17683-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17684+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17685
17686 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17687
17688@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17689 unsigned long gdt, tss;
17690
17691 store_gdt(&gdt_desc);
17692- gdt = gdt_desc.address;
17693+ gdt = (unsigned long)gdt_desc.address;
17694
17695 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17696
17697@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17698 /* 0x2 bit is always set */
17699 .flags = X86_EFLAGS_SF | 0x2,
17700 .sp = STACK_START,
17701- .es = __USER_DS,
17702+ .es = __KERNEL_DS,
17703 .cs = __KERNEL_CS,
17704 .ss = __KERNEL_DS,
17705- .ds = __USER_DS,
17706+ .ds = __KERNEL_DS,
17707 .fs = __KERNEL_PERCPU,
17708
17709 .__cr3 = __pa_nodebug(swapper_pg_dir),
17710diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17711index ae42418b..787c16b 100644
17712--- a/arch/x86/kernel/dumpstack.c
17713+++ b/arch/x86/kernel/dumpstack.c
17714@@ -2,6 +2,9 @@
17715 * Copyright (C) 1991, 1992 Linus Torvalds
17716 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17717 */
17718+#ifdef CONFIG_GRKERNSEC_HIDESYM
17719+#define __INCLUDED_BY_HIDESYM 1
17720+#endif
17721 #include <linux/kallsyms.h>
17722 #include <linux/kprobes.h>
17723 #include <linux/uaccess.h>
17724@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17725 static void
17726 print_ftrace_graph_addr(unsigned long addr, void *data,
17727 const struct stacktrace_ops *ops,
17728- struct thread_info *tinfo, int *graph)
17729+ struct task_struct *task, int *graph)
17730 {
17731- struct task_struct *task;
17732 unsigned long ret_addr;
17733 int index;
17734
17735 if (addr != (unsigned long)return_to_handler)
17736 return;
17737
17738- task = tinfo->task;
17739 index = task->curr_ret_stack;
17740
17741 if (!task->ret_stack || index < *graph)
17742@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17743 static inline void
17744 print_ftrace_graph_addr(unsigned long addr, void *data,
17745 const struct stacktrace_ops *ops,
17746- struct thread_info *tinfo, int *graph)
17747+ struct task_struct *task, int *graph)
17748 { }
17749 #endif
17750
17751@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17752 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17753 */
17754
17755-static inline int valid_stack_ptr(struct thread_info *tinfo,
17756- void *p, unsigned int size, void *end)
17757+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17758 {
17759- void *t = tinfo;
17760 if (end) {
17761 if (p < end && p >= (end-THREAD_SIZE))
17762 return 1;
17763@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17764 }
17765
17766 unsigned long
17767-print_context_stack(struct thread_info *tinfo,
17768+print_context_stack(struct task_struct *task, void *stack_start,
17769 unsigned long *stack, unsigned long bp,
17770 const struct stacktrace_ops *ops, void *data,
17771 unsigned long *end, int *graph)
17772 {
17773 struct stack_frame *frame = (struct stack_frame *)bp;
17774
17775- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17776+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17777 unsigned long addr;
17778
17779 addr = *stack;
17780@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17781 } else {
17782 ops->address(data, addr, 0);
17783 }
17784- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17785+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17786 }
17787 stack++;
17788 }
17789@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17790 EXPORT_SYMBOL_GPL(print_context_stack);
17791
17792 unsigned long
17793-print_context_stack_bp(struct thread_info *tinfo,
17794+print_context_stack_bp(struct task_struct *task, void *stack_start,
17795 unsigned long *stack, unsigned long bp,
17796 const struct stacktrace_ops *ops, void *data,
17797 unsigned long *end, int *graph)
17798@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17799 struct stack_frame *frame = (struct stack_frame *)bp;
17800 unsigned long *ret_addr = &frame->return_address;
17801
17802- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17803+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17804 unsigned long addr = *ret_addr;
17805
17806 if (!__kernel_text_address(addr))
17807@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17808 ops->address(data, addr, 1);
17809 frame = frame->next_frame;
17810 ret_addr = &frame->return_address;
17811- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17812+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17813 }
17814
17815 return (unsigned long)frame;
17816@@ -189,7 +188,7 @@ void dump_stack(void)
17817
17818 bp = stack_frame(current, NULL);
17819 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17820- current->pid, current->comm, print_tainted(),
17821+ task_pid_nr(current), current->comm, print_tainted(),
17822 init_utsname()->release,
17823 (int)strcspn(init_utsname()->version, " "),
17824 init_utsname()->version);
17825@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17826 }
17827 EXPORT_SYMBOL_GPL(oops_begin);
17828
17829+extern void gr_handle_kernel_exploit(void);
17830+
17831 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17832 {
17833 if (regs && kexec_should_crash(current))
17834@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17835 panic("Fatal exception in interrupt");
17836 if (panic_on_oops)
17837 panic("Fatal exception");
17838- do_exit(signr);
17839+
17840+ gr_handle_kernel_exploit();
17841+
17842+ do_group_exit(signr);
17843 }
17844
17845 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17846@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17847 print_modules();
17848 show_regs(regs);
17849 #ifdef CONFIG_X86_32
17850- if (user_mode_vm(regs)) {
17851+ if (user_mode(regs)) {
17852 sp = regs->sp;
17853 ss = regs->ss & 0xffff;
17854 } else {
17855@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17856 unsigned long flags = oops_begin();
17857 int sig = SIGSEGV;
17858
17859- if (!user_mode_vm(regs))
17860+ if (!user_mode(regs))
17861 report_bug(regs->ip, regs);
17862
17863 if (__die(str, regs, err))
17864diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17865index 1038a41..db2c12b 100644
17866--- a/arch/x86/kernel/dumpstack_32.c
17867+++ b/arch/x86/kernel/dumpstack_32.c
17868@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17869 bp = stack_frame(task, regs);
17870
17871 for (;;) {
17872- struct thread_info *context;
17873+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17874
17875- context = (struct thread_info *)
17876- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17877- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17878+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17879
17880- stack = (unsigned long *)context->previous_esp;
17881- if (!stack)
17882+ if (stack_start == task_stack_page(task))
17883 break;
17884+ stack = *(unsigned long **)stack_start;
17885 if (ops->stack(data, "IRQ") < 0)
17886 break;
17887 touch_nmi_watchdog();
17888@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17889 {
17890 int i;
17891
17892- __show_regs(regs, !user_mode_vm(regs));
17893+ __show_regs(regs, !user_mode(regs));
17894
17895 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17896 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17897@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17898 * When in-kernel, we also print out the stack and code at the
17899 * time of the fault..
17900 */
17901- if (!user_mode_vm(regs)) {
17902+ if (!user_mode(regs)) {
17903 unsigned int code_prologue = code_bytes * 43 / 64;
17904 unsigned int code_len = code_bytes;
17905 unsigned char c;
17906 u8 *ip;
17907+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17908
17909 pr_emerg("Stack:\n");
17910 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17911
17912 pr_emerg("Code:");
17913
17914- ip = (u8 *)regs->ip - code_prologue;
17915+ ip = (u8 *)regs->ip - code_prologue + cs_base;
17916 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17917 /* try starting at IP */
17918- ip = (u8 *)regs->ip;
17919+ ip = (u8 *)regs->ip + cs_base;
17920 code_len = code_len - code_prologue + 1;
17921 }
17922 for (i = 0; i < code_len; i++, ip++) {
17923@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17924 pr_cont(" Bad EIP value.");
17925 break;
17926 }
17927- if (ip == (u8 *)regs->ip)
17928+ if (ip == (u8 *)regs->ip + cs_base)
17929 pr_cont(" <%02x>", c);
17930 else
17931 pr_cont(" %02x", c);
17932@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17933 {
17934 unsigned short ud2;
17935
17936+ ip = ktla_ktva(ip);
17937 if (ip < PAGE_OFFSET)
17938 return 0;
17939 if (probe_kernel_address((unsigned short *)ip, ud2))
17940@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17941
17942 return ud2 == 0x0b0f;
17943 }
17944+
17945+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17946+void pax_check_alloca(unsigned long size)
17947+{
17948+ unsigned long sp = (unsigned long)&sp, stack_left;
17949+
17950+ /* all kernel stacks are of the same size */
17951+ stack_left = sp & (THREAD_SIZE - 1);
17952+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17953+}
17954+EXPORT_SYMBOL(pax_check_alloca);
17955+#endif
17956diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17957index b653675..51cc8c0 100644
17958--- a/arch/x86/kernel/dumpstack_64.c
17959+++ b/arch/x86/kernel/dumpstack_64.c
17960@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17961 unsigned long *irq_stack_end =
17962 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17963 unsigned used = 0;
17964- struct thread_info *tinfo;
17965 int graph = 0;
17966 unsigned long dummy;
17967+ void *stack_start;
17968
17969 if (!task)
17970 task = current;
17971@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17972 * current stack address. If the stacks consist of nested
17973 * exceptions
17974 */
17975- tinfo = task_thread_info(task);
17976 for (;;) {
17977 char *id;
17978 unsigned long *estack_end;
17979+
17980 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17981 &used, &id);
17982
17983@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17984 if (ops->stack(data, id) < 0)
17985 break;
17986
17987- bp = ops->walk_stack(tinfo, stack, bp, ops,
17988+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17989 data, estack_end, &graph);
17990 ops->stack(data, "<EOE>");
17991 /*
17992@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17993 * second-to-last pointer (index -2 to end) in the
17994 * exception stack:
17995 */
17996+ if ((u16)estack_end[-1] != __KERNEL_DS)
17997+ goto out;
17998 stack = (unsigned long *) estack_end[-2];
17999 continue;
18000 }
18001@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18002 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18003 if (ops->stack(data, "IRQ") < 0)
18004 break;
18005- bp = ops->walk_stack(tinfo, stack, bp,
18006+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18007 ops, data, irq_stack_end, &graph);
18008 /*
18009 * We link to the next stack (which would be
18010@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18011 /*
18012 * This handles the process stack:
18013 */
18014- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18015+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18016+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18017+out:
18018 put_cpu();
18019 }
18020 EXPORT_SYMBOL(dump_trace);
18021@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18022 {
18023 int i;
18024 unsigned long sp;
18025- const int cpu = smp_processor_id();
18026+ const int cpu = raw_smp_processor_id();
18027 struct task_struct *cur = current;
18028
18029 sp = regs->sp;
18030@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18031
18032 return ud2 == 0x0b0f;
18033 }
18034+
18035+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18036+void pax_check_alloca(unsigned long size)
18037+{
18038+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18039+ unsigned cpu, used;
18040+ char *id;
18041+
18042+ /* check the process stack first */
18043+ stack_start = (unsigned long)task_stack_page(current);
18044+ stack_end = stack_start + THREAD_SIZE;
18045+ if (likely(stack_start <= sp && sp < stack_end)) {
18046+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18047+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18048+ return;
18049+ }
18050+
18051+ cpu = get_cpu();
18052+
18053+ /* check the irq stacks */
18054+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18055+ stack_start = stack_end - IRQ_STACK_SIZE;
18056+ if (stack_start <= sp && sp < stack_end) {
18057+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18058+ put_cpu();
18059+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18060+ return;
18061+ }
18062+
18063+ /* check the exception stacks */
18064+ used = 0;
18065+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18066+ stack_start = stack_end - EXCEPTION_STKSZ;
18067+ if (stack_end && stack_start <= sp && sp < stack_end) {
18068+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18069+ put_cpu();
18070+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18071+ return;
18072+ }
18073+
18074+ put_cpu();
18075+
18076+ /* unknown stack */
18077+ BUG();
18078+}
18079+EXPORT_SYMBOL(pax_check_alloca);
18080+#endif
18081diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18082index 9b9f18b..9fcaa04 100644
18083--- a/arch/x86/kernel/early_printk.c
18084+++ b/arch/x86/kernel/early_printk.c
18085@@ -7,6 +7,7 @@
18086 #include <linux/pci_regs.h>
18087 #include <linux/pci_ids.h>
18088 #include <linux/errno.h>
18089+#include <linux/sched.h>
18090 #include <asm/io.h>
18091 #include <asm/processor.h>
18092 #include <asm/fcntl.h>
18093diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18094index 6ed91d9..6cc365b 100644
18095--- a/arch/x86/kernel/entry_32.S
18096+++ b/arch/x86/kernel/entry_32.S
18097@@ -177,13 +177,153 @@
18098 /*CFI_REL_OFFSET gs, PT_GS*/
18099 .endm
18100 .macro SET_KERNEL_GS reg
18101+
18102+#ifdef CONFIG_CC_STACKPROTECTOR
18103 movl $(__KERNEL_STACK_CANARY), \reg
18104+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18105+ movl $(__USER_DS), \reg
18106+#else
18107+ xorl \reg, \reg
18108+#endif
18109+
18110 movl \reg, %gs
18111 .endm
18112
18113 #endif /* CONFIG_X86_32_LAZY_GS */
18114
18115-.macro SAVE_ALL
18116+.macro pax_enter_kernel
18117+#ifdef CONFIG_PAX_KERNEXEC
18118+ call pax_enter_kernel
18119+#endif
18120+.endm
18121+
18122+.macro pax_exit_kernel
18123+#ifdef CONFIG_PAX_KERNEXEC
18124+ call pax_exit_kernel
18125+#endif
18126+.endm
18127+
18128+#ifdef CONFIG_PAX_KERNEXEC
18129+ENTRY(pax_enter_kernel)
18130+#ifdef CONFIG_PARAVIRT
18131+ pushl %eax
18132+ pushl %ecx
18133+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18134+ mov %eax, %esi
18135+#else
18136+ mov %cr0, %esi
18137+#endif
18138+ bts $16, %esi
18139+ jnc 1f
18140+ mov %cs, %esi
18141+ cmp $__KERNEL_CS, %esi
18142+ jz 3f
18143+ ljmp $__KERNEL_CS, $3f
18144+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18145+2:
18146+#ifdef CONFIG_PARAVIRT
18147+ mov %esi, %eax
18148+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18149+#else
18150+ mov %esi, %cr0
18151+#endif
18152+3:
18153+#ifdef CONFIG_PARAVIRT
18154+ popl %ecx
18155+ popl %eax
18156+#endif
18157+ ret
18158+ENDPROC(pax_enter_kernel)
18159+
18160+ENTRY(pax_exit_kernel)
18161+#ifdef CONFIG_PARAVIRT
18162+ pushl %eax
18163+ pushl %ecx
18164+#endif
18165+ mov %cs, %esi
18166+ cmp $__KERNEXEC_KERNEL_CS, %esi
18167+ jnz 2f
18168+#ifdef CONFIG_PARAVIRT
18169+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18170+ mov %eax, %esi
18171+#else
18172+ mov %cr0, %esi
18173+#endif
18174+ btr $16, %esi
18175+ ljmp $__KERNEL_CS, $1f
18176+1:
18177+#ifdef CONFIG_PARAVIRT
18178+ mov %esi, %eax
18179+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18180+#else
18181+ mov %esi, %cr0
18182+#endif
18183+2:
18184+#ifdef CONFIG_PARAVIRT
18185+ popl %ecx
18186+ popl %eax
18187+#endif
18188+ ret
18189+ENDPROC(pax_exit_kernel)
18190+#endif
18191+
18192+.macro pax_erase_kstack
18193+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18194+ call pax_erase_kstack
18195+#endif
18196+.endm
18197+
18198+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18199+/*
18200+ * ebp: thread_info
18201+ */
18202+ENTRY(pax_erase_kstack)
18203+ pushl %edi
18204+ pushl %ecx
18205+ pushl %eax
18206+
18207+ mov TI_lowest_stack(%ebp), %edi
18208+ mov $-0xBEEF, %eax
18209+ std
18210+
18211+1: mov %edi, %ecx
18212+ and $THREAD_SIZE_asm - 1, %ecx
18213+ shr $2, %ecx
18214+ repne scasl
18215+ jecxz 2f
18216+
18217+ cmp $2*16, %ecx
18218+ jc 2f
18219+
18220+ mov $2*16, %ecx
18221+ repe scasl
18222+ jecxz 2f
18223+ jne 1b
18224+
18225+2: cld
18226+ mov %esp, %ecx
18227+ sub %edi, %ecx
18228+
18229+ cmp $THREAD_SIZE_asm, %ecx
18230+ jb 3f
18231+ ud2
18232+3:
18233+
18234+ shr $2, %ecx
18235+ rep stosl
18236+
18237+ mov TI_task_thread_sp0(%ebp), %edi
18238+ sub $128, %edi
18239+ mov %edi, TI_lowest_stack(%ebp)
18240+
18241+ popl %eax
18242+ popl %ecx
18243+ popl %edi
18244+ ret
18245+ENDPROC(pax_erase_kstack)
18246+#endif
18247+
18248+.macro __SAVE_ALL _DS
18249 cld
18250 PUSH_GS
18251 pushl_cfi %fs
18252@@ -206,7 +346,7 @@
18253 CFI_REL_OFFSET ecx, 0
18254 pushl_cfi %ebx
18255 CFI_REL_OFFSET ebx, 0
18256- movl $(__USER_DS), %edx
18257+ movl $\_DS, %edx
18258 movl %edx, %ds
18259 movl %edx, %es
18260 movl $(__KERNEL_PERCPU), %edx
18261@@ -214,6 +354,15 @@
18262 SET_KERNEL_GS %edx
18263 .endm
18264
18265+.macro SAVE_ALL
18266+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18267+ __SAVE_ALL __KERNEL_DS
18268+ pax_enter_kernel
18269+#else
18270+ __SAVE_ALL __USER_DS
18271+#endif
18272+.endm
18273+
18274 .macro RESTORE_INT_REGS
18275 popl_cfi %ebx
18276 CFI_RESTORE ebx
18277@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18278 popfl_cfi
18279 jmp syscall_exit
18280 CFI_ENDPROC
18281-END(ret_from_fork)
18282+ENDPROC(ret_from_fork)
18283
18284 ENTRY(ret_from_kernel_thread)
18285 CFI_STARTPROC
18286@@ -344,7 +493,15 @@ ret_from_intr:
18287 andl $SEGMENT_RPL_MASK, %eax
18288 #endif
18289 cmpl $USER_RPL, %eax
18290+
18291+#ifdef CONFIG_PAX_KERNEXEC
18292+ jae resume_userspace
18293+
18294+ pax_exit_kernel
18295+ jmp resume_kernel
18296+#else
18297 jb resume_kernel # not returning to v8086 or userspace
18298+#endif
18299
18300 ENTRY(resume_userspace)
18301 LOCKDEP_SYS_EXIT
18302@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18303 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18304 # int/exception return?
18305 jne work_pending
18306- jmp restore_all
18307-END(ret_from_exception)
18308+ jmp restore_all_pax
18309+ENDPROC(ret_from_exception)
18310
18311 #ifdef CONFIG_PREEMPT
18312 ENTRY(resume_kernel)
18313@@ -372,7 +529,7 @@ need_resched:
18314 jz restore_all
18315 call preempt_schedule_irq
18316 jmp need_resched
18317-END(resume_kernel)
18318+ENDPROC(resume_kernel)
18319 #endif
18320 CFI_ENDPROC
18321 /*
18322@@ -406,30 +563,45 @@ sysenter_past_esp:
18323 /*CFI_REL_OFFSET cs, 0*/
18324 /*
18325 * Push current_thread_info()->sysenter_return to the stack.
18326- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18327- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18328 */
18329- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18330+ pushl_cfi $0
18331 CFI_REL_OFFSET eip, 0
18332
18333 pushl_cfi %eax
18334 SAVE_ALL
18335+ GET_THREAD_INFO(%ebp)
18336+ movl TI_sysenter_return(%ebp),%ebp
18337+ movl %ebp,PT_EIP(%esp)
18338 ENABLE_INTERRUPTS(CLBR_NONE)
18339
18340 /*
18341 * Load the potential sixth argument from user stack.
18342 * Careful about security.
18343 */
18344+ movl PT_OLDESP(%esp),%ebp
18345+
18346+#ifdef CONFIG_PAX_MEMORY_UDEREF
18347+ mov PT_OLDSS(%esp),%ds
18348+1: movl %ds:(%ebp),%ebp
18349+ push %ss
18350+ pop %ds
18351+#else
18352 cmpl $__PAGE_OFFSET-3,%ebp
18353 jae syscall_fault
18354 ASM_STAC
18355 1: movl (%ebp),%ebp
18356 ASM_CLAC
18357+#endif
18358+
18359 movl %ebp,PT_EBP(%esp)
18360 _ASM_EXTABLE(1b,syscall_fault)
18361
18362 GET_THREAD_INFO(%ebp)
18363
18364+#ifdef CONFIG_PAX_RANDKSTACK
18365+ pax_erase_kstack
18366+#endif
18367+
18368 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18369 jnz sysenter_audit
18370 sysenter_do_call:
18371@@ -444,12 +616,24 @@ sysenter_do_call:
18372 testl $_TIF_ALLWORK_MASK, %ecx
18373 jne sysexit_audit
18374 sysenter_exit:
18375+
18376+#ifdef CONFIG_PAX_RANDKSTACK
18377+ pushl_cfi %eax
18378+ movl %esp, %eax
18379+ call pax_randomize_kstack
18380+ popl_cfi %eax
18381+#endif
18382+
18383+ pax_erase_kstack
18384+
18385 /* if something modifies registers it must also disable sysexit */
18386 movl PT_EIP(%esp), %edx
18387 movl PT_OLDESP(%esp), %ecx
18388 xorl %ebp,%ebp
18389 TRACE_IRQS_ON
18390 1: mov PT_FS(%esp), %fs
18391+2: mov PT_DS(%esp), %ds
18392+3: mov PT_ES(%esp), %es
18393 PTGS_TO_GS
18394 ENABLE_INTERRUPTS_SYSEXIT
18395
18396@@ -466,6 +650,9 @@ sysenter_audit:
18397 movl %eax,%edx /* 2nd arg: syscall number */
18398 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18399 call __audit_syscall_entry
18400+
18401+ pax_erase_kstack
18402+
18403 pushl_cfi %ebx
18404 movl PT_EAX(%esp),%eax /* reload syscall number */
18405 jmp sysenter_do_call
18406@@ -491,10 +678,16 @@ sysexit_audit:
18407
18408 CFI_ENDPROC
18409 .pushsection .fixup,"ax"
18410-2: movl $0,PT_FS(%esp)
18411+4: movl $0,PT_FS(%esp)
18412+ jmp 1b
18413+5: movl $0,PT_DS(%esp)
18414+ jmp 1b
18415+6: movl $0,PT_ES(%esp)
18416 jmp 1b
18417 .popsection
18418- _ASM_EXTABLE(1b,2b)
18419+ _ASM_EXTABLE(1b,4b)
18420+ _ASM_EXTABLE(2b,5b)
18421+ _ASM_EXTABLE(3b,6b)
18422 PTGS_TO_GS_EX
18423 ENDPROC(ia32_sysenter_target)
18424
18425@@ -509,6 +702,11 @@ ENTRY(system_call)
18426 pushl_cfi %eax # save orig_eax
18427 SAVE_ALL
18428 GET_THREAD_INFO(%ebp)
18429+
18430+#ifdef CONFIG_PAX_RANDKSTACK
18431+ pax_erase_kstack
18432+#endif
18433+
18434 # system call tracing in operation / emulation
18435 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18436 jnz syscall_trace_entry
18437@@ -527,6 +725,15 @@ syscall_exit:
18438 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18439 jne syscall_exit_work
18440
18441+restore_all_pax:
18442+
18443+#ifdef CONFIG_PAX_RANDKSTACK
18444+ movl %esp, %eax
18445+ call pax_randomize_kstack
18446+#endif
18447+
18448+ pax_erase_kstack
18449+
18450 restore_all:
18451 TRACE_IRQS_IRET
18452 restore_all_notrace:
18453@@ -583,14 +790,34 @@ ldt_ss:
18454 * compensating for the offset by changing to the ESPFIX segment with
18455 * a base address that matches for the difference.
18456 */
18457-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18458+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18459 mov %esp, %edx /* load kernel esp */
18460 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18461 mov %dx, %ax /* eax: new kernel esp */
18462 sub %eax, %edx /* offset (low word is 0) */
18463+#ifdef CONFIG_SMP
18464+ movl PER_CPU_VAR(cpu_number), %ebx
18465+ shll $PAGE_SHIFT_asm, %ebx
18466+ addl $cpu_gdt_table, %ebx
18467+#else
18468+ movl $cpu_gdt_table, %ebx
18469+#endif
18470 shr $16, %edx
18471- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18472- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18473+
18474+#ifdef CONFIG_PAX_KERNEXEC
18475+ mov %cr0, %esi
18476+ btr $16, %esi
18477+ mov %esi, %cr0
18478+#endif
18479+
18480+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18481+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18482+
18483+#ifdef CONFIG_PAX_KERNEXEC
18484+ bts $16, %esi
18485+ mov %esi, %cr0
18486+#endif
18487+
18488 pushl_cfi $__ESPFIX_SS
18489 pushl_cfi %eax /* new kernel esp */
18490 /* Disable interrupts, but do not irqtrace this section: we
18491@@ -619,20 +846,18 @@ work_resched:
18492 movl TI_flags(%ebp), %ecx
18493 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18494 # than syscall tracing?
18495- jz restore_all
18496+ jz restore_all_pax
18497 testb $_TIF_NEED_RESCHED, %cl
18498 jnz work_resched
18499
18500 work_notifysig: # deal with pending signals and
18501 # notify-resume requests
18502+ movl %esp, %eax
18503 #ifdef CONFIG_VM86
18504 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18505- movl %esp, %eax
18506 jne work_notifysig_v86 # returning to kernel-space or
18507 # vm86-space
18508 1:
18509-#else
18510- movl %esp, %eax
18511 #endif
18512 TRACE_IRQS_ON
18513 ENABLE_INTERRUPTS(CLBR_NONE)
18514@@ -653,7 +878,7 @@ work_notifysig_v86:
18515 movl %eax, %esp
18516 jmp 1b
18517 #endif
18518-END(work_pending)
18519+ENDPROC(work_pending)
18520
18521 # perform syscall exit tracing
18522 ALIGN
18523@@ -661,11 +886,14 @@ syscall_trace_entry:
18524 movl $-ENOSYS,PT_EAX(%esp)
18525 movl %esp, %eax
18526 call syscall_trace_enter
18527+
18528+ pax_erase_kstack
18529+
18530 /* What it returned is what we'll actually use. */
18531 cmpl $(NR_syscalls), %eax
18532 jnae syscall_call
18533 jmp syscall_exit
18534-END(syscall_trace_entry)
18535+ENDPROC(syscall_trace_entry)
18536
18537 # perform syscall exit tracing
18538 ALIGN
18539@@ -678,21 +906,25 @@ syscall_exit_work:
18540 movl %esp, %eax
18541 call syscall_trace_leave
18542 jmp resume_userspace
18543-END(syscall_exit_work)
18544+ENDPROC(syscall_exit_work)
18545 CFI_ENDPROC
18546
18547 RING0_INT_FRAME # can't unwind into user space anyway
18548 syscall_fault:
18549+#ifdef CONFIG_PAX_MEMORY_UDEREF
18550+ push %ss
18551+ pop %ds
18552+#endif
18553 ASM_CLAC
18554 GET_THREAD_INFO(%ebp)
18555 movl $-EFAULT,PT_EAX(%esp)
18556 jmp resume_userspace
18557-END(syscall_fault)
18558+ENDPROC(syscall_fault)
18559
18560 syscall_badsys:
18561 movl $-ENOSYS,PT_EAX(%esp)
18562 jmp resume_userspace
18563-END(syscall_badsys)
18564+ENDPROC(syscall_badsys)
18565 CFI_ENDPROC
18566 /*
18567 * End of kprobes section
18568@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18569 * normal stack and adjusts ESP with the matching offset.
18570 */
18571 /* fixup the stack */
18572- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18573- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18574+#ifdef CONFIG_SMP
18575+ movl PER_CPU_VAR(cpu_number), %ebx
18576+ shll $PAGE_SHIFT_asm, %ebx
18577+ addl $cpu_gdt_table, %ebx
18578+#else
18579+ movl $cpu_gdt_table, %ebx
18580+#endif
18581+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18582+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18583 shl $16, %eax
18584 addl %esp, %eax /* the adjusted stack pointer */
18585 pushl_cfi $__KERNEL_DS
18586@@ -807,7 +1046,7 @@ vector=vector+1
18587 .endr
18588 2: jmp common_interrupt
18589 .endr
18590-END(irq_entries_start)
18591+ENDPROC(irq_entries_start)
18592
18593 .previous
18594 END(interrupt)
18595@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18596 pushl_cfi $do_coprocessor_error
18597 jmp error_code
18598 CFI_ENDPROC
18599-END(coprocessor_error)
18600+ENDPROC(coprocessor_error)
18601
18602 ENTRY(simd_coprocessor_error)
18603 RING0_INT_FRAME
18604@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18605 #endif
18606 jmp error_code
18607 CFI_ENDPROC
18608-END(simd_coprocessor_error)
18609+ENDPROC(simd_coprocessor_error)
18610
18611 ENTRY(device_not_available)
18612 RING0_INT_FRAME
18613@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18614 pushl_cfi $do_device_not_available
18615 jmp error_code
18616 CFI_ENDPROC
18617-END(device_not_available)
18618+ENDPROC(device_not_available)
18619
18620 #ifdef CONFIG_PARAVIRT
18621 ENTRY(native_iret)
18622 iret
18623 _ASM_EXTABLE(native_iret, iret_exc)
18624-END(native_iret)
18625+ENDPROC(native_iret)
18626
18627 ENTRY(native_irq_enable_sysexit)
18628 sti
18629 sysexit
18630-END(native_irq_enable_sysexit)
18631+ENDPROC(native_irq_enable_sysexit)
18632 #endif
18633
18634 ENTRY(overflow)
18635@@ -910,7 +1149,7 @@ ENTRY(overflow)
18636 pushl_cfi $do_overflow
18637 jmp error_code
18638 CFI_ENDPROC
18639-END(overflow)
18640+ENDPROC(overflow)
18641
18642 ENTRY(bounds)
18643 RING0_INT_FRAME
18644@@ -919,7 +1158,7 @@ ENTRY(bounds)
18645 pushl_cfi $do_bounds
18646 jmp error_code
18647 CFI_ENDPROC
18648-END(bounds)
18649+ENDPROC(bounds)
18650
18651 ENTRY(invalid_op)
18652 RING0_INT_FRAME
18653@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18654 pushl_cfi $do_invalid_op
18655 jmp error_code
18656 CFI_ENDPROC
18657-END(invalid_op)
18658+ENDPROC(invalid_op)
18659
18660 ENTRY(coprocessor_segment_overrun)
18661 RING0_INT_FRAME
18662@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18663 pushl_cfi $do_coprocessor_segment_overrun
18664 jmp error_code
18665 CFI_ENDPROC
18666-END(coprocessor_segment_overrun)
18667+ENDPROC(coprocessor_segment_overrun)
18668
18669 ENTRY(invalid_TSS)
18670 RING0_EC_FRAME
18671@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18672 pushl_cfi $do_invalid_TSS
18673 jmp error_code
18674 CFI_ENDPROC
18675-END(invalid_TSS)
18676+ENDPROC(invalid_TSS)
18677
18678 ENTRY(segment_not_present)
18679 RING0_EC_FRAME
18680@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18681 pushl_cfi $do_segment_not_present
18682 jmp error_code
18683 CFI_ENDPROC
18684-END(segment_not_present)
18685+ENDPROC(segment_not_present)
18686
18687 ENTRY(stack_segment)
18688 RING0_EC_FRAME
18689@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18690 pushl_cfi $do_stack_segment
18691 jmp error_code
18692 CFI_ENDPROC
18693-END(stack_segment)
18694+ENDPROC(stack_segment)
18695
18696 ENTRY(alignment_check)
18697 RING0_EC_FRAME
18698@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18699 pushl_cfi $do_alignment_check
18700 jmp error_code
18701 CFI_ENDPROC
18702-END(alignment_check)
18703+ENDPROC(alignment_check)
18704
18705 ENTRY(divide_error)
18706 RING0_INT_FRAME
18707@@ -978,7 +1217,7 @@ ENTRY(divide_error)
18708 pushl_cfi $do_divide_error
18709 jmp error_code
18710 CFI_ENDPROC
18711-END(divide_error)
18712+ENDPROC(divide_error)
18713
18714 #ifdef CONFIG_X86_MCE
18715 ENTRY(machine_check)
18716@@ -988,7 +1227,7 @@ ENTRY(machine_check)
18717 pushl_cfi machine_check_vector
18718 jmp error_code
18719 CFI_ENDPROC
18720-END(machine_check)
18721+ENDPROC(machine_check)
18722 #endif
18723
18724 ENTRY(spurious_interrupt_bug)
18725@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18726 pushl_cfi $do_spurious_interrupt_bug
18727 jmp error_code
18728 CFI_ENDPROC
18729-END(spurious_interrupt_bug)
18730+ENDPROC(spurious_interrupt_bug)
18731 /*
18732 * End of kprobes section
18733 */
18734@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18735
18736 ENTRY(mcount)
18737 ret
18738-END(mcount)
18739+ENDPROC(mcount)
18740
18741 ENTRY(ftrace_caller)
18742 cmpl $0, function_trace_stop
18743@@ -1134,7 +1373,7 @@ ftrace_graph_call:
18744 .globl ftrace_stub
18745 ftrace_stub:
18746 ret
18747-END(ftrace_caller)
18748+ENDPROC(ftrace_caller)
18749
18750 ENTRY(ftrace_regs_caller)
18751 pushf /* push flags before compare (in cs location) */
18752@@ -1235,7 +1474,7 @@ trace:
18753 popl %ecx
18754 popl %eax
18755 jmp ftrace_stub
18756-END(mcount)
18757+ENDPROC(mcount)
18758 #endif /* CONFIG_DYNAMIC_FTRACE */
18759 #endif /* CONFIG_FUNCTION_TRACER */
18760
18761@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18762 popl %ecx
18763 popl %eax
18764 ret
18765-END(ftrace_graph_caller)
18766+ENDPROC(ftrace_graph_caller)
18767
18768 .globl return_to_handler
18769 return_to_handler:
18770@@ -1309,15 +1548,18 @@ error_code:
18771 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18772 REG_TO_PTGS %ecx
18773 SET_KERNEL_GS %ecx
18774- movl $(__USER_DS), %ecx
18775+ movl $(__KERNEL_DS), %ecx
18776 movl %ecx, %ds
18777 movl %ecx, %es
18778+
18779+ pax_enter_kernel
18780+
18781 TRACE_IRQS_OFF
18782 movl %esp,%eax # pt_regs pointer
18783 call *%edi
18784 jmp ret_from_exception
18785 CFI_ENDPROC
18786-END(page_fault)
18787+ENDPROC(page_fault)
18788
18789 /*
18790 * Debug traps and NMI can happen at the one SYSENTER instruction
18791@@ -1360,7 +1602,7 @@ debug_stack_correct:
18792 call do_debug
18793 jmp ret_from_exception
18794 CFI_ENDPROC
18795-END(debug)
18796+ENDPROC(debug)
18797
18798 /*
18799 * NMI is doubly nasty. It can happen _while_ we're handling
18800@@ -1398,6 +1640,9 @@ nmi_stack_correct:
18801 xorl %edx,%edx # zero error code
18802 movl %esp,%eax # pt_regs pointer
18803 call do_nmi
18804+
18805+ pax_exit_kernel
18806+
18807 jmp restore_all_notrace
18808 CFI_ENDPROC
18809
18810@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18811 FIXUP_ESPFIX_STACK # %eax == %esp
18812 xorl %edx,%edx # zero error code
18813 call do_nmi
18814+
18815+ pax_exit_kernel
18816+
18817 RESTORE_REGS
18818 lss 12+4(%esp), %esp # back to espfix stack
18819 CFI_ADJUST_CFA_OFFSET -24
18820 jmp irq_return
18821 CFI_ENDPROC
18822-END(nmi)
18823+ENDPROC(nmi)
18824
18825 ENTRY(int3)
18826 RING0_INT_FRAME
18827@@ -1452,14 +1700,14 @@ ENTRY(int3)
18828 call do_int3
18829 jmp ret_from_exception
18830 CFI_ENDPROC
18831-END(int3)
18832+ENDPROC(int3)
18833
18834 ENTRY(general_protection)
18835 RING0_EC_FRAME
18836 pushl_cfi $do_general_protection
18837 jmp error_code
18838 CFI_ENDPROC
18839-END(general_protection)
18840+ENDPROC(general_protection)
18841
18842 #ifdef CONFIG_KVM_GUEST
18843 ENTRY(async_page_fault)
18844@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18845 pushl_cfi $do_async_page_fault
18846 jmp error_code
18847 CFI_ENDPROC
18848-END(async_page_fault)
18849+ENDPROC(async_page_fault)
18850 #endif
18851
18852 /*
18853diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18854index cb3c591..bc63707 100644
18855--- a/arch/x86/kernel/entry_64.S
18856+++ b/arch/x86/kernel/entry_64.S
18857@@ -59,6 +59,8 @@
18858 #include <asm/context_tracking.h>
18859 #include <asm/smap.h>
18860 #include <linux/err.h>
18861+#include <asm/pgtable.h>
18862+#include <asm/alternative-asm.h>
18863
18864 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18865 #include <linux/elf-em.h>
18866@@ -80,8 +82,9 @@
18867 #ifdef CONFIG_DYNAMIC_FTRACE
18868
18869 ENTRY(function_hook)
18870+ pax_force_retaddr
18871 retq
18872-END(function_hook)
18873+ENDPROC(function_hook)
18874
18875 /* skip is set if stack has been adjusted */
18876 .macro ftrace_caller_setup skip=0
18877@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18878 #endif
18879
18880 GLOBAL(ftrace_stub)
18881+ pax_force_retaddr
18882 retq
18883-END(ftrace_caller)
18884+ENDPROC(ftrace_caller)
18885
18886 ENTRY(ftrace_regs_caller)
18887 /* Save the current flags before compare (in SS location)*/
18888@@ -191,7 +195,7 @@ ftrace_restore_flags:
18889 popfq
18890 jmp ftrace_stub
18891
18892-END(ftrace_regs_caller)
18893+ENDPROC(ftrace_regs_caller)
18894
18895
18896 #else /* ! CONFIG_DYNAMIC_FTRACE */
18897@@ -212,6 +216,7 @@ ENTRY(function_hook)
18898 #endif
18899
18900 GLOBAL(ftrace_stub)
18901+ pax_force_retaddr
18902 retq
18903
18904 trace:
18905@@ -225,12 +230,13 @@ trace:
18906 #endif
18907 subq $MCOUNT_INSN_SIZE, %rdi
18908
18909+ pax_force_fptr ftrace_trace_function
18910 call *ftrace_trace_function
18911
18912 MCOUNT_RESTORE_FRAME
18913
18914 jmp ftrace_stub
18915-END(function_hook)
18916+ENDPROC(function_hook)
18917 #endif /* CONFIG_DYNAMIC_FTRACE */
18918 #endif /* CONFIG_FUNCTION_TRACER */
18919
18920@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18921
18922 MCOUNT_RESTORE_FRAME
18923
18924+ pax_force_retaddr
18925 retq
18926-END(ftrace_graph_caller)
18927+ENDPROC(ftrace_graph_caller)
18928
18929 GLOBAL(return_to_handler)
18930 subq $24, %rsp
18931@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18932 movq 8(%rsp), %rdx
18933 movq (%rsp), %rax
18934 addq $24, %rsp
18935+ pax_force_fptr %rdi
18936 jmp *%rdi
18937+ENDPROC(return_to_handler)
18938 #endif
18939
18940
18941@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18942 ENDPROC(native_usergs_sysret64)
18943 #endif /* CONFIG_PARAVIRT */
18944
18945+ .macro ljmpq sel, off
18946+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18947+ .byte 0x48; ljmp *1234f(%rip)
18948+ .pushsection .rodata
18949+ .align 16
18950+ 1234: .quad \off; .word \sel
18951+ .popsection
18952+#else
18953+ pushq $\sel
18954+ pushq $\off
18955+ lretq
18956+#endif
18957+ .endm
18958+
18959+ .macro pax_enter_kernel
18960+ pax_set_fptr_mask
18961+#ifdef CONFIG_PAX_KERNEXEC
18962+ call pax_enter_kernel
18963+#endif
18964+ .endm
18965+
18966+ .macro pax_exit_kernel
18967+#ifdef CONFIG_PAX_KERNEXEC
18968+ call pax_exit_kernel
18969+#endif
18970+ .endm
18971+
18972+#ifdef CONFIG_PAX_KERNEXEC
18973+ENTRY(pax_enter_kernel)
18974+ pushq %rdi
18975+
18976+#ifdef CONFIG_PARAVIRT
18977+ PV_SAVE_REGS(CLBR_RDI)
18978+#endif
18979+
18980+ GET_CR0_INTO_RDI
18981+ bts $16,%rdi
18982+ jnc 3f
18983+ mov %cs,%edi
18984+ cmp $__KERNEL_CS,%edi
18985+ jnz 2f
18986+1:
18987+
18988+#ifdef CONFIG_PARAVIRT
18989+ PV_RESTORE_REGS(CLBR_RDI)
18990+#endif
18991+
18992+ popq %rdi
18993+ pax_force_retaddr
18994+ retq
18995+
18996+2: ljmpq __KERNEL_CS,1f
18997+3: ljmpq __KERNEXEC_KERNEL_CS,4f
18998+4: SET_RDI_INTO_CR0
18999+ jmp 1b
19000+ENDPROC(pax_enter_kernel)
19001+
19002+ENTRY(pax_exit_kernel)
19003+ pushq %rdi
19004+
19005+#ifdef CONFIG_PARAVIRT
19006+ PV_SAVE_REGS(CLBR_RDI)
19007+#endif
19008+
19009+ mov %cs,%rdi
19010+ cmp $__KERNEXEC_KERNEL_CS,%edi
19011+ jz 2f
19012+1:
19013+
19014+#ifdef CONFIG_PARAVIRT
19015+ PV_RESTORE_REGS(CLBR_RDI);
19016+#endif
19017+
19018+ popq %rdi
19019+ pax_force_retaddr
19020+ retq
19021+
19022+2: GET_CR0_INTO_RDI
19023+ btr $16,%rdi
19024+ ljmpq __KERNEL_CS,3f
19025+3: SET_RDI_INTO_CR0
19026+ jmp 1b
19027+ENDPROC(pax_exit_kernel)
19028+#endif
19029+
19030+ .macro pax_enter_kernel_user
19031+ pax_set_fptr_mask
19032+#ifdef CONFIG_PAX_MEMORY_UDEREF
19033+ call pax_enter_kernel_user
19034+#endif
19035+ .endm
19036+
19037+ .macro pax_exit_kernel_user
19038+#ifdef CONFIG_PAX_MEMORY_UDEREF
19039+ call pax_exit_kernel_user
19040+#endif
19041+#ifdef CONFIG_PAX_RANDKSTACK
19042+ pushq %rax
19043+ call pax_randomize_kstack
19044+ popq %rax
19045+#endif
19046+ .endm
19047+
19048+#ifdef CONFIG_PAX_MEMORY_UDEREF
19049+ENTRY(pax_enter_kernel_user)
19050+ pushq %rdi
19051+ pushq %rbx
19052+
19053+#ifdef CONFIG_PARAVIRT
19054+ PV_SAVE_REGS(CLBR_RDI)
19055+#endif
19056+
19057+ GET_CR3_INTO_RDI
19058+ mov %rdi,%rbx
19059+ add $__START_KERNEL_map,%rbx
19060+ sub phys_base(%rip),%rbx
19061+
19062+#ifdef CONFIG_PARAVIRT
19063+ pushq %rdi
19064+ cmpl $0, pv_info+PARAVIRT_enabled
19065+ jz 1f
19066+ i = 0
19067+ .rept USER_PGD_PTRS
19068+ mov i*8(%rbx),%rsi
19069+ mov $0,%sil
19070+ lea i*8(%rbx),%rdi
19071+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19072+ i = i + 1
19073+ .endr
19074+ jmp 2f
19075+1:
19076+#endif
19077+
19078+ i = 0
19079+ .rept USER_PGD_PTRS
19080+ movb $0,i*8(%rbx)
19081+ i = i + 1
19082+ .endr
19083+
19084+#ifdef CONFIG_PARAVIRT
19085+2: popq %rdi
19086+#endif
19087+ SET_RDI_INTO_CR3
19088+
19089+#ifdef CONFIG_PAX_KERNEXEC
19090+ GET_CR0_INTO_RDI
19091+ bts $16,%rdi
19092+ SET_RDI_INTO_CR0
19093+#endif
19094+
19095+#ifdef CONFIG_PARAVIRT
19096+ PV_RESTORE_REGS(CLBR_RDI)
19097+#endif
19098+
19099+ popq %rbx
19100+ popq %rdi
19101+ pax_force_retaddr
19102+ retq
19103+ENDPROC(pax_enter_kernel_user)
19104+
19105+ENTRY(pax_exit_kernel_user)
19106+ push %rdi
19107+
19108+#ifdef CONFIG_PARAVIRT
19109+ pushq %rbx
19110+ PV_SAVE_REGS(CLBR_RDI)
19111+#endif
19112+
19113+#ifdef CONFIG_PAX_KERNEXEC
19114+ GET_CR0_INTO_RDI
19115+ btr $16,%rdi
19116+ SET_RDI_INTO_CR0
19117+#endif
19118+
19119+ GET_CR3_INTO_RDI
19120+ add $__START_KERNEL_map,%rdi
19121+ sub phys_base(%rip),%rdi
19122+
19123+#ifdef CONFIG_PARAVIRT
19124+ cmpl $0, pv_info+PARAVIRT_enabled
19125+ jz 1f
19126+ mov %rdi,%rbx
19127+ i = 0
19128+ .rept USER_PGD_PTRS
19129+ mov i*8(%rbx),%rsi
19130+ mov $0x67,%sil
19131+ lea i*8(%rbx),%rdi
19132+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19133+ i = i + 1
19134+ .endr
19135+ jmp 2f
19136+1:
19137+#endif
19138+
19139+ i = 0
19140+ .rept USER_PGD_PTRS
19141+ movb $0x67,i*8(%rdi)
19142+ i = i + 1
19143+ .endr
19144+
19145+#ifdef CONFIG_PARAVIRT
19146+2: PV_RESTORE_REGS(CLBR_RDI)
19147+ popq %rbx
19148+#endif
19149+
19150+ popq %rdi
19151+ pax_force_retaddr
19152+ retq
19153+ENDPROC(pax_exit_kernel_user)
19154+#endif
19155+
19156+.macro pax_erase_kstack
19157+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19158+ call pax_erase_kstack
19159+#endif
19160+.endm
19161+
19162+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19163+ENTRY(pax_erase_kstack)
19164+ pushq %rdi
19165+ pushq %rcx
19166+ pushq %rax
19167+ pushq %r11
19168+
19169+ GET_THREAD_INFO(%r11)
19170+ mov TI_lowest_stack(%r11), %rdi
19171+ mov $-0xBEEF, %rax
19172+ std
19173+
19174+1: mov %edi, %ecx
19175+ and $THREAD_SIZE_asm - 1, %ecx
19176+ shr $3, %ecx
19177+ repne scasq
19178+ jecxz 2f
19179+
19180+ cmp $2*8, %ecx
19181+ jc 2f
19182+
19183+ mov $2*8, %ecx
19184+ repe scasq
19185+ jecxz 2f
19186+ jne 1b
19187+
19188+2: cld
19189+ mov %esp, %ecx
19190+ sub %edi, %ecx
19191+
19192+ cmp $THREAD_SIZE_asm, %rcx
19193+ jb 3f
19194+ ud2
19195+3:
19196+
19197+ shr $3, %ecx
19198+ rep stosq
19199+
19200+ mov TI_task_thread_sp0(%r11), %rdi
19201+ sub $256, %rdi
19202+ mov %rdi, TI_lowest_stack(%r11)
19203+
19204+ popq %r11
19205+ popq %rax
19206+ popq %rcx
19207+ popq %rdi
19208+ pax_force_retaddr
19209+ ret
19210+ENDPROC(pax_erase_kstack)
19211+#endif
19212
19213 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19214 #ifdef CONFIG_TRACE_IRQFLAGS
19215@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
19216 .endm
19217
19218 .macro UNFAKE_STACK_FRAME
19219- addq $8*6, %rsp
19220- CFI_ADJUST_CFA_OFFSET -(6*8)
19221+ addq $8*6 + ARG_SKIP, %rsp
19222+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19223 .endm
19224
19225 /*
19226@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
19227 movq %rsp, %rsi
19228
19229 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19230- testl $3, CS-RBP(%rsi)
19231+ testb $3, CS-RBP(%rsi)
19232 je 1f
19233 SWAPGS
19234 /*
19235@@ -498,9 +774,10 @@ ENTRY(save_rest)
19236 movq_cfi r15, R15+16
19237 movq %r11, 8(%rsp) /* return address */
19238 FIXUP_TOP_OF_STACK %r11, 16
19239+ pax_force_retaddr
19240 ret
19241 CFI_ENDPROC
19242-END(save_rest)
19243+ENDPROC(save_rest)
19244
19245 /* save complete stack frame */
19246 .pushsection .kprobes.text, "ax"
19247@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
19248 js 1f /* negative -> in kernel */
19249 SWAPGS
19250 xorl %ebx,%ebx
19251-1: ret
19252+1: pax_force_retaddr_bts
19253+ ret
19254 CFI_ENDPROC
19255-END(save_paranoid)
19256+ENDPROC(save_paranoid)
19257 .popsection
19258
19259 /*
19260@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
19261
19262 RESTORE_REST
19263
19264- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19265+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19266 jz 1f
19267
19268 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19269@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
19270 RESTORE_REST
19271 jmp int_ret_from_sys_call
19272 CFI_ENDPROC
19273-END(ret_from_fork)
19274+ENDPROC(ret_from_fork)
19275
19276 /*
19277 * System call entry. Up to 6 arguments in registers are supported.
19278@@ -608,7 +886,7 @@ END(ret_from_fork)
19279 ENTRY(system_call)
19280 CFI_STARTPROC simple
19281 CFI_SIGNAL_FRAME
19282- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19283+ CFI_DEF_CFA rsp,0
19284 CFI_REGISTER rip,rcx
19285 /*CFI_REGISTER rflags,r11*/
19286 SWAPGS_UNSAFE_STACK
19287@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
19288
19289 movq %rsp,PER_CPU_VAR(old_rsp)
19290 movq PER_CPU_VAR(kernel_stack),%rsp
19291+ SAVE_ARGS 8*6,0
19292+ pax_enter_kernel_user
19293+
19294+#ifdef CONFIG_PAX_RANDKSTACK
19295+ pax_erase_kstack
19296+#endif
19297+
19298 /*
19299 * No need to follow this irqs off/on section - it's straight
19300 * and short:
19301 */
19302 ENABLE_INTERRUPTS(CLBR_NONE)
19303- SAVE_ARGS 8,0
19304 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19305 movq %rcx,RIP-ARGOFFSET(%rsp)
19306 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19307- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19308+ GET_THREAD_INFO(%rcx)
19309+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19310 jnz tracesys
19311 system_call_fastpath:
19312 #if __SYSCALL_MASK == ~0
19313@@ -640,7 +925,7 @@ system_call_fastpath:
19314 cmpl $__NR_syscall_max,%eax
19315 #endif
19316 ja badsys
19317- movq %r10,%rcx
19318+ movq R10-ARGOFFSET(%rsp),%rcx
19319 call *sys_call_table(,%rax,8) # XXX: rip relative
19320 movq %rax,RAX-ARGOFFSET(%rsp)
19321 /*
19322@@ -654,10 +939,13 @@ sysret_check:
19323 LOCKDEP_SYS_EXIT
19324 DISABLE_INTERRUPTS(CLBR_NONE)
19325 TRACE_IRQS_OFF
19326- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19327+ GET_THREAD_INFO(%rcx)
19328+ movl TI_flags(%rcx),%edx
19329 andl %edi,%edx
19330 jnz sysret_careful
19331 CFI_REMEMBER_STATE
19332+ pax_exit_kernel_user
19333+ pax_erase_kstack
19334 /*
19335 * sysretq will re-enable interrupts:
19336 */
19337@@ -709,14 +997,18 @@ badsys:
19338 * jump back to the normal fast path.
19339 */
19340 auditsys:
19341- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19342+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19343 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19344 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19345 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19346 movq %rax,%rsi /* 2nd arg: syscall number */
19347 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19348 call __audit_syscall_entry
19349+
19350+ pax_erase_kstack
19351+
19352 LOAD_ARGS 0 /* reload call-clobbered registers */
19353+ pax_set_fptr_mask
19354 jmp system_call_fastpath
19355
19356 /*
19357@@ -737,7 +1029,7 @@ sysret_audit:
19358 /* Do syscall tracing */
19359 tracesys:
19360 #ifdef CONFIG_AUDITSYSCALL
19361- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19362+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19363 jz auditsys
19364 #endif
19365 SAVE_REST
19366@@ -745,12 +1037,16 @@ tracesys:
19367 FIXUP_TOP_OF_STACK %rdi
19368 movq %rsp,%rdi
19369 call syscall_trace_enter
19370+
19371+ pax_erase_kstack
19372+
19373 /*
19374 * Reload arg registers from stack in case ptrace changed them.
19375 * We don't reload %rax because syscall_trace_enter() returned
19376 * the value it wants us to use in the table lookup.
19377 */
19378 LOAD_ARGS ARGOFFSET, 1
19379+ pax_set_fptr_mask
19380 RESTORE_REST
19381 #if __SYSCALL_MASK == ~0
19382 cmpq $__NR_syscall_max,%rax
19383@@ -759,7 +1055,7 @@ tracesys:
19384 cmpl $__NR_syscall_max,%eax
19385 #endif
19386 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19387- movq %r10,%rcx /* fixup for C */
19388+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19389 call *sys_call_table(,%rax,8)
19390 movq %rax,RAX-ARGOFFSET(%rsp)
19391 /* Use IRET because user could have changed frame */
19392@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19393 andl %edi,%edx
19394 jnz int_careful
19395 andl $~TS_COMPAT,TI_status(%rcx)
19396- jmp retint_swapgs
19397+ pax_exit_kernel_user
19398+ pax_erase_kstack
19399+ jmp retint_swapgs_pax
19400
19401 /* Either reschedule or signal or syscall exit tracking needed. */
19402 /* First do a reschedule test. */
19403@@ -826,7 +1124,7 @@ int_restore_rest:
19404 TRACE_IRQS_OFF
19405 jmp int_with_check
19406 CFI_ENDPROC
19407-END(system_call)
19408+ENDPROC(system_call)
19409
19410 /*
19411 * Certain special system calls that need to save a complete full stack frame.
19412@@ -842,7 +1140,7 @@ ENTRY(\label)
19413 call \func
19414 jmp ptregscall_common
19415 CFI_ENDPROC
19416-END(\label)
19417+ENDPROC(\label)
19418 .endm
19419
19420 .macro FORK_LIKE func
19421@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19422 DEFAULT_FRAME 0 8 /* offset 8: return address */
19423 call sys_\func
19424 RESTORE_TOP_OF_STACK %r11, 8
19425+ pax_force_retaddr
19426 ret $REST_SKIP /* pop extended registers */
19427 CFI_ENDPROC
19428-END(stub_\func)
19429+ENDPROC(stub_\func)
19430 .endm
19431
19432 FORK_LIKE clone
19433@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19434 movq_cfi_restore R12+8, r12
19435 movq_cfi_restore RBP+8, rbp
19436 movq_cfi_restore RBX+8, rbx
19437+ pax_force_retaddr
19438 ret $REST_SKIP /* pop extended registers */
19439 CFI_ENDPROC
19440-END(ptregscall_common)
19441+ENDPROC(ptregscall_common)
19442
19443 ENTRY(stub_execve)
19444 CFI_STARTPROC
19445@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19446 RESTORE_REST
19447 jmp int_ret_from_sys_call
19448 CFI_ENDPROC
19449-END(stub_execve)
19450+ENDPROC(stub_execve)
19451
19452 /*
19453 * sigreturn is special because it needs to restore all registers on return.
19454@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19455 RESTORE_REST
19456 jmp int_ret_from_sys_call
19457 CFI_ENDPROC
19458-END(stub_rt_sigreturn)
19459+ENDPROC(stub_rt_sigreturn)
19460
19461 #ifdef CONFIG_X86_X32_ABI
19462 ENTRY(stub_x32_rt_sigreturn)
19463@@ -975,7 +1275,7 @@ vector=vector+1
19464 2: jmp common_interrupt
19465 .endr
19466 CFI_ENDPROC
19467-END(irq_entries_start)
19468+ENDPROC(irq_entries_start)
19469
19470 .previous
19471 END(interrupt)
19472@@ -995,6 +1295,16 @@ END(interrupt)
19473 subq $ORIG_RAX-RBP, %rsp
19474 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19475 SAVE_ARGS_IRQ
19476+#ifdef CONFIG_PAX_MEMORY_UDEREF
19477+ testb $3, CS(%rdi)
19478+ jnz 1f
19479+ pax_enter_kernel
19480+ jmp 2f
19481+1: pax_enter_kernel_user
19482+2:
19483+#else
19484+ pax_enter_kernel
19485+#endif
19486 call \func
19487 .endm
19488
19489@@ -1027,7 +1337,7 @@ ret_from_intr:
19490
19491 exit_intr:
19492 GET_THREAD_INFO(%rcx)
19493- testl $3,CS-ARGOFFSET(%rsp)
19494+ testb $3,CS-ARGOFFSET(%rsp)
19495 je retint_kernel
19496
19497 /* Interrupt came from user space */
19498@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19499 * The iretq could re-enable interrupts:
19500 */
19501 DISABLE_INTERRUPTS(CLBR_ANY)
19502+ pax_exit_kernel_user
19503+retint_swapgs_pax:
19504 TRACE_IRQS_IRETQ
19505 SWAPGS
19506 jmp restore_args
19507
19508 retint_restore_args: /* return to kernel space */
19509 DISABLE_INTERRUPTS(CLBR_ANY)
19510+ pax_exit_kernel
19511+ pax_force_retaddr (RIP-ARGOFFSET)
19512 /*
19513 * The iretq could re-enable interrupts:
19514 */
19515@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19516 #endif
19517
19518 CFI_ENDPROC
19519-END(common_interrupt)
19520+ENDPROC(common_interrupt)
19521 /*
19522 * End of kprobes section
19523 */
19524@@ -1155,7 +1469,7 @@ ENTRY(\sym)
19525 interrupt \do_sym
19526 jmp ret_from_intr
19527 CFI_ENDPROC
19528-END(\sym)
19529+ENDPROC(\sym)
19530 .endm
19531
19532 #ifdef CONFIG_SMP
19533@@ -1211,12 +1525,22 @@ ENTRY(\sym)
19534 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19535 call error_entry
19536 DEFAULT_FRAME 0
19537+#ifdef CONFIG_PAX_MEMORY_UDEREF
19538+ testb $3, CS(%rsp)
19539+ jnz 1f
19540+ pax_enter_kernel
19541+ jmp 2f
19542+1: pax_enter_kernel_user
19543+2:
19544+#else
19545+ pax_enter_kernel
19546+#endif
19547 movq %rsp,%rdi /* pt_regs pointer */
19548 xorl %esi,%esi /* no error code */
19549 call \do_sym
19550 jmp error_exit /* %ebx: no swapgs flag */
19551 CFI_ENDPROC
19552-END(\sym)
19553+ENDPROC(\sym)
19554 .endm
19555
19556 .macro paranoidzeroentry sym do_sym
19557@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19558 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19559 call save_paranoid
19560 TRACE_IRQS_OFF
19561+#ifdef CONFIG_PAX_MEMORY_UDEREF
19562+ testb $3, CS(%rsp)
19563+ jnz 1f
19564+ pax_enter_kernel
19565+ jmp 2f
19566+1: pax_enter_kernel_user
19567+2:
19568+#else
19569+ pax_enter_kernel
19570+#endif
19571 movq %rsp,%rdi /* pt_regs pointer */
19572 xorl %esi,%esi /* no error code */
19573 call \do_sym
19574 jmp paranoid_exit /* %ebx: no swapgs flag */
19575 CFI_ENDPROC
19576-END(\sym)
19577+ENDPROC(\sym)
19578 .endm
19579
19580-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19581+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19582 .macro paranoidzeroentry_ist sym do_sym ist
19583 ENTRY(\sym)
19584 INTR_FRAME
19585@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19586 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19587 call save_paranoid
19588 TRACE_IRQS_OFF_DEBUG
19589+#ifdef CONFIG_PAX_MEMORY_UDEREF
19590+ testb $3, CS(%rsp)
19591+ jnz 1f
19592+ pax_enter_kernel
19593+ jmp 2f
19594+1: pax_enter_kernel_user
19595+2:
19596+#else
19597+ pax_enter_kernel
19598+#endif
19599 movq %rsp,%rdi /* pt_regs pointer */
19600 xorl %esi,%esi /* no error code */
19601+#ifdef CONFIG_SMP
19602+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19603+ lea init_tss(%r12), %r12
19604+#else
19605+ lea init_tss(%rip), %r12
19606+#endif
19607 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19608 call \do_sym
19609 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19610 jmp paranoid_exit /* %ebx: no swapgs flag */
19611 CFI_ENDPROC
19612-END(\sym)
19613+ENDPROC(\sym)
19614 .endm
19615
19616 .macro errorentry sym do_sym
19617@@ -1267,13 +1617,23 @@ ENTRY(\sym)
19618 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19619 call error_entry
19620 DEFAULT_FRAME 0
19621+#ifdef CONFIG_PAX_MEMORY_UDEREF
19622+ testb $3, CS(%rsp)
19623+ jnz 1f
19624+ pax_enter_kernel
19625+ jmp 2f
19626+1: pax_enter_kernel_user
19627+2:
19628+#else
19629+ pax_enter_kernel
19630+#endif
19631 movq %rsp,%rdi /* pt_regs pointer */
19632 movq ORIG_RAX(%rsp),%rsi /* get error code */
19633 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19634 call \do_sym
19635 jmp error_exit /* %ebx: no swapgs flag */
19636 CFI_ENDPROC
19637-END(\sym)
19638+ENDPROC(\sym)
19639 .endm
19640
19641 /* error code is on the stack already */
19642@@ -1287,13 +1647,23 @@ ENTRY(\sym)
19643 call save_paranoid
19644 DEFAULT_FRAME 0
19645 TRACE_IRQS_OFF
19646+#ifdef CONFIG_PAX_MEMORY_UDEREF
19647+ testb $3, CS(%rsp)
19648+ jnz 1f
19649+ pax_enter_kernel
19650+ jmp 2f
19651+1: pax_enter_kernel_user
19652+2:
19653+#else
19654+ pax_enter_kernel
19655+#endif
19656 movq %rsp,%rdi /* pt_regs pointer */
19657 movq ORIG_RAX(%rsp),%rsi /* get error code */
19658 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19659 call \do_sym
19660 jmp paranoid_exit /* %ebx: no swapgs flag */
19661 CFI_ENDPROC
19662-END(\sym)
19663+ENDPROC(\sym)
19664 .endm
19665
19666 zeroentry divide_error do_divide_error
19667@@ -1323,9 +1693,10 @@ gs_change:
19668 2: mfence /* workaround */
19669 SWAPGS
19670 popfq_cfi
19671+ pax_force_retaddr
19672 ret
19673 CFI_ENDPROC
19674-END(native_load_gs_index)
19675+ENDPROC(native_load_gs_index)
19676
19677 _ASM_EXTABLE(gs_change,bad_gs)
19678 .section .fixup,"ax"
19679@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19680 CFI_DEF_CFA_REGISTER rsp
19681 CFI_ADJUST_CFA_OFFSET -8
19682 decl PER_CPU_VAR(irq_count)
19683+ pax_force_retaddr
19684 ret
19685 CFI_ENDPROC
19686-END(call_softirq)
19687+ENDPROC(call_softirq)
19688
19689 #ifdef CONFIG_XEN
19690 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19691@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19692 decl PER_CPU_VAR(irq_count)
19693 jmp error_exit
19694 CFI_ENDPROC
19695-END(xen_do_hypervisor_callback)
19696+ENDPROC(xen_do_hypervisor_callback)
19697
19698 /*
19699 * Hypervisor uses this for application faults while it executes.
19700@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19701 SAVE_ALL
19702 jmp error_exit
19703 CFI_ENDPROC
19704-END(xen_failsafe_callback)
19705+ENDPROC(xen_failsafe_callback)
19706
19707 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19708 xen_hvm_callback_vector xen_evtchn_do_upcall
19709@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19710 TRACE_IRQS_OFF_DEBUG
19711 testl %ebx,%ebx /* swapgs needed? */
19712 jnz paranoid_restore
19713- testl $3,CS(%rsp)
19714+ testb $3,CS(%rsp)
19715 jnz paranoid_userspace
19716+#ifdef CONFIG_PAX_MEMORY_UDEREF
19717+ pax_exit_kernel
19718+ TRACE_IRQS_IRETQ 0
19719+ SWAPGS_UNSAFE_STACK
19720+ RESTORE_ALL 8
19721+ pax_force_retaddr_bts
19722+ jmp irq_return
19723+#endif
19724 paranoid_swapgs:
19725+#ifdef CONFIG_PAX_MEMORY_UDEREF
19726+ pax_exit_kernel_user
19727+#else
19728+ pax_exit_kernel
19729+#endif
19730 TRACE_IRQS_IRETQ 0
19731 SWAPGS_UNSAFE_STACK
19732 RESTORE_ALL 8
19733 jmp irq_return
19734 paranoid_restore:
19735+ pax_exit_kernel
19736 TRACE_IRQS_IRETQ_DEBUG 0
19737 RESTORE_ALL 8
19738+ pax_force_retaddr_bts
19739 jmp irq_return
19740 paranoid_userspace:
19741 GET_THREAD_INFO(%rcx)
19742@@ -1539,7 +1926,7 @@ paranoid_schedule:
19743 TRACE_IRQS_OFF
19744 jmp paranoid_userspace
19745 CFI_ENDPROC
19746-END(paranoid_exit)
19747+ENDPROC(paranoid_exit)
19748
19749 /*
19750 * Exception entry point. This expects an error code/orig_rax on the stack.
19751@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19752 movq_cfi r14, R14+8
19753 movq_cfi r15, R15+8
19754 xorl %ebx,%ebx
19755- testl $3,CS+8(%rsp)
19756+ testb $3,CS+8(%rsp)
19757 je error_kernelspace
19758 error_swapgs:
19759 SWAPGS
19760 error_sti:
19761 TRACE_IRQS_OFF
19762+ pax_force_retaddr_bts
19763 ret
19764
19765 /*
19766@@ -1598,7 +1986,7 @@ bstep_iret:
19767 movq %rcx,RIP+8(%rsp)
19768 jmp error_swapgs
19769 CFI_ENDPROC
19770-END(error_entry)
19771+ENDPROC(error_entry)
19772
19773
19774 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19775@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19776 jnz retint_careful
19777 jmp retint_swapgs
19778 CFI_ENDPROC
19779-END(error_exit)
19780+ENDPROC(error_exit)
19781
19782 /*
19783 * Test if a given stack is an NMI stack or not.
19784@@ -1676,9 +2064,11 @@ ENTRY(nmi)
19785 * If %cs was not the kernel segment, then the NMI triggered in user
19786 * space, which means it is definitely not nested.
19787 */
19788+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19789+ je 1f
19790 cmpl $__KERNEL_CS, 16(%rsp)
19791 jne first_nmi
19792-
19793+1:
19794 /*
19795 * Check the special variable on the stack to see if NMIs are
19796 * executing.
19797@@ -1847,6 +2237,17 @@ end_repeat_nmi:
19798 */
19799 movq %cr2, %r12
19800
19801+#ifdef CONFIG_PAX_MEMORY_UDEREF
19802+ testb $3, CS(%rsp)
19803+ jnz 1f
19804+ pax_enter_kernel
19805+ jmp 2f
19806+1: pax_enter_kernel_user
19807+2:
19808+#else
19809+ pax_enter_kernel
19810+#endif
19811+
19812 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19813 movq %rsp,%rdi
19814 movq $-1,%rsi
19815@@ -1862,23 +2263,34 @@ end_repeat_nmi:
19816 testl %ebx,%ebx /* swapgs needed? */
19817 jnz nmi_restore
19818 nmi_swapgs:
19819+#ifdef CONFIG_PAX_MEMORY_UDEREF
19820+ pax_exit_kernel_user
19821+#else
19822+ pax_exit_kernel
19823+#endif
19824 SWAPGS_UNSAFE_STACK
19825+ RESTORE_ALL 6*8
19826+ /* Clear the NMI executing stack variable */
19827+ movq $0, 5*8(%rsp)
19828+ jmp irq_return
19829 nmi_restore:
19830+ pax_exit_kernel
19831 /* Pop the extra iret frame at once */
19832 RESTORE_ALL 6*8
19833+ pax_force_retaddr_bts
19834
19835 /* Clear the NMI executing stack variable */
19836 movq $0, 5*8(%rsp)
19837 jmp irq_return
19838 CFI_ENDPROC
19839-END(nmi)
19840+ENDPROC(nmi)
19841
19842 ENTRY(ignore_sysret)
19843 CFI_STARTPROC
19844 mov $-ENOSYS,%eax
19845 sysret
19846 CFI_ENDPROC
19847-END(ignore_sysret)
19848+ENDPROC(ignore_sysret)
19849
19850 /*
19851 * End of kprobes section
19852diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19853index 1d41402..af9a46a 100644
19854--- a/arch/x86/kernel/ftrace.c
19855+++ b/arch/x86/kernel/ftrace.c
19856@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19857 {
19858 unsigned char replaced[MCOUNT_INSN_SIZE];
19859
19860+ ip = ktla_ktva(ip);
19861+
19862 /*
19863 * Note: Due to modules and __init, code can
19864 * disappear and change, we need to protect against faulting
19865@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19866 unsigned char old[MCOUNT_INSN_SIZE], *new;
19867 int ret;
19868
19869- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19870+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19871 new = ftrace_call_replace(ip, (unsigned long)func);
19872
19873 /* See comment above by declaration of modifying_ftrace_code */
19874@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19875 /* Also update the regs callback function */
19876 if (!ret) {
19877 ip = (unsigned long)(&ftrace_regs_call);
19878- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19879+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19880 new = ftrace_call_replace(ip, (unsigned long)func);
19881 ret = ftrace_modify_code(ip, old, new);
19882 }
19883@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19884 * kernel identity mapping to modify code.
19885 */
19886 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19887- ip = (unsigned long)__va(__pa(ip));
19888+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19889
19890 return probe_kernel_write((void *)ip, val, size);
19891 }
19892@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19893 unsigned char replaced[MCOUNT_INSN_SIZE];
19894 unsigned char brk = BREAKPOINT_INSTRUCTION;
19895
19896- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19897+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19898 return -EFAULT;
19899
19900 /* Make sure it is what we expect it to be */
19901@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19902 return ret;
19903
19904 fail_update:
19905- probe_kernel_write((void *)ip, &old_code[0], 1);
19906+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19907 goto out;
19908 }
19909
19910@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19911 {
19912 unsigned char code[MCOUNT_INSN_SIZE];
19913
19914+ ip = ktla_ktva(ip);
19915+
19916 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19917 return -EFAULT;
19918
19919diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19920index c18f59d..9c0c9f6 100644
19921--- a/arch/x86/kernel/head32.c
19922+++ b/arch/x86/kernel/head32.c
19923@@ -18,6 +18,7 @@
19924 #include <asm/io_apic.h>
19925 #include <asm/bios_ebda.h>
19926 #include <asm/tlbflush.h>
19927+#include <asm/boot.h>
19928
19929 static void __init i386_default_early_setup(void)
19930 {
19931@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19932
19933 void __init i386_start_kernel(void)
19934 {
19935- memblock_reserve(__pa_symbol(&_text),
19936- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19937+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19938
19939 #ifdef CONFIG_BLK_DEV_INITRD
19940 /* Reserve INITRD */
19941diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19942index c8932c7..d56b622 100644
19943--- a/arch/x86/kernel/head_32.S
19944+++ b/arch/x86/kernel/head_32.S
19945@@ -26,6 +26,12 @@
19946 /* Physical address */
19947 #define pa(X) ((X) - __PAGE_OFFSET)
19948
19949+#ifdef CONFIG_PAX_KERNEXEC
19950+#define ta(X) (X)
19951+#else
19952+#define ta(X) ((X) - __PAGE_OFFSET)
19953+#endif
19954+
19955 /*
19956 * References to members of the new_cpu_data structure.
19957 */
19958@@ -55,11 +61,7 @@
19959 * and small than max_low_pfn, otherwise will waste some page table entries
19960 */
19961
19962-#if PTRS_PER_PMD > 1
19963-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19964-#else
19965-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19966-#endif
19967+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19968
19969 /* Number of possible pages in the lowmem region */
19970 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19971@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19972 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19973
19974 /*
19975+ * Real beginning of normal "text" segment
19976+ */
19977+ENTRY(stext)
19978+ENTRY(_stext)
19979+
19980+/*
19981 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19982 * %esi points to the real-mode code as a 32-bit pointer.
19983 * CS and DS must be 4 GB flat segments, but we don't depend on
19984@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19985 * can.
19986 */
19987 __HEAD
19988+
19989+#ifdef CONFIG_PAX_KERNEXEC
19990+ jmp startup_32
19991+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19992+.fill PAGE_SIZE-5,1,0xcc
19993+#endif
19994+
19995 ENTRY(startup_32)
19996 movl pa(stack_start),%ecx
19997
19998@@ -106,6 +121,59 @@ ENTRY(startup_32)
19999 2:
20000 leal -__PAGE_OFFSET(%ecx),%esp
20001
20002+#ifdef CONFIG_SMP
20003+ movl $pa(cpu_gdt_table),%edi
20004+ movl $__per_cpu_load,%eax
20005+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20006+ rorl $16,%eax
20007+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20008+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20009+ movl $__per_cpu_end - 1,%eax
20010+ subl $__per_cpu_start,%eax
20011+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20012+#endif
20013+
20014+#ifdef CONFIG_PAX_MEMORY_UDEREF
20015+ movl $NR_CPUS,%ecx
20016+ movl $pa(cpu_gdt_table),%edi
20017+1:
20018+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20019+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20020+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20021+ addl $PAGE_SIZE_asm,%edi
20022+ loop 1b
20023+#endif
20024+
20025+#ifdef CONFIG_PAX_KERNEXEC
20026+ movl $pa(boot_gdt),%edi
20027+ movl $__LOAD_PHYSICAL_ADDR,%eax
20028+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20029+ rorl $16,%eax
20030+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20031+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20032+ rorl $16,%eax
20033+
20034+ ljmp $(__BOOT_CS),$1f
20035+1:
20036+
20037+ movl $NR_CPUS,%ecx
20038+ movl $pa(cpu_gdt_table),%edi
20039+ addl $__PAGE_OFFSET,%eax
20040+1:
20041+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20042+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20043+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20044+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20045+ rorl $16,%eax
20046+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20047+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20048+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20049+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20050+ rorl $16,%eax
20051+ addl $PAGE_SIZE_asm,%edi
20052+ loop 1b
20053+#endif
20054+
20055 /*
20056 * Clear BSS first so that there are no surprises...
20057 */
20058@@ -196,8 +264,11 @@ ENTRY(startup_32)
20059 movl %eax, pa(max_pfn_mapped)
20060
20061 /* Do early initialization of the fixmap area */
20062- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20063- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20064+#ifdef CONFIG_COMPAT_VDSO
20065+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20066+#else
20067+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20068+#endif
20069 #else /* Not PAE */
20070
20071 page_pde_offset = (__PAGE_OFFSET >> 20);
20072@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20073 movl %eax, pa(max_pfn_mapped)
20074
20075 /* Do early initialization of the fixmap area */
20076- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20077- movl %eax,pa(initial_page_table+0xffc)
20078+#ifdef CONFIG_COMPAT_VDSO
20079+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20080+#else
20081+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20082+#endif
20083 #endif
20084
20085 #ifdef CONFIG_PARAVIRT
20086@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20087 cmpl $num_subarch_entries, %eax
20088 jae bad_subarch
20089
20090- movl pa(subarch_entries)(,%eax,4), %eax
20091- subl $__PAGE_OFFSET, %eax
20092- jmp *%eax
20093+ jmp *pa(subarch_entries)(,%eax,4)
20094
20095 bad_subarch:
20096 WEAK(lguest_entry)
20097@@ -256,10 +328,10 @@ WEAK(xen_entry)
20098 __INITDATA
20099
20100 subarch_entries:
20101- .long default_entry /* normal x86/PC */
20102- .long lguest_entry /* lguest hypervisor */
20103- .long xen_entry /* Xen hypervisor */
20104- .long default_entry /* Moorestown MID */
20105+ .long ta(default_entry) /* normal x86/PC */
20106+ .long ta(lguest_entry) /* lguest hypervisor */
20107+ .long ta(xen_entry) /* Xen hypervisor */
20108+ .long ta(default_entry) /* Moorestown MID */
20109 num_subarch_entries = (. - subarch_entries) / 4
20110 .previous
20111 #else
20112@@ -335,6 +407,7 @@ default_entry:
20113 movl pa(mmu_cr4_features),%eax
20114 movl %eax,%cr4
20115
20116+#ifdef CONFIG_X86_PAE
20117 testb $X86_CR4_PAE, %al # check if PAE is enabled
20118 jz 6f
20119
20120@@ -363,6 +436,9 @@ default_entry:
20121 /* Make changes effective */
20122 wrmsr
20123
20124+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20125+#endif
20126+
20127 6:
20128
20129 /*
20130@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
20131 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20132 movl %eax,%ss # after changing gdt.
20133
20134- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20135+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20136 movl %eax,%ds
20137 movl %eax,%es
20138
20139 movl $(__KERNEL_PERCPU), %eax
20140 movl %eax,%fs # set this cpu's percpu
20141
20142+#ifdef CONFIG_CC_STACKPROTECTOR
20143 movl $(__KERNEL_STACK_CANARY),%eax
20144+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20145+ movl $(__USER_DS),%eax
20146+#else
20147+ xorl %eax,%eax
20148+#endif
20149 movl %eax,%gs
20150
20151 xorl %eax,%eax # Clear LDT
20152@@ -544,8 +626,11 @@ setup_once:
20153 * relocation. Manually set base address in stack canary
20154 * segment descriptor.
20155 */
20156- movl $gdt_page,%eax
20157+ movl $cpu_gdt_table,%eax
20158 movl $stack_canary,%ecx
20159+#ifdef CONFIG_SMP
20160+ addl $__per_cpu_load,%ecx
20161+#endif
20162 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20163 shrl $16, %ecx
20164 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20165@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
20166 /* This is global to keep gas from relaxing the jumps */
20167 ENTRY(early_idt_handler)
20168 cld
20169- cmpl $2,%ss:early_recursion_flag
20170+ cmpl $1,%ss:early_recursion_flag
20171 je hlt_loop
20172 incl %ss:early_recursion_flag
20173
20174@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
20175 pushl (20+6*4)(%esp) /* trapno */
20176 pushl $fault_msg
20177 call printk
20178-#endif
20179 call dump_stack
20180+#endif
20181 hlt_loop:
20182 hlt
20183 jmp hlt_loop
20184@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
20185 /* This is the default interrupt "handler" :-) */
20186 ALIGN
20187 ignore_int:
20188- cld
20189 #ifdef CONFIG_PRINTK
20190+ cmpl $2,%ss:early_recursion_flag
20191+ je hlt_loop
20192+ incl %ss:early_recursion_flag
20193+ cld
20194 pushl %eax
20195 pushl %ecx
20196 pushl %edx
20197@@ -644,9 +732,6 @@ ignore_int:
20198 movl $(__KERNEL_DS),%eax
20199 movl %eax,%ds
20200 movl %eax,%es
20201- cmpl $2,early_recursion_flag
20202- je hlt_loop
20203- incl early_recursion_flag
20204 pushl 16(%esp)
20205 pushl 24(%esp)
20206 pushl 32(%esp)
20207@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
20208 /*
20209 * BSS section
20210 */
20211-__PAGE_ALIGNED_BSS
20212- .align PAGE_SIZE
20213 #ifdef CONFIG_X86_PAE
20214+.section .initial_pg_pmd,"a",@progbits
20215 initial_pg_pmd:
20216 .fill 1024*KPMDS,4,0
20217 #else
20218+.section .initial_page_table,"a",@progbits
20219 ENTRY(initial_page_table)
20220 .fill 1024,4,0
20221 #endif
20222+.section .initial_pg_fixmap,"a",@progbits
20223 initial_pg_fixmap:
20224 .fill 1024,4,0
20225+.section .empty_zero_page,"a",@progbits
20226 ENTRY(empty_zero_page)
20227 .fill 4096,1,0
20228+.section .swapper_pg_dir,"a",@progbits
20229 ENTRY(swapper_pg_dir)
20230+#ifdef CONFIG_X86_PAE
20231+ .fill 4,8,0
20232+#else
20233 .fill 1024,4,0
20234+#endif
20235+
20236+/*
20237+ * The IDT has to be page-aligned to simplify the Pentium
20238+ * F0 0F bug workaround.. We have a special link segment
20239+ * for this.
20240+ */
20241+.section .idt,"a",@progbits
20242+ENTRY(idt_table)
20243+ .fill 256,8,0
20244
20245 /*
20246 * This starts the data section.
20247 */
20248 #ifdef CONFIG_X86_PAE
20249-__PAGE_ALIGNED_DATA
20250- /* Page-aligned for the benefit of paravirt? */
20251- .align PAGE_SIZE
20252+.section .initial_page_table,"a",@progbits
20253 ENTRY(initial_page_table)
20254 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20255 # if KPMDS == 3
20256@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
20257 # error "Kernel PMDs should be 1, 2 or 3"
20258 # endif
20259 .align PAGE_SIZE /* needs to be page-sized too */
20260+
20261+#ifdef CONFIG_PAX_PER_CPU_PGD
20262+ENTRY(cpu_pgd)
20263+ .rept NR_CPUS
20264+ .fill 4,8,0
20265+ .endr
20266+#endif
20267+
20268 #endif
20269
20270 .data
20271 .balign 4
20272 ENTRY(stack_start)
20273- .long init_thread_union+THREAD_SIZE
20274+ .long init_thread_union+THREAD_SIZE-8
20275
20276 __INITRODATA
20277 int_msg:
20278@@ -754,7 +861,7 @@ fault_msg:
20279 * segment size, and 32-bit linear address value:
20280 */
20281
20282- .data
20283+.section .rodata,"a",@progbits
20284 .globl boot_gdt_descr
20285 .globl idt_descr
20286
20287@@ -763,7 +870,7 @@ fault_msg:
20288 .word 0 # 32 bit align gdt_desc.address
20289 boot_gdt_descr:
20290 .word __BOOT_DS+7
20291- .long boot_gdt - __PAGE_OFFSET
20292+ .long pa(boot_gdt)
20293
20294 .word 0 # 32-bit align idt_desc.address
20295 idt_descr:
20296@@ -774,7 +881,7 @@ idt_descr:
20297 .word 0 # 32 bit align gdt_desc.address
20298 ENTRY(early_gdt_descr)
20299 .word GDT_ENTRIES*8-1
20300- .long gdt_page /* Overwritten for secondary CPUs */
20301+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20302
20303 /*
20304 * The boot_gdt must mirror the equivalent in setup.S and is
20305@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
20306 .align L1_CACHE_BYTES
20307 ENTRY(boot_gdt)
20308 .fill GDT_ENTRY_BOOT_CS,8,0
20309- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20310- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20311+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20312+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20313+
20314+ .align PAGE_SIZE_asm
20315+ENTRY(cpu_gdt_table)
20316+ .rept NR_CPUS
20317+ .quad 0x0000000000000000 /* NULL descriptor */
20318+ .quad 0x0000000000000000 /* 0x0b reserved */
20319+ .quad 0x0000000000000000 /* 0x13 reserved */
20320+ .quad 0x0000000000000000 /* 0x1b reserved */
20321+
20322+#ifdef CONFIG_PAX_KERNEXEC
20323+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20324+#else
20325+ .quad 0x0000000000000000 /* 0x20 unused */
20326+#endif
20327+
20328+ .quad 0x0000000000000000 /* 0x28 unused */
20329+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20330+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20331+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20332+ .quad 0x0000000000000000 /* 0x4b reserved */
20333+ .quad 0x0000000000000000 /* 0x53 reserved */
20334+ .quad 0x0000000000000000 /* 0x5b reserved */
20335+
20336+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20337+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20338+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20339+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20340+
20341+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20342+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20343+
20344+ /*
20345+ * Segments used for calling PnP BIOS have byte granularity.
20346+ * The code segments and data segments have fixed 64k limits,
20347+ * the transfer segment sizes are set at run time.
20348+ */
20349+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20350+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20351+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20352+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20353+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20354+
20355+ /*
20356+ * The APM segments have byte granularity and their bases
20357+ * are set at run time. All have 64k limits.
20358+ */
20359+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20360+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20361+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20362+
20363+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20364+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20365+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20366+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20367+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20368+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20369+
20370+ /* Be sure this is zeroed to avoid false validations in Xen */
20371+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20372+ .endr
20373diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20374index 980053c..74d3b44 100644
20375--- a/arch/x86/kernel/head_64.S
20376+++ b/arch/x86/kernel/head_64.S
20377@@ -20,6 +20,8 @@
20378 #include <asm/processor-flags.h>
20379 #include <asm/percpu.h>
20380 #include <asm/nops.h>
20381+#include <asm/cpufeature.h>
20382+#include <asm/alternative-asm.h>
20383
20384 #ifdef CONFIG_PARAVIRT
20385 #include <asm/asm-offsets.h>
20386@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20387 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20388 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20389 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20390+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20391+L3_VMALLOC_START = pud_index(VMALLOC_START)
20392+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20393+L3_VMALLOC_END = pud_index(VMALLOC_END)
20394+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20395+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20396
20397 .text
20398 __HEAD
20399@@ -88,35 +96,23 @@ startup_64:
20400 */
20401 addq %rbp, init_level4_pgt + 0(%rip)
20402 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20403+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20404+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20405+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20406 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20407
20408 addq %rbp, level3_ident_pgt + 0(%rip)
20409+#ifndef CONFIG_XEN
20410+ addq %rbp, level3_ident_pgt + 8(%rip)
20411+#endif
20412
20413- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20414- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20415+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20416+
20417+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20418+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20419
20420 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20421-
20422- /* Add an Identity mapping if I am above 1G */
20423- leaq _text(%rip), %rdi
20424- andq $PMD_PAGE_MASK, %rdi
20425-
20426- movq %rdi, %rax
20427- shrq $PUD_SHIFT, %rax
20428- andq $(PTRS_PER_PUD - 1), %rax
20429- jz ident_complete
20430-
20431- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20432- leaq level3_ident_pgt(%rip), %rbx
20433- movq %rdx, 0(%rbx, %rax, 8)
20434-
20435- movq %rdi, %rax
20436- shrq $PMD_SHIFT, %rax
20437- andq $(PTRS_PER_PMD - 1), %rax
20438- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20439- leaq level2_spare_pgt(%rip), %rbx
20440- movq %rdx, 0(%rbx, %rax, 8)
20441-ident_complete:
20442+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20443
20444 /*
20445 * Fixup the kernel text+data virtual addresses. Note that
20446@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20447 * after the boot processor executes this code.
20448 */
20449
20450- /* Enable PAE mode and PGE */
20451- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20452+ /* Enable PAE mode and PSE/PGE */
20453+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20454 movq %rax, %cr4
20455
20456 /* Setup early boot stage 4 level pagetables. */
20457@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20458 movl $MSR_EFER, %ecx
20459 rdmsr
20460 btsl $_EFER_SCE, %eax /* Enable System Call */
20461- btl $20,%edi /* No Execute supported? */
20462+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20463 jnc 1f
20464 btsl $_EFER_NX, %eax
20465+ leaq init_level4_pgt(%rip), %rdi
20466+#ifndef CONFIG_EFI
20467+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20468+#endif
20469+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20470+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20471+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20472+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20473 1: wrmsr /* Make changes effective */
20474
20475 /* Setup cr0 */
20476@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20477 * jump. In addition we need to ensure %cs is set so we make this
20478 * a far return.
20479 */
20480+ pax_set_fptr_mask
20481 movq initial_code(%rip),%rax
20482 pushq $0 # fake return address to stop unwinder
20483 pushq $__KERNEL_CS # set correct cs
20484@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20485 bad_address:
20486 jmp bad_address
20487
20488- .section ".init.text","ax"
20489+ __INIT
20490 .globl early_idt_handlers
20491 early_idt_handlers:
20492 # 104(%rsp) %rflags
20493@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20494 call dump_stack
20495 #ifdef CONFIG_KALLSYMS
20496 leaq early_idt_ripmsg(%rip),%rdi
20497- movq 40(%rsp),%rsi # %rip again
20498+ movq 88(%rsp),%rsi # %rip again
20499 call __print_symbol
20500 #endif
20501 #endif /* EARLY_PRINTK */
20502@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20503 addq $16,%rsp # drop vector number and error code
20504 decl early_recursion_flag(%rip)
20505 INTERRUPT_RETURN
20506+ .previous
20507
20508+ __INITDATA
20509 .balign 4
20510 early_recursion_flag:
20511 .long 0
20512+ .previous
20513
20514+ .section .rodata,"a",@progbits
20515 #ifdef CONFIG_EARLY_PRINTK
20516 early_idt_msg:
20517 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20518@@ -376,6 +385,7 @@ early_idt_ripmsg:
20519 #endif /* CONFIG_EARLY_PRINTK */
20520 .previous
20521
20522+ .section .rodata,"a",@progbits
20523 #define NEXT_PAGE(name) \
20524 .balign PAGE_SIZE; \
20525 ENTRY(name)
20526@@ -388,7 +398,6 @@ ENTRY(name)
20527 i = i + 1 ; \
20528 .endr
20529
20530- .data
20531 /*
20532 * This default setting generates an ident mapping at address 0x100000
20533 * and a mapping for the kernel that precisely maps virtual address
20534@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20535 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20536 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20537 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20538+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20539+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20540+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20541+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20542+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20543+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20544 .org init_level4_pgt + L4_START_KERNEL*8, 0
20545 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20546 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20547
20548+#ifdef CONFIG_PAX_PER_CPU_PGD
20549+NEXT_PAGE(cpu_pgd)
20550+ .rept NR_CPUS
20551+ .fill 512,8,0
20552+ .endr
20553+#endif
20554+
20555 NEXT_PAGE(level3_ident_pgt)
20556 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20557+#ifdef CONFIG_XEN
20558 .fill 511,8,0
20559+#else
20560+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20561+ .fill 510,8,0
20562+#endif
20563+
20564+NEXT_PAGE(level3_vmalloc_start_pgt)
20565+ .fill 512,8,0
20566+
20567+NEXT_PAGE(level3_vmalloc_end_pgt)
20568+ .fill 512,8,0
20569+
20570+NEXT_PAGE(level3_vmemmap_pgt)
20571+ .fill L3_VMEMMAP_START,8,0
20572+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20573
20574 NEXT_PAGE(level3_kernel_pgt)
20575 .fill L3_START_KERNEL,8,0
20576@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20577 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20578 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20579
20580+NEXT_PAGE(level2_vmemmap_pgt)
20581+ .fill 512,8,0
20582+
20583 NEXT_PAGE(level2_fixmap_pgt)
20584- .fill 506,8,0
20585- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20586- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20587- .fill 5,8,0
20588+ .fill 507,8,0
20589+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20590+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20591+ .fill 4,8,0
20592
20593-NEXT_PAGE(level1_fixmap_pgt)
20594+NEXT_PAGE(level1_vsyscall_pgt)
20595 .fill 512,8,0
20596
20597-NEXT_PAGE(level2_ident_pgt)
20598- /* Since I easily can, map the first 1G.
20599+ /* Since I easily can, map the first 2G.
20600 * Don't set NX because code runs from these pages.
20601 */
20602- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20603+NEXT_PAGE(level2_ident_pgt)
20604+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20605
20606 NEXT_PAGE(level2_kernel_pgt)
20607 /*
20608@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20609 * If you want to increase this then increase MODULES_VADDR
20610 * too.)
20611 */
20612- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20613- KERNEL_IMAGE_SIZE/PMD_SIZE)
20614-
20615-NEXT_PAGE(level2_spare_pgt)
20616- .fill 512, 8, 0
20617+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20618
20619 #undef PMDS
20620 #undef NEXT_PAGE
20621
20622- .data
20623+ .align PAGE_SIZE
20624+ENTRY(cpu_gdt_table)
20625+ .rept NR_CPUS
20626+ .quad 0x0000000000000000 /* NULL descriptor */
20627+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20628+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20629+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20630+ .quad 0x00cffb000000ffff /* __USER32_CS */
20631+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20632+ .quad 0x00affb000000ffff /* __USER_CS */
20633+
20634+#ifdef CONFIG_PAX_KERNEXEC
20635+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20636+#else
20637+ .quad 0x0 /* unused */
20638+#endif
20639+
20640+ .quad 0,0 /* TSS */
20641+ .quad 0,0 /* LDT */
20642+ .quad 0,0,0 /* three TLS descriptors */
20643+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20644+ /* asm/segment.h:GDT_ENTRIES must match this */
20645+
20646+ /* zero the remaining page */
20647+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20648+ .endr
20649+
20650 .align 16
20651 .globl early_gdt_descr
20652 early_gdt_descr:
20653 .word GDT_ENTRIES*8-1
20654 early_gdt_descr_base:
20655- .quad INIT_PER_CPU_VAR(gdt_page)
20656+ .quad cpu_gdt_table
20657
20658 ENTRY(phys_base)
20659 /* This must match the first entry in level2_kernel_pgt */
20660 .quad 0x0000000000000000
20661
20662 #include "../../x86/xen/xen-head.S"
20663-
20664- .section .bss, "aw", @nobits
20665+
20666+ .section .rodata,"a",@progbits
20667 .align L1_CACHE_BYTES
20668 ENTRY(idt_table)
20669- .skip IDT_ENTRIES * 16
20670+ .fill 512,8,0
20671
20672 .align L1_CACHE_BYTES
20673 ENTRY(nmi_idt_table)
20674- .skip IDT_ENTRIES * 16
20675+ .fill 512,8,0
20676
20677 __PAGE_ALIGNED_BSS
20678 .align PAGE_SIZE
20679diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20680index 9c3bd4a..e1d9b35 100644
20681--- a/arch/x86/kernel/i386_ksyms_32.c
20682+++ b/arch/x86/kernel/i386_ksyms_32.c
20683@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20684 EXPORT_SYMBOL(cmpxchg8b_emu);
20685 #endif
20686
20687+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20688+
20689 /* Networking helper routines. */
20690 EXPORT_SYMBOL(csum_partial_copy_generic);
20691+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20692+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20693
20694 EXPORT_SYMBOL(__get_user_1);
20695 EXPORT_SYMBOL(__get_user_2);
20696@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20697
20698 EXPORT_SYMBOL(csum_partial);
20699 EXPORT_SYMBOL(empty_zero_page);
20700+
20701+#ifdef CONFIG_PAX_KERNEXEC
20702+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20703+#endif
20704diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20705index 245a71d..89d9ce4 100644
20706--- a/arch/x86/kernel/i387.c
20707+++ b/arch/x86/kernel/i387.c
20708@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20709 static inline bool interrupted_user_mode(void)
20710 {
20711 struct pt_regs *regs = get_irq_regs();
20712- return regs && user_mode_vm(regs);
20713+ return regs && user_mode(regs);
20714 }
20715
20716 /*
20717diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20718index 9a5c460..b332a4b 100644
20719--- a/arch/x86/kernel/i8259.c
20720+++ b/arch/x86/kernel/i8259.c
20721@@ -209,7 +209,7 @@ spurious_8259A_irq:
20722 "spurious 8259A interrupt: IRQ%d.\n", irq);
20723 spurious_irq_mask |= irqmask;
20724 }
20725- atomic_inc(&irq_err_count);
20726+ atomic_inc_unchecked(&irq_err_count);
20727 /*
20728 * Theoretically we do not have to handle this IRQ,
20729 * but in Linux this does not cause problems and is
20730@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20731 /* (slave's support for AEOI in flat mode is to be investigated) */
20732 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20733
20734+ pax_open_kernel();
20735 if (auto_eoi)
20736 /*
20737 * In AEOI mode we just have to mask the interrupt
20738 * when acking.
20739 */
20740- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20741+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20742 else
20743- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20744+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20745+ pax_close_kernel();
20746
20747 udelay(100); /* wait for 8259A to initialize */
20748
20749diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20750index a979b5b..1d6db75 100644
20751--- a/arch/x86/kernel/io_delay.c
20752+++ b/arch/x86/kernel/io_delay.c
20753@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20754 * Quirk table for systems that misbehave (lock up, etc.) if port
20755 * 0x80 is used:
20756 */
20757-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20758+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20759 {
20760 .callback = dmi_io_delay_0xed_port,
20761 .ident = "Compaq Presario V6000",
20762diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20763index 8c96897..be66bfa 100644
20764--- a/arch/x86/kernel/ioport.c
20765+++ b/arch/x86/kernel/ioport.c
20766@@ -6,6 +6,7 @@
20767 #include <linux/sched.h>
20768 #include <linux/kernel.h>
20769 #include <linux/capability.h>
20770+#include <linux/security.h>
20771 #include <linux/errno.h>
20772 #include <linux/types.h>
20773 #include <linux/ioport.h>
20774@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20775
20776 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20777 return -EINVAL;
20778+#ifdef CONFIG_GRKERNSEC_IO
20779+ if (turn_on && grsec_disable_privio) {
20780+ gr_handle_ioperm();
20781+ return -EPERM;
20782+ }
20783+#endif
20784 if (turn_on && !capable(CAP_SYS_RAWIO))
20785 return -EPERM;
20786
20787@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20788 * because the ->io_bitmap_max value must match the bitmap
20789 * contents:
20790 */
20791- tss = &per_cpu(init_tss, get_cpu());
20792+ tss = init_tss + get_cpu();
20793
20794 if (turn_on)
20795 bitmap_clear(t->io_bitmap_ptr, from, num);
20796@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20797 return -EINVAL;
20798 /* Trying to gain more privileges? */
20799 if (level > old) {
20800+#ifdef CONFIG_GRKERNSEC_IO
20801+ if (grsec_disable_privio) {
20802+ gr_handle_iopl();
20803+ return -EPERM;
20804+ }
20805+#endif
20806 if (!capable(CAP_SYS_RAWIO))
20807 return -EPERM;
20808 }
20809diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20810index e4595f1..ee3bfb8 100644
20811--- a/arch/x86/kernel/irq.c
20812+++ b/arch/x86/kernel/irq.c
20813@@ -18,7 +18,7 @@
20814 #include <asm/mce.h>
20815 #include <asm/hw_irq.h>
20816
20817-atomic_t irq_err_count;
20818+atomic_unchecked_t irq_err_count;
20819
20820 /* Function pointer for generic interrupt vector handling */
20821 void (*x86_platform_ipi_callback)(void) = NULL;
20822@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20823 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20824 seq_printf(p, " Machine check polls\n");
20825 #endif
20826- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20827+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20828 #if defined(CONFIG_X86_IO_APIC)
20829- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20830+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20831 #endif
20832 return 0;
20833 }
20834@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20835
20836 u64 arch_irq_stat(void)
20837 {
20838- u64 sum = atomic_read(&irq_err_count);
20839+ u64 sum = atomic_read_unchecked(&irq_err_count);
20840
20841 #ifdef CONFIG_X86_IO_APIC
20842- sum += atomic_read(&irq_mis_count);
20843+ sum += atomic_read_unchecked(&irq_mis_count);
20844 #endif
20845 return sum;
20846 }
20847diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20848index 344faf8..355f60d 100644
20849--- a/arch/x86/kernel/irq_32.c
20850+++ b/arch/x86/kernel/irq_32.c
20851@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20852 __asm__ __volatile__("andl %%esp,%0" :
20853 "=r" (sp) : "0" (THREAD_SIZE - 1));
20854
20855- return sp < (sizeof(struct thread_info) + STACK_WARN);
20856+ return sp < STACK_WARN;
20857 }
20858
20859 static void print_stack_overflow(void)
20860@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20861 * per-CPU IRQ handling contexts (thread information and stack)
20862 */
20863 union irq_ctx {
20864- struct thread_info tinfo;
20865- u32 stack[THREAD_SIZE/sizeof(u32)];
20866+ unsigned long previous_esp;
20867+ u32 stack[THREAD_SIZE/sizeof(u32)];
20868 } __attribute__((aligned(THREAD_SIZE)));
20869
20870 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20871@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20872 static inline int
20873 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20874 {
20875- union irq_ctx *curctx, *irqctx;
20876+ union irq_ctx *irqctx;
20877 u32 *isp, arg1, arg2;
20878
20879- curctx = (union irq_ctx *) current_thread_info();
20880 irqctx = __this_cpu_read(hardirq_ctx);
20881
20882 /*
20883@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20884 * handler) we can't do that and just have to keep using the
20885 * current stack (which is the irq stack already after all)
20886 */
20887- if (unlikely(curctx == irqctx))
20888+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20889 return 0;
20890
20891 /* build the stack frame on the IRQ stack */
20892- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20893- irqctx->tinfo.task = curctx->tinfo.task;
20894- irqctx->tinfo.previous_esp = current_stack_pointer;
20895+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20896+ irqctx->previous_esp = current_stack_pointer;
20897
20898- /* Copy the preempt_count so that the [soft]irq checks work. */
20899- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20900+#ifdef CONFIG_PAX_MEMORY_UDEREF
20901+ __set_fs(MAKE_MM_SEG(0));
20902+#endif
20903
20904 if (unlikely(overflow))
20905 call_on_stack(print_stack_overflow, isp);
20906@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20907 : "0" (irq), "1" (desc), "2" (isp),
20908 "D" (desc->handle_irq)
20909 : "memory", "cc", "ecx");
20910+
20911+#ifdef CONFIG_PAX_MEMORY_UDEREF
20912+ __set_fs(current_thread_info()->addr_limit);
20913+#endif
20914+
20915 return 1;
20916 }
20917
20918@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20919 */
20920 void __cpuinit irq_ctx_init(int cpu)
20921 {
20922- union irq_ctx *irqctx;
20923-
20924 if (per_cpu(hardirq_ctx, cpu))
20925 return;
20926
20927- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20928- THREADINFO_GFP,
20929- THREAD_SIZE_ORDER));
20930- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20931- irqctx->tinfo.cpu = cpu;
20932- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20933- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20934-
20935- per_cpu(hardirq_ctx, cpu) = irqctx;
20936-
20937- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20938- THREADINFO_GFP,
20939- THREAD_SIZE_ORDER));
20940- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20941- irqctx->tinfo.cpu = cpu;
20942- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20943-
20944- per_cpu(softirq_ctx, cpu) = irqctx;
20945+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20946+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20947+
20948+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20949+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20950
20951 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20952 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20953@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20954 asmlinkage void do_softirq(void)
20955 {
20956 unsigned long flags;
20957- struct thread_info *curctx;
20958 union irq_ctx *irqctx;
20959 u32 *isp;
20960
20961@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20962 local_irq_save(flags);
20963
20964 if (local_softirq_pending()) {
20965- curctx = current_thread_info();
20966 irqctx = __this_cpu_read(softirq_ctx);
20967- irqctx->tinfo.task = curctx->task;
20968- irqctx->tinfo.previous_esp = current_stack_pointer;
20969+ irqctx->previous_esp = current_stack_pointer;
20970
20971 /* build the stack frame on the softirq stack */
20972- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20973+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20974+
20975+#ifdef CONFIG_PAX_MEMORY_UDEREF
20976+ __set_fs(MAKE_MM_SEG(0));
20977+#endif
20978
20979 call_on_stack(__do_softirq, isp);
20980+
20981+#ifdef CONFIG_PAX_MEMORY_UDEREF
20982+ __set_fs(current_thread_info()->addr_limit);
20983+#endif
20984+
20985 /*
20986 * Shouldn't happen, we returned above if in_interrupt():
20987 */
20988@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20989 if (unlikely(!desc))
20990 return false;
20991
20992- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20993+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20994 if (unlikely(overflow))
20995 print_stack_overflow();
20996 desc->handle_irq(irq, desc);
20997diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20998index d04d3ec..ea4b374 100644
20999--- a/arch/x86/kernel/irq_64.c
21000+++ b/arch/x86/kernel/irq_64.c
21001@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21002 u64 estack_top, estack_bottom;
21003 u64 curbase = (u64)task_stack_page(current);
21004
21005- if (user_mode_vm(regs))
21006+ if (user_mode(regs))
21007 return;
21008
21009 if (regs->sp >= curbase + sizeof(struct thread_info) +
21010diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21011index dc1404b..bbc43e7 100644
21012--- a/arch/x86/kernel/kdebugfs.c
21013+++ b/arch/x86/kernel/kdebugfs.c
21014@@ -27,7 +27,7 @@ struct setup_data_node {
21015 u32 len;
21016 };
21017
21018-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21019+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21020 size_t count, loff_t *ppos)
21021 {
21022 struct setup_data_node *node = file->private_data;
21023diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21024index 836f832..a8bda67 100644
21025--- a/arch/x86/kernel/kgdb.c
21026+++ b/arch/x86/kernel/kgdb.c
21027@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21028 #ifdef CONFIG_X86_32
21029 switch (regno) {
21030 case GDB_SS:
21031- if (!user_mode_vm(regs))
21032+ if (!user_mode(regs))
21033 *(unsigned long *)mem = __KERNEL_DS;
21034 break;
21035 case GDB_SP:
21036- if (!user_mode_vm(regs))
21037+ if (!user_mode(regs))
21038 *(unsigned long *)mem = kernel_stack_pointer(regs);
21039 break;
21040 case GDB_GS:
21041@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21042 bp->attr.bp_addr = breakinfo[breakno].addr;
21043 bp->attr.bp_len = breakinfo[breakno].len;
21044 bp->attr.bp_type = breakinfo[breakno].type;
21045- info->address = breakinfo[breakno].addr;
21046+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21047+ info->address = ktla_ktva(breakinfo[breakno].addr);
21048+ else
21049+ info->address = breakinfo[breakno].addr;
21050 info->len = breakinfo[breakno].len;
21051 info->type = breakinfo[breakno].type;
21052 val = arch_install_hw_breakpoint(bp);
21053@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21054 case 'k':
21055 /* clear the trace bit */
21056 linux_regs->flags &= ~X86_EFLAGS_TF;
21057- atomic_set(&kgdb_cpu_doing_single_step, -1);
21058+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21059
21060 /* set the trace bit if we're stepping */
21061 if (remcomInBuffer[0] == 's') {
21062 linux_regs->flags |= X86_EFLAGS_TF;
21063- atomic_set(&kgdb_cpu_doing_single_step,
21064+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21065 raw_smp_processor_id());
21066 }
21067
21068@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21069
21070 switch (cmd) {
21071 case DIE_DEBUG:
21072- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21073+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21074 if (user_mode(regs))
21075 return single_step_cont(regs, args);
21076 break;
21077@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21078 #endif /* CONFIG_DEBUG_RODATA */
21079
21080 bpt->type = BP_BREAKPOINT;
21081- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21082+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21083 BREAK_INSTR_SIZE);
21084 if (err)
21085 return err;
21086- err = probe_kernel_write((char *)bpt->bpt_addr,
21087+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21088 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21089 #ifdef CONFIG_DEBUG_RODATA
21090 if (!err)
21091@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21092 return -EBUSY;
21093 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21094 BREAK_INSTR_SIZE);
21095- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21096+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21097 if (err)
21098 return err;
21099 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21100@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21101 if (mutex_is_locked(&text_mutex))
21102 goto knl_write;
21103 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, 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 || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21107 goto knl_write;
21108 return err;
21109 knl_write:
21110 #endif /* CONFIG_DEBUG_RODATA */
21111- return probe_kernel_write((char *)bpt->bpt_addr,
21112+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21113 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21114 }
21115
21116diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
21117index c5e410e..ed5a7f0 100644
21118--- a/arch/x86/kernel/kprobes-opt.c
21119+++ b/arch/x86/kernel/kprobes-opt.c
21120@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21121 * Verify if the address gap is in 2GB range, because this uses
21122 * a relative jump.
21123 */
21124- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21125+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21126 if (abs(rel) > 0x7fffffff)
21127 return -ERANGE;
21128
21129@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21130 op->optinsn.size = ret;
21131
21132 /* Copy arch-dep-instance from template */
21133- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21134+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21135
21136 /* Set probe information */
21137 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21138
21139 /* Set probe function call */
21140- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21141+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21142
21143 /* Set returning jmp instruction at the tail of out-of-line buffer */
21144- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21145+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21146 (u8 *)op->kp.addr + op->optinsn.size);
21147
21148 flush_icache_range((unsigned long) buf,
21149@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21150 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21151
21152 /* Backup instructions which will be replaced by jump address */
21153- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21154+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21155 RELATIVE_ADDR_SIZE);
21156
21157 insn_buf[0] = RELATIVEJUMP_OPCODE;
21158@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21159 /* This kprobe is really able to run optimized path. */
21160 op = container_of(p, struct optimized_kprobe, kp);
21161 /* Detour through copied instructions */
21162- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21163+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21164 if (!reenter)
21165 reset_current_kprobe();
21166 preempt_enable_no_resched();
21167diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
21168index 57916c0..9e0b9d0 100644
21169--- a/arch/x86/kernel/kprobes.c
21170+++ b/arch/x86/kernel/kprobes.c
21171@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21172 s32 raddr;
21173 } __attribute__((packed)) *insn;
21174
21175- insn = (struct __arch_relative_insn *)from;
21176+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21177+
21178+ pax_open_kernel();
21179 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21180 insn->op = op;
21181+ pax_close_kernel();
21182 }
21183
21184 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21185@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21186 kprobe_opcode_t opcode;
21187 kprobe_opcode_t *orig_opcodes = opcodes;
21188
21189- if (search_exception_tables((unsigned long)opcodes))
21190+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21191 return 0; /* Page fault may occur on this address. */
21192
21193 retry:
21194@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21195 * for the first byte, we can recover the original instruction
21196 * from it and kp->opcode.
21197 */
21198- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21199+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21200 buf[0] = kp->opcode;
21201- return (unsigned long)buf;
21202+ return ktva_ktla((unsigned long)buf);
21203 }
21204
21205 /*
21206@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21207 /* Another subsystem puts a breakpoint, failed to recover */
21208 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21209 return 0;
21210+ pax_open_kernel();
21211 memcpy(dest, insn.kaddr, insn.length);
21212+ pax_close_kernel();
21213
21214 #ifdef CONFIG_X86_64
21215 if (insn_rip_relative(&insn)) {
21216@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21217 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21218 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21219 disp = (u8 *) dest + insn_offset_displacement(&insn);
21220+ pax_open_kernel();
21221 *(s32 *) disp = (s32) newdisp;
21222+ pax_close_kernel();
21223 }
21224 #endif
21225 return insn.length;
21226@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21227 * nor set current_kprobe, because it doesn't use single
21228 * stepping.
21229 */
21230- regs->ip = (unsigned long)p->ainsn.insn;
21231+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21232 preempt_enable_no_resched();
21233 return;
21234 }
21235@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21236 regs->flags &= ~X86_EFLAGS_IF;
21237 /* single step inline if the instruction is an int3 */
21238 if (p->opcode == BREAKPOINT_INSTRUCTION)
21239- regs->ip = (unsigned long)p->addr;
21240+ regs->ip = ktla_ktva((unsigned long)p->addr);
21241 else
21242- regs->ip = (unsigned long)p->ainsn.insn;
21243+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21244 }
21245
21246 /*
21247@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21248 setup_singlestep(p, regs, kcb, 0);
21249 return 1;
21250 }
21251- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21252+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21253 /*
21254 * The breakpoint instruction was removed right
21255 * after we hit it. Another cpu has removed
21256@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21257 " movq %rax, 152(%rsp)\n"
21258 RESTORE_REGS_STRING
21259 " popfq\n"
21260+#ifdef KERNEXEC_PLUGIN
21261+ " btsq $63,(%rsp)\n"
21262+#endif
21263 #else
21264 " pushf\n"
21265 SAVE_REGS_STRING
21266@@ -788,7 +798,7 @@ static void __kprobes
21267 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21268 {
21269 unsigned long *tos = stack_addr(regs);
21270- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21271+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21272 unsigned long orig_ip = (unsigned long)p->addr;
21273 kprobe_opcode_t *insn = p->ainsn.insn;
21274
21275@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21276 struct die_args *args = data;
21277 int ret = NOTIFY_DONE;
21278
21279- if (args->regs && user_mode_vm(args->regs))
21280+ if (args->regs && user_mode(args->regs))
21281 return ret;
21282
21283 switch (val) {
21284diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21285index 9c2bd8b..bb1131c 100644
21286--- a/arch/x86/kernel/kvm.c
21287+++ b/arch/x86/kernel/kvm.c
21288@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21289 return NOTIFY_OK;
21290 }
21291
21292-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21293+static struct notifier_block kvm_cpu_notifier = {
21294 .notifier_call = kvm_cpu_notify,
21295 };
21296 #endif
21297diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21298index ebc9873..1b9724b 100644
21299--- a/arch/x86/kernel/ldt.c
21300+++ b/arch/x86/kernel/ldt.c
21301@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21302 if (reload) {
21303 #ifdef CONFIG_SMP
21304 preempt_disable();
21305- load_LDT(pc);
21306+ load_LDT_nolock(pc);
21307 if (!cpumask_equal(mm_cpumask(current->mm),
21308 cpumask_of(smp_processor_id())))
21309 smp_call_function(flush_ldt, current->mm, 1);
21310 preempt_enable();
21311 #else
21312- load_LDT(pc);
21313+ load_LDT_nolock(pc);
21314 #endif
21315 }
21316 if (oldsize) {
21317@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21318 return err;
21319
21320 for (i = 0; i < old->size; i++)
21321- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21322+ write_ldt_entry(new->ldt, i, old->ldt + i);
21323 return 0;
21324 }
21325
21326@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21327 retval = copy_ldt(&mm->context, &old_mm->context);
21328 mutex_unlock(&old_mm->context.lock);
21329 }
21330+
21331+ if (tsk == current) {
21332+ mm->context.vdso = 0;
21333+
21334+#ifdef CONFIG_X86_32
21335+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21336+ mm->context.user_cs_base = 0UL;
21337+ mm->context.user_cs_limit = ~0UL;
21338+
21339+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21340+ cpus_clear(mm->context.cpu_user_cs_mask);
21341+#endif
21342+
21343+#endif
21344+#endif
21345+
21346+ }
21347+
21348 return retval;
21349 }
21350
21351@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21352 }
21353 }
21354
21355+#ifdef CONFIG_PAX_SEGMEXEC
21356+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21357+ error = -EINVAL;
21358+ goto out_unlock;
21359+ }
21360+#endif
21361+
21362 fill_ldt(&ldt, &ldt_info);
21363 if (oldmode)
21364 ldt.avl = 0;
21365diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21366index 5b19e4d..6476a76 100644
21367--- a/arch/x86/kernel/machine_kexec_32.c
21368+++ b/arch/x86/kernel/machine_kexec_32.c
21369@@ -26,7 +26,7 @@
21370 #include <asm/cacheflush.h>
21371 #include <asm/debugreg.h>
21372
21373-static void set_idt(void *newidt, __u16 limit)
21374+static void set_idt(struct desc_struct *newidt, __u16 limit)
21375 {
21376 struct desc_ptr curidt;
21377
21378@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21379 }
21380
21381
21382-static void set_gdt(void *newgdt, __u16 limit)
21383+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21384 {
21385 struct desc_ptr curgdt;
21386
21387@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21388 }
21389
21390 control_page = page_address(image->control_code_page);
21391- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21392+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21393
21394 relocate_kernel_ptr = control_page;
21395 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21396diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21397index 3a04b22..1d2eb09 100644
21398--- a/arch/x86/kernel/microcode_core.c
21399+++ b/arch/x86/kernel/microcode_core.c
21400@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21401 return NOTIFY_OK;
21402 }
21403
21404-static struct notifier_block __refdata mc_cpu_notifier = {
21405+static struct notifier_block mc_cpu_notifier = {
21406 .notifier_call = mc_cpu_callback,
21407 };
21408
21409diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21410index 3544aed..01ddc1c 100644
21411--- a/arch/x86/kernel/microcode_intel.c
21412+++ b/arch/x86/kernel/microcode_intel.c
21413@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21414
21415 static int get_ucode_user(void *to, const void *from, size_t n)
21416 {
21417- return copy_from_user(to, from, n);
21418+ return copy_from_user(to, (const void __force_user *)from, n);
21419 }
21420
21421 static enum ucode_state
21422 request_microcode_user(int cpu, const void __user *buf, size_t size)
21423 {
21424- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21425+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21426 }
21427
21428 static void microcode_fini_cpu(int cpu)
21429diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21430index 216a4d7..228255a 100644
21431--- a/arch/x86/kernel/module.c
21432+++ b/arch/x86/kernel/module.c
21433@@ -43,15 +43,60 @@ do { \
21434 } while (0)
21435 #endif
21436
21437-void *module_alloc(unsigned long size)
21438+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21439 {
21440- if (PAGE_ALIGN(size) > MODULES_LEN)
21441+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21442 return NULL;
21443 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21444- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21445+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21446 -1, __builtin_return_address(0));
21447 }
21448
21449+void *module_alloc(unsigned long size)
21450+{
21451+
21452+#ifdef CONFIG_PAX_KERNEXEC
21453+ return __module_alloc(size, PAGE_KERNEL);
21454+#else
21455+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21456+#endif
21457+
21458+}
21459+
21460+#ifdef CONFIG_PAX_KERNEXEC
21461+#ifdef CONFIG_X86_32
21462+void *module_alloc_exec(unsigned long size)
21463+{
21464+ struct vm_struct *area;
21465+
21466+ if (size == 0)
21467+ return NULL;
21468+
21469+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21470+ return area ? area->addr : NULL;
21471+}
21472+EXPORT_SYMBOL(module_alloc_exec);
21473+
21474+void module_free_exec(struct module *mod, void *module_region)
21475+{
21476+ vunmap(module_region);
21477+}
21478+EXPORT_SYMBOL(module_free_exec);
21479+#else
21480+void module_free_exec(struct module *mod, void *module_region)
21481+{
21482+ module_free(mod, module_region);
21483+}
21484+EXPORT_SYMBOL(module_free_exec);
21485+
21486+void *module_alloc_exec(unsigned long size)
21487+{
21488+ return __module_alloc(size, PAGE_KERNEL_RX);
21489+}
21490+EXPORT_SYMBOL(module_alloc_exec);
21491+#endif
21492+#endif
21493+
21494 #ifdef CONFIG_X86_32
21495 int apply_relocate(Elf32_Shdr *sechdrs,
21496 const char *strtab,
21497@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21498 unsigned int i;
21499 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21500 Elf32_Sym *sym;
21501- uint32_t *location;
21502+ uint32_t *plocation, location;
21503
21504 DEBUGP("Applying relocate section %u to %u\n",
21505 relsec, sechdrs[relsec].sh_info);
21506 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21507 /* This is where to make the change */
21508- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21509- + rel[i].r_offset;
21510+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21511+ location = (uint32_t)plocation;
21512+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21513+ plocation = ktla_ktva((void *)plocation);
21514 /* This is the symbol it is referring to. Note that all
21515 undefined symbols have been resolved. */
21516 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21517@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21518 switch (ELF32_R_TYPE(rel[i].r_info)) {
21519 case R_386_32:
21520 /* We add the value into the location given */
21521- *location += sym->st_value;
21522+ pax_open_kernel();
21523+ *plocation += sym->st_value;
21524+ pax_close_kernel();
21525 break;
21526 case R_386_PC32:
21527 /* Add the value, subtract its position */
21528- *location += sym->st_value - (uint32_t)location;
21529+ pax_open_kernel();
21530+ *plocation += sym->st_value - location;
21531+ pax_close_kernel();
21532 break;
21533 default:
21534 pr_err("%s: Unknown relocation: %u\n",
21535@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21536 case R_X86_64_NONE:
21537 break;
21538 case R_X86_64_64:
21539+ pax_open_kernel();
21540 *(u64 *)loc = val;
21541+ pax_close_kernel();
21542 break;
21543 case R_X86_64_32:
21544+ pax_open_kernel();
21545 *(u32 *)loc = val;
21546+ pax_close_kernel();
21547 if (val != *(u32 *)loc)
21548 goto overflow;
21549 break;
21550 case R_X86_64_32S:
21551+ pax_open_kernel();
21552 *(s32 *)loc = val;
21553+ pax_close_kernel();
21554 if ((s64)val != *(s32 *)loc)
21555 goto overflow;
21556 break;
21557 case R_X86_64_PC32:
21558 val -= (u64)loc;
21559+ pax_open_kernel();
21560 *(u32 *)loc = val;
21561+ pax_close_kernel();
21562+
21563 #if 0
21564 if ((s64)val != *(s32 *)loc)
21565 goto overflow;
21566diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21567index 4929502..686c291 100644
21568--- a/arch/x86/kernel/msr.c
21569+++ b/arch/x86/kernel/msr.c
21570@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21571 return notifier_from_errno(err);
21572 }
21573
21574-static struct notifier_block __refdata msr_class_cpu_notifier = {
21575+static struct notifier_block msr_class_cpu_notifier = {
21576 .notifier_call = msr_class_cpu_callback,
21577 };
21578
21579diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21580index f84f5c5..f404e81 100644
21581--- a/arch/x86/kernel/nmi.c
21582+++ b/arch/x86/kernel/nmi.c
21583@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21584 return handled;
21585 }
21586
21587-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21588+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21589 {
21590 struct nmi_desc *desc = nmi_to_desc(type);
21591 unsigned long flags;
21592@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21593 * event confuses some handlers (kdump uses this flag)
21594 */
21595 if (action->flags & NMI_FLAG_FIRST)
21596- list_add_rcu(&action->list, &desc->head);
21597+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21598 else
21599- list_add_tail_rcu(&action->list, &desc->head);
21600+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21601
21602 spin_unlock_irqrestore(&desc->lock, flags);
21603 return 0;
21604@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21605 if (!strcmp(n->name, name)) {
21606 WARN(in_nmi(),
21607 "Trying to free NMI (%s) from NMI context!\n", n->name);
21608- list_del_rcu(&n->list);
21609+ pax_list_del_rcu((struct list_head *)&n->list);
21610 break;
21611 }
21612 }
21613@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21614 dotraplinkage notrace __kprobes void
21615 do_nmi(struct pt_regs *regs, long error_code)
21616 {
21617+
21618+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21619+ if (!user_mode(regs)) {
21620+ unsigned long cs = regs->cs & 0xFFFF;
21621+ unsigned long ip = ktva_ktla(regs->ip);
21622+
21623+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21624+ regs->ip = ip;
21625+ }
21626+#endif
21627+
21628 nmi_nesting_preprocess(regs);
21629
21630 nmi_enter();
21631diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21632index 6d9582e..f746287 100644
21633--- a/arch/x86/kernel/nmi_selftest.c
21634+++ b/arch/x86/kernel/nmi_selftest.c
21635@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21636 {
21637 /* trap all the unknown NMIs we may generate */
21638 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21639- __initdata);
21640+ __initconst);
21641 }
21642
21643 static void __init cleanup_nmi_testsuite(void)
21644@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21645 unsigned long timeout;
21646
21647 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21648- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21649+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21650 nmi_fail = FAILURE;
21651 return;
21652 }
21653diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21654index 676b8c7..870ba04 100644
21655--- a/arch/x86/kernel/paravirt-spinlocks.c
21656+++ b/arch/x86/kernel/paravirt-spinlocks.c
21657@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21658 arch_spin_lock(lock);
21659 }
21660
21661-struct pv_lock_ops pv_lock_ops = {
21662+struct pv_lock_ops pv_lock_ops __read_only = {
21663 #ifdef CONFIG_SMP
21664 .spin_is_locked = __ticket_spin_is_locked,
21665 .spin_is_contended = __ticket_spin_is_contended,
21666diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21667index 17fff18..5cfa0f4 100644
21668--- a/arch/x86/kernel/paravirt.c
21669+++ b/arch/x86/kernel/paravirt.c
21670@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21671 {
21672 return x;
21673 }
21674+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21675+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21676+#endif
21677
21678 void __init default_banner(void)
21679 {
21680@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21681 if (opfunc == NULL)
21682 /* If there's no function, patch it with a ud2a (BUG) */
21683 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21684- else if (opfunc == _paravirt_nop)
21685+ else if (opfunc == (void *)_paravirt_nop)
21686 /* If the operation is a nop, then nop the callsite */
21687 ret = paravirt_patch_nop();
21688
21689 /* identity functions just return their single argument */
21690- else if (opfunc == _paravirt_ident_32)
21691+ else if (opfunc == (void *)_paravirt_ident_32)
21692 ret = paravirt_patch_ident_32(insnbuf, len);
21693- else if (opfunc == _paravirt_ident_64)
21694+ else if (opfunc == (void *)_paravirt_ident_64)
21695 ret = paravirt_patch_ident_64(insnbuf, len);
21696+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21697+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21698+ ret = paravirt_patch_ident_64(insnbuf, len);
21699+#endif
21700
21701 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21702 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21703@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21704 if (insn_len > len || start == NULL)
21705 insn_len = len;
21706 else
21707- memcpy(insnbuf, start, insn_len);
21708+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21709
21710 return insn_len;
21711 }
21712@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21713 preempt_enable();
21714 }
21715
21716-struct pv_info pv_info = {
21717+struct pv_info pv_info __read_only = {
21718 .name = "bare hardware",
21719 .paravirt_enabled = 0,
21720 .kernel_rpl = 0,
21721@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21722 #endif
21723 };
21724
21725-struct pv_init_ops pv_init_ops = {
21726+struct pv_init_ops pv_init_ops __read_only = {
21727 .patch = native_patch,
21728 };
21729
21730-struct pv_time_ops pv_time_ops = {
21731+struct pv_time_ops pv_time_ops __read_only = {
21732 .sched_clock = native_sched_clock,
21733 .steal_clock = native_steal_clock,
21734 };
21735
21736-struct pv_irq_ops pv_irq_ops = {
21737+struct pv_irq_ops pv_irq_ops __read_only = {
21738 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21739 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21740 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21741@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21742 #endif
21743 };
21744
21745-struct pv_cpu_ops pv_cpu_ops = {
21746+struct pv_cpu_ops pv_cpu_ops __read_only = {
21747 .cpuid = native_cpuid,
21748 .get_debugreg = native_get_debugreg,
21749 .set_debugreg = native_set_debugreg,
21750@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21751 .end_context_switch = paravirt_nop,
21752 };
21753
21754-struct pv_apic_ops pv_apic_ops = {
21755+struct pv_apic_ops pv_apic_ops __read_only= {
21756 #ifdef CONFIG_X86_LOCAL_APIC
21757 .startup_ipi_hook = paravirt_nop,
21758 #endif
21759 };
21760
21761-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21762+#ifdef CONFIG_X86_32
21763+#ifdef CONFIG_X86_PAE
21764+/* 64-bit pagetable entries */
21765+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21766+#else
21767 /* 32-bit pagetable entries */
21768 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21769+#endif
21770 #else
21771 /* 64-bit pagetable entries */
21772 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21773 #endif
21774
21775-struct pv_mmu_ops pv_mmu_ops = {
21776+struct pv_mmu_ops pv_mmu_ops __read_only = {
21777
21778 .read_cr2 = native_read_cr2,
21779 .write_cr2 = native_write_cr2,
21780@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21781 .make_pud = PTE_IDENT,
21782
21783 .set_pgd = native_set_pgd,
21784+ .set_pgd_batched = native_set_pgd_batched,
21785 #endif
21786 #endif /* PAGETABLE_LEVELS >= 3 */
21787
21788@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21789 },
21790
21791 .set_fixmap = native_set_fixmap,
21792+
21793+#ifdef CONFIG_PAX_KERNEXEC
21794+ .pax_open_kernel = native_pax_open_kernel,
21795+ .pax_close_kernel = native_pax_close_kernel,
21796+#endif
21797+
21798 };
21799
21800 EXPORT_SYMBOL_GPL(pv_time_ops);
21801diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21802index 35ccf75..7a15747 100644
21803--- a/arch/x86/kernel/pci-iommu_table.c
21804+++ b/arch/x86/kernel/pci-iommu_table.c
21805@@ -2,7 +2,7 @@
21806 #include <asm/iommu_table.h>
21807 #include <linux/string.h>
21808 #include <linux/kallsyms.h>
21809-
21810+#include <linux/sched.h>
21811
21812 #define DEBUG 1
21813
21814diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21815index 6c483ba..d10ce2f 100644
21816--- a/arch/x86/kernel/pci-swiotlb.c
21817+++ b/arch/x86/kernel/pci-swiotlb.c
21818@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21819 void *vaddr, dma_addr_t dma_addr,
21820 struct dma_attrs *attrs)
21821 {
21822- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21823+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21824 }
21825
21826 static struct dma_map_ops swiotlb_dma_ops = {
21827diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21828index 2ed787f..f70c9f6 100644
21829--- a/arch/x86/kernel/process.c
21830+++ b/arch/x86/kernel/process.c
21831@@ -36,7 +36,8 @@
21832 * section. Since TSS's are completely CPU-local, we want them
21833 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21834 */
21835-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21836+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21837+EXPORT_SYMBOL(init_tss);
21838
21839 #ifdef CONFIG_X86_64
21840 static DEFINE_PER_CPU(unsigned char, is_idle);
21841@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21842 task_xstate_cachep =
21843 kmem_cache_create("task_xstate", xstate_size,
21844 __alignof__(union thread_xstate),
21845- SLAB_PANIC | SLAB_NOTRACK, NULL);
21846+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21847 }
21848
21849 /*
21850@@ -105,7 +106,7 @@ void exit_thread(void)
21851 unsigned long *bp = t->io_bitmap_ptr;
21852
21853 if (bp) {
21854- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21855+ struct tss_struct *tss = init_tss + get_cpu();
21856
21857 t->io_bitmap_ptr = NULL;
21858 clear_thread_flag(TIF_IO_BITMAP);
21859@@ -136,7 +137,7 @@ void show_regs_common(void)
21860 board = dmi_get_system_info(DMI_BOARD_NAME);
21861
21862 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21863- current->pid, current->comm, print_tainted(),
21864+ task_pid_nr(current), current->comm, print_tainted(),
21865 init_utsname()->release,
21866 (int)strcspn(init_utsname()->version, " "),
21867 init_utsname()->version,
21868@@ -149,6 +150,9 @@ void flush_thread(void)
21869 {
21870 struct task_struct *tsk = current;
21871
21872+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21873+ loadsegment(gs, 0);
21874+#endif
21875 flush_ptrace_hw_breakpoint(tsk);
21876 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21877 drop_init_fpu(tsk);
21878@@ -301,7 +305,7 @@ static void __exit_idle(void)
21879 void exit_idle(void)
21880 {
21881 /* idle loop has pid 0 */
21882- if (current->pid)
21883+ if (task_pid_nr(current))
21884 return;
21885 __exit_idle();
21886 }
21887@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21888
21889 return ret;
21890 }
21891-void stop_this_cpu(void *dummy)
21892+__noreturn void stop_this_cpu(void *dummy)
21893 {
21894 local_irq_disable();
21895 /*
21896@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21897 }
21898 early_param("idle", idle_setup);
21899
21900-unsigned long arch_align_stack(unsigned long sp)
21901+#ifdef CONFIG_PAX_RANDKSTACK
21902+void pax_randomize_kstack(struct pt_regs *regs)
21903 {
21904- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21905- sp -= get_random_int() % 8192;
21906- return sp & ~0xf;
21907-}
21908+ struct thread_struct *thread = &current->thread;
21909+ unsigned long time;
21910
21911-unsigned long arch_randomize_brk(struct mm_struct *mm)
21912-{
21913- unsigned long range_end = mm->brk + 0x02000000;
21914- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21915-}
21916+ if (!randomize_va_space)
21917+ return;
21918+
21919+ if (v8086_mode(regs))
21920+ return;
21921
21922+ rdtscl(time);
21923+
21924+ /* P4 seems to return a 0 LSB, ignore it */
21925+#ifdef CONFIG_MPENTIUM4
21926+ time &= 0x3EUL;
21927+ time <<= 2;
21928+#elif defined(CONFIG_X86_64)
21929+ time &= 0xFUL;
21930+ time <<= 4;
21931+#else
21932+ time &= 0x1FUL;
21933+ time <<= 3;
21934+#endif
21935+
21936+ thread->sp0 ^= time;
21937+ load_sp0(init_tss + smp_processor_id(), thread);
21938+
21939+#ifdef CONFIG_X86_64
21940+ this_cpu_write(kernel_stack, thread->sp0);
21941+#endif
21942+}
21943+#endif
21944diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21945index b5a8905..d9cacac 100644
21946--- a/arch/x86/kernel/process_32.c
21947+++ b/arch/x86/kernel/process_32.c
21948@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21949 unsigned long thread_saved_pc(struct task_struct *tsk)
21950 {
21951 return ((unsigned long *)tsk->thread.sp)[3];
21952+//XXX return tsk->thread.eip;
21953 }
21954
21955 void __show_regs(struct pt_regs *regs, int all)
21956@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21957 unsigned long sp;
21958 unsigned short ss, gs;
21959
21960- if (user_mode_vm(regs)) {
21961+ if (user_mode(regs)) {
21962 sp = regs->sp;
21963 ss = regs->ss & 0xffff;
21964- gs = get_user_gs(regs);
21965 } else {
21966 sp = kernel_stack_pointer(regs);
21967 savesegment(ss, ss);
21968- savesegment(gs, gs);
21969 }
21970+ gs = get_user_gs(regs);
21971
21972 show_regs_common();
21973
21974 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21975 (u16)regs->cs, regs->ip, regs->flags,
21976- smp_processor_id());
21977+ raw_smp_processor_id());
21978 print_symbol("EIP is at %s\n", regs->ip);
21979
21980 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21981@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21982 int copy_thread(unsigned long clone_flags, unsigned long sp,
21983 unsigned long arg, struct task_struct *p)
21984 {
21985- struct pt_regs *childregs = task_pt_regs(p);
21986+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21987 struct task_struct *tsk;
21988 int err;
21989
21990 p->thread.sp = (unsigned long) childregs;
21991 p->thread.sp0 = (unsigned long) (childregs+1);
21992+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21993
21994 if (unlikely(p->flags & PF_KTHREAD)) {
21995 /* kernel thread */
21996 memset(childregs, 0, sizeof(struct pt_regs));
21997 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21998- task_user_gs(p) = __KERNEL_STACK_CANARY;
21999- childregs->ds = __USER_DS;
22000- childregs->es = __USER_DS;
22001+ savesegment(gs, childregs->gs);
22002+ childregs->ds = __KERNEL_DS;
22003+ childregs->es = __KERNEL_DS;
22004 childregs->fs = __KERNEL_PERCPU;
22005 childregs->bx = sp; /* function */
22006 childregs->bp = arg;
22007@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22008 struct thread_struct *prev = &prev_p->thread,
22009 *next = &next_p->thread;
22010 int cpu = smp_processor_id();
22011- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22012+ struct tss_struct *tss = init_tss + cpu;
22013 fpu_switch_t fpu;
22014
22015 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22016@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22017 */
22018 lazy_save_gs(prev->gs);
22019
22020+#ifdef CONFIG_PAX_MEMORY_UDEREF
22021+ __set_fs(task_thread_info(next_p)->addr_limit);
22022+#endif
22023+
22024 /*
22025 * Load the per-thread Thread-Local Storage descriptor.
22026 */
22027@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22028 */
22029 arch_end_context_switch(next_p);
22030
22031+ this_cpu_write(current_task, next_p);
22032+ this_cpu_write(current_tinfo, &next_p->tinfo);
22033+
22034 /*
22035 * Restore %gs if needed (which is common)
22036 */
22037@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22038
22039 switch_fpu_finish(next_p, fpu);
22040
22041- this_cpu_write(current_task, next_p);
22042-
22043 return prev_p;
22044 }
22045
22046@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22047 } while (count++ < 16);
22048 return 0;
22049 }
22050-
22051diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22052index 6e68a61..955a9a5 100644
22053--- a/arch/x86/kernel/process_64.c
22054+++ b/arch/x86/kernel/process_64.c
22055@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22056 struct pt_regs *childregs;
22057 struct task_struct *me = current;
22058
22059- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22060+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22061 childregs = task_pt_regs(p);
22062 p->thread.sp = (unsigned long) childregs;
22063 p->thread.usersp = me->thread.usersp;
22064+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22065 set_tsk_thread_flag(p, TIF_FORK);
22066 p->fpu_counter = 0;
22067 p->thread.io_bitmap_ptr = NULL;
22068@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22069 struct thread_struct *prev = &prev_p->thread;
22070 struct thread_struct *next = &next_p->thread;
22071 int cpu = smp_processor_id();
22072- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22073+ struct tss_struct *tss = init_tss + cpu;
22074 unsigned fsindex, gsindex;
22075 fpu_switch_t fpu;
22076
22077@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22078 prev->usersp = this_cpu_read(old_rsp);
22079 this_cpu_write(old_rsp, next->usersp);
22080 this_cpu_write(current_task, next_p);
22081+ this_cpu_write(current_tinfo, &next_p->tinfo);
22082
22083- this_cpu_write(kernel_stack,
22084- (unsigned long)task_stack_page(next_p) +
22085- THREAD_SIZE - KERNEL_STACK_OFFSET);
22086+ this_cpu_write(kernel_stack, next->sp0);
22087
22088 /*
22089 * Now maybe reload the debug registers and handle I/O bitmaps
22090@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22091 if (!p || p == current || p->state == TASK_RUNNING)
22092 return 0;
22093 stack = (unsigned long)task_stack_page(p);
22094- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22095+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22096 return 0;
22097 fp = *(u64 *)(p->thread.sp);
22098 do {
22099- if (fp < (unsigned long)stack ||
22100- fp >= (unsigned long)stack+THREAD_SIZE)
22101+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22102 return 0;
22103 ip = *(u64 *)(fp+8);
22104 if (!in_sched_functions(ip))
22105diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22106index b629bbe..0fa615a 100644
22107--- a/arch/x86/kernel/ptrace.c
22108+++ b/arch/x86/kernel/ptrace.c
22109@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22110 {
22111 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22112 unsigned long sp = (unsigned long)&regs->sp;
22113- struct thread_info *tinfo;
22114
22115- if (context == (sp & ~(THREAD_SIZE - 1)))
22116+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22117 return sp;
22118
22119- tinfo = (struct thread_info *)context;
22120- if (tinfo->previous_esp)
22121- return tinfo->previous_esp;
22122+ sp = *(unsigned long *)context;
22123+ if (sp)
22124+ return sp;
22125
22126 return (unsigned long)regs;
22127 }
22128@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22129 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22130 {
22131 int i;
22132- int dr7 = 0;
22133+ unsigned long dr7 = 0;
22134 struct arch_hw_breakpoint *info;
22135
22136 for (i = 0; i < HBP_NUM; i++) {
22137@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22138 unsigned long addr, unsigned long data)
22139 {
22140 int ret;
22141- unsigned long __user *datap = (unsigned long __user *)data;
22142+ unsigned long __user *datap = (__force unsigned long __user *)data;
22143
22144 switch (request) {
22145 /* read the word at location addr in the USER area. */
22146@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22147 if ((int) addr < 0)
22148 return -EIO;
22149 ret = do_get_thread_area(child, addr,
22150- (struct user_desc __user *)data);
22151+ (__force struct user_desc __user *) data);
22152 break;
22153
22154 case PTRACE_SET_THREAD_AREA:
22155 if ((int) addr < 0)
22156 return -EIO;
22157 ret = do_set_thread_area(child, addr,
22158- (struct user_desc __user *)data, 0);
22159+ (__force struct user_desc __user *) data, 0);
22160 break;
22161 #endif
22162
22163@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22164
22165 #ifdef CONFIG_X86_64
22166
22167-static struct user_regset x86_64_regsets[] __read_mostly = {
22168+static user_regset_no_const x86_64_regsets[] __read_only = {
22169 [REGSET_GENERAL] = {
22170 .core_note_type = NT_PRSTATUS,
22171 .n = sizeof(struct user_regs_struct) / sizeof(long),
22172@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22173 #endif /* CONFIG_X86_64 */
22174
22175 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22176-static struct user_regset x86_32_regsets[] __read_mostly = {
22177+static user_regset_no_const x86_32_regsets[] __read_only = {
22178 [REGSET_GENERAL] = {
22179 .core_note_type = NT_PRSTATUS,
22180 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22181@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22182 */
22183 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22184
22185-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22186+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22187 {
22188 #ifdef CONFIG_X86_64
22189 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22190@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22191 memset(info, 0, sizeof(*info));
22192 info->si_signo = SIGTRAP;
22193 info->si_code = si_code;
22194- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22195+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22196 }
22197
22198 void user_single_step_siginfo(struct task_struct *tsk,
22199@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22200 # define IS_IA32 0
22201 #endif
22202
22203+#ifdef CONFIG_GRKERNSEC_SETXID
22204+extern void gr_delayed_cred_worker(void);
22205+#endif
22206+
22207 /*
22208 * We must return the syscall number to actually look up in the table.
22209 * This can be -1L to skip running any syscall at all.
22210@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22211
22212 user_exit();
22213
22214+#ifdef CONFIG_GRKERNSEC_SETXID
22215+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22216+ gr_delayed_cred_worker();
22217+#endif
22218+
22219 /*
22220 * If we stepped into a sysenter/syscall insn, it trapped in
22221 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22222@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22223 */
22224 user_exit();
22225
22226+#ifdef CONFIG_GRKERNSEC_SETXID
22227+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22228+ gr_delayed_cred_worker();
22229+#endif
22230+
22231 audit_syscall_exit(regs);
22232
22233 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22234diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22235index 2cb9470..ff1fd80 100644
22236--- a/arch/x86/kernel/pvclock.c
22237+++ b/arch/x86/kernel/pvclock.c
22238@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22239 return pv_tsc_khz;
22240 }
22241
22242-static atomic64_t last_value = ATOMIC64_INIT(0);
22243+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22244
22245 void pvclock_resume(void)
22246 {
22247- atomic64_set(&last_value, 0);
22248+ atomic64_set_unchecked(&last_value, 0);
22249 }
22250
22251 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22252@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22253 * updating at the same time, and one of them could be slightly behind,
22254 * making the assumption that last_value always go forward fail to hold.
22255 */
22256- last = atomic64_read(&last_value);
22257+ last = atomic64_read_unchecked(&last_value);
22258 do {
22259 if (ret < last)
22260 return last;
22261- last = atomic64_cmpxchg(&last_value, last, ret);
22262+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22263 } while (unlikely(last != ret));
22264
22265 return ret;
22266diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22267index 76fa1e9..abf09ea 100644
22268--- a/arch/x86/kernel/reboot.c
22269+++ b/arch/x86/kernel/reboot.c
22270@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22271 EXPORT_SYMBOL(pm_power_off);
22272
22273 static const struct desc_ptr no_idt = {};
22274-static int reboot_mode;
22275+static unsigned short reboot_mode;
22276 enum reboot_type reboot_type = BOOT_ACPI;
22277 int reboot_force;
22278
22279@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22280
22281 void __noreturn machine_real_restart(unsigned int type)
22282 {
22283+
22284+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22285+ struct desc_struct *gdt;
22286+#endif
22287+
22288 local_irq_disable();
22289
22290 /*
22291@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22292
22293 /* Jump to the identity-mapped low memory code */
22294 #ifdef CONFIG_X86_32
22295- asm volatile("jmpl *%0" : :
22296+
22297+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22298+ gdt = get_cpu_gdt_table(smp_processor_id());
22299+ pax_open_kernel();
22300+#ifdef CONFIG_PAX_MEMORY_UDEREF
22301+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22302+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22303+ loadsegment(ds, __KERNEL_DS);
22304+ loadsegment(es, __KERNEL_DS);
22305+ loadsegment(ss, __KERNEL_DS);
22306+#endif
22307+#ifdef CONFIG_PAX_KERNEXEC
22308+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22309+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22310+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22311+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22312+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22313+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22314+#endif
22315+ pax_close_kernel();
22316+#endif
22317+
22318+ asm volatile("ljmpl *%0" : :
22319 "rm" (real_mode_header->machine_real_restart_asm),
22320 "a" (type));
22321 #else
22322@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22323 * try to force a triple fault and then cycle between hitting the keyboard
22324 * controller and doing that
22325 */
22326-static void native_machine_emergency_restart(void)
22327+static void __noreturn native_machine_emergency_restart(void)
22328 {
22329 int i;
22330 int attempt = 0;
22331@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22332 #endif
22333 }
22334
22335-static void __machine_emergency_restart(int emergency)
22336+static void __noreturn __machine_emergency_restart(int emergency)
22337 {
22338 reboot_emergency = emergency;
22339 machine_ops.emergency_restart();
22340 }
22341
22342-static void native_machine_restart(char *__unused)
22343+static void __noreturn native_machine_restart(char *__unused)
22344 {
22345 pr_notice("machine restart\n");
22346
22347@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22348 __machine_emergency_restart(0);
22349 }
22350
22351-static void native_machine_halt(void)
22352+static void __noreturn native_machine_halt(void)
22353 {
22354 /* Stop other cpus and apics */
22355 machine_shutdown();
22356@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22357 stop_this_cpu(NULL);
22358 }
22359
22360-static void native_machine_power_off(void)
22361+static void __noreturn native_machine_power_off(void)
22362 {
22363 if (pm_power_off) {
22364 if (!reboot_force)
22365@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22366 }
22367 /* A fallback in case there is no PM info available */
22368 tboot_shutdown(TB_SHUTDOWN_HALT);
22369+ unreachable();
22370 }
22371
22372-struct machine_ops machine_ops = {
22373+struct machine_ops machine_ops __read_only = {
22374 .power_off = native_machine_power_off,
22375 .shutdown = native_machine_shutdown,
22376 .emergency_restart = native_machine_emergency_restart,
22377diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22378index 7a6f3b3..bed145d7 100644
22379--- a/arch/x86/kernel/relocate_kernel_64.S
22380+++ b/arch/x86/kernel/relocate_kernel_64.S
22381@@ -11,6 +11,7 @@
22382 #include <asm/kexec.h>
22383 #include <asm/processor-flags.h>
22384 #include <asm/pgtable_types.h>
22385+#include <asm/alternative-asm.h>
22386
22387 /*
22388 * Must be relocatable PIC code callable as a C function
22389@@ -160,13 +161,14 @@ identity_mapped:
22390 xorq %rbp, %rbp
22391 xorq %r8, %r8
22392 xorq %r9, %r9
22393- xorq %r10, %r9
22394+ xorq %r10, %r10
22395 xorq %r11, %r11
22396 xorq %r12, %r12
22397 xorq %r13, %r13
22398 xorq %r14, %r14
22399 xorq %r15, %r15
22400
22401+ pax_force_retaddr 0, 1
22402 ret
22403
22404 1:
22405diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22406index 8b24289..d37b58b 100644
22407--- a/arch/x86/kernel/setup.c
22408+++ b/arch/x86/kernel/setup.c
22409@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22410
22411 switch (data->type) {
22412 case SETUP_E820_EXT:
22413- parse_e820_ext(data);
22414+ parse_e820_ext((struct setup_data __force_kernel *)data);
22415 break;
22416 case SETUP_DTB:
22417 add_dtb(pa_data);
22418@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22419 * area (640->1Mb) as ram even though it is not.
22420 * take them out.
22421 */
22422- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22423+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22424
22425 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22426 }
22427@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22428
22429 if (!boot_params.hdr.root_flags)
22430 root_mountflags &= ~MS_RDONLY;
22431- init_mm.start_code = (unsigned long) _text;
22432- init_mm.end_code = (unsigned long) _etext;
22433+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22434+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22435 init_mm.end_data = (unsigned long) _edata;
22436 init_mm.brk = _brk_end;
22437
22438- code_resource.start = virt_to_phys(_text);
22439- code_resource.end = virt_to_phys(_etext)-1;
22440- data_resource.start = virt_to_phys(_etext);
22441+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22442+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22443+ data_resource.start = virt_to_phys(_sdata);
22444 data_resource.end = virt_to_phys(_edata)-1;
22445 bss_resource.start = virt_to_phys(&__bss_start);
22446 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22447diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22448index 5cdff03..80fa283 100644
22449--- a/arch/x86/kernel/setup_percpu.c
22450+++ b/arch/x86/kernel/setup_percpu.c
22451@@ -21,19 +21,17 @@
22452 #include <asm/cpu.h>
22453 #include <asm/stackprotector.h>
22454
22455-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22456+#ifdef CONFIG_SMP
22457+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22458 EXPORT_PER_CPU_SYMBOL(cpu_number);
22459+#endif
22460
22461-#ifdef CONFIG_X86_64
22462 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22463-#else
22464-#define BOOT_PERCPU_OFFSET 0
22465-#endif
22466
22467 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22468 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22469
22470-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22471+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22472 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22473 };
22474 EXPORT_SYMBOL(__per_cpu_offset);
22475@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22476 {
22477 #ifdef CONFIG_NEED_MULTIPLE_NODES
22478 pg_data_t *last = NULL;
22479- unsigned int cpu;
22480+ int cpu;
22481
22482 for_each_possible_cpu(cpu) {
22483 int node = early_cpu_to_node(cpu);
22484@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22485 {
22486 #ifdef CONFIG_X86_32
22487 struct desc_struct gdt;
22488+ unsigned long base = per_cpu_offset(cpu);
22489
22490- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22491- 0x2 | DESCTYPE_S, 0x8);
22492- gdt.s = 1;
22493+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22494+ 0x83 | DESCTYPE_S, 0xC);
22495 write_gdt_entry(get_cpu_gdt_table(cpu),
22496 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22497 #endif
22498@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22499 /* alrighty, percpu areas up and running */
22500 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22501 for_each_possible_cpu(cpu) {
22502+#ifdef CONFIG_CC_STACKPROTECTOR
22503+#ifdef CONFIG_X86_32
22504+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22505+#endif
22506+#endif
22507 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22508 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22509 per_cpu(cpu_number, cpu) = cpu;
22510@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22511 */
22512 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22513 #endif
22514+#ifdef CONFIG_CC_STACKPROTECTOR
22515+#ifdef CONFIG_X86_32
22516+ if (!cpu)
22517+ per_cpu(stack_canary.canary, cpu) = canary;
22518+#endif
22519+#endif
22520 /*
22521 * Up to this point, the boot CPU has been using .init.data
22522 * area. Reload any changed state for the boot CPU.
22523diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22524index d6bf1f3..3ffce5a 100644
22525--- a/arch/x86/kernel/signal.c
22526+++ b/arch/x86/kernel/signal.c
22527@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22528 * Align the stack pointer according to the i386 ABI,
22529 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22530 */
22531- sp = ((sp + 4) & -16ul) - 4;
22532+ sp = ((sp - 12) & -16ul) - 4;
22533 #else /* !CONFIG_X86_32 */
22534 sp = round_down(sp, 16) - 8;
22535 #endif
22536@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22537 }
22538
22539 if (current->mm->context.vdso)
22540- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22541+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22542 else
22543- restorer = &frame->retcode;
22544+ restorer = (void __user *)&frame->retcode;
22545 if (ka->sa.sa_flags & SA_RESTORER)
22546 restorer = ka->sa.sa_restorer;
22547
22548@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22549 * reasons and because gdb uses it as a signature to notice
22550 * signal handler stack frames.
22551 */
22552- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22553+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22554
22555 if (err)
22556 return -EFAULT;
22557@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22558 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22559
22560 /* Set up to return from userspace. */
22561- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22562+ if (current->mm->context.vdso)
22563+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22564+ else
22565+ restorer = (void __user *)&frame->retcode;
22566 if (ka->sa.sa_flags & SA_RESTORER)
22567 restorer = ka->sa.sa_restorer;
22568 put_user_ex(restorer, &frame->pretcode);
22569@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22570 * reasons and because gdb uses it as a signature to notice
22571 * signal handler stack frames.
22572 */
22573- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22574+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22575 } put_user_catch(err);
22576
22577 err |= copy_siginfo_to_user(&frame->info, info);
22578diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22579index 48d2b7d..90d328a 100644
22580--- a/arch/x86/kernel/smp.c
22581+++ b/arch/x86/kernel/smp.c
22582@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22583
22584 __setup("nonmi_ipi", nonmi_ipi_setup);
22585
22586-struct smp_ops smp_ops = {
22587+struct smp_ops smp_ops __read_only = {
22588 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22589 .smp_prepare_cpus = native_smp_prepare_cpus,
22590 .smp_cpus_done = native_smp_cpus_done,
22591diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22592index ed0fe38..87fc692 100644
22593--- a/arch/x86/kernel/smpboot.c
22594+++ b/arch/x86/kernel/smpboot.c
22595@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22596 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22597 (THREAD_SIZE + task_stack_page(idle))) - 1);
22598 per_cpu(current_task, cpu) = idle;
22599+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22600
22601 #ifdef CONFIG_X86_32
22602 /* Stack for startup_32 can be just as for start_secondary onwards */
22603@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22604 #else
22605 clear_tsk_thread_flag(idle, TIF_FORK);
22606 initial_gs = per_cpu_offset(cpu);
22607- per_cpu(kernel_stack, cpu) =
22608- (unsigned long)task_stack_page(idle) -
22609- KERNEL_STACK_OFFSET + THREAD_SIZE;
22610+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22611 #endif
22612+
22613+ pax_open_kernel();
22614 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22615+ pax_close_kernel();
22616+
22617 initial_code = (unsigned long)start_secondary;
22618 stack_start = idle->thread.sp;
22619
22620@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22621 /* the FPU context is blank, nobody can own it */
22622 __cpu_disable_lazy_restore(cpu);
22623
22624+#ifdef CONFIG_PAX_PER_CPU_PGD
22625+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22626+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22627+ KERNEL_PGD_PTRS);
22628+#endif
22629+
22630+ /* the FPU context is blank, nobody can own it */
22631+ __cpu_disable_lazy_restore(cpu);
22632+
22633 err = do_boot_cpu(apicid, cpu, tidle);
22634 if (err) {
22635 pr_debug("do_boot_cpu failed %d\n", err);
22636diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22637index 9b4d51d..5d28b58 100644
22638--- a/arch/x86/kernel/step.c
22639+++ b/arch/x86/kernel/step.c
22640@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22641 struct desc_struct *desc;
22642 unsigned long base;
22643
22644- seg &= ~7UL;
22645+ seg >>= 3;
22646
22647 mutex_lock(&child->mm->context.lock);
22648- if (unlikely((seg >> 3) >= child->mm->context.size))
22649+ if (unlikely(seg >= child->mm->context.size))
22650 addr = -1L; /* bogus selector, access would fault */
22651 else {
22652 desc = child->mm->context.ldt + seg;
22653@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22654 addr += base;
22655 }
22656 mutex_unlock(&child->mm->context.lock);
22657- }
22658+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22659+ addr = ktla_ktva(addr);
22660
22661 return addr;
22662 }
22663@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22664 unsigned char opcode[15];
22665 unsigned long addr = convert_ip_to_linear(child, regs);
22666
22667+ if (addr == -EINVAL)
22668+ return 0;
22669+
22670 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22671 for (i = 0; i < copied; i++) {
22672 switch (opcode[i]) {
22673diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22674new file mode 100644
22675index 0000000..207bec6
22676--- /dev/null
22677+++ b/arch/x86/kernel/sys_i386_32.c
22678@@ -0,0 +1,250 @@
22679+/*
22680+ * This file contains various random system calls that
22681+ * have a non-standard calling sequence on the Linux/i386
22682+ * platform.
22683+ */
22684+
22685+#include <linux/errno.h>
22686+#include <linux/sched.h>
22687+#include <linux/mm.h>
22688+#include <linux/fs.h>
22689+#include <linux/smp.h>
22690+#include <linux/sem.h>
22691+#include <linux/msg.h>
22692+#include <linux/shm.h>
22693+#include <linux/stat.h>
22694+#include <linux/syscalls.h>
22695+#include <linux/mman.h>
22696+#include <linux/file.h>
22697+#include <linux/utsname.h>
22698+#include <linux/ipc.h>
22699+
22700+#include <linux/uaccess.h>
22701+#include <linux/unistd.h>
22702+
22703+#include <asm/syscalls.h>
22704+
22705+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22706+{
22707+ unsigned long pax_task_size = TASK_SIZE;
22708+
22709+#ifdef CONFIG_PAX_SEGMEXEC
22710+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22711+ pax_task_size = SEGMEXEC_TASK_SIZE;
22712+#endif
22713+
22714+ if (flags & MAP_FIXED)
22715+ if (len > pax_task_size || addr > pax_task_size - len)
22716+ return -EINVAL;
22717+
22718+ return 0;
22719+}
22720+
22721+unsigned long
22722+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22723+ unsigned long len, unsigned long pgoff, unsigned long flags)
22724+{
22725+ struct mm_struct *mm = current->mm;
22726+ struct vm_area_struct *vma;
22727+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22728+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22729+
22730+#ifdef CONFIG_PAX_SEGMEXEC
22731+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22732+ pax_task_size = SEGMEXEC_TASK_SIZE;
22733+#endif
22734+
22735+ pax_task_size -= PAGE_SIZE;
22736+
22737+ if (len > pax_task_size)
22738+ return -ENOMEM;
22739+
22740+ if (flags & MAP_FIXED)
22741+ return addr;
22742+
22743+#ifdef CONFIG_PAX_RANDMMAP
22744+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22745+#endif
22746+
22747+ if (addr) {
22748+ addr = PAGE_ALIGN(addr);
22749+ if (pax_task_size - len >= addr) {
22750+ vma = find_vma(mm, addr);
22751+ if (check_heap_stack_gap(vma, addr, len, offset))
22752+ return addr;
22753+ }
22754+ }
22755+ if (len > mm->cached_hole_size) {
22756+ start_addr = addr = mm->free_area_cache;
22757+ } else {
22758+ start_addr = addr = mm->mmap_base;
22759+ mm->cached_hole_size = 0;
22760+ }
22761+
22762+#ifdef CONFIG_PAX_PAGEEXEC
22763+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22764+ start_addr = 0x00110000UL;
22765+
22766+#ifdef CONFIG_PAX_RANDMMAP
22767+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22768+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22769+#endif
22770+
22771+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22772+ start_addr = addr = mm->mmap_base;
22773+ else
22774+ addr = start_addr;
22775+ }
22776+#endif
22777+
22778+full_search:
22779+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22780+ /* At this point: (!vma || addr < vma->vm_end). */
22781+ if (pax_task_size - len < addr) {
22782+ /*
22783+ * Start a new search - just in case we missed
22784+ * some holes.
22785+ */
22786+ if (start_addr != mm->mmap_base) {
22787+ start_addr = addr = mm->mmap_base;
22788+ mm->cached_hole_size = 0;
22789+ goto full_search;
22790+ }
22791+ return -ENOMEM;
22792+ }
22793+ if (check_heap_stack_gap(vma, addr, len, offset))
22794+ break;
22795+ if (addr + mm->cached_hole_size < vma->vm_start)
22796+ mm->cached_hole_size = vma->vm_start - addr;
22797+ addr = vma->vm_end;
22798+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22799+ start_addr = addr = mm->mmap_base;
22800+ mm->cached_hole_size = 0;
22801+ goto full_search;
22802+ }
22803+ }
22804+
22805+ /*
22806+ * Remember the place where we stopped the search:
22807+ */
22808+ mm->free_area_cache = addr + len;
22809+ return addr;
22810+}
22811+
22812+unsigned long
22813+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22814+ const unsigned long len, const unsigned long pgoff,
22815+ const unsigned long flags)
22816+{
22817+ struct vm_area_struct *vma;
22818+ struct mm_struct *mm = current->mm;
22819+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22820+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22821+
22822+#ifdef CONFIG_PAX_SEGMEXEC
22823+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22824+ pax_task_size = SEGMEXEC_TASK_SIZE;
22825+#endif
22826+
22827+ pax_task_size -= PAGE_SIZE;
22828+
22829+ /* requested length too big for entire address space */
22830+ if (len > pax_task_size)
22831+ return -ENOMEM;
22832+
22833+ if (flags & MAP_FIXED)
22834+ return addr;
22835+
22836+#ifdef CONFIG_PAX_PAGEEXEC
22837+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22838+ goto bottomup;
22839+#endif
22840+
22841+#ifdef CONFIG_PAX_RANDMMAP
22842+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22843+#endif
22844+
22845+ /* requesting a specific address */
22846+ if (addr) {
22847+ addr = PAGE_ALIGN(addr);
22848+ if (pax_task_size - len >= addr) {
22849+ vma = find_vma(mm, addr);
22850+ if (check_heap_stack_gap(vma, addr, len, offset))
22851+ return addr;
22852+ }
22853+ }
22854+
22855+ /* check if free_area_cache is useful for us */
22856+ if (len <= mm->cached_hole_size) {
22857+ mm->cached_hole_size = 0;
22858+ mm->free_area_cache = mm->mmap_base;
22859+ }
22860+
22861+ /* either no address requested or can't fit in requested address hole */
22862+ addr = mm->free_area_cache;
22863+
22864+ /* make sure it can fit in the remaining address space */
22865+ if (addr > len) {
22866+ vma = find_vma(mm, addr-len);
22867+ if (check_heap_stack_gap(vma, addr - len, len, offset))
22868+ /* remember the address as a hint for next time */
22869+ return (mm->free_area_cache = addr-len);
22870+ }
22871+
22872+ if (mm->mmap_base < len)
22873+ goto bottomup;
22874+
22875+ addr = mm->mmap_base-len;
22876+
22877+ do {
22878+ /*
22879+ * Lookup failure means no vma is above this address,
22880+ * else if new region fits below vma->vm_start,
22881+ * return with success:
22882+ */
22883+ vma = find_vma(mm, addr);
22884+ if (check_heap_stack_gap(vma, addr, len, offset))
22885+ /* remember the address as a hint for next time */
22886+ return (mm->free_area_cache = addr);
22887+
22888+ /* remember the largest hole we saw so far */
22889+ if (addr + mm->cached_hole_size < vma->vm_start)
22890+ mm->cached_hole_size = vma->vm_start - addr;
22891+
22892+ /* try just below the current vma->vm_start */
22893+ addr = skip_heap_stack_gap(vma, len, offset);
22894+ } while (!IS_ERR_VALUE(addr));
22895+
22896+bottomup:
22897+ /*
22898+ * A failed mmap() very likely causes application failure,
22899+ * so fall back to the bottom-up function here. This scenario
22900+ * can happen with large stack limits and large mmap()
22901+ * allocations.
22902+ */
22903+
22904+#ifdef CONFIG_PAX_SEGMEXEC
22905+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22906+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22907+ else
22908+#endif
22909+
22910+ mm->mmap_base = TASK_UNMAPPED_BASE;
22911+
22912+#ifdef CONFIG_PAX_RANDMMAP
22913+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22914+ mm->mmap_base += mm->delta_mmap;
22915+#endif
22916+
22917+ mm->free_area_cache = mm->mmap_base;
22918+ mm->cached_hole_size = ~0UL;
22919+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22920+ /*
22921+ * Restore the topdown base:
22922+ */
22923+ mm->mmap_base = base;
22924+ mm->free_area_cache = base;
22925+ mm->cached_hole_size = ~0UL;
22926+
22927+ return addr;
22928+}
22929diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22930index 97ef74b..57a1882 100644
22931--- a/arch/x86/kernel/sys_x86_64.c
22932+++ b/arch/x86/kernel/sys_x86_64.c
22933@@ -81,8 +81,8 @@ out:
22934 return error;
22935 }
22936
22937-static void find_start_end(unsigned long flags, unsigned long *begin,
22938- unsigned long *end)
22939+static void find_start_end(struct mm_struct *mm, unsigned long flags,
22940+ unsigned long *begin, unsigned long *end)
22941 {
22942 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22943 unsigned long new_begin;
22944@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22945 *begin = new_begin;
22946 }
22947 } else {
22948- *begin = TASK_UNMAPPED_BASE;
22949+ *begin = mm->mmap_base;
22950 *end = TASK_SIZE;
22951 }
22952 }
22953@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22954 struct vm_area_struct *vma;
22955 struct vm_unmapped_area_info info;
22956 unsigned long begin, end;
22957+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22958
22959 if (flags & MAP_FIXED)
22960 return addr;
22961
22962- find_start_end(flags, &begin, &end);
22963+ find_start_end(mm, flags, &begin, &end);
22964
22965 if (len > end)
22966 return -ENOMEM;
22967
22968+#ifdef CONFIG_PAX_RANDMMAP
22969+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22970+#endif
22971+
22972 if (addr) {
22973 addr = PAGE_ALIGN(addr);
22974 vma = find_vma(mm, addr);
22975- if (end - len >= addr &&
22976- (!vma || addr + len <= vma->vm_start))
22977+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22978 return addr;
22979 }
22980
22981@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22982 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22983 goto bottomup;
22984
22985+#ifdef CONFIG_PAX_RANDMMAP
22986+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22987+#endif
22988+
22989 /* requesting a specific address */
22990 if (addr) {
22991 addr = PAGE_ALIGN(addr);
22992diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22993index f84fe00..f41d9f1 100644
22994--- a/arch/x86/kernel/tboot.c
22995+++ b/arch/x86/kernel/tboot.c
22996@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22997
22998 void tboot_shutdown(u32 shutdown_type)
22999 {
23000- void (*shutdown)(void);
23001+ void (* __noreturn shutdown)(void);
23002
23003 if (!tboot_enabled())
23004 return;
23005@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23006
23007 switch_to_tboot_pt();
23008
23009- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23010+ shutdown = (void *)tboot->shutdown_entry;
23011 shutdown();
23012
23013 /* should not reach here */
23014@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23015 return 0;
23016 }
23017
23018-static atomic_t ap_wfs_count;
23019+static atomic_unchecked_t ap_wfs_count;
23020
23021 static int tboot_wait_for_aps(int num_aps)
23022 {
23023@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23024 {
23025 switch (action) {
23026 case CPU_DYING:
23027- atomic_inc(&ap_wfs_count);
23028+ atomic_inc_unchecked(&ap_wfs_count);
23029 if (num_online_cpus() == 1)
23030- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23031+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23032 return NOTIFY_BAD;
23033 break;
23034 }
23035 return NOTIFY_OK;
23036 }
23037
23038-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23039+static struct notifier_block tboot_cpu_notifier =
23040 {
23041 .notifier_call = tboot_cpu_callback,
23042 };
23043@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23044
23045 tboot_create_trampoline();
23046
23047- atomic_set(&ap_wfs_count, 0);
23048+ atomic_set_unchecked(&ap_wfs_count, 0);
23049 register_hotcpu_notifier(&tboot_cpu_notifier);
23050
23051 acpi_os_set_prepare_sleep(&tboot_sleep);
23052diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23053index 24d3c91..d06b473 100644
23054--- a/arch/x86/kernel/time.c
23055+++ b/arch/x86/kernel/time.c
23056@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23057 {
23058 unsigned long pc = instruction_pointer(regs);
23059
23060- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23061+ if (!user_mode(regs) && in_lock_functions(pc)) {
23062 #ifdef CONFIG_FRAME_POINTER
23063- return *(unsigned long *)(regs->bp + sizeof(long));
23064+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23065 #else
23066 unsigned long *sp =
23067 (unsigned long *)kernel_stack_pointer(regs);
23068@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23069 * or above a saved flags. Eflags has bits 22-31 zero,
23070 * kernel addresses don't.
23071 */
23072+
23073+#ifdef CONFIG_PAX_KERNEXEC
23074+ return ktla_ktva(sp[0]);
23075+#else
23076 if (sp[0] >> 22)
23077 return sp[0];
23078 if (sp[1] >> 22)
23079 return sp[1];
23080 #endif
23081+
23082+#endif
23083 }
23084 return pc;
23085 }
23086diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23087index 9d9d2f9..cad418a 100644
23088--- a/arch/x86/kernel/tls.c
23089+++ b/arch/x86/kernel/tls.c
23090@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23091 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23092 return -EINVAL;
23093
23094+#ifdef CONFIG_PAX_SEGMEXEC
23095+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23096+ return -EINVAL;
23097+#endif
23098+
23099 set_tls_desc(p, idx, &info, 1);
23100
23101 return 0;
23102@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23103
23104 if (kbuf)
23105 info = kbuf;
23106- else if (__copy_from_user(infobuf, ubuf, count))
23107+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23108 return -EFAULT;
23109 else
23110 info = infobuf;
23111diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23112index ecffca1..95c4d13 100644
23113--- a/arch/x86/kernel/traps.c
23114+++ b/arch/x86/kernel/traps.c
23115@@ -68,12 +68,6 @@
23116 #include <asm/setup.h>
23117
23118 asmlinkage int system_call(void);
23119-
23120-/*
23121- * The IDT has to be page-aligned to simplify the Pentium
23122- * F0 0F bug workaround.
23123- */
23124-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23125 #endif
23126
23127 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23128@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23129 }
23130
23131 static int __kprobes
23132-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23133+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23134 struct pt_regs *regs, long error_code)
23135 {
23136 #ifdef CONFIG_X86_32
23137- if (regs->flags & X86_VM_MASK) {
23138+ if (v8086_mode(regs)) {
23139 /*
23140 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23141 * On nmi (interrupt 2), do_trap should not be called.
23142@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23143 return -1;
23144 }
23145 #endif
23146- if (!user_mode(regs)) {
23147+ if (!user_mode_novm(regs)) {
23148 if (!fixup_exception(regs)) {
23149 tsk->thread.error_code = error_code;
23150 tsk->thread.trap_nr = trapnr;
23151+
23152+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23153+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23154+ str = "PAX: suspicious stack segment fault";
23155+#endif
23156+
23157 die(str, regs, error_code);
23158 }
23159+
23160+#ifdef CONFIG_PAX_REFCOUNT
23161+ if (trapnr == 4)
23162+ pax_report_refcount_overflow(regs);
23163+#endif
23164+
23165 return 0;
23166 }
23167
23168@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23169 }
23170
23171 static void __kprobes
23172-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23173+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23174 long error_code, siginfo_t *info)
23175 {
23176 struct task_struct *tsk = current;
23177@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23178 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23179 printk_ratelimit()) {
23180 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23181- tsk->comm, tsk->pid, str,
23182+ tsk->comm, task_pid_nr(tsk), str,
23183 regs->ip, regs->sp, error_code);
23184 print_vma_addr(" in ", regs->ip);
23185 pr_cont("\n");
23186@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23187 conditional_sti(regs);
23188
23189 #ifdef CONFIG_X86_32
23190- if (regs->flags & X86_VM_MASK) {
23191+ if (v8086_mode(regs)) {
23192 local_irq_enable();
23193 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23194 goto exit;
23195@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23196 #endif
23197
23198 tsk = current;
23199- if (!user_mode(regs)) {
23200+ if (!user_mode_novm(regs)) {
23201 if (fixup_exception(regs))
23202 goto exit;
23203
23204 tsk->thread.error_code = error_code;
23205 tsk->thread.trap_nr = X86_TRAP_GP;
23206 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23207- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23208+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23209+
23210+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23211+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23212+ die("PAX: suspicious general protection fault", regs, error_code);
23213+ else
23214+#endif
23215+
23216 die("general protection fault", regs, error_code);
23217+ }
23218 goto exit;
23219 }
23220
23221+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23222+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23223+ struct mm_struct *mm = tsk->mm;
23224+ unsigned long limit;
23225+
23226+ down_write(&mm->mmap_sem);
23227+ limit = mm->context.user_cs_limit;
23228+ if (limit < TASK_SIZE) {
23229+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23230+ up_write(&mm->mmap_sem);
23231+ return;
23232+ }
23233+ up_write(&mm->mmap_sem);
23234+ }
23235+#endif
23236+
23237 tsk->thread.error_code = error_code;
23238 tsk->thread.trap_nr = X86_TRAP_GP;
23239
23240@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23241 /* It's safe to allow irq's after DR6 has been saved */
23242 preempt_conditional_sti(regs);
23243
23244- if (regs->flags & X86_VM_MASK) {
23245+ if (v8086_mode(regs)) {
23246 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23247 X86_TRAP_DB);
23248 preempt_conditional_cli(regs);
23249@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23250 * We already checked v86 mode above, so we can check for kernel mode
23251 * by just checking the CPL of CS.
23252 */
23253- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23254+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23255 tsk->thread.debugreg6 &= ~DR_STEP;
23256 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23257 regs->flags &= ~X86_EFLAGS_TF;
23258@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23259 return;
23260 conditional_sti(regs);
23261
23262- if (!user_mode_vm(regs))
23263+ if (!user_mode(regs))
23264 {
23265 if (!fixup_exception(regs)) {
23266 task->thread.error_code = error_code;
23267diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23268index c71025b..b117501 100644
23269--- a/arch/x86/kernel/uprobes.c
23270+++ b/arch/x86/kernel/uprobes.c
23271@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23272 int ret = NOTIFY_DONE;
23273
23274 /* We are only interested in userspace traps */
23275- if (regs && !user_mode_vm(regs))
23276+ if (regs && !user_mode(regs))
23277 return NOTIFY_DONE;
23278
23279 switch (val) {
23280diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23281index b9242ba..50c5edd 100644
23282--- a/arch/x86/kernel/verify_cpu.S
23283+++ b/arch/x86/kernel/verify_cpu.S
23284@@ -20,6 +20,7 @@
23285 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23286 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23287 * arch/x86/kernel/head_32.S: processor startup
23288+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23289 *
23290 * verify_cpu, returns the status of longmode and SSE in register %eax.
23291 * 0: Success 1: Failure
23292diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23293index 1dfe69c..a3df6f6 100644
23294--- a/arch/x86/kernel/vm86_32.c
23295+++ b/arch/x86/kernel/vm86_32.c
23296@@ -43,6 +43,7 @@
23297 #include <linux/ptrace.h>
23298 #include <linux/audit.h>
23299 #include <linux/stddef.h>
23300+#include <linux/grsecurity.h>
23301
23302 #include <asm/uaccess.h>
23303 #include <asm/io.h>
23304@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23305 do_exit(SIGSEGV);
23306 }
23307
23308- tss = &per_cpu(init_tss, get_cpu());
23309+ tss = init_tss + get_cpu();
23310 current->thread.sp0 = current->thread.saved_sp0;
23311 current->thread.sysenter_cs = __KERNEL_CS;
23312 load_sp0(tss, &current->thread);
23313@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23314 struct task_struct *tsk;
23315 int tmp, ret = -EPERM;
23316
23317+#ifdef CONFIG_GRKERNSEC_VM86
23318+ if (!capable(CAP_SYS_RAWIO)) {
23319+ gr_handle_vm86();
23320+ goto out;
23321+ }
23322+#endif
23323+
23324 tsk = current;
23325 if (tsk->thread.saved_sp0)
23326 goto out;
23327@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23328 int tmp, ret;
23329 struct vm86plus_struct __user *v86;
23330
23331+#ifdef CONFIG_GRKERNSEC_VM86
23332+ if (!capable(CAP_SYS_RAWIO)) {
23333+ gr_handle_vm86();
23334+ ret = -EPERM;
23335+ goto out;
23336+ }
23337+#endif
23338+
23339 tsk = current;
23340 switch (cmd) {
23341 case VM86_REQUEST_IRQ:
23342@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23343 tsk->thread.saved_fs = info->regs32->fs;
23344 tsk->thread.saved_gs = get_user_gs(info->regs32);
23345
23346- tss = &per_cpu(init_tss, get_cpu());
23347+ tss = init_tss + get_cpu();
23348 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23349 if (cpu_has_sep)
23350 tsk->thread.sysenter_cs = 0;
23351@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23352 goto cannot_handle;
23353 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23354 goto cannot_handle;
23355- intr_ptr = (unsigned long __user *) (i << 2);
23356+ intr_ptr = (__force unsigned long __user *) (i << 2);
23357 if (get_user(segoffs, intr_ptr))
23358 goto cannot_handle;
23359 if ((segoffs >> 16) == BIOSSEG)
23360diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23361index 22a1530..8fbaaad 100644
23362--- a/arch/x86/kernel/vmlinux.lds.S
23363+++ b/arch/x86/kernel/vmlinux.lds.S
23364@@ -26,6 +26,13 @@
23365 #include <asm/page_types.h>
23366 #include <asm/cache.h>
23367 #include <asm/boot.h>
23368+#include <asm/segment.h>
23369+
23370+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23371+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23372+#else
23373+#define __KERNEL_TEXT_OFFSET 0
23374+#endif
23375
23376 #undef i386 /* in case the preprocessor is a 32bit one */
23377
23378@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23379
23380 PHDRS {
23381 text PT_LOAD FLAGS(5); /* R_E */
23382+#ifdef CONFIG_X86_32
23383+ module PT_LOAD FLAGS(5); /* R_E */
23384+#endif
23385+#ifdef CONFIG_XEN
23386+ rodata PT_LOAD FLAGS(5); /* R_E */
23387+#else
23388+ rodata PT_LOAD FLAGS(4); /* R__ */
23389+#endif
23390 data PT_LOAD FLAGS(6); /* RW_ */
23391-#ifdef CONFIG_X86_64
23392+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23393 #ifdef CONFIG_SMP
23394 percpu PT_LOAD FLAGS(6); /* RW_ */
23395 #endif
23396+ text.init PT_LOAD FLAGS(5); /* R_E */
23397+ text.exit PT_LOAD FLAGS(5); /* R_E */
23398 init PT_LOAD FLAGS(7); /* RWE */
23399-#endif
23400 note PT_NOTE FLAGS(0); /* ___ */
23401 }
23402
23403 SECTIONS
23404 {
23405 #ifdef CONFIG_X86_32
23406- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23407- phys_startup_32 = startup_32 - LOAD_OFFSET;
23408+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23409 #else
23410- . = __START_KERNEL;
23411- phys_startup_64 = startup_64 - LOAD_OFFSET;
23412+ . = __START_KERNEL;
23413 #endif
23414
23415 /* Text and read-only data */
23416- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23417- _text = .;
23418+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23419 /* bootstrapping code */
23420+#ifdef CONFIG_X86_32
23421+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23422+#else
23423+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23424+#endif
23425+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23426+ _text = .;
23427 HEAD_TEXT
23428 #ifdef CONFIG_X86_32
23429 . = ALIGN(PAGE_SIZE);
23430@@ -108,13 +128,48 @@ SECTIONS
23431 IRQENTRY_TEXT
23432 *(.fixup)
23433 *(.gnu.warning)
23434- /* End of text section */
23435- _etext = .;
23436 } :text = 0x9090
23437
23438- NOTES :text :note
23439+ . += __KERNEL_TEXT_OFFSET;
23440
23441- EXCEPTION_TABLE(16) :text = 0x9090
23442+#ifdef CONFIG_X86_32
23443+ . = ALIGN(PAGE_SIZE);
23444+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23445+
23446+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23447+ MODULES_EXEC_VADDR = .;
23448+ BYTE(0)
23449+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23450+ . = ALIGN(HPAGE_SIZE) - 1;
23451+ MODULES_EXEC_END = .;
23452+#endif
23453+
23454+ } :module
23455+#endif
23456+
23457+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23458+ /* End of text section */
23459+ BYTE(0)
23460+ _etext = . - __KERNEL_TEXT_OFFSET;
23461+ }
23462+
23463+#ifdef CONFIG_X86_32
23464+ . = ALIGN(PAGE_SIZE);
23465+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23466+ *(.idt)
23467+ . = ALIGN(PAGE_SIZE);
23468+ *(.empty_zero_page)
23469+ *(.initial_pg_fixmap)
23470+ *(.initial_pg_pmd)
23471+ *(.initial_page_table)
23472+ *(.swapper_pg_dir)
23473+ } :rodata
23474+#endif
23475+
23476+ . = ALIGN(PAGE_SIZE);
23477+ NOTES :rodata :note
23478+
23479+ EXCEPTION_TABLE(16) :rodata
23480
23481 #if defined(CONFIG_DEBUG_RODATA)
23482 /* .text should occupy whole number of pages */
23483@@ -126,16 +181,20 @@ SECTIONS
23484
23485 /* Data */
23486 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23487+
23488+#ifdef CONFIG_PAX_KERNEXEC
23489+ . = ALIGN(HPAGE_SIZE);
23490+#else
23491+ . = ALIGN(PAGE_SIZE);
23492+#endif
23493+
23494 /* Start of data section */
23495 _sdata = .;
23496
23497 /* init_task */
23498 INIT_TASK_DATA(THREAD_SIZE)
23499
23500-#ifdef CONFIG_X86_32
23501- /* 32 bit has nosave before _edata */
23502 NOSAVE_DATA
23503-#endif
23504
23505 PAGE_ALIGNED_DATA(PAGE_SIZE)
23506
23507@@ -176,12 +235,19 @@ SECTIONS
23508 #endif /* CONFIG_X86_64 */
23509
23510 /* Init code and data - will be freed after init */
23511- . = ALIGN(PAGE_SIZE);
23512 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23513+ BYTE(0)
23514+
23515+#ifdef CONFIG_PAX_KERNEXEC
23516+ . = ALIGN(HPAGE_SIZE);
23517+#else
23518+ . = ALIGN(PAGE_SIZE);
23519+#endif
23520+
23521 __init_begin = .; /* paired with __init_end */
23522- }
23523+ } :init.begin
23524
23525-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23526+#ifdef CONFIG_SMP
23527 /*
23528 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23529 * output PHDR, so the next output section - .init.text - should
23530@@ -190,12 +256,27 @@ SECTIONS
23531 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23532 #endif
23533
23534- INIT_TEXT_SECTION(PAGE_SIZE)
23535-#ifdef CONFIG_X86_64
23536- :init
23537-#endif
23538+ . = ALIGN(PAGE_SIZE);
23539+ init_begin = .;
23540+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23541+ VMLINUX_SYMBOL(_sinittext) = .;
23542+ INIT_TEXT
23543+ VMLINUX_SYMBOL(_einittext) = .;
23544+ . = ALIGN(PAGE_SIZE);
23545+ } :text.init
23546
23547- INIT_DATA_SECTION(16)
23548+ /*
23549+ * .exit.text is discard at runtime, not link time, to deal with
23550+ * references from .altinstructions and .eh_frame
23551+ */
23552+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23553+ EXIT_TEXT
23554+ . = ALIGN(16);
23555+ } :text.exit
23556+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23557+
23558+ . = ALIGN(PAGE_SIZE);
23559+ INIT_DATA_SECTION(16) :init
23560
23561 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23562 __x86_cpu_dev_start = .;
23563@@ -257,19 +338,12 @@ SECTIONS
23564 }
23565
23566 . = ALIGN(8);
23567- /*
23568- * .exit.text is discard at runtime, not link time, to deal with
23569- * references from .altinstructions and .eh_frame
23570- */
23571- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23572- EXIT_TEXT
23573- }
23574
23575 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23576 EXIT_DATA
23577 }
23578
23579-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23580+#ifndef CONFIG_SMP
23581 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23582 #endif
23583
23584@@ -288,16 +362,10 @@ SECTIONS
23585 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23586 __smp_locks = .;
23587 *(.smp_locks)
23588- . = ALIGN(PAGE_SIZE);
23589 __smp_locks_end = .;
23590+ . = ALIGN(PAGE_SIZE);
23591 }
23592
23593-#ifdef CONFIG_X86_64
23594- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23595- NOSAVE_DATA
23596- }
23597-#endif
23598-
23599 /* BSS */
23600 . = ALIGN(PAGE_SIZE);
23601 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23602@@ -313,6 +381,7 @@ SECTIONS
23603 __brk_base = .;
23604 . += 64 * 1024; /* 64k alignment slop space */
23605 *(.brk_reservation) /* areas brk users have reserved */
23606+ . = ALIGN(HPAGE_SIZE);
23607 __brk_limit = .;
23608 }
23609
23610@@ -339,13 +408,12 @@ SECTIONS
23611 * for the boot processor.
23612 */
23613 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23614-INIT_PER_CPU(gdt_page);
23615 INIT_PER_CPU(irq_stack_union);
23616
23617 /*
23618 * Build-time check on the image size:
23619 */
23620-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23621+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23622 "kernel image bigger than KERNEL_IMAGE_SIZE");
23623
23624 #ifdef CONFIG_SMP
23625diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23626index 9a907a6..f83f921 100644
23627--- a/arch/x86/kernel/vsyscall_64.c
23628+++ b/arch/x86/kernel/vsyscall_64.c
23629@@ -56,15 +56,13 @@
23630 DEFINE_VVAR(int, vgetcpu_mode);
23631 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23632
23633-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23634+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23635
23636 static int __init vsyscall_setup(char *str)
23637 {
23638 if (str) {
23639 if (!strcmp("emulate", str))
23640 vsyscall_mode = EMULATE;
23641- else if (!strcmp("native", str))
23642- vsyscall_mode = NATIVE;
23643 else if (!strcmp("none", str))
23644 vsyscall_mode = NONE;
23645 else
23646@@ -323,8 +321,7 @@ do_ret:
23647 return true;
23648
23649 sigsegv:
23650- force_sig(SIGSEGV, current);
23651- return true;
23652+ do_group_exit(SIGKILL);
23653 }
23654
23655 /*
23656@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23657 extern char __vvar_page;
23658 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23659
23660- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23661- vsyscall_mode == NATIVE
23662- ? PAGE_KERNEL_VSYSCALL
23663- : PAGE_KERNEL_VVAR);
23664+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23665 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23666 (unsigned long)VSYSCALL_START);
23667
23668diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23669index 1330dd1..d220b99 100644
23670--- a/arch/x86/kernel/x8664_ksyms_64.c
23671+++ b/arch/x86/kernel/x8664_ksyms_64.c
23672@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23673 EXPORT_SYMBOL(copy_user_generic_unrolled);
23674 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23675 EXPORT_SYMBOL(__copy_user_nocache);
23676-EXPORT_SYMBOL(_copy_from_user);
23677-EXPORT_SYMBOL(_copy_to_user);
23678
23679 EXPORT_SYMBOL(copy_page);
23680 EXPORT_SYMBOL(clear_page);
23681diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23682index 7a3d075..6cb373d 100644
23683--- a/arch/x86/kernel/x86_init.c
23684+++ b/arch/x86/kernel/x86_init.c
23685@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23686 },
23687 };
23688
23689-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23690+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23691 .early_percpu_clock_init = x86_init_noop,
23692 .setup_percpu_clockev = setup_secondary_APIC_clock,
23693 };
23694@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23695 static void default_nmi_init(void) { };
23696 static int default_i8042_detect(void) { return 1; };
23697
23698-struct x86_platform_ops x86_platform = {
23699+struct x86_platform_ops x86_platform __read_only = {
23700 .calibrate_tsc = native_calibrate_tsc,
23701 .get_wallclock = mach_get_cmos_time,
23702 .set_wallclock = mach_set_rtc_mmss,
23703@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23704 };
23705
23706 EXPORT_SYMBOL_GPL(x86_platform);
23707-struct x86_msi_ops x86_msi = {
23708+struct x86_msi_ops x86_msi __read_only = {
23709 .setup_msi_irqs = native_setup_msi_irqs,
23710 .teardown_msi_irq = native_teardown_msi_irq,
23711 .teardown_msi_irqs = default_teardown_msi_irqs,
23712 .restore_msi_irqs = default_restore_msi_irqs,
23713 };
23714
23715-struct x86_io_apic_ops x86_io_apic_ops = {
23716+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23717 .init = native_io_apic_init_mappings,
23718 .read = native_io_apic_read,
23719 .write = native_io_apic_write,
23720diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23721index ada87a3..afea76d 100644
23722--- a/arch/x86/kernel/xsave.c
23723+++ b/arch/x86/kernel/xsave.c
23724@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23725 {
23726 int err;
23727
23728+ buf = (struct xsave_struct __user *)____m(buf);
23729 if (use_xsave())
23730 err = xsave_user(buf);
23731 else if (use_fxsr())
23732@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23733 */
23734 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23735 {
23736+ buf = (void __user *)____m(buf);
23737 if (use_xsave()) {
23738 if ((unsigned long)buf % 64 || fx_only) {
23739 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23740diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23741index a20ecb5..d0e2194 100644
23742--- a/arch/x86/kvm/cpuid.c
23743+++ b/arch/x86/kvm/cpuid.c
23744@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23745 struct kvm_cpuid2 *cpuid,
23746 struct kvm_cpuid_entry2 __user *entries)
23747 {
23748- int r;
23749+ int r, i;
23750
23751 r = -E2BIG;
23752 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23753 goto out;
23754 r = -EFAULT;
23755- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23756- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23757+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23758 goto out;
23759+ for (i = 0; i < cpuid->nent; ++i) {
23760+ struct kvm_cpuid_entry2 cpuid_entry;
23761+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23762+ goto out;
23763+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23764+ }
23765 vcpu->arch.cpuid_nent = cpuid->nent;
23766 kvm_apic_set_version(vcpu);
23767 kvm_x86_ops->cpuid_update(vcpu);
23768@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23769 struct kvm_cpuid2 *cpuid,
23770 struct kvm_cpuid_entry2 __user *entries)
23771 {
23772- int r;
23773+ int r, i;
23774
23775 r = -E2BIG;
23776 if (cpuid->nent < vcpu->arch.cpuid_nent)
23777 goto out;
23778 r = -EFAULT;
23779- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23780- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23781+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23782 goto out;
23783+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23784+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23785+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23786+ goto out;
23787+ }
23788 return 0;
23789
23790 out:
23791diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23792index a27e763..54bfe43 100644
23793--- a/arch/x86/kvm/emulate.c
23794+++ b/arch/x86/kvm/emulate.c
23795@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23796
23797 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23798 do { \
23799+ unsigned long _tmp; \
23800 __asm__ __volatile__ ( \
23801 _PRE_EFLAGS("0", "4", "2") \
23802 _op _suffix " %"_x"3,%1; " \
23803@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23804 /* Raw emulation: instruction has two explicit operands. */
23805 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23806 do { \
23807- unsigned long _tmp; \
23808- \
23809 switch ((ctxt)->dst.bytes) { \
23810 case 2: \
23811 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23812@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23813
23814 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23815 do { \
23816- unsigned long _tmp; \
23817 switch ((ctxt)->dst.bytes) { \
23818 case 1: \
23819 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23820diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23821index 9392f52..0e56d77 100644
23822--- a/arch/x86/kvm/lapic.c
23823+++ b/arch/x86/kvm/lapic.c
23824@@ -55,7 +55,7 @@
23825 #define APIC_BUS_CYCLE_NS 1
23826
23827 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23828-#define apic_debug(fmt, arg...)
23829+#define apic_debug(fmt, arg...) do {} while (0)
23830
23831 #define APIC_LVT_NUM 6
23832 /* 14 is the version for Xeon and Pentium 8.4.8*/
23833diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23834index 891eb6d..e027900 100644
23835--- a/arch/x86/kvm/paging_tmpl.h
23836+++ b/arch/x86/kvm/paging_tmpl.h
23837@@ -208,7 +208,7 @@ retry_walk:
23838 if (unlikely(kvm_is_error_hva(host_addr)))
23839 goto error;
23840
23841- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23842+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23843 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23844 goto error;
23845 walker->ptep_user[walker->level - 1] = ptep_user;
23846diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23847index d29d3cd..ec9d522 100644
23848--- a/arch/x86/kvm/svm.c
23849+++ b/arch/x86/kvm/svm.c
23850@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23851 int cpu = raw_smp_processor_id();
23852
23853 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23854+
23855+ pax_open_kernel();
23856 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23857+ pax_close_kernel();
23858+
23859 load_TR_desc();
23860 }
23861
23862@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23863 #endif
23864 #endif
23865
23866+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23867+ __set_fs(current_thread_info()->addr_limit);
23868+#endif
23869+
23870 reload_tss(vcpu);
23871
23872 local_irq_disable();
23873diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23874index 9120ae1..238abc0 100644
23875--- a/arch/x86/kvm/vmx.c
23876+++ b/arch/x86/kvm/vmx.c
23877@@ -1370,7 +1370,11 @@ static void reload_tss(void)
23878 struct desc_struct *descs;
23879
23880 descs = (void *)gdt->address;
23881+
23882+ pax_open_kernel();
23883 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23884+ pax_close_kernel();
23885+
23886 load_TR_desc();
23887 }
23888
23889@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23890 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23891 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23892
23893+#ifdef CONFIG_PAX_PER_CPU_PGD
23894+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23895+#endif
23896+
23897 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23898 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23899 vmx->loaded_vmcs->cpu = cpu;
23900@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23901 if (!cpu_has_vmx_flexpriority())
23902 flexpriority_enabled = 0;
23903
23904- if (!cpu_has_vmx_tpr_shadow())
23905- kvm_x86_ops->update_cr8_intercept = NULL;
23906+ if (!cpu_has_vmx_tpr_shadow()) {
23907+ pax_open_kernel();
23908+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23909+ pax_close_kernel();
23910+ }
23911
23912 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23913 kvm_disable_largepages();
23914@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23915
23916 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23917 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23918+
23919+#ifndef CONFIG_PAX_PER_CPU_PGD
23920 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23921+#endif
23922
23923 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23924 #ifdef CONFIG_X86_64
23925@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23926 native_store_idt(&dt);
23927 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23928
23929- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23930+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23931
23932 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23933 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23934@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23935 "jmp 2f \n\t"
23936 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23937 "2: "
23938+
23939+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23940+ "ljmp %[cs],$3f\n\t"
23941+ "3: "
23942+#endif
23943+
23944 /* Save guest registers, load host registers, keep flags */
23945 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23946 "pop %0 \n\t"
23947@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23948 #endif
23949 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23950 [wordsize]"i"(sizeof(ulong))
23951+
23952+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23953+ ,[cs]"i"(__KERNEL_CS)
23954+#endif
23955+
23956 : "cc", "memory"
23957 #ifdef CONFIG_X86_64
23958 , "rax", "rbx", "rdi", "rsi"
23959@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23960 if (debugctlmsr)
23961 update_debugctlmsr(debugctlmsr);
23962
23963-#ifndef CONFIG_X86_64
23964+#ifdef CONFIG_X86_32
23965 /*
23966 * The sysexit path does not restore ds/es, so we must set them to
23967 * a reasonable value ourselves.
23968@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23969 * may be executed in interrupt context, which saves and restore segments
23970 * around it, nullifying its effect.
23971 */
23972- loadsegment(ds, __USER_DS);
23973- loadsegment(es, __USER_DS);
23974+ loadsegment(ds, __KERNEL_DS);
23975+ loadsegment(es, __KERNEL_DS);
23976+ loadsegment(ss, __KERNEL_DS);
23977+
23978+#ifdef CONFIG_PAX_KERNEXEC
23979+ loadsegment(fs, __KERNEL_PERCPU);
23980+#endif
23981+
23982+#ifdef CONFIG_PAX_MEMORY_UDEREF
23983+ __set_fs(current_thread_info()->addr_limit);
23984+#endif
23985+
23986 #endif
23987
23988 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23989diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23990index c243b81..b692af3 100644
23991--- a/arch/x86/kvm/x86.c
23992+++ b/arch/x86/kvm/x86.c
23993@@ -1408,10 +1408,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
23994 unsigned long flags, this_tsc_khz;
23995 struct kvm_vcpu_arch *vcpu = &v->arch;
23996 struct kvm_arch *ka = &v->kvm->arch;
23997- void *shared_kaddr;
23998 s64 kernel_ns, max_kernel_ns;
23999 u64 tsc_timestamp, host_tsc;
24000- struct pvclock_vcpu_time_info *guest_hv_clock;
24001+ struct pvclock_vcpu_time_info guest_hv_clock;
24002 u8 pvclock_flags;
24003 bool use_master_clock;
24004
24005@@ -1465,7 +1464,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24006
24007 local_irq_restore(flags);
24008
24009- if (!vcpu->time_page)
24010+ if (!vcpu->pv_time_enabled)
24011 return 0;
24012
24013 /*
24014@@ -1527,12 +1526,12 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24015 */
24016 vcpu->hv_clock.version += 2;
24017
24018- shared_kaddr = kmap_atomic(vcpu->time_page);
24019-
24020- guest_hv_clock = shared_kaddr + vcpu->time_offset;
24021+ if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
24022+ &guest_hv_clock, sizeof(guest_hv_clock))))
24023+ return 0;
24024
24025 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
24026- pvclock_flags = (guest_hv_clock->flags & PVCLOCK_GUEST_STOPPED);
24027+ pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);
24028
24029 if (vcpu->pvclock_set_guest_stopped_request) {
24030 pvclock_flags |= PVCLOCK_GUEST_STOPPED;
24031@@ -1545,12 +1544,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24032
24033 vcpu->hv_clock.flags = pvclock_flags;
24034
24035- memcpy(shared_kaddr + vcpu->time_offset, &vcpu->hv_clock,
24036- sizeof(vcpu->hv_clock));
24037-
24038- kunmap_atomic(shared_kaddr);
24039-
24040- mark_page_dirty(v->kvm, vcpu->time >> PAGE_SHIFT);
24041+ kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
24042+ &vcpu->hv_clock,
24043+ sizeof(vcpu->hv_clock));
24044 return 0;
24045 }
24046
24047@@ -1692,8 +1688,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24048 {
24049 struct kvm *kvm = vcpu->kvm;
24050 int lm = is_long_mode(vcpu);
24051- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24052- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24053+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24054+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24055 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24056 : kvm->arch.xen_hvm_config.blob_size_32;
24057 u32 page_num = data & ~PAGE_MASK;
24058@@ -1839,10 +1835,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
24059
24060 static void kvmclock_reset(struct kvm_vcpu *vcpu)
24061 {
24062- if (vcpu->arch.time_page) {
24063- kvm_release_page_dirty(vcpu->arch.time_page);
24064- vcpu->arch.time_page = NULL;
24065- }
24066+ vcpu->arch.pv_time_enabled = false;
24067 }
24068
24069 static void accumulate_steal_time(struct kvm_vcpu *vcpu)
24070@@ -1948,6 +1941,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24071 break;
24072 case MSR_KVM_SYSTEM_TIME_NEW:
24073 case MSR_KVM_SYSTEM_TIME: {
24074+ u64 gpa_offset;
24075 kvmclock_reset(vcpu);
24076
24077 vcpu->arch.time = data;
24078@@ -1957,14 +1951,17 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24079 if (!(data & 1))
24080 break;
24081
24082- /* ...but clean it before doing the actual write */
24083- vcpu->arch.time_offset = data & ~(PAGE_MASK | 1);
24084+ gpa_offset = data & ~(PAGE_MASK | 1);
24085
24086- vcpu->arch.time_page =
24087- gfn_to_page(vcpu->kvm, data >> PAGE_SHIFT);
24088+ /* Check that the address is 32-byte aligned. */
24089+ if (gpa_offset & (sizeof(struct pvclock_vcpu_time_info) - 1))
24090+ break;
24091
24092- if (is_error_page(vcpu->arch.time_page))
24093- vcpu->arch.time_page = NULL;
24094+ if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
24095+ &vcpu->arch.pv_time, data & ~1ULL))
24096+ vcpu->arch.pv_time_enabled = false;
24097+ else
24098+ vcpu->arch.pv_time_enabled = true;
24099
24100 break;
24101 }
24102@@ -2571,6 +2568,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24103 if (n < msr_list.nmsrs)
24104 goto out;
24105 r = -EFAULT;
24106+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24107+ goto out;
24108 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24109 num_msrs_to_save * sizeof(u32)))
24110 goto out;
24111@@ -2700,7 +2699,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24112 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24113 struct kvm_interrupt *irq)
24114 {
24115- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24116+ if (irq->irq >= KVM_NR_INTERRUPTS)
24117 return -EINVAL;
24118 if (irqchip_in_kernel(vcpu->kvm))
24119 return -ENXIO;
24120@@ -2967,7 +2966,7 @@ static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu,
24121 */
24122 static int kvm_set_guest_paused(struct kvm_vcpu *vcpu)
24123 {
24124- if (!vcpu->arch.time_page)
24125+ if (!vcpu->arch.pv_time_enabled)
24126 return -EINVAL;
24127 vcpu->arch.pvclock_set_guest_stopped_request = true;
24128 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
24129@@ -5213,7 +5212,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24130 };
24131 #endif
24132
24133-int kvm_arch_init(void *opaque)
24134+int kvm_arch_init(const void *opaque)
24135 {
24136 int r;
24137 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24138@@ -6661,6 +6660,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
24139 goto fail_free_wbinvd_dirty_mask;
24140
24141 vcpu->arch.ia32_tsc_adjust_msr = 0x0;
24142+ vcpu->arch.pv_time_enabled = false;
24143 kvm_async_pf_hash_reset(vcpu);
24144 kvm_pmu_init(vcpu);
24145
24146diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24147index df4176c..23ce092 100644
24148--- a/arch/x86/lguest/boot.c
24149+++ b/arch/x86/lguest/boot.c
24150@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24151 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24152 * Launcher to reboot us.
24153 */
24154-static void lguest_restart(char *reason)
24155+static __noreturn void lguest_restart(char *reason)
24156 {
24157 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24158+ BUG();
24159 }
24160
24161 /*G:050
24162diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24163index 00933d5..3a64af9 100644
24164--- a/arch/x86/lib/atomic64_386_32.S
24165+++ b/arch/x86/lib/atomic64_386_32.S
24166@@ -48,6 +48,10 @@ BEGIN(read)
24167 movl (v), %eax
24168 movl 4(v), %edx
24169 RET_ENDP
24170+BEGIN(read_unchecked)
24171+ movl (v), %eax
24172+ movl 4(v), %edx
24173+RET_ENDP
24174 #undef v
24175
24176 #define v %esi
24177@@ -55,6 +59,10 @@ BEGIN(set)
24178 movl %ebx, (v)
24179 movl %ecx, 4(v)
24180 RET_ENDP
24181+BEGIN(set_unchecked)
24182+ movl %ebx, (v)
24183+ movl %ecx, 4(v)
24184+RET_ENDP
24185 #undef v
24186
24187 #define v %esi
24188@@ -70,6 +78,20 @@ RET_ENDP
24189 BEGIN(add)
24190 addl %eax, (v)
24191 adcl %edx, 4(v)
24192+
24193+#ifdef CONFIG_PAX_REFCOUNT
24194+ jno 0f
24195+ subl %eax, (v)
24196+ sbbl %edx, 4(v)
24197+ int $4
24198+0:
24199+ _ASM_EXTABLE(0b, 0b)
24200+#endif
24201+
24202+RET_ENDP
24203+BEGIN(add_unchecked)
24204+ addl %eax, (v)
24205+ adcl %edx, 4(v)
24206 RET_ENDP
24207 #undef v
24208
24209@@ -77,6 +99,24 @@ RET_ENDP
24210 BEGIN(add_return)
24211 addl (v), %eax
24212 adcl 4(v), %edx
24213+
24214+#ifdef CONFIG_PAX_REFCOUNT
24215+ into
24216+1234:
24217+ _ASM_EXTABLE(1234b, 2f)
24218+#endif
24219+
24220+ movl %eax, (v)
24221+ movl %edx, 4(v)
24222+
24223+#ifdef CONFIG_PAX_REFCOUNT
24224+2:
24225+#endif
24226+
24227+RET_ENDP
24228+BEGIN(add_return_unchecked)
24229+ addl (v), %eax
24230+ adcl 4(v), %edx
24231 movl %eax, (v)
24232 movl %edx, 4(v)
24233 RET_ENDP
24234@@ -86,6 +126,20 @@ RET_ENDP
24235 BEGIN(sub)
24236 subl %eax, (v)
24237 sbbl %edx, 4(v)
24238+
24239+#ifdef CONFIG_PAX_REFCOUNT
24240+ jno 0f
24241+ addl %eax, (v)
24242+ adcl %edx, 4(v)
24243+ int $4
24244+0:
24245+ _ASM_EXTABLE(0b, 0b)
24246+#endif
24247+
24248+RET_ENDP
24249+BEGIN(sub_unchecked)
24250+ subl %eax, (v)
24251+ sbbl %edx, 4(v)
24252 RET_ENDP
24253 #undef v
24254
24255@@ -96,6 +150,27 @@ BEGIN(sub_return)
24256 sbbl $0, %edx
24257 addl (v), %eax
24258 adcl 4(v), %edx
24259+
24260+#ifdef CONFIG_PAX_REFCOUNT
24261+ into
24262+1234:
24263+ _ASM_EXTABLE(1234b, 2f)
24264+#endif
24265+
24266+ movl %eax, (v)
24267+ movl %edx, 4(v)
24268+
24269+#ifdef CONFIG_PAX_REFCOUNT
24270+2:
24271+#endif
24272+
24273+RET_ENDP
24274+BEGIN(sub_return_unchecked)
24275+ negl %edx
24276+ negl %eax
24277+ sbbl $0, %edx
24278+ addl (v), %eax
24279+ adcl 4(v), %edx
24280 movl %eax, (v)
24281 movl %edx, 4(v)
24282 RET_ENDP
24283@@ -105,6 +180,20 @@ RET_ENDP
24284 BEGIN(inc)
24285 addl $1, (v)
24286 adcl $0, 4(v)
24287+
24288+#ifdef CONFIG_PAX_REFCOUNT
24289+ jno 0f
24290+ subl $1, (v)
24291+ sbbl $0, 4(v)
24292+ int $4
24293+0:
24294+ _ASM_EXTABLE(0b, 0b)
24295+#endif
24296+
24297+RET_ENDP
24298+BEGIN(inc_unchecked)
24299+ addl $1, (v)
24300+ adcl $0, 4(v)
24301 RET_ENDP
24302 #undef v
24303
24304@@ -114,6 +203,26 @@ BEGIN(inc_return)
24305 movl 4(v), %edx
24306 addl $1, %eax
24307 adcl $0, %edx
24308+
24309+#ifdef CONFIG_PAX_REFCOUNT
24310+ into
24311+1234:
24312+ _ASM_EXTABLE(1234b, 2f)
24313+#endif
24314+
24315+ movl %eax, (v)
24316+ movl %edx, 4(v)
24317+
24318+#ifdef CONFIG_PAX_REFCOUNT
24319+2:
24320+#endif
24321+
24322+RET_ENDP
24323+BEGIN(inc_return_unchecked)
24324+ movl (v), %eax
24325+ movl 4(v), %edx
24326+ addl $1, %eax
24327+ adcl $0, %edx
24328 movl %eax, (v)
24329 movl %edx, 4(v)
24330 RET_ENDP
24331@@ -123,6 +232,20 @@ RET_ENDP
24332 BEGIN(dec)
24333 subl $1, (v)
24334 sbbl $0, 4(v)
24335+
24336+#ifdef CONFIG_PAX_REFCOUNT
24337+ jno 0f
24338+ addl $1, (v)
24339+ adcl $0, 4(v)
24340+ int $4
24341+0:
24342+ _ASM_EXTABLE(0b, 0b)
24343+#endif
24344+
24345+RET_ENDP
24346+BEGIN(dec_unchecked)
24347+ subl $1, (v)
24348+ sbbl $0, 4(v)
24349 RET_ENDP
24350 #undef v
24351
24352@@ -132,6 +255,26 @@ BEGIN(dec_return)
24353 movl 4(v), %edx
24354 subl $1, %eax
24355 sbbl $0, %edx
24356+
24357+#ifdef CONFIG_PAX_REFCOUNT
24358+ into
24359+1234:
24360+ _ASM_EXTABLE(1234b, 2f)
24361+#endif
24362+
24363+ movl %eax, (v)
24364+ movl %edx, 4(v)
24365+
24366+#ifdef CONFIG_PAX_REFCOUNT
24367+2:
24368+#endif
24369+
24370+RET_ENDP
24371+BEGIN(dec_return_unchecked)
24372+ movl (v), %eax
24373+ movl 4(v), %edx
24374+ subl $1, %eax
24375+ sbbl $0, %edx
24376 movl %eax, (v)
24377 movl %edx, 4(v)
24378 RET_ENDP
24379@@ -143,6 +286,13 @@ BEGIN(add_unless)
24380 adcl %edx, %edi
24381 addl (v), %eax
24382 adcl 4(v), %edx
24383+
24384+#ifdef CONFIG_PAX_REFCOUNT
24385+ into
24386+1234:
24387+ _ASM_EXTABLE(1234b, 2f)
24388+#endif
24389+
24390 cmpl %eax, %ecx
24391 je 3f
24392 1:
24393@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24394 1:
24395 addl $1, %eax
24396 adcl $0, %edx
24397+
24398+#ifdef CONFIG_PAX_REFCOUNT
24399+ into
24400+1234:
24401+ _ASM_EXTABLE(1234b, 2f)
24402+#endif
24403+
24404 movl %eax, (v)
24405 movl %edx, 4(v)
24406 movl $1, %eax
24407@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24408 movl 4(v), %edx
24409 subl $1, %eax
24410 sbbl $0, %edx
24411+
24412+#ifdef CONFIG_PAX_REFCOUNT
24413+ into
24414+1234:
24415+ _ASM_EXTABLE(1234b, 1f)
24416+#endif
24417+
24418 js 1f
24419 movl %eax, (v)
24420 movl %edx, 4(v)
24421diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24422index f5cc9eb..51fa319 100644
24423--- a/arch/x86/lib/atomic64_cx8_32.S
24424+++ b/arch/x86/lib/atomic64_cx8_32.S
24425@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24426 CFI_STARTPROC
24427
24428 read64 %ecx
24429+ pax_force_retaddr
24430 ret
24431 CFI_ENDPROC
24432 ENDPROC(atomic64_read_cx8)
24433
24434+ENTRY(atomic64_read_unchecked_cx8)
24435+ CFI_STARTPROC
24436+
24437+ read64 %ecx
24438+ pax_force_retaddr
24439+ ret
24440+ CFI_ENDPROC
24441+ENDPROC(atomic64_read_unchecked_cx8)
24442+
24443 ENTRY(atomic64_set_cx8)
24444 CFI_STARTPROC
24445
24446@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24447 cmpxchg8b (%esi)
24448 jne 1b
24449
24450+ pax_force_retaddr
24451 ret
24452 CFI_ENDPROC
24453 ENDPROC(atomic64_set_cx8)
24454
24455+ENTRY(atomic64_set_unchecked_cx8)
24456+ CFI_STARTPROC
24457+
24458+1:
24459+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24460+ * are atomic on 586 and newer */
24461+ cmpxchg8b (%esi)
24462+ jne 1b
24463+
24464+ pax_force_retaddr
24465+ ret
24466+ CFI_ENDPROC
24467+ENDPROC(atomic64_set_unchecked_cx8)
24468+
24469 ENTRY(atomic64_xchg_cx8)
24470 CFI_STARTPROC
24471
24472@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24473 cmpxchg8b (%esi)
24474 jne 1b
24475
24476+ pax_force_retaddr
24477 ret
24478 CFI_ENDPROC
24479 ENDPROC(atomic64_xchg_cx8)
24480
24481-.macro addsub_return func ins insc
24482-ENTRY(atomic64_\func\()_return_cx8)
24483+.macro addsub_return func ins insc unchecked=""
24484+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24485 CFI_STARTPROC
24486 SAVE ebp
24487 SAVE ebx
24488@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24489 movl %edx, %ecx
24490 \ins\()l %esi, %ebx
24491 \insc\()l %edi, %ecx
24492+
24493+.ifb \unchecked
24494+#ifdef CONFIG_PAX_REFCOUNT
24495+ into
24496+2:
24497+ _ASM_EXTABLE(2b, 3f)
24498+#endif
24499+.endif
24500+
24501 LOCK_PREFIX
24502 cmpxchg8b (%ebp)
24503 jne 1b
24504-
24505-10:
24506 movl %ebx, %eax
24507 movl %ecx, %edx
24508+
24509+.ifb \unchecked
24510+#ifdef CONFIG_PAX_REFCOUNT
24511+3:
24512+#endif
24513+.endif
24514+
24515 RESTORE edi
24516 RESTORE esi
24517 RESTORE ebx
24518 RESTORE ebp
24519+ pax_force_retaddr
24520 ret
24521 CFI_ENDPROC
24522-ENDPROC(atomic64_\func\()_return_cx8)
24523+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24524 .endm
24525
24526 addsub_return add add adc
24527 addsub_return sub sub sbb
24528+addsub_return add add adc _unchecked
24529+addsub_return sub sub sbb _unchecked
24530
24531-.macro incdec_return func ins insc
24532-ENTRY(atomic64_\func\()_return_cx8)
24533+.macro incdec_return func ins insc unchecked=""
24534+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24535 CFI_STARTPROC
24536 SAVE ebx
24537
24538@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24539 movl %edx, %ecx
24540 \ins\()l $1, %ebx
24541 \insc\()l $0, %ecx
24542+
24543+.ifb \unchecked
24544+#ifdef CONFIG_PAX_REFCOUNT
24545+ into
24546+2:
24547+ _ASM_EXTABLE(2b, 3f)
24548+#endif
24549+.endif
24550+
24551 LOCK_PREFIX
24552 cmpxchg8b (%esi)
24553 jne 1b
24554
24555-10:
24556 movl %ebx, %eax
24557 movl %ecx, %edx
24558+
24559+.ifb \unchecked
24560+#ifdef CONFIG_PAX_REFCOUNT
24561+3:
24562+#endif
24563+.endif
24564+
24565 RESTORE ebx
24566+ pax_force_retaddr
24567 ret
24568 CFI_ENDPROC
24569-ENDPROC(atomic64_\func\()_return_cx8)
24570+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24571 .endm
24572
24573 incdec_return inc add adc
24574 incdec_return dec sub sbb
24575+incdec_return inc add adc _unchecked
24576+incdec_return dec sub sbb _unchecked
24577
24578 ENTRY(atomic64_dec_if_positive_cx8)
24579 CFI_STARTPROC
24580@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24581 movl %edx, %ecx
24582 subl $1, %ebx
24583 sbb $0, %ecx
24584+
24585+#ifdef CONFIG_PAX_REFCOUNT
24586+ into
24587+1234:
24588+ _ASM_EXTABLE(1234b, 2f)
24589+#endif
24590+
24591 js 2f
24592 LOCK_PREFIX
24593 cmpxchg8b (%esi)
24594@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24595 movl %ebx, %eax
24596 movl %ecx, %edx
24597 RESTORE ebx
24598+ pax_force_retaddr
24599 ret
24600 CFI_ENDPROC
24601 ENDPROC(atomic64_dec_if_positive_cx8)
24602@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24603 movl %edx, %ecx
24604 addl %ebp, %ebx
24605 adcl %edi, %ecx
24606+
24607+#ifdef CONFIG_PAX_REFCOUNT
24608+ into
24609+1234:
24610+ _ASM_EXTABLE(1234b, 3f)
24611+#endif
24612+
24613 LOCK_PREFIX
24614 cmpxchg8b (%esi)
24615 jne 1b
24616@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24617 CFI_ADJUST_CFA_OFFSET -8
24618 RESTORE ebx
24619 RESTORE ebp
24620+ pax_force_retaddr
24621 ret
24622 4:
24623 cmpl %edx, 4(%esp)
24624@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24625 xorl %ecx, %ecx
24626 addl $1, %ebx
24627 adcl %edx, %ecx
24628+
24629+#ifdef CONFIG_PAX_REFCOUNT
24630+ into
24631+1234:
24632+ _ASM_EXTABLE(1234b, 3f)
24633+#endif
24634+
24635 LOCK_PREFIX
24636 cmpxchg8b (%esi)
24637 jne 1b
24638@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24639 movl $1, %eax
24640 3:
24641 RESTORE ebx
24642+ pax_force_retaddr
24643 ret
24644 CFI_ENDPROC
24645 ENDPROC(atomic64_inc_not_zero_cx8)
24646diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24647index 2af5df3..62b1a5a 100644
24648--- a/arch/x86/lib/checksum_32.S
24649+++ b/arch/x86/lib/checksum_32.S
24650@@ -29,7 +29,8 @@
24651 #include <asm/dwarf2.h>
24652 #include <asm/errno.h>
24653 #include <asm/asm.h>
24654-
24655+#include <asm/segment.h>
24656+
24657 /*
24658 * computes a partial checksum, e.g. for TCP/UDP fragments
24659 */
24660@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24661
24662 #define ARGBASE 16
24663 #define FP 12
24664-
24665-ENTRY(csum_partial_copy_generic)
24666+
24667+ENTRY(csum_partial_copy_generic_to_user)
24668 CFI_STARTPROC
24669+
24670+#ifdef CONFIG_PAX_MEMORY_UDEREF
24671+ pushl_cfi %gs
24672+ popl_cfi %es
24673+ jmp csum_partial_copy_generic
24674+#endif
24675+
24676+ENTRY(csum_partial_copy_generic_from_user)
24677+
24678+#ifdef CONFIG_PAX_MEMORY_UDEREF
24679+ pushl_cfi %gs
24680+ popl_cfi %ds
24681+#endif
24682+
24683+ENTRY(csum_partial_copy_generic)
24684 subl $4,%esp
24685 CFI_ADJUST_CFA_OFFSET 4
24686 pushl_cfi %edi
24687@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24688 jmp 4f
24689 SRC(1: movw (%esi), %bx )
24690 addl $2, %esi
24691-DST( movw %bx, (%edi) )
24692+DST( movw %bx, %es:(%edi) )
24693 addl $2, %edi
24694 addw %bx, %ax
24695 adcl $0, %eax
24696@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24697 SRC(1: movl (%esi), %ebx )
24698 SRC( movl 4(%esi), %edx )
24699 adcl %ebx, %eax
24700-DST( movl %ebx, (%edi) )
24701+DST( movl %ebx, %es:(%edi) )
24702 adcl %edx, %eax
24703-DST( movl %edx, 4(%edi) )
24704+DST( movl %edx, %es:4(%edi) )
24705
24706 SRC( movl 8(%esi), %ebx )
24707 SRC( movl 12(%esi), %edx )
24708 adcl %ebx, %eax
24709-DST( movl %ebx, 8(%edi) )
24710+DST( movl %ebx, %es:8(%edi) )
24711 adcl %edx, %eax
24712-DST( movl %edx, 12(%edi) )
24713+DST( movl %edx, %es:12(%edi) )
24714
24715 SRC( movl 16(%esi), %ebx )
24716 SRC( movl 20(%esi), %edx )
24717 adcl %ebx, %eax
24718-DST( movl %ebx, 16(%edi) )
24719+DST( movl %ebx, %es:16(%edi) )
24720 adcl %edx, %eax
24721-DST( movl %edx, 20(%edi) )
24722+DST( movl %edx, %es:20(%edi) )
24723
24724 SRC( movl 24(%esi), %ebx )
24725 SRC( movl 28(%esi), %edx )
24726 adcl %ebx, %eax
24727-DST( movl %ebx, 24(%edi) )
24728+DST( movl %ebx, %es:24(%edi) )
24729 adcl %edx, %eax
24730-DST( movl %edx, 28(%edi) )
24731+DST( movl %edx, %es:28(%edi) )
24732
24733 lea 32(%esi), %esi
24734 lea 32(%edi), %edi
24735@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24736 shrl $2, %edx # This clears CF
24737 SRC(3: movl (%esi), %ebx )
24738 adcl %ebx, %eax
24739-DST( movl %ebx, (%edi) )
24740+DST( movl %ebx, %es:(%edi) )
24741 lea 4(%esi), %esi
24742 lea 4(%edi), %edi
24743 dec %edx
24744@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24745 jb 5f
24746 SRC( movw (%esi), %cx )
24747 leal 2(%esi), %esi
24748-DST( movw %cx, (%edi) )
24749+DST( movw %cx, %es:(%edi) )
24750 leal 2(%edi), %edi
24751 je 6f
24752 shll $16,%ecx
24753 SRC(5: movb (%esi), %cl )
24754-DST( movb %cl, (%edi) )
24755+DST( movb %cl, %es:(%edi) )
24756 6: addl %ecx, %eax
24757 adcl $0, %eax
24758 7:
24759@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24760
24761 6001:
24762 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24763- movl $-EFAULT, (%ebx)
24764+ movl $-EFAULT, %ss:(%ebx)
24765
24766 # zero the complete destination - computing the rest
24767 # is too much work
24768@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24769
24770 6002:
24771 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24772- movl $-EFAULT,(%ebx)
24773+ movl $-EFAULT,%ss:(%ebx)
24774 jmp 5000b
24775
24776 .previous
24777
24778+ pushl_cfi %ss
24779+ popl_cfi %ds
24780+ pushl_cfi %ss
24781+ popl_cfi %es
24782 popl_cfi %ebx
24783 CFI_RESTORE ebx
24784 popl_cfi %esi
24785@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24786 popl_cfi %ecx # equivalent to addl $4,%esp
24787 ret
24788 CFI_ENDPROC
24789-ENDPROC(csum_partial_copy_generic)
24790+ENDPROC(csum_partial_copy_generic_to_user)
24791
24792 #else
24793
24794 /* Version for PentiumII/PPro */
24795
24796 #define ROUND1(x) \
24797+ nop; nop; nop; \
24798 SRC(movl x(%esi), %ebx ) ; \
24799 addl %ebx, %eax ; \
24800- DST(movl %ebx, x(%edi) ) ;
24801+ DST(movl %ebx, %es:x(%edi)) ;
24802
24803 #define ROUND(x) \
24804+ nop; nop; nop; \
24805 SRC(movl x(%esi), %ebx ) ; \
24806 adcl %ebx, %eax ; \
24807- DST(movl %ebx, x(%edi) ) ;
24808+ DST(movl %ebx, %es:x(%edi)) ;
24809
24810 #define ARGBASE 12
24811-
24812-ENTRY(csum_partial_copy_generic)
24813+
24814+ENTRY(csum_partial_copy_generic_to_user)
24815 CFI_STARTPROC
24816+
24817+#ifdef CONFIG_PAX_MEMORY_UDEREF
24818+ pushl_cfi %gs
24819+ popl_cfi %es
24820+ jmp csum_partial_copy_generic
24821+#endif
24822+
24823+ENTRY(csum_partial_copy_generic_from_user)
24824+
24825+#ifdef CONFIG_PAX_MEMORY_UDEREF
24826+ pushl_cfi %gs
24827+ popl_cfi %ds
24828+#endif
24829+
24830+ENTRY(csum_partial_copy_generic)
24831 pushl_cfi %ebx
24832 CFI_REL_OFFSET ebx, 0
24833 pushl_cfi %edi
24834@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24835 subl %ebx, %edi
24836 lea -1(%esi),%edx
24837 andl $-32,%edx
24838- lea 3f(%ebx,%ebx), %ebx
24839+ lea 3f(%ebx,%ebx,2), %ebx
24840 testl %esi, %esi
24841 jmp *%ebx
24842 1: addl $64,%esi
24843@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24844 jb 5f
24845 SRC( movw (%esi), %dx )
24846 leal 2(%esi), %esi
24847-DST( movw %dx, (%edi) )
24848+DST( movw %dx, %es:(%edi) )
24849 leal 2(%edi), %edi
24850 je 6f
24851 shll $16,%edx
24852 5:
24853 SRC( movb (%esi), %dl )
24854-DST( movb %dl, (%edi) )
24855+DST( movb %dl, %es:(%edi) )
24856 6: addl %edx, %eax
24857 adcl $0, %eax
24858 7:
24859 .section .fixup, "ax"
24860 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24861- movl $-EFAULT, (%ebx)
24862+ movl $-EFAULT, %ss:(%ebx)
24863 # zero the complete destination (computing the rest is too much work)
24864 movl ARGBASE+8(%esp),%edi # dst
24865 movl ARGBASE+12(%esp),%ecx # len
24866@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24867 rep; stosb
24868 jmp 7b
24869 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24870- movl $-EFAULT, (%ebx)
24871+ movl $-EFAULT, %ss:(%ebx)
24872 jmp 7b
24873 .previous
24874
24875+#ifdef CONFIG_PAX_MEMORY_UDEREF
24876+ pushl_cfi %ss
24877+ popl_cfi %ds
24878+ pushl_cfi %ss
24879+ popl_cfi %es
24880+#endif
24881+
24882 popl_cfi %esi
24883 CFI_RESTORE esi
24884 popl_cfi %edi
24885@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24886 CFI_RESTORE ebx
24887 ret
24888 CFI_ENDPROC
24889-ENDPROC(csum_partial_copy_generic)
24890+ENDPROC(csum_partial_copy_generic_to_user)
24891
24892 #undef ROUND
24893 #undef ROUND1
24894diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24895index f2145cf..cea889d 100644
24896--- a/arch/x86/lib/clear_page_64.S
24897+++ b/arch/x86/lib/clear_page_64.S
24898@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24899 movl $4096/8,%ecx
24900 xorl %eax,%eax
24901 rep stosq
24902+ pax_force_retaddr
24903 ret
24904 CFI_ENDPROC
24905 ENDPROC(clear_page_c)
24906@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24907 movl $4096,%ecx
24908 xorl %eax,%eax
24909 rep stosb
24910+ pax_force_retaddr
24911 ret
24912 CFI_ENDPROC
24913 ENDPROC(clear_page_c_e)
24914@@ -43,6 +45,7 @@ ENTRY(clear_page)
24915 leaq 64(%rdi),%rdi
24916 jnz .Lloop
24917 nop
24918+ pax_force_retaddr
24919 ret
24920 CFI_ENDPROC
24921 .Lclear_page_end:
24922@@ -58,7 +61,7 @@ ENDPROC(clear_page)
24923
24924 #include <asm/cpufeature.h>
24925
24926- .section .altinstr_replacement,"ax"
24927+ .section .altinstr_replacement,"a"
24928 1: .byte 0xeb /* jmp <disp8> */
24929 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24930 2: .byte 0xeb /* jmp <disp8> */
24931diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24932index 1e572c5..2a162cd 100644
24933--- a/arch/x86/lib/cmpxchg16b_emu.S
24934+++ b/arch/x86/lib/cmpxchg16b_emu.S
24935@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24936
24937 popf
24938 mov $1, %al
24939+ pax_force_retaddr
24940 ret
24941
24942 not_same:
24943 popf
24944 xor %al,%al
24945+ pax_force_retaddr
24946 ret
24947
24948 CFI_ENDPROC
24949diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24950index 176cca6..1166c50 100644
24951--- a/arch/x86/lib/copy_page_64.S
24952+++ b/arch/x86/lib/copy_page_64.S
24953@@ -9,6 +9,7 @@ copy_page_rep:
24954 CFI_STARTPROC
24955 movl $4096/8, %ecx
24956 rep movsq
24957+ pax_force_retaddr
24958 ret
24959 CFI_ENDPROC
24960 ENDPROC(copy_page_rep)
24961@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24962
24963 ENTRY(copy_page)
24964 CFI_STARTPROC
24965- subq $2*8, %rsp
24966- CFI_ADJUST_CFA_OFFSET 2*8
24967+ subq $3*8, %rsp
24968+ CFI_ADJUST_CFA_OFFSET 3*8
24969 movq %rbx, (%rsp)
24970 CFI_REL_OFFSET rbx, 0
24971 movq %r12, 1*8(%rsp)
24972 CFI_REL_OFFSET r12, 1*8
24973+ movq %r13, 2*8(%rsp)
24974+ CFI_REL_OFFSET r13, 2*8
24975
24976 movl $(4096/64)-5, %ecx
24977 .p2align 4
24978@@ -36,7 +39,7 @@ ENTRY(copy_page)
24979 movq 0x8*2(%rsi), %rdx
24980 movq 0x8*3(%rsi), %r8
24981 movq 0x8*4(%rsi), %r9
24982- movq 0x8*5(%rsi), %r10
24983+ movq 0x8*5(%rsi), %r13
24984 movq 0x8*6(%rsi), %r11
24985 movq 0x8*7(%rsi), %r12
24986
24987@@ -47,7 +50,7 @@ ENTRY(copy_page)
24988 movq %rdx, 0x8*2(%rdi)
24989 movq %r8, 0x8*3(%rdi)
24990 movq %r9, 0x8*4(%rdi)
24991- movq %r10, 0x8*5(%rdi)
24992+ movq %r13, 0x8*5(%rdi)
24993 movq %r11, 0x8*6(%rdi)
24994 movq %r12, 0x8*7(%rdi)
24995
24996@@ -66,7 +69,7 @@ ENTRY(copy_page)
24997 movq 0x8*2(%rsi), %rdx
24998 movq 0x8*3(%rsi), %r8
24999 movq 0x8*4(%rsi), %r9
25000- movq 0x8*5(%rsi), %r10
25001+ movq 0x8*5(%rsi), %r13
25002 movq 0x8*6(%rsi), %r11
25003 movq 0x8*7(%rsi), %r12
25004
25005@@ -75,7 +78,7 @@ ENTRY(copy_page)
25006 movq %rdx, 0x8*2(%rdi)
25007 movq %r8, 0x8*3(%rdi)
25008 movq %r9, 0x8*4(%rdi)
25009- movq %r10, 0x8*5(%rdi)
25010+ movq %r13, 0x8*5(%rdi)
25011 movq %r11, 0x8*6(%rdi)
25012 movq %r12, 0x8*7(%rdi)
25013
25014@@ -87,8 +90,11 @@ ENTRY(copy_page)
25015 CFI_RESTORE rbx
25016 movq 1*8(%rsp), %r12
25017 CFI_RESTORE r12
25018- addq $2*8, %rsp
25019- CFI_ADJUST_CFA_OFFSET -2*8
25020+ movq 2*8(%rsp), %r13
25021+ CFI_RESTORE r13
25022+ addq $3*8, %rsp
25023+ CFI_ADJUST_CFA_OFFSET -3*8
25024+ pax_force_retaddr
25025 ret
25026 .Lcopy_page_end:
25027 CFI_ENDPROC
25028@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25029
25030 #include <asm/cpufeature.h>
25031
25032- .section .altinstr_replacement,"ax"
25033+ .section .altinstr_replacement,"a"
25034 1: .byte 0xeb /* jmp <disp8> */
25035 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25036 2:
25037diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25038index a30ca15..d25fab6 100644
25039--- a/arch/x86/lib/copy_user_64.S
25040+++ b/arch/x86/lib/copy_user_64.S
25041@@ -18,6 +18,7 @@
25042 #include <asm/alternative-asm.h>
25043 #include <asm/asm.h>
25044 #include <asm/smap.h>
25045+#include <asm/pgtable.h>
25046
25047 /*
25048 * By placing feature2 after feature1 in altinstructions section, we logically
25049@@ -31,7 +32,7 @@
25050 .byte 0xe9 /* 32bit jump */
25051 .long \orig-1f /* by default jump to orig */
25052 1:
25053- .section .altinstr_replacement,"ax"
25054+ .section .altinstr_replacement,"a"
25055 2: .byte 0xe9 /* near jump with 32bit immediate */
25056 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25057 3: .byte 0xe9 /* near jump with 32bit immediate */
25058@@ -70,47 +71,20 @@
25059 #endif
25060 .endm
25061
25062-/* Standard copy_to_user with segment limit checking */
25063-ENTRY(_copy_to_user)
25064- CFI_STARTPROC
25065- GET_THREAD_INFO(%rax)
25066- movq %rdi,%rcx
25067- addq %rdx,%rcx
25068- jc bad_to_user
25069- cmpq TI_addr_limit(%rax),%rcx
25070- ja bad_to_user
25071- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25072- copy_user_generic_unrolled,copy_user_generic_string, \
25073- copy_user_enhanced_fast_string
25074- CFI_ENDPROC
25075-ENDPROC(_copy_to_user)
25076-
25077-/* Standard copy_from_user with segment limit checking */
25078-ENTRY(_copy_from_user)
25079- CFI_STARTPROC
25080- GET_THREAD_INFO(%rax)
25081- movq %rsi,%rcx
25082- addq %rdx,%rcx
25083- jc bad_from_user
25084- cmpq TI_addr_limit(%rax),%rcx
25085- ja bad_from_user
25086- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25087- copy_user_generic_unrolled,copy_user_generic_string, \
25088- copy_user_enhanced_fast_string
25089- CFI_ENDPROC
25090-ENDPROC(_copy_from_user)
25091-
25092 .section .fixup,"ax"
25093 /* must zero dest */
25094 ENTRY(bad_from_user)
25095 bad_from_user:
25096 CFI_STARTPROC
25097+ testl %edx,%edx
25098+ js bad_to_user
25099 movl %edx,%ecx
25100 xorl %eax,%eax
25101 rep
25102 stosb
25103 bad_to_user:
25104 movl %edx,%eax
25105+ pax_force_retaddr
25106 ret
25107 CFI_ENDPROC
25108 ENDPROC(bad_from_user)
25109@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25110 jz 17f
25111 1: movq (%rsi),%r8
25112 2: movq 1*8(%rsi),%r9
25113-3: movq 2*8(%rsi),%r10
25114+3: movq 2*8(%rsi),%rax
25115 4: movq 3*8(%rsi),%r11
25116 5: movq %r8,(%rdi)
25117 6: movq %r9,1*8(%rdi)
25118-7: movq %r10,2*8(%rdi)
25119+7: movq %rax,2*8(%rdi)
25120 8: movq %r11,3*8(%rdi)
25121 9: movq 4*8(%rsi),%r8
25122 10: movq 5*8(%rsi),%r9
25123-11: movq 6*8(%rsi),%r10
25124+11: movq 6*8(%rsi),%rax
25125 12: movq 7*8(%rsi),%r11
25126 13: movq %r8,4*8(%rdi)
25127 14: movq %r9,5*8(%rdi)
25128-15: movq %r10,6*8(%rdi)
25129+15: movq %rax,6*8(%rdi)
25130 16: movq %r11,7*8(%rdi)
25131 leaq 64(%rsi),%rsi
25132 leaq 64(%rdi),%rdi
25133@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25134 jnz 21b
25135 23: xor %eax,%eax
25136 ASM_CLAC
25137+ pax_force_retaddr
25138 ret
25139
25140 .section .fixup,"ax"
25141@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25142 movsb
25143 4: xorl %eax,%eax
25144 ASM_CLAC
25145+ pax_force_retaddr
25146 ret
25147
25148 .section .fixup,"ax"
25149@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25150 movsb
25151 2: xorl %eax,%eax
25152 ASM_CLAC
25153+ pax_force_retaddr
25154 ret
25155
25156 .section .fixup,"ax"
25157diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25158index 6a4f43c..f5f9e26 100644
25159--- a/arch/x86/lib/copy_user_nocache_64.S
25160+++ b/arch/x86/lib/copy_user_nocache_64.S
25161@@ -8,6 +8,7 @@
25162
25163 #include <linux/linkage.h>
25164 #include <asm/dwarf2.h>
25165+#include <asm/alternative-asm.h>
25166
25167 #define FIX_ALIGNMENT 1
25168
25169@@ -16,6 +17,7 @@
25170 #include <asm/thread_info.h>
25171 #include <asm/asm.h>
25172 #include <asm/smap.h>
25173+#include <asm/pgtable.h>
25174
25175 .macro ALIGN_DESTINATION
25176 #ifdef FIX_ALIGNMENT
25177@@ -49,6 +51,15 @@
25178 */
25179 ENTRY(__copy_user_nocache)
25180 CFI_STARTPROC
25181+
25182+#ifdef CONFIG_PAX_MEMORY_UDEREF
25183+ mov $PAX_USER_SHADOW_BASE,%rcx
25184+ cmp %rcx,%rsi
25185+ jae 1f
25186+ add %rcx,%rsi
25187+1:
25188+#endif
25189+
25190 ASM_STAC
25191 cmpl $8,%edx
25192 jb 20f /* less then 8 bytes, go to byte copy loop */
25193@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25194 jz 17f
25195 1: movq (%rsi),%r8
25196 2: movq 1*8(%rsi),%r9
25197-3: movq 2*8(%rsi),%r10
25198+3: movq 2*8(%rsi),%rax
25199 4: movq 3*8(%rsi),%r11
25200 5: movnti %r8,(%rdi)
25201 6: movnti %r9,1*8(%rdi)
25202-7: movnti %r10,2*8(%rdi)
25203+7: movnti %rax,2*8(%rdi)
25204 8: movnti %r11,3*8(%rdi)
25205 9: movq 4*8(%rsi),%r8
25206 10: movq 5*8(%rsi),%r9
25207-11: movq 6*8(%rsi),%r10
25208+11: movq 6*8(%rsi),%rax
25209 12: movq 7*8(%rsi),%r11
25210 13: movnti %r8,4*8(%rdi)
25211 14: movnti %r9,5*8(%rdi)
25212-15: movnti %r10,6*8(%rdi)
25213+15: movnti %rax,6*8(%rdi)
25214 16: movnti %r11,7*8(%rdi)
25215 leaq 64(%rsi),%rsi
25216 leaq 64(%rdi),%rdi
25217@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25218 23: xorl %eax,%eax
25219 ASM_CLAC
25220 sfence
25221+ pax_force_retaddr
25222 ret
25223
25224 .section .fixup,"ax"
25225diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25226index 2419d5f..953ee51 100644
25227--- a/arch/x86/lib/csum-copy_64.S
25228+++ b/arch/x86/lib/csum-copy_64.S
25229@@ -9,6 +9,7 @@
25230 #include <asm/dwarf2.h>
25231 #include <asm/errno.h>
25232 #include <asm/asm.h>
25233+#include <asm/alternative-asm.h>
25234
25235 /*
25236 * Checksum copy with exception handling.
25237@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25238 CFI_RESTORE rbp
25239 addq $7*8, %rsp
25240 CFI_ADJUST_CFA_OFFSET -7*8
25241+ pax_force_retaddr 0, 1
25242 ret
25243 CFI_RESTORE_STATE
25244
25245diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25246index 25b7ae8..169fafc 100644
25247--- a/arch/x86/lib/csum-wrappers_64.c
25248+++ b/arch/x86/lib/csum-wrappers_64.c
25249@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25250 len -= 2;
25251 }
25252 }
25253- isum = csum_partial_copy_generic((__force const void *)src,
25254+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25255 dst, len, isum, errp, NULL);
25256 if (unlikely(*errp))
25257 goto out_err;
25258@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25259 }
25260
25261 *errp = 0;
25262- return csum_partial_copy_generic(src, (void __force *)dst,
25263+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25264 len, isum, NULL, errp);
25265 }
25266 EXPORT_SYMBOL(csum_partial_copy_to_user);
25267diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25268index 156b9c8..b144132 100644
25269--- a/arch/x86/lib/getuser.S
25270+++ b/arch/x86/lib/getuser.S
25271@@ -34,17 +34,40 @@
25272 #include <asm/thread_info.h>
25273 #include <asm/asm.h>
25274 #include <asm/smap.h>
25275+#include <asm/segment.h>
25276+#include <asm/pgtable.h>
25277+#include <asm/alternative-asm.h>
25278+
25279+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25280+#define __copyuser_seg gs;
25281+#else
25282+#define __copyuser_seg
25283+#endif
25284
25285 .text
25286 ENTRY(__get_user_1)
25287 CFI_STARTPROC
25288+
25289+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25290 GET_THREAD_INFO(%_ASM_DX)
25291 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25292 jae bad_get_user
25293 ASM_STAC
25294-1: movzb (%_ASM_AX),%edx
25295+
25296+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25297+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25298+ cmp %_ASM_DX,%_ASM_AX
25299+ jae 1234f
25300+ add %_ASM_DX,%_ASM_AX
25301+1234:
25302+#endif
25303+
25304+#endif
25305+
25306+1: __copyuser_seg movzb (%_ASM_AX),%edx
25307 xor %eax,%eax
25308 ASM_CLAC
25309+ pax_force_retaddr
25310 ret
25311 CFI_ENDPROC
25312 ENDPROC(__get_user_1)
25313@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
25314 ENTRY(__get_user_2)
25315 CFI_STARTPROC
25316 add $1,%_ASM_AX
25317+
25318+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25319 jc bad_get_user
25320 GET_THREAD_INFO(%_ASM_DX)
25321 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25322 jae bad_get_user
25323 ASM_STAC
25324-2: movzwl -1(%_ASM_AX),%edx
25325+
25326+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25327+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25328+ cmp %_ASM_DX,%_ASM_AX
25329+ jae 1234f
25330+ add %_ASM_DX,%_ASM_AX
25331+1234:
25332+#endif
25333+
25334+#endif
25335+
25336+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25337 xor %eax,%eax
25338 ASM_CLAC
25339+ pax_force_retaddr
25340 ret
25341 CFI_ENDPROC
25342 ENDPROC(__get_user_2)
25343@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
25344 ENTRY(__get_user_4)
25345 CFI_STARTPROC
25346 add $3,%_ASM_AX
25347+
25348+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25349 jc bad_get_user
25350 GET_THREAD_INFO(%_ASM_DX)
25351 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25352 jae bad_get_user
25353 ASM_STAC
25354-3: mov -3(%_ASM_AX),%edx
25355+
25356+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25357+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25358+ cmp %_ASM_DX,%_ASM_AX
25359+ jae 1234f
25360+ add %_ASM_DX,%_ASM_AX
25361+1234:
25362+#endif
25363+
25364+#endif
25365+
25366+3: __copyuser_seg mov -3(%_ASM_AX),%edx
25367 xor %eax,%eax
25368 ASM_CLAC
25369+ pax_force_retaddr
25370 ret
25371 CFI_ENDPROC
25372 ENDPROC(__get_user_4)
25373@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25374 GET_THREAD_INFO(%_ASM_DX)
25375 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25376 jae bad_get_user
25377+
25378+#ifdef CONFIG_PAX_MEMORY_UDEREF
25379+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25380+ cmp %_ASM_DX,%_ASM_AX
25381+ jae 1234f
25382+ add %_ASM_DX,%_ASM_AX
25383+1234:
25384+#endif
25385+
25386 ASM_STAC
25387 4: movq -7(%_ASM_AX),%_ASM_DX
25388 xor %eax,%eax
25389 ASM_CLAC
25390+ pax_force_retaddr
25391 ret
25392 CFI_ENDPROC
25393 ENDPROC(__get_user_8)
25394@@ -101,6 +162,7 @@ bad_get_user:
25395 xor %edx,%edx
25396 mov $(-EFAULT),%_ASM_AX
25397 ASM_CLAC
25398+ pax_force_retaddr
25399 ret
25400 CFI_ENDPROC
25401 END(bad_get_user)
25402diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25403index 54fcffe..7be149e 100644
25404--- a/arch/x86/lib/insn.c
25405+++ b/arch/x86/lib/insn.c
25406@@ -20,8 +20,10 @@
25407
25408 #ifdef __KERNEL__
25409 #include <linux/string.h>
25410+#include <asm/pgtable_types.h>
25411 #else
25412 #include <string.h>
25413+#define ktla_ktva(addr) addr
25414 #endif
25415 #include <asm/inat.h>
25416 #include <asm/insn.h>
25417@@ -53,8 +55,8 @@
25418 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25419 {
25420 memset(insn, 0, sizeof(*insn));
25421- insn->kaddr = kaddr;
25422- insn->next_byte = kaddr;
25423+ insn->kaddr = ktla_ktva(kaddr);
25424+ insn->next_byte = ktla_ktva(kaddr);
25425 insn->x86_64 = x86_64 ? 1 : 0;
25426 insn->opnd_bytes = 4;
25427 if (x86_64)
25428diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25429index 05a95e7..326f2fa 100644
25430--- a/arch/x86/lib/iomap_copy_64.S
25431+++ b/arch/x86/lib/iomap_copy_64.S
25432@@ -17,6 +17,7 @@
25433
25434 #include <linux/linkage.h>
25435 #include <asm/dwarf2.h>
25436+#include <asm/alternative-asm.h>
25437
25438 /*
25439 * override generic version in lib/iomap_copy.c
25440@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25441 CFI_STARTPROC
25442 movl %edx,%ecx
25443 rep movsd
25444+ pax_force_retaddr
25445 ret
25446 CFI_ENDPROC
25447 ENDPROC(__iowrite32_copy)
25448diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25449index 1c273be..da9cc0e 100644
25450--- a/arch/x86/lib/memcpy_64.S
25451+++ b/arch/x86/lib/memcpy_64.S
25452@@ -33,6 +33,7 @@
25453 rep movsq
25454 movl %edx, %ecx
25455 rep movsb
25456+ pax_force_retaddr
25457 ret
25458 .Lmemcpy_e:
25459 .previous
25460@@ -49,6 +50,7 @@
25461 movq %rdi, %rax
25462 movq %rdx, %rcx
25463 rep movsb
25464+ pax_force_retaddr
25465 ret
25466 .Lmemcpy_e_e:
25467 .previous
25468@@ -76,13 +78,13 @@ ENTRY(memcpy)
25469 */
25470 movq 0*8(%rsi), %r8
25471 movq 1*8(%rsi), %r9
25472- movq 2*8(%rsi), %r10
25473+ movq 2*8(%rsi), %rcx
25474 movq 3*8(%rsi), %r11
25475 leaq 4*8(%rsi), %rsi
25476
25477 movq %r8, 0*8(%rdi)
25478 movq %r9, 1*8(%rdi)
25479- movq %r10, 2*8(%rdi)
25480+ movq %rcx, 2*8(%rdi)
25481 movq %r11, 3*8(%rdi)
25482 leaq 4*8(%rdi), %rdi
25483 jae .Lcopy_forward_loop
25484@@ -105,12 +107,12 @@ ENTRY(memcpy)
25485 subq $0x20, %rdx
25486 movq -1*8(%rsi), %r8
25487 movq -2*8(%rsi), %r9
25488- movq -3*8(%rsi), %r10
25489+ movq -3*8(%rsi), %rcx
25490 movq -4*8(%rsi), %r11
25491 leaq -4*8(%rsi), %rsi
25492 movq %r8, -1*8(%rdi)
25493 movq %r9, -2*8(%rdi)
25494- movq %r10, -3*8(%rdi)
25495+ movq %rcx, -3*8(%rdi)
25496 movq %r11, -4*8(%rdi)
25497 leaq -4*8(%rdi), %rdi
25498 jae .Lcopy_backward_loop
25499@@ -130,12 +132,13 @@ ENTRY(memcpy)
25500 */
25501 movq 0*8(%rsi), %r8
25502 movq 1*8(%rsi), %r9
25503- movq -2*8(%rsi, %rdx), %r10
25504+ movq -2*8(%rsi, %rdx), %rcx
25505 movq -1*8(%rsi, %rdx), %r11
25506 movq %r8, 0*8(%rdi)
25507 movq %r9, 1*8(%rdi)
25508- movq %r10, -2*8(%rdi, %rdx)
25509+ movq %rcx, -2*8(%rdi, %rdx)
25510 movq %r11, -1*8(%rdi, %rdx)
25511+ pax_force_retaddr
25512 retq
25513 .p2align 4
25514 .Lless_16bytes:
25515@@ -148,6 +151,7 @@ ENTRY(memcpy)
25516 movq -1*8(%rsi, %rdx), %r9
25517 movq %r8, 0*8(%rdi)
25518 movq %r9, -1*8(%rdi, %rdx)
25519+ pax_force_retaddr
25520 retq
25521 .p2align 4
25522 .Lless_8bytes:
25523@@ -161,6 +165,7 @@ ENTRY(memcpy)
25524 movl -4(%rsi, %rdx), %r8d
25525 movl %ecx, (%rdi)
25526 movl %r8d, -4(%rdi, %rdx)
25527+ pax_force_retaddr
25528 retq
25529 .p2align 4
25530 .Lless_3bytes:
25531@@ -179,6 +184,7 @@ ENTRY(memcpy)
25532 movb %cl, (%rdi)
25533
25534 .Lend:
25535+ pax_force_retaddr
25536 retq
25537 CFI_ENDPROC
25538 ENDPROC(memcpy)
25539diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25540index ee16461..c39c199 100644
25541--- a/arch/x86/lib/memmove_64.S
25542+++ b/arch/x86/lib/memmove_64.S
25543@@ -61,13 +61,13 @@ ENTRY(memmove)
25544 5:
25545 sub $0x20, %rdx
25546 movq 0*8(%rsi), %r11
25547- movq 1*8(%rsi), %r10
25548+ movq 1*8(%rsi), %rcx
25549 movq 2*8(%rsi), %r9
25550 movq 3*8(%rsi), %r8
25551 leaq 4*8(%rsi), %rsi
25552
25553 movq %r11, 0*8(%rdi)
25554- movq %r10, 1*8(%rdi)
25555+ movq %rcx, 1*8(%rdi)
25556 movq %r9, 2*8(%rdi)
25557 movq %r8, 3*8(%rdi)
25558 leaq 4*8(%rdi), %rdi
25559@@ -81,10 +81,10 @@ ENTRY(memmove)
25560 4:
25561 movq %rdx, %rcx
25562 movq -8(%rsi, %rdx), %r11
25563- lea -8(%rdi, %rdx), %r10
25564+ lea -8(%rdi, %rdx), %r9
25565 shrq $3, %rcx
25566 rep movsq
25567- movq %r11, (%r10)
25568+ movq %r11, (%r9)
25569 jmp 13f
25570 .Lmemmove_end_forward:
25571
25572@@ -95,14 +95,14 @@ ENTRY(memmove)
25573 7:
25574 movq %rdx, %rcx
25575 movq (%rsi), %r11
25576- movq %rdi, %r10
25577+ movq %rdi, %r9
25578 leaq -8(%rsi, %rdx), %rsi
25579 leaq -8(%rdi, %rdx), %rdi
25580 shrq $3, %rcx
25581 std
25582 rep movsq
25583 cld
25584- movq %r11, (%r10)
25585+ movq %r11, (%r9)
25586 jmp 13f
25587
25588 /*
25589@@ -127,13 +127,13 @@ ENTRY(memmove)
25590 8:
25591 subq $0x20, %rdx
25592 movq -1*8(%rsi), %r11
25593- movq -2*8(%rsi), %r10
25594+ movq -2*8(%rsi), %rcx
25595 movq -3*8(%rsi), %r9
25596 movq -4*8(%rsi), %r8
25597 leaq -4*8(%rsi), %rsi
25598
25599 movq %r11, -1*8(%rdi)
25600- movq %r10, -2*8(%rdi)
25601+ movq %rcx, -2*8(%rdi)
25602 movq %r9, -3*8(%rdi)
25603 movq %r8, -4*8(%rdi)
25604 leaq -4*8(%rdi), %rdi
25605@@ -151,11 +151,11 @@ ENTRY(memmove)
25606 * Move data from 16 bytes to 31 bytes.
25607 */
25608 movq 0*8(%rsi), %r11
25609- movq 1*8(%rsi), %r10
25610+ movq 1*8(%rsi), %rcx
25611 movq -2*8(%rsi, %rdx), %r9
25612 movq -1*8(%rsi, %rdx), %r8
25613 movq %r11, 0*8(%rdi)
25614- movq %r10, 1*8(%rdi)
25615+ movq %rcx, 1*8(%rdi)
25616 movq %r9, -2*8(%rdi, %rdx)
25617 movq %r8, -1*8(%rdi, %rdx)
25618 jmp 13f
25619@@ -167,9 +167,9 @@ ENTRY(memmove)
25620 * Move data from 8 bytes to 15 bytes.
25621 */
25622 movq 0*8(%rsi), %r11
25623- movq -1*8(%rsi, %rdx), %r10
25624+ movq -1*8(%rsi, %rdx), %r9
25625 movq %r11, 0*8(%rdi)
25626- movq %r10, -1*8(%rdi, %rdx)
25627+ movq %r9, -1*8(%rdi, %rdx)
25628 jmp 13f
25629 10:
25630 cmpq $4, %rdx
25631@@ -178,9 +178,9 @@ ENTRY(memmove)
25632 * Move data from 4 bytes to 7 bytes.
25633 */
25634 movl (%rsi), %r11d
25635- movl -4(%rsi, %rdx), %r10d
25636+ movl -4(%rsi, %rdx), %r9d
25637 movl %r11d, (%rdi)
25638- movl %r10d, -4(%rdi, %rdx)
25639+ movl %r9d, -4(%rdi, %rdx)
25640 jmp 13f
25641 11:
25642 cmp $2, %rdx
25643@@ -189,9 +189,9 @@ ENTRY(memmove)
25644 * Move data from 2 bytes to 3 bytes.
25645 */
25646 movw (%rsi), %r11w
25647- movw -2(%rsi, %rdx), %r10w
25648+ movw -2(%rsi, %rdx), %r9w
25649 movw %r11w, (%rdi)
25650- movw %r10w, -2(%rdi, %rdx)
25651+ movw %r9w, -2(%rdi, %rdx)
25652 jmp 13f
25653 12:
25654 cmp $1, %rdx
25655@@ -202,6 +202,7 @@ ENTRY(memmove)
25656 movb (%rsi), %r11b
25657 movb %r11b, (%rdi)
25658 13:
25659+ pax_force_retaddr
25660 retq
25661 CFI_ENDPROC
25662
25663@@ -210,6 +211,7 @@ ENTRY(memmove)
25664 /* Forward moving data. */
25665 movq %rdx, %rcx
25666 rep movsb
25667+ pax_force_retaddr
25668 retq
25669 .Lmemmove_end_forward_efs:
25670 .previous
25671diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25672index 2dcb380..963660a 100644
25673--- a/arch/x86/lib/memset_64.S
25674+++ b/arch/x86/lib/memset_64.S
25675@@ -30,6 +30,7 @@
25676 movl %edx,%ecx
25677 rep stosb
25678 movq %r9,%rax
25679+ pax_force_retaddr
25680 ret
25681 .Lmemset_e:
25682 .previous
25683@@ -52,6 +53,7 @@
25684 movq %rdx,%rcx
25685 rep stosb
25686 movq %r9,%rax
25687+ pax_force_retaddr
25688 ret
25689 .Lmemset_e_e:
25690 .previous
25691@@ -59,7 +61,7 @@
25692 ENTRY(memset)
25693 ENTRY(__memset)
25694 CFI_STARTPROC
25695- movq %rdi,%r10
25696+ movq %rdi,%r11
25697
25698 /* expand byte value */
25699 movzbl %sil,%ecx
25700@@ -117,7 +119,8 @@ ENTRY(__memset)
25701 jnz .Lloop_1
25702
25703 .Lende:
25704- movq %r10,%rax
25705+ movq %r11,%rax
25706+ pax_force_retaddr
25707 ret
25708
25709 CFI_RESTORE_STATE
25710diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25711index c9f2d9b..e7fd2c0 100644
25712--- a/arch/x86/lib/mmx_32.c
25713+++ b/arch/x86/lib/mmx_32.c
25714@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25715 {
25716 void *p;
25717 int i;
25718+ unsigned long cr0;
25719
25720 if (unlikely(in_interrupt()))
25721 return __memcpy(to, from, len);
25722@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25723 kernel_fpu_begin();
25724
25725 __asm__ __volatile__ (
25726- "1: prefetch (%0)\n" /* This set is 28 bytes */
25727- " prefetch 64(%0)\n"
25728- " prefetch 128(%0)\n"
25729- " prefetch 192(%0)\n"
25730- " prefetch 256(%0)\n"
25731+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25732+ " prefetch 64(%1)\n"
25733+ " prefetch 128(%1)\n"
25734+ " prefetch 192(%1)\n"
25735+ " prefetch 256(%1)\n"
25736 "2: \n"
25737 ".section .fixup, \"ax\"\n"
25738- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25739+ "3: \n"
25740+
25741+#ifdef CONFIG_PAX_KERNEXEC
25742+ " movl %%cr0, %0\n"
25743+ " movl %0, %%eax\n"
25744+ " andl $0xFFFEFFFF, %%eax\n"
25745+ " movl %%eax, %%cr0\n"
25746+#endif
25747+
25748+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25749+
25750+#ifdef CONFIG_PAX_KERNEXEC
25751+ " movl %0, %%cr0\n"
25752+#endif
25753+
25754 " jmp 2b\n"
25755 ".previous\n"
25756 _ASM_EXTABLE(1b, 3b)
25757- : : "r" (from));
25758+ : "=&r" (cr0) : "r" (from) : "ax");
25759
25760 for ( ; i > 5; i--) {
25761 __asm__ __volatile__ (
25762- "1: prefetch 320(%0)\n"
25763- "2: movq (%0), %%mm0\n"
25764- " movq 8(%0), %%mm1\n"
25765- " movq 16(%0), %%mm2\n"
25766- " movq 24(%0), %%mm3\n"
25767- " movq %%mm0, (%1)\n"
25768- " movq %%mm1, 8(%1)\n"
25769- " movq %%mm2, 16(%1)\n"
25770- " movq %%mm3, 24(%1)\n"
25771- " movq 32(%0), %%mm0\n"
25772- " movq 40(%0), %%mm1\n"
25773- " movq 48(%0), %%mm2\n"
25774- " movq 56(%0), %%mm3\n"
25775- " movq %%mm0, 32(%1)\n"
25776- " movq %%mm1, 40(%1)\n"
25777- " movq %%mm2, 48(%1)\n"
25778- " movq %%mm3, 56(%1)\n"
25779+ "1: prefetch 320(%1)\n"
25780+ "2: movq (%1), %%mm0\n"
25781+ " movq 8(%1), %%mm1\n"
25782+ " movq 16(%1), %%mm2\n"
25783+ " movq 24(%1), %%mm3\n"
25784+ " movq %%mm0, (%2)\n"
25785+ " movq %%mm1, 8(%2)\n"
25786+ " movq %%mm2, 16(%2)\n"
25787+ " movq %%mm3, 24(%2)\n"
25788+ " movq 32(%1), %%mm0\n"
25789+ " movq 40(%1), %%mm1\n"
25790+ " movq 48(%1), %%mm2\n"
25791+ " movq 56(%1), %%mm3\n"
25792+ " movq %%mm0, 32(%2)\n"
25793+ " movq %%mm1, 40(%2)\n"
25794+ " movq %%mm2, 48(%2)\n"
25795+ " movq %%mm3, 56(%2)\n"
25796 ".section .fixup, \"ax\"\n"
25797- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25798+ "3:\n"
25799+
25800+#ifdef CONFIG_PAX_KERNEXEC
25801+ " movl %%cr0, %0\n"
25802+ " movl %0, %%eax\n"
25803+ " andl $0xFFFEFFFF, %%eax\n"
25804+ " movl %%eax, %%cr0\n"
25805+#endif
25806+
25807+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25808+
25809+#ifdef CONFIG_PAX_KERNEXEC
25810+ " movl %0, %%cr0\n"
25811+#endif
25812+
25813 " jmp 2b\n"
25814 ".previous\n"
25815 _ASM_EXTABLE(1b, 3b)
25816- : : "r" (from), "r" (to) : "memory");
25817+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25818
25819 from += 64;
25820 to += 64;
25821@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25822 static void fast_copy_page(void *to, void *from)
25823 {
25824 int i;
25825+ unsigned long cr0;
25826
25827 kernel_fpu_begin();
25828
25829@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25830 * but that is for later. -AV
25831 */
25832 __asm__ __volatile__(
25833- "1: prefetch (%0)\n"
25834- " prefetch 64(%0)\n"
25835- " prefetch 128(%0)\n"
25836- " prefetch 192(%0)\n"
25837- " prefetch 256(%0)\n"
25838+ "1: prefetch (%1)\n"
25839+ " prefetch 64(%1)\n"
25840+ " prefetch 128(%1)\n"
25841+ " prefetch 192(%1)\n"
25842+ " prefetch 256(%1)\n"
25843 "2: \n"
25844 ".section .fixup, \"ax\"\n"
25845- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25846+ "3: \n"
25847+
25848+#ifdef CONFIG_PAX_KERNEXEC
25849+ " movl %%cr0, %0\n"
25850+ " movl %0, %%eax\n"
25851+ " andl $0xFFFEFFFF, %%eax\n"
25852+ " movl %%eax, %%cr0\n"
25853+#endif
25854+
25855+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25856+
25857+#ifdef CONFIG_PAX_KERNEXEC
25858+ " movl %0, %%cr0\n"
25859+#endif
25860+
25861 " jmp 2b\n"
25862 ".previous\n"
25863- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25864+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25865
25866 for (i = 0; i < (4096-320)/64; i++) {
25867 __asm__ __volatile__ (
25868- "1: prefetch 320(%0)\n"
25869- "2: movq (%0), %%mm0\n"
25870- " movntq %%mm0, (%1)\n"
25871- " movq 8(%0), %%mm1\n"
25872- " movntq %%mm1, 8(%1)\n"
25873- " movq 16(%0), %%mm2\n"
25874- " movntq %%mm2, 16(%1)\n"
25875- " movq 24(%0), %%mm3\n"
25876- " movntq %%mm3, 24(%1)\n"
25877- " movq 32(%0), %%mm4\n"
25878- " movntq %%mm4, 32(%1)\n"
25879- " movq 40(%0), %%mm5\n"
25880- " movntq %%mm5, 40(%1)\n"
25881- " movq 48(%0), %%mm6\n"
25882- " movntq %%mm6, 48(%1)\n"
25883- " movq 56(%0), %%mm7\n"
25884- " movntq %%mm7, 56(%1)\n"
25885+ "1: prefetch 320(%1)\n"
25886+ "2: movq (%1), %%mm0\n"
25887+ " movntq %%mm0, (%2)\n"
25888+ " movq 8(%1), %%mm1\n"
25889+ " movntq %%mm1, 8(%2)\n"
25890+ " movq 16(%1), %%mm2\n"
25891+ " movntq %%mm2, 16(%2)\n"
25892+ " movq 24(%1), %%mm3\n"
25893+ " movntq %%mm3, 24(%2)\n"
25894+ " movq 32(%1), %%mm4\n"
25895+ " movntq %%mm4, 32(%2)\n"
25896+ " movq 40(%1), %%mm5\n"
25897+ " movntq %%mm5, 40(%2)\n"
25898+ " movq 48(%1), %%mm6\n"
25899+ " movntq %%mm6, 48(%2)\n"
25900+ " movq 56(%1), %%mm7\n"
25901+ " movntq %%mm7, 56(%2)\n"
25902 ".section .fixup, \"ax\"\n"
25903- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25904+ "3:\n"
25905+
25906+#ifdef CONFIG_PAX_KERNEXEC
25907+ " movl %%cr0, %0\n"
25908+ " movl %0, %%eax\n"
25909+ " andl $0xFFFEFFFF, %%eax\n"
25910+ " movl %%eax, %%cr0\n"
25911+#endif
25912+
25913+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25914+
25915+#ifdef CONFIG_PAX_KERNEXEC
25916+ " movl %0, %%cr0\n"
25917+#endif
25918+
25919 " jmp 2b\n"
25920 ".previous\n"
25921- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25922+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25923
25924 from += 64;
25925 to += 64;
25926@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25927 static void fast_copy_page(void *to, void *from)
25928 {
25929 int i;
25930+ unsigned long cr0;
25931
25932 kernel_fpu_begin();
25933
25934 __asm__ __volatile__ (
25935- "1: prefetch (%0)\n"
25936- " prefetch 64(%0)\n"
25937- " prefetch 128(%0)\n"
25938- " prefetch 192(%0)\n"
25939- " prefetch 256(%0)\n"
25940+ "1: prefetch (%1)\n"
25941+ " prefetch 64(%1)\n"
25942+ " prefetch 128(%1)\n"
25943+ " prefetch 192(%1)\n"
25944+ " prefetch 256(%1)\n"
25945 "2: \n"
25946 ".section .fixup, \"ax\"\n"
25947- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25948+ "3: \n"
25949+
25950+#ifdef CONFIG_PAX_KERNEXEC
25951+ " movl %%cr0, %0\n"
25952+ " movl %0, %%eax\n"
25953+ " andl $0xFFFEFFFF, %%eax\n"
25954+ " movl %%eax, %%cr0\n"
25955+#endif
25956+
25957+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25958+
25959+#ifdef CONFIG_PAX_KERNEXEC
25960+ " movl %0, %%cr0\n"
25961+#endif
25962+
25963 " jmp 2b\n"
25964 ".previous\n"
25965- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25966+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25967
25968 for (i = 0; i < 4096/64; i++) {
25969 __asm__ __volatile__ (
25970- "1: prefetch 320(%0)\n"
25971- "2: movq (%0), %%mm0\n"
25972- " movq 8(%0), %%mm1\n"
25973- " movq 16(%0), %%mm2\n"
25974- " movq 24(%0), %%mm3\n"
25975- " movq %%mm0, (%1)\n"
25976- " movq %%mm1, 8(%1)\n"
25977- " movq %%mm2, 16(%1)\n"
25978- " movq %%mm3, 24(%1)\n"
25979- " movq 32(%0), %%mm0\n"
25980- " movq 40(%0), %%mm1\n"
25981- " movq 48(%0), %%mm2\n"
25982- " movq 56(%0), %%mm3\n"
25983- " movq %%mm0, 32(%1)\n"
25984- " movq %%mm1, 40(%1)\n"
25985- " movq %%mm2, 48(%1)\n"
25986- " movq %%mm3, 56(%1)\n"
25987+ "1: prefetch 320(%1)\n"
25988+ "2: movq (%1), %%mm0\n"
25989+ " movq 8(%1), %%mm1\n"
25990+ " movq 16(%1), %%mm2\n"
25991+ " movq 24(%1), %%mm3\n"
25992+ " movq %%mm0, (%2)\n"
25993+ " movq %%mm1, 8(%2)\n"
25994+ " movq %%mm2, 16(%2)\n"
25995+ " movq %%mm3, 24(%2)\n"
25996+ " movq 32(%1), %%mm0\n"
25997+ " movq 40(%1), %%mm1\n"
25998+ " movq 48(%1), %%mm2\n"
25999+ " movq 56(%1), %%mm3\n"
26000+ " movq %%mm0, 32(%2)\n"
26001+ " movq %%mm1, 40(%2)\n"
26002+ " movq %%mm2, 48(%2)\n"
26003+ " movq %%mm3, 56(%2)\n"
26004 ".section .fixup, \"ax\"\n"
26005- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26006+ "3:\n"
26007+
26008+#ifdef CONFIG_PAX_KERNEXEC
26009+ " movl %%cr0, %0\n"
26010+ " movl %0, %%eax\n"
26011+ " andl $0xFFFEFFFF, %%eax\n"
26012+ " movl %%eax, %%cr0\n"
26013+#endif
26014+
26015+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26016+
26017+#ifdef CONFIG_PAX_KERNEXEC
26018+ " movl %0, %%cr0\n"
26019+#endif
26020+
26021 " jmp 2b\n"
26022 ".previous\n"
26023 _ASM_EXTABLE(1b, 3b)
26024- : : "r" (from), "r" (to) : "memory");
26025+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26026
26027 from += 64;
26028 to += 64;
26029diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26030index f6d13ee..aca5f0b 100644
26031--- a/arch/x86/lib/msr-reg.S
26032+++ b/arch/x86/lib/msr-reg.S
26033@@ -3,6 +3,7 @@
26034 #include <asm/dwarf2.h>
26035 #include <asm/asm.h>
26036 #include <asm/msr.h>
26037+#include <asm/alternative-asm.h>
26038
26039 #ifdef CONFIG_X86_64
26040 /*
26041@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26042 CFI_STARTPROC
26043 pushq_cfi %rbx
26044 pushq_cfi %rbp
26045- movq %rdi, %r10 /* Save pointer */
26046+ movq %rdi, %r9 /* Save pointer */
26047 xorl %r11d, %r11d /* Return value */
26048 movl (%rdi), %eax
26049 movl 4(%rdi), %ecx
26050@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26051 movl 28(%rdi), %edi
26052 CFI_REMEMBER_STATE
26053 1: \op
26054-2: movl %eax, (%r10)
26055+2: movl %eax, (%r9)
26056 movl %r11d, %eax /* Return value */
26057- movl %ecx, 4(%r10)
26058- movl %edx, 8(%r10)
26059- movl %ebx, 12(%r10)
26060- movl %ebp, 20(%r10)
26061- movl %esi, 24(%r10)
26062- movl %edi, 28(%r10)
26063+ movl %ecx, 4(%r9)
26064+ movl %edx, 8(%r9)
26065+ movl %ebx, 12(%r9)
26066+ movl %ebp, 20(%r9)
26067+ movl %esi, 24(%r9)
26068+ movl %edi, 28(%r9)
26069 popq_cfi %rbp
26070 popq_cfi %rbx
26071+ pax_force_retaddr
26072 ret
26073 3:
26074 CFI_RESTORE_STATE
26075diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26076index fc6ba17..04471c5 100644
26077--- a/arch/x86/lib/putuser.S
26078+++ b/arch/x86/lib/putuser.S
26079@@ -16,7 +16,9 @@
26080 #include <asm/errno.h>
26081 #include <asm/asm.h>
26082 #include <asm/smap.h>
26083-
26084+#include <asm/segment.h>
26085+#include <asm/pgtable.h>
26086+#include <asm/alternative-asm.h>
26087
26088 /*
26089 * __put_user_X
26090@@ -30,57 +32,125 @@
26091 * as they get called from within inline assembly.
26092 */
26093
26094-#define ENTER CFI_STARTPROC ; \
26095- GET_THREAD_INFO(%_ASM_BX)
26096-#define EXIT ASM_CLAC ; \
26097- ret ; \
26098+#define ENTER CFI_STARTPROC
26099+#define EXIT ASM_CLAC ; \
26100+ pax_force_retaddr ; \
26101+ ret ; \
26102 CFI_ENDPROC
26103
26104+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26105+#define _DEST %_ASM_CX,%_ASM_BX
26106+#else
26107+#define _DEST %_ASM_CX
26108+#endif
26109+
26110+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26111+#define __copyuser_seg gs;
26112+#else
26113+#define __copyuser_seg
26114+#endif
26115+
26116 .text
26117 ENTRY(__put_user_1)
26118 ENTER
26119+
26120+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26121+ GET_THREAD_INFO(%_ASM_BX)
26122 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26123 jae bad_put_user
26124 ASM_STAC
26125-1: movb %al,(%_ASM_CX)
26126+
26127+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26128+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26129+ cmp %_ASM_BX,%_ASM_CX
26130+ jb 1234f
26131+ xor %ebx,%ebx
26132+1234:
26133+#endif
26134+
26135+#endif
26136+
26137+1: __copyuser_seg movb %al,(_DEST)
26138 xor %eax,%eax
26139 EXIT
26140 ENDPROC(__put_user_1)
26141
26142 ENTRY(__put_user_2)
26143 ENTER
26144+
26145+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26146+ GET_THREAD_INFO(%_ASM_BX)
26147 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26148 sub $1,%_ASM_BX
26149 cmp %_ASM_BX,%_ASM_CX
26150 jae bad_put_user
26151 ASM_STAC
26152-2: movw %ax,(%_ASM_CX)
26153+
26154+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26155+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26156+ cmp %_ASM_BX,%_ASM_CX
26157+ jb 1234f
26158+ xor %ebx,%ebx
26159+1234:
26160+#endif
26161+
26162+#endif
26163+
26164+2: __copyuser_seg movw %ax,(_DEST)
26165 xor %eax,%eax
26166 EXIT
26167 ENDPROC(__put_user_2)
26168
26169 ENTRY(__put_user_4)
26170 ENTER
26171+
26172+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26173+ GET_THREAD_INFO(%_ASM_BX)
26174 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26175 sub $3,%_ASM_BX
26176 cmp %_ASM_BX,%_ASM_CX
26177 jae bad_put_user
26178 ASM_STAC
26179-3: movl %eax,(%_ASM_CX)
26180+
26181+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26182+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26183+ cmp %_ASM_BX,%_ASM_CX
26184+ jb 1234f
26185+ xor %ebx,%ebx
26186+1234:
26187+#endif
26188+
26189+#endif
26190+
26191+3: __copyuser_seg movl %eax,(_DEST)
26192 xor %eax,%eax
26193 EXIT
26194 ENDPROC(__put_user_4)
26195
26196 ENTRY(__put_user_8)
26197 ENTER
26198+
26199+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26200+ GET_THREAD_INFO(%_ASM_BX)
26201 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26202 sub $7,%_ASM_BX
26203 cmp %_ASM_BX,%_ASM_CX
26204 jae bad_put_user
26205 ASM_STAC
26206-4: mov %_ASM_AX,(%_ASM_CX)
26207+
26208+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26209+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26210+ cmp %_ASM_BX,%_ASM_CX
26211+ jb 1234f
26212+ xor %ebx,%ebx
26213+1234:
26214+#endif
26215+
26216+#endif
26217+
26218+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26219 #ifdef CONFIG_X86_32
26220-5: movl %edx,4(%_ASM_CX)
26221+5: __copyuser_seg movl %edx,4(_DEST)
26222 #endif
26223 xor %eax,%eax
26224 EXIT
26225diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26226index 1cad221..de671ee 100644
26227--- a/arch/x86/lib/rwlock.S
26228+++ b/arch/x86/lib/rwlock.S
26229@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26230 FRAME
26231 0: LOCK_PREFIX
26232 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26233+
26234+#ifdef CONFIG_PAX_REFCOUNT
26235+ jno 1234f
26236+ LOCK_PREFIX
26237+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26238+ int $4
26239+1234:
26240+ _ASM_EXTABLE(1234b, 1234b)
26241+#endif
26242+
26243 1: rep; nop
26244 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26245 jne 1b
26246 LOCK_PREFIX
26247 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26248+
26249+#ifdef CONFIG_PAX_REFCOUNT
26250+ jno 1234f
26251+ LOCK_PREFIX
26252+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26253+ int $4
26254+1234:
26255+ _ASM_EXTABLE(1234b, 1234b)
26256+#endif
26257+
26258 jnz 0b
26259 ENDFRAME
26260+ pax_force_retaddr
26261 ret
26262 CFI_ENDPROC
26263 END(__write_lock_failed)
26264@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26265 FRAME
26266 0: LOCK_PREFIX
26267 READ_LOCK_SIZE(inc) (%__lock_ptr)
26268+
26269+#ifdef CONFIG_PAX_REFCOUNT
26270+ jno 1234f
26271+ LOCK_PREFIX
26272+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26273+ int $4
26274+1234:
26275+ _ASM_EXTABLE(1234b, 1234b)
26276+#endif
26277+
26278 1: rep; nop
26279 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26280 js 1b
26281 LOCK_PREFIX
26282 READ_LOCK_SIZE(dec) (%__lock_ptr)
26283+
26284+#ifdef CONFIG_PAX_REFCOUNT
26285+ jno 1234f
26286+ LOCK_PREFIX
26287+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26288+ int $4
26289+1234:
26290+ _ASM_EXTABLE(1234b, 1234b)
26291+#endif
26292+
26293 js 0b
26294 ENDFRAME
26295+ pax_force_retaddr
26296 ret
26297 CFI_ENDPROC
26298 END(__read_lock_failed)
26299diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26300index 5dff5f0..cadebf4 100644
26301--- a/arch/x86/lib/rwsem.S
26302+++ b/arch/x86/lib/rwsem.S
26303@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26304 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26305 CFI_RESTORE __ASM_REG(dx)
26306 restore_common_regs
26307+ pax_force_retaddr
26308 ret
26309 CFI_ENDPROC
26310 ENDPROC(call_rwsem_down_read_failed)
26311@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26312 movq %rax,%rdi
26313 call rwsem_down_write_failed
26314 restore_common_regs
26315+ pax_force_retaddr
26316 ret
26317 CFI_ENDPROC
26318 ENDPROC(call_rwsem_down_write_failed)
26319@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26320 movq %rax,%rdi
26321 call rwsem_wake
26322 restore_common_regs
26323-1: ret
26324+1: pax_force_retaddr
26325+ ret
26326 CFI_ENDPROC
26327 ENDPROC(call_rwsem_wake)
26328
26329@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26330 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26331 CFI_RESTORE __ASM_REG(dx)
26332 restore_common_regs
26333+ pax_force_retaddr
26334 ret
26335 CFI_ENDPROC
26336 ENDPROC(call_rwsem_downgrade_wake)
26337diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26338index a63efd6..ccecad8 100644
26339--- a/arch/x86/lib/thunk_64.S
26340+++ b/arch/x86/lib/thunk_64.S
26341@@ -8,6 +8,7 @@
26342 #include <linux/linkage.h>
26343 #include <asm/dwarf2.h>
26344 #include <asm/calling.h>
26345+#include <asm/alternative-asm.h>
26346
26347 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26348 .macro THUNK name, func, put_ret_addr_in_rdi=0
26349@@ -41,5 +42,6 @@
26350 SAVE_ARGS
26351 restore:
26352 RESTORE_ARGS
26353+ pax_force_retaddr
26354 ret
26355 CFI_ENDPROC
26356diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26357index f0312d7..9c39d63 100644
26358--- a/arch/x86/lib/usercopy_32.c
26359+++ b/arch/x86/lib/usercopy_32.c
26360@@ -42,11 +42,13 @@ do { \
26361 int __d0; \
26362 might_fault(); \
26363 __asm__ __volatile__( \
26364+ __COPYUSER_SET_ES \
26365 ASM_STAC "\n" \
26366 "0: rep; stosl\n" \
26367 " movl %2,%0\n" \
26368 "1: rep; stosb\n" \
26369 "2: " ASM_CLAC "\n" \
26370+ __COPYUSER_RESTORE_ES \
26371 ".section .fixup,\"ax\"\n" \
26372 "3: lea 0(%2,%0,4),%0\n" \
26373 " jmp 2b\n" \
26374@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26375
26376 #ifdef CONFIG_X86_INTEL_USERCOPY
26377 static unsigned long
26378-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26379+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26380 {
26381 int d0, d1;
26382 __asm__ __volatile__(
26383@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26384 " .align 2,0x90\n"
26385 "3: movl 0(%4), %%eax\n"
26386 "4: movl 4(%4), %%edx\n"
26387- "5: movl %%eax, 0(%3)\n"
26388- "6: movl %%edx, 4(%3)\n"
26389+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26390+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26391 "7: movl 8(%4), %%eax\n"
26392 "8: movl 12(%4),%%edx\n"
26393- "9: movl %%eax, 8(%3)\n"
26394- "10: movl %%edx, 12(%3)\n"
26395+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26396+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26397 "11: movl 16(%4), %%eax\n"
26398 "12: movl 20(%4), %%edx\n"
26399- "13: movl %%eax, 16(%3)\n"
26400- "14: movl %%edx, 20(%3)\n"
26401+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26402+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26403 "15: movl 24(%4), %%eax\n"
26404 "16: movl 28(%4), %%edx\n"
26405- "17: movl %%eax, 24(%3)\n"
26406- "18: movl %%edx, 28(%3)\n"
26407+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26408+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26409 "19: movl 32(%4), %%eax\n"
26410 "20: movl 36(%4), %%edx\n"
26411- "21: movl %%eax, 32(%3)\n"
26412- "22: movl %%edx, 36(%3)\n"
26413+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26414+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26415 "23: movl 40(%4), %%eax\n"
26416 "24: movl 44(%4), %%edx\n"
26417- "25: movl %%eax, 40(%3)\n"
26418- "26: movl %%edx, 44(%3)\n"
26419+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26420+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26421 "27: movl 48(%4), %%eax\n"
26422 "28: movl 52(%4), %%edx\n"
26423- "29: movl %%eax, 48(%3)\n"
26424- "30: movl %%edx, 52(%3)\n"
26425+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26426+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26427 "31: movl 56(%4), %%eax\n"
26428 "32: movl 60(%4), %%edx\n"
26429- "33: movl %%eax, 56(%3)\n"
26430- "34: movl %%edx, 60(%3)\n"
26431+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26432+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26433 " addl $-64, %0\n"
26434 " addl $64, %4\n"
26435 " addl $64, %3\n"
26436@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26437 " shrl $2, %0\n"
26438 " andl $3, %%eax\n"
26439 " cld\n"
26440+ __COPYUSER_SET_ES
26441 "99: rep; movsl\n"
26442 "36: movl %%eax, %0\n"
26443 "37: rep; movsb\n"
26444 "100:\n"
26445+ __COPYUSER_RESTORE_ES
26446 ".section .fixup,\"ax\"\n"
26447 "101: lea 0(%%eax,%0,4),%0\n"
26448 " jmp 100b\n"
26449@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26450 }
26451
26452 static unsigned long
26453+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26454+{
26455+ int d0, d1;
26456+ __asm__ __volatile__(
26457+ " .align 2,0x90\n"
26458+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26459+ " cmpl $67, %0\n"
26460+ " jbe 3f\n"
26461+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26462+ " .align 2,0x90\n"
26463+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26464+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26465+ "5: movl %%eax, 0(%3)\n"
26466+ "6: movl %%edx, 4(%3)\n"
26467+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26468+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26469+ "9: movl %%eax, 8(%3)\n"
26470+ "10: movl %%edx, 12(%3)\n"
26471+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26472+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26473+ "13: movl %%eax, 16(%3)\n"
26474+ "14: movl %%edx, 20(%3)\n"
26475+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26476+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26477+ "17: movl %%eax, 24(%3)\n"
26478+ "18: movl %%edx, 28(%3)\n"
26479+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26480+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26481+ "21: movl %%eax, 32(%3)\n"
26482+ "22: movl %%edx, 36(%3)\n"
26483+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26484+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26485+ "25: movl %%eax, 40(%3)\n"
26486+ "26: movl %%edx, 44(%3)\n"
26487+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26488+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26489+ "29: movl %%eax, 48(%3)\n"
26490+ "30: movl %%edx, 52(%3)\n"
26491+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26492+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26493+ "33: movl %%eax, 56(%3)\n"
26494+ "34: movl %%edx, 60(%3)\n"
26495+ " addl $-64, %0\n"
26496+ " addl $64, %4\n"
26497+ " addl $64, %3\n"
26498+ " cmpl $63, %0\n"
26499+ " ja 1b\n"
26500+ "35: movl %0, %%eax\n"
26501+ " shrl $2, %0\n"
26502+ " andl $3, %%eax\n"
26503+ " cld\n"
26504+ "99: rep; "__copyuser_seg" movsl\n"
26505+ "36: movl %%eax, %0\n"
26506+ "37: rep; "__copyuser_seg" movsb\n"
26507+ "100:\n"
26508+ ".section .fixup,\"ax\"\n"
26509+ "101: lea 0(%%eax,%0,4),%0\n"
26510+ " jmp 100b\n"
26511+ ".previous\n"
26512+ _ASM_EXTABLE(1b,100b)
26513+ _ASM_EXTABLE(2b,100b)
26514+ _ASM_EXTABLE(3b,100b)
26515+ _ASM_EXTABLE(4b,100b)
26516+ _ASM_EXTABLE(5b,100b)
26517+ _ASM_EXTABLE(6b,100b)
26518+ _ASM_EXTABLE(7b,100b)
26519+ _ASM_EXTABLE(8b,100b)
26520+ _ASM_EXTABLE(9b,100b)
26521+ _ASM_EXTABLE(10b,100b)
26522+ _ASM_EXTABLE(11b,100b)
26523+ _ASM_EXTABLE(12b,100b)
26524+ _ASM_EXTABLE(13b,100b)
26525+ _ASM_EXTABLE(14b,100b)
26526+ _ASM_EXTABLE(15b,100b)
26527+ _ASM_EXTABLE(16b,100b)
26528+ _ASM_EXTABLE(17b,100b)
26529+ _ASM_EXTABLE(18b,100b)
26530+ _ASM_EXTABLE(19b,100b)
26531+ _ASM_EXTABLE(20b,100b)
26532+ _ASM_EXTABLE(21b,100b)
26533+ _ASM_EXTABLE(22b,100b)
26534+ _ASM_EXTABLE(23b,100b)
26535+ _ASM_EXTABLE(24b,100b)
26536+ _ASM_EXTABLE(25b,100b)
26537+ _ASM_EXTABLE(26b,100b)
26538+ _ASM_EXTABLE(27b,100b)
26539+ _ASM_EXTABLE(28b,100b)
26540+ _ASM_EXTABLE(29b,100b)
26541+ _ASM_EXTABLE(30b,100b)
26542+ _ASM_EXTABLE(31b,100b)
26543+ _ASM_EXTABLE(32b,100b)
26544+ _ASM_EXTABLE(33b,100b)
26545+ _ASM_EXTABLE(34b,100b)
26546+ _ASM_EXTABLE(35b,100b)
26547+ _ASM_EXTABLE(36b,100b)
26548+ _ASM_EXTABLE(37b,100b)
26549+ _ASM_EXTABLE(99b,101b)
26550+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26551+ : "1"(to), "2"(from), "0"(size)
26552+ : "eax", "edx", "memory");
26553+ return size;
26554+}
26555+
26556+static unsigned long __size_overflow(3)
26557 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26558 {
26559 int d0, d1;
26560 __asm__ __volatile__(
26561 " .align 2,0x90\n"
26562- "0: movl 32(%4), %%eax\n"
26563+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26564 " cmpl $67, %0\n"
26565 " jbe 2f\n"
26566- "1: movl 64(%4), %%eax\n"
26567+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26568 " .align 2,0x90\n"
26569- "2: movl 0(%4), %%eax\n"
26570- "21: movl 4(%4), %%edx\n"
26571+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26572+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26573 " movl %%eax, 0(%3)\n"
26574 " movl %%edx, 4(%3)\n"
26575- "3: movl 8(%4), %%eax\n"
26576- "31: movl 12(%4),%%edx\n"
26577+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26578+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26579 " movl %%eax, 8(%3)\n"
26580 " movl %%edx, 12(%3)\n"
26581- "4: movl 16(%4), %%eax\n"
26582- "41: movl 20(%4), %%edx\n"
26583+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26584+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26585 " movl %%eax, 16(%3)\n"
26586 " movl %%edx, 20(%3)\n"
26587- "10: movl 24(%4), %%eax\n"
26588- "51: movl 28(%4), %%edx\n"
26589+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26590+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26591 " movl %%eax, 24(%3)\n"
26592 " movl %%edx, 28(%3)\n"
26593- "11: movl 32(%4), %%eax\n"
26594- "61: movl 36(%4), %%edx\n"
26595+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26596+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26597 " movl %%eax, 32(%3)\n"
26598 " movl %%edx, 36(%3)\n"
26599- "12: movl 40(%4), %%eax\n"
26600- "71: movl 44(%4), %%edx\n"
26601+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26602+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26603 " movl %%eax, 40(%3)\n"
26604 " movl %%edx, 44(%3)\n"
26605- "13: movl 48(%4), %%eax\n"
26606- "81: movl 52(%4), %%edx\n"
26607+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26608+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26609 " movl %%eax, 48(%3)\n"
26610 " movl %%edx, 52(%3)\n"
26611- "14: movl 56(%4), %%eax\n"
26612- "91: movl 60(%4), %%edx\n"
26613+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26614+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26615 " movl %%eax, 56(%3)\n"
26616 " movl %%edx, 60(%3)\n"
26617 " addl $-64, %0\n"
26618@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26619 " shrl $2, %0\n"
26620 " andl $3, %%eax\n"
26621 " cld\n"
26622- "6: rep; movsl\n"
26623+ "6: rep; "__copyuser_seg" movsl\n"
26624 " movl %%eax,%0\n"
26625- "7: rep; movsb\n"
26626+ "7: rep; "__copyuser_seg" movsb\n"
26627 "8:\n"
26628 ".section .fixup,\"ax\"\n"
26629 "9: lea 0(%%eax,%0,4),%0\n"
26630@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26631 * hyoshiok@miraclelinux.com
26632 */
26633
26634-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26635+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26636 const void __user *from, unsigned long size)
26637 {
26638 int d0, d1;
26639
26640 __asm__ __volatile__(
26641 " .align 2,0x90\n"
26642- "0: movl 32(%4), %%eax\n"
26643+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26644 " cmpl $67, %0\n"
26645 " jbe 2f\n"
26646- "1: movl 64(%4), %%eax\n"
26647+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26648 " .align 2,0x90\n"
26649- "2: movl 0(%4), %%eax\n"
26650- "21: movl 4(%4), %%edx\n"
26651+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26652+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26653 " movnti %%eax, 0(%3)\n"
26654 " movnti %%edx, 4(%3)\n"
26655- "3: movl 8(%4), %%eax\n"
26656- "31: movl 12(%4),%%edx\n"
26657+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26658+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26659 " movnti %%eax, 8(%3)\n"
26660 " movnti %%edx, 12(%3)\n"
26661- "4: movl 16(%4), %%eax\n"
26662- "41: movl 20(%4), %%edx\n"
26663+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26664+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26665 " movnti %%eax, 16(%3)\n"
26666 " movnti %%edx, 20(%3)\n"
26667- "10: movl 24(%4), %%eax\n"
26668- "51: movl 28(%4), %%edx\n"
26669+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26670+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26671 " movnti %%eax, 24(%3)\n"
26672 " movnti %%edx, 28(%3)\n"
26673- "11: movl 32(%4), %%eax\n"
26674- "61: movl 36(%4), %%edx\n"
26675+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26676+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26677 " movnti %%eax, 32(%3)\n"
26678 " movnti %%edx, 36(%3)\n"
26679- "12: movl 40(%4), %%eax\n"
26680- "71: movl 44(%4), %%edx\n"
26681+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26682+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26683 " movnti %%eax, 40(%3)\n"
26684 " movnti %%edx, 44(%3)\n"
26685- "13: movl 48(%4), %%eax\n"
26686- "81: movl 52(%4), %%edx\n"
26687+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26688+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26689 " movnti %%eax, 48(%3)\n"
26690 " movnti %%edx, 52(%3)\n"
26691- "14: movl 56(%4), %%eax\n"
26692- "91: movl 60(%4), %%edx\n"
26693+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26694+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26695 " movnti %%eax, 56(%3)\n"
26696 " movnti %%edx, 60(%3)\n"
26697 " addl $-64, %0\n"
26698@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26699 " shrl $2, %0\n"
26700 " andl $3, %%eax\n"
26701 " cld\n"
26702- "6: rep; movsl\n"
26703+ "6: rep; "__copyuser_seg" movsl\n"
26704 " movl %%eax,%0\n"
26705- "7: rep; movsb\n"
26706+ "7: rep; "__copyuser_seg" movsb\n"
26707 "8:\n"
26708 ".section .fixup,\"ax\"\n"
26709 "9: lea 0(%%eax,%0,4),%0\n"
26710@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26711 return size;
26712 }
26713
26714-static unsigned long __copy_user_intel_nocache(void *to,
26715+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26716 const void __user *from, unsigned long size)
26717 {
26718 int d0, d1;
26719
26720 __asm__ __volatile__(
26721 " .align 2,0x90\n"
26722- "0: movl 32(%4), %%eax\n"
26723+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26724 " cmpl $67, %0\n"
26725 " jbe 2f\n"
26726- "1: movl 64(%4), %%eax\n"
26727+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26728 " .align 2,0x90\n"
26729- "2: movl 0(%4), %%eax\n"
26730- "21: movl 4(%4), %%edx\n"
26731+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26732+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26733 " movnti %%eax, 0(%3)\n"
26734 " movnti %%edx, 4(%3)\n"
26735- "3: movl 8(%4), %%eax\n"
26736- "31: movl 12(%4),%%edx\n"
26737+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26738+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26739 " movnti %%eax, 8(%3)\n"
26740 " movnti %%edx, 12(%3)\n"
26741- "4: movl 16(%4), %%eax\n"
26742- "41: movl 20(%4), %%edx\n"
26743+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26744+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26745 " movnti %%eax, 16(%3)\n"
26746 " movnti %%edx, 20(%3)\n"
26747- "10: movl 24(%4), %%eax\n"
26748- "51: movl 28(%4), %%edx\n"
26749+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26750+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26751 " movnti %%eax, 24(%3)\n"
26752 " movnti %%edx, 28(%3)\n"
26753- "11: movl 32(%4), %%eax\n"
26754- "61: movl 36(%4), %%edx\n"
26755+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26756+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26757 " movnti %%eax, 32(%3)\n"
26758 " movnti %%edx, 36(%3)\n"
26759- "12: movl 40(%4), %%eax\n"
26760- "71: movl 44(%4), %%edx\n"
26761+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26762+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26763 " movnti %%eax, 40(%3)\n"
26764 " movnti %%edx, 44(%3)\n"
26765- "13: movl 48(%4), %%eax\n"
26766- "81: movl 52(%4), %%edx\n"
26767+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26768+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26769 " movnti %%eax, 48(%3)\n"
26770 " movnti %%edx, 52(%3)\n"
26771- "14: movl 56(%4), %%eax\n"
26772- "91: movl 60(%4), %%edx\n"
26773+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26774+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26775 " movnti %%eax, 56(%3)\n"
26776 " movnti %%edx, 60(%3)\n"
26777 " addl $-64, %0\n"
26778@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26779 " shrl $2, %0\n"
26780 " andl $3, %%eax\n"
26781 " cld\n"
26782- "6: rep; movsl\n"
26783+ "6: rep; "__copyuser_seg" movsl\n"
26784 " movl %%eax,%0\n"
26785- "7: rep; movsb\n"
26786+ "7: rep; "__copyuser_seg" movsb\n"
26787 "8:\n"
26788 ".section .fixup,\"ax\"\n"
26789 "9: lea 0(%%eax,%0,4),%0\n"
26790@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26791 */
26792 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26793 unsigned long size);
26794-unsigned long __copy_user_intel(void __user *to, const void *from,
26795+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26796+ unsigned long size);
26797+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26798 unsigned long size);
26799 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26800 const void __user *from, unsigned long size);
26801 #endif /* CONFIG_X86_INTEL_USERCOPY */
26802
26803 /* Generic arbitrary sized copy. */
26804-#define __copy_user(to, from, size) \
26805+#define __copy_user(to, from, size, prefix, set, restore) \
26806 do { \
26807 int __d0, __d1, __d2; \
26808 __asm__ __volatile__( \
26809+ set \
26810 " cmp $7,%0\n" \
26811 " jbe 1f\n" \
26812 " movl %1,%0\n" \
26813 " negl %0\n" \
26814 " andl $7,%0\n" \
26815 " subl %0,%3\n" \
26816- "4: rep; movsb\n" \
26817+ "4: rep; "prefix"movsb\n" \
26818 " movl %3,%0\n" \
26819 " shrl $2,%0\n" \
26820 " andl $3,%3\n" \
26821 " .align 2,0x90\n" \
26822- "0: rep; movsl\n" \
26823+ "0: rep; "prefix"movsl\n" \
26824 " movl %3,%0\n" \
26825- "1: rep; movsb\n" \
26826+ "1: rep; "prefix"movsb\n" \
26827 "2:\n" \
26828+ restore \
26829 ".section .fixup,\"ax\"\n" \
26830 "5: addl %3,%0\n" \
26831 " jmp 2b\n" \
26832@@ -538,14 +650,14 @@ do { \
26833 " negl %0\n" \
26834 " andl $7,%0\n" \
26835 " subl %0,%3\n" \
26836- "4: rep; movsb\n" \
26837+ "4: rep; "__copyuser_seg"movsb\n" \
26838 " movl %3,%0\n" \
26839 " shrl $2,%0\n" \
26840 " andl $3,%3\n" \
26841 " .align 2,0x90\n" \
26842- "0: rep; movsl\n" \
26843+ "0: rep; "__copyuser_seg"movsl\n" \
26844 " movl %3,%0\n" \
26845- "1: rep; movsb\n" \
26846+ "1: rep; "__copyuser_seg"movsb\n" \
26847 "2:\n" \
26848 ".section .fixup,\"ax\"\n" \
26849 "5: addl %3,%0\n" \
26850@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26851 {
26852 stac();
26853 if (movsl_is_ok(to, from, n))
26854- __copy_user(to, from, n);
26855+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26856 else
26857- n = __copy_user_intel(to, from, n);
26858+ n = __generic_copy_to_user_intel(to, from, n);
26859 clac();
26860 return n;
26861 }
26862@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26863 {
26864 stac();
26865 if (movsl_is_ok(to, from, n))
26866- __copy_user(to, from, n);
26867+ __copy_user(to, from, n, __copyuser_seg, "", "");
26868 else
26869- n = __copy_user_intel((void __user *)to,
26870- (const void *)from, n);
26871+ n = __generic_copy_from_user_intel(to, from, n);
26872 clac();
26873 return n;
26874 }
26875@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26876 if (n > 64 && cpu_has_xmm2)
26877 n = __copy_user_intel_nocache(to, from, n);
26878 else
26879- __copy_user(to, from, n);
26880+ __copy_user(to, from, n, __copyuser_seg, "", "");
26881 #else
26882- __copy_user(to, from, n);
26883+ __copy_user(to, from, n, __copyuser_seg, "", "");
26884 #endif
26885 clac();
26886 return n;
26887 }
26888 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26889
26890-/**
26891- * copy_to_user: - Copy a block of data into user space.
26892- * @to: Destination address, in user space.
26893- * @from: Source address, in kernel space.
26894- * @n: Number of bytes to copy.
26895- *
26896- * Context: User context only. This function may sleep.
26897- *
26898- * Copy data from kernel space to user space.
26899- *
26900- * Returns number of bytes that could not be copied.
26901- * On success, this will be zero.
26902- */
26903-unsigned long
26904-copy_to_user(void __user *to, const void *from, unsigned long n)
26905-{
26906- if (access_ok(VERIFY_WRITE, to, n))
26907- n = __copy_to_user(to, from, n);
26908- return n;
26909-}
26910-EXPORT_SYMBOL(copy_to_user);
26911-
26912-/**
26913- * copy_from_user: - Copy a block of data from user space.
26914- * @to: Destination address, in kernel space.
26915- * @from: Source address, in user space.
26916- * @n: Number of bytes to copy.
26917- *
26918- * Context: User context only. This function may sleep.
26919- *
26920- * Copy data from user space to kernel space.
26921- *
26922- * Returns number of bytes that could not be copied.
26923- * On success, this will be zero.
26924- *
26925- * If some data could not be copied, this function will pad the copied
26926- * data to the requested size using zero bytes.
26927- */
26928-unsigned long
26929-_copy_from_user(void *to, const void __user *from, unsigned long n)
26930-{
26931- if (access_ok(VERIFY_READ, from, n))
26932- n = __copy_from_user(to, from, n);
26933- else
26934- memset(to, 0, n);
26935- return n;
26936-}
26937-EXPORT_SYMBOL(_copy_from_user);
26938-
26939 void copy_from_user_overflow(void)
26940 {
26941 WARN(1, "Buffer overflow detected!\n");
26942 }
26943 EXPORT_SYMBOL(copy_from_user_overflow);
26944+
26945+void copy_to_user_overflow(void)
26946+{
26947+ WARN(1, "Buffer overflow detected!\n");
26948+}
26949+EXPORT_SYMBOL(copy_to_user_overflow);
26950+
26951+#ifdef CONFIG_PAX_MEMORY_UDEREF
26952+void __set_fs(mm_segment_t x)
26953+{
26954+ switch (x.seg) {
26955+ case 0:
26956+ loadsegment(gs, 0);
26957+ break;
26958+ case TASK_SIZE_MAX:
26959+ loadsegment(gs, __USER_DS);
26960+ break;
26961+ case -1UL:
26962+ loadsegment(gs, __KERNEL_DS);
26963+ break;
26964+ default:
26965+ BUG();
26966+ }
26967+ return;
26968+}
26969+EXPORT_SYMBOL(__set_fs);
26970+
26971+void set_fs(mm_segment_t x)
26972+{
26973+ current_thread_info()->addr_limit = x;
26974+ __set_fs(x);
26975+}
26976+EXPORT_SYMBOL(set_fs);
26977+#endif
26978diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26979index 05928aa..b33dea1 100644
26980--- a/arch/x86/lib/usercopy_64.c
26981+++ b/arch/x86/lib/usercopy_64.c
26982@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26983 _ASM_EXTABLE(0b,3b)
26984 _ASM_EXTABLE(1b,2b)
26985 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26986- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26987+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26988 [zero] "r" (0UL), [eight] "r" (8UL));
26989 clac();
26990 return size;
26991@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26992 }
26993 EXPORT_SYMBOL(clear_user);
26994
26995-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26996+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26997 {
26998- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26999- return copy_user_generic((__force void *)to, (__force void *)from, len);
27000- }
27001- return len;
27002+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27003+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27004+ return len;
27005 }
27006 EXPORT_SYMBOL(copy_in_user);
27007
27008@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27009 * it is not necessary to optimize tail handling.
27010 */
27011 unsigned long
27012-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27013+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27014 {
27015 char c;
27016 unsigned zero_len;
27017@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27018 clac();
27019 return len;
27020 }
27021+
27022+void copy_from_user_overflow(void)
27023+{
27024+ WARN(1, "Buffer overflow detected!\n");
27025+}
27026+EXPORT_SYMBOL(copy_from_user_overflow);
27027+
27028+void copy_to_user_overflow(void)
27029+{
27030+ WARN(1, "Buffer overflow detected!\n");
27031+}
27032+EXPORT_SYMBOL(copy_to_user_overflow);
27033diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27034index 903ec1e..c4166b2 100644
27035--- a/arch/x86/mm/extable.c
27036+++ b/arch/x86/mm/extable.c
27037@@ -6,12 +6,24 @@
27038 static inline unsigned long
27039 ex_insn_addr(const struct exception_table_entry *x)
27040 {
27041- return (unsigned long)&x->insn + x->insn;
27042+ unsigned long reloc = 0;
27043+
27044+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27045+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27046+#endif
27047+
27048+ return (unsigned long)&x->insn + x->insn + reloc;
27049 }
27050 static inline unsigned long
27051 ex_fixup_addr(const struct exception_table_entry *x)
27052 {
27053- return (unsigned long)&x->fixup + x->fixup;
27054+ unsigned long reloc = 0;
27055+
27056+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27057+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27058+#endif
27059+
27060+ return (unsigned long)&x->fixup + x->fixup + reloc;
27061 }
27062
27063 int fixup_exception(struct pt_regs *regs)
27064@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27065 unsigned long new_ip;
27066
27067 #ifdef CONFIG_PNPBIOS
27068- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27069+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27070 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27071 extern u32 pnp_bios_is_utter_crap;
27072 pnp_bios_is_utter_crap = 1;
27073@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27074 i += 4;
27075 p->fixup -= i;
27076 i += 4;
27077+
27078+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27079+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27080+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27081+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27082+#endif
27083+
27084 }
27085 }
27086
27087diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27088index fb674fd..1be28b9 100644
27089--- a/arch/x86/mm/fault.c
27090+++ b/arch/x86/mm/fault.c
27091@@ -13,12 +13,19 @@
27092 #include <linux/perf_event.h> /* perf_sw_event */
27093 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27094 #include <linux/prefetch.h> /* prefetchw */
27095+#include <linux/unistd.h>
27096+#include <linux/compiler.h>
27097
27098 #include <asm/traps.h> /* dotraplinkage, ... */
27099 #include <asm/pgalloc.h> /* pgd_*(), ... */
27100 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27101 #include <asm/fixmap.h> /* VSYSCALL_START */
27102 #include <asm/context_tracking.h> /* exception_enter(), ... */
27103+#include <asm/tlbflush.h>
27104+
27105+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27106+#include <asm/stacktrace.h>
27107+#endif
27108
27109 /*
27110 * Page fault error code bits:
27111@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27112 int ret = 0;
27113
27114 /* kprobe_running() needs smp_processor_id() */
27115- if (kprobes_built_in() && !user_mode_vm(regs)) {
27116+ if (kprobes_built_in() && !user_mode(regs)) {
27117 preempt_disable();
27118 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27119 ret = 1;
27120@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27121 return !instr_lo || (instr_lo>>1) == 1;
27122 case 0x00:
27123 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27124- if (probe_kernel_address(instr, opcode))
27125+ if (user_mode(regs)) {
27126+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27127+ return 0;
27128+ } else if (probe_kernel_address(instr, opcode))
27129 return 0;
27130
27131 *prefetch = (instr_lo == 0xF) &&
27132@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27133 while (instr < max_instr) {
27134 unsigned char opcode;
27135
27136- if (probe_kernel_address(instr, opcode))
27137+ if (user_mode(regs)) {
27138+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27139+ break;
27140+ } else if (probe_kernel_address(instr, opcode))
27141 break;
27142
27143 instr++;
27144@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27145 force_sig_info(si_signo, &info, tsk);
27146 }
27147
27148+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27149+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27150+#endif
27151+
27152+#ifdef CONFIG_PAX_EMUTRAMP
27153+static int pax_handle_fetch_fault(struct pt_regs *regs);
27154+#endif
27155+
27156+#ifdef CONFIG_PAX_PAGEEXEC
27157+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27158+{
27159+ pgd_t *pgd;
27160+ pud_t *pud;
27161+ pmd_t *pmd;
27162+
27163+ pgd = pgd_offset(mm, address);
27164+ if (!pgd_present(*pgd))
27165+ return NULL;
27166+ pud = pud_offset(pgd, address);
27167+ if (!pud_present(*pud))
27168+ return NULL;
27169+ pmd = pmd_offset(pud, address);
27170+ if (!pmd_present(*pmd))
27171+ return NULL;
27172+ return pmd;
27173+}
27174+#endif
27175+
27176 DEFINE_SPINLOCK(pgd_lock);
27177 LIST_HEAD(pgd_list);
27178
27179@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27180 for (address = VMALLOC_START & PMD_MASK;
27181 address >= TASK_SIZE && address < FIXADDR_TOP;
27182 address += PMD_SIZE) {
27183+
27184+#ifdef CONFIG_PAX_PER_CPU_PGD
27185+ unsigned long cpu;
27186+#else
27187 struct page *page;
27188+#endif
27189
27190 spin_lock(&pgd_lock);
27191+
27192+#ifdef CONFIG_PAX_PER_CPU_PGD
27193+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27194+ pgd_t *pgd = get_cpu_pgd(cpu);
27195+ pmd_t *ret;
27196+#else
27197 list_for_each_entry(page, &pgd_list, lru) {
27198+ pgd_t *pgd = page_address(page);
27199 spinlock_t *pgt_lock;
27200 pmd_t *ret;
27201
27202@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
27203 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27204
27205 spin_lock(pgt_lock);
27206- ret = vmalloc_sync_one(page_address(page), address);
27207+#endif
27208+
27209+ ret = vmalloc_sync_one(pgd, address);
27210+
27211+#ifndef CONFIG_PAX_PER_CPU_PGD
27212 spin_unlock(pgt_lock);
27213+#endif
27214
27215 if (!ret)
27216 break;
27217@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27218 * an interrupt in the middle of a task switch..
27219 */
27220 pgd_paddr = read_cr3();
27221+
27222+#ifdef CONFIG_PAX_PER_CPU_PGD
27223+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27224+#endif
27225+
27226 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27227 if (!pmd_k)
27228 return -1;
27229@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27230 * happen within a race in page table update. In the later
27231 * case just flush:
27232 */
27233+
27234+#ifdef CONFIG_PAX_PER_CPU_PGD
27235+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27236+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27237+#else
27238 pgd = pgd_offset(current->active_mm, address);
27239+#endif
27240+
27241 pgd_ref = pgd_offset_k(address);
27242 if (pgd_none(*pgd_ref))
27243 return -1;
27244@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27245 static int is_errata100(struct pt_regs *regs, unsigned long address)
27246 {
27247 #ifdef CONFIG_X86_64
27248- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27249+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27250 return 1;
27251 #endif
27252 return 0;
27253@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27254 }
27255
27256 static const char nx_warning[] = KERN_CRIT
27257-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27258+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27259
27260 static void
27261 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27262@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27263 if (!oops_may_print())
27264 return;
27265
27266- if (error_code & PF_INSTR) {
27267+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27268 unsigned int level;
27269
27270 pte_t *pte = lookup_address(address, &level);
27271
27272 if (pte && pte_present(*pte) && !pte_exec(*pte))
27273- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27274+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27275 }
27276
27277+#ifdef CONFIG_PAX_KERNEXEC
27278+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27279+ if (current->signal->curr_ip)
27280+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27281+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27282+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27283+ else
27284+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27285+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27286+ }
27287+#endif
27288+
27289 printk(KERN_ALERT "BUG: unable to handle kernel ");
27290 if (address < PAGE_SIZE)
27291 printk(KERN_CONT "NULL pointer dereference");
27292@@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27293 return;
27294 }
27295 #endif
27296+
27297+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27298+ if (pax_is_fetch_fault(regs, error_code, address)) {
27299+
27300+#ifdef CONFIG_PAX_EMUTRAMP
27301+ switch (pax_handle_fetch_fault(regs)) {
27302+ case 2:
27303+ return;
27304+ }
27305+#endif
27306+
27307+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27308+ do_group_exit(SIGKILL);
27309+ }
27310+#endif
27311+
27312 /* Kernel addresses are always protection faults: */
27313 if (address >= TASK_SIZE)
27314 error_code |= PF_PROT;
27315@@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27316 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27317 printk(KERN_ERR
27318 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27319- tsk->comm, tsk->pid, address);
27320+ tsk->comm, task_pid_nr(tsk), address);
27321 code = BUS_MCEERR_AR;
27322 }
27323 #endif
27324@@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27325 return 1;
27326 }
27327
27328+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27329+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27330+{
27331+ pte_t *pte;
27332+ pmd_t *pmd;
27333+ spinlock_t *ptl;
27334+ unsigned char pte_mask;
27335+
27336+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27337+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27338+ return 0;
27339+
27340+ /* PaX: it's our fault, let's handle it if we can */
27341+
27342+ /* PaX: take a look at read faults before acquiring any locks */
27343+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27344+ /* instruction fetch attempt from a protected page in user mode */
27345+ up_read(&mm->mmap_sem);
27346+
27347+#ifdef CONFIG_PAX_EMUTRAMP
27348+ switch (pax_handle_fetch_fault(regs)) {
27349+ case 2:
27350+ return 1;
27351+ }
27352+#endif
27353+
27354+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27355+ do_group_exit(SIGKILL);
27356+ }
27357+
27358+ pmd = pax_get_pmd(mm, address);
27359+ if (unlikely(!pmd))
27360+ return 0;
27361+
27362+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27363+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27364+ pte_unmap_unlock(pte, ptl);
27365+ return 0;
27366+ }
27367+
27368+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27369+ /* write attempt to a protected page in user mode */
27370+ pte_unmap_unlock(pte, ptl);
27371+ return 0;
27372+ }
27373+
27374+#ifdef CONFIG_SMP
27375+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27376+#else
27377+ if (likely(address > get_limit(regs->cs)))
27378+#endif
27379+ {
27380+ set_pte(pte, pte_mkread(*pte));
27381+ __flush_tlb_one(address);
27382+ pte_unmap_unlock(pte, ptl);
27383+ up_read(&mm->mmap_sem);
27384+ return 1;
27385+ }
27386+
27387+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27388+
27389+ /*
27390+ * PaX: fill DTLB with user rights and retry
27391+ */
27392+ __asm__ __volatile__ (
27393+ "orb %2,(%1)\n"
27394+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27395+/*
27396+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27397+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27398+ * page fault when examined during a TLB load attempt. this is true not only
27399+ * for PTEs holding a non-present entry but also present entries that will
27400+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27401+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27402+ * for our target pages since their PTEs are simply not in the TLBs at all.
27403+
27404+ * the best thing in omitting it is that we gain around 15-20% speed in the
27405+ * fast path of the page fault handler and can get rid of tracing since we
27406+ * can no longer flush unintended entries.
27407+ */
27408+ "invlpg (%0)\n"
27409+#endif
27410+ __copyuser_seg"testb $0,(%0)\n"
27411+ "xorb %3,(%1)\n"
27412+ :
27413+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27414+ : "memory", "cc");
27415+ pte_unmap_unlock(pte, ptl);
27416+ up_read(&mm->mmap_sem);
27417+ return 1;
27418+}
27419+#endif
27420+
27421 /*
27422 * Handle a spurious fault caused by a stale TLB entry.
27423 *
27424@@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
27425 static inline int
27426 access_error(unsigned long error_code, struct vm_area_struct *vma)
27427 {
27428+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27429+ return 1;
27430+
27431 if (error_code & PF_WRITE) {
27432 /* write, present and write, not present: */
27433 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27434@@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27435 if (error_code & PF_USER)
27436 return false;
27437
27438- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27439+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27440 return false;
27441
27442 return true;
27443@@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27444 {
27445 struct vm_area_struct *vma;
27446 struct task_struct *tsk;
27447- unsigned long address;
27448 struct mm_struct *mm;
27449 int fault;
27450 int write = error_code & PF_WRITE;
27451 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27452 (write ? FAULT_FLAG_WRITE : 0);
27453
27454- tsk = current;
27455- mm = tsk->mm;
27456-
27457 /* Get the faulting address: */
27458- address = read_cr2();
27459+ unsigned long address = read_cr2();
27460+
27461+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27462+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27463+ if (!search_exception_tables(regs->ip)) {
27464+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27465+ bad_area_nosemaphore(regs, error_code, address);
27466+ return;
27467+ }
27468+ if (address < PAX_USER_SHADOW_BASE) {
27469+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27470+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27471+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27472+ } else
27473+ address -= PAX_USER_SHADOW_BASE;
27474+ }
27475+#endif
27476+
27477+ tsk = current;
27478+ mm = tsk->mm;
27479
27480 /*
27481 * Detect and handle instructions that would cause a page fault for
27482@@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27483 * User-mode registers count as a user access even for any
27484 * potential system fault or CPU buglet:
27485 */
27486- if (user_mode_vm(regs)) {
27487+ if (user_mode(regs)) {
27488 local_irq_enable();
27489 error_code |= PF_USER;
27490 } else {
27491@@ -1146,6 +1355,11 @@ retry:
27492 might_sleep();
27493 }
27494
27495+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27496+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27497+ return;
27498+#endif
27499+
27500 vma = find_vma(mm, address);
27501 if (unlikely(!vma)) {
27502 bad_area(regs, error_code, address);
27503@@ -1157,18 +1371,24 @@ retry:
27504 bad_area(regs, error_code, address);
27505 return;
27506 }
27507- if (error_code & PF_USER) {
27508- /*
27509- * Accessing the stack below %sp is always a bug.
27510- * The large cushion allows instructions like enter
27511- * and pusha to work. ("enter $65535, $31" pushes
27512- * 32 pointers and then decrements %sp by 65535.)
27513- */
27514- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27515- bad_area(regs, error_code, address);
27516- return;
27517- }
27518+ /*
27519+ * Accessing the stack below %sp is always a bug.
27520+ * The large cushion allows instructions like enter
27521+ * and pusha to work. ("enter $65535, $31" pushes
27522+ * 32 pointers and then decrements %sp by 65535.)
27523+ */
27524+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27525+ bad_area(regs, error_code, address);
27526+ return;
27527 }
27528+
27529+#ifdef CONFIG_PAX_SEGMEXEC
27530+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27531+ bad_area(regs, error_code, address);
27532+ return;
27533+ }
27534+#endif
27535+
27536 if (unlikely(expand_stack(vma, address))) {
27537 bad_area(regs, error_code, address);
27538 return;
27539@@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27540 __do_page_fault(regs, error_code);
27541 exception_exit(regs);
27542 }
27543+
27544+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27545+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27546+{
27547+ struct mm_struct *mm = current->mm;
27548+ unsigned long ip = regs->ip;
27549+
27550+ if (v8086_mode(regs))
27551+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27552+
27553+#ifdef CONFIG_PAX_PAGEEXEC
27554+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27555+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27556+ return true;
27557+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27558+ return true;
27559+ return false;
27560+ }
27561+#endif
27562+
27563+#ifdef CONFIG_PAX_SEGMEXEC
27564+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27565+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27566+ return true;
27567+ return false;
27568+ }
27569+#endif
27570+
27571+ return false;
27572+}
27573+#endif
27574+
27575+#ifdef CONFIG_PAX_EMUTRAMP
27576+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27577+{
27578+ int err;
27579+
27580+ do { /* PaX: libffi trampoline emulation */
27581+ unsigned char mov, jmp;
27582+ unsigned int addr1, addr2;
27583+
27584+#ifdef CONFIG_X86_64
27585+ if ((regs->ip + 9) >> 32)
27586+ break;
27587+#endif
27588+
27589+ err = get_user(mov, (unsigned char __user *)regs->ip);
27590+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27591+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27592+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27593+
27594+ if (err)
27595+ break;
27596+
27597+ if (mov == 0xB8 && jmp == 0xE9) {
27598+ regs->ax = addr1;
27599+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27600+ return 2;
27601+ }
27602+ } while (0);
27603+
27604+ do { /* PaX: gcc trampoline emulation #1 */
27605+ unsigned char mov1, mov2;
27606+ unsigned short jmp;
27607+ unsigned int addr1, addr2;
27608+
27609+#ifdef CONFIG_X86_64
27610+ if ((regs->ip + 11) >> 32)
27611+ break;
27612+#endif
27613+
27614+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27615+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27616+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27617+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27618+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27619+
27620+ if (err)
27621+ break;
27622+
27623+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27624+ regs->cx = addr1;
27625+ regs->ax = addr2;
27626+ regs->ip = addr2;
27627+ return 2;
27628+ }
27629+ } while (0);
27630+
27631+ do { /* PaX: gcc trampoline emulation #2 */
27632+ unsigned char mov, jmp;
27633+ unsigned int addr1, addr2;
27634+
27635+#ifdef CONFIG_X86_64
27636+ if ((regs->ip + 9) >> 32)
27637+ break;
27638+#endif
27639+
27640+ err = get_user(mov, (unsigned char __user *)regs->ip);
27641+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27642+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27643+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27644+
27645+ if (err)
27646+ break;
27647+
27648+ if (mov == 0xB9 && jmp == 0xE9) {
27649+ regs->cx = addr1;
27650+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27651+ return 2;
27652+ }
27653+ } while (0);
27654+
27655+ return 1; /* PaX in action */
27656+}
27657+
27658+#ifdef CONFIG_X86_64
27659+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27660+{
27661+ int err;
27662+
27663+ do { /* PaX: libffi trampoline emulation */
27664+ unsigned short mov1, mov2, jmp1;
27665+ unsigned char stcclc, jmp2;
27666+ unsigned long addr1, addr2;
27667+
27668+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27669+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27670+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27671+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27672+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27673+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27674+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27675+
27676+ if (err)
27677+ break;
27678+
27679+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27680+ regs->r11 = addr1;
27681+ regs->r10 = addr2;
27682+ if (stcclc == 0xF8)
27683+ regs->flags &= ~X86_EFLAGS_CF;
27684+ else
27685+ regs->flags |= X86_EFLAGS_CF;
27686+ regs->ip = addr1;
27687+ return 2;
27688+ }
27689+ } while (0);
27690+
27691+ do { /* PaX: gcc trampoline emulation #1 */
27692+ unsigned short mov1, mov2, jmp1;
27693+ unsigned char jmp2;
27694+ unsigned int addr1;
27695+ unsigned long addr2;
27696+
27697+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27698+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27699+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27700+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27701+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27702+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27703+
27704+ if (err)
27705+ break;
27706+
27707+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27708+ regs->r11 = addr1;
27709+ regs->r10 = addr2;
27710+ regs->ip = addr1;
27711+ return 2;
27712+ }
27713+ } while (0);
27714+
27715+ do { /* PaX: gcc trampoline emulation #2 */
27716+ unsigned short mov1, mov2, jmp1;
27717+ unsigned char jmp2;
27718+ unsigned long addr1, addr2;
27719+
27720+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27721+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27722+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27723+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27724+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27725+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27726+
27727+ if (err)
27728+ break;
27729+
27730+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27731+ regs->r11 = addr1;
27732+ regs->r10 = addr2;
27733+ regs->ip = addr1;
27734+ return 2;
27735+ }
27736+ } while (0);
27737+
27738+ return 1; /* PaX in action */
27739+}
27740+#endif
27741+
27742+/*
27743+ * PaX: decide what to do with offenders (regs->ip = fault address)
27744+ *
27745+ * returns 1 when task should be killed
27746+ * 2 when gcc trampoline was detected
27747+ */
27748+static int pax_handle_fetch_fault(struct pt_regs *regs)
27749+{
27750+ if (v8086_mode(regs))
27751+ return 1;
27752+
27753+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27754+ return 1;
27755+
27756+#ifdef CONFIG_X86_32
27757+ return pax_handle_fetch_fault_32(regs);
27758+#else
27759+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27760+ return pax_handle_fetch_fault_32(regs);
27761+ else
27762+ return pax_handle_fetch_fault_64(regs);
27763+#endif
27764+}
27765+#endif
27766+
27767+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27768+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27769+{
27770+ long i;
27771+
27772+ printk(KERN_ERR "PAX: bytes at PC: ");
27773+ for (i = 0; i < 20; i++) {
27774+ unsigned char c;
27775+ if (get_user(c, (unsigned char __force_user *)pc+i))
27776+ printk(KERN_CONT "?? ");
27777+ else
27778+ printk(KERN_CONT "%02x ", c);
27779+ }
27780+ printk("\n");
27781+
27782+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27783+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27784+ unsigned long c;
27785+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27786+#ifdef CONFIG_X86_32
27787+ printk(KERN_CONT "???????? ");
27788+#else
27789+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27790+ printk(KERN_CONT "???????? ???????? ");
27791+ else
27792+ printk(KERN_CONT "???????????????? ");
27793+#endif
27794+ } else {
27795+#ifdef CONFIG_X86_64
27796+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27797+ printk(KERN_CONT "%08x ", (unsigned int)c);
27798+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27799+ } else
27800+#endif
27801+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27802+ }
27803+ }
27804+ printk("\n");
27805+}
27806+#endif
27807+
27808+/**
27809+ * probe_kernel_write(): safely attempt to write to a location
27810+ * @dst: address to write to
27811+ * @src: pointer to the data that shall be written
27812+ * @size: size of the data chunk
27813+ *
27814+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27815+ * happens, handle that and return -EFAULT.
27816+ */
27817+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27818+{
27819+ long ret;
27820+ mm_segment_t old_fs = get_fs();
27821+
27822+ set_fs(KERNEL_DS);
27823+ pagefault_disable();
27824+ pax_open_kernel();
27825+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27826+ pax_close_kernel();
27827+ pagefault_enable();
27828+ set_fs(old_fs);
27829+
27830+ return ret ? -EFAULT : 0;
27831+}
27832diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27833index dd74e46..7d26398 100644
27834--- a/arch/x86/mm/gup.c
27835+++ b/arch/x86/mm/gup.c
27836@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27837 addr = start;
27838 len = (unsigned long) nr_pages << PAGE_SHIFT;
27839 end = start + len;
27840- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27841+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27842 (void __user *)start, len)))
27843 return 0;
27844
27845diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27846index 6f31ee5..8ee4164 100644
27847--- a/arch/x86/mm/highmem_32.c
27848+++ b/arch/x86/mm/highmem_32.c
27849@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27850 idx = type + KM_TYPE_NR*smp_processor_id();
27851 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27852 BUG_ON(!pte_none(*(kmap_pte-idx)));
27853+
27854+ pax_open_kernel();
27855 set_pte(kmap_pte-idx, mk_pte(page, prot));
27856+ pax_close_kernel();
27857+
27858 arch_flush_lazy_mmu_mode();
27859
27860 return (void *)vaddr;
27861diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27862index ae1aa71..56316db 100644
27863--- a/arch/x86/mm/hugetlbpage.c
27864+++ b/arch/x86/mm/hugetlbpage.c
27865@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27866 info.flags = 0;
27867 info.length = len;
27868 info.low_limit = TASK_UNMAPPED_BASE;
27869+
27870+#ifdef CONFIG_PAX_RANDMMAP
27871+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27872+ info.low_limit += current->mm->delta_mmap;
27873+#endif
27874+
27875 info.high_limit = TASK_SIZE;
27876 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27877 info.align_offset = 0;
27878@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27879 VM_BUG_ON(addr != -ENOMEM);
27880 info.flags = 0;
27881 info.low_limit = TASK_UNMAPPED_BASE;
27882+
27883+#ifdef CONFIG_PAX_RANDMMAP
27884+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27885+ info.low_limit += current->mm->delta_mmap;
27886+#endif
27887+
27888 info.high_limit = TASK_SIZE;
27889 addr = vm_unmapped_area(&info);
27890 }
27891@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27892 struct hstate *h = hstate_file(file);
27893 struct mm_struct *mm = current->mm;
27894 struct vm_area_struct *vma;
27895+ unsigned long pax_task_size = TASK_SIZE;
27896+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27897
27898 if (len & ~huge_page_mask(h))
27899 return -EINVAL;
27900- if (len > TASK_SIZE)
27901+
27902+#ifdef CONFIG_PAX_SEGMEXEC
27903+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27904+ pax_task_size = SEGMEXEC_TASK_SIZE;
27905+#endif
27906+
27907+ pax_task_size -= PAGE_SIZE;
27908+
27909+ if (len > pax_task_size)
27910 return -ENOMEM;
27911
27912 if (flags & MAP_FIXED) {
27913@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27914 return addr;
27915 }
27916
27917+#ifdef CONFIG_PAX_RANDMMAP
27918+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27919+#endif
27920+
27921 if (addr) {
27922 addr = ALIGN(addr, huge_page_size(h));
27923 vma = find_vma(mm, addr);
27924- if (TASK_SIZE - len >= addr &&
27925- (!vma || addr + len <= vma->vm_start))
27926+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27927 return addr;
27928 }
27929 if (mm->get_unmapped_area == arch_get_unmapped_area)
27930diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27931index d7aea41..0fc945b 100644
27932--- a/arch/x86/mm/init.c
27933+++ b/arch/x86/mm/init.c
27934@@ -4,6 +4,7 @@
27935 #include <linux/swap.h>
27936 #include <linux/memblock.h>
27937 #include <linux/bootmem.h> /* for max_low_pfn */
27938+#include <linux/tboot.h>
27939
27940 #include <asm/cacheflush.h>
27941 #include <asm/e820.h>
27942@@ -16,6 +17,8 @@
27943 #include <asm/tlb.h>
27944 #include <asm/proto.h>
27945 #include <asm/dma.h> /* for MAX_DMA_PFN */
27946+#include <asm/desc.h>
27947+#include <asm/bios_ebda.h>
27948
27949 unsigned long __initdata pgt_buf_start;
27950 unsigned long __meminitdata pgt_buf_end;
27951@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27952 {
27953 int i;
27954 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27955- unsigned long start = 0, good_end;
27956+ unsigned long start = 0x100000, good_end;
27957 phys_addr_t base;
27958
27959 for (i = 0; i < nr_range; i++) {
27960@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27961 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27962 * mmio resources as well as potential bios/acpi data regions.
27963 */
27964+
27965+#ifdef CONFIG_GRKERNSEC_KMEM
27966+static unsigned int ebda_start __read_only;
27967+static unsigned int ebda_end __read_only;
27968+#endif
27969+
27970 int devmem_is_allowed(unsigned long pagenr)
27971 {
27972- if (pagenr < 256)
27973+#ifdef CONFIG_GRKERNSEC_KMEM
27974+ /* allow BDA */
27975+ if (!pagenr)
27976 return 1;
27977+ /* allow EBDA */
27978+ if (pagenr >= ebda_start && pagenr < ebda_end)
27979+ return 1;
27980+ /* if tboot is in use, allow access to its hardcoded serial log range */
27981+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27982+ return 1;
27983+#else
27984+ if (!pagenr)
27985+ return 1;
27986+#ifdef CONFIG_VM86
27987+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27988+ return 1;
27989+#endif
27990+#endif
27991+
27992+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27993+ return 1;
27994+#ifdef CONFIG_GRKERNSEC_KMEM
27995+ /* throw out everything else below 1MB */
27996+ if (pagenr <= 256)
27997+ return 0;
27998+#endif
27999 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28000 return 0;
28001 if (!page_is_ram(pagenr))
28002@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28003 #endif
28004 }
28005
28006+#ifdef CONFIG_GRKERNSEC_KMEM
28007+static inline void gr_init_ebda(void)
28008+{
28009+ unsigned int ebda_addr;
28010+ unsigned int ebda_size = 0;
28011+
28012+ ebda_addr = get_bios_ebda();
28013+ if (ebda_addr) {
28014+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28015+ ebda_size <<= 10;
28016+ }
28017+ if (ebda_addr && ebda_size) {
28018+ ebda_start = ebda_addr >> PAGE_SHIFT;
28019+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28020+ } else {
28021+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28022+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28023+ }
28024+}
28025+#else
28026+static inline void gr_init_ebda(void) { }
28027+#endif
28028+
28029 void free_initmem(void)
28030 {
28031+#ifdef CONFIG_PAX_KERNEXEC
28032+#ifdef CONFIG_X86_32
28033+ /* PaX: limit KERNEL_CS to actual size */
28034+ unsigned long addr, limit;
28035+ struct desc_struct d;
28036+ int cpu;
28037+#else
28038+ pgd_t *pgd;
28039+ pud_t *pud;
28040+ pmd_t *pmd;
28041+ unsigned long addr, end;
28042+#endif
28043+#endif
28044+
28045+ gr_init_ebda();
28046+
28047+#ifdef CONFIG_PAX_KERNEXEC
28048+#ifdef CONFIG_X86_32
28049+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28050+ limit = (limit - 1UL) >> PAGE_SHIFT;
28051+
28052+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28053+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28054+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28055+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28056+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28057+ }
28058+
28059+ /* PaX: make KERNEL_CS read-only */
28060+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28061+ if (!paravirt_enabled())
28062+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28063+/*
28064+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28065+ pgd = pgd_offset_k(addr);
28066+ pud = pud_offset(pgd, addr);
28067+ pmd = pmd_offset(pud, addr);
28068+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28069+ }
28070+*/
28071+#ifdef CONFIG_X86_PAE
28072+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28073+/*
28074+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28075+ pgd = pgd_offset_k(addr);
28076+ pud = pud_offset(pgd, addr);
28077+ pmd = pmd_offset(pud, addr);
28078+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28079+ }
28080+*/
28081+#endif
28082+
28083+#ifdef CONFIG_MODULES
28084+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28085+#endif
28086+
28087+#else
28088+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28089+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28090+ pgd = pgd_offset_k(addr);
28091+ pud = pud_offset(pgd, addr);
28092+ pmd = pmd_offset(pud, addr);
28093+ if (!pmd_present(*pmd))
28094+ continue;
28095+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28096+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28097+ else
28098+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28099+ }
28100+
28101+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28102+ end = addr + KERNEL_IMAGE_SIZE;
28103+ for (; addr < end; addr += PMD_SIZE) {
28104+ pgd = pgd_offset_k(addr);
28105+ pud = pud_offset(pgd, addr);
28106+ pmd = pmd_offset(pud, addr);
28107+ if (!pmd_present(*pmd))
28108+ continue;
28109+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28110+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28111+ }
28112+#endif
28113+
28114+ flush_tlb_all();
28115+#endif
28116+
28117 free_init_pages("unused kernel memory",
28118 (unsigned long)(&__init_begin),
28119 (unsigned long)(&__init_end));
28120diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28121index 745d66b..56bf568 100644
28122--- a/arch/x86/mm/init_32.c
28123+++ b/arch/x86/mm/init_32.c
28124@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
28125 }
28126
28127 /*
28128- * Creates a middle page table and puts a pointer to it in the
28129- * given global directory entry. This only returns the gd entry
28130- * in non-PAE compilation mode, since the middle layer is folded.
28131- */
28132-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28133-{
28134- pud_t *pud;
28135- pmd_t *pmd_table;
28136-
28137-#ifdef CONFIG_X86_PAE
28138- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28139- if (after_bootmem)
28140- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
28141- else
28142- pmd_table = (pmd_t *)alloc_low_page();
28143- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28144- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28145- pud = pud_offset(pgd, 0);
28146- BUG_ON(pmd_table != pmd_offset(pud, 0));
28147-
28148- return pmd_table;
28149- }
28150-#endif
28151- pud = pud_offset(pgd, 0);
28152- pmd_table = pmd_offset(pud, 0);
28153-
28154- return pmd_table;
28155-}
28156-
28157-/*
28158 * Create a page table and place a pointer to it in a middle page
28159 * directory entry:
28160 */
28161@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28162 page_table = (pte_t *)alloc_low_page();
28163
28164 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28165+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28166+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28167+#else
28168 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28169+#endif
28170 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28171 }
28172
28173 return pte_offset_kernel(pmd, 0);
28174 }
28175
28176+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28177+{
28178+ pud_t *pud;
28179+ pmd_t *pmd_table;
28180+
28181+ pud = pud_offset(pgd, 0);
28182+ pmd_table = pmd_offset(pud, 0);
28183+
28184+ return pmd_table;
28185+}
28186+
28187 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28188 {
28189 int pgd_idx = pgd_index(vaddr);
28190@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28191 int pgd_idx, pmd_idx;
28192 unsigned long vaddr;
28193 pgd_t *pgd;
28194+ pud_t *pud;
28195 pmd_t *pmd;
28196 pte_t *pte = NULL;
28197
28198@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28199 pgd = pgd_base + pgd_idx;
28200
28201 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28202- pmd = one_md_table_init(pgd);
28203- pmd = pmd + pmd_index(vaddr);
28204+ pud = pud_offset(pgd, vaddr);
28205+ pmd = pmd_offset(pud, vaddr);
28206+
28207+#ifdef CONFIG_X86_PAE
28208+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28209+#endif
28210+
28211 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28212 pmd++, pmd_idx++) {
28213 pte = page_table_kmap_check(one_page_table_init(pmd),
28214@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28215 }
28216 }
28217
28218-static inline int is_kernel_text(unsigned long addr)
28219+static inline int is_kernel_text(unsigned long start, unsigned long end)
28220 {
28221- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28222- return 1;
28223- return 0;
28224+ if ((start > ktla_ktva((unsigned long)_etext) ||
28225+ end <= ktla_ktva((unsigned long)_stext)) &&
28226+ (start > ktla_ktva((unsigned long)_einittext) ||
28227+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28228+
28229+#ifdef CONFIG_ACPI_SLEEP
28230+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28231+#endif
28232+
28233+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28234+ return 0;
28235+ return 1;
28236 }
28237
28238 /*
28239@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
28240 unsigned long last_map_addr = end;
28241 unsigned long start_pfn, end_pfn;
28242 pgd_t *pgd_base = swapper_pg_dir;
28243- int pgd_idx, pmd_idx, pte_ofs;
28244+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28245 unsigned long pfn;
28246 pgd_t *pgd;
28247+ pud_t *pud;
28248 pmd_t *pmd;
28249 pte_t *pte;
28250 unsigned pages_2m, pages_4k;
28251@@ -280,8 +281,13 @@ repeat:
28252 pfn = start_pfn;
28253 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28254 pgd = pgd_base + pgd_idx;
28255- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28256- pmd = one_md_table_init(pgd);
28257+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28258+ pud = pud_offset(pgd, 0);
28259+ pmd = pmd_offset(pud, 0);
28260+
28261+#ifdef CONFIG_X86_PAE
28262+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28263+#endif
28264
28265 if (pfn >= end_pfn)
28266 continue;
28267@@ -293,14 +299,13 @@ repeat:
28268 #endif
28269 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28270 pmd++, pmd_idx++) {
28271- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28272+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28273
28274 /*
28275 * Map with big pages if possible, otherwise
28276 * create normal page tables:
28277 */
28278 if (use_pse) {
28279- unsigned int addr2;
28280 pgprot_t prot = PAGE_KERNEL_LARGE;
28281 /*
28282 * first pass will use the same initial
28283@@ -310,11 +315,7 @@ repeat:
28284 __pgprot(PTE_IDENT_ATTR |
28285 _PAGE_PSE);
28286
28287- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28288- PAGE_OFFSET + PAGE_SIZE-1;
28289-
28290- if (is_kernel_text(addr) ||
28291- is_kernel_text(addr2))
28292+ if (is_kernel_text(address, address + PMD_SIZE))
28293 prot = PAGE_KERNEL_LARGE_EXEC;
28294
28295 pages_2m++;
28296@@ -331,7 +332,7 @@ repeat:
28297 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28298 pte += pte_ofs;
28299 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28300- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28301+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28302 pgprot_t prot = PAGE_KERNEL;
28303 /*
28304 * first pass will use the same initial
28305@@ -339,7 +340,7 @@ repeat:
28306 */
28307 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28308
28309- if (is_kernel_text(addr))
28310+ if (is_kernel_text(address, address + PAGE_SIZE))
28311 prot = PAGE_KERNEL_EXEC;
28312
28313 pages_4k++;
28314@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
28315
28316 pud = pud_offset(pgd, va);
28317 pmd = pmd_offset(pud, va);
28318- if (!pmd_present(*pmd))
28319+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
28320 break;
28321
28322 pte = pte_offset_kernel(pmd, va);
28323@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
28324
28325 static void __init pagetable_init(void)
28326 {
28327- pgd_t *pgd_base = swapper_pg_dir;
28328-
28329- permanent_kmaps_init(pgd_base);
28330+ permanent_kmaps_init(swapper_pg_dir);
28331 }
28332
28333-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28334+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28335 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28336
28337 /* user-defined highmem size */
28338@@ -728,6 +727,12 @@ void __init mem_init(void)
28339
28340 pci_iommu_alloc();
28341
28342+#ifdef CONFIG_PAX_PER_CPU_PGD
28343+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28344+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28345+ KERNEL_PGD_PTRS);
28346+#endif
28347+
28348 #ifdef CONFIG_FLATMEM
28349 BUG_ON(!mem_map);
28350 #endif
28351@@ -754,7 +759,7 @@ void __init mem_init(void)
28352 reservedpages++;
28353
28354 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28355- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28356+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28357 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28358
28359 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28360@@ -795,10 +800,10 @@ void __init mem_init(void)
28361 ((unsigned long)&__init_end -
28362 (unsigned long)&__init_begin) >> 10,
28363
28364- (unsigned long)&_etext, (unsigned long)&_edata,
28365- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28366+ (unsigned long)&_sdata, (unsigned long)&_edata,
28367+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28368
28369- (unsigned long)&_text, (unsigned long)&_etext,
28370+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28371 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28372
28373 /*
28374@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28375 if (!kernel_set_to_readonly)
28376 return;
28377
28378+ start = ktla_ktva(start);
28379 pr_debug("Set kernel text: %lx - %lx for read write\n",
28380 start, start+size);
28381
28382@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28383 if (!kernel_set_to_readonly)
28384 return;
28385
28386+ start = ktla_ktva(start);
28387 pr_debug("Set kernel text: %lx - %lx for read only\n",
28388 start, start+size);
28389
28390@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28391 unsigned long start = PFN_ALIGN(_text);
28392 unsigned long size = PFN_ALIGN(_etext) - start;
28393
28394+ start = ktla_ktva(start);
28395 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28396 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28397 size >> 10);
28398diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28399index 75c9a6a..498d677 100644
28400--- a/arch/x86/mm/init_64.c
28401+++ b/arch/x86/mm/init_64.c
28402@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28403 * around without checking the pgd every time.
28404 */
28405
28406-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28407+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28408 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28409
28410 int force_personality32;
28411@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28412
28413 for (address = start; address <= end; address += PGDIR_SIZE) {
28414 const pgd_t *pgd_ref = pgd_offset_k(address);
28415+
28416+#ifdef CONFIG_PAX_PER_CPU_PGD
28417+ unsigned long cpu;
28418+#else
28419 struct page *page;
28420+#endif
28421
28422 if (pgd_none(*pgd_ref))
28423 continue;
28424
28425 spin_lock(&pgd_lock);
28426+
28427+#ifdef CONFIG_PAX_PER_CPU_PGD
28428+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28429+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28430+#else
28431 list_for_each_entry(page, &pgd_list, lru) {
28432 pgd_t *pgd;
28433 spinlock_t *pgt_lock;
28434@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28435 /* the pgt_lock only for Xen */
28436 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28437 spin_lock(pgt_lock);
28438+#endif
28439
28440 if (pgd_none(*pgd))
28441 set_pgd(pgd, *pgd_ref);
28442@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28443 BUG_ON(pgd_page_vaddr(*pgd)
28444 != pgd_page_vaddr(*pgd_ref));
28445
28446+#ifndef CONFIG_PAX_PER_CPU_PGD
28447 spin_unlock(pgt_lock);
28448+#endif
28449+
28450 }
28451 spin_unlock(&pgd_lock);
28452 }
28453@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28454 {
28455 if (pgd_none(*pgd)) {
28456 pud_t *pud = (pud_t *)spp_getpage();
28457- pgd_populate(&init_mm, pgd, pud);
28458+ pgd_populate_kernel(&init_mm, pgd, pud);
28459 if (pud != pud_offset(pgd, 0))
28460 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28461 pud, pud_offset(pgd, 0));
28462@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28463 {
28464 if (pud_none(*pud)) {
28465 pmd_t *pmd = (pmd_t *) spp_getpage();
28466- pud_populate(&init_mm, pud, pmd);
28467+ pud_populate_kernel(&init_mm, pud, pmd);
28468 if (pmd != pmd_offset(pud, 0))
28469 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28470 pmd, pmd_offset(pud, 0));
28471@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28472 pmd = fill_pmd(pud, vaddr);
28473 pte = fill_pte(pmd, vaddr);
28474
28475+ pax_open_kernel();
28476 set_pte(pte, new_pte);
28477+ pax_close_kernel();
28478
28479 /*
28480 * It's enough to flush this one mapping.
28481@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28482 pgd = pgd_offset_k((unsigned long)__va(phys));
28483 if (pgd_none(*pgd)) {
28484 pud = (pud_t *) spp_getpage();
28485- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28486- _PAGE_USER));
28487+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28488 }
28489 pud = pud_offset(pgd, (unsigned long)__va(phys));
28490 if (pud_none(*pud)) {
28491 pmd = (pmd_t *) spp_getpage();
28492- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28493- _PAGE_USER));
28494+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28495 }
28496 pmd = pmd_offset(pud, phys);
28497 BUG_ON(!pmd_none(*pmd));
28498@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28499 if (pfn >= pgt_buf_top)
28500 panic("alloc_low_page: ran out of memory");
28501
28502- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28503+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28504 clear_page(adr);
28505 *phys = pfn * PAGE_SIZE;
28506 return adr;
28507@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28508
28509 phys = __pa(virt);
28510 left = phys & (PAGE_SIZE - 1);
28511- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28512+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28513 adr = (void *)(((unsigned long)adr) | left);
28514
28515 return adr;
28516@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28517 unmap_low_page(pmd);
28518
28519 spin_lock(&init_mm.page_table_lock);
28520- pud_populate(&init_mm, pud, __va(pmd_phys));
28521+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28522 spin_unlock(&init_mm.page_table_lock);
28523 }
28524 __flush_tlb_all();
28525@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28526 unmap_low_page(pud);
28527
28528 spin_lock(&init_mm.page_table_lock);
28529- pgd_populate(&init_mm, pgd, __va(pud_phys));
28530+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28531 spin_unlock(&init_mm.page_table_lock);
28532 pgd_changed = true;
28533 }
28534@@ -693,6 +707,12 @@ void __init mem_init(void)
28535
28536 pci_iommu_alloc();
28537
28538+#ifdef CONFIG_PAX_PER_CPU_PGD
28539+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28540+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28541+ KERNEL_PGD_PTRS);
28542+#endif
28543+
28544 /* clear_bss() already clear the empty_zero_page */
28545
28546 reservedpages = 0;
28547@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28548 static struct vm_area_struct gate_vma = {
28549 .vm_start = VSYSCALL_START,
28550 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28551- .vm_page_prot = PAGE_READONLY_EXEC,
28552- .vm_flags = VM_READ | VM_EXEC
28553+ .vm_page_prot = PAGE_READONLY,
28554+ .vm_flags = VM_READ
28555 };
28556
28557 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28558@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28559
28560 const char *arch_vma_name(struct vm_area_struct *vma)
28561 {
28562- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28563+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28564 return "[vdso]";
28565 if (vma == &gate_vma)
28566 return "[vsyscall]";
28567diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28568index 7b179b4..6bd1777 100644
28569--- a/arch/x86/mm/iomap_32.c
28570+++ b/arch/x86/mm/iomap_32.c
28571@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28572 type = kmap_atomic_idx_push();
28573 idx = type + KM_TYPE_NR * smp_processor_id();
28574 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28575+
28576+ pax_open_kernel();
28577 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28578+ pax_close_kernel();
28579+
28580 arch_flush_lazy_mmu_mode();
28581
28582 return (void *)vaddr;
28583diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28584index 78fe3f1..2f9433c 100644
28585--- a/arch/x86/mm/ioremap.c
28586+++ b/arch/x86/mm/ioremap.c
28587@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28588 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28589 int is_ram = page_is_ram(pfn);
28590
28591- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28592+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28593 return NULL;
28594 WARN_ON_ONCE(is_ram);
28595 }
28596@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28597 *
28598 * Caller must ensure there is only one unmapping for the same pointer.
28599 */
28600-void iounmap(volatile void __iomem *addr)
28601+void iounmap(const volatile void __iomem *addr)
28602 {
28603 struct vm_struct *p, *o;
28604
28605@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28606
28607 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28608 if (page_is_ram(start >> PAGE_SHIFT))
28609+#ifdef CONFIG_HIGHMEM
28610+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28611+#endif
28612 return __va(phys);
28613
28614 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28615@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
28616 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28617
28618 static __initdata int after_paging_init;
28619-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28620+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28621
28622 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28623 {
28624@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
28625 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28626
28627 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28628- memset(bm_pte, 0, sizeof(bm_pte));
28629- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28630+ pmd_populate_user(&init_mm, pmd, bm_pte);
28631
28632 /*
28633 * The boot-ioremap range spans multiple pmds, for which
28634diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28635index d87dd6d..bf3fa66 100644
28636--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28637+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28638@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28639 * memory (e.g. tracked pages)? For now, we need this to avoid
28640 * invoking kmemcheck for PnP BIOS calls.
28641 */
28642- if (regs->flags & X86_VM_MASK)
28643+ if (v8086_mode(regs))
28644 return false;
28645- if (regs->cs != __KERNEL_CS)
28646+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28647 return false;
28648
28649 pte = kmemcheck_pte_lookup(address);
28650diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28651index 845df68..1d8d29f 100644
28652--- a/arch/x86/mm/mmap.c
28653+++ b/arch/x86/mm/mmap.c
28654@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28655 * Leave an at least ~128 MB hole with possible stack randomization.
28656 */
28657 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28658-#define MAX_GAP (TASK_SIZE/6*5)
28659+#define MAX_GAP (pax_task_size/6*5)
28660
28661 static int mmap_is_legacy(void)
28662 {
28663@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28664 return rnd << PAGE_SHIFT;
28665 }
28666
28667-static unsigned long mmap_base(void)
28668+static unsigned long mmap_base(struct mm_struct *mm)
28669 {
28670 unsigned long gap = rlimit(RLIMIT_STACK);
28671+ unsigned long pax_task_size = TASK_SIZE;
28672+
28673+#ifdef CONFIG_PAX_SEGMEXEC
28674+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28675+ pax_task_size = SEGMEXEC_TASK_SIZE;
28676+#endif
28677
28678 if (gap < MIN_GAP)
28679 gap = MIN_GAP;
28680 else if (gap > MAX_GAP)
28681 gap = MAX_GAP;
28682
28683- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28684+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28685 }
28686
28687 /*
28688 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28689 * does, but not when emulating X86_32
28690 */
28691-static unsigned long mmap_legacy_base(void)
28692+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28693 {
28694- if (mmap_is_ia32())
28695+ if (mmap_is_ia32()) {
28696+
28697+#ifdef CONFIG_PAX_SEGMEXEC
28698+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28699+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28700+ else
28701+#endif
28702+
28703 return TASK_UNMAPPED_BASE;
28704- else
28705+ } else
28706 return TASK_UNMAPPED_BASE + mmap_rnd();
28707 }
28708
28709@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28710 void arch_pick_mmap_layout(struct mm_struct *mm)
28711 {
28712 if (mmap_is_legacy()) {
28713- mm->mmap_base = mmap_legacy_base();
28714+ mm->mmap_base = mmap_legacy_base(mm);
28715+
28716+#ifdef CONFIG_PAX_RANDMMAP
28717+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28718+ mm->mmap_base += mm->delta_mmap;
28719+#endif
28720+
28721 mm->get_unmapped_area = arch_get_unmapped_area;
28722 mm->unmap_area = arch_unmap_area;
28723 } else {
28724- mm->mmap_base = mmap_base();
28725+ mm->mmap_base = mmap_base(mm);
28726+
28727+#ifdef CONFIG_PAX_RANDMMAP
28728+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28729+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28730+#endif
28731+
28732 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28733 mm->unmap_area = arch_unmap_area_topdown;
28734 }
28735diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28736index dc0b727..f612039 100644
28737--- a/arch/x86/mm/mmio-mod.c
28738+++ b/arch/x86/mm/mmio-mod.c
28739@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28740 break;
28741 default:
28742 {
28743- unsigned char *ip = (unsigned char *)instptr;
28744+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28745 my_trace->opcode = MMIO_UNKNOWN_OP;
28746 my_trace->width = 0;
28747 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28748@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28749 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28750 void __iomem *addr)
28751 {
28752- static atomic_t next_id;
28753+ static atomic_unchecked_t next_id;
28754 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28755 /* These are page-unaligned. */
28756 struct mmiotrace_map map = {
28757@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28758 .private = trace
28759 },
28760 .phys = offset,
28761- .id = atomic_inc_return(&next_id)
28762+ .id = atomic_inc_return_unchecked(&next_id)
28763 };
28764 map.map_id = trace->id;
28765
28766@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28767 ioremap_trace_core(offset, size, addr);
28768 }
28769
28770-static void iounmap_trace_core(volatile void __iomem *addr)
28771+static void iounmap_trace_core(const volatile void __iomem *addr)
28772 {
28773 struct mmiotrace_map map = {
28774 .phys = 0,
28775@@ -328,7 +328,7 @@ not_enabled:
28776 }
28777 }
28778
28779-void mmiotrace_iounmap(volatile void __iomem *addr)
28780+void mmiotrace_iounmap(const volatile void __iomem *addr)
28781 {
28782 might_sleep();
28783 if (is_enabled()) /* recheck and proper locking in *_core() */
28784diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28785index 8504f36..5fc68f2 100644
28786--- a/arch/x86/mm/numa.c
28787+++ b/arch/x86/mm/numa.c
28788@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28789 return true;
28790 }
28791
28792-static int __init numa_register_memblks(struct numa_meminfo *mi)
28793+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28794 {
28795 unsigned long uninitialized_var(pfn_align);
28796 int i, nid;
28797diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28798index b008656..773eac2 100644
28799--- a/arch/x86/mm/pageattr-test.c
28800+++ b/arch/x86/mm/pageattr-test.c
28801@@ -36,7 +36,7 @@ enum {
28802
28803 static int pte_testbit(pte_t pte)
28804 {
28805- return pte_flags(pte) & _PAGE_UNUSED1;
28806+ return pte_flags(pte) & _PAGE_CPA_TEST;
28807 }
28808
28809 struct split_state {
28810diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28811index a718e0d..77419bc 100644
28812--- a/arch/x86/mm/pageattr.c
28813+++ b/arch/x86/mm/pageattr.c
28814@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28815 */
28816 #ifdef CONFIG_PCI_BIOS
28817 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28818- pgprot_val(forbidden) |= _PAGE_NX;
28819+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28820 #endif
28821
28822 /*
28823@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28824 * Does not cover __inittext since that is gone later on. On
28825 * 64bit we do not enforce !NX on the low mapping
28826 */
28827- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28828- pgprot_val(forbidden) |= _PAGE_NX;
28829+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28830+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28831
28832+#ifdef CONFIG_DEBUG_RODATA
28833 /*
28834 * The .rodata section needs to be read-only. Using the pfn
28835 * catches all aliases.
28836@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28837 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28838 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28839 pgprot_val(forbidden) |= _PAGE_RW;
28840+#endif
28841
28842 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28843 /*
28844@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28845 }
28846 #endif
28847
28848+#ifdef CONFIG_PAX_KERNEXEC
28849+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28850+ pgprot_val(forbidden) |= _PAGE_RW;
28851+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28852+ }
28853+#endif
28854+
28855 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28856
28857 return prot;
28858@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28859 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28860 {
28861 /* change init_mm */
28862+ pax_open_kernel();
28863 set_pte_atomic(kpte, pte);
28864+
28865 #ifdef CONFIG_X86_32
28866 if (!SHARED_KERNEL_PMD) {
28867+
28868+#ifdef CONFIG_PAX_PER_CPU_PGD
28869+ unsigned long cpu;
28870+#else
28871 struct page *page;
28872+#endif
28873
28874+#ifdef CONFIG_PAX_PER_CPU_PGD
28875+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28876+ pgd_t *pgd = get_cpu_pgd(cpu);
28877+#else
28878 list_for_each_entry(page, &pgd_list, lru) {
28879- pgd_t *pgd;
28880+ pgd_t *pgd = (pgd_t *)page_address(page);
28881+#endif
28882+
28883 pud_t *pud;
28884 pmd_t *pmd;
28885
28886- pgd = (pgd_t *)page_address(page) + pgd_index(address);
28887+ pgd += pgd_index(address);
28888 pud = pud_offset(pgd, address);
28889 pmd = pmd_offset(pud, address);
28890 set_pte_atomic((pte_t *)pmd, pte);
28891 }
28892 }
28893 #endif
28894+ pax_close_kernel();
28895 }
28896
28897 static int
28898diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28899index 0eb572e..92f5c1e 100644
28900--- a/arch/x86/mm/pat.c
28901+++ b/arch/x86/mm/pat.c
28902@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28903
28904 if (!entry) {
28905 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28906- current->comm, current->pid, start, end - 1);
28907+ current->comm, task_pid_nr(current), start, end - 1);
28908 return -EINVAL;
28909 }
28910
28911@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28912
28913 while (cursor < to) {
28914 if (!devmem_is_allowed(pfn)) {
28915- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28916- current->comm, from, to - 1);
28917+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28918+ current->comm, from, to - 1, cursor);
28919 return 0;
28920 }
28921 cursor += PAGE_SIZE;
28922@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28923 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28924 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28925 "for [mem %#010Lx-%#010Lx]\n",
28926- current->comm, current->pid,
28927+ current->comm, task_pid_nr(current),
28928 cattr_name(flags),
28929 base, (unsigned long long)(base + size-1));
28930 return -EINVAL;
28931@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28932 flags = lookup_memtype(paddr);
28933 if (want_flags != flags) {
28934 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28935- current->comm, current->pid,
28936+ current->comm, task_pid_nr(current),
28937 cattr_name(want_flags),
28938 (unsigned long long)paddr,
28939 (unsigned long long)(paddr + size - 1),
28940@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28941 free_memtype(paddr, paddr + size);
28942 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28943 " 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),
28949diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28950index 9f0614d..92ae64a 100644
28951--- a/arch/x86/mm/pf_in.c
28952+++ b/arch/x86/mm/pf_in.c
28953@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28954 int i;
28955 enum reason_type rv = OTHERS;
28956
28957- p = (unsigned char *)ins_addr;
28958+ p = (unsigned char *)ktla_ktva(ins_addr);
28959 p += skip_prefix(p, &prf);
28960 p += get_opcode(p, &opcode);
28961
28962@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28963 struct prefix_bits prf;
28964 int i;
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@@ -191,7 +191,7 @@ unsigned int get_ins_mem_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@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
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 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28989@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
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(imm_wop); i++)
28998diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28999index e27fbf8..8b56dc9 100644
29000--- a/arch/x86/mm/pgtable.c
29001+++ b/arch/x86/mm/pgtable.c
29002@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29003 list_del(&page->lru);
29004 }
29005
29006-#define UNSHARED_PTRS_PER_PGD \
29007- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29008+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29009+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29010
29011+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29012+{
29013+ unsigned int count = USER_PGD_PTRS;
29014
29015+ while (count--)
29016+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29017+}
29018+#endif
29019+
29020+#ifdef CONFIG_PAX_PER_CPU_PGD
29021+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29022+{
29023+ unsigned int count = USER_PGD_PTRS;
29024+
29025+ while (count--) {
29026+ pgd_t pgd;
29027+
29028+#ifdef CONFIG_X86_64
29029+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29030+#else
29031+ pgd = *src++;
29032+#endif
29033+
29034+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29035+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29036+#endif
29037+
29038+ *dst++ = pgd;
29039+ }
29040+
29041+}
29042+#endif
29043+
29044+#ifdef CONFIG_X86_64
29045+#define pxd_t pud_t
29046+#define pyd_t pgd_t
29047+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29048+#define pxd_free(mm, pud) pud_free((mm), (pud))
29049+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29050+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29051+#define PYD_SIZE PGDIR_SIZE
29052+#else
29053+#define pxd_t pmd_t
29054+#define pyd_t pud_t
29055+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29056+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29057+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29058+#define pyd_offset(mm, address) pud_offset((mm), (address))
29059+#define PYD_SIZE PUD_SIZE
29060+#endif
29061+
29062+#ifdef CONFIG_PAX_PER_CPU_PGD
29063+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29064+static inline void pgd_dtor(pgd_t *pgd) {}
29065+#else
29066 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29067 {
29068 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29069@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
29070 pgd_list_del(pgd);
29071 spin_unlock(&pgd_lock);
29072 }
29073+#endif
29074
29075 /*
29076 * List of all pgd's needed for non-PAE so it can invalidate entries
29077@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
29078 * -- nyc
29079 */
29080
29081-#ifdef CONFIG_X86_PAE
29082+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29083 /*
29084 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29085 * updating the top-level pagetable entries to guarantee the
29086@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
29087 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29088 * and initialize the kernel pmds here.
29089 */
29090-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29091+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29092
29093 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29094 {
29095@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29096 */
29097 flush_tlb_mm(mm);
29098 }
29099+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29100+#define PREALLOCATED_PXDS USER_PGD_PTRS
29101 #else /* !CONFIG_X86_PAE */
29102
29103 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29104-#define PREALLOCATED_PMDS 0
29105+#define PREALLOCATED_PXDS 0
29106
29107 #endif /* CONFIG_X86_PAE */
29108
29109-static void free_pmds(pmd_t *pmds[])
29110+static void free_pxds(pxd_t *pxds[])
29111 {
29112 int i;
29113
29114- for(i = 0; i < PREALLOCATED_PMDS; i++)
29115- if (pmds[i])
29116- free_page((unsigned long)pmds[i]);
29117+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29118+ if (pxds[i])
29119+ free_page((unsigned long)pxds[i]);
29120 }
29121
29122-static int preallocate_pmds(pmd_t *pmds[])
29123+static int preallocate_pxds(pxd_t *pxds[])
29124 {
29125 int i;
29126 bool failed = false;
29127
29128- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29129- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29130- if (pmd == NULL)
29131+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29132+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29133+ if (pxd == NULL)
29134 failed = true;
29135- pmds[i] = pmd;
29136+ pxds[i] = pxd;
29137 }
29138
29139 if (failed) {
29140- free_pmds(pmds);
29141+ free_pxds(pxds);
29142 return -ENOMEM;
29143 }
29144
29145@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29146 * preallocate which never got a corresponding vma will need to be
29147 * freed manually.
29148 */
29149-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29150+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29151 {
29152 int i;
29153
29154- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29155+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29156 pgd_t pgd = pgdp[i];
29157
29158 if (pgd_val(pgd) != 0) {
29159- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29160+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29161
29162- pgdp[i] = native_make_pgd(0);
29163+ set_pgd(pgdp + i, native_make_pgd(0));
29164
29165- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29166- pmd_free(mm, pmd);
29167+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29168+ pxd_free(mm, pxd);
29169 }
29170 }
29171 }
29172
29173-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29174+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29175 {
29176- pud_t *pud;
29177+ pyd_t *pyd;
29178 unsigned long addr;
29179 int i;
29180
29181- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29182+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29183 return;
29184
29185- pud = pud_offset(pgd, 0);
29186+#ifdef CONFIG_X86_64
29187+ pyd = pyd_offset(mm, 0L);
29188+#else
29189+ pyd = pyd_offset(pgd, 0L);
29190+#endif
29191
29192- for (addr = i = 0; i < PREALLOCATED_PMDS;
29193- i++, pud++, addr += PUD_SIZE) {
29194- pmd_t *pmd = pmds[i];
29195+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29196+ i++, pyd++, addr += PYD_SIZE) {
29197+ pxd_t *pxd = pxds[i];
29198
29199 if (i >= KERNEL_PGD_BOUNDARY)
29200- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29201- sizeof(pmd_t) * PTRS_PER_PMD);
29202+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29203+ sizeof(pxd_t) * PTRS_PER_PMD);
29204
29205- pud_populate(mm, pud, pmd);
29206+ pyd_populate(mm, pyd, pxd);
29207 }
29208 }
29209
29210 pgd_t *pgd_alloc(struct mm_struct *mm)
29211 {
29212 pgd_t *pgd;
29213- pmd_t *pmds[PREALLOCATED_PMDS];
29214+ pxd_t *pxds[PREALLOCATED_PXDS];
29215
29216 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29217
29218@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29219
29220 mm->pgd = pgd;
29221
29222- if (preallocate_pmds(pmds) != 0)
29223+ if (preallocate_pxds(pxds) != 0)
29224 goto out_free_pgd;
29225
29226 if (paravirt_pgd_alloc(mm) != 0)
29227- goto out_free_pmds;
29228+ goto out_free_pxds;
29229
29230 /*
29231 * Make sure that pre-populating the pmds is atomic with
29232@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29233 spin_lock(&pgd_lock);
29234
29235 pgd_ctor(mm, pgd);
29236- pgd_prepopulate_pmd(mm, pgd, pmds);
29237+ pgd_prepopulate_pxd(mm, pgd, pxds);
29238
29239 spin_unlock(&pgd_lock);
29240
29241 return pgd;
29242
29243-out_free_pmds:
29244- free_pmds(pmds);
29245+out_free_pxds:
29246+ free_pxds(pxds);
29247 out_free_pgd:
29248 free_page((unsigned long)pgd);
29249 out:
29250@@ -295,7 +356,7 @@ out:
29251
29252 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29253 {
29254- pgd_mop_up_pmds(mm, pgd);
29255+ pgd_mop_up_pxds(mm, pgd);
29256 pgd_dtor(pgd);
29257 paravirt_pgd_free(mm, pgd);
29258 free_page((unsigned long)pgd);
29259diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29260index a69bcb8..19068ab 100644
29261--- a/arch/x86/mm/pgtable_32.c
29262+++ b/arch/x86/mm/pgtable_32.c
29263@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29264 return;
29265 }
29266 pte = pte_offset_kernel(pmd, vaddr);
29267+
29268+ pax_open_kernel();
29269 if (pte_val(pteval))
29270 set_pte_at(&init_mm, vaddr, pte, pteval);
29271 else
29272 pte_clear(&init_mm, vaddr, pte);
29273+ pax_close_kernel();
29274
29275 /*
29276 * It's enough to flush this one mapping.
29277diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29278index d2e2735..5c6586f 100644
29279--- a/arch/x86/mm/physaddr.c
29280+++ b/arch/x86/mm/physaddr.c
29281@@ -8,7 +8,7 @@
29282
29283 #ifdef CONFIG_X86_64
29284
29285-unsigned long __phys_addr(unsigned long x)
29286+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29287 {
29288 if (x >= __START_KERNEL_map) {
29289 x -= __START_KERNEL_map;
29290@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29291 #else
29292
29293 #ifdef CONFIG_DEBUG_VIRTUAL
29294-unsigned long __phys_addr(unsigned long x)
29295+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29296 {
29297 /* VMALLOC_* aren't constants */
29298 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
29299diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29300index 410531d..0f16030 100644
29301--- a/arch/x86/mm/setup_nx.c
29302+++ b/arch/x86/mm/setup_nx.c
29303@@ -5,8 +5,10 @@
29304 #include <asm/pgtable.h>
29305 #include <asm/proto.h>
29306
29307+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29308 static int disable_nx __cpuinitdata;
29309
29310+#ifndef CONFIG_PAX_PAGEEXEC
29311 /*
29312 * noexec = on|off
29313 *
29314@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29315 return 0;
29316 }
29317 early_param("noexec", noexec_setup);
29318+#endif
29319+
29320+#endif
29321
29322 void __cpuinit x86_configure_nx(void)
29323 {
29324+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29325 if (cpu_has_nx && !disable_nx)
29326 __supported_pte_mask |= _PAGE_NX;
29327 else
29328+#endif
29329 __supported_pte_mask &= ~_PAGE_NX;
29330 }
29331
29332diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29333index 13a6b29..c2fff23 100644
29334--- a/arch/x86/mm/tlb.c
29335+++ b/arch/x86/mm/tlb.c
29336@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29337 BUG();
29338 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29339 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29340+
29341+#ifndef CONFIG_PAX_PER_CPU_PGD
29342 load_cr3(swapper_pg_dir);
29343+#endif
29344+
29345 }
29346 }
29347 EXPORT_SYMBOL_GPL(leave_mm);
29348diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29349index 877b9a1..a8ecf42 100644
29350--- a/arch/x86/net/bpf_jit.S
29351+++ b/arch/x86/net/bpf_jit.S
29352@@ -9,6 +9,7 @@
29353 */
29354 #include <linux/linkage.h>
29355 #include <asm/dwarf2.h>
29356+#include <asm/alternative-asm.h>
29357
29358 /*
29359 * Calling convention :
29360@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29361 jle bpf_slow_path_word
29362 mov (SKBDATA,%rsi),%eax
29363 bswap %eax /* ntohl() */
29364+ pax_force_retaddr
29365 ret
29366
29367 sk_load_half:
29368@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29369 jle bpf_slow_path_half
29370 movzwl (SKBDATA,%rsi),%eax
29371 rol $8,%ax # ntohs()
29372+ pax_force_retaddr
29373 ret
29374
29375 sk_load_byte:
29376@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29377 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29378 jle bpf_slow_path_byte
29379 movzbl (SKBDATA,%rsi),%eax
29380+ pax_force_retaddr
29381 ret
29382
29383 /**
29384@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29385 movzbl (SKBDATA,%rsi),%ebx
29386 and $15,%bl
29387 shl $2,%bl
29388+ pax_force_retaddr
29389 ret
29390
29391 /* rsi contains offset and can be scratched */
29392@@ -109,6 +114,7 @@ bpf_slow_path_word:
29393 js bpf_error
29394 mov -12(%rbp),%eax
29395 bswap %eax
29396+ pax_force_retaddr
29397 ret
29398
29399 bpf_slow_path_half:
29400@@ -117,12 +123,14 @@ bpf_slow_path_half:
29401 mov -12(%rbp),%ax
29402 rol $8,%ax
29403 movzwl %ax,%eax
29404+ pax_force_retaddr
29405 ret
29406
29407 bpf_slow_path_byte:
29408 bpf_slow_path_common(1)
29409 js bpf_error
29410 movzbl -12(%rbp),%eax
29411+ pax_force_retaddr
29412 ret
29413
29414 bpf_slow_path_byte_msh:
29415@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29416 and $15,%al
29417 shl $2,%al
29418 xchg %eax,%ebx
29419+ pax_force_retaddr
29420 ret
29421
29422 #define sk_negative_common(SIZE) \
29423@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29424 sk_negative_common(4)
29425 mov (%rax), %eax
29426 bswap %eax
29427+ pax_force_retaddr
29428 ret
29429
29430 bpf_slow_path_half_neg:
29431@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29432 mov (%rax),%ax
29433 rol $8,%ax
29434 movzwl %ax,%eax
29435+ pax_force_retaddr
29436 ret
29437
29438 bpf_slow_path_byte_neg:
29439@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29440 .globl sk_load_byte_negative_offset
29441 sk_negative_common(1)
29442 movzbl (%rax), %eax
29443+ pax_force_retaddr
29444 ret
29445
29446 bpf_slow_path_byte_msh_neg:
29447@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29448 and $15,%al
29449 shl $2,%al
29450 xchg %eax,%ebx
29451+ pax_force_retaddr
29452 ret
29453
29454 bpf_error:
29455@@ -197,4 +210,5 @@ bpf_error:
29456 xor %eax,%eax
29457 mov -8(%rbp),%rbx
29458 leaveq
29459+ pax_force_retaddr
29460 ret
29461diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29462index d11a470..3f9adff3 100644
29463--- a/arch/x86/net/bpf_jit_comp.c
29464+++ b/arch/x86/net/bpf_jit_comp.c
29465@@ -12,6 +12,7 @@
29466 #include <linux/netdevice.h>
29467 #include <linux/filter.h>
29468 #include <linux/if_vlan.h>
29469+#include <linux/random.h>
29470
29471 /*
29472 * Conventions :
29473@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29474 return ptr + len;
29475 }
29476
29477+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29478+#define MAX_INSTR_CODE_SIZE 96
29479+#else
29480+#define MAX_INSTR_CODE_SIZE 64
29481+#endif
29482+
29483 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29484
29485 #define EMIT1(b1) EMIT(b1, 1)
29486 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29487 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29488 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29489+
29490+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29491+/* original constant will appear in ecx */
29492+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29493+do { \
29494+ /* mov ecx, randkey */ \
29495+ EMIT1(0xb9); \
29496+ EMIT(_key, 4); \
29497+ /* xor ecx, randkey ^ off */ \
29498+ EMIT2(0x81, 0xf1); \
29499+ EMIT((_key) ^ (_off), 4); \
29500+} while (0)
29501+
29502+#define EMIT1_off32(b1, _off) \
29503+do { \
29504+ switch (b1) { \
29505+ case 0x05: /* add eax, imm32 */ \
29506+ case 0x2d: /* sub eax, imm32 */ \
29507+ case 0x25: /* and eax, imm32 */ \
29508+ case 0x0d: /* or eax, imm32 */ \
29509+ case 0xb8: /* mov eax, imm32 */ \
29510+ case 0x3d: /* cmp eax, imm32 */ \
29511+ case 0xa9: /* test eax, imm32 */ \
29512+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29513+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29514+ break; \
29515+ case 0xbb: /* mov ebx, imm32 */ \
29516+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29517+ /* mov ebx, ecx */ \
29518+ EMIT2(0x89, 0xcb); \
29519+ break; \
29520+ case 0xbe: /* mov esi, imm32 */ \
29521+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29522+ /* mov esi, ecx */ \
29523+ EMIT2(0x89, 0xce); \
29524+ break; \
29525+ case 0xe9: /* jmp rel imm32 */ \
29526+ EMIT1(b1); \
29527+ EMIT(_off, 4); \
29528+ /* prevent fall-through, we're not called if off = 0 */ \
29529+ EMIT(0xcccccccc, 4); \
29530+ EMIT(0xcccccccc, 4); \
29531+ break; \
29532+ default: \
29533+ EMIT1(b1); \
29534+ EMIT(_off, 4); \
29535+ } \
29536+} while (0)
29537+
29538+#define EMIT2_off32(b1, b2, _off) \
29539+do { \
29540+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29541+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29542+ EMIT(randkey, 4); \
29543+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29544+ EMIT((_off) - randkey, 4); \
29545+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29546+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29547+ /* imul eax, ecx */ \
29548+ EMIT3(0x0f, 0xaf, 0xc1); \
29549+ } else { \
29550+ EMIT2(b1, b2); \
29551+ EMIT(_off, 4); \
29552+ } \
29553+} while (0)
29554+#else
29555 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29556+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29557+#endif
29558
29559 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29560 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29561@@ -90,6 +165,24 @@ do { \
29562 #define X86_JBE 0x76
29563 #define X86_JA 0x77
29564
29565+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29566+#define APPEND_FLOW_VERIFY() \
29567+do { \
29568+ /* mov ecx, randkey */ \
29569+ EMIT1(0xb9); \
29570+ EMIT(randkey, 4); \
29571+ /* cmp ecx, randkey */ \
29572+ EMIT2(0x81, 0xf9); \
29573+ EMIT(randkey, 4); \
29574+ /* jz after 8 int 3s */ \
29575+ EMIT2(0x74, 0x08); \
29576+ EMIT(0xcccccccc, 4); \
29577+ EMIT(0xcccccccc, 4); \
29578+} while (0)
29579+#else
29580+#define APPEND_FLOW_VERIFY() do { } while (0)
29581+#endif
29582+
29583 #define EMIT_COND_JMP(op, offset) \
29584 do { \
29585 if (is_near(offset)) \
29586@@ -97,6 +190,7 @@ do { \
29587 else { \
29588 EMIT2(0x0f, op + 0x10); \
29589 EMIT(offset, 4); /* jxx .+off32 */ \
29590+ APPEND_FLOW_VERIFY(); \
29591 } \
29592 } while (0)
29593
29594@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29595 set_fs(old_fs);
29596 }
29597
29598+struct bpf_jit_work {
29599+ struct work_struct work;
29600+ void *image;
29601+};
29602+
29603 #define CHOOSE_LOAD_FUNC(K, func) \
29604 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29605
29606 void bpf_jit_compile(struct sk_filter *fp)
29607 {
29608- u8 temp[64];
29609+ u8 temp[MAX_INSTR_CODE_SIZE];
29610 u8 *prog;
29611 unsigned int proglen, oldproglen = 0;
29612 int ilen, i;
29613@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29614 unsigned int *addrs;
29615 const struct sock_filter *filter = fp->insns;
29616 int flen = fp->len;
29617+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29618+ unsigned int randkey;
29619+#endif
29620
29621 if (!bpf_jit_enable)
29622 return;
29623@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29624 if (addrs == NULL)
29625 return;
29626
29627+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29628+ if (!fp->work)
29629+ goto out;
29630+
29631+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29632+ randkey = get_random_int();
29633+#endif
29634+
29635 /* Before first pass, make a rough estimation of addrs[]
29636- * each bpf instruction is translated to less than 64 bytes
29637+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29638 */
29639 for (proglen = 0, i = 0; i < flen; i++) {
29640- proglen += 64;
29641+ proglen += MAX_INSTR_CODE_SIZE;
29642 addrs[i] = proglen;
29643 }
29644 cleanup_addr = proglen; /* epilogue address */
29645@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29646 case BPF_S_ALU_MUL_K: /* A *= K */
29647 if (is_imm8(K))
29648 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29649- else {
29650- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29651- EMIT(K, 4);
29652- }
29653+ else
29654+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29655 break;
29656 case BPF_S_ALU_DIV_X: /* A /= X; */
29657 seen |= SEEN_XREG;
29658@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29659 break;
29660 case BPF_S_ALU_MOD_K: /* A %= K; */
29661 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29662+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29663+ DILUTE_CONST_SEQUENCE(K, randkey);
29664+#else
29665 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29666+#endif
29667 EMIT2(0xf7, 0xf1); /* div %ecx */
29668 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29669 break;
29670 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29671+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29672+ DILUTE_CONST_SEQUENCE(K, randkey);
29673+ // imul rax, rcx
29674+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29675+#else
29676 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29677 EMIT(K, 4);
29678+#endif
29679 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29680 break;
29681 case BPF_S_ALU_AND_X:
29682@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29683 if (is_imm8(K)) {
29684 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29685 } else {
29686- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29687- EMIT(K, 4);
29688+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29689 }
29690 } else {
29691 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29692@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29693 break;
29694 default:
29695 /* hmm, too complex filter, give up with jit compiler */
29696- goto out;
29697+ goto error;
29698 }
29699 ilen = prog - temp;
29700 if (image) {
29701 if (unlikely(proglen + ilen > oldproglen)) {
29702 pr_err("bpb_jit_compile fatal error\n");
29703- kfree(addrs);
29704- module_free(NULL, image);
29705- return;
29706+ module_free_exec(NULL, image);
29707+ goto error;
29708 }
29709+ pax_open_kernel();
29710 memcpy(image + proglen, temp, ilen);
29711+ pax_close_kernel();
29712 }
29713 proglen += ilen;
29714 addrs[i] = proglen;
29715@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29716 break;
29717 }
29718 if (proglen == oldproglen) {
29719- image = module_alloc(max_t(unsigned int,
29720- proglen,
29721- sizeof(struct work_struct)));
29722+ image = module_alloc_exec(proglen);
29723 if (!image)
29724- goto out;
29725+ goto error;
29726 }
29727 oldproglen = proglen;
29728 }
29729@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29730 bpf_flush_icache(image, image + proglen);
29731
29732 fp->bpf_func = (void *)image;
29733- }
29734+ } else
29735+error:
29736+ kfree(fp->work);
29737+
29738 out:
29739 kfree(addrs);
29740 return;
29741@@ -707,18 +826,20 @@ out:
29742
29743 static void jit_free_defer(struct work_struct *arg)
29744 {
29745- module_free(NULL, arg);
29746+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29747+ kfree(arg);
29748 }
29749
29750 /* run from softirq, we must use a work_struct to call
29751- * module_free() from process context
29752+ * module_free_exec() from process context
29753 */
29754 void bpf_jit_free(struct sk_filter *fp)
29755 {
29756 if (fp->bpf_func != sk_run_filter) {
29757- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29758+ struct work_struct *work = &fp->work->work;
29759
29760 INIT_WORK(work, jit_free_defer);
29761+ fp->work->image = fp->bpf_func;
29762 schedule_work(work);
29763 }
29764 }
29765diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29766index d6aa6e8..266395a 100644
29767--- a/arch/x86/oprofile/backtrace.c
29768+++ b/arch/x86/oprofile/backtrace.c
29769@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29770 struct stack_frame_ia32 *fp;
29771 unsigned long bytes;
29772
29773- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29774+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29775 if (bytes != sizeof(bufhead))
29776 return NULL;
29777
29778- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29779+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29780
29781 oprofile_add_trace(bufhead[0].return_address);
29782
29783@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29784 struct stack_frame bufhead[2];
29785 unsigned long bytes;
29786
29787- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29788+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29789 if (bytes != sizeof(bufhead))
29790 return NULL;
29791
29792@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29793 {
29794 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29795
29796- if (!user_mode_vm(regs)) {
29797+ if (!user_mode(regs)) {
29798 unsigned long stack = kernel_stack_pointer(regs);
29799 if (depth)
29800 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29801diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29802index 48768df..ba9143c 100644
29803--- a/arch/x86/oprofile/nmi_int.c
29804+++ b/arch/x86/oprofile/nmi_int.c
29805@@ -23,6 +23,7 @@
29806 #include <asm/nmi.h>
29807 #include <asm/msr.h>
29808 #include <asm/apic.h>
29809+#include <asm/pgtable.h>
29810
29811 #include "op_counter.h"
29812 #include "op_x86_model.h"
29813@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29814 if (ret)
29815 return ret;
29816
29817- if (!model->num_virt_counters)
29818- model->num_virt_counters = model->num_counters;
29819+ if (!model->num_virt_counters) {
29820+ pax_open_kernel();
29821+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29822+ pax_close_kernel();
29823+ }
29824
29825 mux_init(ops);
29826
29827diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29828index b2b9443..be58856 100644
29829--- a/arch/x86/oprofile/op_model_amd.c
29830+++ b/arch/x86/oprofile/op_model_amd.c
29831@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29832 num_counters = AMD64_NUM_COUNTERS;
29833 }
29834
29835- op_amd_spec.num_counters = num_counters;
29836- op_amd_spec.num_controls = num_counters;
29837- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29838+ pax_open_kernel();
29839+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29840+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29841+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29842+ pax_close_kernel();
29843
29844 return 0;
29845 }
29846diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29847index d90528e..0127e2b 100644
29848--- a/arch/x86/oprofile/op_model_ppro.c
29849+++ b/arch/x86/oprofile/op_model_ppro.c
29850@@ -19,6 +19,7 @@
29851 #include <asm/msr.h>
29852 #include <asm/apic.h>
29853 #include <asm/nmi.h>
29854+#include <asm/pgtable.h>
29855
29856 #include "op_x86_model.h"
29857 #include "op_counter.h"
29858@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29859
29860 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29861
29862- op_arch_perfmon_spec.num_counters = num_counters;
29863- op_arch_perfmon_spec.num_controls = num_counters;
29864+ pax_open_kernel();
29865+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
29866+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
29867+ pax_close_kernel();
29868 }
29869
29870 static int arch_perfmon_init(struct oprofile_operations *ignore)
29871diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
29872index 71e8a67..6a313bb 100644
29873--- a/arch/x86/oprofile/op_x86_model.h
29874+++ b/arch/x86/oprofile/op_x86_model.h
29875@@ -52,7 +52,7 @@ struct op_x86_model_spec {
29876 void (*switch_ctrl)(struct op_x86_model_spec const *model,
29877 struct op_msrs const * const msrs);
29878 #endif
29879-};
29880+} __do_const;
29881
29882 struct op_counter_config;
29883
29884diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29885index e9e6ed5..e47ae67 100644
29886--- a/arch/x86/pci/amd_bus.c
29887+++ b/arch/x86/pci/amd_bus.c
29888@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29889 return NOTIFY_OK;
29890 }
29891
29892-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29893+static struct notifier_block amd_cpu_notifier = {
29894 .notifier_call = amd_cpu_notify,
29895 };
29896
29897diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
29898index 372e9b8..e775a6c 100644
29899--- a/arch/x86/pci/irq.c
29900+++ b/arch/x86/pci/irq.c
29901@@ -50,7 +50,7 @@ struct irq_router {
29902 struct irq_router_handler {
29903 u16 vendor;
29904 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
29905-};
29906+} __do_const;
29907
29908 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
29909 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
29910@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
29911 return 0;
29912 }
29913
29914-static __initdata struct irq_router_handler pirq_routers[] = {
29915+static __initconst const struct irq_router_handler pirq_routers[] = {
29916 { PCI_VENDOR_ID_INTEL, intel_router_probe },
29917 { PCI_VENDOR_ID_AL, ali_router_probe },
29918 { PCI_VENDOR_ID_ITE, ite_router_probe },
29919@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
29920 static void __init pirq_find_router(struct irq_router *r)
29921 {
29922 struct irq_routing_table *rt = pirq_table;
29923- struct irq_router_handler *h;
29924+ const struct irq_router_handler *h;
29925
29926 #ifdef CONFIG_PCI_BIOS
29927 if (!rt->signature) {
29928@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
29929 return 0;
29930 }
29931
29932-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
29933+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
29934 {
29935 .callback = fix_broken_hp_bios_irq9,
29936 .ident = "HP Pavilion N5400 Series Laptop",
29937diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29938index 6eb18c4..20d83de 100644
29939--- a/arch/x86/pci/mrst.c
29940+++ b/arch/x86/pci/mrst.c
29941@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29942 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29943 pci_mmcfg_late_init();
29944 pcibios_enable_irq = mrst_pci_irq_enable;
29945- pci_root_ops = pci_mrst_ops;
29946+ pax_open_kernel();
29947+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29948+ pax_close_kernel();
29949 pci_soc_mode = 1;
29950 /* Continue with standard init */
29951 return 1;
29952diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29953index c77b24a..c979855 100644
29954--- a/arch/x86/pci/pcbios.c
29955+++ b/arch/x86/pci/pcbios.c
29956@@ -79,7 +79,7 @@ union bios32 {
29957 static struct {
29958 unsigned long address;
29959 unsigned short segment;
29960-} bios32_indirect = { 0, __KERNEL_CS };
29961+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29962
29963 /*
29964 * Returns the entry point for the given service, NULL on error
29965@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29966 unsigned long length; /* %ecx */
29967 unsigned long entry; /* %edx */
29968 unsigned long flags;
29969+ struct desc_struct d, *gdt;
29970
29971 local_irq_save(flags);
29972- __asm__("lcall *(%%edi); cld"
29973+
29974+ gdt = get_cpu_gdt_table(smp_processor_id());
29975+
29976+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29977+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29978+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29979+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29980+
29981+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29982 : "=a" (return_code),
29983 "=b" (address),
29984 "=c" (length),
29985 "=d" (entry)
29986 : "0" (service),
29987 "1" (0),
29988- "D" (&bios32_indirect));
29989+ "D" (&bios32_indirect),
29990+ "r"(__PCIBIOS_DS)
29991+ : "memory");
29992+
29993+ pax_open_kernel();
29994+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29995+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29996+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29997+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29998+ pax_close_kernel();
29999+
30000 local_irq_restore(flags);
30001
30002 switch (return_code) {
30003- case 0:
30004- return address + entry;
30005- case 0x80: /* Not present */
30006- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30007- return 0;
30008- default: /* Shouldn't happen */
30009- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30010- service, return_code);
30011+ case 0: {
30012+ int cpu;
30013+ unsigned char flags;
30014+
30015+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30016+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30017+ printk(KERN_WARNING "bios32_service: not valid\n");
30018 return 0;
30019+ }
30020+ address = address + PAGE_OFFSET;
30021+ length += 16UL; /* some BIOSs underreport this... */
30022+ flags = 4;
30023+ if (length >= 64*1024*1024) {
30024+ length >>= PAGE_SHIFT;
30025+ flags |= 8;
30026+ }
30027+
30028+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30029+ gdt = get_cpu_gdt_table(cpu);
30030+ pack_descriptor(&d, address, length, 0x9b, flags);
30031+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30032+ pack_descriptor(&d, address, length, 0x93, flags);
30033+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30034+ }
30035+ return entry;
30036+ }
30037+ case 0x80: /* Not present */
30038+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30039+ return 0;
30040+ default: /* Shouldn't happen */
30041+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30042+ service, return_code);
30043+ return 0;
30044 }
30045 }
30046
30047 static struct {
30048 unsigned long address;
30049 unsigned short segment;
30050-} pci_indirect = { 0, __KERNEL_CS };
30051+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30052
30053-static int pci_bios_present;
30054+static int pci_bios_present __read_only;
30055
30056 static int check_pcibios(void)
30057 {
30058@@ -131,11 +174,13 @@ static int check_pcibios(void)
30059 unsigned long flags, pcibios_entry;
30060
30061 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30062- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30063+ pci_indirect.address = pcibios_entry;
30064
30065 local_irq_save(flags);
30066- __asm__(
30067- "lcall *(%%edi); cld\n\t"
30068+ __asm__("movw %w6, %%ds\n\t"
30069+ "lcall *%%ss:(%%edi); cld\n\t"
30070+ "push %%ss\n\t"
30071+ "pop %%ds\n\t"
30072 "jc 1f\n\t"
30073 "xor %%ah, %%ah\n"
30074 "1:"
30075@@ -144,7 +189,8 @@ static int check_pcibios(void)
30076 "=b" (ebx),
30077 "=c" (ecx)
30078 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30079- "D" (&pci_indirect)
30080+ "D" (&pci_indirect),
30081+ "r" (__PCIBIOS_DS)
30082 : "memory");
30083 local_irq_restore(flags);
30084
30085@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30086
30087 switch (len) {
30088 case 1:
30089- __asm__("lcall *(%%esi); cld\n\t"
30090+ __asm__("movw %w6, %%ds\n\t"
30091+ "lcall *%%ss:(%%esi); cld\n\t"
30092+ "push %%ss\n\t"
30093+ "pop %%ds\n\t"
30094 "jc 1f\n\t"
30095 "xor %%ah, %%ah\n"
30096 "1:"
30097@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30098 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30099 "b" (bx),
30100 "D" ((long)reg),
30101- "S" (&pci_indirect));
30102+ "S" (&pci_indirect),
30103+ "r" (__PCIBIOS_DS));
30104 /*
30105 * Zero-extend the result beyond 8 bits, do not trust the
30106 * BIOS having done it:
30107@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30108 *value &= 0xff;
30109 break;
30110 case 2:
30111- __asm__("lcall *(%%esi); cld\n\t"
30112+ __asm__("movw %w6, %%ds\n\t"
30113+ "lcall *%%ss:(%%esi); cld\n\t"
30114+ "push %%ss\n\t"
30115+ "pop %%ds\n\t"
30116 "jc 1f\n\t"
30117 "xor %%ah, %%ah\n"
30118 "1:"
30119@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30120 : "1" (PCIBIOS_READ_CONFIG_WORD),
30121 "b" (bx),
30122 "D" ((long)reg),
30123- "S" (&pci_indirect));
30124+ "S" (&pci_indirect),
30125+ "r" (__PCIBIOS_DS));
30126 /*
30127 * Zero-extend the result beyond 16 bits, do not trust the
30128 * BIOS having done it:
30129@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30130 *value &= 0xffff;
30131 break;
30132 case 4:
30133- __asm__("lcall *(%%esi); cld\n\t"
30134+ __asm__("movw %w6, %%ds\n\t"
30135+ "lcall *%%ss:(%%esi); cld\n\t"
30136+ "push %%ss\n\t"
30137+ "pop %%ds\n\t"
30138 "jc 1f\n\t"
30139 "xor %%ah, %%ah\n"
30140 "1:"
30141@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30142 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30143 "b" (bx),
30144 "D" ((long)reg),
30145- "S" (&pci_indirect));
30146+ "S" (&pci_indirect),
30147+ "r" (__PCIBIOS_DS));
30148 break;
30149 }
30150
30151@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30152
30153 switch (len) {
30154 case 1:
30155- __asm__("lcall *(%%esi); cld\n\t"
30156+ __asm__("movw %w6, %%ds\n\t"
30157+ "lcall *%%ss:(%%esi); cld\n\t"
30158+ "push %%ss\n\t"
30159+ "pop %%ds\n\t"
30160 "jc 1f\n\t"
30161 "xor %%ah, %%ah\n"
30162 "1:"
30163@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30164 "c" (value),
30165 "b" (bx),
30166 "D" ((long)reg),
30167- "S" (&pci_indirect));
30168+ "S" (&pci_indirect),
30169+ "r" (__PCIBIOS_DS));
30170 break;
30171 case 2:
30172- __asm__("lcall *(%%esi); cld\n\t"
30173+ __asm__("movw %w6, %%ds\n\t"
30174+ "lcall *%%ss:(%%esi); cld\n\t"
30175+ "push %%ss\n\t"
30176+ "pop %%ds\n\t"
30177 "jc 1f\n\t"
30178 "xor %%ah, %%ah\n"
30179 "1:"
30180@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30181 "c" (value),
30182 "b" (bx),
30183 "D" ((long)reg),
30184- "S" (&pci_indirect));
30185+ "S" (&pci_indirect),
30186+ "r" (__PCIBIOS_DS));
30187 break;
30188 case 4:
30189- __asm__("lcall *(%%esi); cld\n\t"
30190+ __asm__("movw %w6, %%ds\n\t"
30191+ "lcall *%%ss:(%%esi); cld\n\t"
30192+ "push %%ss\n\t"
30193+ "pop %%ds\n\t"
30194 "jc 1f\n\t"
30195 "xor %%ah, %%ah\n"
30196 "1:"
30197@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30198 "c" (value),
30199 "b" (bx),
30200 "D" ((long)reg),
30201- "S" (&pci_indirect));
30202+ "S" (&pci_indirect),
30203+ "r" (__PCIBIOS_DS));
30204 break;
30205 }
30206
30207@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30208
30209 DBG("PCI: Fetching IRQ routing table... ");
30210 __asm__("push %%es\n\t"
30211+ "movw %w8, %%ds\n\t"
30212 "push %%ds\n\t"
30213 "pop %%es\n\t"
30214- "lcall *(%%esi); cld\n\t"
30215+ "lcall *%%ss:(%%esi); cld\n\t"
30216 "pop %%es\n\t"
30217+ "push %%ss\n\t"
30218+ "pop %%ds\n"
30219 "jc 1f\n\t"
30220 "xor %%ah, %%ah\n"
30221 "1:"
30222@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30223 "1" (0),
30224 "D" ((long) &opt),
30225 "S" (&pci_indirect),
30226- "m" (opt)
30227+ "m" (opt),
30228+ "r" (__PCIBIOS_DS)
30229 : "memory");
30230 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30231 if (ret & 0xff00)
30232@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30233 {
30234 int ret;
30235
30236- __asm__("lcall *(%%esi); cld\n\t"
30237+ __asm__("movw %w5, %%ds\n\t"
30238+ "lcall *%%ss:(%%esi); cld\n\t"
30239+ "push %%ss\n\t"
30240+ "pop %%ds\n"
30241 "jc 1f\n\t"
30242 "xor %%ah, %%ah\n"
30243 "1:"
30244@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30245 : "0" (PCIBIOS_SET_PCI_HW_INT),
30246 "b" ((dev->bus->number << 8) | dev->devfn),
30247 "c" ((irq << 8) | (pin + 10)),
30248- "S" (&pci_indirect));
30249+ "S" (&pci_indirect),
30250+ "r" (__PCIBIOS_DS));
30251 return !(ret & 0xff00);
30252 }
30253 EXPORT_SYMBOL(pcibios_set_irq_routing);
30254diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30255index 40e4469..1ab536e 100644
30256--- a/arch/x86/platform/efi/efi_32.c
30257+++ b/arch/x86/platform/efi/efi_32.c
30258@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30259 {
30260 struct desc_ptr gdt_descr;
30261
30262+#ifdef CONFIG_PAX_KERNEXEC
30263+ struct desc_struct d;
30264+#endif
30265+
30266 local_irq_save(efi_rt_eflags);
30267
30268 load_cr3(initial_page_table);
30269 __flush_tlb_all();
30270
30271+#ifdef CONFIG_PAX_KERNEXEC
30272+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30273+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30274+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30275+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30276+#endif
30277+
30278 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30279 gdt_descr.size = GDT_SIZE - 1;
30280 load_gdt(&gdt_descr);
30281@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30282 {
30283 struct desc_ptr gdt_descr;
30284
30285+#ifdef CONFIG_PAX_KERNEXEC
30286+ struct desc_struct d;
30287+
30288+ memset(&d, 0, sizeof d);
30289+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30290+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30291+#endif
30292+
30293 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30294 gdt_descr.size = GDT_SIZE - 1;
30295 load_gdt(&gdt_descr);
30296diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30297index fbe66e6..eae5e38 100644
30298--- a/arch/x86/platform/efi/efi_stub_32.S
30299+++ b/arch/x86/platform/efi/efi_stub_32.S
30300@@ -6,7 +6,9 @@
30301 */
30302
30303 #include <linux/linkage.h>
30304+#include <linux/init.h>
30305 #include <asm/page_types.h>
30306+#include <asm/segment.h>
30307
30308 /*
30309 * efi_call_phys(void *, ...) is a function with variable parameters.
30310@@ -20,7 +22,7 @@
30311 * service functions will comply with gcc calling convention, too.
30312 */
30313
30314-.text
30315+__INIT
30316 ENTRY(efi_call_phys)
30317 /*
30318 * 0. The function can only be called in Linux kernel. So CS has been
30319@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30320 * The mapping of lower virtual memory has been created in prelog and
30321 * epilog.
30322 */
30323- movl $1f, %edx
30324- subl $__PAGE_OFFSET, %edx
30325- jmp *%edx
30326+#ifdef CONFIG_PAX_KERNEXEC
30327+ movl $(__KERNEXEC_EFI_DS), %edx
30328+ mov %edx, %ds
30329+ mov %edx, %es
30330+ mov %edx, %ss
30331+ addl $2f,(1f)
30332+ ljmp *(1f)
30333+
30334+__INITDATA
30335+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30336+.previous
30337+
30338+2:
30339+ subl $2b,(1b)
30340+#else
30341+ jmp 1f-__PAGE_OFFSET
30342 1:
30343+#endif
30344
30345 /*
30346 * 2. Now on the top of stack is the return
30347@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30348 * parameter 2, ..., param n. To make things easy, we save the return
30349 * address of efi_call_phys in a global variable.
30350 */
30351- popl %edx
30352- movl %edx, saved_return_addr
30353- /* get the function pointer into ECX*/
30354- popl %ecx
30355- movl %ecx, efi_rt_function_ptr
30356- movl $2f, %edx
30357- subl $__PAGE_OFFSET, %edx
30358- pushl %edx
30359+ popl (saved_return_addr)
30360+ popl (efi_rt_function_ptr)
30361
30362 /*
30363 * 3. Clear PG bit in %CR0.
30364@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30365 /*
30366 * 5. Call the physical function.
30367 */
30368- jmp *%ecx
30369+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30370
30371-2:
30372 /*
30373 * 6. After EFI runtime service returns, control will return to
30374 * following instruction. We'd better readjust stack pointer first.
30375@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30376 movl %cr0, %edx
30377 orl $0x80000000, %edx
30378 movl %edx, %cr0
30379- jmp 1f
30380-1:
30381+
30382 /*
30383 * 8. Now restore the virtual mode from flat mode by
30384 * adding EIP with PAGE_OFFSET.
30385 */
30386- movl $1f, %edx
30387- jmp *%edx
30388+#ifdef CONFIG_PAX_KERNEXEC
30389+ movl $(__KERNEL_DS), %edx
30390+ mov %edx, %ds
30391+ mov %edx, %es
30392+ mov %edx, %ss
30393+ ljmp $(__KERNEL_CS),$1f
30394+#else
30395+ jmp 1f+__PAGE_OFFSET
30396+#endif
30397 1:
30398
30399 /*
30400 * 9. Balance the stack. And because EAX contain the return value,
30401 * we'd better not clobber it.
30402 */
30403- leal efi_rt_function_ptr, %edx
30404- movl (%edx), %ecx
30405- pushl %ecx
30406+ pushl (efi_rt_function_ptr)
30407
30408 /*
30409- * 10. Push the saved return address onto the stack and return.
30410+ * 10. Return to the saved return address.
30411 */
30412- leal saved_return_addr, %edx
30413- movl (%edx), %ecx
30414- pushl %ecx
30415- ret
30416+ jmpl *(saved_return_addr)
30417 ENDPROC(efi_call_phys)
30418 .previous
30419
30420-.data
30421+__INITDATA
30422 saved_return_addr:
30423 .long 0
30424 efi_rt_function_ptr:
30425diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30426index 4c07cca..2c8427d 100644
30427--- a/arch/x86/platform/efi/efi_stub_64.S
30428+++ b/arch/x86/platform/efi/efi_stub_64.S
30429@@ -7,6 +7,7 @@
30430 */
30431
30432 #include <linux/linkage.h>
30433+#include <asm/alternative-asm.h>
30434
30435 #define SAVE_XMM \
30436 mov %rsp, %rax; \
30437@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30438 call *%rdi
30439 addq $32, %rsp
30440 RESTORE_XMM
30441+ pax_force_retaddr 0, 1
30442 ret
30443 ENDPROC(efi_call0)
30444
30445@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30446 call *%rdi
30447 addq $32, %rsp
30448 RESTORE_XMM
30449+ pax_force_retaddr 0, 1
30450 ret
30451 ENDPROC(efi_call1)
30452
30453@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30454 call *%rdi
30455 addq $32, %rsp
30456 RESTORE_XMM
30457+ pax_force_retaddr 0, 1
30458 ret
30459 ENDPROC(efi_call2)
30460
30461@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30462 call *%rdi
30463 addq $32, %rsp
30464 RESTORE_XMM
30465+ pax_force_retaddr 0, 1
30466 ret
30467 ENDPROC(efi_call3)
30468
30469@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30470 call *%rdi
30471 addq $32, %rsp
30472 RESTORE_XMM
30473+ pax_force_retaddr 0, 1
30474 ret
30475 ENDPROC(efi_call4)
30476
30477@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30478 call *%rdi
30479 addq $48, %rsp
30480 RESTORE_XMM
30481+ pax_force_retaddr 0, 1
30482 ret
30483 ENDPROC(efi_call5)
30484
30485@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30486 call *%rdi
30487 addq $48, %rsp
30488 RESTORE_XMM
30489+ pax_force_retaddr 0, 1
30490 ret
30491 ENDPROC(efi_call6)
30492diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30493index e31bcd8..f12dc46 100644
30494--- a/arch/x86/platform/mrst/mrst.c
30495+++ b/arch/x86/platform/mrst/mrst.c
30496@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30497 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30498 int sfi_mrtc_num;
30499
30500-static void mrst_power_off(void)
30501+static __noreturn void mrst_power_off(void)
30502 {
30503+ BUG();
30504 }
30505
30506-static void mrst_reboot(void)
30507+static __noreturn void mrst_reboot(void)
30508 {
30509 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30510+ BUG();
30511 }
30512
30513 /* parse all the mtimer info to a static mtimer array */
30514diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30515index d6ee929..3637cb5 100644
30516--- a/arch/x86/platform/olpc/olpc_dt.c
30517+++ b/arch/x86/platform/olpc/olpc_dt.c
30518@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30519 return res;
30520 }
30521
30522-static struct of_pdt_ops prom_olpc_ops __initdata = {
30523+static struct of_pdt_ops prom_olpc_ops __initconst = {
30524 .nextprop = olpc_dt_nextprop,
30525 .getproplen = olpc_dt_getproplen,
30526 .getproperty = olpc_dt_getproperty,
30527diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30528index 3c68768..07e82b8 100644
30529--- a/arch/x86/power/cpu.c
30530+++ b/arch/x86/power/cpu.c
30531@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30532 static void fix_processor_context(void)
30533 {
30534 int cpu = smp_processor_id();
30535- struct tss_struct *t = &per_cpu(init_tss, cpu);
30536+ struct tss_struct *t = init_tss + cpu;
30537
30538 set_tss_desc(cpu, t); /*
30539 * This just modifies memory; should not be
30540@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30541 */
30542
30543 #ifdef CONFIG_X86_64
30544- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30545-
30546 syscall_init(); /* This sets MSR_*STAR and related */
30547 #endif
30548 load_TR_desc(); /* This does ltr */
30549diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30550index cbca565..bae7133 100644
30551--- a/arch/x86/realmode/init.c
30552+++ b/arch/x86/realmode/init.c
30553@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30554 __va(real_mode_header->trampoline_header);
30555
30556 #ifdef CONFIG_X86_32
30557- trampoline_header->start = __pa(startup_32_smp);
30558+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30559+
30560+#ifdef CONFIG_PAX_KERNEXEC
30561+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30562+#endif
30563+
30564+ trampoline_header->boot_cs = __BOOT_CS;
30565 trampoline_header->gdt_limit = __BOOT_DS + 7;
30566 trampoline_header->gdt_base = __pa(boot_gdt);
30567 #else
30568diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30569index 8869287..d577672 100644
30570--- a/arch/x86/realmode/rm/Makefile
30571+++ b/arch/x86/realmode/rm/Makefile
30572@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30573 $(call cc-option, -fno-unit-at-a-time)) \
30574 $(call cc-option, -fno-stack-protector) \
30575 $(call cc-option, -mpreferred-stack-boundary=2)
30576+ifdef CONSTIFY_PLUGIN
30577+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30578+endif
30579 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30580 GCOV_PROFILE := n
30581diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30582index a28221d..93c40f1 100644
30583--- a/arch/x86/realmode/rm/header.S
30584+++ b/arch/x86/realmode/rm/header.S
30585@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30586 #endif
30587 /* APM/BIOS reboot */
30588 .long pa_machine_real_restart_asm
30589-#ifdef CONFIG_X86_64
30590+#ifdef CONFIG_X86_32
30591+ .long __KERNEL_CS
30592+#else
30593 .long __KERNEL32_CS
30594 #endif
30595 END(real_mode_header)
30596diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30597index c1b2791..f9e31c7 100644
30598--- a/arch/x86/realmode/rm/trampoline_32.S
30599+++ b/arch/x86/realmode/rm/trampoline_32.S
30600@@ -25,6 +25,12 @@
30601 #include <asm/page_types.h>
30602 #include "realmode.h"
30603
30604+#ifdef CONFIG_PAX_KERNEXEC
30605+#define ta(X) (X)
30606+#else
30607+#define ta(X) (pa_ ## X)
30608+#endif
30609+
30610 .text
30611 .code16
30612
30613@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30614
30615 cli # We should be safe anyway
30616
30617- movl tr_start, %eax # where we need to go
30618-
30619 movl $0xA5A5A5A5, trampoline_status
30620 # write marker for master knows we're running
30621
30622@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30623 movw $1, %dx # protected mode (PE) bit
30624 lmsw %dx # into protected mode
30625
30626- ljmpl $__BOOT_CS, $pa_startup_32
30627+ ljmpl *(trampoline_header)
30628
30629 .section ".text32","ax"
30630 .code32
30631@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30632 .balign 8
30633 GLOBAL(trampoline_header)
30634 tr_start: .space 4
30635- tr_gdt_pad: .space 2
30636+ tr_boot_cs: .space 2
30637 tr_gdt: .space 6
30638 END(trampoline_header)
30639
30640diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30641index bb360dc..3e5945f 100644
30642--- a/arch/x86/realmode/rm/trampoline_64.S
30643+++ b/arch/x86/realmode/rm/trampoline_64.S
30644@@ -107,7 +107,7 @@ ENTRY(startup_32)
30645 wrmsr
30646
30647 # Enable paging and in turn activate Long Mode
30648- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30649+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30650 movl %eax, %cr0
30651
30652 /*
30653diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30654index 79d67bd..c7e1b90 100644
30655--- a/arch/x86/tools/relocs.c
30656+++ b/arch/x86/tools/relocs.c
30657@@ -12,10 +12,13 @@
30658 #include <regex.h>
30659 #include <tools/le_byteshift.h>
30660
30661+#include "../../../include/generated/autoconf.h"
30662+
30663 static void die(char *fmt, ...);
30664
30665 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30666 static Elf32_Ehdr ehdr;
30667+static Elf32_Phdr *phdr;
30668 static unsigned long reloc_count, reloc_idx;
30669 static unsigned long *relocs;
30670 static unsigned long reloc16_count, reloc16_idx;
30671@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30672 }
30673 }
30674
30675+static void read_phdrs(FILE *fp)
30676+{
30677+ unsigned int i;
30678+
30679+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30680+ if (!phdr) {
30681+ die("Unable to allocate %d program headers\n",
30682+ ehdr.e_phnum);
30683+ }
30684+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30685+ die("Seek to %d failed: %s\n",
30686+ ehdr.e_phoff, strerror(errno));
30687+ }
30688+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30689+ die("Cannot read ELF program headers: %s\n",
30690+ strerror(errno));
30691+ }
30692+ for(i = 0; i < ehdr.e_phnum; i++) {
30693+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30694+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30695+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30696+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30697+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30698+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30699+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30700+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30701+ }
30702+
30703+}
30704+
30705 static void read_shdrs(FILE *fp)
30706 {
30707- int i;
30708+ unsigned int i;
30709 Elf32_Shdr shdr;
30710
30711 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30712@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30713
30714 static void read_strtabs(FILE *fp)
30715 {
30716- int i;
30717+ unsigned int i;
30718 for (i = 0; i < ehdr.e_shnum; i++) {
30719 struct section *sec = &secs[i];
30720 if (sec->shdr.sh_type != SHT_STRTAB) {
30721@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30722
30723 static void read_symtabs(FILE *fp)
30724 {
30725- int i,j;
30726+ unsigned int i,j;
30727 for (i = 0; i < ehdr.e_shnum; i++) {
30728 struct section *sec = &secs[i];
30729 if (sec->shdr.sh_type != SHT_SYMTAB) {
30730@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30731 }
30732
30733
30734-static void read_relocs(FILE *fp)
30735+static void read_relocs(FILE *fp, int use_real_mode)
30736 {
30737- int i,j;
30738+ unsigned int i,j;
30739+ uint32_t base;
30740+
30741 for (i = 0; i < ehdr.e_shnum; i++) {
30742 struct section *sec = &secs[i];
30743 if (sec->shdr.sh_type != SHT_REL) {
30744@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30745 die("Cannot read symbol table: %s\n",
30746 strerror(errno));
30747 }
30748+ base = 0;
30749+
30750+#ifdef CONFIG_X86_32
30751+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30752+ if (phdr[j].p_type != PT_LOAD )
30753+ continue;
30754+ 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)
30755+ continue;
30756+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30757+ break;
30758+ }
30759+#endif
30760+
30761 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30762 Elf32_Rel *rel = &sec->reltab[j];
30763- rel->r_offset = elf32_to_cpu(rel->r_offset);
30764+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30765 rel->r_info = elf32_to_cpu(rel->r_info);
30766 }
30767 }
30768@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30769
30770 static void print_absolute_symbols(void)
30771 {
30772- int i;
30773+ unsigned int i;
30774 printf("Absolute symbols\n");
30775 printf(" Num: Value Size Type Bind Visibility Name\n");
30776 for (i = 0; i < ehdr.e_shnum; i++) {
30777 struct section *sec = &secs[i];
30778 char *sym_strtab;
30779- int j;
30780+ unsigned int j;
30781
30782 if (sec->shdr.sh_type != SHT_SYMTAB) {
30783 continue;
30784@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30785
30786 static void print_absolute_relocs(void)
30787 {
30788- int i, printed = 0;
30789+ unsigned int i, printed = 0;
30790
30791 for (i = 0; i < ehdr.e_shnum; i++) {
30792 struct section *sec = &secs[i];
30793 struct section *sec_applies, *sec_symtab;
30794 char *sym_strtab;
30795 Elf32_Sym *sh_symtab;
30796- int j;
30797+ unsigned int j;
30798 if (sec->shdr.sh_type != SHT_REL) {
30799 continue;
30800 }
30801@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30802 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30803 int use_real_mode)
30804 {
30805- int i;
30806+ unsigned int i;
30807 /* Walk through the relocations */
30808 for (i = 0; i < ehdr.e_shnum; i++) {
30809 char *sym_strtab;
30810 Elf32_Sym *sh_symtab;
30811 struct section *sec_applies, *sec_symtab;
30812- int j;
30813+ unsigned int j;
30814 struct section *sec = &secs[i];
30815
30816 if (sec->shdr.sh_type != SHT_REL) {
30817@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30818 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30819 r_type = ELF32_R_TYPE(rel->r_info);
30820
30821+ if (!use_real_mode) {
30822+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30823+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30824+ continue;
30825+
30826+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30827+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30828+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30829+ continue;
30830+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30831+ continue;
30832+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30833+ continue;
30834+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30835+ continue;
30836+#endif
30837+ }
30838+
30839 shn_abs = sym->st_shndx == SHN_ABS;
30840
30841 switch (r_type) {
30842@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30843
30844 static void emit_relocs(int as_text, int use_real_mode)
30845 {
30846- int i;
30847+ unsigned int i;
30848 /* Count how many relocations I have and allocate space for them. */
30849 reloc_count = 0;
30850 walk_relocs(count_reloc, use_real_mode);
30851@@ -808,10 +874,11 @@ int main(int argc, char **argv)
30852 fname, strerror(errno));
30853 }
30854 read_ehdr(fp);
30855+ read_phdrs(fp);
30856 read_shdrs(fp);
30857 read_strtabs(fp);
30858 read_symtabs(fp);
30859- read_relocs(fp);
30860+ read_relocs(fp, use_real_mode);
30861 if (show_absolute_syms) {
30862 print_absolute_symbols();
30863 goto out;
30864diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30865index fd14be1..e3c79c0 100644
30866--- a/arch/x86/vdso/Makefile
30867+++ b/arch/x86/vdso/Makefile
30868@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30869 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30870 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30871
30872-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30873+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30874 GCOV_PROFILE := n
30875
30876 #
30877diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30878index 0faad64..39ef157 100644
30879--- a/arch/x86/vdso/vdso32-setup.c
30880+++ b/arch/x86/vdso/vdso32-setup.c
30881@@ -25,6 +25,7 @@
30882 #include <asm/tlbflush.h>
30883 #include <asm/vdso.h>
30884 #include <asm/proto.h>
30885+#include <asm/mman.h>
30886
30887 enum {
30888 VDSO_DISABLED = 0,
30889@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30890 void enable_sep_cpu(void)
30891 {
30892 int cpu = get_cpu();
30893- struct tss_struct *tss = &per_cpu(init_tss, cpu);
30894+ struct tss_struct *tss = init_tss + cpu;
30895
30896 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30897 put_cpu();
30898@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30899 gate_vma.vm_start = FIXADDR_USER_START;
30900 gate_vma.vm_end = FIXADDR_USER_END;
30901 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30902- gate_vma.vm_page_prot = __P101;
30903+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30904
30905 return 0;
30906 }
30907@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30908 if (compat)
30909 addr = VDSO_HIGH_BASE;
30910 else {
30911- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30912+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30913 if (IS_ERR_VALUE(addr)) {
30914 ret = addr;
30915 goto up_fail;
30916 }
30917 }
30918
30919- current->mm->context.vdso = (void *)addr;
30920+ current->mm->context.vdso = addr;
30921
30922 if (compat_uses_vma || !compat) {
30923 /*
30924@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30925 }
30926
30927 current_thread_info()->sysenter_return =
30928- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30929+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30930
30931 up_fail:
30932 if (ret)
30933- current->mm->context.vdso = NULL;
30934+ current->mm->context.vdso = 0;
30935
30936 up_write(&mm->mmap_sem);
30937
30938@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30939
30940 const char *arch_vma_name(struct vm_area_struct *vma)
30941 {
30942- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30943+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30944 return "[vdso]";
30945+
30946+#ifdef CONFIG_PAX_SEGMEXEC
30947+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30948+ return "[vdso]";
30949+#endif
30950+
30951 return NULL;
30952 }
30953
30954@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30955 * Check to see if the corresponding task was created in compat vdso
30956 * mode.
30957 */
30958- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30959+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30960 return &gate_vma;
30961 return NULL;
30962 }
30963diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30964index 431e875..cbb23f3 100644
30965--- a/arch/x86/vdso/vma.c
30966+++ b/arch/x86/vdso/vma.c
30967@@ -16,8 +16,6 @@
30968 #include <asm/vdso.h>
30969 #include <asm/page.h>
30970
30971-unsigned int __read_mostly vdso_enabled = 1;
30972-
30973 extern char vdso_start[], vdso_end[];
30974 extern unsigned short vdso_sync_cpuid;
30975
30976@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30977 * unaligned here as a result of stack start randomization.
30978 */
30979 addr = PAGE_ALIGN(addr);
30980- addr = align_vdso_addr(addr);
30981
30982 return addr;
30983 }
30984@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30985 unsigned size)
30986 {
30987 struct mm_struct *mm = current->mm;
30988- unsigned long addr;
30989+ unsigned long addr = 0;
30990 int ret;
30991
30992- if (!vdso_enabled)
30993- return 0;
30994-
30995 down_write(&mm->mmap_sem);
30996+
30997+#ifdef CONFIG_PAX_RANDMMAP
30998+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30999+#endif
31000+
31001 addr = vdso_addr(mm->start_stack, size);
31002+ addr = align_vdso_addr(addr);
31003 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31004 if (IS_ERR_VALUE(addr)) {
31005 ret = addr;
31006 goto up_fail;
31007 }
31008
31009- current->mm->context.vdso = (void *)addr;
31010+ mm->context.vdso = addr;
31011
31012 ret = install_special_mapping(mm, addr, size,
31013 VM_READ|VM_EXEC|
31014 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31015 pages);
31016- if (ret) {
31017- current->mm->context.vdso = NULL;
31018- goto up_fail;
31019- }
31020+ if (ret)
31021+ mm->context.vdso = 0;
31022
31023 up_fail:
31024 up_write(&mm->mmap_sem);
31025@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31026 vdsox32_size);
31027 }
31028 #endif
31029-
31030-static __init int vdso_setup(char *s)
31031-{
31032- vdso_enabled = simple_strtoul(s, NULL, 0);
31033- return 0;
31034-}
31035-__setup("vdso=", vdso_setup);
31036diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31037index 2262003..f229ced 100644
31038--- a/arch/x86/xen/enlighten.c
31039+++ b/arch/x86/xen/enlighten.c
31040@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31041
31042 struct shared_info xen_dummy_shared_info;
31043
31044-void *xen_initial_gdt;
31045-
31046 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31047 __read_mostly int xen_have_vector_callback;
31048 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31049@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31050 {
31051 unsigned long va = dtr->address;
31052 unsigned int size = dtr->size + 1;
31053- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31054- unsigned long frames[pages];
31055+ unsigned long frames[65536 / PAGE_SIZE];
31056 int f;
31057
31058 /*
31059@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31060 {
31061 unsigned long va = dtr->address;
31062 unsigned int size = dtr->size + 1;
31063- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31064- unsigned long frames[pages];
31065+ unsigned long frames[65536 / PAGE_SIZE];
31066 int f;
31067
31068 /*
31069@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31070 return 0;
31071 }
31072
31073-static void set_xen_basic_apic_ops(void)
31074+static void __init set_xen_basic_apic_ops(void)
31075 {
31076 apic->read = xen_apic_read;
31077 apic->write = xen_apic_write;
31078@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31079 #endif
31080 };
31081
31082-static void xen_reboot(int reason)
31083+static __noreturn void xen_reboot(int reason)
31084 {
31085 struct sched_shutdown r = { .reason = reason };
31086
31087- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31088- BUG();
31089+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31090+ BUG();
31091 }
31092
31093-static void xen_restart(char *msg)
31094+static __noreturn void xen_restart(char *msg)
31095 {
31096 xen_reboot(SHUTDOWN_reboot);
31097 }
31098
31099-static void xen_emergency_restart(void)
31100+static __noreturn void xen_emergency_restart(void)
31101 {
31102 xen_reboot(SHUTDOWN_reboot);
31103 }
31104
31105-static void xen_machine_halt(void)
31106+static __noreturn void xen_machine_halt(void)
31107 {
31108 xen_reboot(SHUTDOWN_poweroff);
31109 }
31110
31111-static void xen_machine_power_off(void)
31112+static __noreturn void xen_machine_power_off(void)
31113 {
31114 if (pm_power_off)
31115 pm_power_off();
31116@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
31117 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31118
31119 /* Work out if we support NX */
31120- x86_configure_nx();
31121+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31122+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31123+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31124+ unsigned l, h;
31125+
31126+ __supported_pte_mask |= _PAGE_NX;
31127+ rdmsr(MSR_EFER, l, h);
31128+ l |= EFER_NX;
31129+ wrmsr(MSR_EFER, l, h);
31130+ }
31131+#endif
31132
31133 xen_setup_features();
31134
31135@@ -1399,14 +1405,7 @@ asmlinkage void __init xen_start_kernel(void)
31136 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
31137 }
31138
31139- machine_ops = xen_machine_ops;
31140-
31141- /*
31142- * The only reliable way to retain the initial address of the
31143- * percpu gdt_page is to remember it here, so we can go and
31144- * mark it RW later, when the initial percpu area is freed.
31145- */
31146- xen_initial_gdt = &per_cpu(gdt_page, 0);
31147+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
31148
31149 xen_smp_init();
31150
31151@@ -1598,7 +1597,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31152 return NOTIFY_OK;
31153 }
31154
31155-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31156+static struct notifier_block xen_hvm_cpu_notifier = {
31157 .notifier_call = xen_hvm_cpu_notify,
31158 };
31159
31160diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31161index 01de35c..0bda07b 100644
31162--- a/arch/x86/xen/mmu.c
31163+++ b/arch/x86/xen/mmu.c
31164@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31165 /* L3_k[510] -> level2_kernel_pgt
31166 * L3_i[511] -> level2_fixmap_pgt */
31167 convert_pfn_mfn(level3_kernel_pgt);
31168+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31169+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31170+ convert_pfn_mfn(level3_vmemmap_pgt);
31171
31172 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31173 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31174@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31175 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31176 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31177 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31178+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31179+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31180+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31181 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31182 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31183+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31184 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31185 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31186
31187@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
31188 pv_mmu_ops.set_pud = xen_set_pud;
31189 #if PAGETABLE_LEVELS == 4
31190 pv_mmu_ops.set_pgd = xen_set_pgd;
31191+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31192 #endif
31193
31194 /* This will work as long as patching hasn't happened yet
31195@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31196 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31197 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31198 .set_pgd = xen_set_pgd_hyper,
31199+ .set_pgd_batched = xen_set_pgd_hyper,
31200
31201 .alloc_pud = xen_alloc_pmd_init,
31202 .release_pud = xen_release_pmd_init,
31203diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31204index 34bc4ce..c34aa24 100644
31205--- a/arch/x86/xen/smp.c
31206+++ b/arch/x86/xen/smp.c
31207@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31208 {
31209 BUG_ON(smp_processor_id() != 0);
31210 native_smp_prepare_boot_cpu();
31211-
31212- /* We've switched to the "real" per-cpu gdt, so make sure the
31213- old memory can be recycled */
31214- make_lowmem_page_readwrite(xen_initial_gdt);
31215-
31216 xen_filter_cpu_maps();
31217 xen_setup_vcpu_info_placement();
31218 }
31219@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31220 gdt = get_cpu_gdt_table(cpu);
31221
31222 ctxt->flags = VGCF_IN_KERNEL;
31223- ctxt->user_regs.ds = __USER_DS;
31224- ctxt->user_regs.es = __USER_DS;
31225+ ctxt->user_regs.ds = __KERNEL_DS;
31226+ ctxt->user_regs.es = __KERNEL_DS;
31227 ctxt->user_regs.ss = __KERNEL_DS;
31228 #ifdef CONFIG_X86_32
31229 ctxt->user_regs.fs = __KERNEL_PERCPU;
31230- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31231+ savesegment(gs, ctxt->user_regs.gs);
31232 #else
31233 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31234 #endif
31235@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31236 int rc;
31237
31238 per_cpu(current_task, cpu) = idle;
31239+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31240 #ifdef CONFIG_X86_32
31241 irq_ctx_init(cpu);
31242 #else
31243 clear_tsk_thread_flag(idle, TIF_FORK);
31244- per_cpu(kernel_stack, cpu) =
31245- (unsigned long)task_stack_page(idle) -
31246- KERNEL_STACK_OFFSET + THREAD_SIZE;
31247+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31248 #endif
31249 xen_setup_runstate_info(cpu);
31250 xen_setup_timer(cpu);
31251@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31252
31253 void __init xen_smp_init(void)
31254 {
31255- smp_ops = xen_smp_ops;
31256+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31257 xen_fill_possible_map();
31258 xen_init_spinlocks();
31259 }
31260diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31261index 33ca6e4..0ded929 100644
31262--- a/arch/x86/xen/xen-asm_32.S
31263+++ b/arch/x86/xen/xen-asm_32.S
31264@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31265 ESP_OFFSET=4 # bytes pushed onto stack
31266
31267 /*
31268- * Store vcpu_info pointer for easy access. Do it this way to
31269- * avoid having to reload %fs
31270+ * Store vcpu_info pointer for easy access.
31271 */
31272 #ifdef CONFIG_SMP
31273- GET_THREAD_INFO(%eax)
31274- movl %ss:TI_cpu(%eax), %eax
31275- movl %ss:__per_cpu_offset(,%eax,4), %eax
31276- mov %ss:xen_vcpu(%eax), %eax
31277+ push %fs
31278+ mov $(__KERNEL_PERCPU), %eax
31279+ mov %eax, %fs
31280+ mov PER_CPU_VAR(xen_vcpu), %eax
31281+ pop %fs
31282 #else
31283 movl %ss:xen_vcpu, %eax
31284 #endif
31285diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31286index 7faed58..ba4427c 100644
31287--- a/arch/x86/xen/xen-head.S
31288+++ b/arch/x86/xen/xen-head.S
31289@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31290 #ifdef CONFIG_X86_32
31291 mov %esi,xen_start_info
31292 mov $init_thread_union+THREAD_SIZE,%esp
31293+#ifdef CONFIG_SMP
31294+ movl $cpu_gdt_table,%edi
31295+ movl $__per_cpu_load,%eax
31296+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31297+ rorl $16,%eax
31298+ movb %al,__KERNEL_PERCPU + 4(%edi)
31299+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31300+ movl $__per_cpu_end - 1,%eax
31301+ subl $__per_cpu_start,%eax
31302+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31303+#endif
31304 #else
31305 mov %rsi,xen_start_info
31306 mov $init_thread_union+THREAD_SIZE,%rsp
31307diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31308index a95b417..b6dbd0b 100644
31309--- a/arch/x86/xen/xen-ops.h
31310+++ b/arch/x86/xen/xen-ops.h
31311@@ -10,8 +10,6 @@
31312 extern const char xen_hypervisor_callback[];
31313 extern const char xen_failsafe_callback[];
31314
31315-extern void *xen_initial_gdt;
31316-
31317 struct trap_info;
31318 void xen_copy_trap_info(struct trap_info *traps);
31319
31320diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31321index 525bd3d..ef888b1 100644
31322--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31323+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31324@@ -119,9 +119,9 @@
31325 ----------------------------------------------------------------------*/
31326
31327 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31328-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31329 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31330 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31331+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31332
31333 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31334 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31335diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31336index 2f33760..835e50a 100644
31337--- a/arch/xtensa/variants/fsf/include/variant/core.h
31338+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31339@@ -11,6 +11,7 @@
31340 #ifndef _XTENSA_CORE_H
31341 #define _XTENSA_CORE_H
31342
31343+#include <linux/const.h>
31344
31345 /****************************************************************************
31346 Parameters Useful for Any Code, USER or PRIVILEGED
31347@@ -112,9 +113,9 @@
31348 ----------------------------------------------------------------------*/
31349
31350 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31351-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31352 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31353 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31354+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31355
31356 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31357 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31358diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31359index af00795..2bb8105 100644
31360--- a/arch/xtensa/variants/s6000/include/variant/core.h
31361+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31362@@ -11,6 +11,7 @@
31363 #ifndef _XTENSA_CORE_CONFIGURATION_H
31364 #define _XTENSA_CORE_CONFIGURATION_H
31365
31366+#include <linux/const.h>
31367
31368 /****************************************************************************
31369 Parameters Useful for Any Code, USER or PRIVILEGED
31370@@ -118,9 +119,9 @@
31371 ----------------------------------------------------------------------*/
31372
31373 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31374-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31375 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31376 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31377+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31378
31379 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31380 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31381diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31382index 58916af..eb9dbcf6 100644
31383--- a/block/blk-iopoll.c
31384+++ b/block/blk-iopoll.c
31385@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31386 }
31387 EXPORT_SYMBOL(blk_iopoll_complete);
31388
31389-static void blk_iopoll_softirq(struct softirq_action *h)
31390+static void blk_iopoll_softirq(void)
31391 {
31392 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31393 int rearm = 0, budget = blk_iopoll_budget;
31394@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31395 return NOTIFY_OK;
31396 }
31397
31398-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31399+static struct notifier_block blk_iopoll_cpu_notifier = {
31400 .notifier_call = blk_iopoll_cpu_notify,
31401 };
31402
31403diff --git a/block/blk-map.c b/block/blk-map.c
31404index 623e1cd..ca1e109 100644
31405--- a/block/blk-map.c
31406+++ b/block/blk-map.c
31407@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31408 if (!len || !kbuf)
31409 return -EINVAL;
31410
31411- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31412+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31413 if (do_copy)
31414 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31415 else
31416diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31417index 467c8de..f3628c5 100644
31418--- a/block/blk-softirq.c
31419+++ b/block/blk-softirq.c
31420@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31421 * Softirq action handler - move entries to local list and loop over them
31422 * while passing them to the queue registered handler.
31423 */
31424-static void blk_done_softirq(struct softirq_action *h)
31425+static void blk_done_softirq(void)
31426 {
31427 struct list_head *cpu_list, local_list;
31428
31429@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31430 return NOTIFY_OK;
31431 }
31432
31433-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31434+static struct notifier_block blk_cpu_notifier = {
31435 .notifier_call = blk_cpu_notify,
31436 };
31437
31438diff --git a/block/bsg.c b/block/bsg.c
31439index ff64ae3..593560c 100644
31440--- a/block/bsg.c
31441+++ b/block/bsg.c
31442@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31443 struct sg_io_v4 *hdr, struct bsg_device *bd,
31444 fmode_t has_write_perm)
31445 {
31446+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31447+ unsigned char *cmdptr;
31448+
31449 if (hdr->request_len > BLK_MAX_CDB) {
31450 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31451 if (!rq->cmd)
31452 return -ENOMEM;
31453- }
31454+ cmdptr = rq->cmd;
31455+ } else
31456+ cmdptr = tmpcmd;
31457
31458- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31459+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31460 hdr->request_len))
31461 return -EFAULT;
31462
31463+ if (cmdptr != rq->cmd)
31464+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31465+
31466 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31467 if (blk_verify_command(rq->cmd, has_write_perm))
31468 return -EPERM;
31469diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31470index 7c668c8..db3521c 100644
31471--- a/block/compat_ioctl.c
31472+++ b/block/compat_ioctl.c
31473@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31474 err |= __get_user(f->spec1, &uf->spec1);
31475 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31476 err |= __get_user(name, &uf->name);
31477- f->name = compat_ptr(name);
31478+ f->name = (void __force_kernel *)compat_ptr(name);
31479 if (err) {
31480 err = -EFAULT;
31481 goto out;
31482diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31483index b62fb88..bdab4c4 100644
31484--- a/block/partitions/efi.c
31485+++ b/block/partitions/efi.c
31486@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31487 if (!gpt)
31488 return NULL;
31489
31490+ if (!le32_to_cpu(gpt->num_partition_entries))
31491+ return NULL;
31492+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31493+ if (!pte)
31494+ return NULL;
31495+
31496 count = le32_to_cpu(gpt->num_partition_entries) *
31497 le32_to_cpu(gpt->sizeof_partition_entry);
31498- if (!count)
31499- return NULL;
31500- pte = kzalloc(count, GFP_KERNEL);
31501- if (!pte)
31502- return NULL;
31503-
31504 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31505 (u8 *) pte,
31506 count) < count) {
31507diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31508index 9a87daa..fb17486 100644
31509--- a/block/scsi_ioctl.c
31510+++ b/block/scsi_ioctl.c
31511@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31512 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31513 struct sg_io_hdr *hdr, fmode_t mode)
31514 {
31515- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31516+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31517+ unsigned char *cmdptr;
31518+
31519+ if (rq->cmd != rq->__cmd)
31520+ cmdptr = rq->cmd;
31521+ else
31522+ cmdptr = tmpcmd;
31523+
31524+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31525 return -EFAULT;
31526+
31527+ if (cmdptr != rq->cmd)
31528+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31529+
31530 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31531 return -EPERM;
31532
31533@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31534 int err;
31535 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31536 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31537+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31538+ unsigned char *cmdptr;
31539
31540 if (!sic)
31541 return -EINVAL;
31542@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31543 */
31544 err = -EFAULT;
31545 rq->cmd_len = cmdlen;
31546- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31547+
31548+ if (rq->cmd != rq->__cmd)
31549+ cmdptr = rq->cmd;
31550+ else
31551+ cmdptr = tmpcmd;
31552+
31553+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31554 goto error;
31555
31556+ if (rq->cmd != cmdptr)
31557+ memcpy(rq->cmd, cmdptr, cmdlen);
31558+
31559 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31560 goto error;
31561
31562diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31563index 7bdd61b..afec999 100644
31564--- a/crypto/cryptd.c
31565+++ b/crypto/cryptd.c
31566@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31567
31568 struct cryptd_blkcipher_request_ctx {
31569 crypto_completion_t complete;
31570-};
31571+} __no_const;
31572
31573 struct cryptd_hash_ctx {
31574 struct crypto_shash *child;
31575@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31576
31577 struct cryptd_aead_request_ctx {
31578 crypto_completion_t complete;
31579-};
31580+} __no_const;
31581
31582 static void cryptd_queue_worker(struct work_struct *work);
31583
31584diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
31585index f6d9baf..dfd511f 100644
31586--- a/crypto/crypto_user.c
31587+++ b/crypto/crypto_user.c
31588@@ -30,6 +30,8 @@
31589
31590 #include "internal.h"
31591
31592+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
31593+
31594 static DEFINE_MUTEX(crypto_cfg_mutex);
31595
31596 /* The crypto netlink socket */
31597@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
31598 struct crypto_dump_info info;
31599 int err;
31600
31601- if (!p->cru_driver_name)
31602+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31603+ return -EINVAL;
31604+
31605+ if (!p->cru_driver_name[0])
31606 return -EINVAL;
31607
31608 alg = crypto_alg_match(p, 1);
31609@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31610 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31611 LIST_HEAD(list);
31612
31613+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31614+ return -EINVAL;
31615+
31616 if (priority && !strlen(p->cru_driver_name))
31617 return -EINVAL;
31618
31619@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31620 struct crypto_alg *alg;
31621 struct crypto_user_alg *p = nlmsg_data(nlh);
31622
31623+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31624+ return -EINVAL;
31625+
31626 alg = crypto_alg_match(p, 1);
31627 if (!alg)
31628 return -ENOENT;
31629@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31630 struct crypto_user_alg *p = nlmsg_data(nlh);
31631 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31632
31633+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31634+ return -EINVAL;
31635+
31636 if (strlen(p->cru_driver_name))
31637 exact = 1;
31638
31639diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31640index f220d64..d359ad6 100644
31641--- a/drivers/acpi/apei/apei-internal.h
31642+++ b/drivers/acpi/apei/apei-internal.h
31643@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31644 struct apei_exec_ins_type {
31645 u32 flags;
31646 apei_exec_ins_func_t run;
31647-};
31648+} __do_const;
31649
31650 struct apei_exec_context {
31651 u32 ip;
31652diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31653index e6defd8..c26a225 100644
31654--- a/drivers/acpi/apei/cper.c
31655+++ b/drivers/acpi/apei/cper.c
31656@@ -38,12 +38,12 @@
31657 */
31658 u64 cper_next_record_id(void)
31659 {
31660- static atomic64_t seq;
31661+ static atomic64_unchecked_t seq;
31662
31663- if (!atomic64_read(&seq))
31664- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31665+ if (!atomic64_read_unchecked(&seq))
31666+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31667
31668- return atomic64_inc_return(&seq);
31669+ return atomic64_inc_return_unchecked(&seq);
31670 }
31671 EXPORT_SYMBOL_GPL(cper_next_record_id);
31672
31673diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31674index be60399..778b33e8 100644
31675--- a/drivers/acpi/bgrt.c
31676+++ b/drivers/acpi/bgrt.c
31677@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31678 return -ENODEV;
31679
31680 sysfs_bin_attr_init(&image_attr);
31681- image_attr.private = bgrt_image;
31682- image_attr.size = bgrt_image_size;
31683+ pax_open_kernel();
31684+ *(void **)&image_attr.private = bgrt_image;
31685+ *(size_t *)&image_attr.size = bgrt_image_size;
31686+ pax_close_kernel();
31687
31688 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31689 if (!bgrt_kobj)
31690diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31691index cb96296..b81293b 100644
31692--- a/drivers/acpi/blacklist.c
31693+++ b/drivers/acpi/blacklist.c
31694@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31695 u32 is_critical_error;
31696 };
31697
31698-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31699+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31700
31701 /*
31702 * POLICY: If *anything* doesn't work, put it on the blacklist.
31703@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31704 return 0;
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 .callback = dmi_disable_osi_vista,
31711 .ident = "Fujitsu Siemens",
31712diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31713index 7586544..636a2f0 100644
31714--- a/drivers/acpi/ec_sys.c
31715+++ b/drivers/acpi/ec_sys.c
31716@@ -12,6 +12,7 @@
31717 #include <linux/acpi.h>
31718 #include <linux/debugfs.h>
31719 #include <linux/module.h>
31720+#include <linux/uaccess.h>
31721 #include "internal.h"
31722
31723 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31724@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31725 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31726 */
31727 unsigned int size = EC_SPACE_SIZE;
31728- u8 *data = (u8 *) buf;
31729+ u8 data;
31730 loff_t init_off = *off;
31731 int err = 0;
31732
31733@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31734 size = count;
31735
31736 while (size) {
31737- err = ec_read(*off, &data[*off - init_off]);
31738+ err = ec_read(*off, &data);
31739 if (err)
31740 return err;
31741+ if (put_user(data, &buf[*off - init_off]))
31742+ return -EFAULT;
31743 *off += 1;
31744 size--;
31745 }
31746@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31747
31748 unsigned int size = count;
31749 loff_t init_off = *off;
31750- u8 *data = (u8 *) buf;
31751 int err = 0;
31752
31753 if (*off >= EC_SPACE_SIZE)
31754@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31755 }
31756
31757 while (size) {
31758- u8 byte_write = data[*off - init_off];
31759+ u8 byte_write;
31760+ if (get_user(byte_write, &buf[*off - init_off]))
31761+ return -EFAULT;
31762 err = ec_write(*off, byte_write);
31763 if (err)
31764 return err;
31765diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31766index e83311b..142b5cc 100644
31767--- a/drivers/acpi/processor_driver.c
31768+++ b/drivers/acpi/processor_driver.c
31769@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31770 return 0;
31771 #endif
31772
31773- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31774+ BUG_ON(pr->id >= nr_cpu_ids);
31775
31776 /*
31777 * Buggy BIOS check
31778diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31779index ed9a1cc..f4a354c 100644
31780--- a/drivers/acpi/processor_idle.c
31781+++ b/drivers/acpi/processor_idle.c
31782@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31783 {
31784 int i, count = CPUIDLE_DRIVER_STATE_START;
31785 struct acpi_processor_cx *cx;
31786- struct cpuidle_state *state;
31787+ cpuidle_state_no_const *state;
31788 struct cpuidle_driver *drv = &acpi_idle_driver;
31789
31790 if (!pr->flags.power_setup_done)
31791diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31792index ea61ca9..3fdd70d 100644
31793--- a/drivers/acpi/sysfs.c
31794+++ b/drivers/acpi/sysfs.c
31795@@ -420,11 +420,11 @@ static u32 num_counters;
31796 static struct attribute **all_attrs;
31797 static u32 acpi_gpe_count;
31798
31799-static struct attribute_group interrupt_stats_attr_group = {
31800+static attribute_group_no_const interrupt_stats_attr_group = {
31801 .name = "interrupts",
31802 };
31803
31804-static struct kobj_attribute *counter_attrs;
31805+static kobj_attribute_no_const *counter_attrs;
31806
31807 static void delete_gpe_attr_array(void)
31808 {
31809diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
31810index 6cd7805..07facb3 100644
31811--- a/drivers/ata/libahci.c
31812+++ b/drivers/ata/libahci.c
31813@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
31814 }
31815 EXPORT_SYMBOL_GPL(ahci_kick_engine);
31816
31817-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31818+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31819 struct ata_taskfile *tf, int is_cmd, u16 flags,
31820 unsigned long timeout_msec)
31821 {
31822diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31823index 46cd3f4..0871ad0 100644
31824--- a/drivers/ata/libata-core.c
31825+++ b/drivers/ata/libata-core.c
31826@@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31827 struct ata_port *ap;
31828 unsigned int tag;
31829
31830- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31831+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31832 ap = qc->ap;
31833
31834 qc->flags = 0;
31835@@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31836 struct ata_port *ap;
31837 struct ata_link *link;
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 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31842 ap = qc->ap;
31843 link = qc->dev->link;
31844@@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31845 return;
31846
31847 spin_lock(&lock);
31848+ pax_open_kernel();
31849
31850 for (cur = ops->inherits; cur; cur = cur->inherits) {
31851 void **inherit = (void **)cur;
31852@@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31853 if (IS_ERR(*pp))
31854 *pp = NULL;
31855
31856- ops->inherits = NULL;
31857+ *(struct ata_port_operations **)&ops->inherits = NULL;
31858
31859+ pax_close_kernel();
31860 spin_unlock(&lock);
31861 }
31862
31863diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31864index 405022d..fb70e53 100644
31865--- a/drivers/ata/pata_arasan_cf.c
31866+++ b/drivers/ata/pata_arasan_cf.c
31867@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31868 /* Handle platform specific quirks */
31869 if (pdata->quirk) {
31870 if (pdata->quirk & CF_BROKEN_PIO) {
31871- ap->ops->set_piomode = NULL;
31872+ pax_open_kernel();
31873+ *(void **)&ap->ops->set_piomode = NULL;
31874+ pax_close_kernel();
31875 ap->pio_mask = 0;
31876 }
31877 if (pdata->quirk & CF_BROKEN_MWDMA)
31878diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31879index f9b983a..887b9d8 100644
31880--- a/drivers/atm/adummy.c
31881+++ b/drivers/atm/adummy.c
31882@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31883 vcc->pop(vcc, skb);
31884 else
31885 dev_kfree_skb_any(skb);
31886- atomic_inc(&vcc->stats->tx);
31887+ atomic_inc_unchecked(&vcc->stats->tx);
31888
31889 return 0;
31890 }
31891diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31892index 77a7480..05cde58 100644
31893--- a/drivers/atm/ambassador.c
31894+++ b/drivers/atm/ambassador.c
31895@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31896 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31897
31898 // VC layer stats
31899- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31900+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31901
31902 // free the descriptor
31903 kfree (tx_descr);
31904@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31905 dump_skb ("<<<", vc, skb);
31906
31907 // VC layer stats
31908- atomic_inc(&atm_vcc->stats->rx);
31909+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31910 __net_timestamp(skb);
31911 // end of our responsibility
31912 atm_vcc->push (atm_vcc, skb);
31913@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31914 } else {
31915 PRINTK (KERN_INFO, "dropped over-size frame");
31916 // should we count this?
31917- atomic_inc(&atm_vcc->stats->rx_drop);
31918+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31919 }
31920
31921 } else {
31922@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31923 }
31924
31925 if (check_area (skb->data, skb->len)) {
31926- atomic_inc(&atm_vcc->stats->tx_err);
31927+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31928 return -ENOMEM; // ?
31929 }
31930
31931diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31932index b22d71c..d6e1049 100644
31933--- a/drivers/atm/atmtcp.c
31934+++ b/drivers/atm/atmtcp.c
31935@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31936 if (vcc->pop) vcc->pop(vcc,skb);
31937 else dev_kfree_skb(skb);
31938 if (dev_data) return 0;
31939- atomic_inc(&vcc->stats->tx_err);
31940+ atomic_inc_unchecked(&vcc->stats->tx_err);
31941 return -ENOLINK;
31942 }
31943 size = skb->len+sizeof(struct atmtcp_hdr);
31944@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31945 if (!new_skb) {
31946 if (vcc->pop) vcc->pop(vcc,skb);
31947 else dev_kfree_skb(skb);
31948- atomic_inc(&vcc->stats->tx_err);
31949+ atomic_inc_unchecked(&vcc->stats->tx_err);
31950 return -ENOBUFS;
31951 }
31952 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31953@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31954 if (vcc->pop) vcc->pop(vcc,skb);
31955 else dev_kfree_skb(skb);
31956 out_vcc->push(out_vcc,new_skb);
31957- atomic_inc(&vcc->stats->tx);
31958- atomic_inc(&out_vcc->stats->rx);
31959+ atomic_inc_unchecked(&vcc->stats->tx);
31960+ atomic_inc_unchecked(&out_vcc->stats->rx);
31961 return 0;
31962 }
31963
31964@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31965 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31966 read_unlock(&vcc_sklist_lock);
31967 if (!out_vcc) {
31968- atomic_inc(&vcc->stats->tx_err);
31969+ atomic_inc_unchecked(&vcc->stats->tx_err);
31970 goto done;
31971 }
31972 skb_pull(skb,sizeof(struct atmtcp_hdr));
31973@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31974 __net_timestamp(new_skb);
31975 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31976 out_vcc->push(out_vcc,new_skb);
31977- atomic_inc(&vcc->stats->tx);
31978- atomic_inc(&out_vcc->stats->rx);
31979+ atomic_inc_unchecked(&vcc->stats->tx);
31980+ atomic_inc_unchecked(&out_vcc->stats->rx);
31981 done:
31982 if (vcc->pop) vcc->pop(vcc,skb);
31983 else dev_kfree_skb(skb);
31984diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31985index c1eb6fa..4c71be9 100644
31986--- a/drivers/atm/eni.c
31987+++ b/drivers/atm/eni.c
31988@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31989 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31990 vcc->dev->number);
31991 length = 0;
31992- atomic_inc(&vcc->stats->rx_err);
31993+ atomic_inc_unchecked(&vcc->stats->rx_err);
31994 }
31995 else {
31996 length = ATM_CELL_SIZE-1; /* no HEC */
31997@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31998 size);
31999 }
32000 eff = length = 0;
32001- atomic_inc(&vcc->stats->rx_err);
32002+ atomic_inc_unchecked(&vcc->stats->rx_err);
32003 }
32004 else {
32005 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32006@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32007 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32008 vcc->dev->number,vcc->vci,length,size << 2,descr);
32009 length = eff = 0;
32010- atomic_inc(&vcc->stats->rx_err);
32011+ atomic_inc_unchecked(&vcc->stats->rx_err);
32012 }
32013 }
32014 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32015@@ -767,7 +767,7 @@ rx_dequeued++;
32016 vcc->push(vcc,skb);
32017 pushed++;
32018 }
32019- atomic_inc(&vcc->stats->rx);
32020+ atomic_inc_unchecked(&vcc->stats->rx);
32021 }
32022 wake_up(&eni_dev->rx_wait);
32023 }
32024@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32025 PCI_DMA_TODEVICE);
32026 if (vcc->pop) vcc->pop(vcc,skb);
32027 else dev_kfree_skb_irq(skb);
32028- atomic_inc(&vcc->stats->tx);
32029+ atomic_inc_unchecked(&vcc->stats->tx);
32030 wake_up(&eni_dev->tx_wait);
32031 dma_complete++;
32032 }
32033diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32034index b41c948..a002b17 100644
32035--- a/drivers/atm/firestream.c
32036+++ b/drivers/atm/firestream.c
32037@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32038 }
32039 }
32040
32041- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32042+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32043
32044 fs_dprintk (FS_DEBUG_TXMEM, "i");
32045 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32046@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32047 #endif
32048 skb_put (skb, qe->p1 & 0xffff);
32049 ATM_SKB(skb)->vcc = atm_vcc;
32050- atomic_inc(&atm_vcc->stats->rx);
32051+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32052 __net_timestamp(skb);
32053 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32054 atm_vcc->push (atm_vcc, skb);
32055@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32056 kfree (pe);
32057 }
32058 if (atm_vcc)
32059- atomic_inc(&atm_vcc->stats->rx_drop);
32060+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32061 break;
32062 case 0x1f: /* Reassembly abort: no buffers. */
32063 /* Silently increment error counter. */
32064 if (atm_vcc)
32065- atomic_inc(&atm_vcc->stats->rx_drop);
32066+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32067 break;
32068 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32069 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32070diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32071index 204814e..cede831 100644
32072--- a/drivers/atm/fore200e.c
32073+++ b/drivers/atm/fore200e.c
32074@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32075 #endif
32076 /* check error condition */
32077 if (*entry->status & STATUS_ERROR)
32078- atomic_inc(&vcc->stats->tx_err);
32079+ atomic_inc_unchecked(&vcc->stats->tx_err);
32080 else
32081- atomic_inc(&vcc->stats->tx);
32082+ atomic_inc_unchecked(&vcc->stats->tx);
32083 }
32084 }
32085
32086@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32087 if (skb == NULL) {
32088 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32089
32090- atomic_inc(&vcc->stats->rx_drop);
32091+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32092 return -ENOMEM;
32093 }
32094
32095@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32096
32097 dev_kfree_skb_any(skb);
32098
32099- atomic_inc(&vcc->stats->rx_drop);
32100+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32101 return -ENOMEM;
32102 }
32103
32104 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32105
32106 vcc->push(vcc, skb);
32107- atomic_inc(&vcc->stats->rx);
32108+ atomic_inc_unchecked(&vcc->stats->rx);
32109
32110 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32111
32112@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32113 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32114 fore200e->atm_dev->number,
32115 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32116- atomic_inc(&vcc->stats->rx_err);
32117+ atomic_inc_unchecked(&vcc->stats->rx_err);
32118 }
32119 }
32120
32121@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32122 goto retry_here;
32123 }
32124
32125- atomic_inc(&vcc->stats->tx_err);
32126+ atomic_inc_unchecked(&vcc->stats->tx_err);
32127
32128 fore200e->tx_sat++;
32129 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32130diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32131index 72b6960..cf9167a 100644
32132--- a/drivers/atm/he.c
32133+++ b/drivers/atm/he.c
32134@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32135
32136 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32137 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32138- atomic_inc(&vcc->stats->rx_drop);
32139+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32140 goto return_host_buffers;
32141 }
32142
32143@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32144 RBRQ_LEN_ERR(he_dev->rbrq_head)
32145 ? "LEN_ERR" : "",
32146 vcc->vpi, vcc->vci);
32147- atomic_inc(&vcc->stats->rx_err);
32148+ atomic_inc_unchecked(&vcc->stats->rx_err);
32149 goto return_host_buffers;
32150 }
32151
32152@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32153 vcc->push(vcc, skb);
32154 spin_lock(&he_dev->global_lock);
32155
32156- atomic_inc(&vcc->stats->rx);
32157+ atomic_inc_unchecked(&vcc->stats->rx);
32158
32159 return_host_buffers:
32160 ++pdus_assembled;
32161@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32162 tpd->vcc->pop(tpd->vcc, tpd->skb);
32163 else
32164 dev_kfree_skb_any(tpd->skb);
32165- atomic_inc(&tpd->vcc->stats->tx_err);
32166+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32167 }
32168 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32169 return;
32170@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32171 vcc->pop(vcc, skb);
32172 else
32173 dev_kfree_skb_any(skb);
32174- atomic_inc(&vcc->stats->tx_err);
32175+ atomic_inc_unchecked(&vcc->stats->tx_err);
32176 return -EINVAL;
32177 }
32178
32179@@ -2527,7 +2527,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 #endif
32188@@ -2539,7 +2539,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 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32195 return -ENOMEM;
32196 }
32197@@ -2581,7 +2581,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@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32207 __enqueue_tpd(he_dev, tpd, cid);
32208 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32209
32210- atomic_inc(&vcc->stats->tx);
32211+ atomic_inc_unchecked(&vcc->stats->tx);
32212
32213 return 0;
32214 }
32215diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32216index 1dc0519..1aadaf7 100644
32217--- a/drivers/atm/horizon.c
32218+++ b/drivers/atm/horizon.c
32219@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32220 {
32221 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32222 // VC layer stats
32223- atomic_inc(&vcc->stats->rx);
32224+ atomic_inc_unchecked(&vcc->stats->rx);
32225 __net_timestamp(skb);
32226 // end of our responsibility
32227 vcc->push (vcc, skb);
32228@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32229 dev->tx_iovec = NULL;
32230
32231 // VC layer stats
32232- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32233+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32234
32235 // free the skb
32236 hrz_kfree_skb (skb);
32237diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32238index 272f009..a18ba55 100644
32239--- a/drivers/atm/idt77252.c
32240+++ b/drivers/atm/idt77252.c
32241@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32242 else
32243 dev_kfree_skb(skb);
32244
32245- atomic_inc(&vcc->stats->tx);
32246+ atomic_inc_unchecked(&vcc->stats->tx);
32247 }
32248
32249 atomic_dec(&scq->used);
32250@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32251 if ((sb = dev_alloc_skb(64)) == NULL) {
32252 printk("%s: Can't allocate buffers for aal0.\n",
32253 card->name);
32254- atomic_add(i, &vcc->stats->rx_drop);
32255+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32256 break;
32257 }
32258 if (!atm_charge(vcc, sb->truesize)) {
32259 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32260 card->name);
32261- atomic_add(i - 1, &vcc->stats->rx_drop);
32262+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32263 dev_kfree_skb(sb);
32264 break;
32265 }
32266@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32267 ATM_SKB(sb)->vcc = vcc;
32268 __net_timestamp(sb);
32269 vcc->push(vcc, sb);
32270- atomic_inc(&vcc->stats->rx);
32271+ atomic_inc_unchecked(&vcc->stats->rx);
32272
32273 cell += ATM_CELL_PAYLOAD;
32274 }
32275@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32276 "(CDC: %08x)\n",
32277 card->name, len, rpp->len, readl(SAR_REG_CDC));
32278 recycle_rx_pool_skb(card, rpp);
32279- atomic_inc(&vcc->stats->rx_err);
32280+ atomic_inc_unchecked(&vcc->stats->rx_err);
32281 return;
32282 }
32283 if (stat & SAR_RSQE_CRC) {
32284 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32285 recycle_rx_pool_skb(card, rpp);
32286- atomic_inc(&vcc->stats->rx_err);
32287+ atomic_inc_unchecked(&vcc->stats->rx_err);
32288 return;
32289 }
32290 if (skb_queue_len(&rpp->queue) > 1) {
32291@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32292 RXPRINTK("%s: Can't alloc RX skb.\n",
32293 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 (!atm_charge(vcc, skb->truesize)) {
32300@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32301 __net_timestamp(skb);
32302
32303 vcc->push(vcc, skb);
32304- atomic_inc(&vcc->stats->rx);
32305+ atomic_inc_unchecked(&vcc->stats->rx);
32306
32307 return;
32308 }
32309@@ -1193,7 +1193,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 if (skb->truesize > SAR_FB_SIZE_3)
32317 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32318@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32319 if (vcc->qos.aal != ATM_AAL0) {
32320 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32321 card->name, vpi, vci);
32322- atomic_inc(&vcc->stats->rx_drop);
32323+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32324 goto drop;
32325 }
32326
32327 if ((sb = dev_alloc_skb(64)) == NULL) {
32328 printk("%s: Can't allocate buffers for AAL0.\n",
32329 card->name);
32330- atomic_inc(&vcc->stats->rx_err);
32331+ atomic_inc_unchecked(&vcc->stats->rx_err);
32332 goto drop;
32333 }
32334
32335@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32336 ATM_SKB(sb)->vcc = vcc;
32337 __net_timestamp(sb);
32338 vcc->push(vcc, sb);
32339- atomic_inc(&vcc->stats->rx);
32340+ atomic_inc_unchecked(&vcc->stats->rx);
32341
32342 drop:
32343 skb_pull(queue, 64);
32344@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32345
32346 if (vc == NULL) {
32347 printk("%s: NULL connection in send().\n", card->name);
32348- atomic_inc(&vcc->stats->tx_err);
32349+ atomic_inc_unchecked(&vcc->stats->tx_err);
32350 dev_kfree_skb(skb);
32351 return -EINVAL;
32352 }
32353 if (!test_bit(VCF_TX, &vc->flags)) {
32354 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32355- atomic_inc(&vcc->stats->tx_err);
32356+ atomic_inc_unchecked(&vcc->stats->tx_err);
32357 dev_kfree_skb(skb);
32358 return -EINVAL;
32359 }
32360@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32361 break;
32362 default:
32363 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
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
32370 if (skb_shinfo(skb)->nr_frags != 0) {
32371 printk("%s: No scatter-gather yet.\n", card->name);
32372- atomic_inc(&vcc->stats->tx_err);
32373+ atomic_inc_unchecked(&vcc->stats->tx_err);
32374 dev_kfree_skb(skb);
32375 return -EINVAL;
32376 }
32377@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32378
32379 err = queue_skb(card, vc, skb, oam);
32380 if (err) {
32381- atomic_inc(&vcc->stats->tx_err);
32382+ atomic_inc_unchecked(&vcc->stats->tx_err);
32383 dev_kfree_skb(skb);
32384 return err;
32385 }
32386@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32387 skb = dev_alloc_skb(64);
32388 if (!skb) {
32389 printk("%s: Out of memory in send_oam().\n", card->name);
32390- atomic_inc(&vcc->stats->tx_err);
32391+ atomic_inc_unchecked(&vcc->stats->tx_err);
32392 return -ENOMEM;
32393 }
32394 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32395diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32396index 4217f29..88f547a 100644
32397--- a/drivers/atm/iphase.c
32398+++ b/drivers/atm/iphase.c
32399@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32400 status = (u_short) (buf_desc_ptr->desc_mode);
32401 if (status & (RX_CER | RX_PTE | RX_OFL))
32402 {
32403- atomic_inc(&vcc->stats->rx_err);
32404+ atomic_inc_unchecked(&vcc->stats->rx_err);
32405 IF_ERR(printk("IA: bad packet, dropping it");)
32406 if (status & RX_CER) {
32407 IF_ERR(printk(" cause: packet CRC error\n");)
32408@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32409 len = dma_addr - buf_addr;
32410 if (len > iadev->rx_buf_sz) {
32411 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32412- atomic_inc(&vcc->stats->rx_err);
32413+ atomic_inc_unchecked(&vcc->stats->rx_err);
32414 goto out_free_desc;
32415 }
32416
32417@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32418 ia_vcc = INPH_IA_VCC(vcc);
32419 if (ia_vcc == NULL)
32420 {
32421- atomic_inc(&vcc->stats->rx_err);
32422+ atomic_inc_unchecked(&vcc->stats->rx_err);
32423 atm_return(vcc, skb->truesize);
32424 dev_kfree_skb_any(skb);
32425 goto INCR_DLE;
32426@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32427 if ((length > iadev->rx_buf_sz) || (length >
32428 (skb->len - sizeof(struct cpcs_trailer))))
32429 {
32430- atomic_inc(&vcc->stats->rx_err);
32431+ atomic_inc_unchecked(&vcc->stats->rx_err);
32432 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32433 length, skb->len);)
32434 atm_return(vcc, skb->truesize);
32435@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32436
32437 IF_RX(printk("rx_dle_intr: skb push");)
32438 vcc->push(vcc,skb);
32439- atomic_inc(&vcc->stats->rx);
32440+ atomic_inc_unchecked(&vcc->stats->rx);
32441 iadev->rx_pkt_cnt++;
32442 }
32443 INCR_DLE:
32444@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32445 {
32446 struct k_sonet_stats *stats;
32447 stats = &PRIV(_ia_dev[board])->sonet_stats;
32448- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32449- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32450- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32451- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32452- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32453- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32454- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32455- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32456- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32457+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32458+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32459+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32460+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32461+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32462+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32463+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32464+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32465+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32466 }
32467 ia_cmds.status = 0;
32468 break;
32469@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32470 if ((desc == 0) || (desc > iadev->num_tx_desc))
32471 {
32472 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32473- atomic_inc(&vcc->stats->tx);
32474+ atomic_inc_unchecked(&vcc->stats->tx);
32475 if (vcc->pop)
32476 vcc->pop(vcc, skb);
32477 else
32478@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32479 ATM_DESC(skb) = vcc->vci;
32480 skb_queue_tail(&iadev->tx_dma_q, skb);
32481
32482- atomic_inc(&vcc->stats->tx);
32483+ atomic_inc_unchecked(&vcc->stats->tx);
32484 iadev->tx_pkt_cnt++;
32485 /* Increment transaction counter */
32486 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32487
32488 #if 0
32489 /* add flow control logic */
32490- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32491+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32492 if (iavcc->vc_desc_cnt > 10) {
32493 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32494 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32495diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32496index fa7d701..1e404c7 100644
32497--- a/drivers/atm/lanai.c
32498+++ b/drivers/atm/lanai.c
32499@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32500 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32501 lanai_endtx(lanai, lvcc);
32502 lanai_free_skb(lvcc->tx.atmvcc, skb);
32503- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32504+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32505 }
32506
32507 /* Try to fill the buffer - don't call unless there is backlog */
32508@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32509 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32510 __net_timestamp(skb);
32511 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32512- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32513+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32514 out:
32515 lvcc->rx.buf.ptr = end;
32516 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32517@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32518 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32519 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32520 lanai->stats.service_rxnotaal5++;
32521- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32522+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32523 return 0;
32524 }
32525 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32526@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32527 int bytes;
32528 read_unlock(&vcc_sklist_lock);
32529 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32530- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32531+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32532 lvcc->stats.x.aal5.service_trash++;
32533 bytes = (SERVICE_GET_END(s) * 16) -
32534 (((unsigned long) lvcc->rx.buf.ptr) -
32535@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32536 }
32537 if (s & SERVICE_STREAM) {
32538 read_unlock(&vcc_sklist_lock);
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_stream++;
32542 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32543 "PDU on VCI %d!\n", lanai->number, vci);
32544@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32545 return 0;
32546 }
32547 DPRINTK("got rx crc error on vci %d\n", vci);
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_rxcrc++;
32551 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32552 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32553diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32554index ed1d2b7..8cffc1f 100644
32555--- a/drivers/atm/nicstar.c
32556+++ b/drivers/atm/nicstar.c
32557@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32558 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32559 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32560 card->index);
32561- atomic_inc(&vcc->stats->tx_err);
32562+ atomic_inc_unchecked(&vcc->stats->tx_err);
32563 dev_kfree_skb_any(skb);
32564 return -EINVAL;
32565 }
32566@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32567 if (!vc->tx) {
32568 printk("nicstar%d: Trying to transmit on a non-tx VC.\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@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32576 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32577 printk("nicstar%d: Only AAL0 and AAL5 are supported.\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
32585 if (skb_shinfo(skb)->nr_frags != 0) {
32586 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32587- atomic_inc(&vcc->stats->tx_err);
32588+ atomic_inc_unchecked(&vcc->stats->tx_err);
32589 dev_kfree_skb_any(skb);
32590 return -EINVAL;
32591 }
32592@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32593 }
32594
32595 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32596- atomic_inc(&vcc->stats->tx_err);
32597+ atomic_inc_unchecked(&vcc->stats->tx_err);
32598 dev_kfree_skb_any(skb);
32599 return -EIO;
32600 }
32601- atomic_inc(&vcc->stats->tx);
32602+ atomic_inc_unchecked(&vcc->stats->tx);
32603
32604 return 0;
32605 }
32606@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32607 printk
32608 ("nicstar%d: Can't allocate buffers for aal0.\n",
32609 card->index);
32610- atomic_add(i, &vcc->stats->rx_drop);
32611+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32612 break;
32613 }
32614 if (!atm_charge(vcc, sb->truesize)) {
32615 RXPRINTK
32616 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32617 card->index);
32618- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32619+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32620 dev_kfree_skb_any(sb);
32621 break;
32622 }
32623@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32624 ATM_SKB(sb)->vcc = vcc;
32625 __net_timestamp(sb);
32626 vcc->push(vcc, sb);
32627- atomic_inc(&vcc->stats->rx);
32628+ atomic_inc_unchecked(&vcc->stats->rx);
32629 cell += ATM_CELL_PAYLOAD;
32630 }
32631
32632@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32633 if (iovb == NULL) {
32634 printk("nicstar%d: Out of iovec buffers.\n",
32635 card->index);
32636- atomic_inc(&vcc->stats->rx_drop);
32637+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32638 recycle_rx_buf(card, skb);
32639 return;
32640 }
32641@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32642 small or large buffer itself. */
32643 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32644 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32645- atomic_inc(&vcc->stats->rx_err);
32646+ atomic_inc_unchecked(&vcc->stats->rx_err);
32647 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32648 NS_MAX_IOVECS);
32649 NS_PRV_IOVCNT(iovb) = 0;
32650@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32651 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32652 card->index);
32653 which_list(card, skb);
32654- atomic_inc(&vcc->stats->rx_err);
32655+ atomic_inc_unchecked(&vcc->stats->rx_err);
32656 recycle_rx_buf(card, skb);
32657 vc->rx_iov = NULL;
32658 recycle_iov_buf(card, iovb);
32659@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32660 ("nicstar%d: Expected a large 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_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32666 NS_PRV_IOVCNT(iovb));
32667 vc->rx_iov = NULL;
32668@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32669 printk(" - PDU size mismatch.\n");
32670 else
32671 printk(".\n");
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@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32678 /* skb points to a small buffer */
32679 if (!atm_charge(vcc, skb->truesize)) {
32680 push_rxbufs(card, skb);
32681- atomic_inc(&vcc->stats->rx_drop);
32682+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32683 } else {
32684 skb_put(skb, len);
32685 dequeue_sm_buf(card, skb);
32686@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32687 ATM_SKB(skb)->vcc = vcc;
32688 __net_timestamp(skb);
32689 vcc->push(vcc, skb);
32690- atomic_inc(&vcc->stats->rx);
32691+ atomic_inc_unchecked(&vcc->stats->rx);
32692 }
32693 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32694 struct sk_buff *sb;
32695@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32696 if (len <= NS_SMBUFSIZE) {
32697 if (!atm_charge(vcc, sb->truesize)) {
32698 push_rxbufs(card, sb);
32699- atomic_inc(&vcc->stats->rx_drop);
32700+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32701 } else {
32702 skb_put(sb, len);
32703 dequeue_sm_buf(card, sb);
32704@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32705 ATM_SKB(sb)->vcc = vcc;
32706 __net_timestamp(sb);
32707 vcc->push(vcc, sb);
32708- atomic_inc(&vcc->stats->rx);
32709+ atomic_inc_unchecked(&vcc->stats->rx);
32710 }
32711
32712 push_rxbufs(card, skb);
32713@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32714
32715 if (!atm_charge(vcc, skb->truesize)) {
32716 push_rxbufs(card, skb);
32717- atomic_inc(&vcc->stats->rx_drop);
32718+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32719 } else {
32720 dequeue_lg_buf(card, skb);
32721 #ifdef NS_USE_DESTRUCTORS
32722@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32723 ATM_SKB(skb)->vcc = vcc;
32724 __net_timestamp(skb);
32725 vcc->push(vcc, skb);
32726- atomic_inc(&vcc->stats->rx);
32727+ atomic_inc_unchecked(&vcc->stats->rx);
32728 }
32729
32730 push_rxbufs(card, sb);
32731@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32732 printk
32733 ("nicstar%d: Out of huge buffers.\n",
32734 card->index);
32735- atomic_inc(&vcc->stats->rx_drop);
32736+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32737 recycle_iovec_rx_bufs(card,
32738 (struct iovec *)
32739 iovb->data,
32740@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32741 card->hbpool.count++;
32742 } else
32743 dev_kfree_skb_any(hb);
32744- atomic_inc(&vcc->stats->rx_drop);
32745+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32746 } else {
32747 /* Copy the small buffer to the huge buffer */
32748 sb = (struct sk_buff *)iov->iov_base;
32749@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32750 #endif /* NS_USE_DESTRUCTORS */
32751 __net_timestamp(hb);
32752 vcc->push(vcc, hb);
32753- atomic_inc(&vcc->stats->rx);
32754+ atomic_inc_unchecked(&vcc->stats->rx);
32755 }
32756 }
32757
32758diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32759index 0474a89..06ea4a1 100644
32760--- a/drivers/atm/solos-pci.c
32761+++ b/drivers/atm/solos-pci.c
32762@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32763 }
32764 atm_charge(vcc, skb->truesize);
32765 vcc->push(vcc, skb);
32766- atomic_inc(&vcc->stats->rx);
32767+ atomic_inc_unchecked(&vcc->stats->rx);
32768 break;
32769
32770 case PKT_STATUS:
32771@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32772 vcc = SKB_CB(oldskb)->vcc;
32773
32774 if (vcc) {
32775- atomic_inc(&vcc->stats->tx);
32776+ atomic_inc_unchecked(&vcc->stats->tx);
32777 solos_pop(vcc, oldskb);
32778 } else {
32779 dev_kfree_skb_irq(oldskb);
32780diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32781index 0215934..ce9f5b1 100644
32782--- a/drivers/atm/suni.c
32783+++ b/drivers/atm/suni.c
32784@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32785
32786
32787 #define ADD_LIMITED(s,v) \
32788- atomic_add((v),&stats->s); \
32789- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32790+ atomic_add_unchecked((v),&stats->s); \
32791+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32792
32793
32794 static void suni_hz(unsigned long from_timer)
32795diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32796index 5120a96..e2572bd 100644
32797--- a/drivers/atm/uPD98402.c
32798+++ b/drivers/atm/uPD98402.c
32799@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32800 struct sonet_stats tmp;
32801 int error = 0;
32802
32803- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32804+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32805 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32806 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32807 if (zero && !error) {
32808@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32809
32810
32811 #define ADD_LIMITED(s,v) \
32812- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32813- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32814- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32815+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32816+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32817+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32818
32819
32820 static void stat_event(struct atm_dev *dev)
32821@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32822 if (reason & uPD98402_INT_PFM) stat_event(dev);
32823 if (reason & uPD98402_INT_PCO) {
32824 (void) GET(PCOCR); /* clear interrupt cause */
32825- atomic_add(GET(HECCT),
32826+ atomic_add_unchecked(GET(HECCT),
32827 &PRIV(dev)->sonet_stats.uncorr_hcs);
32828 }
32829 if ((reason & uPD98402_INT_RFO) &&
32830@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32831 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32832 uPD98402_INT_LOS),PIMR); /* enable them */
32833 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32834- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32835- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32836- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32837+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32838+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32839+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32840 return 0;
32841 }
32842
32843diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32844index 969c3c2..9b72956 100644
32845--- a/drivers/atm/zatm.c
32846+++ b/drivers/atm/zatm.c
32847@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32848 }
32849 if (!size) {
32850 dev_kfree_skb_irq(skb);
32851- if (vcc) atomic_inc(&vcc->stats->rx_err);
32852+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32853 continue;
32854 }
32855 if (!atm_charge(vcc,skb->truesize)) {
32856@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32857 skb->len = size;
32858 ATM_SKB(skb)->vcc = vcc;
32859 vcc->push(vcc,skb);
32860- atomic_inc(&vcc->stats->rx);
32861+ atomic_inc_unchecked(&vcc->stats->rx);
32862 }
32863 zout(pos & 0xffff,MTA(mbx));
32864 #if 0 /* probably a stupid idea */
32865@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32866 skb_queue_head(&zatm_vcc->backlog,skb);
32867 break;
32868 }
32869- atomic_inc(&vcc->stats->tx);
32870+ atomic_inc_unchecked(&vcc->stats->tx);
32871 wake_up(&zatm_vcc->tx_wait);
32872 }
32873
32874diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32875index 6856303..0602d70 100644
32876--- a/drivers/base/bus.c
32877+++ b/drivers/base/bus.c
32878@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32879 return -EINVAL;
32880
32881 mutex_lock(&subsys->p->mutex);
32882- list_add_tail(&sif->node, &subsys->p->interfaces);
32883+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32884 if (sif->add_dev) {
32885 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32886 while ((dev = subsys_dev_iter_next(&iter)))
32887@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32888 subsys = sif->subsys;
32889
32890 mutex_lock(&subsys->p->mutex);
32891- list_del_init(&sif->node);
32892+ pax_list_del_init((struct list_head *)&sif->node);
32893 if (sif->remove_dev) {
32894 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32895 while ((dev = subsys_dev_iter_next(&iter)))
32896diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32897index 17cf7ca..7e553e1 100644
32898--- a/drivers/base/devtmpfs.c
32899+++ b/drivers/base/devtmpfs.c
32900@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32901 if (!thread)
32902 return 0;
32903
32904- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32905+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32906 if (err)
32907 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32908 else
32909diff --git a/drivers/base/node.c b/drivers/base/node.c
32910index fac124a..66bd4ab 100644
32911--- a/drivers/base/node.c
32912+++ b/drivers/base/node.c
32913@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
32914 struct node_attr {
32915 struct device_attribute attr;
32916 enum node_states state;
32917-};
32918+} __do_const;
32919
32920 static ssize_t show_node_state(struct device *dev,
32921 struct device_attribute *attr, char *buf)
32922diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
32923index acc3a8d..981c236 100644
32924--- a/drivers/base/power/domain.c
32925+++ b/drivers/base/power/domain.c
32926@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
32927 {
32928 struct cpuidle_driver *cpuidle_drv;
32929 struct gpd_cpu_data *cpu_data;
32930- struct cpuidle_state *idle_state;
32931+ cpuidle_state_no_const *idle_state;
32932 int ret = 0;
32933
32934 if (IS_ERR_OR_NULL(genpd) || state < 0)
32935@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
32936 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
32937 {
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))
32944diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32945index e6ee5e8..98ad7fc 100644
32946--- a/drivers/base/power/wakeup.c
32947+++ b/drivers/base/power/wakeup.c
32948@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32949 * They need to be modified together atomically, so it's better to use one
32950 * atomic variable to hold them both.
32951 */
32952-static atomic_t combined_event_count = ATOMIC_INIT(0);
32953+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32954
32955 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32956 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32957
32958 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32959 {
32960- unsigned int comb = atomic_read(&combined_event_count);
32961+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
32962
32963 *cnt = (comb >> IN_PROGRESS_BITS);
32964 *inpr = comb & MAX_IN_PROGRESS;
32965@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32966 ws->start_prevent_time = ws->last_time;
32967
32968 /* Increment the counter of events in progress. */
32969- cec = atomic_inc_return(&combined_event_count);
32970+ cec = atomic_inc_return_unchecked(&combined_event_count);
32971
32972 trace_wakeup_source_activate(ws->name, cec);
32973 }
32974@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32975 * Increment the counter of registered wakeup events and decrement the
32976 * couter of wakeup events in progress simultaneously.
32977 */
32978- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32979+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32980 trace_wakeup_source_deactivate(ws->name, cec);
32981
32982 split_counters(&cnt, &inpr);
32983diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
32984index e8d11b6..7b1b36f 100644
32985--- a/drivers/base/syscore.c
32986+++ b/drivers/base/syscore.c
32987@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
32988 void register_syscore_ops(struct syscore_ops *ops)
32989 {
32990 mutex_lock(&syscore_ops_lock);
32991- list_add_tail(&ops->node, &syscore_ops_list);
32992+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
32993 mutex_unlock(&syscore_ops_lock);
32994 }
32995 EXPORT_SYMBOL_GPL(register_syscore_ops);
32996@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
32997 void unregister_syscore_ops(struct syscore_ops *ops)
32998 {
32999 mutex_lock(&syscore_ops_lock);
33000- list_del(&ops->node);
33001+ pax_list_del((struct list_head *)&ops->node);
33002 mutex_unlock(&syscore_ops_lock);
33003 }
33004 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33005diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33006index ade58bc..867143d 100644
33007--- a/drivers/block/cciss.c
33008+++ b/drivers/block/cciss.c
33009@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33010 int err;
33011 u32 cp;
33012
33013+ memset(&arg64, 0, sizeof(arg64));
33014+
33015 err = 0;
33016 err |=
33017 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33018@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33019 while (!list_empty(&h->reqQ)) {
33020 c = list_entry(h->reqQ.next, CommandList_struct, list);
33021 /* can't do anything if fifo is full */
33022- if ((h->access.fifo_full(h))) {
33023+ if ((h->access->fifo_full(h))) {
33024 dev_warn(&h->pdev->dev, "fifo full\n");
33025 break;
33026 }
33027@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33028 h->Qdepth--;
33029
33030 /* Tell the controller execute command */
33031- h->access.submit_command(h, c);
33032+ h->access->submit_command(h, c);
33033
33034 /* Put job onto the completed Q */
33035 addQ(&h->cmpQ, c);
33036@@ -3441,17 +3443,17 @@ startio:
33037
33038 static inline unsigned long get_next_completion(ctlr_info_t *h)
33039 {
33040- return h->access.command_completed(h);
33041+ return h->access->command_completed(h);
33042 }
33043
33044 static inline int interrupt_pending(ctlr_info_t *h)
33045 {
33046- return h->access.intr_pending(h);
33047+ return h->access->intr_pending(h);
33048 }
33049
33050 static inline long interrupt_not_for_us(ctlr_info_t *h)
33051 {
33052- return ((h->access.intr_pending(h) == 0) ||
33053+ return ((h->access->intr_pending(h) == 0) ||
33054 (h->interrupts_enabled == 0));
33055 }
33056
33057@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33058 u32 a;
33059
33060 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33061- return h->access.command_completed(h);
33062+ return h->access->command_completed(h);
33063
33064 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33065 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33066@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33067 trans_support & CFGTBL_Trans_use_short_tags);
33068
33069 /* Change the access methods to the performant access methods */
33070- h->access = SA5_performant_access;
33071+ h->access = &SA5_performant_access;
33072 h->transMethod = CFGTBL_Trans_Performant;
33073
33074 return;
33075@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33076 if (prod_index < 0)
33077 return -ENODEV;
33078 h->product_name = products[prod_index].product_name;
33079- h->access = *(products[prod_index].access);
33080+ h->access = products[prod_index].access;
33081
33082 if (cciss_board_disabled(h)) {
33083 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33084@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33085 }
33086
33087 /* make sure the board interrupts are off */
33088- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33089+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33090 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33091 if (rc)
33092 goto clean2;
33093@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33094 * fake ones to scoop up any residual completions.
33095 */
33096 spin_lock_irqsave(&h->lock, flags);
33097- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33098+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33099 spin_unlock_irqrestore(&h->lock, flags);
33100 free_irq(h->intr[h->intr_mode], h);
33101 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33102@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33103 dev_info(&h->pdev->dev, "Board READY.\n");
33104 dev_info(&h->pdev->dev,
33105 "Waiting for stale completions to drain.\n");
33106- h->access.set_intr_mask(h, CCISS_INTR_ON);
33107+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33108 msleep(10000);
33109- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33110+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33111
33112 rc = controller_reset_failed(h->cfgtable);
33113 if (rc)
33114@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33115 cciss_scsi_setup(h);
33116
33117 /* Turn the interrupts on so we can service requests */
33118- h->access.set_intr_mask(h, CCISS_INTR_ON);
33119+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33120
33121 /* Get the firmware version */
33122 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33123@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33124 kfree(flush_buf);
33125 if (return_code != IO_OK)
33126 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33127- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33128+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33129 free_irq(h->intr[h->intr_mode], h);
33130 }
33131
33132diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33133index 7fda30e..eb5dfe0 100644
33134--- a/drivers/block/cciss.h
33135+++ b/drivers/block/cciss.h
33136@@ -101,7 +101,7 @@ struct ctlr_info
33137 /* information about each logical volume */
33138 drive_info_struct *drv[CISS_MAX_LUN];
33139
33140- struct access_method access;
33141+ struct access_method *access;
33142
33143 /* queue and queue Info */
33144 struct list_head reqQ;
33145diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33146index 3f08713..56a586a 100644
33147--- a/drivers/block/cpqarray.c
33148+++ b/drivers/block/cpqarray.c
33149@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33150 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33151 goto Enomem4;
33152 }
33153- hba[i]->access.set_intr_mask(hba[i], 0);
33154+ hba[i]->access->set_intr_mask(hba[i], 0);
33155 if (request_irq(hba[i]->intr, do_ida_intr,
33156 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33157 {
33158@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33159 add_timer(&hba[i]->timer);
33160
33161 /* Enable IRQ now that spinlock and rate limit timer are set up */
33162- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33163+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33164
33165 for(j=0; j<NWD; j++) {
33166 struct gendisk *disk = ida_gendisk[i][j];
33167@@ -694,7 +694,7 @@ DBGINFO(
33168 for(i=0; i<NR_PRODUCTS; i++) {
33169 if (board_id == products[i].board_id) {
33170 c->product_name = products[i].product_name;
33171- c->access = *(products[i].access);
33172+ c->access = products[i].access;
33173 break;
33174 }
33175 }
33176@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33177 hba[ctlr]->intr = intr;
33178 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33179 hba[ctlr]->product_name = products[j].product_name;
33180- hba[ctlr]->access = *(products[j].access);
33181+ hba[ctlr]->access = products[j].access;
33182 hba[ctlr]->ctlr = ctlr;
33183 hba[ctlr]->board_id = board_id;
33184 hba[ctlr]->pci_dev = NULL; /* not PCI */
33185@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33186
33187 while((c = h->reqQ) != NULL) {
33188 /* Can't do anything if we're busy */
33189- if (h->access.fifo_full(h) == 0)
33190+ if (h->access->fifo_full(h) == 0)
33191 return;
33192
33193 /* Get the first entry from the request Q */
33194@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33195 h->Qdepth--;
33196
33197 /* Tell the controller to do our bidding */
33198- h->access.submit_command(h, c);
33199+ h->access->submit_command(h, c);
33200
33201 /* Get onto the completion Q */
33202 addQ(&h->cmpQ, c);
33203@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33204 unsigned long flags;
33205 __u32 a,a1;
33206
33207- istat = h->access.intr_pending(h);
33208+ istat = h->access->intr_pending(h);
33209 /* Is this interrupt for us? */
33210 if (istat == 0)
33211 return IRQ_NONE;
33212@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33213 */
33214 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33215 if (istat & FIFO_NOT_EMPTY) {
33216- while((a = h->access.command_completed(h))) {
33217+ while((a = h->access->command_completed(h))) {
33218 a1 = a; a &= ~3;
33219 if ((c = h->cmpQ) == NULL)
33220 {
33221@@ -1449,11 +1449,11 @@ static int sendcmd(
33222 /*
33223 * Disable interrupt
33224 */
33225- info_p->access.set_intr_mask(info_p, 0);
33226+ info_p->access->set_intr_mask(info_p, 0);
33227 /* Make sure there is room in the command FIFO */
33228 /* Actually it should be completely empty at this time. */
33229 for (i = 200000; i > 0; i--) {
33230- temp = info_p->access.fifo_full(info_p);
33231+ temp = info_p->access->fifo_full(info_p);
33232 if (temp != 0) {
33233 break;
33234 }
33235@@ -1466,7 +1466,7 @@ DBG(
33236 /*
33237 * Send the cmd
33238 */
33239- info_p->access.submit_command(info_p, c);
33240+ info_p->access->submit_command(info_p, c);
33241 complete = pollcomplete(ctlr);
33242
33243 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33244@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33245 * we check the new geometry. Then turn interrupts back on when
33246 * we're done.
33247 */
33248- host->access.set_intr_mask(host, 0);
33249+ host->access->set_intr_mask(host, 0);
33250 getgeometry(ctlr);
33251- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33252+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33253
33254 for(i=0; i<NWD; i++) {
33255 struct gendisk *disk = ida_gendisk[ctlr][i];
33256@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
33257 /* Wait (up to 2 seconds) for a command to complete */
33258
33259 for (i = 200000; i > 0; i--) {
33260- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33261+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33262 if (done == 0) {
33263 udelay(10); /* a short fixed delay */
33264 } else
33265diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33266index be73e9d..7fbf140 100644
33267--- a/drivers/block/cpqarray.h
33268+++ b/drivers/block/cpqarray.h
33269@@ -99,7 +99,7 @@ struct ctlr_info {
33270 drv_info_t drv[NWD];
33271 struct proc_dir_entry *proc;
33272
33273- struct access_method access;
33274+ struct access_method *access;
33275
33276 cmdlist_t *reqQ;
33277 cmdlist_t *cmpQ;
33278diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33279index 6b51afa..17e1191 100644
33280--- a/drivers/block/drbd/drbd_int.h
33281+++ b/drivers/block/drbd/drbd_int.h
33282@@ -582,7 +582,7 @@ struct drbd_epoch {
33283 struct drbd_tconn *tconn;
33284 struct list_head list;
33285 unsigned int barrier_nr;
33286- atomic_t epoch_size; /* increased on every request added. */
33287+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33288 atomic_t active; /* increased on every req. added, and dec on every finished. */
33289 unsigned long flags;
33290 };
33291@@ -1011,7 +1011,7 @@ struct drbd_conf {
33292 int al_tr_cycle;
33293 int al_tr_pos; /* position of the next transaction in the journal */
33294 wait_queue_head_t seq_wait;
33295- atomic_t packet_seq;
33296+ atomic_unchecked_t packet_seq;
33297 unsigned int peer_seq;
33298 spinlock_t peer_seq_lock;
33299 unsigned int minor;
33300@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33301 char __user *uoptval;
33302 int err;
33303
33304- uoptval = (char __user __force *)optval;
33305+ uoptval = (char __force_user *)optval;
33306
33307 set_fs(KERNEL_DS);
33308 if (level == SOL_SOCKET)
33309diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33310index 8c13eeb..217adee 100644
33311--- a/drivers/block/drbd/drbd_main.c
33312+++ b/drivers/block/drbd/drbd_main.c
33313@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33314 p->sector = sector;
33315 p->block_id = block_id;
33316 p->blksize = blksize;
33317- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33318+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33319 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33320 }
33321
33322@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33323 return -EIO;
33324 p->sector = cpu_to_be64(req->i.sector);
33325 p->block_id = (unsigned long)req;
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 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33329 if (mdev->state.conn >= C_SYNC_SOURCE &&
33330 mdev->state.conn <= C_PAUSED_SYNC_T)
33331@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33332 {
33333 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33334
33335- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33336- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33337+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33338+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33339 kfree(tconn->current_epoch);
33340
33341 idr_destroy(&tconn->volumes);
33342diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33343index a9eccfc..f5efe87 100644
33344--- a/drivers/block/drbd/drbd_receiver.c
33345+++ b/drivers/block/drbd/drbd_receiver.c
33346@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33347 {
33348 int err;
33349
33350- atomic_set(&mdev->packet_seq, 0);
33351+ atomic_set_unchecked(&mdev->packet_seq, 0);
33352 mdev->peer_seq = 0;
33353
33354 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33355@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33356 do {
33357 next_epoch = NULL;
33358
33359- epoch_size = atomic_read(&epoch->epoch_size);
33360+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33361
33362 switch (ev & ~EV_CLEANUP) {
33363 case EV_PUT:
33364@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33365 rv = FE_DESTROYED;
33366 } else {
33367 epoch->flags = 0;
33368- atomic_set(&epoch->epoch_size, 0);
33369+ atomic_set_unchecked(&epoch->epoch_size, 0);
33370 /* atomic_set(&epoch->active, 0); is already zero */
33371 if (rv == FE_STILL_LIVE)
33372 rv = FE_RECYCLED;
33373@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33374 conn_wait_active_ee_empty(tconn);
33375 drbd_flush(tconn);
33376
33377- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33378+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33379 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33380 if (epoch)
33381 break;
33382@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33383 }
33384
33385 epoch->flags = 0;
33386- atomic_set(&epoch->epoch_size, 0);
33387+ atomic_set_unchecked(&epoch->epoch_size, 0);
33388 atomic_set(&epoch->active, 0);
33389
33390 spin_lock(&tconn->epoch_lock);
33391- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33392+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33393 list_add(&epoch->list, &tconn->current_epoch->list);
33394 tconn->current_epoch = epoch;
33395 tconn->epochs++;
33396@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33397
33398 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33399 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33400- atomic_inc(&tconn->current_epoch->epoch_size);
33401+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33402 err2 = drbd_drain_block(mdev, pi->size);
33403 if (!err)
33404 err = err2;
33405@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33406
33407 spin_lock(&tconn->epoch_lock);
33408 peer_req->epoch = tconn->current_epoch;
33409- atomic_inc(&peer_req->epoch->epoch_size);
33410+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33411 atomic_inc(&peer_req->epoch->active);
33412 spin_unlock(&tconn->epoch_lock);
33413
33414@@ -4346,7 +4346,7 @@ struct data_cmd {
33415 int expect_payload;
33416 size_t pkt_size;
33417 int (*fn)(struct drbd_tconn *, struct packet_info *);
33418-};
33419+} __do_const;
33420
33421 static struct data_cmd drbd_cmd_handler[] = {
33422 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33423@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33424 if (!list_empty(&tconn->current_epoch->list))
33425 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33426 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33427- atomic_set(&tconn->current_epoch->epoch_size, 0);
33428+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33429 tconn->send.seen_any_write_yet = false;
33430
33431 conn_info(tconn, "Connection closed\n");
33432@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33433 struct asender_cmd {
33434 size_t pkt_size;
33435 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33436-};
33437+} __do_const;
33438
33439 static struct asender_cmd asender_tbl[] = {
33440 [P_PING] = { 0, got_Ping },
33441diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33442index 8bc6d39..f492563 100644
33443--- a/drivers/block/loop.c
33444+++ b/drivers/block/loop.c
33445@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33446 mm_segment_t old_fs = get_fs();
33447
33448 set_fs(get_ds());
33449- bw = file->f_op->write(file, buf, len, &pos);
33450+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33451 set_fs(old_fs);
33452 if (likely(bw == len))
33453 return 0;
33454diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33455index d620b44..587561e 100644
33456--- a/drivers/cdrom/cdrom.c
33457+++ b/drivers/cdrom/cdrom.c
33458@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33459 ENSURE(reset, CDC_RESET);
33460 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33461 cdi->mc_flags = 0;
33462- cdo->n_minors = 0;
33463 cdi->options = CDO_USE_FFLAGS;
33464
33465 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33466@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33467 else
33468 cdi->cdda_method = CDDA_OLD;
33469
33470- if (!cdo->generic_packet)
33471- cdo->generic_packet = cdrom_dummy_generic_packet;
33472+ if (!cdo->generic_packet) {
33473+ pax_open_kernel();
33474+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33475+ pax_close_kernel();
33476+ }
33477
33478 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33479 mutex_lock(&cdrom_mutex);
33480@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33481 if (cdi->exit)
33482 cdi->exit(cdi);
33483
33484- cdi->ops->n_minors--;
33485 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33486 }
33487
33488diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33489index d59cdcb..11afddf 100644
33490--- a/drivers/cdrom/gdrom.c
33491+++ b/drivers/cdrom/gdrom.c
33492@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33493 .audio_ioctl = gdrom_audio_ioctl,
33494 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33495 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33496- .n_minors = 1,
33497 };
33498
33499 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33500diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33501index 72bedad..8181ce1 100644
33502--- a/drivers/char/Kconfig
33503+++ b/drivers/char/Kconfig
33504@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33505
33506 config DEVKMEM
33507 bool "/dev/kmem virtual device support"
33508- default y
33509+ default n
33510+ depends on !GRKERNSEC_KMEM
33511 help
33512 Say Y here if you want to support the /dev/kmem device. The
33513 /dev/kmem device is rarely used, but can be used for certain
33514@@ -581,6 +582,7 @@ config DEVPORT
33515 bool
33516 depends on !M68K
33517 depends on ISA || PCI
33518+ depends on !GRKERNSEC_KMEM
33519 default y
33520
33521 source "drivers/s390/char/Kconfig"
33522diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33523index 2e04433..22afc64 100644
33524--- a/drivers/char/agp/frontend.c
33525+++ b/drivers/char/agp/frontend.c
33526@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33527 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33528 return -EFAULT;
33529
33530- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33531+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33532 return -EFAULT;
33533
33534 client = agp_find_client_by_pid(reserve.pid);
33535diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33536index 21cb980..f15107c 100644
33537--- a/drivers/char/genrtc.c
33538+++ b/drivers/char/genrtc.c
33539@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33540 switch (cmd) {
33541
33542 case RTC_PLL_GET:
33543+ memset(&pll, 0, sizeof(pll));
33544 if (get_rtc_pll(&pll))
33545 return -EINVAL;
33546 else
33547diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33548index fe6d4be..89f32100 100644
33549--- a/drivers/char/hpet.c
33550+++ b/drivers/char/hpet.c
33551@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33552 }
33553
33554 static int
33555-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33556+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33557 struct hpet_info *info)
33558 {
33559 struct hpet_timer __iomem *timer;
33560diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33561index 053201b0..8335cce 100644
33562--- a/drivers/char/ipmi/ipmi_msghandler.c
33563+++ b/drivers/char/ipmi/ipmi_msghandler.c
33564@@ -420,7 +420,7 @@ struct ipmi_smi {
33565 struct proc_dir_entry *proc_dir;
33566 char proc_dir_name[10];
33567
33568- atomic_t stats[IPMI_NUM_STATS];
33569+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33570
33571 /*
33572 * run_to_completion duplicate of smb_info, smi_info
33573@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33574
33575
33576 #define ipmi_inc_stat(intf, stat) \
33577- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33578+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33579 #define ipmi_get_stat(intf, stat) \
33580- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33581+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33582
33583 static int is_lan_addr(struct ipmi_addr *addr)
33584 {
33585@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33586 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33587 init_waitqueue_head(&intf->waitq);
33588 for (i = 0; i < IPMI_NUM_STATS; i++)
33589- atomic_set(&intf->stats[i], 0);
33590+ atomic_set_unchecked(&intf->stats[i], 0);
33591
33592 intf->proc_dir = NULL;
33593
33594diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33595index 1c7fdcd..4899100 100644
33596--- a/drivers/char/ipmi/ipmi_si_intf.c
33597+++ b/drivers/char/ipmi/ipmi_si_intf.c
33598@@ -275,7 +275,7 @@ struct smi_info {
33599 unsigned char slave_addr;
33600
33601 /* Counters and things for the proc filesystem. */
33602- atomic_t stats[SI_NUM_STATS];
33603+ atomic_unchecked_t stats[SI_NUM_STATS];
33604
33605 struct task_struct *thread;
33606
33607@@ -284,9 +284,9 @@ struct smi_info {
33608 };
33609
33610 #define smi_inc_stat(smi, stat) \
33611- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33612+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33613 #define smi_get_stat(smi, stat) \
33614- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33615+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33616
33617 #define SI_MAX_PARMS 4
33618
33619@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
33620 atomic_set(&new_smi->req_events, 0);
33621 new_smi->run_to_completion = 0;
33622 for (i = 0; i < SI_NUM_STATS; i++)
33623- atomic_set(&new_smi->stats[i], 0);
33624+ atomic_set_unchecked(&new_smi->stats[i], 0);
33625
33626 new_smi->interrupt_disabled = 1;
33627 atomic_set(&new_smi->stop_operation, 0);
33628diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33629index c6fa3bc..4ca3e42 100644
33630--- a/drivers/char/mem.c
33631+++ b/drivers/char/mem.c
33632@@ -18,6 +18,7 @@
33633 #include <linux/raw.h>
33634 #include <linux/tty.h>
33635 #include <linux/capability.h>
33636+#include <linux/security.h>
33637 #include <linux/ptrace.h>
33638 #include <linux/device.h>
33639 #include <linux/highmem.h>
33640@@ -37,6 +38,10 @@
33641
33642 #define DEVPORT_MINOR 4
33643
33644+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33645+extern const struct file_operations grsec_fops;
33646+#endif
33647+
33648 static inline unsigned long size_inside_page(unsigned long start,
33649 unsigned long size)
33650 {
33651@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33652
33653 while (cursor < to) {
33654 if (!devmem_is_allowed(pfn)) {
33655+#ifdef CONFIG_GRKERNSEC_KMEM
33656+ gr_handle_mem_readwrite(from, to);
33657+#else
33658 printk(KERN_INFO
33659 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33660 current->comm, from, to);
33661+#endif
33662 return 0;
33663 }
33664 cursor += PAGE_SIZE;
33665@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33666 }
33667 return 1;
33668 }
33669+#elif defined(CONFIG_GRKERNSEC_KMEM)
33670+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33671+{
33672+ return 0;
33673+}
33674 #else
33675 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33676 {
33677@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33678
33679 while (count > 0) {
33680 unsigned long remaining;
33681+ char *temp;
33682
33683 sz = size_inside_page(p, count);
33684
33685@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33686 if (!ptr)
33687 return -EFAULT;
33688
33689- remaining = copy_to_user(buf, ptr, sz);
33690+#ifdef CONFIG_PAX_USERCOPY
33691+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33692+ if (!temp) {
33693+ unxlate_dev_mem_ptr(p, ptr);
33694+ return -ENOMEM;
33695+ }
33696+ memcpy(temp, ptr, sz);
33697+#else
33698+ temp = ptr;
33699+#endif
33700+
33701+ remaining = copy_to_user(buf, temp, sz);
33702+
33703+#ifdef CONFIG_PAX_USERCOPY
33704+ kfree(temp);
33705+#endif
33706+
33707 unxlate_dev_mem_ptr(p, ptr);
33708 if (remaining)
33709 return -EFAULT;
33710@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33711 size_t count, loff_t *ppos)
33712 {
33713 unsigned long p = *ppos;
33714- ssize_t low_count, read, sz;
33715+ ssize_t low_count, read, sz, err = 0;
33716 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33717- int err = 0;
33718
33719 read = 0;
33720 if (p < (unsigned long) high_memory) {
33721@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33722 }
33723 #endif
33724 while (low_count > 0) {
33725+ char *temp;
33726+
33727 sz = size_inside_page(p, low_count);
33728
33729 /*
33730@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33731 */
33732 kbuf = xlate_dev_kmem_ptr((char *)p);
33733
33734- if (copy_to_user(buf, kbuf, sz))
33735+#ifdef CONFIG_PAX_USERCOPY
33736+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33737+ if (!temp)
33738+ return -ENOMEM;
33739+ memcpy(temp, kbuf, sz);
33740+#else
33741+ temp = kbuf;
33742+#endif
33743+
33744+ err = copy_to_user(buf, temp, sz);
33745+
33746+#ifdef CONFIG_PAX_USERCOPY
33747+ kfree(temp);
33748+#endif
33749+
33750+ if (err)
33751 return -EFAULT;
33752 buf += sz;
33753 p += sz;
33754@@ -833,6 +880,9 @@ static const struct memdev {
33755 #ifdef CONFIG_CRASH_DUMP
33756 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33757 #endif
33758+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33759+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33760+#endif
33761 };
33762
33763 static int memory_open(struct inode *inode, struct file *filp)
33764diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33765index 9df78e2..01ba9ae 100644
33766--- a/drivers/char/nvram.c
33767+++ b/drivers/char/nvram.c
33768@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33769
33770 spin_unlock_irq(&rtc_lock);
33771
33772- if (copy_to_user(buf, contents, tmp - contents))
33773+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33774 return -EFAULT;
33775
33776 *ppos = i;
33777diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33778index b66eaa0..2619d1b 100644
33779--- a/drivers/char/pcmcia/synclink_cs.c
33780+++ b/drivers/char/pcmcia/synclink_cs.c
33781@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33782
33783 if (debug_level >= DEBUG_LEVEL_INFO)
33784 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33785- __FILE__,__LINE__, info->device_name, port->count);
33786+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
33787
33788- WARN_ON(!port->count);
33789+ WARN_ON(!atomic_read(&port->count));
33790
33791 if (tty_port_close_start(port, tty, filp) == 0)
33792 goto cleanup;
33793@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33794 cleanup:
33795 if (debug_level >= DEBUG_LEVEL_INFO)
33796 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
33797- tty->driver->name, port->count);
33798+ tty->driver->name, atomic_read(&port->count));
33799 }
33800
33801 /* Wait until the transmitter is empty.
33802@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33803
33804 if (debug_level >= DEBUG_LEVEL_INFO)
33805 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
33806- __FILE__,__LINE__,tty->driver->name, port->count);
33807+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
33808
33809 /* If port is closing, signal caller to try again */
33810 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
33811@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33812 goto cleanup;
33813 }
33814 spin_lock(&port->lock);
33815- port->count++;
33816+ atomic_inc(&port->count);
33817 spin_unlock(&port->lock);
33818 spin_unlock_irqrestore(&info->netlock, flags);
33819
33820- if (port->count == 1) {
33821+ if (atomic_read(&port->count) == 1) {
33822 /* 1st open on this device, init hardware */
33823 retval = startup(info, tty);
33824 if (retval < 0)
33825@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
33826 unsigned short new_crctype;
33827
33828 /* return error if TTY interface open */
33829- if (info->port.count)
33830+ if (atomic_read(&info->port.count))
33831 return -EBUSY;
33832
33833 switch (encoding)
33834@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
33835
33836 /* arbitrate between network and tty opens */
33837 spin_lock_irqsave(&info->netlock, flags);
33838- if (info->port.count != 0 || info->netcount != 0) {
33839+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
33840 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
33841 spin_unlock_irqrestore(&info->netlock, flags);
33842 return -EBUSY;
33843@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33844 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
33845
33846 /* return error if TTY interface open */
33847- if (info->port.count)
33848+ if (atomic_read(&info->port.count))
33849 return -EBUSY;
33850
33851 if (cmd != SIOCWANDEV)
33852diff --git a/drivers/char/random.c b/drivers/char/random.c
33853index 57d4b15..253207b 100644
33854--- a/drivers/char/random.c
33855+++ b/drivers/char/random.c
33856@@ -272,8 +272,13 @@
33857 /*
33858 * Configuration information
33859 */
33860+#ifdef CONFIG_GRKERNSEC_RANDNET
33861+#define INPUT_POOL_WORDS 512
33862+#define OUTPUT_POOL_WORDS 128
33863+#else
33864 #define INPUT_POOL_WORDS 128
33865 #define OUTPUT_POOL_WORDS 32
33866+#endif
33867 #define SEC_XFER_SIZE 512
33868 #define EXTRACT_SIZE 10
33869
33870@@ -313,10 +318,17 @@ static struct poolinfo {
33871 int poolwords;
33872 int tap1, tap2, tap3, tap4, tap5;
33873 } poolinfo_table[] = {
33874+#ifdef CONFIG_GRKERNSEC_RANDNET
33875+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33876+ { 512, 411, 308, 208, 104, 1 },
33877+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33878+ { 128, 103, 76, 51, 25, 1 },
33879+#else
33880 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33881 { 128, 103, 76, 51, 25, 1 },
33882 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33883 { 32, 26, 20, 14, 7, 1 },
33884+#endif
33885 #if 0
33886 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33887 { 2048, 1638, 1231, 819, 411, 1 },
33888@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33889 input_rotate += i ? 7 : 14;
33890 }
33891
33892- ACCESS_ONCE(r->input_rotate) = input_rotate;
33893- ACCESS_ONCE(r->add_ptr) = i;
33894+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33895+ ACCESS_ONCE_RW(r->add_ptr) = i;
33896 smp_wmb();
33897
33898 if (out)
33899@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33900
33901 extract_buf(r, tmp);
33902 i = min_t(int, nbytes, EXTRACT_SIZE);
33903- if (copy_to_user(buf, tmp, i)) {
33904+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33905 ret = -EFAULT;
33906 break;
33907 }
33908@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33909 #include <linux/sysctl.h>
33910
33911 static int min_read_thresh = 8, min_write_thresh;
33912-static int max_read_thresh = INPUT_POOL_WORDS * 32;
33913+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33914 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33915 static char sysctl_bootid[16];
33916
33917@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
33918 static int proc_do_uuid(ctl_table *table, int write,
33919 void __user *buffer, size_t *lenp, loff_t *ppos)
33920 {
33921- ctl_table fake_table;
33922+ ctl_table_no_const fake_table;
33923 unsigned char buf[64], tmp_uuid[16], *uuid;
33924
33925 uuid = table->data;
33926diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33927index d780295..b29f3a8 100644
33928--- a/drivers/char/sonypi.c
33929+++ b/drivers/char/sonypi.c
33930@@ -54,6 +54,7 @@
33931
33932 #include <asm/uaccess.h>
33933 #include <asm/io.h>
33934+#include <asm/local.h>
33935
33936 #include <linux/sonypi.h>
33937
33938@@ -490,7 +491,7 @@ static struct sonypi_device {
33939 spinlock_t fifo_lock;
33940 wait_queue_head_t fifo_proc_list;
33941 struct fasync_struct *fifo_async;
33942- int open_count;
33943+ local_t open_count;
33944 int model;
33945 struct input_dev *input_jog_dev;
33946 struct input_dev *input_key_dev;
33947@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33948 static int sonypi_misc_release(struct inode *inode, struct file *file)
33949 {
33950 mutex_lock(&sonypi_device.lock);
33951- sonypi_device.open_count--;
33952+ local_dec(&sonypi_device.open_count);
33953 mutex_unlock(&sonypi_device.lock);
33954 return 0;
33955 }
33956@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33957 {
33958 mutex_lock(&sonypi_device.lock);
33959 /* Flush input queue on first open */
33960- if (!sonypi_device.open_count)
33961+ if (!local_read(&sonypi_device.open_count))
33962 kfifo_reset(&sonypi_device.fifo);
33963- sonypi_device.open_count++;
33964+ local_inc(&sonypi_device.open_count);
33965 mutex_unlock(&sonypi_device.lock);
33966
33967 return 0;
33968diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33969index 93211df..c7805f7 100644
33970--- a/drivers/char/tpm/tpm.c
33971+++ b/drivers/char/tpm/tpm.c
33972@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33973 chip->vendor.req_complete_val)
33974 goto out_recv;
33975
33976- if ((status == chip->vendor.req_canceled)) {
33977+ if (status == chip->vendor.req_canceled) {
33978 dev_err(chip->dev, "Operation Canceled\n");
33979 rc = -ECANCELED;
33980 goto out;
33981diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33982index 56051d0..11cf3b7 100644
33983--- a/drivers/char/tpm/tpm_acpi.c
33984+++ b/drivers/char/tpm/tpm_acpi.c
33985@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33986 virt = acpi_os_map_memory(start, len);
33987 if (!virt) {
33988 kfree(log->bios_event_log);
33989+ log->bios_event_log = NULL;
33990 printk("%s: ERROR - Unable to map memory\n", __func__);
33991 return -EIO;
33992 }
33993
33994- memcpy_fromio(log->bios_event_log, virt, len);
33995+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33996
33997 acpi_os_unmap_memory(virt, len);
33998 return 0;
33999diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34000index 84ddc55..1d32f1e 100644
34001--- a/drivers/char/tpm/tpm_eventlog.c
34002+++ b/drivers/char/tpm/tpm_eventlog.c
34003@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34004 event = addr;
34005
34006 if ((event->event_type == 0 && event->event_size == 0) ||
34007- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34008+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34009 return NULL;
34010
34011 return addr;
34012@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34013 return NULL;
34014
34015 if ((event->event_type == 0 && event->event_size == 0) ||
34016- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34017+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34018 return NULL;
34019
34020 (*pos)++;
34021@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34022 int i;
34023
34024 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34025- seq_putc(m, data[i]);
34026+ if (!seq_putc(m, data[i]))
34027+ return -EFAULT;
34028
34029 return 0;
34030 }
34031diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34032index ee4dbea..69c817b 100644
34033--- a/drivers/char/virtio_console.c
34034+++ b/drivers/char/virtio_console.c
34035@@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34036 if (to_user) {
34037 ssize_t ret;
34038
34039- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34040+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34041 if (ret)
34042 return -EFAULT;
34043 } else {
34044@@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34045 if (!port_has_data(port) && !port->host_connected)
34046 return 0;
34047
34048- return fill_readbuf(port, ubuf, count, true);
34049+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34050 }
34051
34052 static int wait_port_writable(struct port *port, bool nonblock)
34053diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
34054index 8ae1a61..9c00613 100644
34055--- a/drivers/clocksource/arm_generic.c
34056+++ b/drivers/clocksource/arm_generic.c
34057@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34058 return NOTIFY_OK;
34059 }
34060
34061-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34062+static struct notifier_block arch_timer_cpu_nb = {
34063 .notifier_call = arch_timer_cpu_notify,
34064 };
34065
34066diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34067index 7b0d49d..134fac9 100644
34068--- a/drivers/cpufreq/acpi-cpufreq.c
34069+++ b/drivers/cpufreq/acpi-cpufreq.c
34070@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34071 return sprintf(buf, "%u\n", boost_enabled);
34072 }
34073
34074-static struct global_attr global_boost = __ATTR(boost, 0644,
34075+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34076 show_global_boost,
34077 store_global_boost);
34078
34079@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34080 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34081 per_cpu(acfreq_data, cpu) = data;
34082
34083- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34084- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34085+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34086+ pax_open_kernel();
34087+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34088+ pax_close_kernel();
34089+ }
34090
34091 result = acpi_processor_register_performance(data->acpi_data, cpu);
34092 if (result)
34093@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34094 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34095 break;
34096 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34097- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34098+ pax_open_kernel();
34099+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34100+ pax_close_kernel();
34101 policy->cur = get_cur_freq_on_cpu(cpu);
34102 break;
34103 default:
34104@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34105 acpi_processor_notify_smm(THIS_MODULE);
34106
34107 /* Check for APERF/MPERF support in hardware */
34108- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34109- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34110+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34111+ pax_open_kernel();
34112+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34113+ pax_close_kernel();
34114+ }
34115
34116 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34117 for (i = 0; i < perf->state_count; i++)
34118diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34119index 1f93dbd..305cef1 100644
34120--- a/drivers/cpufreq/cpufreq.c
34121+++ b/drivers/cpufreq/cpufreq.c
34122@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34123 return NOTIFY_OK;
34124 }
34125
34126-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34127+static struct notifier_block cpufreq_cpu_notifier = {
34128 .notifier_call = cpufreq_cpu_callback,
34129 };
34130
34131@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34132
34133 pr_debug("trying to register driver %s\n", driver_data->name);
34134
34135- if (driver_data->setpolicy)
34136- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34137+ if (driver_data->setpolicy) {
34138+ pax_open_kernel();
34139+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34140+ pax_close_kernel();
34141+ }
34142
34143 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34144 if (cpufreq_driver) {
34145diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34146index 6c5f1d3..c7e2f35e 100644
34147--- a/drivers/cpufreq/cpufreq_governor.c
34148+++ b/drivers/cpufreq/cpufreq_governor.c
34149@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34150 * governor, thus we are bound to jiffes/HZ
34151 */
34152 if (dbs_data->governor == GOV_CONSERVATIVE) {
34153- struct cs_ops *ops = dbs_data->gov_ops;
34154+ const struct cs_ops *ops = dbs_data->gov_ops;
34155
34156 cpufreq_register_notifier(ops->notifier_block,
34157 CPUFREQ_TRANSITION_NOTIFIER);
34158@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34159 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
34160 jiffies_to_usecs(10);
34161 } else {
34162- struct od_ops *ops = dbs_data->gov_ops;
34163+ const struct od_ops *ops = dbs_data->gov_ops;
34164
34165 od_tuners->io_is_busy = ops->io_busy();
34166 }
34167@@ -268,7 +268,7 @@ second_time:
34168 cs_dbs_info->enable = 1;
34169 cs_dbs_info->requested_freq = policy->cur;
34170 } else {
34171- struct od_ops *ops = dbs_data->gov_ops;
34172+ const struct od_ops *ops = dbs_data->gov_ops;
34173 od_dbs_info->rate_mult = 1;
34174 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
34175 ops->powersave_bias_init_cpu(cpu);
34176@@ -289,7 +289,7 @@ second_time:
34177 mutex_destroy(&cpu_cdbs->timer_mutex);
34178 dbs_data->enable--;
34179 if (!dbs_data->enable) {
34180- struct cs_ops *ops = dbs_data->gov_ops;
34181+ const struct cs_ops *ops = dbs_data->gov_ops;
34182
34183 sysfs_remove_group(cpufreq_global_kobject,
34184 dbs_data->attr_group);
34185diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34186index f661654..6c8e638 100644
34187--- a/drivers/cpufreq/cpufreq_governor.h
34188+++ b/drivers/cpufreq/cpufreq_governor.h
34189@@ -142,7 +142,7 @@ struct dbs_data {
34190 void (*gov_check_cpu)(int cpu, unsigned int load);
34191
34192 /* Governor specific ops, see below */
34193- void *gov_ops;
34194+ const void *gov_ops;
34195 };
34196
34197 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34198diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34199index 9d7732b..0b1a793 100644
34200--- a/drivers/cpufreq/cpufreq_stats.c
34201+++ b/drivers/cpufreq/cpufreq_stats.c
34202@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34203 }
34204
34205 /* priority=1 so this will get called before cpufreq_remove_dev */
34206-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34207+static struct notifier_block cpufreq_stat_cpu_notifier = {
34208 .notifier_call = cpufreq_stat_cpu_callback,
34209 .priority = 1,
34210 };
34211diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34212index 827629c9..0bc6a03 100644
34213--- a/drivers/cpufreq/p4-clockmod.c
34214+++ b/drivers/cpufreq/p4-clockmod.c
34215@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34216 case 0x0F: /* Core Duo */
34217 case 0x16: /* Celeron Core */
34218 case 0x1C: /* Atom */
34219- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34220+ pax_open_kernel();
34221+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34222+ pax_close_kernel();
34223 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34224 case 0x0D: /* Pentium M (Dothan) */
34225- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34226+ pax_open_kernel();
34227+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34228+ pax_close_kernel();
34229 /* fall through */
34230 case 0x09: /* Pentium M (Banias) */
34231 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34232@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34233
34234 /* on P-4s, the TSC runs with constant frequency independent whether
34235 * throttling is active or not. */
34236- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34237+ pax_open_kernel();
34238+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34239+ pax_close_kernel();
34240
34241 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34242 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34243diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34244index 3a953d5..f5993f6 100644
34245--- a/drivers/cpufreq/speedstep-centrino.c
34246+++ b/drivers/cpufreq/speedstep-centrino.c
34247@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34248 !cpu_has(cpu, X86_FEATURE_EST))
34249 return -ENODEV;
34250
34251- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34252- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34253+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34254+ pax_open_kernel();
34255+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34256+ pax_close_kernel();
34257+ }
34258
34259 if (policy->cpu != 0)
34260 return -ENODEV;
34261diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34262index e1f6860..f8de20b 100644
34263--- a/drivers/cpuidle/cpuidle.c
34264+++ b/drivers/cpuidle/cpuidle.c
34265@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
34266
34267 static void poll_idle_init(struct cpuidle_driver *drv)
34268 {
34269- struct cpuidle_state *state = &drv->states[0];
34270+ cpuidle_state_no_const *state = &drv->states[0];
34271
34272 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34273 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34274diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34275index ea2f8e7..70ac501 100644
34276--- a/drivers/cpuidle/governor.c
34277+++ b/drivers/cpuidle/governor.c
34278@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34279 mutex_lock(&cpuidle_lock);
34280 if (__cpuidle_find_governor(gov->name) == NULL) {
34281 ret = 0;
34282- list_add_tail(&gov->governor_list, &cpuidle_governors);
34283+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34284 if (!cpuidle_curr_governor ||
34285 cpuidle_curr_governor->rating < gov->rating)
34286 cpuidle_switch_governor(gov);
34287@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34288 new_gov = cpuidle_replace_governor(gov->rating);
34289 cpuidle_switch_governor(new_gov);
34290 }
34291- list_del(&gov->governor_list);
34292+ pax_list_del((struct list_head *)&gov->governor_list);
34293 mutex_unlock(&cpuidle_lock);
34294 }
34295
34296diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34297index 428754a..8bdf9cc 100644
34298--- a/drivers/cpuidle/sysfs.c
34299+++ b/drivers/cpuidle/sysfs.c
34300@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34301 NULL
34302 };
34303
34304-static struct attribute_group cpuidle_attr_group = {
34305+static attribute_group_no_const cpuidle_attr_group = {
34306 .attrs = cpuidle_default_attrs,
34307 .name = "cpuidle",
34308 };
34309diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34310index 3b36797..289c16a 100644
34311--- a/drivers/devfreq/devfreq.c
34312+++ b/drivers/devfreq/devfreq.c
34313@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34314 goto err_out;
34315 }
34316
34317- list_add(&governor->node, &devfreq_governor_list);
34318+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34319
34320 list_for_each_entry(devfreq, &devfreq_list, node) {
34321 int ret = 0;
34322@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34323 }
34324 }
34325
34326- list_del(&governor->node);
34327+ pax_list_del((struct list_head *)&governor->node);
34328 err_out:
34329 mutex_unlock(&devfreq_list_lock);
34330
34331diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34332index b70709b..1d8d02a 100644
34333--- a/drivers/dma/sh/shdma.c
34334+++ b/drivers/dma/sh/shdma.c
34335@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34336 return ret;
34337 }
34338
34339-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34340+static struct notifier_block sh_dmae_nmi_notifier = {
34341 .notifier_call = sh_dmae_nmi_handler,
34342
34343 /* Run before NMI debug handler and KGDB */
34344diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34345index 0ca1ca7..6e6f454 100644
34346--- a/drivers/edac/edac_mc_sysfs.c
34347+++ b/drivers/edac/edac_mc_sysfs.c
34348@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34349 struct dev_ch_attribute {
34350 struct device_attribute attr;
34351 int channel;
34352-};
34353+} __do_const;
34354
34355 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34356 struct dev_ch_attribute dev_attr_legacy_##_name = \
34357diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34358index 0056c4d..23b54d9 100644
34359--- a/drivers/edac/edac_pci_sysfs.c
34360+++ b/drivers/edac/edac_pci_sysfs.c
34361@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34362 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34363 static int edac_pci_poll_msec = 1000; /* one second workq period */
34364
34365-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34366-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34367+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34368+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34369
34370 static struct kobject *edac_pci_top_main_kobj;
34371 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34372@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34373 void *value;
34374 ssize_t(*show) (void *, char *);
34375 ssize_t(*store) (void *, const char *, size_t);
34376-};
34377+} __do_const;
34378
34379 /* Set of show/store abstract level functions for PCI Parity object */
34380 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34381@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34382 edac_printk(KERN_CRIT, EDAC_PCI,
34383 "Signaled System Error on %s\n",
34384 pci_name(dev));
34385- atomic_inc(&pci_nonparity_count);
34386+ atomic_inc_unchecked(&pci_nonparity_count);
34387 }
34388
34389 if (status & (PCI_STATUS_PARITY)) {
34390@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34391 "Master Data Parity Error on %s\n",
34392 pci_name(dev));
34393
34394- atomic_inc(&pci_parity_count);
34395+ atomic_inc_unchecked(&pci_parity_count);
34396 }
34397
34398 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34399@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34400 "Detected 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
34408@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34409 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34410 "Signaled System Error on %s\n",
34411 pci_name(dev));
34412- atomic_inc(&pci_nonparity_count);
34413+ atomic_inc_unchecked(&pci_nonparity_count);
34414 }
34415
34416 if (status & (PCI_STATUS_PARITY)) {
34417@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34418 "Master Data Parity Error on "
34419 "%s\n", pci_name(dev));
34420
34421- atomic_inc(&pci_parity_count);
34422+ atomic_inc_unchecked(&pci_parity_count);
34423 }
34424
34425 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34426@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34427 "Detected Parity Error on %s\n",
34428 pci_name(dev));
34429
34430- atomic_inc(&pci_parity_count);
34431+ atomic_inc_unchecked(&pci_parity_count);
34432 }
34433 }
34434 }
34435@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34436 if (!check_pci_errors)
34437 return;
34438
34439- before_count = atomic_read(&pci_parity_count);
34440+ before_count = atomic_read_unchecked(&pci_parity_count);
34441
34442 /* scan all PCI devices looking for a Parity Error on devices and
34443 * bridges.
34444@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34445 /* Only if operator has selected panic on PCI Error */
34446 if (edac_pci_get_panic_on_pe()) {
34447 /* If the count is different 'after' from 'before' */
34448- if (before_count != atomic_read(&pci_parity_count))
34449+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34450 panic("EDAC: PCI Parity Error");
34451 }
34452 }
34453diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34454index 6796799..99e8377 100644
34455--- a/drivers/edac/mce_amd.h
34456+++ b/drivers/edac/mce_amd.h
34457@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34458 struct amd_decoder_ops {
34459 bool (*mc0_mce)(u16, u8);
34460 bool (*mc1_mce)(u16, u8);
34461-};
34462+} __no_const;
34463
34464 void amd_report_gart_errors(bool);
34465 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34466diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34467index 57ea7f4..789e3c3 100644
34468--- a/drivers/firewire/core-card.c
34469+++ b/drivers/firewire/core-card.c
34470@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34471
34472 void fw_core_remove_card(struct fw_card *card)
34473 {
34474- struct fw_card_driver dummy_driver = dummy_driver_template;
34475+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34476
34477 card->driver->update_phy_reg(card, 4,
34478 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34479diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34480index f8d2287..5aaf4db 100644
34481--- a/drivers/firewire/core-cdev.c
34482+++ b/drivers/firewire/core-cdev.c
34483@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34484 int ret;
34485
34486 if ((request->channels == 0 && request->bandwidth == 0) ||
34487- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34488- request->bandwidth < 0)
34489+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34490 return -EINVAL;
34491
34492 r = kmalloc(sizeof(*r), GFP_KERNEL);
34493diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34494index af3e8aa..eb2f227 100644
34495--- a/drivers/firewire/core-device.c
34496+++ b/drivers/firewire/core-device.c
34497@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34498 struct config_rom_attribute {
34499 struct device_attribute attr;
34500 u32 key;
34501-};
34502+} __do_const;
34503
34504 static ssize_t show_immediate(struct device *dev,
34505 struct device_attribute *dattr, char *buf)
34506diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34507index 28a94c7..58da63a 100644
34508--- a/drivers/firewire/core-transaction.c
34509+++ b/drivers/firewire/core-transaction.c
34510@@ -38,6 +38,7 @@
34511 #include <linux/timer.h>
34512 #include <linux/types.h>
34513 #include <linux/workqueue.h>
34514+#include <linux/sched.h>
34515
34516 #include <asm/byteorder.h>
34517
34518diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34519index 515a42c..5ecf3ba 100644
34520--- a/drivers/firewire/core.h
34521+++ b/drivers/firewire/core.h
34522@@ -111,6 +111,7 @@ struct fw_card_driver {
34523
34524 int (*stop_iso)(struct fw_iso_context *ctx);
34525 };
34526+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34527
34528 void fw_card_initialize(struct fw_card *card,
34529 const struct fw_card_driver *driver, struct device *device);
34530diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34531index 94a58a0..f5eba42 100644
34532--- a/drivers/firmware/dmi-id.c
34533+++ b/drivers/firmware/dmi-id.c
34534@@ -16,7 +16,7 @@
34535 struct dmi_device_attribute{
34536 struct device_attribute dev_attr;
34537 int field;
34538-};
34539+} __do_const;
34540 #define to_dmi_dev_attr(_dev_attr) \
34541 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34542
34543diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34544index 4cd392d..4b629e1 100644
34545--- a/drivers/firmware/dmi_scan.c
34546+++ b/drivers/firmware/dmi_scan.c
34547@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
34548 }
34549 }
34550 else {
34551- /*
34552- * no iounmap() for that ioremap(); it would be a no-op, but
34553- * it's so early in setup that sucker gets confused into doing
34554- * what it shouldn't if we actually call it.
34555- */
34556 p = dmi_ioremap(0xF0000, 0x10000);
34557 if (p == NULL)
34558 goto error;
34559@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34560 if (buf == NULL)
34561 return -1;
34562
34563- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34564+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34565
34566 iounmap(buf);
34567 return 0;
34568diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34569index 2a2e145..73745e79 100644
34570--- a/drivers/firmware/efivars.c
34571+++ b/drivers/firmware/efivars.c
34572@@ -133,7 +133,7 @@ struct efivar_attribute {
34573 };
34574
34575 static struct efivars __efivars;
34576-static struct efivar_operations ops;
34577+static efivar_operations_no_const ops __read_only;
34578
34579 #define PSTORE_EFI_ATTRIBUTES \
34580 (EFI_VARIABLE_NON_VOLATILE | \
34581@@ -1798,7 +1798,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34582 static int
34583 create_efivars_bin_attributes(struct efivars *efivars)
34584 {
34585- struct bin_attribute *attr;
34586+ bin_attribute_no_const *attr;
34587 int error;
34588
34589 /* new_var */
34590diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34591index 2a90ba6..07f3733 100644
34592--- a/drivers/firmware/google/memconsole.c
34593+++ b/drivers/firmware/google/memconsole.c
34594@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34595 if (!found_memconsole())
34596 return -ENODEV;
34597
34598- memconsole_bin_attr.size = memconsole_length;
34599+ pax_open_kernel();
34600+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34601+ pax_close_kernel();
34602
34603 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34604
34605diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34606index 6f2306d..af9476a 100644
34607--- a/drivers/gpio/gpio-ich.c
34608+++ b/drivers/gpio/gpio-ich.c
34609@@ -69,7 +69,7 @@ struct ichx_desc {
34610 /* Some chipsets have quirks, let these use their own request/get */
34611 int (*request)(struct gpio_chip *chip, unsigned offset);
34612 int (*get)(struct gpio_chip *chip, unsigned offset);
34613-};
34614+} __do_const;
34615
34616 static struct {
34617 spinlock_t lock;
34618diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34619index 9902732..64b62dd 100644
34620--- a/drivers/gpio/gpio-vr41xx.c
34621+++ b/drivers/gpio/gpio-vr41xx.c
34622@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34623 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34624 maskl, pendl, maskh, pendh);
34625
34626- atomic_inc(&irq_err_count);
34627+ atomic_inc_unchecked(&irq_err_count);
34628
34629 return -EINVAL;
34630 }
34631diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34632index 7b2d378..cc947ea 100644
34633--- a/drivers/gpu/drm/drm_crtc_helper.c
34634+++ b/drivers/gpu/drm/drm_crtc_helper.c
34635@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34636 struct drm_crtc *tmp;
34637 int crtc_mask = 1;
34638
34639- WARN(!crtc, "checking null crtc?\n");
34640+ BUG_ON(!crtc);
34641
34642 dev = crtc->dev;
34643
34644diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34645index be174ca..7f38143 100644
34646--- a/drivers/gpu/drm/drm_drv.c
34647+++ b/drivers/gpu/drm/drm_drv.c
34648@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
34649 /**
34650 * Copy and IOCTL return string to user space
34651 */
34652-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34653+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34654 {
34655 int len;
34656
34657@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
34658 struct drm_file *file_priv = filp->private_data;
34659 struct drm_device *dev;
34660 struct drm_ioctl_desc *ioctl;
34661- drm_ioctl_t *func;
34662+ drm_ioctl_no_const_t func;
34663 unsigned int nr = DRM_IOCTL_NR(cmd);
34664 int retcode = -EINVAL;
34665 char stack_kdata[128];
34666@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
34667 return -ENODEV;
34668
34669 atomic_inc(&dev->ioctl_count);
34670- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34671+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34672 ++file_priv->ioctl_count;
34673
34674 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34675diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34676index 133b413..fd68225 100644
34677--- a/drivers/gpu/drm/drm_fops.c
34678+++ b/drivers/gpu/drm/drm_fops.c
34679@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34680 }
34681
34682 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34683- atomic_set(&dev->counts[i], 0);
34684+ atomic_set_unchecked(&dev->counts[i], 0);
34685
34686 dev->sigdata.lock = NULL;
34687
34688@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
34689 if (drm_device_is_unplugged(dev))
34690 return -ENODEV;
34691
34692- if (!dev->open_count++)
34693+ if (local_inc_return(&dev->open_count) == 1)
34694 need_setup = 1;
34695 mutex_lock(&dev->struct_mutex);
34696 old_mapping = dev->dev_mapping;
34697@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
34698 retcode = drm_open_helper(inode, filp, dev);
34699 if (retcode)
34700 goto err_undo;
34701- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34702+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34703 if (need_setup) {
34704 retcode = drm_setup(dev);
34705 if (retcode)
34706@@ -164,7 +164,7 @@ err_undo:
34707 iput(container_of(dev->dev_mapping, struct inode, i_data));
34708 dev->dev_mapping = old_mapping;
34709 mutex_unlock(&dev->struct_mutex);
34710- dev->open_count--;
34711+ local_dec(&dev->open_count);
34712 return retcode;
34713 }
34714 EXPORT_SYMBOL(drm_open);
34715@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
34716
34717 mutex_lock(&drm_global_mutex);
34718
34719- DRM_DEBUG("open_count = %d\n", dev->open_count);
34720+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34721
34722 if (dev->driver->preclose)
34723 dev->driver->preclose(dev, file_priv);
34724@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
34725 * Begin inline drm_release
34726 */
34727
34728- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34729+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34730 task_pid_nr(current),
34731 (long)old_encode_dev(file_priv->minor->device),
34732- dev->open_count);
34733+ local_read(&dev->open_count));
34734
34735 /* Release any auth tokens that might point to this file_priv,
34736 (do that under the drm_global_mutex) */
34737@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
34738 * End inline drm_release
34739 */
34740
34741- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34742- if (!--dev->open_count) {
34743+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34744+ if (local_dec_and_test(&dev->open_count)) {
34745 if (atomic_read(&dev->ioctl_count)) {
34746 DRM_ERROR("Device busy: %d\n",
34747 atomic_read(&dev->ioctl_count));
34748diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34749index f731116..629842c 100644
34750--- a/drivers/gpu/drm/drm_global.c
34751+++ b/drivers/gpu/drm/drm_global.c
34752@@ -36,7 +36,7 @@
34753 struct drm_global_item {
34754 struct mutex mutex;
34755 void *object;
34756- int refcount;
34757+ atomic_t refcount;
34758 };
34759
34760 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34761@@ -49,7 +49,7 @@ void drm_global_init(void)
34762 struct drm_global_item *item = &glob[i];
34763 mutex_init(&item->mutex);
34764 item->object = NULL;
34765- item->refcount = 0;
34766+ atomic_set(&item->refcount, 0);
34767 }
34768 }
34769
34770@@ -59,7 +59,7 @@ void drm_global_release(void)
34771 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34772 struct drm_global_item *item = &glob[i];
34773 BUG_ON(item->object != NULL);
34774- BUG_ON(item->refcount != 0);
34775+ BUG_ON(atomic_read(&item->refcount) != 0);
34776 }
34777 }
34778
34779@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34780 void *object;
34781
34782 mutex_lock(&item->mutex);
34783- if (item->refcount == 0) {
34784+ if (atomic_read(&item->refcount) == 0) {
34785 item->object = kzalloc(ref->size, GFP_KERNEL);
34786 if (unlikely(item->object == NULL)) {
34787 ret = -ENOMEM;
34788@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34789 goto out_err;
34790
34791 }
34792- ++item->refcount;
34793+ atomic_inc(&item->refcount);
34794 ref->object = item->object;
34795 object = item->object;
34796 mutex_unlock(&item->mutex);
34797@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34798 struct drm_global_item *item = &glob[ref->global_type];
34799
34800 mutex_lock(&item->mutex);
34801- BUG_ON(item->refcount == 0);
34802+ BUG_ON(atomic_read(&item->refcount) == 0);
34803 BUG_ON(ref->object != item->object);
34804- if (--item->refcount == 0) {
34805+ if (atomic_dec_and_test(&item->refcount)) {
34806 ref->release(ref);
34807 item->object = NULL;
34808 }
34809diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
34810index d4b20ce..77a8d41 100644
34811--- a/drivers/gpu/drm/drm_info.c
34812+++ b/drivers/gpu/drm/drm_info.c
34813@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
34814 struct drm_local_map *map;
34815 struct drm_map_list *r_list;
34816
34817- /* Hardcoded from _DRM_FRAME_BUFFER,
34818- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
34819- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
34820- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
34821+ static const char * const types[] = {
34822+ [_DRM_FRAME_BUFFER] = "FB",
34823+ [_DRM_REGISTERS] = "REG",
34824+ [_DRM_SHM] = "SHM",
34825+ [_DRM_AGP] = "AGP",
34826+ [_DRM_SCATTER_GATHER] = "SG",
34827+ [_DRM_CONSISTENT] = "PCI",
34828+ [_DRM_GEM] = "GEM" };
34829 const char *type;
34830 int i;
34831
34832@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
34833 map = r_list->map;
34834 if (!map)
34835 continue;
34836- if (map->type < 0 || map->type > 5)
34837+ if (map->type >= ARRAY_SIZE(types))
34838 type = "??";
34839 else
34840 type = types[map->type];
34841@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
34842 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
34843 vma->vm_flags & VM_LOCKED ? 'l' : '-',
34844 vma->vm_flags & VM_IO ? 'i' : '-',
34845+#ifdef CONFIG_GRKERNSEC_HIDESYM
34846+ 0);
34847+#else
34848 vma->vm_pgoff);
34849+#endif
34850
34851 #if defined(__i386__)
34852 pgprot = pgprot_val(vma->vm_page_prot);
34853diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
34854index 2f4c434..dd12cd2 100644
34855--- a/drivers/gpu/drm/drm_ioc32.c
34856+++ b/drivers/gpu/drm/drm_ioc32.c
34857@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
34858 request = compat_alloc_user_space(nbytes);
34859 if (!access_ok(VERIFY_WRITE, request, nbytes))
34860 return -EFAULT;
34861- list = (struct drm_buf_desc *) (request + 1);
34862+ list = (struct drm_buf_desc __user *) (request + 1);
34863
34864 if (__put_user(count, &request->count)
34865 || __put_user(list, &request->list))
34866@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(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_pub *) (request + 1);
34871+ list = (struct drm_buf_pub __user *) (request + 1);
34872
34873 if (__put_user(count, &request->count)
34874 || __put_user(list, &request->list))
34875@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
34876 return 0;
34877 }
34878
34879-drm_ioctl_compat_t *drm_compat_ioctls[] = {
34880+drm_ioctl_compat_t drm_compat_ioctls[] = {
34881 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
34882 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
34883 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
34884@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
34885 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34886 {
34887 unsigned int nr = DRM_IOCTL_NR(cmd);
34888- drm_ioctl_compat_t *fn;
34889 int ret;
34890
34891 /* Assume that ioctls without an explicit compat routine will just
34892@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34893 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
34894 return drm_ioctl(filp, cmd, arg);
34895
34896- fn = drm_compat_ioctls[nr];
34897-
34898- if (fn != NULL)
34899- ret = (*fn) (filp, cmd, arg);
34900+ if (drm_compat_ioctls[nr] != NULL)
34901+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
34902 else
34903 ret = drm_ioctl(filp, cmd, arg);
34904
34905diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
34906index e77bd8b..1571b85 100644
34907--- a/drivers/gpu/drm/drm_ioctl.c
34908+++ b/drivers/gpu/drm/drm_ioctl.c
34909@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
34910 stats->data[i].value =
34911 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
34912 else
34913- stats->data[i].value = atomic_read(&dev->counts[i]);
34914+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
34915 stats->data[i].type = dev->types[i];
34916 }
34917
34918diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
34919index d752c96..fe08455 100644
34920--- a/drivers/gpu/drm/drm_lock.c
34921+++ b/drivers/gpu/drm/drm_lock.c
34922@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34923 if (drm_lock_take(&master->lock, lock->context)) {
34924 master->lock.file_priv = file_priv;
34925 master->lock.lock_time = jiffies;
34926- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
34927+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
34928 break; /* Got lock */
34929 }
34930
34931@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34932 return -EINVAL;
34933 }
34934
34935- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
34936+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
34937
34938 if (drm_lock_free(&master->lock, lock->context)) {
34939 /* FIXME: Should really bail out here. */
34940diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
34941index 200e104..59facda 100644
34942--- a/drivers/gpu/drm/drm_stub.c
34943+++ b/drivers/gpu/drm/drm_stub.c
34944@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
34945
34946 drm_device_set_unplugged(dev);
34947
34948- if (dev->open_count == 0) {
34949+ if (local_read(&dev->open_count) == 0) {
34950 drm_put_dev(dev);
34951 }
34952 mutex_unlock(&drm_global_mutex);
34953diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
34954index 004ecdf..db1f6e0 100644
34955--- a/drivers/gpu/drm/i810/i810_dma.c
34956+++ b/drivers/gpu/drm/i810/i810_dma.c
34957@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
34958 dma->buflist[vertex->idx],
34959 vertex->discard, vertex->used);
34960
34961- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34962- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34963+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34964+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34965 sarea_priv->last_enqueue = dev_priv->counter - 1;
34966 sarea_priv->last_dispatch = (int)hw_status[5];
34967
34968@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
34969 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
34970 mc->last_render);
34971
34972- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34973- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34974+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34975+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34976 sarea_priv->last_enqueue = dev_priv->counter - 1;
34977 sarea_priv->last_dispatch = (int)hw_status[5];
34978
34979diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
34980index 6e0acad..93c8289 100644
34981--- a/drivers/gpu/drm/i810/i810_drv.h
34982+++ b/drivers/gpu/drm/i810/i810_drv.h
34983@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
34984 int page_flipping;
34985
34986 wait_queue_head_t irq_queue;
34987- atomic_t irq_received;
34988- atomic_t irq_emitted;
34989+ atomic_unchecked_t irq_received;
34990+ atomic_unchecked_t irq_emitted;
34991
34992 int front_offset;
34993 } drm_i810_private_t;
34994diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
34995index 8a7c48b..72effc2 100644
34996--- a/drivers/gpu/drm/i915/i915_debugfs.c
34997+++ b/drivers/gpu/drm/i915/i915_debugfs.c
34998@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
34999 I915_READ(GTIMR));
35000 }
35001 seq_printf(m, "Interrupts received: %d\n",
35002- atomic_read(&dev_priv->irq_received));
35003+ atomic_read_unchecked(&dev_priv->irq_received));
35004 for_each_ring(ring, dev_priv, i) {
35005 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35006 seq_printf(m,
35007diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35008index 99daa89..84ebd44 100644
35009--- a/drivers/gpu/drm/i915/i915_dma.c
35010+++ b/drivers/gpu/drm/i915/i915_dma.c
35011@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35012 bool can_switch;
35013
35014 spin_lock(&dev->count_lock);
35015- can_switch = (dev->open_count == 0);
35016+ can_switch = (local_read(&dev->open_count) == 0);
35017 spin_unlock(&dev->count_lock);
35018 return can_switch;
35019 }
35020diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35021index 7339a4b..445aaba 100644
35022--- a/drivers/gpu/drm/i915/i915_drv.h
35023+++ b/drivers/gpu/drm/i915/i915_drv.h
35024@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
35025 drm_dma_handle_t *status_page_dmah;
35026 struct resource mch_res;
35027
35028- atomic_t irq_received;
35029+ atomic_unchecked_t irq_received;
35030
35031 /* protects the irq masks */
35032 spinlock_t irq_lock;
35033@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
35034 * will be page flipped away on the next vblank. When it
35035 * reaches 0, dev_priv->pending_flip_queue will be woken up.
35036 */
35037- atomic_t pending_flip;
35038+ atomic_unchecked_t pending_flip;
35039 };
35040 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
35041
35042@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35043 struct drm_i915_private *dev_priv, unsigned port);
35044 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35045 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35046-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35047+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35048 {
35049 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35050 }
35051diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35052index 26d08bb..e24fb51 100644
35053--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35054+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35055@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
35056 i915_gem_clflush_object(obj);
35057
35058 if (obj->base.pending_write_domain)
35059- flips |= atomic_read(&obj->pending_flip);
35060+ flips |= atomic_read_unchecked(&obj->pending_flip);
35061
35062 flush_domains |= obj->base.write_domain;
35063 }
35064@@ -703,18 +703,23 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35065
35066 static int
35067 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35068- int count)
35069+ unsigned int count)
35070 {
35071- int i;
35072+ unsigned int i;
35073+ int relocs_total = 0;
35074+ int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35075
35076 for (i = 0; i < count; i++) {
35077 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
35078 int length; /* limited by fault_in_pages_readable() */
35079
35080- /* First check for malicious input causing overflow */
35081- if (exec[i].relocation_count >
35082- INT_MAX / sizeof(struct drm_i915_gem_relocation_entry))
35083+ /* First check for malicious input causing overflow in
35084+ * the worst case where we need to allocate the entire
35085+ * relocation tree as a single array.
35086+ */
35087+ if (exec[i].relocation_count > relocs_max - relocs_total)
35088 return -EINVAL;
35089+ relocs_total += exec[i].relocation_count;
35090
35091 length = exec[i].relocation_count *
35092 sizeof(struct drm_i915_gem_relocation_entry);
35093@@ -1197,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35094 return -ENOMEM;
35095 }
35096 ret = copy_from_user(exec2_list,
35097- (struct drm_i915_relocation_entry __user *)
35098+ (struct drm_i915_gem_exec_object2 __user *)
35099 (uintptr_t) args->buffers_ptr,
35100 sizeof(*exec2_list) * args->buffer_count);
35101 if (ret != 0) {
35102diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35103index 3c59584..500f2e9 100644
35104--- a/drivers/gpu/drm/i915/i915_ioc32.c
35105+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35106@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35107 (unsigned long)request);
35108 }
35109
35110-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35111+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35112 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35113 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35114 [DRM_I915_GETPARAM] = compat_i915_getparam,
35115@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35116 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35117 {
35118 unsigned int nr = DRM_IOCTL_NR(cmd);
35119- drm_ioctl_compat_t *fn = NULL;
35120 int ret;
35121
35122 if (nr < DRM_COMMAND_BASE)
35123 return drm_compat_ioctl(filp, cmd, arg);
35124
35125- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35126- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35127-
35128- if (fn != NULL)
35129+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35130+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35131 ret = (*fn) (filp, cmd, arg);
35132- else
35133+ } else
35134 ret = drm_ioctl(filp, cmd, arg);
35135
35136 return ret;
35137diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35138index fe84338..a863190 100644
35139--- a/drivers/gpu/drm/i915/i915_irq.c
35140+++ b/drivers/gpu/drm/i915/i915_irq.c
35141@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35142 u32 pipe_stats[I915_MAX_PIPES];
35143 bool blc_event;
35144
35145- atomic_inc(&dev_priv->irq_received);
35146+ atomic_inc_unchecked(&dev_priv->irq_received);
35147
35148 while (true) {
35149 iir = I915_READ(VLV_IIR);
35150@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35151 irqreturn_t ret = IRQ_NONE;
35152 int i;
35153
35154- atomic_inc(&dev_priv->irq_received);
35155+ atomic_inc_unchecked(&dev_priv->irq_received);
35156
35157 /* disable master interrupt before clearing iir */
35158 de_ier = I915_READ(DEIER);
35159@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35160 int ret = IRQ_NONE;
35161 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
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@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35169 {
35170 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35171
35172- atomic_set(&dev_priv->irq_received, 0);
35173+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35174
35175 I915_WRITE(HWSTAM, 0xeffe);
35176
35177@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35178 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35179 int pipe;
35180
35181- atomic_set(&dev_priv->irq_received, 0);
35182+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35183
35184 /* VLV magic */
35185 I915_WRITE(VLV_IMR, 0);
35186@@ -2108,7 +2108,7 @@ static void i8xx_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 for_each_pipe(pipe)
35194 I915_WRITE(PIPESTAT(pipe), 0);
35195@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35196 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35197 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35198
35199- atomic_inc(&dev_priv->irq_received);
35200+ atomic_inc_unchecked(&dev_priv->irq_received);
35201
35202 iir = I915_READ16(IIR);
35203 if (iir == 0)
35204@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35205 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35206 int pipe;
35207
35208- atomic_set(&dev_priv->irq_received, 0);
35209+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35210
35211 if (I915_HAS_HOTPLUG(dev)) {
35212 I915_WRITE(PORT_HOTPLUG_EN, 0);
35213@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35214 };
35215 int pipe, ret = IRQ_NONE;
35216
35217- atomic_inc(&dev_priv->irq_received);
35218+ atomic_inc_unchecked(&dev_priv->irq_received);
35219
35220 iir = I915_READ(IIR);
35221 do {
35222@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35223 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35224 int pipe;
35225
35226- atomic_set(&dev_priv->irq_received, 0);
35227+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35228
35229 I915_WRITE(PORT_HOTPLUG_EN, 0);
35230 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35231@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35232 int irq_received;
35233 int ret = IRQ_NONE, pipe;
35234
35235- atomic_inc(&dev_priv->irq_received);
35236+ atomic_inc_unchecked(&dev_priv->irq_received);
35237
35238 iir = I915_READ(IIR);
35239
35240diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35241index 80aa1fc..85cfce3 100644
35242--- a/drivers/gpu/drm/i915/intel_display.c
35243+++ b/drivers/gpu/drm/i915/intel_display.c
35244@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35245
35246 wait_event(dev_priv->pending_flip_queue,
35247 atomic_read(&dev_priv->mm.wedged) ||
35248- atomic_read(&obj->pending_flip) == 0);
35249+ atomic_read_unchecked(&obj->pending_flip) == 0);
35250
35251 /* Big Hammer, we also need to ensure that any pending
35252 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35253@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35254
35255 obj = work->old_fb_obj;
35256
35257- atomic_clear_mask(1 << intel_crtc->plane,
35258- &obj->pending_flip.counter);
35259+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35260 wake_up(&dev_priv->pending_flip_queue);
35261
35262 queue_work(dev_priv->wq, &work->work);
35263@@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35264 /* Block clients from rendering to the new back buffer until
35265 * the flip occurs and the object is no longer visible.
35266 */
35267- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35268+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35269 atomic_inc(&intel_crtc->unpin_work_count);
35270
35271 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35272@@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35273
35274 cleanup_pending:
35275 atomic_dec(&intel_crtc->unpin_work_count);
35276- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35277+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35278 drm_gem_object_unreference(&work->old_fb_obj->base);
35279 drm_gem_object_unreference(&obj->base);
35280 mutex_unlock(&dev->struct_mutex);
35281@@ -8849,13 +8848,13 @@ struct intel_quirk {
35282 int subsystem_vendor;
35283 int subsystem_device;
35284 void (*hook)(struct drm_device *dev);
35285-};
35286+} __do_const;
35287
35288 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35289 struct intel_dmi_quirk {
35290 void (*hook)(struct drm_device *dev);
35291 const struct dmi_system_id (*dmi_id_list)[];
35292-};
35293+} __do_const;
35294
35295 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35296 {
35297@@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35298 return 1;
35299 }
35300
35301+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35302+ {
35303+ .callback = intel_dmi_reverse_brightness,
35304+ .ident = "NCR Corporation",
35305+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35306+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35307+ },
35308+ },
35309+ { } /* terminating entry */
35310+};
35311+
35312 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35313 {
35314- .dmi_id_list = &(const struct dmi_system_id[]) {
35315- {
35316- .callback = intel_dmi_reverse_brightness,
35317- .ident = "NCR Corporation",
35318- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35319- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35320- },
35321- },
35322- { } /* terminating entry */
35323- },
35324+ .dmi_id_list = &intel_dmi_quirks_table,
35325 .hook = quirk_invert_brightness,
35326 },
35327 };
35328diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35329index 54558a0..2d97005 100644
35330--- a/drivers/gpu/drm/mga/mga_drv.h
35331+++ b/drivers/gpu/drm/mga/mga_drv.h
35332@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35333 u32 clear_cmd;
35334 u32 maccess;
35335
35336- atomic_t vbl_received; /**< Number of vblanks received. */
35337+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35338 wait_queue_head_t fence_queue;
35339- atomic_t last_fence_retired;
35340+ atomic_unchecked_t last_fence_retired;
35341 u32 next_fence_to_post;
35342
35343 unsigned int fb_cpp;
35344diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35345index 709e90d..89a1c0d 100644
35346--- a/drivers/gpu/drm/mga/mga_ioc32.c
35347+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35348@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35349 return 0;
35350 }
35351
35352-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35353+drm_ioctl_compat_t mga_compat_ioctls[] = {
35354 [DRM_MGA_INIT] = compat_mga_init,
35355 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35356 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35357@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35358 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35359 {
35360 unsigned int nr = DRM_IOCTL_NR(cmd);
35361- drm_ioctl_compat_t *fn = NULL;
35362 int ret;
35363
35364 if (nr < DRM_COMMAND_BASE)
35365 return drm_compat_ioctl(filp, cmd, arg);
35366
35367- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35368- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35369-
35370- if (fn != NULL)
35371+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35372+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35373 ret = (*fn) (filp, cmd, arg);
35374- else
35375+ } else
35376 ret = drm_ioctl(filp, cmd, arg);
35377
35378 return ret;
35379diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35380index 598c281..60d590e 100644
35381--- a/drivers/gpu/drm/mga/mga_irq.c
35382+++ b/drivers/gpu/drm/mga/mga_irq.c
35383@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35384 if (crtc != 0)
35385 return 0;
35386
35387- return atomic_read(&dev_priv->vbl_received);
35388+ return atomic_read_unchecked(&dev_priv->vbl_received);
35389 }
35390
35391
35392@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35393 /* VBLANK interrupt */
35394 if (status & MGA_VLINEPEN) {
35395 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35396- atomic_inc(&dev_priv->vbl_received);
35397+ atomic_inc_unchecked(&dev_priv->vbl_received);
35398 drm_handle_vblank(dev, 0);
35399 handled = 1;
35400 }
35401@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35402 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35403 MGA_WRITE(MGA_PRIMEND, prim_end);
35404
35405- atomic_inc(&dev_priv->last_fence_retired);
35406+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35407 DRM_WAKEUP(&dev_priv->fence_queue);
35408 handled = 1;
35409 }
35410@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35411 * using fences.
35412 */
35413 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35414- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35415+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35416 - *sequence) <= (1 << 23)));
35417
35418 *sequence = cur_fence;
35419diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35420index 865eddf..62c4cc3 100644
35421--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35422+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35423@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35424 struct bit_table {
35425 const char id;
35426 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35427-};
35428+} __no_const;
35429
35430 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35431
35432diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35433index aa89eb9..d45d38b 100644
35434--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35435+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35436@@ -80,7 +80,7 @@ struct nouveau_drm {
35437 struct drm_global_reference mem_global_ref;
35438 struct ttm_bo_global_ref bo_global_ref;
35439 struct ttm_bo_device bdev;
35440- atomic_t validate_sequence;
35441+ atomic_unchecked_t validate_sequence;
35442 int (*move)(struct nouveau_channel *,
35443 struct ttm_buffer_object *,
35444 struct ttm_mem_reg *, struct ttm_mem_reg *);
35445diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35446index cdb83ac..27f0a16 100644
35447--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35448+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35449@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35450 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35451 struct nouveau_channel *);
35452 u32 (*read)(struct nouveau_channel *);
35453-};
35454+} __no_const;
35455
35456 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35457
35458diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35459index 8bf695c..9fbc90a 100644
35460--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35461+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35462@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35463 int trycnt = 0;
35464 int ret, i;
35465
35466- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35467+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35468 retry:
35469 if (++trycnt > 100000) {
35470 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35471diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35472index 08214bc..9208577 100644
35473--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35474+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35475@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35476 unsigned long arg)
35477 {
35478 unsigned int nr = DRM_IOCTL_NR(cmd);
35479- drm_ioctl_compat_t *fn = NULL;
35480+ drm_ioctl_compat_t fn = NULL;
35481 int ret;
35482
35483 if (nr < DRM_COMMAND_BASE)
35484diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35485index 25d3495..d81aaf6 100644
35486--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35487+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35488@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35489 bool can_switch;
35490
35491 spin_lock(&dev->count_lock);
35492- can_switch = (dev->open_count == 0);
35493+ can_switch = (local_read(&dev->open_count) == 0);
35494 spin_unlock(&dev->count_lock);
35495 return can_switch;
35496 }
35497diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35498index d4660cf..70dbe65 100644
35499--- a/drivers/gpu/drm/r128/r128_cce.c
35500+++ b/drivers/gpu/drm/r128/r128_cce.c
35501@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35502
35503 /* GH: Simple idle check.
35504 */
35505- atomic_set(&dev_priv->idle_count, 0);
35506+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35507
35508 /* We don't support anything other than bus-mastering ring mode,
35509 * but the ring can be in either AGP or PCI space for the ring
35510diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35511index 930c71b..499aded 100644
35512--- a/drivers/gpu/drm/r128/r128_drv.h
35513+++ b/drivers/gpu/drm/r128/r128_drv.h
35514@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35515 int is_pci;
35516 unsigned long cce_buffers_offset;
35517
35518- atomic_t idle_count;
35519+ atomic_unchecked_t idle_count;
35520
35521 int page_flipping;
35522 int current_page;
35523 u32 crtc_offset;
35524 u32 crtc_offset_cntl;
35525
35526- atomic_t vbl_received;
35527+ atomic_unchecked_t vbl_received;
35528
35529 u32 color_fmt;
35530 unsigned int front_offset;
35531diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35532index a954c54..9cc595c 100644
35533--- a/drivers/gpu/drm/r128/r128_ioc32.c
35534+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35535@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35536 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35537 }
35538
35539-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35540+drm_ioctl_compat_t r128_compat_ioctls[] = {
35541 [DRM_R128_INIT] = compat_r128_init,
35542 [DRM_R128_DEPTH] = compat_r128_depth,
35543 [DRM_R128_STIPPLE] = compat_r128_stipple,
35544@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35545 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35546 {
35547 unsigned int nr = DRM_IOCTL_NR(cmd);
35548- drm_ioctl_compat_t *fn = NULL;
35549 int ret;
35550
35551 if (nr < DRM_COMMAND_BASE)
35552 return drm_compat_ioctl(filp, cmd, arg);
35553
35554- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35555- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35556-
35557- if (fn != NULL)
35558+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35559+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35560 ret = (*fn) (filp, cmd, arg);
35561- else
35562+ } else
35563 ret = drm_ioctl(filp, cmd, arg);
35564
35565 return ret;
35566diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35567index 2ea4f09..d391371 100644
35568--- a/drivers/gpu/drm/r128/r128_irq.c
35569+++ b/drivers/gpu/drm/r128/r128_irq.c
35570@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35571 if (crtc != 0)
35572 return 0;
35573
35574- return atomic_read(&dev_priv->vbl_received);
35575+ return atomic_read_unchecked(&dev_priv->vbl_received);
35576 }
35577
35578 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35579@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35580 /* VBLANK interrupt */
35581 if (status & R128_CRTC_VBLANK_INT) {
35582 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35583- atomic_inc(&dev_priv->vbl_received);
35584+ atomic_inc_unchecked(&dev_priv->vbl_received);
35585 drm_handle_vblank(dev, 0);
35586 return IRQ_HANDLED;
35587 }
35588diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35589index 19bb7e6..de7e2a2 100644
35590--- a/drivers/gpu/drm/r128/r128_state.c
35591+++ b/drivers/gpu/drm/r128/r128_state.c
35592@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35593
35594 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35595 {
35596- if (atomic_read(&dev_priv->idle_count) == 0)
35597+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35598 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35599 else
35600- atomic_set(&dev_priv->idle_count, 0);
35601+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35602 }
35603
35604 #endif
35605diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35606index 5a82b6b..9e69c73 100644
35607--- a/drivers/gpu/drm/radeon/mkregtable.c
35608+++ b/drivers/gpu/drm/radeon/mkregtable.c
35609@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35610 regex_t mask_rex;
35611 regmatch_t match[4];
35612 char buf[1024];
35613- size_t end;
35614+ long end;
35615 int len;
35616 int done = 0;
35617 int r;
35618 unsigned o;
35619 struct offset *offset;
35620 char last_reg_s[10];
35621- int last_reg;
35622+ unsigned long last_reg;
35623
35624 if (regcomp
35625 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35626diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35627index 0d6562b..a154330 100644
35628--- a/drivers/gpu/drm/radeon/radeon_device.c
35629+++ b/drivers/gpu/drm/radeon/radeon_device.c
35630@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35631 bool can_switch;
35632
35633 spin_lock(&dev->count_lock);
35634- can_switch = (dev->open_count == 0);
35635+ can_switch = (local_read(&dev->open_count) == 0);
35636 spin_unlock(&dev->count_lock);
35637 return can_switch;
35638 }
35639diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35640index e7fdf16..f4f6490 100644
35641--- a/drivers/gpu/drm/radeon/radeon_drv.h
35642+++ b/drivers/gpu/drm/radeon/radeon_drv.h
35643@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35644
35645 /* SW interrupt */
35646 wait_queue_head_t swi_queue;
35647- atomic_t swi_emitted;
35648+ atomic_unchecked_t swi_emitted;
35649 int vblank_crtc;
35650 uint32_t irq_enable_reg;
35651 uint32_t r500_disp_irq_reg;
35652diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35653index c180df8..5fd8186 100644
35654--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35655+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35656@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35657 request = compat_alloc_user_space(sizeof(*request));
35658 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35659 || __put_user(req32.param, &request->param)
35660- || __put_user((void __user *)(unsigned long)req32.value,
35661+ || __put_user((unsigned long)req32.value,
35662 &request->value))
35663 return -EFAULT;
35664
35665@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35666 #define compat_radeon_cp_setparam NULL
35667 #endif /* X86_64 || IA64 */
35668
35669-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35670+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35671 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35672 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35673 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35674@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35675 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35676 {
35677 unsigned int nr = DRM_IOCTL_NR(cmd);
35678- drm_ioctl_compat_t *fn = NULL;
35679 int ret;
35680
35681 if (nr < DRM_COMMAND_BASE)
35682 return drm_compat_ioctl(filp, cmd, arg);
35683
35684- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35685- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35686-
35687- if (fn != NULL)
35688+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35689+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35690 ret = (*fn) (filp, cmd, arg);
35691- else
35692+ } else
35693 ret = drm_ioctl(filp, cmd, arg);
35694
35695 return ret;
35696diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35697index e771033..a0bc6b3 100644
35698--- a/drivers/gpu/drm/radeon/radeon_irq.c
35699+++ b/drivers/gpu/drm/radeon/radeon_irq.c
35700@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35701 unsigned int ret;
35702 RING_LOCALS;
35703
35704- atomic_inc(&dev_priv->swi_emitted);
35705- ret = atomic_read(&dev_priv->swi_emitted);
35706+ atomic_inc_unchecked(&dev_priv->swi_emitted);
35707+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35708
35709 BEGIN_RING(4);
35710 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35711@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35712 drm_radeon_private_t *dev_priv =
35713 (drm_radeon_private_t *) dev->dev_private;
35714
35715- atomic_set(&dev_priv->swi_emitted, 0);
35716+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35717 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35718
35719 dev->max_vblank_count = 0x001fffff;
35720diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35721index 8e9057b..af6dacb 100644
35722--- a/drivers/gpu/drm/radeon/radeon_state.c
35723+++ b/drivers/gpu/drm/radeon/radeon_state.c
35724@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35725 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35726 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35727
35728- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35729+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35730 sarea_priv->nbox * sizeof(depth_boxes[0])))
35731 return -EFAULT;
35732
35733@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35734 {
35735 drm_radeon_private_t *dev_priv = dev->dev_private;
35736 drm_radeon_getparam_t *param = data;
35737- int value;
35738+ int value = 0;
35739
35740 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35741
35742diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35743index 93f760e..8088227 100644
35744--- a/drivers/gpu/drm/radeon/radeon_ttm.c
35745+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35746@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35747 man->size = size >> PAGE_SHIFT;
35748 }
35749
35750-static struct vm_operations_struct radeon_ttm_vm_ops;
35751+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35752 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35753
35754 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35755@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35756 }
35757 if (unlikely(ttm_vm_ops == NULL)) {
35758 ttm_vm_ops = vma->vm_ops;
35759+ pax_open_kernel();
35760 radeon_ttm_vm_ops = *ttm_vm_ops;
35761 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35762+ pax_close_kernel();
35763 }
35764 vma->vm_ops = &radeon_ttm_vm_ops;
35765 return 0;
35766@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35767 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35768 else
35769 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35770- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35771- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35772- radeon_mem_types_list[i].driver_features = 0;
35773+ pax_open_kernel();
35774+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35775+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35776+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35777 if (i == 0)
35778- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35779+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35780 else
35781- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35782-
35783+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35784+ pax_close_kernel();
35785 }
35786 /* Add ttm page pool to debugfs */
35787 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35788- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35789- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35790- radeon_mem_types_list[i].driver_features = 0;
35791- radeon_mem_types_list[i++].data = NULL;
35792+ pax_open_kernel();
35793+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35794+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35795+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35796+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35797+ pax_close_kernel();
35798 #ifdef CONFIG_SWIOTLB
35799 if (swiotlb_nr_tbl()) {
35800 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35801- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35802- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35803- radeon_mem_types_list[i].driver_features = 0;
35804- radeon_mem_types_list[i++].data = NULL;
35805+ pax_open_kernel();
35806+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35807+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35808+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35809+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35810+ pax_close_kernel();
35811 }
35812 #endif
35813 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35814diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35815index 5706d2a..17aedaa 100644
35816--- a/drivers/gpu/drm/radeon/rs690.c
35817+++ b/drivers/gpu/drm/radeon/rs690.c
35818@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35819 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35820 rdev->pm.sideport_bandwidth.full)
35821 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35822- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35823+ read_delay_latency.full = dfixed_const(800 * 1000);
35824 read_delay_latency.full = dfixed_div(read_delay_latency,
35825 rdev->pm.igp_sideport_mclk);
35826+ a.full = dfixed_const(370);
35827+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35828 } else {
35829 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35830 rdev->pm.k8_bandwidth.full)
35831diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35832index bd2a3b4..122d9ad 100644
35833--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35834+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35835@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35836 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35837 struct shrink_control *sc)
35838 {
35839- static atomic_t start_pool = ATOMIC_INIT(0);
35840+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35841 unsigned i;
35842- unsigned pool_offset = atomic_add_return(1, &start_pool);
35843+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35844 struct ttm_page_pool *pool;
35845 int shrink_pages = sc->nr_to_scan;
35846
35847diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35848index 1eb060c..188b1fc 100644
35849--- a/drivers/gpu/drm/udl/udl_fb.c
35850+++ b/drivers/gpu/drm/udl/udl_fb.c
35851@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35852 fb_deferred_io_cleanup(info);
35853 kfree(info->fbdefio);
35854 info->fbdefio = NULL;
35855- info->fbops->fb_mmap = udl_fb_mmap;
35856 }
35857
35858 pr_warn("released /dev/fb%d user=%d count=%d\n",
35859diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35860index 893a650..6190d3b 100644
35861--- a/drivers/gpu/drm/via/via_drv.h
35862+++ b/drivers/gpu/drm/via/via_drv.h
35863@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35864 typedef uint32_t maskarray_t[5];
35865
35866 typedef struct drm_via_irq {
35867- atomic_t irq_received;
35868+ atomic_unchecked_t irq_received;
35869 uint32_t pending_mask;
35870 uint32_t enable_mask;
35871 wait_queue_head_t irq_queue;
35872@@ -75,7 +75,7 @@ typedef struct drm_via_private {
35873 struct timeval last_vblank;
35874 int last_vblank_valid;
35875 unsigned usec_per_vblank;
35876- atomic_t vbl_received;
35877+ atomic_unchecked_t vbl_received;
35878 drm_via_state_t hc_state;
35879 char pci_buf[VIA_PCI_BUF_SIZE];
35880 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35881diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35882index ac98964..5dbf512 100644
35883--- a/drivers/gpu/drm/via/via_irq.c
35884+++ b/drivers/gpu/drm/via/via_irq.c
35885@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35886 if (crtc != 0)
35887 return 0;
35888
35889- return atomic_read(&dev_priv->vbl_received);
35890+ return atomic_read_unchecked(&dev_priv->vbl_received);
35891 }
35892
35893 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35894@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35895
35896 status = VIA_READ(VIA_REG_INTERRUPT);
35897 if (status & VIA_IRQ_VBLANK_PENDING) {
35898- atomic_inc(&dev_priv->vbl_received);
35899- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35900+ atomic_inc_unchecked(&dev_priv->vbl_received);
35901+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35902 do_gettimeofday(&cur_vblank);
35903 if (dev_priv->last_vblank_valid) {
35904 dev_priv->usec_per_vblank =
35905@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35906 dev_priv->last_vblank = cur_vblank;
35907 dev_priv->last_vblank_valid = 1;
35908 }
35909- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35910+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35911 DRM_DEBUG("US per vblank is: %u\n",
35912 dev_priv->usec_per_vblank);
35913 }
35914@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35915
35916 for (i = 0; i < dev_priv->num_irqs; ++i) {
35917 if (status & cur_irq->pending_mask) {
35918- atomic_inc(&cur_irq->irq_received);
35919+ atomic_inc_unchecked(&cur_irq->irq_received);
35920 DRM_WAKEUP(&cur_irq->irq_queue);
35921 handled = 1;
35922 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35923@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35924 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35925 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35926 masks[irq][4]));
35927- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35928+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35929 } else {
35930 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35931 (((cur_irq_sequence =
35932- atomic_read(&cur_irq->irq_received)) -
35933+ atomic_read_unchecked(&cur_irq->irq_received)) -
35934 *sequence) <= (1 << 23)));
35935 }
35936 *sequence = cur_irq_sequence;
35937@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35938 }
35939
35940 for (i = 0; i < dev_priv->num_irqs; ++i) {
35941- atomic_set(&cur_irq->irq_received, 0);
35942+ atomic_set_unchecked(&cur_irq->irq_received, 0);
35943 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35944 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35945 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35946@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35947 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35948 case VIA_IRQ_RELATIVE:
35949 irqwait->request.sequence +=
35950- atomic_read(&cur_irq->irq_received);
35951+ atomic_read_unchecked(&cur_irq->irq_received);
35952 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35953 case VIA_IRQ_ABSOLUTE:
35954 break;
35955diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35956index 13aeda7..4a952d1 100644
35957--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35958+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35959@@ -290,7 +290,7 @@ struct vmw_private {
35960 * Fencing and IRQs.
35961 */
35962
35963- atomic_t marker_seq;
35964+ atomic_unchecked_t marker_seq;
35965 wait_queue_head_t fence_queue;
35966 wait_queue_head_t fifo_queue;
35967 int fence_queue_waiters; /* Protected by hw_mutex */
35968diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35969index 3eb1486..0a47ee9 100644
35970--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35971+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35972@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35973 (unsigned int) min,
35974 (unsigned int) fifo->capabilities);
35975
35976- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35977+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35978 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35979 vmw_marker_queue_init(&fifo->marker_queue);
35980 return vmw_fifo_send_fence(dev_priv, &dummy);
35981@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35982 if (reserveable)
35983 iowrite32(bytes, fifo_mem +
35984 SVGA_FIFO_RESERVED);
35985- return fifo_mem + (next_cmd >> 2);
35986+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
35987 } else {
35988 need_bounce = true;
35989 }
35990@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35991
35992 fm = vmw_fifo_reserve(dev_priv, bytes);
35993 if (unlikely(fm == NULL)) {
35994- *seqno = atomic_read(&dev_priv->marker_seq);
35995+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35996 ret = -ENOMEM;
35997 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
35998 false, 3*HZ);
35999@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36000 }
36001
36002 do {
36003- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36004+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36005 } while (*seqno == 0);
36006
36007 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36008diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36009index 4640adb..e1384ed 100644
36010--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36011+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36012@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36013 * emitted. Then the fence is stale and signaled.
36014 */
36015
36016- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36017+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36018 > VMW_FENCE_WRAP);
36019
36020 return ret;
36021@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36022
36023 if (fifo_idle)
36024 down_read(&fifo_state->rwsem);
36025- signal_seq = atomic_read(&dev_priv->marker_seq);
36026+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36027 ret = 0;
36028
36029 for (;;) {
36030diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36031index 8a8725c..afed796 100644
36032--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36033+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36034@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36035 while (!vmw_lag_lt(queue, us)) {
36036 spin_lock(&queue->lock);
36037 if (list_empty(&queue->head))
36038- seqno = atomic_read(&dev_priv->marker_seq);
36039+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36040 else {
36041 marker = list_first_entry(&queue->head,
36042 struct vmw_marker, head);
36043diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36044index ceb3040..6160c5c 100644
36045--- a/drivers/hid/hid-core.c
36046+++ b/drivers/hid/hid-core.c
36047@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36048
36049 int hid_add_device(struct hid_device *hdev)
36050 {
36051- static atomic_t id = ATOMIC_INIT(0);
36052+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36053 int ret;
36054
36055 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36056@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
36057 /* XXX hack, any other cleaner solution after the driver core
36058 * is converted to allow more than 20 bytes as the device name? */
36059 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36060- hdev->vendor, hdev->product, atomic_inc_return(&id));
36061+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36062
36063 hid_debug_register(hdev, dev_name(&hdev->dev));
36064 ret = device_add(&hdev->dev);
36065diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36066index eec3291..8ed706b 100644
36067--- a/drivers/hid/hid-wiimote-debug.c
36068+++ b/drivers/hid/hid-wiimote-debug.c
36069@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36070 else if (size == 0)
36071 return -EIO;
36072
36073- if (copy_to_user(u, buf, size))
36074+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36075 return -EFAULT;
36076
36077 *off += size;
36078diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36079index 773a2f2..7ce08bc 100644
36080--- a/drivers/hv/channel.c
36081+++ b/drivers/hv/channel.c
36082@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36083 int ret = 0;
36084 int t;
36085
36086- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36087- atomic_inc(&vmbus_connection.next_gpadl_handle);
36088+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36089+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36090
36091 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36092 if (ret)
36093diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36094index 3648f8f..30ef30d 100644
36095--- a/drivers/hv/hv.c
36096+++ b/drivers/hv/hv.c
36097@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36098 u64 output_address = (output) ? virt_to_phys(output) : 0;
36099 u32 output_address_hi = output_address >> 32;
36100 u32 output_address_lo = output_address & 0xFFFFFFFF;
36101- void *hypercall_page = hv_context.hypercall_page;
36102+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36103
36104 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36105 "=a"(hv_status_lo) : "d" (control_hi),
36106diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36107index d8d1fad..b91caf7 100644
36108--- a/drivers/hv/hyperv_vmbus.h
36109+++ b/drivers/hv/hyperv_vmbus.h
36110@@ -594,7 +594,7 @@ enum vmbus_connect_state {
36111 struct vmbus_connection {
36112 enum vmbus_connect_state conn_state;
36113
36114- atomic_t next_gpadl_handle;
36115+ atomic_unchecked_t next_gpadl_handle;
36116
36117 /*
36118 * Represents channel interrupts. Each bit position represents a
36119diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36120index 8e1a9ec..4687821 100644
36121--- a/drivers/hv/vmbus_drv.c
36122+++ b/drivers/hv/vmbus_drv.c
36123@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36124 {
36125 int ret = 0;
36126
36127- static atomic_t device_num = ATOMIC_INIT(0);
36128+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36129
36130 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36131- atomic_inc_return(&device_num));
36132+ atomic_inc_return_unchecked(&device_num));
36133
36134 child_device_obj->device.bus = &hv_bus;
36135 child_device_obj->device.parent = &hv_acpi_dev->dev;
36136diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36137index 1672e2a..4a6297c 100644
36138--- a/drivers/hwmon/acpi_power_meter.c
36139+++ b/drivers/hwmon/acpi_power_meter.c
36140@@ -117,7 +117,7 @@ struct sensor_template {
36141 struct device_attribute *devattr,
36142 const char *buf, size_t count);
36143 int index;
36144-};
36145+} __do_const;
36146
36147 /* Averaging interval */
36148 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36149@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36150 struct sensor_template *attrs)
36151 {
36152 struct device *dev = &resource->acpi_dev->dev;
36153- struct sensor_device_attribute *sensors =
36154+ sensor_device_attribute_no_const *sensors =
36155 &resource->sensors[resource->num_sensors];
36156 int res = 0;
36157
36158diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36159index b41baff..4953e4d 100644
36160--- a/drivers/hwmon/applesmc.c
36161+++ b/drivers/hwmon/applesmc.c
36162@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36163 {
36164 struct applesmc_node_group *grp;
36165 struct applesmc_dev_attr *node;
36166- struct attribute *attr;
36167+ attribute_no_const *attr;
36168 int ret, i;
36169
36170 for (grp = groups; grp->format; grp++) {
36171diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36172index 56dbcfb..9874bf1 100644
36173--- a/drivers/hwmon/asus_atk0110.c
36174+++ b/drivers/hwmon/asus_atk0110.c
36175@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36176 struct atk_sensor_data {
36177 struct list_head list;
36178 struct atk_data *data;
36179- struct device_attribute label_attr;
36180- struct device_attribute input_attr;
36181- struct device_attribute limit1_attr;
36182- struct device_attribute limit2_attr;
36183+ device_attribute_no_const label_attr;
36184+ device_attribute_no_const input_attr;
36185+ device_attribute_no_const limit1_attr;
36186+ device_attribute_no_const limit2_attr;
36187 char label_attr_name[ATTR_NAME_SIZE];
36188 char input_attr_name[ATTR_NAME_SIZE];
36189 char limit1_attr_name[ATTR_NAME_SIZE];
36190@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36191 static struct device_attribute atk_name_attr =
36192 __ATTR(name, 0444, atk_name_show, NULL);
36193
36194-static void atk_init_attribute(struct device_attribute *attr, char *name,
36195+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36196 sysfs_show_func show)
36197 {
36198 sysfs_attr_init(&attr->attr);
36199diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36200index d64923d..72591e8 100644
36201--- a/drivers/hwmon/coretemp.c
36202+++ b/drivers/hwmon/coretemp.c
36203@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36204 return NOTIFY_OK;
36205 }
36206
36207-static struct notifier_block coretemp_cpu_notifier __refdata = {
36208+static struct notifier_block coretemp_cpu_notifier = {
36209 .notifier_call = coretemp_cpu_callback,
36210 };
36211
36212diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36213index a14f634..2916ee2 100644
36214--- a/drivers/hwmon/ibmaem.c
36215+++ b/drivers/hwmon/ibmaem.c
36216@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36217 struct aem_rw_sensor_template *rw)
36218 {
36219 struct device *dev = &data->pdev->dev;
36220- struct sensor_device_attribute *sensors = data->sensors;
36221+ sensor_device_attribute_no_const *sensors = data->sensors;
36222 int err;
36223
36224 /* Set up read-only sensors */
36225diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36226index 7d19b1b..8fdaaac 100644
36227--- a/drivers/hwmon/pmbus/pmbus_core.c
36228+++ b/drivers/hwmon/pmbus/pmbus_core.c
36229@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36230
36231 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36232 do { \
36233- struct sensor_device_attribute *a \
36234+ sensor_device_attribute_no_const *a \
36235 = &data->_type##s[data->num_##_type##s].attribute; \
36236 BUG_ON(data->num_attributes >= data->max_attributes); \
36237 sysfs_attr_init(&a->dev_attr.attr); \
36238diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36239index 8047fed..1e956f0 100644
36240--- a/drivers/hwmon/sht15.c
36241+++ b/drivers/hwmon/sht15.c
36242@@ -169,7 +169,7 @@ struct sht15_data {
36243 int supply_uV;
36244 bool supply_uV_valid;
36245 struct work_struct update_supply_work;
36246- atomic_t interrupt_handled;
36247+ atomic_unchecked_t interrupt_handled;
36248 };
36249
36250 /**
36251@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36252 return ret;
36253
36254 gpio_direction_input(data->pdata->gpio_data);
36255- atomic_set(&data->interrupt_handled, 0);
36256+ atomic_set_unchecked(&data->interrupt_handled, 0);
36257
36258 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36259 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36260 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36261 /* Only relevant if the interrupt hasn't occurred. */
36262- if (!atomic_read(&data->interrupt_handled))
36263+ if (!atomic_read_unchecked(&data->interrupt_handled))
36264 schedule_work(&data->read_work);
36265 }
36266 ret = wait_event_timeout(data->wait_queue,
36267@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36268
36269 /* First disable the interrupt */
36270 disable_irq_nosync(irq);
36271- atomic_inc(&data->interrupt_handled);
36272+ atomic_inc_unchecked(&data->interrupt_handled);
36273 /* Then schedule a reading work struct */
36274 if (data->state != SHT15_READING_NOTHING)
36275 schedule_work(&data->read_work);
36276@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36277 * If not, then start the interrupt again - care here as could
36278 * have gone low in meantime so verify it hasn't!
36279 */
36280- atomic_set(&data->interrupt_handled, 0);
36281+ atomic_set_unchecked(&data->interrupt_handled, 0);
36282 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36283 /* If still not occurred or another handler was scheduled */
36284 if (gpio_get_value(data->pdata->gpio_data)
36285- || atomic_read(&data->interrupt_handled))
36286+ || atomic_read_unchecked(&data->interrupt_handled))
36287 return;
36288 }
36289
36290diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36291index 76f157b..9c0db1b 100644
36292--- a/drivers/hwmon/via-cputemp.c
36293+++ b/drivers/hwmon/via-cputemp.c
36294@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36295 return NOTIFY_OK;
36296 }
36297
36298-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36299+static struct notifier_block via_cputemp_cpu_notifier = {
36300 .notifier_call = via_cputemp_cpu_callback,
36301 };
36302
36303diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36304index 378fcb5..5e91fa8 100644
36305--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36306+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36307@@ -43,7 +43,7 @@
36308 extern struct i2c_adapter amd756_smbus;
36309
36310 static struct i2c_adapter *s4882_adapter;
36311-static struct i2c_algorithm *s4882_algo;
36312+static i2c_algorithm_no_const *s4882_algo;
36313
36314 /* Wrapper access functions for multiplexed SMBus */
36315 static DEFINE_MUTEX(amd756_lock);
36316diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36317index 29015eb..af2d8e9 100644
36318--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36319+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36320@@ -41,7 +41,7 @@
36321 extern struct i2c_adapter *nforce2_smbus;
36322
36323 static struct i2c_adapter *s4985_adapter;
36324-static struct i2c_algorithm *s4985_algo;
36325+static i2c_algorithm_no_const *s4985_algo;
36326
36327 /* Wrapper access functions for multiplexed SMBus */
36328 static DEFINE_MUTEX(nforce2_lock);
36329diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36330index 8126824..55a2798 100644
36331--- a/drivers/ide/ide-cd.c
36332+++ b/drivers/ide/ide-cd.c
36333@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36334 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36335 if ((unsigned long)buf & alignment
36336 || blk_rq_bytes(rq) & q->dma_pad_mask
36337- || object_is_on_stack(buf))
36338+ || object_starts_on_stack(buf))
36339 drive->dma = 0;
36340 }
36341 }
36342diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36343index 8848f16..f8e6dd8 100644
36344--- a/drivers/iio/industrialio-core.c
36345+++ b/drivers/iio/industrialio-core.c
36346@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36347 }
36348
36349 static
36350-int __iio_device_attr_init(struct device_attribute *dev_attr,
36351+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36352 const char *postfix,
36353 struct iio_chan_spec const *chan,
36354 ssize_t (*readfunc)(struct device *dev,
36355diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36356index 394fea2..c833880 100644
36357--- a/drivers/infiniband/core/cm.c
36358+++ b/drivers/infiniband/core/cm.c
36359@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36360
36361 struct cm_counter_group {
36362 struct kobject obj;
36363- atomic_long_t counter[CM_ATTR_COUNT];
36364+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36365 };
36366
36367 struct cm_counter_attribute {
36368@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36369 struct ib_mad_send_buf *msg = NULL;
36370 int ret;
36371
36372- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36373+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36374 counter[CM_REQ_COUNTER]);
36375
36376 /* Quick state check to discard duplicate REQs. */
36377@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36378 if (!cm_id_priv)
36379 return;
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_REP_COUNTER]);
36384 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36385 if (ret)
36386@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36387 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36388 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36389 spin_unlock_irq(&cm_id_priv->lock);
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_RTU_COUNTER]);
36393 goto out;
36394 }
36395@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36396 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36397 dreq_msg->local_comm_id);
36398 if (!cm_id_priv) {
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_DREQ_COUNTER]);
36402 cm_issue_drep(work->port, work->mad_recv_wc);
36403 return -EINVAL;
36404@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36405 case IB_CM_MRA_REP_RCVD:
36406 break;
36407 case IB_CM_TIMEWAIT:
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 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36412 goto unlock;
36413@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36414 cm_free_msg(msg);
36415 goto deref;
36416 case IB_CM_DREQ_RCVD:
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 goto unlock;
36421 default:
36422@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36423 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36424 cm_id_priv->msg, timeout)) {
36425 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36426- atomic_long_inc(&work->port->
36427+ atomic_long_inc_unchecked(&work->port->
36428 counter_group[CM_RECV_DUPLICATES].
36429 counter[CM_MRA_COUNTER]);
36430 goto out;
36431@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36432 break;
36433 case IB_CM_MRA_REQ_RCVD:
36434 case IB_CM_MRA_REP_RCVD:
36435- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36436+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36437 counter[CM_MRA_COUNTER]);
36438 /* fall through */
36439 default:
36440@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36441 case IB_CM_LAP_IDLE:
36442 break;
36443 case IB_CM_MRA_LAP_SENT:
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_LAP_COUNTER]);
36447 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36448 goto unlock;
36449@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36450 cm_free_msg(msg);
36451 goto deref;
36452 case IB_CM_LAP_RCVD:
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 goto unlock;
36457 default:
36458@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36459 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36460 if (cur_cm_id_priv) {
36461 spin_unlock_irq(&cm.lock);
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_SIDR_REQ_COUNTER]);
36465 goto out; /* Duplicate message. */
36466 }
36467@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36468 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36469 msg->retries = 1;
36470
36471- atomic_long_add(1 + msg->retries,
36472+ atomic_long_add_unchecked(1 + msg->retries,
36473 &port->counter_group[CM_XMIT].counter[attr_index]);
36474 if (msg->retries)
36475- atomic_long_add(msg->retries,
36476+ atomic_long_add_unchecked(msg->retries,
36477 &port->counter_group[CM_XMIT_RETRIES].
36478 counter[attr_index]);
36479
36480@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36481 }
36482
36483 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36484- atomic_long_inc(&port->counter_group[CM_RECV].
36485+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36486 counter[attr_id - CM_ATTR_ID_OFFSET]);
36487
36488 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36489@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36490 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36491
36492 return sprintf(buf, "%ld\n",
36493- atomic_long_read(&group->counter[cm_attr->index]));
36494+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36495 }
36496
36497 static const struct sysfs_ops cm_counter_ops = {
36498diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36499index 176c8f9..2627b62 100644
36500--- a/drivers/infiniband/core/fmr_pool.c
36501+++ b/drivers/infiniband/core/fmr_pool.c
36502@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36503
36504 struct task_struct *thread;
36505
36506- atomic_t req_ser;
36507- atomic_t flush_ser;
36508+ atomic_unchecked_t req_ser;
36509+ atomic_unchecked_t flush_ser;
36510
36511 wait_queue_head_t force_wait;
36512 };
36513@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36514 struct ib_fmr_pool *pool = pool_ptr;
36515
36516 do {
36517- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36518+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36519 ib_fmr_batch_release(pool);
36520
36521- atomic_inc(&pool->flush_ser);
36522+ atomic_inc_unchecked(&pool->flush_ser);
36523 wake_up_interruptible(&pool->force_wait);
36524
36525 if (pool->flush_function)
36526@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36527 }
36528
36529 set_current_state(TASK_INTERRUPTIBLE);
36530- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36531+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36532 !kthread_should_stop())
36533 schedule();
36534 __set_current_state(TASK_RUNNING);
36535@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36536 pool->dirty_watermark = params->dirty_watermark;
36537 pool->dirty_len = 0;
36538 spin_lock_init(&pool->pool_lock);
36539- atomic_set(&pool->req_ser, 0);
36540- atomic_set(&pool->flush_ser, 0);
36541+ atomic_set_unchecked(&pool->req_ser, 0);
36542+ atomic_set_unchecked(&pool->flush_ser, 0);
36543 init_waitqueue_head(&pool->force_wait);
36544
36545 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36546@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36547 }
36548 spin_unlock_irq(&pool->pool_lock);
36549
36550- serial = atomic_inc_return(&pool->req_ser);
36551+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36552 wake_up_process(pool->thread);
36553
36554 if (wait_event_interruptible(pool->force_wait,
36555- atomic_read(&pool->flush_ser) - serial >= 0))
36556+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36557 return -EINTR;
36558
36559 return 0;
36560@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36561 } else {
36562 list_add_tail(&fmr->list, &pool->dirty_list);
36563 if (++pool->dirty_len >= pool->dirty_watermark) {
36564- atomic_inc(&pool->req_ser);
36565+ atomic_inc_unchecked(&pool->req_ser);
36566 wake_up_process(pool->thread);
36567 }
36568 }
36569diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36570index afd8179..598063f 100644
36571--- a/drivers/infiniband/hw/cxgb4/mem.c
36572+++ b/drivers/infiniband/hw/cxgb4/mem.c
36573@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36574 int err;
36575 struct fw_ri_tpte tpt;
36576 u32 stag_idx;
36577- static atomic_t key;
36578+ static atomic_unchecked_t key;
36579
36580 if (c4iw_fatal_error(rdev))
36581 return -EIO;
36582@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36583 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36584 rdev->stats.stag.max = rdev->stats.stag.cur;
36585 mutex_unlock(&rdev->stats.lock);
36586- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36587+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36588 }
36589 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36590 __func__, stag_state, type, pdid, stag_idx);
36591diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36592index 79b3dbc..96e5fcc 100644
36593--- a/drivers/infiniband/hw/ipath/ipath_rc.c
36594+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36595@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36596 struct ib_atomic_eth *ateth;
36597 struct ipath_ack_entry *e;
36598 u64 vaddr;
36599- atomic64_t *maddr;
36600+ atomic64_unchecked_t *maddr;
36601 u64 sdata;
36602 u32 rkey;
36603 u8 next;
36604@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36605 IB_ACCESS_REMOTE_ATOMIC)))
36606 goto nack_acc_unlck;
36607 /* Perform atomic OP and save result. */
36608- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36609+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36610 sdata = be64_to_cpu(ateth->swap_data);
36611 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36612 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36613- (u64) atomic64_add_return(sdata, maddr) - sdata :
36614+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36615 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36616 be64_to_cpu(ateth->compare_data),
36617 sdata);
36618diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36619index 1f95bba..9530f87 100644
36620--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36621+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36622@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36623 unsigned long flags;
36624 struct ib_wc wc;
36625 u64 sdata;
36626- atomic64_t *maddr;
36627+ atomic64_unchecked_t *maddr;
36628 enum ib_wc_status send_status;
36629
36630 /*
36631@@ -382,11 +382,11 @@ again:
36632 IB_ACCESS_REMOTE_ATOMIC)))
36633 goto acc_err;
36634 /* Perform atomic OP and save result. */
36635- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36636+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36637 sdata = wqe->wr.wr.atomic.compare_add;
36638 *(u64 *) sqp->s_sge.sge.vaddr =
36639 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36640- (u64) atomic64_add_return(sdata, maddr) - sdata :
36641+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36642 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36643 sdata, wqe->wr.wr.atomic.swap);
36644 goto send_comp;
36645diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
36646index 9d3e5c1..d9afe4a 100644
36647--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
36648+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
36649@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
36650 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
36651 }
36652
36653-int mthca_QUERY_FW(struct mthca_dev *dev)
36654+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
36655 {
36656 struct mthca_mailbox *mailbox;
36657 u32 *outbox;
36658diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
36659index ed9a989..e0c5871 100644
36660--- a/drivers/infiniband/hw/mthca/mthca_mr.c
36661+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
36662@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
36663 return key;
36664 }
36665
36666-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36667+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36668 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
36669 {
36670 struct mthca_mailbox *mailbox;
36671diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36672index 5b152a3..c1f3e83 100644
36673--- a/drivers/infiniband/hw/nes/nes.c
36674+++ b/drivers/infiniband/hw/nes/nes.c
36675@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36676 LIST_HEAD(nes_adapter_list);
36677 static LIST_HEAD(nes_dev_list);
36678
36679-atomic_t qps_destroyed;
36680+atomic_unchecked_t qps_destroyed;
36681
36682 static unsigned int ee_flsh_adapter;
36683 static unsigned int sysfs_nonidx_addr;
36684@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36685 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36686 struct nes_adapter *nesadapter = nesdev->nesadapter;
36687
36688- atomic_inc(&qps_destroyed);
36689+ atomic_inc_unchecked(&qps_destroyed);
36690
36691 /* Free the control structures */
36692
36693diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36694index 33cc589..3bd6538 100644
36695--- a/drivers/infiniband/hw/nes/nes.h
36696+++ b/drivers/infiniband/hw/nes/nes.h
36697@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36698 extern unsigned int wqm_quanta;
36699 extern struct list_head nes_adapter_list;
36700
36701-extern atomic_t cm_connects;
36702-extern atomic_t cm_accepts;
36703-extern atomic_t cm_disconnects;
36704-extern atomic_t cm_closes;
36705-extern atomic_t cm_connecteds;
36706-extern atomic_t cm_connect_reqs;
36707-extern atomic_t cm_rejects;
36708-extern atomic_t mod_qp_timouts;
36709-extern atomic_t qps_created;
36710-extern atomic_t qps_destroyed;
36711-extern atomic_t sw_qps_destroyed;
36712+extern atomic_unchecked_t cm_connects;
36713+extern atomic_unchecked_t cm_accepts;
36714+extern atomic_unchecked_t cm_disconnects;
36715+extern atomic_unchecked_t cm_closes;
36716+extern atomic_unchecked_t cm_connecteds;
36717+extern atomic_unchecked_t cm_connect_reqs;
36718+extern atomic_unchecked_t cm_rejects;
36719+extern atomic_unchecked_t mod_qp_timouts;
36720+extern atomic_unchecked_t qps_created;
36721+extern atomic_unchecked_t qps_destroyed;
36722+extern atomic_unchecked_t sw_qps_destroyed;
36723 extern u32 mh_detected;
36724 extern u32 mh_pauses_sent;
36725 extern u32 cm_packets_sent;
36726@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36727 extern u32 cm_packets_received;
36728 extern u32 cm_packets_dropped;
36729 extern u32 cm_packets_retrans;
36730-extern atomic_t cm_listens_created;
36731-extern atomic_t cm_listens_destroyed;
36732+extern atomic_unchecked_t cm_listens_created;
36733+extern atomic_unchecked_t cm_listens_destroyed;
36734 extern u32 cm_backlog_drops;
36735-extern atomic_t cm_loopbacks;
36736-extern atomic_t cm_nodes_created;
36737-extern atomic_t cm_nodes_destroyed;
36738-extern atomic_t cm_accel_dropped_pkts;
36739-extern atomic_t cm_resets_recvd;
36740-extern atomic_t pau_qps_created;
36741-extern atomic_t pau_qps_destroyed;
36742+extern atomic_unchecked_t cm_loopbacks;
36743+extern atomic_unchecked_t cm_nodes_created;
36744+extern atomic_unchecked_t cm_nodes_destroyed;
36745+extern atomic_unchecked_t cm_accel_dropped_pkts;
36746+extern atomic_unchecked_t cm_resets_recvd;
36747+extern atomic_unchecked_t pau_qps_created;
36748+extern atomic_unchecked_t pau_qps_destroyed;
36749
36750 extern u32 int_mod_timer_init;
36751 extern u32 int_mod_cq_depth_256;
36752diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36753index 22ea67e..dcbe3bc 100644
36754--- a/drivers/infiniband/hw/nes/nes_cm.c
36755+++ b/drivers/infiniband/hw/nes/nes_cm.c
36756@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36757 u32 cm_packets_retrans;
36758 u32 cm_packets_created;
36759 u32 cm_packets_received;
36760-atomic_t cm_listens_created;
36761-atomic_t cm_listens_destroyed;
36762+atomic_unchecked_t cm_listens_created;
36763+atomic_unchecked_t cm_listens_destroyed;
36764 u32 cm_backlog_drops;
36765-atomic_t cm_loopbacks;
36766-atomic_t cm_nodes_created;
36767-atomic_t cm_nodes_destroyed;
36768-atomic_t cm_accel_dropped_pkts;
36769-atomic_t cm_resets_recvd;
36770+atomic_unchecked_t cm_loopbacks;
36771+atomic_unchecked_t cm_nodes_created;
36772+atomic_unchecked_t cm_nodes_destroyed;
36773+atomic_unchecked_t cm_accel_dropped_pkts;
36774+atomic_unchecked_t cm_resets_recvd;
36775
36776 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36777 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36778@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36779
36780 static struct nes_cm_core *g_cm_core;
36781
36782-atomic_t cm_connects;
36783-atomic_t cm_accepts;
36784-atomic_t cm_disconnects;
36785-atomic_t cm_closes;
36786-atomic_t cm_connecteds;
36787-atomic_t cm_connect_reqs;
36788-atomic_t cm_rejects;
36789+atomic_unchecked_t cm_connects;
36790+atomic_unchecked_t cm_accepts;
36791+atomic_unchecked_t cm_disconnects;
36792+atomic_unchecked_t cm_closes;
36793+atomic_unchecked_t cm_connecteds;
36794+atomic_unchecked_t cm_connect_reqs;
36795+atomic_unchecked_t cm_rejects;
36796
36797 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36798 {
36799@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36800 kfree(listener);
36801 listener = NULL;
36802 ret = 0;
36803- atomic_inc(&cm_listens_destroyed);
36804+ atomic_inc_unchecked(&cm_listens_destroyed);
36805 } else {
36806 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36807 }
36808@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36809 cm_node->rem_mac);
36810
36811 add_hte_node(cm_core, cm_node);
36812- atomic_inc(&cm_nodes_created);
36813+ atomic_inc_unchecked(&cm_nodes_created);
36814
36815 return cm_node;
36816 }
36817@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36818 }
36819
36820 atomic_dec(&cm_core->node_cnt);
36821- atomic_inc(&cm_nodes_destroyed);
36822+ atomic_inc_unchecked(&cm_nodes_destroyed);
36823 nesqp = cm_node->nesqp;
36824 if (nesqp) {
36825 nesqp->cm_node = NULL;
36826@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36827
36828 static void drop_packet(struct sk_buff *skb)
36829 {
36830- atomic_inc(&cm_accel_dropped_pkts);
36831+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36832 dev_kfree_skb_any(skb);
36833 }
36834
36835@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36836 {
36837
36838 int reset = 0; /* whether to send reset in case of err.. */
36839- atomic_inc(&cm_resets_recvd);
36840+ atomic_inc_unchecked(&cm_resets_recvd);
36841 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36842 " refcnt=%d\n", cm_node, cm_node->state,
36843 atomic_read(&cm_node->ref_count));
36844@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36845 rem_ref_cm_node(cm_node->cm_core, cm_node);
36846 return NULL;
36847 }
36848- atomic_inc(&cm_loopbacks);
36849+ atomic_inc_unchecked(&cm_loopbacks);
36850 loopbackremotenode->loopbackpartner = cm_node;
36851 loopbackremotenode->tcp_cntxt.rcv_wscale =
36852 NES_CM_DEFAULT_RCV_WND_SCALE;
36853@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36854 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36855 else {
36856 rem_ref_cm_node(cm_core, cm_node);
36857- atomic_inc(&cm_accel_dropped_pkts);
36858+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36859 dev_kfree_skb_any(skb);
36860 }
36861 break;
36862@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36863
36864 if ((cm_id) && (cm_id->event_handler)) {
36865 if (issue_disconn) {
36866- atomic_inc(&cm_disconnects);
36867+ atomic_inc_unchecked(&cm_disconnects);
36868 cm_event.event = IW_CM_EVENT_DISCONNECT;
36869 cm_event.status = disconn_status;
36870 cm_event.local_addr = cm_id->local_addr;
36871@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36872 }
36873
36874 if (issue_close) {
36875- atomic_inc(&cm_closes);
36876+ atomic_inc_unchecked(&cm_closes);
36877 nes_disconnect(nesqp, 1);
36878
36879 cm_id->provider_data = nesqp;
36880@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36881
36882 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36883 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36884- atomic_inc(&cm_accepts);
36885+ atomic_inc_unchecked(&cm_accepts);
36886
36887 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36888 netdev_refcnt_read(nesvnic->netdev));
36889@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36890 struct nes_cm_core *cm_core;
36891 u8 *start_buff;
36892
36893- atomic_inc(&cm_rejects);
36894+ atomic_inc_unchecked(&cm_rejects);
36895 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36896 loopback = cm_node->loopbackpartner;
36897 cm_core = cm_node->cm_core;
36898@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36899 ntohl(cm_id->local_addr.sin_addr.s_addr),
36900 ntohs(cm_id->local_addr.sin_port));
36901
36902- atomic_inc(&cm_connects);
36903+ atomic_inc_unchecked(&cm_connects);
36904 nesqp->active_conn = 1;
36905
36906 /* cache the cm_id in the qp */
36907@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36908 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36909 return err;
36910 }
36911- atomic_inc(&cm_listens_created);
36912+ atomic_inc_unchecked(&cm_listens_created);
36913 }
36914
36915 cm_id->add_ref(cm_id);
36916@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36917
36918 if (nesqp->destroyed)
36919 return;
36920- atomic_inc(&cm_connecteds);
36921+ atomic_inc_unchecked(&cm_connecteds);
36922 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36923 " local port 0x%04X. jiffies = %lu.\n",
36924 nesqp->hwqp.qp_id,
36925@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36926
36927 cm_id->add_ref(cm_id);
36928 ret = cm_id->event_handler(cm_id, &cm_event);
36929- atomic_inc(&cm_closes);
36930+ atomic_inc_unchecked(&cm_closes);
36931 cm_event.event = IW_CM_EVENT_CLOSE;
36932 cm_event.status = 0;
36933 cm_event.provider_data = cm_id->provider_data;
36934@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36935 return;
36936 cm_id = cm_node->cm_id;
36937
36938- atomic_inc(&cm_connect_reqs);
36939+ atomic_inc_unchecked(&cm_connect_reqs);
36940 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36941 cm_node, cm_id, jiffies);
36942
36943@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(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
36952diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36953index 4166452..fc952c3 100644
36954--- a/drivers/infiniband/hw/nes/nes_mgt.c
36955+++ b/drivers/infiniband/hw/nes/nes_mgt.c
36956@@ -40,8 +40,8 @@
36957 #include "nes.h"
36958 #include "nes_mgt.h"
36959
36960-atomic_t pau_qps_created;
36961-atomic_t pau_qps_destroyed;
36962+atomic_unchecked_t pau_qps_created;
36963+atomic_unchecked_t pau_qps_destroyed;
36964
36965 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36966 {
36967@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36968 {
36969 struct sk_buff *skb;
36970 unsigned long flags;
36971- atomic_inc(&pau_qps_destroyed);
36972+ atomic_inc_unchecked(&pau_qps_destroyed);
36973
36974 /* Free packets that have not yet been forwarded */
36975 /* Lock is acquired by skb_dequeue when removing the skb */
36976@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36977 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36978 skb_queue_head_init(&nesqp->pau_list);
36979 spin_lock_init(&nesqp->pau_lock);
36980- atomic_inc(&pau_qps_created);
36981+ atomic_inc_unchecked(&pau_qps_created);
36982 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
36983 }
36984
36985diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
36986index 9542e16..a008c40 100644
36987--- a/drivers/infiniband/hw/nes/nes_nic.c
36988+++ b/drivers/infiniband/hw/nes/nes_nic.c
36989@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
36990 target_stat_values[++index] = mh_detected;
36991 target_stat_values[++index] = mh_pauses_sent;
36992 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
36993- target_stat_values[++index] = atomic_read(&cm_connects);
36994- target_stat_values[++index] = atomic_read(&cm_accepts);
36995- target_stat_values[++index] = atomic_read(&cm_disconnects);
36996- target_stat_values[++index] = atomic_read(&cm_connecteds);
36997- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
36998- target_stat_values[++index] = atomic_read(&cm_rejects);
36999- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37000- target_stat_values[++index] = atomic_read(&qps_created);
37001- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37002- target_stat_values[++index] = atomic_read(&qps_destroyed);
37003- target_stat_values[++index] = atomic_read(&cm_closes);
37004+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37005+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37006+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37007+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37008+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37009+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37010+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37011+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37012+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37013+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37014+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37015 target_stat_values[++index] = cm_packets_sent;
37016 target_stat_values[++index] = cm_packets_bounced;
37017 target_stat_values[++index] = cm_packets_created;
37018 target_stat_values[++index] = cm_packets_received;
37019 target_stat_values[++index] = cm_packets_dropped;
37020 target_stat_values[++index] = cm_packets_retrans;
37021- target_stat_values[++index] = atomic_read(&cm_listens_created);
37022- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37023+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37024+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37025 target_stat_values[++index] = cm_backlog_drops;
37026- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37027- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37028- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37029- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37030- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37031+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37032+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37033+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37034+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37035+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37036 target_stat_values[++index] = nesadapter->free_4kpbl;
37037 target_stat_values[++index] = nesadapter->free_256pbl;
37038 target_stat_values[++index] = int_mod_timer_init;
37039 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37040 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37041 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37042- target_stat_values[++index] = atomic_read(&pau_qps_created);
37043- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37044+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37045+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37046 }
37047
37048 /**
37049diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37050index 07e4fba..685f041 100644
37051--- a/drivers/infiniband/hw/nes/nes_verbs.c
37052+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37053@@ -46,9 +46,9 @@
37054
37055 #include <rdma/ib_umem.h>
37056
37057-atomic_t mod_qp_timouts;
37058-atomic_t qps_created;
37059-atomic_t sw_qps_destroyed;
37060+atomic_unchecked_t mod_qp_timouts;
37061+atomic_unchecked_t qps_created;
37062+atomic_unchecked_t sw_qps_destroyed;
37063
37064 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37065
37066@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37067 if (init_attr->create_flags)
37068 return ERR_PTR(-EINVAL);
37069
37070- atomic_inc(&qps_created);
37071+ atomic_inc_unchecked(&qps_created);
37072 switch (init_attr->qp_type) {
37073 case IB_QPT_RC:
37074 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37075@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37076 struct iw_cm_event cm_event;
37077 int ret = 0;
37078
37079- atomic_inc(&sw_qps_destroyed);
37080+ atomic_inc_unchecked(&sw_qps_destroyed);
37081 nesqp->destroyed = 1;
37082
37083 /* Blow away the connection if it exists. */
37084diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37085index 4d11575..3e890e5 100644
37086--- a/drivers/infiniband/hw/qib/qib.h
37087+++ b/drivers/infiniband/hw/qib/qib.h
37088@@ -51,6 +51,7 @@
37089 #include <linux/completion.h>
37090 #include <linux/kref.h>
37091 #include <linux/sched.h>
37092+#include <linux/slab.h>
37093
37094 #include "qib_common.h"
37095 #include "qib_verbs.h"
37096diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37097index da739d9..da1c7f4 100644
37098--- a/drivers/input/gameport/gameport.c
37099+++ b/drivers/input/gameport/gameport.c
37100@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37101 */
37102 static void gameport_init_port(struct gameport *gameport)
37103 {
37104- static atomic_t gameport_no = ATOMIC_INIT(0);
37105+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37106
37107 __module_get(THIS_MODULE);
37108
37109 mutex_init(&gameport->drv_mutex);
37110 device_initialize(&gameport->dev);
37111 dev_set_name(&gameport->dev, "gameport%lu",
37112- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37113+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37114 gameport->dev.bus = &gameport_bus;
37115 gameport->dev.release = gameport_release_port;
37116 if (gameport->parent)
37117diff --git a/drivers/input/input.c b/drivers/input/input.c
37118index c044699..174d71a 100644
37119--- a/drivers/input/input.c
37120+++ b/drivers/input/input.c
37121@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37122 */
37123 int input_register_device(struct input_dev *dev)
37124 {
37125- static atomic_t input_no = ATOMIC_INIT(0);
37126+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37127 struct input_devres *devres = NULL;
37128 struct input_handler *handler;
37129 unsigned int packet_size;
37130@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37131 dev->setkeycode = input_default_setkeycode;
37132
37133 dev_set_name(&dev->dev, "input%ld",
37134- (unsigned long) atomic_inc_return(&input_no) - 1);
37135+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37136
37137 error = device_add(&dev->dev);
37138 if (error)
37139diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37140index 04c69af..5f92d00 100644
37141--- a/drivers/input/joystick/sidewinder.c
37142+++ b/drivers/input/joystick/sidewinder.c
37143@@ -30,6 +30,7 @@
37144 #include <linux/kernel.h>
37145 #include <linux/module.h>
37146 #include <linux/slab.h>
37147+#include <linux/sched.h>
37148 #include <linux/init.h>
37149 #include <linux/input.h>
37150 #include <linux/gameport.h>
37151diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37152index d6cbfe9..6225402 100644
37153--- a/drivers/input/joystick/xpad.c
37154+++ b/drivers/input/joystick/xpad.c
37155@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37156
37157 static int xpad_led_probe(struct usb_xpad *xpad)
37158 {
37159- static atomic_t led_seq = ATOMIC_INIT(0);
37160+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37161 long led_no;
37162 struct xpad_led *led;
37163 struct led_classdev *led_cdev;
37164@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37165 if (!led)
37166 return -ENOMEM;
37167
37168- led_no = (long)atomic_inc_return(&led_seq) - 1;
37169+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37170
37171 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37172 led->xpad = xpad;
37173diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37174index fe1df23..5b710f3 100644
37175--- a/drivers/input/mouse/psmouse.h
37176+++ b/drivers/input/mouse/psmouse.h
37177@@ -115,7 +115,7 @@ struct psmouse_attribute {
37178 ssize_t (*set)(struct psmouse *psmouse, void *data,
37179 const char *buf, size_t count);
37180 bool protect;
37181-};
37182+} __do_const;
37183 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37184
37185 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37186diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37187index 4c842c3..590b0bf 100644
37188--- a/drivers/input/mousedev.c
37189+++ b/drivers/input/mousedev.c
37190@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37191
37192 spin_unlock_irq(&client->packet_lock);
37193
37194- if (copy_to_user(buffer, data, count))
37195+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37196 return -EFAULT;
37197
37198 return count;
37199diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37200index 25fc597..558bf3b 100644
37201--- a/drivers/input/serio/serio.c
37202+++ b/drivers/input/serio/serio.c
37203@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37204 */
37205 static void serio_init_port(struct serio *serio)
37206 {
37207- static atomic_t serio_no = ATOMIC_INIT(0);
37208+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37209
37210 __module_get(THIS_MODULE);
37211
37212@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37213 mutex_init(&serio->drv_mutex);
37214 device_initialize(&serio->dev);
37215 dev_set_name(&serio->dev, "serio%ld",
37216- (long)atomic_inc_return(&serio_no) - 1);
37217+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37218 serio->dev.bus = &serio_bus;
37219 serio->dev.release = serio_release_port;
37220 serio->dev.groups = serio_device_attr_groups;
37221diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37222index ddbdaca..be18a78 100644
37223--- a/drivers/iommu/iommu.c
37224+++ b/drivers/iommu/iommu.c
37225@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37226 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37227 {
37228 bus_register_notifier(bus, &iommu_bus_nb);
37229- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37230+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37231 }
37232
37233 /**
37234diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37235index 89562a8..218999b 100644
37236--- a/drivers/isdn/capi/capi.c
37237+++ b/drivers/isdn/capi/capi.c
37238@@ -81,8 +81,8 @@ struct capiminor {
37239
37240 struct capi20_appl *ap;
37241 u32 ncci;
37242- atomic_t datahandle;
37243- atomic_t msgid;
37244+ atomic_unchecked_t datahandle;
37245+ atomic_unchecked_t msgid;
37246
37247 struct tty_port port;
37248 int ttyinstop;
37249@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37250 capimsg_setu16(s, 2, mp->ap->applid);
37251 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37252 capimsg_setu8 (s, 5, CAPI_RESP);
37253- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37254+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37255 capimsg_setu32(s, 8, mp->ncci);
37256 capimsg_setu16(s, 12, datahandle);
37257 }
37258@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37259 mp->outbytes -= len;
37260 spin_unlock_bh(&mp->outlock);
37261
37262- datahandle = atomic_inc_return(&mp->datahandle);
37263+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37264 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37265 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37266 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37267 capimsg_setu16(skb->data, 2, mp->ap->applid);
37268 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37269 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37270- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37271+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37272 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37273 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37274 capimsg_setu16(skb->data, 16, len); /* Data length */
37275diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37276index 67abf3f..076b3a6 100644
37277--- a/drivers/isdn/gigaset/interface.c
37278+++ b/drivers/isdn/gigaset/interface.c
37279@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37280 }
37281 tty->driver_data = cs;
37282
37283- ++cs->port.count;
37284+ atomic_inc(&cs->port.count);
37285
37286- if (cs->port.count == 1) {
37287+ if (atomic_read(&cs->port.count) == 1) {
37288 tty_port_tty_set(&cs->port, tty);
37289 tty->low_latency = 1;
37290 }
37291@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37292
37293 if (!cs->connected)
37294 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37295- else if (!cs->port.count)
37296+ else if (!atomic_read(&cs->port.count))
37297 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37298- else if (!--cs->port.count)
37299+ else if (!atomic_dec_return(&cs->port.count))
37300 tty_port_tty_set(&cs->port, NULL);
37301
37302 mutex_unlock(&cs->mutex);
37303diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37304index 821f7ac..28d4030 100644
37305--- a/drivers/isdn/hardware/avm/b1.c
37306+++ b/drivers/isdn/hardware/avm/b1.c
37307@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37308 }
37309 if (left) {
37310 if (t4file->user) {
37311- if (copy_from_user(buf, dp, left))
37312+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37313 return -EFAULT;
37314 } else {
37315 memcpy(buf, dp, left);
37316@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37317 }
37318 if (left) {
37319 if (config->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);
37325diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37326index e09dc8a..15e2efb 100644
37327--- a/drivers/isdn/i4l/isdn_tty.c
37328+++ b/drivers/isdn/i4l/isdn_tty.c
37329@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37330
37331 #ifdef ISDN_DEBUG_MODEM_OPEN
37332 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37333- port->count);
37334+ atomic_read(&port->count));
37335 #endif
37336- port->count++;
37337+ atomic_inc(&port->count);
37338 port->tty = tty;
37339 /*
37340 * Start up serial port
37341@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37342 #endif
37343 return;
37344 }
37345- if ((tty->count == 1) && (port->count != 1)) {
37346+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37347 /*
37348 * Uh, oh. tty->count is 1, which means that the tty
37349 * structure will be freed. Info->count should always
37350@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37351 * serial port won't be shutdown.
37352 */
37353 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37354- "info->count is %d\n", port->count);
37355- port->count = 1;
37356+ "info->count is %d\n", atomic_read(&port->count));
37357+ atomic_set(&port->count, 1);
37358 }
37359- if (--port->count < 0) {
37360+ if (atomic_dec_return(&port->count) < 0) {
37361 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37362- info->line, port->count);
37363- port->count = 0;
37364+ info->line, atomic_read(&port->count));
37365+ atomic_set(&port->count, 0);
37366 }
37367- if (port->count) {
37368+ if (atomic_read(&port->count)) {
37369 #ifdef ISDN_DEBUG_MODEM_OPEN
37370 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37371 #endif
37372@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37373 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37374 return;
37375 isdn_tty_shutdown(info);
37376- port->count = 0;
37377+ atomic_set(&port->count, 0);
37378 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37379 port->tty = NULL;
37380 wake_up_interruptible(&port->open_wait);
37381@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37382 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37383 modem_info *info = &dev->mdm.info[i];
37384
37385- if (info->port.count == 0)
37386+ if (atomic_read(&info->port.count) == 0)
37387 continue;
37388 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37389 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37390diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37391index e74df7c..03a03ba 100644
37392--- a/drivers/isdn/icn/icn.c
37393+++ b/drivers/isdn/icn/icn.c
37394@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37395 if (count > len)
37396 count = len;
37397 if (user) {
37398- if (copy_from_user(msg, buf, count))
37399+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37400 return -EFAULT;
37401 } else
37402 memcpy(msg, buf, count);
37403diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37404index 6a8405d..0bd1c7e 100644
37405--- a/drivers/leds/leds-clevo-mail.c
37406+++ b/drivers/leds/leds-clevo-mail.c
37407@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37408 * detected as working, but in reality it is not) as low as
37409 * possible.
37410 */
37411-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37412+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37413 {
37414 .callback = clevo_mail_led_dmi_callback,
37415 .ident = "Clevo D410J",
37416diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37417index ec9b287..65c9bf4 100644
37418--- a/drivers/leds/leds-ss4200.c
37419+++ b/drivers/leds/leds-ss4200.c
37420@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37421 * detected as working, but in reality it is not) as low as
37422 * possible.
37423 */
37424-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37425+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37426 {
37427 .callback = ss4200_led_dmi_callback,
37428 .ident = "Intel SS4200-E",
37429diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37430index a5ebc00..982886f 100644
37431--- a/drivers/lguest/core.c
37432+++ b/drivers/lguest/core.c
37433@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37434 * it's worked so far. The end address needs +1 because __get_vm_area
37435 * allocates an extra guard page, so we need space for that.
37436 */
37437+
37438+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37439+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37440+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37441+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37442+#else
37443 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37444 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37445 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37446+#endif
37447+
37448 if (!switcher_vma) {
37449 err = -ENOMEM;
37450 printk("lguest: could not map switcher pages high\n");
37451@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37452 * Now the Switcher is mapped at the right address, we can't fail!
37453 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37454 */
37455- memcpy(switcher_vma->addr, start_switcher_text,
37456+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37457 end_switcher_text - start_switcher_text);
37458
37459 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37460diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37461index 3b62be16..e33134a 100644
37462--- a/drivers/lguest/page_tables.c
37463+++ b/drivers/lguest/page_tables.c
37464@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37465 /*:*/
37466
37467 #ifdef CONFIG_X86_PAE
37468-static void release_pmd(pmd_t *spmd)
37469+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37470 {
37471 /* If the entry's not present, there's nothing to release. */
37472 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37473diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37474index 4af12e1..0e89afe 100644
37475--- a/drivers/lguest/x86/core.c
37476+++ b/drivers/lguest/x86/core.c
37477@@ -59,7 +59,7 @@ static struct {
37478 /* Offset from where switcher.S was compiled to where we've copied it */
37479 static unsigned long switcher_offset(void)
37480 {
37481- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37482+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37483 }
37484
37485 /* This cpu's struct lguest_pages. */
37486@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37487 * These copies are pretty cheap, so we do them unconditionally: */
37488 /* Save the current Host top-level page directory.
37489 */
37490+
37491+#ifdef CONFIG_PAX_PER_CPU_PGD
37492+ pages->state.host_cr3 = read_cr3();
37493+#else
37494 pages->state.host_cr3 = __pa(current->mm->pgd);
37495+#endif
37496+
37497 /*
37498 * Set up the Guest's page tables to see this CPU's pages (and no
37499 * other CPU's pages).
37500@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37501 * compiled-in switcher code and the high-mapped copy we just made.
37502 */
37503 for (i = 0; i < IDT_ENTRIES; i++)
37504- default_idt_entries[i] += switcher_offset();
37505+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37506
37507 /*
37508 * Set up the Switcher's per-cpu areas.
37509@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37510 * it will be undisturbed when we switch. To change %cs and jump we
37511 * need this structure to feed to Intel's "lcall" instruction.
37512 */
37513- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37514+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37515 lguest_entry.segment = LGUEST_CS;
37516
37517 /*
37518diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37519index 40634b0..4f5855e 100644
37520--- a/drivers/lguest/x86/switcher_32.S
37521+++ b/drivers/lguest/x86/switcher_32.S
37522@@ -87,6 +87,7 @@
37523 #include <asm/page.h>
37524 #include <asm/segment.h>
37525 #include <asm/lguest.h>
37526+#include <asm/processor-flags.h>
37527
37528 // We mark the start of the code to copy
37529 // It's placed in .text tho it's never run here
37530@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37531 // Changes type when we load it: damn Intel!
37532 // For after we switch over our page tables
37533 // That entry will be read-only: we'd crash.
37534+
37535+#ifdef CONFIG_PAX_KERNEXEC
37536+ mov %cr0, %edx
37537+ xor $X86_CR0_WP, %edx
37538+ mov %edx, %cr0
37539+#endif
37540+
37541 movl $(GDT_ENTRY_TSS*8), %edx
37542 ltr %dx
37543
37544@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37545 // Let's clear it again for our return.
37546 // The GDT descriptor of the Host
37547 // Points to the table after two "size" bytes
37548- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37549+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37550 // Clear "used" from type field (byte 5, bit 2)
37551- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37552+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37553+
37554+#ifdef CONFIG_PAX_KERNEXEC
37555+ mov %cr0, %eax
37556+ xor $X86_CR0_WP, %eax
37557+ mov %eax, %cr0
37558+#endif
37559
37560 // Once our page table's switched, the Guest is live!
37561 // The Host fades as we run this final step.
37562@@ -295,13 +309,12 @@ deliver_to_host:
37563 // I consulted gcc, and it gave
37564 // These instructions, which I gladly credit:
37565 leal (%edx,%ebx,8), %eax
37566- movzwl (%eax),%edx
37567- movl 4(%eax), %eax
37568- xorw %ax, %ax
37569- orl %eax, %edx
37570+ movl 4(%eax), %edx
37571+ movw (%eax), %dx
37572 // Now the address of the handler's in %edx
37573 // We call it now: its "iret" drops us home.
37574- jmp *%edx
37575+ ljmp $__KERNEL_CS, $1f
37576+1: jmp *%edx
37577
37578 // Every interrupt can come to us here
37579 // But we must truly tell each apart.
37580diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37581index 7155945..4bcc562 100644
37582--- a/drivers/md/bitmap.c
37583+++ b/drivers/md/bitmap.c
37584@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37585 chunk_kb ? "KB" : "B");
37586 if (bitmap->storage.file) {
37587 seq_printf(seq, ", file: ");
37588- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37589+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37590 }
37591
37592 seq_printf(seq, "\n");
37593diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37594index eee353d..74504c4 100644
37595--- a/drivers/md/dm-ioctl.c
37596+++ b/drivers/md/dm-ioctl.c
37597@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37598 cmd == DM_LIST_VERSIONS_CMD)
37599 return 0;
37600
37601- if ((cmd == DM_DEV_CREATE_CMD)) {
37602+ if (cmd == DM_DEV_CREATE_CMD) {
37603 if (!*param->name) {
37604 DMWARN("name not supplied when creating device");
37605 return -EINVAL;
37606diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37607index 7f24190..0e18099 100644
37608--- a/drivers/md/dm-raid1.c
37609+++ b/drivers/md/dm-raid1.c
37610@@ -40,7 +40,7 @@ enum dm_raid1_error {
37611
37612 struct mirror {
37613 struct mirror_set *ms;
37614- atomic_t error_count;
37615+ atomic_unchecked_t error_count;
37616 unsigned long error_type;
37617 struct dm_dev *dev;
37618 sector_t offset;
37619@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37620 struct mirror *m;
37621
37622 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37623- if (!atomic_read(&m->error_count))
37624+ if (!atomic_read_unchecked(&m->error_count))
37625 return m;
37626
37627 return NULL;
37628@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37629 * simple way to tell if a device has encountered
37630 * errors.
37631 */
37632- atomic_inc(&m->error_count);
37633+ atomic_inc_unchecked(&m->error_count);
37634
37635 if (test_and_set_bit(error_type, &m->error_type))
37636 return;
37637@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37638 struct mirror *m = get_default_mirror(ms);
37639
37640 do {
37641- if (likely(!atomic_read(&m->error_count)))
37642+ if (likely(!atomic_read_unchecked(&m->error_count)))
37643 return m;
37644
37645 if (m-- == ms->mirror)
37646@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37647 {
37648 struct mirror *default_mirror = get_default_mirror(m->ms);
37649
37650- return !atomic_read(&default_mirror->error_count);
37651+ return !atomic_read_unchecked(&default_mirror->error_count);
37652 }
37653
37654 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37655@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37656 */
37657 if (likely(region_in_sync(ms, region, 1)))
37658 m = choose_mirror(ms, bio->bi_sector);
37659- else if (m && atomic_read(&m->error_count))
37660+ else if (m && atomic_read_unchecked(&m->error_count))
37661 m = NULL;
37662
37663 if (likely(m))
37664@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37665 }
37666
37667 ms->mirror[mirror].ms = ms;
37668- atomic_set(&(ms->mirror[mirror].error_count), 0);
37669+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37670 ms->mirror[mirror].error_type = 0;
37671 ms->mirror[mirror].offset = offset;
37672
37673@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37674 */
37675 static char device_status_char(struct mirror *m)
37676 {
37677- if (!atomic_read(&(m->error_count)))
37678+ if (!atomic_read_unchecked(&(m->error_count)))
37679 return 'A';
37680
37681 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37682diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37683index aaecefa..23b3026 100644
37684--- a/drivers/md/dm-stripe.c
37685+++ b/drivers/md/dm-stripe.c
37686@@ -20,7 +20,7 @@ struct stripe {
37687 struct dm_dev *dev;
37688 sector_t physical_start;
37689
37690- atomic_t error_count;
37691+ atomic_unchecked_t error_count;
37692 };
37693
37694 struct stripe_c {
37695@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37696 kfree(sc);
37697 return r;
37698 }
37699- atomic_set(&(sc->stripe[i].error_count), 0);
37700+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37701 }
37702
37703 ti->private = sc;
37704@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
37705 DMEMIT("%d ", sc->stripes);
37706 for (i = 0; i < sc->stripes; i++) {
37707 DMEMIT("%s ", sc->stripe[i].dev->name);
37708- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37709+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37710 'D' : 'A';
37711 }
37712 buffer[i] = '\0';
37713@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37714 */
37715 for (i = 0; i < sc->stripes; i++)
37716 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37717- atomic_inc(&(sc->stripe[i].error_count));
37718- if (atomic_read(&(sc->stripe[i].error_count)) <
37719+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
37720+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37721 DM_IO_ERROR_THRESHOLD)
37722 schedule_work(&sc->trigger_event);
37723 }
37724diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37725index daf25d0..d74f49f 100644
37726--- a/drivers/md/dm-table.c
37727+++ b/drivers/md/dm-table.c
37728@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37729 if (!dev_size)
37730 return 0;
37731
37732- if ((start >= dev_size) || (start + len > dev_size)) {
37733+ if ((start >= dev_size) || (len > dev_size - start)) {
37734 DMWARN("%s: %s too small for target: "
37735 "start=%llu, len=%llu, dev_size=%llu",
37736 dm_device_name(ti->table->md), bdevname(bdev, b),
37737diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37738index 4d6e853..a234157 100644
37739--- a/drivers/md/dm-thin-metadata.c
37740+++ b/drivers/md/dm-thin-metadata.c
37741@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37742 {
37743 pmd->info.tm = pmd->tm;
37744 pmd->info.levels = 2;
37745- pmd->info.value_type.context = pmd->data_sm;
37746+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37747 pmd->info.value_type.size = sizeof(__le64);
37748 pmd->info.value_type.inc = data_block_inc;
37749 pmd->info.value_type.dec = data_block_dec;
37750@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37751
37752 pmd->bl_info.tm = pmd->tm;
37753 pmd->bl_info.levels = 1;
37754- pmd->bl_info.value_type.context = pmd->data_sm;
37755+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37756 pmd->bl_info.value_type.size = sizeof(__le64);
37757 pmd->bl_info.value_type.inc = data_block_inc;
37758 pmd->bl_info.value_type.dec = data_block_dec;
37759diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37760index 0d8f086..f5a91d5 100644
37761--- a/drivers/md/dm.c
37762+++ b/drivers/md/dm.c
37763@@ -170,9 +170,9 @@ struct mapped_device {
37764 /*
37765 * Event handling.
37766 */
37767- atomic_t event_nr;
37768+ atomic_unchecked_t event_nr;
37769 wait_queue_head_t eventq;
37770- atomic_t uevent_seq;
37771+ atomic_unchecked_t uevent_seq;
37772 struct list_head uevent_list;
37773 spinlock_t uevent_lock; /* Protect access to uevent_list */
37774
37775@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37776 rwlock_init(&md->map_lock);
37777 atomic_set(&md->holders, 1);
37778 atomic_set(&md->open_count, 0);
37779- atomic_set(&md->event_nr, 0);
37780- atomic_set(&md->uevent_seq, 0);
37781+ atomic_set_unchecked(&md->event_nr, 0);
37782+ atomic_set_unchecked(&md->uevent_seq, 0);
37783 INIT_LIST_HEAD(&md->uevent_list);
37784 spin_lock_init(&md->uevent_lock);
37785
37786@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
37787
37788 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37789
37790- atomic_inc(&md->event_nr);
37791+ atomic_inc_unchecked(&md->event_nr);
37792 wake_up(&md->eventq);
37793 }
37794
37795@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37796
37797 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37798 {
37799- return atomic_add_return(1, &md->uevent_seq);
37800+ return atomic_add_return_unchecked(1, &md->uevent_seq);
37801 }
37802
37803 uint32_t dm_get_event_nr(struct mapped_device *md)
37804 {
37805- return atomic_read(&md->event_nr);
37806+ return atomic_read_unchecked(&md->event_nr);
37807 }
37808
37809 int dm_wait_event(struct mapped_device *md, int event_nr)
37810 {
37811 return wait_event_interruptible(md->eventq,
37812- (event_nr != atomic_read(&md->event_nr)));
37813+ (event_nr != atomic_read_unchecked(&md->event_nr)));
37814 }
37815
37816 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37817diff --git a/drivers/md/md.c b/drivers/md/md.c
37818index f363135..9b38815 100644
37819--- a/drivers/md/md.c
37820+++ b/drivers/md/md.c
37821@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37822 * start build, activate spare
37823 */
37824 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37825-static atomic_t md_event_count;
37826+static atomic_unchecked_t md_event_count;
37827 void md_new_event(struct mddev *mddev)
37828 {
37829- atomic_inc(&md_event_count);
37830+ atomic_inc_unchecked(&md_event_count);
37831 wake_up(&md_event_waiters);
37832 }
37833 EXPORT_SYMBOL_GPL(md_new_event);
37834@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37835 */
37836 static void md_new_event_inintr(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
37843@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37844 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37845 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37846 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37847- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37848+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37849
37850 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37851 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37852@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37853 else
37854 sb->resync_offset = cpu_to_le64(0);
37855
37856- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37857+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37858
37859 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37860 sb->size = cpu_to_le64(mddev->dev_sectors);
37861@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37862 static ssize_t
37863 errors_show(struct md_rdev *rdev, char *page)
37864 {
37865- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37866+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37867 }
37868
37869 static ssize_t
37870@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37871 char *e;
37872 unsigned long n = simple_strtoul(buf, &e, 10);
37873 if (*buf && (*e == 0 || *e == '\n')) {
37874- atomic_set(&rdev->corrected_errors, n);
37875+ atomic_set_unchecked(&rdev->corrected_errors, n);
37876 return len;
37877 }
37878 return -EINVAL;
37879@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
37880 rdev->sb_loaded = 0;
37881 rdev->bb_page = NULL;
37882 atomic_set(&rdev->nr_pending, 0);
37883- atomic_set(&rdev->read_errors, 0);
37884- atomic_set(&rdev->corrected_errors, 0);
37885+ atomic_set_unchecked(&rdev->read_errors, 0);
37886+ atomic_set_unchecked(&rdev->corrected_errors, 0);
37887
37888 INIT_LIST_HEAD(&rdev->same_set);
37889 init_waitqueue_head(&rdev->blocked_wait);
37890@@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37891
37892 spin_unlock(&pers_lock);
37893 seq_printf(seq, "\n");
37894- seq->poll_event = atomic_read(&md_event_count);
37895+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37896 return 0;
37897 }
37898 if (v == (void*)2) {
37899@@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37900 return error;
37901
37902 seq = file->private_data;
37903- seq->poll_event = atomic_read(&md_event_count);
37904+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37905 return error;
37906 }
37907
37908@@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37909 /* always allow read */
37910 mask = POLLIN | POLLRDNORM;
37911
37912- if (seq->poll_event != atomic_read(&md_event_count))
37913+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37914 mask |= POLLERR | POLLPRI;
37915 return mask;
37916 }
37917@@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37918 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37919 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37920 (int)part_stat_read(&disk->part0, sectors[1]) -
37921- atomic_read(&disk->sync_io);
37922+ atomic_read_unchecked(&disk->sync_io);
37923 /* sync IO will cause sync_io to increase before the disk_stats
37924 * as sync_io is counted when a request starts, and
37925 * disk_stats is counted when it completes.
37926diff --git a/drivers/md/md.h b/drivers/md/md.h
37927index eca59c3..7c42285 100644
37928--- a/drivers/md/md.h
37929+++ b/drivers/md/md.h
37930@@ -94,13 +94,13 @@ struct md_rdev {
37931 * only maintained for arrays that
37932 * support hot removal
37933 */
37934- atomic_t read_errors; /* number of consecutive read errors that
37935+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
37936 * we have tried to ignore.
37937 */
37938 struct timespec last_read_error; /* monotonic time since our
37939 * last read error
37940 */
37941- atomic_t corrected_errors; /* number of corrected read errors,
37942+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37943 * for reporting to userspace and storing
37944 * in superblock.
37945 */
37946@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37947
37948 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37949 {
37950- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37951+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37952 }
37953
37954 struct md_personality
37955diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37956index 1cbfc6b..56e1dbb 100644
37957--- a/drivers/md/persistent-data/dm-space-map.h
37958+++ b/drivers/md/persistent-data/dm-space-map.h
37959@@ -60,6 +60,7 @@ struct dm_space_map {
37960 int (*root_size)(struct dm_space_map *sm, size_t *result);
37961 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37962 };
37963+typedef struct dm_space_map __no_const dm_space_map_no_const;
37964
37965 /*----------------------------------------------------------------*/
37966
37967diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37968index 75b1f89..00ba344 100644
37969--- a/drivers/md/raid1.c
37970+++ b/drivers/md/raid1.c
37971@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37972 if (r1_sync_page_io(rdev, sect, s,
37973 bio->bi_io_vec[idx].bv_page,
37974 READ) != 0)
37975- atomic_add(s, &rdev->corrected_errors);
37976+ atomic_add_unchecked(s, &rdev->corrected_errors);
37977 }
37978 sectors -= s;
37979 sect += s;
37980@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37981 test_bit(In_sync, &rdev->flags)) {
37982 if (r1_sync_page_io(rdev, sect, s,
37983 conf->tmppage, READ)) {
37984- atomic_add(s, &rdev->corrected_errors);
37985+ atomic_add_unchecked(s, &rdev->corrected_errors);
37986 printk(KERN_INFO
37987 "md/raid1:%s: read error corrected "
37988 "(%d sectors at %llu on %s)\n",
37989diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
37990index 8d925dc..11d674f 100644
37991--- a/drivers/md/raid10.c
37992+++ b/drivers/md/raid10.c
37993@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
37994 /* The write handler will notice the lack of
37995 * R10BIO_Uptodate and record any errors etc
37996 */
37997- atomic_add(r10_bio->sectors,
37998+ atomic_add_unchecked(r10_bio->sectors,
37999 &conf->mirrors[d].rdev->corrected_errors);
38000
38001 /* for reconstruct, we always reschedule after a read.
38002@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38003 {
38004 struct timespec cur_time_mon;
38005 unsigned long hours_since_last;
38006- unsigned int read_errors = atomic_read(&rdev->read_errors);
38007+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38008
38009 ktime_get_ts(&cur_time_mon);
38010
38011@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38012 * overflowing the shift of read_errors by hours_since_last.
38013 */
38014 if (hours_since_last >= 8 * sizeof(read_errors))
38015- atomic_set(&rdev->read_errors, 0);
38016+ atomic_set_unchecked(&rdev->read_errors, 0);
38017 else
38018- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38019+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38020 }
38021
38022 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38023@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38024 return;
38025
38026 check_decay_read_errors(mddev, rdev);
38027- atomic_inc(&rdev->read_errors);
38028- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38029+ atomic_inc_unchecked(&rdev->read_errors);
38030+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38031 char b[BDEVNAME_SIZE];
38032 bdevname(rdev->bdev, b);
38033
38034@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38035 "md/raid10:%s: %s: Raid device exceeded "
38036 "read_error threshold [cur %d:max %d]\n",
38037 mdname(mddev), b,
38038- atomic_read(&rdev->read_errors), max_read_errors);
38039+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38040 printk(KERN_NOTICE
38041 "md/raid10:%s: %s: Failing raid device\n",
38042 mdname(mddev), b);
38043@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38044 sect +
38045 choose_data_offset(r10_bio, rdev)),
38046 bdevname(rdev->bdev, b));
38047- atomic_add(s, &rdev->corrected_errors);
38048+ atomic_add_unchecked(s, &rdev->corrected_errors);
38049 }
38050
38051 rdev_dec_pending(rdev, mddev);
38052diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38053index 19d77a0..56051b92 100644
38054--- a/drivers/md/raid5.c
38055+++ b/drivers/md/raid5.c
38056@@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38057 mdname(conf->mddev), STRIPE_SECTORS,
38058 (unsigned long long)s,
38059 bdevname(rdev->bdev, b));
38060- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38061+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38062 clear_bit(R5_ReadError, &sh->dev[i].flags);
38063 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38064 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38065 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38066
38067- if (atomic_read(&rdev->read_errors))
38068- atomic_set(&rdev->read_errors, 0);
38069+ if (atomic_read_unchecked(&rdev->read_errors))
38070+ atomic_set_unchecked(&rdev->read_errors, 0);
38071 } else {
38072 const char *bdn = bdevname(rdev->bdev, b);
38073 int retry = 0;
38074 int set_bad = 0;
38075
38076 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38077- atomic_inc(&rdev->read_errors);
38078+ atomic_inc_unchecked(&rdev->read_errors);
38079 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38080 printk_ratelimited(
38081 KERN_WARNING
38082@@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38083 mdname(conf->mddev),
38084 (unsigned long long)s,
38085 bdn);
38086- } else if (atomic_read(&rdev->read_errors)
38087+ } else if (atomic_read_unchecked(&rdev->read_errors)
38088 > conf->max_nr_stripes)
38089 printk(KERN_WARNING
38090 "md/raid:%s: Too many read errors, failing device %s.\n",
38091diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38092index d33101a..6b13069 100644
38093--- a/drivers/media/dvb-core/dvbdev.c
38094+++ b/drivers/media/dvb-core/dvbdev.c
38095@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38096 const struct dvb_device *template, void *priv, int type)
38097 {
38098 struct dvb_device *dvbdev;
38099- struct file_operations *dvbdevfops;
38100+ file_operations_no_const *dvbdevfops;
38101 struct device *clsdev;
38102 int minor;
38103 int id;
38104diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38105index 404f63a..4796533 100644
38106--- a/drivers/media/dvb-frontends/dib3000.h
38107+++ b/drivers/media/dvb-frontends/dib3000.h
38108@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38109 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38110 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38111 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38112-};
38113+} __no_const;
38114
38115 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
38116 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38117diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38118index 8e9a668..78d6310 100644
38119--- a/drivers/media/platform/omap/omap_vout.c
38120+++ b/drivers/media/platform/omap/omap_vout.c
38121@@ -63,7 +63,6 @@ enum omap_vout_channels {
38122 OMAP_VIDEO2,
38123 };
38124
38125-static struct videobuf_queue_ops video_vbq_ops;
38126 /* Variables configurable through module params*/
38127 static u32 video1_numbuffers = 3;
38128 static u32 video2_numbuffers = 3;
38129@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38130 {
38131 struct videobuf_queue *q;
38132 struct omap_vout_device *vout = NULL;
38133+ static struct videobuf_queue_ops video_vbq_ops = {
38134+ .buf_setup = omap_vout_buffer_setup,
38135+ .buf_prepare = omap_vout_buffer_prepare,
38136+ .buf_release = omap_vout_buffer_release,
38137+ .buf_queue = omap_vout_buffer_queue,
38138+ };
38139
38140 vout = video_drvdata(file);
38141 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38142@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38143 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38144
38145 q = &vout->vbq;
38146- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38147- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38148- video_vbq_ops.buf_release = omap_vout_buffer_release;
38149- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38150 spin_lock_init(&vout->vbq_lock);
38151
38152 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38153diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38154index b671e20..34088b7 100644
38155--- a/drivers/media/platform/s5p-tv/mixer.h
38156+++ b/drivers/media/platform/s5p-tv/mixer.h
38157@@ -155,7 +155,7 @@ struct mxr_layer {
38158 /** layer index (unique identifier) */
38159 int idx;
38160 /** callbacks for layer methods */
38161- struct mxr_layer_ops ops;
38162+ struct mxr_layer_ops *ops;
38163 /** format array */
38164 const struct mxr_format **fmt_array;
38165 /** size of format array */
38166diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38167index b93a21f..2535195 100644
38168--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38169+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38170@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38171 {
38172 struct mxr_layer *layer;
38173 int ret;
38174- struct mxr_layer_ops ops = {
38175+ static struct mxr_layer_ops ops = {
38176 .release = mxr_graph_layer_release,
38177 .buffer_set = mxr_graph_buffer_set,
38178 .stream_set = mxr_graph_stream_set,
38179diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38180index 3b1670a..595c939 100644
38181--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38182+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38183@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38184 layer->update_buf = next;
38185 }
38186
38187- layer->ops.buffer_set(layer, layer->update_buf);
38188+ layer->ops->buffer_set(layer, layer->update_buf);
38189
38190 if (done && done != layer->shadow_buf)
38191 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38192diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38193index 1f3b743..e839271 100644
38194--- a/drivers/media/platform/s5p-tv/mixer_video.c
38195+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38196@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38197 layer->geo.src.height = layer->geo.src.full_height;
38198
38199 mxr_geometry_dump(mdev, &layer->geo);
38200- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38201+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38202 mxr_geometry_dump(mdev, &layer->geo);
38203 }
38204
38205@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38206 layer->geo.dst.full_width = mbus_fmt.width;
38207 layer->geo.dst.full_height = mbus_fmt.height;
38208 layer->geo.dst.field = mbus_fmt.field;
38209- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38210+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38211
38212 mxr_geometry_dump(mdev, &layer->geo);
38213 }
38214@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38215 /* set source size to highest accepted value */
38216 geo->src.full_width = max(geo->dst.full_width, pix->width);
38217 geo->src.full_height = max(geo->dst.full_height, pix->height);
38218- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38219+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38220 mxr_geometry_dump(mdev, &layer->geo);
38221 /* set cropping to total visible screen */
38222 geo->src.width = pix->width;
38223@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38224 geo->src.x_offset = 0;
38225 geo->src.y_offset = 0;
38226 /* assure consistency of geometry */
38227- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38228+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38229 mxr_geometry_dump(mdev, &layer->geo);
38230 /* set full size to lowest possible value */
38231 geo->src.full_width = 0;
38232 geo->src.full_height = 0;
38233- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38234+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38235 mxr_geometry_dump(mdev, &layer->geo);
38236
38237 /* returning results */
38238@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38239 target->width = s->r.width;
38240 target->height = s->r.height;
38241
38242- layer->ops.fix_geometry(layer, stage, s->flags);
38243+ layer->ops->fix_geometry(layer, stage, s->flags);
38244
38245 /* retrieve update selection rectangle */
38246 res.left = target->x_offset;
38247@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38248 mxr_output_get(mdev);
38249
38250 mxr_layer_update_output(layer);
38251- layer->ops.format_set(layer);
38252+ layer->ops->format_set(layer);
38253 /* enabling layer in hardware */
38254 spin_lock_irqsave(&layer->enq_slock, flags);
38255 layer->state = MXR_LAYER_STREAMING;
38256 spin_unlock_irqrestore(&layer->enq_slock, flags);
38257
38258- layer->ops.stream_set(layer, MXR_ENABLE);
38259+ layer->ops->stream_set(layer, MXR_ENABLE);
38260 mxr_streamer_get(mdev);
38261
38262 return 0;
38263@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38264 spin_unlock_irqrestore(&layer->enq_slock, flags);
38265
38266 /* disabling layer in hardware */
38267- layer->ops.stream_set(layer, MXR_DISABLE);
38268+ layer->ops->stream_set(layer, MXR_DISABLE);
38269 /* remove one streamer */
38270 mxr_streamer_put(mdev);
38271 /* allow changes in output configuration */
38272@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38273
38274 void mxr_layer_release(struct mxr_layer *layer)
38275 {
38276- if (layer->ops.release)
38277- layer->ops.release(layer);
38278+ if (layer->ops->release)
38279+ layer->ops->release(layer);
38280 }
38281
38282 void mxr_base_layer_release(struct mxr_layer *layer)
38283@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38284
38285 layer->mdev = mdev;
38286 layer->idx = idx;
38287- layer->ops = *ops;
38288+ layer->ops = ops;
38289
38290 spin_lock_init(&layer->enq_slock);
38291 INIT_LIST_HEAD(&layer->enq_list);
38292diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38293index 3d13a63..da31bf1 100644
38294--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38295+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38296@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38297 {
38298 struct mxr_layer *layer;
38299 int ret;
38300- struct mxr_layer_ops ops = {
38301+ static struct mxr_layer_ops ops = {
38302 .release = mxr_vp_layer_release,
38303 .buffer_set = mxr_vp_buffer_set,
38304 .stream_set = mxr_vp_stream_set,
38305diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38306index 643d80a..56bb96b 100644
38307--- a/drivers/media/radio/radio-cadet.c
38308+++ b/drivers/media/radio/radio-cadet.c
38309@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38310 unsigned char readbuf[RDS_BUFFER];
38311 int i = 0;
38312
38313+ if (count > RDS_BUFFER)
38314+ return -EFAULT;
38315 mutex_lock(&dev->lock);
38316 if (dev->rdsstat == 0)
38317 cadet_start_rds(dev);
38318@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38319 while (i < count && dev->rdsin != dev->rdsout)
38320 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38321
38322- if (i && copy_to_user(data, readbuf, i))
38323+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38324 i = -EFAULT;
38325 unlock:
38326 mutex_unlock(&dev->lock);
38327diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38328index 3940bb0..fb3952a 100644
38329--- a/drivers/media/usb/dvb-usb/cxusb.c
38330+++ b/drivers/media/usb/dvb-usb/cxusb.c
38331@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38332
38333 struct dib0700_adapter_state {
38334 int (*set_param_save) (struct dvb_frontend *);
38335-};
38336+} __no_const;
38337
38338 static int dib7070_set_param_override(struct dvb_frontend *fe)
38339 {
38340diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38341index 9382895..ac8093c 100644
38342--- a/drivers/media/usb/dvb-usb/dw2102.c
38343+++ b/drivers/media/usb/dvb-usb/dw2102.c
38344@@ -95,7 +95,7 @@ struct su3000_state {
38345
38346 struct s6x0_state {
38347 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38348-};
38349+} __no_const;
38350
38351 /* debug */
38352 static int dvb_usb_dw2102_debug;
38353diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38354index aa6e7c7..4cd8061 100644
38355--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38356+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38357@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38358 struct file *file, void *fh, void *p);
38359 } u;
38360 void (*debug)(const void *arg, bool write_only);
38361-};
38362+} __do_const;
38363+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38364
38365 /* This control needs a priority check */
38366 #define INFO_FL_PRIO (1 << 0)
38367@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38368 struct video_device *vfd = video_devdata(file);
38369 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38370 bool write_only = false;
38371- struct v4l2_ioctl_info default_info;
38372+ v4l2_ioctl_info_no_const default_info;
38373 const struct v4l2_ioctl_info *info;
38374 void *fh = file->private_data;
38375 struct v4l2_fh *vfh = NULL;
38376diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38377index 29b2172..a7c5b31 100644
38378--- a/drivers/memstick/host/r592.c
38379+++ b/drivers/memstick/host/r592.c
38380@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38381 /* Executes one TPC (data is read/written from small or large fifo) */
38382 static void r592_execute_tpc(struct r592_device *dev)
38383 {
38384- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38385+ bool is_write;
38386 int len, error;
38387 u32 status, reg;
38388
38389@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38390 return;
38391 }
38392
38393+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38394 len = dev->req->long_data ?
38395 dev->req->sg.length : dev->req->data_len;
38396
38397diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38398index fb69baa..3aeea2e 100644
38399--- a/drivers/message/fusion/mptbase.c
38400+++ b/drivers/message/fusion/mptbase.c
38401@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38402 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38403 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38404
38405+#ifdef CONFIG_GRKERNSEC_HIDESYM
38406+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38407+#else
38408 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38409 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38410+#endif
38411+
38412 /*
38413 * Rounding UP to nearest 4-kB boundary here...
38414 */
38415@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38416 ioc->facts.GlobalCredits);
38417
38418 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38419+#ifdef CONFIG_GRKERNSEC_HIDESYM
38420+ NULL, NULL);
38421+#else
38422 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38423+#endif
38424 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38425 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38426 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38427diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38428index fa43c39..daeb158 100644
38429--- a/drivers/message/fusion/mptsas.c
38430+++ b/drivers/message/fusion/mptsas.c
38431@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38432 return 0;
38433 }
38434
38435+static inline void
38436+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38437+{
38438+ if (phy_info->port_details) {
38439+ phy_info->port_details->rphy = rphy;
38440+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38441+ ioc->name, rphy));
38442+ }
38443+
38444+ if (rphy) {
38445+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38446+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38447+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38448+ ioc->name, rphy, rphy->dev.release));
38449+ }
38450+}
38451+
38452 /* no mutex */
38453 static void
38454 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38455@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38456 return NULL;
38457 }
38458
38459-static inline void
38460-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38461-{
38462- if (phy_info->port_details) {
38463- phy_info->port_details->rphy = rphy;
38464- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38465- ioc->name, rphy));
38466- }
38467-
38468- if (rphy) {
38469- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38470- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38471- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38472- ioc->name, rphy, rphy->dev.release));
38473- }
38474-}
38475-
38476 static inline struct sas_port *
38477 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38478 {
38479diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38480index 164afa7..b6b2e74 100644
38481--- a/drivers/message/fusion/mptscsih.c
38482+++ b/drivers/message/fusion/mptscsih.c
38483@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38484
38485 h = shost_priv(SChost);
38486
38487- if (h) {
38488- if (h->info_kbuf == NULL)
38489- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38490- return h->info_kbuf;
38491- h->info_kbuf[0] = '\0';
38492+ if (!h)
38493+ return NULL;
38494
38495- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38496- h->info_kbuf[size-1] = '\0';
38497- }
38498+ if (h->info_kbuf == NULL)
38499+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38500+ return h->info_kbuf;
38501+ h->info_kbuf[0] = '\0';
38502+
38503+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38504+ h->info_kbuf[size-1] = '\0';
38505
38506 return h->info_kbuf;
38507 }
38508diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38509index 8001aa6..b137580 100644
38510--- a/drivers/message/i2o/i2o_proc.c
38511+++ b/drivers/message/i2o/i2o_proc.c
38512@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38513 "Array Controller Device"
38514 };
38515
38516-static char *chtostr(char *tmp, u8 *chars, int n)
38517-{
38518- tmp[0] = 0;
38519- return strncat(tmp, (char *)chars, n);
38520-}
38521-
38522 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38523 char *group)
38524 {
38525@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38526 } *result;
38527
38528 i2o_exec_execute_ddm_table ddm_table;
38529- char tmp[28 + 1];
38530
38531 result = kmalloc(sizeof(*result), GFP_KERNEL);
38532 if (!result)
38533@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38534
38535 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38536 seq_printf(seq, "%-#8x", ddm_table.module_id);
38537- seq_printf(seq, "%-29s",
38538- chtostr(tmp, ddm_table.module_name_version, 28));
38539+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38540 seq_printf(seq, "%9d ", ddm_table.data_size);
38541 seq_printf(seq, "%8d", ddm_table.code_size);
38542
38543@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38544
38545 i2o_driver_result_table *result;
38546 i2o_driver_store_table *dst;
38547- char tmp[28 + 1];
38548
38549 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38550 if (result == NULL)
38551@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38552
38553 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38554 seq_printf(seq, "%-#8x", dst->module_id);
38555- seq_printf(seq, "%-29s",
38556- chtostr(tmp, dst->module_name_version, 28));
38557- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38558+ seq_printf(seq, "%-.28s", dst->module_name_version);
38559+ seq_printf(seq, "%-.8s", dst->date);
38560 seq_printf(seq, "%8d ", dst->module_size);
38561 seq_printf(seq, "%8d ", dst->mpb_size);
38562 seq_printf(seq, "0x%04x", dst->module_flags);
38563@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38564 // == (allow) 512d bytes (max)
38565 static u16 *work16 = (u16 *) work32;
38566 int token;
38567- char tmp[16 + 1];
38568
38569 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38570
38571@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38572 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38573 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38574 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38575- seq_printf(seq, "Vendor info : %s\n",
38576- chtostr(tmp, (u8 *) (work32 + 2), 16));
38577- seq_printf(seq, "Product info : %s\n",
38578- chtostr(tmp, (u8 *) (work32 + 6), 16));
38579- seq_printf(seq, "Description : %s\n",
38580- chtostr(tmp, (u8 *) (work32 + 10), 16));
38581- seq_printf(seq, "Product rev. : %s\n",
38582- chtostr(tmp, (u8 *) (work32 + 14), 8));
38583+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38584+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38585+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38586+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38587
38588 seq_printf(seq, "Serial number : ");
38589 print_serial_number(seq, (u8 *) (work32 + 16),
38590@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38591 u8 pad[256]; // allow up to 256 byte (max) serial number
38592 } result;
38593
38594- char tmp[24 + 1];
38595-
38596 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38597
38598 if (token < 0) {
38599@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38600 }
38601
38602 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38603- seq_printf(seq, "Module name : %s\n",
38604- chtostr(tmp, result.module_name, 24));
38605- seq_printf(seq, "Module revision : %s\n",
38606- chtostr(tmp, result.module_rev, 8));
38607+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
38608+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38609
38610 seq_printf(seq, "Serial number : ");
38611 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38612@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38613 u8 instance_number[4];
38614 } result;
38615
38616- char tmp[64 + 1];
38617-
38618 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38619
38620 if (token < 0) {
38621@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38622 return 0;
38623 }
38624
38625- seq_printf(seq, "Device name : %s\n",
38626- chtostr(tmp, result.device_name, 64));
38627- seq_printf(seq, "Service name : %s\n",
38628- chtostr(tmp, result.service_name, 64));
38629- seq_printf(seq, "Physical name : %s\n",
38630- chtostr(tmp, result.physical_location, 64));
38631- seq_printf(seq, "Instance number : %s\n",
38632- chtostr(tmp, result.instance_number, 4));
38633+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
38634+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
38635+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38636+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38637
38638 return 0;
38639 }
38640diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38641index a8c08f3..155fe3d 100644
38642--- a/drivers/message/i2o/iop.c
38643+++ b/drivers/message/i2o/iop.c
38644@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38645
38646 spin_lock_irqsave(&c->context_list_lock, flags);
38647
38648- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38649- atomic_inc(&c->context_list_counter);
38650+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38651+ atomic_inc_unchecked(&c->context_list_counter);
38652
38653- entry->context = atomic_read(&c->context_list_counter);
38654+ entry->context = atomic_read_unchecked(&c->context_list_counter);
38655
38656 list_add(&entry->list, &c->context_list);
38657
38658@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38659
38660 #if BITS_PER_LONG == 64
38661 spin_lock_init(&c->context_list_lock);
38662- atomic_set(&c->context_list_counter, 0);
38663+ atomic_set_unchecked(&c->context_list_counter, 0);
38664 INIT_LIST_HEAD(&c->context_list);
38665 #endif
38666
38667diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38668index 45ece11..8efa218 100644
38669--- a/drivers/mfd/janz-cmodio.c
38670+++ b/drivers/mfd/janz-cmodio.c
38671@@ -13,6 +13,7 @@
38672
38673 #include <linux/kernel.h>
38674 #include <linux/module.h>
38675+#include <linux/slab.h>
38676 #include <linux/init.h>
38677 #include <linux/pci.h>
38678 #include <linux/interrupt.h>
38679diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38680index a5f9888..1c0ed56 100644
38681--- a/drivers/mfd/twl4030-irq.c
38682+++ b/drivers/mfd/twl4030-irq.c
38683@@ -35,6 +35,7 @@
38684 #include <linux/of.h>
38685 #include <linux/irqdomain.h>
38686 #include <linux/i2c/twl.h>
38687+#include <asm/pgtable.h>
38688
38689 #include "twl-core.h"
38690
38691@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38692 * Install an irq handler for each of the SIH modules;
38693 * clone dummy irq_chip since PIH can't *do* anything
38694 */
38695- twl4030_irq_chip = dummy_irq_chip;
38696- twl4030_irq_chip.name = "twl4030";
38697+ pax_open_kernel();
38698+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38699+ *(const char **)&twl4030_irq_chip.name = "twl4030";
38700
38701- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38702+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38703+ pax_close_kernel();
38704
38705 for (i = irq_base; i < irq_end; i++) {
38706 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38707diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38708index 277a8db..0e0b754 100644
38709--- a/drivers/mfd/twl6030-irq.c
38710+++ b/drivers/mfd/twl6030-irq.c
38711@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38712 * install an irq handler for each of the modules;
38713 * clone dummy irq_chip since PIH can't *do* anything
38714 */
38715- twl6030_irq_chip = dummy_irq_chip;
38716- twl6030_irq_chip.name = "twl6030";
38717- twl6030_irq_chip.irq_set_type = NULL;
38718- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38719+ pax_open_kernel();
38720+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38721+ *(const char **)&twl6030_irq_chip.name = "twl6030";
38722+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38723+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38724+ pax_close_kernel();
38725
38726 for (i = irq_base; i < irq_end; i++) {
38727 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38728diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38729index f428d86..274c368 100644
38730--- a/drivers/misc/c2port/core.c
38731+++ b/drivers/misc/c2port/core.c
38732@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38733 mutex_init(&c2dev->mutex);
38734
38735 /* Create binary file */
38736- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38737+ pax_open_kernel();
38738+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38739+ pax_close_kernel();
38740 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38741 if (unlikely(ret))
38742 goto error_device_create_bin_file;
38743diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38744index 3aa9a96..59cf685 100644
38745--- a/drivers/misc/kgdbts.c
38746+++ b/drivers/misc/kgdbts.c
38747@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38748 char before[BREAK_INSTR_SIZE];
38749 char after[BREAK_INSTR_SIZE];
38750
38751- probe_kernel_read(before, (char *)kgdbts_break_test,
38752+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38753 BREAK_INSTR_SIZE);
38754 init_simple_test();
38755 ts.tst = plant_and_detach_test;
38756@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38757 /* Activate test with initial breakpoint */
38758 if (!is_early)
38759 kgdb_breakpoint();
38760- probe_kernel_read(after, (char *)kgdbts_break_test,
38761+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38762 BREAK_INSTR_SIZE);
38763 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38764 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38765diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38766index 4a87e5c..76bdf5c 100644
38767--- a/drivers/misc/lis3lv02d/lis3lv02d.c
38768+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38769@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38770 * the lid is closed. This leads to interrupts as soon as a little move
38771 * is done.
38772 */
38773- atomic_inc(&lis3->count);
38774+ atomic_inc_unchecked(&lis3->count);
38775
38776 wake_up_interruptible(&lis3->misc_wait);
38777 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38778@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38779 if (lis3->pm_dev)
38780 pm_runtime_get_sync(lis3->pm_dev);
38781
38782- atomic_set(&lis3->count, 0);
38783+ atomic_set_unchecked(&lis3->count, 0);
38784 return 0;
38785 }
38786
38787@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38788 add_wait_queue(&lis3->misc_wait, &wait);
38789 while (true) {
38790 set_current_state(TASK_INTERRUPTIBLE);
38791- data = atomic_xchg(&lis3->count, 0);
38792+ data = atomic_xchg_unchecked(&lis3->count, 0);
38793 if (data)
38794 break;
38795
38796@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38797 struct lis3lv02d, miscdev);
38798
38799 poll_wait(file, &lis3->misc_wait, wait);
38800- if (atomic_read(&lis3->count))
38801+ if (atomic_read_unchecked(&lis3->count))
38802 return POLLIN | POLLRDNORM;
38803 return 0;
38804 }
38805diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38806index c439c82..1f20f57 100644
38807--- a/drivers/misc/lis3lv02d/lis3lv02d.h
38808+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38809@@ -297,7 +297,7 @@ struct lis3lv02d {
38810 struct input_polled_dev *idev; /* input device */
38811 struct platform_device *pdev; /* platform device */
38812 struct regulator_bulk_data regulators[2];
38813- atomic_t count; /* interrupt count after last read */
38814+ atomic_unchecked_t count; /* interrupt count after last read */
38815 union axis_conversion ac; /* hw -> logical axis */
38816 int mapped_btns[3];
38817
38818diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38819index 2f30bad..c4c13d0 100644
38820--- a/drivers/misc/sgi-gru/gruhandles.c
38821+++ b/drivers/misc/sgi-gru/gruhandles.c
38822@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38823 unsigned long nsec;
38824
38825 nsec = CLKS2NSEC(clks);
38826- atomic_long_inc(&mcs_op_statistics[op].count);
38827- atomic_long_add(nsec, &mcs_op_statistics[op].total);
38828+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38829+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38830 if (mcs_op_statistics[op].max < nsec)
38831 mcs_op_statistics[op].max = nsec;
38832 }
38833diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38834index 950dbe9..eeef0f8 100644
38835--- a/drivers/misc/sgi-gru/gruprocfs.c
38836+++ b/drivers/misc/sgi-gru/gruprocfs.c
38837@@ -32,9 +32,9 @@
38838
38839 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38840
38841-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38842+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38843 {
38844- unsigned long val = atomic_long_read(v);
38845+ unsigned long val = atomic_long_read_unchecked(v);
38846
38847 seq_printf(s, "%16lu %s\n", val, id);
38848 }
38849@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38850
38851 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38852 for (op = 0; op < mcsop_last; op++) {
38853- count = atomic_long_read(&mcs_op_statistics[op].count);
38854- total = atomic_long_read(&mcs_op_statistics[op].total);
38855+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38856+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38857 max = mcs_op_statistics[op].max;
38858 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38859 count ? total / count : 0, max);
38860diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38861index 5c3ce24..4915ccb 100644
38862--- a/drivers/misc/sgi-gru/grutables.h
38863+++ b/drivers/misc/sgi-gru/grutables.h
38864@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38865 * GRU statistics.
38866 */
38867 struct gru_stats_s {
38868- atomic_long_t vdata_alloc;
38869- atomic_long_t vdata_free;
38870- atomic_long_t gts_alloc;
38871- atomic_long_t gts_free;
38872- atomic_long_t gms_alloc;
38873- atomic_long_t gms_free;
38874- atomic_long_t gts_double_allocate;
38875- atomic_long_t assign_context;
38876- atomic_long_t assign_context_failed;
38877- atomic_long_t free_context;
38878- atomic_long_t load_user_context;
38879- atomic_long_t load_kernel_context;
38880- atomic_long_t lock_kernel_context;
38881- atomic_long_t unlock_kernel_context;
38882- atomic_long_t steal_user_context;
38883- atomic_long_t steal_kernel_context;
38884- atomic_long_t steal_context_failed;
38885- atomic_long_t nopfn;
38886- atomic_long_t asid_new;
38887- atomic_long_t asid_next;
38888- atomic_long_t asid_wrap;
38889- atomic_long_t asid_reuse;
38890- atomic_long_t intr;
38891- atomic_long_t intr_cbr;
38892- atomic_long_t intr_tfh;
38893- atomic_long_t intr_spurious;
38894- atomic_long_t intr_mm_lock_failed;
38895- atomic_long_t call_os;
38896- atomic_long_t call_os_wait_queue;
38897- atomic_long_t user_flush_tlb;
38898- atomic_long_t user_unload_context;
38899- atomic_long_t user_exception;
38900- atomic_long_t set_context_option;
38901- atomic_long_t check_context_retarget_intr;
38902- atomic_long_t check_context_unload;
38903- atomic_long_t tlb_dropin;
38904- atomic_long_t tlb_preload_page;
38905- atomic_long_t tlb_dropin_fail_no_asid;
38906- atomic_long_t tlb_dropin_fail_upm;
38907- atomic_long_t tlb_dropin_fail_invalid;
38908- atomic_long_t tlb_dropin_fail_range_active;
38909- atomic_long_t tlb_dropin_fail_idle;
38910- atomic_long_t tlb_dropin_fail_fmm;
38911- atomic_long_t tlb_dropin_fail_no_exception;
38912- atomic_long_t tfh_stale_on_fault;
38913- atomic_long_t mmu_invalidate_range;
38914- atomic_long_t mmu_invalidate_page;
38915- atomic_long_t flush_tlb;
38916- atomic_long_t flush_tlb_gru;
38917- atomic_long_t flush_tlb_gru_tgh;
38918- atomic_long_t flush_tlb_gru_zero_asid;
38919+ atomic_long_unchecked_t vdata_alloc;
38920+ atomic_long_unchecked_t vdata_free;
38921+ atomic_long_unchecked_t gts_alloc;
38922+ atomic_long_unchecked_t gts_free;
38923+ atomic_long_unchecked_t gms_alloc;
38924+ atomic_long_unchecked_t gms_free;
38925+ atomic_long_unchecked_t gts_double_allocate;
38926+ atomic_long_unchecked_t assign_context;
38927+ atomic_long_unchecked_t assign_context_failed;
38928+ atomic_long_unchecked_t free_context;
38929+ atomic_long_unchecked_t load_user_context;
38930+ atomic_long_unchecked_t load_kernel_context;
38931+ atomic_long_unchecked_t lock_kernel_context;
38932+ atomic_long_unchecked_t unlock_kernel_context;
38933+ atomic_long_unchecked_t steal_user_context;
38934+ atomic_long_unchecked_t steal_kernel_context;
38935+ atomic_long_unchecked_t steal_context_failed;
38936+ atomic_long_unchecked_t nopfn;
38937+ atomic_long_unchecked_t asid_new;
38938+ atomic_long_unchecked_t asid_next;
38939+ atomic_long_unchecked_t asid_wrap;
38940+ atomic_long_unchecked_t asid_reuse;
38941+ atomic_long_unchecked_t intr;
38942+ atomic_long_unchecked_t intr_cbr;
38943+ atomic_long_unchecked_t intr_tfh;
38944+ atomic_long_unchecked_t intr_spurious;
38945+ atomic_long_unchecked_t intr_mm_lock_failed;
38946+ atomic_long_unchecked_t call_os;
38947+ atomic_long_unchecked_t call_os_wait_queue;
38948+ atomic_long_unchecked_t user_flush_tlb;
38949+ atomic_long_unchecked_t user_unload_context;
38950+ atomic_long_unchecked_t user_exception;
38951+ atomic_long_unchecked_t set_context_option;
38952+ atomic_long_unchecked_t check_context_retarget_intr;
38953+ atomic_long_unchecked_t check_context_unload;
38954+ atomic_long_unchecked_t tlb_dropin;
38955+ atomic_long_unchecked_t tlb_preload_page;
38956+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38957+ atomic_long_unchecked_t tlb_dropin_fail_upm;
38958+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
38959+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
38960+ atomic_long_unchecked_t tlb_dropin_fail_idle;
38961+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
38962+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38963+ atomic_long_unchecked_t tfh_stale_on_fault;
38964+ atomic_long_unchecked_t mmu_invalidate_range;
38965+ atomic_long_unchecked_t mmu_invalidate_page;
38966+ atomic_long_unchecked_t flush_tlb;
38967+ atomic_long_unchecked_t flush_tlb_gru;
38968+ atomic_long_unchecked_t flush_tlb_gru_tgh;
38969+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38970
38971- atomic_long_t copy_gpa;
38972- atomic_long_t read_gpa;
38973+ atomic_long_unchecked_t copy_gpa;
38974+ atomic_long_unchecked_t read_gpa;
38975
38976- atomic_long_t mesq_receive;
38977- atomic_long_t mesq_receive_none;
38978- atomic_long_t mesq_send;
38979- atomic_long_t mesq_send_failed;
38980- atomic_long_t mesq_noop;
38981- atomic_long_t mesq_send_unexpected_error;
38982- atomic_long_t mesq_send_lb_overflow;
38983- atomic_long_t mesq_send_qlimit_reached;
38984- atomic_long_t mesq_send_amo_nacked;
38985- atomic_long_t mesq_send_put_nacked;
38986- atomic_long_t mesq_page_overflow;
38987- atomic_long_t mesq_qf_locked;
38988- atomic_long_t mesq_qf_noop_not_full;
38989- atomic_long_t mesq_qf_switch_head_failed;
38990- atomic_long_t mesq_qf_unexpected_error;
38991- atomic_long_t mesq_noop_unexpected_error;
38992- atomic_long_t mesq_noop_lb_overflow;
38993- atomic_long_t mesq_noop_qlimit_reached;
38994- atomic_long_t mesq_noop_amo_nacked;
38995- atomic_long_t mesq_noop_put_nacked;
38996- atomic_long_t mesq_noop_page_overflow;
38997+ atomic_long_unchecked_t mesq_receive;
38998+ atomic_long_unchecked_t mesq_receive_none;
38999+ atomic_long_unchecked_t mesq_send;
39000+ atomic_long_unchecked_t mesq_send_failed;
39001+ atomic_long_unchecked_t mesq_noop;
39002+ atomic_long_unchecked_t mesq_send_unexpected_error;
39003+ atomic_long_unchecked_t mesq_send_lb_overflow;
39004+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39005+ atomic_long_unchecked_t mesq_send_amo_nacked;
39006+ atomic_long_unchecked_t mesq_send_put_nacked;
39007+ atomic_long_unchecked_t mesq_page_overflow;
39008+ atomic_long_unchecked_t mesq_qf_locked;
39009+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39010+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39011+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39012+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39013+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39014+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39015+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39016+ atomic_long_unchecked_t mesq_noop_put_nacked;
39017+ atomic_long_unchecked_t mesq_noop_page_overflow;
39018
39019 };
39020
39021@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39022 tghop_invalidate, mcsop_last};
39023
39024 struct mcs_op_statistic {
39025- atomic_long_t count;
39026- atomic_long_t total;
39027+ atomic_long_unchecked_t count;
39028+ atomic_long_unchecked_t total;
39029 unsigned long max;
39030 };
39031
39032@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39033
39034 #define STAT(id) do { \
39035 if (gru_options & OPT_STATS) \
39036- atomic_long_inc(&gru_stats.id); \
39037+ atomic_long_inc_unchecked(&gru_stats.id); \
39038 } while (0)
39039
39040 #ifdef CONFIG_SGI_GRU_DEBUG
39041diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39042index c862cd4..0d176fe 100644
39043--- a/drivers/misc/sgi-xp/xp.h
39044+++ b/drivers/misc/sgi-xp/xp.h
39045@@ -288,7 +288,7 @@ struct xpc_interface {
39046 xpc_notify_func, void *);
39047 void (*received) (short, int, void *);
39048 enum xp_retval (*partid_to_nasids) (short, void *);
39049-};
39050+} __no_const;
39051
39052 extern struct xpc_interface xpc_interface;
39053
39054diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39055index b94d5f7..7f494c5 100644
39056--- a/drivers/misc/sgi-xp/xpc.h
39057+++ b/drivers/misc/sgi-xp/xpc.h
39058@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39059 void (*received_payload) (struct xpc_channel *, void *);
39060 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39061 };
39062+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39063
39064 /* struct xpc_partition act_state values (for XPC HB) */
39065
39066@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39067 /* found in xpc_main.c */
39068 extern struct device *xpc_part;
39069 extern struct device *xpc_chan;
39070-extern struct xpc_arch_operations xpc_arch_ops;
39071+extern xpc_arch_operations_no_const xpc_arch_ops;
39072 extern int xpc_disengage_timelimit;
39073 extern int xpc_disengage_timedout;
39074 extern int xpc_activate_IRQ_rcvd;
39075diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39076index d971817..33bdca5 100644
39077--- a/drivers/misc/sgi-xp/xpc_main.c
39078+++ b/drivers/misc/sgi-xp/xpc_main.c
39079@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39080 .notifier_call = xpc_system_die,
39081 };
39082
39083-struct xpc_arch_operations xpc_arch_ops;
39084+xpc_arch_operations_no_const xpc_arch_ops;
39085
39086 /*
39087 * Timer function to enforce the timelimit on the partition disengage.
39088@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39089
39090 if (((die_args->trapnr == X86_TRAP_MF) ||
39091 (die_args->trapnr == X86_TRAP_XF)) &&
39092- !user_mode_vm(die_args->regs))
39093+ !user_mode(die_args->regs))
39094 xpc_die_deactivate();
39095
39096 break;
39097diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39098index 6d8f701..35b6369 100644
39099--- a/drivers/mmc/core/mmc_ops.c
39100+++ b/drivers/mmc/core/mmc_ops.c
39101@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39102 void *data_buf;
39103 int is_on_stack;
39104
39105- is_on_stack = object_is_on_stack(buf);
39106+ is_on_stack = object_starts_on_stack(buf);
39107 if (is_on_stack) {
39108 /*
39109 * dma onto stack is unsafe/nonportable, but callers to this
39110diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39111index 53b8fd9..615b462 100644
39112--- a/drivers/mmc/host/dw_mmc.h
39113+++ b/drivers/mmc/host/dw_mmc.h
39114@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39115 int (*parse_dt)(struct dw_mci *host);
39116 int (*setup_bus)(struct dw_mci *host,
39117 struct device_node *slot_np, u8 bus_width);
39118-};
39119+} __do_const;
39120 #endif /* _DW_MMC_H_ */
39121diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39122index 82a8de1..3c56ccb 100644
39123--- a/drivers/mmc/host/sdhci-s3c.c
39124+++ b/drivers/mmc/host/sdhci-s3c.c
39125@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39126 * we can use overriding functions instead of default.
39127 */
39128 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39129- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39130- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39131- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39132+ pax_open_kernel();
39133+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39134+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39135+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39136+ pax_close_kernel();
39137 }
39138
39139 /* It supports additional host capabilities if needed */
39140diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39141index a4eb8b5..8c0628f 100644
39142--- a/drivers/mtd/devices/doc2000.c
39143+++ b/drivers/mtd/devices/doc2000.c
39144@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39145
39146 /* The ECC will not be calculated correctly if less than 512 is written */
39147 /* DBB-
39148- if (len != 0x200 && eccbuf)
39149+ if (len != 0x200)
39150 printk(KERN_WARNING
39151 "ECC needs a full sector write (adr: %lx size %lx)\n",
39152 (long) to, (long) len);
39153diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39154index 0c8bb6b..6f35deb 100644
39155--- a/drivers/mtd/nand/denali.c
39156+++ b/drivers/mtd/nand/denali.c
39157@@ -24,6 +24,7 @@
39158 #include <linux/slab.h>
39159 #include <linux/mtd/mtd.h>
39160 #include <linux/module.h>
39161+#include <linux/slab.h>
39162
39163 #include "denali.h"
39164
39165diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39166index 51b9d6a..52af9a7 100644
39167--- a/drivers/mtd/nftlmount.c
39168+++ b/drivers/mtd/nftlmount.c
39169@@ -24,6 +24,7 @@
39170 #include <asm/errno.h>
39171 #include <linux/delay.h>
39172 #include <linux/slab.h>
39173+#include <linux/sched.h>
39174 #include <linux/mtd/mtd.h>
39175 #include <linux/mtd/nand.h>
39176 #include <linux/mtd/nftl.h>
39177diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39178index 8dd6ba5..419cc1d 100644
39179--- a/drivers/mtd/sm_ftl.c
39180+++ b/drivers/mtd/sm_ftl.c
39181@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39182 #define SM_CIS_VENDOR_OFFSET 0x59
39183 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39184 {
39185- struct attribute_group *attr_group;
39186+ attribute_group_no_const *attr_group;
39187 struct attribute **attributes;
39188 struct sm_sysfs_attribute *vendor_attribute;
39189
39190diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39191index a079da17..f86ffd5 100644
39192--- a/drivers/net/bonding/bond_main.c
39193+++ b/drivers/net/bonding/bond_main.c
39194@@ -4862,7 +4862,7 @@ static unsigned int bond_get_num_tx_queues(void)
39195 return tx_queues;
39196 }
39197
39198-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39199+static struct rtnl_link_ops bond_link_ops = {
39200 .kind = "bond",
39201 .priv_size = sizeof(struct bonding),
39202 .setup = bond_setup,
39203diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39204index 70dba5d..11a0919 100644
39205--- a/drivers/net/ethernet/8390/ax88796.c
39206+++ b/drivers/net/ethernet/8390/ax88796.c
39207@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39208 if (ax->plat->reg_offsets)
39209 ei_local->reg_offset = ax->plat->reg_offsets;
39210 else {
39211+ resource_size_t _mem_size = mem_size;
39212+ do_div(_mem_size, 0x18);
39213 ei_local->reg_offset = ax->reg_offsets;
39214 for (ret = 0; ret < 0x18; ret++)
39215- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39216+ ax->reg_offsets[ret] = _mem_size * ret;
39217 }
39218
39219 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39220diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39221index 0991534..8098e92 100644
39222--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39223+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39224@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39225 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39226 {
39227 /* RX_MODE controlling object */
39228- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39229+ bnx2x_init_rx_mode_obj(bp);
39230
39231 /* multicast configuration controlling object */
39232 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39233diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39234index 09b625e..15b16fe 100644
39235--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39236+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39237@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39238 return rc;
39239 }
39240
39241-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39242- struct bnx2x_rx_mode_obj *o)
39243+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39244 {
39245 if (CHIP_IS_E1x(bp)) {
39246- o->wait_comp = bnx2x_empty_rx_mode_wait;
39247- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39248+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39249+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39250 } else {
39251- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39252- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39253+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39254+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39255 }
39256 }
39257
39258diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39259index adbd91b..58ec94a 100644
39260--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39261+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39262@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39263
39264 /********************* RX MODE ****************/
39265
39266-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39267- struct bnx2x_rx_mode_obj *o);
39268+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39269
39270 /**
39271 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39272diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39273index d330e81..ce1fb9a 100644
39274--- a/drivers/net/ethernet/broadcom/tg3.h
39275+++ b/drivers/net/ethernet/broadcom/tg3.h
39276@@ -146,6 +146,7 @@
39277 #define CHIPREV_ID_5750_A0 0x4000
39278 #define CHIPREV_ID_5750_A1 0x4001
39279 #define CHIPREV_ID_5750_A3 0x4003
39280+#define CHIPREV_ID_5750_C1 0x4201
39281 #define CHIPREV_ID_5750_C2 0x4202
39282 #define CHIPREV_ID_5752_A0_HW 0x5000
39283 #define CHIPREV_ID_5752_A0 0x6000
39284diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39285index 8cffcdf..aadf043 100644
39286--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39287+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39288@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39289 */
39290 struct l2t_skb_cb {
39291 arp_failure_handler_func arp_failure_handler;
39292-};
39293+} __no_const;
39294
39295 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39296
39297diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39298index 4c83003..2a2a5b9 100644
39299--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39300+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39301@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39302 for (i=0; i<ETH_ALEN; i++) {
39303 tmp.addr[i] = dev->dev_addr[i];
39304 }
39305- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39306+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39307 break;
39308
39309 case DE4X5_SET_HWADDR: /* Set the hardware address */
39310@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39311 spin_lock_irqsave(&lp->lock, flags);
39312 memcpy(&statbuf, &lp->pktStats, ioc->len);
39313 spin_unlock_irqrestore(&lp->lock, flags);
39314- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39315+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39316 return -EFAULT;
39317 break;
39318 }
39319diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39320index 4d6f3c5..6169e60 100644
39321--- a/drivers/net/ethernet/emulex/benet/be_main.c
39322+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39323@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39324
39325 if (wrapped)
39326 newacc += 65536;
39327- ACCESS_ONCE(*acc) = newacc;
39328+ ACCESS_ONCE_RW(*acc) = newacc;
39329 }
39330
39331 void be_parse_stats(struct be_adapter *adapter)
39332diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39333index 74d749e..eefb1bd 100644
39334--- a/drivers/net/ethernet/faraday/ftgmac100.c
39335+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39336@@ -31,6 +31,8 @@
39337 #include <linux/netdevice.h>
39338 #include <linux/phy.h>
39339 #include <linux/platform_device.h>
39340+#include <linux/interrupt.h>
39341+#include <linux/irqreturn.h>
39342 #include <net/ip.h>
39343
39344 #include "ftgmac100.h"
39345diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39346index b901a01..1ff32ee 100644
39347--- a/drivers/net/ethernet/faraday/ftmac100.c
39348+++ b/drivers/net/ethernet/faraday/ftmac100.c
39349@@ -31,6 +31,8 @@
39350 #include <linux/module.h>
39351 #include <linux/netdevice.h>
39352 #include <linux/platform_device.h>
39353+#include <linux/interrupt.h>
39354+#include <linux/irqreturn.h>
39355
39356 #include "ftmac100.h"
39357
39358diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39359index bb9256a..56d8752 100644
39360--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39361+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39362@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39363 }
39364
39365 /* update the base incval used to calculate frequency adjustment */
39366- ACCESS_ONCE(adapter->base_incval) = incval;
39367+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39368 smp_mb();
39369
39370 /* need lock to prevent incorrect read while modifying cyclecounter */
39371diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39372index fbe5363..266b4e3 100644
39373--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39374+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39375@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39376 struct __vxge_hw_fifo *fifo;
39377 struct vxge_hw_fifo_config *config;
39378 u32 txdl_size, txdl_per_memblock;
39379- struct vxge_hw_mempool_cbs fifo_mp_callback;
39380+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39381+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39382+ };
39383+
39384 struct __vxge_hw_virtualpath *vpath;
39385
39386 if ((vp == NULL) || (attr == NULL)) {
39387@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39388 goto exit;
39389 }
39390
39391- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39392-
39393 fifo->mempool =
39394 __vxge_hw_mempool_create(vpath->hldev,
39395 fifo->config->memblock_size,
39396diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39397index 998974f..ecd26db 100644
39398--- a/drivers/net/ethernet/realtek/r8169.c
39399+++ b/drivers/net/ethernet/realtek/r8169.c
39400@@ -741,22 +741,22 @@ struct rtl8169_private {
39401 struct mdio_ops {
39402 void (*write)(struct rtl8169_private *, int, int);
39403 int (*read)(struct rtl8169_private *, int);
39404- } mdio_ops;
39405+ } __no_const mdio_ops;
39406
39407 struct pll_power_ops {
39408 void (*down)(struct rtl8169_private *);
39409 void (*up)(struct rtl8169_private *);
39410- } pll_power_ops;
39411+ } __no_const pll_power_ops;
39412
39413 struct jumbo_ops {
39414 void (*enable)(struct rtl8169_private *);
39415 void (*disable)(struct rtl8169_private *);
39416- } jumbo_ops;
39417+ } __no_const jumbo_ops;
39418
39419 struct csi_ops {
39420 void (*write)(struct rtl8169_private *, int, int);
39421 u32 (*read)(struct rtl8169_private *, int);
39422- } csi_ops;
39423+ } __no_const csi_ops;
39424
39425 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39426 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39427diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39428index 0767043f..08c2553 100644
39429--- a/drivers/net/ethernet/sfc/ptp.c
39430+++ b/drivers/net/ethernet/sfc/ptp.c
39431@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39432 (u32)((u64)ptp->start.dma_addr >> 32));
39433
39434 /* Clear flag that signals MC ready */
39435- ACCESS_ONCE(*start) = 0;
39436+ ACCESS_ONCE_RW(*start) = 0;
39437 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39438 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39439
39440diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39441index 0c74a70..3bc6f68 100644
39442--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39443+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39444@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39445
39446 writel(value, ioaddr + MMC_CNTRL);
39447
39448- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39449- MMC_CNTRL, value);
39450+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39451+// MMC_CNTRL, value);
39452 }
39453
39454 /* To mask all all interrupts.*/
39455diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39456index e6fe0d8..2b7d752 100644
39457--- a/drivers/net/hyperv/hyperv_net.h
39458+++ b/drivers/net/hyperv/hyperv_net.h
39459@@ -101,7 +101,7 @@ struct rndis_device {
39460
39461 enum rndis_device_state state;
39462 bool link_state;
39463- atomic_t new_req_id;
39464+ atomic_unchecked_t new_req_id;
39465
39466 spinlock_t request_lock;
39467 struct list_head req_list;
39468diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39469index 2b657d4..9903bc0 100644
39470--- a/drivers/net/hyperv/rndis_filter.c
39471+++ b/drivers/net/hyperv/rndis_filter.c
39472@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39473 * template
39474 */
39475 set = &rndis_msg->msg.set_req;
39476- set->req_id = atomic_inc_return(&dev->new_req_id);
39477+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39478
39479 /* Add to the request list */
39480 spin_lock_irqsave(&dev->request_lock, flags);
39481@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39482
39483 /* Setup the rndis set */
39484 halt = &request->request_msg.msg.halt_req;
39485- halt->req_id = atomic_inc_return(&dev->new_req_id);
39486+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39487
39488 /* Ignore return since this msg is optional. */
39489 rndis_filter_send_request(dev, request);
39490diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39491index 1e9cb0b..7839125 100644
39492--- a/drivers/net/ieee802154/fakehard.c
39493+++ b/drivers/net/ieee802154/fakehard.c
39494@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39495 phy->transmit_power = 0xbf;
39496
39497 dev->netdev_ops = &fake_ops;
39498- dev->ml_priv = &fake_mlme;
39499+ dev->ml_priv = (void *)&fake_mlme;
39500
39501 priv = netdev_priv(dev);
39502 priv->phy = phy;
39503diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39504index e5cb723..1fc0461 100644
39505--- a/drivers/net/macvlan.c
39506+++ b/drivers/net/macvlan.c
39507@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39508 int macvlan_link_register(struct rtnl_link_ops *ops)
39509 {
39510 /* common fields */
39511- ops->priv_size = sizeof(struct macvlan_dev);
39512- ops->validate = macvlan_validate;
39513- ops->maxtype = IFLA_MACVLAN_MAX;
39514- ops->policy = macvlan_policy;
39515- ops->changelink = macvlan_changelink;
39516- ops->get_size = macvlan_get_size;
39517- ops->fill_info = macvlan_fill_info;
39518+ pax_open_kernel();
39519+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39520+ *(void **)&ops->validate = macvlan_validate;
39521+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39522+ *(const void **)&ops->policy = macvlan_policy;
39523+ *(void **)&ops->changelink = macvlan_changelink;
39524+ *(void **)&ops->get_size = macvlan_get_size;
39525+ *(void **)&ops->fill_info = macvlan_fill_info;
39526+ pax_close_kernel();
39527
39528 return rtnl_link_register(ops);
39529 };
39530@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39531 return NOTIFY_DONE;
39532 }
39533
39534-static struct notifier_block macvlan_notifier_block __read_mostly = {
39535+static struct notifier_block macvlan_notifier_block = {
39536 .notifier_call = macvlan_device_event,
39537 };
39538
39539diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39540index 0f0f9ce..0ca5819 100644
39541--- a/drivers/net/macvtap.c
39542+++ b/drivers/net/macvtap.c
39543@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39544 return NOTIFY_DONE;
39545 }
39546
39547-static struct notifier_block macvtap_notifier_block __read_mostly = {
39548+static struct notifier_block macvtap_notifier_block = {
39549 .notifier_call = macvtap_device_event,
39550 };
39551
39552diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39553index daec9b0..6428fcb 100644
39554--- a/drivers/net/phy/mdio-bitbang.c
39555+++ b/drivers/net/phy/mdio-bitbang.c
39556@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39557 struct mdiobb_ctrl *ctrl = bus->priv;
39558
39559 module_put(ctrl->ops->owner);
39560+ mdiobus_unregister(bus);
39561 mdiobus_free(bus);
39562 }
39563 EXPORT_SYMBOL(free_mdio_bitbang);
39564diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39565index 508570e..f706dc7 100644
39566--- a/drivers/net/ppp/ppp_generic.c
39567+++ b/drivers/net/ppp/ppp_generic.c
39568@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39569 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39570 struct ppp_stats stats;
39571 struct ppp_comp_stats cstats;
39572- char *vers;
39573
39574 switch (cmd) {
39575 case SIOCGPPPSTATS:
39576@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39577 break;
39578
39579 case SIOCGPPPVER:
39580- vers = PPP_VERSION;
39581- if (copy_to_user(addr, vers, strlen(vers) + 1))
39582+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39583 break;
39584 err = 0;
39585 break;
39586diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39587index 8efe47a..a8075c5 100644
39588--- a/drivers/net/team/team.c
39589+++ b/drivers/net/team/team.c
39590@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
39591 return NOTIFY_DONE;
39592 }
39593
39594-static struct notifier_block team_notifier_block __read_mostly = {
39595+static struct notifier_block team_notifier_block = {
39596 .notifier_call = team_device_event,
39597 };
39598
39599diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39600index cb95fe5..a5bdab5 100644
39601--- a/drivers/net/tun.c
39602+++ b/drivers/net/tun.c
39603@@ -1838,7 +1838,7 @@ unlock:
39604 }
39605
39606 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39607- unsigned long arg, int ifreq_len)
39608+ unsigned long arg, size_t ifreq_len)
39609 {
39610 struct tun_file *tfile = file->private_data;
39611 struct tun_struct *tun;
39612@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39613 int vnet_hdr_sz;
39614 int ret;
39615
39616+ if (ifreq_len > sizeof ifr)
39617+ return -EFAULT;
39618+
39619 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39620 if (copy_from_user(&ifr, argp, ifreq_len))
39621 return -EFAULT;
39622diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39623index cd8ccb2..cff5144 100644
39624--- a/drivers/net/usb/hso.c
39625+++ b/drivers/net/usb/hso.c
39626@@ -71,7 +71,7 @@
39627 #include <asm/byteorder.h>
39628 #include <linux/serial_core.h>
39629 #include <linux/serial.h>
39630-
39631+#include <asm/local.h>
39632
39633 #define MOD_AUTHOR "Option Wireless"
39634 #define MOD_DESCRIPTION "USB High Speed Option driver"
39635@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39636 struct urb *urb;
39637
39638 urb = serial->rx_urb[0];
39639- if (serial->port.count > 0) {
39640+ if (atomic_read(&serial->port.count) > 0) {
39641 count = put_rxbuf_data(urb, serial);
39642 if (count == -1)
39643 return;
39644@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39645 DUMP1(urb->transfer_buffer, urb->actual_length);
39646
39647 /* Anyone listening? */
39648- if (serial->port.count == 0)
39649+ if (atomic_read(&serial->port.count) == 0)
39650 return;
39651
39652 if (status == 0) {
39653@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39654 tty_port_tty_set(&serial->port, tty);
39655
39656 /* check for port already opened, if not set the termios */
39657- serial->port.count++;
39658- if (serial->port.count == 1) {
39659+ if (atomic_inc_return(&serial->port.count) == 1) {
39660 serial->rx_state = RX_IDLE;
39661 /* Force default termio settings */
39662 _hso_serial_set_termios(tty, NULL);
39663@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39664 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39665 if (result) {
39666 hso_stop_serial_device(serial->parent);
39667- serial->port.count--;
39668+ atomic_dec(&serial->port.count);
39669 kref_put(&serial->parent->ref, hso_serial_ref_free);
39670 }
39671 } else {
39672@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39673
39674 /* reset the rts and dtr */
39675 /* do the actual close */
39676- serial->port.count--;
39677+ atomic_dec(&serial->port.count);
39678
39679- if (serial->port.count <= 0) {
39680- serial->port.count = 0;
39681+ if (atomic_read(&serial->port.count) <= 0) {
39682+ atomic_set(&serial->port.count, 0);
39683 tty_port_tty_set(&serial->port, NULL);
39684 if (!usb_gone)
39685 hso_stop_serial_device(serial->parent);
39686@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39687
39688 /* the actual setup */
39689 spin_lock_irqsave(&serial->serial_lock, flags);
39690- if (serial->port.count)
39691+ if (atomic_read(&serial->port.count))
39692 _hso_serial_set_termios(tty, old);
39693 else
39694 tty->termios = *old;
39695@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39696 D1("Pending read interrupt on port %d\n", i);
39697 spin_lock(&serial->serial_lock);
39698 if (serial->rx_state == RX_IDLE &&
39699- serial->port.count > 0) {
39700+ atomic_read(&serial->port.count) > 0) {
39701 /* Setup and send a ctrl req read on
39702 * port i */
39703 if (!serial->rx_urb_filled[0]) {
39704@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39705 /* Start all serial ports */
39706 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39707 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39708- if (dev2ser(serial_table[i])->port.count) {
39709+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39710 result =
39711 hso_start_serial_device(serial_table[i], GFP_NOIO);
39712 hso_kick_transmit(dev2ser(serial_table[i]));
39713diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39714index 6993bfa..9053a34 100644
39715--- a/drivers/net/vxlan.c
39716+++ b/drivers/net/vxlan.c
39717@@ -1428,7 +1428,7 @@ nla_put_failure:
39718 return -EMSGSIZE;
39719 }
39720
39721-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39722+static struct rtnl_link_ops vxlan_link_ops = {
39723 .kind = "vxlan",
39724 .maxtype = IFLA_VXLAN_MAX,
39725 .policy = vxlan_policy,
39726diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
39727index 77fa428..996b355 100644
39728--- a/drivers/net/wireless/at76c50x-usb.c
39729+++ b/drivers/net/wireless/at76c50x-usb.c
39730@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
39731 }
39732
39733 /* Convert timeout from the DFU status to jiffies */
39734-static inline unsigned long at76_get_timeout(struct dfu_status *s)
39735+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
39736 {
39737 return msecs_to_jiffies((s->poll_timeout[2] << 16)
39738 | (s->poll_timeout[1] << 8)
39739diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39740index 8d78253..bebbb68 100644
39741--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39742+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39743@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39744 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39745 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39746
39747- ACCESS_ONCE(ads->ds_link) = i->link;
39748- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39749+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
39750+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39751
39752 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39753 ctl6 = SM(i->keytype, AR_EncrType);
39754@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39755
39756 if ((i->is_first || i->is_last) &&
39757 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39758- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39759+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39760 | set11nTries(i->rates, 1)
39761 | set11nTries(i->rates, 2)
39762 | set11nTries(i->rates, 3)
39763 | (i->dur_update ? AR_DurUpdateEna : 0)
39764 | SM(0, AR_BurstDur);
39765
39766- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39767+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39768 | set11nRate(i->rates, 1)
39769 | set11nRate(i->rates, 2)
39770 | set11nRate(i->rates, 3);
39771 } else {
39772- ACCESS_ONCE(ads->ds_ctl2) = 0;
39773- ACCESS_ONCE(ads->ds_ctl3) = 0;
39774+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39775+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39776 }
39777
39778 if (!i->is_first) {
39779- ACCESS_ONCE(ads->ds_ctl0) = 0;
39780- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39781- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39782+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39783+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39784+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39785 return;
39786 }
39787
39788@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39789 break;
39790 }
39791
39792- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39793+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39794 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39795 | SM(i->txpower, AR_XmitPower)
39796 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39797@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39798 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39799 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39800
39801- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39802- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39803+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39804+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39805
39806 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39807 return;
39808
39809- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39810+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39811 | set11nPktDurRTSCTS(i->rates, 1);
39812
39813- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39814+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39815 | set11nPktDurRTSCTS(i->rates, 3);
39816
39817- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39818+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39819 | set11nRateFlags(i->rates, 1)
39820 | set11nRateFlags(i->rates, 2)
39821 | set11nRateFlags(i->rates, 3)
39822diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39823index 301bf72..3f5654f 100644
39824--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39825+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39826@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39827 (i->qcu << AR_TxQcuNum_S) | desc_len;
39828
39829 checksum += val;
39830- ACCESS_ONCE(ads->info) = val;
39831+ ACCESS_ONCE_RW(ads->info) = val;
39832
39833 checksum += i->link;
39834- ACCESS_ONCE(ads->link) = i->link;
39835+ ACCESS_ONCE_RW(ads->link) = i->link;
39836
39837 checksum += i->buf_addr[0];
39838- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39839+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39840 checksum += i->buf_addr[1];
39841- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39842+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39843 checksum += i->buf_addr[2];
39844- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39845+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39846 checksum += i->buf_addr[3];
39847- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39848+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39849
39850 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39851- ACCESS_ONCE(ads->ctl3) = val;
39852+ ACCESS_ONCE_RW(ads->ctl3) = val;
39853 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39854- ACCESS_ONCE(ads->ctl5) = val;
39855+ ACCESS_ONCE_RW(ads->ctl5) = val;
39856 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39857- ACCESS_ONCE(ads->ctl7) = val;
39858+ ACCESS_ONCE_RW(ads->ctl7) = val;
39859 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39860- ACCESS_ONCE(ads->ctl9) = val;
39861+ ACCESS_ONCE_RW(ads->ctl9) = val;
39862
39863 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39864- ACCESS_ONCE(ads->ctl10) = checksum;
39865+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
39866
39867 if (i->is_first || i->is_last) {
39868- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39869+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39870 | set11nTries(i->rates, 1)
39871 | set11nTries(i->rates, 2)
39872 | set11nTries(i->rates, 3)
39873 | (i->dur_update ? AR_DurUpdateEna : 0)
39874 | SM(0, AR_BurstDur);
39875
39876- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39877+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39878 | set11nRate(i->rates, 1)
39879 | set11nRate(i->rates, 2)
39880 | set11nRate(i->rates, 3);
39881 } else {
39882- ACCESS_ONCE(ads->ctl13) = 0;
39883- ACCESS_ONCE(ads->ctl14) = 0;
39884+ ACCESS_ONCE_RW(ads->ctl13) = 0;
39885+ ACCESS_ONCE_RW(ads->ctl14) = 0;
39886 }
39887
39888 ads->ctl20 = 0;
39889@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39890
39891 ctl17 = SM(i->keytype, AR_EncrType);
39892 if (!i->is_first) {
39893- ACCESS_ONCE(ads->ctl11) = 0;
39894- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39895- ACCESS_ONCE(ads->ctl15) = 0;
39896- ACCESS_ONCE(ads->ctl16) = 0;
39897- ACCESS_ONCE(ads->ctl17) = ctl17;
39898- ACCESS_ONCE(ads->ctl18) = 0;
39899- ACCESS_ONCE(ads->ctl19) = 0;
39900+ ACCESS_ONCE_RW(ads->ctl11) = 0;
39901+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39902+ ACCESS_ONCE_RW(ads->ctl15) = 0;
39903+ ACCESS_ONCE_RW(ads->ctl16) = 0;
39904+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39905+ ACCESS_ONCE_RW(ads->ctl18) = 0;
39906+ ACCESS_ONCE_RW(ads->ctl19) = 0;
39907 return;
39908 }
39909
39910- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39911+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39912 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39913 | SM(i->txpower, AR_XmitPower)
39914 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39915@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39916 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39917 ctl12 |= SM(val, AR_PAPRDChainMask);
39918
39919- ACCESS_ONCE(ads->ctl12) = ctl12;
39920- ACCESS_ONCE(ads->ctl17) = ctl17;
39921+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39922+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39923
39924- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39925+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39926 | set11nPktDurRTSCTS(i->rates, 1);
39927
39928- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39929+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39930 | set11nPktDurRTSCTS(i->rates, 3);
39931
39932- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39933+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39934 | set11nRateFlags(i->rates, 1)
39935 | set11nRateFlags(i->rates, 2)
39936 | set11nRateFlags(i->rates, 3)
39937 | SM(i->rtscts_rate, AR_RTSCTSRate);
39938
39939- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39940+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39941 }
39942
39943 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39944diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39945index 9d26fc5..60d9f14 100644
39946--- a/drivers/net/wireless/ath/ath9k/hw.h
39947+++ b/drivers/net/wireless/ath/ath9k/hw.h
39948@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39949
39950 /* ANI */
39951 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39952-};
39953+} __no_const;
39954
39955 /**
39956 * struct ath_hw_ops - callbacks used by hardware code and driver code
39957@@ -688,7 +688,7 @@ struct ath_hw_ops {
39958 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39959 struct ath_hw_antcomb_conf *antconf);
39960 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39961-};
39962+} __no_const;
39963
39964 struct ath_nf_limits {
39965 s16 max;
39966diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
39967index 3726cd6..b655808 100644
39968--- a/drivers/net/wireless/iwlegacy/3945-mac.c
39969+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
39970@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39971 */
39972 if (il3945_mod_params.disable_hw_scan) {
39973 D_INFO("Disabling hw_scan\n");
39974- il3945_mac_ops.hw_scan = NULL;
39975+ pax_open_kernel();
39976+ *(void **)&il3945_mac_ops.hw_scan = NULL;
39977+ pax_close_kernel();
39978 }
39979
39980 D_INFO("*** LOAD DRIVER ***\n");
39981diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39982index 5b9533e..7733880 100644
39983--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39984+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39985@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
39986 {
39987 struct iwl_priv *priv = file->private_data;
39988 char buf[64];
39989- int buf_size;
39990+ size_t buf_size;
39991 u32 offset, len;
39992
39993 memset(buf, 0, sizeof(buf));
39994@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
39995 struct iwl_priv *priv = file->private_data;
39996
39997 char buf[8];
39998- int buf_size;
39999+ size_t buf_size;
40000 u32 reset_flag;
40001
40002 memset(buf, 0, sizeof(buf));
40003@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40004 {
40005 struct iwl_priv *priv = file->private_data;
40006 char buf[8];
40007- int buf_size;
40008+ size_t buf_size;
40009 int ht40;
40010
40011 memset(buf, 0, sizeof(buf));
40012@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_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 value;
40019
40020 memset(buf, 0, sizeof(buf));
40021@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_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 clear;
40028
40029 memset(buf, 0, sizeof(buf));
40030@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_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 trace;
40037
40038 memset(buf, 0, sizeof(buf));
40039@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_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 missed;
40046
40047 memset(buf, 0, sizeof(buf));
40048@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_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 plcp;
40055
40056 memset(buf, 0, sizeof(buf));
40057@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_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 flush;
40064
40065 memset(buf, 0, sizeof(buf));
40066@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_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 rts;
40073
40074 if (!priv->cfg->ht_params)
40075@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_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
40082 memset(buf, 0, sizeof(buf));
40083 buf_size = min(count, sizeof(buf) - 1);
40084@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40085 struct iwl_priv *priv = file->private_data;
40086 u32 event_log_flag;
40087 char buf[8];
40088- int buf_size;
40089+ size_t buf_size;
40090
40091 /* check that the interface is up */
40092 if (!iwl_is_ready(priv))
40093@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40094 struct iwl_priv *priv = file->private_data;
40095 char buf[8];
40096 u32 calib_disabled;
40097- int buf_size;
40098+ size_t buf_size;
40099
40100 memset(buf, 0, sizeof(buf));
40101 buf_size = min(count, sizeof(buf) - 1);
40102diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40103index 35708b9..31f7754 100644
40104--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40105+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40106@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40107 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40108
40109 char buf[8];
40110- int buf_size;
40111+ size_t buf_size;
40112 u32 reset_flag;
40113
40114 memset(buf, 0, sizeof(buf));
40115@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40116 {
40117 struct iwl_trans *trans = file->private_data;
40118 char buf[8];
40119- int buf_size;
40120+ size_t buf_size;
40121 int csr;
40122
40123 memset(buf, 0, sizeof(buf));
40124diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40125index ff90855..e46d223 100644
40126--- a/drivers/net/wireless/mac80211_hwsim.c
40127+++ b/drivers/net/wireless/mac80211_hwsim.c
40128@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
40129
40130 if (channels > 1) {
40131 hwsim_if_comb.num_different_channels = channels;
40132- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40133- mac80211_hwsim_ops.cancel_hw_scan =
40134- mac80211_hwsim_cancel_hw_scan;
40135- mac80211_hwsim_ops.sw_scan_start = NULL;
40136- mac80211_hwsim_ops.sw_scan_complete = NULL;
40137- mac80211_hwsim_ops.remain_on_channel =
40138- mac80211_hwsim_roc;
40139- mac80211_hwsim_ops.cancel_remain_on_channel =
40140- mac80211_hwsim_croc;
40141- mac80211_hwsim_ops.add_chanctx =
40142- mac80211_hwsim_add_chanctx;
40143- mac80211_hwsim_ops.remove_chanctx =
40144- mac80211_hwsim_remove_chanctx;
40145- mac80211_hwsim_ops.change_chanctx =
40146- mac80211_hwsim_change_chanctx;
40147- mac80211_hwsim_ops.assign_vif_chanctx =
40148- mac80211_hwsim_assign_vif_chanctx;
40149- mac80211_hwsim_ops.unassign_vif_chanctx =
40150- mac80211_hwsim_unassign_vif_chanctx;
40151+ pax_open_kernel();
40152+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40153+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40154+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40155+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40156+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40157+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40158+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40159+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40160+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40161+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40162+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40163+ pax_close_kernel();
40164 }
40165
40166 spin_lock_init(&hwsim_radio_lock);
40167diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40168index abe1d03..fb02c22 100644
40169--- a/drivers/net/wireless/rndis_wlan.c
40170+++ b/drivers/net/wireless/rndis_wlan.c
40171@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40172
40173 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40174
40175- if (rts_threshold < 0 || rts_threshold > 2347)
40176+ if (rts_threshold > 2347)
40177 rts_threshold = 2347;
40178
40179 tmp = cpu_to_le32(rts_threshold);
40180diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40181index 0751b35..246ba3e 100644
40182--- a/drivers/net/wireless/rt2x00/rt2x00.h
40183+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40184@@ -398,7 +398,7 @@ struct rt2x00_intf {
40185 * for hardware which doesn't support hardware
40186 * sequence counting.
40187 */
40188- atomic_t seqno;
40189+ atomic_unchecked_t seqno;
40190 };
40191
40192 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40193diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40194index e488b94..14b6a0c 100644
40195--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40196+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40197@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40198 * sequence counter given by mac80211.
40199 */
40200 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40201- seqno = atomic_add_return(0x10, &intf->seqno);
40202+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40203 else
40204- seqno = atomic_read(&intf->seqno);
40205+ seqno = atomic_read_unchecked(&intf->seqno);
40206
40207 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40208 hdr->seq_ctrl |= cpu_to_le16(seqno);
40209diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40210index e57ee48..541cf6c 100644
40211--- a/drivers/net/wireless/ti/wl1251/sdio.c
40212+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40213@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40214
40215 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40216
40217- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40218- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40219+ pax_open_kernel();
40220+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40221+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40222+ pax_close_kernel();
40223
40224 wl1251_info("using dedicated interrupt line");
40225 } else {
40226- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40227- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40228+ pax_open_kernel();
40229+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40230+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40231+ pax_close_kernel();
40232
40233 wl1251_info("using SDIO interrupt");
40234 }
40235diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40236index e5f5f8f..fdf15b7 100644
40237--- a/drivers/net/wireless/ti/wl12xx/main.c
40238+++ b/drivers/net/wireless/ti/wl12xx/main.c
40239@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40240 sizeof(wl->conf.mem));
40241
40242 /* read data preparation is only needed by wl127x */
40243- wl->ops->prepare_read = wl127x_prepare_read;
40244+ pax_open_kernel();
40245+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40246+ pax_close_kernel();
40247
40248 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40249 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40250@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40251 sizeof(wl->conf.mem));
40252
40253 /* read data preparation is only needed by wl127x */
40254- wl->ops->prepare_read = wl127x_prepare_read;
40255+ pax_open_kernel();
40256+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40257+ pax_close_kernel();
40258
40259 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40260 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40261diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
40262index 8d8c1f8..e754844 100644
40263--- a/drivers/net/wireless/ti/wl18xx/main.c
40264+++ b/drivers/net/wireless/ti/wl18xx/main.c
40265@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
40266 }
40267
40268 if (!checksum_param) {
40269- wl18xx_ops.set_rx_csum = NULL;
40270- wl18xx_ops.init_vif = NULL;
40271+ pax_open_kernel();
40272+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
40273+ *(void **)&wl18xx_ops.init_vif = NULL;
40274+ pax_close_kernel();
40275 }
40276
40277 /* Enable 11a Band only if we have 5G antennas */
40278diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
40279index d93b2b6..ae50401 100644
40280--- a/drivers/oprofile/buffer_sync.c
40281+++ b/drivers/oprofile/buffer_sync.c
40282@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
40283 if (cookie == NO_COOKIE)
40284 offset = pc;
40285 if (cookie == INVALID_COOKIE) {
40286- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40287+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40288 offset = pc;
40289 }
40290 if (cookie != last_cookie) {
40291@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
40292 /* add userspace sample */
40293
40294 if (!mm) {
40295- atomic_inc(&oprofile_stats.sample_lost_no_mm);
40296+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
40297 return 0;
40298 }
40299
40300 cookie = lookup_dcookie(mm, s->eip, &offset);
40301
40302 if (cookie == INVALID_COOKIE) {
40303- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40304+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40305 return 0;
40306 }
40307
40308@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
40309 /* ignore backtraces if failed to add a sample */
40310 if (state == sb_bt_start) {
40311 state = sb_bt_ignore;
40312- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
40313+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
40314 }
40315 }
40316 release_mm(mm);
40317diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
40318index c0cc4e7..44d4e54 100644
40319--- a/drivers/oprofile/event_buffer.c
40320+++ b/drivers/oprofile/event_buffer.c
40321@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
40322 }
40323
40324 if (buffer_pos == buffer_size) {
40325- atomic_inc(&oprofile_stats.event_lost_overflow);
40326+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
40327 return;
40328 }
40329
40330diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
40331index ed2c3ec..deda85a 100644
40332--- a/drivers/oprofile/oprof.c
40333+++ b/drivers/oprofile/oprof.c
40334@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
40335 if (oprofile_ops.switch_events())
40336 return;
40337
40338- atomic_inc(&oprofile_stats.multiplex_counter);
40339+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
40340 start_switch_worker();
40341 }
40342
40343diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
40344index 84a208d..d61b0a1 100644
40345--- a/drivers/oprofile/oprofile_files.c
40346+++ b/drivers/oprofile/oprofile_files.c
40347@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
40348
40349 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
40350
40351-static ssize_t timeout_read(struct file *file, char __user *buf,
40352+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
40353 size_t count, loff_t *offset)
40354 {
40355 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
40356diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
40357index 917d28e..d62d981 100644
40358--- a/drivers/oprofile/oprofile_stats.c
40359+++ b/drivers/oprofile/oprofile_stats.c
40360@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
40361 cpu_buf->sample_invalid_eip = 0;
40362 }
40363
40364- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
40365- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
40366- atomic_set(&oprofile_stats.event_lost_overflow, 0);
40367- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
40368- atomic_set(&oprofile_stats.multiplex_counter, 0);
40369+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
40370+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
40371+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
40372+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
40373+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
40374 }
40375
40376
40377diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
40378index 38b6fc0..b5cbfce 100644
40379--- a/drivers/oprofile/oprofile_stats.h
40380+++ b/drivers/oprofile/oprofile_stats.h
40381@@ -13,11 +13,11 @@
40382 #include <linux/atomic.h>
40383
40384 struct oprofile_stat_struct {
40385- atomic_t sample_lost_no_mm;
40386- atomic_t sample_lost_no_mapping;
40387- atomic_t bt_lost_no_mapping;
40388- atomic_t event_lost_overflow;
40389- atomic_t multiplex_counter;
40390+ atomic_unchecked_t sample_lost_no_mm;
40391+ atomic_unchecked_t sample_lost_no_mapping;
40392+ atomic_unchecked_t bt_lost_no_mapping;
40393+ atomic_unchecked_t event_lost_overflow;
40394+ atomic_unchecked_t multiplex_counter;
40395 };
40396
40397 extern struct oprofile_stat_struct oprofile_stats;
40398diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40399index 849357c..b83c1e0 100644
40400--- a/drivers/oprofile/oprofilefs.c
40401+++ b/drivers/oprofile/oprofilefs.c
40402@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
40403
40404
40405 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40406- char const *name, atomic_t *val)
40407+ char const *name, atomic_unchecked_t *val)
40408 {
40409 return __oprofilefs_create_file(sb, root, name,
40410 &atomic_ro_fops, 0444, val);
40411diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40412index 93404f7..4a313d8 100644
40413--- a/drivers/oprofile/timer_int.c
40414+++ b/drivers/oprofile/timer_int.c
40415@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40416 return NOTIFY_OK;
40417 }
40418
40419-static struct notifier_block __refdata oprofile_cpu_notifier = {
40420+static struct notifier_block oprofile_cpu_notifier = {
40421 .notifier_call = oprofile_cpu_notify,
40422 };
40423
40424diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40425index 3f56bc0..707d642 100644
40426--- a/drivers/parport/procfs.c
40427+++ b/drivers/parport/procfs.c
40428@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40429
40430 *ppos += len;
40431
40432- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40433+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40434 }
40435
40436 #ifdef CONFIG_PARPORT_1284
40437@@ -106,7 +106,7 @@ static int do_autoprobe(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 #endif /* IEEE1284.3 support. */
40445
40446diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40447index c35e8ad..fc33beb 100644
40448--- a/drivers/pci/hotplug/acpiphp_ibm.c
40449+++ b/drivers/pci/hotplug/acpiphp_ibm.c
40450@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40451 goto init_cleanup;
40452 }
40453
40454- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40455+ pax_open_kernel();
40456+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40457+ pax_close_kernel();
40458 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40459
40460 return retval;
40461diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40462index a6a71c4..c91097b 100644
40463--- a/drivers/pci/hotplug/cpcihp_generic.c
40464+++ b/drivers/pci/hotplug/cpcihp_generic.c
40465@@ -73,7 +73,6 @@ static u16 port;
40466 static unsigned int enum_bit;
40467 static u8 enum_mask;
40468
40469-static struct cpci_hp_controller_ops generic_hpc_ops;
40470 static struct cpci_hp_controller generic_hpc;
40471
40472 static int __init validate_parameters(void)
40473@@ -139,6 +138,10 @@ static int query_enum(void)
40474 return ((value & enum_mask) == enum_mask);
40475 }
40476
40477+static struct cpci_hp_controller_ops generic_hpc_ops = {
40478+ .query_enum = query_enum,
40479+};
40480+
40481 static int __init cpcihp_generic_init(void)
40482 {
40483 int status;
40484@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40485 pci_dev_put(dev);
40486
40487 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40488- generic_hpc_ops.query_enum = query_enum;
40489 generic_hpc.ops = &generic_hpc_ops;
40490
40491 status = cpci_hp_register_controller(&generic_hpc);
40492diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40493index 449b4bb..257e2e8 100644
40494--- a/drivers/pci/hotplug/cpcihp_zt5550.c
40495+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40496@@ -59,7 +59,6 @@
40497 /* local variables */
40498 static bool debug;
40499 static bool poll;
40500-static struct cpci_hp_controller_ops zt5550_hpc_ops;
40501 static struct cpci_hp_controller zt5550_hpc;
40502
40503 /* Primary cPCI bus bridge device */
40504@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40505 return 0;
40506 }
40507
40508+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40509+ .query_enum = zt5550_hc_query_enum,
40510+};
40511+
40512 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40513 {
40514 int status;
40515@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40516 dbg("returned from zt5550_hc_config");
40517
40518 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40519- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40520 zt5550_hpc.ops = &zt5550_hpc_ops;
40521 if(!poll) {
40522 zt5550_hpc.irq = hc_dev->irq;
40523 zt5550_hpc.irq_flags = IRQF_SHARED;
40524 zt5550_hpc.dev_id = hc_dev;
40525
40526- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40527- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40528- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40529+ pax_open_kernel();
40530+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40531+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40532+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40533+ pax_open_kernel();
40534 } else {
40535 info("using ENUM# polling mode");
40536 }
40537diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40538index 76ba8a1..20ca857 100644
40539--- a/drivers/pci/hotplug/cpqphp_nvram.c
40540+++ b/drivers/pci/hotplug/cpqphp_nvram.c
40541@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40542
40543 void compaq_nvram_init (void __iomem *rom_start)
40544 {
40545+
40546+#ifndef CONFIG_PAX_KERNEXEC
40547 if (rom_start) {
40548 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40549 }
40550+#endif
40551+
40552 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40553
40554 /* initialize our int15 lock */
40555diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40556index 202f4a9..8ee47d0 100644
40557--- a/drivers/pci/hotplug/pci_hotplug_core.c
40558+++ b/drivers/pci/hotplug/pci_hotplug_core.c
40559@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40560 return -EINVAL;
40561 }
40562
40563- slot->ops->owner = owner;
40564- slot->ops->mod_name = mod_name;
40565+ pax_open_kernel();
40566+ *(struct module **)&slot->ops->owner = owner;
40567+ *(const char **)&slot->ops->mod_name = mod_name;
40568+ pax_close_kernel();
40569
40570 mutex_lock(&pci_hp_mutex);
40571 /*
40572diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40573index 939bd1d..a1459c9 100644
40574--- a/drivers/pci/hotplug/pciehp_core.c
40575+++ b/drivers/pci/hotplug/pciehp_core.c
40576@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40577 struct slot *slot = ctrl->slot;
40578 struct hotplug_slot *hotplug = NULL;
40579 struct hotplug_slot_info *info = NULL;
40580- struct hotplug_slot_ops *ops = NULL;
40581+ hotplug_slot_ops_no_const *ops = NULL;
40582 char name[SLOT_NAME_SIZE];
40583 int retval = -ENOMEM;
40584
40585diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40586index 9c6e9bb..2916736 100644
40587--- a/drivers/pci/pci-sysfs.c
40588+++ b/drivers/pci/pci-sysfs.c
40589@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40590 {
40591 /* allocate attribute structure, piggyback attribute name */
40592 int name_len = write_combine ? 13 : 10;
40593- struct bin_attribute *res_attr;
40594+ bin_attribute_no_const *res_attr;
40595 int retval;
40596
40597 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40598@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40599 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40600 {
40601 int retval;
40602- struct bin_attribute *attr;
40603+ bin_attribute_no_const *attr;
40604
40605 /* If the device has VPD, try to expose it in sysfs. */
40606 if (dev->vpd) {
40607@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40608 {
40609 int retval;
40610 int rom_size = 0;
40611- struct bin_attribute *attr;
40612+ bin_attribute_no_const *attr;
40613
40614 if (!sysfs_initialized)
40615 return -EACCES;
40616diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40617index e851829..a1a7196 100644
40618--- a/drivers/pci/pci.h
40619+++ b/drivers/pci/pci.h
40620@@ -98,7 +98,7 @@ struct pci_vpd_ops {
40621 struct pci_vpd {
40622 unsigned int len;
40623 const struct pci_vpd_ops *ops;
40624- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40625+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40626 };
40627
40628 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40629diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40630index 8474b6a..ee81993 100644
40631--- a/drivers/pci/pcie/aspm.c
40632+++ b/drivers/pci/pcie/aspm.c
40633@@ -27,9 +27,9 @@
40634 #define MODULE_PARAM_PREFIX "pcie_aspm."
40635
40636 /* Note: those are not register definitions */
40637-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40638-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40639-#define ASPM_STATE_L1 (4) /* L1 state */
40640+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40641+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40642+#define ASPM_STATE_L1 (4U) /* L1 state */
40643 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40644 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40645
40646diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40647index 6186f03..1a78714 100644
40648--- a/drivers/pci/probe.c
40649+++ b/drivers/pci/probe.c
40650@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40651 struct pci_bus_region region;
40652 bool bar_too_big = false, bar_disabled = false;
40653
40654- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40655+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40656
40657 /* No printks while decoding is disabled! */
40658 if (!dev->mmio_always_on) {
40659diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40660index 9b8505c..f00870a 100644
40661--- a/drivers/pci/proc.c
40662+++ b/drivers/pci/proc.c
40663@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40664 static int __init pci_proc_init(void)
40665 {
40666 struct pci_dev *dev = NULL;
40667+
40668+#ifdef CONFIG_GRKERNSEC_PROC_ADD
40669+#ifdef CONFIG_GRKERNSEC_PROC_USER
40670+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40671+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40672+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40673+#endif
40674+#else
40675 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40676+#endif
40677 proc_create("devices", 0, proc_bus_pci_dir,
40678 &proc_bus_pci_dev_operations);
40679 proc_initialized = 1;
40680diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40681index 2111dbb..79e434b 100644
40682--- a/drivers/platform/x86/msi-laptop.c
40683+++ b/drivers/platform/x86/msi-laptop.c
40684@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40685 int result;
40686
40687 /* allow userland write sysfs file */
40688- dev_attr_bluetooth.store = store_bluetooth;
40689- dev_attr_wlan.store = store_wlan;
40690- dev_attr_threeg.store = store_threeg;
40691- dev_attr_bluetooth.attr.mode |= S_IWUSR;
40692- dev_attr_wlan.attr.mode |= S_IWUSR;
40693- dev_attr_threeg.attr.mode |= S_IWUSR;
40694+ pax_open_kernel();
40695+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40696+ *(void **)&dev_attr_wlan.store = store_wlan;
40697+ *(void **)&dev_attr_threeg.store = store_threeg;
40698+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40699+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40700+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40701+ pax_close_kernel();
40702
40703 /* disable hardware control by fn key */
40704 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40705diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40706index 0fe987f..6f3d5c3 100644
40707--- a/drivers/platform/x86/sony-laptop.c
40708+++ b/drivers/platform/x86/sony-laptop.c
40709@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40710 }
40711
40712 /* High speed charging function */
40713-static struct device_attribute *hsc_handle;
40714+static device_attribute_no_const *hsc_handle;
40715
40716 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40717 struct device_attribute *attr,
40718diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40719index f946ca7..f25c833 100644
40720--- a/drivers/platform/x86/thinkpad_acpi.c
40721+++ b/drivers/platform/x86/thinkpad_acpi.c
40722@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40723 return 0;
40724 }
40725
40726-void static hotkey_mask_warn_incomplete_mask(void)
40727+static void hotkey_mask_warn_incomplete_mask(void)
40728 {
40729 /* log only what the user can fix... */
40730 const u32 wantedmask = hotkey_driver_mask &
40731@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40732 }
40733 }
40734
40735-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40736- struct tp_nvram_state *newn,
40737- const u32 event_mask)
40738-{
40739-
40740 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40741 do { \
40742 if ((event_mask & (1 << __scancode)) && \
40743@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40744 tpacpi_hotkey_send_key(__scancode); \
40745 } while (0)
40746
40747- void issue_volchange(const unsigned int oldvol,
40748- const unsigned int newvol)
40749- {
40750- unsigned int i = oldvol;
40751+static void issue_volchange(const unsigned int oldvol,
40752+ const unsigned int newvol,
40753+ const u32 event_mask)
40754+{
40755+ unsigned int i = oldvol;
40756
40757- while (i > newvol) {
40758- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40759- i--;
40760- }
40761- while (i < newvol) {
40762- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40763- i++;
40764- }
40765+ while (i > newvol) {
40766+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40767+ i--;
40768 }
40769+ while (i < newvol) {
40770+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40771+ i++;
40772+ }
40773+}
40774
40775- void issue_brightnesschange(const unsigned int oldbrt,
40776- const unsigned int newbrt)
40777- {
40778- unsigned int i = oldbrt;
40779+static void issue_brightnesschange(const unsigned int oldbrt,
40780+ const unsigned int newbrt,
40781+ const u32 event_mask)
40782+{
40783+ unsigned int i = oldbrt;
40784
40785- while (i > newbrt) {
40786- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40787- i--;
40788- }
40789- while (i < newbrt) {
40790- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40791- i++;
40792- }
40793+ while (i > newbrt) {
40794+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40795+ i--;
40796+ }
40797+ while (i < newbrt) {
40798+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40799+ i++;
40800 }
40801+}
40802
40803+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40804+ struct tp_nvram_state *newn,
40805+ const u32 event_mask)
40806+{
40807 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40808 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40809 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40810@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40811 oldn->volume_level != newn->volume_level) {
40812 /* recently muted, or repeated mute keypress, or
40813 * multiple presses ending in mute */
40814- issue_volchange(oldn->volume_level, newn->volume_level);
40815+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40816 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40817 }
40818 } else {
40819@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40820 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40821 }
40822 if (oldn->volume_level != newn->volume_level) {
40823- issue_volchange(oldn->volume_level, newn->volume_level);
40824+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40825 } else if (oldn->volume_toggle != newn->volume_toggle) {
40826 /* repeated vol up/down keypress at end of scale ? */
40827 if (newn->volume_level == 0)
40828@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40829 /* handle brightness */
40830 if (oldn->brightness_level != newn->brightness_level) {
40831 issue_brightnesschange(oldn->brightness_level,
40832- newn->brightness_level);
40833+ newn->brightness_level,
40834+ event_mask);
40835 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40836 /* repeated key presses that didn't change state */
40837 if (newn->brightness_level == 0)
40838@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40839 && !tp_features.bright_unkfw)
40840 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40841 }
40842+}
40843
40844 #undef TPACPI_COMPARE_KEY
40845 #undef TPACPI_MAY_SEND_KEY
40846-}
40847
40848 /*
40849 * Polling driver
40850diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40851index 769d265..a3a05ca 100644
40852--- a/drivers/pnp/pnpbios/bioscalls.c
40853+++ b/drivers/pnp/pnpbios/bioscalls.c
40854@@ -58,7 +58,7 @@ do { \
40855 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40856 } while(0)
40857
40858-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40859+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40860 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40861
40862 /*
40863@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40864
40865 cpu = get_cpu();
40866 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40867+
40868+ pax_open_kernel();
40869 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40870+ pax_close_kernel();
40871
40872 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40873 spin_lock_irqsave(&pnp_bios_lock, flags);
40874@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40875 :"memory");
40876 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40877
40878+ pax_open_kernel();
40879 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40880+ pax_close_kernel();
40881+
40882 put_cpu();
40883
40884 /* If we get here and this is set then the PnP BIOS faulted on us. */
40885@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40886 return status;
40887 }
40888
40889-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40890+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40891 {
40892 int i;
40893
40894@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40895 pnp_bios_callpoint.offset = header->fields.pm16offset;
40896 pnp_bios_callpoint.segment = PNP_CS16;
40897
40898+ pax_open_kernel();
40899+
40900 for_each_possible_cpu(i) {
40901 struct desc_struct *gdt = get_cpu_gdt_table(i);
40902 if (!gdt)
40903@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40904 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40905 (unsigned long)__va(header->fields.pm16dseg));
40906 }
40907+
40908+ pax_close_kernel();
40909 }
40910diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40911index 3e6db1c..1fbbdae 100644
40912--- a/drivers/pnp/resource.c
40913+++ b/drivers/pnp/resource.c
40914@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40915 return 1;
40916
40917 /* check if the resource is valid */
40918- if (*irq < 0 || *irq > 15)
40919+ if (*irq > 15)
40920 return 0;
40921
40922 /* check if the resource is reserved */
40923@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40924 return 1;
40925
40926 /* check if the resource is valid */
40927- if (*dma < 0 || *dma == 4 || *dma > 7)
40928+ if (*dma == 4 || *dma > 7)
40929 return 0;
40930
40931 /* check if the resource is reserved */
40932diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40933index 7df7c5f..bd48c47 100644
40934--- a/drivers/power/pda_power.c
40935+++ b/drivers/power/pda_power.c
40936@@ -37,7 +37,11 @@ static int polling;
40937
40938 #ifdef CONFIG_USB_OTG_UTILS
40939 static struct usb_phy *transceiver;
40940-static struct notifier_block otg_nb;
40941+static int otg_handle_notification(struct notifier_block *nb,
40942+ unsigned long event, void *unused);
40943+static struct notifier_block otg_nb = {
40944+ .notifier_call = otg_handle_notification
40945+};
40946 #endif
40947
40948 static struct regulator *ac_draw;
40949@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40950
40951 #ifdef CONFIG_USB_OTG_UTILS
40952 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
40953- otg_nb.notifier_call = otg_handle_notification;
40954 ret = usb_register_notifier(transceiver, &otg_nb);
40955 if (ret) {
40956 dev_err(dev, "failure to register otg notifier\n");
40957diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
40958index cc439fd..8fa30df 100644
40959--- a/drivers/power/power_supply.h
40960+++ b/drivers/power/power_supply.h
40961@@ -16,12 +16,12 @@ struct power_supply;
40962
40963 #ifdef CONFIG_SYSFS
40964
40965-extern void power_supply_init_attrs(struct device_type *dev_type);
40966+extern void power_supply_init_attrs(void);
40967 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
40968
40969 #else
40970
40971-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
40972+static inline void power_supply_init_attrs(void) {}
40973 #define power_supply_uevent NULL
40974
40975 #endif /* CONFIG_SYSFS */
40976diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
40977index 8a7cfb3..72e6e9b 100644
40978--- a/drivers/power/power_supply_core.c
40979+++ b/drivers/power/power_supply_core.c
40980@@ -24,7 +24,10 @@
40981 struct class *power_supply_class;
40982 EXPORT_SYMBOL_GPL(power_supply_class);
40983
40984-static struct device_type power_supply_dev_type;
40985+extern const struct attribute_group *power_supply_attr_groups[];
40986+static struct device_type power_supply_dev_type = {
40987+ .groups = power_supply_attr_groups,
40988+};
40989
40990 static int __power_supply_changed_work(struct device *dev, void *data)
40991 {
40992@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
40993 return PTR_ERR(power_supply_class);
40994
40995 power_supply_class->dev_uevent = power_supply_uevent;
40996- power_supply_init_attrs(&power_supply_dev_type);
40997+ power_supply_init_attrs();
40998
40999 return 0;
41000 }
41001diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41002index 40fa3b7..d9c2e0e 100644
41003--- a/drivers/power/power_supply_sysfs.c
41004+++ b/drivers/power/power_supply_sysfs.c
41005@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
41006 .is_visible = power_supply_attr_is_visible,
41007 };
41008
41009-static const struct attribute_group *power_supply_attr_groups[] = {
41010+const struct attribute_group *power_supply_attr_groups[] = {
41011 &power_supply_attr_group,
41012 NULL,
41013 };
41014
41015-void power_supply_init_attrs(struct device_type *dev_type)
41016+void power_supply_init_attrs(void)
41017 {
41018 int i;
41019
41020- dev_type->groups = power_supply_attr_groups;
41021-
41022 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41023 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41024 }
41025diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41026index 4d7c635..9860196 100644
41027--- a/drivers/regulator/max8660.c
41028+++ b/drivers/regulator/max8660.c
41029@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41030 max8660->shadow_regs[MAX8660_OVER1] = 5;
41031 } else {
41032 /* Otherwise devices can be toggled via software */
41033- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41034- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41035+ pax_open_kernel();
41036+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41037+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41038+ pax_close_kernel();
41039 }
41040
41041 /*
41042diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41043index 9a8ea91..c483dd9 100644
41044--- a/drivers/regulator/max8973-regulator.c
41045+++ b/drivers/regulator/max8973-regulator.c
41046@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41047 if (!pdata->enable_ext_control) {
41048 max->desc.enable_reg = MAX8973_VOUT;
41049 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41050- max8973_dcdc_ops.enable = regulator_enable_regmap;
41051- max8973_dcdc_ops.disable = regulator_disable_regmap;
41052- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41053+ pax_open_kernel();
41054+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41055+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41056+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41057+ pax_close_kernel();
41058 }
41059
41060 max->enable_external_control = pdata->enable_ext_control;
41061diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41062index 0d84b1f..c2da6ac 100644
41063--- a/drivers/regulator/mc13892-regulator.c
41064+++ b/drivers/regulator/mc13892-regulator.c
41065@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41066 }
41067 mc13xxx_unlock(mc13892);
41068
41069- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41070+ pax_open_kernel();
41071+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41072 = mc13892_vcam_set_mode;
41073- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41074+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41075 = mc13892_vcam_get_mode;
41076+ pax_close_kernel();
41077
41078 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41079 ARRAY_SIZE(mc13892_regulators));
41080diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41081index 16630aa..6afc992 100644
41082--- a/drivers/rtc/rtc-cmos.c
41083+++ b/drivers/rtc/rtc-cmos.c
41084@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41085 hpet_rtc_timer_init();
41086
41087 /* export at least the first block of NVRAM */
41088- nvram.size = address_space - NVRAM_OFFSET;
41089+ pax_open_kernel();
41090+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41091+ pax_close_kernel();
41092 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41093 if (retval < 0) {
41094 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41095diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41096index 9a86b4b..3a383dc 100644
41097--- a/drivers/rtc/rtc-dev.c
41098+++ b/drivers/rtc/rtc-dev.c
41099@@ -14,6 +14,7 @@
41100 #include <linux/module.h>
41101 #include <linux/rtc.h>
41102 #include <linux/sched.h>
41103+#include <linux/grsecurity.h>
41104 #include "rtc-core.h"
41105
41106 static dev_t rtc_devt;
41107@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
41108 if (copy_from_user(&tm, uarg, sizeof(tm)))
41109 return -EFAULT;
41110
41111+ gr_log_timechange();
41112+
41113 return rtc_set_time(rtc, &tm);
41114
41115 case RTC_PIE_ON:
41116diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41117index e0d0ba4..3c65868 100644
41118--- a/drivers/rtc/rtc-ds1307.c
41119+++ b/drivers/rtc/rtc-ds1307.c
41120@@ -106,7 +106,7 @@ struct ds1307 {
41121 u8 offset; /* register's offset */
41122 u8 regs[11];
41123 u16 nvram_offset;
41124- struct bin_attribute *nvram;
41125+ bin_attribute_no_const *nvram;
41126 enum ds_type type;
41127 unsigned long flags;
41128 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41129diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41130index 130f29a..6179d03 100644
41131--- a/drivers/rtc/rtc-m48t59.c
41132+++ b/drivers/rtc/rtc-m48t59.c
41133@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41134 goto out;
41135 }
41136
41137- m48t59_nvram_attr.size = pdata->offset;
41138+ pax_open_kernel();
41139+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41140+ pax_close_kernel();
41141
41142 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41143 if (ret) {
41144diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41145index e693af6..2e525b6 100644
41146--- a/drivers/scsi/bfa/bfa_fcpim.h
41147+++ b/drivers/scsi/bfa/bfa_fcpim.h
41148@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41149
41150 struct bfa_itn_s {
41151 bfa_isr_func_t isr;
41152-};
41153+} __no_const;
41154
41155 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41156 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41157diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41158index 23a90e7..9cf04ee 100644
41159--- a/drivers/scsi/bfa/bfa_ioc.h
41160+++ b/drivers/scsi/bfa/bfa_ioc.h
41161@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41162 bfa_ioc_disable_cbfn_t disable_cbfn;
41163 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41164 bfa_ioc_reset_cbfn_t reset_cbfn;
41165-};
41166+} __no_const;
41167
41168 /*
41169 * IOC event notification mechanism.
41170@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41171 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41172 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41173 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41174-};
41175+} __no_const;
41176
41177 /*
41178 * Queue element to wait for room in request queue. FIFO order is
41179diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41180index 593085a..47aa999 100644
41181--- a/drivers/scsi/hosts.c
41182+++ b/drivers/scsi/hosts.c
41183@@ -42,7 +42,7 @@
41184 #include "scsi_logging.h"
41185
41186
41187-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41188+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41189
41190
41191 static void scsi_host_cls_release(struct device *dev)
41192@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41193 * subtract one because we increment first then return, but we need to
41194 * know what the next host number was before increment
41195 */
41196- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41197+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41198 shost->dma_channel = 0xff;
41199
41200 /* These three are default values which can be overridden */
41201diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41202index 4f33806..afd6f60 100644
41203--- a/drivers/scsi/hpsa.c
41204+++ b/drivers/scsi/hpsa.c
41205@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41206 unsigned long flags;
41207
41208 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41209- return h->access.command_completed(h, q);
41210+ return h->access->command_completed(h, q);
41211
41212 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41213 a = rq->head[rq->current_entry];
41214@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
41215 while (!list_empty(&h->reqQ)) {
41216 c = list_entry(h->reqQ.next, struct CommandList, list);
41217 /* can't do anything if fifo is full */
41218- if ((h->access.fifo_full(h))) {
41219+ if ((h->access->fifo_full(h))) {
41220 dev_warn(&h->pdev->dev, "fifo full\n");
41221 break;
41222 }
41223@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
41224
41225 /* Tell the controller execute command */
41226 spin_unlock_irqrestore(&h->lock, flags);
41227- h->access.submit_command(h, c);
41228+ h->access->submit_command(h, c);
41229 spin_lock_irqsave(&h->lock, flags);
41230 }
41231 spin_unlock_irqrestore(&h->lock, flags);
41232@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
41233
41234 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
41235 {
41236- return h->access.command_completed(h, q);
41237+ return h->access->command_completed(h, q);
41238 }
41239
41240 static inline bool interrupt_pending(struct ctlr_info *h)
41241 {
41242- return h->access.intr_pending(h);
41243+ return h->access->intr_pending(h);
41244 }
41245
41246 static inline long interrupt_not_for_us(struct ctlr_info *h)
41247 {
41248- return (h->access.intr_pending(h) == 0) ||
41249+ return (h->access->intr_pending(h) == 0) ||
41250 (h->interrupts_enabled == 0);
41251 }
41252
41253@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
41254 if (prod_index < 0)
41255 return -ENODEV;
41256 h->product_name = products[prod_index].product_name;
41257- h->access = *(products[prod_index].access);
41258+ h->access = products[prod_index].access;
41259
41260 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
41261 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
41262@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
41263
41264 assert_spin_locked(&lockup_detector_lock);
41265 remove_ctlr_from_lockup_detector_list(h);
41266- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41267+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41268 spin_lock_irqsave(&h->lock, flags);
41269 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
41270 spin_unlock_irqrestore(&h->lock, flags);
41271@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
41272 }
41273
41274 /* make sure the board interrupts are off */
41275- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41276+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41277
41278 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
41279 goto clean2;
41280@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
41281 * fake ones to scoop up any residual completions.
41282 */
41283 spin_lock_irqsave(&h->lock, flags);
41284- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41285+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41286 spin_unlock_irqrestore(&h->lock, flags);
41287 free_irqs(h);
41288 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
41289@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
41290 dev_info(&h->pdev->dev, "Board READY.\n");
41291 dev_info(&h->pdev->dev,
41292 "Waiting for stale completions to drain.\n");
41293- h->access.set_intr_mask(h, HPSA_INTR_ON);
41294+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41295 msleep(10000);
41296- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41297+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41298
41299 rc = controller_reset_failed(h->cfgtable);
41300 if (rc)
41301@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
41302 }
41303
41304 /* Turn the interrupts on so we can service requests */
41305- h->access.set_intr_mask(h, HPSA_INTR_ON);
41306+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41307
41308 hpsa_hba_inquiry(h);
41309 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
41310@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
41311 * To write all data in the battery backed cache to disks
41312 */
41313 hpsa_flush_cache(h);
41314- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41315+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41316 hpsa_free_irqs_and_disable_msix(h);
41317 }
41318
41319@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
41320 return;
41321 }
41322 /* Change the access methods to the performant access methods */
41323- h->access = SA5_performant_access;
41324+ h->access = &SA5_performant_access;
41325 h->transMethod = CFGTBL_Trans_Performant;
41326 }
41327
41328diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
41329index 9816479..c5d4e97 100644
41330--- a/drivers/scsi/hpsa.h
41331+++ b/drivers/scsi/hpsa.h
41332@@ -79,7 +79,7 @@ struct ctlr_info {
41333 unsigned int msix_vector;
41334 unsigned int msi_vector;
41335 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
41336- struct access_method access;
41337+ struct access_method *access;
41338
41339 /* queue and queue Info */
41340 struct list_head reqQ;
41341diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
41342index c772d8d..35c362c 100644
41343--- a/drivers/scsi/libfc/fc_exch.c
41344+++ b/drivers/scsi/libfc/fc_exch.c
41345@@ -100,12 +100,12 @@ struct fc_exch_mgr {
41346 u16 pool_max_index;
41347
41348 struct {
41349- atomic_t no_free_exch;
41350- atomic_t no_free_exch_xid;
41351- atomic_t xid_not_found;
41352- atomic_t xid_busy;
41353- atomic_t seq_not_found;
41354- atomic_t non_bls_resp;
41355+ atomic_unchecked_t no_free_exch;
41356+ atomic_unchecked_t no_free_exch_xid;
41357+ atomic_unchecked_t xid_not_found;
41358+ atomic_unchecked_t xid_busy;
41359+ atomic_unchecked_t seq_not_found;
41360+ atomic_unchecked_t non_bls_resp;
41361 } stats;
41362 };
41363
41364@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
41365 /* allocate memory for exchange */
41366 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
41367 if (!ep) {
41368- atomic_inc(&mp->stats.no_free_exch);
41369+ atomic_inc_unchecked(&mp->stats.no_free_exch);
41370 goto out;
41371 }
41372 memset(ep, 0, sizeof(*ep));
41373@@ -786,7 +786,7 @@ out:
41374 return ep;
41375 err:
41376 spin_unlock_bh(&pool->lock);
41377- atomic_inc(&mp->stats.no_free_exch_xid);
41378+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
41379 mempool_free(ep, mp->ep_pool);
41380 return NULL;
41381 }
41382@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41383 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41384 ep = fc_exch_find(mp, xid);
41385 if (!ep) {
41386- atomic_inc(&mp->stats.xid_not_found);
41387+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41388 reject = FC_RJT_OX_ID;
41389 goto out;
41390 }
41391@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41392 ep = fc_exch_find(mp, xid);
41393 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41394 if (ep) {
41395- atomic_inc(&mp->stats.xid_busy);
41396+ atomic_inc_unchecked(&mp->stats.xid_busy);
41397 reject = FC_RJT_RX_ID;
41398 goto rel;
41399 }
41400@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41401 }
41402 xid = ep->xid; /* get our XID */
41403 } else if (!ep) {
41404- atomic_inc(&mp->stats.xid_not_found);
41405+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41406 reject = FC_RJT_RX_ID; /* XID not found */
41407 goto out;
41408 }
41409@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41410 } else {
41411 sp = &ep->seq;
41412 if (sp->id != fh->fh_seq_id) {
41413- atomic_inc(&mp->stats.seq_not_found);
41414+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41415 if (f_ctl & FC_FC_END_SEQ) {
41416 /*
41417 * Update sequence_id based on incoming last
41418@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41419
41420 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41421 if (!ep) {
41422- atomic_inc(&mp->stats.xid_not_found);
41423+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41424 goto out;
41425 }
41426 if (ep->esb_stat & ESB_ST_COMPLETE) {
41427- atomic_inc(&mp->stats.xid_not_found);
41428+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41429 goto rel;
41430 }
41431 if (ep->rxid == FC_XID_UNKNOWN)
41432 ep->rxid = ntohs(fh->fh_rx_id);
41433 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41434- atomic_inc(&mp->stats.xid_not_found);
41435+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41436 goto rel;
41437 }
41438 if (ep->did != ntoh24(fh->fh_s_id) &&
41439 ep->did != FC_FID_FLOGI) {
41440- atomic_inc(&mp->stats.xid_not_found);
41441+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41442 goto rel;
41443 }
41444 sof = fr_sof(fp);
41445@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41446 sp->ssb_stat |= SSB_ST_RESP;
41447 sp->id = fh->fh_seq_id;
41448 } else if (sp->id != fh->fh_seq_id) {
41449- atomic_inc(&mp->stats.seq_not_found);
41450+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41451 goto rel;
41452 }
41453
41454@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41455 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41456
41457 if (!sp)
41458- atomic_inc(&mp->stats.xid_not_found);
41459+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41460 else
41461- atomic_inc(&mp->stats.non_bls_resp);
41462+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
41463
41464 fc_frame_free(fp);
41465 }
41466@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41467
41468 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41469 mp = ema->mp;
41470- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
41471+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
41472 st->fc_no_free_exch_xid +=
41473- atomic_read(&mp->stats.no_free_exch_xid);
41474- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
41475- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
41476- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
41477- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
41478+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
41479+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
41480+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
41481+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
41482+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
41483 }
41484 }
41485 EXPORT_SYMBOL(fc_exch_update_stats);
41486diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
41487index bdb81cd..d3c7c2c 100644
41488--- a/drivers/scsi/libsas/sas_ata.c
41489+++ b/drivers/scsi/libsas/sas_ata.c
41490@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
41491 .postreset = ata_std_postreset,
41492 .error_handler = ata_std_error_handler,
41493 .post_internal_cmd = sas_ata_post_internal,
41494- .qc_defer = ata_std_qc_defer,
41495+ .qc_defer = ata_std_qc_defer,
41496 .qc_prep = ata_noop_qc_prep,
41497 .qc_issue = sas_ata_qc_issue,
41498 .qc_fill_rtf = sas_ata_qc_fill_rtf,
41499diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
41500index df4c13a..a51e90c 100644
41501--- a/drivers/scsi/lpfc/lpfc.h
41502+++ b/drivers/scsi/lpfc/lpfc.h
41503@@ -424,7 +424,7 @@ struct lpfc_vport {
41504 struct dentry *debug_nodelist;
41505 struct dentry *vport_debugfs_root;
41506 struct lpfc_debugfs_trc *disc_trc;
41507- atomic_t disc_trc_cnt;
41508+ atomic_unchecked_t disc_trc_cnt;
41509 #endif
41510 uint8_t stat_data_enabled;
41511 uint8_t stat_data_blocked;
41512@@ -842,8 +842,8 @@ struct lpfc_hba {
41513 struct timer_list fabric_block_timer;
41514 unsigned long bit_flags;
41515 #define FABRIC_COMANDS_BLOCKED 0
41516- atomic_t num_rsrc_err;
41517- atomic_t num_cmd_success;
41518+ atomic_unchecked_t num_rsrc_err;
41519+ atomic_unchecked_t num_cmd_success;
41520 unsigned long last_rsrc_error_time;
41521 unsigned long last_ramp_down_time;
41522 unsigned long last_ramp_up_time;
41523@@ -879,7 +879,7 @@ struct lpfc_hba {
41524
41525 struct dentry *debug_slow_ring_trc;
41526 struct lpfc_debugfs_trc *slow_ring_trc;
41527- atomic_t slow_ring_trc_cnt;
41528+ atomic_unchecked_t slow_ring_trc_cnt;
41529 /* iDiag debugfs sub-directory */
41530 struct dentry *idiag_root;
41531 struct dentry *idiag_pci_cfg;
41532diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41533index f63f5ff..de29189 100644
41534--- a/drivers/scsi/lpfc/lpfc_debugfs.c
41535+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41536@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41537
41538 #include <linux/debugfs.h>
41539
41540-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41541+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41542 static unsigned long lpfc_debugfs_start_time = 0L;
41543
41544 /* iDiag */
41545@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41546 lpfc_debugfs_enable = 0;
41547
41548 len = 0;
41549- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41550+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41551 (lpfc_debugfs_max_disc_trc - 1);
41552 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41553 dtp = vport->disc_trc + i;
41554@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41555 lpfc_debugfs_enable = 0;
41556
41557 len = 0;
41558- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41559+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41560 (lpfc_debugfs_max_slow_ring_trc - 1);
41561 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41562 dtp = phba->slow_ring_trc + i;
41563@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41564 !vport || !vport->disc_trc)
41565 return;
41566
41567- index = atomic_inc_return(&vport->disc_trc_cnt) &
41568+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41569 (lpfc_debugfs_max_disc_trc - 1);
41570 dtp = vport->disc_trc + index;
41571 dtp->fmt = fmt;
41572 dtp->data1 = data1;
41573 dtp->data2 = data2;
41574 dtp->data3 = data3;
41575- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41576+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41577 dtp->jif = jiffies;
41578 #endif
41579 return;
41580@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41581 !phba || !phba->slow_ring_trc)
41582 return;
41583
41584- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41585+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41586 (lpfc_debugfs_max_slow_ring_trc - 1);
41587 dtp = phba->slow_ring_trc + index;
41588 dtp->fmt = fmt;
41589 dtp->data1 = data1;
41590 dtp->data2 = data2;
41591 dtp->data3 = data3;
41592- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41593+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41594 dtp->jif = jiffies;
41595 #endif
41596 return;
41597@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41598 "slow_ring buffer\n");
41599 goto debug_failed;
41600 }
41601- atomic_set(&phba->slow_ring_trc_cnt, 0);
41602+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41603 memset(phba->slow_ring_trc, 0,
41604 (sizeof(struct lpfc_debugfs_trc) *
41605 lpfc_debugfs_max_slow_ring_trc));
41606@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41607 "buffer\n");
41608 goto debug_failed;
41609 }
41610- atomic_set(&vport->disc_trc_cnt, 0);
41611+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41612
41613 snprintf(name, sizeof(name), "discovery_trace");
41614 vport->debug_disc_trc =
41615diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41616index 89ad558..76956c4 100644
41617--- a/drivers/scsi/lpfc/lpfc_init.c
41618+++ b/drivers/scsi/lpfc/lpfc_init.c
41619@@ -10618,8 +10618,10 @@ lpfc_init(void)
41620 "misc_register returned with status %d", error);
41621
41622 if (lpfc_enable_npiv) {
41623- lpfc_transport_functions.vport_create = lpfc_vport_create;
41624- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41625+ pax_open_kernel();
41626+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41627+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41628+ pax_close_kernel();
41629 }
41630 lpfc_transport_template =
41631 fc_attach_transport(&lpfc_transport_functions);
41632diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41633index 60e5a17..ff7a793 100644
41634--- a/drivers/scsi/lpfc/lpfc_scsi.c
41635+++ b/drivers/scsi/lpfc/lpfc_scsi.c
41636@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41637 uint32_t evt_posted;
41638
41639 spin_lock_irqsave(&phba->hbalock, flags);
41640- atomic_inc(&phba->num_rsrc_err);
41641+ atomic_inc_unchecked(&phba->num_rsrc_err);
41642 phba->last_rsrc_error_time = jiffies;
41643
41644 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41645@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41646 unsigned long flags;
41647 struct lpfc_hba *phba = vport->phba;
41648 uint32_t evt_posted;
41649- atomic_inc(&phba->num_cmd_success);
41650+ atomic_inc_unchecked(&phba->num_cmd_success);
41651
41652 if (vport->cfg_lun_queue_depth <= queue_depth)
41653 return;
41654@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41655 unsigned long num_rsrc_err, num_cmd_success;
41656 int i;
41657
41658- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41659- num_cmd_success = atomic_read(&phba->num_cmd_success);
41660+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41661+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41662
41663 /*
41664 * The error and success command counters are global per
41665@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41666 }
41667 }
41668 lpfc_destroy_vport_work_array(phba, vports);
41669- atomic_set(&phba->num_rsrc_err, 0);
41670- atomic_set(&phba->num_cmd_success, 0);
41671+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41672+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41673 }
41674
41675 /**
41676@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41677 }
41678 }
41679 lpfc_destroy_vport_work_array(phba, vports);
41680- atomic_set(&phba->num_rsrc_err, 0);
41681- atomic_set(&phba->num_cmd_success, 0);
41682+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41683+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41684 }
41685
41686 /**
41687diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41688index b46f5e9..c4c4ccb 100644
41689--- a/drivers/scsi/pmcraid.c
41690+++ b/drivers/scsi/pmcraid.c
41691@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41692 res->scsi_dev = scsi_dev;
41693 scsi_dev->hostdata = res;
41694 res->change_detected = 0;
41695- atomic_set(&res->read_failures, 0);
41696- atomic_set(&res->write_failures, 0);
41697+ atomic_set_unchecked(&res->read_failures, 0);
41698+ atomic_set_unchecked(&res->write_failures, 0);
41699 rc = 0;
41700 }
41701 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41702@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41703
41704 /* If this was a SCSI read/write command keep count of errors */
41705 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41706- atomic_inc(&res->read_failures);
41707+ atomic_inc_unchecked(&res->read_failures);
41708 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41709- atomic_inc(&res->write_failures);
41710+ atomic_inc_unchecked(&res->write_failures);
41711
41712 if (!RES_IS_GSCSI(res->cfg_entry) &&
41713 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41714@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41715 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41716 * hrrq_id assigned here in queuecommand
41717 */
41718- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41719+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41720 pinstance->num_hrrq;
41721 cmd->cmd_done = pmcraid_io_done;
41722
41723@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
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
41731 if (request_size) {
41732@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41733
41734 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41735 /* add resources only after host is added into system */
41736- if (!atomic_read(&pinstance->expose_resources))
41737+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41738 return;
41739
41740 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41741@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41742 init_waitqueue_head(&pinstance->reset_wait_q);
41743
41744 atomic_set(&pinstance->outstanding_cmds, 0);
41745- atomic_set(&pinstance->last_message_id, 0);
41746- atomic_set(&pinstance->expose_resources, 0);
41747+ atomic_set_unchecked(&pinstance->last_message_id, 0);
41748+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41749
41750 INIT_LIST_HEAD(&pinstance->free_res_q);
41751 INIT_LIST_HEAD(&pinstance->used_res_q);
41752@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41753 /* Schedule worker thread to handle CCN and take care of adding and
41754 * removing devices to OS
41755 */
41756- atomic_set(&pinstance->expose_resources, 1);
41757+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41758 schedule_work(&pinstance->worker_q);
41759 return rc;
41760
41761diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41762index e1d150f..6c6df44 100644
41763--- a/drivers/scsi/pmcraid.h
41764+++ b/drivers/scsi/pmcraid.h
41765@@ -748,7 +748,7 @@ struct pmcraid_instance {
41766 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41767
41768 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41769- atomic_t last_message_id;
41770+ atomic_unchecked_t last_message_id;
41771
41772 /* configuration table */
41773 struct pmcraid_config_table *cfg_table;
41774@@ -777,7 +777,7 @@ struct pmcraid_instance {
41775 atomic_t outstanding_cmds;
41776
41777 /* should add/delete resources to mid-layer now ?*/
41778- atomic_t expose_resources;
41779+ atomic_unchecked_t expose_resources;
41780
41781
41782
41783@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41784 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41785 };
41786 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41787- atomic_t read_failures; /* count of failed READ commands */
41788- atomic_t write_failures; /* count of failed WRITE commands */
41789+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41790+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41791
41792 /* To indicate add/delete/modify during CCN */
41793 u8 change_detected;
41794diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41795index 83d7984..a27d947 100644
41796--- a/drivers/scsi/qla2xxx/qla_attr.c
41797+++ b/drivers/scsi/qla2xxx/qla_attr.c
41798@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41799 return 0;
41800 }
41801
41802-struct fc_function_template qla2xxx_transport_functions = {
41803+fc_function_template_no_const qla2xxx_transport_functions = {
41804
41805 .show_host_node_name = 1,
41806 .show_host_port_name = 1,
41807@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41808 .bsg_timeout = qla24xx_bsg_timeout,
41809 };
41810
41811-struct fc_function_template qla2xxx_transport_vport_functions = {
41812+fc_function_template_no_const qla2xxx_transport_vport_functions = {
41813
41814 .show_host_node_name = 1,
41815 .show_host_port_name = 1,
41816diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41817index 2411d1a..4673766 100644
41818--- a/drivers/scsi/qla2xxx/qla_gbl.h
41819+++ b/drivers/scsi/qla2xxx/qla_gbl.h
41820@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41821 struct device_attribute;
41822 extern struct device_attribute *qla2x00_host_attrs[];
41823 struct fc_function_template;
41824-extern struct fc_function_template qla2xxx_transport_functions;
41825-extern struct fc_function_template qla2xxx_transport_vport_functions;
41826+extern fc_function_template_no_const qla2xxx_transport_functions;
41827+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41828 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41829 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41830 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41831diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41832index 10d23f8..a7d5d4c 100644
41833--- a/drivers/scsi/qla2xxx/qla_os.c
41834+++ b/drivers/scsi/qla2xxx/qla_os.c
41835@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41836 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41837 /* Ok, a 64bit DMA mask is applicable. */
41838 ha->flags.enable_64bit_addressing = 1;
41839- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41840- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41841+ pax_open_kernel();
41842+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41843+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41844+ pax_close_kernel();
41845 return;
41846 }
41847 }
41848diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41849index 329d553..f20d31d 100644
41850--- a/drivers/scsi/qla4xxx/ql4_def.h
41851+++ b/drivers/scsi/qla4xxx/ql4_def.h
41852@@ -273,7 +273,7 @@ struct ddb_entry {
41853 * (4000 only) */
41854 atomic_t relogin_timer; /* Max Time to wait for
41855 * relogin to complete */
41856- atomic_t relogin_retry_count; /* Num of times relogin has been
41857+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41858 * retried */
41859 uint32_t default_time2wait; /* Default Min time between
41860 * relogins (+aens) */
41861diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41862index 4cec123..7c1329f 100644
41863--- a/drivers/scsi/qla4xxx/ql4_os.c
41864+++ b/drivers/scsi/qla4xxx/ql4_os.c
41865@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41866 */
41867 if (!iscsi_is_session_online(cls_sess)) {
41868 /* Reset retry relogin timer */
41869- atomic_inc(&ddb_entry->relogin_retry_count);
41870+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41871 DEBUG2(ql4_printk(KERN_INFO, ha,
41872 "%s: index[%d] relogin timed out-retrying"
41873 " relogin (%d), retry (%d)\n", __func__,
41874 ddb_entry->fw_ddb_index,
41875- atomic_read(&ddb_entry->relogin_retry_count),
41876+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41877 ddb_entry->default_time2wait + 4));
41878 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41879 atomic_set(&ddb_entry->retry_relogin_timer,
41880@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41881
41882 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41883 atomic_set(&ddb_entry->relogin_timer, 0);
41884- atomic_set(&ddb_entry->relogin_retry_count, 0);
41885+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41886 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41887 ddb_entry->default_relogin_timeout =
41888 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41889diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41890index 2c0d0ec..4e8681a 100644
41891--- a/drivers/scsi/scsi.c
41892+++ b/drivers/scsi/scsi.c
41893@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41894 unsigned long timeout;
41895 int rtn = 0;
41896
41897- atomic_inc(&cmd->device->iorequest_cnt);
41898+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41899
41900 /* check if the device is still usable */
41901 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41902diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41903index f1bf5af..f67e943 100644
41904--- a/drivers/scsi/scsi_lib.c
41905+++ b/drivers/scsi/scsi_lib.c
41906@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41907 shost = sdev->host;
41908 scsi_init_cmd_errh(cmd);
41909 cmd->result = DID_NO_CONNECT << 16;
41910- atomic_inc(&cmd->device->iorequest_cnt);
41911+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41912
41913 /*
41914 * SCSI request completion path will do scsi_device_unbusy(),
41915@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41916
41917 INIT_LIST_HEAD(&cmd->eh_entry);
41918
41919- atomic_inc(&cmd->device->iodone_cnt);
41920+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41921 if (cmd->result)
41922- atomic_inc(&cmd->device->ioerr_cnt);
41923+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41924
41925 disposition = scsi_decide_disposition(cmd);
41926 if (disposition != SUCCESS &&
41927diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41928index 931a7d9..0c2a754 100644
41929--- a/drivers/scsi/scsi_sysfs.c
41930+++ b/drivers/scsi/scsi_sysfs.c
41931@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41932 char *buf) \
41933 { \
41934 struct scsi_device *sdev = to_scsi_device(dev); \
41935- unsigned long long count = atomic_read(&sdev->field); \
41936+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41937 return snprintf(buf, 20, "0x%llx\n", count); \
41938 } \
41939 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41940diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41941index 84a1fdf..693b0d6 100644
41942--- a/drivers/scsi/scsi_tgt_lib.c
41943+++ b/drivers/scsi/scsi_tgt_lib.c
41944@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41945 int err;
41946
41947 dprintk("%lx %u\n", uaddr, len);
41948- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41949+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41950 if (err) {
41951 /*
41952 * TODO: need to fixup sg_tablesize, max_segment_size,
41953diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41954index e894ca7..de9d7660 100644
41955--- a/drivers/scsi/scsi_transport_fc.c
41956+++ b/drivers/scsi/scsi_transport_fc.c
41957@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
41958 * Netlink Infrastructure
41959 */
41960
41961-static atomic_t fc_event_seq;
41962+static atomic_unchecked_t fc_event_seq;
41963
41964 /**
41965 * fc_get_event_number - Obtain the next sequential FC event number
41966@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
41967 u32
41968 fc_get_event_number(void)
41969 {
41970- return atomic_add_return(1, &fc_event_seq);
41971+ return atomic_add_return_unchecked(1, &fc_event_seq);
41972 }
41973 EXPORT_SYMBOL(fc_get_event_number);
41974
41975@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
41976 {
41977 int error;
41978
41979- atomic_set(&fc_event_seq, 0);
41980+ atomic_set_unchecked(&fc_event_seq, 0);
41981
41982 error = transport_class_register(&fc_host_class);
41983 if (error)
41984@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
41985 char *cp;
41986
41987 *val = simple_strtoul(buf, &cp, 0);
41988- if ((*cp && (*cp != '\n')) || (*val < 0))
41989+ if (*cp && (*cp != '\n'))
41990 return -EINVAL;
41991 /*
41992 * Check for overflow; dev_loss_tmo is u32
41993diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41994index 31969f2..2b348f0 100644
41995--- a/drivers/scsi/scsi_transport_iscsi.c
41996+++ b/drivers/scsi/scsi_transport_iscsi.c
41997@@ -79,7 +79,7 @@ struct iscsi_internal {
41998 struct transport_container session_cont;
41999 };
42000
42001-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42002+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42003 static struct workqueue_struct *iscsi_eh_timer_workq;
42004
42005 static DEFINE_IDA(iscsi_sess_ida);
42006@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42007 int err;
42008
42009 ihost = shost->shost_data;
42010- session->sid = atomic_add_return(1, &iscsi_session_nr);
42011+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42012
42013 if (target_id == ISCSI_MAX_TARGET) {
42014 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42015@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
42016 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42017 ISCSI_TRANSPORT_VERSION);
42018
42019- atomic_set(&iscsi_session_nr, 0);
42020+ atomic_set_unchecked(&iscsi_session_nr, 0);
42021
42022 err = class_register(&iscsi_transport_class);
42023 if (err)
42024diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42025index f379c7f..e8fc69c 100644
42026--- a/drivers/scsi/scsi_transport_srp.c
42027+++ b/drivers/scsi/scsi_transport_srp.c
42028@@ -33,7 +33,7 @@
42029 #include "scsi_transport_srp_internal.h"
42030
42031 struct srp_host_attrs {
42032- atomic_t next_port_id;
42033+ atomic_unchecked_t next_port_id;
42034 };
42035 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42036
42037@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42038 struct Scsi_Host *shost = dev_to_shost(dev);
42039 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42040
42041- atomic_set(&srp_host->next_port_id, 0);
42042+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42043 return 0;
42044 }
42045
42046@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42047 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42048 rport->roles = ids->roles;
42049
42050- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42051+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42052 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42053
42054 transport_setup_device(&rport->dev);
42055diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42056index 7992635..609faf8 100644
42057--- a/drivers/scsi/sd.c
42058+++ b/drivers/scsi/sd.c
42059@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
42060 sdkp->disk = gd;
42061 sdkp->index = index;
42062 atomic_set(&sdkp->openers, 0);
42063- atomic_set(&sdkp->device->ioerr_cnt, 0);
42064+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42065
42066 if (!sdp->request_queue->rq_timeout) {
42067 if (sdp->type != TYPE_MOD)
42068diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42069index be2c9a6..275525c 100644
42070--- a/drivers/scsi/sg.c
42071+++ b/drivers/scsi/sg.c
42072@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42073 sdp->disk->disk_name,
42074 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42075 NULL,
42076- (char *)arg);
42077+ (char __user *)arg);
42078 case BLKTRACESTART:
42079 return blk_trace_startstop(sdp->device->request_queue, 1);
42080 case BLKTRACESTOP:
42081diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42082index 19ee901..6e8c2ef 100644
42083--- a/drivers/spi/spi.c
42084+++ b/drivers/spi/spi.c
42085@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
42086 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42087
42088 /* portable code must never pass more than 32 bytes */
42089-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42090+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42091
42092 static u8 *buf;
42093
42094diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42095index c7a5f97..71ecd35 100644
42096--- a/drivers/staging/iio/iio_hwmon.c
42097+++ b/drivers/staging/iio/iio_hwmon.c
42098@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
42099 static int iio_hwmon_probe(struct platform_device *pdev)
42100 {
42101 struct iio_hwmon_state *st;
42102- struct sensor_device_attribute *a;
42103+ sensor_device_attribute_no_const *a;
42104 int ret, i;
42105 int in_i = 1, temp_i = 1, curr_i = 1;
42106 enum iio_chan_type type;
42107diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42108index 34afc16..ffe44dd 100644
42109--- a/drivers/staging/octeon/ethernet-rx.c
42110+++ b/drivers/staging/octeon/ethernet-rx.c
42111@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42112 /* Increment RX stats for virtual ports */
42113 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42114 #ifdef CONFIG_64BIT
42115- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42116- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42117+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42118+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42119 #else
42120- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42121- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42122+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42123+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42124 #endif
42125 }
42126 netif_receive_skb(skb);
42127@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42128 dev->name);
42129 */
42130 #ifdef CONFIG_64BIT
42131- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42132+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42133 #else
42134- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42135+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42136 #endif
42137 dev_kfree_skb_irq(skb);
42138 }
42139diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42140index ef32dc1..a159d68 100644
42141--- a/drivers/staging/octeon/ethernet.c
42142+++ b/drivers/staging/octeon/ethernet.c
42143@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42144 * since the RX tasklet also increments it.
42145 */
42146 #ifdef CONFIG_64BIT
42147- atomic64_add(rx_status.dropped_packets,
42148- (atomic64_t *)&priv->stats.rx_dropped);
42149+ atomic64_add_unchecked(rx_status.dropped_packets,
42150+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42151 #else
42152- atomic_add(rx_status.dropped_packets,
42153- (atomic_t *)&priv->stats.rx_dropped);
42154+ atomic_add_unchecked(rx_status.dropped_packets,
42155+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42156 #endif
42157 }
42158
42159diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42160index a2b7e03..aaf3630 100644
42161--- a/drivers/staging/ramster/tmem.c
42162+++ b/drivers/staging/ramster/tmem.c
42163@@ -50,25 +50,25 @@
42164 * A tmem host implementation must use this function to register callbacks
42165 * for memory allocation.
42166 */
42167-static struct tmem_hostops tmem_hostops;
42168+static struct tmem_hostops *tmem_hostops;
42169
42170 static void tmem_objnode_tree_init(void);
42171
42172 void tmem_register_hostops(struct tmem_hostops *m)
42173 {
42174 tmem_objnode_tree_init();
42175- tmem_hostops = *m;
42176+ tmem_hostops = m;
42177 }
42178
42179 /*
42180 * A tmem host implementation must use this function to register
42181 * callbacks for a page-accessible memory (PAM) implementation.
42182 */
42183-static struct tmem_pamops tmem_pamops;
42184+static struct tmem_pamops *tmem_pamops;
42185
42186 void tmem_register_pamops(struct tmem_pamops *m)
42187 {
42188- tmem_pamops = *m;
42189+ tmem_pamops = m;
42190 }
42191
42192 /*
42193@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42194 obj->pampd_count = 0;
42195 #ifdef CONFIG_RAMSTER
42196 if (tmem_pamops.new_obj != NULL)
42197- (*tmem_pamops.new_obj)(obj);
42198+ (tmem_pamops->new_obj)(obj);
42199 #endif
42200 SET_SENTINEL(obj, OBJ);
42201
42202@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42203 rbnode = rb_next(rbnode);
42204 tmem_pampd_destroy_all_in_obj(obj, true);
42205 tmem_obj_free(obj, hb);
42206- (*tmem_hostops.obj_free)(obj, pool);
42207+ (tmem_hostops->obj_free)(obj, pool);
42208 }
42209 spin_unlock(&hb->lock);
42210 }
42211@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
42212 ASSERT_SENTINEL(obj, OBJ);
42213 BUG_ON(obj->pool == NULL);
42214 ASSERT_SENTINEL(obj->pool, POOL);
42215- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
42216+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
42217 if (unlikely(objnode == NULL))
42218 goto out;
42219 objnode->obj = obj;
42220@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
42221 ASSERT_SENTINEL(pool, POOL);
42222 objnode->obj->objnode_count--;
42223 objnode->obj = NULL;
42224- (*tmem_hostops.objnode_free)(objnode, pool);
42225+ (tmem_hostops->objnode_free)(objnode, pool);
42226 }
42227
42228 /*
42229@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
42230 void *old_pampd = *(void **)slot;
42231 *(void **)slot = new_pampd;
42232 if (!no_free)
42233- (*tmem_pamops.free)(old_pampd, obj->pool,
42234+ (tmem_pamops->free)(old_pampd, obj->pool,
42235 NULL, 0, false);
42236 ret = new_pampd;
42237 }
42238@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
42239 if (objnode->slots[i]) {
42240 if (ht == 1) {
42241 obj->pampd_count--;
42242- (*tmem_pamops.free)(objnode->slots[i],
42243+ (tmem_pamops->free)(objnode->slots[i],
42244 obj->pool, NULL, 0, true);
42245 objnode->slots[i] = NULL;
42246 continue;
42247@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42248 return;
42249 if (obj->objnode_tree_height == 0) {
42250 obj->pampd_count--;
42251- (*tmem_pamops.free)(obj->objnode_tree_root,
42252+ (tmem_pamops->free)(obj->objnode_tree_root,
42253 obj->pool, NULL, 0, true);
42254 } else {
42255 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
42256@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42257 obj->objnode_tree_root = NULL;
42258 #ifdef CONFIG_RAMSTER
42259 if (tmem_pamops.free_obj != NULL)
42260- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
42261+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
42262 #endif
42263 }
42264
42265@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42266 /* if found, is a dup put, flush the old one */
42267 pampd_del = tmem_pampd_delete_from_obj(obj, index);
42268 BUG_ON(pampd_del != pampd);
42269- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42270+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42271 if (obj->pampd_count == 0) {
42272 objnew = obj;
42273 objfound = NULL;
42274@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42275 pampd = NULL;
42276 }
42277 } else {
42278- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
42279+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
42280 if (unlikely(obj == NULL)) {
42281 ret = -ENOMEM;
42282 goto out;
42283@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42284 if (unlikely(ret == -ENOMEM))
42285 /* may have partially built objnode tree ("stump") */
42286 goto delete_and_free;
42287- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
42288+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
42289 goto out;
42290
42291 delete_and_free:
42292 (void)tmem_pampd_delete_from_obj(obj, index);
42293 if (pampd)
42294- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
42295+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
42296 if (objnew) {
42297 tmem_obj_free(objnew, hb);
42298- (*tmem_hostops.obj_free)(objnew, pool);
42299+ (tmem_hostops->obj_free)(objnew, pool);
42300 }
42301 out:
42302 spin_unlock(&hb->lock);
42303@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
42304 if (pampd != NULL) {
42305 BUG_ON(obj == NULL);
42306 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
42307- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
42308+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
42309 } else if (delete) {
42310 BUG_ON(obj == NULL);
42311 (void)tmem_pampd_delete_from_obj(obj, index);
42312@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42313 int ret = 0;
42314
42315 if (!is_ephemeral(pool))
42316- new_pampd = (*tmem_pamops.repatriate_preload)(
42317+ new_pampd = (tmem_pamops->repatriate_preload)(
42318 old_pampd, pool, oidp, index, &intransit);
42319 if (intransit)
42320 ret = -EAGAIN;
42321@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42322 /* must release the hb->lock else repatriate can't sleep */
42323 spin_unlock(&hb->lock);
42324 if (!intransit)
42325- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
42326+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
42327 oidp, index, free, data);
42328 if (ret == -EAGAIN) {
42329 /* rare I think, but should cond_resched()??? */
42330@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
42331 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
42332 /* if we bug here, pamops wasn't properly set up for ramster */
42333 BUG_ON(tmem_pamops.replace_in_obj == NULL);
42334- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
42335+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
42336 out:
42337 spin_unlock(&hb->lock);
42338 return ret;
42339@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42340 if (free) {
42341 if (obj->pampd_count == 0) {
42342 tmem_obj_free(obj, hb);
42343- (*tmem_hostops.obj_free)(obj, pool);
42344+ (tmem_hostops->obj_free)(obj, pool);
42345 obj = NULL;
42346 }
42347 }
42348 if (free)
42349- ret = (*tmem_pamops.get_data_and_free)(
42350+ ret = (tmem_pamops->get_data_and_free)(
42351 data, sizep, raw, pampd, pool, oidp, index);
42352 else
42353- ret = (*tmem_pamops.get_data)(
42354+ ret = (tmem_pamops->get_data)(
42355 data, sizep, raw, pampd, pool, oidp, index);
42356 if (ret < 0)
42357 goto out;
42358@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
42359 pampd = tmem_pampd_delete_from_obj(obj, index);
42360 if (pampd == NULL)
42361 goto out;
42362- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42363+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42364 if (obj->pampd_count == 0) {
42365 tmem_obj_free(obj, hb);
42366- (*tmem_hostops.obj_free)(obj, pool);
42367+ (tmem_hostops->obj_free)(obj, pool);
42368 }
42369 ret = 0;
42370
42371@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
42372 goto out;
42373 tmem_pampd_destroy_all_in_obj(obj, false);
42374 tmem_obj_free(obj, hb);
42375- (*tmem_hostops.obj_free)(obj, pool);
42376+ (tmem_hostops->obj_free)(obj, pool);
42377 ret = 0;
42378
42379 out:
42380diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
42381index dc23395..cf7e9b1 100644
42382--- a/drivers/staging/rtl8712/rtl871x_io.h
42383+++ b/drivers/staging/rtl8712/rtl871x_io.h
42384@@ -108,7 +108,7 @@ struct _io_ops {
42385 u8 *pmem);
42386 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42387 u8 *pmem);
42388-};
42389+} __no_const;
42390
42391 struct io_req {
42392 struct list_head list;
42393diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42394index 1f5088b..0e59820 100644
42395--- a/drivers/staging/sbe-2t3e3/netdev.c
42396+++ b/drivers/staging/sbe-2t3e3/netdev.c
42397@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42398 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42399
42400 if (rlen)
42401- if (copy_to_user(data, &resp, rlen))
42402+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42403 return -EFAULT;
42404
42405 return 0;
42406diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42407index 5dddc4d..34fcb2f 100644
42408--- a/drivers/staging/usbip/vhci.h
42409+++ b/drivers/staging/usbip/vhci.h
42410@@ -83,7 +83,7 @@ struct vhci_hcd {
42411 unsigned resuming:1;
42412 unsigned long re_timeout;
42413
42414- atomic_t seqnum;
42415+ atomic_unchecked_t seqnum;
42416
42417 /*
42418 * NOTE:
42419diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42420index c3aa219..bf8b3de 100644
42421--- a/drivers/staging/usbip/vhci_hcd.c
42422+++ b/drivers/staging/usbip/vhci_hcd.c
42423@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
42424 return;
42425 }
42426
42427- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42428+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42429 if (priv->seqnum == 0xffff)
42430 dev_info(&urb->dev->dev, "seqnum max\n");
42431
42432@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42433 return -ENOMEM;
42434 }
42435
42436- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42437+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42438 if (unlink->seqnum == 0xffff)
42439 pr_info("seqnum max\n");
42440
42441@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
42442 vdev->rhport = rhport;
42443 }
42444
42445- atomic_set(&vhci->seqnum, 0);
42446+ atomic_set_unchecked(&vhci->seqnum, 0);
42447 spin_lock_init(&vhci->lock);
42448
42449 hcd->power_budget = 0; /* no limit */
42450diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42451index ba5f1c0..11d8122 100644
42452--- a/drivers/staging/usbip/vhci_rx.c
42453+++ b/drivers/staging/usbip/vhci_rx.c
42454@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42455 if (!urb) {
42456 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42457 pr_info("max seqnum %d\n",
42458- atomic_read(&the_controller->seqnum));
42459+ atomic_read_unchecked(&the_controller->seqnum));
42460 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42461 return;
42462 }
42463diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42464index 5f13890..36a044b 100644
42465--- a/drivers/staging/vt6655/hostap.c
42466+++ b/drivers/staging/vt6655/hostap.c
42467@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42468 *
42469 */
42470
42471+static net_device_ops_no_const apdev_netdev_ops;
42472+
42473 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42474 {
42475 PSDevice apdev_priv;
42476 struct net_device *dev = pDevice->dev;
42477 int ret;
42478- const struct net_device_ops apdev_netdev_ops = {
42479- .ndo_start_xmit = pDevice->tx_80211,
42480- };
42481
42482 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42483
42484@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42485 *apdev_priv = *pDevice;
42486 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42487
42488+ /* only half broken now */
42489+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42490 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42491
42492 pDevice->apdev->type = ARPHRD_IEEE80211;
42493diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42494index 26a7d0e..897b083 100644
42495--- a/drivers/staging/vt6656/hostap.c
42496+++ b/drivers/staging/vt6656/hostap.c
42497@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42498 *
42499 */
42500
42501+static net_device_ops_no_const apdev_netdev_ops;
42502+
42503 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42504 {
42505 PSDevice apdev_priv;
42506 struct net_device *dev = pDevice->dev;
42507 int ret;
42508- const struct net_device_ops apdev_netdev_ops = {
42509- .ndo_start_xmit = pDevice->tx_80211,
42510- };
42511
42512 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42513
42514@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42515 *apdev_priv = *pDevice;
42516 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42517
42518+ /* only half broken now */
42519+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42520 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42521
42522 pDevice->apdev->type = ARPHRD_IEEE80211;
42523diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42524index 56c8e60..1920c63 100644
42525--- a/drivers/staging/zcache/tmem.c
42526+++ b/drivers/staging/zcache/tmem.c
42527@@ -39,7 +39,7 @@
42528 * A tmem host implementation must use this function to register callbacks
42529 * for memory allocation.
42530 */
42531-static struct tmem_hostops tmem_hostops;
42532+static tmem_hostops_no_const tmem_hostops;
42533
42534 static void tmem_objnode_tree_init(void);
42535
42536@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42537 * A tmem host implementation must use this function to register
42538 * callbacks for a page-accessible memory (PAM) implementation
42539 */
42540-static struct tmem_pamops tmem_pamops;
42541+static tmem_pamops_no_const tmem_pamops;
42542
42543 void tmem_register_pamops(struct tmem_pamops *m)
42544 {
42545diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42546index 0d4aa82..f7832d4 100644
42547--- a/drivers/staging/zcache/tmem.h
42548+++ b/drivers/staging/zcache/tmem.h
42549@@ -180,6 +180,7 @@ struct tmem_pamops {
42550 void (*new_obj)(struct tmem_obj *);
42551 int (*replace_in_obj)(void *, struct tmem_obj *);
42552 };
42553+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42554 extern void tmem_register_pamops(struct tmem_pamops *m);
42555
42556 /* memory allocation methods provided by the host implementation */
42557@@ -189,6 +190,7 @@ struct tmem_hostops {
42558 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42559 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42560 };
42561+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42562 extern void tmem_register_hostops(struct tmem_hostops *m);
42563
42564 /* core tmem accessor functions */
42565diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42566index 96f4981..4daaa7e 100644
42567--- a/drivers/target/target_core_device.c
42568+++ b/drivers/target/target_core_device.c
42569@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42570 spin_lock_init(&dev->se_port_lock);
42571 spin_lock_init(&dev->se_tmr_lock);
42572 spin_lock_init(&dev->qf_cmd_lock);
42573- atomic_set(&dev->dev_ordered_id, 0);
42574+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
42575 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42576 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42577 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42578diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42579index bd587b7..173daf3 100644
42580--- a/drivers/target/target_core_transport.c
42581+++ b/drivers/target/target_core_transport.c
42582@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42583 * Used to determine when ORDERED commands should go from
42584 * Dormant to Active status.
42585 */
42586- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42587+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42588 smp_mb__after_atomic_inc();
42589 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42590 cmd->se_ordered_id, cmd->sam_task_attr,
42591diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42592index b09c8d1f..c4225c0 100644
42593--- a/drivers/tty/cyclades.c
42594+++ b/drivers/tty/cyclades.c
42595@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42596 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42597 info->port.count);
42598 #endif
42599- info->port.count++;
42600+ atomic_inc(&info->port.count);
42601 #ifdef CY_DEBUG_COUNT
42602 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42603- current->pid, info->port.count);
42604+ current->pid, atomic_read(&info->port.count));
42605 #endif
42606
42607 /*
42608@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42609 for (j = 0; j < cy_card[i].nports; j++) {
42610 info = &cy_card[i].ports[j];
42611
42612- if (info->port.count) {
42613+ if (atomic_read(&info->port.count)) {
42614 /* XXX is the ldisc num worth this? */
42615 struct tty_struct *tty;
42616 struct tty_ldisc *ld;
42617diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42618index 13ee53b..418d164 100644
42619--- a/drivers/tty/hvc/hvc_console.c
42620+++ b/drivers/tty/hvc/hvc_console.c
42621@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42622
42623 spin_lock_irqsave(&hp->port.lock, flags);
42624 /* Check and then increment for fast path open. */
42625- if (hp->port.count++ > 0) {
42626+ if (atomic_inc_return(&hp->port.count) > 1) {
42627 spin_unlock_irqrestore(&hp->port.lock, flags);
42628 hvc_kick();
42629 return 0;
42630@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42631
42632 spin_lock_irqsave(&hp->port.lock, flags);
42633
42634- if (--hp->port.count == 0) {
42635+ if (atomic_dec_return(&hp->port.count) == 0) {
42636 spin_unlock_irqrestore(&hp->port.lock, flags);
42637 /* We are done with the tty pointer now. */
42638 tty_port_tty_set(&hp->port, NULL);
42639@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42640 */
42641 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42642 } else {
42643- if (hp->port.count < 0)
42644+ if (atomic_read(&hp->port.count) < 0)
42645 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42646- hp->vtermno, hp->port.count);
42647+ hp->vtermno, atomic_read(&hp->port.count));
42648 spin_unlock_irqrestore(&hp->port.lock, flags);
42649 }
42650 }
42651@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42652 * open->hangup case this can be called after the final close so prevent
42653 * that from happening for now.
42654 */
42655- if (hp->port.count <= 0) {
42656+ if (atomic_read(&hp->port.count) <= 0) {
42657 spin_unlock_irqrestore(&hp->port.lock, flags);
42658 return;
42659 }
42660
42661- hp->port.count = 0;
42662+ atomic_set(&hp->port.count, 0);
42663 spin_unlock_irqrestore(&hp->port.lock, flags);
42664 tty_port_tty_set(&hp->port, NULL);
42665
42666@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42667 return -EPIPE;
42668
42669 /* FIXME what's this (unprotected) check for? */
42670- if (hp->port.count <= 0)
42671+ if (atomic_read(&hp->port.count) <= 0)
42672 return -EIO;
42673
42674 spin_lock_irqsave(&hp->lock, flags);
42675diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42676index 8776357..b2d4afd 100644
42677--- a/drivers/tty/hvc/hvcs.c
42678+++ b/drivers/tty/hvc/hvcs.c
42679@@ -83,6 +83,7 @@
42680 #include <asm/hvcserver.h>
42681 #include <asm/uaccess.h>
42682 #include <asm/vio.h>
42683+#include <asm/local.h>
42684
42685 /*
42686 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42687@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42688
42689 spin_lock_irqsave(&hvcsd->lock, flags);
42690
42691- if (hvcsd->port.count > 0) {
42692+ if (atomic_read(&hvcsd->port.count) > 0) {
42693 spin_unlock_irqrestore(&hvcsd->lock, flags);
42694 printk(KERN_INFO "HVCS: vterm state unchanged. "
42695 "The hvcs device node is still in use.\n");
42696@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42697 }
42698 }
42699
42700- hvcsd->port.count = 0;
42701+ atomic_set(&hvcsd->port.count, 0);
42702 hvcsd->port.tty = tty;
42703 tty->driver_data = hvcsd;
42704
42705@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42706 unsigned long flags;
42707
42708 spin_lock_irqsave(&hvcsd->lock, flags);
42709- hvcsd->port.count++;
42710+ atomic_inc(&hvcsd->port.count);
42711 hvcsd->todo_mask |= HVCS_SCHED_READ;
42712 spin_unlock_irqrestore(&hvcsd->lock, flags);
42713
42714@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42715 hvcsd = tty->driver_data;
42716
42717 spin_lock_irqsave(&hvcsd->lock, flags);
42718- if (--hvcsd->port.count == 0) {
42719+ if (atomic_dec_and_test(&hvcsd->port.count)) {
42720
42721 vio_disable_interrupts(hvcsd->vdev);
42722
42723@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42724
42725 free_irq(irq, hvcsd);
42726 return;
42727- } else if (hvcsd->port.count < 0) {
42728+ } else if (atomic_read(&hvcsd->port.count) < 0) {
42729 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42730 " is missmanaged.\n",
42731- hvcsd->vdev->unit_address, hvcsd->port.count);
42732+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42733 }
42734
42735 spin_unlock_irqrestore(&hvcsd->lock, flags);
42736@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42737
42738 spin_lock_irqsave(&hvcsd->lock, flags);
42739 /* Preserve this so that we know how many kref refs to put */
42740- temp_open_count = hvcsd->port.count;
42741+ temp_open_count = atomic_read(&hvcsd->port.count);
42742
42743 /*
42744 * Don't kref put inside the spinlock because the destruction
42745@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42746 tty->driver_data = NULL;
42747 hvcsd->port.tty = NULL;
42748
42749- hvcsd->port.count = 0;
42750+ atomic_set(&hvcsd->port.count, 0);
42751
42752 /* This will drop any buffered data on the floor which is OK in a hangup
42753 * scenario. */
42754@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42755 * the middle of a write operation? This is a crummy place to do this
42756 * but we want to keep it all in the spinlock.
42757 */
42758- if (hvcsd->port.count <= 0) {
42759+ if (atomic_read(&hvcsd->port.count) <= 0) {
42760 spin_unlock_irqrestore(&hvcsd->lock, flags);
42761 return -ENODEV;
42762 }
42763@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42764 {
42765 struct hvcs_struct *hvcsd = tty->driver_data;
42766
42767- if (!hvcsd || hvcsd->port.count <= 0)
42768+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42769 return 0;
42770
42771 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42772diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42773index 2cde13d..645d78f 100644
42774--- a/drivers/tty/ipwireless/tty.c
42775+++ b/drivers/tty/ipwireless/tty.c
42776@@ -29,6 +29,7 @@
42777 #include <linux/tty_driver.h>
42778 #include <linux/tty_flip.h>
42779 #include <linux/uaccess.h>
42780+#include <asm/local.h>
42781
42782 #include "tty.h"
42783 #include "network.h"
42784@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42785 mutex_unlock(&tty->ipw_tty_mutex);
42786 return -ENODEV;
42787 }
42788- if (tty->port.count == 0)
42789+ if (atomic_read(&tty->port.count) == 0)
42790 tty->tx_bytes_queued = 0;
42791
42792- tty->port.count++;
42793+ atomic_inc(&tty->port.count);
42794
42795 tty->port.tty = linux_tty;
42796 linux_tty->driver_data = tty;
42797@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42798
42799 static void do_ipw_close(struct ipw_tty *tty)
42800 {
42801- tty->port.count--;
42802-
42803- if (tty->port.count == 0) {
42804+ if (atomic_dec_return(&tty->port.count) == 0) {
42805 struct tty_struct *linux_tty = tty->port.tty;
42806
42807 if (linux_tty != NULL) {
42808@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42809 return;
42810
42811 mutex_lock(&tty->ipw_tty_mutex);
42812- if (tty->port.count == 0) {
42813+ if (atomic_read(&tty->port.count) == 0) {
42814 mutex_unlock(&tty->ipw_tty_mutex);
42815 return;
42816 }
42817@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42818 return;
42819 }
42820
42821- if (!tty->port.count) {
42822+ if (!atomic_read(&tty->port.count)) {
42823 mutex_unlock(&tty->ipw_tty_mutex);
42824 return;
42825 }
42826@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42827 return -ENODEV;
42828
42829 mutex_lock(&tty->ipw_tty_mutex);
42830- if (!tty->port.count) {
42831+ if (!atomic_read(&tty->port.count)) {
42832 mutex_unlock(&tty->ipw_tty_mutex);
42833 return -EINVAL;
42834 }
42835@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42836 if (!tty)
42837 return -ENODEV;
42838
42839- if (!tty->port.count)
42840+ if (!atomic_read(&tty->port.count))
42841 return -EINVAL;
42842
42843 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42844@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42845 if (!tty)
42846 return 0;
42847
42848- if (!tty->port.count)
42849+ if (!atomic_read(&tty->port.count))
42850 return 0;
42851
42852 return tty->tx_bytes_queued;
42853@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42854 if (!tty)
42855 return -ENODEV;
42856
42857- if (!tty->port.count)
42858+ if (!atomic_read(&tty->port.count))
42859 return -EINVAL;
42860
42861 return get_control_lines(tty);
42862@@ -391,7 +390,7 @@ ipw_tiocmset(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 set_control_lines(tty, set, clear);
42871@@ -405,7 +404,7 @@ static int ipw_ioctl(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 /* FIXME: Exactly how is the tty object locked here .. */
42880@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42881 * are gone */
42882 mutex_lock(&ttyj->ipw_tty_mutex);
42883 }
42884- while (ttyj->port.count)
42885+ while (atomic_read(&ttyj->port.count))
42886 do_ipw_close(ttyj);
42887 ipwireless_disassociate_network_ttys(network,
42888 ttyj->channel_idx);
42889diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42890index f9d2850..b006f04 100644
42891--- a/drivers/tty/moxa.c
42892+++ b/drivers/tty/moxa.c
42893@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42894 }
42895
42896 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42897- ch->port.count++;
42898+ atomic_inc(&ch->port.count);
42899 tty->driver_data = ch;
42900 tty_port_tty_set(&ch->port, tty);
42901 mutex_lock(&ch->port.mutex);
42902diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42903index bfd6771..e0d93c4 100644
42904--- a/drivers/tty/n_gsm.c
42905+++ b/drivers/tty/n_gsm.c
42906@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42907 spin_lock_init(&dlci->lock);
42908 mutex_init(&dlci->mutex);
42909 dlci->fifo = &dlci->_fifo;
42910- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42911+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42912 kfree(dlci);
42913 return NULL;
42914 }
42915@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42916 struct gsm_dlci *dlci = tty->driver_data;
42917 struct tty_port *port = &dlci->port;
42918
42919- port->count++;
42920+ atomic_inc(&port->count);
42921 dlci_get(dlci);
42922 dlci_get(dlci->gsm->dlci[0]);
42923 mux_get(dlci->gsm);
42924diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42925index 19083ef..6e34e97 100644
42926--- a/drivers/tty/n_tty.c
42927+++ b/drivers/tty/n_tty.c
42928@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42929 {
42930 *ops = tty_ldisc_N_TTY;
42931 ops->owner = NULL;
42932- ops->refcount = ops->flags = 0;
42933+ atomic_set(&ops->refcount, 0);
42934+ ops->flags = 0;
42935 }
42936 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42937diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42938index ac35c90..c47deac 100644
42939--- a/drivers/tty/pty.c
42940+++ b/drivers/tty/pty.c
42941@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
42942 panic("Couldn't register Unix98 pts driver");
42943
42944 /* Now create the /dev/ptmx special device */
42945+ pax_open_kernel();
42946 tty_default_fops(&ptmx_fops);
42947- ptmx_fops.open = ptmx_open;
42948+ *(void **)&ptmx_fops.open = ptmx_open;
42949+ pax_close_kernel();
42950
42951 cdev_init(&ptmx_cdev, &ptmx_fops);
42952 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
42953diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
42954index e42009a..566a036 100644
42955--- a/drivers/tty/rocket.c
42956+++ b/drivers/tty/rocket.c
42957@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42958 tty->driver_data = info;
42959 tty_port_tty_set(port, tty);
42960
42961- if (port->count++ == 0) {
42962+ if (atomic_inc_return(&port->count) == 1) {
42963 atomic_inc(&rp_num_ports_open);
42964
42965 #ifdef ROCKET_DEBUG_OPEN
42966@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42967 #endif
42968 }
42969 #ifdef ROCKET_DEBUG_OPEN
42970- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
42971+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
42972 #endif
42973
42974 /*
42975@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
42976 spin_unlock_irqrestore(&info->port.lock, flags);
42977 return;
42978 }
42979- if (info->port.count)
42980+ if (atomic_read(&info->port.count))
42981 atomic_dec(&rp_num_ports_open);
42982 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
42983 spin_unlock_irqrestore(&info->port.lock, flags);
42984diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
42985index 1002054..dd644a8 100644
42986--- a/drivers/tty/serial/kgdboc.c
42987+++ b/drivers/tty/serial/kgdboc.c
42988@@ -24,8 +24,9 @@
42989 #define MAX_CONFIG_LEN 40
42990
42991 static struct kgdb_io kgdboc_io_ops;
42992+static struct kgdb_io kgdboc_io_ops_console;
42993
42994-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
42995+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
42996 static int configured = -1;
42997
42998 static char config[MAX_CONFIG_LEN];
42999@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43000 kgdboc_unregister_kbd();
43001 if (configured == 1)
43002 kgdb_unregister_io_module(&kgdboc_io_ops);
43003+ else if (configured == 2)
43004+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43005 }
43006
43007 static int configure_kgdboc(void)
43008@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43009 int err;
43010 char *cptr = config;
43011 struct console *cons;
43012+ int is_console = 0;
43013
43014 err = kgdboc_option_setup(config);
43015 if (err || !strlen(config) || isspace(config[0]))
43016 goto noconfig;
43017
43018 err = -ENODEV;
43019- kgdboc_io_ops.is_console = 0;
43020 kgdb_tty_driver = NULL;
43021
43022 kgdboc_use_kms = 0;
43023@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43024 int idx;
43025 if (cons->device && cons->device(cons, &idx) == p &&
43026 idx == tty_line) {
43027- kgdboc_io_ops.is_console = 1;
43028+ is_console = 1;
43029 break;
43030 }
43031 cons = cons->next;
43032@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43033 kgdb_tty_line = tty_line;
43034
43035 do_register:
43036- err = kgdb_register_io_module(&kgdboc_io_ops);
43037+ if (is_console) {
43038+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43039+ configured = 2;
43040+ } else {
43041+ err = kgdb_register_io_module(&kgdboc_io_ops);
43042+ configured = 1;
43043+ }
43044 if (err)
43045 goto noconfig;
43046
43047@@ -205,8 +214,6 @@ do_register:
43048 if (err)
43049 goto nmi_con_failed;
43050
43051- configured = 1;
43052-
43053 return 0;
43054
43055 nmi_con_failed:
43056@@ -223,7 +230,7 @@ noconfig:
43057 static int __init init_kgdboc(void)
43058 {
43059 /* Already configured? */
43060- if (configured == 1)
43061+ if (configured >= 1)
43062 return 0;
43063
43064 return configure_kgdboc();
43065@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43066 if (config[len - 1] == '\n')
43067 config[len - 1] = '\0';
43068
43069- if (configured == 1)
43070+ if (configured >= 1)
43071 cleanup_kgdboc();
43072
43073 /* Go and configure with the new params. */
43074@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43075 .post_exception = kgdboc_post_exp_handler,
43076 };
43077
43078+static struct kgdb_io kgdboc_io_ops_console = {
43079+ .name = "kgdboc",
43080+ .read_char = kgdboc_get_char,
43081+ .write_char = kgdboc_put_char,
43082+ .pre_exception = kgdboc_pre_exp_handler,
43083+ .post_exception = kgdboc_post_exp_handler,
43084+ .is_console = 1
43085+};
43086+
43087 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43088 /* This is only available if kgdboc is a built in for early debugging */
43089 static int __init kgdboc_early_init(char *opt)
43090diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43091index e514b3a..c73d614 100644
43092--- a/drivers/tty/serial/samsung.c
43093+++ b/drivers/tty/serial/samsung.c
43094@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43095 }
43096 }
43097
43098+static int s3c64xx_serial_startup(struct uart_port *port);
43099 static int s3c24xx_serial_startup(struct uart_port *port)
43100 {
43101 struct s3c24xx_uart_port *ourport = to_ourport(port);
43102 int ret;
43103
43104+ /* Startup sequence is different for s3c64xx and higher SoC's */
43105+ if (s3c24xx_serial_has_interrupt_mask(port))
43106+ return s3c64xx_serial_startup(port);
43107+
43108 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43109 port->mapbase, port->membase);
43110
43111@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43112 /* setup info for port */
43113 port->dev = &platdev->dev;
43114
43115- /* Startup sequence is different for s3c64xx and higher SoC's */
43116- if (s3c24xx_serial_has_interrupt_mask(port))
43117- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43118-
43119 port->uartclk = 1;
43120
43121 if (cfg->uart_flags & UPF_CONS_FLOW) {
43122diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43123index 2c7230a..2104f16 100644
43124--- a/drivers/tty/serial/serial_core.c
43125+++ b/drivers/tty/serial/serial_core.c
43126@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
43127 uart_flush_buffer(tty);
43128 uart_shutdown(tty, state);
43129 spin_lock_irqsave(&port->lock, flags);
43130- port->count = 0;
43131+ atomic_set(&port->count, 0);
43132 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43133 spin_unlock_irqrestore(&port->lock, flags);
43134 tty_port_tty_set(port, NULL);
43135@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43136 goto end;
43137 }
43138
43139- port->count++;
43140+ atomic_inc(&port->count);
43141 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43142 retval = -ENXIO;
43143 goto err_dec_count;
43144@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43145 /*
43146 * Make sure the device is in D0 state.
43147 */
43148- if (port->count == 1)
43149+ if (atomic_read(&port->count) == 1)
43150 uart_change_pm(state, 0);
43151
43152 /*
43153@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43154 end:
43155 return retval;
43156 err_dec_count:
43157- port->count--;
43158+ atomic_inc(&port->count);
43159 mutex_unlock(&port->mutex);
43160 goto end;
43161 }
43162diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43163index 9e071f6..f30ae69 100644
43164--- a/drivers/tty/synclink.c
43165+++ b/drivers/tty/synclink.c
43166@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43167
43168 if (debug_level >= DEBUG_LEVEL_INFO)
43169 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43170- __FILE__,__LINE__, info->device_name, info->port.count);
43171+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43172
43173 if (tty_port_close_start(&info->port, tty, filp) == 0)
43174 goto cleanup;
43175@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43176 cleanup:
43177 if (debug_level >= DEBUG_LEVEL_INFO)
43178 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43179- tty->driver->name, info->port.count);
43180+ tty->driver->name, atomic_read(&info->port.count));
43181
43182 } /* end of mgsl_close() */
43183
43184@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43185
43186 mgsl_flush_buffer(tty);
43187 shutdown(info);
43188-
43189- info->port.count = 0;
43190+
43191+ atomic_set(&info->port.count, 0);
43192 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43193 info->port.tty = NULL;
43194
43195@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43196
43197 if (debug_level >= DEBUG_LEVEL_INFO)
43198 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43199- __FILE__,__LINE__, tty->driver->name, port->count );
43200+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43201
43202 spin_lock_irqsave(&info->irq_spinlock, flags);
43203 if (!tty_hung_up_p(filp)) {
43204 extra_count = true;
43205- port->count--;
43206+ atomic_dec(&port->count);
43207 }
43208 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43209 port->blocked_open++;
43210@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43211
43212 if (debug_level >= DEBUG_LEVEL_INFO)
43213 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43214- __FILE__,__LINE__, tty->driver->name, port->count );
43215+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43216
43217 tty_unlock(tty);
43218 schedule();
43219@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43220
43221 /* FIXME: Racy on hangup during close wait */
43222 if (extra_count)
43223- port->count++;
43224+ atomic_inc(&port->count);
43225 port->blocked_open--;
43226
43227 if (debug_level >= DEBUG_LEVEL_INFO)
43228 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43229- __FILE__,__LINE__, tty->driver->name, port->count );
43230+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43231
43232 if (!retval)
43233 port->flags |= ASYNC_NORMAL_ACTIVE;
43234@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43235
43236 if (debug_level >= DEBUG_LEVEL_INFO)
43237 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43238- __FILE__,__LINE__,tty->driver->name, info->port.count);
43239+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43240
43241 /* If port is closing, signal caller to try again */
43242 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43243@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43244 spin_unlock_irqrestore(&info->netlock, flags);
43245 goto cleanup;
43246 }
43247- info->port.count++;
43248+ atomic_inc(&info->port.count);
43249 spin_unlock_irqrestore(&info->netlock, flags);
43250
43251- if (info->port.count == 1) {
43252+ if (atomic_read(&info->port.count) == 1) {
43253 /* 1st open on this device, init hardware */
43254 retval = startup(info);
43255 if (retval < 0)
43256@@ -3451,8 +3451,8 @@ cleanup:
43257 if (retval) {
43258 if (tty->count == 1)
43259 info->port.tty = NULL; /* tty layer will release tty struct */
43260- if(info->port.count)
43261- info->port.count--;
43262+ if (atomic_read(&info->port.count))
43263+ atomic_dec(&info->port.count);
43264 }
43265
43266 return retval;
43267@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43268 unsigned short new_crctype;
43269
43270 /* return error if TTY interface open */
43271- if (info->port.count)
43272+ if (atomic_read(&info->port.count))
43273 return -EBUSY;
43274
43275 switch (encoding)
43276@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
43277
43278 /* arbitrate between network and tty opens */
43279 spin_lock_irqsave(&info->netlock, flags);
43280- if (info->port.count != 0 || info->netcount != 0) {
43281+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43282 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43283 spin_unlock_irqrestore(&info->netlock, flags);
43284 return -EBUSY;
43285@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43286 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43287
43288 /* return error if TTY interface open */
43289- if (info->port.count)
43290+ if (atomic_read(&info->port.count))
43291 return -EBUSY;
43292
43293 if (cmd != SIOCWANDEV)
43294diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43295index aba1e59..877ac33 100644
43296--- a/drivers/tty/synclink_gt.c
43297+++ b/drivers/tty/synclink_gt.c
43298@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43299 tty->driver_data = info;
43300 info->port.tty = tty;
43301
43302- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43303+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43304
43305 /* If port is closing, signal caller to try again */
43306 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43307@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43308 mutex_unlock(&info->port.mutex);
43309 goto cleanup;
43310 }
43311- info->port.count++;
43312+ atomic_inc(&info->port.count);
43313 spin_unlock_irqrestore(&info->netlock, flags);
43314
43315- if (info->port.count == 1) {
43316+ if (atomic_read(&info->port.count) == 1) {
43317 /* 1st open on this device, init hardware */
43318 retval = startup(info);
43319 if (retval < 0) {
43320@@ -716,8 +716,8 @@ cleanup:
43321 if (retval) {
43322 if (tty->count == 1)
43323 info->port.tty = NULL; /* tty layer will release tty struct */
43324- if(info->port.count)
43325- info->port.count--;
43326+ if(atomic_read(&info->port.count))
43327+ atomic_dec(&info->port.count);
43328 }
43329
43330 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43331@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43332
43333 if (sanity_check(info, tty->name, "close"))
43334 return;
43335- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43336+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43337
43338 if (tty_port_close_start(&info->port, tty, filp) == 0)
43339 goto cleanup;
43340@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43341 tty_port_close_end(&info->port, tty);
43342 info->port.tty = NULL;
43343 cleanup:
43344- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
43345+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
43346 }
43347
43348 static void hangup(struct tty_struct *tty)
43349@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
43350 shutdown(info);
43351
43352 spin_lock_irqsave(&info->port.lock, flags);
43353- info->port.count = 0;
43354+ atomic_set(&info->port.count, 0);
43355 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43356 info->port.tty = NULL;
43357 spin_unlock_irqrestore(&info->port.lock, flags);
43358@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43359 unsigned short new_crctype;
43360
43361 /* return error if TTY interface open */
43362- if (info->port.count)
43363+ if (atomic_read(&info->port.count))
43364 return -EBUSY;
43365
43366 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
43367@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
43368
43369 /* arbitrate between network and tty opens */
43370 spin_lock_irqsave(&info->netlock, flags);
43371- if (info->port.count != 0 || info->netcount != 0) {
43372+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43373 DBGINFO(("%s hdlc_open busy\n", dev->name));
43374 spin_unlock_irqrestore(&info->netlock, flags);
43375 return -EBUSY;
43376@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43377 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
43378
43379 /* return error if TTY interface open */
43380- if (info->port.count)
43381+ if (atomic_read(&info->port.count))
43382 return -EBUSY;
43383
43384 if (cmd != SIOCWANDEV)
43385@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43386 if (port == NULL)
43387 continue;
43388 spin_lock(&port->lock);
43389- if ((port->port.count || port->netcount) &&
43390+ if ((atomic_read(&port->port.count) || port->netcount) &&
43391 port->pending_bh && !port->bh_running &&
43392 !port->bh_requested) {
43393 DBGISR(("%s bh queued\n", port->device_name));
43394@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43395 spin_lock_irqsave(&info->lock, flags);
43396 if (!tty_hung_up_p(filp)) {
43397 extra_count = true;
43398- port->count--;
43399+ atomic_dec(&port->count);
43400 }
43401 spin_unlock_irqrestore(&info->lock, flags);
43402 port->blocked_open++;
43403@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43404 remove_wait_queue(&port->open_wait, &wait);
43405
43406 if (extra_count)
43407- port->count++;
43408+ atomic_inc(&port->count);
43409 port->blocked_open--;
43410
43411 if (!retval)
43412diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43413index fd43fb6..34704ad 100644
43414--- a/drivers/tty/synclinkmp.c
43415+++ b/drivers/tty/synclinkmp.c
43416@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43417
43418 if (debug_level >= DEBUG_LEVEL_INFO)
43419 printk("%s(%d):%s open(), old ref count = %d\n",
43420- __FILE__,__LINE__,tty->driver->name, info->port.count);
43421+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43422
43423 /* If port is closing, signal caller to try again */
43424 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43425@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43426 spin_unlock_irqrestore(&info->netlock, flags);
43427 goto cleanup;
43428 }
43429- info->port.count++;
43430+ atomic_inc(&info->port.count);
43431 spin_unlock_irqrestore(&info->netlock, flags);
43432
43433- if (info->port.count == 1) {
43434+ if (atomic_read(&info->port.count) == 1) {
43435 /* 1st open on this device, init hardware */
43436 retval = startup(info);
43437 if (retval < 0)
43438@@ -797,8 +797,8 @@ cleanup:
43439 if (retval) {
43440 if (tty->count == 1)
43441 info->port.tty = NULL; /* tty layer will release tty struct */
43442- if(info->port.count)
43443- info->port.count--;
43444+ if(atomic_read(&info->port.count))
43445+ atomic_dec(&info->port.count);
43446 }
43447
43448 return retval;
43449@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43450
43451 if (debug_level >= DEBUG_LEVEL_INFO)
43452 printk("%s(%d):%s close() entry, count=%d\n",
43453- __FILE__,__LINE__, info->device_name, info->port.count);
43454+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43455
43456 if (tty_port_close_start(&info->port, tty, filp) == 0)
43457 goto cleanup;
43458@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43459 cleanup:
43460 if (debug_level >= DEBUG_LEVEL_INFO)
43461 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43462- tty->driver->name, info->port.count);
43463+ tty->driver->name, atomic_read(&info->port.count));
43464 }
43465
43466 /* Called by tty_hangup() when a hangup is signaled.
43467@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
43468 shutdown(info);
43469
43470 spin_lock_irqsave(&info->port.lock, flags);
43471- info->port.count = 0;
43472+ atomic_set(&info->port.count, 0);
43473 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43474 info->port.tty = NULL;
43475 spin_unlock_irqrestore(&info->port.lock, flags);
43476@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43477 unsigned short new_crctype;
43478
43479 /* return error if TTY interface open */
43480- if (info->port.count)
43481+ if (atomic_read(&info->port.count))
43482 return -EBUSY;
43483
43484 switch (encoding)
43485@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
43486
43487 /* arbitrate between network and tty opens */
43488 spin_lock_irqsave(&info->netlock, flags);
43489- if (info->port.count != 0 || info->netcount != 0) {
43490+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43491 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43492 spin_unlock_irqrestore(&info->netlock, flags);
43493 return -EBUSY;
43494@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43495 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43496
43497 /* return error if TTY interface open */
43498- if (info->port.count)
43499+ if (atomic_read(&info->port.count))
43500 return -EBUSY;
43501
43502 if (cmd != SIOCWANDEV)
43503@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43504 * do not request bottom half processing if the
43505 * device is not open in a normal mode.
43506 */
43507- if ( port && (port->port.count || port->netcount) &&
43508+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43509 port->pending_bh && !port->bh_running &&
43510 !port->bh_requested ) {
43511 if ( debug_level >= DEBUG_LEVEL_ISR )
43512@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43513
43514 if (debug_level >= DEBUG_LEVEL_INFO)
43515 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43516- __FILE__,__LINE__, tty->driver->name, port->count );
43517+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43518
43519 spin_lock_irqsave(&info->lock, flags);
43520 if (!tty_hung_up_p(filp)) {
43521 extra_count = true;
43522- port->count--;
43523+ atomic_dec(&port->count);
43524 }
43525 spin_unlock_irqrestore(&info->lock, flags);
43526 port->blocked_open++;
43527@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43528
43529 if (debug_level >= DEBUG_LEVEL_INFO)
43530 printk("%s(%d):%s block_til_ready() count=%d\n",
43531- __FILE__,__LINE__, tty->driver->name, port->count );
43532+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43533
43534 tty_unlock(tty);
43535 schedule();
43536@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43537 remove_wait_queue(&port->open_wait, &wait);
43538
43539 if (extra_count)
43540- port->count++;
43541+ atomic_inc(&port->count);
43542 port->blocked_open--;
43543
43544 if (debug_level >= DEBUG_LEVEL_INFO)
43545 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43546- __FILE__,__LINE__, tty->driver->name, port->count );
43547+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43548
43549 if (!retval)
43550 port->flags |= ASYNC_NORMAL_ACTIVE;
43551diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43552index b3c4a25..723916f 100644
43553--- a/drivers/tty/sysrq.c
43554+++ b/drivers/tty/sysrq.c
43555@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43556 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43557 size_t count, loff_t *ppos)
43558 {
43559- if (count) {
43560+ if (count && capable(CAP_SYS_ADMIN)) {
43561 char c;
43562
43563 if (get_user(c, buf))
43564diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43565index da9fde8..c07975f 100644
43566--- a/drivers/tty/tty_io.c
43567+++ b/drivers/tty/tty_io.c
43568@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43569
43570 void tty_default_fops(struct file_operations *fops)
43571 {
43572- *fops = tty_fops;
43573+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43574 }
43575
43576 /*
43577diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43578index c578229..45aa9ee 100644
43579--- a/drivers/tty/tty_ldisc.c
43580+++ b/drivers/tty/tty_ldisc.c
43581@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43582 if (atomic_dec_and_test(&ld->users)) {
43583 struct tty_ldisc_ops *ldo = ld->ops;
43584
43585- ldo->refcount--;
43586+ atomic_dec(&ldo->refcount);
43587 module_put(ldo->owner);
43588 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43589
43590@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43591 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43592 tty_ldiscs[disc] = new_ldisc;
43593 new_ldisc->num = disc;
43594- new_ldisc->refcount = 0;
43595+ atomic_set(&new_ldisc->refcount, 0);
43596 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43597
43598 return ret;
43599@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43600 return -EINVAL;
43601
43602 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43603- if (tty_ldiscs[disc]->refcount)
43604+ if (atomic_read(&tty_ldiscs[disc]->refcount))
43605 ret = -EBUSY;
43606 else
43607 tty_ldiscs[disc] = NULL;
43608@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43609 if (ldops) {
43610 ret = ERR_PTR(-EAGAIN);
43611 if (try_module_get(ldops->owner)) {
43612- ldops->refcount++;
43613+ atomic_inc(&ldops->refcount);
43614 ret = ldops;
43615 }
43616 }
43617@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43618 unsigned long flags;
43619
43620 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43621- ldops->refcount--;
43622+ atomic_dec(&ldops->refcount);
43623 module_put(ldops->owner);
43624 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43625 }
43626diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43627index b7ff59d..7c6105e 100644
43628--- a/drivers/tty/tty_port.c
43629+++ b/drivers/tty/tty_port.c
43630@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43631 unsigned long flags;
43632
43633 spin_lock_irqsave(&port->lock, flags);
43634- port->count = 0;
43635+ atomic_set(&port->count, 0);
43636 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43637 if (port->tty) {
43638 set_bit(TTY_IO_ERROR, &port->tty->flags);
43639@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43640 /* The port lock protects the port counts */
43641 spin_lock_irqsave(&port->lock, flags);
43642 if (!tty_hung_up_p(filp))
43643- port->count--;
43644+ atomic_dec(&port->count);
43645 port->blocked_open++;
43646 spin_unlock_irqrestore(&port->lock, flags);
43647
43648@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43649 we must not mess that up further */
43650 spin_lock_irqsave(&port->lock, flags);
43651 if (!tty_hung_up_p(filp))
43652- port->count++;
43653+ atomic_inc(&port->count);
43654 port->blocked_open--;
43655 if (retval == 0)
43656 port->flags |= ASYNC_NORMAL_ACTIVE;
43657@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43658 return 0;
43659 }
43660
43661- if (tty->count == 1 && port->count != 1) {
43662+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
43663 printk(KERN_WARNING
43664 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43665- port->count);
43666- port->count = 1;
43667+ atomic_read(&port->count));
43668+ atomic_set(&port->count, 1);
43669 }
43670- if (--port->count < 0) {
43671+ if (atomic_dec_return(&port->count) < 0) {
43672 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43673- port->count);
43674- port->count = 0;
43675+ atomic_read(&port->count));
43676+ atomic_set(&port->count, 0);
43677 }
43678
43679- if (port->count) {
43680+ if (atomic_read(&port->count)) {
43681 spin_unlock_irqrestore(&port->lock, flags);
43682 if (port->ops->drop)
43683 port->ops->drop(port);
43684@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43685 {
43686 spin_lock_irq(&port->lock);
43687 if (!tty_hung_up_p(filp))
43688- ++port->count;
43689+ atomic_inc(&port->count);
43690 spin_unlock_irq(&port->lock);
43691 tty_port_tty_set(port, tty);
43692
43693diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43694index 681765b..d3ccdf2 100644
43695--- a/drivers/tty/vt/keyboard.c
43696+++ b/drivers/tty/vt/keyboard.c
43697@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43698 kbd->kbdmode == VC_OFF) &&
43699 value != KVAL(K_SAK))
43700 return; /* SAK is allowed even in raw mode */
43701+
43702+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43703+ {
43704+ void *func = fn_handler[value];
43705+ if (func == fn_show_state || func == fn_show_ptregs ||
43706+ func == fn_show_mem)
43707+ return;
43708+ }
43709+#endif
43710+
43711 fn_handler[value](vc);
43712 }
43713
43714@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43715 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43716 return -EFAULT;
43717
43718- if (!capable(CAP_SYS_TTY_CONFIG))
43719- perm = 0;
43720-
43721 switch (cmd) {
43722 case KDGKBENT:
43723 /* Ensure another thread doesn't free it under us */
43724@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43725 spin_unlock_irqrestore(&kbd_event_lock, flags);
43726 return put_user(val, &user_kbe->kb_value);
43727 case KDSKBENT:
43728+ if (!capable(CAP_SYS_TTY_CONFIG))
43729+ perm = 0;
43730+
43731 if (!perm)
43732 return -EPERM;
43733 if (!i && v == K_NOSUCHMAP) {
43734@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43735 int i, j, k;
43736 int ret;
43737
43738- if (!capable(CAP_SYS_TTY_CONFIG))
43739- perm = 0;
43740-
43741 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43742 if (!kbs) {
43743 ret = -ENOMEM;
43744@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43745 kfree(kbs);
43746 return ((p && *p) ? -EOVERFLOW : 0);
43747 case KDSKBSENT:
43748+ if (!capable(CAP_SYS_TTY_CONFIG))
43749+ perm = 0;
43750+
43751 if (!perm) {
43752 ret = -EPERM;
43753 goto reterr;
43754diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43755index 5110f36..8dc0a74 100644
43756--- a/drivers/uio/uio.c
43757+++ b/drivers/uio/uio.c
43758@@ -25,6 +25,7 @@
43759 #include <linux/kobject.h>
43760 #include <linux/cdev.h>
43761 #include <linux/uio_driver.h>
43762+#include <asm/local.h>
43763
43764 #define UIO_MAX_DEVICES (1U << MINORBITS)
43765
43766@@ -32,10 +33,10 @@ struct uio_device {
43767 struct module *owner;
43768 struct device *dev;
43769 int minor;
43770- atomic_t event;
43771+ atomic_unchecked_t event;
43772 struct fasync_struct *async_queue;
43773 wait_queue_head_t wait;
43774- int vma_count;
43775+ local_t vma_count;
43776 struct uio_info *info;
43777 struct kobject *map_dir;
43778 struct kobject *portio_dir;
43779@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43780 struct device_attribute *attr, char *buf)
43781 {
43782 struct uio_device *idev = dev_get_drvdata(dev);
43783- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43784+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43785 }
43786
43787 static struct device_attribute uio_class_attributes[] = {
43788@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43789 {
43790 struct uio_device *idev = info->uio_dev;
43791
43792- atomic_inc(&idev->event);
43793+ atomic_inc_unchecked(&idev->event);
43794 wake_up_interruptible(&idev->wait);
43795 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43796 }
43797@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43798 }
43799
43800 listener->dev = idev;
43801- listener->event_count = atomic_read(&idev->event);
43802+ listener->event_count = atomic_read_unchecked(&idev->event);
43803 filep->private_data = listener;
43804
43805 if (idev->info->open) {
43806@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43807 return -EIO;
43808
43809 poll_wait(filep, &idev->wait, wait);
43810- if (listener->event_count != atomic_read(&idev->event))
43811+ if (listener->event_count != atomic_read_unchecked(&idev->event))
43812 return POLLIN | POLLRDNORM;
43813 return 0;
43814 }
43815@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43816 do {
43817 set_current_state(TASK_INTERRUPTIBLE);
43818
43819- event_count = atomic_read(&idev->event);
43820+ event_count = atomic_read_unchecked(&idev->event);
43821 if (event_count != listener->event_count) {
43822 if (copy_to_user(buf, &event_count, count))
43823 retval = -EFAULT;
43824@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43825 static void uio_vma_open(struct vm_area_struct *vma)
43826 {
43827 struct uio_device *idev = vma->vm_private_data;
43828- idev->vma_count++;
43829+ local_inc(&idev->vma_count);
43830 }
43831
43832 static void uio_vma_close(struct vm_area_struct *vma)
43833 {
43834 struct uio_device *idev = vma->vm_private_data;
43835- idev->vma_count--;
43836+ local_dec(&idev->vma_count);
43837 }
43838
43839 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43840@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43841 idev->owner = owner;
43842 idev->info = info;
43843 init_waitqueue_head(&idev->wait);
43844- atomic_set(&idev->event, 0);
43845+ atomic_set_unchecked(&idev->event, 0);
43846
43847 ret = uio_get_minor(idev);
43848 if (ret)
43849diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43850index b7eb86a..36d28af 100644
43851--- a/drivers/usb/atm/cxacru.c
43852+++ b/drivers/usb/atm/cxacru.c
43853@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43854 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43855 if (ret < 2)
43856 return -EINVAL;
43857- if (index < 0 || index > 0x7f)
43858+ if (index > 0x7f)
43859 return -EINVAL;
43860 pos += tmp;
43861
43862diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43863index 35f10bf..6a38a0b 100644
43864--- a/drivers/usb/atm/usbatm.c
43865+++ b/drivers/usb/atm/usbatm.c
43866@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43867 if (printk_ratelimit())
43868 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43869 __func__, vpi, vci);
43870- atomic_inc(&vcc->stats->rx_err);
43871+ atomic_inc_unchecked(&vcc->stats->rx_err);
43872 return;
43873 }
43874
43875@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43876 if (length > ATM_MAX_AAL5_PDU) {
43877 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43878 __func__, length, vcc);
43879- atomic_inc(&vcc->stats->rx_err);
43880+ atomic_inc_unchecked(&vcc->stats->rx_err);
43881 goto out;
43882 }
43883
43884@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43885 if (sarb->len < pdu_length) {
43886 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43887 __func__, pdu_length, sarb->len, vcc);
43888- atomic_inc(&vcc->stats->rx_err);
43889+ atomic_inc_unchecked(&vcc->stats->rx_err);
43890 goto out;
43891 }
43892
43893 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43894 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43895 __func__, vcc);
43896- atomic_inc(&vcc->stats->rx_err);
43897+ atomic_inc_unchecked(&vcc->stats->rx_err);
43898 goto out;
43899 }
43900
43901@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43902 if (printk_ratelimit())
43903 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43904 __func__, length);
43905- atomic_inc(&vcc->stats->rx_drop);
43906+ atomic_inc_unchecked(&vcc->stats->rx_drop);
43907 goto out;
43908 }
43909
43910@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43911
43912 vcc->push(vcc, skb);
43913
43914- atomic_inc(&vcc->stats->rx);
43915+ atomic_inc_unchecked(&vcc->stats->rx);
43916 out:
43917 skb_trim(sarb, 0);
43918 }
43919@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43920 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43921
43922 usbatm_pop(vcc, skb);
43923- atomic_inc(&vcc->stats->tx);
43924+ atomic_inc_unchecked(&vcc->stats->tx);
43925
43926 skb = skb_dequeue(&instance->sndqueue);
43927 }
43928@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43929 if (!left--)
43930 return sprintf(page,
43931 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43932- atomic_read(&atm_dev->stats.aal5.tx),
43933- atomic_read(&atm_dev->stats.aal5.tx_err),
43934- atomic_read(&atm_dev->stats.aal5.rx),
43935- atomic_read(&atm_dev->stats.aal5.rx_err),
43936- atomic_read(&atm_dev->stats.aal5.rx_drop));
43937+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43938+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43939+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43940+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43941+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43942
43943 if (!left--) {
43944 if (instance->disconnected)
43945diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43946index cbacea9..246cccd 100644
43947--- a/drivers/usb/core/devices.c
43948+++ b/drivers/usb/core/devices.c
43949@@ -126,7 +126,7 @@ static const char format_endpt[] =
43950 * time it gets called.
43951 */
43952 static struct device_connect_event {
43953- atomic_t count;
43954+ atomic_unchecked_t count;
43955 wait_queue_head_t wait;
43956 } device_event = {
43957 .count = ATOMIC_INIT(1),
43958@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
43959
43960 void usbfs_conn_disc_event(void)
43961 {
43962- atomic_add(2, &device_event.count);
43963+ atomic_add_unchecked(2, &device_event.count);
43964 wake_up(&device_event.wait);
43965 }
43966
43967@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
43968
43969 poll_wait(file, &device_event.wait, wait);
43970
43971- event_count = atomic_read(&device_event.count);
43972+ event_count = atomic_read_unchecked(&device_event.count);
43973 if (file->f_version != event_count) {
43974 file->f_version = event_count;
43975 return POLLIN | POLLRDNORM;
43976diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
43977index 8e64adf..9a33a3c 100644
43978--- a/drivers/usb/core/hcd.c
43979+++ b/drivers/usb/core/hcd.c
43980@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43981 */
43982 usb_get_urb(urb);
43983 atomic_inc(&urb->use_count);
43984- atomic_inc(&urb->dev->urbnum);
43985+ atomic_inc_unchecked(&urb->dev->urbnum);
43986 usbmon_urb_submit(&hcd->self, urb);
43987
43988 /* NOTE requirements on root-hub callers (usbfs and the hub
43989@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43990 urb->hcpriv = NULL;
43991 INIT_LIST_HEAD(&urb->urb_list);
43992 atomic_dec(&urb->use_count);
43993- atomic_dec(&urb->dev->urbnum);
43994+ atomic_dec_unchecked(&urb->dev->urbnum);
43995 if (atomic_read(&urb->reject))
43996 wake_up(&usb_kill_urb_queue);
43997 usb_put_urb(urb);
43998diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
43999index 131f736..99004c3 100644
44000--- a/drivers/usb/core/message.c
44001+++ b/drivers/usb/core/message.c
44002@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44003 * method can wait for it to complete. Since you don't have a handle on the
44004 * URB used, you can't cancel the request.
44005 */
44006-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44007+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44008 __u8 requesttype, __u16 value, __u16 index, void *data,
44009 __u16 size, int timeout)
44010 {
44011diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44012index 818e4a0..0fc9589 100644
44013--- a/drivers/usb/core/sysfs.c
44014+++ b/drivers/usb/core/sysfs.c
44015@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44016 struct usb_device *udev;
44017
44018 udev = to_usb_device(dev);
44019- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44020+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44021 }
44022 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44023
44024diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44025index f81b925..78d22ec 100644
44026--- a/drivers/usb/core/usb.c
44027+++ b/drivers/usb/core/usb.c
44028@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44029 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44030 dev->state = USB_STATE_ATTACHED;
44031 dev->lpm_disable_count = 1;
44032- atomic_set(&dev->urbnum, 0);
44033+ atomic_set_unchecked(&dev->urbnum, 0);
44034
44035 INIT_LIST_HEAD(&dev->ep0.urb_list);
44036 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44037diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44038index 5e29dde..eca992f 100644
44039--- a/drivers/usb/early/ehci-dbgp.c
44040+++ b/drivers/usb/early/ehci-dbgp.c
44041@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44042
44043 #ifdef CONFIG_KGDB
44044 static struct kgdb_io kgdbdbgp_io_ops;
44045-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44046+static struct kgdb_io kgdbdbgp_io_ops_console;
44047+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44048 #else
44049 #define dbgp_kgdb_mode (0)
44050 #endif
44051@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44052 .write_char = kgdbdbgp_write_char,
44053 };
44054
44055+static struct kgdb_io kgdbdbgp_io_ops_console = {
44056+ .name = "kgdbdbgp",
44057+ .read_char = kgdbdbgp_read_char,
44058+ .write_char = kgdbdbgp_write_char,
44059+ .is_console = 1
44060+};
44061+
44062 static int kgdbdbgp_wait_time;
44063
44064 static int __init kgdbdbgp_parse_config(char *str)
44065@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44066 ptr++;
44067 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44068 }
44069- kgdb_register_io_module(&kgdbdbgp_io_ops);
44070- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44071+ if (early_dbgp_console.index != -1)
44072+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44073+ else
44074+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44075
44076 return 0;
44077 }
44078diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44079index 598dcc1..032dd4f 100644
44080--- a/drivers/usb/gadget/u_serial.c
44081+++ b/drivers/usb/gadget/u_serial.c
44082@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44083 spin_lock_irq(&port->port_lock);
44084
44085 /* already open? Great. */
44086- if (port->port.count) {
44087+ if (atomic_read(&port->port.count)) {
44088 status = 0;
44089- port->port.count++;
44090+ atomic_inc(&port->port.count);
44091
44092 /* currently opening/closing? wait ... */
44093 } else if (port->openclose) {
44094@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44095 tty->driver_data = port;
44096 port->port.tty = tty;
44097
44098- port->port.count = 1;
44099+ atomic_set(&port->port.count, 1);
44100 port->openclose = false;
44101
44102 /* if connected, start the I/O stream */
44103@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44104
44105 spin_lock_irq(&port->port_lock);
44106
44107- if (port->port.count != 1) {
44108- if (port->port.count == 0)
44109+ if (atomic_read(&port->port.count) != 1) {
44110+ if (atomic_read(&port->port.count) == 0)
44111 WARN_ON(1);
44112 else
44113- --port->port.count;
44114+ atomic_dec(&port->port.count);
44115 goto exit;
44116 }
44117
44118@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44119 * and sleep if necessary
44120 */
44121 port->openclose = true;
44122- port->port.count = 0;
44123+ atomic_set(&port->port.count, 0);
44124
44125 gser = port->port_usb;
44126 if (gser && gser->disconnect)
44127@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44128 int cond;
44129
44130 spin_lock_irq(&port->port_lock);
44131- cond = (port->port.count == 0) && !port->openclose;
44132+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44133 spin_unlock_irq(&port->port_lock);
44134 return cond;
44135 }
44136@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44137 /* if it's already open, start I/O ... and notify the serial
44138 * protocol about open/close status (connect/disconnect).
44139 */
44140- if (port->port.count) {
44141+ if (atomic_read(&port->port.count)) {
44142 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44143 gs_start_io(port);
44144 if (gser->connect)
44145@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44146
44147 port->port_usb = NULL;
44148 gser->ioport = NULL;
44149- if (port->port.count > 0 || port->openclose) {
44150+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44151 wake_up_interruptible(&port->drain_wait);
44152 if (port->port.tty)
44153 tty_hangup(port->port.tty);
44154@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44155
44156 /* finally, free any unused/unusable I/O buffers */
44157 spin_lock_irqsave(&port->port_lock, flags);
44158- if (port->port.count == 0 && !port->openclose)
44159+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44160 gs_buf_free(&port->port_write_buf);
44161 gs_free_requests(gser->out, &port->read_pool, NULL);
44162 gs_free_requests(gser->out, &port->read_queue, NULL);
44163diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44164index 5f3bcd3..bfca43f 100644
44165--- a/drivers/usb/serial/console.c
44166+++ b/drivers/usb/serial/console.c
44167@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44168
44169 info->port = port;
44170
44171- ++port->port.count;
44172+ atomic_inc(&port->port.count);
44173 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44174 if (serial->type->set_termios) {
44175 /*
44176@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44177 }
44178 /* Now that any required fake tty operations are completed restore
44179 * the tty port count */
44180- --port->port.count;
44181+ atomic_dec(&port->port.count);
44182 /* The console is special in terms of closing the device so
44183 * indicate this port is now acting as a system console. */
44184 port->port.console = 1;
44185@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44186 free_tty:
44187 kfree(tty);
44188 reset_open_count:
44189- port->port.count = 0;
44190+ atomic_set(&port->port.count, 0);
44191 usb_autopm_put_interface(serial->interface);
44192 error_get_interface:
44193 usb_serial_put(serial);
44194diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44195index 75f70f0..d467e1a 100644
44196--- a/drivers/usb/storage/usb.h
44197+++ b/drivers/usb/storage/usb.h
44198@@ -63,7 +63,7 @@ struct us_unusual_dev {
44199 __u8 useProtocol;
44200 __u8 useTransport;
44201 int (*initFunction)(struct us_data *);
44202-};
44203+} __do_const;
44204
44205
44206 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44207diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44208index d6bea3e..60b250e 100644
44209--- a/drivers/usb/wusbcore/wa-hc.h
44210+++ b/drivers/usb/wusbcore/wa-hc.h
44211@@ -192,7 +192,7 @@ struct wahc {
44212 struct list_head xfer_delayed_list;
44213 spinlock_t xfer_list_lock;
44214 struct work_struct xfer_work;
44215- atomic_t xfer_id_count;
44216+ atomic_unchecked_t xfer_id_count;
44217 };
44218
44219
44220@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44221 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44222 spin_lock_init(&wa->xfer_list_lock);
44223 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44224- atomic_set(&wa->xfer_id_count, 1);
44225+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44226 }
44227
44228 /**
44229diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44230index 57c01ab..8a05959 100644
44231--- a/drivers/usb/wusbcore/wa-xfer.c
44232+++ b/drivers/usb/wusbcore/wa-xfer.c
44233@@ -296,7 +296,7 @@ out:
44234 */
44235 static void wa_xfer_id_init(struct wa_xfer *xfer)
44236 {
44237- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44238+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44239 }
44240
44241 /*
44242diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44243index 8c55011..eed4ae1a 100644
44244--- a/drivers/video/aty/aty128fb.c
44245+++ b/drivers/video/aty/aty128fb.c
44246@@ -149,7 +149,7 @@ enum {
44247 };
44248
44249 /* Must match above enum */
44250-static char * const r128_family[] = {
44251+static const char * const r128_family[] = {
44252 "AGP",
44253 "PCI",
44254 "PRO AGP",
44255diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44256index 4f27fdc..d3537e6 100644
44257--- a/drivers/video/aty/atyfb_base.c
44258+++ b/drivers/video/aty/atyfb_base.c
44259@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44260 par->accel_flags = var->accel_flags; /* hack */
44261
44262 if (var->accel_flags) {
44263- info->fbops->fb_sync = atyfb_sync;
44264+ pax_open_kernel();
44265+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44266+ pax_close_kernel();
44267 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44268 } else {
44269- info->fbops->fb_sync = NULL;
44270+ pax_open_kernel();
44271+ *(void **)&info->fbops->fb_sync = NULL;
44272+ pax_close_kernel();
44273 info->flags |= FBINFO_HWACCEL_DISABLED;
44274 }
44275
44276diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44277index 95ec042..e6affdd 100644
44278--- a/drivers/video/aty/mach64_cursor.c
44279+++ b/drivers/video/aty/mach64_cursor.c
44280@@ -7,6 +7,7 @@
44281 #include <linux/string.h>
44282
44283 #include <asm/io.h>
44284+#include <asm/pgtable.h>
44285
44286 #ifdef __sparc__
44287 #include <asm/fbio.h>
44288@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44289 info->sprite.buf_align = 16; /* and 64 lines tall. */
44290 info->sprite.flags = FB_PIXMAP_IO;
44291
44292- info->fbops->fb_cursor = atyfb_cursor;
44293+ pax_open_kernel();
44294+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44295+ pax_close_kernel();
44296
44297 return 0;
44298 }
44299diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44300index 6c5ed6b..b727c88 100644
44301--- a/drivers/video/backlight/kb3886_bl.c
44302+++ b/drivers/video/backlight/kb3886_bl.c
44303@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44304 static unsigned long kb3886bl_flags;
44305 #define KB3886BL_SUSPENDED 0x01
44306
44307-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44308+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44309 {
44310 .ident = "Sahara Touch-iT",
44311 .matches = {
44312diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44313index 88cad6b..dd746c7 100644
44314--- a/drivers/video/fb_defio.c
44315+++ b/drivers/video/fb_defio.c
44316@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44317
44318 BUG_ON(!fbdefio);
44319 mutex_init(&fbdefio->lock);
44320- info->fbops->fb_mmap = fb_deferred_io_mmap;
44321+ pax_open_kernel();
44322+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44323+ pax_close_kernel();
44324 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
44325 INIT_LIST_HEAD(&fbdefio->pagelist);
44326 if (fbdefio->delay == 0) /* set a default of 1 s */
44327@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
44328 page->mapping = NULL;
44329 }
44330
44331- info->fbops->fb_mmap = NULL;
44332+ *(void **)&info->fbops->fb_mmap = NULL;
44333 mutex_destroy(&fbdefio->lock);
44334 }
44335 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
44336diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
44337index 5c3960d..15cf8fc 100644
44338--- a/drivers/video/fbcmap.c
44339+++ b/drivers/video/fbcmap.c
44340@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
44341 rc = -ENODEV;
44342 goto out;
44343 }
44344- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
44345- !info->fbops->fb_setcmap)) {
44346+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
44347 rc = -EINVAL;
44348 goto out1;
44349 }
44350diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
44351index dc61c12..e29796e 100644
44352--- a/drivers/video/fbmem.c
44353+++ b/drivers/video/fbmem.c
44354@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44355 image->dx += image->width + 8;
44356 }
44357 } else if (rotate == FB_ROTATE_UD) {
44358- for (x = 0; x < num && image->dx >= 0; x++) {
44359+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
44360 info->fbops->fb_imageblit(info, image);
44361 image->dx -= image->width + 8;
44362 }
44363@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44364 image->dy += image->height + 8;
44365 }
44366 } else if (rotate == FB_ROTATE_CCW) {
44367- for (x = 0; x < num && image->dy >= 0; x++) {
44368+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
44369 info->fbops->fb_imageblit(info, image);
44370 image->dy -= image->height + 8;
44371 }
44372@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
44373 return -EFAULT;
44374 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
44375 return -EINVAL;
44376- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
44377+ if (con2fb.framebuffer >= FB_MAX)
44378 return -EINVAL;
44379 if (!registered_fb[con2fb.framebuffer])
44380 request_module("fb%d", con2fb.framebuffer);
44381diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
44382index 7672d2e..b56437f 100644
44383--- a/drivers/video/i810/i810_accel.c
44384+++ b/drivers/video/i810/i810_accel.c
44385@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
44386 }
44387 }
44388 printk("ringbuffer lockup!!!\n");
44389+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
44390 i810_report_error(mmio);
44391 par->dev_flags |= LOCKUP;
44392 info->pixmap.scan_align = 1;
44393diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
44394index 3c14e43..eafa544 100644
44395--- a/drivers/video/logo/logo_linux_clut224.ppm
44396+++ b/drivers/video/logo/logo_linux_clut224.ppm
44397@@ -1,1604 +1,1123 @@
44398 P3
44399-# Standard 224-color Linux logo
44400 80 80
44401 255
44402- 0 0 0 0 0 0 0 0 0 0 0 0
44403- 0 0 0 0 0 0 0 0 0 0 0 0
44404- 0 0 0 0 0 0 0 0 0 0 0 0
44405- 0 0 0 0 0 0 0 0 0 0 0 0
44406- 0 0 0 0 0 0 0 0 0 0 0 0
44407- 0 0 0 0 0 0 0 0 0 0 0 0
44408- 0 0 0 0 0 0 0 0 0 0 0 0
44409- 0 0 0 0 0 0 0 0 0 0 0 0
44410- 0 0 0 0 0 0 0 0 0 0 0 0
44411- 6 6 6 6 6 6 10 10 10 10 10 10
44412- 10 10 10 6 6 6 6 6 6 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
44421- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
44431- 22 22 22 26 26 26 30 30 30 34 34 34
44432- 30 30 30 30 30 30 26 26 26 18 18 18
44433- 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0
44440- 0 0 0 0 0 0 0 0 0 0 0 0
44441- 0 0 0 0 0 0 0 0 0 0 0 0
44442- 0 0 0 0 0 0 0 0 0 0 0 0
44443- 0 0 0 0 0 1 0 0 1 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- 6 6 6 14 14 14 26 26 26 42 42 42
44451- 54 54 54 66 66 66 78 78 78 78 78 78
44452- 78 78 78 74 74 74 66 66 66 54 54 54
44453- 42 42 42 26 26 26 18 18 18 10 10 10
44454- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
44460- 0 0 0 0 0 0 0 0 0 0 0 0
44461- 0 0 0 0 0 0 0 0 0 0 0 0
44462- 0 0 0 0 0 0 0 0 0 0 0 0
44463- 0 0 1 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 10 10 10
44470- 22 22 22 42 42 42 66 66 66 86 86 86
44471- 66 66 66 38 38 38 38 38 38 22 22 22
44472- 26 26 26 34 34 34 54 54 54 66 66 66
44473- 86 86 86 70 70 70 46 46 46 26 26 26
44474- 14 14 14 6 6 6 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 0 0 0
44479- 0 0 0 0 0 0 0 0 0 0 0 0
44480- 0 0 0 0 0 0 0 0 0 0 0 0
44481- 0 0 0 0 0 0 0 0 0 0 0 0
44482- 0 0 0 0 0 0 0 0 0 0 0 0
44483- 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
44490- 50 50 50 82 82 82 58 58 58 6 6 6
44491- 2 2 6 2 2 6 2 2 6 2 2 6
44492- 2 2 6 2 2 6 2 2 6 2 2 6
44493- 6 6 6 54 54 54 86 86 86 66 66 66
44494- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0
44499- 0 0 0 0 0 0 0 0 0 0 0 0
44500- 0 0 0 0 0 0 0 0 0 0 0 0
44501- 0 0 0 0 0 0 0 0 0 0 0 0
44502- 0 0 0 0 0 0 0 0 0 0 0 0
44503- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
44510- 78 78 78 34 34 34 2 2 6 2 2 6
44511- 2 2 6 2 2 6 2 2 6 2 2 6
44512- 2 2 6 2 2 6 2 2 6 2 2 6
44513- 2 2 6 2 2 6 6 6 6 70 70 70
44514- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
44519- 0 0 0 0 0 0 0 0 0 0 0 0
44520- 0 0 0 0 0 0 0 0 0 0 0 0
44521- 0 0 0 0 0 0 0 0 0 0 0 0
44522- 0 0 0 0 0 0 0 0 0 0 0 0
44523- 0 0 1 0 0 1 0 0 1 0 0 0
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- 6 6 6 18 18 18 42 42 42 82 82 82
44530- 26 26 26 2 2 6 2 2 6 2 2 6
44531- 2 2 6 2 2 6 2 2 6 2 2 6
44532- 2 2 6 2 2 6 2 2 6 14 14 14
44533- 46 46 46 34 34 34 6 6 6 2 2 6
44534- 42 42 42 78 78 78 42 42 42 18 18 18
44535- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
44539- 0 0 0 0 0 0 0 0 0 0 0 0
44540- 0 0 0 0 0 0 0 0 0 0 0 0
44541- 0 0 0 0 0 0 0 0 0 0 0 0
44542- 0 0 0 0 0 0 0 0 0 0 0 0
44543- 0 0 1 0 0 0 0 0 1 0 0 0
44544- 0 0 0 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- 10 10 10 30 30 30 66 66 66 58 58 58
44550- 2 2 6 2 2 6 2 2 6 2 2 6
44551- 2 2 6 2 2 6 2 2 6 2 2 6
44552- 2 2 6 2 2 6 2 2 6 26 26 26
44553- 86 86 86 101 101 101 46 46 46 10 10 10
44554- 2 2 6 58 58 58 70 70 70 34 34 34
44555- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
44559- 0 0 0 0 0 0 0 0 0 0 0 0
44560- 0 0 0 0 0 0 0 0 0 0 0 0
44561- 0 0 0 0 0 0 0 0 0 0 0 0
44562- 0 0 0 0 0 0 0 0 0 0 0 0
44563- 0 0 1 0 0 1 0 0 1 0 0 0
44564- 0 0 0 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- 14 14 14 42 42 42 86 86 86 10 10 10
44570- 2 2 6 2 2 6 2 2 6 2 2 6
44571- 2 2 6 2 2 6 2 2 6 2 2 6
44572- 2 2 6 2 2 6 2 2 6 30 30 30
44573- 94 94 94 94 94 94 58 58 58 26 26 26
44574- 2 2 6 6 6 6 78 78 78 54 54 54
44575- 22 22 22 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
44579- 0 0 0 0 0 0 0 0 0 0 0 0
44580- 0 0 0 0 0 0 0 0 0 0 0 0
44581- 0 0 0 0 0 0 0 0 0 0 0 0
44582- 0 0 0 0 0 0 0 0 0 0 0 0
44583- 0 0 0 0 0 0 0 0 0 0 0 0
44584- 0 0 0 0 0 0 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 6 6 6
44589- 22 22 22 62 62 62 62 62 62 2 2 6
44590- 2 2 6 2 2 6 2 2 6 2 2 6
44591- 2 2 6 2 2 6 2 2 6 2 2 6
44592- 2 2 6 2 2 6 2 2 6 26 26 26
44593- 54 54 54 38 38 38 18 18 18 10 10 10
44594- 2 2 6 2 2 6 34 34 34 82 82 82
44595- 38 38 38 14 14 14 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 0 0 0
44598- 0 0 0 0 0 0 0 0 0 0 0 0
44599- 0 0 0 0 0 0 0 0 0 0 0 0
44600- 0 0 0 0 0 0 0 0 0 0 0 0
44601- 0 0 0 0 0 0 0 0 0 0 0 0
44602- 0 0 0 0 0 0 0 0 0 0 0 0
44603- 0 0 0 0 0 1 0 0 1 0 0 0
44604- 0 0 0 0 0 0 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 6 6 6
44609- 30 30 30 78 78 78 30 30 30 2 2 6
44610- 2 2 6 2 2 6 2 2 6 2 2 6
44611- 2 2 6 2 2 6 2 2 6 2 2 6
44612- 2 2 6 2 2 6 2 2 6 10 10 10
44613- 10 10 10 2 2 6 2 2 6 2 2 6
44614- 2 2 6 2 2 6 2 2 6 78 78 78
44615- 50 50 50 18 18 18 6 6 6 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 0 0 0
44618- 0 0 0 0 0 0 0 0 0 0 0 0
44619- 0 0 0 0 0 0 0 0 0 0 0 0
44620- 0 0 0 0 0 0 0 0 0 0 0 0
44621- 0 0 0 0 0 0 0 0 0 0 0 0
44622- 0 0 0 0 0 0 0 0 0 0 0 0
44623- 0 0 1 0 0 0 0 0 0 0 0 0
44624- 0 0 0 0 0 0 0 0 0 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 10 10 10
44629- 38 38 38 86 86 86 14 14 14 2 2 6
44630- 2 2 6 2 2 6 2 2 6 2 2 6
44631- 2 2 6 2 2 6 2 2 6 2 2 6
44632- 2 2 6 2 2 6 2 2 6 2 2 6
44633- 2 2 6 2 2 6 2 2 6 2 2 6
44634- 2 2 6 2 2 6 2 2 6 54 54 54
44635- 66 66 66 26 26 26 6 6 6 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 0 0 0
44638- 0 0 0 0 0 0 0 0 0 0 0 0
44639- 0 0 0 0 0 0 0 0 0 0 0 0
44640- 0 0 0 0 0 0 0 0 0 0 0 0
44641- 0 0 0 0 0 0 0 0 0 0 0 0
44642- 0 0 0 0 0 0 0 0 0 0 0 0
44643- 0 0 0 0 0 1 0 0 1 0 0 0
44644- 0 0 0 0 0 0 0 0 0 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 14 14 14
44649- 42 42 42 82 82 82 2 2 6 2 2 6
44650- 2 2 6 6 6 6 10 10 10 2 2 6
44651- 2 2 6 2 2 6 2 2 6 2 2 6
44652- 2 2 6 2 2 6 2 2 6 6 6 6
44653- 14 14 14 10 10 10 2 2 6 2 2 6
44654- 2 2 6 2 2 6 2 2 6 18 18 18
44655- 82 82 82 34 34 34 10 10 10 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 0 0 0
44658- 0 0 0 0 0 0 0 0 0 0 0 0
44659- 0 0 0 0 0 0 0 0 0 0 0 0
44660- 0 0 0 0 0 0 0 0 0 0 0 0
44661- 0 0 0 0 0 0 0 0 0 0 0 0
44662- 0 0 0 0 0 0 0 0 0 0 0 0
44663- 0 0 1 0 0 0 0 0 0 0 0 0
44664- 0 0 0 0 0 0 0 0 0 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 14 14 14
44669- 46 46 46 86 86 86 2 2 6 2 2 6
44670- 6 6 6 6 6 6 22 22 22 34 34 34
44671- 6 6 6 2 2 6 2 2 6 2 2 6
44672- 2 2 6 2 2 6 18 18 18 34 34 34
44673- 10 10 10 50 50 50 22 22 22 2 2 6
44674- 2 2 6 2 2 6 2 2 6 10 10 10
44675- 86 86 86 42 42 42 14 14 14 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 0 0 0
44678- 0 0 0 0 0 0 0 0 0 0 0 0
44679- 0 0 0 0 0 0 0 0 0 0 0 0
44680- 0 0 0 0 0 0 0 0 0 0 0 0
44681- 0 0 0 0 0 0 0 0 0 0 0 0
44682- 0 0 0 0 0 0 0 0 0 0 0 0
44683- 0 0 1 0 0 1 0 0 1 0 0 0
44684- 0 0 0 0 0 0 0 0 0 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 14 14 14
44689- 46 46 46 86 86 86 2 2 6 2 2 6
44690- 38 38 38 116 116 116 94 94 94 22 22 22
44691- 22 22 22 2 2 6 2 2 6 2 2 6
44692- 14 14 14 86 86 86 138 138 138 162 162 162
44693-154 154 154 38 38 38 26 26 26 6 6 6
44694- 2 2 6 2 2 6 2 2 6 2 2 6
44695- 86 86 86 46 46 46 14 14 14 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 0 0 0
44698- 0 0 0 0 0 0 0 0 0 0 0 0
44699- 0 0 0 0 0 0 0 0 0 0 0 0
44700- 0 0 0 0 0 0 0 0 0 0 0 0
44701- 0 0 0 0 0 0 0 0 0 0 0 0
44702- 0 0 0 0 0 0 0 0 0 0 0 0
44703- 0 0 0 0 0 0 0 0 0 0 0 0
44704- 0 0 0 0 0 0 0 0 0 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 14 14 14
44709- 46 46 46 86 86 86 2 2 6 14 14 14
44710-134 134 134 198 198 198 195 195 195 116 116 116
44711- 10 10 10 2 2 6 2 2 6 6 6 6
44712-101 98 89 187 187 187 210 210 210 218 218 218
44713-214 214 214 134 134 134 14 14 14 6 6 6
44714- 2 2 6 2 2 6 2 2 6 2 2 6
44715- 86 86 86 50 50 50 18 18 18 6 6 6
44716- 0 0 0 0 0 0 0 0 0 0 0 0
44717- 0 0 0 0 0 0 0 0 0 0 0 0
44718- 0 0 0 0 0 0 0 0 0 0 0 0
44719- 0 0 0 0 0 0 0 0 0 0 0 0
44720- 0 0 0 0 0 0 0 0 0 0 0 0
44721- 0 0 0 0 0 0 0 0 0 0 0 0
44722- 0 0 0 0 0 0 0 0 1 0 0 0
44723- 0 0 1 0 0 1 0 0 1 0 0 0
44724- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
44729- 46 46 46 86 86 86 2 2 6 54 54 54
44730-218 218 218 195 195 195 226 226 226 246 246 246
44731- 58 58 58 2 2 6 2 2 6 30 30 30
44732-210 210 210 253 253 253 174 174 174 123 123 123
44733-221 221 221 234 234 234 74 74 74 2 2 6
44734- 2 2 6 2 2 6 2 2 6 2 2 6
44735- 70 70 70 58 58 58 22 22 22 6 6 6
44736- 0 0 0 0 0 0 0 0 0 0 0 0
44737- 0 0 0 0 0 0 0 0 0 0 0 0
44738- 0 0 0 0 0 0 0 0 0 0 0 0
44739- 0 0 0 0 0 0 0 0 0 0 0 0
44740- 0 0 0 0 0 0 0 0 0 0 0 0
44741- 0 0 0 0 0 0 0 0 0 0 0 0
44742- 0 0 0 0 0 0 0 0 0 0 0 0
44743- 0 0 0 0 0 0 0 0 0 0 0 0
44744- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
44749- 46 46 46 82 82 82 2 2 6 106 106 106
44750-170 170 170 26 26 26 86 86 86 226 226 226
44751-123 123 123 10 10 10 14 14 14 46 46 46
44752-231 231 231 190 190 190 6 6 6 70 70 70
44753- 90 90 90 238 238 238 158 158 158 2 2 6
44754- 2 2 6 2 2 6 2 2 6 2 2 6
44755- 70 70 70 58 58 58 22 22 22 6 6 6
44756- 0 0 0 0 0 0 0 0 0 0 0 0
44757- 0 0 0 0 0 0 0 0 0 0 0 0
44758- 0 0 0 0 0 0 0 0 0 0 0 0
44759- 0 0 0 0 0 0 0 0 0 0 0 0
44760- 0 0 0 0 0 0 0 0 0 0 0 0
44761- 0 0 0 0 0 0 0 0 0 0 0 0
44762- 0 0 0 0 0 0 0 0 1 0 0 0
44763- 0 0 1 0 0 1 0 0 1 0 0 0
44764- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
44769- 42 42 42 86 86 86 6 6 6 116 116 116
44770-106 106 106 6 6 6 70 70 70 149 149 149
44771-128 128 128 18 18 18 38 38 38 54 54 54
44772-221 221 221 106 106 106 2 2 6 14 14 14
44773- 46 46 46 190 190 190 198 198 198 2 2 6
44774- 2 2 6 2 2 6 2 2 6 2 2 6
44775- 74 74 74 62 62 62 22 22 22 6 6 6
44776- 0 0 0 0 0 0 0 0 0 0 0 0
44777- 0 0 0 0 0 0 0 0 0 0 0 0
44778- 0 0 0 0 0 0 0 0 0 0 0 0
44779- 0 0 0 0 0 0 0 0 0 0 0 0
44780- 0 0 0 0 0 0 0 0 0 0 0 0
44781- 0 0 0 0 0 0 0 0 0 0 0 0
44782- 0 0 0 0 0 0 0 0 1 0 0 0
44783- 0 0 1 0 0 0 0 0 1 0 0 0
44784- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
44789- 42 42 42 94 94 94 14 14 14 101 101 101
44790-128 128 128 2 2 6 18 18 18 116 116 116
44791-118 98 46 121 92 8 121 92 8 98 78 10
44792-162 162 162 106 106 106 2 2 6 2 2 6
44793- 2 2 6 195 195 195 195 195 195 6 6 6
44794- 2 2 6 2 2 6 2 2 6 2 2 6
44795- 74 74 74 62 62 62 22 22 22 6 6 6
44796- 0 0 0 0 0 0 0 0 0 0 0 0
44797- 0 0 0 0 0 0 0 0 0 0 0 0
44798- 0 0 0 0 0 0 0 0 0 0 0 0
44799- 0 0 0 0 0 0 0 0 0 0 0 0
44800- 0 0 0 0 0 0 0 0 0 0 0 0
44801- 0 0 0 0 0 0 0 0 0 0 0 0
44802- 0 0 0 0 0 0 0 0 1 0 0 1
44803- 0 0 1 0 0 0 0 0 1 0 0 0
44804- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44809- 38 38 38 90 90 90 14 14 14 58 58 58
44810-210 210 210 26 26 26 54 38 6 154 114 10
44811-226 170 11 236 186 11 225 175 15 184 144 12
44812-215 174 15 175 146 61 37 26 9 2 2 6
44813- 70 70 70 246 246 246 138 138 138 2 2 6
44814- 2 2 6 2 2 6 2 2 6 2 2 6
44815- 70 70 70 66 66 66 26 26 26 6 6 6
44816- 0 0 0 0 0 0 0 0 0 0 0 0
44817- 0 0 0 0 0 0 0 0 0 0 0 0
44818- 0 0 0 0 0 0 0 0 0 0 0 0
44819- 0 0 0 0 0 0 0 0 0 0 0 0
44820- 0 0 0 0 0 0 0 0 0 0 0 0
44821- 0 0 0 0 0 0 0 0 0 0 0 0
44822- 0 0 0 0 0 0 0 0 0 0 0 0
44823- 0 0 0 0 0 0 0 0 0 0 0 0
44824- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44829- 38 38 38 86 86 86 14 14 14 10 10 10
44830-195 195 195 188 164 115 192 133 9 225 175 15
44831-239 182 13 234 190 10 232 195 16 232 200 30
44832-245 207 45 241 208 19 232 195 16 184 144 12
44833-218 194 134 211 206 186 42 42 42 2 2 6
44834- 2 2 6 2 2 6 2 2 6 2 2 6
44835- 50 50 50 74 74 74 30 30 30 6 6 6
44836- 0 0 0 0 0 0 0 0 0 0 0 0
44837- 0 0 0 0 0 0 0 0 0 0 0 0
44838- 0 0 0 0 0 0 0 0 0 0 0 0
44839- 0 0 0 0 0 0 0 0 0 0 0 0
44840- 0 0 0 0 0 0 0 0 0 0 0 0
44841- 0 0 0 0 0 0 0 0 0 0 0 0
44842- 0 0 0 0 0 0 0 0 0 0 0 0
44843- 0 0 0 0 0 0 0 0 0 0 0 0
44844- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44849- 34 34 34 86 86 86 14 14 14 2 2 6
44850-121 87 25 192 133 9 219 162 10 239 182 13
44851-236 186 11 232 195 16 241 208 19 244 214 54
44852-246 218 60 246 218 38 246 215 20 241 208 19
44853-241 208 19 226 184 13 121 87 25 2 2 6
44854- 2 2 6 2 2 6 2 2 6 2 2 6
44855- 50 50 50 82 82 82 34 34 34 10 10 10
44856- 0 0 0 0 0 0 0 0 0 0 0 0
44857- 0 0 0 0 0 0 0 0 0 0 0 0
44858- 0 0 0 0 0 0 0 0 0 0 0 0
44859- 0 0 0 0 0 0 0 0 0 0 0 0
44860- 0 0 0 0 0 0 0 0 0 0 0 0
44861- 0 0 0 0 0 0 0 0 0 0 0 0
44862- 0 0 0 0 0 0 0 0 0 0 0 0
44863- 0 0 0 0 0 0 0 0 0 0 0 0
44864- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44869- 34 34 34 82 82 82 30 30 30 61 42 6
44870-180 123 7 206 145 10 230 174 11 239 182 13
44871-234 190 10 238 202 15 241 208 19 246 218 74
44872-246 218 38 246 215 20 246 215 20 246 215 20
44873-226 184 13 215 174 15 184 144 12 6 6 6
44874- 2 2 6 2 2 6 2 2 6 2 2 6
44875- 26 26 26 94 94 94 42 42 42 14 14 14
44876- 0 0 0 0 0 0 0 0 0 0 0 0
44877- 0 0 0 0 0 0 0 0 0 0 0 0
44878- 0 0 0 0 0 0 0 0 0 0 0 0
44879- 0 0 0 0 0 0 0 0 0 0 0 0
44880- 0 0 0 0 0 0 0 0 0 0 0 0
44881- 0 0 0 0 0 0 0 0 0 0 0 0
44882- 0 0 0 0 0 0 0 0 0 0 0 0
44883- 0 0 0 0 0 0 0 0 0 0 0 0
44884- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44889- 30 30 30 78 78 78 50 50 50 104 69 6
44890-192 133 9 216 158 10 236 178 12 236 186 11
44891-232 195 16 241 208 19 244 214 54 245 215 43
44892-246 215 20 246 215 20 241 208 19 198 155 10
44893-200 144 11 216 158 10 156 118 10 2 2 6
44894- 2 2 6 2 2 6 2 2 6 2 2 6
44895- 6 6 6 90 90 90 54 54 54 18 18 18
44896- 6 6 6 0 0 0 0 0 0 0 0 0
44897- 0 0 0 0 0 0 0 0 0 0 0 0
44898- 0 0 0 0 0 0 0 0 0 0 0 0
44899- 0 0 0 0 0 0 0 0 0 0 0 0
44900- 0 0 0 0 0 0 0 0 0 0 0 0
44901- 0 0 0 0 0 0 0 0 0 0 0 0
44902- 0 0 0 0 0 0 0 0 0 0 0 0
44903- 0 0 0 0 0 0 0 0 0 0 0 0
44904- 0 0 0 0 0 0 0 0 0 0 0 0
44905- 0 0 0 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 10 10 10
44909- 30 30 30 78 78 78 46 46 46 22 22 22
44910-137 92 6 210 162 10 239 182 13 238 190 10
44911-238 202 15 241 208 19 246 215 20 246 215 20
44912-241 208 19 203 166 17 185 133 11 210 150 10
44913-216 158 10 210 150 10 102 78 10 2 2 6
44914- 6 6 6 54 54 54 14 14 14 2 2 6
44915- 2 2 6 62 62 62 74 74 74 30 30 30
44916- 10 10 10 0 0 0 0 0 0 0 0 0
44917- 0 0 0 0 0 0 0 0 0 0 0 0
44918- 0 0 0 0 0 0 0 0 0 0 0 0
44919- 0 0 0 0 0 0 0 0 0 0 0 0
44920- 0 0 0 0 0 0 0 0 0 0 0 0
44921- 0 0 0 0 0 0 0 0 0 0 0 0
44922- 0 0 0 0 0 0 0 0 0 0 0 0
44923- 0 0 0 0 0 0 0 0 0 0 0 0
44924- 0 0 0 0 0 0 0 0 0 0 0 0
44925- 0 0 0 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 10 10 10
44929- 34 34 34 78 78 78 50 50 50 6 6 6
44930- 94 70 30 139 102 15 190 146 13 226 184 13
44931-232 200 30 232 195 16 215 174 15 190 146 13
44932-168 122 10 192 133 9 210 150 10 213 154 11
44933-202 150 34 182 157 106 101 98 89 2 2 6
44934- 2 2 6 78 78 78 116 116 116 58 58 58
44935- 2 2 6 22 22 22 90 90 90 46 46 46
44936- 18 18 18 6 6 6 0 0 0 0 0 0
44937- 0 0 0 0 0 0 0 0 0 0 0 0
44938- 0 0 0 0 0 0 0 0 0 0 0 0
44939- 0 0 0 0 0 0 0 0 0 0 0 0
44940- 0 0 0 0 0 0 0 0 0 0 0 0
44941- 0 0 0 0 0 0 0 0 0 0 0 0
44942- 0 0 0 0 0 0 0 0 0 0 0 0
44943- 0 0 0 0 0 0 0 0 0 0 0 0
44944- 0 0 0 0 0 0 0 0 0 0 0 0
44945- 0 0 0 0 0 0 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 10 10 10
44949- 38 38 38 86 86 86 50 50 50 6 6 6
44950-128 128 128 174 154 114 156 107 11 168 122 10
44951-198 155 10 184 144 12 197 138 11 200 144 11
44952-206 145 10 206 145 10 197 138 11 188 164 115
44953-195 195 195 198 198 198 174 174 174 14 14 14
44954- 2 2 6 22 22 22 116 116 116 116 116 116
44955- 22 22 22 2 2 6 74 74 74 70 70 70
44956- 30 30 30 10 10 10 0 0 0 0 0 0
44957- 0 0 0 0 0 0 0 0 0 0 0 0
44958- 0 0 0 0 0 0 0 0 0 0 0 0
44959- 0 0 0 0 0 0 0 0 0 0 0 0
44960- 0 0 0 0 0 0 0 0 0 0 0 0
44961- 0 0 0 0 0 0 0 0 0 0 0 0
44962- 0 0 0 0 0 0 0 0 0 0 0 0
44963- 0 0 0 0 0 0 0 0 0 0 0 0
44964- 0 0 0 0 0 0 0 0 0 0 0 0
44965- 0 0 0 0 0 0 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 6 6 6 18 18 18
44969- 50 50 50 101 101 101 26 26 26 10 10 10
44970-138 138 138 190 190 190 174 154 114 156 107 11
44971-197 138 11 200 144 11 197 138 11 192 133 9
44972-180 123 7 190 142 34 190 178 144 187 187 187
44973-202 202 202 221 221 221 214 214 214 66 66 66
44974- 2 2 6 2 2 6 50 50 50 62 62 62
44975- 6 6 6 2 2 6 10 10 10 90 90 90
44976- 50 50 50 18 18 18 6 6 6 0 0 0
44977- 0 0 0 0 0 0 0 0 0 0 0 0
44978- 0 0 0 0 0 0 0 0 0 0 0 0
44979- 0 0 0 0 0 0 0 0 0 0 0 0
44980- 0 0 0 0 0 0 0 0 0 0 0 0
44981- 0 0 0 0 0 0 0 0 0 0 0 0
44982- 0 0 0 0 0 0 0 0 0 0 0 0
44983- 0 0 0 0 0 0 0 0 0 0 0 0
44984- 0 0 0 0 0 0 0 0 0 0 0 0
44985- 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
44989- 74 74 74 74 74 74 2 2 6 6 6 6
44990-144 144 144 198 198 198 190 190 190 178 166 146
44991-154 121 60 156 107 11 156 107 11 168 124 44
44992-174 154 114 187 187 187 190 190 190 210 210 210
44993-246 246 246 253 253 253 253 253 253 182 182 182
44994- 6 6 6 2 2 6 2 2 6 2 2 6
44995- 2 2 6 2 2 6 2 2 6 62 62 62
44996- 74 74 74 34 34 34 14 14 14 0 0 0
44997- 0 0 0 0 0 0 0 0 0 0 0 0
44998- 0 0 0 0 0 0 0 0 0 0 0 0
44999- 0 0 0 0 0 0 0 0 0 0 0 0
45000- 0 0 0 0 0 0 0 0 0 0 0 0
45001- 0 0 0 0 0 0 0 0 0 0 0 0
45002- 0 0 0 0 0 0 0 0 0 0 0 0
45003- 0 0 0 0 0 0 0 0 0 0 0 0
45004- 0 0 0 0 0 0 0 0 0 0 0 0
45005- 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
45009- 94 94 94 18 18 18 2 2 6 46 46 46
45010-234 234 234 221 221 221 190 190 190 190 190 190
45011-190 190 190 187 187 187 187 187 187 190 190 190
45012-190 190 190 195 195 195 214 214 214 242 242 242
45013-253 253 253 253 253 253 253 253 253 253 253 253
45014- 82 82 82 2 2 6 2 2 6 2 2 6
45015- 2 2 6 2 2 6 2 2 6 14 14 14
45016- 86 86 86 54 54 54 22 22 22 6 6 6
45017- 0 0 0 0 0 0 0 0 0 0 0 0
45018- 0 0 0 0 0 0 0 0 0 0 0 0
45019- 0 0 0 0 0 0 0 0 0 0 0 0
45020- 0 0 0 0 0 0 0 0 0 0 0 0
45021- 0 0 0 0 0 0 0 0 0 0 0 0
45022- 0 0 0 0 0 0 0 0 0 0 0 0
45023- 0 0 0 0 0 0 0 0 0 0 0 0
45024- 0 0 0 0 0 0 0 0 0 0 0 0
45025- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 18 18 18 46 46 46 90 90 90
45029- 46 46 46 18 18 18 6 6 6 182 182 182
45030-253 253 253 246 246 246 206 206 206 190 190 190
45031-190 190 190 190 190 190 190 190 190 190 190 190
45032-206 206 206 231 231 231 250 250 250 253 253 253
45033-253 253 253 253 253 253 253 253 253 253 253 253
45034-202 202 202 14 14 14 2 2 6 2 2 6
45035- 2 2 6 2 2 6 2 2 6 2 2 6
45036- 42 42 42 86 86 86 42 42 42 18 18 18
45037- 6 6 6 0 0 0 0 0 0 0 0 0
45038- 0 0 0 0 0 0 0 0 0 0 0 0
45039- 0 0 0 0 0 0 0 0 0 0 0 0
45040- 0 0 0 0 0 0 0 0 0 0 0 0
45041- 0 0 0 0 0 0 0 0 0 0 0 0
45042- 0 0 0 0 0 0 0 0 0 0 0 0
45043- 0 0 0 0 0 0 0 0 0 0 0 0
45044- 0 0 0 0 0 0 0 0 0 0 0 0
45045- 0 0 0 0 0 0 0 0 0 0 0 0
45046- 0 0 0 0 0 0 0 0 0 0 0 0
45047- 0 0 0 0 0 0 0 0 0 6 6 6
45048- 14 14 14 38 38 38 74 74 74 66 66 66
45049- 2 2 6 6 6 6 90 90 90 250 250 250
45050-253 253 253 253 253 253 238 238 238 198 198 198
45051-190 190 190 190 190 190 195 195 195 221 221 221
45052-246 246 246 253 253 253 253 253 253 253 253 253
45053-253 253 253 253 253 253 253 253 253 253 253 253
45054-253 253 253 82 82 82 2 2 6 2 2 6
45055- 2 2 6 2 2 6 2 2 6 2 2 6
45056- 2 2 6 78 78 78 70 70 70 34 34 34
45057- 14 14 14 6 6 6 0 0 0 0 0 0
45058- 0 0 0 0 0 0 0 0 0 0 0 0
45059- 0 0 0 0 0 0 0 0 0 0 0 0
45060- 0 0 0 0 0 0 0 0 0 0 0 0
45061- 0 0 0 0 0 0 0 0 0 0 0 0
45062- 0 0 0 0 0 0 0 0 0 0 0 0
45063- 0 0 0 0 0 0 0 0 0 0 0 0
45064- 0 0 0 0 0 0 0 0 0 0 0 0
45065- 0 0 0 0 0 0 0 0 0 0 0 0
45066- 0 0 0 0 0 0 0 0 0 0 0 0
45067- 0 0 0 0 0 0 0 0 0 14 14 14
45068- 34 34 34 66 66 66 78 78 78 6 6 6
45069- 2 2 6 18 18 18 218 218 218 253 253 253
45070-253 253 253 253 253 253 253 253 253 246 246 246
45071-226 226 226 231 231 231 246 246 246 253 253 253
45072-253 253 253 253 253 253 253 253 253 253 253 253
45073-253 253 253 253 253 253 253 253 253 253 253 253
45074-253 253 253 178 178 178 2 2 6 2 2 6
45075- 2 2 6 2 2 6 2 2 6 2 2 6
45076- 2 2 6 18 18 18 90 90 90 62 62 62
45077- 30 30 30 10 10 10 0 0 0 0 0 0
45078- 0 0 0 0 0 0 0 0 0 0 0 0
45079- 0 0 0 0 0 0 0 0 0 0 0 0
45080- 0 0 0 0 0 0 0 0 0 0 0 0
45081- 0 0 0 0 0 0 0 0 0 0 0 0
45082- 0 0 0 0 0 0 0 0 0 0 0 0
45083- 0 0 0 0 0 0 0 0 0 0 0 0
45084- 0 0 0 0 0 0 0 0 0 0 0 0
45085- 0 0 0 0 0 0 0 0 0 0 0 0
45086- 0 0 0 0 0 0 0 0 0 0 0 0
45087- 0 0 0 0 0 0 10 10 10 26 26 26
45088- 58 58 58 90 90 90 18 18 18 2 2 6
45089- 2 2 6 110 110 110 253 253 253 253 253 253
45090-253 253 253 253 253 253 253 253 253 253 253 253
45091-250 250 250 253 253 253 253 253 253 253 253 253
45092-253 253 253 253 253 253 253 253 253 253 253 253
45093-253 253 253 253 253 253 253 253 253 253 253 253
45094-253 253 253 231 231 231 18 18 18 2 2 6
45095- 2 2 6 2 2 6 2 2 6 2 2 6
45096- 2 2 6 2 2 6 18 18 18 94 94 94
45097- 54 54 54 26 26 26 10 10 10 0 0 0
45098- 0 0 0 0 0 0 0 0 0 0 0 0
45099- 0 0 0 0 0 0 0 0 0 0 0 0
45100- 0 0 0 0 0 0 0 0 0 0 0 0
45101- 0 0 0 0 0 0 0 0 0 0 0 0
45102- 0 0 0 0 0 0 0 0 0 0 0 0
45103- 0 0 0 0 0 0 0 0 0 0 0 0
45104- 0 0 0 0 0 0 0 0 0 0 0 0
45105- 0 0 0 0 0 0 0 0 0 0 0 0
45106- 0 0 0 0 0 0 0 0 0 0 0 0
45107- 0 0 0 6 6 6 22 22 22 50 50 50
45108- 90 90 90 26 26 26 2 2 6 2 2 6
45109- 14 14 14 195 195 195 250 250 250 253 253 253
45110-253 253 253 253 253 253 253 253 253 253 253 253
45111-253 253 253 253 253 253 253 253 253 253 253 253
45112-253 253 253 253 253 253 253 253 253 253 253 253
45113-253 253 253 253 253 253 253 253 253 253 253 253
45114-250 250 250 242 242 242 54 54 54 2 2 6
45115- 2 2 6 2 2 6 2 2 6 2 2 6
45116- 2 2 6 2 2 6 2 2 6 38 38 38
45117- 86 86 86 50 50 50 22 22 22 6 6 6
45118- 0 0 0 0 0 0 0 0 0 0 0 0
45119- 0 0 0 0 0 0 0 0 0 0 0 0
45120- 0 0 0 0 0 0 0 0 0 0 0 0
45121- 0 0 0 0 0 0 0 0 0 0 0 0
45122- 0 0 0 0 0 0 0 0 0 0 0 0
45123- 0 0 0 0 0 0 0 0 0 0 0 0
45124- 0 0 0 0 0 0 0 0 0 0 0 0
45125- 0 0 0 0 0 0 0 0 0 0 0 0
45126- 0 0 0 0 0 0 0 0 0 0 0 0
45127- 6 6 6 14 14 14 38 38 38 82 82 82
45128- 34 34 34 2 2 6 2 2 6 2 2 6
45129- 42 42 42 195 195 195 246 246 246 253 253 253
45130-253 253 253 253 253 253 253 253 253 250 250 250
45131-242 242 242 242 242 242 250 250 250 253 253 253
45132-253 253 253 253 253 253 253 253 253 253 253 253
45133-253 253 253 250 250 250 246 246 246 238 238 238
45134-226 226 226 231 231 231 101 101 101 6 6 6
45135- 2 2 6 2 2 6 2 2 6 2 2 6
45136- 2 2 6 2 2 6 2 2 6 2 2 6
45137- 38 38 38 82 82 82 42 42 42 14 14 14
45138- 6 6 6 0 0 0 0 0 0 0 0 0
45139- 0 0 0 0 0 0 0 0 0 0 0 0
45140- 0 0 0 0 0 0 0 0 0 0 0 0
45141- 0 0 0 0 0 0 0 0 0 0 0 0
45142- 0 0 0 0 0 0 0 0 0 0 0 0
45143- 0 0 0 0 0 0 0 0 0 0 0 0
45144- 0 0 0 0 0 0 0 0 0 0 0 0
45145- 0 0 0 0 0 0 0 0 0 0 0 0
45146- 0 0 0 0 0 0 0 0 0 0 0 0
45147- 10 10 10 26 26 26 62 62 62 66 66 66
45148- 2 2 6 2 2 6 2 2 6 6 6 6
45149- 70 70 70 170 170 170 206 206 206 234 234 234
45150-246 246 246 250 250 250 250 250 250 238 238 238
45151-226 226 226 231 231 231 238 238 238 250 250 250
45152-250 250 250 250 250 250 246 246 246 231 231 231
45153-214 214 214 206 206 206 202 202 202 202 202 202
45154-198 198 198 202 202 202 182 182 182 18 18 18
45155- 2 2 6 2 2 6 2 2 6 2 2 6
45156- 2 2 6 2 2 6 2 2 6 2 2 6
45157- 2 2 6 62 62 62 66 66 66 30 30 30
45158- 10 10 10 0 0 0 0 0 0 0 0 0
45159- 0 0 0 0 0 0 0 0 0 0 0 0
45160- 0 0 0 0 0 0 0 0 0 0 0 0
45161- 0 0 0 0 0 0 0 0 0 0 0 0
45162- 0 0 0 0 0 0 0 0 0 0 0 0
45163- 0 0 0 0 0 0 0 0 0 0 0 0
45164- 0 0 0 0 0 0 0 0 0 0 0 0
45165- 0 0 0 0 0 0 0 0 0 0 0 0
45166- 0 0 0 0 0 0 0 0 0 0 0 0
45167- 14 14 14 42 42 42 82 82 82 18 18 18
45168- 2 2 6 2 2 6 2 2 6 10 10 10
45169- 94 94 94 182 182 182 218 218 218 242 242 242
45170-250 250 250 253 253 253 253 253 253 250 250 250
45171-234 234 234 253 253 253 253 253 253 253 253 253
45172-253 253 253 253 253 253 253 253 253 246 246 246
45173-238 238 238 226 226 226 210 210 210 202 202 202
45174-195 195 195 195 195 195 210 210 210 158 158 158
45175- 6 6 6 14 14 14 50 50 50 14 14 14
45176- 2 2 6 2 2 6 2 2 6 2 2 6
45177- 2 2 6 6 6 6 86 86 86 46 46 46
45178- 18 18 18 6 6 6 0 0 0 0 0 0
45179- 0 0 0 0 0 0 0 0 0 0 0 0
45180- 0 0 0 0 0 0 0 0 0 0 0 0
45181- 0 0 0 0 0 0 0 0 0 0 0 0
45182- 0 0 0 0 0 0 0 0 0 0 0 0
45183- 0 0 0 0 0 0 0 0 0 0 0 0
45184- 0 0 0 0 0 0 0 0 0 0 0 0
45185- 0 0 0 0 0 0 0 0 0 0 0 0
45186- 0 0 0 0 0 0 0 0 0 6 6 6
45187- 22 22 22 54 54 54 70 70 70 2 2 6
45188- 2 2 6 10 10 10 2 2 6 22 22 22
45189-166 166 166 231 231 231 250 250 250 253 253 253
45190-253 253 253 253 253 253 253 253 253 250 250 250
45191-242 242 242 253 253 253 253 253 253 253 253 253
45192-253 253 253 253 253 253 253 253 253 253 253 253
45193-253 253 253 253 253 253 253 253 253 246 246 246
45194-231 231 231 206 206 206 198 198 198 226 226 226
45195- 94 94 94 2 2 6 6 6 6 38 38 38
45196- 30 30 30 2 2 6 2 2 6 2 2 6
45197- 2 2 6 2 2 6 62 62 62 66 66 66
45198- 26 26 26 10 10 10 0 0 0 0 0 0
45199- 0 0 0 0 0 0 0 0 0 0 0 0
45200- 0 0 0 0 0 0 0 0 0 0 0 0
45201- 0 0 0 0 0 0 0 0 0 0 0 0
45202- 0 0 0 0 0 0 0 0 0 0 0 0
45203- 0 0 0 0 0 0 0 0 0 0 0 0
45204- 0 0 0 0 0 0 0 0 0 0 0 0
45205- 0 0 0 0 0 0 0 0 0 0 0 0
45206- 0 0 0 0 0 0 0 0 0 10 10 10
45207- 30 30 30 74 74 74 50 50 50 2 2 6
45208- 26 26 26 26 26 26 2 2 6 106 106 106
45209-238 238 238 253 253 253 253 253 253 253 253 253
45210-253 253 253 253 253 253 253 253 253 253 253 253
45211-253 253 253 253 253 253 253 253 253 253 253 253
45212-253 253 253 253 253 253 253 253 253 253 253 253
45213-253 253 253 253 253 253 253 253 253 253 253 253
45214-253 253 253 246 246 246 218 218 218 202 202 202
45215-210 210 210 14 14 14 2 2 6 2 2 6
45216- 30 30 30 22 22 22 2 2 6 2 2 6
45217- 2 2 6 2 2 6 18 18 18 86 86 86
45218- 42 42 42 14 14 14 0 0 0 0 0 0
45219- 0 0 0 0 0 0 0 0 0 0 0 0
45220- 0 0 0 0 0 0 0 0 0 0 0 0
45221- 0 0 0 0 0 0 0 0 0 0 0 0
45222- 0 0 0 0 0 0 0 0 0 0 0 0
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 0 0 0 0 0 0 0 0 0 0 0 0
45225- 0 0 0 0 0 0 0 0 0 0 0 0
45226- 0 0 0 0 0 0 0 0 0 14 14 14
45227- 42 42 42 90 90 90 22 22 22 2 2 6
45228- 42 42 42 2 2 6 18 18 18 218 218 218
45229-253 253 253 253 253 253 253 253 253 253 253 253
45230-253 253 253 253 253 253 253 253 253 253 253 253
45231-253 253 253 253 253 253 253 253 253 253 253 253
45232-253 253 253 253 253 253 253 253 253 253 253 253
45233-253 253 253 253 253 253 253 253 253 253 253 253
45234-253 253 253 253 253 253 250 250 250 221 221 221
45235-218 218 218 101 101 101 2 2 6 14 14 14
45236- 18 18 18 38 38 38 10 10 10 2 2 6
45237- 2 2 6 2 2 6 2 2 6 78 78 78
45238- 58 58 58 22 22 22 6 6 6 0 0 0
45239- 0 0 0 0 0 0 0 0 0 0 0 0
45240- 0 0 0 0 0 0 0 0 0 0 0 0
45241- 0 0 0 0 0 0 0 0 0 0 0 0
45242- 0 0 0 0 0 0 0 0 0 0 0 0
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 0 0 0 0 0 0 0 0 0 0 0 0
45245- 0 0 0 0 0 0 0 0 0 0 0 0
45246- 0 0 0 0 0 0 6 6 6 18 18 18
45247- 54 54 54 82 82 82 2 2 6 26 26 26
45248- 22 22 22 2 2 6 123 123 123 253 253 253
45249-253 253 253 253 253 253 253 253 253 253 253 253
45250-253 253 253 253 253 253 253 253 253 253 253 253
45251-253 253 253 253 253 253 253 253 253 253 253 253
45252-253 253 253 253 253 253 253 253 253 253 253 253
45253-253 253 253 253 253 253 253 253 253 253 253 253
45254-253 253 253 253 253 253 253 253 253 250 250 250
45255-238 238 238 198 198 198 6 6 6 38 38 38
45256- 58 58 58 26 26 26 38 38 38 2 2 6
45257- 2 2 6 2 2 6 2 2 6 46 46 46
45258- 78 78 78 30 30 30 10 10 10 0 0 0
45259- 0 0 0 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 0 0 0 0 0 0 0 0 0 0
45262- 0 0 0 0 0 0 0 0 0 0 0 0
45263- 0 0 0 0 0 0 0 0 0 0 0 0
45264- 0 0 0 0 0 0 0 0 0 0 0 0
45265- 0 0 0 0 0 0 0 0 0 0 0 0
45266- 0 0 0 0 0 0 10 10 10 30 30 30
45267- 74 74 74 58 58 58 2 2 6 42 42 42
45268- 2 2 6 22 22 22 231 231 231 253 253 253
45269-253 253 253 253 253 253 253 253 253 253 253 253
45270-253 253 253 253 253 253 253 253 253 250 250 250
45271-253 253 253 253 253 253 253 253 253 253 253 253
45272-253 253 253 253 253 253 253 253 253 253 253 253
45273-253 253 253 253 253 253 253 253 253 253 253 253
45274-253 253 253 253 253 253 253 253 253 253 253 253
45275-253 253 253 246 246 246 46 46 46 38 38 38
45276- 42 42 42 14 14 14 38 38 38 14 14 14
45277- 2 2 6 2 2 6 2 2 6 6 6 6
45278- 86 86 86 46 46 46 14 14 14 0 0 0
45279- 0 0 0 0 0 0 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 0 0 0 0 0 0
45283- 0 0 0 0 0 0 0 0 0 0 0 0
45284- 0 0 0 0 0 0 0 0 0 0 0 0
45285- 0 0 0 0 0 0 0 0 0 0 0 0
45286- 0 0 0 6 6 6 14 14 14 42 42 42
45287- 90 90 90 18 18 18 18 18 18 26 26 26
45288- 2 2 6 116 116 116 253 253 253 253 253 253
45289-253 253 253 253 253 253 253 253 253 253 253 253
45290-253 253 253 253 253 253 250 250 250 238 238 238
45291-253 253 253 253 253 253 253 253 253 253 253 253
45292-253 253 253 253 253 253 253 253 253 253 253 253
45293-253 253 253 253 253 253 253 253 253 253 253 253
45294-253 253 253 253 253 253 253 253 253 253 253 253
45295-253 253 253 253 253 253 94 94 94 6 6 6
45296- 2 2 6 2 2 6 10 10 10 34 34 34
45297- 2 2 6 2 2 6 2 2 6 2 2 6
45298- 74 74 74 58 58 58 22 22 22 6 6 6
45299- 0 0 0 0 0 0 0 0 0 0 0 0
45300- 0 0 0 0 0 0 0 0 0 0 0 0
45301- 0 0 0 0 0 0 0 0 0 0 0 0
45302- 0 0 0 0 0 0 0 0 0 0 0 0
45303- 0 0 0 0 0 0 0 0 0 0 0 0
45304- 0 0 0 0 0 0 0 0 0 0 0 0
45305- 0 0 0 0 0 0 0 0 0 0 0 0
45306- 0 0 0 10 10 10 26 26 26 66 66 66
45307- 82 82 82 2 2 6 38 38 38 6 6 6
45308- 14 14 14 210 210 210 253 253 253 253 253 253
45309-253 253 253 253 253 253 253 253 253 253 253 253
45310-253 253 253 253 253 253 246 246 246 242 242 242
45311-253 253 253 253 253 253 253 253 253 253 253 253
45312-253 253 253 253 253 253 253 253 253 253 253 253
45313-253 253 253 253 253 253 253 253 253 253 253 253
45314-253 253 253 253 253 253 253 253 253 253 253 253
45315-253 253 253 253 253 253 144 144 144 2 2 6
45316- 2 2 6 2 2 6 2 2 6 46 46 46
45317- 2 2 6 2 2 6 2 2 6 2 2 6
45318- 42 42 42 74 74 74 30 30 30 10 10 10
45319- 0 0 0 0 0 0 0 0 0 0 0 0
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 0 0 0 0 0 0 0 0 0 0
45322- 0 0 0 0 0 0 0 0 0 0 0 0
45323- 0 0 0 0 0 0 0 0 0 0 0 0
45324- 0 0 0 0 0 0 0 0 0 0 0 0
45325- 0 0 0 0 0 0 0 0 0 0 0 0
45326- 6 6 6 14 14 14 42 42 42 90 90 90
45327- 26 26 26 6 6 6 42 42 42 2 2 6
45328- 74 74 74 250 250 250 253 253 253 253 253 253
45329-253 253 253 253 253 253 253 253 253 253 253 253
45330-253 253 253 253 253 253 242 242 242 242 242 242
45331-253 253 253 253 253 253 253 253 253 253 253 253
45332-253 253 253 253 253 253 253 253 253 253 253 253
45333-253 253 253 253 253 253 253 253 253 253 253 253
45334-253 253 253 253 253 253 253 253 253 253 253 253
45335-253 253 253 253 253 253 182 182 182 2 2 6
45336- 2 2 6 2 2 6 2 2 6 46 46 46
45337- 2 2 6 2 2 6 2 2 6 2 2 6
45338- 10 10 10 86 86 86 38 38 38 10 10 10
45339- 0 0 0 0 0 0 0 0 0 0 0 0
45340- 0 0 0 0 0 0 0 0 0 0 0 0
45341- 0 0 0 0 0 0 0 0 0 0 0 0
45342- 0 0 0 0 0 0 0 0 0 0 0 0
45343- 0 0 0 0 0 0 0 0 0 0 0 0
45344- 0 0 0 0 0 0 0 0 0 0 0 0
45345- 0 0 0 0 0 0 0 0 0 0 0 0
45346- 10 10 10 26 26 26 66 66 66 82 82 82
45347- 2 2 6 22 22 22 18 18 18 2 2 6
45348-149 149 149 253 253 253 253 253 253 253 253 253
45349-253 253 253 253 253 253 253 253 253 253 253 253
45350-253 253 253 253 253 253 234 234 234 242 242 242
45351-253 253 253 253 253 253 253 253 253 253 253 253
45352-253 253 253 253 253 253 253 253 253 253 253 253
45353-253 253 253 253 253 253 253 253 253 253 253 253
45354-253 253 253 253 253 253 253 253 253 253 253 253
45355-253 253 253 253 253 253 206 206 206 2 2 6
45356- 2 2 6 2 2 6 2 2 6 38 38 38
45357- 2 2 6 2 2 6 2 2 6 2 2 6
45358- 6 6 6 86 86 86 46 46 46 14 14 14
45359- 0 0 0 0 0 0 0 0 0 0 0 0
45360- 0 0 0 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 0 0 0 0 0 0 0 0 0 0 0 0
45363- 0 0 0 0 0 0 0 0 0 0 0 0
45364- 0 0 0 0 0 0 0 0 0 0 0 0
45365- 0 0 0 0 0 0 0 0 0 6 6 6
45366- 18 18 18 46 46 46 86 86 86 18 18 18
45367- 2 2 6 34 34 34 10 10 10 6 6 6
45368-210 210 210 253 253 253 253 253 253 253 253 253
45369-253 253 253 253 253 253 253 253 253 253 253 253
45370-253 253 253 253 253 253 234 234 234 242 242 242
45371-253 253 253 253 253 253 253 253 253 253 253 253
45372-253 253 253 253 253 253 253 253 253 253 253 253
45373-253 253 253 253 253 253 253 253 253 253 253 253
45374-253 253 253 253 253 253 253 253 253 253 253 253
45375-253 253 253 253 253 253 221 221 221 6 6 6
45376- 2 2 6 2 2 6 6 6 6 30 30 30
45377- 2 2 6 2 2 6 2 2 6 2 2 6
45378- 2 2 6 82 82 82 54 54 54 18 18 18
45379- 6 6 6 0 0 0 0 0 0 0 0 0
45380- 0 0 0 0 0 0 0 0 0 0 0 0
45381- 0 0 0 0 0 0 0 0 0 0 0 0
45382- 0 0 0 0 0 0 0 0 0 0 0 0
45383- 0 0 0 0 0 0 0 0 0 0 0 0
45384- 0 0 0 0 0 0 0 0 0 0 0 0
45385- 0 0 0 0 0 0 0 0 0 10 10 10
45386- 26 26 26 66 66 66 62 62 62 2 2 6
45387- 2 2 6 38 38 38 10 10 10 26 26 26
45388-238 238 238 253 253 253 253 253 253 253 253 253
45389-253 253 253 253 253 253 253 253 253 253 253 253
45390-253 253 253 253 253 253 231 231 231 238 238 238
45391-253 253 253 253 253 253 253 253 253 253 253 253
45392-253 253 253 253 253 253 253 253 253 253 253 253
45393-253 253 253 253 253 253 253 253 253 253 253 253
45394-253 253 253 253 253 253 253 253 253 253 253 253
45395-253 253 253 253 253 253 231 231 231 6 6 6
45396- 2 2 6 2 2 6 10 10 10 30 30 30
45397- 2 2 6 2 2 6 2 2 6 2 2 6
45398- 2 2 6 66 66 66 58 58 58 22 22 22
45399- 6 6 6 0 0 0 0 0 0 0 0 0
45400- 0 0 0 0 0 0 0 0 0 0 0 0
45401- 0 0 0 0 0 0 0 0 0 0 0 0
45402- 0 0 0 0 0 0 0 0 0 0 0 0
45403- 0 0 0 0 0 0 0 0 0 0 0 0
45404- 0 0 0 0 0 0 0 0 0 0 0 0
45405- 0 0 0 0 0 0 0 0 0 10 10 10
45406- 38 38 38 78 78 78 6 6 6 2 2 6
45407- 2 2 6 46 46 46 14 14 14 42 42 42
45408-246 246 246 253 253 253 253 253 253 253 253 253
45409-253 253 253 253 253 253 253 253 253 253 253 253
45410-253 253 253 253 253 253 231 231 231 242 242 242
45411-253 253 253 253 253 253 253 253 253 253 253 253
45412-253 253 253 253 253 253 253 253 253 253 253 253
45413-253 253 253 253 253 253 253 253 253 253 253 253
45414-253 253 253 253 253 253 253 253 253 253 253 253
45415-253 253 253 253 253 253 234 234 234 10 10 10
45416- 2 2 6 2 2 6 22 22 22 14 14 14
45417- 2 2 6 2 2 6 2 2 6 2 2 6
45418- 2 2 6 66 66 66 62 62 62 22 22 22
45419- 6 6 6 0 0 0 0 0 0 0 0 0
45420- 0 0 0 0 0 0 0 0 0 0 0 0
45421- 0 0 0 0 0 0 0 0 0 0 0 0
45422- 0 0 0 0 0 0 0 0 0 0 0 0
45423- 0 0 0 0 0 0 0 0 0 0 0 0
45424- 0 0 0 0 0 0 0 0 0 0 0 0
45425- 0 0 0 0 0 0 6 6 6 18 18 18
45426- 50 50 50 74 74 74 2 2 6 2 2 6
45427- 14 14 14 70 70 70 34 34 34 62 62 62
45428-250 250 250 253 253 253 253 253 253 253 253 253
45429-253 253 253 253 253 253 253 253 253 253 253 253
45430-253 253 253 253 253 253 231 231 231 246 246 246
45431-253 253 253 253 253 253 253 253 253 253 253 253
45432-253 253 253 253 253 253 253 253 253 253 253 253
45433-253 253 253 253 253 253 253 253 253 253 253 253
45434-253 253 253 253 253 253 253 253 253 253 253 253
45435-253 253 253 253 253 253 234 234 234 14 14 14
45436- 2 2 6 2 2 6 30 30 30 2 2 6
45437- 2 2 6 2 2 6 2 2 6 2 2 6
45438- 2 2 6 66 66 66 62 62 62 22 22 22
45439- 6 6 6 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 0 0 0 0 0 0 0 0 0 0
45442- 0 0 0 0 0 0 0 0 0 0 0 0
45443- 0 0 0 0 0 0 0 0 0 0 0 0
45444- 0 0 0 0 0 0 0 0 0 0 0 0
45445- 0 0 0 0 0 0 6 6 6 18 18 18
45446- 54 54 54 62 62 62 2 2 6 2 2 6
45447- 2 2 6 30 30 30 46 46 46 70 70 70
45448-250 250 250 253 253 253 253 253 253 253 253 253
45449-253 253 253 253 253 253 253 253 253 253 253 253
45450-253 253 253 253 253 253 231 231 231 246 246 246
45451-253 253 253 253 253 253 253 253 253 253 253 253
45452-253 253 253 253 253 253 253 253 253 253 253 253
45453-253 253 253 253 253 253 253 253 253 253 253 253
45454-253 253 253 253 253 253 253 253 253 253 253 253
45455-253 253 253 253 253 253 226 226 226 10 10 10
45456- 2 2 6 6 6 6 30 30 30 2 2 6
45457- 2 2 6 2 2 6 2 2 6 2 2 6
45458- 2 2 6 66 66 66 58 58 58 22 22 22
45459- 6 6 6 0 0 0 0 0 0 0 0 0
45460- 0 0 0 0 0 0 0 0 0 0 0 0
45461- 0 0 0 0 0 0 0 0 0 0 0 0
45462- 0 0 0 0 0 0 0 0 0 0 0 0
45463- 0 0 0 0 0 0 0 0 0 0 0 0
45464- 0 0 0 0 0 0 0 0 0 0 0 0
45465- 0 0 0 0 0 0 6 6 6 22 22 22
45466- 58 58 58 62 62 62 2 2 6 2 2 6
45467- 2 2 6 2 2 6 30 30 30 78 78 78
45468-250 250 250 253 253 253 253 253 253 253 253 253
45469-253 253 253 253 253 253 253 253 253 253 253 253
45470-253 253 253 253 253 253 231 231 231 246 246 246
45471-253 253 253 253 253 253 253 253 253 253 253 253
45472-253 253 253 253 253 253 253 253 253 253 253 253
45473-253 253 253 253 253 253 253 253 253 253 253 253
45474-253 253 253 253 253 253 253 253 253 253 253 253
45475-253 253 253 253 253 253 206 206 206 2 2 6
45476- 22 22 22 34 34 34 18 14 6 22 22 22
45477- 26 26 26 18 18 18 6 6 6 2 2 6
45478- 2 2 6 82 82 82 54 54 54 18 18 18
45479- 6 6 6 0 0 0 0 0 0 0 0 0
45480- 0 0 0 0 0 0 0 0 0 0 0 0
45481- 0 0 0 0 0 0 0 0 0 0 0 0
45482- 0 0 0 0 0 0 0 0 0 0 0 0
45483- 0 0 0 0 0 0 0 0 0 0 0 0
45484- 0 0 0 0 0 0 0 0 0 0 0 0
45485- 0 0 0 0 0 0 6 6 6 26 26 26
45486- 62 62 62 106 106 106 74 54 14 185 133 11
45487-210 162 10 121 92 8 6 6 6 62 62 62
45488-238 238 238 253 253 253 253 253 253 253 253 253
45489-253 253 253 253 253 253 253 253 253 253 253 253
45490-253 253 253 253 253 253 231 231 231 246 246 246
45491-253 253 253 253 253 253 253 253 253 253 253 253
45492-253 253 253 253 253 253 253 253 253 253 253 253
45493-253 253 253 253 253 253 253 253 253 253 253 253
45494-253 253 253 253 253 253 253 253 253 253 253 253
45495-253 253 253 253 253 253 158 158 158 18 18 18
45496- 14 14 14 2 2 6 2 2 6 2 2 6
45497- 6 6 6 18 18 18 66 66 66 38 38 38
45498- 6 6 6 94 94 94 50 50 50 18 18 18
45499- 6 6 6 0 0 0 0 0 0 0 0 0
45500- 0 0 0 0 0 0 0 0 0 0 0 0
45501- 0 0 0 0 0 0 0 0 0 0 0 0
45502- 0 0 0 0 0 0 0 0 0 0 0 0
45503- 0 0 0 0 0 0 0 0 0 0 0 0
45504- 0 0 0 0 0 0 0 0 0 6 6 6
45505- 10 10 10 10 10 10 18 18 18 38 38 38
45506- 78 78 78 142 134 106 216 158 10 242 186 14
45507-246 190 14 246 190 14 156 118 10 10 10 10
45508- 90 90 90 238 238 238 253 253 253 253 253 253
45509-253 253 253 253 253 253 253 253 253 253 253 253
45510-253 253 253 253 253 253 231 231 231 250 250 250
45511-253 253 253 253 253 253 253 253 253 253 253 253
45512-253 253 253 253 253 253 253 253 253 253 253 253
45513-253 253 253 253 253 253 253 253 253 253 253 253
45514-253 253 253 253 253 253 253 253 253 246 230 190
45515-238 204 91 238 204 91 181 142 44 37 26 9
45516- 2 2 6 2 2 6 2 2 6 2 2 6
45517- 2 2 6 2 2 6 38 38 38 46 46 46
45518- 26 26 26 106 106 106 54 54 54 18 18 18
45519- 6 6 6 0 0 0 0 0 0 0 0 0
45520- 0 0 0 0 0 0 0 0 0 0 0 0
45521- 0 0 0 0 0 0 0 0 0 0 0 0
45522- 0 0 0 0 0 0 0 0 0 0 0 0
45523- 0 0 0 0 0 0 0 0 0 0 0 0
45524- 0 0 0 6 6 6 14 14 14 22 22 22
45525- 30 30 30 38 38 38 50 50 50 70 70 70
45526-106 106 106 190 142 34 226 170 11 242 186 14
45527-246 190 14 246 190 14 246 190 14 154 114 10
45528- 6 6 6 74 74 74 226 226 226 253 253 253
45529-253 253 253 253 253 253 253 253 253 253 253 253
45530-253 253 253 253 253 253 231 231 231 250 250 250
45531-253 253 253 253 253 253 253 253 253 253 253 253
45532-253 253 253 253 253 253 253 253 253 253 253 253
45533-253 253 253 253 253 253 253 253 253 253 253 253
45534-253 253 253 253 253 253 253 253 253 228 184 62
45535-241 196 14 241 208 19 232 195 16 38 30 10
45536- 2 2 6 2 2 6 2 2 6 2 2 6
45537- 2 2 6 6 6 6 30 30 30 26 26 26
45538-203 166 17 154 142 90 66 66 66 26 26 26
45539- 6 6 6 0 0 0 0 0 0 0 0 0
45540- 0 0 0 0 0 0 0 0 0 0 0 0
45541- 0 0 0 0 0 0 0 0 0 0 0 0
45542- 0 0 0 0 0 0 0 0 0 0 0 0
45543- 0 0 0 0 0 0 0 0 0 0 0 0
45544- 6 6 6 18 18 18 38 38 38 58 58 58
45545- 78 78 78 86 86 86 101 101 101 123 123 123
45546-175 146 61 210 150 10 234 174 13 246 186 14
45547-246 190 14 246 190 14 246 190 14 238 190 10
45548-102 78 10 2 2 6 46 46 46 198 198 198
45549-253 253 253 253 253 253 253 253 253 253 253 253
45550-253 253 253 253 253 253 234 234 234 242 242 242
45551-253 253 253 253 253 253 253 253 253 253 253 253
45552-253 253 253 253 253 253 253 253 253 253 253 253
45553-253 253 253 253 253 253 253 253 253 253 253 253
45554-253 253 253 253 253 253 253 253 253 224 178 62
45555-242 186 14 241 196 14 210 166 10 22 18 6
45556- 2 2 6 2 2 6 2 2 6 2 2 6
45557- 2 2 6 2 2 6 6 6 6 121 92 8
45558-238 202 15 232 195 16 82 82 82 34 34 34
45559- 10 10 10 0 0 0 0 0 0 0 0 0
45560- 0 0 0 0 0 0 0 0 0 0 0 0
45561- 0 0 0 0 0 0 0 0 0 0 0 0
45562- 0 0 0 0 0 0 0 0 0 0 0 0
45563- 0 0 0 0 0 0 0 0 0 0 0 0
45564- 14 14 14 38 38 38 70 70 70 154 122 46
45565-190 142 34 200 144 11 197 138 11 197 138 11
45566-213 154 11 226 170 11 242 186 14 246 190 14
45567-246 190 14 246 190 14 246 190 14 246 190 14
45568-225 175 15 46 32 6 2 2 6 22 22 22
45569-158 158 158 250 250 250 253 253 253 253 253 253
45570-253 253 253 253 253 253 253 253 253 253 253 253
45571-253 253 253 253 253 253 253 253 253 253 253 253
45572-253 253 253 253 253 253 253 253 253 253 253 253
45573-253 253 253 253 253 253 253 253 253 253 253 253
45574-253 253 253 250 250 250 242 242 242 224 178 62
45575-239 182 13 236 186 11 213 154 11 46 32 6
45576- 2 2 6 2 2 6 2 2 6 2 2 6
45577- 2 2 6 2 2 6 61 42 6 225 175 15
45578-238 190 10 236 186 11 112 100 78 42 42 42
45579- 14 14 14 0 0 0 0 0 0 0 0 0
45580- 0 0 0 0 0 0 0 0 0 0 0 0
45581- 0 0 0 0 0 0 0 0 0 0 0 0
45582- 0 0 0 0 0 0 0 0 0 0 0 0
45583- 0 0 0 0 0 0 0 0 0 6 6 6
45584- 22 22 22 54 54 54 154 122 46 213 154 11
45585-226 170 11 230 174 11 226 170 11 226 170 11
45586-236 178 12 242 186 14 246 190 14 246 190 14
45587-246 190 14 246 190 14 246 190 14 246 190 14
45588-241 196 14 184 144 12 10 10 10 2 2 6
45589- 6 6 6 116 116 116 242 242 242 253 253 253
45590-253 253 253 253 253 253 253 253 253 253 253 253
45591-253 253 253 253 253 253 253 253 253 253 253 253
45592-253 253 253 253 253 253 253 253 253 253 253 253
45593-253 253 253 253 253 253 253 253 253 253 253 253
45594-253 253 253 231 231 231 198 198 198 214 170 54
45595-236 178 12 236 178 12 210 150 10 137 92 6
45596- 18 14 6 2 2 6 2 2 6 2 2 6
45597- 6 6 6 70 47 6 200 144 11 236 178 12
45598-239 182 13 239 182 13 124 112 88 58 58 58
45599- 22 22 22 6 6 6 0 0 0 0 0 0
45600- 0 0 0 0 0 0 0 0 0 0 0 0
45601- 0 0 0 0 0 0 0 0 0 0 0 0
45602- 0 0 0 0 0 0 0 0 0 0 0 0
45603- 0 0 0 0 0 0 0 0 0 10 10 10
45604- 30 30 30 70 70 70 180 133 36 226 170 11
45605-239 182 13 242 186 14 242 186 14 246 186 14
45606-246 190 14 246 190 14 246 190 14 246 190 14
45607-246 190 14 246 190 14 246 190 14 246 190 14
45608-246 190 14 232 195 16 98 70 6 2 2 6
45609- 2 2 6 2 2 6 66 66 66 221 221 221
45610-253 253 253 253 253 253 253 253 253 253 253 253
45611-253 253 253 253 253 253 253 253 253 253 253 253
45612-253 253 253 253 253 253 253 253 253 253 253 253
45613-253 253 253 253 253 253 253 253 253 253 253 253
45614-253 253 253 206 206 206 198 198 198 214 166 58
45615-230 174 11 230 174 11 216 158 10 192 133 9
45616-163 110 8 116 81 8 102 78 10 116 81 8
45617-167 114 7 197 138 11 226 170 11 239 182 13
45618-242 186 14 242 186 14 162 146 94 78 78 78
45619- 34 34 34 14 14 14 6 6 6 0 0 0
45620- 0 0 0 0 0 0 0 0 0 0 0 0
45621- 0 0 0 0 0 0 0 0 0 0 0 0
45622- 0 0 0 0 0 0 0 0 0 0 0 0
45623- 0 0 0 0 0 0 0 0 0 6 6 6
45624- 30 30 30 78 78 78 190 142 34 226 170 11
45625-239 182 13 246 190 14 246 190 14 246 190 14
45626-246 190 14 246 190 14 246 190 14 246 190 14
45627-246 190 14 246 190 14 246 190 14 246 190 14
45628-246 190 14 241 196 14 203 166 17 22 18 6
45629- 2 2 6 2 2 6 2 2 6 38 38 38
45630-218 218 218 253 253 253 253 253 253 253 253 253
45631-253 253 253 253 253 253 253 253 253 253 253 253
45632-253 253 253 253 253 253 253 253 253 253 253 253
45633-253 253 253 253 253 253 253 253 253 253 253 253
45634-250 250 250 206 206 206 198 198 198 202 162 69
45635-226 170 11 236 178 12 224 166 10 210 150 10
45636-200 144 11 197 138 11 192 133 9 197 138 11
45637-210 150 10 226 170 11 242 186 14 246 190 14
45638-246 190 14 246 186 14 225 175 15 124 112 88
45639- 62 62 62 30 30 30 14 14 14 6 6 6
45640- 0 0 0 0 0 0 0 0 0 0 0 0
45641- 0 0 0 0 0 0 0 0 0 0 0 0
45642- 0 0 0 0 0 0 0 0 0 0 0 0
45643- 0 0 0 0 0 0 0 0 0 10 10 10
45644- 30 30 30 78 78 78 174 135 50 224 166 10
45645-239 182 13 246 190 14 246 190 14 246 190 14
45646-246 190 14 246 190 14 246 190 14 246 190 14
45647-246 190 14 246 190 14 246 190 14 246 190 14
45648-246 190 14 246 190 14 241 196 14 139 102 15
45649- 2 2 6 2 2 6 2 2 6 2 2 6
45650- 78 78 78 250 250 250 253 253 253 253 253 253
45651-253 253 253 253 253 253 253 253 253 253 253 253
45652-253 253 253 253 253 253 253 253 253 253 253 253
45653-253 253 253 253 253 253 253 253 253 253 253 253
45654-250 250 250 214 214 214 198 198 198 190 150 46
45655-219 162 10 236 178 12 234 174 13 224 166 10
45656-216 158 10 213 154 11 213 154 11 216 158 10
45657-226 170 11 239 182 13 246 190 14 246 190 14
45658-246 190 14 246 190 14 242 186 14 206 162 42
45659-101 101 101 58 58 58 30 30 30 14 14 14
45660- 6 6 6 0 0 0 0 0 0 0 0 0
45661- 0 0 0 0 0 0 0 0 0 0 0 0
45662- 0 0 0 0 0 0 0 0 0 0 0 0
45663- 0 0 0 0 0 0 0 0 0 10 10 10
45664- 30 30 30 74 74 74 174 135 50 216 158 10
45665-236 178 12 246 190 14 246 190 14 246 190 14
45666-246 190 14 246 190 14 246 190 14 246 190 14
45667-246 190 14 246 190 14 246 190 14 246 190 14
45668-246 190 14 246 190 14 241 196 14 226 184 13
45669- 61 42 6 2 2 6 2 2 6 2 2 6
45670- 22 22 22 238 238 238 253 253 253 253 253 253
45671-253 253 253 253 253 253 253 253 253 253 253 253
45672-253 253 253 253 253 253 253 253 253 253 253 253
45673-253 253 253 253 253 253 253 253 253 253 253 253
45674-253 253 253 226 226 226 187 187 187 180 133 36
45675-216 158 10 236 178 12 239 182 13 236 178 12
45676-230 174 11 226 170 11 226 170 11 230 174 11
45677-236 178 12 242 186 14 246 190 14 246 190 14
45678-246 190 14 246 190 14 246 186 14 239 182 13
45679-206 162 42 106 106 106 66 66 66 34 34 34
45680- 14 14 14 6 6 6 0 0 0 0 0 0
45681- 0 0 0 0 0 0 0 0 0 0 0 0
45682- 0 0 0 0 0 0 0 0 0 0 0 0
45683- 0 0 0 0 0 0 0 0 0 6 6 6
45684- 26 26 26 70 70 70 163 133 67 213 154 11
45685-236 178 12 246 190 14 246 190 14 246 190 14
45686-246 190 14 246 190 14 246 190 14 246 190 14
45687-246 190 14 246 190 14 246 190 14 246 190 14
45688-246 190 14 246 190 14 246 190 14 241 196 14
45689-190 146 13 18 14 6 2 2 6 2 2 6
45690- 46 46 46 246 246 246 253 253 253 253 253 253
45691-253 253 253 253 253 253 253 253 253 253 253 253
45692-253 253 253 253 253 253 253 253 253 253 253 253
45693-253 253 253 253 253 253 253 253 253 253 253 253
45694-253 253 253 221 221 221 86 86 86 156 107 11
45695-216 158 10 236 178 12 242 186 14 246 186 14
45696-242 186 14 239 182 13 239 182 13 242 186 14
45697-242 186 14 246 186 14 246 190 14 246 190 14
45698-246 190 14 246 190 14 246 190 14 246 190 14
45699-242 186 14 225 175 15 142 122 72 66 66 66
45700- 30 30 30 10 10 10 0 0 0 0 0 0
45701- 0 0 0 0 0 0 0 0 0 0 0 0
45702- 0 0 0 0 0 0 0 0 0 0 0 0
45703- 0 0 0 0 0 0 0 0 0 6 6 6
45704- 26 26 26 70 70 70 163 133 67 210 150 10
45705-236 178 12 246 190 14 246 190 14 246 190 14
45706-246 190 14 246 190 14 246 190 14 246 190 14
45707-246 190 14 246 190 14 246 190 14 246 190 14
45708-246 190 14 246 190 14 246 190 14 246 190 14
45709-232 195 16 121 92 8 34 34 34 106 106 106
45710-221 221 221 253 253 253 253 253 253 253 253 253
45711-253 253 253 253 253 253 253 253 253 253 253 253
45712-253 253 253 253 253 253 253 253 253 253 253 253
45713-253 253 253 253 253 253 253 253 253 253 253 253
45714-242 242 242 82 82 82 18 14 6 163 110 8
45715-216 158 10 236 178 12 242 186 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-246 190 14 246 190 14 246 190 14 246 190 14
45719-246 190 14 246 190 14 242 186 14 163 133 67
45720- 46 46 46 18 18 18 6 6 6 0 0 0
45721- 0 0 0 0 0 0 0 0 0 0 0 0
45722- 0 0 0 0 0 0 0 0 0 0 0 0
45723- 0 0 0 0 0 0 0 0 0 10 10 10
45724- 30 30 30 78 78 78 163 133 67 210 150 10
45725-236 178 12 246 186 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 246 190 14 246 190 14
45729-241 196 14 215 174 15 190 178 144 253 253 253
45730-253 253 253 253 253 253 253 253 253 253 253 253
45731-253 253 253 253 253 253 253 253 253 253 253 253
45732-253 253 253 253 253 253 253 253 253 253 253 253
45733-253 253 253 253 253 253 253 253 253 218 218 218
45734- 58 58 58 2 2 6 22 18 6 167 114 7
45735-216 158 10 236 178 12 246 186 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-246 190 14 246 190 14 246 190 14 246 190 14
45739-246 190 14 246 186 14 242 186 14 190 150 46
45740- 54 54 54 22 22 22 6 6 6 0 0 0
45741- 0 0 0 0 0 0 0 0 0 0 0 0
45742- 0 0 0 0 0 0 0 0 0 0 0 0
45743- 0 0 0 0 0 0 0 0 0 14 14 14
45744- 38 38 38 86 86 86 180 133 36 213 154 11
45745-236 178 12 246 186 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 190 14 246 190 14 246 190 14
45749-246 190 14 232 195 16 190 146 13 214 214 214
45750-253 253 253 253 253 253 253 253 253 253 253 253
45751-253 253 253 253 253 253 253 253 253 253 253 253
45752-253 253 253 253 253 253 253 253 253 253 253 253
45753-253 253 253 250 250 250 170 170 170 26 26 26
45754- 2 2 6 2 2 6 37 26 9 163 110 8
45755-219 162 10 239 182 13 246 186 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 246 190 14 246 190 14 246 190 14
45759-246 186 14 236 178 12 224 166 10 142 122 72
45760- 46 46 46 18 18 18 6 6 6 0 0 0
45761- 0 0 0 0 0 0 0 0 0 0 0 0
45762- 0 0 0 0 0 0 0 0 0 0 0 0
45763- 0 0 0 0 0 0 6 6 6 18 18 18
45764- 50 50 50 109 106 95 192 133 9 224 166 10
45765-242 186 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 190 14 246 190 14 246 190 14 246 190 14
45769-242 186 14 226 184 13 210 162 10 142 110 46
45770-226 226 226 253 253 253 253 253 253 253 253 253
45771-253 253 253 253 253 253 253 253 253 253 253 253
45772-253 253 253 253 253 253 253 253 253 253 253 253
45773-198 198 198 66 66 66 2 2 6 2 2 6
45774- 2 2 6 2 2 6 50 34 6 156 107 11
45775-219 162 10 239 182 13 246 186 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-246 190 14 246 190 14 246 190 14 242 186 14
45779-234 174 13 213 154 11 154 122 46 66 66 66
45780- 30 30 30 10 10 10 0 0 0 0 0 0
45781- 0 0 0 0 0 0 0 0 0 0 0 0
45782- 0 0 0 0 0 0 0 0 0 0 0 0
45783- 0 0 0 0 0 0 6 6 6 22 22 22
45784- 58 58 58 154 121 60 206 145 10 234 174 13
45785-242 186 14 246 186 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 246 190 14
45788-246 190 14 246 190 14 246 190 14 246 190 14
45789-246 186 14 236 178 12 210 162 10 163 110 8
45790- 61 42 6 138 138 138 218 218 218 250 250 250
45791-253 253 253 253 253 253 253 253 253 250 250 250
45792-242 242 242 210 210 210 144 144 144 66 66 66
45793- 6 6 6 2 2 6 2 2 6 2 2 6
45794- 2 2 6 2 2 6 61 42 6 163 110 8
45795-216 158 10 236 178 12 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 190 14 239 182 13 230 174 11 216 158 10
45799-190 142 34 124 112 88 70 70 70 38 38 38
45800- 18 18 18 6 6 6 0 0 0 0 0 0
45801- 0 0 0 0 0 0 0 0 0 0 0 0
45802- 0 0 0 0 0 0 0 0 0 0 0 0
45803- 0 0 0 0 0 0 6 6 6 22 22 22
45804- 62 62 62 168 124 44 206 145 10 224 166 10
45805-236 178 12 239 182 13 242 186 14 242 186 14
45806-246 186 14 246 190 14 246 190 14 246 190 14
45807-246 190 14 246 190 14 246 190 14 246 190 14
45808-246 190 14 246 190 14 246 190 14 246 190 14
45809-246 190 14 236 178 12 216 158 10 175 118 6
45810- 80 54 7 2 2 6 6 6 6 30 30 30
45811- 54 54 54 62 62 62 50 50 50 38 38 38
45812- 14 14 14 2 2 6 2 2 6 2 2 6
45813- 2 2 6 2 2 6 2 2 6 2 2 6
45814- 2 2 6 6 6 6 80 54 7 167 114 7
45815-213 154 11 236 178 12 246 190 14 246 190 14
45816-246 190 14 246 190 14 246 190 14 246 190 14
45817-246 190 14 242 186 14 239 182 13 239 182 13
45818-230 174 11 210 150 10 174 135 50 124 112 88
45819- 82 82 82 54 54 54 34 34 34 18 18 18
45820- 6 6 6 0 0 0 0 0 0 0 0 0
45821- 0 0 0 0 0 0 0 0 0 0 0 0
45822- 0 0 0 0 0 0 0 0 0 0 0 0
45823- 0 0 0 0 0 0 6 6 6 18 18 18
45824- 50 50 50 158 118 36 192 133 9 200 144 11
45825-216 158 10 219 162 10 224 166 10 226 170 11
45826-230 174 11 236 178 12 239 182 13 239 182 13
45827-242 186 14 246 186 14 246 190 14 246 190 14
45828-246 190 14 246 190 14 246 190 14 246 190 14
45829-246 186 14 230 174 11 210 150 10 163 110 8
45830-104 69 6 10 10 10 2 2 6 2 2 6
45831- 2 2 6 2 2 6 2 2 6 2 2 6
45832- 2 2 6 2 2 6 2 2 6 2 2 6
45833- 2 2 6 2 2 6 2 2 6 2 2 6
45834- 2 2 6 6 6 6 91 60 6 167 114 7
45835-206 145 10 230 174 11 242 186 14 246 190 14
45836-246 190 14 246 190 14 246 186 14 242 186 14
45837-239 182 13 230 174 11 224 166 10 213 154 11
45838-180 133 36 124 112 88 86 86 86 58 58 58
45839- 38 38 38 22 22 22 10 10 10 6 6 6
45840- 0 0 0 0 0 0 0 0 0 0 0 0
45841- 0 0 0 0 0 0 0 0 0 0 0 0
45842- 0 0 0 0 0 0 0 0 0 0 0 0
45843- 0 0 0 0 0 0 0 0 0 14 14 14
45844- 34 34 34 70 70 70 138 110 50 158 118 36
45845-167 114 7 180 123 7 192 133 9 197 138 11
45846-200 144 11 206 145 10 213 154 11 219 162 10
45847-224 166 10 230 174 11 239 182 13 242 186 14
45848-246 186 14 246 186 14 246 186 14 246 186 14
45849-239 182 13 216 158 10 185 133 11 152 99 6
45850-104 69 6 18 14 6 2 2 6 2 2 6
45851- 2 2 6 2 2 6 2 2 6 2 2 6
45852- 2 2 6 2 2 6 2 2 6 2 2 6
45853- 2 2 6 2 2 6 2 2 6 2 2 6
45854- 2 2 6 6 6 6 80 54 7 152 99 6
45855-192 133 9 219 162 10 236 178 12 239 182 13
45856-246 186 14 242 186 14 239 182 13 236 178 12
45857-224 166 10 206 145 10 192 133 9 154 121 60
45858- 94 94 94 62 62 62 42 42 42 22 22 22
45859- 14 14 14 6 6 6 0 0 0 0 0 0
45860- 0 0 0 0 0 0 0 0 0 0 0 0
45861- 0 0 0 0 0 0 0 0 0 0 0 0
45862- 0 0 0 0 0 0 0 0 0 0 0 0
45863- 0 0 0 0 0 0 0 0 0 6 6 6
45864- 18 18 18 34 34 34 58 58 58 78 78 78
45865-101 98 89 124 112 88 142 110 46 156 107 11
45866-163 110 8 167 114 7 175 118 6 180 123 7
45867-185 133 11 197 138 11 210 150 10 219 162 10
45868-226 170 11 236 178 12 236 178 12 234 174 13
45869-219 162 10 197 138 11 163 110 8 130 83 6
45870- 91 60 6 10 10 10 2 2 6 2 2 6
45871- 18 18 18 38 38 38 38 38 38 38 38 38
45872- 38 38 38 38 38 38 38 38 38 38 38 38
45873- 38 38 38 38 38 38 26 26 26 2 2 6
45874- 2 2 6 6 6 6 70 47 6 137 92 6
45875-175 118 6 200 144 11 219 162 10 230 174 11
45876-234 174 13 230 174 11 219 162 10 210 150 10
45877-192 133 9 163 110 8 124 112 88 82 82 82
45878- 50 50 50 30 30 30 14 14 14 6 6 6
45879- 0 0 0 0 0 0 0 0 0 0 0 0
45880- 0 0 0 0 0 0 0 0 0 0 0 0
45881- 0 0 0 0 0 0 0 0 0 0 0 0
45882- 0 0 0 0 0 0 0 0 0 0 0 0
45883- 0 0 0 0 0 0 0 0 0 0 0 0
45884- 6 6 6 14 14 14 22 22 22 34 34 34
45885- 42 42 42 58 58 58 74 74 74 86 86 86
45886-101 98 89 122 102 70 130 98 46 121 87 25
45887-137 92 6 152 99 6 163 110 8 180 123 7
45888-185 133 11 197 138 11 206 145 10 200 144 11
45889-180 123 7 156 107 11 130 83 6 104 69 6
45890- 50 34 6 54 54 54 110 110 110 101 98 89
45891- 86 86 86 82 82 82 78 78 78 78 78 78
45892- 78 78 78 78 78 78 78 78 78 78 78 78
45893- 78 78 78 82 82 82 86 86 86 94 94 94
45894-106 106 106 101 101 101 86 66 34 124 80 6
45895-156 107 11 180 123 7 192 133 9 200 144 11
45896-206 145 10 200 144 11 192 133 9 175 118 6
45897-139 102 15 109 106 95 70 70 70 42 42 42
45898- 22 22 22 10 10 10 0 0 0 0 0 0
45899- 0 0 0 0 0 0 0 0 0 0 0 0
45900- 0 0 0 0 0 0 0 0 0 0 0 0
45901- 0 0 0 0 0 0 0 0 0 0 0 0
45902- 0 0 0 0 0 0 0 0 0 0 0 0
45903- 0 0 0 0 0 0 0 0 0 0 0 0
45904- 0 0 0 0 0 0 6 6 6 10 10 10
45905- 14 14 14 22 22 22 30 30 30 38 38 38
45906- 50 50 50 62 62 62 74 74 74 90 90 90
45907-101 98 89 112 100 78 121 87 25 124 80 6
45908-137 92 6 152 99 6 152 99 6 152 99 6
45909-138 86 6 124 80 6 98 70 6 86 66 30
45910-101 98 89 82 82 82 58 58 58 46 46 46
45911- 38 38 38 34 34 34 34 34 34 34 34 34
45912- 34 34 34 34 34 34 34 34 34 34 34 34
45913- 34 34 34 34 34 34 38 38 38 42 42 42
45914- 54 54 54 82 82 82 94 86 76 91 60 6
45915-134 86 6 156 107 11 167 114 7 175 118 6
45916-175 118 6 167 114 7 152 99 6 121 87 25
45917-101 98 89 62 62 62 34 34 34 18 18 18
45918- 6 6 6 0 0 0 0 0 0 0 0 0
45919- 0 0 0 0 0 0 0 0 0 0 0 0
45920- 0 0 0 0 0 0 0 0 0 0 0 0
45921- 0 0 0 0 0 0 0 0 0 0 0 0
45922- 0 0 0 0 0 0 0 0 0 0 0 0
45923- 0 0 0 0 0 0 0 0 0 0 0 0
45924- 0 0 0 0 0 0 0 0 0 0 0 0
45925- 0 0 0 6 6 6 6 6 6 10 10 10
45926- 18 18 18 22 22 22 30 30 30 42 42 42
45927- 50 50 50 66 66 66 86 86 86 101 98 89
45928-106 86 58 98 70 6 104 69 6 104 69 6
45929-104 69 6 91 60 6 82 62 34 90 90 90
45930- 62 62 62 38 38 38 22 22 22 14 14 14
45931- 10 10 10 10 10 10 10 10 10 10 10 10
45932- 10 10 10 10 10 10 6 6 6 10 10 10
45933- 10 10 10 10 10 10 10 10 10 14 14 14
45934- 22 22 22 42 42 42 70 70 70 89 81 66
45935- 80 54 7 104 69 6 124 80 6 137 92 6
45936-134 86 6 116 81 8 100 82 52 86 86 86
45937- 58 58 58 30 30 30 14 14 14 6 6 6
45938- 0 0 0 0 0 0 0 0 0 0 0 0
45939- 0 0 0 0 0 0 0 0 0 0 0 0
45940- 0 0 0 0 0 0 0 0 0 0 0 0
45941- 0 0 0 0 0 0 0 0 0 0 0 0
45942- 0 0 0 0 0 0 0 0 0 0 0 0
45943- 0 0 0 0 0 0 0 0 0 0 0 0
45944- 0 0 0 0 0 0 0 0 0 0 0 0
45945- 0 0 0 0 0 0 0 0 0 0 0 0
45946- 0 0 0 6 6 6 10 10 10 14 14 14
45947- 18 18 18 26 26 26 38 38 38 54 54 54
45948- 70 70 70 86 86 86 94 86 76 89 81 66
45949- 89 81 66 86 86 86 74 74 74 50 50 50
45950- 30 30 30 14 14 14 6 6 6 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- 6 6 6 18 18 18 34 34 34 58 58 58
45955- 82 82 82 89 81 66 89 81 66 89 81 66
45956- 94 86 66 94 86 76 74 74 74 50 50 50
45957- 26 26 26 14 14 14 6 6 6 0 0 0
45958- 0 0 0 0 0 0 0 0 0 0 0 0
45959- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
45964- 0 0 0 0 0 0 0 0 0 0 0 0
45965- 0 0 0 0 0 0 0 0 0 0 0 0
45966- 0 0 0 0 0 0 0 0 0 0 0 0
45967- 6 6 6 6 6 6 14 14 14 18 18 18
45968- 30 30 30 38 38 38 46 46 46 54 54 54
45969- 50 50 50 42 42 42 30 30 30 18 18 18
45970- 10 10 10 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 6 6 6 14 14 14 26 26 26
45975- 38 38 38 50 50 50 58 58 58 58 58 58
45976- 54 54 54 42 42 42 30 30 30 18 18 18
45977- 10 10 10 0 0 0 0 0 0 0 0 0
45978- 0 0 0 0 0 0 0 0 0 0 0 0
45979- 0 0 0 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 0 0 0 0 0 0 0 0 0
45984- 0 0 0 0 0 0 0 0 0 0 0 0
45985- 0 0 0 0 0 0 0 0 0 0 0 0
45986- 0 0 0 0 0 0 0 0 0 0 0 0
45987- 0 0 0 0 0 0 0 0 0 6 6 6
45988- 6 6 6 10 10 10 14 14 14 18 18 18
45989- 18 18 18 14 14 14 10 10 10 6 6 6
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 6 6 6
45995- 14 14 14 18 18 18 22 22 22 22 22 22
45996- 18 18 18 14 14 14 10 10 10 6 6 6
45997- 0 0 0 0 0 0 0 0 0 0 0 0
45998- 0 0 0 0 0 0 0 0 0 0 0 0
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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 3 3 3 0 0 0 0 0 0
46091+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
46095+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46096+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46097+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
46100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
46105+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46106+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
46109+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46110+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46111+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46112+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46113+4 4 4 4 4 4
46114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46115+4 4 4 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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46119+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46120+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46123+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46124+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46125+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46126+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46127+4 4 4 4 4 4
46128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46129+4 4 4 4 4 4 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 5 5 5 5 5 5 2 2 2 0 0 0
46132+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46133+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46134+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46136+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46137+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46138+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46139+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46140+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46141+4 4 4 4 4 4
46142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46146+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46147+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46148+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46149+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46150+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46151+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46152+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46153+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46154+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46155+4 4 4 4 4 4
46156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46159+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46160+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46161+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46162+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46163+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46164+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46165+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46166+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46167+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46168+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46169+4 4 4 4 4 4
46170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46172+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46173+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46174+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46175+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46176+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46177+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46178+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46179+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46180+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46181+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46182+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46183+4 4 4 4 4 4
46184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46186+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46187+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46188+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46189+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46190+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46191+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46192+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46193+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46194+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46195+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46196+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46197+4 4 4 4 4 4
46198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46200+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46201+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46202+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46203+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46204+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46205+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46206+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46207+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46208+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46209+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46210+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46211+4 4 4 4 4 4
46212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46214+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46215+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46216+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46217+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46218+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46219+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46220+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46221+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46222+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46223+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46224+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46225+4 4 4 4 4 4
46226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46227+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46228+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46229+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46230+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46231+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46232+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46233+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46234+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46235+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46236+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46237+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46238+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46239+4 4 4 4 4 4
46240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46241+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46242+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46243+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46244+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46245+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46246+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46247+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46248+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46249+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46250+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46251+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46252+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46253+0 0 0 4 4 4
46254+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46255+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46256+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46257+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46258+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46259+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46260+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46261+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46262+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46263+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46264+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46265+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46266+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46267+2 0 0 0 0 0
46268+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46269+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46270+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46271+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46272+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46273+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46274+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46275+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46276+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46277+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46278+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46279+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46280+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46281+37 38 37 0 0 0
46282+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46283+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46284+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46285+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46286+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46287+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46288+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46289+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46290+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46291+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46292+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46293+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46294+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46295+85 115 134 4 0 0
46296+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46297+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46298+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46299+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46300+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46301+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46302+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46303+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46304+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46305+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46306+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46307+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46308+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46309+60 73 81 4 0 0
46310+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46311+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46312+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46313+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46314+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46315+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46316+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46317+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46318+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46319+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46320+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46321+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46322+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46323+16 19 21 4 0 0
46324+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
46325+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
46326+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
46327+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
46328+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
46329+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
46330+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
46331+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
46332+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
46333+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
46334+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
46335+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
46336+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
46337+4 0 0 4 3 3
46338+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
46339+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
46340+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
46341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
46342+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
46343+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
46344+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
46345+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
46346+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
46347+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
46348+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
46349+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
46350+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
46351+3 2 2 4 4 4
46352+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
46353+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
46354+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
46355+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46356+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
46357+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
46358+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
46359+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
46360+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
46361+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
46362+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
46363+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
46364+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
46365+4 4 4 4 4 4
46366+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
46367+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
46368+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
46369+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
46370+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
46371+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
46372+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
46373+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
46374+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
46375+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
46376+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
46377+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
46378+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
46379+4 4 4 4 4 4
46380+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
46381+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
46382+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
46383+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
46384+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
46385+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46386+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
46387+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
46388+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
46389+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
46390+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
46391+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
46392+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
46393+5 5 5 5 5 5
46394+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
46395+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46396+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46397+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46398+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46399+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46400+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46401+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46402+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46403+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46404+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46405+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46406+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46407+5 5 5 4 4 4
46408+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46409+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46410+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46411+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46412+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46413+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46414+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46415+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46416+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46417+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46418+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46419+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46421+4 4 4 4 4 4
46422+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46423+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46424+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46425+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46426+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46427+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46428+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46429+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46430+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46431+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46432+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46433+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46435+4 4 4 4 4 4
46436+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46437+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46438+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46439+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46440+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46441+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46442+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46443+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46444+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46445+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46446+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46449+4 4 4 4 4 4
46450+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46451+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46452+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46453+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46454+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46455+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46456+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46457+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46458+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46459+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46460+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46463+4 4 4 4 4 4
46464+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46465+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46466+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46467+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46468+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46469+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46470+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46471+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46472+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46473+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46474+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46477+4 4 4 4 4 4
46478+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46479+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46480+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46481+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46482+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46483+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46484+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46485+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46486+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46487+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46488+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46491+4 4 4 4 4 4
46492+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46493+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46494+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46495+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46496+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46497+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46498+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46499+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46500+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46501+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46502+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46505+4 4 4 4 4 4
46506+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46507+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46508+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46509+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46510+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46511+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46512+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46513+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46514+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46515+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46516+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46519+4 4 4 4 4 4
46520+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46521+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46522+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46523+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46524+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46525+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46526+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46527+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46528+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46529+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46530+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46533+4 4 4 4 4 4
46534+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46535+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46536+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46537+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46538+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46539+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46540+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46541+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46542+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46543+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46544+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46547+4 4 4 4 4 4
46548+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46549+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46550+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46551+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46552+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46553+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46554+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46555+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46556+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46557+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46558+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46561+4 4 4 4 4 4
46562+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46563+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46564+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46565+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46566+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46567+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46568+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46569+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46570+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46571+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46572+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46575+4 4 4 4 4 4
46576+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46577+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46578+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46579+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46580+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46581+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46582+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46583+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46584+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46585+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46586+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46589+4 4 4 4 4 4
46590+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46591+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46592+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46593+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46594+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46595+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46596+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46597+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46598+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46599+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46600+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46603+4 4 4 4 4 4
46604+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46605+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46606+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46607+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46608+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46609+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46610+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46611+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46612+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46613+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46614+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46617+4 4 4 4 4 4
46618+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46619+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46620+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46621+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46622+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46623+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46624+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46625+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46626+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46627+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46628+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46631+4 4 4 4 4 4
46632+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46633+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46634+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46635+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46636+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46637+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46638+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46639+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46640+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46641+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46642+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46645+4 4 4 4 4 4
46646+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46647+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46648+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46649+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46650+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46651+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46652+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46653+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46654+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46655+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46656+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46659+4 4 4 4 4 4
46660+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46661+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46662+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46663+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46664+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46665+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46666+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46667+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46668+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46669+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46670+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46673+4 4 4 4 4 4
46674+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46675+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46676+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46677+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46678+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46679+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46680+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46681+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46682+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46683+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46684+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46687+4 4 4 4 4 4
46688+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46689+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46690+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46691+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46692+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46693+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46694+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46695+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46696+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46697+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46698+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46701+4 4 4 4 4 4
46702+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46703+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46704+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46705+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46706+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46707+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46708+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46709+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46710+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46711+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46712+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46715+4 4 4 4 4 4
46716+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46717+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46718+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46719+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46720+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46721+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46722+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46723+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46724+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46725+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46726+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46729+4 4 4 4 4 4
46730+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46731+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46732+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46733+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46734+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46735+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46736+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46737+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46738+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46739+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46740+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46743+4 4 4 4 4 4
46744+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46745+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46746+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46747+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46748+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46749+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46750+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46751+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46752+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46753+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46754+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46757+4 4 4 4 4 4
46758+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46759+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46760+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46761+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46762+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46763+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46764+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46765+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46766+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46767+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46768+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46771+4 4 4 4 4 4
46772+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46773+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46774+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46775+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46776+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46777+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46778+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46779+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46780+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46781+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46782+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46785+4 4 4 4 4 4
46786+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46787+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46788+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46789+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46790+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46791+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46792+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46793+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46794+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46795+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46796+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46799+4 4 4 4 4 4
46800+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46801+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46802+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46803+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46804+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46805+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46806+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46807+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46808+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46809+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46810+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46813+4 4 4 4 4 4
46814+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46815+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46816+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46817+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46818+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46819+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46820+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46821+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46822+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46823+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
46824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46827+4 4 4 4 4 4
46828+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46829+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46830+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46831+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46832+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46833+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46834+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46835+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46836+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46837+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46841+4 4 4 4 4 4
46842+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46843+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46844+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46845+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46846+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46847+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46848+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46849+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46850+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46851+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46855+4 4 4 4 4 4
46856+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46857+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46858+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46859+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46860+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46861+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46862+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46863+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46864+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46865+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46869+4 4 4 4 4 4
46870+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46871+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46872+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46873+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46874+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46875+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46876+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46877+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46878+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
46879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46883+4 4 4 4 4 4
46884+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46885+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46886+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46887+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46888+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46889+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46890+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46891+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46892+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
46893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46897+4 4 4 4 4 4
46898+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46899+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46900+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46901+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46902+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46903+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46904+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46905+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46906+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46911+4 4 4 4 4 4
46912+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46913+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46914+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46915+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46916+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46917+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46918+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46919+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
46920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46925+4 4 4 4 4 4
46926+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46927+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46928+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46929+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46930+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46931+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46932+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46933+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46939+4 4 4 4 4 4
46940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46941+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
46942+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46943+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
46944+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
46945+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
46946+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
46947+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
46948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46953+4 4 4 4 4 4
46954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46955+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
46956+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
46957+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
46958+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
46959+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
46960+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
46961+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
46962+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46967+4 4 4 4 4 4
46968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46969+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46970+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
46971+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46972+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
46973+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
46974+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
46975+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46976+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
46979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46981+4 4 4 4 4 4
46982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46984+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46985+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
46986+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
46987+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
46988+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
46989+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46990+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46995+4 4 4 4 4 4
46996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46999+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47000+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47001+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47002+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 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 4 4 4
47008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47009+4 4 4 4 4 4
47010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47013+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47014+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47015+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47016+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47023+4 4 4 4 4 4
47024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
47028+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47029+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47030+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
47037+4 4 4 4 4 4
47038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5
47042+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47043+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47044+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
47051+4 4 4 4 4 4
47052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5
47056+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47057+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47058+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4
47065+4 4 4 4 4 4
47066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47067+4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47071+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47072+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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 4 4 4
47080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47081+4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47085+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47086+5 5 5 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 4 4 4 4 4 4 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 4 4 4
47094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47095+4 4 4 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 5 5 5 4 3 3 6 6 6
47099+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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
47108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 5 5 5 4 3 3
47113+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
47122diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47123index fe92eed..106e085 100644
47124--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47125+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47126@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47127 struct mb862xxfb_par *par = info->par;
47128
47129 if (info->var.bits_per_pixel == 32) {
47130- info->fbops->fb_fillrect = cfb_fillrect;
47131- info->fbops->fb_copyarea = cfb_copyarea;
47132- info->fbops->fb_imageblit = cfb_imageblit;
47133+ pax_open_kernel();
47134+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47135+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47136+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47137+ pax_close_kernel();
47138 } else {
47139 outreg(disp, GC_L0EM, 3);
47140- info->fbops->fb_fillrect = mb86290fb_fillrect;
47141- info->fbops->fb_copyarea = mb86290fb_copyarea;
47142- info->fbops->fb_imageblit = mb86290fb_imageblit;
47143+ pax_open_kernel();
47144+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47145+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47146+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47147+ pax_close_kernel();
47148 }
47149 outreg(draw, GDC_REG_DRAW_BASE, 0);
47150 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47151diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47152index ff22871..b129bed 100644
47153--- a/drivers/video/nvidia/nvidia.c
47154+++ b/drivers/video/nvidia/nvidia.c
47155@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47156 info->fix.line_length = (info->var.xres_virtual *
47157 info->var.bits_per_pixel) >> 3;
47158 if (info->var.accel_flags) {
47159- info->fbops->fb_imageblit = nvidiafb_imageblit;
47160- info->fbops->fb_fillrect = nvidiafb_fillrect;
47161- info->fbops->fb_copyarea = nvidiafb_copyarea;
47162- info->fbops->fb_sync = nvidiafb_sync;
47163+ pax_open_kernel();
47164+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47165+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47166+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47167+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47168+ pax_close_kernel();
47169 info->pixmap.scan_align = 4;
47170 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47171 info->flags |= FBINFO_READS_FAST;
47172 NVResetGraphics(info);
47173 } else {
47174- info->fbops->fb_imageblit = cfb_imageblit;
47175- info->fbops->fb_fillrect = cfb_fillrect;
47176- info->fbops->fb_copyarea = cfb_copyarea;
47177- info->fbops->fb_sync = NULL;
47178+ pax_open_kernel();
47179+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47180+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47181+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47182+ *(void **)&info->fbops->fb_sync = NULL;
47183+ pax_close_kernel();
47184 info->pixmap.scan_align = 1;
47185 info->flags |= FBINFO_HWACCEL_DISABLED;
47186 info->flags &= ~FBINFO_READS_FAST;
47187@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47188 info->pixmap.size = 8 * 1024;
47189 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47190
47191- if (!hwcur)
47192- info->fbops->fb_cursor = NULL;
47193+ if (!hwcur) {
47194+ pax_open_kernel();
47195+ *(void **)&info->fbops->fb_cursor = NULL;
47196+ pax_close_kernel();
47197+ }
47198
47199 info->var.accel_flags = (!noaccel);
47200
47201diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47202index 76d9053..dec2bfd 100644
47203--- a/drivers/video/s1d13xxxfb.c
47204+++ b/drivers/video/s1d13xxxfb.c
47205@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47206
47207 switch(prod_id) {
47208 case S1D13506_PROD_ID: /* activate acceleration */
47209- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47210- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47211+ pax_open_kernel();
47212+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47213+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47214+ pax_close_kernel();
47215 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47216 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47217 break;
47218diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47219index 97bd662..39fab85 100644
47220--- a/drivers/video/smscufx.c
47221+++ b/drivers/video/smscufx.c
47222@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47223 fb_deferred_io_cleanup(info);
47224 kfree(info->fbdefio);
47225 info->fbdefio = NULL;
47226- info->fbops->fb_mmap = ufx_ops_mmap;
47227+ pax_open_kernel();
47228+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47229+ pax_close_kernel();
47230 }
47231
47232 pr_debug("released /dev/fb%d user=%d count=%d",
47233diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47234index 86d449e..8e04dc5 100644
47235--- a/drivers/video/udlfb.c
47236+++ b/drivers/video/udlfb.c
47237@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47238 dlfb_urb_completion(urb);
47239
47240 error:
47241- atomic_add(bytes_sent, &dev->bytes_sent);
47242- atomic_add(bytes_identical, &dev->bytes_identical);
47243- atomic_add(width*height*2, &dev->bytes_rendered);
47244+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47245+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47246+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47247 end_cycles = get_cycles();
47248- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47249+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47250 >> 10)), /* Kcycles */
47251 &dev->cpu_kcycles_used);
47252
47253@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47254 dlfb_urb_completion(urb);
47255
47256 error:
47257- atomic_add(bytes_sent, &dev->bytes_sent);
47258- atomic_add(bytes_identical, &dev->bytes_identical);
47259- atomic_add(bytes_rendered, &dev->bytes_rendered);
47260+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47261+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47262+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47263 end_cycles = get_cycles();
47264- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47265+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47266 >> 10)), /* Kcycles */
47267 &dev->cpu_kcycles_used);
47268 }
47269@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47270 fb_deferred_io_cleanup(info);
47271 kfree(info->fbdefio);
47272 info->fbdefio = NULL;
47273- info->fbops->fb_mmap = dlfb_ops_mmap;
47274+ pax_open_kernel();
47275+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47276+ pax_close_kernel();
47277 }
47278
47279 pr_warn("released /dev/fb%d user=%d count=%d\n",
47280@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47281 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47282 struct dlfb_data *dev = fb_info->par;
47283 return snprintf(buf, PAGE_SIZE, "%u\n",
47284- atomic_read(&dev->bytes_rendered));
47285+ atomic_read_unchecked(&dev->bytes_rendered));
47286 }
47287
47288 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47289@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_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_identical));
47294+ atomic_read_unchecked(&dev->bytes_identical));
47295 }
47296
47297 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47298@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_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_sent));
47303+ atomic_read_unchecked(&dev->bytes_sent));
47304 }
47305
47306 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47307@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_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->cpu_kcycles_used));
47312+ atomic_read_unchecked(&dev->cpu_kcycles_used));
47313 }
47314
47315 static ssize_t edid_show(
47316@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
47317 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47318 struct dlfb_data *dev = fb_info->par;
47319
47320- atomic_set(&dev->bytes_rendered, 0);
47321- atomic_set(&dev->bytes_identical, 0);
47322- atomic_set(&dev->bytes_sent, 0);
47323- atomic_set(&dev->cpu_kcycles_used, 0);
47324+ atomic_set_unchecked(&dev->bytes_rendered, 0);
47325+ atomic_set_unchecked(&dev->bytes_identical, 0);
47326+ atomic_set_unchecked(&dev->bytes_sent, 0);
47327+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
47328
47329 return count;
47330 }
47331diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
47332index b75db01..ad2f34a 100644
47333--- a/drivers/video/uvesafb.c
47334+++ b/drivers/video/uvesafb.c
47335@@ -19,6 +19,7 @@
47336 #include <linux/io.h>
47337 #include <linux/mutex.h>
47338 #include <linux/slab.h>
47339+#include <linux/moduleloader.h>
47340 #include <video/edid.h>
47341 #include <video/uvesafb.h>
47342 #ifdef CONFIG_X86
47343@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
47344 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
47345 par->pmi_setpal = par->ypan = 0;
47346 } else {
47347+
47348+#ifdef CONFIG_PAX_KERNEXEC
47349+#ifdef CONFIG_MODULES
47350+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
47351+#endif
47352+ if (!par->pmi_code) {
47353+ par->pmi_setpal = par->ypan = 0;
47354+ return 0;
47355+ }
47356+#endif
47357+
47358 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
47359 + task->t.regs.edi);
47360+
47361+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47362+ pax_open_kernel();
47363+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
47364+ pax_close_kernel();
47365+
47366+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
47367+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
47368+#else
47369 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
47370 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
47371+#endif
47372+
47373 printk(KERN_INFO "uvesafb: protected mode interface info at "
47374 "%04x:%04x\n",
47375 (u16)task->t.regs.es, (u16)task->t.regs.edi);
47376@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
47377 par->ypan = ypan;
47378
47379 if (par->pmi_setpal || par->ypan) {
47380+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
47381 if (__supported_pte_mask & _PAGE_NX) {
47382 par->pmi_setpal = par->ypan = 0;
47383 printk(KERN_WARNING "uvesafb: NX protection is actively."
47384 "We have better not to use the PMI.\n");
47385- } else {
47386+ } else
47387+#endif
47388 uvesafb_vbe_getpmi(task, par);
47389- }
47390 }
47391 #else
47392 /* The protected mode interface is not available on non-x86. */
47393@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47394 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
47395
47396 /* Disable blanking if the user requested so. */
47397- if (!blank)
47398- info->fbops->fb_blank = NULL;
47399+ if (!blank) {
47400+ pax_open_kernel();
47401+ *(void **)&info->fbops->fb_blank = NULL;
47402+ pax_close_kernel();
47403+ }
47404
47405 /*
47406 * Find out how much IO memory is required for the mode with
47407@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47408 info->flags = FBINFO_FLAG_DEFAULT |
47409 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47410
47411- if (!par->ypan)
47412- info->fbops->fb_pan_display = NULL;
47413+ if (!par->ypan) {
47414+ pax_open_kernel();
47415+ *(void **)&info->fbops->fb_pan_display = NULL;
47416+ pax_close_kernel();
47417+ }
47418 }
47419
47420 static void uvesafb_init_mtrr(struct fb_info *info)
47421@@ -1836,6 +1866,11 @@ out:
47422 if (par->vbe_modes)
47423 kfree(par->vbe_modes);
47424
47425+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47426+ if (par->pmi_code)
47427+ module_free_exec(NULL, par->pmi_code);
47428+#endif
47429+
47430 framebuffer_release(info);
47431 return err;
47432 }
47433@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47434 kfree(par->vbe_state_orig);
47435 if (par->vbe_state_saved)
47436 kfree(par->vbe_state_saved);
47437+
47438+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47439+ if (par->pmi_code)
47440+ module_free_exec(NULL, par->pmi_code);
47441+#endif
47442+
47443 }
47444
47445 framebuffer_release(info);
47446diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47447index 501b340..d80aa17 100644
47448--- a/drivers/video/vesafb.c
47449+++ b/drivers/video/vesafb.c
47450@@ -9,6 +9,7 @@
47451 */
47452
47453 #include <linux/module.h>
47454+#include <linux/moduleloader.h>
47455 #include <linux/kernel.h>
47456 #include <linux/errno.h>
47457 #include <linux/string.h>
47458@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47459 static int vram_total __initdata; /* Set total amount of memory */
47460 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47461 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47462-static void (*pmi_start)(void) __read_mostly;
47463-static void (*pmi_pal) (void) __read_mostly;
47464+static void (*pmi_start)(void) __read_only;
47465+static void (*pmi_pal) (void) __read_only;
47466 static int depth __read_mostly;
47467 static int vga_compat __read_mostly;
47468 /* --------------------------------------------------------------------- */
47469@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47470 unsigned int size_vmode;
47471 unsigned int size_remap;
47472 unsigned int size_total;
47473+ void *pmi_code = NULL;
47474
47475 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47476 return -ENODEV;
47477@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47478 size_remap = size_total;
47479 vesafb_fix.smem_len = size_remap;
47480
47481-#ifndef __i386__
47482- screen_info.vesapm_seg = 0;
47483-#endif
47484-
47485 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47486 printk(KERN_WARNING
47487 "vesafb: cannot reserve video memory at 0x%lx\n",
47488@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47489 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47490 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47491
47492+#ifdef __i386__
47493+
47494+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47495+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
47496+ if (!pmi_code)
47497+#elif !defined(CONFIG_PAX_KERNEXEC)
47498+ if (0)
47499+#endif
47500+
47501+#endif
47502+ screen_info.vesapm_seg = 0;
47503+
47504 if (screen_info.vesapm_seg) {
47505- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47506- screen_info.vesapm_seg,screen_info.vesapm_off);
47507+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47508+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47509 }
47510
47511 if (screen_info.vesapm_seg < 0xc000)
47512@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47513
47514 if (ypan || pmi_setpal) {
47515 unsigned short *pmi_base;
47516+
47517 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47518- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47519- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47520+
47521+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47522+ pax_open_kernel();
47523+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47524+#else
47525+ pmi_code = pmi_base;
47526+#endif
47527+
47528+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47529+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47530+
47531+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47532+ pmi_start = ktva_ktla(pmi_start);
47533+ pmi_pal = ktva_ktla(pmi_pal);
47534+ pax_close_kernel();
47535+#endif
47536+
47537 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47538 if (pmi_base[3]) {
47539 printk(KERN_INFO "vesafb: pmi: ports = ");
47540@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47541 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47542 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47543
47544- if (!ypan)
47545- info->fbops->fb_pan_display = NULL;
47546+ if (!ypan) {
47547+ pax_open_kernel();
47548+ *(void **)&info->fbops->fb_pan_display = NULL;
47549+ pax_close_kernel();
47550+ }
47551
47552 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47553 err = -ENOMEM;
47554@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47555 info->node, info->fix.id);
47556 return 0;
47557 err:
47558+
47559+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47560+ module_free_exec(NULL, pmi_code);
47561+#endif
47562+
47563 if (info->screen_base)
47564 iounmap(info->screen_base);
47565 framebuffer_release(info);
47566diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47567index 88714ae..16c2e11 100644
47568--- a/drivers/video/via/via_clock.h
47569+++ b/drivers/video/via/via_clock.h
47570@@ -56,7 +56,7 @@ struct via_clock {
47571
47572 void (*set_engine_pll_state)(u8 state);
47573 void (*set_engine_pll)(struct via_pll_config config);
47574-};
47575+} __no_const;
47576
47577
47578 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47579diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47580index fef20db..d28b1ab 100644
47581--- a/drivers/xen/xenfs/xenstored.c
47582+++ b/drivers/xen/xenfs/xenstored.c
47583@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47584 static int xsd_kva_open(struct inode *inode, struct file *file)
47585 {
47586 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47587+#ifdef CONFIG_GRKERNSEC_HIDESYM
47588+ NULL);
47589+#else
47590 xen_store_interface);
47591+#endif
47592+
47593 if (!file->private_data)
47594 return -ENOMEM;
47595 return 0;
47596diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47597index 890bed5..17ae73e 100644
47598--- a/fs/9p/vfs_inode.c
47599+++ b/fs/9p/vfs_inode.c
47600@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47601 void
47602 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47603 {
47604- char *s = nd_get_link(nd);
47605+ const char *s = nd_get_link(nd);
47606
47607 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47608 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47609diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47610index 0efd152..b5802ad 100644
47611--- a/fs/Kconfig.binfmt
47612+++ b/fs/Kconfig.binfmt
47613@@ -89,7 +89,7 @@ config HAVE_AOUT
47614
47615 config BINFMT_AOUT
47616 tristate "Kernel support for a.out and ECOFF binaries"
47617- depends on HAVE_AOUT
47618+ depends on HAVE_AOUT && BROKEN
47619 ---help---
47620 A.out (Assembler.OUTput) is a set of formats for libraries and
47621 executables used in the earliest versions of UNIX. Linux used
47622diff --git a/fs/aio.c b/fs/aio.c
47623index 71f613c..9d01f1f 100644
47624--- a/fs/aio.c
47625+++ b/fs/aio.c
47626@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47627 size += sizeof(struct io_event) * nr_events;
47628 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47629
47630- if (nr_pages < 0)
47631+ if (nr_pages <= 0)
47632 return -EINVAL;
47633
47634 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47635@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47636 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47637 {
47638 ssize_t ret;
47639+ struct iovec iovstack;
47640
47641 #ifdef CONFIG_COMPAT
47642 if (compat)
47643 ret = compat_rw_copy_check_uvector(type,
47644 (struct compat_iovec __user *)kiocb->ki_buf,
47645- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47646+ kiocb->ki_nbytes, 1, &iovstack,
47647 &kiocb->ki_iovec);
47648 else
47649 #endif
47650 ret = rw_copy_check_uvector(type,
47651 (struct iovec __user *)kiocb->ki_buf,
47652- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47653+ kiocb->ki_nbytes, 1, &iovstack,
47654 &kiocb->ki_iovec);
47655 if (ret < 0)
47656 goto out;
47657@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47658 if (ret < 0)
47659 goto out;
47660
47661+ if (kiocb->ki_iovec == &iovstack) {
47662+ kiocb->ki_inline_vec = iovstack;
47663+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
47664+ }
47665 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47666 kiocb->ki_cur_seg = 0;
47667 /* ki_nbytes/left now reflect bytes instead of segs */
47668diff --git a/fs/attr.c b/fs/attr.c
47669index 1449adb..a2038c2 100644
47670--- a/fs/attr.c
47671+++ b/fs/attr.c
47672@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47673 unsigned long limit;
47674
47675 limit = rlimit(RLIMIT_FSIZE);
47676+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47677 if (limit != RLIM_INFINITY && offset > limit)
47678 goto out_sig;
47679 if (offset > inode->i_sb->s_maxbytes)
47680diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47681index 03bc1d3..6205356 100644
47682--- a/fs/autofs4/waitq.c
47683+++ b/fs/autofs4/waitq.c
47684@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47685 {
47686 unsigned long sigpipe, flags;
47687 mm_segment_t fs;
47688- const char *data = (const char *)addr;
47689+ const char __user *data = (const char __force_user *)addr;
47690 ssize_t wr = 0;
47691
47692 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47693@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47694 return 1;
47695 }
47696
47697+#ifdef CONFIG_GRKERNSEC_HIDESYM
47698+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47699+#endif
47700+
47701 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47702 enum autofs_notify notify)
47703 {
47704@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47705
47706 /* If this is a direct mount request create a dummy name */
47707 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47708+#ifdef CONFIG_GRKERNSEC_HIDESYM
47709+ /* this name does get written to userland via autofs4_write() */
47710+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47711+#else
47712 qstr.len = sprintf(name, "%p", dentry);
47713+#endif
47714 else {
47715 qstr.len = autofs4_getpath(sbi, dentry, &name);
47716 if (!qstr.len) {
47717diff --git a/fs/befs/endian.h b/fs/befs/endian.h
47718index 2722387..c8dd2a7 100644
47719--- a/fs/befs/endian.h
47720+++ b/fs/befs/endian.h
47721@@ -11,7 +11,7 @@
47722
47723 #include <asm/byteorder.h>
47724
47725-static inline u64
47726+static inline u64 __intentional_overflow(-1)
47727 fs64_to_cpu(const struct super_block *sb, fs64 n)
47728 {
47729 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47730@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
47731 return (__force fs64)cpu_to_be64(n);
47732 }
47733
47734-static inline u32
47735+static inline u32 __intentional_overflow(-1)
47736 fs32_to_cpu(const struct super_block *sb, fs32 n)
47737 {
47738 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47739diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47740index 2b3bda8..6a2d4be 100644
47741--- a/fs/befs/linuxvfs.c
47742+++ b/fs/befs/linuxvfs.c
47743@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47744 {
47745 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47746 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47747- char *link = nd_get_link(nd);
47748+ const char *link = nd_get_link(nd);
47749 if (!IS_ERR(link))
47750 kfree(link);
47751 }
47752diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47753index 6043567..16a9239 100644
47754--- a/fs/binfmt_aout.c
47755+++ b/fs/binfmt_aout.c
47756@@ -16,6 +16,7 @@
47757 #include <linux/string.h>
47758 #include <linux/fs.h>
47759 #include <linux/file.h>
47760+#include <linux/security.h>
47761 #include <linux/stat.h>
47762 #include <linux/fcntl.h>
47763 #include <linux/ptrace.h>
47764@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47765 #endif
47766 # define START_STACK(u) ((void __user *)u.start_stack)
47767
47768+ memset(&dump, 0, sizeof(dump));
47769+
47770 fs = get_fs();
47771 set_fs(KERNEL_DS);
47772 has_dumped = 1;
47773@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47774
47775 /* If the size of the dump file exceeds the rlimit, then see what would happen
47776 if we wrote the stack, but not the data area. */
47777+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47778 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47779 dump.u_dsize = 0;
47780
47781 /* Make sure we have enough room to write the stack and data areas. */
47782+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47783 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47784 dump.u_ssize = 0;
47785
47786@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47787 rlim = rlimit(RLIMIT_DATA);
47788 if (rlim >= RLIM_INFINITY)
47789 rlim = ~0;
47790+
47791+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47792 if (ex.a_data + ex.a_bss > rlim)
47793 return -ENOMEM;
47794
47795@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47796
47797 install_exec_creds(bprm);
47798
47799+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47800+ current->mm->pax_flags = 0UL;
47801+#endif
47802+
47803+#ifdef CONFIG_PAX_PAGEEXEC
47804+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47805+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47806+
47807+#ifdef CONFIG_PAX_EMUTRAMP
47808+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47809+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47810+#endif
47811+
47812+#ifdef CONFIG_PAX_MPROTECT
47813+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47814+ current->mm->pax_flags |= MF_PAX_MPROTECT;
47815+#endif
47816+
47817+ }
47818+#endif
47819+
47820 if (N_MAGIC(ex) == OMAGIC) {
47821 unsigned long text_addr, map_size;
47822 loff_t pos;
47823@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47824 }
47825
47826 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47827- PROT_READ | PROT_WRITE | PROT_EXEC,
47828+ PROT_READ | PROT_WRITE,
47829 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47830 fd_offset + ex.a_text);
47831 if (error != N_DATADDR(ex)) {
47832diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47833index 0c42cdb..12478dd 100644
47834--- a/fs/binfmt_elf.c
47835+++ b/fs/binfmt_elf.c
47836@@ -33,6 +33,7 @@
47837 #include <linux/elf.h>
47838 #include <linux/utsname.h>
47839 #include <linux/coredump.h>
47840+#include <linux/xattr.h>
47841 #include <asm/uaccess.h>
47842 #include <asm/param.h>
47843 #include <asm/page.h>
47844@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47845 #define elf_core_dump NULL
47846 #endif
47847
47848+#ifdef CONFIG_PAX_MPROTECT
47849+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47850+#endif
47851+
47852 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47853 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47854 #else
47855@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47856 .load_binary = load_elf_binary,
47857 .load_shlib = load_elf_library,
47858 .core_dump = elf_core_dump,
47859+
47860+#ifdef CONFIG_PAX_MPROTECT
47861+ .handle_mprotect= elf_handle_mprotect,
47862+#endif
47863+
47864 .min_coredump = ELF_EXEC_PAGESIZE,
47865 };
47866
47867@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47868
47869 static int set_brk(unsigned long start, unsigned long end)
47870 {
47871+ unsigned long e = end;
47872+
47873 start = ELF_PAGEALIGN(start);
47874 end = ELF_PAGEALIGN(end);
47875 if (end > start) {
47876@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47877 if (BAD_ADDR(addr))
47878 return addr;
47879 }
47880- current->mm->start_brk = current->mm->brk = end;
47881+ current->mm->start_brk = current->mm->brk = e;
47882 return 0;
47883 }
47884
47885@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47886 elf_addr_t __user *u_rand_bytes;
47887 const char *k_platform = ELF_PLATFORM;
47888 const char *k_base_platform = ELF_BASE_PLATFORM;
47889- unsigned char k_rand_bytes[16];
47890+ u32 k_rand_bytes[4];
47891 int items;
47892 elf_addr_t *elf_info;
47893 int ei_index = 0;
47894 const struct cred *cred = current_cred();
47895 struct vm_area_struct *vma;
47896+ unsigned long saved_auxv[AT_VECTOR_SIZE];
47897
47898 /*
47899 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47900@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47901 * Generate 16 random bytes for userspace PRNG seeding.
47902 */
47903 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47904- u_rand_bytes = (elf_addr_t __user *)
47905- STACK_ALLOC(p, sizeof(k_rand_bytes));
47906+ srandom32(k_rand_bytes[0] ^ random32());
47907+ srandom32(k_rand_bytes[1] ^ random32());
47908+ srandom32(k_rand_bytes[2] ^ random32());
47909+ srandom32(k_rand_bytes[3] ^ random32());
47910+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
47911+ u_rand_bytes = (elf_addr_t __user *) p;
47912 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47913 return -EFAULT;
47914
47915@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47916 return -EFAULT;
47917 current->mm->env_end = p;
47918
47919+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47920+
47921 /* Put the elf_info on the stack in the right place. */
47922 sp = (elf_addr_t __user *)envp + 1;
47923- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47924+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47925 return -EFAULT;
47926 return 0;
47927 }
47928@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47929 an ELF header */
47930
47931 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47932- struct file *interpreter, unsigned long *interp_map_addr,
47933- unsigned long no_base)
47934+ struct file *interpreter, unsigned long no_base)
47935 {
47936 struct elf_phdr *elf_phdata;
47937 struct elf_phdr *eppnt;
47938- unsigned long load_addr = 0;
47939+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
47940 int load_addr_set = 0;
47941 unsigned long last_bss = 0, elf_bss = 0;
47942- unsigned long error = ~0UL;
47943+ unsigned long error = -EINVAL;
47944 unsigned long total_size;
47945 int retval, i, size;
47946
47947@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47948 goto out_close;
47949 }
47950
47951+#ifdef CONFIG_PAX_SEGMEXEC
47952+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
47953+ pax_task_size = SEGMEXEC_TASK_SIZE;
47954+#endif
47955+
47956 eppnt = elf_phdata;
47957 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
47958 if (eppnt->p_type == PT_LOAD) {
47959@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47960 map_addr = elf_map(interpreter, load_addr + vaddr,
47961 eppnt, elf_prot, elf_type, total_size);
47962 total_size = 0;
47963- if (!*interp_map_addr)
47964- *interp_map_addr = map_addr;
47965 error = map_addr;
47966 if (BAD_ADDR(map_addr))
47967 goto out_close;
47968@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47969 k = load_addr + eppnt->p_vaddr;
47970 if (BAD_ADDR(k) ||
47971 eppnt->p_filesz > eppnt->p_memsz ||
47972- eppnt->p_memsz > TASK_SIZE ||
47973- TASK_SIZE - eppnt->p_memsz < k) {
47974+ eppnt->p_memsz > pax_task_size ||
47975+ pax_task_size - eppnt->p_memsz < k) {
47976 error = -ENOMEM;
47977 goto out_close;
47978 }
47979@@ -530,6 +551,315 @@ out:
47980 return error;
47981 }
47982
47983+#ifdef CONFIG_PAX_PT_PAX_FLAGS
47984+#ifdef CONFIG_PAX_SOFTMODE
47985+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
47986+{
47987+ unsigned long pax_flags = 0UL;
47988+
47989+#ifdef CONFIG_PAX_PAGEEXEC
47990+ if (elf_phdata->p_flags & PF_PAGEEXEC)
47991+ pax_flags |= MF_PAX_PAGEEXEC;
47992+#endif
47993+
47994+#ifdef CONFIG_PAX_SEGMEXEC
47995+ if (elf_phdata->p_flags & PF_SEGMEXEC)
47996+ pax_flags |= MF_PAX_SEGMEXEC;
47997+#endif
47998+
47999+#ifdef CONFIG_PAX_EMUTRAMP
48000+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48001+ pax_flags |= MF_PAX_EMUTRAMP;
48002+#endif
48003+
48004+#ifdef CONFIG_PAX_MPROTECT
48005+ if (elf_phdata->p_flags & PF_MPROTECT)
48006+ pax_flags |= MF_PAX_MPROTECT;
48007+#endif
48008+
48009+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48010+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48011+ pax_flags |= MF_PAX_RANDMMAP;
48012+#endif
48013+
48014+ return pax_flags;
48015+}
48016+#endif
48017+
48018+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48019+{
48020+ unsigned long pax_flags = 0UL;
48021+
48022+#ifdef CONFIG_PAX_PAGEEXEC
48023+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48024+ pax_flags |= MF_PAX_PAGEEXEC;
48025+#endif
48026+
48027+#ifdef CONFIG_PAX_SEGMEXEC
48028+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48029+ pax_flags |= MF_PAX_SEGMEXEC;
48030+#endif
48031+
48032+#ifdef CONFIG_PAX_EMUTRAMP
48033+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48034+ pax_flags |= MF_PAX_EMUTRAMP;
48035+#endif
48036+
48037+#ifdef CONFIG_PAX_MPROTECT
48038+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48039+ pax_flags |= MF_PAX_MPROTECT;
48040+#endif
48041+
48042+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48043+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48044+ pax_flags |= MF_PAX_RANDMMAP;
48045+#endif
48046+
48047+ return pax_flags;
48048+}
48049+#endif
48050+
48051+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48052+#ifdef CONFIG_PAX_SOFTMODE
48053+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48054+{
48055+ unsigned long pax_flags = 0UL;
48056+
48057+#ifdef CONFIG_PAX_PAGEEXEC
48058+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48059+ pax_flags |= MF_PAX_PAGEEXEC;
48060+#endif
48061+
48062+#ifdef CONFIG_PAX_SEGMEXEC
48063+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48064+ pax_flags |= MF_PAX_SEGMEXEC;
48065+#endif
48066+
48067+#ifdef CONFIG_PAX_EMUTRAMP
48068+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
48069+ pax_flags |= MF_PAX_EMUTRAMP;
48070+#endif
48071+
48072+#ifdef CONFIG_PAX_MPROTECT
48073+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48074+ pax_flags |= MF_PAX_MPROTECT;
48075+#endif
48076+
48077+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48078+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48079+ pax_flags |= MF_PAX_RANDMMAP;
48080+#endif
48081+
48082+ return pax_flags;
48083+}
48084+#endif
48085+
48086+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48087+{
48088+ unsigned long pax_flags = 0UL;
48089+
48090+#ifdef CONFIG_PAX_PAGEEXEC
48091+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48092+ pax_flags |= MF_PAX_PAGEEXEC;
48093+#endif
48094+
48095+#ifdef CONFIG_PAX_SEGMEXEC
48096+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48097+ pax_flags |= MF_PAX_SEGMEXEC;
48098+#endif
48099+
48100+#ifdef CONFIG_PAX_EMUTRAMP
48101+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48102+ pax_flags |= MF_PAX_EMUTRAMP;
48103+#endif
48104+
48105+#ifdef CONFIG_PAX_MPROTECT
48106+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48107+ pax_flags |= MF_PAX_MPROTECT;
48108+#endif
48109+
48110+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48111+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48112+ pax_flags |= MF_PAX_RANDMMAP;
48113+#endif
48114+
48115+ return pax_flags;
48116+}
48117+#endif
48118+
48119+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48120+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48121+{
48122+ unsigned long pax_flags = 0UL;
48123+
48124+#ifdef CONFIG_PAX_EI_PAX
48125+
48126+#ifdef CONFIG_PAX_PAGEEXEC
48127+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48128+ pax_flags |= MF_PAX_PAGEEXEC;
48129+#endif
48130+
48131+#ifdef CONFIG_PAX_SEGMEXEC
48132+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48133+ pax_flags |= MF_PAX_SEGMEXEC;
48134+#endif
48135+
48136+#ifdef CONFIG_PAX_EMUTRAMP
48137+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48138+ pax_flags |= MF_PAX_EMUTRAMP;
48139+#endif
48140+
48141+#ifdef CONFIG_PAX_MPROTECT
48142+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48143+ pax_flags |= MF_PAX_MPROTECT;
48144+#endif
48145+
48146+#ifdef CONFIG_PAX_ASLR
48147+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48148+ pax_flags |= MF_PAX_RANDMMAP;
48149+#endif
48150+
48151+#else
48152+
48153+#ifdef CONFIG_PAX_PAGEEXEC
48154+ pax_flags |= MF_PAX_PAGEEXEC;
48155+#endif
48156+
48157+#ifdef CONFIG_PAX_SEGMEXEC
48158+ pax_flags |= MF_PAX_SEGMEXEC;
48159+#endif
48160+
48161+#ifdef CONFIG_PAX_MPROTECT
48162+ pax_flags |= MF_PAX_MPROTECT;
48163+#endif
48164+
48165+#ifdef CONFIG_PAX_RANDMMAP
48166+ if (randomize_va_space)
48167+ pax_flags |= MF_PAX_RANDMMAP;
48168+#endif
48169+
48170+#endif
48171+
48172+ return pax_flags;
48173+}
48174+
48175+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48176+{
48177+
48178+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48179+ unsigned long i;
48180+
48181+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48182+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48183+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48184+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48185+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48186+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48187+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48188+ return ~0UL;
48189+
48190+#ifdef CONFIG_PAX_SOFTMODE
48191+ if (pax_softmode)
48192+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48193+ else
48194+#endif
48195+
48196+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48197+ break;
48198+ }
48199+#endif
48200+
48201+ return ~0UL;
48202+}
48203+
48204+static unsigned long pax_parse_xattr_pax(struct file * const file)
48205+{
48206+
48207+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48208+ ssize_t xattr_size, i;
48209+ unsigned char xattr_value[5];
48210+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48211+
48212+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
48213+ if (xattr_size <= 0 || xattr_size > 5)
48214+ return ~0UL;
48215+
48216+ for (i = 0; i < xattr_size; i++)
48217+ switch (xattr_value[i]) {
48218+ default:
48219+ return ~0UL;
48220+
48221+#define parse_flag(option1, option2, flag) \
48222+ case option1: \
48223+ if (pax_flags_hardmode & MF_PAX_##flag) \
48224+ return ~0UL; \
48225+ pax_flags_hardmode |= MF_PAX_##flag; \
48226+ break; \
48227+ case option2: \
48228+ if (pax_flags_softmode & MF_PAX_##flag) \
48229+ return ~0UL; \
48230+ pax_flags_softmode |= MF_PAX_##flag; \
48231+ break;
48232+
48233+ parse_flag('p', 'P', PAGEEXEC);
48234+ parse_flag('e', 'E', EMUTRAMP);
48235+ parse_flag('m', 'M', MPROTECT);
48236+ parse_flag('r', 'R', RANDMMAP);
48237+ parse_flag('s', 'S', SEGMEXEC);
48238+
48239+#undef parse_flag
48240+ }
48241+
48242+ if (pax_flags_hardmode & pax_flags_softmode)
48243+ return ~0UL;
48244+
48245+#ifdef CONFIG_PAX_SOFTMODE
48246+ if (pax_softmode)
48247+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48248+ else
48249+#endif
48250+
48251+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48252+#else
48253+ return ~0UL;
48254+#endif
48255+
48256+}
48257+
48258+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48259+{
48260+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48261+
48262+ pax_flags = pax_parse_ei_pax(elf_ex);
48263+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48264+ xattr_pax_flags = pax_parse_xattr_pax(file);
48265+
48266+ if (pt_pax_flags == ~0UL)
48267+ pt_pax_flags = xattr_pax_flags;
48268+ else if (xattr_pax_flags == ~0UL)
48269+ xattr_pax_flags = pt_pax_flags;
48270+ if (pt_pax_flags != xattr_pax_flags)
48271+ return -EINVAL;
48272+ if (pt_pax_flags != ~0UL)
48273+ pax_flags = pt_pax_flags;
48274+
48275+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48276+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48277+ if ((__supported_pte_mask & _PAGE_NX))
48278+ pax_flags &= ~MF_PAX_SEGMEXEC;
48279+ else
48280+ pax_flags &= ~MF_PAX_PAGEEXEC;
48281+ }
48282+#endif
48283+
48284+ if (0 > pax_check_flags(&pax_flags))
48285+ return -EINVAL;
48286+
48287+ current->mm->pax_flags = pax_flags;
48288+ return 0;
48289+}
48290+#endif
48291+
48292 /*
48293 * These are the functions used to load ELF style executables and shared
48294 * libraries. There is no binary dependent code anywhere else.
48295@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48296 {
48297 unsigned int random_variable = 0;
48298
48299+#ifdef CONFIG_PAX_RANDUSTACK
48300+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
48301+ return stack_top - current->mm->delta_stack;
48302+#endif
48303+
48304 if ((current->flags & PF_RANDOMIZE) &&
48305 !(current->personality & ADDR_NO_RANDOMIZE)) {
48306 random_variable = get_random_int() & STACK_RND_MASK;
48307@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
48308 unsigned long load_addr = 0, load_bias = 0;
48309 int load_addr_set = 0;
48310 char * elf_interpreter = NULL;
48311- unsigned long error;
48312+ unsigned long error = 0;
48313 struct elf_phdr *elf_ppnt, *elf_phdata;
48314 unsigned long elf_bss, elf_brk;
48315 int retval, i;
48316@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
48317 unsigned long start_code, end_code, start_data, end_data;
48318 unsigned long reloc_func_desc __maybe_unused = 0;
48319 int executable_stack = EXSTACK_DEFAULT;
48320- unsigned long def_flags = 0;
48321 struct pt_regs *regs = current_pt_regs();
48322 struct {
48323 struct elfhdr elf_ex;
48324 struct elfhdr interp_elf_ex;
48325 } *loc;
48326+ unsigned long pax_task_size = TASK_SIZE;
48327
48328 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
48329 if (!loc) {
48330@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
48331 goto out_free_dentry;
48332
48333 /* OK, This is the point of no return */
48334- current->mm->def_flags = def_flags;
48335+
48336+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48337+ current->mm->pax_flags = 0UL;
48338+#endif
48339+
48340+#ifdef CONFIG_PAX_DLRESOLVE
48341+ current->mm->call_dl_resolve = 0UL;
48342+#endif
48343+
48344+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
48345+ current->mm->call_syscall = 0UL;
48346+#endif
48347+
48348+#ifdef CONFIG_PAX_ASLR
48349+ current->mm->delta_mmap = 0UL;
48350+ current->mm->delta_stack = 0UL;
48351+#endif
48352+
48353+ current->mm->def_flags = 0;
48354+
48355+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48356+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
48357+ send_sig(SIGKILL, current, 0);
48358+ goto out_free_dentry;
48359+ }
48360+#endif
48361+
48362+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
48363+ pax_set_initial_flags(bprm);
48364+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
48365+ if (pax_set_initial_flags_func)
48366+ (pax_set_initial_flags_func)(bprm);
48367+#endif
48368+
48369+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48370+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
48371+ current->mm->context.user_cs_limit = PAGE_SIZE;
48372+ current->mm->def_flags |= VM_PAGEEXEC;
48373+ }
48374+#endif
48375+
48376+#ifdef CONFIG_PAX_SEGMEXEC
48377+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
48378+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
48379+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
48380+ pax_task_size = SEGMEXEC_TASK_SIZE;
48381+ current->mm->def_flags |= VM_NOHUGEPAGE;
48382+ }
48383+#endif
48384+
48385+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
48386+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48387+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
48388+ put_cpu();
48389+ }
48390+#endif
48391
48392 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
48393 may depend on the personality. */
48394 SET_PERSONALITY(loc->elf_ex);
48395+
48396+#ifdef CONFIG_PAX_ASLR
48397+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48398+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
48399+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
48400+ }
48401+#endif
48402+
48403+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48404+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48405+ executable_stack = EXSTACK_DISABLE_X;
48406+ current->personality &= ~READ_IMPLIES_EXEC;
48407+ } else
48408+#endif
48409+
48410 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
48411 current->personality |= READ_IMPLIES_EXEC;
48412
48413@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
48414 #else
48415 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
48416 #endif
48417+
48418+#ifdef CONFIG_PAX_RANDMMAP
48419+ /* PaX: randomize base address at the default exe base if requested */
48420+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48421+#ifdef CONFIG_SPARC64
48422+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48423+#else
48424+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48425+#endif
48426+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48427+ elf_flags |= MAP_FIXED;
48428+ }
48429+#endif
48430+
48431 }
48432
48433 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48434@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48435 * allowed task size. Note that p_filesz must always be
48436 * <= p_memsz so it is only necessary to check p_memsz.
48437 */
48438- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48439- elf_ppnt->p_memsz > TASK_SIZE ||
48440- TASK_SIZE - elf_ppnt->p_memsz < k) {
48441+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48442+ elf_ppnt->p_memsz > pax_task_size ||
48443+ pax_task_size - elf_ppnt->p_memsz < k) {
48444 /* set_brk can never work. Avoid overflows. */
48445 send_sig(SIGKILL, current, 0);
48446 retval = -EINVAL;
48447@@ -883,17 +1302,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
48448 goto out_free_dentry;
48449 }
48450 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48451- send_sig(SIGSEGV, current, 0);
48452- retval = -EFAULT; /* Nobody gets to see this, but.. */
48453- goto out_free_dentry;
48454+ /*
48455+ * This bss-zeroing can fail if the ELF
48456+ * file specifies odd protections. So
48457+ * we don't check the return value
48458+ */
48459 }
48460
48461+#ifdef CONFIG_PAX_RANDMMAP
48462+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48463+ unsigned long start, size, flags, vm_flags;
48464+
48465+ start = ELF_PAGEALIGN(elf_brk);
48466+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48467+ flags = MAP_FIXED | MAP_PRIVATE;
48468+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
48469+
48470+ down_write(&current->mm->mmap_sem);
48471+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
48472+ retval = -ENOMEM;
48473+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48474+// if (current->personality & ADDR_NO_RANDOMIZE)
48475+// vm_flags |= VM_READ | VM_MAYREAD;
48476+ start = mmap_region(NULL, start, PAGE_ALIGN(size), flags, vm_flags, 0);
48477+ up_write(&current->mm->mmap_sem);
48478+ retval = IS_ERR_VALUE(start) ? start : 0;
48479+ } else
48480+ up_write(&current->mm->mmap_sem);
48481+ if (retval == 0)
48482+ retval = set_brk(start + size, start + size + PAGE_SIZE);
48483+ if (retval < 0) {
48484+ send_sig(SIGKILL, current, 0);
48485+ goto out_free_dentry;
48486+ }
48487+ }
48488+#endif
48489+
48490 if (elf_interpreter) {
48491- unsigned long interp_map_addr = 0;
48492-
48493 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48494 interpreter,
48495- &interp_map_addr,
48496 load_bias);
48497 if (!IS_ERR((void *)elf_entry)) {
48498 /*
48499@@ -1115,7 +1562,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48500 * Decide what to dump of a segment, part, all or none.
48501 */
48502 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48503- unsigned long mm_flags)
48504+ unsigned long mm_flags, long signr)
48505 {
48506 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48507
48508@@ -1152,7 +1599,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48509 if (vma->vm_file == NULL)
48510 return 0;
48511
48512- if (FILTER(MAPPED_PRIVATE))
48513+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48514 goto whole;
48515
48516 /*
48517@@ -1374,9 +1821,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48518 {
48519 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48520 int i = 0;
48521- do
48522+ do {
48523 i += 2;
48524- while (auxv[i - 2] != AT_NULL);
48525+ } while (auxv[i - 2] != AT_NULL);
48526 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48527 }
48528
48529@@ -2006,14 +2453,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48530 }
48531
48532 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48533- unsigned long mm_flags)
48534+ struct coredump_params *cprm)
48535 {
48536 struct vm_area_struct *vma;
48537 size_t size = 0;
48538
48539 for (vma = first_vma(current, gate_vma); vma != NULL;
48540 vma = next_vma(vma, gate_vma))
48541- size += vma_dump_size(vma, mm_flags);
48542+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48543 return size;
48544 }
48545
48546@@ -2107,7 +2554,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48547
48548 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48549
48550- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48551+ offset += elf_core_vma_data_size(gate_vma, cprm);
48552 offset += elf_core_extra_data_size();
48553 e_shoff = offset;
48554
48555@@ -2121,10 +2568,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48556 offset = dataoff;
48557
48558 size += sizeof(*elf);
48559+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48560 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48561 goto end_coredump;
48562
48563 size += sizeof(*phdr4note);
48564+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48565 if (size > cprm->limit
48566 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48567 goto end_coredump;
48568@@ -2138,7 +2587,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48569 phdr.p_offset = offset;
48570 phdr.p_vaddr = vma->vm_start;
48571 phdr.p_paddr = 0;
48572- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48573+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48574 phdr.p_memsz = vma->vm_end - vma->vm_start;
48575 offset += phdr.p_filesz;
48576 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48577@@ -2149,6 +2598,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48578 phdr.p_align = ELF_EXEC_PAGESIZE;
48579
48580 size += sizeof(phdr);
48581+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48582 if (size > cprm->limit
48583 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48584 goto end_coredump;
48585@@ -2173,7 +2623,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48586 unsigned long addr;
48587 unsigned long end;
48588
48589- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48590+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48591
48592 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48593 struct page *page;
48594@@ -2182,6 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48595 page = get_dump_page(addr);
48596 if (page) {
48597 void *kaddr = kmap(page);
48598+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48599 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48600 !dump_write(cprm->file, kaddr,
48601 PAGE_SIZE);
48602@@ -2199,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48603
48604 if (e_phnum == PN_XNUM) {
48605 size += sizeof(*shdr4extnum);
48606+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48607 if (size > cprm->limit
48608 || !dump_write(cprm->file, shdr4extnum,
48609 sizeof(*shdr4extnum)))
48610@@ -2219,6 +2671,97 @@ out:
48611
48612 #endif /* CONFIG_ELF_CORE */
48613
48614+#ifdef CONFIG_PAX_MPROTECT
48615+/* PaX: non-PIC ELF libraries need relocations on their executable segments
48616+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48617+ * we'll remove VM_MAYWRITE for good on RELRO segments.
48618+ *
48619+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48620+ * basis because we want to allow the common case and not the special ones.
48621+ */
48622+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48623+{
48624+ struct elfhdr elf_h;
48625+ struct elf_phdr elf_p;
48626+ unsigned long i;
48627+ unsigned long oldflags;
48628+ bool is_textrel_rw, is_textrel_rx, is_relro;
48629+
48630+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48631+ return;
48632+
48633+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48634+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48635+
48636+#ifdef CONFIG_PAX_ELFRELOCS
48637+ /* possible TEXTREL */
48638+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48639+ 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);
48640+#else
48641+ is_textrel_rw = false;
48642+ is_textrel_rx = false;
48643+#endif
48644+
48645+ /* possible RELRO */
48646+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48647+
48648+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48649+ return;
48650+
48651+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48652+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48653+
48654+#ifdef CONFIG_PAX_ETEXECRELOCS
48655+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48656+#else
48657+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48658+#endif
48659+
48660+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48661+ !elf_check_arch(&elf_h) ||
48662+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48663+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48664+ return;
48665+
48666+ for (i = 0UL; i < elf_h.e_phnum; i++) {
48667+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48668+ return;
48669+ switch (elf_p.p_type) {
48670+ case PT_DYNAMIC:
48671+ if (!is_textrel_rw && !is_textrel_rx)
48672+ continue;
48673+ i = 0UL;
48674+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48675+ elf_dyn dyn;
48676+
48677+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48678+ return;
48679+ if (dyn.d_tag == DT_NULL)
48680+ return;
48681+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48682+ gr_log_textrel(vma);
48683+ if (is_textrel_rw)
48684+ vma->vm_flags |= VM_MAYWRITE;
48685+ else
48686+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48687+ vma->vm_flags &= ~VM_MAYWRITE;
48688+ return;
48689+ }
48690+ i++;
48691+ }
48692+ return;
48693+
48694+ case PT_GNU_RELRO:
48695+ if (!is_relro)
48696+ continue;
48697+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48698+ vma->vm_flags &= ~VM_MAYWRITE;
48699+ return;
48700+ }
48701+ }
48702+}
48703+#endif
48704+
48705 static int __init init_elf_binfmt(void)
48706 {
48707 register_binfmt(&elf_format);
48708diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48709index b563719..3868998 100644
48710--- a/fs/binfmt_flat.c
48711+++ b/fs/binfmt_flat.c
48712@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48713 realdatastart = (unsigned long) -ENOMEM;
48714 printk("Unable to allocate RAM for process data, errno %d\n",
48715 (int)-realdatastart);
48716+ down_write(&current->mm->mmap_sem);
48717 vm_munmap(textpos, text_len);
48718+ up_write(&current->mm->mmap_sem);
48719 ret = realdatastart;
48720 goto err;
48721 }
48722@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48723 }
48724 if (IS_ERR_VALUE(result)) {
48725 printk("Unable to read data+bss, errno %d\n", (int)-result);
48726+ down_write(&current->mm->mmap_sem);
48727 vm_munmap(textpos, text_len);
48728 vm_munmap(realdatastart, len);
48729+ up_write(&current->mm->mmap_sem);
48730 ret = result;
48731 goto err;
48732 }
48733@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48734 }
48735 if (IS_ERR_VALUE(result)) {
48736 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48737+ down_write(&current->mm->mmap_sem);
48738 vm_munmap(textpos, text_len + data_len + extra +
48739 MAX_SHARED_LIBS * sizeof(unsigned long));
48740+ up_write(&current->mm->mmap_sem);
48741 ret = result;
48742 goto err;
48743 }
48744diff --git a/fs/bio.c b/fs/bio.c
48745index b96fc6c..431d628 100644
48746--- a/fs/bio.c
48747+++ b/fs/bio.c
48748@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48749 /*
48750 * Overflow, abort
48751 */
48752- if (end < start)
48753+ if (end < start || end - start > INT_MAX - nr_pages)
48754 return ERR_PTR(-EINVAL);
48755
48756 nr_pages += end - start;
48757@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48758 /*
48759 * Overflow, abort
48760 */
48761- if (end < start)
48762+ if (end < start || end - start > INT_MAX - nr_pages)
48763 return ERR_PTR(-EINVAL);
48764
48765 nr_pages += end - start;
48766@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48767 const int read = bio_data_dir(bio) == READ;
48768 struct bio_map_data *bmd = bio->bi_private;
48769 int i;
48770- char *p = bmd->sgvecs[0].iov_base;
48771+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48772
48773 __bio_for_each_segment(bvec, bio, i, 0) {
48774 char *addr = page_address(bvec->bv_page);
48775diff --git a/fs/block_dev.c b/fs/block_dev.c
48776index 78edf76..da14f3f 100644
48777--- a/fs/block_dev.c
48778+++ b/fs/block_dev.c
48779@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48780 else if (bdev->bd_contains == bdev)
48781 return true; /* is a whole device which isn't held */
48782
48783- else if (whole->bd_holder == bd_may_claim)
48784+ else if (whole->bd_holder == (void *)bd_may_claim)
48785 return true; /* is a partition of a device that is being partitioned */
48786 else if (whole->bd_holder != NULL)
48787 return false; /* is a partition of a held device */
48788diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48789index eea5da7..88fead70 100644
48790--- a/fs/btrfs/ctree.c
48791+++ b/fs/btrfs/ctree.c
48792@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48793 free_extent_buffer(buf);
48794 add_root_to_dirty_list(root);
48795 } else {
48796- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48797- parent_start = parent->start;
48798- else
48799+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48800+ if (parent)
48801+ parent_start = parent->start;
48802+ else
48803+ parent_start = 0;
48804+ } else
48805 parent_start = 0;
48806
48807 WARN_ON(trans->transid != btrfs_header_generation(parent));
48808diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48809index 659ea81..0f63c1a 100644
48810--- a/fs/btrfs/inode.c
48811+++ b/fs/btrfs/inode.c
48812@@ -7300,7 +7300,7 @@ fail:
48813 return -ENOMEM;
48814 }
48815
48816-static int btrfs_getattr(struct vfsmount *mnt,
48817+int btrfs_getattr(struct vfsmount *mnt,
48818 struct dentry *dentry, struct kstat *stat)
48819 {
48820 struct inode *inode = dentry->d_inode;
48821@@ -7314,6 +7314,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48822 return 0;
48823 }
48824
48825+EXPORT_SYMBOL(btrfs_getattr);
48826+
48827+dev_t get_btrfs_dev_from_inode(struct inode *inode)
48828+{
48829+ return BTRFS_I(inode)->root->anon_dev;
48830+}
48831+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48832+
48833 /*
48834 * If a file is moved, it will inherit the cow and compression flags of the new
48835 * directory.
48836diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48837index 338f259..b657640 100644
48838--- a/fs/btrfs/ioctl.c
48839+++ b/fs/btrfs/ioctl.c
48840@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48841 for (i = 0; i < num_types; i++) {
48842 struct btrfs_space_info *tmp;
48843
48844+ /* Don't copy in more than we allocated */
48845 if (!slot_count)
48846 break;
48847
48848+ slot_count--;
48849+
48850 info = NULL;
48851 rcu_read_lock();
48852 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48853@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48854 memcpy(dest, &space, sizeof(space));
48855 dest++;
48856 space_args.total_spaces++;
48857- slot_count--;
48858 }
48859- if (!slot_count)
48860- break;
48861 }
48862 up_read(&info->groups_sem);
48863 }
48864diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48865index 300e09a..9fe4539 100644
48866--- a/fs/btrfs/relocation.c
48867+++ b/fs/btrfs/relocation.c
48868@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48869 }
48870 spin_unlock(&rc->reloc_root_tree.lock);
48871
48872- BUG_ON((struct btrfs_root *)node->data != root);
48873+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
48874
48875 if (!del) {
48876 spin_lock(&rc->reloc_root_tree.lock);
48877diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48878index d8982e9..29a85fa 100644
48879--- a/fs/btrfs/super.c
48880+++ b/fs/btrfs/super.c
48881@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48882 function, line, errstr);
48883 return;
48884 }
48885- ACCESS_ONCE(trans->transaction->aborted) = errno;
48886+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48887 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48888 }
48889 /*
48890diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48891index 622f469..e8d2d55 100644
48892--- a/fs/cachefiles/bind.c
48893+++ b/fs/cachefiles/bind.c
48894@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48895 args);
48896
48897 /* start by checking things over */
48898- ASSERT(cache->fstop_percent >= 0 &&
48899- cache->fstop_percent < cache->fcull_percent &&
48900+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
48901 cache->fcull_percent < cache->frun_percent &&
48902 cache->frun_percent < 100);
48903
48904- ASSERT(cache->bstop_percent >= 0 &&
48905- cache->bstop_percent < cache->bcull_percent &&
48906+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
48907 cache->bcull_percent < cache->brun_percent &&
48908 cache->brun_percent < 100);
48909
48910diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48911index 0a1467b..6a53245 100644
48912--- a/fs/cachefiles/daemon.c
48913+++ b/fs/cachefiles/daemon.c
48914@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48915 if (n > buflen)
48916 return -EMSGSIZE;
48917
48918- if (copy_to_user(_buffer, buffer, n) != 0)
48919+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48920 return -EFAULT;
48921
48922 return n;
48923@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48924 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48925 return -EIO;
48926
48927- if (datalen < 0 || datalen > PAGE_SIZE - 1)
48928+ if (datalen > PAGE_SIZE - 1)
48929 return -EOPNOTSUPP;
48930
48931 /* drag the command string into the kernel so we can parse it */
48932@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48933 if (args[0] != '%' || args[1] != '\0')
48934 return -EINVAL;
48935
48936- if (fstop < 0 || fstop >= cache->fcull_percent)
48937+ if (fstop >= cache->fcull_percent)
48938 return cachefiles_daemon_range_error(cache, args);
48939
48940 cache->fstop_percent = fstop;
48941@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48942 if (args[0] != '%' || args[1] != '\0')
48943 return -EINVAL;
48944
48945- if (bstop < 0 || bstop >= cache->bcull_percent)
48946+ if (bstop >= cache->bcull_percent)
48947 return cachefiles_daemon_range_error(cache, args);
48948
48949 cache->bstop_percent = bstop;
48950diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48951index 4938251..7e01445 100644
48952--- a/fs/cachefiles/internal.h
48953+++ b/fs/cachefiles/internal.h
48954@@ -59,7 +59,7 @@ struct cachefiles_cache {
48955 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48956 struct rb_root active_nodes; /* active nodes (can't be culled) */
48957 rwlock_t active_lock; /* lock for active_nodes */
48958- atomic_t gravecounter; /* graveyard uniquifier */
48959+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48960 unsigned frun_percent; /* when to stop culling (% files) */
48961 unsigned fcull_percent; /* when to start culling (% files) */
48962 unsigned fstop_percent; /* when to stop allocating (% files) */
48963@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
48964 * proc.c
48965 */
48966 #ifdef CONFIG_CACHEFILES_HISTOGRAM
48967-extern atomic_t cachefiles_lookup_histogram[HZ];
48968-extern atomic_t cachefiles_mkdir_histogram[HZ];
48969-extern atomic_t cachefiles_create_histogram[HZ];
48970+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48971+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48972+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
48973
48974 extern int __init cachefiles_proc_init(void);
48975 extern void cachefiles_proc_cleanup(void);
48976 static inline
48977-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
48978+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
48979 {
48980 unsigned long jif = jiffies - start_jif;
48981 if (jif >= HZ)
48982 jif = HZ - 1;
48983- atomic_inc(&histogram[jif]);
48984+ atomic_inc_unchecked(&histogram[jif]);
48985 }
48986
48987 #else
48988diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
48989index 8c01c5fc..15f982e 100644
48990--- a/fs/cachefiles/namei.c
48991+++ b/fs/cachefiles/namei.c
48992@@ -317,7 +317,7 @@ try_again:
48993 /* first step is to make up a grave dentry in the graveyard */
48994 sprintf(nbuffer, "%08x%08x",
48995 (uint32_t) get_seconds(),
48996- (uint32_t) atomic_inc_return(&cache->gravecounter));
48997+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
48998
48999 /* do the multiway lock magic */
49000 trap = lock_rename(cache->graveyard, dir);
49001diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49002index eccd339..4c1d995 100644
49003--- a/fs/cachefiles/proc.c
49004+++ b/fs/cachefiles/proc.c
49005@@ -14,9 +14,9 @@
49006 #include <linux/seq_file.h>
49007 #include "internal.h"
49008
49009-atomic_t cachefiles_lookup_histogram[HZ];
49010-atomic_t cachefiles_mkdir_histogram[HZ];
49011-atomic_t cachefiles_create_histogram[HZ];
49012+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49013+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49014+atomic_unchecked_t cachefiles_create_histogram[HZ];
49015
49016 /*
49017 * display the latency histogram
49018@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49019 return 0;
49020 default:
49021 index = (unsigned long) v - 3;
49022- x = atomic_read(&cachefiles_lookup_histogram[index]);
49023- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49024- z = atomic_read(&cachefiles_create_histogram[index]);
49025+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49026+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49027+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49028 if (x == 0 && y == 0 && z == 0)
49029 return 0;
49030
49031diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49032index 4809922..aab2c39 100644
49033--- a/fs/cachefiles/rdwr.c
49034+++ b/fs/cachefiles/rdwr.c
49035@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49036 old_fs = get_fs();
49037 set_fs(KERNEL_DS);
49038 ret = file->f_op->write(
49039- file, (const void __user *) data, len, &pos);
49040+ file, (const void __force_user *) data, len, &pos);
49041 set_fs(old_fs);
49042 kunmap(page);
49043 if (ret != len)
49044diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49045index 8c1aabe..bbf856a 100644
49046--- a/fs/ceph/dir.c
49047+++ b/fs/ceph/dir.c
49048@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49049 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49050 struct ceph_mds_client *mdsc = fsc->mdsc;
49051 unsigned frag = fpos_frag(filp->f_pos);
49052- int off = fpos_off(filp->f_pos);
49053+ unsigned int off = fpos_off(filp->f_pos);
49054 int err;
49055 u32 ftype;
49056 struct ceph_mds_reply_info_parsed *rinfo;
49057diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49058index d9ea6ed..1e6c8ac 100644
49059--- a/fs/cifs/cifs_debug.c
49060+++ b/fs/cifs/cifs_debug.c
49061@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49062
49063 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49064 #ifdef CONFIG_CIFS_STATS2
49065- atomic_set(&totBufAllocCount, 0);
49066- atomic_set(&totSmBufAllocCount, 0);
49067+ atomic_set_unchecked(&totBufAllocCount, 0);
49068+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49069 #endif /* CONFIG_CIFS_STATS2 */
49070 spin_lock(&cifs_tcp_ses_lock);
49071 list_for_each(tmp1, &cifs_tcp_ses_list) {
49072@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49073 tcon = list_entry(tmp3,
49074 struct cifs_tcon,
49075 tcon_list);
49076- atomic_set(&tcon->num_smbs_sent, 0);
49077+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49078 if (server->ops->clear_stats)
49079 server->ops->clear_stats(tcon);
49080 }
49081@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49082 smBufAllocCount.counter, cifs_min_small);
49083 #ifdef CONFIG_CIFS_STATS2
49084 seq_printf(m, "Total Large %d Small %d Allocations\n",
49085- atomic_read(&totBufAllocCount),
49086- atomic_read(&totSmBufAllocCount));
49087+ atomic_read_unchecked(&totBufAllocCount),
49088+ atomic_read_unchecked(&totSmBufAllocCount));
49089 #endif /* CONFIG_CIFS_STATS2 */
49090
49091 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49092@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49093 if (tcon->need_reconnect)
49094 seq_puts(m, "\tDISCONNECTED ");
49095 seq_printf(m, "\nSMBs: %d",
49096- atomic_read(&tcon->num_smbs_sent));
49097+ atomic_read_unchecked(&tcon->num_smbs_sent));
49098 if (server->ops->print_stats)
49099 server->ops->print_stats(m, tcon);
49100 }
49101diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49102index e328339..322228b 100644
49103--- a/fs/cifs/cifsfs.c
49104+++ b/fs/cifs/cifsfs.c
49105@@ -1002,7 +1002,7 @@ cifs_init_request_bufs(void)
49106 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49107 cifs_req_cachep = kmem_cache_create("cifs_request",
49108 CIFSMaxBufSize + max_hdr_size, 0,
49109- SLAB_HWCACHE_ALIGN, NULL);
49110+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49111 if (cifs_req_cachep == NULL)
49112 return -ENOMEM;
49113
49114@@ -1029,7 +1029,7 @@ cifs_init_request_bufs(void)
49115 efficient to alloc 1 per page off the slab compared to 17K (5page)
49116 alloc of large cifs buffers even when page debugging is on */
49117 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49118- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49119+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49120 NULL);
49121 if (cifs_sm_req_cachep == NULL) {
49122 mempool_destroy(cifs_req_poolp);
49123@@ -1114,8 +1114,8 @@ init_cifs(void)
49124 atomic_set(&bufAllocCount, 0);
49125 atomic_set(&smBufAllocCount, 0);
49126 #ifdef CONFIG_CIFS_STATS2
49127- atomic_set(&totBufAllocCount, 0);
49128- atomic_set(&totSmBufAllocCount, 0);
49129+ atomic_set_unchecked(&totBufAllocCount, 0);
49130+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49131 #endif /* CONFIG_CIFS_STATS2 */
49132
49133 atomic_set(&midCount, 0);
49134diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49135index e6899ce..d6b2920 100644
49136--- a/fs/cifs/cifsglob.h
49137+++ b/fs/cifs/cifsglob.h
49138@@ -751,35 +751,35 @@ struct cifs_tcon {
49139 __u16 Flags; /* optional support bits */
49140 enum statusEnum tidStatus;
49141 #ifdef CONFIG_CIFS_STATS
49142- atomic_t num_smbs_sent;
49143+ atomic_unchecked_t num_smbs_sent;
49144 union {
49145 struct {
49146- atomic_t num_writes;
49147- atomic_t num_reads;
49148- atomic_t num_flushes;
49149- atomic_t num_oplock_brks;
49150- atomic_t num_opens;
49151- atomic_t num_closes;
49152- atomic_t num_deletes;
49153- atomic_t num_mkdirs;
49154- atomic_t num_posixopens;
49155- atomic_t num_posixmkdirs;
49156- atomic_t num_rmdirs;
49157- atomic_t num_renames;
49158- atomic_t num_t2renames;
49159- atomic_t num_ffirst;
49160- atomic_t num_fnext;
49161- atomic_t num_fclose;
49162- atomic_t num_hardlinks;
49163- atomic_t num_symlinks;
49164- atomic_t num_locks;
49165- atomic_t num_acl_get;
49166- atomic_t num_acl_set;
49167+ atomic_unchecked_t num_writes;
49168+ atomic_unchecked_t num_reads;
49169+ atomic_unchecked_t num_flushes;
49170+ atomic_unchecked_t num_oplock_brks;
49171+ atomic_unchecked_t num_opens;
49172+ atomic_unchecked_t num_closes;
49173+ atomic_unchecked_t num_deletes;
49174+ atomic_unchecked_t num_mkdirs;
49175+ atomic_unchecked_t num_posixopens;
49176+ atomic_unchecked_t num_posixmkdirs;
49177+ atomic_unchecked_t num_rmdirs;
49178+ atomic_unchecked_t num_renames;
49179+ atomic_unchecked_t num_t2renames;
49180+ atomic_unchecked_t num_ffirst;
49181+ atomic_unchecked_t num_fnext;
49182+ atomic_unchecked_t num_fclose;
49183+ atomic_unchecked_t num_hardlinks;
49184+ atomic_unchecked_t num_symlinks;
49185+ atomic_unchecked_t num_locks;
49186+ atomic_unchecked_t num_acl_get;
49187+ atomic_unchecked_t num_acl_set;
49188 } cifs_stats;
49189 #ifdef CONFIG_CIFS_SMB2
49190 struct {
49191- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49192- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49193+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49194+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49195 } smb2_stats;
49196 #endif /* CONFIG_CIFS_SMB2 */
49197 } stats;
49198@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49199 }
49200
49201 #ifdef CONFIG_CIFS_STATS
49202-#define cifs_stats_inc atomic_inc
49203+#define cifs_stats_inc atomic_inc_unchecked
49204
49205 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49206 unsigned int bytes)
49207@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49208 /* Various Debug counters */
49209 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49210 #ifdef CONFIG_CIFS_STATS2
49211-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49212-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49213+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49214+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49215 #endif
49216 GLOBAL_EXTERN atomic_t smBufAllocCount;
49217 GLOBAL_EXTERN atomic_t midCount;
49218diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49219index 51dc2fb..1e12a33 100644
49220--- a/fs/cifs/link.c
49221+++ b/fs/cifs/link.c
49222@@ -616,7 +616,7 @@ symlink_exit:
49223
49224 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49225 {
49226- char *p = nd_get_link(nd);
49227+ const char *p = nd_get_link(nd);
49228 if (!IS_ERR(p))
49229 kfree(p);
49230 }
49231diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49232index 3a00c0d..42d901c 100644
49233--- a/fs/cifs/misc.c
49234+++ b/fs/cifs/misc.c
49235@@ -169,7 +169,7 @@ cifs_buf_get(void)
49236 memset(ret_buf, 0, buf_size + 3);
49237 atomic_inc(&bufAllocCount);
49238 #ifdef CONFIG_CIFS_STATS2
49239- atomic_inc(&totBufAllocCount);
49240+ atomic_inc_unchecked(&totBufAllocCount);
49241 #endif /* CONFIG_CIFS_STATS2 */
49242 }
49243
49244@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49245 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49246 atomic_inc(&smBufAllocCount);
49247 #ifdef CONFIG_CIFS_STATS2
49248- atomic_inc(&totSmBufAllocCount);
49249+ atomic_inc_unchecked(&totSmBufAllocCount);
49250 #endif /* CONFIG_CIFS_STATS2 */
49251
49252 }
49253diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49254index 47bc5a8..10decbe 100644
49255--- a/fs/cifs/smb1ops.c
49256+++ b/fs/cifs/smb1ops.c
49257@@ -586,27 +586,27 @@ static void
49258 cifs_clear_stats(struct cifs_tcon *tcon)
49259 {
49260 #ifdef CONFIG_CIFS_STATS
49261- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49262- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49263- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49264- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49265- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49266- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49267- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49268- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49269- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49270- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49271- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49272- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49273- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49274- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49275- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49276- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49277- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49278- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49279- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49280- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49281- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49282+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49283+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49284+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49285+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49286+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49287+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49288+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49289+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49290+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49291+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49292+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49293+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49294+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49295+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49296+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49297+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49298+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49299+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49300+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49301+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49302+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49303 #endif
49304 }
49305
49306@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49307 {
49308 #ifdef CONFIG_CIFS_STATS
49309 seq_printf(m, " Oplocks breaks: %d",
49310- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49311+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49312 seq_printf(m, "\nReads: %d Bytes: %llu",
49313- atomic_read(&tcon->stats.cifs_stats.num_reads),
49314+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49315 (long long)(tcon->bytes_read));
49316 seq_printf(m, "\nWrites: %d Bytes: %llu",
49317- atomic_read(&tcon->stats.cifs_stats.num_writes),
49318+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49319 (long long)(tcon->bytes_written));
49320 seq_printf(m, "\nFlushes: %d",
49321- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49322+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49323 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49324- atomic_read(&tcon->stats.cifs_stats.num_locks),
49325- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49326- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49327+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49328+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49329+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49330 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
49331- atomic_read(&tcon->stats.cifs_stats.num_opens),
49332- atomic_read(&tcon->stats.cifs_stats.num_closes),
49333- atomic_read(&tcon->stats.cifs_stats.num_deletes));
49334+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
49335+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
49336+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
49337 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
49338- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
49339- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
49340+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
49341+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
49342 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
49343- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
49344- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
49345+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
49346+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
49347 seq_printf(m, "\nRenames: %d T2 Renames %d",
49348- atomic_read(&tcon->stats.cifs_stats.num_renames),
49349- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
49350+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
49351+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
49352 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
49353- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
49354- atomic_read(&tcon->stats.cifs_stats.num_fnext),
49355- atomic_read(&tcon->stats.cifs_stats.num_fclose));
49356+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
49357+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
49358+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
49359 #endif
49360 }
49361
49362diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
49363index bceffe7..cd1ae59 100644
49364--- a/fs/cifs/smb2ops.c
49365+++ b/fs/cifs/smb2ops.c
49366@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
49367 #ifdef CONFIG_CIFS_STATS
49368 int i;
49369 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
49370- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49371- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49372+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49373+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49374 }
49375 #endif
49376 }
49377@@ -284,66 +284,66 @@ static void
49378 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49379 {
49380 #ifdef CONFIG_CIFS_STATS
49381- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49382- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49383+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49384+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49385 seq_printf(m, "\nNegotiates: %d sent %d failed",
49386- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
49387- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
49388+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
49389+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
49390 seq_printf(m, "\nSessionSetups: %d sent %d failed",
49391- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
49392- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
49393+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
49394+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
49395 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
49396 seq_printf(m, "\nLogoffs: %d sent %d failed",
49397- atomic_read(&sent[SMB2_LOGOFF_HE]),
49398- atomic_read(&failed[SMB2_LOGOFF_HE]));
49399+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
49400+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
49401 seq_printf(m, "\nTreeConnects: %d sent %d failed",
49402- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
49403- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
49404+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
49405+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
49406 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
49407- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
49408- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
49409+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
49410+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
49411 seq_printf(m, "\nCreates: %d sent %d failed",
49412- atomic_read(&sent[SMB2_CREATE_HE]),
49413- atomic_read(&failed[SMB2_CREATE_HE]));
49414+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
49415+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
49416 seq_printf(m, "\nCloses: %d sent %d failed",
49417- atomic_read(&sent[SMB2_CLOSE_HE]),
49418- atomic_read(&failed[SMB2_CLOSE_HE]));
49419+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49420+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49421 seq_printf(m, "\nFlushes: %d sent %d failed",
49422- atomic_read(&sent[SMB2_FLUSH_HE]),
49423- atomic_read(&failed[SMB2_FLUSH_HE]));
49424+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49425+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49426 seq_printf(m, "\nReads: %d sent %d failed",
49427- atomic_read(&sent[SMB2_READ_HE]),
49428- atomic_read(&failed[SMB2_READ_HE]));
49429+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
49430+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
49431 seq_printf(m, "\nWrites: %d sent %d failed",
49432- atomic_read(&sent[SMB2_WRITE_HE]),
49433- atomic_read(&failed[SMB2_WRITE_HE]));
49434+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49435+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49436 seq_printf(m, "\nLocks: %d sent %d failed",
49437- atomic_read(&sent[SMB2_LOCK_HE]),
49438- atomic_read(&failed[SMB2_LOCK_HE]));
49439+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49440+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49441 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49442- atomic_read(&sent[SMB2_IOCTL_HE]),
49443- atomic_read(&failed[SMB2_IOCTL_HE]));
49444+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49445+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49446 seq_printf(m, "\nCancels: %d sent %d failed",
49447- atomic_read(&sent[SMB2_CANCEL_HE]),
49448- atomic_read(&failed[SMB2_CANCEL_HE]));
49449+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49450+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49451 seq_printf(m, "\nEchos: %d sent %d failed",
49452- atomic_read(&sent[SMB2_ECHO_HE]),
49453- atomic_read(&failed[SMB2_ECHO_HE]));
49454+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49455+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49456 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49457- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49458- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49459+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49460+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49461 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49462- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49463- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49464+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49465+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49466 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49467- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49468- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49469+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49470+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49471 seq_printf(m, "\nSetInfos: %d sent %d failed",
49472- atomic_read(&sent[SMB2_SET_INFO_HE]),
49473- atomic_read(&failed[SMB2_SET_INFO_HE]));
49474+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49475+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49476 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49477- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49478- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49479+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49480+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49481 #endif
49482 }
49483
49484diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49485index 41d9d07..dbb4772 100644
49486--- a/fs/cifs/smb2pdu.c
49487+++ b/fs/cifs/smb2pdu.c
49488@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49489 default:
49490 cERROR(1, "info level %u isn't supported",
49491 srch_inf->info_level);
49492- rc = -EINVAL;
49493- goto qdir_exit;
49494+ return -EINVAL;
49495 }
49496
49497 req->FileIndex = cpu_to_le32(index);
49498diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49499index 958ae0e..505c9d0 100644
49500--- a/fs/coda/cache.c
49501+++ b/fs/coda/cache.c
49502@@ -24,7 +24,7 @@
49503 #include "coda_linux.h"
49504 #include "coda_cache.h"
49505
49506-static atomic_t permission_epoch = ATOMIC_INIT(0);
49507+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49508
49509 /* replace or extend an acl cache hit */
49510 void coda_cache_enter(struct inode *inode, int mask)
49511@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49512 struct coda_inode_info *cii = ITOC(inode);
49513
49514 spin_lock(&cii->c_lock);
49515- cii->c_cached_epoch = atomic_read(&permission_epoch);
49516+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49517 if (cii->c_uid != current_fsuid()) {
49518 cii->c_uid = current_fsuid();
49519 cii->c_cached_perm = mask;
49520@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49521 {
49522 struct coda_inode_info *cii = ITOC(inode);
49523 spin_lock(&cii->c_lock);
49524- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49525+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49526 spin_unlock(&cii->c_lock);
49527 }
49528
49529 /* remove all acl caches */
49530 void coda_cache_clear_all(struct super_block *sb)
49531 {
49532- atomic_inc(&permission_epoch);
49533+ atomic_inc_unchecked(&permission_epoch);
49534 }
49535
49536
49537@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49538 spin_lock(&cii->c_lock);
49539 hit = (mask & cii->c_cached_perm) == mask &&
49540 cii->c_uid == current_fsuid() &&
49541- cii->c_cached_epoch == atomic_read(&permission_epoch);
49542+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49543 spin_unlock(&cii->c_lock);
49544
49545 return hit;
49546diff --git a/fs/compat.c b/fs/compat.c
49547index a06dcbc..dacb6d3 100644
49548--- a/fs/compat.c
49549+++ b/fs/compat.c
49550@@ -54,7 +54,7 @@
49551 #include <asm/ioctls.h>
49552 #include "internal.h"
49553
49554-int compat_log = 1;
49555+int compat_log = 0;
49556
49557 int compat_printk(const char *fmt, ...)
49558 {
49559@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49560
49561 set_fs(KERNEL_DS);
49562 /* The __user pointer cast is valid because of the set_fs() */
49563- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49564+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49565 set_fs(oldfs);
49566 /* truncating is ok because it's a user address */
49567 if (!ret)
49568@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49569 goto out;
49570
49571 ret = -EINVAL;
49572- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49573+ if (nr_segs > UIO_MAXIOV)
49574 goto out;
49575 if (nr_segs > fast_segs) {
49576 ret = -ENOMEM;
49577@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
49578
49579 struct compat_readdir_callback {
49580 struct compat_old_linux_dirent __user *dirent;
49581+ struct file * file;
49582 int result;
49583 };
49584
49585@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49586 buf->result = -EOVERFLOW;
49587 return -EOVERFLOW;
49588 }
49589+
49590+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49591+ return 0;
49592+
49593 buf->result++;
49594 dirent = buf->dirent;
49595 if (!access_ok(VERIFY_WRITE, dirent,
49596@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49597
49598 buf.result = 0;
49599 buf.dirent = dirent;
49600+ buf.file = f.file;
49601
49602 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49603 if (buf.result)
49604@@ -901,6 +907,7 @@ struct compat_linux_dirent {
49605 struct compat_getdents_callback {
49606 struct compat_linux_dirent __user *current_dir;
49607 struct compat_linux_dirent __user *previous;
49608+ struct file * file;
49609 int count;
49610 int error;
49611 };
49612@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49613 buf->error = -EOVERFLOW;
49614 return -EOVERFLOW;
49615 }
49616+
49617+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49618+ return 0;
49619+
49620 dirent = buf->previous;
49621 if (dirent) {
49622 if (__put_user(offset, &dirent->d_off))
49623@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49624 buf.previous = NULL;
49625 buf.count = count;
49626 buf.error = 0;
49627+ buf.file = f.file;
49628
49629 error = vfs_readdir(f.file, compat_filldir, &buf);
49630 if (error >= 0)
49631@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49632 struct compat_getdents_callback64 {
49633 struct linux_dirent64 __user *current_dir;
49634 struct linux_dirent64 __user *previous;
49635+ struct file * file;
49636 int count;
49637 int error;
49638 };
49639@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49640 buf->error = -EINVAL; /* only used if we fail.. */
49641 if (reclen > buf->count)
49642 return -EINVAL;
49643+
49644+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49645+ return 0;
49646+
49647 dirent = buf->previous;
49648
49649 if (dirent) {
49650@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49651 buf.previous = NULL;
49652 buf.count = count;
49653 buf.error = 0;
49654+ buf.file = f.file;
49655
49656 error = vfs_readdir(f.file, compat_filldir64, &buf);
49657 if (error >= 0)
49658 error = buf.error;
49659 lastdirent = buf.previous;
49660 if (lastdirent) {
49661- typeof(lastdirent->d_off) d_off = f.file->f_pos;
49662+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49663 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49664 error = -EFAULT;
49665 else
49666diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49667index a81147e..20bf2b5 100644
49668--- a/fs/compat_binfmt_elf.c
49669+++ b/fs/compat_binfmt_elf.c
49670@@ -30,11 +30,13 @@
49671 #undef elf_phdr
49672 #undef elf_shdr
49673 #undef elf_note
49674+#undef elf_dyn
49675 #undef elf_addr_t
49676 #define elfhdr elf32_hdr
49677 #define elf_phdr elf32_phdr
49678 #define elf_shdr elf32_shdr
49679 #define elf_note elf32_note
49680+#define elf_dyn Elf32_Dyn
49681 #define elf_addr_t Elf32_Addr
49682
49683 /*
49684diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49685index e2f57a0..3c78771 100644
49686--- a/fs/compat_ioctl.c
49687+++ b/fs/compat_ioctl.c
49688@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49689 return -EFAULT;
49690 if (__get_user(udata, &ss32->iomem_base))
49691 return -EFAULT;
49692- ss.iomem_base = compat_ptr(udata);
49693+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49694 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49695 __get_user(ss.port_high, &ss32->port_high))
49696 return -EFAULT;
49697@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49698 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49699 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49700 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49701- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49702+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49703 return -EFAULT;
49704
49705 return ioctl_preallocate(file, p);
49706@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49707 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49708 {
49709 unsigned int a, b;
49710- a = *(unsigned int *)p;
49711- b = *(unsigned int *)q;
49712+ a = *(const unsigned int *)p;
49713+ b = *(const unsigned int *)q;
49714 if (a > b)
49715 return 1;
49716 if (a < b)
49717diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49718index 712b10f..c33c4ca 100644
49719--- a/fs/configfs/dir.c
49720+++ b/fs/configfs/dir.c
49721@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49722 static int configfs_depend_prep(struct dentry *origin,
49723 struct config_item *target)
49724 {
49725- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49726+ struct configfs_dirent *child_sd, *sd;
49727 int ret = 0;
49728
49729- BUG_ON(!origin || !sd);
49730+ BUG_ON(!origin || !origin->d_fsdata);
49731+ sd = origin->d_fsdata;
49732
49733 if (sd->s_element == target) /* Boo-yah */
49734 goto out;
49735@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49736 }
49737 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49738 struct configfs_dirent *next;
49739- const char * name;
49740+ const unsigned char * name;
49741+ char d_name[sizeof(next->s_dentry->d_iname)];
49742 int len;
49743 struct inode *inode = NULL;
49744
49745@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49746 continue;
49747
49748 name = configfs_get_name(next);
49749- len = strlen(name);
49750+ if (next->s_dentry && name == next->s_dentry->d_iname) {
49751+ len = next->s_dentry->d_name.len;
49752+ memcpy(d_name, name, len);
49753+ name = d_name;
49754+ } else
49755+ len = strlen(name);
49756
49757 /*
49758 * We'll have a dentry and an inode for
49759diff --git a/fs/coredump.c b/fs/coredump.c
49760index 1774932..5812106 100644
49761--- a/fs/coredump.c
49762+++ b/fs/coredump.c
49763@@ -52,7 +52,7 @@ struct core_name {
49764 char *corename;
49765 int used, size;
49766 };
49767-static atomic_t call_count = ATOMIC_INIT(1);
49768+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49769
49770 /* The maximal length of core_pattern is also specified in sysctl.c */
49771
49772@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49773 {
49774 char *old_corename = cn->corename;
49775
49776- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49777+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49778 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49779
49780 if (!cn->corename) {
49781@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49782 int pid_in_pattern = 0;
49783 int err = 0;
49784
49785- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49786+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49787 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49788 cn->used = 0;
49789
49790@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49791 pipe = file->f_path.dentry->d_inode->i_pipe;
49792
49793 pipe_lock(pipe);
49794- pipe->readers++;
49795- pipe->writers--;
49796+ atomic_inc(&pipe->readers);
49797+ atomic_dec(&pipe->writers);
49798
49799- while ((pipe->readers > 1) && (!signal_pending(current))) {
49800+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49801 wake_up_interruptible_sync(&pipe->wait);
49802 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49803 pipe_wait(pipe);
49804 }
49805
49806- pipe->readers--;
49807- pipe->writers++;
49808+ atomic_dec(&pipe->readers);
49809+ atomic_inc(&pipe->writers);
49810 pipe_unlock(pipe);
49811
49812 }
49813@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49814 int ispipe;
49815 struct files_struct *displaced;
49816 bool need_nonrelative = false;
49817- static atomic_t core_dump_count = ATOMIC_INIT(0);
49818+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49819+ long signr = siginfo->si_signo;
49820 struct coredump_params cprm = {
49821 .siginfo = siginfo,
49822 .regs = signal_pt_regs(),
49823@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49824 .mm_flags = mm->flags,
49825 };
49826
49827- audit_core_dumps(siginfo->si_signo);
49828+ audit_core_dumps(signr);
49829+
49830+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49831+ gr_handle_brute_attach(cprm.mm_flags);
49832
49833 binfmt = mm->binfmt;
49834 if (!binfmt || !binfmt->core_dump)
49835@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49836 need_nonrelative = true;
49837 }
49838
49839- retval = coredump_wait(siginfo->si_signo, &core_state);
49840+ retval = coredump_wait(signr, &core_state);
49841 if (retval < 0)
49842 goto fail_creds;
49843
49844@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49845 }
49846 cprm.limit = RLIM_INFINITY;
49847
49848- dump_count = atomic_inc_return(&core_dump_count);
49849+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
49850 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49851 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49852 task_tgid_vnr(current), current->comm);
49853@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49854 } else {
49855 struct inode *inode;
49856
49857+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49858+
49859 if (cprm.limit < binfmt->min_coredump)
49860 goto fail_unlock;
49861
49862@@ -640,7 +646,7 @@ close_fail:
49863 filp_close(cprm.file, NULL);
49864 fail_dropcount:
49865 if (ispipe)
49866- atomic_dec(&core_dump_count);
49867+ atomic_dec_unchecked(&core_dump_count);
49868 fail_unlock:
49869 kfree(cn.corename);
49870 fail_corename:
49871@@ -659,7 +665,7 @@ fail:
49872 */
49873 int dump_write(struct file *file, const void *addr, int nr)
49874 {
49875- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49876+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49877 }
49878 EXPORT_SYMBOL(dump_write);
49879
49880diff --git a/fs/dcache.c b/fs/dcache.c
49881index 19153a0..428c2f5 100644
49882--- a/fs/dcache.c
49883+++ b/fs/dcache.c
49884@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49885 mempages -= reserve;
49886
49887 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49888- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49889+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49890
49891 dcache_init();
49892 inode_init();
49893diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49894index a5f12b7..4ee8a6f 100644
49895--- a/fs/debugfs/inode.c
49896+++ b/fs/debugfs/inode.c
49897@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49898 */
49899 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49900 {
49901+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49902+ return __create_file(name, S_IFDIR | S_IRWXU,
49903+#else
49904 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49905+#endif
49906 parent, NULL, NULL);
49907 }
49908 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49909diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49910index cc7709e..7e7211f 100644
49911--- a/fs/ecryptfs/inode.c
49912+++ b/fs/ecryptfs/inode.c
49913@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49914 old_fs = get_fs();
49915 set_fs(get_ds());
49916 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49917- (char __user *)lower_buf,
49918+ (char __force_user *)lower_buf,
49919 PATH_MAX);
49920 set_fs(old_fs);
49921 if (rc < 0)
49922@@ -706,7 +706,7 @@ out:
49923 static void
49924 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49925 {
49926- char *buf = nd_get_link(nd);
49927+ const char *buf = nd_get_link(nd);
49928 if (!IS_ERR(buf)) {
49929 /* Free the char* */
49930 kfree(buf);
49931diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49932index 412e6ed..4292d22 100644
49933--- a/fs/ecryptfs/miscdev.c
49934+++ b/fs/ecryptfs/miscdev.c
49935@@ -315,7 +315,7 @@ check_list:
49936 goto out_unlock_msg_ctx;
49937 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49938 if (msg_ctx->msg) {
49939- if (copy_to_user(&buf[i], packet_length, packet_length_size))
49940+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49941 goto out_unlock_msg_ctx;
49942 i += packet_length_size;
49943 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49944diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49945index b2a34a1..162fa69 100644
49946--- a/fs/ecryptfs/read_write.c
49947+++ b/fs/ecryptfs/read_write.c
49948@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49949 return -EIO;
49950 fs_save = get_fs();
49951 set_fs(get_ds());
49952- rc = vfs_write(lower_file, data, size, &offset);
49953+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49954 set_fs(fs_save);
49955 mark_inode_dirty_sync(ecryptfs_inode);
49956 return rc;
49957@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49958 return -EIO;
49959 fs_save = get_fs();
49960 set_fs(get_ds());
49961- rc = vfs_read(lower_file, data, size, &offset);
49962+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
49963 set_fs(fs_save);
49964 return rc;
49965 }
49966diff --git a/fs/exec.c b/fs/exec.c
49967index 20df02c..09b65a1 100644
49968--- a/fs/exec.c
49969+++ b/fs/exec.c
49970@@ -55,6 +55,17 @@
49971 #include <linux/pipe_fs_i.h>
49972 #include <linux/oom.h>
49973 #include <linux/compat.h>
49974+#include <linux/random.h>
49975+#include <linux/seq_file.h>
49976+#include <linux/coredump.h>
49977+#include <linux/mman.h>
49978+
49979+#ifdef CONFIG_PAX_REFCOUNT
49980+#include <linux/kallsyms.h>
49981+#include <linux/kdebug.h>
49982+#endif
49983+
49984+#include <trace/events/fs.h>
49985
49986 #include <asm/uaccess.h>
49987 #include <asm/mmu_context.h>
49988@@ -66,6 +77,18 @@
49989
49990 #include <trace/events/sched.h>
49991
49992+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49993+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
49994+{
49995+ 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");
49996+}
49997+#endif
49998+
49999+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50000+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50001+EXPORT_SYMBOL(pax_set_initial_flags_func);
50002+#endif
50003+
50004 int suid_dumpable = 0;
50005
50006 static LIST_HEAD(formats);
50007@@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50008 {
50009 BUG_ON(!fmt);
50010 write_lock(&binfmt_lock);
50011- insert ? list_add(&fmt->lh, &formats) :
50012- list_add_tail(&fmt->lh, &formats);
50013+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50014+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50015 write_unlock(&binfmt_lock);
50016 }
50017
50018@@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
50019 void unregister_binfmt(struct linux_binfmt * fmt)
50020 {
50021 write_lock(&binfmt_lock);
50022- list_del(&fmt->lh);
50023+ pax_list_del((struct list_head *)&fmt->lh);
50024 write_unlock(&binfmt_lock);
50025 }
50026
50027@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50028 int write)
50029 {
50030 struct page *page;
50031- int ret;
50032
50033-#ifdef CONFIG_STACK_GROWSUP
50034- if (write) {
50035- ret = expand_downwards(bprm->vma, pos);
50036- if (ret < 0)
50037- return NULL;
50038- }
50039-#endif
50040- ret = get_user_pages(current, bprm->mm, pos,
50041- 1, write, 1, &page, NULL);
50042- if (ret <= 0)
50043+ if (0 > expand_downwards(bprm->vma, pos))
50044+ return NULL;
50045+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50046 return NULL;
50047
50048 if (write) {
50049@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50050 if (size <= ARG_MAX)
50051 return page;
50052
50053+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50054+ // only allow 512KB for argv+env on suid/sgid binaries
50055+ // to prevent easy ASLR exhaustion
50056+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50057+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50058+ (size > (512 * 1024))) {
50059+ put_page(page);
50060+ return NULL;
50061+ }
50062+#endif
50063+
50064 /*
50065 * Limit to 1/4-th the stack size for the argv+env strings.
50066 * This ensures that:
50067@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50068 vma->vm_end = STACK_TOP_MAX;
50069 vma->vm_start = vma->vm_end - PAGE_SIZE;
50070 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50071+
50072+#ifdef CONFIG_PAX_SEGMEXEC
50073+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50074+#endif
50075+
50076 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50077 INIT_LIST_HEAD(&vma->anon_vma_chain);
50078
50079@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50080 mm->stack_vm = mm->total_vm = 1;
50081 up_write(&mm->mmap_sem);
50082 bprm->p = vma->vm_end - sizeof(void *);
50083+
50084+#ifdef CONFIG_PAX_RANDUSTACK
50085+ if (randomize_va_space)
50086+ bprm->p ^= random32() & ~PAGE_MASK;
50087+#endif
50088+
50089 return 0;
50090 err:
50091 up_write(&mm->mmap_sem);
50092@@ -396,7 +433,7 @@ struct user_arg_ptr {
50093 } ptr;
50094 };
50095
50096-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50097+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50098 {
50099 const char __user *native;
50100
50101@@ -405,14 +442,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50102 compat_uptr_t compat;
50103
50104 if (get_user(compat, argv.ptr.compat + nr))
50105- return ERR_PTR(-EFAULT);
50106+ return (const char __force_user *)ERR_PTR(-EFAULT);
50107
50108 return compat_ptr(compat);
50109 }
50110 #endif
50111
50112 if (get_user(native, argv.ptr.native + nr))
50113- return ERR_PTR(-EFAULT);
50114+ return (const char __force_user *)ERR_PTR(-EFAULT);
50115
50116 return native;
50117 }
50118@@ -431,7 +468,7 @@ static int count(struct user_arg_ptr argv, int max)
50119 if (!p)
50120 break;
50121
50122- if (IS_ERR(p))
50123+ if (IS_ERR((const char __force_kernel *)p))
50124 return -EFAULT;
50125
50126 if (i >= max)
50127@@ -466,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50128
50129 ret = -EFAULT;
50130 str = get_user_arg_ptr(argv, argc);
50131- if (IS_ERR(str))
50132+ if (IS_ERR((const char __force_kernel *)str))
50133 goto out;
50134
50135 len = strnlen_user(str, MAX_ARG_STRLEN);
50136@@ -548,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50137 int r;
50138 mm_segment_t oldfs = get_fs();
50139 struct user_arg_ptr argv = {
50140- .ptr.native = (const char __user *const __user *)__argv,
50141+ .ptr.native = (const char __force_user *const __force_user *)__argv,
50142 };
50143
50144 set_fs(KERNEL_DS);
50145@@ -583,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50146 unsigned long new_end = old_end - shift;
50147 struct mmu_gather tlb;
50148
50149- BUG_ON(new_start > new_end);
50150+ if (new_start >= new_end || new_start < mmap_min_addr)
50151+ return -ENOMEM;
50152
50153 /*
50154 * ensure there are no vmas between where we want to go
50155@@ -592,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50156 if (vma != find_vma(mm, new_start))
50157 return -EFAULT;
50158
50159+#ifdef CONFIG_PAX_SEGMEXEC
50160+ BUG_ON(pax_find_mirror_vma(vma));
50161+#endif
50162+
50163 /*
50164 * cover the whole range: [new_start, old_end)
50165 */
50166@@ -672,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50167 stack_top = arch_align_stack(stack_top);
50168 stack_top = PAGE_ALIGN(stack_top);
50169
50170- if (unlikely(stack_top < mmap_min_addr) ||
50171- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50172- return -ENOMEM;
50173-
50174 stack_shift = vma->vm_end - stack_top;
50175
50176 bprm->p -= stack_shift;
50177@@ -687,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50178 bprm->exec -= stack_shift;
50179
50180 down_write(&mm->mmap_sem);
50181+
50182+ /* Move stack pages down in memory. */
50183+ if (stack_shift) {
50184+ ret = shift_arg_pages(vma, stack_shift);
50185+ if (ret)
50186+ goto out_unlock;
50187+ }
50188+
50189 vm_flags = VM_STACK_FLAGS;
50190
50191+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50192+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50193+ vm_flags &= ~VM_EXEC;
50194+
50195+#ifdef CONFIG_PAX_MPROTECT
50196+ if (mm->pax_flags & MF_PAX_MPROTECT)
50197+ vm_flags &= ~VM_MAYEXEC;
50198+#endif
50199+
50200+ }
50201+#endif
50202+
50203 /*
50204 * Adjust stack execute permissions; explicitly enable for
50205 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50206@@ -707,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50207 goto out_unlock;
50208 BUG_ON(prev != vma);
50209
50210- /* Move stack pages down in memory. */
50211- if (stack_shift) {
50212- ret = shift_arg_pages(vma, stack_shift);
50213- if (ret)
50214- goto out_unlock;
50215- }
50216-
50217 /* mprotect_fixup is overkill to remove the temporary stack flags */
50218 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50219
50220@@ -737,6 +788,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50221 #endif
50222 current->mm->start_stack = bprm->p;
50223 ret = expand_stack(vma, stack_base);
50224+
50225+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50226+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50227+ unsigned long size, flags, vm_flags;
50228+
50229+ size = STACK_TOP - vma->vm_end;
50230+ flags = MAP_FIXED | MAP_PRIVATE;
50231+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50232+
50233+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
50234+
50235+#ifdef CONFIG_X86
50236+ if (!ret) {
50237+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50238+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), flags, vm_flags, 0);
50239+ }
50240+#endif
50241+
50242+ }
50243+#endif
50244+
50245 if (ret)
50246 ret = -EFAULT;
50247
50248@@ -772,6 +844,8 @@ struct file *open_exec(const char *name)
50249
50250 fsnotify_open(file);
50251
50252+ trace_open_exec(name);
50253+
50254 err = deny_write_access(file);
50255 if (err)
50256 goto exit;
50257@@ -795,7 +869,7 @@ int kernel_read(struct file *file, loff_t offset,
50258 old_fs = get_fs();
50259 set_fs(get_ds());
50260 /* The cast to a user pointer is valid due to the set_fs() */
50261- result = vfs_read(file, (void __user *)addr, count, &pos);
50262+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50263 set_fs(old_fs);
50264 return result;
50265 }
50266@@ -1247,7 +1321,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50267 }
50268 rcu_read_unlock();
50269
50270- if (p->fs->users > n_fs) {
50271+ if (atomic_read(&p->fs->users) > n_fs) {
50272 bprm->unsafe |= LSM_UNSAFE_SHARE;
50273 } else {
50274 res = -EAGAIN;
50275@@ -1447,6 +1521,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50276
50277 EXPORT_SYMBOL(search_binary_handler);
50278
50279+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50280+static DEFINE_PER_CPU(u64, exec_counter);
50281+static int __init init_exec_counters(void)
50282+{
50283+ unsigned int cpu;
50284+
50285+ for_each_possible_cpu(cpu) {
50286+ per_cpu(exec_counter, cpu) = (u64)cpu;
50287+ }
50288+
50289+ return 0;
50290+}
50291+early_initcall(init_exec_counters);
50292+static inline void increment_exec_counter(void)
50293+{
50294+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50295+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50296+}
50297+#else
50298+static inline void increment_exec_counter(void) {}
50299+#endif
50300+
50301+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50302+ struct user_arg_ptr argv);
50303+
50304 /*
50305 * sys_execve() executes a new program.
50306 */
50307@@ -1454,6 +1553,11 @@ static int do_execve_common(const char *filename,
50308 struct user_arg_ptr argv,
50309 struct user_arg_ptr envp)
50310 {
50311+#ifdef CONFIG_GRKERNSEC
50312+ struct file *old_exec_file;
50313+ struct acl_subject_label *old_acl;
50314+ struct rlimit old_rlim[RLIM_NLIMITS];
50315+#endif
50316 struct linux_binprm *bprm;
50317 struct file *file;
50318 struct files_struct *displaced;
50319@@ -1461,6 +1565,8 @@ static int do_execve_common(const char *filename,
50320 int retval;
50321 const struct cred *cred = current_cred();
50322
50323+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
50324+
50325 /*
50326 * We move the actual failure in case of RLIMIT_NPROC excess from
50327 * set*uid() to execve() because too many poorly written programs
50328@@ -1501,12 +1607,27 @@ static int do_execve_common(const char *filename,
50329 if (IS_ERR(file))
50330 goto out_unmark;
50331
50332+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50333+ retval = -EPERM;
50334+ goto out_file;
50335+ }
50336+
50337 sched_exec();
50338
50339 bprm->file = file;
50340 bprm->filename = filename;
50341 bprm->interp = filename;
50342
50343+ if (gr_process_user_ban()) {
50344+ retval = -EPERM;
50345+ goto out_file;
50346+ }
50347+
50348+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
50349+ retval = -EACCES;
50350+ goto out_file;
50351+ }
50352+
50353 retval = bprm_mm_init(bprm);
50354 if (retval)
50355 goto out_file;
50356@@ -1523,24 +1644,65 @@ static int do_execve_common(const char *filename,
50357 if (retval < 0)
50358 goto out;
50359
50360+#ifdef CONFIG_GRKERNSEC
50361+ old_acl = current->acl;
50362+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
50363+ old_exec_file = current->exec_file;
50364+ get_file(file);
50365+ current->exec_file = file;
50366+#endif
50367+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50368+ /* limit suid stack to 8MB
50369+ * we saved the old limits above and will restore them if this exec fails
50370+ */
50371+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
50372+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
50373+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
50374+#endif
50375+
50376+ if (!gr_tpe_allow(file)) {
50377+ retval = -EACCES;
50378+ goto out_fail;
50379+ }
50380+
50381+ if (gr_check_crash_exec(file)) {
50382+ retval = -EACCES;
50383+ goto out_fail;
50384+ }
50385+
50386+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
50387+ bprm->unsafe);
50388+ if (retval < 0)
50389+ goto out_fail;
50390+
50391 retval = copy_strings_kernel(1, &bprm->filename, bprm);
50392 if (retval < 0)
50393- goto out;
50394+ goto out_fail;
50395
50396 bprm->exec = bprm->p;
50397 retval = copy_strings(bprm->envc, envp, bprm);
50398 if (retval < 0)
50399- goto out;
50400+ goto out_fail;
50401
50402 retval = copy_strings(bprm->argc, argv, bprm);
50403 if (retval < 0)
50404- goto out;
50405+ goto out_fail;
50406+
50407+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
50408+
50409+ gr_handle_exec_args(bprm, argv);
50410
50411 retval = search_binary_handler(bprm);
50412 if (retval < 0)
50413- goto out;
50414+ goto out_fail;
50415+#ifdef CONFIG_GRKERNSEC
50416+ if (old_exec_file)
50417+ fput(old_exec_file);
50418+#endif
50419
50420 /* execve succeeded */
50421+
50422+ increment_exec_counter();
50423 current->fs->in_exec = 0;
50424 current->in_execve = 0;
50425 acct_update_integrals(current);
50426@@ -1549,6 +1711,14 @@ static int do_execve_common(const char *filename,
50427 put_files_struct(displaced);
50428 return retval;
50429
50430+out_fail:
50431+#ifdef CONFIG_GRKERNSEC
50432+ current->acl = old_acl;
50433+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50434+ fput(current->exec_file);
50435+ current->exec_file = old_exec_file;
50436+#endif
50437+
50438 out:
50439 if (bprm->mm) {
50440 acct_arg_size(bprm, 0);
50441@@ -1697,3 +1867,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50442 return error;
50443 }
50444 #endif
50445+
50446+int pax_check_flags(unsigned long *flags)
50447+{
50448+ int retval = 0;
50449+
50450+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50451+ if (*flags & MF_PAX_SEGMEXEC)
50452+ {
50453+ *flags &= ~MF_PAX_SEGMEXEC;
50454+ retval = -EINVAL;
50455+ }
50456+#endif
50457+
50458+ if ((*flags & MF_PAX_PAGEEXEC)
50459+
50460+#ifdef CONFIG_PAX_PAGEEXEC
50461+ && (*flags & MF_PAX_SEGMEXEC)
50462+#endif
50463+
50464+ )
50465+ {
50466+ *flags &= ~MF_PAX_PAGEEXEC;
50467+ retval = -EINVAL;
50468+ }
50469+
50470+ if ((*flags & MF_PAX_MPROTECT)
50471+
50472+#ifdef CONFIG_PAX_MPROTECT
50473+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50474+#endif
50475+
50476+ )
50477+ {
50478+ *flags &= ~MF_PAX_MPROTECT;
50479+ retval = -EINVAL;
50480+ }
50481+
50482+ if ((*flags & MF_PAX_EMUTRAMP)
50483+
50484+#ifdef CONFIG_PAX_EMUTRAMP
50485+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50486+#endif
50487+
50488+ )
50489+ {
50490+ *flags &= ~MF_PAX_EMUTRAMP;
50491+ retval = -EINVAL;
50492+ }
50493+
50494+ return retval;
50495+}
50496+
50497+EXPORT_SYMBOL(pax_check_flags);
50498+
50499+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50500+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50501+{
50502+ struct task_struct *tsk = current;
50503+ struct mm_struct *mm = current->mm;
50504+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50505+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50506+ char *path_exec = NULL;
50507+ char *path_fault = NULL;
50508+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
50509+ siginfo_t info = { };
50510+
50511+ if (buffer_exec && buffer_fault) {
50512+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50513+
50514+ down_read(&mm->mmap_sem);
50515+ vma = mm->mmap;
50516+ while (vma && (!vma_exec || !vma_fault)) {
50517+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50518+ vma_exec = vma;
50519+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50520+ vma_fault = vma;
50521+ vma = vma->vm_next;
50522+ }
50523+ if (vma_exec) {
50524+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50525+ if (IS_ERR(path_exec))
50526+ path_exec = "<path too long>";
50527+ else {
50528+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50529+ if (path_exec) {
50530+ *path_exec = 0;
50531+ path_exec = buffer_exec;
50532+ } else
50533+ path_exec = "<path too long>";
50534+ }
50535+ }
50536+ if (vma_fault) {
50537+ start = vma_fault->vm_start;
50538+ end = vma_fault->vm_end;
50539+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50540+ if (vma_fault->vm_file) {
50541+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50542+ if (IS_ERR(path_fault))
50543+ path_fault = "<path too long>";
50544+ else {
50545+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50546+ if (path_fault) {
50547+ *path_fault = 0;
50548+ path_fault = buffer_fault;
50549+ } else
50550+ path_fault = "<path too long>";
50551+ }
50552+ } else
50553+ path_fault = "<anonymous mapping>";
50554+ }
50555+ up_read(&mm->mmap_sem);
50556+ }
50557+ if (tsk->signal->curr_ip)
50558+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50559+ else
50560+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50561+ 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),
50562+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
50563+ free_page((unsigned long)buffer_exec);
50564+ free_page((unsigned long)buffer_fault);
50565+ pax_report_insns(regs, pc, sp);
50566+ info.si_signo = SIGKILL;
50567+ info.si_errno = 0;
50568+ info.si_code = SI_KERNEL;
50569+ info.si_pid = 0;
50570+ info.si_uid = 0;
50571+ do_coredump(&info);
50572+}
50573+#endif
50574+
50575+#ifdef CONFIG_PAX_REFCOUNT
50576+void pax_report_refcount_overflow(struct pt_regs *regs)
50577+{
50578+ if (current->signal->curr_ip)
50579+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50580+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
50581+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50582+ else
50583+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50584+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50585+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50586+ show_regs(regs);
50587+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50588+}
50589+#endif
50590+
50591+#ifdef CONFIG_PAX_USERCOPY
50592+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50593+static noinline int check_stack_object(const void *obj, unsigned long len)
50594+{
50595+ const void * const stack = task_stack_page(current);
50596+ const void * const stackend = stack + THREAD_SIZE;
50597+
50598+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50599+ const void *frame = NULL;
50600+ const void *oldframe;
50601+#endif
50602+
50603+ if (obj + len < obj)
50604+ return -1;
50605+
50606+ if (obj + len <= stack || stackend <= obj)
50607+ return 0;
50608+
50609+ if (obj < stack || stackend < obj + len)
50610+ return -1;
50611+
50612+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50613+ oldframe = __builtin_frame_address(1);
50614+ if (oldframe)
50615+ frame = __builtin_frame_address(2);
50616+ /*
50617+ low ----------------------------------------------> high
50618+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
50619+ ^----------------^
50620+ allow copies only within here
50621+ */
50622+ while (stack <= frame && frame < stackend) {
50623+ /* if obj + len extends past the last frame, this
50624+ check won't pass and the next frame will be 0,
50625+ causing us to bail out and correctly report
50626+ the copy as invalid
50627+ */
50628+ if (obj + len <= frame)
50629+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50630+ oldframe = frame;
50631+ frame = *(const void * const *)frame;
50632+ }
50633+ return -1;
50634+#else
50635+ return 1;
50636+#endif
50637+}
50638+
50639+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50640+{
50641+ if (current->signal->curr_ip)
50642+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50643+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50644+ else
50645+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50646+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50647+ dump_stack();
50648+ gr_handle_kernel_exploit();
50649+ do_group_exit(SIGKILL);
50650+}
50651+#endif
50652+
50653+void __check_object_size(const void *ptr, unsigned long n, bool to)
50654+{
50655+
50656+#ifdef CONFIG_PAX_USERCOPY
50657+ const char *type;
50658+
50659+ if (!n)
50660+ return;
50661+
50662+ type = check_heap_object(ptr, n);
50663+ if (!type) {
50664+ if (check_stack_object(ptr, n) != -1)
50665+ return;
50666+ type = "<process stack>";
50667+ }
50668+
50669+ pax_report_usercopy(ptr, n, to, type);
50670+#endif
50671+
50672+}
50673+EXPORT_SYMBOL(__check_object_size);
50674+
50675+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50676+void pax_track_stack(void)
50677+{
50678+ unsigned long sp = (unsigned long)&sp;
50679+ if (sp < current_thread_info()->lowest_stack &&
50680+ sp > (unsigned long)task_stack_page(current))
50681+ current_thread_info()->lowest_stack = sp;
50682+}
50683+EXPORT_SYMBOL(pax_track_stack);
50684+#endif
50685+
50686+#ifdef CONFIG_PAX_SIZE_OVERFLOW
50687+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50688+{
50689+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50690+ dump_stack();
50691+ do_group_exit(SIGKILL);
50692+}
50693+EXPORT_SYMBOL(report_size_overflow);
50694+#endif
50695diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50696index 2616d0e..2ffdec9 100644
50697--- a/fs/ext2/balloc.c
50698+++ b/fs/ext2/balloc.c
50699@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50700
50701 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50702 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50703- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50704+ if (free_blocks < root_blocks + 1 &&
50705 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50706 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50707- !in_group_p (sbi->s_resgid))) {
50708+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50709 return 0;
50710 }
50711 return 1;
50712diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50713index 22548f5..41521d8 100644
50714--- a/fs/ext3/balloc.c
50715+++ b/fs/ext3/balloc.c
50716@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50717
50718 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50719 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50720- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50721+ if (free_blocks < root_blocks + 1 &&
50722 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50723 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50724- !in_group_p (sbi->s_resgid))) {
50725+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50726 return 0;
50727 }
50728 return 1;
50729diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50730index 92e68b3..115d987 100644
50731--- a/fs/ext4/balloc.c
50732+++ b/fs/ext4/balloc.c
50733@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50734 /* Hm, nope. Are (enough) root reserved clusters available? */
50735 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50736 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50737- capable(CAP_SYS_RESOURCE) ||
50738- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50739+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50740+ capable_nolog(CAP_SYS_RESOURCE)) {
50741
50742 if (free_clusters >= (nclusters + dirty_clusters))
50743 return 1;
50744diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50745index 8462eb3..4a71af6 100644
50746--- a/fs/ext4/ext4.h
50747+++ b/fs/ext4/ext4.h
50748@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50749 unsigned long s_mb_last_start;
50750
50751 /* stats for buddy allocator */
50752- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50753- atomic_t s_bal_success; /* we found long enough chunks */
50754- atomic_t s_bal_allocated; /* in blocks */
50755- atomic_t s_bal_ex_scanned; /* total extents scanned */
50756- atomic_t s_bal_goals; /* goal hits */
50757- atomic_t s_bal_breaks; /* too long searches */
50758- atomic_t s_bal_2orders; /* 2^order hits */
50759+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50760+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50761+ atomic_unchecked_t s_bal_allocated; /* in blocks */
50762+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50763+ atomic_unchecked_t s_bal_goals; /* goal hits */
50764+ atomic_unchecked_t s_bal_breaks; /* too long searches */
50765+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50766 spinlock_t s_bal_lock;
50767 unsigned long s_mb_buddies_generated;
50768 unsigned long long s_mb_generation_time;
50769- atomic_t s_mb_lost_chunks;
50770- atomic_t s_mb_preallocated;
50771- atomic_t s_mb_discarded;
50772+ atomic_unchecked_t s_mb_lost_chunks;
50773+ atomic_unchecked_t s_mb_preallocated;
50774+ atomic_unchecked_t s_mb_discarded;
50775 atomic_t s_lock_busy;
50776
50777 /* locality groups */
50778diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50779index 28bbf9b..75ca7c1 100644
50780--- a/fs/ext4/mballoc.c
50781+++ b/fs/ext4/mballoc.c
50782@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50783 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50784
50785 if (EXT4_SB(sb)->s_mb_stats)
50786- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50787+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50788
50789 break;
50790 }
50791@@ -2044,7 +2044,7 @@ repeat:
50792 ac->ac_status = AC_STATUS_CONTINUE;
50793 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50794 cr = 3;
50795- atomic_inc(&sbi->s_mb_lost_chunks);
50796+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50797 goto repeat;
50798 }
50799 }
50800@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50801 if (sbi->s_mb_stats) {
50802 ext4_msg(sb, KERN_INFO,
50803 "mballoc: %u blocks %u reqs (%u success)",
50804- atomic_read(&sbi->s_bal_allocated),
50805- atomic_read(&sbi->s_bal_reqs),
50806- atomic_read(&sbi->s_bal_success));
50807+ atomic_read_unchecked(&sbi->s_bal_allocated),
50808+ atomic_read_unchecked(&sbi->s_bal_reqs),
50809+ atomic_read_unchecked(&sbi->s_bal_success));
50810 ext4_msg(sb, KERN_INFO,
50811 "mballoc: %u extents scanned, %u goal hits, "
50812 "%u 2^N hits, %u breaks, %u lost",
50813- atomic_read(&sbi->s_bal_ex_scanned),
50814- atomic_read(&sbi->s_bal_goals),
50815- atomic_read(&sbi->s_bal_2orders),
50816- atomic_read(&sbi->s_bal_breaks),
50817- atomic_read(&sbi->s_mb_lost_chunks));
50818+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50819+ atomic_read_unchecked(&sbi->s_bal_goals),
50820+ atomic_read_unchecked(&sbi->s_bal_2orders),
50821+ atomic_read_unchecked(&sbi->s_bal_breaks),
50822+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50823 ext4_msg(sb, KERN_INFO,
50824 "mballoc: %lu generated and it took %Lu",
50825 sbi->s_mb_buddies_generated,
50826 sbi->s_mb_generation_time);
50827 ext4_msg(sb, KERN_INFO,
50828 "mballoc: %u preallocated, %u discarded",
50829- atomic_read(&sbi->s_mb_preallocated),
50830- atomic_read(&sbi->s_mb_discarded));
50831+ atomic_read_unchecked(&sbi->s_mb_preallocated),
50832+ atomic_read_unchecked(&sbi->s_mb_discarded));
50833 }
50834
50835 free_percpu(sbi->s_locality_groups);
50836@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50837 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50838
50839 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50840- atomic_inc(&sbi->s_bal_reqs);
50841- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50842+ atomic_inc_unchecked(&sbi->s_bal_reqs);
50843+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50844 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50845- atomic_inc(&sbi->s_bal_success);
50846- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50847+ atomic_inc_unchecked(&sbi->s_bal_success);
50848+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50849 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50850 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50851- atomic_inc(&sbi->s_bal_goals);
50852+ atomic_inc_unchecked(&sbi->s_bal_goals);
50853 if (ac->ac_found > sbi->s_mb_max_to_scan)
50854- atomic_inc(&sbi->s_bal_breaks);
50855+ atomic_inc_unchecked(&sbi->s_bal_breaks);
50856 }
50857
50858 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50859@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50860 trace_ext4_mb_new_inode_pa(ac, pa);
50861
50862 ext4_mb_use_inode_pa(ac, pa);
50863- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50864+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50865
50866 ei = EXT4_I(ac->ac_inode);
50867 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50868@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50869 trace_ext4_mb_new_group_pa(ac, pa);
50870
50871 ext4_mb_use_group_pa(ac, pa);
50872- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50873+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50874
50875 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50876 lg = ac->ac_lg;
50877@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50878 * from the bitmap and continue.
50879 */
50880 }
50881- atomic_add(free, &sbi->s_mb_discarded);
50882+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
50883
50884 return err;
50885 }
50886@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50887 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50888 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50889 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50890- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50891+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50892 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50893
50894 return 0;
50895diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50896index 5fa223d..12fa738 100644
50897--- a/fs/ext4/super.c
50898+++ b/fs/ext4/super.c
50899@@ -2429,7 +2429,7 @@ struct ext4_attr {
50900 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50901 const char *, size_t);
50902 int offset;
50903-};
50904+} __do_const;
50905
50906 static int parse_strtoul(const char *buf,
50907 unsigned long max, unsigned long *value)
50908diff --git a/fs/fcntl.c b/fs/fcntl.c
50909index 71a600a..20d87b1 100644
50910--- a/fs/fcntl.c
50911+++ b/fs/fcntl.c
50912@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50913 if (err)
50914 return err;
50915
50916+ if (gr_handle_chroot_fowner(pid, type))
50917+ return -ENOENT;
50918+ if (gr_check_protected_task_fowner(pid, type))
50919+ return -EACCES;
50920+
50921 f_modown(filp, pid, type, force);
50922 return 0;
50923 }
50924diff --git a/fs/fhandle.c b/fs/fhandle.c
50925index 999ff5c..41f4109 100644
50926--- a/fs/fhandle.c
50927+++ b/fs/fhandle.c
50928@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50929 } else
50930 retval = 0;
50931 /* copy the mount id */
50932- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50933- sizeof(*mnt_id)) ||
50934+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50935 copy_to_user(ufh, handle,
50936 sizeof(struct file_handle) + handle_bytes))
50937 retval = -EFAULT;
50938diff --git a/fs/fifo.c b/fs/fifo.c
50939index cf6f434..3d7942c 100644
50940--- a/fs/fifo.c
50941+++ b/fs/fifo.c
50942@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50943 */
50944 filp->f_op = &read_pipefifo_fops;
50945 pipe->r_counter++;
50946- if (pipe->readers++ == 0)
50947+ if (atomic_inc_return(&pipe->readers) == 1)
50948 wake_up_partner(inode);
50949
50950- if (!pipe->writers) {
50951+ if (!atomic_read(&pipe->writers)) {
50952 if ((filp->f_flags & O_NONBLOCK)) {
50953 /* suppress POLLHUP until we have
50954 * seen a writer */
50955@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50956 * errno=ENXIO when there is no process reading the FIFO.
50957 */
50958 ret = -ENXIO;
50959- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50960+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
50961 goto err;
50962
50963 filp->f_op = &write_pipefifo_fops;
50964 pipe->w_counter++;
50965- if (!pipe->writers++)
50966+ if (atomic_inc_return(&pipe->writers) == 1)
50967 wake_up_partner(inode);
50968
50969- if (!pipe->readers) {
50970+ if (!atomic_read(&pipe->readers)) {
50971 if (wait_for_partner(inode, &pipe->r_counter))
50972 goto err_wr;
50973 }
50974@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
50975 */
50976 filp->f_op = &rdwr_pipefifo_fops;
50977
50978- pipe->readers++;
50979- pipe->writers++;
50980+ atomic_inc(&pipe->readers);
50981+ atomic_inc(&pipe->writers);
50982 pipe->r_counter++;
50983 pipe->w_counter++;
50984- if (pipe->readers == 1 || pipe->writers == 1)
50985+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
50986 wake_up_partner(inode);
50987 break;
50988
50989@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
50990 return 0;
50991
50992 err_rd:
50993- if (!--pipe->readers)
50994+ if (atomic_dec_and_test(&pipe->readers))
50995 wake_up_interruptible(&pipe->wait);
50996 ret = -ERESTARTSYS;
50997 goto err;
50998
50999 err_wr:
51000- if (!--pipe->writers)
51001+ if (atomic_dec_and_test(&pipe->writers))
51002 wake_up_interruptible(&pipe->wait);
51003 ret = -ERESTARTSYS;
51004 goto err;
51005
51006 err:
51007- if (!pipe->readers && !pipe->writers)
51008+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51009 free_pipe_info(inode);
51010
51011 err_nocleanup:
51012diff --git a/fs/file.c b/fs/file.c
51013index 2b3570b..c57924b 100644
51014--- a/fs/file.c
51015+++ b/fs/file.c
51016@@ -16,6 +16,7 @@
51017 #include <linux/slab.h>
51018 #include <linux/vmalloc.h>
51019 #include <linux/file.h>
51020+#include <linux/security.h>
51021 #include <linux/fdtable.h>
51022 #include <linux/bitops.h>
51023 #include <linux/interrupt.h>
51024@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51025 if (!file)
51026 return __close_fd(files, fd);
51027
51028+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51029 if (fd >= rlimit(RLIMIT_NOFILE))
51030 return -EBADF;
51031
51032@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51033 if (unlikely(oldfd == newfd))
51034 return -EINVAL;
51035
51036+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51037 if (newfd >= rlimit(RLIMIT_NOFILE))
51038 return -EBADF;
51039
51040@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51041 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51042 {
51043 int err;
51044+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51045 if (from >= rlimit(RLIMIT_NOFILE))
51046 return -EINVAL;
51047 err = alloc_fd(from, flags);
51048diff --git a/fs/filesystems.c b/fs/filesystems.c
51049index da165f6..3671bdb 100644
51050--- a/fs/filesystems.c
51051+++ b/fs/filesystems.c
51052@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
51053 int len = dot ? dot - name : strlen(name);
51054
51055 fs = __get_fs_type(name, len);
51056+
51057+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51058+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
51059+#else
51060 if (!fs && (request_module("%.*s", len, name) == 0))
51061+#endif
51062 fs = __get_fs_type(name, len);
51063
51064 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51065diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51066index fe6ca58..65318cf 100644
51067--- a/fs/fs_struct.c
51068+++ b/fs/fs_struct.c
51069@@ -4,6 +4,7 @@
51070 #include <linux/path.h>
51071 #include <linux/slab.h>
51072 #include <linux/fs_struct.h>
51073+#include <linux/grsecurity.h>
51074 #include "internal.h"
51075
51076 /*
51077@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51078 write_seqcount_begin(&fs->seq);
51079 old_root = fs->root;
51080 fs->root = *path;
51081+ gr_set_chroot_entries(current, path);
51082 write_seqcount_end(&fs->seq);
51083 spin_unlock(&fs->lock);
51084 if (old_root.dentry)
51085@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51086 return 1;
51087 }
51088
51089+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51090+{
51091+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51092+ return 0;
51093+ *p = *new;
51094+
51095+ /* This function is only called from pivot_root(). Leave our
51096+ gr_chroot_dentry and is_chrooted flags as-is, so that a
51097+ pivoted root isn't treated as a chroot
51098+ */
51099+ //gr_set_chroot_entries(task, new);
51100+
51101+ return 1;
51102+}
51103+
51104 void chroot_fs_refs(struct path *old_root, struct path *new_root)
51105 {
51106 struct task_struct *g, *p;
51107@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
51108 int hits = 0;
51109 spin_lock(&fs->lock);
51110 write_seqcount_begin(&fs->seq);
51111- hits += replace_path(&fs->root, old_root, new_root);
51112+ hits += replace_root_path(p, &fs->root, old_root, new_root);
51113 hits += replace_path(&fs->pwd, old_root, new_root);
51114 write_seqcount_end(&fs->seq);
51115 while (hits--) {
51116@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
51117 task_lock(tsk);
51118 spin_lock(&fs->lock);
51119 tsk->fs = NULL;
51120- kill = !--fs->users;
51121+ gr_clear_chroot_entries(tsk);
51122+ kill = !atomic_dec_return(&fs->users);
51123 spin_unlock(&fs->lock);
51124 task_unlock(tsk);
51125 if (kill)
51126@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51127 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51128 /* We don't need to lock fs - think why ;-) */
51129 if (fs) {
51130- fs->users = 1;
51131+ atomic_set(&fs->users, 1);
51132 fs->in_exec = 0;
51133 spin_lock_init(&fs->lock);
51134 seqcount_init(&fs->seq);
51135@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51136 spin_lock(&old->lock);
51137 fs->root = old->root;
51138 path_get(&fs->root);
51139+ /* instead of calling gr_set_chroot_entries here,
51140+ we call it from every caller of this function
51141+ */
51142 fs->pwd = old->pwd;
51143 path_get(&fs->pwd);
51144 spin_unlock(&old->lock);
51145@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
51146
51147 task_lock(current);
51148 spin_lock(&fs->lock);
51149- kill = !--fs->users;
51150+ kill = !atomic_dec_return(&fs->users);
51151 current->fs = new_fs;
51152+ gr_set_chroot_entries(current, &new_fs->root);
51153 spin_unlock(&fs->lock);
51154 task_unlock(current);
51155
51156@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51157
51158 int current_umask(void)
51159 {
51160- return current->fs->umask;
51161+ return current->fs->umask | gr_acl_umask();
51162 }
51163 EXPORT_SYMBOL(current_umask);
51164
51165 /* to be mentioned only in INIT_TASK */
51166 struct fs_struct init_fs = {
51167- .users = 1,
51168+ .users = ATOMIC_INIT(1),
51169 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51170 .seq = SEQCNT_ZERO,
51171 .umask = 0022,
51172diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51173index 8dcb114..b1072e2 100644
51174--- a/fs/fscache/cookie.c
51175+++ b/fs/fscache/cookie.c
51176@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51177 parent ? (char *) parent->def->name : "<no-parent>",
51178 def->name, netfs_data);
51179
51180- fscache_stat(&fscache_n_acquires);
51181+ fscache_stat_unchecked(&fscache_n_acquires);
51182
51183 /* if there's no parent cookie, then we don't create one here either */
51184 if (!parent) {
51185- fscache_stat(&fscache_n_acquires_null);
51186+ fscache_stat_unchecked(&fscache_n_acquires_null);
51187 _leave(" [no parent]");
51188 return NULL;
51189 }
51190@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51191 /* allocate and initialise a cookie */
51192 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51193 if (!cookie) {
51194- fscache_stat(&fscache_n_acquires_oom);
51195+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51196 _leave(" [ENOMEM]");
51197 return NULL;
51198 }
51199@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51200
51201 switch (cookie->def->type) {
51202 case FSCACHE_COOKIE_TYPE_INDEX:
51203- fscache_stat(&fscache_n_cookie_index);
51204+ fscache_stat_unchecked(&fscache_n_cookie_index);
51205 break;
51206 case FSCACHE_COOKIE_TYPE_DATAFILE:
51207- fscache_stat(&fscache_n_cookie_data);
51208+ fscache_stat_unchecked(&fscache_n_cookie_data);
51209 break;
51210 default:
51211- fscache_stat(&fscache_n_cookie_special);
51212+ fscache_stat_unchecked(&fscache_n_cookie_special);
51213 break;
51214 }
51215
51216@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51217 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51218 atomic_dec(&parent->n_children);
51219 __fscache_cookie_put(cookie);
51220- fscache_stat(&fscache_n_acquires_nobufs);
51221+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51222 _leave(" = NULL");
51223 return NULL;
51224 }
51225 }
51226
51227- fscache_stat(&fscache_n_acquires_ok);
51228+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51229 _leave(" = %p", cookie);
51230 return cookie;
51231 }
51232@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51233 cache = fscache_select_cache_for_object(cookie->parent);
51234 if (!cache) {
51235 up_read(&fscache_addremove_sem);
51236- fscache_stat(&fscache_n_acquires_no_cache);
51237+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51238 _leave(" = -ENOMEDIUM [no cache]");
51239 return -ENOMEDIUM;
51240 }
51241@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51242 object = cache->ops->alloc_object(cache, cookie);
51243 fscache_stat_d(&fscache_n_cop_alloc_object);
51244 if (IS_ERR(object)) {
51245- fscache_stat(&fscache_n_object_no_alloc);
51246+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51247 ret = PTR_ERR(object);
51248 goto error;
51249 }
51250
51251- fscache_stat(&fscache_n_object_alloc);
51252+ fscache_stat_unchecked(&fscache_n_object_alloc);
51253
51254 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51255
51256@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51257
51258 _enter("{%s}", cookie->def->name);
51259
51260- fscache_stat(&fscache_n_invalidates);
51261+ fscache_stat_unchecked(&fscache_n_invalidates);
51262
51263 /* Only permit invalidation of data files. Invalidating an index will
51264 * require the caller to release all its attachments to the tree rooted
51265@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51266 struct fscache_object *object;
51267 struct hlist_node *_p;
51268
51269- fscache_stat(&fscache_n_updates);
51270+ fscache_stat_unchecked(&fscache_n_updates);
51271
51272 if (!cookie) {
51273- fscache_stat(&fscache_n_updates_null);
51274+ fscache_stat_unchecked(&fscache_n_updates_null);
51275 _leave(" [no cookie]");
51276 return;
51277 }
51278@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51279 struct fscache_object *object;
51280 unsigned long event;
51281
51282- fscache_stat(&fscache_n_relinquishes);
51283+ fscache_stat_unchecked(&fscache_n_relinquishes);
51284 if (retire)
51285- fscache_stat(&fscache_n_relinquishes_retire);
51286+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51287
51288 if (!cookie) {
51289- fscache_stat(&fscache_n_relinquishes_null);
51290+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51291 _leave(" [no cookie]");
51292 return;
51293 }
51294@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51295
51296 /* wait for the cookie to finish being instantiated (or to fail) */
51297 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51298- fscache_stat(&fscache_n_relinquishes_waitcrt);
51299+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51300 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
51301 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
51302 }
51303diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
51304index ee38fef..0a326d4 100644
51305--- a/fs/fscache/internal.h
51306+++ b/fs/fscache/internal.h
51307@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
51308 * stats.c
51309 */
51310 #ifdef CONFIG_FSCACHE_STATS
51311-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51312-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51313+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51314+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51315
51316-extern atomic_t fscache_n_op_pend;
51317-extern atomic_t fscache_n_op_run;
51318-extern atomic_t fscache_n_op_enqueue;
51319-extern atomic_t fscache_n_op_deferred_release;
51320-extern atomic_t fscache_n_op_release;
51321-extern atomic_t fscache_n_op_gc;
51322-extern atomic_t fscache_n_op_cancelled;
51323-extern atomic_t fscache_n_op_rejected;
51324+extern atomic_unchecked_t fscache_n_op_pend;
51325+extern atomic_unchecked_t fscache_n_op_run;
51326+extern atomic_unchecked_t fscache_n_op_enqueue;
51327+extern atomic_unchecked_t fscache_n_op_deferred_release;
51328+extern atomic_unchecked_t fscache_n_op_release;
51329+extern atomic_unchecked_t fscache_n_op_gc;
51330+extern atomic_unchecked_t fscache_n_op_cancelled;
51331+extern atomic_unchecked_t fscache_n_op_rejected;
51332
51333-extern atomic_t fscache_n_attr_changed;
51334-extern atomic_t fscache_n_attr_changed_ok;
51335-extern atomic_t fscache_n_attr_changed_nobufs;
51336-extern atomic_t fscache_n_attr_changed_nomem;
51337-extern atomic_t fscache_n_attr_changed_calls;
51338+extern atomic_unchecked_t fscache_n_attr_changed;
51339+extern atomic_unchecked_t fscache_n_attr_changed_ok;
51340+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
51341+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
51342+extern atomic_unchecked_t fscache_n_attr_changed_calls;
51343
51344-extern atomic_t fscache_n_allocs;
51345-extern atomic_t fscache_n_allocs_ok;
51346-extern atomic_t fscache_n_allocs_wait;
51347-extern atomic_t fscache_n_allocs_nobufs;
51348-extern atomic_t fscache_n_allocs_intr;
51349-extern atomic_t fscache_n_allocs_object_dead;
51350-extern atomic_t fscache_n_alloc_ops;
51351-extern atomic_t fscache_n_alloc_op_waits;
51352+extern atomic_unchecked_t fscache_n_allocs;
51353+extern atomic_unchecked_t fscache_n_allocs_ok;
51354+extern atomic_unchecked_t fscache_n_allocs_wait;
51355+extern atomic_unchecked_t fscache_n_allocs_nobufs;
51356+extern atomic_unchecked_t fscache_n_allocs_intr;
51357+extern atomic_unchecked_t fscache_n_allocs_object_dead;
51358+extern atomic_unchecked_t fscache_n_alloc_ops;
51359+extern atomic_unchecked_t fscache_n_alloc_op_waits;
51360
51361-extern atomic_t fscache_n_retrievals;
51362-extern atomic_t fscache_n_retrievals_ok;
51363-extern atomic_t fscache_n_retrievals_wait;
51364-extern atomic_t fscache_n_retrievals_nodata;
51365-extern atomic_t fscache_n_retrievals_nobufs;
51366-extern atomic_t fscache_n_retrievals_intr;
51367-extern atomic_t fscache_n_retrievals_nomem;
51368-extern atomic_t fscache_n_retrievals_object_dead;
51369-extern atomic_t fscache_n_retrieval_ops;
51370-extern atomic_t fscache_n_retrieval_op_waits;
51371+extern atomic_unchecked_t fscache_n_retrievals;
51372+extern atomic_unchecked_t fscache_n_retrievals_ok;
51373+extern atomic_unchecked_t fscache_n_retrievals_wait;
51374+extern atomic_unchecked_t fscache_n_retrievals_nodata;
51375+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
51376+extern atomic_unchecked_t fscache_n_retrievals_intr;
51377+extern atomic_unchecked_t fscache_n_retrievals_nomem;
51378+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
51379+extern atomic_unchecked_t fscache_n_retrieval_ops;
51380+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
51381
51382-extern atomic_t fscache_n_stores;
51383-extern atomic_t fscache_n_stores_ok;
51384-extern atomic_t fscache_n_stores_again;
51385-extern atomic_t fscache_n_stores_nobufs;
51386-extern atomic_t fscache_n_stores_oom;
51387-extern atomic_t fscache_n_store_ops;
51388-extern atomic_t fscache_n_store_calls;
51389-extern atomic_t fscache_n_store_pages;
51390-extern atomic_t fscache_n_store_radix_deletes;
51391-extern atomic_t fscache_n_store_pages_over_limit;
51392+extern atomic_unchecked_t fscache_n_stores;
51393+extern atomic_unchecked_t fscache_n_stores_ok;
51394+extern atomic_unchecked_t fscache_n_stores_again;
51395+extern atomic_unchecked_t fscache_n_stores_nobufs;
51396+extern atomic_unchecked_t fscache_n_stores_oom;
51397+extern atomic_unchecked_t fscache_n_store_ops;
51398+extern atomic_unchecked_t fscache_n_store_calls;
51399+extern atomic_unchecked_t fscache_n_store_pages;
51400+extern atomic_unchecked_t fscache_n_store_radix_deletes;
51401+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
51402
51403-extern atomic_t fscache_n_store_vmscan_not_storing;
51404-extern atomic_t fscache_n_store_vmscan_gone;
51405-extern atomic_t fscache_n_store_vmscan_busy;
51406-extern atomic_t fscache_n_store_vmscan_cancelled;
51407-extern atomic_t fscache_n_store_vmscan_wait;
51408+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51409+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51410+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51411+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51412+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51413
51414-extern atomic_t fscache_n_marks;
51415-extern atomic_t fscache_n_uncaches;
51416+extern atomic_unchecked_t fscache_n_marks;
51417+extern atomic_unchecked_t fscache_n_uncaches;
51418
51419-extern atomic_t fscache_n_acquires;
51420-extern atomic_t fscache_n_acquires_null;
51421-extern atomic_t fscache_n_acquires_no_cache;
51422-extern atomic_t fscache_n_acquires_ok;
51423-extern atomic_t fscache_n_acquires_nobufs;
51424-extern atomic_t fscache_n_acquires_oom;
51425+extern atomic_unchecked_t fscache_n_acquires;
51426+extern atomic_unchecked_t fscache_n_acquires_null;
51427+extern atomic_unchecked_t fscache_n_acquires_no_cache;
51428+extern atomic_unchecked_t fscache_n_acquires_ok;
51429+extern atomic_unchecked_t fscache_n_acquires_nobufs;
51430+extern atomic_unchecked_t fscache_n_acquires_oom;
51431
51432-extern atomic_t fscache_n_invalidates;
51433-extern atomic_t fscache_n_invalidates_run;
51434+extern atomic_unchecked_t fscache_n_invalidates;
51435+extern atomic_unchecked_t fscache_n_invalidates_run;
51436
51437-extern atomic_t fscache_n_updates;
51438-extern atomic_t fscache_n_updates_null;
51439-extern atomic_t fscache_n_updates_run;
51440+extern atomic_unchecked_t fscache_n_updates;
51441+extern atomic_unchecked_t fscache_n_updates_null;
51442+extern atomic_unchecked_t fscache_n_updates_run;
51443
51444-extern atomic_t fscache_n_relinquishes;
51445-extern atomic_t fscache_n_relinquishes_null;
51446-extern atomic_t fscache_n_relinquishes_waitcrt;
51447-extern atomic_t fscache_n_relinquishes_retire;
51448+extern atomic_unchecked_t fscache_n_relinquishes;
51449+extern atomic_unchecked_t fscache_n_relinquishes_null;
51450+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51451+extern atomic_unchecked_t fscache_n_relinquishes_retire;
51452
51453-extern atomic_t fscache_n_cookie_index;
51454-extern atomic_t fscache_n_cookie_data;
51455-extern atomic_t fscache_n_cookie_special;
51456+extern atomic_unchecked_t fscache_n_cookie_index;
51457+extern atomic_unchecked_t fscache_n_cookie_data;
51458+extern atomic_unchecked_t fscache_n_cookie_special;
51459
51460-extern atomic_t fscache_n_object_alloc;
51461-extern atomic_t fscache_n_object_no_alloc;
51462-extern atomic_t fscache_n_object_lookups;
51463-extern atomic_t fscache_n_object_lookups_negative;
51464-extern atomic_t fscache_n_object_lookups_positive;
51465-extern atomic_t fscache_n_object_lookups_timed_out;
51466-extern atomic_t fscache_n_object_created;
51467-extern atomic_t fscache_n_object_avail;
51468-extern atomic_t fscache_n_object_dead;
51469+extern atomic_unchecked_t fscache_n_object_alloc;
51470+extern atomic_unchecked_t fscache_n_object_no_alloc;
51471+extern atomic_unchecked_t fscache_n_object_lookups;
51472+extern atomic_unchecked_t fscache_n_object_lookups_negative;
51473+extern atomic_unchecked_t fscache_n_object_lookups_positive;
51474+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51475+extern atomic_unchecked_t fscache_n_object_created;
51476+extern atomic_unchecked_t fscache_n_object_avail;
51477+extern atomic_unchecked_t fscache_n_object_dead;
51478
51479-extern atomic_t fscache_n_checkaux_none;
51480-extern atomic_t fscache_n_checkaux_okay;
51481-extern atomic_t fscache_n_checkaux_update;
51482-extern atomic_t fscache_n_checkaux_obsolete;
51483+extern atomic_unchecked_t fscache_n_checkaux_none;
51484+extern atomic_unchecked_t fscache_n_checkaux_okay;
51485+extern atomic_unchecked_t fscache_n_checkaux_update;
51486+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51487
51488 extern atomic_t fscache_n_cop_alloc_object;
51489 extern atomic_t fscache_n_cop_lookup_object;
51490@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51491 atomic_inc(stat);
51492 }
51493
51494+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51495+{
51496+ atomic_inc_unchecked(stat);
51497+}
51498+
51499 static inline void fscache_stat_d(atomic_t *stat)
51500 {
51501 atomic_dec(stat);
51502@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51503
51504 #define __fscache_stat(stat) (NULL)
51505 #define fscache_stat(stat) do {} while (0)
51506+#define fscache_stat_unchecked(stat) do {} while (0)
51507 #define fscache_stat_d(stat) do {} while (0)
51508 #endif
51509
51510diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51511index 50d41c1..10ee117 100644
51512--- a/fs/fscache/object.c
51513+++ b/fs/fscache/object.c
51514@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51515 /* Invalidate an object on disk */
51516 case FSCACHE_OBJECT_INVALIDATING:
51517 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51518- fscache_stat(&fscache_n_invalidates_run);
51519+ fscache_stat_unchecked(&fscache_n_invalidates_run);
51520 fscache_stat(&fscache_n_cop_invalidate_object);
51521 fscache_invalidate_object(object);
51522 fscache_stat_d(&fscache_n_cop_invalidate_object);
51523@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51524 /* update the object metadata on disk */
51525 case FSCACHE_OBJECT_UPDATING:
51526 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51527- fscache_stat(&fscache_n_updates_run);
51528+ fscache_stat_unchecked(&fscache_n_updates_run);
51529 fscache_stat(&fscache_n_cop_update_object);
51530 object->cache->ops->update_object(object);
51531 fscache_stat_d(&fscache_n_cop_update_object);
51532@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51533 spin_lock(&object->lock);
51534 object->state = FSCACHE_OBJECT_DEAD;
51535 spin_unlock(&object->lock);
51536- fscache_stat(&fscache_n_object_dead);
51537+ fscache_stat_unchecked(&fscache_n_object_dead);
51538 goto terminal_transit;
51539
51540 /* handle the parent cache of this object being withdrawn from
51541@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51542 spin_lock(&object->lock);
51543 object->state = FSCACHE_OBJECT_DEAD;
51544 spin_unlock(&object->lock);
51545- fscache_stat(&fscache_n_object_dead);
51546+ fscache_stat_unchecked(&fscache_n_object_dead);
51547 goto terminal_transit;
51548
51549 /* complain about the object being woken up once it is
51550@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51551 parent->cookie->def->name, cookie->def->name,
51552 object->cache->tag->name);
51553
51554- fscache_stat(&fscache_n_object_lookups);
51555+ fscache_stat_unchecked(&fscache_n_object_lookups);
51556 fscache_stat(&fscache_n_cop_lookup_object);
51557 ret = object->cache->ops->lookup_object(object);
51558 fscache_stat_d(&fscache_n_cop_lookup_object);
51559@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51560 if (ret == -ETIMEDOUT) {
51561 /* probably stuck behind another object, so move this one to
51562 * the back of the queue */
51563- fscache_stat(&fscache_n_object_lookups_timed_out);
51564+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51565 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51566 }
51567
51568@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51569
51570 spin_lock(&object->lock);
51571 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51572- fscache_stat(&fscache_n_object_lookups_negative);
51573+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51574
51575 /* transit here to allow write requests to begin stacking up
51576 * and read requests to begin returning ENODATA */
51577@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51578 * result, in which case there may be data available */
51579 spin_lock(&object->lock);
51580 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51581- fscache_stat(&fscache_n_object_lookups_positive);
51582+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51583
51584 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51585
51586@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51587 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51588 } else {
51589 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51590- fscache_stat(&fscache_n_object_created);
51591+ fscache_stat_unchecked(&fscache_n_object_created);
51592
51593 object->state = FSCACHE_OBJECT_AVAILABLE;
51594 spin_unlock(&object->lock);
51595@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51596 fscache_enqueue_dependents(object);
51597
51598 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51599- fscache_stat(&fscache_n_object_avail);
51600+ fscache_stat_unchecked(&fscache_n_object_avail);
51601
51602 _leave("");
51603 }
51604@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51605 enum fscache_checkaux result;
51606
51607 if (!object->cookie->def->check_aux) {
51608- fscache_stat(&fscache_n_checkaux_none);
51609+ fscache_stat_unchecked(&fscache_n_checkaux_none);
51610 return FSCACHE_CHECKAUX_OKAY;
51611 }
51612
51613@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51614 switch (result) {
51615 /* entry okay as is */
51616 case FSCACHE_CHECKAUX_OKAY:
51617- fscache_stat(&fscache_n_checkaux_okay);
51618+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
51619 break;
51620
51621 /* entry requires update */
51622 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51623- fscache_stat(&fscache_n_checkaux_update);
51624+ fscache_stat_unchecked(&fscache_n_checkaux_update);
51625 break;
51626
51627 /* entry requires deletion */
51628 case FSCACHE_CHECKAUX_OBSOLETE:
51629- fscache_stat(&fscache_n_checkaux_obsolete);
51630+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51631 break;
51632
51633 default:
51634diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51635index 762a9ec..2023284 100644
51636--- a/fs/fscache/operation.c
51637+++ b/fs/fscache/operation.c
51638@@ -17,7 +17,7 @@
51639 #include <linux/slab.h>
51640 #include "internal.h"
51641
51642-atomic_t fscache_op_debug_id;
51643+atomic_unchecked_t fscache_op_debug_id;
51644 EXPORT_SYMBOL(fscache_op_debug_id);
51645
51646 /**
51647@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51648 ASSERTCMP(atomic_read(&op->usage), >, 0);
51649 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51650
51651- fscache_stat(&fscache_n_op_enqueue);
51652+ fscache_stat_unchecked(&fscache_n_op_enqueue);
51653 switch (op->flags & FSCACHE_OP_TYPE) {
51654 case FSCACHE_OP_ASYNC:
51655 _debug("queue async");
51656@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51657 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51658 if (op->processor)
51659 fscache_enqueue_operation(op);
51660- fscache_stat(&fscache_n_op_run);
51661+ fscache_stat_unchecked(&fscache_n_op_run);
51662 }
51663
51664 /*
51665@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51666 if (object->n_in_progress > 0) {
51667 atomic_inc(&op->usage);
51668 list_add_tail(&op->pend_link, &object->pending_ops);
51669- fscache_stat(&fscache_n_op_pend);
51670+ fscache_stat_unchecked(&fscache_n_op_pend);
51671 } else if (!list_empty(&object->pending_ops)) {
51672 atomic_inc(&op->usage);
51673 list_add_tail(&op->pend_link, &object->pending_ops);
51674- fscache_stat(&fscache_n_op_pend);
51675+ fscache_stat_unchecked(&fscache_n_op_pend);
51676 fscache_start_operations(object);
51677 } else {
51678 ASSERTCMP(object->n_in_progress, ==, 0);
51679@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51680 object->n_exclusive++; /* reads and writes must wait */
51681 atomic_inc(&op->usage);
51682 list_add_tail(&op->pend_link, &object->pending_ops);
51683- fscache_stat(&fscache_n_op_pend);
51684+ fscache_stat_unchecked(&fscache_n_op_pend);
51685 ret = 0;
51686 } else {
51687 /* If we're in any other state, there must have been an I/O
51688@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51689 if (object->n_exclusive > 0) {
51690 atomic_inc(&op->usage);
51691 list_add_tail(&op->pend_link, &object->pending_ops);
51692- fscache_stat(&fscache_n_op_pend);
51693+ fscache_stat_unchecked(&fscache_n_op_pend);
51694 } else if (!list_empty(&object->pending_ops)) {
51695 atomic_inc(&op->usage);
51696 list_add_tail(&op->pend_link, &object->pending_ops);
51697- fscache_stat(&fscache_n_op_pend);
51698+ fscache_stat_unchecked(&fscache_n_op_pend);
51699 fscache_start_operations(object);
51700 } else {
51701 ASSERTCMP(object->n_exclusive, ==, 0);
51702@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51703 object->n_ops++;
51704 atomic_inc(&op->usage);
51705 list_add_tail(&op->pend_link, &object->pending_ops);
51706- fscache_stat(&fscache_n_op_pend);
51707+ fscache_stat_unchecked(&fscache_n_op_pend);
51708 ret = 0;
51709 } else if (object->state == FSCACHE_OBJECT_DYING ||
51710 object->state == FSCACHE_OBJECT_LC_DYING ||
51711 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51712- fscache_stat(&fscache_n_op_rejected);
51713+ fscache_stat_unchecked(&fscache_n_op_rejected);
51714 op->state = FSCACHE_OP_ST_CANCELLED;
51715 ret = -ENOBUFS;
51716 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51717@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51718 ret = -EBUSY;
51719 if (op->state == FSCACHE_OP_ST_PENDING) {
51720 ASSERT(!list_empty(&op->pend_link));
51721- fscache_stat(&fscache_n_op_cancelled);
51722+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51723 list_del_init(&op->pend_link);
51724 if (do_cancel)
51725 do_cancel(op);
51726@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51727 while (!list_empty(&object->pending_ops)) {
51728 op = list_entry(object->pending_ops.next,
51729 struct fscache_operation, pend_link);
51730- fscache_stat(&fscache_n_op_cancelled);
51731+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51732 list_del_init(&op->pend_link);
51733
51734 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51735@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51736 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51737 op->state = FSCACHE_OP_ST_DEAD;
51738
51739- fscache_stat(&fscache_n_op_release);
51740+ fscache_stat_unchecked(&fscache_n_op_release);
51741
51742 if (op->release) {
51743 op->release(op);
51744@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51745 * lock, and defer it otherwise */
51746 if (!spin_trylock(&object->lock)) {
51747 _debug("defer put");
51748- fscache_stat(&fscache_n_op_deferred_release);
51749+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
51750
51751 cache = object->cache;
51752 spin_lock(&cache->op_gc_list_lock);
51753@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51754
51755 _debug("GC DEFERRED REL OBJ%x OP%x",
51756 object->debug_id, op->debug_id);
51757- fscache_stat(&fscache_n_op_gc);
51758+ fscache_stat_unchecked(&fscache_n_op_gc);
51759
51760 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51761 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51762diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51763index ff000e5..c44ec6d 100644
51764--- a/fs/fscache/page.c
51765+++ b/fs/fscache/page.c
51766@@ -61,7 +61,7 @@ try_again:
51767 val = radix_tree_lookup(&cookie->stores, page->index);
51768 if (!val) {
51769 rcu_read_unlock();
51770- fscache_stat(&fscache_n_store_vmscan_not_storing);
51771+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51772 __fscache_uncache_page(cookie, page);
51773 return true;
51774 }
51775@@ -91,11 +91,11 @@ try_again:
51776 spin_unlock(&cookie->stores_lock);
51777
51778 if (xpage) {
51779- fscache_stat(&fscache_n_store_vmscan_cancelled);
51780- fscache_stat(&fscache_n_store_radix_deletes);
51781+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51782+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51783 ASSERTCMP(xpage, ==, page);
51784 } else {
51785- fscache_stat(&fscache_n_store_vmscan_gone);
51786+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51787 }
51788
51789 wake_up_bit(&cookie->flags, 0);
51790@@ -110,11 +110,11 @@ page_busy:
51791 * sleeping on memory allocation, so we may need to impose a timeout
51792 * too. */
51793 if (!(gfp & __GFP_WAIT)) {
51794- fscache_stat(&fscache_n_store_vmscan_busy);
51795+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51796 return false;
51797 }
51798
51799- fscache_stat(&fscache_n_store_vmscan_wait);
51800+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51801 __fscache_wait_on_page_write(cookie, page);
51802 gfp &= ~__GFP_WAIT;
51803 goto try_again;
51804@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51805 FSCACHE_COOKIE_STORING_TAG);
51806 if (!radix_tree_tag_get(&cookie->stores, page->index,
51807 FSCACHE_COOKIE_PENDING_TAG)) {
51808- fscache_stat(&fscache_n_store_radix_deletes);
51809+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51810 xpage = radix_tree_delete(&cookie->stores, page->index);
51811 }
51812 spin_unlock(&cookie->stores_lock);
51813@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51814
51815 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51816
51817- fscache_stat(&fscache_n_attr_changed_calls);
51818+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51819
51820 if (fscache_object_is_active(object)) {
51821 fscache_stat(&fscache_n_cop_attr_changed);
51822@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51823
51824 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51825
51826- fscache_stat(&fscache_n_attr_changed);
51827+ fscache_stat_unchecked(&fscache_n_attr_changed);
51828
51829 op = kzalloc(sizeof(*op), GFP_KERNEL);
51830 if (!op) {
51831- fscache_stat(&fscache_n_attr_changed_nomem);
51832+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51833 _leave(" = -ENOMEM");
51834 return -ENOMEM;
51835 }
51836@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51837 if (fscache_submit_exclusive_op(object, op) < 0)
51838 goto nobufs;
51839 spin_unlock(&cookie->lock);
51840- fscache_stat(&fscache_n_attr_changed_ok);
51841+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51842 fscache_put_operation(op);
51843 _leave(" = 0");
51844 return 0;
51845@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51846 nobufs:
51847 spin_unlock(&cookie->lock);
51848 kfree(op);
51849- fscache_stat(&fscache_n_attr_changed_nobufs);
51850+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51851 _leave(" = %d", -ENOBUFS);
51852 return -ENOBUFS;
51853 }
51854@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51855 /* allocate a retrieval operation and attempt to submit it */
51856 op = kzalloc(sizeof(*op), GFP_NOIO);
51857 if (!op) {
51858- fscache_stat(&fscache_n_retrievals_nomem);
51859+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51860 return NULL;
51861 }
51862
51863@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51864 return 0;
51865 }
51866
51867- fscache_stat(&fscache_n_retrievals_wait);
51868+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
51869
51870 jif = jiffies;
51871 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51872 fscache_wait_bit_interruptible,
51873 TASK_INTERRUPTIBLE) != 0) {
51874- fscache_stat(&fscache_n_retrievals_intr);
51875+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51876 _leave(" = -ERESTARTSYS");
51877 return -ERESTARTSYS;
51878 }
51879@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51880 */
51881 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51882 struct fscache_retrieval *op,
51883- atomic_t *stat_op_waits,
51884- atomic_t *stat_object_dead)
51885+ atomic_unchecked_t *stat_op_waits,
51886+ atomic_unchecked_t *stat_object_dead)
51887 {
51888 int ret;
51889
51890@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51891 goto check_if_dead;
51892
51893 _debug(">>> WT");
51894- fscache_stat(stat_op_waits);
51895+ fscache_stat_unchecked(stat_op_waits);
51896 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51897 fscache_wait_bit_interruptible,
51898 TASK_INTERRUPTIBLE) != 0) {
51899@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51900
51901 check_if_dead:
51902 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51903- fscache_stat(stat_object_dead);
51904+ fscache_stat_unchecked(stat_object_dead);
51905 _leave(" = -ENOBUFS [cancelled]");
51906 return -ENOBUFS;
51907 }
51908 if (unlikely(fscache_object_is_dead(object))) {
51909 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51910 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51911- fscache_stat(stat_object_dead);
51912+ fscache_stat_unchecked(stat_object_dead);
51913 return -ENOBUFS;
51914 }
51915 return 0;
51916@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51917
51918 _enter("%p,%p,,,", cookie, page);
51919
51920- fscache_stat(&fscache_n_retrievals);
51921+ fscache_stat_unchecked(&fscache_n_retrievals);
51922
51923 if (hlist_empty(&cookie->backing_objects))
51924 goto nobufs;
51925@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51926 goto nobufs_unlock_dec;
51927 spin_unlock(&cookie->lock);
51928
51929- fscache_stat(&fscache_n_retrieval_ops);
51930+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51931
51932 /* pin the netfs read context in case we need to do the actual netfs
51933 * read because we've encountered a cache read failure */
51934@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51935
51936 error:
51937 if (ret == -ENOMEM)
51938- fscache_stat(&fscache_n_retrievals_nomem);
51939+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51940 else if (ret == -ERESTARTSYS)
51941- fscache_stat(&fscache_n_retrievals_intr);
51942+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51943 else if (ret == -ENODATA)
51944- fscache_stat(&fscache_n_retrievals_nodata);
51945+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51946 else if (ret < 0)
51947- fscache_stat(&fscache_n_retrievals_nobufs);
51948+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51949 else
51950- fscache_stat(&fscache_n_retrievals_ok);
51951+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
51952
51953 fscache_put_retrieval(op);
51954 _leave(" = %d", ret);
51955@@ -467,7 +467,7 @@ nobufs_unlock:
51956 spin_unlock(&cookie->lock);
51957 kfree(op);
51958 nobufs:
51959- fscache_stat(&fscache_n_retrievals_nobufs);
51960+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51961 _leave(" = -ENOBUFS");
51962 return -ENOBUFS;
51963 }
51964@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51965
51966 _enter("%p,,%d,,,", cookie, *nr_pages);
51967
51968- fscache_stat(&fscache_n_retrievals);
51969+ fscache_stat_unchecked(&fscache_n_retrievals);
51970
51971 if (hlist_empty(&cookie->backing_objects))
51972 goto nobufs;
51973@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51974 goto nobufs_unlock_dec;
51975 spin_unlock(&cookie->lock);
51976
51977- fscache_stat(&fscache_n_retrieval_ops);
51978+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51979
51980 /* pin the netfs read context in case we need to do the actual netfs
51981 * read because we've encountered a cache read failure */
51982@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51983
51984 error:
51985 if (ret == -ENOMEM)
51986- fscache_stat(&fscache_n_retrievals_nomem);
51987+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51988 else if (ret == -ERESTARTSYS)
51989- fscache_stat(&fscache_n_retrievals_intr);
51990+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51991 else if (ret == -ENODATA)
51992- fscache_stat(&fscache_n_retrievals_nodata);
51993+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51994 else if (ret < 0)
51995- fscache_stat(&fscache_n_retrievals_nobufs);
51996+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51997 else
51998- fscache_stat(&fscache_n_retrievals_ok);
51999+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52000
52001 fscache_put_retrieval(op);
52002 _leave(" = %d", ret);
52003@@ -591,7 +591,7 @@ nobufs_unlock:
52004 spin_unlock(&cookie->lock);
52005 kfree(op);
52006 nobufs:
52007- fscache_stat(&fscache_n_retrievals_nobufs);
52008+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52009 _leave(" = -ENOBUFS");
52010 return -ENOBUFS;
52011 }
52012@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52013
52014 _enter("%p,%p,,,", cookie, page);
52015
52016- fscache_stat(&fscache_n_allocs);
52017+ fscache_stat_unchecked(&fscache_n_allocs);
52018
52019 if (hlist_empty(&cookie->backing_objects))
52020 goto nobufs;
52021@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52022 goto nobufs_unlock;
52023 spin_unlock(&cookie->lock);
52024
52025- fscache_stat(&fscache_n_alloc_ops);
52026+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52027
52028 ret = fscache_wait_for_retrieval_activation(
52029 object, op,
52030@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52031
52032 error:
52033 if (ret == -ERESTARTSYS)
52034- fscache_stat(&fscache_n_allocs_intr);
52035+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52036 else if (ret < 0)
52037- fscache_stat(&fscache_n_allocs_nobufs);
52038+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52039 else
52040- fscache_stat(&fscache_n_allocs_ok);
52041+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52042
52043 fscache_put_retrieval(op);
52044 _leave(" = %d", ret);
52045@@ -677,7 +677,7 @@ nobufs_unlock:
52046 spin_unlock(&cookie->lock);
52047 kfree(op);
52048 nobufs:
52049- fscache_stat(&fscache_n_allocs_nobufs);
52050+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52051 _leave(" = -ENOBUFS");
52052 return -ENOBUFS;
52053 }
52054@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52055
52056 spin_lock(&cookie->stores_lock);
52057
52058- fscache_stat(&fscache_n_store_calls);
52059+ fscache_stat_unchecked(&fscache_n_store_calls);
52060
52061 /* find a page to store */
52062 page = NULL;
52063@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52064 page = results[0];
52065 _debug("gang %d [%lx]", n, page->index);
52066 if (page->index > op->store_limit) {
52067- fscache_stat(&fscache_n_store_pages_over_limit);
52068+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52069 goto superseded;
52070 }
52071
52072@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52073 spin_unlock(&cookie->stores_lock);
52074 spin_unlock(&object->lock);
52075
52076- fscache_stat(&fscache_n_store_pages);
52077+ fscache_stat_unchecked(&fscache_n_store_pages);
52078 fscache_stat(&fscache_n_cop_write_page);
52079 ret = object->cache->ops->write_page(op, page);
52080 fscache_stat_d(&fscache_n_cop_write_page);
52081@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52082 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52083 ASSERT(PageFsCache(page));
52084
52085- fscache_stat(&fscache_n_stores);
52086+ fscache_stat_unchecked(&fscache_n_stores);
52087
52088 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52089 _leave(" = -ENOBUFS [invalidating]");
52090@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52091 spin_unlock(&cookie->stores_lock);
52092 spin_unlock(&object->lock);
52093
52094- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52095+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52096 op->store_limit = object->store_limit;
52097
52098 if (fscache_submit_op(object, &op->op) < 0)
52099@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52100
52101 spin_unlock(&cookie->lock);
52102 radix_tree_preload_end();
52103- fscache_stat(&fscache_n_store_ops);
52104- fscache_stat(&fscache_n_stores_ok);
52105+ fscache_stat_unchecked(&fscache_n_store_ops);
52106+ fscache_stat_unchecked(&fscache_n_stores_ok);
52107
52108 /* the work queue now carries its own ref on the object */
52109 fscache_put_operation(&op->op);
52110@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52111 return 0;
52112
52113 already_queued:
52114- fscache_stat(&fscache_n_stores_again);
52115+ fscache_stat_unchecked(&fscache_n_stores_again);
52116 already_pending:
52117 spin_unlock(&cookie->stores_lock);
52118 spin_unlock(&object->lock);
52119 spin_unlock(&cookie->lock);
52120 radix_tree_preload_end();
52121 kfree(op);
52122- fscache_stat(&fscache_n_stores_ok);
52123+ fscache_stat_unchecked(&fscache_n_stores_ok);
52124 _leave(" = 0");
52125 return 0;
52126
52127@@ -959,14 +959,14 @@ nobufs:
52128 spin_unlock(&cookie->lock);
52129 radix_tree_preload_end();
52130 kfree(op);
52131- fscache_stat(&fscache_n_stores_nobufs);
52132+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52133 _leave(" = -ENOBUFS");
52134 return -ENOBUFS;
52135
52136 nomem_free:
52137 kfree(op);
52138 nomem:
52139- fscache_stat(&fscache_n_stores_oom);
52140+ fscache_stat_unchecked(&fscache_n_stores_oom);
52141 _leave(" = -ENOMEM");
52142 return -ENOMEM;
52143 }
52144@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52145 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52146 ASSERTCMP(page, !=, NULL);
52147
52148- fscache_stat(&fscache_n_uncaches);
52149+ fscache_stat_unchecked(&fscache_n_uncaches);
52150
52151 /* cache withdrawal may beat us to it */
52152 if (!PageFsCache(page))
52153@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52154 struct fscache_cookie *cookie = op->op.object->cookie;
52155
52156 #ifdef CONFIG_FSCACHE_STATS
52157- atomic_inc(&fscache_n_marks);
52158+ atomic_inc_unchecked(&fscache_n_marks);
52159 #endif
52160
52161 _debug("- mark %p{%lx}", page, page->index);
52162diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52163index 8179e8b..5072cc7 100644
52164--- a/fs/fscache/stats.c
52165+++ b/fs/fscache/stats.c
52166@@ -18,99 +18,99 @@
52167 /*
52168 * operation counters
52169 */
52170-atomic_t fscache_n_op_pend;
52171-atomic_t fscache_n_op_run;
52172-atomic_t fscache_n_op_enqueue;
52173-atomic_t fscache_n_op_requeue;
52174-atomic_t fscache_n_op_deferred_release;
52175-atomic_t fscache_n_op_release;
52176-atomic_t fscache_n_op_gc;
52177-atomic_t fscache_n_op_cancelled;
52178-atomic_t fscache_n_op_rejected;
52179+atomic_unchecked_t fscache_n_op_pend;
52180+atomic_unchecked_t fscache_n_op_run;
52181+atomic_unchecked_t fscache_n_op_enqueue;
52182+atomic_unchecked_t fscache_n_op_requeue;
52183+atomic_unchecked_t fscache_n_op_deferred_release;
52184+atomic_unchecked_t fscache_n_op_release;
52185+atomic_unchecked_t fscache_n_op_gc;
52186+atomic_unchecked_t fscache_n_op_cancelled;
52187+atomic_unchecked_t fscache_n_op_rejected;
52188
52189-atomic_t fscache_n_attr_changed;
52190-atomic_t fscache_n_attr_changed_ok;
52191-atomic_t fscache_n_attr_changed_nobufs;
52192-atomic_t fscache_n_attr_changed_nomem;
52193-atomic_t fscache_n_attr_changed_calls;
52194+atomic_unchecked_t fscache_n_attr_changed;
52195+atomic_unchecked_t fscache_n_attr_changed_ok;
52196+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52197+atomic_unchecked_t fscache_n_attr_changed_nomem;
52198+atomic_unchecked_t fscache_n_attr_changed_calls;
52199
52200-atomic_t fscache_n_allocs;
52201-atomic_t fscache_n_allocs_ok;
52202-atomic_t fscache_n_allocs_wait;
52203-atomic_t fscache_n_allocs_nobufs;
52204-atomic_t fscache_n_allocs_intr;
52205-atomic_t fscache_n_allocs_object_dead;
52206-atomic_t fscache_n_alloc_ops;
52207-atomic_t fscache_n_alloc_op_waits;
52208+atomic_unchecked_t fscache_n_allocs;
52209+atomic_unchecked_t fscache_n_allocs_ok;
52210+atomic_unchecked_t fscache_n_allocs_wait;
52211+atomic_unchecked_t fscache_n_allocs_nobufs;
52212+atomic_unchecked_t fscache_n_allocs_intr;
52213+atomic_unchecked_t fscache_n_allocs_object_dead;
52214+atomic_unchecked_t fscache_n_alloc_ops;
52215+atomic_unchecked_t fscache_n_alloc_op_waits;
52216
52217-atomic_t fscache_n_retrievals;
52218-atomic_t fscache_n_retrievals_ok;
52219-atomic_t fscache_n_retrievals_wait;
52220-atomic_t fscache_n_retrievals_nodata;
52221-atomic_t fscache_n_retrievals_nobufs;
52222-atomic_t fscache_n_retrievals_intr;
52223-atomic_t fscache_n_retrievals_nomem;
52224-atomic_t fscache_n_retrievals_object_dead;
52225-atomic_t fscache_n_retrieval_ops;
52226-atomic_t fscache_n_retrieval_op_waits;
52227+atomic_unchecked_t fscache_n_retrievals;
52228+atomic_unchecked_t fscache_n_retrievals_ok;
52229+atomic_unchecked_t fscache_n_retrievals_wait;
52230+atomic_unchecked_t fscache_n_retrievals_nodata;
52231+atomic_unchecked_t fscache_n_retrievals_nobufs;
52232+atomic_unchecked_t fscache_n_retrievals_intr;
52233+atomic_unchecked_t fscache_n_retrievals_nomem;
52234+atomic_unchecked_t fscache_n_retrievals_object_dead;
52235+atomic_unchecked_t fscache_n_retrieval_ops;
52236+atomic_unchecked_t fscache_n_retrieval_op_waits;
52237
52238-atomic_t fscache_n_stores;
52239-atomic_t fscache_n_stores_ok;
52240-atomic_t fscache_n_stores_again;
52241-atomic_t fscache_n_stores_nobufs;
52242-atomic_t fscache_n_stores_oom;
52243-atomic_t fscache_n_store_ops;
52244-atomic_t fscache_n_store_calls;
52245-atomic_t fscache_n_store_pages;
52246-atomic_t fscache_n_store_radix_deletes;
52247-atomic_t fscache_n_store_pages_over_limit;
52248+atomic_unchecked_t fscache_n_stores;
52249+atomic_unchecked_t fscache_n_stores_ok;
52250+atomic_unchecked_t fscache_n_stores_again;
52251+atomic_unchecked_t fscache_n_stores_nobufs;
52252+atomic_unchecked_t fscache_n_stores_oom;
52253+atomic_unchecked_t fscache_n_store_ops;
52254+atomic_unchecked_t fscache_n_store_calls;
52255+atomic_unchecked_t fscache_n_store_pages;
52256+atomic_unchecked_t fscache_n_store_radix_deletes;
52257+atomic_unchecked_t fscache_n_store_pages_over_limit;
52258
52259-atomic_t fscache_n_store_vmscan_not_storing;
52260-atomic_t fscache_n_store_vmscan_gone;
52261-atomic_t fscache_n_store_vmscan_busy;
52262-atomic_t fscache_n_store_vmscan_cancelled;
52263-atomic_t fscache_n_store_vmscan_wait;
52264+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52265+atomic_unchecked_t fscache_n_store_vmscan_gone;
52266+atomic_unchecked_t fscache_n_store_vmscan_busy;
52267+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52268+atomic_unchecked_t fscache_n_store_vmscan_wait;
52269
52270-atomic_t fscache_n_marks;
52271-atomic_t fscache_n_uncaches;
52272+atomic_unchecked_t fscache_n_marks;
52273+atomic_unchecked_t fscache_n_uncaches;
52274
52275-atomic_t fscache_n_acquires;
52276-atomic_t fscache_n_acquires_null;
52277-atomic_t fscache_n_acquires_no_cache;
52278-atomic_t fscache_n_acquires_ok;
52279-atomic_t fscache_n_acquires_nobufs;
52280-atomic_t fscache_n_acquires_oom;
52281+atomic_unchecked_t fscache_n_acquires;
52282+atomic_unchecked_t fscache_n_acquires_null;
52283+atomic_unchecked_t fscache_n_acquires_no_cache;
52284+atomic_unchecked_t fscache_n_acquires_ok;
52285+atomic_unchecked_t fscache_n_acquires_nobufs;
52286+atomic_unchecked_t fscache_n_acquires_oom;
52287
52288-atomic_t fscache_n_invalidates;
52289-atomic_t fscache_n_invalidates_run;
52290+atomic_unchecked_t fscache_n_invalidates;
52291+atomic_unchecked_t fscache_n_invalidates_run;
52292
52293-atomic_t fscache_n_updates;
52294-atomic_t fscache_n_updates_null;
52295-atomic_t fscache_n_updates_run;
52296+atomic_unchecked_t fscache_n_updates;
52297+atomic_unchecked_t fscache_n_updates_null;
52298+atomic_unchecked_t fscache_n_updates_run;
52299
52300-atomic_t fscache_n_relinquishes;
52301-atomic_t fscache_n_relinquishes_null;
52302-atomic_t fscache_n_relinquishes_waitcrt;
52303-atomic_t fscache_n_relinquishes_retire;
52304+atomic_unchecked_t fscache_n_relinquishes;
52305+atomic_unchecked_t fscache_n_relinquishes_null;
52306+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52307+atomic_unchecked_t fscache_n_relinquishes_retire;
52308
52309-atomic_t fscache_n_cookie_index;
52310-atomic_t fscache_n_cookie_data;
52311-atomic_t fscache_n_cookie_special;
52312+atomic_unchecked_t fscache_n_cookie_index;
52313+atomic_unchecked_t fscache_n_cookie_data;
52314+atomic_unchecked_t fscache_n_cookie_special;
52315
52316-atomic_t fscache_n_object_alloc;
52317-atomic_t fscache_n_object_no_alloc;
52318-atomic_t fscache_n_object_lookups;
52319-atomic_t fscache_n_object_lookups_negative;
52320-atomic_t fscache_n_object_lookups_positive;
52321-atomic_t fscache_n_object_lookups_timed_out;
52322-atomic_t fscache_n_object_created;
52323-atomic_t fscache_n_object_avail;
52324-atomic_t fscache_n_object_dead;
52325+atomic_unchecked_t fscache_n_object_alloc;
52326+atomic_unchecked_t fscache_n_object_no_alloc;
52327+atomic_unchecked_t fscache_n_object_lookups;
52328+atomic_unchecked_t fscache_n_object_lookups_negative;
52329+atomic_unchecked_t fscache_n_object_lookups_positive;
52330+atomic_unchecked_t fscache_n_object_lookups_timed_out;
52331+atomic_unchecked_t fscache_n_object_created;
52332+atomic_unchecked_t fscache_n_object_avail;
52333+atomic_unchecked_t fscache_n_object_dead;
52334
52335-atomic_t fscache_n_checkaux_none;
52336-atomic_t fscache_n_checkaux_okay;
52337-atomic_t fscache_n_checkaux_update;
52338-atomic_t fscache_n_checkaux_obsolete;
52339+atomic_unchecked_t fscache_n_checkaux_none;
52340+atomic_unchecked_t fscache_n_checkaux_okay;
52341+atomic_unchecked_t fscache_n_checkaux_update;
52342+atomic_unchecked_t fscache_n_checkaux_obsolete;
52343
52344 atomic_t fscache_n_cop_alloc_object;
52345 atomic_t fscache_n_cop_lookup_object;
52346@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
52347 seq_puts(m, "FS-Cache statistics\n");
52348
52349 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
52350- atomic_read(&fscache_n_cookie_index),
52351- atomic_read(&fscache_n_cookie_data),
52352- atomic_read(&fscache_n_cookie_special));
52353+ atomic_read_unchecked(&fscache_n_cookie_index),
52354+ atomic_read_unchecked(&fscache_n_cookie_data),
52355+ atomic_read_unchecked(&fscache_n_cookie_special));
52356
52357 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
52358- atomic_read(&fscache_n_object_alloc),
52359- atomic_read(&fscache_n_object_no_alloc),
52360- atomic_read(&fscache_n_object_avail),
52361- atomic_read(&fscache_n_object_dead));
52362+ atomic_read_unchecked(&fscache_n_object_alloc),
52363+ atomic_read_unchecked(&fscache_n_object_no_alloc),
52364+ atomic_read_unchecked(&fscache_n_object_avail),
52365+ atomic_read_unchecked(&fscache_n_object_dead));
52366 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
52367- atomic_read(&fscache_n_checkaux_none),
52368- atomic_read(&fscache_n_checkaux_okay),
52369- atomic_read(&fscache_n_checkaux_update),
52370- atomic_read(&fscache_n_checkaux_obsolete));
52371+ atomic_read_unchecked(&fscache_n_checkaux_none),
52372+ atomic_read_unchecked(&fscache_n_checkaux_okay),
52373+ atomic_read_unchecked(&fscache_n_checkaux_update),
52374+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
52375
52376 seq_printf(m, "Pages : mrk=%u unc=%u\n",
52377- atomic_read(&fscache_n_marks),
52378- atomic_read(&fscache_n_uncaches));
52379+ atomic_read_unchecked(&fscache_n_marks),
52380+ atomic_read_unchecked(&fscache_n_uncaches));
52381
52382 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
52383 " oom=%u\n",
52384- atomic_read(&fscache_n_acquires),
52385- atomic_read(&fscache_n_acquires_null),
52386- atomic_read(&fscache_n_acquires_no_cache),
52387- atomic_read(&fscache_n_acquires_ok),
52388- atomic_read(&fscache_n_acquires_nobufs),
52389- atomic_read(&fscache_n_acquires_oom));
52390+ atomic_read_unchecked(&fscache_n_acquires),
52391+ atomic_read_unchecked(&fscache_n_acquires_null),
52392+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
52393+ atomic_read_unchecked(&fscache_n_acquires_ok),
52394+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
52395+ atomic_read_unchecked(&fscache_n_acquires_oom));
52396
52397 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
52398- atomic_read(&fscache_n_object_lookups),
52399- atomic_read(&fscache_n_object_lookups_negative),
52400- atomic_read(&fscache_n_object_lookups_positive),
52401- atomic_read(&fscache_n_object_created),
52402- atomic_read(&fscache_n_object_lookups_timed_out));
52403+ atomic_read_unchecked(&fscache_n_object_lookups),
52404+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
52405+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
52406+ atomic_read_unchecked(&fscache_n_object_created),
52407+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52408
52409 seq_printf(m, "Invals : n=%u run=%u\n",
52410- atomic_read(&fscache_n_invalidates),
52411- atomic_read(&fscache_n_invalidates_run));
52412+ atomic_read_unchecked(&fscache_n_invalidates),
52413+ atomic_read_unchecked(&fscache_n_invalidates_run));
52414
52415 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52416- atomic_read(&fscache_n_updates),
52417- atomic_read(&fscache_n_updates_null),
52418- atomic_read(&fscache_n_updates_run));
52419+ atomic_read_unchecked(&fscache_n_updates),
52420+ atomic_read_unchecked(&fscache_n_updates_null),
52421+ atomic_read_unchecked(&fscache_n_updates_run));
52422
52423 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52424- atomic_read(&fscache_n_relinquishes),
52425- atomic_read(&fscache_n_relinquishes_null),
52426- atomic_read(&fscache_n_relinquishes_waitcrt),
52427- atomic_read(&fscache_n_relinquishes_retire));
52428+ atomic_read_unchecked(&fscache_n_relinquishes),
52429+ atomic_read_unchecked(&fscache_n_relinquishes_null),
52430+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52431+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
52432
52433 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52434- atomic_read(&fscache_n_attr_changed),
52435- atomic_read(&fscache_n_attr_changed_ok),
52436- atomic_read(&fscache_n_attr_changed_nobufs),
52437- atomic_read(&fscache_n_attr_changed_nomem),
52438- atomic_read(&fscache_n_attr_changed_calls));
52439+ atomic_read_unchecked(&fscache_n_attr_changed),
52440+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
52441+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52442+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52443+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
52444
52445 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52446- atomic_read(&fscache_n_allocs),
52447- atomic_read(&fscache_n_allocs_ok),
52448- atomic_read(&fscache_n_allocs_wait),
52449- atomic_read(&fscache_n_allocs_nobufs),
52450- atomic_read(&fscache_n_allocs_intr));
52451+ atomic_read_unchecked(&fscache_n_allocs),
52452+ atomic_read_unchecked(&fscache_n_allocs_ok),
52453+ atomic_read_unchecked(&fscache_n_allocs_wait),
52454+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
52455+ atomic_read_unchecked(&fscache_n_allocs_intr));
52456 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52457- atomic_read(&fscache_n_alloc_ops),
52458- atomic_read(&fscache_n_alloc_op_waits),
52459- atomic_read(&fscache_n_allocs_object_dead));
52460+ atomic_read_unchecked(&fscache_n_alloc_ops),
52461+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
52462+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
52463
52464 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52465 " int=%u oom=%u\n",
52466- atomic_read(&fscache_n_retrievals),
52467- atomic_read(&fscache_n_retrievals_ok),
52468- atomic_read(&fscache_n_retrievals_wait),
52469- atomic_read(&fscache_n_retrievals_nodata),
52470- atomic_read(&fscache_n_retrievals_nobufs),
52471- atomic_read(&fscache_n_retrievals_intr),
52472- atomic_read(&fscache_n_retrievals_nomem));
52473+ atomic_read_unchecked(&fscache_n_retrievals),
52474+ atomic_read_unchecked(&fscache_n_retrievals_ok),
52475+ atomic_read_unchecked(&fscache_n_retrievals_wait),
52476+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
52477+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52478+ atomic_read_unchecked(&fscache_n_retrievals_intr),
52479+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
52480 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52481- atomic_read(&fscache_n_retrieval_ops),
52482- atomic_read(&fscache_n_retrieval_op_waits),
52483- atomic_read(&fscache_n_retrievals_object_dead));
52484+ atomic_read_unchecked(&fscache_n_retrieval_ops),
52485+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52486+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52487
52488 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52489- atomic_read(&fscache_n_stores),
52490- atomic_read(&fscache_n_stores_ok),
52491- atomic_read(&fscache_n_stores_again),
52492- atomic_read(&fscache_n_stores_nobufs),
52493- atomic_read(&fscache_n_stores_oom));
52494+ atomic_read_unchecked(&fscache_n_stores),
52495+ atomic_read_unchecked(&fscache_n_stores_ok),
52496+ atomic_read_unchecked(&fscache_n_stores_again),
52497+ atomic_read_unchecked(&fscache_n_stores_nobufs),
52498+ atomic_read_unchecked(&fscache_n_stores_oom));
52499 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52500- atomic_read(&fscache_n_store_ops),
52501- atomic_read(&fscache_n_store_calls),
52502- atomic_read(&fscache_n_store_pages),
52503- atomic_read(&fscache_n_store_radix_deletes),
52504- atomic_read(&fscache_n_store_pages_over_limit));
52505+ atomic_read_unchecked(&fscache_n_store_ops),
52506+ atomic_read_unchecked(&fscache_n_store_calls),
52507+ atomic_read_unchecked(&fscache_n_store_pages),
52508+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
52509+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52510
52511 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52512- atomic_read(&fscache_n_store_vmscan_not_storing),
52513- atomic_read(&fscache_n_store_vmscan_gone),
52514- atomic_read(&fscache_n_store_vmscan_busy),
52515- atomic_read(&fscache_n_store_vmscan_cancelled),
52516- atomic_read(&fscache_n_store_vmscan_wait));
52517+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52518+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52519+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52520+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52521+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52522
52523 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52524- atomic_read(&fscache_n_op_pend),
52525- atomic_read(&fscache_n_op_run),
52526- atomic_read(&fscache_n_op_enqueue),
52527- atomic_read(&fscache_n_op_cancelled),
52528- atomic_read(&fscache_n_op_rejected));
52529+ atomic_read_unchecked(&fscache_n_op_pend),
52530+ atomic_read_unchecked(&fscache_n_op_run),
52531+ atomic_read_unchecked(&fscache_n_op_enqueue),
52532+ atomic_read_unchecked(&fscache_n_op_cancelled),
52533+ atomic_read_unchecked(&fscache_n_op_rejected));
52534 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52535- atomic_read(&fscache_n_op_deferred_release),
52536- atomic_read(&fscache_n_op_release),
52537- atomic_read(&fscache_n_op_gc));
52538+ atomic_read_unchecked(&fscache_n_op_deferred_release),
52539+ atomic_read_unchecked(&fscache_n_op_release),
52540+ atomic_read_unchecked(&fscache_n_op_gc));
52541
52542 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52543 atomic_read(&fscache_n_cop_alloc_object),
52544diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52545index e397b67..b0d8709 100644
52546--- a/fs/fuse/cuse.c
52547+++ b/fs/fuse/cuse.c
52548@@ -593,10 +593,12 @@ static int __init cuse_init(void)
52549 INIT_LIST_HEAD(&cuse_conntbl[i]);
52550
52551 /* inherit and extend fuse_dev_operations */
52552- cuse_channel_fops = fuse_dev_operations;
52553- cuse_channel_fops.owner = THIS_MODULE;
52554- cuse_channel_fops.open = cuse_channel_open;
52555- cuse_channel_fops.release = cuse_channel_release;
52556+ pax_open_kernel();
52557+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52558+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52559+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
52560+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
52561+ pax_close_kernel();
52562
52563 cuse_class = class_create(THIS_MODULE, "cuse");
52564 if (IS_ERR(cuse_class))
52565diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52566index e83351a..41e3c9c 100644
52567--- a/fs/fuse/dev.c
52568+++ b/fs/fuse/dev.c
52569@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52570 ret = 0;
52571 pipe_lock(pipe);
52572
52573- if (!pipe->readers) {
52574+ if (!atomic_read(&pipe->readers)) {
52575 send_sig(SIGPIPE, current, 0);
52576 if (!ret)
52577 ret = -EPIPE;
52578diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52579index 315e1f8..91f890c 100644
52580--- a/fs/fuse/dir.c
52581+++ b/fs/fuse/dir.c
52582@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52583 return link;
52584 }
52585
52586-static void free_link(char *link)
52587+static void free_link(const char *link)
52588 {
52589 if (!IS_ERR(link))
52590 free_page((unsigned long) link);
52591diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52592index 2b6f569..fcb4d1f 100644
52593--- a/fs/gfs2/inode.c
52594+++ b/fs/gfs2/inode.c
52595@@ -1499,7 +1499,7 @@ out:
52596
52597 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52598 {
52599- char *s = nd_get_link(nd);
52600+ const char *s = nd_get_link(nd);
52601 if (!IS_ERR(s))
52602 kfree(s);
52603 }
52604diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52605index 78bde32..767e906 100644
52606--- a/fs/hugetlbfs/inode.c
52607+++ b/fs/hugetlbfs/inode.c
52608@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52609 struct mm_struct *mm = current->mm;
52610 struct vm_area_struct *vma;
52611 struct hstate *h = hstate_file(file);
52612+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52613 struct vm_unmapped_area_info info;
52614
52615 if (len & ~huge_page_mask(h))
52616@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52617 return addr;
52618 }
52619
52620+#ifdef CONFIG_PAX_RANDMMAP
52621+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52622+#endif
52623+
52624 if (addr) {
52625 addr = ALIGN(addr, huge_page_size(h));
52626 vma = find_vma(mm, addr);
52627- if (TASK_SIZE - len >= addr &&
52628- (!vma || addr + len <= vma->vm_start))
52629+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52630 return addr;
52631 }
52632
52633 info.flags = 0;
52634 info.length = len;
52635 info.low_limit = TASK_UNMAPPED_BASE;
52636+
52637+#ifdef CONFIG_PAX_RANDMMAP
52638+ if (mm->pax_flags & MF_PAX_RANDMMAP)
52639+ info.low_limit += mm->delta_mmap;
52640+#endif
52641+
52642 info.high_limit = TASK_SIZE;
52643 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52644 info.align_offset = 0;
52645@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52646 .kill_sb = kill_litter_super,
52647 };
52648
52649-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52650+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52651
52652 static int can_do_hugetlb_shm(void)
52653 {
52654diff --git a/fs/inode.c b/fs/inode.c
52655index 14084b7..29af1d9 100644
52656--- a/fs/inode.c
52657+++ b/fs/inode.c
52658@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52659
52660 #ifdef CONFIG_SMP
52661 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52662- static atomic_t shared_last_ino;
52663- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52664+ static atomic_unchecked_t shared_last_ino;
52665+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52666
52667 res = next - LAST_INO_BATCH;
52668 }
52669diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52670index 4a6cf28..d3a29d3 100644
52671--- a/fs/jffs2/erase.c
52672+++ b/fs/jffs2/erase.c
52673@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52674 struct jffs2_unknown_node marker = {
52675 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52676 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52677- .totlen = cpu_to_je32(c->cleanmarker_size)
52678+ .totlen = cpu_to_je32(c->cleanmarker_size),
52679+ .hdr_crc = cpu_to_je32(0)
52680 };
52681
52682 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52683diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52684index a6597d6..41b30ec 100644
52685--- a/fs/jffs2/wbuf.c
52686+++ b/fs/jffs2/wbuf.c
52687@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52688 {
52689 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52690 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52691- .totlen = constant_cpu_to_je32(8)
52692+ .totlen = constant_cpu_to_je32(8),
52693+ .hdr_crc = constant_cpu_to_je32(0)
52694 };
52695
52696 /*
52697diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52698index 1a543be..a4e1363 100644
52699--- a/fs/jfs/super.c
52700+++ b/fs/jfs/super.c
52701@@ -225,7 +225,7 @@ static const match_table_t tokens = {
52702 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52703 int *flag)
52704 {
52705- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52706+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52707 char *p;
52708 struct jfs_sb_info *sbi = JFS_SBI(sb);
52709
52710@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52711 /* Don't do anything ;-) */
52712 break;
52713 case Opt_iocharset:
52714- if (nls_map && nls_map != (void *) -1)
52715+ if (nls_map && nls_map != (const void *) -1)
52716 unload_nls(nls_map);
52717 if (!strcmp(args[0].from, "none"))
52718 nls_map = NULL;
52719@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52720
52721 jfs_inode_cachep =
52722 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52723- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52724+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52725 init_once);
52726 if (jfs_inode_cachep == NULL)
52727 return -ENOMEM;
52728diff --git a/fs/libfs.c b/fs/libfs.c
52729index 916da8c..1588998 100644
52730--- a/fs/libfs.c
52731+++ b/fs/libfs.c
52732@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52733
52734 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52735 struct dentry *next;
52736+ char d_name[sizeof(next->d_iname)];
52737+ const unsigned char *name;
52738+
52739 next = list_entry(p, struct dentry, d_u.d_child);
52740 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52741 if (!simple_positive(next)) {
52742@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52743
52744 spin_unlock(&next->d_lock);
52745 spin_unlock(&dentry->d_lock);
52746- if (filldir(dirent, next->d_name.name,
52747+ name = next->d_name.name;
52748+ if (name == next->d_iname) {
52749+ memcpy(d_name, name, next->d_name.len);
52750+ name = d_name;
52751+ }
52752+ if (filldir(dirent, name,
52753 next->d_name.len, filp->f_pos,
52754 next->d_inode->i_ino,
52755 dt_type(next->d_inode)) < 0)
52756diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52757index 52e5120..808936e 100644
52758--- a/fs/lockd/clntproc.c
52759+++ b/fs/lockd/clntproc.c
52760@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52761 /*
52762 * Cookie counter for NLM requests
52763 */
52764-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52765+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52766
52767 void nlmclnt_next_cookie(struct nlm_cookie *c)
52768 {
52769- u32 cookie = atomic_inc_return(&nlm_cookie);
52770+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52771
52772 memcpy(c->data, &cookie, 4);
52773 c->len=4;
52774diff --git a/fs/locks.c b/fs/locks.c
52775index a94e331..060bce3 100644
52776--- a/fs/locks.c
52777+++ b/fs/locks.c
52778@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52779 return;
52780
52781 if (filp->f_op && filp->f_op->flock) {
52782- struct file_lock fl = {
52783+ struct file_lock flock = {
52784 .fl_pid = current->tgid,
52785 .fl_file = filp,
52786 .fl_flags = FL_FLOCK,
52787 .fl_type = F_UNLCK,
52788 .fl_end = OFFSET_MAX,
52789 };
52790- filp->f_op->flock(filp, F_SETLKW, &fl);
52791- if (fl.fl_ops && fl.fl_ops->fl_release_private)
52792- fl.fl_ops->fl_release_private(&fl);
52793+ filp->f_op->flock(filp, F_SETLKW, &flock);
52794+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
52795+ flock.fl_ops->fl_release_private(&flock);
52796 }
52797
52798 lock_flocks();
52799diff --git a/fs/namei.c b/fs/namei.c
52800index ec97aef..e67718d 100644
52801--- a/fs/namei.c
52802+++ b/fs/namei.c
52803@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52804 if (ret != -EACCES)
52805 return ret;
52806
52807+#ifdef CONFIG_GRKERNSEC
52808+ /* we'll block if we have to log due to a denied capability use */
52809+ if (mask & MAY_NOT_BLOCK)
52810+ return -ECHILD;
52811+#endif
52812+
52813 if (S_ISDIR(inode->i_mode)) {
52814 /* DACs are overridable for directories */
52815- if (inode_capable(inode, CAP_DAC_OVERRIDE))
52816- return 0;
52817 if (!(mask & MAY_WRITE))
52818- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52819+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52820+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52821 return 0;
52822+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
52823+ return 0;
52824 return -EACCES;
52825 }
52826 /*
52827+ * Searching includes executable on directories, else just read.
52828+ */
52829+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52830+ if (mask == MAY_READ)
52831+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52832+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52833+ return 0;
52834+
52835+ /*
52836 * Read/write DACs are always overridable.
52837 * Executable DACs are overridable when there is
52838 * at least one exec bit set.
52839@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52840 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52841 return 0;
52842
52843- /*
52844- * Searching includes executable on directories, else just read.
52845- */
52846- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52847- if (mask == MAY_READ)
52848- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52849- return 0;
52850-
52851 return -EACCES;
52852 }
52853
52854@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52855 {
52856 struct dentry *dentry = link->dentry;
52857 int error;
52858- char *s;
52859+ const char *s;
52860
52861 BUG_ON(nd->flags & LOOKUP_RCU);
52862
52863@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52864 if (error)
52865 goto out_put_nd_path;
52866
52867+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
52868+ dentry->d_inode, dentry, nd->path.mnt)) {
52869+ error = -EACCES;
52870+ goto out_put_nd_path;
52871+ }
52872+
52873 nd->last_type = LAST_BIND;
52874 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52875 error = PTR_ERR(*p);
52876@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52877 break;
52878 res = walk_component(nd, path, &nd->last,
52879 nd->last_type, LOOKUP_FOLLOW);
52880+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52881+ res = -EACCES;
52882 put_link(nd, &link, cookie);
52883 } while (res > 0);
52884
52885@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
52886 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52887 {
52888 unsigned long a, b, adata, bdata, mask, hash, len;
52889- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52890+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52891
52892 hash = a = 0;
52893 len = -sizeof(unsigned long);
52894@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
52895 if (err)
52896 break;
52897 err = lookup_last(nd, &path);
52898+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
52899+ err = -EACCES;
52900 put_link(nd, &link, cookie);
52901 }
52902 }
52903@@ -1984,6 +2002,13 @@ static int path_lookupat(int dfd, const char *name,
52904 if (!err)
52905 err = complete_walk(nd);
52906
52907+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
52908+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52909+ path_put(&nd->path);
52910+ err = -ENOENT;
52911+ }
52912+ }
52913+
52914 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52915 if (!nd->inode->i_op->lookup) {
52916 path_put(&nd->path);
52917@@ -2011,8 +2036,15 @@ static int filename_lookup(int dfd, struct filename *name,
52918 retval = path_lookupat(dfd, name->name,
52919 flags | LOOKUP_REVAL, nd);
52920
52921- if (likely(!retval))
52922+ if (likely(!retval)) {
52923 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52924+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52925+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
52926+ path_put(&nd->path);
52927+ return -ENOENT;
52928+ }
52929+ }
52930+ }
52931 return retval;
52932 }
52933
52934@@ -2390,6 +2422,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52935 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52936 return -EPERM;
52937
52938+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52939+ return -EPERM;
52940+ if (gr_handle_rawio(inode))
52941+ return -EPERM;
52942+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52943+ return -EACCES;
52944+
52945 return 0;
52946 }
52947
52948@@ -2611,7 +2650,7 @@ looked_up:
52949 * cleared otherwise prior to returning.
52950 */
52951 static int lookup_open(struct nameidata *nd, struct path *path,
52952- struct file *file,
52953+ struct path *link, struct file *file,
52954 const struct open_flags *op,
52955 bool got_write, int *opened)
52956 {
52957@@ -2646,6 +2685,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52958 /* Negative dentry, just create the file */
52959 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52960 umode_t mode = op->mode;
52961+
52962+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
52963+ error = -EACCES;
52964+ goto out_dput;
52965+ }
52966+
52967+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
52968+ error = -EACCES;
52969+ goto out_dput;
52970+ }
52971+
52972 if (!IS_POSIXACL(dir->d_inode))
52973 mode &= ~current_umask();
52974 /*
52975@@ -2667,6 +2717,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52976 nd->flags & LOOKUP_EXCL);
52977 if (error)
52978 goto out_dput;
52979+ else
52980+ gr_handle_create(dentry, nd->path.mnt);
52981 }
52982 out_no_open:
52983 path->dentry = dentry;
52984@@ -2681,7 +2733,7 @@ out_dput:
52985 /*
52986 * Handle the last step of open()
52987 */
52988-static int do_last(struct nameidata *nd, struct path *path,
52989+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
52990 struct file *file, const struct open_flags *op,
52991 int *opened, struct filename *name)
52992 {
52993@@ -2710,16 +2762,32 @@ static int do_last(struct nameidata *nd, struct path *path,
52994 error = complete_walk(nd);
52995 if (error)
52996 return error;
52997+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52998+ error = -ENOENT;
52999+ goto out;
53000+ }
53001 audit_inode(name, nd->path.dentry, 0);
53002 if (open_flag & O_CREAT) {
53003 error = -EISDIR;
53004 goto out;
53005 }
53006+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53007+ error = -EACCES;
53008+ goto out;
53009+ }
53010 goto finish_open;
53011 case LAST_BIND:
53012 error = complete_walk(nd);
53013 if (error)
53014 return error;
53015+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53016+ error = -ENOENT;
53017+ goto out;
53018+ }
53019+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53020+ error = -EACCES;
53021+ goto out;
53022+ }
53023 audit_inode(name, dir, 0);
53024 goto finish_open;
53025 }
53026@@ -2768,7 +2836,7 @@ retry_lookup:
53027 */
53028 }
53029 mutex_lock(&dir->d_inode->i_mutex);
53030- error = lookup_open(nd, path, file, op, got_write, opened);
53031+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53032 mutex_unlock(&dir->d_inode->i_mutex);
53033
53034 if (error <= 0) {
53035@@ -2792,11 +2860,28 @@ retry_lookup:
53036 goto finish_open_created;
53037 }
53038
53039+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53040+ error = -ENOENT;
53041+ goto exit_dput;
53042+ }
53043+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53044+ error = -EACCES;
53045+ goto exit_dput;
53046+ }
53047+
53048 /*
53049 * create/update audit record if it already exists.
53050 */
53051- if (path->dentry->d_inode)
53052+ if (path->dentry->d_inode) {
53053+ /* only check if O_CREAT is specified, all other checks need to go
53054+ into may_open */
53055+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53056+ error = -EACCES;
53057+ goto exit_dput;
53058+ }
53059+
53060 audit_inode(name, path->dentry, 0);
53061+ }
53062
53063 /*
53064 * If atomic_open() acquired write access it is dropped now due to
53065@@ -2837,6 +2922,11 @@ finish_lookup:
53066 }
53067 }
53068 BUG_ON(inode != path->dentry->d_inode);
53069+ /* if we're resolving a symlink to another symlink */
53070+ if (link && gr_handle_symlink_owner(link, inode)) {
53071+ error = -EACCES;
53072+ goto out;
53073+ }
53074 return 1;
53075 }
53076
53077@@ -2846,7 +2936,6 @@ finish_lookup:
53078 save_parent.dentry = nd->path.dentry;
53079 save_parent.mnt = mntget(path->mnt);
53080 nd->path.dentry = path->dentry;
53081-
53082 }
53083 nd->inode = inode;
53084 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53085@@ -2855,6 +2944,16 @@ finish_lookup:
53086 path_put(&save_parent);
53087 return error;
53088 }
53089+
53090+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53091+ error = -ENOENT;
53092+ goto out;
53093+ }
53094+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53095+ error = -EACCES;
53096+ goto out;
53097+ }
53098+
53099 error = -EISDIR;
53100 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53101 goto out;
53102@@ -2953,7 +3052,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53103 if (unlikely(error))
53104 goto out;
53105
53106- error = do_last(nd, &path, file, op, &opened, pathname);
53107+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53108 while (unlikely(error > 0)) { /* trailing symlink */
53109 struct path link = path;
53110 void *cookie;
53111@@ -2971,7 +3070,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53112 error = follow_link(&link, nd, &cookie);
53113 if (unlikely(error))
53114 break;
53115- error = do_last(nd, &path, file, op, &opened, pathname);
53116+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53117 put_link(nd, &link, cookie);
53118 }
53119 out:
53120@@ -3071,8 +3170,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53121 goto unlock;
53122
53123 error = -EEXIST;
53124- if (dentry->d_inode)
53125+ if (dentry->d_inode) {
53126+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53127+ error = -ENOENT;
53128+ }
53129 goto fail;
53130+ }
53131 /*
53132 * Special case - lookup gave negative, but... we had foo/bar/
53133 * From the vfs_mknod() POV we just have a negative dentry -
53134@@ -3124,6 +3227,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53135 }
53136 EXPORT_SYMBOL(user_path_create);
53137
53138+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53139+{
53140+ struct filename *tmp = getname(pathname);
53141+ struct dentry *res;
53142+ if (IS_ERR(tmp))
53143+ return ERR_CAST(tmp);
53144+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53145+ if (IS_ERR(res))
53146+ putname(tmp);
53147+ else
53148+ *to = tmp;
53149+ return res;
53150+}
53151+
53152 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53153 {
53154 int error = may_create(dir, dentry);
53155@@ -3186,6 +3303,17 @@ retry:
53156
53157 if (!IS_POSIXACL(path.dentry->d_inode))
53158 mode &= ~current_umask();
53159+
53160+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53161+ error = -EPERM;
53162+ goto out;
53163+ }
53164+
53165+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53166+ error = -EACCES;
53167+ goto out;
53168+ }
53169+
53170 error = security_path_mknod(&path, dentry, mode, dev);
53171 if (error)
53172 goto out;
53173@@ -3202,6 +3330,8 @@ retry:
53174 break;
53175 }
53176 out:
53177+ if (!error)
53178+ gr_handle_create(dentry, path.mnt);
53179 done_path_create(&path, dentry);
53180 if (retry_estale(error, lookup_flags)) {
53181 lookup_flags |= LOOKUP_REVAL;
53182@@ -3254,9 +3384,16 @@ retry:
53183
53184 if (!IS_POSIXACL(path.dentry->d_inode))
53185 mode &= ~current_umask();
53186+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53187+ error = -EACCES;
53188+ goto out;
53189+ }
53190 error = security_path_mkdir(&path, dentry, mode);
53191 if (!error)
53192 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53193+ if (!error)
53194+ gr_handle_create(dentry, path.mnt);
53195+out:
53196 done_path_create(&path, dentry);
53197 if (retry_estale(error, lookup_flags)) {
53198 lookup_flags |= LOOKUP_REVAL;
53199@@ -3337,6 +3474,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53200 struct filename *name;
53201 struct dentry *dentry;
53202 struct nameidata nd;
53203+ ino_t saved_ino = 0;
53204+ dev_t saved_dev = 0;
53205 unsigned int lookup_flags = 0;
53206 retry:
53207 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53208@@ -3369,10 +3508,21 @@ retry:
53209 error = -ENOENT;
53210 goto exit3;
53211 }
53212+
53213+ saved_ino = dentry->d_inode->i_ino;
53214+ saved_dev = gr_get_dev_from_dentry(dentry);
53215+
53216+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53217+ error = -EACCES;
53218+ goto exit3;
53219+ }
53220+
53221 error = security_path_rmdir(&nd.path, dentry);
53222 if (error)
53223 goto exit3;
53224 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53225+ if (!error && (saved_dev || saved_ino))
53226+ gr_handle_delete(saved_ino, saved_dev);
53227 exit3:
53228 dput(dentry);
53229 exit2:
53230@@ -3438,6 +3588,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53231 struct dentry *dentry;
53232 struct nameidata nd;
53233 struct inode *inode = NULL;
53234+ ino_t saved_ino = 0;
53235+ dev_t saved_dev = 0;
53236 unsigned int lookup_flags = 0;
53237 retry:
53238 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53239@@ -3464,10 +3616,22 @@ retry:
53240 if (!inode)
53241 goto slashes;
53242 ihold(inode);
53243+
53244+ if (inode->i_nlink <= 1) {
53245+ saved_ino = inode->i_ino;
53246+ saved_dev = gr_get_dev_from_dentry(dentry);
53247+ }
53248+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53249+ error = -EACCES;
53250+ goto exit2;
53251+ }
53252+
53253 error = security_path_unlink(&nd.path, dentry);
53254 if (error)
53255 goto exit2;
53256 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53257+ if (!error && (saved_ino || saved_dev))
53258+ gr_handle_delete(saved_ino, saved_dev);
53259 exit2:
53260 dput(dentry);
53261 }
53262@@ -3545,9 +3709,17 @@ retry:
53263 if (IS_ERR(dentry))
53264 goto out_putname;
53265
53266+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53267+ error = -EACCES;
53268+ goto out;
53269+ }
53270+
53271 error = security_path_symlink(&path, dentry, from->name);
53272 if (!error)
53273 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
53274+ if (!error)
53275+ gr_handle_create(dentry, path.mnt);
53276+out:
53277 done_path_create(&path, dentry);
53278 if (retry_estale(error, lookup_flags)) {
53279 lookup_flags |= LOOKUP_REVAL;
53280@@ -3621,6 +3793,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53281 {
53282 struct dentry *new_dentry;
53283 struct path old_path, new_path;
53284+ struct filename *to = NULL;
53285 int how = 0;
53286 int error;
53287
53288@@ -3644,7 +3817,7 @@ retry:
53289 if (error)
53290 return error;
53291
53292- new_dentry = user_path_create(newdfd, newname, &new_path,
53293+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53294 (how & LOOKUP_REVAL));
53295 error = PTR_ERR(new_dentry);
53296 if (IS_ERR(new_dentry))
53297@@ -3656,11 +3829,28 @@ retry:
53298 error = may_linkat(&old_path);
53299 if (unlikely(error))
53300 goto out_dput;
53301+
53302+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
53303+ old_path.dentry->d_inode,
53304+ old_path.dentry->d_inode->i_mode, to)) {
53305+ error = -EACCES;
53306+ goto out_dput;
53307+ }
53308+
53309+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
53310+ old_path.dentry, old_path.mnt, to)) {
53311+ error = -EACCES;
53312+ goto out_dput;
53313+ }
53314+
53315 error = security_path_link(old_path.dentry, &new_path, new_dentry);
53316 if (error)
53317 goto out_dput;
53318 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
53319+ if (!error)
53320+ gr_handle_create(new_dentry, new_path.mnt);
53321 out_dput:
53322+ putname(to);
53323 done_path_create(&new_path, new_dentry);
53324 if (retry_estale(error, how)) {
53325 how |= LOOKUP_REVAL;
53326@@ -3906,12 +4096,21 @@ retry:
53327 if (new_dentry == trap)
53328 goto exit5;
53329
53330+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
53331+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
53332+ to);
53333+ if (error)
53334+ goto exit5;
53335+
53336 error = security_path_rename(&oldnd.path, old_dentry,
53337 &newnd.path, new_dentry);
53338 if (error)
53339 goto exit5;
53340 error = vfs_rename(old_dir->d_inode, old_dentry,
53341 new_dir->d_inode, new_dentry);
53342+ if (!error)
53343+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
53344+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
53345 exit5:
53346 dput(new_dentry);
53347 exit4:
53348@@ -3943,6 +4142,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
53349
53350 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
53351 {
53352+ char tmpbuf[64];
53353+ const char *newlink;
53354 int len;
53355
53356 len = PTR_ERR(link);
53357@@ -3952,7 +4153,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
53358 len = strlen(link);
53359 if (len > (unsigned) buflen)
53360 len = buflen;
53361- if (copy_to_user(buffer, link, len))
53362+
53363+ if (len < sizeof(tmpbuf)) {
53364+ memcpy(tmpbuf, link, len);
53365+ newlink = tmpbuf;
53366+ } else
53367+ newlink = link;
53368+
53369+ if (copy_to_user(buffer, newlink, len))
53370 len = -EFAULT;
53371 out:
53372 return len;
53373diff --git a/fs/namespace.c b/fs/namespace.c
53374index a51054f..f9b53e5 100644
53375--- a/fs/namespace.c
53376+++ b/fs/namespace.c
53377@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
53378 if (!(sb->s_flags & MS_RDONLY))
53379 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53380 up_write(&sb->s_umount);
53381+
53382+ gr_log_remount(mnt->mnt_devname, retval);
53383+
53384 return retval;
53385 }
53386
53387@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
53388 br_write_unlock(&vfsmount_lock);
53389 up_write(&namespace_sem);
53390 release_mounts(&umount_list);
53391+
53392+ gr_log_unmount(mnt->mnt_devname, retval);
53393+
53394 return retval;
53395 }
53396
53397@@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53398 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53399 MS_STRICTATIME);
53400
53401+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53402+ retval = -EPERM;
53403+ goto dput_out;
53404+ }
53405+
53406+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53407+ retval = -EPERM;
53408+ goto dput_out;
53409+ }
53410+
53411 if (flags & MS_REMOUNT)
53412 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53413 data_page);
53414@@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53415 dev_name, data_page);
53416 dput_out:
53417 path_put(&path);
53418+
53419+ gr_log_mount(dev_name, dir_name, retval);
53420+
53421 return retval;
53422 }
53423
53424@@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53425 if (error)
53426 goto out2;
53427
53428+ if (gr_handle_chroot_pivot()) {
53429+ error = -EPERM;
53430+ goto out2;
53431+ }
53432+
53433 get_fs_root(current->fs, &root);
53434 error = lock_mount(&old);
53435 if (error)
53436@@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53437 !nsown_capable(CAP_SYS_ADMIN))
53438 return -EPERM;
53439
53440- if (fs->users != 1)
53441+ if (atomic_read(&fs->users) != 1)
53442 return -EINVAL;
53443
53444 get_mnt_ns(mnt_ns);
53445diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53446index 59461c9..b17c57e 100644
53447--- a/fs/nfs/callback_xdr.c
53448+++ b/fs/nfs/callback_xdr.c
53449@@ -51,7 +51,7 @@ struct callback_op {
53450 callback_decode_arg_t decode_args;
53451 callback_encode_res_t encode_res;
53452 long res_maxsize;
53453-};
53454+} __do_const;
53455
53456 static struct callback_op callback_ops[];
53457
53458diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53459index ebeb94c..ff35337 100644
53460--- a/fs/nfs/inode.c
53461+++ b/fs/nfs/inode.c
53462@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53463 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53464 }
53465
53466-static atomic_long_t nfs_attr_generation_counter;
53467+static atomic_long_unchecked_t nfs_attr_generation_counter;
53468
53469 static unsigned long nfs_read_attr_generation_counter(void)
53470 {
53471- return atomic_long_read(&nfs_attr_generation_counter);
53472+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53473 }
53474
53475 unsigned long nfs_inc_attr_generation_counter(void)
53476 {
53477- return atomic_long_inc_return(&nfs_attr_generation_counter);
53478+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53479 }
53480
53481 void nfs_fattr_init(struct nfs_fattr *fattr)
53482diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53483index 9d1c5db..1e13db8 100644
53484--- a/fs/nfsd/nfs4proc.c
53485+++ b/fs/nfsd/nfs4proc.c
53486@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53487 nfsd4op_rsize op_rsize_bop;
53488 stateid_getter op_get_currentstateid;
53489 stateid_setter op_set_currentstateid;
53490-};
53491+} __do_const;
53492
53493 static struct nfsd4_operation nfsd4_ops[];
53494
53495diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53496index 0dc1158..ccf0338 100644
53497--- a/fs/nfsd/nfs4xdr.c
53498+++ b/fs/nfsd/nfs4xdr.c
53499@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53500
53501 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53502
53503-static nfsd4_dec nfsd4_dec_ops[] = {
53504+static const nfsd4_dec nfsd4_dec_ops[] = {
53505 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53506 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53507 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53508@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53509 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53510 };
53511
53512-static nfsd4_dec nfsd41_dec_ops[] = {
53513+static const nfsd4_dec nfsd41_dec_ops[] = {
53514 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53515 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53516 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53517@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53518 };
53519
53520 struct nfsd4_minorversion_ops {
53521- nfsd4_dec *decoders;
53522+ const nfsd4_dec *decoders;
53523 int nops;
53524 };
53525
53526diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53527index d586117..143d568 100644
53528--- a/fs/nfsd/vfs.c
53529+++ b/fs/nfsd/vfs.c
53530@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53531 } else {
53532 oldfs = get_fs();
53533 set_fs(KERNEL_DS);
53534- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53535+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53536 set_fs(oldfs);
53537 }
53538
53539@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53540
53541 /* Write the data. */
53542 oldfs = get_fs(); set_fs(KERNEL_DS);
53543- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53544+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53545 set_fs(oldfs);
53546 if (host_err < 0)
53547 goto out_nfserr;
53548@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53549 */
53550
53551 oldfs = get_fs(); set_fs(KERNEL_DS);
53552- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53553+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53554 set_fs(oldfs);
53555
53556 if (host_err < 0)
53557diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53558index fea6bd5..8ee9d81 100644
53559--- a/fs/nls/nls_base.c
53560+++ b/fs/nls/nls_base.c
53561@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53562
53563 int register_nls(struct nls_table * nls)
53564 {
53565- struct nls_table ** tmp = &tables;
53566+ struct nls_table *tmp = tables;
53567
53568 if (nls->next)
53569 return -EBUSY;
53570
53571 spin_lock(&nls_lock);
53572- while (*tmp) {
53573- if (nls == *tmp) {
53574+ while (tmp) {
53575+ if (nls == tmp) {
53576 spin_unlock(&nls_lock);
53577 return -EBUSY;
53578 }
53579- tmp = &(*tmp)->next;
53580+ tmp = tmp->next;
53581 }
53582- nls->next = tables;
53583+ pax_open_kernel();
53584+ *(struct nls_table **)&nls->next = tables;
53585+ pax_close_kernel();
53586 tables = nls;
53587 spin_unlock(&nls_lock);
53588 return 0;
53589@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53590
53591 int unregister_nls(struct nls_table * nls)
53592 {
53593- struct nls_table ** tmp = &tables;
53594+ struct nls_table * const * tmp = &tables;
53595
53596 spin_lock(&nls_lock);
53597 while (*tmp) {
53598 if (nls == *tmp) {
53599- *tmp = nls->next;
53600+ pax_open_kernel();
53601+ *(struct nls_table **)tmp = nls->next;
53602+ pax_close_kernel();
53603 spin_unlock(&nls_lock);
53604 return 0;
53605 }
53606diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53607index 7424929..35f6be5 100644
53608--- a/fs/nls/nls_euc-jp.c
53609+++ b/fs/nls/nls_euc-jp.c
53610@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53611 p_nls = load_nls("cp932");
53612
53613 if (p_nls) {
53614- table.charset2upper = p_nls->charset2upper;
53615- table.charset2lower = p_nls->charset2lower;
53616+ pax_open_kernel();
53617+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53618+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53619+ pax_close_kernel();
53620 return register_nls(&table);
53621 }
53622
53623diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53624index e7bc1d7..06bd4bb 100644
53625--- a/fs/nls/nls_koi8-ru.c
53626+++ b/fs/nls/nls_koi8-ru.c
53627@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53628 p_nls = load_nls("koi8-u");
53629
53630 if (p_nls) {
53631- table.charset2upper = p_nls->charset2upper;
53632- table.charset2lower = p_nls->charset2lower;
53633+ pax_open_kernel();
53634+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53635+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53636+ pax_close_kernel();
53637 return register_nls(&table);
53638 }
53639
53640diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53641index 9ff4a5e..deb1f0f 100644
53642--- a/fs/notify/fanotify/fanotify_user.c
53643+++ b/fs/notify/fanotify/fanotify_user.c
53644@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53645
53646 fd = fanotify_event_metadata.fd;
53647 ret = -EFAULT;
53648- if (copy_to_user(buf, &fanotify_event_metadata,
53649- fanotify_event_metadata.event_len))
53650+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53651+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53652 goto out_close_fd;
53653
53654 ret = prepare_for_access_response(group, event, fd);
53655diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53656index 7b51b05..5ea5ef6 100644
53657--- a/fs/notify/notification.c
53658+++ b/fs/notify/notification.c
53659@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53660 * get set to 0 so it will never get 'freed'
53661 */
53662 static struct fsnotify_event *q_overflow_event;
53663-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53664+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53665
53666 /**
53667 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53668@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53669 */
53670 u32 fsnotify_get_cookie(void)
53671 {
53672- return atomic_inc_return(&fsnotify_sync_cookie);
53673+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53674 }
53675 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53676
53677diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53678index 99e3610..02c1068 100644
53679--- a/fs/ntfs/dir.c
53680+++ b/fs/ntfs/dir.c
53681@@ -1329,7 +1329,7 @@ find_next_index_buffer:
53682 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53683 ~(s64)(ndir->itype.index.block_size - 1)));
53684 /* Bounds checks. */
53685- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53686+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53687 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53688 "inode 0x%lx or driver bug.", vdir->i_ino);
53689 goto err_out;
53690diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53691index 5b2d4f0..c6de396 100644
53692--- a/fs/ntfs/file.c
53693+++ b/fs/ntfs/file.c
53694@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53695 #endif /* NTFS_RW */
53696 };
53697
53698-const struct file_operations ntfs_empty_file_ops = {};
53699+const struct file_operations ntfs_empty_file_ops __read_only;
53700
53701-const struct inode_operations ntfs_empty_inode_ops = {};
53702+const struct inode_operations ntfs_empty_inode_ops __read_only;
53703diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53704index a9f78c7..ed8a381 100644
53705--- a/fs/ocfs2/localalloc.c
53706+++ b/fs/ocfs2/localalloc.c
53707@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53708 goto bail;
53709 }
53710
53711- atomic_inc(&osb->alloc_stats.moves);
53712+ atomic_inc_unchecked(&osb->alloc_stats.moves);
53713
53714 bail:
53715 if (handle)
53716diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53717index d355e6e..578d905 100644
53718--- a/fs/ocfs2/ocfs2.h
53719+++ b/fs/ocfs2/ocfs2.h
53720@@ -235,11 +235,11 @@ enum ocfs2_vol_state
53721
53722 struct ocfs2_alloc_stats
53723 {
53724- atomic_t moves;
53725- atomic_t local_data;
53726- atomic_t bitmap_data;
53727- atomic_t bg_allocs;
53728- atomic_t bg_extends;
53729+ atomic_unchecked_t moves;
53730+ atomic_unchecked_t local_data;
53731+ atomic_unchecked_t bitmap_data;
53732+ atomic_unchecked_t bg_allocs;
53733+ atomic_unchecked_t bg_extends;
53734 };
53735
53736 enum ocfs2_local_alloc_state
53737diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53738index b7e74b5..19c6536 100644
53739--- a/fs/ocfs2/suballoc.c
53740+++ b/fs/ocfs2/suballoc.c
53741@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53742 mlog_errno(status);
53743 goto bail;
53744 }
53745- atomic_inc(&osb->alloc_stats.bg_extends);
53746+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53747
53748 /* You should never ask for this much metadata */
53749 BUG_ON(bits_wanted >
53750@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53751 mlog_errno(status);
53752 goto bail;
53753 }
53754- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53755+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53756
53757 *suballoc_loc = res.sr_bg_blkno;
53758 *suballoc_bit_start = res.sr_bit_offset;
53759@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53760 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53761 res->sr_bits);
53762
53763- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53764+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53765
53766 BUG_ON(res->sr_bits != 1);
53767
53768@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53769 mlog_errno(status);
53770 goto bail;
53771 }
53772- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53773+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53774
53775 BUG_ON(res.sr_bits != 1);
53776
53777@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53778 cluster_start,
53779 num_clusters);
53780 if (!status)
53781- atomic_inc(&osb->alloc_stats.local_data);
53782+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
53783 } else {
53784 if (min_clusters > (osb->bitmap_cpg - 1)) {
53785 /* The only paths asking for contiguousness
53786@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53787 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53788 res.sr_bg_blkno,
53789 res.sr_bit_offset);
53790- atomic_inc(&osb->alloc_stats.bitmap_data);
53791+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53792 *num_clusters = res.sr_bits;
53793 }
53794 }
53795diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53796index 0e91ec2..f4b3fc6 100644
53797--- a/fs/ocfs2/super.c
53798+++ b/fs/ocfs2/super.c
53799@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53800 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53801 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53802 "Stats",
53803- atomic_read(&osb->alloc_stats.bitmap_data),
53804- atomic_read(&osb->alloc_stats.local_data),
53805- atomic_read(&osb->alloc_stats.bg_allocs),
53806- atomic_read(&osb->alloc_stats.moves),
53807- atomic_read(&osb->alloc_stats.bg_extends));
53808+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53809+ atomic_read_unchecked(&osb->alloc_stats.local_data),
53810+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53811+ atomic_read_unchecked(&osb->alloc_stats.moves),
53812+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53813
53814 out += snprintf(buf + out, len - out,
53815 "%10s => State: %u Descriptor: %llu Size: %u bits "
53816@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53817 spin_lock_init(&osb->osb_xattr_lock);
53818 ocfs2_init_steal_slots(osb);
53819
53820- atomic_set(&osb->alloc_stats.moves, 0);
53821- atomic_set(&osb->alloc_stats.local_data, 0);
53822- atomic_set(&osb->alloc_stats.bitmap_data, 0);
53823- atomic_set(&osb->alloc_stats.bg_allocs, 0);
53824- atomic_set(&osb->alloc_stats.bg_extends, 0);
53825+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53826+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53827+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53828+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53829+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53830
53831 /* Copy the blockcheck stats from the superblock probe */
53832 osb->osb_ecc_stats = *stats;
53833diff --git a/fs/open.c b/fs/open.c
53834index 9b33c0c..2ffcca2 100644
53835--- a/fs/open.c
53836+++ b/fs/open.c
53837@@ -31,6 +31,8 @@
53838 #include <linux/ima.h>
53839 #include <linux/dnotify.h>
53840
53841+#define CREATE_TRACE_POINTS
53842+#include <trace/events/fs.h>
53843 #include "internal.h"
53844
53845 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53846@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53847 error = locks_verify_truncate(inode, NULL, length);
53848 if (!error)
53849 error = security_path_truncate(path);
53850+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53851+ error = -EACCES;
53852 if (!error)
53853 error = do_truncate(path->dentry, length, 0, NULL);
53854
53855@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53856 error = locks_verify_truncate(inode, f.file, length);
53857 if (!error)
53858 error = security_path_truncate(&f.file->f_path);
53859+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53860+ error = -EACCES;
53861 if (!error)
53862 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53863 sb_end_write(inode->i_sb);
53864@@ -373,6 +379,9 @@ retry:
53865 if (__mnt_is_readonly(path.mnt))
53866 res = -EROFS;
53867
53868+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53869+ res = -EACCES;
53870+
53871 out_path_release:
53872 path_put(&path);
53873 if (retry_estale(res, lookup_flags)) {
53874@@ -404,6 +413,8 @@ retry:
53875 if (error)
53876 goto dput_and_out;
53877
53878+ gr_log_chdir(path.dentry, path.mnt);
53879+
53880 set_fs_pwd(current->fs, &path);
53881
53882 dput_and_out:
53883@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53884 goto out_putf;
53885
53886 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53887+
53888+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53889+ error = -EPERM;
53890+
53891+ if (!error)
53892+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53893+
53894 if (!error)
53895 set_fs_pwd(current->fs, &f.file->f_path);
53896 out_putf:
53897@@ -462,7 +480,13 @@ retry:
53898 if (error)
53899 goto dput_and_out;
53900
53901+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53902+ goto dput_and_out;
53903+
53904 set_fs_root(current->fs, &path);
53905+
53906+ gr_handle_chroot_chdir(&path);
53907+
53908 error = 0;
53909 dput_and_out:
53910 path_put(&path);
53911@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53912 if (error)
53913 return error;
53914 mutex_lock(&inode->i_mutex);
53915+
53916+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53917+ error = -EACCES;
53918+ goto out_unlock;
53919+ }
53920+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53921+ error = -EACCES;
53922+ goto out_unlock;
53923+ }
53924+
53925 error = security_path_chmod(path, mode);
53926 if (error)
53927 goto out_unlock;
53928@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53929 uid = make_kuid(current_user_ns(), user);
53930 gid = make_kgid(current_user_ns(), group);
53931
53932+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
53933+ return -EACCES;
53934+
53935 newattrs.ia_valid = ATTR_CTIME;
53936 if (user != (uid_t) -1) {
53937 if (!uid_valid(uid))
53938@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53939 } else {
53940 fsnotify_open(f);
53941 fd_install(fd, f);
53942+ trace_do_sys_open(tmp->name, flags, mode);
53943 }
53944 }
53945 putname(tmp);
53946diff --git a/fs/pipe.c b/fs/pipe.c
53947index 8e2e73f..1ef1048 100644
53948--- a/fs/pipe.c
53949+++ b/fs/pipe.c
53950@@ -438,9 +438,9 @@ redo:
53951 }
53952 if (bufs) /* More to do? */
53953 continue;
53954- if (!pipe->writers)
53955+ if (!atomic_read(&pipe->writers))
53956 break;
53957- if (!pipe->waiting_writers) {
53958+ if (!atomic_read(&pipe->waiting_writers)) {
53959 /* syscall merging: Usually we must not sleep
53960 * if O_NONBLOCK is set, or if we got some data.
53961 * But if a writer sleeps in kernel space, then
53962@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
53963 mutex_lock(&inode->i_mutex);
53964 pipe = inode->i_pipe;
53965
53966- if (!pipe->readers) {
53967+ if (!atomic_read(&pipe->readers)) {
53968 send_sig(SIGPIPE, current, 0);
53969 ret = -EPIPE;
53970 goto out;
53971@@ -553,7 +553,7 @@ redo1:
53972 for (;;) {
53973 int bufs;
53974
53975- if (!pipe->readers) {
53976+ if (!atomic_read(&pipe->readers)) {
53977 send_sig(SIGPIPE, current, 0);
53978 if (!ret)
53979 ret = -EPIPE;
53980@@ -644,9 +644,9 @@ redo2:
53981 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
53982 do_wakeup = 0;
53983 }
53984- pipe->waiting_writers++;
53985+ atomic_inc(&pipe->waiting_writers);
53986 pipe_wait(pipe);
53987- pipe->waiting_writers--;
53988+ atomic_dec(&pipe->waiting_writers);
53989 }
53990 out:
53991 mutex_unlock(&inode->i_mutex);
53992@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53993 mask = 0;
53994 if (filp->f_mode & FMODE_READ) {
53995 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
53996- if (!pipe->writers && filp->f_version != pipe->w_counter)
53997+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
53998 mask |= POLLHUP;
53999 }
54000
54001@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54002 * Most Unices do not set POLLERR for FIFOs but on Linux they
54003 * behave exactly like pipes for poll().
54004 */
54005- if (!pipe->readers)
54006+ if (!atomic_read(&pipe->readers))
54007 mask |= POLLERR;
54008 }
54009
54010@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54011
54012 mutex_lock(&inode->i_mutex);
54013 pipe = inode->i_pipe;
54014- pipe->readers -= decr;
54015- pipe->writers -= decw;
54016+ atomic_sub(decr, &pipe->readers);
54017+ atomic_sub(decw, &pipe->writers);
54018
54019- if (!pipe->readers && !pipe->writers) {
54020+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54021 free_pipe_info(inode);
54022 } else {
54023 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54024@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54025
54026 if (inode->i_pipe) {
54027 ret = 0;
54028- inode->i_pipe->readers++;
54029+ atomic_inc(&inode->i_pipe->readers);
54030 }
54031
54032 mutex_unlock(&inode->i_mutex);
54033@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54034
54035 if (inode->i_pipe) {
54036 ret = 0;
54037- inode->i_pipe->writers++;
54038+ atomic_inc(&inode->i_pipe->writers);
54039 }
54040
54041 mutex_unlock(&inode->i_mutex);
54042@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54043 if (inode->i_pipe) {
54044 ret = 0;
54045 if (filp->f_mode & FMODE_READ)
54046- inode->i_pipe->readers++;
54047+ atomic_inc(&inode->i_pipe->readers);
54048 if (filp->f_mode & FMODE_WRITE)
54049- inode->i_pipe->writers++;
54050+ atomic_inc(&inode->i_pipe->writers);
54051 }
54052
54053 mutex_unlock(&inode->i_mutex);
54054@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54055 inode->i_pipe = NULL;
54056 }
54057
54058-static struct vfsmount *pipe_mnt __read_mostly;
54059+struct vfsmount *pipe_mnt __read_mostly;
54060
54061 /*
54062 * pipefs_dname() is called from d_path().
54063@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54064 goto fail_iput;
54065 inode->i_pipe = pipe;
54066
54067- pipe->readers = pipe->writers = 1;
54068+ atomic_set(&pipe->readers, 1);
54069+ atomic_set(&pipe->writers, 1);
54070 inode->i_fop = &rdwr_pipefifo_fops;
54071
54072 /*
54073diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54074index 15af622..0e9f4467 100644
54075--- a/fs/proc/Kconfig
54076+++ b/fs/proc/Kconfig
54077@@ -30,12 +30,12 @@ config PROC_FS
54078
54079 config PROC_KCORE
54080 bool "/proc/kcore support" if !ARM
54081- depends on PROC_FS && MMU
54082+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54083
54084 config PROC_VMCORE
54085 bool "/proc/vmcore support"
54086- depends on PROC_FS && CRASH_DUMP
54087- default y
54088+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54089+ default n
54090 help
54091 Exports the dump image of crashed kernel in ELF format.
54092
54093@@ -59,8 +59,8 @@ config PROC_SYSCTL
54094 limited in memory.
54095
54096 config PROC_PAGE_MONITOR
54097- default y
54098- depends on PROC_FS && MMU
54099+ default n
54100+ depends on PROC_FS && MMU && !GRKERNSEC
54101 bool "Enable /proc page monitoring" if EXPERT
54102 help
54103 Various /proc files exist to monitor process memory utilization:
54104diff --git a/fs/proc/array.c b/fs/proc/array.c
54105index 6a91e6f..e54dbc14 100644
54106--- a/fs/proc/array.c
54107+++ b/fs/proc/array.c
54108@@ -60,6 +60,7 @@
54109 #include <linux/tty.h>
54110 #include <linux/string.h>
54111 #include <linux/mman.h>
54112+#include <linux/grsecurity.h>
54113 #include <linux/proc_fs.h>
54114 #include <linux/ioport.h>
54115 #include <linux/uaccess.h>
54116@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54117 seq_putc(m, '\n');
54118 }
54119
54120+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54121+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54122+{
54123+ if (p->mm)
54124+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54125+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54126+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54127+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54128+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54129+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54130+ else
54131+ seq_printf(m, "PaX:\t-----\n");
54132+}
54133+#endif
54134+
54135 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54136 struct pid *pid, struct task_struct *task)
54137 {
54138@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54139 task_cpus_allowed(m, task);
54140 cpuset_task_status_allowed(m, task);
54141 task_context_switch_counts(m, task);
54142+
54143+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54144+ task_pax(m, task);
54145+#endif
54146+
54147+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54148+ task_grsec_rbac(m, task);
54149+#endif
54150+
54151 return 0;
54152 }
54153
54154+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54155+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54156+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54157+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54158+#endif
54159+
54160 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54161 struct pid *pid, struct task_struct *task, int whole)
54162 {
54163@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54164 char tcomm[sizeof(task->comm)];
54165 unsigned long flags;
54166
54167+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54168+ if (current->exec_id != m->exec_id) {
54169+ gr_log_badprocpid("stat");
54170+ return 0;
54171+ }
54172+#endif
54173+
54174 state = *get_task_state(task);
54175 vsize = eip = esp = 0;
54176 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54177@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54178 gtime = task->gtime;
54179 }
54180
54181+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54182+ if (PAX_RAND_FLAGS(mm)) {
54183+ eip = 0;
54184+ esp = 0;
54185+ wchan = 0;
54186+ }
54187+#endif
54188+#ifdef CONFIG_GRKERNSEC_HIDESYM
54189+ wchan = 0;
54190+ eip =0;
54191+ esp =0;
54192+#endif
54193+
54194 /* scale priority and nice values from timeslices to -20..20 */
54195 /* to make it look like a "normal" Unix priority/nice value */
54196 priority = task_prio(task);
54197@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54198 seq_put_decimal_ull(m, ' ', vsize);
54199 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
54200 seq_put_decimal_ull(m, ' ', rsslim);
54201+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54202+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
54203+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
54204+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
54205+#else
54206 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
54207 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
54208 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
54209+#endif
54210 seq_put_decimal_ull(m, ' ', esp);
54211 seq_put_decimal_ull(m, ' ', eip);
54212 /* The signal information here is obsolete.
54213@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54214 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
54215 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
54216
54217- if (mm && permitted) {
54218+ if (mm && permitted
54219+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54220+ && !PAX_RAND_FLAGS(mm)
54221+#endif
54222+ ) {
54223 seq_put_decimal_ull(m, ' ', mm->start_data);
54224 seq_put_decimal_ull(m, ' ', mm->end_data);
54225 seq_put_decimal_ull(m, ' ', mm->start_brk);
54226@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54227 struct pid *pid, struct task_struct *task)
54228 {
54229 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
54230- struct mm_struct *mm = get_task_mm(task);
54231+ struct mm_struct *mm;
54232
54233+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54234+ if (current->exec_id != m->exec_id) {
54235+ gr_log_badprocpid("statm");
54236+ return 0;
54237+ }
54238+#endif
54239+ mm = get_task_mm(task);
54240 if (mm) {
54241 size = task_statm(mm, &shared, &text, &data, &resident);
54242 mmput(mm);
54243@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54244 return 0;
54245 }
54246
54247+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54248+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
54249+{
54250+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
54251+}
54252+#endif
54253+
54254 #ifdef CONFIG_CHECKPOINT_RESTORE
54255 static struct pid *
54256 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
54257diff --git a/fs/proc/base.c b/fs/proc/base.c
54258index 9b43ff77..ba3e990 100644
54259--- a/fs/proc/base.c
54260+++ b/fs/proc/base.c
54261@@ -111,6 +111,14 @@ struct pid_entry {
54262 union proc_op op;
54263 };
54264
54265+struct getdents_callback {
54266+ struct linux_dirent __user * current_dir;
54267+ struct linux_dirent __user * previous;
54268+ struct file * file;
54269+ int count;
54270+ int error;
54271+};
54272+
54273 #define NOD(NAME, MODE, IOP, FOP, OP) { \
54274 .name = (NAME), \
54275 .len = sizeof(NAME) - 1, \
54276@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
54277 if (!mm->arg_end)
54278 goto out_mm; /* Shh! No looking before we're done */
54279
54280+ if (gr_acl_handle_procpidmem(task))
54281+ goto out_mm;
54282+
54283 len = mm->arg_end - mm->arg_start;
54284
54285 if (len > PAGE_SIZE)
54286@@ -235,12 +246,28 @@ out:
54287 return res;
54288 }
54289
54290+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54291+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54292+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54293+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54294+#endif
54295+
54296 static int proc_pid_auxv(struct task_struct *task, char *buffer)
54297 {
54298 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
54299 int res = PTR_ERR(mm);
54300 if (mm && !IS_ERR(mm)) {
54301 unsigned int nwords = 0;
54302+
54303+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54304+ /* allow if we're currently ptracing this task */
54305+ if (PAX_RAND_FLAGS(mm) &&
54306+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
54307+ mmput(mm);
54308+ return 0;
54309+ }
54310+#endif
54311+
54312 do {
54313 nwords += 2;
54314 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
54315@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
54316 }
54317
54318
54319-#ifdef CONFIG_KALLSYMS
54320+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54321 /*
54322 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
54323 * Returns the resolved symbol. If that fails, simply return the address.
54324@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
54325 mutex_unlock(&task->signal->cred_guard_mutex);
54326 }
54327
54328-#ifdef CONFIG_STACKTRACE
54329+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54330
54331 #define MAX_STACK_TRACE_DEPTH 64
54332
54333@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
54334 return count;
54335 }
54336
54337-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54338+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54339 static int proc_pid_syscall(struct task_struct *task, char *buffer)
54340 {
54341 long nr;
54342@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
54343 /************************************************************************/
54344
54345 /* permission checks */
54346-static int proc_fd_access_allowed(struct inode *inode)
54347+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
54348 {
54349 struct task_struct *task;
54350 int allowed = 0;
54351@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
54352 */
54353 task = get_proc_task(inode);
54354 if (task) {
54355- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54356+ if (log)
54357+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54358+ else
54359+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54360 put_task_struct(task);
54361 }
54362 return allowed;
54363@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
54364 struct task_struct *task,
54365 int hide_pid_min)
54366 {
54367+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54368+ return false;
54369+
54370+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54371+ rcu_read_lock();
54372+ {
54373+ const struct cred *tmpcred = current_cred();
54374+ const struct cred *cred = __task_cred(task);
54375+
54376+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
54377+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54378+ || in_group_p(grsec_proc_gid)
54379+#endif
54380+ ) {
54381+ rcu_read_unlock();
54382+ return true;
54383+ }
54384+ }
54385+ rcu_read_unlock();
54386+
54387+ if (!pid->hide_pid)
54388+ return false;
54389+#endif
54390+
54391 if (pid->hide_pid < hide_pid_min)
54392 return true;
54393 if (in_group_p(pid->pid_gid))
54394 return true;
54395+
54396 return ptrace_may_access(task, PTRACE_MODE_READ);
54397 }
54398
54399@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54400 put_task_struct(task);
54401
54402 if (!has_perms) {
54403+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54404+ {
54405+#else
54406 if (pid->hide_pid == 2) {
54407+#endif
54408 /*
54409 * Let's make getdents(), stat(), and open()
54410 * consistent with each other. If a process
54411@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54412 if (!task)
54413 return -ESRCH;
54414
54415+ if (gr_acl_handle_procpidmem(task)) {
54416+ put_task_struct(task);
54417+ return -EPERM;
54418+ }
54419+
54420 mm = mm_access(task, mode);
54421 put_task_struct(task);
54422
54423@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54424
54425 file->private_data = mm;
54426
54427+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54428+ file->f_version = current->exec_id;
54429+#endif
54430+
54431 return 0;
54432 }
54433
54434@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54435 ssize_t copied;
54436 char *page;
54437
54438+#ifdef CONFIG_GRKERNSEC
54439+ if (write)
54440+ return -EPERM;
54441+#endif
54442+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54443+ if (file->f_version != current->exec_id) {
54444+ gr_log_badprocpid("mem");
54445+ return 0;
54446+ }
54447+#endif
54448+
54449 if (!mm)
54450 return 0;
54451
54452@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54453 if (!mm)
54454 return 0;
54455
54456+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54457+ if (file->f_version != current->exec_id) {
54458+ gr_log_badprocpid("environ");
54459+ return 0;
54460+ }
54461+#endif
54462+
54463 page = (char *)__get_free_page(GFP_TEMPORARY);
54464 if (!page)
54465 return -ENOMEM;
54466@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54467 int error = -EACCES;
54468
54469 /* Are we allowed to snoop on the tasks file descriptors? */
54470- if (!proc_fd_access_allowed(inode))
54471+ if (!proc_fd_access_allowed(inode, 0))
54472 goto out;
54473
54474 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54475@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54476 struct path path;
54477
54478 /* Are we allowed to snoop on the tasks file descriptors? */
54479- if (!proc_fd_access_allowed(inode))
54480- goto out;
54481+ /* logging this is needed for learning on chromium to work properly,
54482+ but we don't want to flood the logs from 'ps' which does a readlink
54483+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54484+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
54485+ */
54486+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54487+ if (!proc_fd_access_allowed(inode,0))
54488+ goto out;
54489+ } else {
54490+ if (!proc_fd_access_allowed(inode,1))
54491+ goto out;
54492+ }
54493
54494 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54495 if (error)
54496@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54497 rcu_read_lock();
54498 cred = __task_cred(task);
54499 inode->i_uid = cred->euid;
54500+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54501+ inode->i_gid = grsec_proc_gid;
54502+#else
54503 inode->i_gid = cred->egid;
54504+#endif
54505 rcu_read_unlock();
54506 }
54507 security_task_to_inode(task, inode);
54508@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54509 return -ENOENT;
54510 }
54511 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54512+#ifdef CONFIG_GRKERNSEC_PROC_USER
54513+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54514+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54515+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54516+#endif
54517 task_dumpable(task)) {
54518 cred = __task_cred(task);
54519 stat->uid = cred->euid;
54520+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54521+ stat->gid = grsec_proc_gid;
54522+#else
54523 stat->gid = cred->egid;
54524+#endif
54525 }
54526 }
54527 rcu_read_unlock();
54528@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54529
54530 if (task) {
54531 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54532+#ifdef CONFIG_GRKERNSEC_PROC_USER
54533+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54534+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54535+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54536+#endif
54537 task_dumpable(task)) {
54538 rcu_read_lock();
54539 cred = __task_cred(task);
54540 inode->i_uid = cred->euid;
54541+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54542+ inode->i_gid = grsec_proc_gid;
54543+#else
54544 inode->i_gid = cred->egid;
54545+#endif
54546 rcu_read_unlock();
54547 } else {
54548 inode->i_uid = GLOBAL_ROOT_UID;
54549@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54550 if (!task)
54551 goto out_no_task;
54552
54553+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54554+ goto out;
54555+
54556 /*
54557 * Yes, it does not scale. And it should not. Don't add
54558 * new entries into /proc/<tgid>/ without very good reasons.
54559@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54560 if (!task)
54561 goto out_no_task;
54562
54563+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54564+ goto out;
54565+
54566 ret = 0;
54567 i = filp->f_pos;
54568 switch (i) {
54569@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54570 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54571 #endif
54572 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54573-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54574+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54575 INF("syscall", S_IRUGO, proc_pid_syscall),
54576 #endif
54577 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54578@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54579 #ifdef CONFIG_SECURITY
54580 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54581 #endif
54582-#ifdef CONFIG_KALLSYMS
54583+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54584 INF("wchan", S_IRUGO, proc_pid_wchan),
54585 #endif
54586-#ifdef CONFIG_STACKTRACE
54587+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54588 ONE("stack", S_IRUGO, proc_pid_stack),
54589 #endif
54590 #ifdef CONFIG_SCHEDSTATS
54591@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54592 #ifdef CONFIG_HARDWALL
54593 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54594 #endif
54595+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54596+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54597+#endif
54598 #ifdef CONFIG_USER_NS
54599 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54600 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54601@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54602 if (!inode)
54603 goto out;
54604
54605+#ifdef CONFIG_GRKERNSEC_PROC_USER
54606+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54607+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54608+ inode->i_gid = grsec_proc_gid;
54609+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54610+#else
54611 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54612+#endif
54613 inode->i_op = &proc_tgid_base_inode_operations;
54614 inode->i_fop = &proc_tgid_base_operations;
54615 inode->i_flags|=S_IMMUTABLE;
54616@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54617 if (!task)
54618 goto out;
54619
54620+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54621+ goto out_put_task;
54622+
54623 result = proc_pid_instantiate(dir, dentry, task, NULL);
54624+out_put_task:
54625 put_task_struct(task);
54626 out:
54627 return result;
54628@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54629 static int fake_filldir(void *buf, const char *name, int namelen,
54630 loff_t offset, u64 ino, unsigned d_type)
54631 {
54632+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
54633+ __buf->error = -EINVAL;
54634 return 0;
54635 }
54636
54637@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54638 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54639 #endif
54640 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54641-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54642+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54643 INF("syscall", S_IRUGO, proc_pid_syscall),
54644 #endif
54645 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54646@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54647 #ifdef CONFIG_SECURITY
54648 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54649 #endif
54650-#ifdef CONFIG_KALLSYMS
54651+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54652 INF("wchan", S_IRUGO, proc_pid_wchan),
54653 #endif
54654-#ifdef CONFIG_STACKTRACE
54655+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54656 ONE("stack", S_IRUGO, proc_pid_stack),
54657 #endif
54658 #ifdef CONFIG_SCHEDSTATS
54659diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54660index 82676e3..5f8518a 100644
54661--- a/fs/proc/cmdline.c
54662+++ b/fs/proc/cmdline.c
54663@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54664
54665 static int __init proc_cmdline_init(void)
54666 {
54667+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54668+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54669+#else
54670 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54671+#endif
54672 return 0;
54673 }
54674 module_init(proc_cmdline_init);
54675diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54676index b143471..bb105e5 100644
54677--- a/fs/proc/devices.c
54678+++ b/fs/proc/devices.c
54679@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54680
54681 static int __init proc_devices_init(void)
54682 {
54683+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54684+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54685+#else
54686 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54687+#endif
54688 return 0;
54689 }
54690 module_init(proc_devices_init);
54691diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54692index d7a4a28..0201742 100644
54693--- a/fs/proc/fd.c
54694+++ b/fs/proc/fd.c
54695@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54696 if (!task)
54697 return -ENOENT;
54698
54699- files = get_files_struct(task);
54700+ if (!gr_acl_handle_procpidmem(task))
54701+ files = get_files_struct(task);
54702 put_task_struct(task);
54703
54704 if (files) {
54705@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54706 */
54707 int proc_fd_permission(struct inode *inode, int mask)
54708 {
54709+ struct task_struct *task;
54710 int rv = generic_permission(inode, mask);
54711- if (rv == 0)
54712- return 0;
54713+
54714 if (task_pid(current) == proc_pid(inode))
54715 rv = 0;
54716+
54717+ task = get_proc_task(inode);
54718+ if (task == NULL)
54719+ return rv;
54720+
54721+ if (gr_acl_handle_procpidmem(task))
54722+ rv = -EACCES;
54723+
54724+ put_task_struct(task);
54725+
54726 return rv;
54727 }
54728
54729diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54730index 439ae688..c21ac36 100644
54731--- a/fs/proc/inode.c
54732+++ b/fs/proc/inode.c
54733@@ -21,11 +21,17 @@
54734 #include <linux/seq_file.h>
54735 #include <linux/slab.h>
54736 #include <linux/mount.h>
54737+#include <linux/grsecurity.h>
54738
54739 #include <asm/uaccess.h>
54740
54741 #include "internal.h"
54742
54743+#ifdef CONFIG_PROC_SYSCTL
54744+extern const struct inode_operations proc_sys_inode_operations;
54745+extern const struct inode_operations proc_sys_dir_operations;
54746+#endif
54747+
54748 static void proc_evict_inode(struct inode *inode)
54749 {
54750 struct proc_dir_entry *de;
54751@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54752 ns = PROC_I(inode)->ns;
54753 if (ns_ops && ns)
54754 ns_ops->put(ns);
54755+
54756+#ifdef CONFIG_PROC_SYSCTL
54757+ if (inode->i_op == &proc_sys_inode_operations ||
54758+ inode->i_op == &proc_sys_dir_operations)
54759+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54760+#endif
54761+
54762 }
54763
54764 static struct kmem_cache * proc_inode_cachep;
54765@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54766 if (de->mode) {
54767 inode->i_mode = de->mode;
54768 inode->i_uid = de->uid;
54769+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54770+ inode->i_gid = grsec_proc_gid;
54771+#else
54772 inode->i_gid = de->gid;
54773+#endif
54774 }
54775 if (de->size)
54776 inode->i_size = de->size;
54777diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54778index 252544c..04395b9 100644
54779--- a/fs/proc/internal.h
54780+++ b/fs/proc/internal.h
54781@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54782 struct pid *pid, struct task_struct *task);
54783 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54784 struct pid *pid, struct task_struct *task);
54785+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54786+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54787+#endif
54788 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54789
54790 extern const struct file_operations proc_tid_children_operations;
54791diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54792index e96d4f1..8b116ed 100644
54793--- a/fs/proc/kcore.c
54794+++ b/fs/proc/kcore.c
54795@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54796 * the addresses in the elf_phdr on our list.
54797 */
54798 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54799- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54800+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54801+ if (tsz > buflen)
54802 tsz = buflen;
54803-
54804+
54805 while (buflen) {
54806 struct kcore_list *m;
54807
54808@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54809 kfree(elf_buf);
54810 } else {
54811 if (kern_addr_valid(start)) {
54812- unsigned long n;
54813+ char *elf_buf;
54814+ mm_segment_t oldfs;
54815
54816- n = copy_to_user(buffer, (char *)start, tsz);
54817- /*
54818- * We cannot distinguish between fault on source
54819- * and fault on destination. When this happens
54820- * we clear too and hope it will trigger the
54821- * EFAULT again.
54822- */
54823- if (n) {
54824- if (clear_user(buffer + tsz - n,
54825- n))
54826+ elf_buf = kmalloc(tsz, GFP_KERNEL);
54827+ if (!elf_buf)
54828+ return -ENOMEM;
54829+ oldfs = get_fs();
54830+ set_fs(KERNEL_DS);
54831+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54832+ set_fs(oldfs);
54833+ if (copy_to_user(buffer, elf_buf, tsz)) {
54834+ kfree(elf_buf);
54835 return -EFAULT;
54836+ }
54837 }
54838+ set_fs(oldfs);
54839+ kfree(elf_buf);
54840 } else {
54841 if (clear_user(buffer, tsz))
54842 return -EFAULT;
54843@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54844
54845 static int open_kcore(struct inode *inode, struct file *filp)
54846 {
54847+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54848+ return -EPERM;
54849+#endif
54850 if (!capable(CAP_SYS_RAWIO))
54851 return -EPERM;
54852 if (kcore_need_update)
54853diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54854index 80e4645..53e5fcf 100644
54855--- a/fs/proc/meminfo.c
54856+++ b/fs/proc/meminfo.c
54857@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54858 vmi.used >> 10,
54859 vmi.largest_chunk >> 10
54860 #ifdef CONFIG_MEMORY_FAILURE
54861- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54862+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54863 #endif
54864 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54865 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54866diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54867index b1822dd..df622cb 100644
54868--- a/fs/proc/nommu.c
54869+++ b/fs/proc/nommu.c
54870@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54871 if (len < 1)
54872 len = 1;
54873 seq_printf(m, "%*c", len, ' ');
54874- seq_path(m, &file->f_path, "");
54875+ seq_path(m, &file->f_path, "\n\\");
54876 }
54877
54878 seq_putc(m, '\n');
54879diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54880index fe72cd0..21b52ff 100644
54881--- a/fs/proc/proc_net.c
54882+++ b/fs/proc/proc_net.c
54883@@ -23,6 +23,7 @@
54884 #include <linux/nsproxy.h>
54885 #include <net/net_namespace.h>
54886 #include <linux/seq_file.h>
54887+#include <linux/grsecurity.h>
54888
54889 #include "internal.h"
54890
54891@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54892 struct task_struct *task;
54893 struct nsproxy *ns;
54894 struct net *net = NULL;
54895+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54896+ const struct cred *cred = current_cred();
54897+#endif
54898+
54899+#ifdef CONFIG_GRKERNSEC_PROC_USER
54900+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54901+ return net;
54902+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54903+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54904+ return net;
54905+#endif
54906
54907 rcu_read_lock();
54908 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54909diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54910index 1827d88..43b0279 100644
54911--- a/fs/proc/proc_sysctl.c
54912+++ b/fs/proc/proc_sysctl.c
54913@@ -12,11 +12,15 @@
54914 #include <linux/module.h>
54915 #include "internal.h"
54916
54917+extern int gr_handle_chroot_sysctl(const int op);
54918+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54919+ const int op);
54920+
54921 static const struct dentry_operations proc_sys_dentry_operations;
54922 static const struct file_operations proc_sys_file_operations;
54923-static const struct inode_operations proc_sys_inode_operations;
54924+const struct inode_operations proc_sys_inode_operations;
54925 static const struct file_operations proc_sys_dir_file_operations;
54926-static const struct inode_operations proc_sys_dir_operations;
54927+const struct inode_operations proc_sys_dir_operations;
54928
54929 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54930 {
54931@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54932
54933 err = NULL;
54934 d_set_d_op(dentry, &proc_sys_dentry_operations);
54935+
54936+ gr_handle_proc_create(dentry, inode);
54937+
54938 d_add(dentry, inode);
54939
54940 out:
54941@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54942 struct inode *inode = filp->f_path.dentry->d_inode;
54943 struct ctl_table_header *head = grab_header(inode);
54944 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54945+ int op = write ? MAY_WRITE : MAY_READ;
54946 ssize_t error;
54947 size_t res;
54948
54949@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54950 * and won't be until we finish.
54951 */
54952 error = -EPERM;
54953- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54954+ if (sysctl_perm(head, table, op))
54955 goto out;
54956
54957 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
54958@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54959 if (!table->proc_handler)
54960 goto out;
54961
54962+#ifdef CONFIG_GRKERNSEC
54963+ error = -EPERM;
54964+ if (gr_handle_chroot_sysctl(op))
54965+ goto out;
54966+ dget(filp->f_path.dentry);
54967+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
54968+ dput(filp->f_path.dentry);
54969+ goto out;
54970+ }
54971+ dput(filp->f_path.dentry);
54972+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
54973+ goto out;
54974+ if (write && !capable(CAP_SYS_ADMIN))
54975+ goto out;
54976+#endif
54977+
54978 /* careful: calling conventions are nasty here */
54979 res = count;
54980 error = table->proc_handler(table, write, buf, &res, ppos);
54981@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
54982 return -ENOMEM;
54983 } else {
54984 d_set_d_op(child, &proc_sys_dentry_operations);
54985+
54986+ gr_handle_proc_create(child, inode);
54987+
54988 d_add(child, inode);
54989 }
54990 } else {
54991@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
54992 if ((*pos)++ < file->f_pos)
54993 return 0;
54994
54995+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
54996+ return 0;
54997+
54998 if (unlikely(S_ISLNK(table->mode)))
54999 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55000 else
55001@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55002 if (IS_ERR(head))
55003 return PTR_ERR(head);
55004
55005+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55006+ return -ENOENT;
55007+
55008 generic_fillattr(inode, stat);
55009 if (table)
55010 stat->mode = (stat->mode & S_IFMT) | table->mode;
55011@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55012 .llseek = generic_file_llseek,
55013 };
55014
55015-static const struct inode_operations proc_sys_inode_operations = {
55016+const struct inode_operations proc_sys_inode_operations = {
55017 .permission = proc_sys_permission,
55018 .setattr = proc_sys_setattr,
55019 .getattr = proc_sys_getattr,
55020 };
55021
55022-static const struct inode_operations proc_sys_dir_operations = {
55023+const struct inode_operations proc_sys_dir_operations = {
55024 .lookup = proc_sys_lookup,
55025 .permission = proc_sys_permission,
55026 .setattr = proc_sys_setattr,
55027@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55028 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55029 const char *name, int namelen)
55030 {
55031- struct ctl_table *table;
55032+ ctl_table_no_const *table;
55033 struct ctl_dir *new;
55034 struct ctl_node *node;
55035 char *new_name;
55036@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55037 return NULL;
55038
55039 node = (struct ctl_node *)(new + 1);
55040- table = (struct ctl_table *)(node + 1);
55041+ table = (ctl_table_no_const *)(node + 1);
55042 new_name = (char *)(table + 2);
55043 memcpy(new_name, name, namelen);
55044 new_name[namelen] = '\0';
55045@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55046 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55047 struct ctl_table_root *link_root)
55048 {
55049- struct ctl_table *link_table, *entry, *link;
55050+ ctl_table_no_const *link_table, *link;
55051+ struct ctl_table *entry;
55052 struct ctl_table_header *links;
55053 struct ctl_node *node;
55054 char *link_name;
55055@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55056 return NULL;
55057
55058 node = (struct ctl_node *)(links + 1);
55059- link_table = (struct ctl_table *)(node + nr_entries);
55060+ link_table = (ctl_table_no_const *)(node + nr_entries);
55061 link_name = (char *)&link_table[nr_entries + 1];
55062
55063 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55064@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55065 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55066 struct ctl_table *table)
55067 {
55068- struct ctl_table *ctl_table_arg = NULL;
55069- struct ctl_table *entry, *files;
55070+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55071+ struct ctl_table *entry;
55072 int nr_files = 0;
55073 int nr_dirs = 0;
55074 int err = -ENOMEM;
55075@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55076 nr_files++;
55077 }
55078
55079- files = table;
55080 /* If there are mixed files and directories we need a new table */
55081 if (nr_dirs && nr_files) {
55082- struct ctl_table *new;
55083+ ctl_table_no_const *new;
55084 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55085 GFP_KERNEL);
55086 if (!files)
55087@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55088 /* Register everything except a directory full of subdirectories */
55089 if (nr_files || !nr_dirs) {
55090 struct ctl_table_header *header;
55091- header = __register_sysctl_table(set, path, files);
55092+ header = __register_sysctl_table(set, path, files ? files : table);
55093 if (!header) {
55094 kfree(ctl_table_arg);
55095 goto out;
55096diff --git a/fs/proc/root.c b/fs/proc/root.c
55097index c6e9fac..a740964 100644
55098--- a/fs/proc/root.c
55099+++ b/fs/proc/root.c
55100@@ -176,7 +176,15 @@ void __init proc_root_init(void)
55101 #ifdef CONFIG_PROC_DEVICETREE
55102 proc_device_tree_init();
55103 #endif
55104+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55105+#ifdef CONFIG_GRKERNSEC_PROC_USER
55106+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55107+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55108+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55109+#endif
55110+#else
55111 proc_mkdir("bus", NULL);
55112+#endif
55113 proc_sys_init();
55114 }
55115
55116diff --git a/fs/proc/self.c b/fs/proc/self.c
55117index aa5cc3b..c91a5d0 100644
55118--- a/fs/proc/self.c
55119+++ b/fs/proc/self.c
55120@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55121 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55122 void *cookie)
55123 {
55124- char *s = nd_get_link(nd);
55125+ const char *s = nd_get_link(nd);
55126 if (!IS_ERR(s))
55127 kfree(s);
55128 }
55129diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55130index ca5ce7f..02c1cf0 100644
55131--- a/fs/proc/task_mmu.c
55132+++ b/fs/proc/task_mmu.c
55133@@ -11,12 +11,19 @@
55134 #include <linux/rmap.h>
55135 #include <linux/swap.h>
55136 #include <linux/swapops.h>
55137+#include <linux/grsecurity.h>
55138
55139 #include <asm/elf.h>
55140 #include <asm/uaccess.h>
55141 #include <asm/tlbflush.h>
55142 #include "internal.h"
55143
55144+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55145+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55146+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55147+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55148+#endif
55149+
55150 void task_mem(struct seq_file *m, struct mm_struct *mm)
55151 {
55152 unsigned long data, text, lib, swap;
55153@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55154 "VmExe:\t%8lu kB\n"
55155 "VmLib:\t%8lu kB\n"
55156 "VmPTE:\t%8lu kB\n"
55157- "VmSwap:\t%8lu kB\n",
55158- hiwater_vm << (PAGE_SHIFT-10),
55159+ "VmSwap:\t%8lu kB\n"
55160+
55161+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55162+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
55163+#endif
55164+
55165+ ,hiwater_vm << (PAGE_SHIFT-10),
55166 total_vm << (PAGE_SHIFT-10),
55167 mm->locked_vm << (PAGE_SHIFT-10),
55168 mm->pinned_vm << (PAGE_SHIFT-10),
55169@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55170 data << (PAGE_SHIFT-10),
55171 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
55172 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
55173- swap << (PAGE_SHIFT-10));
55174+ swap << (PAGE_SHIFT-10)
55175+
55176+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55177+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55178+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
55179+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
55180+#else
55181+ , mm->context.user_cs_base
55182+ , mm->context.user_cs_limit
55183+#endif
55184+#endif
55185+
55186+ );
55187 }
55188
55189 unsigned long task_vsize(struct mm_struct *mm)
55190@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55191 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
55192 }
55193
55194- /* We don't show the stack guard page in /proc/maps */
55195+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55196+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
55197+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
55198+#else
55199 start = vma->vm_start;
55200- if (stack_guard_page_start(vma, start))
55201- start += PAGE_SIZE;
55202 end = vma->vm_end;
55203- if (stack_guard_page_end(vma, end))
55204- end -= PAGE_SIZE;
55205+#endif
55206
55207 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
55208 start,
55209@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55210 flags & VM_WRITE ? 'w' : '-',
55211 flags & VM_EXEC ? 'x' : '-',
55212 flags & VM_MAYSHARE ? 's' : 'p',
55213+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55214+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
55215+#else
55216 pgoff,
55217+#endif
55218 MAJOR(dev), MINOR(dev), ino, &len);
55219
55220 /*
55221@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55222 */
55223 if (file) {
55224 pad_len_spaces(m, len);
55225- seq_path(m, &file->f_path, "\n");
55226+ seq_path(m, &file->f_path, "\n\\");
55227 goto done;
55228 }
55229
55230@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55231 * Thread stack in /proc/PID/task/TID/maps or
55232 * the main process stack.
55233 */
55234- if (!is_pid || (vma->vm_start <= mm->start_stack &&
55235- vma->vm_end >= mm->start_stack)) {
55236+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
55237+ (vma->vm_start <= mm->start_stack &&
55238+ vma->vm_end >= mm->start_stack)) {
55239 name = "[stack]";
55240 } else {
55241 /* Thread stack in /proc/PID/maps */
55242@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
55243 struct proc_maps_private *priv = m->private;
55244 struct task_struct *task = priv->task;
55245
55246+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55247+ if (current->exec_id != m->exec_id) {
55248+ gr_log_badprocpid("maps");
55249+ return 0;
55250+ }
55251+#endif
55252+
55253 show_map_vma(m, vma, is_pid);
55254
55255 if (m->count < m->size) /* vma is copied successfully */
55256@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55257 .private = &mss,
55258 };
55259
55260+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55261+ if (current->exec_id != m->exec_id) {
55262+ gr_log_badprocpid("smaps");
55263+ return 0;
55264+ }
55265+#endif
55266 memset(&mss, 0, sizeof mss);
55267- mss.vma = vma;
55268- /* mmap_sem is held in m_start */
55269- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55270- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55271-
55272+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55273+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
55274+#endif
55275+ mss.vma = vma;
55276+ /* mmap_sem is held in m_start */
55277+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55278+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55279+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55280+ }
55281+#endif
55282 show_map_vma(m, vma, is_pid);
55283
55284 seq_printf(m,
55285@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55286 "KernelPageSize: %8lu kB\n"
55287 "MMUPageSize: %8lu kB\n"
55288 "Locked: %8lu kB\n",
55289+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55290+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
55291+#else
55292 (vma->vm_end - vma->vm_start) >> 10,
55293+#endif
55294 mss.resident >> 10,
55295 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
55296 mss.shared_clean >> 10,
55297@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55298 int n;
55299 char buffer[50];
55300
55301+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55302+ if (current->exec_id != m->exec_id) {
55303+ gr_log_badprocpid("numa_maps");
55304+ return 0;
55305+ }
55306+#endif
55307+
55308 if (!mm)
55309 return 0;
55310
55311@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55312 mpol_to_str(buffer, sizeof(buffer), pol);
55313 mpol_cond_put(pol);
55314
55315+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55316+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
55317+#else
55318 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
55319+#endif
55320
55321 if (file) {
55322 seq_printf(m, " file=");
55323- seq_path(m, &file->f_path, "\n\t= ");
55324+ seq_path(m, &file->f_path, "\n\t\\= ");
55325 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
55326 seq_printf(m, " heap");
55327 } else {
55328diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
55329index 1ccfa53..0848f95 100644
55330--- a/fs/proc/task_nommu.c
55331+++ b/fs/proc/task_nommu.c
55332@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55333 else
55334 bytes += kobjsize(mm);
55335
55336- if (current->fs && current->fs->users > 1)
55337+ if (current->fs && atomic_read(&current->fs->users) > 1)
55338 sbytes += kobjsize(current->fs);
55339 else
55340 bytes += kobjsize(current->fs);
55341@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
55342
55343 if (file) {
55344 pad_len_spaces(m, len);
55345- seq_path(m, &file->f_path, "");
55346+ seq_path(m, &file->f_path, "\n\\");
55347 } else if (mm) {
55348 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
55349
55350diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
55351index b00fcc9..e0c6381 100644
55352--- a/fs/qnx6/qnx6.h
55353+++ b/fs/qnx6/qnx6.h
55354@@ -74,7 +74,7 @@ enum {
55355 BYTESEX_BE,
55356 };
55357
55358-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55359+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55360 {
55361 if (sbi->s_bytesex == BYTESEX_LE)
55362 return le64_to_cpu((__force __le64)n);
55363@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
55364 return (__force __fs64)cpu_to_be64(n);
55365 }
55366
55367-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55368+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55369 {
55370 if (sbi->s_bytesex == BYTESEX_LE)
55371 return le32_to_cpu((__force __le32)n);
55372diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
55373index 16e8abb..2dcf914 100644
55374--- a/fs/quota/netlink.c
55375+++ b/fs/quota/netlink.c
55376@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
55377 void quota_send_warning(struct kqid qid, dev_t dev,
55378 const char warntype)
55379 {
55380- static atomic_t seq;
55381+ static atomic_unchecked_t seq;
55382 struct sk_buff *skb;
55383 void *msg_head;
55384 int ret;
55385@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
55386 "VFS: Not enough memory to send quota warning.\n");
55387 return;
55388 }
55389- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
55390+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
55391 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
55392 if (!msg_head) {
55393 printk(KERN_ERR
55394diff --git a/fs/readdir.c b/fs/readdir.c
55395index 5e69ef5..e5d9099 100644
55396--- a/fs/readdir.c
55397+++ b/fs/readdir.c
55398@@ -17,6 +17,7 @@
55399 #include <linux/security.h>
55400 #include <linux/syscalls.h>
55401 #include <linux/unistd.h>
55402+#include <linux/namei.h>
55403
55404 #include <asm/uaccess.h>
55405
55406@@ -67,6 +68,7 @@ struct old_linux_dirent {
55407
55408 struct readdir_callback {
55409 struct old_linux_dirent __user * dirent;
55410+ struct file * file;
55411 int result;
55412 };
55413
55414@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55415 buf->result = -EOVERFLOW;
55416 return -EOVERFLOW;
55417 }
55418+
55419+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55420+ return 0;
55421+
55422 buf->result++;
55423 dirent = buf->dirent;
55424 if (!access_ok(VERIFY_WRITE, dirent,
55425@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55426
55427 buf.result = 0;
55428 buf.dirent = dirent;
55429+ buf.file = f.file;
55430
55431 error = vfs_readdir(f.file, fillonedir, &buf);
55432 if (buf.result)
55433@@ -139,6 +146,7 @@ struct linux_dirent {
55434 struct getdents_callback {
55435 struct linux_dirent __user * current_dir;
55436 struct linux_dirent __user * previous;
55437+ struct file * file;
55438 int count;
55439 int error;
55440 };
55441@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55442 buf->error = -EOVERFLOW;
55443 return -EOVERFLOW;
55444 }
55445+
55446+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55447+ return 0;
55448+
55449 dirent = buf->previous;
55450 if (dirent) {
55451 if (__put_user(offset, &dirent->d_off))
55452@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55453 buf.previous = NULL;
55454 buf.count = count;
55455 buf.error = 0;
55456+ buf.file = f.file;
55457
55458 error = vfs_readdir(f.file, filldir, &buf);
55459 if (error >= 0)
55460@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55461 struct getdents_callback64 {
55462 struct linux_dirent64 __user * current_dir;
55463 struct linux_dirent64 __user * previous;
55464+ struct file *file;
55465 int count;
55466 int error;
55467 };
55468@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55469 buf->error = -EINVAL; /* only used if we fail.. */
55470 if (reclen > buf->count)
55471 return -EINVAL;
55472+
55473+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55474+ return 0;
55475+
55476 dirent = buf->previous;
55477 if (dirent) {
55478 if (__put_user(offset, &dirent->d_off))
55479@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55480
55481 buf.current_dir = dirent;
55482 buf.previous = NULL;
55483+ buf.file = f.file;
55484 buf.count = count;
55485 buf.error = 0;
55486
55487@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55488 error = buf.error;
55489 lastdirent = buf.previous;
55490 if (lastdirent) {
55491- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55492+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55493 if (__put_user(d_off, &lastdirent->d_off))
55494 error = -EFAULT;
55495 else
55496diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55497index 2b7882b..1c5ef48 100644
55498--- a/fs/reiserfs/do_balan.c
55499+++ b/fs/reiserfs/do_balan.c
55500@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55501 return;
55502 }
55503
55504- atomic_inc(&(fs_generation(tb->tb_sb)));
55505+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55506 do_balance_starts(tb);
55507
55508 /* balance leaf returns 0 except if combining L R and S into
55509diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55510index e60e870..f40ac16 100644
55511--- a/fs/reiserfs/procfs.c
55512+++ b/fs/reiserfs/procfs.c
55513@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55514 "SMALL_TAILS " : "NO_TAILS ",
55515 replay_only(sb) ? "REPLAY_ONLY " : "",
55516 convert_reiserfs(sb) ? "CONV " : "",
55517- atomic_read(&r->s_generation_counter),
55518+ atomic_read_unchecked(&r->s_generation_counter),
55519 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55520 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55521 SF(s_good_search_by_key_reada), SF(s_bmaps),
55522diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55523index 157e474..65a6114 100644
55524--- a/fs/reiserfs/reiserfs.h
55525+++ b/fs/reiserfs/reiserfs.h
55526@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55527 /* Comment? -Hans */
55528 wait_queue_head_t s_wait;
55529 /* To be obsoleted soon by per buffer seals.. -Hans */
55530- atomic_t s_generation_counter; // increased by one every time the
55531+ atomic_unchecked_t s_generation_counter; // increased by one every time the
55532 // tree gets re-balanced
55533 unsigned long s_properties; /* File system properties. Currently holds
55534 on-disk FS format */
55535@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55536 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55537
55538 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55539-#define get_generation(s) atomic_read (&fs_generation(s))
55540+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55541 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55542 #define __fs_changed(gen,s) (gen != get_generation (s))
55543 #define fs_changed(gen,s) \
55544diff --git a/fs/select.c b/fs/select.c
55545index 2ef72d9..f213b17 100644
55546--- a/fs/select.c
55547+++ b/fs/select.c
55548@@ -20,6 +20,7 @@
55549 #include <linux/export.h>
55550 #include <linux/slab.h>
55551 #include <linux/poll.h>
55552+#include <linux/security.h>
55553 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55554 #include <linux/file.h>
55555 #include <linux/fdtable.h>
55556@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55557 struct poll_list *walk = head;
55558 unsigned long todo = nfds;
55559
55560+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55561 if (nfds > rlimit(RLIMIT_NOFILE))
55562 return -EINVAL;
55563
55564diff --git a/fs/seq_file.c b/fs/seq_file.c
55565index f2bc3df..239d4f6 100644
55566--- a/fs/seq_file.c
55567+++ b/fs/seq_file.c
55568@@ -10,6 +10,7 @@
55569 #include <linux/seq_file.h>
55570 #include <linux/slab.h>
55571 #include <linux/cred.h>
55572+#include <linux/sched.h>
55573
55574 #include <asm/uaccess.h>
55575 #include <asm/page.h>
55576@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55577 #ifdef CONFIG_USER_NS
55578 p->user_ns = file->f_cred->user_ns;
55579 #endif
55580+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55581+ p->exec_id = current->exec_id;
55582+#endif
55583
55584 /*
55585 * Wrappers around seq_open(e.g. swaps_open) need to be
55586@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55587 return 0;
55588 }
55589 if (!m->buf) {
55590- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55591+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55592 if (!m->buf)
55593 return -ENOMEM;
55594 }
55595@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55596 Eoverflow:
55597 m->op->stop(m, p);
55598 kfree(m->buf);
55599- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55600+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55601 return !m->buf ? -ENOMEM : -EAGAIN;
55602 }
55603
55604@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55605
55606 /* grab buffer if we didn't have one */
55607 if (!m->buf) {
55608- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55609+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55610 if (!m->buf)
55611 goto Enomem;
55612 }
55613@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55614 goto Fill;
55615 m->op->stop(m, p);
55616 kfree(m->buf);
55617- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55618+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55619 if (!m->buf)
55620 goto Enomem;
55621 m->count = 0;
55622@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55623 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55624 void *data)
55625 {
55626- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55627+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55628 int res = -ENOMEM;
55629
55630 if (op) {
55631diff --git a/fs/splice.c b/fs/splice.c
55632index 6909d89..5b2e8f9 100644
55633--- a/fs/splice.c
55634+++ b/fs/splice.c
55635@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55636 pipe_lock(pipe);
55637
55638 for (;;) {
55639- if (!pipe->readers) {
55640+ if (!atomic_read(&pipe->readers)) {
55641 send_sig(SIGPIPE, current, 0);
55642 if (!ret)
55643 ret = -EPIPE;
55644@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55645 do_wakeup = 0;
55646 }
55647
55648- pipe->waiting_writers++;
55649+ atomic_inc(&pipe->waiting_writers);
55650 pipe_wait(pipe);
55651- pipe->waiting_writers--;
55652+ atomic_dec(&pipe->waiting_writers);
55653 }
55654
55655 pipe_unlock(pipe);
55656@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55657 old_fs = get_fs();
55658 set_fs(get_ds());
55659 /* The cast to a user pointer is valid due to the set_fs() */
55660- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55661+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55662 set_fs(old_fs);
55663
55664 return res;
55665@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55666 old_fs = get_fs();
55667 set_fs(get_ds());
55668 /* The cast to a user pointer is valid due to the set_fs() */
55669- res = vfs_write(file, (const char __user *)buf, count, &pos);
55670+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55671 set_fs(old_fs);
55672
55673 return res;
55674@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55675 goto err;
55676
55677 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55678- vec[i].iov_base = (void __user *) page_address(page);
55679+ vec[i].iov_base = (void __force_user *) page_address(page);
55680 vec[i].iov_len = this_len;
55681 spd.pages[i] = page;
55682 spd.nr_pages++;
55683@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55684 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55685 {
55686 while (!pipe->nrbufs) {
55687- if (!pipe->writers)
55688+ if (!atomic_read(&pipe->writers))
55689 return 0;
55690
55691- if (!pipe->waiting_writers && sd->num_spliced)
55692+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55693 return 0;
55694
55695 if (sd->flags & SPLICE_F_NONBLOCK)
55696@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55697 * out of the pipe right after the splice_to_pipe(). So set
55698 * PIPE_READERS appropriately.
55699 */
55700- pipe->readers = 1;
55701+ atomic_set(&pipe->readers, 1);
55702
55703 current->splice_pipe = pipe;
55704 }
55705@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55706 ret = -ERESTARTSYS;
55707 break;
55708 }
55709- if (!pipe->writers)
55710+ if (!atomic_read(&pipe->writers))
55711 break;
55712- if (!pipe->waiting_writers) {
55713+ if (!atomic_read(&pipe->waiting_writers)) {
55714 if (flags & SPLICE_F_NONBLOCK) {
55715 ret = -EAGAIN;
55716 break;
55717@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55718 pipe_lock(pipe);
55719
55720 while (pipe->nrbufs >= pipe->buffers) {
55721- if (!pipe->readers) {
55722+ if (!atomic_read(&pipe->readers)) {
55723 send_sig(SIGPIPE, current, 0);
55724 ret = -EPIPE;
55725 break;
55726@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55727 ret = -ERESTARTSYS;
55728 break;
55729 }
55730- pipe->waiting_writers++;
55731+ atomic_inc(&pipe->waiting_writers);
55732 pipe_wait(pipe);
55733- pipe->waiting_writers--;
55734+ atomic_dec(&pipe->waiting_writers);
55735 }
55736
55737 pipe_unlock(pipe);
55738@@ -1823,14 +1823,14 @@ retry:
55739 pipe_double_lock(ipipe, opipe);
55740
55741 do {
55742- if (!opipe->readers) {
55743+ if (!atomic_read(&opipe->readers)) {
55744 send_sig(SIGPIPE, current, 0);
55745 if (!ret)
55746 ret = -EPIPE;
55747 break;
55748 }
55749
55750- if (!ipipe->nrbufs && !ipipe->writers)
55751+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55752 break;
55753
55754 /*
55755@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55756 pipe_double_lock(ipipe, opipe);
55757
55758 do {
55759- if (!opipe->readers) {
55760+ if (!atomic_read(&opipe->readers)) {
55761 send_sig(SIGPIPE, current, 0);
55762 if (!ret)
55763 ret = -EPIPE;
55764@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55765 * return EAGAIN if we have the potential of some data in the
55766 * future, otherwise just return 0
55767 */
55768- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55769+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55770 ret = -EAGAIN;
55771
55772 pipe_unlock(ipipe);
55773diff --git a/fs/stat.c b/fs/stat.c
55774index 14f4545..9b7f55b 100644
55775--- a/fs/stat.c
55776+++ b/fs/stat.c
55777@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55778 stat->gid = inode->i_gid;
55779 stat->rdev = inode->i_rdev;
55780 stat->size = i_size_read(inode);
55781- stat->atime = inode->i_atime;
55782- stat->mtime = inode->i_mtime;
55783+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55784+ stat->atime = inode->i_ctime;
55785+ stat->mtime = inode->i_ctime;
55786+ } else {
55787+ stat->atime = inode->i_atime;
55788+ stat->mtime = inode->i_mtime;
55789+ }
55790 stat->ctime = inode->i_ctime;
55791 stat->blksize = (1 << inode->i_blkbits);
55792 stat->blocks = inode->i_blocks;
55793@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55794 if (retval)
55795 return retval;
55796
55797- if (inode->i_op->getattr)
55798- return inode->i_op->getattr(mnt, dentry, stat);
55799+ if (inode->i_op->getattr) {
55800+ retval = inode->i_op->getattr(mnt, dentry, stat);
55801+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55802+ stat->atime = stat->ctime;
55803+ stat->mtime = stat->ctime;
55804+ }
55805+ return retval;
55806+ }
55807
55808 generic_fillattr(inode, stat);
55809 return 0;
55810diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55811index 2fbdff6..5530a61 100644
55812--- a/fs/sysfs/dir.c
55813+++ b/fs/sysfs/dir.c
55814@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55815 struct sysfs_dirent *sd;
55816 int rc;
55817
55818+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55819+ const char *parent_name = parent_sd->s_name;
55820+
55821+ mode = S_IFDIR | S_IRWXU;
55822+
55823+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55824+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55825+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55826+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55827+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55828+#endif
55829+
55830 /* allocate */
55831 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55832 if (!sd)
55833diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55834index 602f56d..6853db8 100644
55835--- a/fs/sysfs/file.c
55836+++ b/fs/sysfs/file.c
55837@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55838
55839 struct sysfs_open_dirent {
55840 atomic_t refcnt;
55841- atomic_t event;
55842+ atomic_unchecked_t event;
55843 wait_queue_head_t poll;
55844 struct list_head buffers; /* goes through sysfs_buffer.list */
55845 };
55846@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55847 if (!sysfs_get_active(attr_sd))
55848 return -ENODEV;
55849
55850- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55851+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55852 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55853
55854 sysfs_put_active(attr_sd);
55855@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55856 return -ENOMEM;
55857
55858 atomic_set(&new_od->refcnt, 0);
55859- atomic_set(&new_od->event, 1);
55860+ atomic_set_unchecked(&new_od->event, 1);
55861 init_waitqueue_head(&new_od->poll);
55862 INIT_LIST_HEAD(&new_od->buffers);
55863 goto retry;
55864@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55865
55866 sysfs_put_active(attr_sd);
55867
55868- if (buffer->event != atomic_read(&od->event))
55869+ if (buffer->event != atomic_read_unchecked(&od->event))
55870 goto trigger;
55871
55872 return DEFAULT_POLLMASK;
55873@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55874
55875 od = sd->s_attr.open;
55876 if (od) {
55877- atomic_inc(&od->event);
55878+ atomic_inc_unchecked(&od->event);
55879 wake_up_interruptible(&od->poll);
55880 }
55881
55882diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55883index 3c9eb56..9dea5be 100644
55884--- a/fs/sysfs/symlink.c
55885+++ b/fs/sysfs/symlink.c
55886@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55887
55888 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55889 {
55890- char *page = nd_get_link(nd);
55891+ const char *page = nd_get_link(nd);
55892 if (!IS_ERR(page))
55893 free_page((unsigned long)page);
55894 }
55895diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
55896index 69d4889..a810bd4 100644
55897--- a/fs/sysv/sysv.h
55898+++ b/fs/sysv/sysv.h
55899@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
55900 #endif
55901 }
55902
55903-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
55904+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
55905 {
55906 if (sbi->s_bytesex == BYTESEX_PDP)
55907 return PDP_swab((__force __u32)n);
55908diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
55909index e18b988..f1d4ad0f 100644
55910--- a/fs/ubifs/io.c
55911+++ b/fs/ubifs/io.c
55912@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
55913 return err;
55914 }
55915
55916-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
55917+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
55918 {
55919 int err;
55920
55921diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55922index c175b4d..8f36a16 100644
55923--- a/fs/udf/misc.c
55924+++ b/fs/udf/misc.c
55925@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55926
55927 u8 udf_tag_checksum(const struct tag *t)
55928 {
55929- u8 *data = (u8 *)t;
55930+ const u8 *data = (const u8 *)t;
55931 u8 checksum = 0;
55932 int i;
55933 for (i = 0; i < sizeof(struct tag); ++i)
55934diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
55935index 8d974c4..b82f6ec 100644
55936--- a/fs/ufs/swab.h
55937+++ b/fs/ufs/swab.h
55938@@ -22,7 +22,7 @@ enum {
55939 BYTESEX_BE
55940 };
55941
55942-static inline u64
55943+static inline u64 __intentional_overflow(-1)
55944 fs64_to_cpu(struct super_block *sbp, __fs64 n)
55945 {
55946 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
55947@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
55948 return (__force __fs64)cpu_to_be64(n);
55949 }
55950
55951-static inline u32
55952+static inline u32 __intentional_overflow(-1)
55953 fs32_to_cpu(struct super_block *sbp, __fs32 n)
55954 {
55955 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
55956diff --git a/fs/utimes.c b/fs/utimes.c
55957index f4fb7ec..3fe03c0 100644
55958--- a/fs/utimes.c
55959+++ b/fs/utimes.c
55960@@ -1,6 +1,7 @@
55961 #include <linux/compiler.h>
55962 #include <linux/file.h>
55963 #include <linux/fs.h>
55964+#include <linux/security.h>
55965 #include <linux/linkage.h>
55966 #include <linux/mount.h>
55967 #include <linux/namei.h>
55968@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
55969 goto mnt_drop_write_and_out;
55970 }
55971 }
55972+
55973+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
55974+ error = -EACCES;
55975+ goto mnt_drop_write_and_out;
55976+ }
55977+
55978 mutex_lock(&inode->i_mutex);
55979 error = notify_change(path->dentry, &newattrs);
55980 mutex_unlock(&inode->i_mutex);
55981diff --git a/fs/xattr.c b/fs/xattr.c
55982index 3377dff..4feded6 100644
55983--- a/fs/xattr.c
55984+++ b/fs/xattr.c
55985@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
55986 * Extended attribute SET operations
55987 */
55988 static long
55989-setxattr(struct dentry *d, const char __user *name, const void __user *value,
55990+setxattr(struct path *path, const char __user *name, const void __user *value,
55991 size_t size, int flags)
55992 {
55993 int error;
55994@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
55995 posix_acl_fix_xattr_from_user(kvalue, size);
55996 }
55997
55998- error = vfs_setxattr(d, kname, kvalue, size, flags);
55999+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56000+ error = -EACCES;
56001+ goto out;
56002+ }
56003+
56004+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56005 out:
56006 if (vvalue)
56007 vfree(vvalue);
56008@@ -377,7 +382,7 @@ retry:
56009 return error;
56010 error = mnt_want_write(path.mnt);
56011 if (!error) {
56012- error = setxattr(path.dentry, name, value, size, flags);
56013+ error = setxattr(&path, name, value, size, flags);
56014 mnt_drop_write(path.mnt);
56015 }
56016 path_put(&path);
56017@@ -401,7 +406,7 @@ retry:
56018 return error;
56019 error = mnt_want_write(path.mnt);
56020 if (!error) {
56021- error = setxattr(path.dentry, name, value, size, flags);
56022+ error = setxattr(&path, name, value, size, flags);
56023 mnt_drop_write(path.mnt);
56024 }
56025 path_put(&path);
56026@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56027 const void __user *,value, size_t, size, int, flags)
56028 {
56029 struct fd f = fdget(fd);
56030- struct dentry *dentry;
56031 int error = -EBADF;
56032
56033 if (!f.file)
56034 return error;
56035- dentry = f.file->f_path.dentry;
56036- audit_inode(NULL, dentry, 0);
56037+ audit_inode(NULL, f.file->f_path.dentry, 0);
56038 error = mnt_want_write_file(f.file);
56039 if (!error) {
56040- error = setxattr(dentry, name, value, size, flags);
56041+ error = setxattr(&f.file->f_path, name, value, size, flags);
56042 mnt_drop_write_file(f.file);
56043 }
56044 fdput(f);
56045diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56046index 9fbea87..6b19972 100644
56047--- a/fs/xattr_acl.c
56048+++ b/fs/xattr_acl.c
56049@@ -76,8 +76,8 @@ struct posix_acl *
56050 posix_acl_from_xattr(struct user_namespace *user_ns,
56051 const void *value, size_t size)
56052 {
56053- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
56054- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
56055+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
56056+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
56057 int count;
56058 struct posix_acl *acl;
56059 struct posix_acl_entry *acl_e;
56060diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
56061index 572a858..12a9b0d 100644
56062--- a/fs/xfs/xfs_bmap.c
56063+++ b/fs/xfs/xfs_bmap.c
56064@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
56065 int nmap,
56066 int ret_nmap);
56067 #else
56068-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
56069+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
56070 #endif /* DEBUG */
56071
56072 STATIC int
56073diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
56074index 1b9fc3e..e1bdde0 100644
56075--- a/fs/xfs/xfs_dir2_sf.c
56076+++ b/fs/xfs/xfs_dir2_sf.c
56077@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
56078 }
56079
56080 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
56081- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56082+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
56083+ char name[sfep->namelen];
56084+ memcpy(name, sfep->name, sfep->namelen);
56085+ if (filldir(dirent, name, sfep->namelen,
56086+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
56087+ *offset = off & 0x7fffffff;
56088+ return 0;
56089+ }
56090+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56091 off & 0x7fffffff, ino, DT_UNKNOWN)) {
56092 *offset = off & 0x7fffffff;
56093 return 0;
56094diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
56095index c1c3ef8..0952438 100644
56096--- a/fs/xfs/xfs_ioctl.c
56097+++ b/fs/xfs/xfs_ioctl.c
56098@@ -127,7 +127,7 @@ xfs_find_handle(
56099 }
56100
56101 error = -EFAULT;
56102- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
56103+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
56104 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
56105 goto out_put;
56106
56107diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
56108index d82efaa..0904a8e 100644
56109--- a/fs/xfs/xfs_iops.c
56110+++ b/fs/xfs/xfs_iops.c
56111@@ -395,7 +395,7 @@ xfs_vn_put_link(
56112 struct nameidata *nd,
56113 void *p)
56114 {
56115- char *s = nd_get_link(nd);
56116+ const char *s = nd_get_link(nd);
56117
56118 if (!IS_ERR(s))
56119 kfree(s);
56120diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
56121new file mode 100644
56122index 0000000..92247e4
56123--- /dev/null
56124+++ b/grsecurity/Kconfig
56125@@ -0,0 +1,1021 @@
56126+#
56127+# grecurity configuration
56128+#
56129+menu "Memory Protections"
56130+depends on GRKERNSEC
56131+
56132+config GRKERNSEC_KMEM
56133+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
56134+ default y if GRKERNSEC_CONFIG_AUTO
56135+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
56136+ help
56137+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
56138+ be written to or read from to modify or leak the contents of the running
56139+ kernel. /dev/port will also not be allowed to be opened and support
56140+ for /dev/cpu/*/msr will be removed. If you have module
56141+ support disabled, enabling this will close up five ways that are
56142+ currently used to insert malicious code into the running kernel.
56143+
56144+ Even with all these features enabled, we still highly recommend that
56145+ you use the RBAC system, as it is still possible for an attacker to
56146+ modify the running kernel through privileged I/O granted by ioperm/iopl.
56147+
56148+ If you are not using XFree86, you may be able to stop this additional
56149+ case by enabling the 'Disable privileged I/O' option. Though nothing
56150+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
56151+ but only to video memory, which is the only writing we allow in this
56152+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
56153+ not be allowed to mprotect it with PROT_WRITE later.
56154+ Enabling this feature will prevent the "cpupower" and "powertop" tools
56155+ from working.
56156+
56157+ It is highly recommended that you say Y here if you meet all the
56158+ conditions above.
56159+
56160+config GRKERNSEC_VM86
56161+ bool "Restrict VM86 mode"
56162+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56163+ depends on X86_32
56164+
56165+ help
56166+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
56167+ make use of a special execution mode on 32bit x86 processors called
56168+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
56169+ video cards and will still work with this option enabled. The purpose
56170+ of the option is to prevent exploitation of emulation errors in
56171+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
56172+ Nearly all users should be able to enable this option.
56173+
56174+config GRKERNSEC_IO
56175+ bool "Disable privileged I/O"
56176+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56177+ depends on X86
56178+ select RTC_CLASS
56179+ select RTC_INTF_DEV
56180+ select RTC_DRV_CMOS
56181+
56182+ help
56183+ If you say Y here, all ioperm and iopl calls will return an error.
56184+ Ioperm and iopl can be used to modify the running kernel.
56185+ Unfortunately, some programs need this access to operate properly,
56186+ the most notable of which are XFree86 and hwclock. hwclock can be
56187+ remedied by having RTC support in the kernel, so real-time
56188+ clock support is enabled if this option is enabled, to ensure
56189+ that hwclock operates correctly. XFree86 still will not
56190+ operate correctly with this option enabled, so DO NOT CHOOSE Y
56191+ IF YOU USE XFree86. If you use XFree86 and you still want to
56192+ protect your kernel against modification, use the RBAC system.
56193+
56194+config GRKERNSEC_JIT_HARDEN
56195+ bool "Harden BPF JIT against spray attacks"
56196+ default y if GRKERNSEC_CONFIG_AUTO
56197+ depends on BPF_JIT
56198+ help
56199+ If you say Y here, the native code generated by the kernel's Berkeley
56200+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
56201+ attacks that attempt to fit attacker-beneficial instructions in
56202+ 32bit immediate fields of JIT-generated native instructions. The
56203+ attacker will generally aim to cause an unintended instruction sequence
56204+ of JIT-generated native code to execute by jumping into the middle of
56205+ a generated instruction. This feature effectively randomizes the 32bit
56206+ immediate constants present in the generated code to thwart such attacks.
56207+
56208+ If you're using KERNEXEC, it's recommended that you enable this option
56209+ to supplement the hardening of the kernel.
56210+
56211+config GRKERNSEC_RAND_THREADSTACK
56212+ bool "Insert random gaps between thread stacks"
56213+ default y if GRKERNSEC_CONFIG_AUTO
56214+ depends on PAX_RANDMMAP && !PPC
56215+ help
56216+ If you say Y here, a random-sized gap will be enforced between allocated
56217+ thread stacks. Glibc's NPTL and other threading libraries that
56218+ pass MAP_STACK to the kernel for thread stack allocation are supported.
56219+ The implementation currently provides 8 bits of entropy for the gap.
56220+
56221+ Many distributions do not compile threaded remote services with the
56222+ -fstack-check argument to GCC, causing the variable-sized stack-based
56223+ allocator, alloca(), to not probe the stack on allocation. This
56224+ permits an unbounded alloca() to skip over any guard page and potentially
56225+ modify another thread's stack reliably. An enforced random gap
56226+ reduces the reliability of such an attack and increases the chance
56227+ that such a read/write to another thread's stack instead lands in
56228+ an unmapped area, causing a crash and triggering grsecurity's
56229+ anti-bruteforcing logic.
56230+
56231+config GRKERNSEC_PROC_MEMMAP
56232+ bool "Harden ASLR against information leaks and entropy reduction"
56233+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
56234+ depends on PAX_NOEXEC || PAX_ASLR
56235+ help
56236+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
56237+ give no information about the addresses of its mappings if
56238+ PaX features that rely on random addresses are enabled on the task.
56239+ In addition to sanitizing this information and disabling other
56240+ dangerous sources of information, this option causes reads of sensitive
56241+ /proc/<pid> entries where the file descriptor was opened in a different
56242+ task than the one performing the read. Such attempts are logged.
56243+ This option also limits argv/env strings for suid/sgid binaries
56244+ to 512KB to prevent a complete exhaustion of the stack entropy provided
56245+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
56246+ binaries to prevent alternative mmap layouts from being abused.
56247+
56248+ If you use PaX it is essential that you say Y here as it closes up
56249+ several holes that make full ASLR useless locally.
56250+
56251+config GRKERNSEC_BRUTE
56252+ bool "Deter exploit bruteforcing"
56253+ default y if GRKERNSEC_CONFIG_AUTO
56254+ help
56255+ If you say Y here, attempts to bruteforce exploits against forking
56256+ daemons such as apache or sshd, as well as against suid/sgid binaries
56257+ will be deterred. When a child of a forking daemon is killed by PaX
56258+ or crashes due to an illegal instruction or other suspicious signal,
56259+ the parent process will be delayed 30 seconds upon every subsequent
56260+ fork until the administrator is able to assess the situation and
56261+ restart the daemon.
56262+ In the suid/sgid case, the attempt is logged, the user has all their
56263+ processes terminated, and they are prevented from executing any further
56264+ processes for 15 minutes.
56265+ It is recommended that you also enable signal logging in the auditing
56266+ section so that logs are generated when a process triggers a suspicious
56267+ signal.
56268+ If the sysctl option is enabled, a sysctl option with name
56269+ "deter_bruteforce" is created.
56270+
56271+
56272+config GRKERNSEC_MODHARDEN
56273+ bool "Harden module auto-loading"
56274+ default y if GRKERNSEC_CONFIG_AUTO
56275+ depends on MODULES
56276+ help
56277+ If you say Y here, module auto-loading in response to use of some
56278+ feature implemented by an unloaded module will be restricted to
56279+ root users. Enabling this option helps defend against attacks
56280+ by unprivileged users who abuse the auto-loading behavior to
56281+ cause a vulnerable module to load that is then exploited.
56282+
56283+ If this option prevents a legitimate use of auto-loading for a
56284+ non-root user, the administrator can execute modprobe manually
56285+ with the exact name of the module mentioned in the alert log.
56286+ Alternatively, the administrator can add the module to the list
56287+ of modules loaded at boot by modifying init scripts.
56288+
56289+ Modification of init scripts will most likely be needed on
56290+ Ubuntu servers with encrypted home directory support enabled,
56291+ as the first non-root user logging in will cause the ecb(aes),
56292+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
56293+
56294+config GRKERNSEC_HIDESYM
56295+ bool "Hide kernel symbols"
56296+ default y if GRKERNSEC_CONFIG_AUTO
56297+ select PAX_USERCOPY_SLABS
56298+ help
56299+ If you say Y here, getting information on loaded modules, and
56300+ displaying all kernel symbols through a syscall will be restricted
56301+ to users with CAP_SYS_MODULE. For software compatibility reasons,
56302+ /proc/kallsyms will be restricted to the root user. The RBAC
56303+ system can hide that entry even from root.
56304+
56305+ This option also prevents leaking of kernel addresses through
56306+ several /proc entries.
56307+
56308+ Note that this option is only effective provided the following
56309+ conditions are met:
56310+ 1) The kernel using grsecurity is not precompiled by some distribution
56311+ 2) You have also enabled GRKERNSEC_DMESG
56312+ 3) You are using the RBAC system and hiding other files such as your
56313+ kernel image and System.map. Alternatively, enabling this option
56314+ causes the permissions on /boot, /lib/modules, and the kernel
56315+ source directory to change at compile time to prevent
56316+ reading by non-root users.
56317+ If the above conditions are met, this option will aid in providing a
56318+ useful protection against local kernel exploitation of overflows
56319+ and arbitrary read/write vulnerabilities.
56320+
56321+config GRKERNSEC_KERN_LOCKOUT
56322+ bool "Active kernel exploit response"
56323+ default y if GRKERNSEC_CONFIG_AUTO
56324+ depends on X86 || ARM || PPC || SPARC
56325+ help
56326+ If you say Y here, when a PaX alert is triggered due to suspicious
56327+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
56328+ or an OOPS occurs due to bad memory accesses, instead of just
56329+ terminating the offending process (and potentially allowing
56330+ a subsequent exploit from the same user), we will take one of two
56331+ actions:
56332+ If the user was root, we will panic the system
56333+ If the user was non-root, we will log the attempt, terminate
56334+ all processes owned by the user, then prevent them from creating
56335+ any new processes until the system is restarted
56336+ This deters repeated kernel exploitation/bruteforcing attempts
56337+ and is useful for later forensics.
56338+
56339+endmenu
56340+menu "Role Based Access Control Options"
56341+depends on GRKERNSEC
56342+
56343+config GRKERNSEC_RBAC_DEBUG
56344+ bool
56345+
56346+config GRKERNSEC_NO_RBAC
56347+ bool "Disable RBAC system"
56348+ help
56349+ If you say Y here, the /dev/grsec device will be removed from the kernel,
56350+ preventing the RBAC system from being enabled. You should only say Y
56351+ here if you have no intention of using the RBAC system, so as to prevent
56352+ an attacker with root access from misusing the RBAC system to hide files
56353+ and processes when loadable module support and /dev/[k]mem have been
56354+ locked down.
56355+
56356+config GRKERNSEC_ACL_HIDEKERN
56357+ bool "Hide kernel processes"
56358+ help
56359+ If you say Y here, all kernel threads will be hidden to all
56360+ processes but those whose subject has the "view hidden processes"
56361+ flag.
56362+
56363+config GRKERNSEC_ACL_MAXTRIES
56364+ int "Maximum tries before password lockout"
56365+ default 3
56366+ help
56367+ This option enforces the maximum number of times a user can attempt
56368+ to authorize themselves with the grsecurity RBAC system before being
56369+ denied the ability to attempt authorization again for a specified time.
56370+ The lower the number, the harder it will be to brute-force a password.
56371+
56372+config GRKERNSEC_ACL_TIMEOUT
56373+ int "Time to wait after max password tries, in seconds"
56374+ default 30
56375+ help
56376+ This option specifies the time the user must wait after attempting to
56377+ authorize to the RBAC system with the maximum number of invalid
56378+ passwords. The higher the number, the harder it will be to brute-force
56379+ a password.
56380+
56381+endmenu
56382+menu "Filesystem Protections"
56383+depends on GRKERNSEC
56384+
56385+config GRKERNSEC_PROC
56386+ bool "Proc restrictions"
56387+ default y if GRKERNSEC_CONFIG_AUTO
56388+ help
56389+ If you say Y here, the permissions of the /proc filesystem
56390+ will be altered to enhance system security and privacy. You MUST
56391+ choose either a user only restriction or a user and group restriction.
56392+ Depending upon the option you choose, you can either restrict users to
56393+ see only the processes they themselves run, or choose a group that can
56394+ view all processes and files normally restricted to root if you choose
56395+ the "restrict to user only" option. NOTE: If you're running identd or
56396+ ntpd as a non-root user, you will have to run it as the group you
56397+ specify here.
56398+
56399+config GRKERNSEC_PROC_USER
56400+ bool "Restrict /proc to user only"
56401+ depends on GRKERNSEC_PROC
56402+ help
56403+ If you say Y here, non-root users will only be able to view their own
56404+ processes, and restricts them from viewing network-related information,
56405+ and viewing kernel symbol and module information.
56406+
56407+config GRKERNSEC_PROC_USERGROUP
56408+ bool "Allow special group"
56409+ default y if GRKERNSEC_CONFIG_AUTO
56410+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56411+ help
56412+ If you say Y here, you will be able to select a group that will be
56413+ able to view all processes and network-related information. If you've
56414+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56415+ remain hidden. This option is useful if you want to run identd as
56416+ a non-root user. The group you select may also be chosen at boot time
56417+ via "grsec_proc_gid=" on the kernel commandline.
56418+
56419+config GRKERNSEC_PROC_GID
56420+ int "GID for special group"
56421+ depends on GRKERNSEC_PROC_USERGROUP
56422+ default 1001
56423+
56424+config GRKERNSEC_PROC_ADD
56425+ bool "Additional restrictions"
56426+ default y if GRKERNSEC_CONFIG_AUTO
56427+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56428+ help
56429+ If you say Y here, additional restrictions will be placed on
56430+ /proc that keep normal users from viewing device information and
56431+ slabinfo information that could be useful for exploits.
56432+
56433+config GRKERNSEC_LINK
56434+ bool "Linking restrictions"
56435+ default y if GRKERNSEC_CONFIG_AUTO
56436+ help
56437+ If you say Y here, /tmp race exploits will be prevented, since users
56438+ will no longer be able to follow symlinks owned by other users in
56439+ world-writable +t directories (e.g. /tmp), unless the owner of the
56440+ symlink is the owner of the directory. users will also not be
56441+ able to hardlink to files they do not own. If the sysctl option is
56442+ enabled, a sysctl option with name "linking_restrictions" is created.
56443+
56444+config GRKERNSEC_SYMLINKOWN
56445+ bool "Kernel-enforced SymlinksIfOwnerMatch"
56446+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56447+ help
56448+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
56449+ that prevents it from being used as a security feature. As Apache
56450+ verifies the symlink by performing a stat() against the target of
56451+ the symlink before it is followed, an attacker can setup a symlink
56452+ to point to a same-owned file, then replace the symlink with one
56453+ that targets another user's file just after Apache "validates" the
56454+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
56455+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56456+ will be in place for the group you specify. If the sysctl option
56457+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
56458+ created.
56459+
56460+config GRKERNSEC_SYMLINKOWN_GID
56461+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56462+ depends on GRKERNSEC_SYMLINKOWN
56463+ default 1006
56464+ help
56465+ Setting this GID determines what group kernel-enforced
56466+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56467+ is enabled, a sysctl option with name "symlinkown_gid" is created.
56468+
56469+config GRKERNSEC_FIFO
56470+ bool "FIFO restrictions"
56471+ default y if GRKERNSEC_CONFIG_AUTO
56472+ help
56473+ If you say Y here, users will not be able to write to FIFOs they don't
56474+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56475+ the FIFO is the same owner of the directory it's held in. If the sysctl
56476+ option is enabled, a sysctl option with name "fifo_restrictions" is
56477+ created.
56478+
56479+config GRKERNSEC_SYSFS_RESTRICT
56480+ bool "Sysfs/debugfs restriction"
56481+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56482+ depends on SYSFS
56483+ help
56484+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56485+ any filesystem normally mounted under it (e.g. debugfs) will be
56486+ mostly accessible only by root. These filesystems generally provide access
56487+ to hardware and debug information that isn't appropriate for unprivileged
56488+ users of the system. Sysfs and debugfs have also become a large source
56489+ of new vulnerabilities, ranging from infoleaks to local compromise.
56490+ There has been very little oversight with an eye toward security involved
56491+ in adding new exporters of information to these filesystems, so their
56492+ use is discouraged.
56493+ For reasons of compatibility, a few directories have been whitelisted
56494+ for access by non-root users:
56495+ /sys/fs/selinux
56496+ /sys/fs/fuse
56497+ /sys/devices/system/cpu
56498+
56499+config GRKERNSEC_ROFS
56500+ bool "Runtime read-only mount protection"
56501+ help
56502+ If you say Y here, a sysctl option with name "romount_protect" will
56503+ be created. By setting this option to 1 at runtime, filesystems
56504+ will be protected in the following ways:
56505+ * No new writable mounts will be allowed
56506+ * Existing read-only mounts won't be able to be remounted read/write
56507+ * Write operations will be denied on all block devices
56508+ This option acts independently of grsec_lock: once it is set to 1,
56509+ it cannot be turned off. Therefore, please be mindful of the resulting
56510+ behavior if this option is enabled in an init script on a read-only
56511+ filesystem. This feature is mainly intended for secure embedded systems.
56512+
56513+config GRKERNSEC_DEVICE_SIDECHANNEL
56514+ bool "Eliminate stat/notify-based device sidechannels"
56515+ default y if GRKERNSEC_CONFIG_AUTO
56516+ help
56517+ If you say Y here, timing analyses on block or character
56518+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56519+ will be thwarted for unprivileged users. If a process without
56520+ CAP_MKNOD stats such a device, the last access and last modify times
56521+ will match the device's create time. No access or modify events
56522+ will be triggered through inotify/dnotify/fanotify for such devices.
56523+ This feature will prevent attacks that may at a minimum
56524+ allow an attacker to determine the administrator's password length.
56525+
56526+config GRKERNSEC_CHROOT
56527+ bool "Chroot jail restrictions"
56528+ default y if GRKERNSEC_CONFIG_AUTO
56529+ help
56530+ If you say Y here, you will be able to choose several options that will
56531+ make breaking out of a chrooted jail much more difficult. If you
56532+ encounter no software incompatibilities with the following options, it
56533+ is recommended that you enable each one.
56534+
56535+config GRKERNSEC_CHROOT_MOUNT
56536+ bool "Deny mounts"
56537+ default y if GRKERNSEC_CONFIG_AUTO
56538+ depends on GRKERNSEC_CHROOT
56539+ help
56540+ If you say Y here, processes inside a chroot will not be able to
56541+ mount or remount filesystems. If the sysctl option is enabled, a
56542+ sysctl option with name "chroot_deny_mount" is created.
56543+
56544+config GRKERNSEC_CHROOT_DOUBLE
56545+ bool "Deny double-chroots"
56546+ default y if GRKERNSEC_CONFIG_AUTO
56547+ depends on GRKERNSEC_CHROOT
56548+ help
56549+ If you say Y here, processes inside a chroot will not be able to chroot
56550+ again outside the chroot. This is a widely used method of breaking
56551+ out of a chroot jail and should not be allowed. If the sysctl
56552+ option is enabled, a sysctl option with name
56553+ "chroot_deny_chroot" is created.
56554+
56555+config GRKERNSEC_CHROOT_PIVOT
56556+ bool "Deny pivot_root in chroot"
56557+ default y if GRKERNSEC_CONFIG_AUTO
56558+ depends on GRKERNSEC_CHROOT
56559+ help
56560+ If you say Y here, processes inside a chroot will not be able to use
56561+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56562+ works similar to chroot in that it changes the root filesystem. This
56563+ function could be misused in a chrooted process to attempt to break out
56564+ of the chroot, and therefore should not be allowed. If the sysctl
56565+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56566+ created.
56567+
56568+config GRKERNSEC_CHROOT_CHDIR
56569+ bool "Enforce chdir(\"/\") on all chroots"
56570+ default y if GRKERNSEC_CONFIG_AUTO
56571+ depends on GRKERNSEC_CHROOT
56572+ help
56573+ If you say Y here, the current working directory of all newly-chrooted
56574+ applications will be set to the the root directory of the chroot.
56575+ The man page on chroot(2) states:
56576+ Note that this call does not change the current working
56577+ directory, so that `.' can be outside the tree rooted at
56578+ `/'. In particular, the super-user can escape from a
56579+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56580+
56581+ It is recommended that you say Y here, since it's not known to break
56582+ any software. If the sysctl option is enabled, a sysctl option with
56583+ name "chroot_enforce_chdir" is created.
56584+
56585+config GRKERNSEC_CHROOT_CHMOD
56586+ bool "Deny (f)chmod +s"
56587+ default y if GRKERNSEC_CONFIG_AUTO
56588+ depends on GRKERNSEC_CHROOT
56589+ help
56590+ If you say Y here, processes inside a chroot will not be able to chmod
56591+ or fchmod files to make them have suid or sgid bits. This protects
56592+ against another published method of breaking a chroot. If the sysctl
56593+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56594+ created.
56595+
56596+config GRKERNSEC_CHROOT_FCHDIR
56597+ bool "Deny fchdir out of chroot"
56598+ default y if GRKERNSEC_CONFIG_AUTO
56599+ depends on GRKERNSEC_CHROOT
56600+ help
56601+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56602+ to a file descriptor of the chrooting process that points to a directory
56603+ outside the filesystem will be stopped. If the sysctl option
56604+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56605+
56606+config GRKERNSEC_CHROOT_MKNOD
56607+ bool "Deny mknod"
56608+ default y if GRKERNSEC_CONFIG_AUTO
56609+ depends on GRKERNSEC_CHROOT
56610+ help
56611+ If you say Y here, processes inside a chroot will not be allowed to
56612+ mknod. The problem with using mknod inside a chroot is that it
56613+ would allow an attacker to create a device entry that is the same
56614+ as one on the physical root of your system, which could range from
56615+ anything from the console device to a device for your harddrive (which
56616+ they could then use to wipe the drive or steal data). It is recommended
56617+ that you say Y here, unless you run into software incompatibilities.
56618+ If the sysctl option is enabled, a sysctl option with name
56619+ "chroot_deny_mknod" is created.
56620+
56621+config GRKERNSEC_CHROOT_SHMAT
56622+ bool "Deny shmat() out of chroot"
56623+ default y if GRKERNSEC_CONFIG_AUTO
56624+ depends on GRKERNSEC_CHROOT
56625+ help
56626+ If you say Y here, processes inside a chroot will not be able to attach
56627+ to shared memory segments that were created outside of the chroot jail.
56628+ It is recommended that you say Y here. If the sysctl option is enabled,
56629+ a sysctl option with name "chroot_deny_shmat" is created.
56630+
56631+config GRKERNSEC_CHROOT_UNIX
56632+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
56633+ default y if GRKERNSEC_CONFIG_AUTO
56634+ depends on GRKERNSEC_CHROOT
56635+ help
56636+ If you say Y here, processes inside a chroot will not be able to
56637+ connect to abstract (meaning not belonging to a filesystem) Unix
56638+ domain sockets that were bound outside of a chroot. It is recommended
56639+ that you say Y here. If the sysctl option is enabled, a sysctl option
56640+ with name "chroot_deny_unix" is created.
56641+
56642+config GRKERNSEC_CHROOT_FINDTASK
56643+ bool "Protect outside processes"
56644+ default y if GRKERNSEC_CONFIG_AUTO
56645+ depends on GRKERNSEC_CHROOT
56646+ help
56647+ If you say Y here, processes inside a chroot will not be able to
56648+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56649+ getsid, or view any process outside of the chroot. If the sysctl
56650+ option is enabled, a sysctl option with name "chroot_findtask" is
56651+ created.
56652+
56653+config GRKERNSEC_CHROOT_NICE
56654+ bool "Restrict priority changes"
56655+ default y if GRKERNSEC_CONFIG_AUTO
56656+ depends on GRKERNSEC_CHROOT
56657+ help
56658+ If you say Y here, processes inside a chroot will not be able to raise
56659+ the priority of processes in the chroot, or alter the priority of
56660+ processes outside the chroot. This provides more security than simply
56661+ removing CAP_SYS_NICE from the process' capability set. If the
56662+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56663+ is created.
56664+
56665+config GRKERNSEC_CHROOT_SYSCTL
56666+ bool "Deny sysctl writes"
56667+ default y if GRKERNSEC_CONFIG_AUTO
56668+ depends on GRKERNSEC_CHROOT
56669+ help
56670+ If you say Y here, an attacker in a chroot will not be able to
56671+ write to sysctl entries, either by sysctl(2) or through a /proc
56672+ interface. It is strongly recommended that you say Y here. If the
56673+ sysctl option is enabled, a sysctl option with name
56674+ "chroot_deny_sysctl" is created.
56675+
56676+config GRKERNSEC_CHROOT_CAPS
56677+ bool "Capability restrictions"
56678+ default y if GRKERNSEC_CONFIG_AUTO
56679+ depends on GRKERNSEC_CHROOT
56680+ help
56681+ If you say Y here, the capabilities on all processes within a
56682+ chroot jail will be lowered to stop module insertion, raw i/o,
56683+ system and net admin tasks, rebooting the system, modifying immutable
56684+ files, modifying IPC owned by another, and changing the system time.
56685+ This is left an option because it can break some apps. Disable this
56686+ if your chrooted apps are having problems performing those kinds of
56687+ tasks. If the sysctl option is enabled, a sysctl option with
56688+ name "chroot_caps" is created.
56689+
56690+endmenu
56691+menu "Kernel Auditing"
56692+depends on GRKERNSEC
56693+
56694+config GRKERNSEC_AUDIT_GROUP
56695+ bool "Single group for auditing"
56696+ help
56697+ If you say Y here, the exec and chdir logging features will only operate
56698+ on a group you specify. This option is recommended if you only want to
56699+ watch certain users instead of having a large amount of logs from the
56700+ entire system. If the sysctl option is enabled, a sysctl option with
56701+ name "audit_group" is created.
56702+
56703+config GRKERNSEC_AUDIT_GID
56704+ int "GID for auditing"
56705+ depends on GRKERNSEC_AUDIT_GROUP
56706+ default 1007
56707+
56708+config GRKERNSEC_EXECLOG
56709+ bool "Exec logging"
56710+ help
56711+ If you say Y here, all execve() calls will be logged (since the
56712+ other exec*() calls are frontends to execve(), all execution
56713+ will be logged). Useful for shell-servers that like to keep track
56714+ of their users. If the sysctl option is enabled, a sysctl option with
56715+ name "exec_logging" is created.
56716+ WARNING: This option when enabled will produce a LOT of logs, especially
56717+ on an active system.
56718+
56719+config GRKERNSEC_RESLOG
56720+ bool "Resource logging"
56721+ default y if GRKERNSEC_CONFIG_AUTO
56722+ help
56723+ If you say Y here, all attempts to overstep resource limits will
56724+ be logged with the resource name, the requested size, and the current
56725+ limit. It is highly recommended that you say Y here. If the sysctl
56726+ option is enabled, a sysctl option with name "resource_logging" is
56727+ created. If the RBAC system is enabled, the sysctl value is ignored.
56728+
56729+config GRKERNSEC_CHROOT_EXECLOG
56730+ bool "Log execs within chroot"
56731+ help
56732+ If you say Y here, all executions inside a chroot jail will be logged
56733+ to syslog. This can cause a large amount of logs if certain
56734+ applications (eg. djb's daemontools) are installed on the system, and
56735+ is therefore left as an option. If the sysctl option is enabled, a
56736+ sysctl option with name "chroot_execlog" is created.
56737+
56738+config GRKERNSEC_AUDIT_PTRACE
56739+ bool "Ptrace logging"
56740+ help
56741+ If you say Y here, all attempts to attach to a process via ptrace
56742+ will be logged. If the sysctl option is enabled, a sysctl option
56743+ with name "audit_ptrace" is created.
56744+
56745+config GRKERNSEC_AUDIT_CHDIR
56746+ bool "Chdir logging"
56747+ help
56748+ If you say Y here, all chdir() calls will be logged. If the sysctl
56749+ option is enabled, a sysctl option with name "audit_chdir" is created.
56750+
56751+config GRKERNSEC_AUDIT_MOUNT
56752+ bool "(Un)Mount logging"
56753+ help
56754+ If you say Y here, all mounts and unmounts will be logged. If the
56755+ sysctl option is enabled, a sysctl option with name "audit_mount" is
56756+ created.
56757+
56758+config GRKERNSEC_SIGNAL
56759+ bool "Signal logging"
56760+ default y if GRKERNSEC_CONFIG_AUTO
56761+ help
56762+ If you say Y here, certain important signals will be logged, such as
56763+ SIGSEGV, which will as a result inform you of when a error in a program
56764+ occurred, which in some cases could mean a possible exploit attempt.
56765+ If the sysctl option is enabled, a sysctl option with name
56766+ "signal_logging" is created.
56767+
56768+config GRKERNSEC_FORKFAIL
56769+ bool "Fork failure logging"
56770+ help
56771+ If you say Y here, all failed fork() attempts will be logged.
56772+ This could suggest a fork bomb, or someone attempting to overstep
56773+ their process limit. If the sysctl option is enabled, a sysctl option
56774+ with name "forkfail_logging" is created.
56775+
56776+config GRKERNSEC_TIME
56777+ bool "Time change logging"
56778+ default y if GRKERNSEC_CONFIG_AUTO
56779+ help
56780+ If you say Y here, any changes of the system clock will be logged.
56781+ If the sysctl option is enabled, a sysctl option with name
56782+ "timechange_logging" is created.
56783+
56784+config GRKERNSEC_PROC_IPADDR
56785+ bool "/proc/<pid>/ipaddr support"
56786+ default y if GRKERNSEC_CONFIG_AUTO
56787+ help
56788+ If you say Y here, a new entry will be added to each /proc/<pid>
56789+ directory that contains the IP address of the person using the task.
56790+ The IP is carried across local TCP and AF_UNIX stream sockets.
56791+ This information can be useful for IDS/IPSes to perform remote response
56792+ to a local attack. The entry is readable by only the owner of the
56793+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56794+ the RBAC system), and thus does not create privacy concerns.
56795+
56796+config GRKERNSEC_RWXMAP_LOG
56797+ bool 'Denied RWX mmap/mprotect logging'
56798+ default y if GRKERNSEC_CONFIG_AUTO
56799+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56800+ help
56801+ If you say Y here, calls to mmap() and mprotect() with explicit
56802+ usage of PROT_WRITE and PROT_EXEC together will be logged when
56803+ denied by the PAX_MPROTECT feature. If the sysctl option is
56804+ enabled, a sysctl option with name "rwxmap_logging" is created.
56805+
56806+config GRKERNSEC_AUDIT_TEXTREL
56807+ bool 'ELF text relocations logging (READ HELP)'
56808+ depends on PAX_MPROTECT
56809+ help
56810+ If you say Y here, text relocations will be logged with the filename
56811+ of the offending library or binary. The purpose of the feature is
56812+ to help Linux distribution developers get rid of libraries and
56813+ binaries that need text relocations which hinder the future progress
56814+ of PaX. Only Linux distribution developers should say Y here, and
56815+ never on a production machine, as this option creates an information
56816+ leak that could aid an attacker in defeating the randomization of
56817+ a single memory region. If the sysctl option is enabled, a sysctl
56818+ option with name "audit_textrel" is created.
56819+
56820+endmenu
56821+
56822+menu "Executable Protections"
56823+depends on GRKERNSEC
56824+
56825+config GRKERNSEC_DMESG
56826+ bool "Dmesg(8) restriction"
56827+ default y if GRKERNSEC_CONFIG_AUTO
56828+ help
56829+ If you say Y here, non-root users will not be able to use dmesg(8)
56830+ to view the contents of the kernel's circular log buffer.
56831+ The kernel's log buffer often contains kernel addresses and other
56832+ identifying information useful to an attacker in fingerprinting a
56833+ system for a targeted exploit.
56834+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
56835+ created.
56836+
56837+config GRKERNSEC_HARDEN_PTRACE
56838+ bool "Deter ptrace-based process snooping"
56839+ default y if GRKERNSEC_CONFIG_AUTO
56840+ help
56841+ If you say Y here, TTY sniffers and other malicious monitoring
56842+ programs implemented through ptrace will be defeated. If you
56843+ have been using the RBAC system, this option has already been
56844+ enabled for several years for all users, with the ability to make
56845+ fine-grained exceptions.
56846+
56847+ This option only affects the ability of non-root users to ptrace
56848+ processes that are not a descendent of the ptracing process.
56849+ This means that strace ./binary and gdb ./binary will still work,
56850+ but attaching to arbitrary processes will not. If the sysctl
56851+ option is enabled, a sysctl option with name "harden_ptrace" is
56852+ created.
56853+
56854+config GRKERNSEC_PTRACE_READEXEC
56855+ bool "Require read access to ptrace sensitive binaries"
56856+ default y if GRKERNSEC_CONFIG_AUTO
56857+ help
56858+ If you say Y here, unprivileged users will not be able to ptrace unreadable
56859+ binaries. This option is useful in environments that
56860+ remove the read bits (e.g. file mode 4711) from suid binaries to
56861+ prevent infoleaking of their contents. This option adds
56862+ consistency to the use of that file mode, as the binary could normally
56863+ be read out when run without privileges while ptracing.
56864+
56865+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56866+ is created.
56867+
56868+config GRKERNSEC_SETXID
56869+ bool "Enforce consistent multithreaded privileges"
56870+ default y if GRKERNSEC_CONFIG_AUTO
56871+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56872+ help
56873+ If you say Y here, a change from a root uid to a non-root uid
56874+ in a multithreaded application will cause the resulting uids,
56875+ gids, supplementary groups, and capabilities in that thread
56876+ to be propagated to the other threads of the process. In most
56877+ cases this is unnecessary, as glibc will emulate this behavior
56878+ on behalf of the application. Other libcs do not act in the
56879+ same way, allowing the other threads of the process to continue
56880+ running with root privileges. If the sysctl option is enabled,
56881+ a sysctl option with name "consistent_setxid" is created.
56882+
56883+config GRKERNSEC_TPE
56884+ bool "Trusted Path Execution (TPE)"
56885+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56886+ help
56887+ If you say Y here, you will be able to choose a gid to add to the
56888+ supplementary groups of users you want to mark as "untrusted."
56889+ These users will not be able to execute any files that are not in
56890+ root-owned directories writable only by root. If the sysctl option
56891+ is enabled, a sysctl option with name "tpe" is created.
56892+
56893+config GRKERNSEC_TPE_ALL
56894+ bool "Partially restrict all non-root users"
56895+ depends on GRKERNSEC_TPE
56896+ help
56897+ If you say Y here, all non-root users will be covered under
56898+ a weaker TPE restriction. This is separate from, and in addition to,
56899+ the main TPE options that you have selected elsewhere. Thus, if a
56900+ "trusted" GID is chosen, this restriction applies to even that GID.
56901+ Under this restriction, all non-root users will only be allowed to
56902+ execute files in directories they own that are not group or
56903+ world-writable, or in directories owned by root and writable only by
56904+ root. If the sysctl option is enabled, a sysctl option with name
56905+ "tpe_restrict_all" is created.
56906+
56907+config GRKERNSEC_TPE_INVERT
56908+ bool "Invert GID option"
56909+ depends on GRKERNSEC_TPE
56910+ help
56911+ If you say Y here, the group you specify in the TPE configuration will
56912+ decide what group TPE restrictions will be *disabled* for. This
56913+ option is useful if you want TPE restrictions to be applied to most
56914+ users on the system. If the sysctl option is enabled, a sysctl option
56915+ with name "tpe_invert" is created. Unlike other sysctl options, this
56916+ entry will default to on for backward-compatibility.
56917+
56918+config GRKERNSEC_TPE_GID
56919+ int
56920+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56921+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56922+
56923+config GRKERNSEC_TPE_UNTRUSTED_GID
56924+ int "GID for TPE-untrusted users"
56925+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56926+ default 1005
56927+ help
56928+ Setting this GID determines what group TPE restrictions will be
56929+ *enabled* for. If the sysctl option is enabled, a sysctl option
56930+ with name "tpe_gid" is created.
56931+
56932+config GRKERNSEC_TPE_TRUSTED_GID
56933+ int "GID for TPE-trusted users"
56934+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56935+ default 1005
56936+ help
56937+ Setting this GID determines what group TPE restrictions will be
56938+ *disabled* for. If the sysctl option is enabled, a sysctl option
56939+ with name "tpe_gid" is created.
56940+
56941+endmenu
56942+menu "Network Protections"
56943+depends on GRKERNSEC
56944+
56945+config GRKERNSEC_RANDNET
56946+ bool "Larger entropy pools"
56947+ default y if GRKERNSEC_CONFIG_AUTO
56948+ help
56949+ If you say Y here, the entropy pools used for many features of Linux
56950+ and grsecurity will be doubled in size. Since several grsecurity
56951+ features use additional randomness, it is recommended that you say Y
56952+ here. Saying Y here has a similar effect as modifying
56953+ /proc/sys/kernel/random/poolsize.
56954+
56955+config GRKERNSEC_BLACKHOLE
56956+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56957+ default y if GRKERNSEC_CONFIG_AUTO
56958+ depends on NET
56959+ help
56960+ If you say Y here, neither TCP resets nor ICMP
56961+ destination-unreachable packets will be sent in response to packets
56962+ sent to ports for which no associated listening process exists.
56963+ This feature supports both IPV4 and IPV6 and exempts the
56964+ loopback interface from blackholing. Enabling this feature
56965+ makes a host more resilient to DoS attacks and reduces network
56966+ visibility against scanners.
56967+
56968+ The blackhole feature as-implemented is equivalent to the FreeBSD
56969+ blackhole feature, as it prevents RST responses to all packets, not
56970+ just SYNs. Under most application behavior this causes no
56971+ problems, but applications (like haproxy) may not close certain
56972+ connections in a way that cleanly terminates them on the remote
56973+ end, leaving the remote host in LAST_ACK state. Because of this
56974+ side-effect and to prevent intentional LAST_ACK DoSes, this
56975+ feature also adds automatic mitigation against such attacks.
56976+ The mitigation drastically reduces the amount of time a socket
56977+ can spend in LAST_ACK state. If you're using haproxy and not
56978+ all servers it connects to have this option enabled, consider
56979+ disabling this feature on the haproxy host.
56980+
56981+ If the sysctl option is enabled, two sysctl options with names
56982+ "ip_blackhole" and "lastack_retries" will be created.
56983+ While "ip_blackhole" takes the standard zero/non-zero on/off
56984+ toggle, "lastack_retries" uses the same kinds of values as
56985+ "tcp_retries1" and "tcp_retries2". The default value of 4
56986+ prevents a socket from lasting more than 45 seconds in LAST_ACK
56987+ state.
56988+
56989+config GRKERNSEC_NO_SIMULT_CONNECT
56990+ bool "Disable TCP Simultaneous Connect"
56991+ default y if GRKERNSEC_CONFIG_AUTO
56992+ depends on NET
56993+ help
56994+ If you say Y here, a feature by Willy Tarreau will be enabled that
56995+ removes a weakness in Linux's strict implementation of TCP that
56996+ allows two clients to connect to each other without either entering
56997+ a listening state. The weakness allows an attacker to easily prevent
56998+ a client from connecting to a known server provided the source port
56999+ for the connection is guessed correctly.
57000+
57001+ As the weakness could be used to prevent an antivirus or IPS from
57002+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57003+ it should be eliminated by enabling this option. Though Linux is
57004+ one of few operating systems supporting simultaneous connect, it
57005+ has no legitimate use in practice and is rarely supported by firewalls.
57006+
57007+config GRKERNSEC_SOCKET
57008+ bool "Socket restrictions"
57009+ depends on NET
57010+ help
57011+ If you say Y here, you will be able to choose from several options.
57012+ If you assign a GID on your system and add it to the supplementary
57013+ groups of users you want to restrict socket access to, this patch
57014+ will perform up to three things, based on the option(s) you choose.
57015+
57016+config GRKERNSEC_SOCKET_ALL
57017+ bool "Deny any sockets to group"
57018+ depends on GRKERNSEC_SOCKET
57019+ help
57020+ If you say Y here, you will be able to choose a GID of whose users will
57021+ be unable to connect to other hosts from your machine or run server
57022+ applications from your machine. If the sysctl option is enabled, a
57023+ sysctl option with name "socket_all" is created.
57024+
57025+config GRKERNSEC_SOCKET_ALL_GID
57026+ int "GID to deny all sockets for"
57027+ depends on GRKERNSEC_SOCKET_ALL
57028+ default 1004
57029+ help
57030+ Here you can choose the GID to disable socket access for. Remember to
57031+ add the users you want socket access disabled for to the GID
57032+ specified here. If the sysctl option is enabled, a sysctl option
57033+ with name "socket_all_gid" is created.
57034+
57035+config GRKERNSEC_SOCKET_CLIENT
57036+ bool "Deny client sockets to group"
57037+ depends on GRKERNSEC_SOCKET
57038+ help
57039+ If you say Y here, you will be able to choose a GID of whose users will
57040+ be unable to connect to other hosts from your machine, but will be
57041+ able to run servers. If this option is enabled, all users in the group
57042+ you specify will have to use passive mode when initiating ftp transfers
57043+ from the shell on your machine. If the sysctl option is enabled, a
57044+ sysctl option with name "socket_client" is created.
57045+
57046+config GRKERNSEC_SOCKET_CLIENT_GID
57047+ int "GID to deny client sockets for"
57048+ depends on GRKERNSEC_SOCKET_CLIENT
57049+ default 1003
57050+ help
57051+ Here you can choose the GID to disable client socket access for.
57052+ Remember to add the users you want client socket access disabled for to
57053+ the GID specified here. If the sysctl option is enabled, a sysctl
57054+ option with name "socket_client_gid" is created.
57055+
57056+config GRKERNSEC_SOCKET_SERVER
57057+ bool "Deny server sockets to group"
57058+ depends on GRKERNSEC_SOCKET
57059+ help
57060+ If you say Y here, you will be able to choose a GID of whose users will
57061+ be unable to run server applications from your machine. If the sysctl
57062+ option is enabled, a sysctl option with name "socket_server" is created.
57063+
57064+config GRKERNSEC_SOCKET_SERVER_GID
57065+ int "GID to deny server sockets for"
57066+ depends on GRKERNSEC_SOCKET_SERVER
57067+ default 1002
57068+ help
57069+ Here you can choose the GID to disable server socket access for.
57070+ Remember to add the users you want server socket access disabled for to
57071+ the GID specified here. If the sysctl option is enabled, a sysctl
57072+ option with name "socket_server_gid" is created.
57073+
57074+endmenu
57075+menu "Sysctl Support"
57076+depends on GRKERNSEC && SYSCTL
57077+
57078+config GRKERNSEC_SYSCTL
57079+ bool "Sysctl support"
57080+ default y if GRKERNSEC_CONFIG_AUTO
57081+ help
57082+ If you say Y here, you will be able to change the options that
57083+ grsecurity runs with at bootup, without having to recompile your
57084+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
57085+ to enable (1) or disable (0) various features. All the sysctl entries
57086+ are mutable until the "grsec_lock" entry is set to a non-zero value.
57087+ All features enabled in the kernel configuration are disabled at boot
57088+ if you do not say Y to the "Turn on features by default" option.
57089+ All options should be set at startup, and the grsec_lock entry should
57090+ be set to a non-zero value after all the options are set.
57091+ *THIS IS EXTREMELY IMPORTANT*
57092+
57093+config GRKERNSEC_SYSCTL_DISTRO
57094+ bool "Extra sysctl support for distro makers (READ HELP)"
57095+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
57096+ help
57097+ If you say Y here, additional sysctl options will be created
57098+ for features that affect processes running as root. Therefore,
57099+ it is critical when using this option that the grsec_lock entry be
57100+ enabled after boot. Only distros with prebuilt kernel packages
57101+ with this option enabled that can ensure grsec_lock is enabled
57102+ after boot should use this option.
57103+ *Failure to set grsec_lock after boot makes all grsec features
57104+ this option covers useless*
57105+
57106+ Currently this option creates the following sysctl entries:
57107+ "Disable Privileged I/O": "disable_priv_io"
57108+
57109+config GRKERNSEC_SYSCTL_ON
57110+ bool "Turn on features by default"
57111+ default y if GRKERNSEC_CONFIG_AUTO
57112+ depends on GRKERNSEC_SYSCTL
57113+ help
57114+ If you say Y here, instead of having all features enabled in the
57115+ kernel configuration disabled at boot time, the features will be
57116+ enabled at boot time. It is recommended you say Y here unless
57117+ there is some reason you would want all sysctl-tunable features to
57118+ be disabled by default. As mentioned elsewhere, it is important
57119+ to enable the grsec_lock entry once you have finished modifying
57120+ the sysctl entries.
57121+
57122+endmenu
57123+menu "Logging Options"
57124+depends on GRKERNSEC
57125+
57126+config GRKERNSEC_FLOODTIME
57127+ int "Seconds in between log messages (minimum)"
57128+ default 10
57129+ help
57130+ This option allows you to enforce the number of seconds between
57131+ grsecurity log messages. The default should be suitable for most
57132+ people, however, if you choose to change it, choose a value small enough
57133+ to allow informative logs to be produced, but large enough to
57134+ prevent flooding.
57135+
57136+config GRKERNSEC_FLOODBURST
57137+ int "Number of messages in a burst (maximum)"
57138+ default 6
57139+ help
57140+ This option allows you to choose the maximum number of messages allowed
57141+ within the flood time interval you chose in a separate option. The
57142+ default should be suitable for most people, however if you find that
57143+ many of your logs are being interpreted as flooding, you may want to
57144+ raise this value.
57145+
57146+endmenu
57147diff --git a/grsecurity/Makefile b/grsecurity/Makefile
57148new file mode 100644
57149index 0000000..1b9afa9
57150--- /dev/null
57151+++ b/grsecurity/Makefile
57152@@ -0,0 +1,38 @@
57153+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
57154+# during 2001-2009 it has been completely redesigned by Brad Spengler
57155+# into an RBAC system
57156+#
57157+# All code in this directory and various hooks inserted throughout the kernel
57158+# are copyright Brad Spengler - Open Source Security, Inc., and released
57159+# under the GPL v2 or higher
57160+
57161+KBUILD_CFLAGS += -Werror
57162+
57163+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
57164+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
57165+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
57166+
57167+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
57168+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
57169+ gracl_learn.o grsec_log.o
57170+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
57171+
57172+ifdef CONFIG_NET
57173+obj-y += grsec_sock.o
57174+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
57175+endif
57176+
57177+ifndef CONFIG_GRKERNSEC
57178+obj-y += grsec_disabled.o
57179+endif
57180+
57181+ifdef CONFIG_GRKERNSEC_HIDESYM
57182+extra-y := grsec_hidesym.o
57183+$(obj)/grsec_hidesym.o:
57184+ @-chmod -f 500 /boot
57185+ @-chmod -f 500 /lib/modules
57186+ @-chmod -f 500 /lib64/modules
57187+ @-chmod -f 500 /lib32/modules
57188+ @-chmod -f 700 .
57189+ @echo ' grsec: protected kernel image paths'
57190+endif
57191diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
57192new file mode 100644
57193index 0000000..ab45812
57194--- /dev/null
57195+++ b/grsecurity/gracl.c
57196@@ -0,0 +1,4071 @@
57197+#include <linux/kernel.h>
57198+#include <linux/module.h>
57199+#include <linux/sched.h>
57200+#include <linux/mm.h>
57201+#include <linux/file.h>
57202+#include <linux/fs.h>
57203+#include <linux/namei.h>
57204+#include <linux/mount.h>
57205+#include <linux/tty.h>
57206+#include <linux/proc_fs.h>
57207+#include <linux/lglock.h>
57208+#include <linux/slab.h>
57209+#include <linux/vmalloc.h>
57210+#include <linux/types.h>
57211+#include <linux/sysctl.h>
57212+#include <linux/netdevice.h>
57213+#include <linux/ptrace.h>
57214+#include <linux/gracl.h>
57215+#include <linux/gralloc.h>
57216+#include <linux/security.h>
57217+#include <linux/grinternal.h>
57218+#include <linux/pid_namespace.h>
57219+#include <linux/stop_machine.h>
57220+#include <linux/fdtable.h>
57221+#include <linux/percpu.h>
57222+#include <linux/lglock.h>
57223+#include <linux/hugetlb.h>
57224+#include <linux/posix-timers.h>
57225+#include "../fs/mount.h"
57226+
57227+#include <asm/uaccess.h>
57228+#include <asm/errno.h>
57229+#include <asm/mman.h>
57230+
57231+extern struct lglock vfsmount_lock;
57232+
57233+static struct acl_role_db acl_role_set;
57234+static struct name_db name_set;
57235+static struct inodev_db inodev_set;
57236+
57237+/* for keeping track of userspace pointers used for subjects, so we
57238+ can share references in the kernel as well
57239+*/
57240+
57241+static struct path real_root;
57242+
57243+static struct acl_subj_map_db subj_map_set;
57244+
57245+static struct acl_role_label *default_role;
57246+
57247+static struct acl_role_label *role_list;
57248+
57249+static u16 acl_sp_role_value;
57250+
57251+extern char *gr_shared_page[4];
57252+static DEFINE_MUTEX(gr_dev_mutex);
57253+DEFINE_RWLOCK(gr_inode_lock);
57254+
57255+struct gr_arg *gr_usermode;
57256+
57257+static unsigned int gr_status __read_only = GR_STATUS_INIT;
57258+
57259+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
57260+extern void gr_clear_learn_entries(void);
57261+
57262+unsigned char *gr_system_salt;
57263+unsigned char *gr_system_sum;
57264+
57265+static struct sprole_pw **acl_special_roles = NULL;
57266+static __u16 num_sprole_pws = 0;
57267+
57268+static struct acl_role_label *kernel_role = NULL;
57269+
57270+static unsigned int gr_auth_attempts = 0;
57271+static unsigned long gr_auth_expires = 0UL;
57272+
57273+#ifdef CONFIG_NET
57274+extern struct vfsmount *sock_mnt;
57275+#endif
57276+
57277+extern struct vfsmount *pipe_mnt;
57278+extern struct vfsmount *shm_mnt;
57279+
57280+#ifdef CONFIG_HUGETLBFS
57281+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57282+#endif
57283+
57284+static struct acl_object_label *fakefs_obj_rw;
57285+static struct acl_object_label *fakefs_obj_rwx;
57286+
57287+extern int gr_init_uidset(void);
57288+extern void gr_free_uidset(void);
57289+extern void gr_remove_uid(uid_t uid);
57290+extern int gr_find_uid(uid_t uid);
57291+
57292+__inline__ int
57293+gr_acl_is_enabled(void)
57294+{
57295+ return (gr_status & GR_READY);
57296+}
57297+
57298+#ifdef CONFIG_BTRFS_FS
57299+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57300+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57301+#endif
57302+
57303+static inline dev_t __get_dev(const struct dentry *dentry)
57304+{
57305+#ifdef CONFIG_BTRFS_FS
57306+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57307+ return get_btrfs_dev_from_inode(dentry->d_inode);
57308+ else
57309+#endif
57310+ return dentry->d_inode->i_sb->s_dev;
57311+}
57312+
57313+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57314+{
57315+ return __get_dev(dentry);
57316+}
57317+
57318+static char gr_task_roletype_to_char(struct task_struct *task)
57319+{
57320+ switch (task->role->roletype &
57321+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
57322+ GR_ROLE_SPECIAL)) {
57323+ case GR_ROLE_DEFAULT:
57324+ return 'D';
57325+ case GR_ROLE_USER:
57326+ return 'U';
57327+ case GR_ROLE_GROUP:
57328+ return 'G';
57329+ case GR_ROLE_SPECIAL:
57330+ return 'S';
57331+ }
57332+
57333+ return 'X';
57334+}
57335+
57336+char gr_roletype_to_char(void)
57337+{
57338+ return gr_task_roletype_to_char(current);
57339+}
57340+
57341+__inline__ int
57342+gr_acl_tpe_check(void)
57343+{
57344+ if (unlikely(!(gr_status & GR_READY)))
57345+ return 0;
57346+ if (current->role->roletype & GR_ROLE_TPE)
57347+ return 1;
57348+ else
57349+ return 0;
57350+}
57351+
57352+int
57353+gr_handle_rawio(const struct inode *inode)
57354+{
57355+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57356+ if (inode && S_ISBLK(inode->i_mode) &&
57357+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57358+ !capable(CAP_SYS_RAWIO))
57359+ return 1;
57360+#endif
57361+ return 0;
57362+}
57363+
57364+static int
57365+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
57366+{
57367+ if (likely(lena != lenb))
57368+ return 0;
57369+
57370+ return !memcmp(a, b, lena);
57371+}
57372+
57373+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
57374+{
57375+ *buflen -= namelen;
57376+ if (*buflen < 0)
57377+ return -ENAMETOOLONG;
57378+ *buffer -= namelen;
57379+ memcpy(*buffer, str, namelen);
57380+ return 0;
57381+}
57382+
57383+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
57384+{
57385+ return prepend(buffer, buflen, name->name, name->len);
57386+}
57387+
57388+static int prepend_path(const struct path *path, struct path *root,
57389+ char **buffer, int *buflen)
57390+{
57391+ struct dentry *dentry = path->dentry;
57392+ struct vfsmount *vfsmnt = path->mnt;
57393+ struct mount *mnt = real_mount(vfsmnt);
57394+ bool slash = false;
57395+ int error = 0;
57396+
57397+ while (dentry != root->dentry || vfsmnt != root->mnt) {
57398+ struct dentry * parent;
57399+
57400+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
57401+ /* Global root? */
57402+ if (!mnt_has_parent(mnt)) {
57403+ goto out;
57404+ }
57405+ dentry = mnt->mnt_mountpoint;
57406+ mnt = mnt->mnt_parent;
57407+ vfsmnt = &mnt->mnt;
57408+ continue;
57409+ }
57410+ parent = dentry->d_parent;
57411+ prefetch(parent);
57412+ spin_lock(&dentry->d_lock);
57413+ error = prepend_name(buffer, buflen, &dentry->d_name);
57414+ spin_unlock(&dentry->d_lock);
57415+ if (!error)
57416+ error = prepend(buffer, buflen, "/", 1);
57417+ if (error)
57418+ break;
57419+
57420+ slash = true;
57421+ dentry = parent;
57422+ }
57423+
57424+out:
57425+ if (!error && !slash)
57426+ error = prepend(buffer, buflen, "/", 1);
57427+
57428+ return error;
57429+}
57430+
57431+/* this must be called with vfsmount_lock and rename_lock held */
57432+
57433+static char *__our_d_path(const struct path *path, struct path *root,
57434+ char *buf, int buflen)
57435+{
57436+ char *res = buf + buflen;
57437+ int error;
57438+
57439+ prepend(&res, &buflen, "\0", 1);
57440+ error = prepend_path(path, root, &res, &buflen);
57441+ if (error)
57442+ return ERR_PTR(error);
57443+
57444+ return res;
57445+}
57446+
57447+static char *
57448+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
57449+{
57450+ char *retval;
57451+
57452+ retval = __our_d_path(path, root, buf, buflen);
57453+ if (unlikely(IS_ERR(retval)))
57454+ retval = strcpy(buf, "<path too long>");
57455+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57456+ retval[1] = '\0';
57457+
57458+ return retval;
57459+}
57460+
57461+static char *
57462+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57463+ char *buf, int buflen)
57464+{
57465+ struct path path;
57466+ char *res;
57467+
57468+ path.dentry = (struct dentry *)dentry;
57469+ path.mnt = (struct vfsmount *)vfsmnt;
57470+
57471+ /* we can use real_root.dentry, real_root.mnt, because this is only called
57472+ by the RBAC system */
57473+ res = gen_full_path(&path, &real_root, buf, buflen);
57474+
57475+ return res;
57476+}
57477+
57478+static char *
57479+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57480+ char *buf, int buflen)
57481+{
57482+ char *res;
57483+ struct path path;
57484+ struct path root;
57485+ struct task_struct *reaper = init_pid_ns.child_reaper;
57486+
57487+ path.dentry = (struct dentry *)dentry;
57488+ path.mnt = (struct vfsmount *)vfsmnt;
57489+
57490+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57491+ get_fs_root(reaper->fs, &root);
57492+
57493+ write_seqlock(&rename_lock);
57494+ br_read_lock(&vfsmount_lock);
57495+ res = gen_full_path(&path, &root, buf, buflen);
57496+ br_read_unlock(&vfsmount_lock);
57497+ write_sequnlock(&rename_lock);
57498+
57499+ path_put(&root);
57500+ return res;
57501+}
57502+
57503+static char *
57504+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57505+{
57506+ char *ret;
57507+ write_seqlock(&rename_lock);
57508+ br_read_lock(&vfsmount_lock);
57509+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57510+ PAGE_SIZE);
57511+ br_read_unlock(&vfsmount_lock);
57512+ write_sequnlock(&rename_lock);
57513+ return ret;
57514+}
57515+
57516+static char *
57517+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57518+{
57519+ char *ret;
57520+ char *buf;
57521+ int buflen;
57522+
57523+ write_seqlock(&rename_lock);
57524+ br_read_lock(&vfsmount_lock);
57525+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57526+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57527+ buflen = (int)(ret - buf);
57528+ if (buflen >= 5)
57529+ prepend(&ret, &buflen, "/proc", 5);
57530+ else
57531+ ret = strcpy(buf, "<path too long>");
57532+ br_read_unlock(&vfsmount_lock);
57533+ write_sequnlock(&rename_lock);
57534+ return ret;
57535+}
57536+
57537+char *
57538+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57539+{
57540+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57541+ PAGE_SIZE);
57542+}
57543+
57544+char *
57545+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57546+{
57547+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57548+ PAGE_SIZE);
57549+}
57550+
57551+char *
57552+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57553+{
57554+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57555+ PAGE_SIZE);
57556+}
57557+
57558+char *
57559+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57560+{
57561+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57562+ PAGE_SIZE);
57563+}
57564+
57565+char *
57566+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57567+{
57568+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57569+ PAGE_SIZE);
57570+}
57571+
57572+__inline__ __u32
57573+to_gr_audit(const __u32 reqmode)
57574+{
57575+ /* masks off auditable permission flags, then shifts them to create
57576+ auditing flags, and adds the special case of append auditing if
57577+ we're requesting write */
57578+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57579+}
57580+
57581+struct acl_subject_label *
57582+lookup_subject_map(const struct acl_subject_label *userp)
57583+{
57584+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
57585+ struct subject_map *match;
57586+
57587+ match = subj_map_set.s_hash[index];
57588+
57589+ while (match && match->user != userp)
57590+ match = match->next;
57591+
57592+ if (match != NULL)
57593+ return match->kernel;
57594+ else
57595+ return NULL;
57596+}
57597+
57598+static void
57599+insert_subj_map_entry(struct subject_map *subjmap)
57600+{
57601+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57602+ struct subject_map **curr;
57603+
57604+ subjmap->prev = NULL;
57605+
57606+ curr = &subj_map_set.s_hash[index];
57607+ if (*curr != NULL)
57608+ (*curr)->prev = subjmap;
57609+
57610+ subjmap->next = *curr;
57611+ *curr = subjmap;
57612+
57613+ return;
57614+}
57615+
57616+static struct acl_role_label *
57617+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57618+ const gid_t gid)
57619+{
57620+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57621+ struct acl_role_label *match;
57622+ struct role_allowed_ip *ipp;
57623+ unsigned int x;
57624+ u32 curr_ip = task->signal->curr_ip;
57625+
57626+ task->signal->saved_ip = curr_ip;
57627+
57628+ match = acl_role_set.r_hash[index];
57629+
57630+ while (match) {
57631+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57632+ for (x = 0; x < match->domain_child_num; x++) {
57633+ if (match->domain_children[x] == uid)
57634+ goto found;
57635+ }
57636+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57637+ break;
57638+ match = match->next;
57639+ }
57640+found:
57641+ if (match == NULL) {
57642+ try_group:
57643+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57644+ match = acl_role_set.r_hash[index];
57645+
57646+ while (match) {
57647+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57648+ for (x = 0; x < match->domain_child_num; x++) {
57649+ if (match->domain_children[x] == gid)
57650+ goto found2;
57651+ }
57652+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57653+ break;
57654+ match = match->next;
57655+ }
57656+found2:
57657+ if (match == NULL)
57658+ match = default_role;
57659+ if (match->allowed_ips == NULL)
57660+ return match;
57661+ else {
57662+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57663+ if (likely
57664+ ((ntohl(curr_ip) & ipp->netmask) ==
57665+ (ntohl(ipp->addr) & ipp->netmask)))
57666+ return match;
57667+ }
57668+ match = default_role;
57669+ }
57670+ } else if (match->allowed_ips == NULL) {
57671+ return match;
57672+ } else {
57673+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57674+ if (likely
57675+ ((ntohl(curr_ip) & ipp->netmask) ==
57676+ (ntohl(ipp->addr) & ipp->netmask)))
57677+ return match;
57678+ }
57679+ goto try_group;
57680+ }
57681+
57682+ return match;
57683+}
57684+
57685+struct acl_subject_label *
57686+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57687+ const struct acl_role_label *role)
57688+{
57689+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57690+ struct acl_subject_label *match;
57691+
57692+ match = role->subj_hash[index];
57693+
57694+ while (match && (match->inode != ino || match->device != dev ||
57695+ (match->mode & GR_DELETED))) {
57696+ match = match->next;
57697+ }
57698+
57699+ if (match && !(match->mode & GR_DELETED))
57700+ return match;
57701+ else
57702+ return NULL;
57703+}
57704+
57705+struct acl_subject_label *
57706+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57707+ const struct acl_role_label *role)
57708+{
57709+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57710+ struct acl_subject_label *match;
57711+
57712+ match = role->subj_hash[index];
57713+
57714+ while (match && (match->inode != ino || match->device != dev ||
57715+ !(match->mode & GR_DELETED))) {
57716+ match = match->next;
57717+ }
57718+
57719+ if (match && (match->mode & GR_DELETED))
57720+ return match;
57721+ else
57722+ return NULL;
57723+}
57724+
57725+static struct acl_object_label *
57726+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57727+ const struct acl_subject_label *subj)
57728+{
57729+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57730+ struct acl_object_label *match;
57731+
57732+ match = subj->obj_hash[index];
57733+
57734+ while (match && (match->inode != ino || match->device != dev ||
57735+ (match->mode & GR_DELETED))) {
57736+ match = match->next;
57737+ }
57738+
57739+ if (match && !(match->mode & GR_DELETED))
57740+ return match;
57741+ else
57742+ return NULL;
57743+}
57744+
57745+static struct acl_object_label *
57746+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57747+ const struct acl_subject_label *subj)
57748+{
57749+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57750+ struct acl_object_label *match;
57751+
57752+ match = subj->obj_hash[index];
57753+
57754+ while (match && (match->inode != ino || match->device != dev ||
57755+ !(match->mode & GR_DELETED))) {
57756+ match = match->next;
57757+ }
57758+
57759+ if (match && (match->mode & GR_DELETED))
57760+ return match;
57761+
57762+ match = subj->obj_hash[index];
57763+
57764+ while (match && (match->inode != ino || match->device != dev ||
57765+ (match->mode & GR_DELETED))) {
57766+ match = match->next;
57767+ }
57768+
57769+ if (match && !(match->mode & GR_DELETED))
57770+ return match;
57771+ else
57772+ return NULL;
57773+}
57774+
57775+static struct name_entry *
57776+lookup_name_entry(const char *name)
57777+{
57778+ unsigned int len = strlen(name);
57779+ unsigned int key = full_name_hash(name, len);
57780+ unsigned int index = key % name_set.n_size;
57781+ struct name_entry *match;
57782+
57783+ match = name_set.n_hash[index];
57784+
57785+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57786+ match = match->next;
57787+
57788+ return match;
57789+}
57790+
57791+static struct name_entry *
57792+lookup_name_entry_create(const char *name)
57793+{
57794+ unsigned int len = strlen(name);
57795+ unsigned int key = full_name_hash(name, len);
57796+ unsigned int index = key % name_set.n_size;
57797+ struct name_entry *match;
57798+
57799+ match = name_set.n_hash[index];
57800+
57801+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57802+ !match->deleted))
57803+ match = match->next;
57804+
57805+ if (match && match->deleted)
57806+ return match;
57807+
57808+ match = name_set.n_hash[index];
57809+
57810+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57811+ match->deleted))
57812+ match = match->next;
57813+
57814+ if (match && !match->deleted)
57815+ return match;
57816+ else
57817+ return NULL;
57818+}
57819+
57820+static struct inodev_entry *
57821+lookup_inodev_entry(const ino_t ino, const dev_t dev)
57822+{
57823+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57824+ struct inodev_entry *match;
57825+
57826+ match = inodev_set.i_hash[index];
57827+
57828+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57829+ match = match->next;
57830+
57831+ return match;
57832+}
57833+
57834+static void
57835+insert_inodev_entry(struct inodev_entry *entry)
57836+{
57837+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57838+ inodev_set.i_size);
57839+ struct inodev_entry **curr;
57840+
57841+ entry->prev = NULL;
57842+
57843+ curr = &inodev_set.i_hash[index];
57844+ if (*curr != NULL)
57845+ (*curr)->prev = entry;
57846+
57847+ entry->next = *curr;
57848+ *curr = entry;
57849+
57850+ return;
57851+}
57852+
57853+static void
57854+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57855+{
57856+ unsigned int index =
57857+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57858+ struct acl_role_label **curr;
57859+ struct acl_role_label *tmp, *tmp2;
57860+
57861+ curr = &acl_role_set.r_hash[index];
57862+
57863+ /* simple case, slot is empty, just set it to our role */
57864+ if (*curr == NULL) {
57865+ *curr = role;
57866+ } else {
57867+ /* example:
57868+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
57869+ 2 -> 3
57870+ */
57871+ /* first check to see if we can already be reached via this slot */
57872+ tmp = *curr;
57873+ while (tmp && tmp != role)
57874+ tmp = tmp->next;
57875+ if (tmp == role) {
57876+ /* we don't need to add ourselves to this slot's chain */
57877+ return;
57878+ }
57879+ /* we need to add ourselves to this chain, two cases */
57880+ if (role->next == NULL) {
57881+ /* simple case, append the current chain to our role */
57882+ role->next = *curr;
57883+ *curr = role;
57884+ } else {
57885+ /* 1 -> 2 -> 3 -> 4
57886+ 2 -> 3 -> 4
57887+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57888+ */
57889+ /* trickier case: walk our role's chain until we find
57890+ the role for the start of the current slot's chain */
57891+ tmp = role;
57892+ tmp2 = *curr;
57893+ while (tmp->next && tmp->next != tmp2)
57894+ tmp = tmp->next;
57895+ if (tmp->next == tmp2) {
57896+ /* from example above, we found 3, so just
57897+ replace this slot's chain with ours */
57898+ *curr = role;
57899+ } else {
57900+ /* we didn't find a subset of our role's chain
57901+ in the current slot's chain, so append their
57902+ chain to ours, and set us as the first role in
57903+ the slot's chain
57904+
57905+ we could fold this case with the case above,
57906+ but making it explicit for clarity
57907+ */
57908+ tmp->next = tmp2;
57909+ *curr = role;
57910+ }
57911+ }
57912+ }
57913+
57914+ return;
57915+}
57916+
57917+static void
57918+insert_acl_role_label(struct acl_role_label *role)
57919+{
57920+ int i;
57921+
57922+ if (role_list == NULL) {
57923+ role_list = role;
57924+ role->prev = NULL;
57925+ } else {
57926+ role->prev = role_list;
57927+ role_list = role;
57928+ }
57929+
57930+ /* used for hash chains */
57931+ role->next = NULL;
57932+
57933+ if (role->roletype & GR_ROLE_DOMAIN) {
57934+ for (i = 0; i < role->domain_child_num; i++)
57935+ __insert_acl_role_label(role, role->domain_children[i]);
57936+ } else
57937+ __insert_acl_role_label(role, role->uidgid);
57938+}
57939+
57940+static int
57941+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57942+{
57943+ struct name_entry **curr, *nentry;
57944+ struct inodev_entry *ientry;
57945+ unsigned int len = strlen(name);
57946+ unsigned int key = full_name_hash(name, len);
57947+ unsigned int index = key % name_set.n_size;
57948+
57949+ curr = &name_set.n_hash[index];
57950+
57951+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57952+ curr = &((*curr)->next);
57953+
57954+ if (*curr != NULL)
57955+ return 1;
57956+
57957+ nentry = acl_alloc(sizeof (struct name_entry));
57958+ if (nentry == NULL)
57959+ return 0;
57960+ ientry = acl_alloc(sizeof (struct inodev_entry));
57961+ if (ientry == NULL)
57962+ return 0;
57963+ ientry->nentry = nentry;
57964+
57965+ nentry->key = key;
57966+ nentry->name = name;
57967+ nentry->inode = inode;
57968+ nentry->device = device;
57969+ nentry->len = len;
57970+ nentry->deleted = deleted;
57971+
57972+ nentry->prev = NULL;
57973+ curr = &name_set.n_hash[index];
57974+ if (*curr != NULL)
57975+ (*curr)->prev = nentry;
57976+ nentry->next = *curr;
57977+ *curr = nentry;
57978+
57979+ /* insert us into the table searchable by inode/dev */
57980+ insert_inodev_entry(ientry);
57981+
57982+ return 1;
57983+}
57984+
57985+static void
57986+insert_acl_obj_label(struct acl_object_label *obj,
57987+ struct acl_subject_label *subj)
57988+{
57989+ unsigned int index =
57990+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
57991+ struct acl_object_label **curr;
57992+
57993+
57994+ obj->prev = NULL;
57995+
57996+ curr = &subj->obj_hash[index];
57997+ if (*curr != NULL)
57998+ (*curr)->prev = obj;
57999+
58000+ obj->next = *curr;
58001+ *curr = obj;
58002+
58003+ return;
58004+}
58005+
58006+static void
58007+insert_acl_subj_label(struct acl_subject_label *obj,
58008+ struct acl_role_label *role)
58009+{
58010+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58011+ struct acl_subject_label **curr;
58012+
58013+ obj->prev = NULL;
58014+
58015+ curr = &role->subj_hash[index];
58016+ if (*curr != NULL)
58017+ (*curr)->prev = obj;
58018+
58019+ obj->next = *curr;
58020+ *curr = obj;
58021+
58022+ return;
58023+}
58024+
58025+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
58026+
58027+static void *
58028+create_table(__u32 * len, int elementsize)
58029+{
58030+ unsigned int table_sizes[] = {
58031+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
58032+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
58033+ 4194301, 8388593, 16777213, 33554393, 67108859
58034+ };
58035+ void *newtable = NULL;
58036+ unsigned int pwr = 0;
58037+
58038+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
58039+ table_sizes[pwr] <= *len)
58040+ pwr++;
58041+
58042+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
58043+ return newtable;
58044+
58045+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
58046+ newtable =
58047+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
58048+ else
58049+ newtable = vmalloc(table_sizes[pwr] * elementsize);
58050+
58051+ *len = table_sizes[pwr];
58052+
58053+ return newtable;
58054+}
58055+
58056+static int
58057+init_variables(const struct gr_arg *arg)
58058+{
58059+ struct task_struct *reaper = init_pid_ns.child_reaper;
58060+ unsigned int stacksize;
58061+
58062+ subj_map_set.s_size = arg->role_db.num_subjects;
58063+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
58064+ name_set.n_size = arg->role_db.num_objects;
58065+ inodev_set.i_size = arg->role_db.num_objects;
58066+
58067+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
58068+ !name_set.n_size || !inodev_set.i_size)
58069+ return 1;
58070+
58071+ if (!gr_init_uidset())
58072+ return 1;
58073+
58074+ /* set up the stack that holds allocation info */
58075+
58076+ stacksize = arg->role_db.num_pointers + 5;
58077+
58078+ if (!acl_alloc_stack_init(stacksize))
58079+ return 1;
58080+
58081+ /* grab reference for the real root dentry and vfsmount */
58082+ get_fs_root(reaper->fs, &real_root);
58083+
58084+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58085+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
58086+#endif
58087+
58088+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
58089+ if (fakefs_obj_rw == NULL)
58090+ return 1;
58091+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
58092+
58093+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
58094+ if (fakefs_obj_rwx == NULL)
58095+ return 1;
58096+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
58097+
58098+ subj_map_set.s_hash =
58099+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
58100+ acl_role_set.r_hash =
58101+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
58102+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
58103+ inodev_set.i_hash =
58104+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
58105+
58106+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
58107+ !name_set.n_hash || !inodev_set.i_hash)
58108+ return 1;
58109+
58110+ memset(subj_map_set.s_hash, 0,
58111+ sizeof(struct subject_map *) * subj_map_set.s_size);
58112+ memset(acl_role_set.r_hash, 0,
58113+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
58114+ memset(name_set.n_hash, 0,
58115+ sizeof (struct name_entry *) * name_set.n_size);
58116+ memset(inodev_set.i_hash, 0,
58117+ sizeof (struct inodev_entry *) * inodev_set.i_size);
58118+
58119+ return 0;
58120+}
58121+
58122+/* free information not needed after startup
58123+ currently contains user->kernel pointer mappings for subjects
58124+*/
58125+
58126+static void
58127+free_init_variables(void)
58128+{
58129+ __u32 i;
58130+
58131+ if (subj_map_set.s_hash) {
58132+ for (i = 0; i < subj_map_set.s_size; i++) {
58133+ if (subj_map_set.s_hash[i]) {
58134+ kfree(subj_map_set.s_hash[i]);
58135+ subj_map_set.s_hash[i] = NULL;
58136+ }
58137+ }
58138+
58139+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
58140+ PAGE_SIZE)
58141+ kfree(subj_map_set.s_hash);
58142+ else
58143+ vfree(subj_map_set.s_hash);
58144+ }
58145+
58146+ return;
58147+}
58148+
58149+static void
58150+free_variables(void)
58151+{
58152+ struct acl_subject_label *s;
58153+ struct acl_role_label *r;
58154+ struct task_struct *task, *task2;
58155+ unsigned int x;
58156+
58157+ gr_clear_learn_entries();
58158+
58159+ read_lock(&tasklist_lock);
58160+ do_each_thread(task2, task) {
58161+ task->acl_sp_role = 0;
58162+ task->acl_role_id = 0;
58163+ task->acl = NULL;
58164+ task->role = NULL;
58165+ } while_each_thread(task2, task);
58166+ read_unlock(&tasklist_lock);
58167+
58168+ /* release the reference to the real root dentry and vfsmount */
58169+ path_put(&real_root);
58170+ memset(&real_root, 0, sizeof(real_root));
58171+
58172+ /* free all object hash tables */
58173+
58174+ FOR_EACH_ROLE_START(r)
58175+ if (r->subj_hash == NULL)
58176+ goto next_role;
58177+ FOR_EACH_SUBJECT_START(r, s, x)
58178+ if (s->obj_hash == NULL)
58179+ break;
58180+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58181+ kfree(s->obj_hash);
58182+ else
58183+ vfree(s->obj_hash);
58184+ FOR_EACH_SUBJECT_END(s, x)
58185+ FOR_EACH_NESTED_SUBJECT_START(r, s)
58186+ if (s->obj_hash == NULL)
58187+ break;
58188+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58189+ kfree(s->obj_hash);
58190+ else
58191+ vfree(s->obj_hash);
58192+ FOR_EACH_NESTED_SUBJECT_END(s)
58193+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
58194+ kfree(r->subj_hash);
58195+ else
58196+ vfree(r->subj_hash);
58197+ r->subj_hash = NULL;
58198+next_role:
58199+ FOR_EACH_ROLE_END(r)
58200+
58201+ acl_free_all();
58202+
58203+ if (acl_role_set.r_hash) {
58204+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
58205+ PAGE_SIZE)
58206+ kfree(acl_role_set.r_hash);
58207+ else
58208+ vfree(acl_role_set.r_hash);
58209+ }
58210+ if (name_set.n_hash) {
58211+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
58212+ PAGE_SIZE)
58213+ kfree(name_set.n_hash);
58214+ else
58215+ vfree(name_set.n_hash);
58216+ }
58217+
58218+ if (inodev_set.i_hash) {
58219+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
58220+ PAGE_SIZE)
58221+ kfree(inodev_set.i_hash);
58222+ else
58223+ vfree(inodev_set.i_hash);
58224+ }
58225+
58226+ gr_free_uidset();
58227+
58228+ memset(&name_set, 0, sizeof (struct name_db));
58229+ memset(&inodev_set, 0, sizeof (struct inodev_db));
58230+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
58231+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
58232+
58233+ default_role = NULL;
58234+ kernel_role = NULL;
58235+ role_list = NULL;
58236+
58237+ return;
58238+}
58239+
58240+static __u32
58241+count_user_objs(struct acl_object_label *userp)
58242+{
58243+ struct acl_object_label o_tmp;
58244+ __u32 num = 0;
58245+
58246+ while (userp) {
58247+ if (copy_from_user(&o_tmp, userp,
58248+ sizeof (struct acl_object_label)))
58249+ break;
58250+
58251+ userp = o_tmp.prev;
58252+ num++;
58253+ }
58254+
58255+ return num;
58256+}
58257+
58258+static struct acl_subject_label *
58259+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
58260+
58261+static int
58262+copy_user_glob(struct acl_object_label *obj)
58263+{
58264+ struct acl_object_label *g_tmp, **guser;
58265+ unsigned int len;
58266+ char *tmp;
58267+
58268+ if (obj->globbed == NULL)
58269+ return 0;
58270+
58271+ guser = &obj->globbed;
58272+ while (*guser) {
58273+ g_tmp = (struct acl_object_label *)
58274+ acl_alloc(sizeof (struct acl_object_label));
58275+ if (g_tmp == NULL)
58276+ return -ENOMEM;
58277+
58278+ if (copy_from_user(g_tmp, *guser,
58279+ sizeof (struct acl_object_label)))
58280+ return -EFAULT;
58281+
58282+ len = strnlen_user(g_tmp->filename, PATH_MAX);
58283+
58284+ if (!len || len >= PATH_MAX)
58285+ return -EINVAL;
58286+
58287+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58288+ return -ENOMEM;
58289+
58290+ if (copy_from_user(tmp, g_tmp->filename, len))
58291+ return -EFAULT;
58292+ tmp[len-1] = '\0';
58293+ g_tmp->filename = tmp;
58294+
58295+ *guser = g_tmp;
58296+ guser = &(g_tmp->next);
58297+ }
58298+
58299+ return 0;
58300+}
58301+
58302+static int
58303+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
58304+ struct acl_role_label *role)
58305+{
58306+ struct acl_object_label *o_tmp;
58307+ unsigned int len;
58308+ int ret;
58309+ char *tmp;
58310+
58311+ while (userp) {
58312+ if ((o_tmp = (struct acl_object_label *)
58313+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
58314+ return -ENOMEM;
58315+
58316+ if (copy_from_user(o_tmp, userp,
58317+ sizeof (struct acl_object_label)))
58318+ return -EFAULT;
58319+
58320+ userp = o_tmp->prev;
58321+
58322+ len = strnlen_user(o_tmp->filename, PATH_MAX);
58323+
58324+ if (!len || len >= PATH_MAX)
58325+ return -EINVAL;
58326+
58327+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58328+ return -ENOMEM;
58329+
58330+ if (copy_from_user(tmp, o_tmp->filename, len))
58331+ return -EFAULT;
58332+ tmp[len-1] = '\0';
58333+ o_tmp->filename = tmp;
58334+
58335+ insert_acl_obj_label(o_tmp, subj);
58336+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
58337+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
58338+ return -ENOMEM;
58339+
58340+ ret = copy_user_glob(o_tmp);
58341+ if (ret)
58342+ return ret;
58343+
58344+ if (o_tmp->nested) {
58345+ int already_copied;
58346+
58347+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
58348+ if (IS_ERR(o_tmp->nested))
58349+ return PTR_ERR(o_tmp->nested);
58350+
58351+ /* insert into nested subject list if we haven't copied this one yet
58352+ to prevent duplicate entries */
58353+ if (!already_copied) {
58354+ o_tmp->nested->next = role->hash->first;
58355+ role->hash->first = o_tmp->nested;
58356+ }
58357+ }
58358+ }
58359+
58360+ return 0;
58361+}
58362+
58363+static __u32
58364+count_user_subjs(struct acl_subject_label *userp)
58365+{
58366+ struct acl_subject_label s_tmp;
58367+ __u32 num = 0;
58368+
58369+ while (userp) {
58370+ if (copy_from_user(&s_tmp, userp,
58371+ sizeof (struct acl_subject_label)))
58372+ break;
58373+
58374+ userp = s_tmp.prev;
58375+ }
58376+
58377+ return num;
58378+}
58379+
58380+static int
58381+copy_user_allowedips(struct acl_role_label *rolep)
58382+{
58383+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
58384+
58385+ ruserip = rolep->allowed_ips;
58386+
58387+ while (ruserip) {
58388+ rlast = rtmp;
58389+
58390+ if ((rtmp = (struct role_allowed_ip *)
58391+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
58392+ return -ENOMEM;
58393+
58394+ if (copy_from_user(rtmp, ruserip,
58395+ sizeof (struct role_allowed_ip)))
58396+ return -EFAULT;
58397+
58398+ ruserip = rtmp->prev;
58399+
58400+ if (!rlast) {
58401+ rtmp->prev = NULL;
58402+ rolep->allowed_ips = rtmp;
58403+ } else {
58404+ rlast->next = rtmp;
58405+ rtmp->prev = rlast;
58406+ }
58407+
58408+ if (!ruserip)
58409+ rtmp->next = NULL;
58410+ }
58411+
58412+ return 0;
58413+}
58414+
58415+static int
58416+copy_user_transitions(struct acl_role_label *rolep)
58417+{
58418+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
58419+
58420+ unsigned int len;
58421+ char *tmp;
58422+
58423+ rusertp = rolep->transitions;
58424+
58425+ while (rusertp) {
58426+ rlast = rtmp;
58427+
58428+ if ((rtmp = (struct role_transition *)
58429+ acl_alloc(sizeof (struct role_transition))) == NULL)
58430+ return -ENOMEM;
58431+
58432+ if (copy_from_user(rtmp, rusertp,
58433+ sizeof (struct role_transition)))
58434+ return -EFAULT;
58435+
58436+ rusertp = rtmp->prev;
58437+
58438+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
58439+
58440+ if (!len || len >= GR_SPROLE_LEN)
58441+ return -EINVAL;
58442+
58443+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58444+ return -ENOMEM;
58445+
58446+ if (copy_from_user(tmp, rtmp->rolename, len))
58447+ return -EFAULT;
58448+ tmp[len-1] = '\0';
58449+ rtmp->rolename = tmp;
58450+
58451+ if (!rlast) {
58452+ rtmp->prev = NULL;
58453+ rolep->transitions = rtmp;
58454+ } else {
58455+ rlast->next = rtmp;
58456+ rtmp->prev = rlast;
58457+ }
58458+
58459+ if (!rusertp)
58460+ rtmp->next = NULL;
58461+ }
58462+
58463+ return 0;
58464+}
58465+
58466+static struct acl_subject_label *
58467+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58468+{
58469+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58470+ unsigned int len;
58471+ char *tmp;
58472+ __u32 num_objs;
58473+ struct acl_ip_label **i_tmp, *i_utmp2;
58474+ struct gr_hash_struct ghash;
58475+ struct subject_map *subjmap;
58476+ unsigned int i_num;
58477+ int err;
58478+
58479+ if (already_copied != NULL)
58480+ *already_copied = 0;
58481+
58482+ s_tmp = lookup_subject_map(userp);
58483+
58484+ /* we've already copied this subject into the kernel, just return
58485+ the reference to it, and don't copy it over again
58486+ */
58487+ if (s_tmp) {
58488+ if (already_copied != NULL)
58489+ *already_copied = 1;
58490+ return(s_tmp);
58491+ }
58492+
58493+ if ((s_tmp = (struct acl_subject_label *)
58494+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58495+ return ERR_PTR(-ENOMEM);
58496+
58497+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58498+ if (subjmap == NULL)
58499+ return ERR_PTR(-ENOMEM);
58500+
58501+ subjmap->user = userp;
58502+ subjmap->kernel = s_tmp;
58503+ insert_subj_map_entry(subjmap);
58504+
58505+ if (copy_from_user(s_tmp, userp,
58506+ sizeof (struct acl_subject_label)))
58507+ return ERR_PTR(-EFAULT);
58508+
58509+ len = strnlen_user(s_tmp->filename, PATH_MAX);
58510+
58511+ if (!len || len >= PATH_MAX)
58512+ return ERR_PTR(-EINVAL);
58513+
58514+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58515+ return ERR_PTR(-ENOMEM);
58516+
58517+ if (copy_from_user(tmp, s_tmp->filename, len))
58518+ return ERR_PTR(-EFAULT);
58519+ tmp[len-1] = '\0';
58520+ s_tmp->filename = tmp;
58521+
58522+ if (!strcmp(s_tmp->filename, "/"))
58523+ role->root_label = s_tmp;
58524+
58525+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58526+ return ERR_PTR(-EFAULT);
58527+
58528+ /* copy user and group transition tables */
58529+
58530+ if (s_tmp->user_trans_num) {
58531+ uid_t *uidlist;
58532+
58533+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58534+ if (uidlist == NULL)
58535+ return ERR_PTR(-ENOMEM);
58536+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58537+ return ERR_PTR(-EFAULT);
58538+
58539+ s_tmp->user_transitions = uidlist;
58540+ }
58541+
58542+ if (s_tmp->group_trans_num) {
58543+ gid_t *gidlist;
58544+
58545+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58546+ if (gidlist == NULL)
58547+ return ERR_PTR(-ENOMEM);
58548+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58549+ return ERR_PTR(-EFAULT);
58550+
58551+ s_tmp->group_transitions = gidlist;
58552+ }
58553+
58554+ /* set up object hash table */
58555+ num_objs = count_user_objs(ghash.first);
58556+
58557+ s_tmp->obj_hash_size = num_objs;
58558+ s_tmp->obj_hash =
58559+ (struct acl_object_label **)
58560+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58561+
58562+ if (!s_tmp->obj_hash)
58563+ return ERR_PTR(-ENOMEM);
58564+
58565+ memset(s_tmp->obj_hash, 0,
58566+ s_tmp->obj_hash_size *
58567+ sizeof (struct acl_object_label *));
58568+
58569+ /* add in objects */
58570+ err = copy_user_objs(ghash.first, s_tmp, role);
58571+
58572+ if (err)
58573+ return ERR_PTR(err);
58574+
58575+ /* set pointer for parent subject */
58576+ if (s_tmp->parent_subject) {
58577+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58578+
58579+ if (IS_ERR(s_tmp2))
58580+ return s_tmp2;
58581+
58582+ s_tmp->parent_subject = s_tmp2;
58583+ }
58584+
58585+ /* add in ip acls */
58586+
58587+ if (!s_tmp->ip_num) {
58588+ s_tmp->ips = NULL;
58589+ goto insert;
58590+ }
58591+
58592+ i_tmp =
58593+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58594+ sizeof (struct acl_ip_label *));
58595+
58596+ if (!i_tmp)
58597+ return ERR_PTR(-ENOMEM);
58598+
58599+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58600+ *(i_tmp + i_num) =
58601+ (struct acl_ip_label *)
58602+ acl_alloc(sizeof (struct acl_ip_label));
58603+ if (!*(i_tmp + i_num))
58604+ return ERR_PTR(-ENOMEM);
58605+
58606+ if (copy_from_user
58607+ (&i_utmp2, s_tmp->ips + i_num,
58608+ sizeof (struct acl_ip_label *)))
58609+ return ERR_PTR(-EFAULT);
58610+
58611+ if (copy_from_user
58612+ (*(i_tmp + i_num), i_utmp2,
58613+ sizeof (struct acl_ip_label)))
58614+ return ERR_PTR(-EFAULT);
58615+
58616+ if ((*(i_tmp + i_num))->iface == NULL)
58617+ continue;
58618+
58619+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58620+ if (!len || len >= IFNAMSIZ)
58621+ return ERR_PTR(-EINVAL);
58622+ tmp = acl_alloc(len);
58623+ if (tmp == NULL)
58624+ return ERR_PTR(-ENOMEM);
58625+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58626+ return ERR_PTR(-EFAULT);
58627+ (*(i_tmp + i_num))->iface = tmp;
58628+ }
58629+
58630+ s_tmp->ips = i_tmp;
58631+
58632+insert:
58633+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58634+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58635+ return ERR_PTR(-ENOMEM);
58636+
58637+ return s_tmp;
58638+}
58639+
58640+static int
58641+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58642+{
58643+ struct acl_subject_label s_pre;
58644+ struct acl_subject_label * ret;
58645+ int err;
58646+
58647+ while (userp) {
58648+ if (copy_from_user(&s_pre, userp,
58649+ sizeof (struct acl_subject_label)))
58650+ return -EFAULT;
58651+
58652+ ret = do_copy_user_subj(userp, role, NULL);
58653+
58654+ err = PTR_ERR(ret);
58655+ if (IS_ERR(ret))
58656+ return err;
58657+
58658+ insert_acl_subj_label(ret, role);
58659+
58660+ userp = s_pre.prev;
58661+ }
58662+
58663+ return 0;
58664+}
58665+
58666+static int
58667+copy_user_acl(struct gr_arg *arg)
58668+{
58669+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58670+ struct acl_subject_label *subj_list;
58671+ struct sprole_pw *sptmp;
58672+ struct gr_hash_struct *ghash;
58673+ uid_t *domainlist;
58674+ unsigned int r_num;
58675+ unsigned int len;
58676+ char *tmp;
58677+ int err = 0;
58678+ __u16 i;
58679+ __u32 num_subjs;
58680+
58681+ /* we need a default and kernel role */
58682+ if (arg->role_db.num_roles < 2)
58683+ return -EINVAL;
58684+
58685+ /* copy special role authentication info from userspace */
58686+
58687+ num_sprole_pws = arg->num_sprole_pws;
58688+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58689+
58690+ if (!acl_special_roles && num_sprole_pws)
58691+ return -ENOMEM;
58692+
58693+ for (i = 0; i < num_sprole_pws; i++) {
58694+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58695+ if (!sptmp)
58696+ return -ENOMEM;
58697+ if (copy_from_user(sptmp, arg->sprole_pws + i,
58698+ sizeof (struct sprole_pw)))
58699+ return -EFAULT;
58700+
58701+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58702+
58703+ if (!len || len >= GR_SPROLE_LEN)
58704+ return -EINVAL;
58705+
58706+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58707+ return -ENOMEM;
58708+
58709+ if (copy_from_user(tmp, sptmp->rolename, len))
58710+ return -EFAULT;
58711+
58712+ tmp[len-1] = '\0';
58713+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58714+ printk(KERN_ALERT "Copying special role %s\n", tmp);
58715+#endif
58716+ sptmp->rolename = tmp;
58717+ acl_special_roles[i] = sptmp;
58718+ }
58719+
58720+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58721+
58722+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58723+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
58724+
58725+ if (!r_tmp)
58726+ return -ENOMEM;
58727+
58728+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
58729+ sizeof (struct acl_role_label *)))
58730+ return -EFAULT;
58731+
58732+ if (copy_from_user(r_tmp, r_utmp2,
58733+ sizeof (struct acl_role_label)))
58734+ return -EFAULT;
58735+
58736+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58737+
58738+ if (!len || len >= PATH_MAX)
58739+ return -EINVAL;
58740+
58741+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58742+ return -ENOMEM;
58743+
58744+ if (copy_from_user(tmp, r_tmp->rolename, len))
58745+ return -EFAULT;
58746+
58747+ tmp[len-1] = '\0';
58748+ r_tmp->rolename = tmp;
58749+
58750+ if (!strcmp(r_tmp->rolename, "default")
58751+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58752+ default_role = r_tmp;
58753+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58754+ kernel_role = r_tmp;
58755+ }
58756+
58757+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58758+ return -ENOMEM;
58759+
58760+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58761+ return -EFAULT;
58762+
58763+ r_tmp->hash = ghash;
58764+
58765+ num_subjs = count_user_subjs(r_tmp->hash->first);
58766+
58767+ r_tmp->subj_hash_size = num_subjs;
58768+ r_tmp->subj_hash =
58769+ (struct acl_subject_label **)
58770+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58771+
58772+ if (!r_tmp->subj_hash)
58773+ return -ENOMEM;
58774+
58775+ err = copy_user_allowedips(r_tmp);
58776+ if (err)
58777+ return err;
58778+
58779+ /* copy domain info */
58780+ if (r_tmp->domain_children != NULL) {
58781+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58782+ if (domainlist == NULL)
58783+ return -ENOMEM;
58784+
58785+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58786+ return -EFAULT;
58787+
58788+ r_tmp->domain_children = domainlist;
58789+ }
58790+
58791+ err = copy_user_transitions(r_tmp);
58792+ if (err)
58793+ return err;
58794+
58795+ memset(r_tmp->subj_hash, 0,
58796+ r_tmp->subj_hash_size *
58797+ sizeof (struct acl_subject_label *));
58798+
58799+ /* acquire the list of subjects, then NULL out
58800+ the list prior to parsing the subjects for this role,
58801+ as during this parsing the list is replaced with a list
58802+ of *nested* subjects for the role
58803+ */
58804+ subj_list = r_tmp->hash->first;
58805+
58806+ /* set nested subject list to null */
58807+ r_tmp->hash->first = NULL;
58808+
58809+ err = copy_user_subjs(subj_list, r_tmp);
58810+
58811+ if (err)
58812+ return err;
58813+
58814+ insert_acl_role_label(r_tmp);
58815+ }
58816+
58817+ if (default_role == NULL || kernel_role == NULL)
58818+ return -EINVAL;
58819+
58820+ return err;
58821+}
58822+
58823+static int
58824+gracl_init(struct gr_arg *args)
58825+{
58826+ int error = 0;
58827+
58828+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58829+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58830+
58831+ if (init_variables(args)) {
58832+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58833+ error = -ENOMEM;
58834+ free_variables();
58835+ goto out;
58836+ }
58837+
58838+ error = copy_user_acl(args);
58839+ free_init_variables();
58840+ if (error) {
58841+ free_variables();
58842+ goto out;
58843+ }
58844+
58845+ if ((error = gr_set_acls(0))) {
58846+ free_variables();
58847+ goto out;
58848+ }
58849+
58850+ pax_open_kernel();
58851+ gr_status |= GR_READY;
58852+ pax_close_kernel();
58853+
58854+ out:
58855+ return error;
58856+}
58857+
58858+/* derived from glibc fnmatch() 0: match, 1: no match*/
58859+
58860+static int
58861+glob_match(const char *p, const char *n)
58862+{
58863+ char c;
58864+
58865+ while ((c = *p++) != '\0') {
58866+ switch (c) {
58867+ case '?':
58868+ if (*n == '\0')
58869+ return 1;
58870+ else if (*n == '/')
58871+ return 1;
58872+ break;
58873+ case '\\':
58874+ if (*n != c)
58875+ return 1;
58876+ break;
58877+ case '*':
58878+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
58879+ if (*n == '/')
58880+ return 1;
58881+ else if (c == '?') {
58882+ if (*n == '\0')
58883+ return 1;
58884+ else
58885+ ++n;
58886+ }
58887+ }
58888+ if (c == '\0') {
58889+ return 0;
58890+ } else {
58891+ const char *endp;
58892+
58893+ if ((endp = strchr(n, '/')) == NULL)
58894+ endp = n + strlen(n);
58895+
58896+ if (c == '[') {
58897+ for (--p; n < endp; ++n)
58898+ if (!glob_match(p, n))
58899+ return 0;
58900+ } else if (c == '/') {
58901+ while (*n != '\0' && *n != '/')
58902+ ++n;
58903+ if (*n == '/' && !glob_match(p, n + 1))
58904+ return 0;
58905+ } else {
58906+ for (--p; n < endp; ++n)
58907+ if (*n == c && !glob_match(p, n))
58908+ return 0;
58909+ }
58910+
58911+ return 1;
58912+ }
58913+ case '[':
58914+ {
58915+ int not;
58916+ char cold;
58917+
58918+ if (*n == '\0' || *n == '/')
58919+ return 1;
58920+
58921+ not = (*p == '!' || *p == '^');
58922+ if (not)
58923+ ++p;
58924+
58925+ c = *p++;
58926+ for (;;) {
58927+ unsigned char fn = (unsigned char)*n;
58928+
58929+ if (c == '\0')
58930+ return 1;
58931+ else {
58932+ if (c == fn)
58933+ goto matched;
58934+ cold = c;
58935+ c = *p++;
58936+
58937+ if (c == '-' && *p != ']') {
58938+ unsigned char cend = *p++;
58939+
58940+ if (cend == '\0')
58941+ return 1;
58942+
58943+ if (cold <= fn && fn <= cend)
58944+ goto matched;
58945+
58946+ c = *p++;
58947+ }
58948+ }
58949+
58950+ if (c == ']')
58951+ break;
58952+ }
58953+ if (!not)
58954+ return 1;
58955+ break;
58956+ matched:
58957+ while (c != ']') {
58958+ if (c == '\0')
58959+ return 1;
58960+
58961+ c = *p++;
58962+ }
58963+ if (not)
58964+ return 1;
58965+ }
58966+ break;
58967+ default:
58968+ if (c != *n)
58969+ return 1;
58970+ }
58971+
58972+ ++n;
58973+ }
58974+
58975+ if (*n == '\0')
58976+ return 0;
58977+
58978+ if (*n == '/')
58979+ return 0;
58980+
58981+ return 1;
58982+}
58983+
58984+static struct acl_object_label *
58985+chk_glob_label(struct acl_object_label *globbed,
58986+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
58987+{
58988+ struct acl_object_label *tmp;
58989+
58990+ if (*path == NULL)
58991+ *path = gr_to_filename_nolock(dentry, mnt);
58992+
58993+ tmp = globbed;
58994+
58995+ while (tmp) {
58996+ if (!glob_match(tmp->filename, *path))
58997+ return tmp;
58998+ tmp = tmp->next;
58999+ }
59000+
59001+ return NULL;
59002+}
59003+
59004+static struct acl_object_label *
59005+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59006+ const ino_t curr_ino, const dev_t curr_dev,
59007+ const struct acl_subject_label *subj, char **path, const int checkglob)
59008+{
59009+ struct acl_subject_label *tmpsubj;
59010+ struct acl_object_label *retval;
59011+ struct acl_object_label *retval2;
59012+
59013+ tmpsubj = (struct acl_subject_label *) subj;
59014+ read_lock(&gr_inode_lock);
59015+ do {
59016+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59017+ if (retval) {
59018+ if (checkglob && retval->globbed) {
59019+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
59020+ if (retval2)
59021+ retval = retval2;
59022+ }
59023+ break;
59024+ }
59025+ } while ((tmpsubj = tmpsubj->parent_subject));
59026+ read_unlock(&gr_inode_lock);
59027+
59028+ return retval;
59029+}
59030+
59031+static __inline__ struct acl_object_label *
59032+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59033+ struct dentry *curr_dentry,
59034+ const struct acl_subject_label *subj, char **path, const int checkglob)
59035+{
59036+ int newglob = checkglob;
59037+ ino_t inode;
59038+ dev_t device;
59039+
59040+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
59041+ as we don't want a / * rule to match instead of the / object
59042+ don't do this for create lookups that call this function though, since they're looking up
59043+ on the parent and thus need globbing checks on all paths
59044+ */
59045+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
59046+ newglob = GR_NO_GLOB;
59047+
59048+ spin_lock(&curr_dentry->d_lock);
59049+ inode = curr_dentry->d_inode->i_ino;
59050+ device = __get_dev(curr_dentry);
59051+ spin_unlock(&curr_dentry->d_lock);
59052+
59053+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
59054+}
59055+
59056+#ifdef CONFIG_HUGETLBFS
59057+static inline bool
59058+is_hugetlbfs_mnt(const struct vfsmount *mnt)
59059+{
59060+ int i;
59061+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
59062+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
59063+ return true;
59064+ }
59065+
59066+ return false;
59067+}
59068+#endif
59069+
59070+static struct acl_object_label *
59071+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59072+ const struct acl_subject_label *subj, char *path, const int checkglob)
59073+{
59074+ struct dentry *dentry = (struct dentry *) l_dentry;
59075+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59076+ struct mount *real_mnt = real_mount(mnt);
59077+ struct acl_object_label *retval;
59078+ struct dentry *parent;
59079+
59080+ write_seqlock(&rename_lock);
59081+ br_read_lock(&vfsmount_lock);
59082+
59083+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
59084+#ifdef CONFIG_NET
59085+ mnt == sock_mnt ||
59086+#endif
59087+#ifdef CONFIG_HUGETLBFS
59088+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
59089+#endif
59090+ /* ignore Eric Biederman */
59091+ IS_PRIVATE(l_dentry->d_inode))) {
59092+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
59093+ goto out;
59094+ }
59095+
59096+ for (;;) {
59097+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59098+ break;
59099+
59100+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59101+ if (!mnt_has_parent(real_mnt))
59102+ break;
59103+
59104+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59105+ if (retval != NULL)
59106+ goto out;
59107+
59108+ dentry = real_mnt->mnt_mountpoint;
59109+ real_mnt = real_mnt->mnt_parent;
59110+ mnt = &real_mnt->mnt;
59111+ continue;
59112+ }
59113+
59114+ parent = dentry->d_parent;
59115+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59116+ if (retval != NULL)
59117+ goto out;
59118+
59119+ dentry = parent;
59120+ }
59121+
59122+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59123+
59124+ /* real_root is pinned so we don't have to hold a reference */
59125+ if (retval == NULL)
59126+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
59127+out:
59128+ br_read_unlock(&vfsmount_lock);
59129+ write_sequnlock(&rename_lock);
59130+
59131+ BUG_ON(retval == NULL);
59132+
59133+ return retval;
59134+}
59135+
59136+static __inline__ struct acl_object_label *
59137+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59138+ const struct acl_subject_label *subj)
59139+{
59140+ char *path = NULL;
59141+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
59142+}
59143+
59144+static __inline__ struct acl_object_label *
59145+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59146+ const struct acl_subject_label *subj)
59147+{
59148+ char *path = NULL;
59149+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
59150+}
59151+
59152+static __inline__ struct acl_object_label *
59153+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59154+ const struct acl_subject_label *subj, char *path)
59155+{
59156+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
59157+}
59158+
59159+static struct acl_subject_label *
59160+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59161+ const struct acl_role_label *role)
59162+{
59163+ struct dentry *dentry = (struct dentry *) l_dentry;
59164+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59165+ struct mount *real_mnt = real_mount(mnt);
59166+ struct acl_subject_label *retval;
59167+ struct dentry *parent;
59168+
59169+ write_seqlock(&rename_lock);
59170+ br_read_lock(&vfsmount_lock);
59171+
59172+ for (;;) {
59173+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59174+ break;
59175+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59176+ if (!mnt_has_parent(real_mnt))
59177+ break;
59178+
59179+ spin_lock(&dentry->d_lock);
59180+ read_lock(&gr_inode_lock);
59181+ retval =
59182+ lookup_acl_subj_label(dentry->d_inode->i_ino,
59183+ __get_dev(dentry), role);
59184+ read_unlock(&gr_inode_lock);
59185+ spin_unlock(&dentry->d_lock);
59186+ if (retval != NULL)
59187+ goto out;
59188+
59189+ dentry = real_mnt->mnt_mountpoint;
59190+ real_mnt = real_mnt->mnt_parent;
59191+ mnt = &real_mnt->mnt;
59192+ continue;
59193+ }
59194+
59195+ spin_lock(&dentry->d_lock);
59196+ read_lock(&gr_inode_lock);
59197+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59198+ __get_dev(dentry), role);
59199+ read_unlock(&gr_inode_lock);
59200+ parent = dentry->d_parent;
59201+ spin_unlock(&dentry->d_lock);
59202+
59203+ if (retval != NULL)
59204+ goto out;
59205+
59206+ dentry = parent;
59207+ }
59208+
59209+ spin_lock(&dentry->d_lock);
59210+ read_lock(&gr_inode_lock);
59211+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59212+ __get_dev(dentry), role);
59213+ read_unlock(&gr_inode_lock);
59214+ spin_unlock(&dentry->d_lock);
59215+
59216+ if (unlikely(retval == NULL)) {
59217+ /* real_root is pinned, we don't need to hold a reference */
59218+ read_lock(&gr_inode_lock);
59219+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
59220+ __get_dev(real_root.dentry), role);
59221+ read_unlock(&gr_inode_lock);
59222+ }
59223+out:
59224+ br_read_unlock(&vfsmount_lock);
59225+ write_sequnlock(&rename_lock);
59226+
59227+ BUG_ON(retval == NULL);
59228+
59229+ return retval;
59230+}
59231+
59232+static void
59233+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
59234+{
59235+ struct task_struct *task = current;
59236+ const struct cred *cred = current_cred();
59237+
59238+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
59239+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59240+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59241+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
59242+
59243+ return;
59244+}
59245+
59246+static void
59247+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
59248+{
59249+ struct task_struct *task = current;
59250+ const struct cred *cred = current_cred();
59251+
59252+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59253+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59254+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59255+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
59256+
59257+ return;
59258+}
59259+
59260+static void
59261+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
59262+{
59263+ struct task_struct *task = current;
59264+ const struct cred *cred = current_cred();
59265+
59266+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59267+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59268+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59269+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
59270+
59271+ return;
59272+}
59273+
59274+__u32
59275+gr_search_file(const struct dentry * dentry, const __u32 mode,
59276+ const struct vfsmount * mnt)
59277+{
59278+ __u32 retval = mode;
59279+ struct acl_subject_label *curracl;
59280+ struct acl_object_label *currobj;
59281+
59282+ if (unlikely(!(gr_status & GR_READY)))
59283+ return (mode & ~GR_AUDITS);
59284+
59285+ curracl = current->acl;
59286+
59287+ currobj = chk_obj_label(dentry, mnt, curracl);
59288+ retval = currobj->mode & mode;
59289+
59290+ /* if we're opening a specified transfer file for writing
59291+ (e.g. /dev/initctl), then transfer our role to init
59292+ */
59293+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
59294+ current->role->roletype & GR_ROLE_PERSIST)) {
59295+ struct task_struct *task = init_pid_ns.child_reaper;
59296+
59297+ if (task->role != current->role) {
59298+ task->acl_sp_role = 0;
59299+ task->acl_role_id = current->acl_role_id;
59300+ task->role = current->role;
59301+ rcu_read_lock();
59302+ read_lock(&grsec_exec_file_lock);
59303+ gr_apply_subject_to_task(task);
59304+ read_unlock(&grsec_exec_file_lock);
59305+ rcu_read_unlock();
59306+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
59307+ }
59308+ }
59309+
59310+ if (unlikely
59311+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
59312+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
59313+ __u32 new_mode = mode;
59314+
59315+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59316+
59317+ retval = new_mode;
59318+
59319+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
59320+ new_mode |= GR_INHERIT;
59321+
59322+ if (!(mode & GR_NOLEARN))
59323+ gr_log_learn(dentry, mnt, new_mode);
59324+ }
59325+
59326+ return retval;
59327+}
59328+
59329+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
59330+ const struct dentry *parent,
59331+ const struct vfsmount *mnt)
59332+{
59333+ struct name_entry *match;
59334+ struct acl_object_label *matchpo;
59335+ struct acl_subject_label *curracl;
59336+ char *path;
59337+
59338+ if (unlikely(!(gr_status & GR_READY)))
59339+ return NULL;
59340+
59341+ preempt_disable();
59342+ path = gr_to_filename_rbac(new_dentry, mnt);
59343+ match = lookup_name_entry_create(path);
59344+
59345+ curracl = current->acl;
59346+
59347+ if (match) {
59348+ read_lock(&gr_inode_lock);
59349+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
59350+ read_unlock(&gr_inode_lock);
59351+
59352+ if (matchpo) {
59353+ preempt_enable();
59354+ return matchpo;
59355+ }
59356+ }
59357+
59358+ // lookup parent
59359+
59360+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
59361+
59362+ preempt_enable();
59363+ return matchpo;
59364+}
59365+
59366+__u32
59367+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
59368+ const struct vfsmount * mnt, const __u32 mode)
59369+{
59370+ struct acl_object_label *matchpo;
59371+ __u32 retval;
59372+
59373+ if (unlikely(!(gr_status & GR_READY)))
59374+ return (mode & ~GR_AUDITS);
59375+
59376+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
59377+
59378+ retval = matchpo->mode & mode;
59379+
59380+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
59381+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59382+ __u32 new_mode = mode;
59383+
59384+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59385+
59386+ gr_log_learn(new_dentry, mnt, new_mode);
59387+ return new_mode;
59388+ }
59389+
59390+ return retval;
59391+}
59392+
59393+__u32
59394+gr_check_link(const struct dentry * new_dentry,
59395+ const struct dentry * parent_dentry,
59396+ const struct vfsmount * parent_mnt,
59397+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
59398+{
59399+ struct acl_object_label *obj;
59400+ __u32 oldmode, newmode;
59401+ __u32 needmode;
59402+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
59403+ GR_DELETE | GR_INHERIT;
59404+
59405+ if (unlikely(!(gr_status & GR_READY)))
59406+ return (GR_CREATE | GR_LINK);
59407+
59408+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
59409+ oldmode = obj->mode;
59410+
59411+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
59412+ newmode = obj->mode;
59413+
59414+ needmode = newmode & checkmodes;
59415+
59416+ // old name for hardlink must have at least the permissions of the new name
59417+ if ((oldmode & needmode) != needmode)
59418+ goto bad;
59419+
59420+ // if old name had restrictions/auditing, make sure the new name does as well
59421+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
59422+
59423+ // don't allow hardlinking of suid/sgid/fcapped files without permission
59424+ if (is_privileged_binary(old_dentry))
59425+ needmode |= GR_SETID;
59426+
59427+ if ((newmode & needmode) != needmode)
59428+ goto bad;
59429+
59430+ // enforce minimum permissions
59431+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
59432+ return newmode;
59433+bad:
59434+ needmode = oldmode;
59435+ if (is_privileged_binary(old_dentry))
59436+ needmode |= GR_SETID;
59437+
59438+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
59439+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
59440+ return (GR_CREATE | GR_LINK);
59441+ } else if (newmode & GR_SUPPRESS)
59442+ return GR_SUPPRESS;
59443+ else
59444+ return 0;
59445+}
59446+
59447+int
59448+gr_check_hidden_task(const struct task_struct *task)
59449+{
59450+ if (unlikely(!(gr_status & GR_READY)))
59451+ return 0;
59452+
59453+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59454+ return 1;
59455+
59456+ return 0;
59457+}
59458+
59459+int
59460+gr_check_protected_task(const struct task_struct *task)
59461+{
59462+ if (unlikely(!(gr_status & GR_READY) || !task))
59463+ return 0;
59464+
59465+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59466+ task->acl != current->acl)
59467+ return 1;
59468+
59469+ return 0;
59470+}
59471+
59472+int
59473+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59474+{
59475+ struct task_struct *p;
59476+ int ret = 0;
59477+
59478+ if (unlikely(!(gr_status & GR_READY) || !pid))
59479+ return ret;
59480+
59481+ read_lock(&tasklist_lock);
59482+ do_each_pid_task(pid, type, p) {
59483+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59484+ p->acl != current->acl) {
59485+ ret = 1;
59486+ goto out;
59487+ }
59488+ } while_each_pid_task(pid, type, p);
59489+out:
59490+ read_unlock(&tasklist_lock);
59491+
59492+ return ret;
59493+}
59494+
59495+void
59496+gr_copy_label(struct task_struct *tsk)
59497+{
59498+ tsk->signal->used_accept = 0;
59499+ tsk->acl_sp_role = 0;
59500+ tsk->acl_role_id = current->acl_role_id;
59501+ tsk->acl = current->acl;
59502+ tsk->role = current->role;
59503+ tsk->signal->curr_ip = current->signal->curr_ip;
59504+ tsk->signal->saved_ip = current->signal->saved_ip;
59505+ if (current->exec_file)
59506+ get_file(current->exec_file);
59507+ tsk->exec_file = current->exec_file;
59508+ tsk->is_writable = current->is_writable;
59509+ if (unlikely(current->signal->used_accept)) {
59510+ current->signal->curr_ip = 0;
59511+ current->signal->saved_ip = 0;
59512+ }
59513+
59514+ return;
59515+}
59516+
59517+static void
59518+gr_set_proc_res(struct task_struct *task)
59519+{
59520+ struct acl_subject_label *proc;
59521+ unsigned short i;
59522+
59523+ proc = task->acl;
59524+
59525+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59526+ return;
59527+
59528+ for (i = 0; i < RLIM_NLIMITS; i++) {
59529+ if (!(proc->resmask & (1 << i)))
59530+ continue;
59531+
59532+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59533+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59534+
59535+ if (i == RLIMIT_CPU)
59536+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
59537+ }
59538+
59539+ return;
59540+}
59541+
59542+extern int __gr_process_user_ban(struct user_struct *user);
59543+
59544+int
59545+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59546+{
59547+ unsigned int i;
59548+ __u16 num;
59549+ uid_t *uidlist;
59550+ uid_t curuid;
59551+ int realok = 0;
59552+ int effectiveok = 0;
59553+ int fsok = 0;
59554+ uid_t globalreal, globaleffective, globalfs;
59555+
59556+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59557+ struct user_struct *user;
59558+
59559+ if (!uid_valid(real))
59560+ goto skipit;
59561+
59562+ /* find user based on global namespace */
59563+
59564+ globalreal = GR_GLOBAL_UID(real);
59565+
59566+ user = find_user(make_kuid(&init_user_ns, globalreal));
59567+ if (user == NULL)
59568+ goto skipit;
59569+
59570+ if (__gr_process_user_ban(user)) {
59571+ /* for find_user */
59572+ free_uid(user);
59573+ return 1;
59574+ }
59575+
59576+ /* for find_user */
59577+ free_uid(user);
59578+
59579+skipit:
59580+#endif
59581+
59582+ if (unlikely(!(gr_status & GR_READY)))
59583+ return 0;
59584+
59585+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59586+ gr_log_learn_uid_change(real, effective, fs);
59587+
59588+ num = current->acl->user_trans_num;
59589+ uidlist = current->acl->user_transitions;
59590+
59591+ if (uidlist == NULL)
59592+ return 0;
59593+
59594+ if (!uid_valid(real)) {
59595+ realok = 1;
59596+ globalreal = (uid_t)-1;
59597+ } else {
59598+ globalreal = GR_GLOBAL_UID(real);
59599+ }
59600+ if (!uid_valid(effective)) {
59601+ effectiveok = 1;
59602+ globaleffective = (uid_t)-1;
59603+ } else {
59604+ globaleffective = GR_GLOBAL_UID(effective);
59605+ }
59606+ if (!uid_valid(fs)) {
59607+ fsok = 1;
59608+ globalfs = (uid_t)-1;
59609+ } else {
59610+ globalfs = GR_GLOBAL_UID(fs);
59611+ }
59612+
59613+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
59614+ for (i = 0; i < num; i++) {
59615+ curuid = uidlist[i];
59616+ if (globalreal == curuid)
59617+ realok = 1;
59618+ if (globaleffective == curuid)
59619+ effectiveok = 1;
59620+ if (globalfs == curuid)
59621+ fsok = 1;
59622+ }
59623+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
59624+ for (i = 0; i < num; i++) {
59625+ curuid = uidlist[i];
59626+ if (globalreal == curuid)
59627+ break;
59628+ if (globaleffective == curuid)
59629+ break;
59630+ if (globalfs == curuid)
59631+ break;
59632+ }
59633+ /* not in deny list */
59634+ if (i == num) {
59635+ realok = 1;
59636+ effectiveok = 1;
59637+ fsok = 1;
59638+ }
59639+ }
59640+
59641+ if (realok && effectiveok && fsok)
59642+ return 0;
59643+ else {
59644+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59645+ return 1;
59646+ }
59647+}
59648+
59649+int
59650+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59651+{
59652+ unsigned int i;
59653+ __u16 num;
59654+ gid_t *gidlist;
59655+ gid_t curgid;
59656+ int realok = 0;
59657+ int effectiveok = 0;
59658+ int fsok = 0;
59659+ gid_t globalreal, globaleffective, globalfs;
59660+
59661+ if (unlikely(!(gr_status & GR_READY)))
59662+ return 0;
59663+
59664+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59665+ gr_log_learn_gid_change(real, effective, fs);
59666+
59667+ num = current->acl->group_trans_num;
59668+ gidlist = current->acl->group_transitions;
59669+
59670+ if (gidlist == NULL)
59671+ return 0;
59672+
59673+ if (!gid_valid(real)) {
59674+ realok = 1;
59675+ globalreal = (gid_t)-1;
59676+ } else {
59677+ globalreal = GR_GLOBAL_GID(real);
59678+ }
59679+ if (!gid_valid(effective)) {
59680+ effectiveok = 1;
59681+ globaleffective = (gid_t)-1;
59682+ } else {
59683+ globaleffective = GR_GLOBAL_GID(effective);
59684+ }
59685+ if (!gid_valid(fs)) {
59686+ fsok = 1;
59687+ globalfs = (gid_t)-1;
59688+ } else {
59689+ globalfs = GR_GLOBAL_GID(fs);
59690+ }
59691+
59692+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
59693+ for (i = 0; i < num; i++) {
59694+ curgid = gidlist[i];
59695+ if (globalreal == curgid)
59696+ realok = 1;
59697+ if (globaleffective == curgid)
59698+ effectiveok = 1;
59699+ if (globalfs == curgid)
59700+ fsok = 1;
59701+ }
59702+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
59703+ for (i = 0; i < num; i++) {
59704+ curgid = gidlist[i];
59705+ if (globalreal == curgid)
59706+ break;
59707+ if (globaleffective == curgid)
59708+ break;
59709+ if (globalfs == curgid)
59710+ break;
59711+ }
59712+ /* not in deny list */
59713+ if (i == num) {
59714+ realok = 1;
59715+ effectiveok = 1;
59716+ fsok = 1;
59717+ }
59718+ }
59719+
59720+ if (realok && effectiveok && fsok)
59721+ return 0;
59722+ else {
59723+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59724+ return 1;
59725+ }
59726+}
59727+
59728+extern int gr_acl_is_capable(const int cap);
59729+
59730+void
59731+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59732+{
59733+ struct acl_role_label *role = task->role;
59734+ struct acl_subject_label *subj = NULL;
59735+ struct acl_object_label *obj;
59736+ struct file *filp;
59737+ uid_t uid;
59738+ gid_t gid;
59739+
59740+ if (unlikely(!(gr_status & GR_READY)))
59741+ return;
59742+
59743+ uid = GR_GLOBAL_UID(kuid);
59744+ gid = GR_GLOBAL_GID(kgid);
59745+
59746+ filp = task->exec_file;
59747+
59748+ /* kernel process, we'll give them the kernel role */
59749+ if (unlikely(!filp)) {
59750+ task->role = kernel_role;
59751+ task->acl = kernel_role->root_label;
59752+ return;
59753+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59754+ role = lookup_acl_role_label(task, uid, gid);
59755+
59756+ /* don't change the role if we're not a privileged process */
59757+ if (role && task->role != role &&
59758+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59759+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59760+ return;
59761+
59762+ /* perform subject lookup in possibly new role
59763+ we can use this result below in the case where role == task->role
59764+ */
59765+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59766+
59767+ /* if we changed uid/gid, but result in the same role
59768+ and are using inheritance, don't lose the inherited subject
59769+ if current subject is other than what normal lookup
59770+ would result in, we arrived via inheritance, don't
59771+ lose subject
59772+ */
59773+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59774+ (subj == task->acl)))
59775+ task->acl = subj;
59776+
59777+ task->role = role;
59778+
59779+ task->is_writable = 0;
59780+
59781+ /* ignore additional mmap checks for processes that are writable
59782+ by the default ACL */
59783+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59784+ if (unlikely(obj->mode & GR_WRITE))
59785+ task->is_writable = 1;
59786+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59787+ if (unlikely(obj->mode & GR_WRITE))
59788+ task->is_writable = 1;
59789+
59790+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59791+ 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);
59792+#endif
59793+
59794+ gr_set_proc_res(task);
59795+
59796+ return;
59797+}
59798+
59799+int
59800+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59801+ const int unsafe_flags)
59802+{
59803+ struct task_struct *task = current;
59804+ struct acl_subject_label *newacl;
59805+ struct acl_object_label *obj;
59806+ __u32 retmode;
59807+
59808+ if (unlikely(!(gr_status & GR_READY)))
59809+ return 0;
59810+
59811+ newacl = chk_subj_label(dentry, mnt, task->role);
59812+
59813+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59814+ did an exec
59815+ */
59816+ rcu_read_lock();
59817+ read_lock(&tasklist_lock);
59818+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59819+ (task->parent->acl->mode & GR_POVERRIDE))) {
59820+ read_unlock(&tasklist_lock);
59821+ rcu_read_unlock();
59822+ goto skip_check;
59823+ }
59824+ read_unlock(&tasklist_lock);
59825+ rcu_read_unlock();
59826+
59827+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59828+ !(task->role->roletype & GR_ROLE_GOD) &&
59829+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59830+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59831+ if (unsafe_flags & LSM_UNSAFE_SHARE)
59832+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59833+ else
59834+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59835+ return -EACCES;
59836+ }
59837+
59838+skip_check:
59839+
59840+ obj = chk_obj_label(dentry, mnt, task->acl);
59841+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59842+
59843+ if (!(task->acl->mode & GR_INHERITLEARN) &&
59844+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59845+ if (obj->nested)
59846+ task->acl = obj->nested;
59847+ else
59848+ task->acl = newacl;
59849+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59850+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59851+
59852+ task->is_writable = 0;
59853+
59854+ /* ignore additional mmap checks for processes that are writable
59855+ by the default ACL */
59856+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
59857+ if (unlikely(obj->mode & GR_WRITE))
59858+ task->is_writable = 1;
59859+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
59860+ if (unlikely(obj->mode & GR_WRITE))
59861+ task->is_writable = 1;
59862+
59863+ gr_set_proc_res(task);
59864+
59865+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59866+ 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);
59867+#endif
59868+ return 0;
59869+}
59870+
59871+/* always called with valid inodev ptr */
59872+static void
59873+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59874+{
59875+ struct acl_object_label *matchpo;
59876+ struct acl_subject_label *matchps;
59877+ struct acl_subject_label *subj;
59878+ struct acl_role_label *role;
59879+ unsigned int x;
59880+
59881+ FOR_EACH_ROLE_START(role)
59882+ FOR_EACH_SUBJECT_START(role, subj, x)
59883+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59884+ matchpo->mode |= GR_DELETED;
59885+ FOR_EACH_SUBJECT_END(subj,x)
59886+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
59887+ /* nested subjects aren't in the role's subj_hash table */
59888+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59889+ matchpo->mode |= GR_DELETED;
59890+ FOR_EACH_NESTED_SUBJECT_END(subj)
59891+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59892+ matchps->mode |= GR_DELETED;
59893+ FOR_EACH_ROLE_END(role)
59894+
59895+ inodev->nentry->deleted = 1;
59896+
59897+ return;
59898+}
59899+
59900+void
59901+gr_handle_delete(const ino_t ino, const dev_t dev)
59902+{
59903+ struct inodev_entry *inodev;
59904+
59905+ if (unlikely(!(gr_status & GR_READY)))
59906+ return;
59907+
59908+ write_lock(&gr_inode_lock);
59909+ inodev = lookup_inodev_entry(ino, dev);
59910+ if (inodev != NULL)
59911+ do_handle_delete(inodev, ino, dev);
59912+ write_unlock(&gr_inode_lock);
59913+
59914+ return;
59915+}
59916+
59917+static void
59918+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59919+ const ino_t newinode, const dev_t newdevice,
59920+ struct acl_subject_label *subj)
59921+{
59922+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59923+ struct acl_object_label *match;
59924+
59925+ match = subj->obj_hash[index];
59926+
59927+ while (match && (match->inode != oldinode ||
59928+ match->device != olddevice ||
59929+ !(match->mode & GR_DELETED)))
59930+ match = match->next;
59931+
59932+ if (match && (match->inode == oldinode)
59933+ && (match->device == olddevice)
59934+ && (match->mode & GR_DELETED)) {
59935+ if (match->prev == NULL) {
59936+ subj->obj_hash[index] = match->next;
59937+ if (match->next != NULL)
59938+ match->next->prev = NULL;
59939+ } else {
59940+ match->prev->next = match->next;
59941+ if (match->next != NULL)
59942+ match->next->prev = match->prev;
59943+ }
59944+ match->prev = NULL;
59945+ match->next = NULL;
59946+ match->inode = newinode;
59947+ match->device = newdevice;
59948+ match->mode &= ~GR_DELETED;
59949+
59950+ insert_acl_obj_label(match, subj);
59951+ }
59952+
59953+ return;
59954+}
59955+
59956+static void
59957+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
59958+ const ino_t newinode, const dev_t newdevice,
59959+ struct acl_role_label *role)
59960+{
59961+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
59962+ struct acl_subject_label *match;
59963+
59964+ match = role->subj_hash[index];
59965+
59966+ while (match && (match->inode != oldinode ||
59967+ match->device != olddevice ||
59968+ !(match->mode & GR_DELETED)))
59969+ match = match->next;
59970+
59971+ if (match && (match->inode == oldinode)
59972+ && (match->device == olddevice)
59973+ && (match->mode & GR_DELETED)) {
59974+ if (match->prev == NULL) {
59975+ role->subj_hash[index] = match->next;
59976+ if (match->next != NULL)
59977+ match->next->prev = NULL;
59978+ } else {
59979+ match->prev->next = match->next;
59980+ if (match->next != NULL)
59981+ match->next->prev = match->prev;
59982+ }
59983+ match->prev = NULL;
59984+ match->next = NULL;
59985+ match->inode = newinode;
59986+ match->device = newdevice;
59987+ match->mode &= ~GR_DELETED;
59988+
59989+ insert_acl_subj_label(match, role);
59990+ }
59991+
59992+ return;
59993+}
59994+
59995+static void
59996+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
59997+ const ino_t newinode, const dev_t newdevice)
59998+{
59999+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60000+ struct inodev_entry *match;
60001+
60002+ match = inodev_set.i_hash[index];
60003+
60004+ while (match && (match->nentry->inode != oldinode ||
60005+ match->nentry->device != olddevice || !match->nentry->deleted))
60006+ match = match->next;
60007+
60008+ if (match && (match->nentry->inode == oldinode)
60009+ && (match->nentry->device == olddevice) &&
60010+ match->nentry->deleted) {
60011+ if (match->prev == NULL) {
60012+ inodev_set.i_hash[index] = match->next;
60013+ if (match->next != NULL)
60014+ match->next->prev = NULL;
60015+ } else {
60016+ match->prev->next = match->next;
60017+ if (match->next != NULL)
60018+ match->next->prev = match->prev;
60019+ }
60020+ match->prev = NULL;
60021+ match->next = NULL;
60022+ match->nentry->inode = newinode;
60023+ match->nentry->device = newdevice;
60024+ match->nentry->deleted = 0;
60025+
60026+ insert_inodev_entry(match);
60027+ }
60028+
60029+ return;
60030+}
60031+
60032+static void
60033+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
60034+{
60035+ struct acl_subject_label *subj;
60036+ struct acl_role_label *role;
60037+ unsigned int x;
60038+
60039+ FOR_EACH_ROLE_START(role)
60040+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
60041+
60042+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60043+ if ((subj->inode == ino) && (subj->device == dev)) {
60044+ subj->inode = ino;
60045+ subj->device = dev;
60046+ }
60047+ /* nested subjects aren't in the role's subj_hash table */
60048+ update_acl_obj_label(matchn->inode, matchn->device,
60049+ ino, dev, subj);
60050+ FOR_EACH_NESTED_SUBJECT_END(subj)
60051+ FOR_EACH_SUBJECT_START(role, subj, x)
60052+ update_acl_obj_label(matchn->inode, matchn->device,
60053+ ino, dev, subj);
60054+ FOR_EACH_SUBJECT_END(subj,x)
60055+ FOR_EACH_ROLE_END(role)
60056+
60057+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
60058+
60059+ return;
60060+}
60061+
60062+static void
60063+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
60064+ const struct vfsmount *mnt)
60065+{
60066+ ino_t ino = dentry->d_inode->i_ino;
60067+ dev_t dev = __get_dev(dentry);
60068+
60069+ __do_handle_create(matchn, ino, dev);
60070+
60071+ return;
60072+}
60073+
60074+void
60075+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60076+{
60077+ struct name_entry *matchn;
60078+
60079+ if (unlikely(!(gr_status & GR_READY)))
60080+ return;
60081+
60082+ preempt_disable();
60083+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
60084+
60085+ if (unlikely((unsigned long)matchn)) {
60086+ write_lock(&gr_inode_lock);
60087+ do_handle_create(matchn, dentry, mnt);
60088+ write_unlock(&gr_inode_lock);
60089+ }
60090+ preempt_enable();
60091+
60092+ return;
60093+}
60094+
60095+void
60096+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60097+{
60098+ struct name_entry *matchn;
60099+
60100+ if (unlikely(!(gr_status & GR_READY)))
60101+ return;
60102+
60103+ preempt_disable();
60104+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
60105+
60106+ if (unlikely((unsigned long)matchn)) {
60107+ write_lock(&gr_inode_lock);
60108+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
60109+ write_unlock(&gr_inode_lock);
60110+ }
60111+ preempt_enable();
60112+
60113+ return;
60114+}
60115+
60116+void
60117+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60118+ struct dentry *old_dentry,
60119+ struct dentry *new_dentry,
60120+ struct vfsmount *mnt, const __u8 replace)
60121+{
60122+ struct name_entry *matchn;
60123+ struct inodev_entry *inodev;
60124+ struct inode *inode = new_dentry->d_inode;
60125+ ino_t old_ino = old_dentry->d_inode->i_ino;
60126+ dev_t old_dev = __get_dev(old_dentry);
60127+
60128+ /* vfs_rename swaps the name and parent link for old_dentry and
60129+ new_dentry
60130+ at this point, old_dentry has the new name, parent link, and inode
60131+ for the renamed file
60132+ if a file is being replaced by a rename, new_dentry has the inode
60133+ and name for the replaced file
60134+ */
60135+
60136+ if (unlikely(!(gr_status & GR_READY)))
60137+ return;
60138+
60139+ preempt_disable();
60140+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
60141+
60142+ /* we wouldn't have to check d_inode if it weren't for
60143+ NFS silly-renaming
60144+ */
60145+
60146+ write_lock(&gr_inode_lock);
60147+ if (unlikely(replace && inode)) {
60148+ ino_t new_ino = inode->i_ino;
60149+ dev_t new_dev = __get_dev(new_dentry);
60150+
60151+ inodev = lookup_inodev_entry(new_ino, new_dev);
60152+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
60153+ do_handle_delete(inodev, new_ino, new_dev);
60154+ }
60155+
60156+ inodev = lookup_inodev_entry(old_ino, old_dev);
60157+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
60158+ do_handle_delete(inodev, old_ino, old_dev);
60159+
60160+ if (unlikely((unsigned long)matchn))
60161+ do_handle_create(matchn, old_dentry, mnt);
60162+
60163+ write_unlock(&gr_inode_lock);
60164+ preempt_enable();
60165+
60166+ return;
60167+}
60168+
60169+static int
60170+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
60171+ unsigned char **sum)
60172+{
60173+ struct acl_role_label *r;
60174+ struct role_allowed_ip *ipp;
60175+ struct role_transition *trans;
60176+ unsigned int i;
60177+ int found = 0;
60178+ u32 curr_ip = current->signal->curr_ip;
60179+
60180+ current->signal->saved_ip = curr_ip;
60181+
60182+ /* check transition table */
60183+
60184+ for (trans = current->role->transitions; trans; trans = trans->next) {
60185+ if (!strcmp(rolename, trans->rolename)) {
60186+ found = 1;
60187+ break;
60188+ }
60189+ }
60190+
60191+ if (!found)
60192+ return 0;
60193+
60194+ /* handle special roles that do not require authentication
60195+ and check ip */
60196+
60197+ FOR_EACH_ROLE_START(r)
60198+ if (!strcmp(rolename, r->rolename) &&
60199+ (r->roletype & GR_ROLE_SPECIAL)) {
60200+ found = 0;
60201+ if (r->allowed_ips != NULL) {
60202+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
60203+ if ((ntohl(curr_ip) & ipp->netmask) ==
60204+ (ntohl(ipp->addr) & ipp->netmask))
60205+ found = 1;
60206+ }
60207+ } else
60208+ found = 2;
60209+ if (!found)
60210+ return 0;
60211+
60212+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
60213+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
60214+ *salt = NULL;
60215+ *sum = NULL;
60216+ return 1;
60217+ }
60218+ }
60219+ FOR_EACH_ROLE_END(r)
60220+
60221+ for (i = 0; i < num_sprole_pws; i++) {
60222+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
60223+ *salt = acl_special_roles[i]->salt;
60224+ *sum = acl_special_roles[i]->sum;
60225+ return 1;
60226+ }
60227+ }
60228+
60229+ return 0;
60230+}
60231+
60232+static void
60233+assign_special_role(char *rolename)
60234+{
60235+ struct acl_object_label *obj;
60236+ struct acl_role_label *r;
60237+ struct acl_role_label *assigned = NULL;
60238+ struct task_struct *tsk;
60239+ struct file *filp;
60240+
60241+ FOR_EACH_ROLE_START(r)
60242+ if (!strcmp(rolename, r->rolename) &&
60243+ (r->roletype & GR_ROLE_SPECIAL)) {
60244+ assigned = r;
60245+ break;
60246+ }
60247+ FOR_EACH_ROLE_END(r)
60248+
60249+ if (!assigned)
60250+ return;
60251+
60252+ read_lock(&tasklist_lock);
60253+ read_lock(&grsec_exec_file_lock);
60254+
60255+ tsk = current->real_parent;
60256+ if (tsk == NULL)
60257+ goto out_unlock;
60258+
60259+ filp = tsk->exec_file;
60260+ if (filp == NULL)
60261+ goto out_unlock;
60262+
60263+ tsk->is_writable = 0;
60264+
60265+ tsk->acl_sp_role = 1;
60266+ tsk->acl_role_id = ++acl_sp_role_value;
60267+ tsk->role = assigned;
60268+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
60269+
60270+ /* ignore additional mmap checks for processes that are writable
60271+ by the default ACL */
60272+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60273+ if (unlikely(obj->mode & GR_WRITE))
60274+ tsk->is_writable = 1;
60275+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
60276+ if (unlikely(obj->mode & GR_WRITE))
60277+ tsk->is_writable = 1;
60278+
60279+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60280+ 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));
60281+#endif
60282+
60283+out_unlock:
60284+ read_unlock(&grsec_exec_file_lock);
60285+ read_unlock(&tasklist_lock);
60286+ return;
60287+}
60288+
60289+int gr_check_secure_terminal(struct task_struct *task)
60290+{
60291+ struct task_struct *p, *p2, *p3;
60292+ struct files_struct *files;
60293+ struct fdtable *fdt;
60294+ struct file *our_file = NULL, *file;
60295+ int i;
60296+
60297+ if (task->signal->tty == NULL)
60298+ return 1;
60299+
60300+ files = get_files_struct(task);
60301+ if (files != NULL) {
60302+ rcu_read_lock();
60303+ fdt = files_fdtable(files);
60304+ for (i=0; i < fdt->max_fds; i++) {
60305+ file = fcheck_files(files, i);
60306+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
60307+ get_file(file);
60308+ our_file = file;
60309+ }
60310+ }
60311+ rcu_read_unlock();
60312+ put_files_struct(files);
60313+ }
60314+
60315+ if (our_file == NULL)
60316+ return 1;
60317+
60318+ read_lock(&tasklist_lock);
60319+ do_each_thread(p2, p) {
60320+ files = get_files_struct(p);
60321+ if (files == NULL ||
60322+ (p->signal && p->signal->tty == task->signal->tty)) {
60323+ if (files != NULL)
60324+ put_files_struct(files);
60325+ continue;
60326+ }
60327+ rcu_read_lock();
60328+ fdt = files_fdtable(files);
60329+ for (i=0; i < fdt->max_fds; i++) {
60330+ file = fcheck_files(files, i);
60331+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
60332+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
60333+ p3 = task;
60334+ while (task_pid_nr(p3) > 0) {
60335+ if (p3 == p)
60336+ break;
60337+ p3 = p3->real_parent;
60338+ }
60339+ if (p3 == p)
60340+ break;
60341+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
60342+ gr_handle_alertkill(p);
60343+ rcu_read_unlock();
60344+ put_files_struct(files);
60345+ read_unlock(&tasklist_lock);
60346+ fput(our_file);
60347+ return 0;
60348+ }
60349+ }
60350+ rcu_read_unlock();
60351+ put_files_struct(files);
60352+ } while_each_thread(p2, p);
60353+ read_unlock(&tasklist_lock);
60354+
60355+ fput(our_file);
60356+ return 1;
60357+}
60358+
60359+static int gr_rbac_disable(void *unused)
60360+{
60361+ pax_open_kernel();
60362+ gr_status &= ~GR_READY;
60363+ pax_close_kernel();
60364+
60365+ return 0;
60366+}
60367+
60368+ssize_t
60369+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
60370+{
60371+ struct gr_arg_wrapper uwrap;
60372+ unsigned char *sprole_salt = NULL;
60373+ unsigned char *sprole_sum = NULL;
60374+ int error = sizeof (struct gr_arg_wrapper);
60375+ int error2 = 0;
60376+
60377+ mutex_lock(&gr_dev_mutex);
60378+
60379+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
60380+ error = -EPERM;
60381+ goto out;
60382+ }
60383+
60384+ if (count != sizeof (struct gr_arg_wrapper)) {
60385+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
60386+ error = -EINVAL;
60387+ goto out;
60388+ }
60389+
60390+
60391+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
60392+ gr_auth_expires = 0;
60393+ gr_auth_attempts = 0;
60394+ }
60395+
60396+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
60397+ error = -EFAULT;
60398+ goto out;
60399+ }
60400+
60401+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
60402+ error = -EINVAL;
60403+ goto out;
60404+ }
60405+
60406+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
60407+ error = -EFAULT;
60408+ goto out;
60409+ }
60410+
60411+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60412+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60413+ time_after(gr_auth_expires, get_seconds())) {
60414+ error = -EBUSY;
60415+ goto out;
60416+ }
60417+
60418+ /* if non-root trying to do anything other than use a special role,
60419+ do not attempt authentication, do not count towards authentication
60420+ locking
60421+ */
60422+
60423+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
60424+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60425+ gr_is_global_nonroot(current_uid())) {
60426+ error = -EPERM;
60427+ goto out;
60428+ }
60429+
60430+ /* ensure pw and special role name are null terminated */
60431+
60432+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
60433+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
60434+
60435+ /* Okay.
60436+ * We have our enough of the argument structure..(we have yet
60437+ * to copy_from_user the tables themselves) . Copy the tables
60438+ * only if we need them, i.e. for loading operations. */
60439+
60440+ switch (gr_usermode->mode) {
60441+ case GR_STATUS:
60442+ if (gr_status & GR_READY) {
60443+ error = 1;
60444+ if (!gr_check_secure_terminal(current))
60445+ error = 3;
60446+ } else
60447+ error = 2;
60448+ goto out;
60449+ case GR_SHUTDOWN:
60450+ if ((gr_status & GR_READY)
60451+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60452+ stop_machine(gr_rbac_disable, NULL, NULL);
60453+ free_variables();
60454+ memset(gr_usermode, 0, sizeof (struct gr_arg));
60455+ memset(gr_system_salt, 0, GR_SALT_LEN);
60456+ memset(gr_system_sum, 0, GR_SHA_LEN);
60457+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60458+ } else if (gr_status & GR_READY) {
60459+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60460+ error = -EPERM;
60461+ } else {
60462+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60463+ error = -EAGAIN;
60464+ }
60465+ break;
60466+ case GR_ENABLE:
60467+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60468+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60469+ else {
60470+ if (gr_status & GR_READY)
60471+ error = -EAGAIN;
60472+ else
60473+ error = error2;
60474+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60475+ }
60476+ break;
60477+ case GR_RELOAD:
60478+ if (!(gr_status & GR_READY)) {
60479+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60480+ error = -EAGAIN;
60481+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60482+ stop_machine(gr_rbac_disable, NULL, NULL);
60483+ free_variables();
60484+ error2 = gracl_init(gr_usermode);
60485+ if (!error2)
60486+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60487+ else {
60488+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60489+ error = error2;
60490+ }
60491+ } else {
60492+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60493+ error = -EPERM;
60494+ }
60495+ break;
60496+ case GR_SEGVMOD:
60497+ if (unlikely(!(gr_status & GR_READY))) {
60498+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60499+ error = -EAGAIN;
60500+ break;
60501+ }
60502+
60503+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60504+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60505+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60506+ struct acl_subject_label *segvacl;
60507+ segvacl =
60508+ lookup_acl_subj_label(gr_usermode->segv_inode,
60509+ gr_usermode->segv_device,
60510+ current->role);
60511+ if (segvacl) {
60512+ segvacl->crashes = 0;
60513+ segvacl->expires = 0;
60514+ }
60515+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60516+ gr_remove_uid(gr_usermode->segv_uid);
60517+ }
60518+ } else {
60519+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60520+ error = -EPERM;
60521+ }
60522+ break;
60523+ case GR_SPROLE:
60524+ case GR_SPROLEPAM:
60525+ if (unlikely(!(gr_status & GR_READY))) {
60526+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60527+ error = -EAGAIN;
60528+ break;
60529+ }
60530+
60531+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60532+ current->role->expires = 0;
60533+ current->role->auth_attempts = 0;
60534+ }
60535+
60536+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60537+ time_after(current->role->expires, get_seconds())) {
60538+ error = -EBUSY;
60539+ goto out;
60540+ }
60541+
60542+ if (lookup_special_role_auth
60543+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60544+ && ((!sprole_salt && !sprole_sum)
60545+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60546+ char *p = "";
60547+ assign_special_role(gr_usermode->sp_role);
60548+ read_lock(&tasklist_lock);
60549+ if (current->real_parent)
60550+ p = current->real_parent->role->rolename;
60551+ read_unlock(&tasklist_lock);
60552+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60553+ p, acl_sp_role_value);
60554+ } else {
60555+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60556+ error = -EPERM;
60557+ if(!(current->role->auth_attempts++))
60558+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60559+
60560+ goto out;
60561+ }
60562+ break;
60563+ case GR_UNSPROLE:
60564+ if (unlikely(!(gr_status & GR_READY))) {
60565+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60566+ error = -EAGAIN;
60567+ break;
60568+ }
60569+
60570+ if (current->role->roletype & GR_ROLE_SPECIAL) {
60571+ char *p = "";
60572+ int i = 0;
60573+
60574+ read_lock(&tasklist_lock);
60575+ if (current->real_parent) {
60576+ p = current->real_parent->role->rolename;
60577+ i = current->real_parent->acl_role_id;
60578+ }
60579+ read_unlock(&tasklist_lock);
60580+
60581+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60582+ gr_set_acls(1);
60583+ } else {
60584+ error = -EPERM;
60585+ goto out;
60586+ }
60587+ break;
60588+ default:
60589+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60590+ error = -EINVAL;
60591+ break;
60592+ }
60593+
60594+ if (error != -EPERM)
60595+ goto out;
60596+
60597+ if(!(gr_auth_attempts++))
60598+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60599+
60600+ out:
60601+ mutex_unlock(&gr_dev_mutex);
60602+ return error;
60603+}
60604+
60605+/* must be called with
60606+ rcu_read_lock();
60607+ read_lock(&tasklist_lock);
60608+ read_lock(&grsec_exec_file_lock);
60609+*/
60610+int gr_apply_subject_to_task(struct task_struct *task)
60611+{
60612+ struct acl_object_label *obj;
60613+ char *tmpname;
60614+ struct acl_subject_label *tmpsubj;
60615+ struct file *filp;
60616+ struct name_entry *nmatch;
60617+
60618+ filp = task->exec_file;
60619+ if (filp == NULL)
60620+ return 0;
60621+
60622+ /* the following is to apply the correct subject
60623+ on binaries running when the RBAC system
60624+ is enabled, when the binaries have been
60625+ replaced or deleted since their execution
60626+ -----
60627+ when the RBAC system starts, the inode/dev
60628+ from exec_file will be one the RBAC system
60629+ is unaware of. It only knows the inode/dev
60630+ of the present file on disk, or the absence
60631+ of it.
60632+ */
60633+ preempt_disable();
60634+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60635+
60636+ nmatch = lookup_name_entry(tmpname);
60637+ preempt_enable();
60638+ tmpsubj = NULL;
60639+ if (nmatch) {
60640+ if (nmatch->deleted)
60641+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60642+ else
60643+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60644+ if (tmpsubj != NULL)
60645+ task->acl = tmpsubj;
60646+ }
60647+ if (tmpsubj == NULL)
60648+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60649+ task->role);
60650+ if (task->acl) {
60651+ task->is_writable = 0;
60652+ /* ignore additional mmap checks for processes that are writable
60653+ by the default ACL */
60654+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60655+ if (unlikely(obj->mode & GR_WRITE))
60656+ task->is_writable = 1;
60657+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60658+ if (unlikely(obj->mode & GR_WRITE))
60659+ task->is_writable = 1;
60660+
60661+ gr_set_proc_res(task);
60662+
60663+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60664+ 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);
60665+#endif
60666+ } else {
60667+ return 1;
60668+ }
60669+
60670+ return 0;
60671+}
60672+
60673+int
60674+gr_set_acls(const int type)
60675+{
60676+ struct task_struct *task, *task2;
60677+ struct acl_role_label *role = current->role;
60678+ __u16 acl_role_id = current->acl_role_id;
60679+ const struct cred *cred;
60680+ int ret;
60681+
60682+ rcu_read_lock();
60683+ read_lock(&tasklist_lock);
60684+ read_lock(&grsec_exec_file_lock);
60685+ do_each_thread(task2, task) {
60686+ /* check to see if we're called from the exit handler,
60687+ if so, only replace ACLs that have inherited the admin
60688+ ACL */
60689+
60690+ if (type && (task->role != role ||
60691+ task->acl_role_id != acl_role_id))
60692+ continue;
60693+
60694+ task->acl_role_id = 0;
60695+ task->acl_sp_role = 0;
60696+
60697+ if (task->exec_file) {
60698+ cred = __task_cred(task);
60699+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60700+ ret = gr_apply_subject_to_task(task);
60701+ if (ret) {
60702+ read_unlock(&grsec_exec_file_lock);
60703+ read_unlock(&tasklist_lock);
60704+ rcu_read_unlock();
60705+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60706+ return ret;
60707+ }
60708+ } else {
60709+ // it's a kernel process
60710+ task->role = kernel_role;
60711+ task->acl = kernel_role->root_label;
60712+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60713+ task->acl->mode &= ~GR_PROCFIND;
60714+#endif
60715+ }
60716+ } while_each_thread(task2, task);
60717+ read_unlock(&grsec_exec_file_lock);
60718+ read_unlock(&tasklist_lock);
60719+ rcu_read_unlock();
60720+
60721+ return 0;
60722+}
60723+
60724+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60725+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60726+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60727+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60728+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60729+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60730+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60731+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60732+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60733+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60734+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60735+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60736+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60737+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60738+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60739+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60740+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60741+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60742+};
60743+
60744+void
60745+gr_learn_resource(const struct task_struct *task,
60746+ const int res, const unsigned long wanted, const int gt)
60747+{
60748+ struct acl_subject_label *acl;
60749+ const struct cred *cred;
60750+
60751+ if (unlikely((gr_status & GR_READY) &&
60752+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60753+ goto skip_reslog;
60754+
60755+ gr_log_resource(task, res, wanted, gt);
60756+skip_reslog:
60757+
60758+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60759+ return;
60760+
60761+ acl = task->acl;
60762+
60763+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60764+ !(acl->resmask & (1 << (unsigned short) res))))
60765+ return;
60766+
60767+ if (wanted >= acl->res[res].rlim_cur) {
60768+ unsigned long res_add;
60769+
60770+ res_add = wanted + res_learn_bumps[res];
60771+
60772+ acl->res[res].rlim_cur = res_add;
60773+
60774+ if (wanted > acl->res[res].rlim_max)
60775+ acl->res[res].rlim_max = res_add;
60776+
60777+ /* only log the subject filename, since resource logging is supported for
60778+ single-subject learning only */
60779+ rcu_read_lock();
60780+ cred = __task_cred(task);
60781+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60782+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60783+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60784+ "", (unsigned long) res, &task->signal->saved_ip);
60785+ rcu_read_unlock();
60786+ }
60787+
60788+ return;
60789+}
60790+EXPORT_SYMBOL(gr_learn_resource);
60791+#endif
60792+
60793+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60794+void
60795+pax_set_initial_flags(struct linux_binprm *bprm)
60796+{
60797+ struct task_struct *task = current;
60798+ struct acl_subject_label *proc;
60799+ unsigned long flags;
60800+
60801+ if (unlikely(!(gr_status & GR_READY)))
60802+ return;
60803+
60804+ flags = pax_get_flags(task);
60805+
60806+ proc = task->acl;
60807+
60808+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60809+ flags &= ~MF_PAX_PAGEEXEC;
60810+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60811+ flags &= ~MF_PAX_SEGMEXEC;
60812+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60813+ flags &= ~MF_PAX_RANDMMAP;
60814+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60815+ flags &= ~MF_PAX_EMUTRAMP;
60816+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60817+ flags &= ~MF_PAX_MPROTECT;
60818+
60819+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60820+ flags |= MF_PAX_PAGEEXEC;
60821+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60822+ flags |= MF_PAX_SEGMEXEC;
60823+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60824+ flags |= MF_PAX_RANDMMAP;
60825+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60826+ flags |= MF_PAX_EMUTRAMP;
60827+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60828+ flags |= MF_PAX_MPROTECT;
60829+
60830+ pax_set_flags(task, flags);
60831+
60832+ return;
60833+}
60834+#endif
60835+
60836+int
60837+gr_handle_proc_ptrace(struct task_struct *task)
60838+{
60839+ struct file *filp;
60840+ struct task_struct *tmp = task;
60841+ struct task_struct *curtemp = current;
60842+ __u32 retmode;
60843+
60844+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60845+ if (unlikely(!(gr_status & GR_READY)))
60846+ return 0;
60847+#endif
60848+
60849+ read_lock(&tasklist_lock);
60850+ read_lock(&grsec_exec_file_lock);
60851+ filp = task->exec_file;
60852+
60853+ while (task_pid_nr(tmp) > 0) {
60854+ if (tmp == curtemp)
60855+ break;
60856+ tmp = tmp->real_parent;
60857+ }
60858+
60859+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60860+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60861+ read_unlock(&grsec_exec_file_lock);
60862+ read_unlock(&tasklist_lock);
60863+ return 1;
60864+ }
60865+
60866+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60867+ if (!(gr_status & GR_READY)) {
60868+ read_unlock(&grsec_exec_file_lock);
60869+ read_unlock(&tasklist_lock);
60870+ return 0;
60871+ }
60872+#endif
60873+
60874+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60875+ read_unlock(&grsec_exec_file_lock);
60876+ read_unlock(&tasklist_lock);
60877+
60878+ if (retmode & GR_NOPTRACE)
60879+ return 1;
60880+
60881+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60882+ && (current->acl != task->acl || (current->acl != current->role->root_label
60883+ && task_pid_nr(current) != task_pid_nr(task))))
60884+ return 1;
60885+
60886+ return 0;
60887+}
60888+
60889+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60890+{
60891+ if (unlikely(!(gr_status & GR_READY)))
60892+ return;
60893+
60894+ if (!(current->role->roletype & GR_ROLE_GOD))
60895+ return;
60896+
60897+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60898+ p->role->rolename, gr_task_roletype_to_char(p),
60899+ p->acl->filename);
60900+}
60901+
60902+int
60903+gr_handle_ptrace(struct task_struct *task, const long request)
60904+{
60905+ struct task_struct *tmp = task;
60906+ struct task_struct *curtemp = current;
60907+ __u32 retmode;
60908+
60909+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60910+ if (unlikely(!(gr_status & GR_READY)))
60911+ return 0;
60912+#endif
60913+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60914+ read_lock(&tasklist_lock);
60915+ while (task_pid_nr(tmp) > 0) {
60916+ if (tmp == curtemp)
60917+ break;
60918+ tmp = tmp->real_parent;
60919+ }
60920+
60921+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60922+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60923+ read_unlock(&tasklist_lock);
60924+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60925+ return 1;
60926+ }
60927+ read_unlock(&tasklist_lock);
60928+ }
60929+
60930+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60931+ if (!(gr_status & GR_READY))
60932+ return 0;
60933+#endif
60934+
60935+ read_lock(&grsec_exec_file_lock);
60936+ if (unlikely(!task->exec_file)) {
60937+ read_unlock(&grsec_exec_file_lock);
60938+ return 0;
60939+ }
60940+
60941+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60942+ read_unlock(&grsec_exec_file_lock);
60943+
60944+ if (retmode & GR_NOPTRACE) {
60945+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60946+ return 1;
60947+ }
60948+
60949+ if (retmode & GR_PTRACERD) {
60950+ switch (request) {
60951+ case PTRACE_SEIZE:
60952+ case PTRACE_POKETEXT:
60953+ case PTRACE_POKEDATA:
60954+ case PTRACE_POKEUSR:
60955+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60956+ case PTRACE_SETREGS:
60957+ case PTRACE_SETFPREGS:
60958+#endif
60959+#ifdef CONFIG_X86
60960+ case PTRACE_SETFPXREGS:
60961+#endif
60962+#ifdef CONFIG_ALTIVEC
60963+ case PTRACE_SETVRREGS:
60964+#endif
60965+ return 1;
60966+ default:
60967+ return 0;
60968+ }
60969+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
60970+ !(current->role->roletype & GR_ROLE_GOD) &&
60971+ (current->acl != task->acl)) {
60972+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60973+ return 1;
60974+ }
60975+
60976+ return 0;
60977+}
60978+
60979+static int is_writable_mmap(const struct file *filp)
60980+{
60981+ struct task_struct *task = current;
60982+ struct acl_object_label *obj, *obj2;
60983+
60984+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
60985+ !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))) {
60986+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60987+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
60988+ task->role->root_label);
60989+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
60990+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
60991+ return 1;
60992+ }
60993+ }
60994+ return 0;
60995+}
60996+
60997+int
60998+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
60999+{
61000+ __u32 mode;
61001+
61002+ if (unlikely(!file || !(prot & PROT_EXEC)))
61003+ return 1;
61004+
61005+ if (is_writable_mmap(file))
61006+ return 0;
61007+
61008+ mode =
61009+ gr_search_file(file->f_path.dentry,
61010+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61011+ file->f_path.mnt);
61012+
61013+ if (!gr_tpe_allow(file))
61014+ return 0;
61015+
61016+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61017+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61018+ return 0;
61019+ } else if (unlikely(!(mode & GR_EXEC))) {
61020+ return 0;
61021+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61022+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61023+ return 1;
61024+ }
61025+
61026+ return 1;
61027+}
61028+
61029+int
61030+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61031+{
61032+ __u32 mode;
61033+
61034+ if (unlikely(!file || !(prot & PROT_EXEC)))
61035+ return 1;
61036+
61037+ if (is_writable_mmap(file))
61038+ return 0;
61039+
61040+ mode =
61041+ gr_search_file(file->f_path.dentry,
61042+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61043+ file->f_path.mnt);
61044+
61045+ if (!gr_tpe_allow(file))
61046+ return 0;
61047+
61048+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61049+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61050+ return 0;
61051+ } else if (unlikely(!(mode & GR_EXEC))) {
61052+ return 0;
61053+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61054+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61055+ return 1;
61056+ }
61057+
61058+ return 1;
61059+}
61060+
61061+void
61062+gr_acl_handle_psacct(struct task_struct *task, const long code)
61063+{
61064+ unsigned long runtime;
61065+ unsigned long cputime;
61066+ unsigned int wday, cday;
61067+ __u8 whr, chr;
61068+ __u8 wmin, cmin;
61069+ __u8 wsec, csec;
61070+ struct timespec timeval;
61071+
61072+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
61073+ !(task->acl->mode & GR_PROCACCT)))
61074+ return;
61075+
61076+ do_posix_clock_monotonic_gettime(&timeval);
61077+ runtime = timeval.tv_sec - task->start_time.tv_sec;
61078+ wday = runtime / (3600 * 24);
61079+ runtime -= wday * (3600 * 24);
61080+ whr = runtime / 3600;
61081+ runtime -= whr * 3600;
61082+ wmin = runtime / 60;
61083+ runtime -= wmin * 60;
61084+ wsec = runtime;
61085+
61086+ cputime = (task->utime + task->stime) / HZ;
61087+ cday = cputime / (3600 * 24);
61088+ cputime -= cday * (3600 * 24);
61089+ chr = cputime / 3600;
61090+ cputime -= chr * 3600;
61091+ cmin = cputime / 60;
61092+ cputime -= cmin * 60;
61093+ csec = cputime;
61094+
61095+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
61096+
61097+ return;
61098+}
61099+
61100+void gr_set_kernel_label(struct task_struct *task)
61101+{
61102+ if (gr_status & GR_READY) {
61103+ task->role = kernel_role;
61104+ task->acl = kernel_role->root_label;
61105+ }
61106+ return;
61107+}
61108+
61109+#ifdef CONFIG_TASKSTATS
61110+int gr_is_taskstats_denied(int pid)
61111+{
61112+ struct task_struct *task;
61113+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61114+ const struct cred *cred;
61115+#endif
61116+ int ret = 0;
61117+
61118+ /* restrict taskstats viewing to un-chrooted root users
61119+ who have the 'view' subject flag if the RBAC system is enabled
61120+ */
61121+
61122+ rcu_read_lock();
61123+ read_lock(&tasklist_lock);
61124+ task = find_task_by_vpid(pid);
61125+ if (task) {
61126+#ifdef CONFIG_GRKERNSEC_CHROOT
61127+ if (proc_is_chrooted(task))
61128+ ret = -EACCES;
61129+#endif
61130+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61131+ cred = __task_cred(task);
61132+#ifdef CONFIG_GRKERNSEC_PROC_USER
61133+ if (gr_is_global_nonroot(cred->uid))
61134+ ret = -EACCES;
61135+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61136+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
61137+ ret = -EACCES;
61138+#endif
61139+#endif
61140+ if (gr_status & GR_READY) {
61141+ if (!(task->acl->mode & GR_VIEW))
61142+ ret = -EACCES;
61143+ }
61144+ } else
61145+ ret = -ENOENT;
61146+
61147+ read_unlock(&tasklist_lock);
61148+ rcu_read_unlock();
61149+
61150+ return ret;
61151+}
61152+#endif
61153+
61154+/* AUXV entries are filled via a descendant of search_binary_handler
61155+ after we've already applied the subject for the target
61156+*/
61157+int gr_acl_enable_at_secure(void)
61158+{
61159+ if (unlikely(!(gr_status & GR_READY)))
61160+ return 0;
61161+
61162+ if (current->acl->mode & GR_ATSECURE)
61163+ return 1;
61164+
61165+ return 0;
61166+}
61167+
61168+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
61169+{
61170+ struct task_struct *task = current;
61171+ struct dentry *dentry = file->f_path.dentry;
61172+ struct vfsmount *mnt = file->f_path.mnt;
61173+ struct acl_object_label *obj, *tmp;
61174+ struct acl_subject_label *subj;
61175+ unsigned int bufsize;
61176+ int is_not_root;
61177+ char *path;
61178+ dev_t dev = __get_dev(dentry);
61179+
61180+ if (unlikely(!(gr_status & GR_READY)))
61181+ return 1;
61182+
61183+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61184+ return 1;
61185+
61186+ /* ignore Eric Biederman */
61187+ if (IS_PRIVATE(dentry->d_inode))
61188+ return 1;
61189+
61190+ subj = task->acl;
61191+ read_lock(&gr_inode_lock);
61192+ do {
61193+ obj = lookup_acl_obj_label(ino, dev, subj);
61194+ if (obj != NULL) {
61195+ read_unlock(&gr_inode_lock);
61196+ return (obj->mode & GR_FIND) ? 1 : 0;
61197+ }
61198+ } while ((subj = subj->parent_subject));
61199+ read_unlock(&gr_inode_lock);
61200+
61201+ /* this is purely an optimization since we're looking for an object
61202+ for the directory we're doing a readdir on
61203+ if it's possible for any globbed object to match the entry we're
61204+ filling into the directory, then the object we find here will be
61205+ an anchor point with attached globbed objects
61206+ */
61207+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
61208+ if (obj->globbed == NULL)
61209+ return (obj->mode & GR_FIND) ? 1 : 0;
61210+
61211+ is_not_root = ((obj->filename[0] == '/') &&
61212+ (obj->filename[1] == '\0')) ? 0 : 1;
61213+ bufsize = PAGE_SIZE - namelen - is_not_root;
61214+
61215+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
61216+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
61217+ return 1;
61218+
61219+ preempt_disable();
61220+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
61221+ bufsize);
61222+
61223+ bufsize = strlen(path);
61224+
61225+ /* if base is "/", don't append an additional slash */
61226+ if (is_not_root)
61227+ *(path + bufsize) = '/';
61228+ memcpy(path + bufsize + is_not_root, name, namelen);
61229+ *(path + bufsize + namelen + is_not_root) = '\0';
61230+
61231+ tmp = obj->globbed;
61232+ while (tmp) {
61233+ if (!glob_match(tmp->filename, path)) {
61234+ preempt_enable();
61235+ return (tmp->mode & GR_FIND) ? 1 : 0;
61236+ }
61237+ tmp = tmp->next;
61238+ }
61239+ preempt_enable();
61240+ return (obj->mode & GR_FIND) ? 1 : 0;
61241+}
61242+
61243+void gr_put_exec_file(struct task_struct *task)
61244+{
61245+ struct file *filp;
61246+
61247+ write_lock(&grsec_exec_file_lock);
61248+ filp = task->exec_file;
61249+ task->exec_file = NULL;
61250+ write_unlock(&grsec_exec_file_lock);
61251+
61252+ if (filp)
61253+ fput(filp);
61254+
61255+ return;
61256+}
61257+
61258+
61259+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
61260+EXPORT_SYMBOL(gr_acl_is_enabled);
61261+#endif
61262+EXPORT_SYMBOL(gr_set_kernel_label);
61263+#ifdef CONFIG_SECURITY
61264+EXPORT_SYMBOL(gr_check_user_change);
61265+EXPORT_SYMBOL(gr_check_group_change);
61266+#endif
61267+
61268diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
61269new file mode 100644
61270index 0000000..34fefda
61271--- /dev/null
61272+++ b/grsecurity/gracl_alloc.c
61273@@ -0,0 +1,105 @@
61274+#include <linux/kernel.h>
61275+#include <linux/mm.h>
61276+#include <linux/slab.h>
61277+#include <linux/vmalloc.h>
61278+#include <linux/gracl.h>
61279+#include <linux/grsecurity.h>
61280+
61281+static unsigned long alloc_stack_next = 1;
61282+static unsigned long alloc_stack_size = 1;
61283+static void **alloc_stack;
61284+
61285+static __inline__ int
61286+alloc_pop(void)
61287+{
61288+ if (alloc_stack_next == 1)
61289+ return 0;
61290+
61291+ kfree(alloc_stack[alloc_stack_next - 2]);
61292+
61293+ alloc_stack_next--;
61294+
61295+ return 1;
61296+}
61297+
61298+static __inline__ int
61299+alloc_push(void *buf)
61300+{
61301+ if (alloc_stack_next >= alloc_stack_size)
61302+ return 1;
61303+
61304+ alloc_stack[alloc_stack_next - 1] = buf;
61305+
61306+ alloc_stack_next++;
61307+
61308+ return 0;
61309+}
61310+
61311+void *
61312+acl_alloc(unsigned long len)
61313+{
61314+ void *ret = NULL;
61315+
61316+ if (!len || len > PAGE_SIZE)
61317+ goto out;
61318+
61319+ ret = kmalloc(len, GFP_KERNEL);
61320+
61321+ if (ret) {
61322+ if (alloc_push(ret)) {
61323+ kfree(ret);
61324+ ret = NULL;
61325+ }
61326+ }
61327+
61328+out:
61329+ return ret;
61330+}
61331+
61332+void *
61333+acl_alloc_num(unsigned long num, unsigned long len)
61334+{
61335+ if (!len || (num > (PAGE_SIZE / len)))
61336+ return NULL;
61337+
61338+ return acl_alloc(num * len);
61339+}
61340+
61341+void
61342+acl_free_all(void)
61343+{
61344+ if (gr_acl_is_enabled() || !alloc_stack)
61345+ return;
61346+
61347+ while (alloc_pop()) ;
61348+
61349+ if (alloc_stack) {
61350+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
61351+ kfree(alloc_stack);
61352+ else
61353+ vfree(alloc_stack);
61354+ }
61355+
61356+ alloc_stack = NULL;
61357+ alloc_stack_size = 1;
61358+ alloc_stack_next = 1;
61359+
61360+ return;
61361+}
61362+
61363+int
61364+acl_alloc_stack_init(unsigned long size)
61365+{
61366+ if ((size * sizeof (void *)) <= PAGE_SIZE)
61367+ alloc_stack =
61368+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
61369+ else
61370+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
61371+
61372+ alloc_stack_size = size;
61373+
61374+ if (!alloc_stack)
61375+ return 0;
61376+ else
61377+ return 1;
61378+}
61379diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
61380new file mode 100644
61381index 0000000..bdd51ea
61382--- /dev/null
61383+++ b/grsecurity/gracl_cap.c
61384@@ -0,0 +1,110 @@
61385+#include <linux/kernel.h>
61386+#include <linux/module.h>
61387+#include <linux/sched.h>
61388+#include <linux/gracl.h>
61389+#include <linux/grsecurity.h>
61390+#include <linux/grinternal.h>
61391+
61392+extern const char *captab_log[];
61393+extern int captab_log_entries;
61394+
61395+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61396+{
61397+ struct acl_subject_label *curracl;
61398+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61399+ kernel_cap_t cap_audit = __cap_empty_set;
61400+
61401+ if (!gr_acl_is_enabled())
61402+ return 1;
61403+
61404+ curracl = task->acl;
61405+
61406+ cap_drop = curracl->cap_lower;
61407+ cap_mask = curracl->cap_mask;
61408+ cap_audit = curracl->cap_invert_audit;
61409+
61410+ while ((curracl = curracl->parent_subject)) {
61411+ /* if the cap isn't specified in the current computed mask but is specified in the
61412+ current level subject, and is lowered in the current level subject, then add
61413+ it to the set of dropped capabilities
61414+ otherwise, add the current level subject's mask to the current computed mask
61415+ */
61416+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61417+ cap_raise(cap_mask, cap);
61418+ if (cap_raised(curracl->cap_lower, cap))
61419+ cap_raise(cap_drop, cap);
61420+ if (cap_raised(curracl->cap_invert_audit, cap))
61421+ cap_raise(cap_audit, cap);
61422+ }
61423+ }
61424+
61425+ if (!cap_raised(cap_drop, cap)) {
61426+ if (cap_raised(cap_audit, cap))
61427+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
61428+ return 1;
61429+ }
61430+
61431+ curracl = task->acl;
61432+
61433+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
61434+ && cap_raised(cred->cap_effective, cap)) {
61435+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61436+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
61437+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
61438+ gr_to_filename(task->exec_file->f_path.dentry,
61439+ task->exec_file->f_path.mnt) : curracl->filename,
61440+ curracl->filename, 0UL,
61441+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
61442+ return 1;
61443+ }
61444+
61445+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
61446+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
61447+
61448+ return 0;
61449+}
61450+
61451+int
61452+gr_acl_is_capable(const int cap)
61453+{
61454+ return gr_task_acl_is_capable(current, current_cred(), cap);
61455+}
61456+
61457+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61458+{
61459+ struct acl_subject_label *curracl;
61460+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61461+
61462+ if (!gr_acl_is_enabled())
61463+ return 1;
61464+
61465+ curracl = task->acl;
61466+
61467+ cap_drop = curracl->cap_lower;
61468+ cap_mask = curracl->cap_mask;
61469+
61470+ while ((curracl = curracl->parent_subject)) {
61471+ /* if the cap isn't specified in the current computed mask but is specified in the
61472+ current level subject, and is lowered in the current level subject, then add
61473+ it to the set of dropped capabilities
61474+ otherwise, add the current level subject's mask to the current computed mask
61475+ */
61476+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61477+ cap_raise(cap_mask, cap);
61478+ if (cap_raised(curracl->cap_lower, cap))
61479+ cap_raise(cap_drop, cap);
61480+ }
61481+ }
61482+
61483+ if (!cap_raised(cap_drop, cap))
61484+ return 1;
61485+
61486+ return 0;
61487+}
61488+
61489+int
61490+gr_acl_is_capable_nolog(const int cap)
61491+{
61492+ return gr_task_acl_is_capable_nolog(current, cap);
61493+}
61494+
61495diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61496new file mode 100644
61497index 0000000..a340c17
61498--- /dev/null
61499+++ b/grsecurity/gracl_fs.c
61500@@ -0,0 +1,431 @@
61501+#include <linux/kernel.h>
61502+#include <linux/sched.h>
61503+#include <linux/types.h>
61504+#include <linux/fs.h>
61505+#include <linux/file.h>
61506+#include <linux/stat.h>
61507+#include <linux/grsecurity.h>
61508+#include <linux/grinternal.h>
61509+#include <linux/gracl.h>
61510+
61511+umode_t
61512+gr_acl_umask(void)
61513+{
61514+ if (unlikely(!gr_acl_is_enabled()))
61515+ return 0;
61516+
61517+ return current->role->umask;
61518+}
61519+
61520+__u32
61521+gr_acl_handle_hidden_file(const struct dentry * dentry,
61522+ const struct vfsmount * mnt)
61523+{
61524+ __u32 mode;
61525+
61526+ if (unlikely(!dentry->d_inode))
61527+ return GR_FIND;
61528+
61529+ mode =
61530+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61531+
61532+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61533+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61534+ return mode;
61535+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61536+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61537+ return 0;
61538+ } else if (unlikely(!(mode & GR_FIND)))
61539+ return 0;
61540+
61541+ return GR_FIND;
61542+}
61543+
61544+__u32
61545+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61546+ int acc_mode)
61547+{
61548+ __u32 reqmode = GR_FIND;
61549+ __u32 mode;
61550+
61551+ if (unlikely(!dentry->d_inode))
61552+ return reqmode;
61553+
61554+ if (acc_mode & MAY_APPEND)
61555+ reqmode |= GR_APPEND;
61556+ else if (acc_mode & MAY_WRITE)
61557+ reqmode |= GR_WRITE;
61558+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61559+ reqmode |= GR_READ;
61560+
61561+ mode =
61562+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61563+ mnt);
61564+
61565+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61566+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61567+ reqmode & GR_READ ? " reading" : "",
61568+ reqmode & GR_WRITE ? " writing" : reqmode &
61569+ GR_APPEND ? " appending" : "");
61570+ return reqmode;
61571+ } else
61572+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61573+ {
61574+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61575+ reqmode & GR_READ ? " reading" : "",
61576+ reqmode & GR_WRITE ? " writing" : reqmode &
61577+ GR_APPEND ? " appending" : "");
61578+ return 0;
61579+ } else if (unlikely((mode & reqmode) != reqmode))
61580+ return 0;
61581+
61582+ return reqmode;
61583+}
61584+
61585+__u32
61586+gr_acl_handle_creat(const struct dentry * dentry,
61587+ const struct dentry * p_dentry,
61588+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61589+ const int imode)
61590+{
61591+ __u32 reqmode = GR_WRITE | GR_CREATE;
61592+ __u32 mode;
61593+
61594+ if (acc_mode & MAY_APPEND)
61595+ reqmode |= GR_APPEND;
61596+ // if a directory was required or the directory already exists, then
61597+ // don't count this open as a read
61598+ if ((acc_mode & MAY_READ) &&
61599+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61600+ reqmode |= GR_READ;
61601+ if ((open_flags & O_CREAT) &&
61602+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61603+ reqmode |= GR_SETID;
61604+
61605+ mode =
61606+ gr_check_create(dentry, p_dentry, p_mnt,
61607+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61608+
61609+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61610+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61611+ reqmode & GR_READ ? " reading" : "",
61612+ reqmode & GR_WRITE ? " writing" : reqmode &
61613+ GR_APPEND ? " appending" : "");
61614+ return reqmode;
61615+ } else
61616+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61617+ {
61618+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61619+ reqmode & GR_READ ? " reading" : "",
61620+ reqmode & GR_WRITE ? " writing" : reqmode &
61621+ GR_APPEND ? " appending" : "");
61622+ return 0;
61623+ } else if (unlikely((mode & reqmode) != reqmode))
61624+ return 0;
61625+
61626+ return reqmode;
61627+}
61628+
61629+__u32
61630+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61631+ const int fmode)
61632+{
61633+ __u32 mode, reqmode = GR_FIND;
61634+
61635+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61636+ reqmode |= GR_EXEC;
61637+ if (fmode & S_IWOTH)
61638+ reqmode |= GR_WRITE;
61639+ if (fmode & S_IROTH)
61640+ reqmode |= GR_READ;
61641+
61642+ mode =
61643+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61644+ mnt);
61645+
61646+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61647+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61648+ reqmode & GR_READ ? " reading" : "",
61649+ reqmode & GR_WRITE ? " writing" : "",
61650+ reqmode & GR_EXEC ? " executing" : "");
61651+ return reqmode;
61652+ } else
61653+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61654+ {
61655+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61656+ reqmode & GR_READ ? " reading" : "",
61657+ reqmode & GR_WRITE ? " writing" : "",
61658+ reqmode & GR_EXEC ? " executing" : "");
61659+ return 0;
61660+ } else if (unlikely((mode & reqmode) != reqmode))
61661+ return 0;
61662+
61663+ return reqmode;
61664+}
61665+
61666+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61667+{
61668+ __u32 mode;
61669+
61670+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61671+
61672+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61673+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61674+ return mode;
61675+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61676+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61677+ return 0;
61678+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61679+ return 0;
61680+
61681+ return (reqmode);
61682+}
61683+
61684+__u32
61685+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61686+{
61687+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61688+}
61689+
61690+__u32
61691+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61692+{
61693+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61694+}
61695+
61696+__u32
61697+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61698+{
61699+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61700+}
61701+
61702+__u32
61703+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61704+{
61705+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61706+}
61707+
61708+__u32
61709+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61710+ umode_t *modeptr)
61711+{
61712+ umode_t mode;
61713+
61714+ *modeptr &= ~gr_acl_umask();
61715+ mode = *modeptr;
61716+
61717+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61718+ return 1;
61719+
61720+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61721+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61722+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61723+ GR_CHMOD_ACL_MSG);
61724+ } else {
61725+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61726+ }
61727+}
61728+
61729+__u32
61730+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61731+{
61732+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61733+}
61734+
61735+__u32
61736+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61737+{
61738+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61739+}
61740+
61741+__u32
61742+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61743+{
61744+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61745+}
61746+
61747+__u32
61748+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61749+{
61750+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61751+ GR_UNIXCONNECT_ACL_MSG);
61752+}
61753+
61754+/* hardlinks require at minimum create and link permission,
61755+ any additional privilege required is based on the
61756+ privilege of the file being linked to
61757+*/
61758+__u32
61759+gr_acl_handle_link(const struct dentry * new_dentry,
61760+ const struct dentry * parent_dentry,
61761+ const struct vfsmount * parent_mnt,
61762+ const struct dentry * old_dentry,
61763+ const struct vfsmount * old_mnt, const struct filename *to)
61764+{
61765+ __u32 mode;
61766+ __u32 needmode = GR_CREATE | GR_LINK;
61767+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61768+
61769+ mode =
61770+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61771+ old_mnt);
61772+
61773+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61774+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61775+ return mode;
61776+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61777+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61778+ return 0;
61779+ } else if (unlikely((mode & needmode) != needmode))
61780+ return 0;
61781+
61782+ return 1;
61783+}
61784+
61785+__u32
61786+gr_acl_handle_symlink(const struct dentry * new_dentry,
61787+ const struct dentry * parent_dentry,
61788+ const struct vfsmount * parent_mnt, const struct filename *from)
61789+{
61790+ __u32 needmode = GR_WRITE | GR_CREATE;
61791+ __u32 mode;
61792+
61793+ mode =
61794+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
61795+ GR_CREATE | GR_AUDIT_CREATE |
61796+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61797+
61798+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61799+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61800+ return mode;
61801+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61802+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61803+ return 0;
61804+ } else if (unlikely((mode & needmode) != needmode))
61805+ return 0;
61806+
61807+ return (GR_WRITE | GR_CREATE);
61808+}
61809+
61810+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)
61811+{
61812+ __u32 mode;
61813+
61814+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61815+
61816+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61817+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61818+ return mode;
61819+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61820+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61821+ return 0;
61822+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61823+ return 0;
61824+
61825+ return (reqmode);
61826+}
61827+
61828+__u32
61829+gr_acl_handle_mknod(const struct dentry * new_dentry,
61830+ const struct dentry * parent_dentry,
61831+ const struct vfsmount * parent_mnt,
61832+ const int mode)
61833+{
61834+ __u32 reqmode = GR_WRITE | GR_CREATE;
61835+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61836+ reqmode |= GR_SETID;
61837+
61838+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61839+ reqmode, GR_MKNOD_ACL_MSG);
61840+}
61841+
61842+__u32
61843+gr_acl_handle_mkdir(const struct dentry *new_dentry,
61844+ const struct dentry *parent_dentry,
61845+ const struct vfsmount *parent_mnt)
61846+{
61847+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61848+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61849+}
61850+
61851+#define RENAME_CHECK_SUCCESS(old, new) \
61852+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61853+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61854+
61855+int
61856+gr_acl_handle_rename(struct dentry *new_dentry,
61857+ struct dentry *parent_dentry,
61858+ const struct vfsmount *parent_mnt,
61859+ struct dentry *old_dentry,
61860+ struct inode *old_parent_inode,
61861+ struct vfsmount *old_mnt, const struct filename *newname)
61862+{
61863+ __u32 comp1, comp2;
61864+ int error = 0;
61865+
61866+ if (unlikely(!gr_acl_is_enabled()))
61867+ return 0;
61868+
61869+ if (!new_dentry->d_inode) {
61870+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61871+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61872+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61873+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61874+ GR_DELETE | GR_AUDIT_DELETE |
61875+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61876+ GR_SUPPRESS, old_mnt);
61877+ } else {
61878+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61879+ GR_CREATE | GR_DELETE |
61880+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61881+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61882+ GR_SUPPRESS, parent_mnt);
61883+ comp2 =
61884+ gr_search_file(old_dentry,
61885+ GR_READ | GR_WRITE | GR_AUDIT_READ |
61886+ GR_DELETE | GR_AUDIT_DELETE |
61887+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61888+ }
61889+
61890+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61891+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61892+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61893+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61894+ && !(comp2 & GR_SUPPRESS)) {
61895+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61896+ error = -EACCES;
61897+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61898+ error = -EACCES;
61899+
61900+ return error;
61901+}
61902+
61903+void
61904+gr_acl_handle_exit(void)
61905+{
61906+ u16 id;
61907+ char *rolename;
61908+
61909+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61910+ !(current->role->roletype & GR_ROLE_PERSIST))) {
61911+ id = current->acl_role_id;
61912+ rolename = current->role->rolename;
61913+ gr_set_acls(1);
61914+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61915+ }
61916+
61917+ gr_put_exec_file(current);
61918+ return;
61919+}
61920+
61921+int
61922+gr_acl_handle_procpidmem(const struct task_struct *task)
61923+{
61924+ if (unlikely(!gr_acl_is_enabled()))
61925+ return 0;
61926+
61927+ if (task != current && task->acl->mode & GR_PROTPROCFD)
61928+ return -EACCES;
61929+
61930+ return 0;
61931+}
61932diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61933new file mode 100644
61934index 0000000..4699807
61935--- /dev/null
61936+++ b/grsecurity/gracl_ip.c
61937@@ -0,0 +1,384 @@
61938+#include <linux/kernel.h>
61939+#include <asm/uaccess.h>
61940+#include <asm/errno.h>
61941+#include <net/sock.h>
61942+#include <linux/file.h>
61943+#include <linux/fs.h>
61944+#include <linux/net.h>
61945+#include <linux/in.h>
61946+#include <linux/skbuff.h>
61947+#include <linux/ip.h>
61948+#include <linux/udp.h>
61949+#include <linux/types.h>
61950+#include <linux/sched.h>
61951+#include <linux/netdevice.h>
61952+#include <linux/inetdevice.h>
61953+#include <linux/gracl.h>
61954+#include <linux/grsecurity.h>
61955+#include <linux/grinternal.h>
61956+
61957+#define GR_BIND 0x01
61958+#define GR_CONNECT 0x02
61959+#define GR_INVERT 0x04
61960+#define GR_BINDOVERRIDE 0x08
61961+#define GR_CONNECTOVERRIDE 0x10
61962+#define GR_SOCK_FAMILY 0x20
61963+
61964+static const char * gr_protocols[IPPROTO_MAX] = {
61965+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
61966+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
61967+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
61968+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
61969+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
61970+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
61971+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
61972+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
61973+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
61974+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
61975+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
61976+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
61977+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
61978+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
61979+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
61980+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
61981+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
61982+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
61983+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
61984+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
61985+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
61986+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
61987+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
61988+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
61989+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
61990+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
61991+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
61992+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
61993+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
61994+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
61995+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
61996+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
61997+ };
61998+
61999+static const char * gr_socktypes[SOCK_MAX] = {
62000+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62001+ "unknown:7", "unknown:8", "unknown:9", "packet"
62002+ };
62003+
62004+static const char * gr_sockfamilies[AF_MAX+1] = {
62005+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62006+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62007+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62008+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62009+ };
62010+
62011+const char *
62012+gr_proto_to_name(unsigned char proto)
62013+{
62014+ return gr_protocols[proto];
62015+}
62016+
62017+const char *
62018+gr_socktype_to_name(unsigned char type)
62019+{
62020+ return gr_socktypes[type];
62021+}
62022+
62023+const char *
62024+gr_sockfamily_to_name(unsigned char family)
62025+{
62026+ return gr_sockfamilies[family];
62027+}
62028+
62029+int
62030+gr_search_socket(const int domain, const int type, const int protocol)
62031+{
62032+ struct acl_subject_label *curr;
62033+ const struct cred *cred = current_cred();
62034+
62035+ if (unlikely(!gr_acl_is_enabled()))
62036+ goto exit;
62037+
62038+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
62039+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
62040+ goto exit; // let the kernel handle it
62041+
62042+ curr = current->acl;
62043+
62044+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
62045+ /* the family is allowed, if this is PF_INET allow it only if
62046+ the extra sock type/protocol checks pass */
62047+ if (domain == PF_INET)
62048+ goto inet_check;
62049+ goto exit;
62050+ } else {
62051+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62052+ __u32 fakeip = 0;
62053+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62054+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62055+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62056+ gr_to_filename(current->exec_file->f_path.dentry,
62057+ current->exec_file->f_path.mnt) :
62058+ curr->filename, curr->filename,
62059+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
62060+ &current->signal->saved_ip);
62061+ goto exit;
62062+ }
62063+ goto exit_fail;
62064+ }
62065+
62066+inet_check:
62067+ /* the rest of this checking is for IPv4 only */
62068+ if (!curr->ips)
62069+ goto exit;
62070+
62071+ if ((curr->ip_type & (1 << type)) &&
62072+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
62073+ goto exit;
62074+
62075+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62076+ /* we don't place acls on raw sockets , and sometimes
62077+ dgram/ip sockets are opened for ioctl and not
62078+ bind/connect, so we'll fake a bind learn log */
62079+ if (type == SOCK_RAW || type == SOCK_PACKET) {
62080+ __u32 fakeip = 0;
62081+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62082+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62083+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62084+ gr_to_filename(current->exec_file->f_path.dentry,
62085+ current->exec_file->f_path.mnt) :
62086+ curr->filename, curr->filename,
62087+ &fakeip, 0, type,
62088+ protocol, GR_CONNECT, &current->signal->saved_ip);
62089+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
62090+ __u32 fakeip = 0;
62091+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62092+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62093+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62094+ gr_to_filename(current->exec_file->f_path.dentry,
62095+ current->exec_file->f_path.mnt) :
62096+ curr->filename, curr->filename,
62097+ &fakeip, 0, type,
62098+ protocol, GR_BIND, &current->signal->saved_ip);
62099+ }
62100+ /* we'll log when they use connect or bind */
62101+ goto exit;
62102+ }
62103+
62104+exit_fail:
62105+ if (domain == PF_INET)
62106+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
62107+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
62108+ else
62109+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
62110+ gr_socktype_to_name(type), protocol);
62111+
62112+ return 0;
62113+exit:
62114+ return 1;
62115+}
62116+
62117+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)
62118+{
62119+ if ((ip->mode & mode) &&
62120+ (ip_port >= ip->low) &&
62121+ (ip_port <= ip->high) &&
62122+ ((ntohl(ip_addr) & our_netmask) ==
62123+ (ntohl(our_addr) & our_netmask))
62124+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
62125+ && (ip->type & (1 << type))) {
62126+ if (ip->mode & GR_INVERT)
62127+ return 2; // specifically denied
62128+ else
62129+ return 1; // allowed
62130+ }
62131+
62132+ return 0; // not specifically allowed, may continue parsing
62133+}
62134+
62135+static int
62136+gr_search_connectbind(const int full_mode, struct sock *sk,
62137+ struct sockaddr_in *addr, const int type)
62138+{
62139+ char iface[IFNAMSIZ] = {0};
62140+ struct acl_subject_label *curr;
62141+ struct acl_ip_label *ip;
62142+ struct inet_sock *isk;
62143+ struct net_device *dev;
62144+ struct in_device *idev;
62145+ unsigned long i;
62146+ int ret;
62147+ int mode = full_mode & (GR_BIND | GR_CONNECT);
62148+ __u32 ip_addr = 0;
62149+ __u32 our_addr;
62150+ __u32 our_netmask;
62151+ char *p;
62152+ __u16 ip_port = 0;
62153+ const struct cred *cred = current_cred();
62154+
62155+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
62156+ return 0;
62157+
62158+ curr = current->acl;
62159+ isk = inet_sk(sk);
62160+
62161+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
62162+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
62163+ addr->sin_addr.s_addr = curr->inaddr_any_override;
62164+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
62165+ struct sockaddr_in saddr;
62166+ int err;
62167+
62168+ saddr.sin_family = AF_INET;
62169+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
62170+ saddr.sin_port = isk->inet_sport;
62171+
62172+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62173+ if (err)
62174+ return err;
62175+
62176+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62177+ if (err)
62178+ return err;
62179+ }
62180+
62181+ if (!curr->ips)
62182+ return 0;
62183+
62184+ ip_addr = addr->sin_addr.s_addr;
62185+ ip_port = ntohs(addr->sin_port);
62186+
62187+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62188+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62189+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62190+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62191+ gr_to_filename(current->exec_file->f_path.dentry,
62192+ current->exec_file->f_path.mnt) :
62193+ curr->filename, curr->filename,
62194+ &ip_addr, ip_port, type,
62195+ sk->sk_protocol, mode, &current->signal->saved_ip);
62196+ return 0;
62197+ }
62198+
62199+ for (i = 0; i < curr->ip_num; i++) {
62200+ ip = *(curr->ips + i);
62201+ if (ip->iface != NULL) {
62202+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
62203+ p = strchr(iface, ':');
62204+ if (p != NULL)
62205+ *p = '\0';
62206+ dev = dev_get_by_name(sock_net(sk), iface);
62207+ if (dev == NULL)
62208+ continue;
62209+ idev = in_dev_get(dev);
62210+ if (idev == NULL) {
62211+ dev_put(dev);
62212+ continue;
62213+ }
62214+ rcu_read_lock();
62215+ for_ifa(idev) {
62216+ if (!strcmp(ip->iface, ifa->ifa_label)) {
62217+ our_addr = ifa->ifa_address;
62218+ our_netmask = 0xffffffff;
62219+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62220+ if (ret == 1) {
62221+ rcu_read_unlock();
62222+ in_dev_put(idev);
62223+ dev_put(dev);
62224+ return 0;
62225+ } else if (ret == 2) {
62226+ rcu_read_unlock();
62227+ in_dev_put(idev);
62228+ dev_put(dev);
62229+ goto denied;
62230+ }
62231+ }
62232+ } endfor_ifa(idev);
62233+ rcu_read_unlock();
62234+ in_dev_put(idev);
62235+ dev_put(dev);
62236+ } else {
62237+ our_addr = ip->addr;
62238+ our_netmask = ip->netmask;
62239+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62240+ if (ret == 1)
62241+ return 0;
62242+ else if (ret == 2)
62243+ goto denied;
62244+ }
62245+ }
62246+
62247+denied:
62248+ if (mode == GR_BIND)
62249+ 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));
62250+ else if (mode == GR_CONNECT)
62251+ 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));
62252+
62253+ return -EACCES;
62254+}
62255+
62256+int
62257+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
62258+{
62259+ /* always allow disconnection of dgram sockets with connect */
62260+ if (addr->sin_family == AF_UNSPEC)
62261+ return 0;
62262+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
62263+}
62264+
62265+int
62266+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
62267+{
62268+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
62269+}
62270+
62271+int gr_search_listen(struct socket *sock)
62272+{
62273+ struct sock *sk = sock->sk;
62274+ struct sockaddr_in addr;
62275+
62276+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62277+ addr.sin_port = inet_sk(sk)->inet_sport;
62278+
62279+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62280+}
62281+
62282+int gr_search_accept(struct socket *sock)
62283+{
62284+ struct sock *sk = sock->sk;
62285+ struct sockaddr_in addr;
62286+
62287+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62288+ addr.sin_port = inet_sk(sk)->inet_sport;
62289+
62290+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62291+}
62292+
62293+int
62294+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
62295+{
62296+ if (addr)
62297+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
62298+ else {
62299+ struct sockaddr_in sin;
62300+ const struct inet_sock *inet = inet_sk(sk);
62301+
62302+ sin.sin_addr.s_addr = inet->inet_daddr;
62303+ sin.sin_port = inet->inet_dport;
62304+
62305+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62306+ }
62307+}
62308+
62309+int
62310+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
62311+{
62312+ struct sockaddr_in sin;
62313+
62314+ if (unlikely(skb->len < sizeof (struct udphdr)))
62315+ return 0; // skip this packet
62316+
62317+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
62318+ sin.sin_port = udp_hdr(skb)->source;
62319+
62320+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62321+}
62322diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
62323new file mode 100644
62324index 0000000..25f54ef
62325--- /dev/null
62326+++ b/grsecurity/gracl_learn.c
62327@@ -0,0 +1,207 @@
62328+#include <linux/kernel.h>
62329+#include <linux/mm.h>
62330+#include <linux/sched.h>
62331+#include <linux/poll.h>
62332+#include <linux/string.h>
62333+#include <linux/file.h>
62334+#include <linux/types.h>
62335+#include <linux/vmalloc.h>
62336+#include <linux/grinternal.h>
62337+
62338+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
62339+ size_t count, loff_t *ppos);
62340+extern int gr_acl_is_enabled(void);
62341+
62342+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
62343+static int gr_learn_attached;
62344+
62345+/* use a 512k buffer */
62346+#define LEARN_BUFFER_SIZE (512 * 1024)
62347+
62348+static DEFINE_SPINLOCK(gr_learn_lock);
62349+static DEFINE_MUTEX(gr_learn_user_mutex);
62350+
62351+/* we need to maintain two buffers, so that the kernel context of grlearn
62352+ uses a semaphore around the userspace copying, and the other kernel contexts
62353+ use a spinlock when copying into the buffer, since they cannot sleep
62354+*/
62355+static char *learn_buffer;
62356+static char *learn_buffer_user;
62357+static int learn_buffer_len;
62358+static int learn_buffer_user_len;
62359+
62360+static ssize_t
62361+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
62362+{
62363+ DECLARE_WAITQUEUE(wait, current);
62364+ ssize_t retval = 0;
62365+
62366+ add_wait_queue(&learn_wait, &wait);
62367+ set_current_state(TASK_INTERRUPTIBLE);
62368+ do {
62369+ mutex_lock(&gr_learn_user_mutex);
62370+ spin_lock(&gr_learn_lock);
62371+ if (learn_buffer_len)
62372+ break;
62373+ spin_unlock(&gr_learn_lock);
62374+ mutex_unlock(&gr_learn_user_mutex);
62375+ if (file->f_flags & O_NONBLOCK) {
62376+ retval = -EAGAIN;
62377+ goto out;
62378+ }
62379+ if (signal_pending(current)) {
62380+ retval = -ERESTARTSYS;
62381+ goto out;
62382+ }
62383+
62384+ schedule();
62385+ } while (1);
62386+
62387+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
62388+ learn_buffer_user_len = learn_buffer_len;
62389+ retval = learn_buffer_len;
62390+ learn_buffer_len = 0;
62391+
62392+ spin_unlock(&gr_learn_lock);
62393+
62394+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
62395+ retval = -EFAULT;
62396+
62397+ mutex_unlock(&gr_learn_user_mutex);
62398+out:
62399+ set_current_state(TASK_RUNNING);
62400+ remove_wait_queue(&learn_wait, &wait);
62401+ return retval;
62402+}
62403+
62404+static unsigned int
62405+poll_learn(struct file * file, poll_table * wait)
62406+{
62407+ poll_wait(file, &learn_wait, wait);
62408+
62409+ if (learn_buffer_len)
62410+ return (POLLIN | POLLRDNORM);
62411+
62412+ return 0;
62413+}
62414+
62415+void
62416+gr_clear_learn_entries(void)
62417+{
62418+ char *tmp;
62419+
62420+ mutex_lock(&gr_learn_user_mutex);
62421+ spin_lock(&gr_learn_lock);
62422+ tmp = learn_buffer;
62423+ learn_buffer = NULL;
62424+ spin_unlock(&gr_learn_lock);
62425+ if (tmp)
62426+ vfree(tmp);
62427+ if (learn_buffer_user != NULL) {
62428+ vfree(learn_buffer_user);
62429+ learn_buffer_user = NULL;
62430+ }
62431+ learn_buffer_len = 0;
62432+ mutex_unlock(&gr_learn_user_mutex);
62433+
62434+ return;
62435+}
62436+
62437+void
62438+gr_add_learn_entry(const char *fmt, ...)
62439+{
62440+ va_list args;
62441+ unsigned int len;
62442+
62443+ if (!gr_learn_attached)
62444+ return;
62445+
62446+ spin_lock(&gr_learn_lock);
62447+
62448+ /* leave a gap at the end so we know when it's "full" but don't have to
62449+ compute the exact length of the string we're trying to append
62450+ */
62451+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
62452+ spin_unlock(&gr_learn_lock);
62453+ wake_up_interruptible(&learn_wait);
62454+ return;
62455+ }
62456+ if (learn_buffer == NULL) {
62457+ spin_unlock(&gr_learn_lock);
62458+ return;
62459+ }
62460+
62461+ va_start(args, fmt);
62462+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62463+ va_end(args);
62464+
62465+ learn_buffer_len += len + 1;
62466+
62467+ spin_unlock(&gr_learn_lock);
62468+ wake_up_interruptible(&learn_wait);
62469+
62470+ return;
62471+}
62472+
62473+static int
62474+open_learn(struct inode *inode, struct file *file)
62475+{
62476+ if (file->f_mode & FMODE_READ && gr_learn_attached)
62477+ return -EBUSY;
62478+ if (file->f_mode & FMODE_READ) {
62479+ int retval = 0;
62480+ mutex_lock(&gr_learn_user_mutex);
62481+ if (learn_buffer == NULL)
62482+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62483+ if (learn_buffer_user == NULL)
62484+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62485+ if (learn_buffer == NULL) {
62486+ retval = -ENOMEM;
62487+ goto out_error;
62488+ }
62489+ if (learn_buffer_user == NULL) {
62490+ retval = -ENOMEM;
62491+ goto out_error;
62492+ }
62493+ learn_buffer_len = 0;
62494+ learn_buffer_user_len = 0;
62495+ gr_learn_attached = 1;
62496+out_error:
62497+ mutex_unlock(&gr_learn_user_mutex);
62498+ return retval;
62499+ }
62500+ return 0;
62501+}
62502+
62503+static int
62504+close_learn(struct inode *inode, struct file *file)
62505+{
62506+ if (file->f_mode & FMODE_READ) {
62507+ char *tmp = NULL;
62508+ mutex_lock(&gr_learn_user_mutex);
62509+ spin_lock(&gr_learn_lock);
62510+ tmp = learn_buffer;
62511+ learn_buffer = NULL;
62512+ spin_unlock(&gr_learn_lock);
62513+ if (tmp)
62514+ vfree(tmp);
62515+ if (learn_buffer_user != NULL) {
62516+ vfree(learn_buffer_user);
62517+ learn_buffer_user = NULL;
62518+ }
62519+ learn_buffer_len = 0;
62520+ learn_buffer_user_len = 0;
62521+ gr_learn_attached = 0;
62522+ mutex_unlock(&gr_learn_user_mutex);
62523+ }
62524+
62525+ return 0;
62526+}
62527+
62528+const struct file_operations grsec_fops = {
62529+ .read = read_learn,
62530+ .write = write_grsec_handler,
62531+ .open = open_learn,
62532+ .release = close_learn,
62533+ .poll = poll_learn,
62534+};
62535diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62536new file mode 100644
62537index 0000000..39645c9
62538--- /dev/null
62539+++ b/grsecurity/gracl_res.c
62540@@ -0,0 +1,68 @@
62541+#include <linux/kernel.h>
62542+#include <linux/sched.h>
62543+#include <linux/gracl.h>
62544+#include <linux/grinternal.h>
62545+
62546+static const char *restab_log[] = {
62547+ [RLIMIT_CPU] = "RLIMIT_CPU",
62548+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62549+ [RLIMIT_DATA] = "RLIMIT_DATA",
62550+ [RLIMIT_STACK] = "RLIMIT_STACK",
62551+ [RLIMIT_CORE] = "RLIMIT_CORE",
62552+ [RLIMIT_RSS] = "RLIMIT_RSS",
62553+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
62554+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62555+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62556+ [RLIMIT_AS] = "RLIMIT_AS",
62557+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62558+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62559+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62560+ [RLIMIT_NICE] = "RLIMIT_NICE",
62561+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62562+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62563+ [GR_CRASH_RES] = "RLIMIT_CRASH"
62564+};
62565+
62566+void
62567+gr_log_resource(const struct task_struct *task,
62568+ const int res, const unsigned long wanted, const int gt)
62569+{
62570+ const struct cred *cred;
62571+ unsigned long rlim;
62572+
62573+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
62574+ return;
62575+
62576+ // not yet supported resource
62577+ if (unlikely(!restab_log[res]))
62578+ return;
62579+
62580+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62581+ rlim = task_rlimit_max(task, res);
62582+ else
62583+ rlim = task_rlimit(task, res);
62584+
62585+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62586+ return;
62587+
62588+ rcu_read_lock();
62589+ cred = __task_cred(task);
62590+
62591+ if (res == RLIMIT_NPROC &&
62592+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62593+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62594+ goto out_rcu_unlock;
62595+ else if (res == RLIMIT_MEMLOCK &&
62596+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62597+ goto out_rcu_unlock;
62598+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62599+ goto out_rcu_unlock;
62600+ rcu_read_unlock();
62601+
62602+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62603+
62604+ return;
62605+out_rcu_unlock:
62606+ rcu_read_unlock();
62607+ return;
62608+}
62609diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62610new file mode 100644
62611index 0000000..8c8fc9d
62612--- /dev/null
62613+++ b/grsecurity/gracl_segv.c
62614@@ -0,0 +1,303 @@
62615+#include <linux/kernel.h>
62616+#include <linux/mm.h>
62617+#include <asm/uaccess.h>
62618+#include <asm/errno.h>
62619+#include <asm/mman.h>
62620+#include <net/sock.h>
62621+#include <linux/file.h>
62622+#include <linux/fs.h>
62623+#include <linux/net.h>
62624+#include <linux/in.h>
62625+#include <linux/slab.h>
62626+#include <linux/types.h>
62627+#include <linux/sched.h>
62628+#include <linux/timer.h>
62629+#include <linux/gracl.h>
62630+#include <linux/grsecurity.h>
62631+#include <linux/grinternal.h>
62632+
62633+static struct crash_uid *uid_set;
62634+static unsigned short uid_used;
62635+static DEFINE_SPINLOCK(gr_uid_lock);
62636+extern rwlock_t gr_inode_lock;
62637+extern struct acl_subject_label *
62638+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62639+ struct acl_role_label *role);
62640+
62641+#ifdef CONFIG_BTRFS_FS
62642+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62643+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62644+#endif
62645+
62646+static inline dev_t __get_dev(const struct dentry *dentry)
62647+{
62648+#ifdef CONFIG_BTRFS_FS
62649+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62650+ return get_btrfs_dev_from_inode(dentry->d_inode);
62651+ else
62652+#endif
62653+ return dentry->d_inode->i_sb->s_dev;
62654+}
62655+
62656+int
62657+gr_init_uidset(void)
62658+{
62659+ uid_set =
62660+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62661+ uid_used = 0;
62662+
62663+ return uid_set ? 1 : 0;
62664+}
62665+
62666+void
62667+gr_free_uidset(void)
62668+{
62669+ if (uid_set)
62670+ kfree(uid_set);
62671+
62672+ return;
62673+}
62674+
62675+int
62676+gr_find_uid(const uid_t uid)
62677+{
62678+ struct crash_uid *tmp = uid_set;
62679+ uid_t buid;
62680+ int low = 0, high = uid_used - 1, mid;
62681+
62682+ while (high >= low) {
62683+ mid = (low + high) >> 1;
62684+ buid = tmp[mid].uid;
62685+ if (buid == uid)
62686+ return mid;
62687+ if (buid > uid)
62688+ high = mid - 1;
62689+ if (buid < uid)
62690+ low = mid + 1;
62691+ }
62692+
62693+ return -1;
62694+}
62695+
62696+static __inline__ void
62697+gr_insertsort(void)
62698+{
62699+ unsigned short i, j;
62700+ struct crash_uid index;
62701+
62702+ for (i = 1; i < uid_used; i++) {
62703+ index = uid_set[i];
62704+ j = i;
62705+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62706+ uid_set[j] = uid_set[j - 1];
62707+ j--;
62708+ }
62709+ uid_set[j] = index;
62710+ }
62711+
62712+ return;
62713+}
62714+
62715+static __inline__ void
62716+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62717+{
62718+ int loc;
62719+ uid_t uid = GR_GLOBAL_UID(kuid);
62720+
62721+ if (uid_used == GR_UIDTABLE_MAX)
62722+ return;
62723+
62724+ loc = gr_find_uid(uid);
62725+
62726+ if (loc >= 0) {
62727+ uid_set[loc].expires = expires;
62728+ return;
62729+ }
62730+
62731+ uid_set[uid_used].uid = uid;
62732+ uid_set[uid_used].expires = expires;
62733+ uid_used++;
62734+
62735+ gr_insertsort();
62736+
62737+ return;
62738+}
62739+
62740+void
62741+gr_remove_uid(const unsigned short loc)
62742+{
62743+ unsigned short i;
62744+
62745+ for (i = loc + 1; i < uid_used; i++)
62746+ uid_set[i - 1] = uid_set[i];
62747+
62748+ uid_used--;
62749+
62750+ return;
62751+}
62752+
62753+int
62754+gr_check_crash_uid(const kuid_t kuid)
62755+{
62756+ int loc;
62757+ int ret = 0;
62758+ uid_t uid;
62759+
62760+ if (unlikely(!gr_acl_is_enabled()))
62761+ return 0;
62762+
62763+ uid = GR_GLOBAL_UID(kuid);
62764+
62765+ spin_lock(&gr_uid_lock);
62766+ loc = gr_find_uid(uid);
62767+
62768+ if (loc < 0)
62769+ goto out_unlock;
62770+
62771+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
62772+ gr_remove_uid(loc);
62773+ else
62774+ ret = 1;
62775+
62776+out_unlock:
62777+ spin_unlock(&gr_uid_lock);
62778+ return ret;
62779+}
62780+
62781+static __inline__ int
62782+proc_is_setxid(const struct cred *cred)
62783+{
62784+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62785+ !uid_eq(cred->uid, cred->fsuid))
62786+ return 1;
62787+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62788+ !gid_eq(cred->gid, cred->fsgid))
62789+ return 1;
62790+
62791+ return 0;
62792+}
62793+
62794+extern int gr_fake_force_sig(int sig, struct task_struct *t);
62795+
62796+void
62797+gr_handle_crash(struct task_struct *task, const int sig)
62798+{
62799+ struct acl_subject_label *curr;
62800+ struct task_struct *tsk, *tsk2;
62801+ const struct cred *cred;
62802+ const struct cred *cred2;
62803+
62804+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62805+ return;
62806+
62807+ if (unlikely(!gr_acl_is_enabled()))
62808+ return;
62809+
62810+ curr = task->acl;
62811+
62812+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
62813+ return;
62814+
62815+ if (time_before_eq(curr->expires, get_seconds())) {
62816+ curr->expires = 0;
62817+ curr->crashes = 0;
62818+ }
62819+
62820+ curr->crashes++;
62821+
62822+ if (!curr->expires)
62823+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62824+
62825+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62826+ time_after(curr->expires, get_seconds())) {
62827+ rcu_read_lock();
62828+ cred = __task_cred(task);
62829+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62830+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62831+ spin_lock(&gr_uid_lock);
62832+ gr_insert_uid(cred->uid, curr->expires);
62833+ spin_unlock(&gr_uid_lock);
62834+ curr->expires = 0;
62835+ curr->crashes = 0;
62836+ read_lock(&tasklist_lock);
62837+ do_each_thread(tsk2, tsk) {
62838+ cred2 = __task_cred(tsk);
62839+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
62840+ gr_fake_force_sig(SIGKILL, tsk);
62841+ } while_each_thread(tsk2, tsk);
62842+ read_unlock(&tasklist_lock);
62843+ } else {
62844+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62845+ read_lock(&tasklist_lock);
62846+ read_lock(&grsec_exec_file_lock);
62847+ do_each_thread(tsk2, tsk) {
62848+ if (likely(tsk != task)) {
62849+ // if this thread has the same subject as the one that triggered
62850+ // RES_CRASH and it's the same binary, kill it
62851+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62852+ gr_fake_force_sig(SIGKILL, tsk);
62853+ }
62854+ } while_each_thread(tsk2, tsk);
62855+ read_unlock(&grsec_exec_file_lock);
62856+ read_unlock(&tasklist_lock);
62857+ }
62858+ rcu_read_unlock();
62859+ }
62860+
62861+ return;
62862+}
62863+
62864+int
62865+gr_check_crash_exec(const struct file *filp)
62866+{
62867+ struct acl_subject_label *curr;
62868+
62869+ if (unlikely(!gr_acl_is_enabled()))
62870+ return 0;
62871+
62872+ read_lock(&gr_inode_lock);
62873+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62874+ __get_dev(filp->f_path.dentry),
62875+ current->role);
62876+ read_unlock(&gr_inode_lock);
62877+
62878+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62879+ (!curr->crashes && !curr->expires))
62880+ return 0;
62881+
62882+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62883+ time_after(curr->expires, get_seconds()))
62884+ return 1;
62885+ else if (time_before_eq(curr->expires, get_seconds())) {
62886+ curr->crashes = 0;
62887+ curr->expires = 0;
62888+ }
62889+
62890+ return 0;
62891+}
62892+
62893+void
62894+gr_handle_alertkill(struct task_struct *task)
62895+{
62896+ struct acl_subject_label *curracl;
62897+ __u32 curr_ip;
62898+ struct task_struct *p, *p2;
62899+
62900+ if (unlikely(!gr_acl_is_enabled()))
62901+ return;
62902+
62903+ curracl = task->acl;
62904+ curr_ip = task->signal->curr_ip;
62905+
62906+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62907+ read_lock(&tasklist_lock);
62908+ do_each_thread(p2, p) {
62909+ if (p->signal->curr_ip == curr_ip)
62910+ gr_fake_force_sig(SIGKILL, p);
62911+ } while_each_thread(p2, p);
62912+ read_unlock(&tasklist_lock);
62913+ } else if (curracl->mode & GR_KILLPROC)
62914+ gr_fake_force_sig(SIGKILL, task);
62915+
62916+ return;
62917+}
62918diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62919new file mode 100644
62920index 0000000..98011b0
62921--- /dev/null
62922+++ b/grsecurity/gracl_shm.c
62923@@ -0,0 +1,40 @@
62924+#include <linux/kernel.h>
62925+#include <linux/mm.h>
62926+#include <linux/sched.h>
62927+#include <linux/file.h>
62928+#include <linux/ipc.h>
62929+#include <linux/gracl.h>
62930+#include <linux/grsecurity.h>
62931+#include <linux/grinternal.h>
62932+
62933+int
62934+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62935+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
62936+{
62937+ struct task_struct *task;
62938+
62939+ if (!gr_acl_is_enabled())
62940+ return 1;
62941+
62942+ rcu_read_lock();
62943+ read_lock(&tasklist_lock);
62944+
62945+ task = find_task_by_vpid(shm_cprid);
62946+
62947+ if (unlikely(!task))
62948+ task = find_task_by_vpid(shm_lapid);
62949+
62950+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62951+ (task_pid_nr(task) == shm_lapid)) &&
62952+ (task->acl->mode & GR_PROTSHM) &&
62953+ (task->acl != current->acl))) {
62954+ read_unlock(&tasklist_lock);
62955+ rcu_read_unlock();
62956+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
62957+ return 0;
62958+ }
62959+ read_unlock(&tasklist_lock);
62960+ rcu_read_unlock();
62961+
62962+ return 1;
62963+}
62964diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
62965new file mode 100644
62966index 0000000..bc0be01
62967--- /dev/null
62968+++ b/grsecurity/grsec_chdir.c
62969@@ -0,0 +1,19 @@
62970+#include <linux/kernel.h>
62971+#include <linux/sched.h>
62972+#include <linux/fs.h>
62973+#include <linux/file.h>
62974+#include <linux/grsecurity.h>
62975+#include <linux/grinternal.h>
62976+
62977+void
62978+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
62979+{
62980+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62981+ if ((grsec_enable_chdir && grsec_enable_group &&
62982+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
62983+ !grsec_enable_group)) {
62984+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
62985+ }
62986+#endif
62987+ return;
62988+}
62989diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
62990new file mode 100644
62991index 0000000..6d2de57
62992--- /dev/null
62993+++ b/grsecurity/grsec_chroot.c
62994@@ -0,0 +1,357 @@
62995+#include <linux/kernel.h>
62996+#include <linux/module.h>
62997+#include <linux/sched.h>
62998+#include <linux/file.h>
62999+#include <linux/fs.h>
63000+#include <linux/mount.h>
63001+#include <linux/types.h>
63002+#include "../fs/mount.h"
63003+#include <linux/grsecurity.h>
63004+#include <linux/grinternal.h>
63005+
63006+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
63007+{
63008+#ifdef CONFIG_GRKERNSEC
63009+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
63010+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
63011+ task->gr_is_chrooted = 1;
63012+ else
63013+ task->gr_is_chrooted = 0;
63014+
63015+ task->gr_chroot_dentry = path->dentry;
63016+#endif
63017+ return;
63018+}
63019+
63020+void gr_clear_chroot_entries(struct task_struct *task)
63021+{
63022+#ifdef CONFIG_GRKERNSEC
63023+ task->gr_is_chrooted = 0;
63024+ task->gr_chroot_dentry = NULL;
63025+#endif
63026+ return;
63027+}
63028+
63029+int
63030+gr_handle_chroot_unix(const pid_t pid)
63031+{
63032+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63033+ struct task_struct *p;
63034+
63035+ if (unlikely(!grsec_enable_chroot_unix))
63036+ return 1;
63037+
63038+ if (likely(!proc_is_chrooted(current)))
63039+ return 1;
63040+
63041+ rcu_read_lock();
63042+ read_lock(&tasklist_lock);
63043+ p = find_task_by_vpid_unrestricted(pid);
63044+ if (unlikely(p && !have_same_root(current, p))) {
63045+ read_unlock(&tasklist_lock);
63046+ rcu_read_unlock();
63047+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
63048+ return 0;
63049+ }
63050+ read_unlock(&tasklist_lock);
63051+ rcu_read_unlock();
63052+#endif
63053+ return 1;
63054+}
63055+
63056+int
63057+gr_handle_chroot_nice(void)
63058+{
63059+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63060+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
63061+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
63062+ return -EPERM;
63063+ }
63064+#endif
63065+ return 0;
63066+}
63067+
63068+int
63069+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
63070+{
63071+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63072+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
63073+ && proc_is_chrooted(current)) {
63074+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
63075+ return -EACCES;
63076+ }
63077+#endif
63078+ return 0;
63079+}
63080+
63081+int
63082+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
63083+{
63084+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63085+ struct task_struct *p;
63086+ int ret = 0;
63087+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
63088+ return ret;
63089+
63090+ read_lock(&tasklist_lock);
63091+ do_each_pid_task(pid, type, p) {
63092+ if (!have_same_root(current, p)) {
63093+ ret = 1;
63094+ goto out;
63095+ }
63096+ } while_each_pid_task(pid, type, p);
63097+out:
63098+ read_unlock(&tasklist_lock);
63099+ return ret;
63100+#endif
63101+ return 0;
63102+}
63103+
63104+int
63105+gr_pid_is_chrooted(struct task_struct *p)
63106+{
63107+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63108+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
63109+ return 0;
63110+
63111+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
63112+ !have_same_root(current, p)) {
63113+ return 1;
63114+ }
63115+#endif
63116+ return 0;
63117+}
63118+
63119+EXPORT_SYMBOL(gr_pid_is_chrooted);
63120+
63121+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
63122+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
63123+{
63124+ struct path path, currentroot;
63125+ int ret = 0;
63126+
63127+ path.dentry = (struct dentry *)u_dentry;
63128+ path.mnt = (struct vfsmount *)u_mnt;
63129+ get_fs_root(current->fs, &currentroot);
63130+ if (path_is_under(&path, &currentroot))
63131+ ret = 1;
63132+ path_put(&currentroot);
63133+
63134+ return ret;
63135+}
63136+#endif
63137+
63138+int
63139+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
63140+{
63141+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63142+ if (!grsec_enable_chroot_fchdir)
63143+ return 1;
63144+
63145+ if (!proc_is_chrooted(current))
63146+ return 1;
63147+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
63148+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
63149+ return 0;
63150+ }
63151+#endif
63152+ return 1;
63153+}
63154+
63155+int
63156+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63157+ const time_t shm_createtime)
63158+{
63159+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63160+ struct task_struct *p;
63161+ time_t starttime;
63162+
63163+ if (unlikely(!grsec_enable_chroot_shmat))
63164+ return 1;
63165+
63166+ if (likely(!proc_is_chrooted(current)))
63167+ return 1;
63168+
63169+ rcu_read_lock();
63170+ read_lock(&tasklist_lock);
63171+
63172+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
63173+ starttime = p->start_time.tv_sec;
63174+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
63175+ if (have_same_root(current, p)) {
63176+ goto allow;
63177+ } else {
63178+ read_unlock(&tasklist_lock);
63179+ rcu_read_unlock();
63180+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63181+ return 0;
63182+ }
63183+ }
63184+ /* creator exited, pid reuse, fall through to next check */
63185+ }
63186+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
63187+ if (unlikely(!have_same_root(current, p))) {
63188+ read_unlock(&tasklist_lock);
63189+ rcu_read_unlock();
63190+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63191+ return 0;
63192+ }
63193+ }
63194+
63195+allow:
63196+ read_unlock(&tasklist_lock);
63197+ rcu_read_unlock();
63198+#endif
63199+ return 1;
63200+}
63201+
63202+void
63203+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
63204+{
63205+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63206+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
63207+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
63208+#endif
63209+ return;
63210+}
63211+
63212+int
63213+gr_handle_chroot_mknod(const struct dentry *dentry,
63214+ const struct vfsmount *mnt, const int mode)
63215+{
63216+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63217+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
63218+ proc_is_chrooted(current)) {
63219+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
63220+ return -EPERM;
63221+ }
63222+#endif
63223+ return 0;
63224+}
63225+
63226+int
63227+gr_handle_chroot_mount(const struct dentry *dentry,
63228+ const struct vfsmount *mnt, const char *dev_name)
63229+{
63230+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63231+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
63232+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
63233+ return -EPERM;
63234+ }
63235+#endif
63236+ return 0;
63237+}
63238+
63239+int
63240+gr_handle_chroot_pivot(void)
63241+{
63242+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63243+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
63244+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
63245+ return -EPERM;
63246+ }
63247+#endif
63248+ return 0;
63249+}
63250+
63251+int
63252+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
63253+{
63254+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63255+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
63256+ !gr_is_outside_chroot(dentry, mnt)) {
63257+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
63258+ return -EPERM;
63259+ }
63260+#endif
63261+ return 0;
63262+}
63263+
63264+extern const char *captab_log[];
63265+extern int captab_log_entries;
63266+
63267+int
63268+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63269+{
63270+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63271+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63272+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63273+ if (cap_raised(chroot_caps, cap)) {
63274+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
63275+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
63276+ }
63277+ return 0;
63278+ }
63279+ }
63280+#endif
63281+ return 1;
63282+}
63283+
63284+int
63285+gr_chroot_is_capable(const int cap)
63286+{
63287+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63288+ return gr_task_chroot_is_capable(current, current_cred(), cap);
63289+#endif
63290+ return 1;
63291+}
63292+
63293+int
63294+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
63295+{
63296+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63297+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63298+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63299+ if (cap_raised(chroot_caps, cap)) {
63300+ return 0;
63301+ }
63302+ }
63303+#endif
63304+ return 1;
63305+}
63306+
63307+int
63308+gr_chroot_is_capable_nolog(const int cap)
63309+{
63310+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63311+ return gr_task_chroot_is_capable_nolog(current, cap);
63312+#endif
63313+ return 1;
63314+}
63315+
63316+int
63317+gr_handle_chroot_sysctl(const int op)
63318+{
63319+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63320+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
63321+ proc_is_chrooted(current))
63322+ return -EACCES;
63323+#endif
63324+ return 0;
63325+}
63326+
63327+void
63328+gr_handle_chroot_chdir(struct path *path)
63329+{
63330+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63331+ if (grsec_enable_chroot_chdir)
63332+ set_fs_pwd(current->fs, path);
63333+#endif
63334+ return;
63335+}
63336+
63337+int
63338+gr_handle_chroot_chmod(const struct dentry *dentry,
63339+ const struct vfsmount *mnt, const int mode)
63340+{
63341+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63342+ /* allow chmod +s on directories, but not files */
63343+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
63344+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
63345+ proc_is_chrooted(current)) {
63346+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
63347+ return -EPERM;
63348+ }
63349+#endif
63350+ return 0;
63351+}
63352diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
63353new file mode 100644
63354index 0000000..207d409
63355--- /dev/null
63356+++ b/grsecurity/grsec_disabled.c
63357@@ -0,0 +1,434 @@
63358+#include <linux/kernel.h>
63359+#include <linux/module.h>
63360+#include <linux/sched.h>
63361+#include <linux/file.h>
63362+#include <linux/fs.h>
63363+#include <linux/kdev_t.h>
63364+#include <linux/net.h>
63365+#include <linux/in.h>
63366+#include <linux/ip.h>
63367+#include <linux/skbuff.h>
63368+#include <linux/sysctl.h>
63369+
63370+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63371+void
63372+pax_set_initial_flags(struct linux_binprm *bprm)
63373+{
63374+ return;
63375+}
63376+#endif
63377+
63378+#ifdef CONFIG_SYSCTL
63379+__u32
63380+gr_handle_sysctl(const struct ctl_table * table, const int op)
63381+{
63382+ return 0;
63383+}
63384+#endif
63385+
63386+#ifdef CONFIG_TASKSTATS
63387+int gr_is_taskstats_denied(int pid)
63388+{
63389+ return 0;
63390+}
63391+#endif
63392+
63393+int
63394+gr_acl_is_enabled(void)
63395+{
63396+ return 0;
63397+}
63398+
63399+void
63400+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
63401+{
63402+ return;
63403+}
63404+
63405+int
63406+gr_handle_rawio(const struct inode *inode)
63407+{
63408+ return 0;
63409+}
63410+
63411+void
63412+gr_acl_handle_psacct(struct task_struct *task, const long code)
63413+{
63414+ return;
63415+}
63416+
63417+int
63418+gr_handle_ptrace(struct task_struct *task, const long request)
63419+{
63420+ return 0;
63421+}
63422+
63423+int
63424+gr_handle_proc_ptrace(struct task_struct *task)
63425+{
63426+ return 0;
63427+}
63428+
63429+int
63430+gr_set_acls(const int type)
63431+{
63432+ return 0;
63433+}
63434+
63435+int
63436+gr_check_hidden_task(const struct task_struct *tsk)
63437+{
63438+ return 0;
63439+}
63440+
63441+int
63442+gr_check_protected_task(const struct task_struct *task)
63443+{
63444+ return 0;
63445+}
63446+
63447+int
63448+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
63449+{
63450+ return 0;
63451+}
63452+
63453+void
63454+gr_copy_label(struct task_struct *tsk)
63455+{
63456+ return;
63457+}
63458+
63459+void
63460+gr_set_pax_flags(struct task_struct *task)
63461+{
63462+ return;
63463+}
63464+
63465+int
63466+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63467+ const int unsafe_share)
63468+{
63469+ return 0;
63470+}
63471+
63472+void
63473+gr_handle_delete(const ino_t ino, const dev_t dev)
63474+{
63475+ return;
63476+}
63477+
63478+void
63479+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63480+{
63481+ return;
63482+}
63483+
63484+void
63485+gr_handle_crash(struct task_struct *task, const int sig)
63486+{
63487+ return;
63488+}
63489+
63490+int
63491+gr_check_crash_exec(const struct file *filp)
63492+{
63493+ return 0;
63494+}
63495+
63496+int
63497+gr_check_crash_uid(const kuid_t uid)
63498+{
63499+ return 0;
63500+}
63501+
63502+void
63503+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63504+ struct dentry *old_dentry,
63505+ struct dentry *new_dentry,
63506+ struct vfsmount *mnt, const __u8 replace)
63507+{
63508+ return;
63509+}
63510+
63511+int
63512+gr_search_socket(const int family, const int type, const int protocol)
63513+{
63514+ return 1;
63515+}
63516+
63517+int
63518+gr_search_connectbind(const int mode, const struct socket *sock,
63519+ const struct sockaddr_in *addr)
63520+{
63521+ return 0;
63522+}
63523+
63524+void
63525+gr_handle_alertkill(struct task_struct *task)
63526+{
63527+ return;
63528+}
63529+
63530+__u32
63531+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63532+{
63533+ return 1;
63534+}
63535+
63536+__u32
63537+gr_acl_handle_hidden_file(const struct dentry * dentry,
63538+ const struct vfsmount * mnt)
63539+{
63540+ return 1;
63541+}
63542+
63543+__u32
63544+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63545+ int acc_mode)
63546+{
63547+ return 1;
63548+}
63549+
63550+__u32
63551+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63552+{
63553+ return 1;
63554+}
63555+
63556+__u32
63557+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63558+{
63559+ return 1;
63560+}
63561+
63562+int
63563+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63564+ unsigned int *vm_flags)
63565+{
63566+ return 1;
63567+}
63568+
63569+__u32
63570+gr_acl_handle_truncate(const struct dentry * dentry,
63571+ const struct vfsmount * mnt)
63572+{
63573+ return 1;
63574+}
63575+
63576+__u32
63577+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63578+{
63579+ return 1;
63580+}
63581+
63582+__u32
63583+gr_acl_handle_access(const struct dentry * dentry,
63584+ const struct vfsmount * mnt, const int fmode)
63585+{
63586+ return 1;
63587+}
63588+
63589+__u32
63590+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63591+ umode_t *mode)
63592+{
63593+ return 1;
63594+}
63595+
63596+__u32
63597+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63598+{
63599+ return 1;
63600+}
63601+
63602+__u32
63603+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63604+{
63605+ return 1;
63606+}
63607+
63608+void
63609+grsecurity_init(void)
63610+{
63611+ return;
63612+}
63613+
63614+umode_t gr_acl_umask(void)
63615+{
63616+ return 0;
63617+}
63618+
63619+__u32
63620+gr_acl_handle_mknod(const struct dentry * new_dentry,
63621+ const struct dentry * parent_dentry,
63622+ const struct vfsmount * parent_mnt,
63623+ const int mode)
63624+{
63625+ return 1;
63626+}
63627+
63628+__u32
63629+gr_acl_handle_mkdir(const struct dentry * new_dentry,
63630+ const struct dentry * parent_dentry,
63631+ const struct vfsmount * parent_mnt)
63632+{
63633+ return 1;
63634+}
63635+
63636+__u32
63637+gr_acl_handle_symlink(const struct dentry * new_dentry,
63638+ const struct dentry * parent_dentry,
63639+ const struct vfsmount * parent_mnt, const struct filename *from)
63640+{
63641+ return 1;
63642+}
63643+
63644+__u32
63645+gr_acl_handle_link(const struct dentry * new_dentry,
63646+ const struct dentry * parent_dentry,
63647+ const struct vfsmount * parent_mnt,
63648+ const struct dentry * old_dentry,
63649+ const struct vfsmount * old_mnt, const struct filename *to)
63650+{
63651+ return 1;
63652+}
63653+
63654+int
63655+gr_acl_handle_rename(const struct dentry *new_dentry,
63656+ const struct dentry *parent_dentry,
63657+ const struct vfsmount *parent_mnt,
63658+ const struct dentry *old_dentry,
63659+ const struct inode *old_parent_inode,
63660+ const struct vfsmount *old_mnt, const struct filename *newname)
63661+{
63662+ return 0;
63663+}
63664+
63665+int
63666+gr_acl_handle_filldir(const struct file *file, const char *name,
63667+ const int namelen, const ino_t ino)
63668+{
63669+ return 1;
63670+}
63671+
63672+int
63673+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63674+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63675+{
63676+ return 1;
63677+}
63678+
63679+int
63680+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63681+{
63682+ return 0;
63683+}
63684+
63685+int
63686+gr_search_accept(const struct socket *sock)
63687+{
63688+ return 0;
63689+}
63690+
63691+int
63692+gr_search_listen(const struct socket *sock)
63693+{
63694+ return 0;
63695+}
63696+
63697+int
63698+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63699+{
63700+ return 0;
63701+}
63702+
63703+__u32
63704+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63705+{
63706+ return 1;
63707+}
63708+
63709+__u32
63710+gr_acl_handle_creat(const struct dentry * dentry,
63711+ const struct dentry * p_dentry,
63712+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63713+ const int imode)
63714+{
63715+ return 1;
63716+}
63717+
63718+void
63719+gr_acl_handle_exit(void)
63720+{
63721+ return;
63722+}
63723+
63724+int
63725+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63726+{
63727+ return 1;
63728+}
63729+
63730+void
63731+gr_set_role_label(const kuid_t uid, const kgid_t gid)
63732+{
63733+ return;
63734+}
63735+
63736+int
63737+gr_acl_handle_procpidmem(const struct task_struct *task)
63738+{
63739+ return 0;
63740+}
63741+
63742+int
63743+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63744+{
63745+ return 0;
63746+}
63747+
63748+int
63749+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63750+{
63751+ return 0;
63752+}
63753+
63754+void
63755+gr_set_kernel_label(struct task_struct *task)
63756+{
63757+ return;
63758+}
63759+
63760+int
63761+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63762+{
63763+ return 0;
63764+}
63765+
63766+int
63767+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63768+{
63769+ return 0;
63770+}
63771+
63772+int gr_acl_enable_at_secure(void)
63773+{
63774+ return 0;
63775+}
63776+
63777+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63778+{
63779+ return dentry->d_inode->i_sb->s_dev;
63780+}
63781+
63782+void gr_put_exec_file(struct task_struct *task)
63783+{
63784+ return;
63785+}
63786+
63787+EXPORT_SYMBOL(gr_set_kernel_label);
63788+#ifdef CONFIG_SECURITY
63789+EXPORT_SYMBOL(gr_check_user_change);
63790+EXPORT_SYMBOL(gr_check_group_change);
63791+#endif
63792diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63793new file mode 100644
63794index 0000000..387032b
63795--- /dev/null
63796+++ b/grsecurity/grsec_exec.c
63797@@ -0,0 +1,187 @@
63798+#include <linux/kernel.h>
63799+#include <linux/sched.h>
63800+#include <linux/file.h>
63801+#include <linux/binfmts.h>
63802+#include <linux/fs.h>
63803+#include <linux/types.h>
63804+#include <linux/grdefs.h>
63805+#include <linux/grsecurity.h>
63806+#include <linux/grinternal.h>
63807+#include <linux/capability.h>
63808+#include <linux/module.h>
63809+#include <linux/compat.h>
63810+
63811+#include <asm/uaccess.h>
63812+
63813+#ifdef CONFIG_GRKERNSEC_EXECLOG
63814+static char gr_exec_arg_buf[132];
63815+static DEFINE_MUTEX(gr_exec_arg_mutex);
63816+#endif
63817+
63818+struct user_arg_ptr {
63819+#ifdef CONFIG_COMPAT
63820+ bool is_compat;
63821+#endif
63822+ union {
63823+ const char __user *const __user *native;
63824+#ifdef CONFIG_COMPAT
63825+ const compat_uptr_t __user *compat;
63826+#endif
63827+ } ptr;
63828+};
63829+
63830+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63831+
63832+void
63833+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63834+{
63835+#ifdef CONFIG_GRKERNSEC_EXECLOG
63836+ char *grarg = gr_exec_arg_buf;
63837+ unsigned int i, x, execlen = 0;
63838+ char c;
63839+
63840+ if (!((grsec_enable_execlog && grsec_enable_group &&
63841+ in_group_p(grsec_audit_gid))
63842+ || (grsec_enable_execlog && !grsec_enable_group)))
63843+ return;
63844+
63845+ mutex_lock(&gr_exec_arg_mutex);
63846+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
63847+
63848+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
63849+ const char __user *p;
63850+ unsigned int len;
63851+
63852+ p = get_user_arg_ptr(argv, i);
63853+ if (IS_ERR(p))
63854+ goto log;
63855+
63856+ len = strnlen_user(p, 128 - execlen);
63857+ if (len > 128 - execlen)
63858+ len = 128 - execlen;
63859+ else if (len > 0)
63860+ len--;
63861+ if (copy_from_user(grarg + execlen, p, len))
63862+ goto log;
63863+
63864+ /* rewrite unprintable characters */
63865+ for (x = 0; x < len; x++) {
63866+ c = *(grarg + execlen + x);
63867+ if (c < 32 || c > 126)
63868+ *(grarg + execlen + x) = ' ';
63869+ }
63870+
63871+ execlen += len;
63872+ *(grarg + execlen) = ' ';
63873+ *(grarg + execlen + 1) = '\0';
63874+ execlen++;
63875+ }
63876+
63877+ log:
63878+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63879+ bprm->file->f_path.mnt, grarg);
63880+ mutex_unlock(&gr_exec_arg_mutex);
63881+#endif
63882+ return;
63883+}
63884+
63885+#ifdef CONFIG_GRKERNSEC
63886+extern int gr_acl_is_capable(const int cap);
63887+extern int gr_acl_is_capable_nolog(const int cap);
63888+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63889+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63890+extern int gr_chroot_is_capable(const int cap);
63891+extern int gr_chroot_is_capable_nolog(const int cap);
63892+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63893+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63894+#endif
63895+
63896+const char *captab_log[] = {
63897+ "CAP_CHOWN",
63898+ "CAP_DAC_OVERRIDE",
63899+ "CAP_DAC_READ_SEARCH",
63900+ "CAP_FOWNER",
63901+ "CAP_FSETID",
63902+ "CAP_KILL",
63903+ "CAP_SETGID",
63904+ "CAP_SETUID",
63905+ "CAP_SETPCAP",
63906+ "CAP_LINUX_IMMUTABLE",
63907+ "CAP_NET_BIND_SERVICE",
63908+ "CAP_NET_BROADCAST",
63909+ "CAP_NET_ADMIN",
63910+ "CAP_NET_RAW",
63911+ "CAP_IPC_LOCK",
63912+ "CAP_IPC_OWNER",
63913+ "CAP_SYS_MODULE",
63914+ "CAP_SYS_RAWIO",
63915+ "CAP_SYS_CHROOT",
63916+ "CAP_SYS_PTRACE",
63917+ "CAP_SYS_PACCT",
63918+ "CAP_SYS_ADMIN",
63919+ "CAP_SYS_BOOT",
63920+ "CAP_SYS_NICE",
63921+ "CAP_SYS_RESOURCE",
63922+ "CAP_SYS_TIME",
63923+ "CAP_SYS_TTY_CONFIG",
63924+ "CAP_MKNOD",
63925+ "CAP_LEASE",
63926+ "CAP_AUDIT_WRITE",
63927+ "CAP_AUDIT_CONTROL",
63928+ "CAP_SETFCAP",
63929+ "CAP_MAC_OVERRIDE",
63930+ "CAP_MAC_ADMIN",
63931+ "CAP_SYSLOG",
63932+ "CAP_WAKE_ALARM"
63933+};
63934+
63935+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63936+
63937+int gr_is_capable(const int cap)
63938+{
63939+#ifdef CONFIG_GRKERNSEC
63940+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63941+ return 1;
63942+ return 0;
63943+#else
63944+ return 1;
63945+#endif
63946+}
63947+
63948+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63949+{
63950+#ifdef CONFIG_GRKERNSEC
63951+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63952+ return 1;
63953+ return 0;
63954+#else
63955+ return 1;
63956+#endif
63957+}
63958+
63959+int gr_is_capable_nolog(const int cap)
63960+{
63961+#ifdef CONFIG_GRKERNSEC
63962+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
63963+ return 1;
63964+ return 0;
63965+#else
63966+ return 1;
63967+#endif
63968+}
63969+
63970+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
63971+{
63972+#ifdef CONFIG_GRKERNSEC
63973+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
63974+ return 1;
63975+ return 0;
63976+#else
63977+ return 1;
63978+#endif
63979+}
63980+
63981+EXPORT_SYMBOL(gr_is_capable);
63982+EXPORT_SYMBOL(gr_is_capable_nolog);
63983+EXPORT_SYMBOL(gr_task_is_capable);
63984+EXPORT_SYMBOL(gr_task_is_capable_nolog);
63985diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
63986new file mode 100644
63987index 0000000..06cc6ea
63988--- /dev/null
63989+++ b/grsecurity/grsec_fifo.c
63990@@ -0,0 +1,24 @@
63991+#include <linux/kernel.h>
63992+#include <linux/sched.h>
63993+#include <linux/fs.h>
63994+#include <linux/file.h>
63995+#include <linux/grinternal.h>
63996+
63997+int
63998+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
63999+ const struct dentry *dir, const int flag, const int acc_mode)
64000+{
64001+#ifdef CONFIG_GRKERNSEC_FIFO
64002+ const struct cred *cred = current_cred();
64003+
64004+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
64005+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
64006+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
64007+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
64008+ if (!inode_permission(dentry->d_inode, acc_mode))
64009+ 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));
64010+ return -EACCES;
64011+ }
64012+#endif
64013+ return 0;
64014+}
64015diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
64016new file mode 100644
64017index 0000000..8ca18bf
64018--- /dev/null
64019+++ b/grsecurity/grsec_fork.c
64020@@ -0,0 +1,23 @@
64021+#include <linux/kernel.h>
64022+#include <linux/sched.h>
64023+#include <linux/grsecurity.h>
64024+#include <linux/grinternal.h>
64025+#include <linux/errno.h>
64026+
64027+void
64028+gr_log_forkfail(const int retval)
64029+{
64030+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64031+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
64032+ switch (retval) {
64033+ case -EAGAIN:
64034+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
64035+ break;
64036+ case -ENOMEM:
64037+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
64038+ break;
64039+ }
64040+ }
64041+#endif
64042+ return;
64043+}
64044diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
64045new file mode 100644
64046index 0000000..a862e9f
64047--- /dev/null
64048+++ b/grsecurity/grsec_init.c
64049@@ -0,0 +1,283 @@
64050+#include <linux/kernel.h>
64051+#include <linux/sched.h>
64052+#include <linux/mm.h>
64053+#include <linux/gracl.h>
64054+#include <linux/slab.h>
64055+#include <linux/vmalloc.h>
64056+#include <linux/percpu.h>
64057+#include <linux/module.h>
64058+
64059+int grsec_enable_ptrace_readexec;
64060+int grsec_enable_setxid;
64061+int grsec_enable_symlinkown;
64062+kgid_t grsec_symlinkown_gid;
64063+int grsec_enable_brute;
64064+int grsec_enable_link;
64065+int grsec_enable_dmesg;
64066+int grsec_enable_harden_ptrace;
64067+int grsec_enable_fifo;
64068+int grsec_enable_execlog;
64069+int grsec_enable_signal;
64070+int grsec_enable_forkfail;
64071+int grsec_enable_audit_ptrace;
64072+int grsec_enable_time;
64073+int grsec_enable_audit_textrel;
64074+int grsec_enable_group;
64075+kgid_t grsec_audit_gid;
64076+int grsec_enable_chdir;
64077+int grsec_enable_mount;
64078+int grsec_enable_rofs;
64079+int grsec_enable_chroot_findtask;
64080+int grsec_enable_chroot_mount;
64081+int grsec_enable_chroot_shmat;
64082+int grsec_enable_chroot_fchdir;
64083+int grsec_enable_chroot_double;
64084+int grsec_enable_chroot_pivot;
64085+int grsec_enable_chroot_chdir;
64086+int grsec_enable_chroot_chmod;
64087+int grsec_enable_chroot_mknod;
64088+int grsec_enable_chroot_nice;
64089+int grsec_enable_chroot_execlog;
64090+int grsec_enable_chroot_caps;
64091+int grsec_enable_chroot_sysctl;
64092+int grsec_enable_chroot_unix;
64093+int grsec_enable_tpe;
64094+kgid_t grsec_tpe_gid;
64095+int grsec_enable_blackhole;
64096+#ifdef CONFIG_IPV6_MODULE
64097+EXPORT_SYMBOL(grsec_enable_blackhole);
64098+#endif
64099+int grsec_lastack_retries;
64100+int grsec_enable_tpe_all;
64101+int grsec_enable_tpe_invert;
64102+int grsec_enable_socket_all;
64103+kgid_t grsec_socket_all_gid;
64104+int grsec_enable_socket_client;
64105+kgid_t grsec_socket_client_gid;
64106+int grsec_enable_socket_server;
64107+kgid_t grsec_socket_server_gid;
64108+int grsec_resource_logging;
64109+int grsec_disable_privio;
64110+int grsec_enable_log_rwxmaps;
64111+int grsec_lock;
64112+
64113+DEFINE_SPINLOCK(grsec_alert_lock);
64114+unsigned long grsec_alert_wtime = 0;
64115+unsigned long grsec_alert_fyet = 0;
64116+
64117+DEFINE_SPINLOCK(grsec_audit_lock);
64118+
64119+DEFINE_RWLOCK(grsec_exec_file_lock);
64120+
64121+char *gr_shared_page[4];
64122+
64123+char *gr_alert_log_fmt;
64124+char *gr_audit_log_fmt;
64125+char *gr_alert_log_buf;
64126+char *gr_audit_log_buf;
64127+
64128+extern struct gr_arg *gr_usermode;
64129+extern unsigned char *gr_system_salt;
64130+extern unsigned char *gr_system_sum;
64131+
64132+void __init
64133+grsecurity_init(void)
64134+{
64135+ int j;
64136+ /* create the per-cpu shared pages */
64137+
64138+#ifdef CONFIG_X86
64139+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
64140+#endif
64141+
64142+ for (j = 0; j < 4; j++) {
64143+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
64144+ if (gr_shared_page[j] == NULL) {
64145+ panic("Unable to allocate grsecurity shared page");
64146+ return;
64147+ }
64148+ }
64149+
64150+ /* allocate log buffers */
64151+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
64152+ if (!gr_alert_log_fmt) {
64153+ panic("Unable to allocate grsecurity alert log format buffer");
64154+ return;
64155+ }
64156+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
64157+ if (!gr_audit_log_fmt) {
64158+ panic("Unable to allocate grsecurity audit log format buffer");
64159+ return;
64160+ }
64161+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64162+ if (!gr_alert_log_buf) {
64163+ panic("Unable to allocate grsecurity alert log buffer");
64164+ return;
64165+ }
64166+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64167+ if (!gr_audit_log_buf) {
64168+ panic("Unable to allocate grsecurity audit log buffer");
64169+ return;
64170+ }
64171+
64172+ /* allocate memory for authentication structure */
64173+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
64174+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
64175+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
64176+
64177+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
64178+ panic("Unable to allocate grsecurity authentication structure");
64179+ return;
64180+ }
64181+
64182+
64183+#ifdef CONFIG_GRKERNSEC_IO
64184+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
64185+ grsec_disable_privio = 1;
64186+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64187+ grsec_disable_privio = 1;
64188+#else
64189+ grsec_disable_privio = 0;
64190+#endif
64191+#endif
64192+
64193+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64194+ /* for backward compatibility, tpe_invert always defaults to on if
64195+ enabled in the kernel
64196+ */
64197+ grsec_enable_tpe_invert = 1;
64198+#endif
64199+
64200+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64201+#ifndef CONFIG_GRKERNSEC_SYSCTL
64202+ grsec_lock = 1;
64203+#endif
64204+
64205+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64206+ grsec_enable_audit_textrel = 1;
64207+#endif
64208+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64209+ grsec_enable_log_rwxmaps = 1;
64210+#endif
64211+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64212+ grsec_enable_group = 1;
64213+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
64214+#endif
64215+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64216+ grsec_enable_ptrace_readexec = 1;
64217+#endif
64218+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64219+ grsec_enable_chdir = 1;
64220+#endif
64221+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64222+ grsec_enable_harden_ptrace = 1;
64223+#endif
64224+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64225+ grsec_enable_mount = 1;
64226+#endif
64227+#ifdef CONFIG_GRKERNSEC_LINK
64228+ grsec_enable_link = 1;
64229+#endif
64230+#ifdef CONFIG_GRKERNSEC_BRUTE
64231+ grsec_enable_brute = 1;
64232+#endif
64233+#ifdef CONFIG_GRKERNSEC_DMESG
64234+ grsec_enable_dmesg = 1;
64235+#endif
64236+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64237+ grsec_enable_blackhole = 1;
64238+ grsec_lastack_retries = 4;
64239+#endif
64240+#ifdef CONFIG_GRKERNSEC_FIFO
64241+ grsec_enable_fifo = 1;
64242+#endif
64243+#ifdef CONFIG_GRKERNSEC_EXECLOG
64244+ grsec_enable_execlog = 1;
64245+#endif
64246+#ifdef CONFIG_GRKERNSEC_SETXID
64247+ grsec_enable_setxid = 1;
64248+#endif
64249+#ifdef CONFIG_GRKERNSEC_SIGNAL
64250+ grsec_enable_signal = 1;
64251+#endif
64252+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64253+ grsec_enable_forkfail = 1;
64254+#endif
64255+#ifdef CONFIG_GRKERNSEC_TIME
64256+ grsec_enable_time = 1;
64257+#endif
64258+#ifdef CONFIG_GRKERNSEC_RESLOG
64259+ grsec_resource_logging = 1;
64260+#endif
64261+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64262+ grsec_enable_chroot_findtask = 1;
64263+#endif
64264+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64265+ grsec_enable_chroot_unix = 1;
64266+#endif
64267+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64268+ grsec_enable_chroot_mount = 1;
64269+#endif
64270+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64271+ grsec_enable_chroot_fchdir = 1;
64272+#endif
64273+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64274+ grsec_enable_chroot_shmat = 1;
64275+#endif
64276+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64277+ grsec_enable_audit_ptrace = 1;
64278+#endif
64279+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64280+ grsec_enable_chroot_double = 1;
64281+#endif
64282+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64283+ grsec_enable_chroot_pivot = 1;
64284+#endif
64285+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64286+ grsec_enable_chroot_chdir = 1;
64287+#endif
64288+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64289+ grsec_enable_chroot_chmod = 1;
64290+#endif
64291+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64292+ grsec_enable_chroot_mknod = 1;
64293+#endif
64294+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64295+ grsec_enable_chroot_nice = 1;
64296+#endif
64297+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64298+ grsec_enable_chroot_execlog = 1;
64299+#endif
64300+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64301+ grsec_enable_chroot_caps = 1;
64302+#endif
64303+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64304+ grsec_enable_chroot_sysctl = 1;
64305+#endif
64306+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64307+ grsec_enable_symlinkown = 1;
64308+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
64309+#endif
64310+#ifdef CONFIG_GRKERNSEC_TPE
64311+ grsec_enable_tpe = 1;
64312+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
64313+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64314+ grsec_enable_tpe_all = 1;
64315+#endif
64316+#endif
64317+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64318+ grsec_enable_socket_all = 1;
64319+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
64320+#endif
64321+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64322+ grsec_enable_socket_client = 1;
64323+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
64324+#endif
64325+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64326+ grsec_enable_socket_server = 1;
64327+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
64328+#endif
64329+#endif
64330+
64331+ return;
64332+}
64333diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
64334new file mode 100644
64335index 0000000..5e05e20
64336--- /dev/null
64337+++ b/grsecurity/grsec_link.c
64338@@ -0,0 +1,58 @@
64339+#include <linux/kernel.h>
64340+#include <linux/sched.h>
64341+#include <linux/fs.h>
64342+#include <linux/file.h>
64343+#include <linux/grinternal.h>
64344+
64345+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
64346+{
64347+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64348+ const struct inode *link_inode = link->dentry->d_inode;
64349+
64350+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
64351+ /* ignore root-owned links, e.g. /proc/self */
64352+ gr_is_global_nonroot(link_inode->i_uid) && target &&
64353+ !uid_eq(link_inode->i_uid, target->i_uid)) {
64354+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
64355+ return 1;
64356+ }
64357+#endif
64358+ return 0;
64359+}
64360+
64361+int
64362+gr_handle_follow_link(const struct inode *parent,
64363+ const struct inode *inode,
64364+ const struct dentry *dentry, const struct vfsmount *mnt)
64365+{
64366+#ifdef CONFIG_GRKERNSEC_LINK
64367+ const struct cred *cred = current_cred();
64368+
64369+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
64370+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
64371+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
64372+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
64373+ return -EACCES;
64374+ }
64375+#endif
64376+ return 0;
64377+}
64378+
64379+int
64380+gr_handle_hardlink(const struct dentry *dentry,
64381+ const struct vfsmount *mnt,
64382+ struct inode *inode, const int mode, const struct filename *to)
64383+{
64384+#ifdef CONFIG_GRKERNSEC_LINK
64385+ const struct cred *cred = current_cred();
64386+
64387+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
64388+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
64389+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
64390+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
64391+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
64392+ return -EPERM;
64393+ }
64394+#endif
64395+ return 0;
64396+}
64397diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
64398new file mode 100644
64399index 0000000..7c06085
64400--- /dev/null
64401+++ b/grsecurity/grsec_log.c
64402@@ -0,0 +1,326 @@
64403+#include <linux/kernel.h>
64404+#include <linux/sched.h>
64405+#include <linux/file.h>
64406+#include <linux/tty.h>
64407+#include <linux/fs.h>
64408+#include <linux/grinternal.h>
64409+
64410+#ifdef CONFIG_TREE_PREEMPT_RCU
64411+#define DISABLE_PREEMPT() preempt_disable()
64412+#define ENABLE_PREEMPT() preempt_enable()
64413+#else
64414+#define DISABLE_PREEMPT()
64415+#define ENABLE_PREEMPT()
64416+#endif
64417+
64418+#define BEGIN_LOCKS(x) \
64419+ DISABLE_PREEMPT(); \
64420+ rcu_read_lock(); \
64421+ read_lock(&tasklist_lock); \
64422+ read_lock(&grsec_exec_file_lock); \
64423+ if (x != GR_DO_AUDIT) \
64424+ spin_lock(&grsec_alert_lock); \
64425+ else \
64426+ spin_lock(&grsec_audit_lock)
64427+
64428+#define END_LOCKS(x) \
64429+ if (x != GR_DO_AUDIT) \
64430+ spin_unlock(&grsec_alert_lock); \
64431+ else \
64432+ spin_unlock(&grsec_audit_lock); \
64433+ read_unlock(&grsec_exec_file_lock); \
64434+ read_unlock(&tasklist_lock); \
64435+ rcu_read_unlock(); \
64436+ ENABLE_PREEMPT(); \
64437+ if (x == GR_DONT_AUDIT) \
64438+ gr_handle_alertkill(current)
64439+
64440+enum {
64441+ FLOODING,
64442+ NO_FLOODING
64443+};
64444+
64445+extern char *gr_alert_log_fmt;
64446+extern char *gr_audit_log_fmt;
64447+extern char *gr_alert_log_buf;
64448+extern char *gr_audit_log_buf;
64449+
64450+static int gr_log_start(int audit)
64451+{
64452+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
64453+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
64454+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64455+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
64456+ unsigned long curr_secs = get_seconds();
64457+
64458+ if (audit == GR_DO_AUDIT)
64459+ goto set_fmt;
64460+
64461+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
64462+ grsec_alert_wtime = curr_secs;
64463+ grsec_alert_fyet = 0;
64464+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
64465+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
64466+ grsec_alert_fyet++;
64467+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
64468+ grsec_alert_wtime = curr_secs;
64469+ grsec_alert_fyet++;
64470+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64471+ return FLOODING;
64472+ }
64473+ else return FLOODING;
64474+
64475+set_fmt:
64476+#endif
64477+ memset(buf, 0, PAGE_SIZE);
64478+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
64479+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64480+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64481+ } else if (current->signal->curr_ip) {
64482+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64483+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64484+ } else if (gr_acl_is_enabled()) {
64485+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64486+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64487+ } else {
64488+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
64489+ strcpy(buf, fmt);
64490+ }
64491+
64492+ return NO_FLOODING;
64493+}
64494+
64495+static void gr_log_middle(int audit, const char *msg, va_list ap)
64496+ __attribute__ ((format (printf, 2, 0)));
64497+
64498+static void gr_log_middle(int audit, const char *msg, va_list ap)
64499+{
64500+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64501+ unsigned int len = strlen(buf);
64502+
64503+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64504+
64505+ return;
64506+}
64507+
64508+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64509+ __attribute__ ((format (printf, 2, 3)));
64510+
64511+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64512+{
64513+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64514+ unsigned int len = strlen(buf);
64515+ va_list ap;
64516+
64517+ va_start(ap, msg);
64518+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64519+ va_end(ap);
64520+
64521+ return;
64522+}
64523+
64524+static void gr_log_end(int audit, int append_default)
64525+{
64526+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64527+ if (append_default) {
64528+ struct task_struct *task = current;
64529+ struct task_struct *parent = task->real_parent;
64530+ const struct cred *cred = __task_cred(task);
64531+ const struct cred *pcred = __task_cred(parent);
64532+ unsigned int len = strlen(buf);
64533+
64534+ 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));
64535+ }
64536+
64537+ printk("%s\n", buf);
64538+
64539+ return;
64540+}
64541+
64542+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64543+{
64544+ int logtype;
64545+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64546+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64547+ void *voidptr = NULL;
64548+ int num1 = 0, num2 = 0;
64549+ unsigned long ulong1 = 0, ulong2 = 0;
64550+ struct dentry *dentry = NULL;
64551+ struct vfsmount *mnt = NULL;
64552+ struct file *file = NULL;
64553+ struct task_struct *task = NULL;
64554+ const struct cred *cred, *pcred;
64555+ va_list ap;
64556+
64557+ BEGIN_LOCKS(audit);
64558+ logtype = gr_log_start(audit);
64559+ if (logtype == FLOODING) {
64560+ END_LOCKS(audit);
64561+ return;
64562+ }
64563+ va_start(ap, argtypes);
64564+ switch (argtypes) {
64565+ case GR_TTYSNIFF:
64566+ task = va_arg(ap, struct task_struct *);
64567+ 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));
64568+ break;
64569+ case GR_SYSCTL_HIDDEN:
64570+ str1 = va_arg(ap, char *);
64571+ gr_log_middle_varargs(audit, msg, result, str1);
64572+ break;
64573+ case GR_RBAC:
64574+ dentry = va_arg(ap, struct dentry *);
64575+ mnt = va_arg(ap, struct vfsmount *);
64576+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64577+ break;
64578+ case GR_RBAC_STR:
64579+ dentry = va_arg(ap, struct dentry *);
64580+ mnt = va_arg(ap, struct vfsmount *);
64581+ str1 = va_arg(ap, char *);
64582+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64583+ break;
64584+ case GR_STR_RBAC:
64585+ str1 = va_arg(ap, char *);
64586+ dentry = va_arg(ap, struct dentry *);
64587+ mnt = va_arg(ap, struct vfsmount *);
64588+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64589+ break;
64590+ case GR_RBAC_MODE2:
64591+ dentry = va_arg(ap, struct dentry *);
64592+ mnt = va_arg(ap, struct vfsmount *);
64593+ str1 = va_arg(ap, char *);
64594+ str2 = va_arg(ap, char *);
64595+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64596+ break;
64597+ case GR_RBAC_MODE3:
64598+ dentry = va_arg(ap, struct dentry *);
64599+ mnt = va_arg(ap, struct vfsmount *);
64600+ str1 = va_arg(ap, char *);
64601+ str2 = va_arg(ap, char *);
64602+ str3 = va_arg(ap, char *);
64603+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64604+ break;
64605+ case GR_FILENAME:
64606+ dentry = va_arg(ap, struct dentry *);
64607+ mnt = va_arg(ap, struct vfsmount *);
64608+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64609+ break;
64610+ case GR_STR_FILENAME:
64611+ str1 = va_arg(ap, char *);
64612+ dentry = va_arg(ap, struct dentry *);
64613+ mnt = va_arg(ap, struct vfsmount *);
64614+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64615+ break;
64616+ case GR_FILENAME_STR:
64617+ dentry = va_arg(ap, struct dentry *);
64618+ mnt = va_arg(ap, struct vfsmount *);
64619+ str1 = va_arg(ap, char *);
64620+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64621+ break;
64622+ case GR_FILENAME_TWO_INT:
64623+ dentry = va_arg(ap, struct dentry *);
64624+ mnt = va_arg(ap, struct vfsmount *);
64625+ num1 = va_arg(ap, int);
64626+ num2 = va_arg(ap, int);
64627+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64628+ break;
64629+ case GR_FILENAME_TWO_INT_STR:
64630+ dentry = va_arg(ap, struct dentry *);
64631+ mnt = va_arg(ap, struct vfsmount *);
64632+ num1 = va_arg(ap, int);
64633+ num2 = va_arg(ap, int);
64634+ str1 = va_arg(ap, char *);
64635+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64636+ break;
64637+ case GR_TEXTREL:
64638+ file = va_arg(ap, struct file *);
64639+ ulong1 = va_arg(ap, unsigned long);
64640+ ulong2 = va_arg(ap, unsigned long);
64641+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64642+ break;
64643+ case GR_PTRACE:
64644+ task = va_arg(ap, struct task_struct *);
64645+ 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));
64646+ break;
64647+ case GR_RESOURCE:
64648+ task = va_arg(ap, struct task_struct *);
64649+ cred = __task_cred(task);
64650+ pcred = __task_cred(task->real_parent);
64651+ ulong1 = va_arg(ap, unsigned long);
64652+ str1 = va_arg(ap, char *);
64653+ ulong2 = va_arg(ap, unsigned long);
64654+ 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));
64655+ break;
64656+ case GR_CAP:
64657+ task = va_arg(ap, struct task_struct *);
64658+ cred = __task_cred(task);
64659+ pcred = __task_cred(task->real_parent);
64660+ str1 = va_arg(ap, char *);
64661+ 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));
64662+ break;
64663+ case GR_SIG:
64664+ str1 = va_arg(ap, char *);
64665+ voidptr = va_arg(ap, void *);
64666+ gr_log_middle_varargs(audit, msg, str1, voidptr);
64667+ break;
64668+ case GR_SIG2:
64669+ task = va_arg(ap, struct task_struct *);
64670+ cred = __task_cred(task);
64671+ pcred = __task_cred(task->real_parent);
64672+ num1 = va_arg(ap, int);
64673+ 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));
64674+ break;
64675+ case GR_CRASH1:
64676+ task = va_arg(ap, struct task_struct *);
64677+ cred = __task_cred(task);
64678+ pcred = __task_cred(task->real_parent);
64679+ ulong1 = va_arg(ap, unsigned long);
64680+ 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);
64681+ break;
64682+ case GR_CRASH2:
64683+ task = va_arg(ap, struct task_struct *);
64684+ cred = __task_cred(task);
64685+ pcred = __task_cred(task->real_parent);
64686+ ulong1 = va_arg(ap, unsigned long);
64687+ 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);
64688+ break;
64689+ case GR_RWXMAP:
64690+ file = va_arg(ap, struct file *);
64691+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64692+ break;
64693+ case GR_PSACCT:
64694+ {
64695+ unsigned int wday, cday;
64696+ __u8 whr, chr;
64697+ __u8 wmin, cmin;
64698+ __u8 wsec, csec;
64699+ char cur_tty[64] = { 0 };
64700+ char parent_tty[64] = { 0 };
64701+
64702+ task = va_arg(ap, struct task_struct *);
64703+ wday = va_arg(ap, unsigned int);
64704+ cday = va_arg(ap, unsigned int);
64705+ whr = va_arg(ap, int);
64706+ chr = va_arg(ap, int);
64707+ wmin = va_arg(ap, int);
64708+ cmin = va_arg(ap, int);
64709+ wsec = va_arg(ap, int);
64710+ csec = va_arg(ap, int);
64711+ ulong1 = va_arg(ap, unsigned long);
64712+ cred = __task_cred(task);
64713+ pcred = __task_cred(task->real_parent);
64714+
64715+ 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));
64716+ }
64717+ break;
64718+ default:
64719+ gr_log_middle(audit, msg, ap);
64720+ }
64721+ va_end(ap);
64722+ // these don't need DEFAULTSECARGS printed on the end
64723+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64724+ gr_log_end(audit, 0);
64725+ else
64726+ gr_log_end(audit, 1);
64727+ END_LOCKS(audit);
64728+}
64729diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64730new file mode 100644
64731index 0000000..f536303
64732--- /dev/null
64733+++ b/grsecurity/grsec_mem.c
64734@@ -0,0 +1,40 @@
64735+#include <linux/kernel.h>
64736+#include <linux/sched.h>
64737+#include <linux/mm.h>
64738+#include <linux/mman.h>
64739+#include <linux/grinternal.h>
64740+
64741+void
64742+gr_handle_ioperm(void)
64743+{
64744+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64745+ return;
64746+}
64747+
64748+void
64749+gr_handle_iopl(void)
64750+{
64751+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64752+ return;
64753+}
64754+
64755+void
64756+gr_handle_mem_readwrite(u64 from, u64 to)
64757+{
64758+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64759+ return;
64760+}
64761+
64762+void
64763+gr_handle_vm86(void)
64764+{
64765+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64766+ return;
64767+}
64768+
64769+void
64770+gr_log_badprocpid(const char *entry)
64771+{
64772+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64773+ return;
64774+}
64775diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64776new file mode 100644
64777index 0000000..2131422
64778--- /dev/null
64779+++ b/grsecurity/grsec_mount.c
64780@@ -0,0 +1,62 @@
64781+#include <linux/kernel.h>
64782+#include <linux/sched.h>
64783+#include <linux/mount.h>
64784+#include <linux/grsecurity.h>
64785+#include <linux/grinternal.h>
64786+
64787+void
64788+gr_log_remount(const char *devname, const int retval)
64789+{
64790+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64791+ if (grsec_enable_mount && (retval >= 0))
64792+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64793+#endif
64794+ return;
64795+}
64796+
64797+void
64798+gr_log_unmount(const char *devname, const int retval)
64799+{
64800+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64801+ if (grsec_enable_mount && (retval >= 0))
64802+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64803+#endif
64804+ return;
64805+}
64806+
64807+void
64808+gr_log_mount(const char *from, const char *to, const int retval)
64809+{
64810+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64811+ if (grsec_enable_mount && (retval >= 0))
64812+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64813+#endif
64814+ return;
64815+}
64816+
64817+int
64818+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64819+{
64820+#ifdef CONFIG_GRKERNSEC_ROFS
64821+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64822+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64823+ return -EPERM;
64824+ } else
64825+ return 0;
64826+#endif
64827+ return 0;
64828+}
64829+
64830+int
64831+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64832+{
64833+#ifdef CONFIG_GRKERNSEC_ROFS
64834+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64835+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64836+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64837+ return -EPERM;
64838+ } else
64839+ return 0;
64840+#endif
64841+ return 0;
64842+}
64843diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64844new file mode 100644
64845index 0000000..a3b12a0
64846--- /dev/null
64847+++ b/grsecurity/grsec_pax.c
64848@@ -0,0 +1,36 @@
64849+#include <linux/kernel.h>
64850+#include <linux/sched.h>
64851+#include <linux/mm.h>
64852+#include <linux/file.h>
64853+#include <linux/grinternal.h>
64854+#include <linux/grsecurity.h>
64855+
64856+void
64857+gr_log_textrel(struct vm_area_struct * vma)
64858+{
64859+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64860+ if (grsec_enable_audit_textrel)
64861+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64862+#endif
64863+ return;
64864+}
64865+
64866+void
64867+gr_log_rwxmmap(struct file *file)
64868+{
64869+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64870+ if (grsec_enable_log_rwxmaps)
64871+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64872+#endif
64873+ return;
64874+}
64875+
64876+void
64877+gr_log_rwxmprotect(struct file *file)
64878+{
64879+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64880+ if (grsec_enable_log_rwxmaps)
64881+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64882+#endif
64883+ return;
64884+}
64885diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64886new file mode 100644
64887index 0000000..f7f29aa
64888--- /dev/null
64889+++ b/grsecurity/grsec_ptrace.c
64890@@ -0,0 +1,30 @@
64891+#include <linux/kernel.h>
64892+#include <linux/sched.h>
64893+#include <linux/grinternal.h>
64894+#include <linux/security.h>
64895+
64896+void
64897+gr_audit_ptrace(struct task_struct *task)
64898+{
64899+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64900+ if (grsec_enable_audit_ptrace)
64901+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64902+#endif
64903+ return;
64904+}
64905+
64906+int
64907+gr_ptrace_readexec(struct file *file, int unsafe_flags)
64908+{
64909+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64910+ const struct dentry *dentry = file->f_path.dentry;
64911+ const struct vfsmount *mnt = file->f_path.mnt;
64912+
64913+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64914+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64915+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64916+ return -EACCES;
64917+ }
64918+#endif
64919+ return 0;
64920+}
64921diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64922new file mode 100644
64923index 0000000..e09715a
64924--- /dev/null
64925+++ b/grsecurity/grsec_sig.c
64926@@ -0,0 +1,222 @@
64927+#include <linux/kernel.h>
64928+#include <linux/sched.h>
64929+#include <linux/delay.h>
64930+#include <linux/grsecurity.h>
64931+#include <linux/grinternal.h>
64932+#include <linux/hardirq.h>
64933+
64934+char *signames[] = {
64935+ [SIGSEGV] = "Segmentation fault",
64936+ [SIGILL] = "Illegal instruction",
64937+ [SIGABRT] = "Abort",
64938+ [SIGBUS] = "Invalid alignment/Bus error"
64939+};
64940+
64941+void
64942+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64943+{
64944+#ifdef CONFIG_GRKERNSEC_SIGNAL
64945+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64946+ (sig == SIGABRT) || (sig == SIGBUS))) {
64947+ if (task_pid_nr(t) == task_pid_nr(current)) {
64948+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64949+ } else {
64950+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64951+ }
64952+ }
64953+#endif
64954+ return;
64955+}
64956+
64957+int
64958+gr_handle_signal(const struct task_struct *p, const int sig)
64959+{
64960+#ifdef CONFIG_GRKERNSEC
64961+ /* ignore the 0 signal for protected task checks */
64962+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
64963+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
64964+ return -EPERM;
64965+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
64966+ return -EPERM;
64967+ }
64968+#endif
64969+ return 0;
64970+}
64971+
64972+#ifdef CONFIG_GRKERNSEC
64973+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
64974+
64975+int gr_fake_force_sig(int sig, struct task_struct *t)
64976+{
64977+ unsigned long int flags;
64978+ int ret, blocked, ignored;
64979+ struct k_sigaction *action;
64980+
64981+ spin_lock_irqsave(&t->sighand->siglock, flags);
64982+ action = &t->sighand->action[sig-1];
64983+ ignored = action->sa.sa_handler == SIG_IGN;
64984+ blocked = sigismember(&t->blocked, sig);
64985+ if (blocked || ignored) {
64986+ action->sa.sa_handler = SIG_DFL;
64987+ if (blocked) {
64988+ sigdelset(&t->blocked, sig);
64989+ recalc_sigpending_and_wake(t);
64990+ }
64991+ }
64992+ if (action->sa.sa_handler == SIG_DFL)
64993+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
64994+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
64995+
64996+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
64997+
64998+ return ret;
64999+}
65000+#endif
65001+
65002+#ifdef CONFIG_GRKERNSEC_BRUTE
65003+#define GR_USER_BAN_TIME (15 * 60)
65004+#define GR_DAEMON_BRUTE_TIME (30 * 60)
65005+
65006+static int __get_dumpable(unsigned long mm_flags)
65007+{
65008+ int ret;
65009+
65010+ ret = mm_flags & MMF_DUMPABLE_MASK;
65011+ return (ret >= 2) ? 2 : ret;
65012+}
65013+#endif
65014+
65015+void gr_handle_brute_attach(unsigned long mm_flags)
65016+{
65017+#ifdef CONFIG_GRKERNSEC_BRUTE
65018+ struct task_struct *p = current;
65019+ kuid_t uid = GLOBAL_ROOT_UID;
65020+ int daemon = 0;
65021+
65022+ if (!grsec_enable_brute)
65023+ return;
65024+
65025+ rcu_read_lock();
65026+ read_lock(&tasklist_lock);
65027+ read_lock(&grsec_exec_file_lock);
65028+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
65029+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
65030+ p->real_parent->brute = 1;
65031+ daemon = 1;
65032+ } else {
65033+ const struct cred *cred = __task_cred(p), *cred2;
65034+ struct task_struct *tsk, *tsk2;
65035+
65036+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
65037+ struct user_struct *user;
65038+
65039+ uid = cred->uid;
65040+
65041+ /* this is put upon execution past expiration */
65042+ user = find_user(uid);
65043+ if (user == NULL)
65044+ goto unlock;
65045+ user->banned = 1;
65046+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
65047+ if (user->ban_expires == ~0UL)
65048+ user->ban_expires--;
65049+
65050+ do_each_thread(tsk2, tsk) {
65051+ cred2 = __task_cred(tsk);
65052+ if (tsk != p && uid_eq(cred2->uid, uid))
65053+ gr_fake_force_sig(SIGKILL, tsk);
65054+ } while_each_thread(tsk2, tsk);
65055+ }
65056+ }
65057+unlock:
65058+ read_unlock(&grsec_exec_file_lock);
65059+ read_unlock(&tasklist_lock);
65060+ rcu_read_unlock();
65061+
65062+ if (gr_is_global_nonroot(uid))
65063+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
65064+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
65065+ else if (daemon)
65066+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
65067+
65068+#endif
65069+ return;
65070+}
65071+
65072+void gr_handle_brute_check(void)
65073+{
65074+#ifdef CONFIG_GRKERNSEC_BRUTE
65075+ struct task_struct *p = current;
65076+
65077+ if (unlikely(p->brute)) {
65078+ if (!grsec_enable_brute)
65079+ p->brute = 0;
65080+ else if (time_before(get_seconds(), p->brute_expires))
65081+ msleep(30 * 1000);
65082+ }
65083+#endif
65084+ return;
65085+}
65086+
65087+void gr_handle_kernel_exploit(void)
65088+{
65089+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
65090+ const struct cred *cred;
65091+ struct task_struct *tsk, *tsk2;
65092+ struct user_struct *user;
65093+ kuid_t uid;
65094+
65095+ if (in_irq() || in_serving_softirq() || in_nmi())
65096+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
65097+
65098+ uid = current_uid();
65099+
65100+ if (gr_is_global_root(uid))
65101+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
65102+ else {
65103+ /* kill all the processes of this user, hold a reference
65104+ to their creds struct, and prevent them from creating
65105+ another process until system reset
65106+ */
65107+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
65108+ GR_GLOBAL_UID(uid));
65109+ /* we intentionally leak this ref */
65110+ user = get_uid(current->cred->user);
65111+ if (user) {
65112+ user->banned = 1;
65113+ user->ban_expires = ~0UL;
65114+ }
65115+
65116+ read_lock(&tasklist_lock);
65117+ do_each_thread(tsk2, tsk) {
65118+ cred = __task_cred(tsk);
65119+ if (uid_eq(cred->uid, uid))
65120+ gr_fake_force_sig(SIGKILL, tsk);
65121+ } while_each_thread(tsk2, tsk);
65122+ read_unlock(&tasklist_lock);
65123+ }
65124+#endif
65125+}
65126+
65127+int __gr_process_user_ban(struct user_struct *user)
65128+{
65129+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65130+ if (unlikely(user->banned)) {
65131+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
65132+ user->banned = 0;
65133+ user->ban_expires = 0;
65134+ free_uid(user);
65135+ } else
65136+ return -EPERM;
65137+ }
65138+#endif
65139+ return 0;
65140+}
65141+
65142+int gr_process_user_ban(void)
65143+{
65144+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65145+ return __gr_process_user_ban(current->cred->user);
65146+#endif
65147+ return 0;
65148+}
65149diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
65150new file mode 100644
65151index 0000000..4030d57
65152--- /dev/null
65153+++ b/grsecurity/grsec_sock.c
65154@@ -0,0 +1,244 @@
65155+#include <linux/kernel.h>
65156+#include <linux/module.h>
65157+#include <linux/sched.h>
65158+#include <linux/file.h>
65159+#include <linux/net.h>
65160+#include <linux/in.h>
65161+#include <linux/ip.h>
65162+#include <net/sock.h>
65163+#include <net/inet_sock.h>
65164+#include <linux/grsecurity.h>
65165+#include <linux/grinternal.h>
65166+#include <linux/gracl.h>
65167+
65168+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
65169+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
65170+
65171+EXPORT_SYMBOL(gr_search_udp_recvmsg);
65172+EXPORT_SYMBOL(gr_search_udp_sendmsg);
65173+
65174+#ifdef CONFIG_UNIX_MODULE
65175+EXPORT_SYMBOL(gr_acl_handle_unix);
65176+EXPORT_SYMBOL(gr_acl_handle_mknod);
65177+EXPORT_SYMBOL(gr_handle_chroot_unix);
65178+EXPORT_SYMBOL(gr_handle_create);
65179+#endif
65180+
65181+#ifdef CONFIG_GRKERNSEC
65182+#define gr_conn_table_size 32749
65183+struct conn_table_entry {
65184+ struct conn_table_entry *next;
65185+ struct signal_struct *sig;
65186+};
65187+
65188+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
65189+DEFINE_SPINLOCK(gr_conn_table_lock);
65190+
65191+extern const char * gr_socktype_to_name(unsigned char type);
65192+extern const char * gr_proto_to_name(unsigned char proto);
65193+extern const char * gr_sockfamily_to_name(unsigned char family);
65194+
65195+static __inline__ int
65196+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
65197+{
65198+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
65199+}
65200+
65201+static __inline__ int
65202+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
65203+ __u16 sport, __u16 dport)
65204+{
65205+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
65206+ sig->gr_sport == sport && sig->gr_dport == dport))
65207+ return 1;
65208+ else
65209+ return 0;
65210+}
65211+
65212+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
65213+{
65214+ struct conn_table_entry **match;
65215+ unsigned int index;
65216+
65217+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65218+ sig->gr_sport, sig->gr_dport,
65219+ gr_conn_table_size);
65220+
65221+ newent->sig = sig;
65222+
65223+ match = &gr_conn_table[index];
65224+ newent->next = *match;
65225+ *match = newent;
65226+
65227+ return;
65228+}
65229+
65230+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
65231+{
65232+ struct conn_table_entry *match, *last = NULL;
65233+ unsigned int index;
65234+
65235+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65236+ sig->gr_sport, sig->gr_dport,
65237+ gr_conn_table_size);
65238+
65239+ match = gr_conn_table[index];
65240+ while (match && !conn_match(match->sig,
65241+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
65242+ sig->gr_dport)) {
65243+ last = match;
65244+ match = match->next;
65245+ }
65246+
65247+ if (match) {
65248+ if (last)
65249+ last->next = match->next;
65250+ else
65251+ gr_conn_table[index] = NULL;
65252+ kfree(match);
65253+ }
65254+
65255+ return;
65256+}
65257+
65258+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
65259+ __u16 sport, __u16 dport)
65260+{
65261+ struct conn_table_entry *match;
65262+ unsigned int index;
65263+
65264+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
65265+
65266+ match = gr_conn_table[index];
65267+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
65268+ match = match->next;
65269+
65270+ if (match)
65271+ return match->sig;
65272+ else
65273+ return NULL;
65274+}
65275+
65276+#endif
65277+
65278+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
65279+{
65280+#ifdef CONFIG_GRKERNSEC
65281+ struct signal_struct *sig = task->signal;
65282+ struct conn_table_entry *newent;
65283+
65284+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
65285+ if (newent == NULL)
65286+ return;
65287+ /* no bh lock needed since we are called with bh disabled */
65288+ spin_lock(&gr_conn_table_lock);
65289+ gr_del_task_from_ip_table_nolock(sig);
65290+ sig->gr_saddr = inet->inet_rcv_saddr;
65291+ sig->gr_daddr = inet->inet_daddr;
65292+ sig->gr_sport = inet->inet_sport;
65293+ sig->gr_dport = inet->inet_dport;
65294+ gr_add_to_task_ip_table_nolock(sig, newent);
65295+ spin_unlock(&gr_conn_table_lock);
65296+#endif
65297+ return;
65298+}
65299+
65300+void gr_del_task_from_ip_table(struct task_struct *task)
65301+{
65302+#ifdef CONFIG_GRKERNSEC
65303+ spin_lock_bh(&gr_conn_table_lock);
65304+ gr_del_task_from_ip_table_nolock(task->signal);
65305+ spin_unlock_bh(&gr_conn_table_lock);
65306+#endif
65307+ return;
65308+}
65309+
65310+void
65311+gr_attach_curr_ip(const struct sock *sk)
65312+{
65313+#ifdef CONFIG_GRKERNSEC
65314+ struct signal_struct *p, *set;
65315+ const struct inet_sock *inet = inet_sk(sk);
65316+
65317+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
65318+ return;
65319+
65320+ set = current->signal;
65321+
65322+ spin_lock_bh(&gr_conn_table_lock);
65323+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
65324+ inet->inet_dport, inet->inet_sport);
65325+ if (unlikely(p != NULL)) {
65326+ set->curr_ip = p->curr_ip;
65327+ set->used_accept = 1;
65328+ gr_del_task_from_ip_table_nolock(p);
65329+ spin_unlock_bh(&gr_conn_table_lock);
65330+ return;
65331+ }
65332+ spin_unlock_bh(&gr_conn_table_lock);
65333+
65334+ set->curr_ip = inet->inet_daddr;
65335+ set->used_accept = 1;
65336+#endif
65337+ return;
65338+}
65339+
65340+int
65341+gr_handle_sock_all(const int family, const int type, const int protocol)
65342+{
65343+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65344+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
65345+ (family != AF_UNIX)) {
65346+ if (family == AF_INET)
65347+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
65348+ else
65349+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
65350+ return -EACCES;
65351+ }
65352+#endif
65353+ return 0;
65354+}
65355+
65356+int
65357+gr_handle_sock_server(const struct sockaddr *sck)
65358+{
65359+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65360+ if (grsec_enable_socket_server &&
65361+ in_group_p(grsec_socket_server_gid) &&
65362+ sck && (sck->sa_family != AF_UNIX) &&
65363+ (sck->sa_family != AF_LOCAL)) {
65364+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65365+ return -EACCES;
65366+ }
65367+#endif
65368+ return 0;
65369+}
65370+
65371+int
65372+gr_handle_sock_server_other(const struct sock *sck)
65373+{
65374+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65375+ if (grsec_enable_socket_server &&
65376+ in_group_p(grsec_socket_server_gid) &&
65377+ sck && (sck->sk_family != AF_UNIX) &&
65378+ (sck->sk_family != AF_LOCAL)) {
65379+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65380+ return -EACCES;
65381+ }
65382+#endif
65383+ return 0;
65384+}
65385+
65386+int
65387+gr_handle_sock_client(const struct sockaddr *sck)
65388+{
65389+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65390+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
65391+ sck && (sck->sa_family != AF_UNIX) &&
65392+ (sck->sa_family != AF_LOCAL)) {
65393+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
65394+ return -EACCES;
65395+ }
65396+#endif
65397+ return 0;
65398+}
65399diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
65400new file mode 100644
65401index 0000000..f55ef0f
65402--- /dev/null
65403+++ b/grsecurity/grsec_sysctl.c
65404@@ -0,0 +1,469 @@
65405+#include <linux/kernel.h>
65406+#include <linux/sched.h>
65407+#include <linux/sysctl.h>
65408+#include <linux/grsecurity.h>
65409+#include <linux/grinternal.h>
65410+
65411+int
65412+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
65413+{
65414+#ifdef CONFIG_GRKERNSEC_SYSCTL
65415+ if (dirname == NULL || name == NULL)
65416+ return 0;
65417+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
65418+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
65419+ return -EACCES;
65420+ }
65421+#endif
65422+ return 0;
65423+}
65424+
65425+#ifdef CONFIG_GRKERNSEC_ROFS
65426+static int __maybe_unused one = 1;
65427+#endif
65428+
65429+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
65430+struct ctl_table grsecurity_table[] = {
65431+#ifdef CONFIG_GRKERNSEC_SYSCTL
65432+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
65433+#ifdef CONFIG_GRKERNSEC_IO
65434+ {
65435+ .procname = "disable_priv_io",
65436+ .data = &grsec_disable_privio,
65437+ .maxlen = sizeof(int),
65438+ .mode = 0600,
65439+ .proc_handler = &proc_dointvec,
65440+ },
65441+#endif
65442+#endif
65443+#ifdef CONFIG_GRKERNSEC_LINK
65444+ {
65445+ .procname = "linking_restrictions",
65446+ .data = &grsec_enable_link,
65447+ .maxlen = sizeof(int),
65448+ .mode = 0600,
65449+ .proc_handler = &proc_dointvec,
65450+ },
65451+#endif
65452+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65453+ {
65454+ .procname = "enforce_symlinksifowner",
65455+ .data = &grsec_enable_symlinkown,
65456+ .maxlen = sizeof(int),
65457+ .mode = 0600,
65458+ .proc_handler = &proc_dointvec,
65459+ },
65460+ {
65461+ .procname = "symlinkown_gid",
65462+ .data = &grsec_symlinkown_gid,
65463+ .maxlen = sizeof(int),
65464+ .mode = 0600,
65465+ .proc_handler = &proc_dointvec,
65466+ },
65467+#endif
65468+#ifdef CONFIG_GRKERNSEC_BRUTE
65469+ {
65470+ .procname = "deter_bruteforce",
65471+ .data = &grsec_enable_brute,
65472+ .maxlen = sizeof(int),
65473+ .mode = 0600,
65474+ .proc_handler = &proc_dointvec,
65475+ },
65476+#endif
65477+#ifdef CONFIG_GRKERNSEC_FIFO
65478+ {
65479+ .procname = "fifo_restrictions",
65480+ .data = &grsec_enable_fifo,
65481+ .maxlen = sizeof(int),
65482+ .mode = 0600,
65483+ .proc_handler = &proc_dointvec,
65484+ },
65485+#endif
65486+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65487+ {
65488+ .procname = "ptrace_readexec",
65489+ .data = &grsec_enable_ptrace_readexec,
65490+ .maxlen = sizeof(int),
65491+ .mode = 0600,
65492+ .proc_handler = &proc_dointvec,
65493+ },
65494+#endif
65495+#ifdef CONFIG_GRKERNSEC_SETXID
65496+ {
65497+ .procname = "consistent_setxid",
65498+ .data = &grsec_enable_setxid,
65499+ .maxlen = sizeof(int),
65500+ .mode = 0600,
65501+ .proc_handler = &proc_dointvec,
65502+ },
65503+#endif
65504+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65505+ {
65506+ .procname = "ip_blackhole",
65507+ .data = &grsec_enable_blackhole,
65508+ .maxlen = sizeof(int),
65509+ .mode = 0600,
65510+ .proc_handler = &proc_dointvec,
65511+ },
65512+ {
65513+ .procname = "lastack_retries",
65514+ .data = &grsec_lastack_retries,
65515+ .maxlen = sizeof(int),
65516+ .mode = 0600,
65517+ .proc_handler = &proc_dointvec,
65518+ },
65519+#endif
65520+#ifdef CONFIG_GRKERNSEC_EXECLOG
65521+ {
65522+ .procname = "exec_logging",
65523+ .data = &grsec_enable_execlog,
65524+ .maxlen = sizeof(int),
65525+ .mode = 0600,
65526+ .proc_handler = &proc_dointvec,
65527+ },
65528+#endif
65529+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65530+ {
65531+ .procname = "rwxmap_logging",
65532+ .data = &grsec_enable_log_rwxmaps,
65533+ .maxlen = sizeof(int),
65534+ .mode = 0600,
65535+ .proc_handler = &proc_dointvec,
65536+ },
65537+#endif
65538+#ifdef CONFIG_GRKERNSEC_SIGNAL
65539+ {
65540+ .procname = "signal_logging",
65541+ .data = &grsec_enable_signal,
65542+ .maxlen = sizeof(int),
65543+ .mode = 0600,
65544+ .proc_handler = &proc_dointvec,
65545+ },
65546+#endif
65547+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65548+ {
65549+ .procname = "forkfail_logging",
65550+ .data = &grsec_enable_forkfail,
65551+ .maxlen = sizeof(int),
65552+ .mode = 0600,
65553+ .proc_handler = &proc_dointvec,
65554+ },
65555+#endif
65556+#ifdef CONFIG_GRKERNSEC_TIME
65557+ {
65558+ .procname = "timechange_logging",
65559+ .data = &grsec_enable_time,
65560+ .maxlen = sizeof(int),
65561+ .mode = 0600,
65562+ .proc_handler = &proc_dointvec,
65563+ },
65564+#endif
65565+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65566+ {
65567+ .procname = "chroot_deny_shmat",
65568+ .data = &grsec_enable_chroot_shmat,
65569+ .maxlen = sizeof(int),
65570+ .mode = 0600,
65571+ .proc_handler = &proc_dointvec,
65572+ },
65573+#endif
65574+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65575+ {
65576+ .procname = "chroot_deny_unix",
65577+ .data = &grsec_enable_chroot_unix,
65578+ .maxlen = sizeof(int),
65579+ .mode = 0600,
65580+ .proc_handler = &proc_dointvec,
65581+ },
65582+#endif
65583+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65584+ {
65585+ .procname = "chroot_deny_mount",
65586+ .data = &grsec_enable_chroot_mount,
65587+ .maxlen = sizeof(int),
65588+ .mode = 0600,
65589+ .proc_handler = &proc_dointvec,
65590+ },
65591+#endif
65592+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65593+ {
65594+ .procname = "chroot_deny_fchdir",
65595+ .data = &grsec_enable_chroot_fchdir,
65596+ .maxlen = sizeof(int),
65597+ .mode = 0600,
65598+ .proc_handler = &proc_dointvec,
65599+ },
65600+#endif
65601+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65602+ {
65603+ .procname = "chroot_deny_chroot",
65604+ .data = &grsec_enable_chroot_double,
65605+ .maxlen = sizeof(int),
65606+ .mode = 0600,
65607+ .proc_handler = &proc_dointvec,
65608+ },
65609+#endif
65610+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65611+ {
65612+ .procname = "chroot_deny_pivot",
65613+ .data = &grsec_enable_chroot_pivot,
65614+ .maxlen = sizeof(int),
65615+ .mode = 0600,
65616+ .proc_handler = &proc_dointvec,
65617+ },
65618+#endif
65619+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65620+ {
65621+ .procname = "chroot_enforce_chdir",
65622+ .data = &grsec_enable_chroot_chdir,
65623+ .maxlen = sizeof(int),
65624+ .mode = 0600,
65625+ .proc_handler = &proc_dointvec,
65626+ },
65627+#endif
65628+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65629+ {
65630+ .procname = "chroot_deny_chmod",
65631+ .data = &grsec_enable_chroot_chmod,
65632+ .maxlen = sizeof(int),
65633+ .mode = 0600,
65634+ .proc_handler = &proc_dointvec,
65635+ },
65636+#endif
65637+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65638+ {
65639+ .procname = "chroot_deny_mknod",
65640+ .data = &grsec_enable_chroot_mknod,
65641+ .maxlen = sizeof(int),
65642+ .mode = 0600,
65643+ .proc_handler = &proc_dointvec,
65644+ },
65645+#endif
65646+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65647+ {
65648+ .procname = "chroot_restrict_nice",
65649+ .data = &grsec_enable_chroot_nice,
65650+ .maxlen = sizeof(int),
65651+ .mode = 0600,
65652+ .proc_handler = &proc_dointvec,
65653+ },
65654+#endif
65655+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65656+ {
65657+ .procname = "chroot_execlog",
65658+ .data = &grsec_enable_chroot_execlog,
65659+ .maxlen = sizeof(int),
65660+ .mode = 0600,
65661+ .proc_handler = &proc_dointvec,
65662+ },
65663+#endif
65664+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65665+ {
65666+ .procname = "chroot_caps",
65667+ .data = &grsec_enable_chroot_caps,
65668+ .maxlen = sizeof(int),
65669+ .mode = 0600,
65670+ .proc_handler = &proc_dointvec,
65671+ },
65672+#endif
65673+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65674+ {
65675+ .procname = "chroot_deny_sysctl",
65676+ .data = &grsec_enable_chroot_sysctl,
65677+ .maxlen = sizeof(int),
65678+ .mode = 0600,
65679+ .proc_handler = &proc_dointvec,
65680+ },
65681+#endif
65682+#ifdef CONFIG_GRKERNSEC_TPE
65683+ {
65684+ .procname = "tpe",
65685+ .data = &grsec_enable_tpe,
65686+ .maxlen = sizeof(int),
65687+ .mode = 0600,
65688+ .proc_handler = &proc_dointvec,
65689+ },
65690+ {
65691+ .procname = "tpe_gid",
65692+ .data = &grsec_tpe_gid,
65693+ .maxlen = sizeof(int),
65694+ .mode = 0600,
65695+ .proc_handler = &proc_dointvec,
65696+ },
65697+#endif
65698+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65699+ {
65700+ .procname = "tpe_invert",
65701+ .data = &grsec_enable_tpe_invert,
65702+ .maxlen = sizeof(int),
65703+ .mode = 0600,
65704+ .proc_handler = &proc_dointvec,
65705+ },
65706+#endif
65707+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65708+ {
65709+ .procname = "tpe_restrict_all",
65710+ .data = &grsec_enable_tpe_all,
65711+ .maxlen = sizeof(int),
65712+ .mode = 0600,
65713+ .proc_handler = &proc_dointvec,
65714+ },
65715+#endif
65716+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65717+ {
65718+ .procname = "socket_all",
65719+ .data = &grsec_enable_socket_all,
65720+ .maxlen = sizeof(int),
65721+ .mode = 0600,
65722+ .proc_handler = &proc_dointvec,
65723+ },
65724+ {
65725+ .procname = "socket_all_gid",
65726+ .data = &grsec_socket_all_gid,
65727+ .maxlen = sizeof(int),
65728+ .mode = 0600,
65729+ .proc_handler = &proc_dointvec,
65730+ },
65731+#endif
65732+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65733+ {
65734+ .procname = "socket_client",
65735+ .data = &grsec_enable_socket_client,
65736+ .maxlen = sizeof(int),
65737+ .mode = 0600,
65738+ .proc_handler = &proc_dointvec,
65739+ },
65740+ {
65741+ .procname = "socket_client_gid",
65742+ .data = &grsec_socket_client_gid,
65743+ .maxlen = sizeof(int),
65744+ .mode = 0600,
65745+ .proc_handler = &proc_dointvec,
65746+ },
65747+#endif
65748+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65749+ {
65750+ .procname = "socket_server",
65751+ .data = &grsec_enable_socket_server,
65752+ .maxlen = sizeof(int),
65753+ .mode = 0600,
65754+ .proc_handler = &proc_dointvec,
65755+ },
65756+ {
65757+ .procname = "socket_server_gid",
65758+ .data = &grsec_socket_server_gid,
65759+ .maxlen = sizeof(int),
65760+ .mode = 0600,
65761+ .proc_handler = &proc_dointvec,
65762+ },
65763+#endif
65764+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65765+ {
65766+ .procname = "audit_group",
65767+ .data = &grsec_enable_group,
65768+ .maxlen = sizeof(int),
65769+ .mode = 0600,
65770+ .proc_handler = &proc_dointvec,
65771+ },
65772+ {
65773+ .procname = "audit_gid",
65774+ .data = &grsec_audit_gid,
65775+ .maxlen = sizeof(int),
65776+ .mode = 0600,
65777+ .proc_handler = &proc_dointvec,
65778+ },
65779+#endif
65780+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65781+ {
65782+ .procname = "audit_chdir",
65783+ .data = &grsec_enable_chdir,
65784+ .maxlen = sizeof(int),
65785+ .mode = 0600,
65786+ .proc_handler = &proc_dointvec,
65787+ },
65788+#endif
65789+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65790+ {
65791+ .procname = "audit_mount",
65792+ .data = &grsec_enable_mount,
65793+ .maxlen = sizeof(int),
65794+ .mode = 0600,
65795+ .proc_handler = &proc_dointvec,
65796+ },
65797+#endif
65798+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65799+ {
65800+ .procname = "audit_textrel",
65801+ .data = &grsec_enable_audit_textrel,
65802+ .maxlen = sizeof(int),
65803+ .mode = 0600,
65804+ .proc_handler = &proc_dointvec,
65805+ },
65806+#endif
65807+#ifdef CONFIG_GRKERNSEC_DMESG
65808+ {
65809+ .procname = "dmesg",
65810+ .data = &grsec_enable_dmesg,
65811+ .maxlen = sizeof(int),
65812+ .mode = 0600,
65813+ .proc_handler = &proc_dointvec,
65814+ },
65815+#endif
65816+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65817+ {
65818+ .procname = "chroot_findtask",
65819+ .data = &grsec_enable_chroot_findtask,
65820+ .maxlen = sizeof(int),
65821+ .mode = 0600,
65822+ .proc_handler = &proc_dointvec,
65823+ },
65824+#endif
65825+#ifdef CONFIG_GRKERNSEC_RESLOG
65826+ {
65827+ .procname = "resource_logging",
65828+ .data = &grsec_resource_logging,
65829+ .maxlen = sizeof(int),
65830+ .mode = 0600,
65831+ .proc_handler = &proc_dointvec,
65832+ },
65833+#endif
65834+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65835+ {
65836+ .procname = "audit_ptrace",
65837+ .data = &grsec_enable_audit_ptrace,
65838+ .maxlen = sizeof(int),
65839+ .mode = 0600,
65840+ .proc_handler = &proc_dointvec,
65841+ },
65842+#endif
65843+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65844+ {
65845+ .procname = "harden_ptrace",
65846+ .data = &grsec_enable_harden_ptrace,
65847+ .maxlen = sizeof(int),
65848+ .mode = 0600,
65849+ .proc_handler = &proc_dointvec,
65850+ },
65851+#endif
65852+ {
65853+ .procname = "grsec_lock",
65854+ .data = &grsec_lock,
65855+ .maxlen = sizeof(int),
65856+ .mode = 0600,
65857+ .proc_handler = &proc_dointvec,
65858+ },
65859+#endif
65860+#ifdef CONFIG_GRKERNSEC_ROFS
65861+ {
65862+ .procname = "romount_protect",
65863+ .data = &grsec_enable_rofs,
65864+ .maxlen = sizeof(int),
65865+ .mode = 0600,
65866+ .proc_handler = &proc_dointvec_minmax,
65867+ .extra1 = &one,
65868+ .extra2 = &one,
65869+ },
65870+#endif
65871+ { }
65872+};
65873+#endif
65874diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65875new file mode 100644
65876index 0000000..0dc13c3
65877--- /dev/null
65878+++ b/grsecurity/grsec_time.c
65879@@ -0,0 +1,16 @@
65880+#include <linux/kernel.h>
65881+#include <linux/sched.h>
65882+#include <linux/grinternal.h>
65883+#include <linux/module.h>
65884+
65885+void
65886+gr_log_timechange(void)
65887+{
65888+#ifdef CONFIG_GRKERNSEC_TIME
65889+ if (grsec_enable_time)
65890+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65891+#endif
65892+ return;
65893+}
65894+
65895+EXPORT_SYMBOL(gr_log_timechange);
65896diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65897new file mode 100644
65898index 0000000..ee57dcf
65899--- /dev/null
65900+++ b/grsecurity/grsec_tpe.c
65901@@ -0,0 +1,73 @@
65902+#include <linux/kernel.h>
65903+#include <linux/sched.h>
65904+#include <linux/file.h>
65905+#include <linux/fs.h>
65906+#include <linux/grinternal.h>
65907+
65908+extern int gr_acl_tpe_check(void);
65909+
65910+int
65911+gr_tpe_allow(const struct file *file)
65912+{
65913+#ifdef CONFIG_GRKERNSEC
65914+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65915+ const struct cred *cred = current_cred();
65916+ char *msg = NULL;
65917+ char *msg2 = NULL;
65918+
65919+ // never restrict root
65920+ if (gr_is_global_root(cred->uid))
65921+ return 1;
65922+
65923+ if (grsec_enable_tpe) {
65924+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65925+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65926+ msg = "not being in trusted group";
65927+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65928+ msg = "being in untrusted group";
65929+#else
65930+ if (in_group_p(grsec_tpe_gid))
65931+ msg = "being in untrusted group";
65932+#endif
65933+ }
65934+ if (!msg && gr_acl_tpe_check())
65935+ msg = "being in untrusted role";
65936+
65937+ // not in any affected group/role
65938+ if (!msg)
65939+ goto next_check;
65940+
65941+ if (gr_is_global_nonroot(inode->i_uid))
65942+ msg2 = "file in non-root-owned directory";
65943+ else if (inode->i_mode & S_IWOTH)
65944+ msg2 = "file in world-writable directory";
65945+ else if (inode->i_mode & S_IWGRP)
65946+ msg2 = "file in group-writable directory";
65947+
65948+ if (msg && msg2) {
65949+ char fullmsg[70] = {0};
65950+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65951+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65952+ return 0;
65953+ }
65954+ msg = NULL;
65955+next_check:
65956+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65957+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
65958+ return 1;
65959+
65960+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
65961+ msg = "directory not owned by user";
65962+ else if (inode->i_mode & S_IWOTH)
65963+ msg = "file in world-writable directory";
65964+ else if (inode->i_mode & S_IWGRP)
65965+ msg = "file in group-writable directory";
65966+
65967+ if (msg) {
65968+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
65969+ return 0;
65970+ }
65971+#endif
65972+#endif
65973+ return 1;
65974+}
65975diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
65976new file mode 100644
65977index 0000000..9f7b1ac
65978--- /dev/null
65979+++ b/grsecurity/grsum.c
65980@@ -0,0 +1,61 @@
65981+#include <linux/err.h>
65982+#include <linux/kernel.h>
65983+#include <linux/sched.h>
65984+#include <linux/mm.h>
65985+#include <linux/scatterlist.h>
65986+#include <linux/crypto.h>
65987+#include <linux/gracl.h>
65988+
65989+
65990+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
65991+#error "crypto and sha256 must be built into the kernel"
65992+#endif
65993+
65994+int
65995+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
65996+{
65997+ char *p;
65998+ struct crypto_hash *tfm;
65999+ struct hash_desc desc;
66000+ struct scatterlist sg;
66001+ unsigned char temp_sum[GR_SHA_LEN];
66002+ volatile int retval = 0;
66003+ volatile int dummy = 0;
66004+ unsigned int i;
66005+
66006+ sg_init_table(&sg, 1);
66007+
66008+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
66009+ if (IS_ERR(tfm)) {
66010+ /* should never happen, since sha256 should be built in */
66011+ return 1;
66012+ }
66013+
66014+ desc.tfm = tfm;
66015+ desc.flags = 0;
66016+
66017+ crypto_hash_init(&desc);
66018+
66019+ p = salt;
66020+ sg_set_buf(&sg, p, GR_SALT_LEN);
66021+ crypto_hash_update(&desc, &sg, sg.length);
66022+
66023+ p = entry->pw;
66024+ sg_set_buf(&sg, p, strlen(p));
66025+
66026+ crypto_hash_update(&desc, &sg, sg.length);
66027+
66028+ crypto_hash_final(&desc, temp_sum);
66029+
66030+ memset(entry->pw, 0, GR_PW_LEN);
66031+
66032+ for (i = 0; i < GR_SHA_LEN; i++)
66033+ if (sum[i] != temp_sum[i])
66034+ retval = 1;
66035+ else
66036+ dummy = 1; // waste a cycle
66037+
66038+ crypto_free_hash(tfm);
66039+
66040+ return retval;
66041+}
66042diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
66043index 77ff547..181834f 100644
66044--- a/include/asm-generic/4level-fixup.h
66045+++ b/include/asm-generic/4level-fixup.h
66046@@ -13,8 +13,10 @@
66047 #define pmd_alloc(mm, pud, address) \
66048 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
66049 NULL: pmd_offset(pud, address))
66050+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
66051
66052 #define pud_alloc(mm, pgd, address) (pgd)
66053+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
66054 #define pud_offset(pgd, start) (pgd)
66055 #define pud_none(pud) 0
66056 #define pud_bad(pud) 0
66057diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
66058index b7babf0..04ad282 100644
66059--- a/include/asm-generic/atomic-long.h
66060+++ b/include/asm-generic/atomic-long.h
66061@@ -22,6 +22,12 @@
66062
66063 typedef atomic64_t atomic_long_t;
66064
66065+#ifdef CONFIG_PAX_REFCOUNT
66066+typedef atomic64_unchecked_t atomic_long_unchecked_t;
66067+#else
66068+typedef atomic64_t atomic_long_unchecked_t;
66069+#endif
66070+
66071 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
66072
66073 static inline long atomic_long_read(atomic_long_t *l)
66074@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66075 return (long)atomic64_read(v);
66076 }
66077
66078+#ifdef CONFIG_PAX_REFCOUNT
66079+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66080+{
66081+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66082+
66083+ return (long)atomic64_read_unchecked(v);
66084+}
66085+#endif
66086+
66087 static inline void atomic_long_set(atomic_long_t *l, long i)
66088 {
66089 atomic64_t *v = (atomic64_t *)l;
66090@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66091 atomic64_set(v, i);
66092 }
66093
66094+#ifdef CONFIG_PAX_REFCOUNT
66095+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66096+{
66097+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66098+
66099+ atomic64_set_unchecked(v, i);
66100+}
66101+#endif
66102+
66103 static inline void atomic_long_inc(atomic_long_t *l)
66104 {
66105 atomic64_t *v = (atomic64_t *)l;
66106@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66107 atomic64_inc(v);
66108 }
66109
66110+#ifdef CONFIG_PAX_REFCOUNT
66111+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66112+{
66113+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66114+
66115+ atomic64_inc_unchecked(v);
66116+}
66117+#endif
66118+
66119 static inline void atomic_long_dec(atomic_long_t *l)
66120 {
66121 atomic64_t *v = (atomic64_t *)l;
66122@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66123 atomic64_dec(v);
66124 }
66125
66126+#ifdef CONFIG_PAX_REFCOUNT
66127+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66128+{
66129+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66130+
66131+ atomic64_dec_unchecked(v);
66132+}
66133+#endif
66134+
66135 static inline void atomic_long_add(long i, atomic_long_t *l)
66136 {
66137 atomic64_t *v = (atomic64_t *)l;
66138@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66139 atomic64_add(i, v);
66140 }
66141
66142+#ifdef CONFIG_PAX_REFCOUNT
66143+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66144+{
66145+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66146+
66147+ atomic64_add_unchecked(i, v);
66148+}
66149+#endif
66150+
66151 static inline void atomic_long_sub(long i, atomic_long_t *l)
66152 {
66153 atomic64_t *v = (atomic64_t *)l;
66154@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66155 atomic64_sub(i, v);
66156 }
66157
66158+#ifdef CONFIG_PAX_REFCOUNT
66159+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66160+{
66161+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66162+
66163+ atomic64_sub_unchecked(i, v);
66164+}
66165+#endif
66166+
66167 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66168 {
66169 atomic64_t *v = (atomic64_t *)l;
66170@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66171 return (long)atomic64_add_return(i, v);
66172 }
66173
66174+#ifdef CONFIG_PAX_REFCOUNT
66175+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66176+{
66177+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66178+
66179+ return (long)atomic64_add_return_unchecked(i, v);
66180+}
66181+#endif
66182+
66183 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66184 {
66185 atomic64_t *v = (atomic64_t *)l;
66186@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66187 return (long)atomic64_inc_return(v);
66188 }
66189
66190+#ifdef CONFIG_PAX_REFCOUNT
66191+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66192+{
66193+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66194+
66195+ return (long)atomic64_inc_return_unchecked(v);
66196+}
66197+#endif
66198+
66199 static inline long atomic_long_dec_return(atomic_long_t *l)
66200 {
66201 atomic64_t *v = (atomic64_t *)l;
66202@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66203
66204 typedef atomic_t atomic_long_t;
66205
66206+#ifdef CONFIG_PAX_REFCOUNT
66207+typedef atomic_unchecked_t atomic_long_unchecked_t;
66208+#else
66209+typedef atomic_t atomic_long_unchecked_t;
66210+#endif
66211+
66212 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
66213 static inline long atomic_long_read(atomic_long_t *l)
66214 {
66215@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66216 return (long)atomic_read(v);
66217 }
66218
66219+#ifdef CONFIG_PAX_REFCOUNT
66220+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66221+{
66222+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66223+
66224+ return (long)atomic_read_unchecked(v);
66225+}
66226+#endif
66227+
66228 static inline void atomic_long_set(atomic_long_t *l, long i)
66229 {
66230 atomic_t *v = (atomic_t *)l;
66231@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66232 atomic_set(v, i);
66233 }
66234
66235+#ifdef CONFIG_PAX_REFCOUNT
66236+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66237+{
66238+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66239+
66240+ atomic_set_unchecked(v, i);
66241+}
66242+#endif
66243+
66244 static inline void atomic_long_inc(atomic_long_t *l)
66245 {
66246 atomic_t *v = (atomic_t *)l;
66247@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66248 atomic_inc(v);
66249 }
66250
66251+#ifdef CONFIG_PAX_REFCOUNT
66252+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66253+{
66254+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66255+
66256+ atomic_inc_unchecked(v);
66257+}
66258+#endif
66259+
66260 static inline void atomic_long_dec(atomic_long_t *l)
66261 {
66262 atomic_t *v = (atomic_t *)l;
66263@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66264 atomic_dec(v);
66265 }
66266
66267+#ifdef CONFIG_PAX_REFCOUNT
66268+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66269+{
66270+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66271+
66272+ atomic_dec_unchecked(v);
66273+}
66274+#endif
66275+
66276 static inline void atomic_long_add(long i, atomic_long_t *l)
66277 {
66278 atomic_t *v = (atomic_t *)l;
66279@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66280 atomic_add(i, v);
66281 }
66282
66283+#ifdef CONFIG_PAX_REFCOUNT
66284+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66285+{
66286+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66287+
66288+ atomic_add_unchecked(i, v);
66289+}
66290+#endif
66291+
66292 static inline void atomic_long_sub(long i, atomic_long_t *l)
66293 {
66294 atomic_t *v = (atomic_t *)l;
66295@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66296 atomic_sub(i, v);
66297 }
66298
66299+#ifdef CONFIG_PAX_REFCOUNT
66300+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66301+{
66302+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66303+
66304+ atomic_sub_unchecked(i, v);
66305+}
66306+#endif
66307+
66308 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66309 {
66310 atomic_t *v = (atomic_t *)l;
66311@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66312 return (long)atomic_add_return(i, v);
66313 }
66314
66315+#ifdef CONFIG_PAX_REFCOUNT
66316+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66317+{
66318+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66319+
66320+ return (long)atomic_add_return_unchecked(i, v);
66321+}
66322+
66323+#endif
66324+
66325 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66326 {
66327 atomic_t *v = (atomic_t *)l;
66328@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66329 return (long)atomic_inc_return(v);
66330 }
66331
66332+#ifdef CONFIG_PAX_REFCOUNT
66333+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66334+{
66335+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66336+
66337+ return (long)atomic_inc_return_unchecked(v);
66338+}
66339+#endif
66340+
66341 static inline long atomic_long_dec_return(atomic_long_t *l)
66342 {
66343 atomic_t *v = (atomic_t *)l;
66344@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66345
66346 #endif /* BITS_PER_LONG == 64 */
66347
66348+#ifdef CONFIG_PAX_REFCOUNT
66349+static inline void pax_refcount_needs_these_functions(void)
66350+{
66351+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
66352+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
66353+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
66354+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
66355+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
66356+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
66357+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
66358+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
66359+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
66360+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
66361+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
66362+#ifdef CONFIG_X86
66363+ atomic_clear_mask_unchecked(0, NULL);
66364+ atomic_set_mask_unchecked(0, NULL);
66365+#endif
66366+
66367+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
66368+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
66369+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
66370+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
66371+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
66372+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
66373+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
66374+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
66375+}
66376+#else
66377+#define atomic_read_unchecked(v) atomic_read(v)
66378+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
66379+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
66380+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
66381+#define atomic_inc_unchecked(v) atomic_inc(v)
66382+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
66383+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
66384+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
66385+#define atomic_dec_unchecked(v) atomic_dec(v)
66386+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
66387+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
66388+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
66389+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
66390+
66391+#define atomic_long_read_unchecked(v) atomic_long_read(v)
66392+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
66393+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
66394+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
66395+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
66396+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
66397+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
66398+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
66399+#endif
66400+
66401 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
66402diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
66403index 1ced641..c896ee8 100644
66404--- a/include/asm-generic/atomic.h
66405+++ b/include/asm-generic/atomic.h
66406@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
66407 * Atomically clears the bits set in @mask from @v
66408 */
66409 #ifndef atomic_clear_mask
66410-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
66411+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
66412 {
66413 unsigned long flags;
66414
66415diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
66416index b18ce4f..2ee2843 100644
66417--- a/include/asm-generic/atomic64.h
66418+++ b/include/asm-generic/atomic64.h
66419@@ -16,6 +16,8 @@ typedef struct {
66420 long long counter;
66421 } atomic64_t;
66422
66423+typedef atomic64_t atomic64_unchecked_t;
66424+
66425 #define ATOMIC64_INIT(i) { (i) }
66426
66427 extern long long atomic64_read(const atomic64_t *v);
66428@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
66429 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
66430 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
66431
66432+#define atomic64_read_unchecked(v) atomic64_read(v)
66433+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
66434+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
66435+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
66436+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
66437+#define atomic64_inc_unchecked(v) atomic64_inc(v)
66438+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
66439+#define atomic64_dec_unchecked(v) atomic64_dec(v)
66440+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
66441+
66442 #endif /* _ASM_GENERIC_ATOMIC64_H */
66443diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
66444index 1bfcfe5..e04c5c9 100644
66445--- a/include/asm-generic/cache.h
66446+++ b/include/asm-generic/cache.h
66447@@ -6,7 +6,7 @@
66448 * cache lines need to provide their own cache.h.
66449 */
66450
66451-#define L1_CACHE_SHIFT 5
66452-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
66453+#define L1_CACHE_SHIFT 5UL
66454+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
66455
66456 #endif /* __ASM_GENERIC_CACHE_H */
66457diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
66458index 0d68a1e..b74a761 100644
66459--- a/include/asm-generic/emergency-restart.h
66460+++ b/include/asm-generic/emergency-restart.h
66461@@ -1,7 +1,7 @@
66462 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
66463 #define _ASM_GENERIC_EMERGENCY_RESTART_H
66464
66465-static inline void machine_emergency_restart(void)
66466+static inline __noreturn void machine_emergency_restart(void)
66467 {
66468 machine_restart(NULL);
66469 }
66470diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66471index 90f99c7..00ce236 100644
66472--- a/include/asm-generic/kmap_types.h
66473+++ b/include/asm-generic/kmap_types.h
66474@@ -2,9 +2,9 @@
66475 #define _ASM_GENERIC_KMAP_TYPES_H
66476
66477 #ifdef __WITH_KM_FENCE
66478-# define KM_TYPE_NR 41
66479+# define KM_TYPE_NR 42
66480 #else
66481-# define KM_TYPE_NR 20
66482+# define KM_TYPE_NR 21
66483 #endif
66484
66485 #endif
66486diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66487index 9ceb03b..62b0b8f 100644
66488--- a/include/asm-generic/local.h
66489+++ b/include/asm-generic/local.h
66490@@ -23,24 +23,37 @@ typedef struct
66491 atomic_long_t a;
66492 } local_t;
66493
66494+typedef struct {
66495+ atomic_long_unchecked_t a;
66496+} local_unchecked_t;
66497+
66498 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66499
66500 #define local_read(l) atomic_long_read(&(l)->a)
66501+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66502 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66503+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66504 #define local_inc(l) atomic_long_inc(&(l)->a)
66505+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66506 #define local_dec(l) atomic_long_dec(&(l)->a)
66507+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66508 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66509+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66510 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66511+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66512
66513 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66514 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66515 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66516 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66517 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66518+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66519 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66520 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66521+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66522
66523 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66524+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66525 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66526 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66527 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66528diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66529index 725612b..9cc513a 100644
66530--- a/include/asm-generic/pgtable-nopmd.h
66531+++ b/include/asm-generic/pgtable-nopmd.h
66532@@ -1,14 +1,19 @@
66533 #ifndef _PGTABLE_NOPMD_H
66534 #define _PGTABLE_NOPMD_H
66535
66536-#ifndef __ASSEMBLY__
66537-
66538 #include <asm-generic/pgtable-nopud.h>
66539
66540-struct mm_struct;
66541-
66542 #define __PAGETABLE_PMD_FOLDED
66543
66544+#define PMD_SHIFT PUD_SHIFT
66545+#define PTRS_PER_PMD 1
66546+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66547+#define PMD_MASK (~(PMD_SIZE-1))
66548+
66549+#ifndef __ASSEMBLY__
66550+
66551+struct mm_struct;
66552+
66553 /*
66554 * Having the pmd type consist of a pud gets the size right, and allows
66555 * us to conceptually access the pud entry that this pmd is folded into
66556@@ -16,11 +21,6 @@ struct mm_struct;
66557 */
66558 typedef struct { pud_t pud; } pmd_t;
66559
66560-#define PMD_SHIFT PUD_SHIFT
66561-#define PTRS_PER_PMD 1
66562-#define PMD_SIZE (1UL << PMD_SHIFT)
66563-#define PMD_MASK (~(PMD_SIZE-1))
66564-
66565 /*
66566 * The "pud_xxx()" functions here are trivial for a folded two-level
66567 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66568diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66569index 810431d..0ec4804f 100644
66570--- a/include/asm-generic/pgtable-nopud.h
66571+++ b/include/asm-generic/pgtable-nopud.h
66572@@ -1,10 +1,15 @@
66573 #ifndef _PGTABLE_NOPUD_H
66574 #define _PGTABLE_NOPUD_H
66575
66576-#ifndef __ASSEMBLY__
66577-
66578 #define __PAGETABLE_PUD_FOLDED
66579
66580+#define PUD_SHIFT PGDIR_SHIFT
66581+#define PTRS_PER_PUD 1
66582+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66583+#define PUD_MASK (~(PUD_SIZE-1))
66584+
66585+#ifndef __ASSEMBLY__
66586+
66587 /*
66588 * Having the pud type consist of a pgd gets the size right, and allows
66589 * us to conceptually access the pgd entry that this pud is folded into
66590@@ -12,11 +17,6 @@
66591 */
66592 typedef struct { pgd_t pgd; } pud_t;
66593
66594-#define PUD_SHIFT PGDIR_SHIFT
66595-#define PTRS_PER_PUD 1
66596-#define PUD_SIZE (1UL << PUD_SHIFT)
66597-#define PUD_MASK (~(PUD_SIZE-1))
66598-
66599 /*
66600 * The "pgd_xxx()" functions here are trivial for a folded two-level
66601 * setup: the pud is never bad, and a pud always exists (as it's folded
66602@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66603 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66604
66605 #define pgd_populate(mm, pgd, pud) do { } while (0)
66606+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66607 /*
66608 * (puds are folded into pgds so this doesn't get actually called,
66609 * but the define is needed for a generic inline function.)
66610diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66611index 5cf680a..4b74d62 100644
66612--- a/include/asm-generic/pgtable.h
66613+++ b/include/asm-generic/pgtable.h
66614@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66615 }
66616 #endif /* CONFIG_NUMA_BALANCING */
66617
66618+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66619+static inline unsigned long pax_open_kernel(void) { return 0; }
66620+#endif
66621+
66622+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66623+static inline unsigned long pax_close_kernel(void) { return 0; }
66624+#endif
66625+
66626 #endif /* CONFIG_MMU */
66627
66628 #endif /* !__ASSEMBLY__ */
66629diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66630index d1ea7ce..b1ebf2a 100644
66631--- a/include/asm-generic/vmlinux.lds.h
66632+++ b/include/asm-generic/vmlinux.lds.h
66633@@ -218,6 +218,7 @@
66634 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66635 VMLINUX_SYMBOL(__start_rodata) = .; \
66636 *(.rodata) *(.rodata.*) \
66637+ *(.data..read_only) \
66638 *(__vermagic) /* Kernel version magic */ \
66639 . = ALIGN(8); \
66640 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66641@@ -725,17 +726,18 @@
66642 * section in the linker script will go there too. @phdr should have
66643 * a leading colon.
66644 *
66645- * Note that this macros defines __per_cpu_load as an absolute symbol.
66646+ * Note that this macros defines per_cpu_load as an absolute symbol.
66647 * If there is no need to put the percpu section at a predetermined
66648 * address, use PERCPU_SECTION.
66649 */
66650 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66651- VMLINUX_SYMBOL(__per_cpu_load) = .; \
66652- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66653+ per_cpu_load = .; \
66654+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66655 - LOAD_OFFSET) { \
66656+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66657 PERCPU_INPUT(cacheline) \
66658 } phdr \
66659- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66660+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66661
66662 /**
66663 * PERCPU_SECTION - define output section for percpu area, simple version
66664diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66665index 418d270..bfd2794 100644
66666--- a/include/crypto/algapi.h
66667+++ b/include/crypto/algapi.h
66668@@ -34,7 +34,7 @@ struct crypto_type {
66669 unsigned int maskclear;
66670 unsigned int maskset;
66671 unsigned int tfmsize;
66672-};
66673+} __do_const;
66674
66675 struct crypto_instance {
66676 struct crypto_alg alg;
66677diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66678index fad21c9..ab858bc 100644
66679--- a/include/drm/drmP.h
66680+++ b/include/drm/drmP.h
66681@@ -72,6 +72,7 @@
66682 #include <linux/workqueue.h>
66683 #include <linux/poll.h>
66684 #include <asm/pgalloc.h>
66685+#include <asm/local.h>
66686 #include <drm/drm.h>
66687 #include <drm/drm_sarea.h>
66688
66689@@ -293,10 +294,12 @@ do { \
66690 * \param cmd command.
66691 * \param arg argument.
66692 */
66693-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66694+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66695+ struct drm_file *file_priv);
66696+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66697 struct drm_file *file_priv);
66698
66699-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66700+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66701 unsigned long arg);
66702
66703 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66704@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66705 struct drm_ioctl_desc {
66706 unsigned int cmd;
66707 int flags;
66708- drm_ioctl_t *func;
66709+ drm_ioctl_t func;
66710 unsigned int cmd_drv;
66711-};
66712+} __do_const;
66713
66714 /**
66715 * Creates a driver or general drm_ioctl_desc array entry for the given
66716@@ -995,7 +998,7 @@ struct drm_info_list {
66717 int (*show)(struct seq_file*, void*); /** show callback */
66718 u32 driver_features; /**< Required driver features for this entry */
66719 void *data;
66720-};
66721+} __do_const;
66722
66723 /**
66724 * debugfs node structure. This structure represents a debugfs file.
66725@@ -1068,7 +1071,7 @@ struct drm_device {
66726
66727 /** \name Usage Counters */
66728 /*@{ */
66729- int open_count; /**< Outstanding files open */
66730+ local_t open_count; /**< Outstanding files open */
66731 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66732 atomic_t vma_count; /**< Outstanding vma areas open */
66733 int buf_use; /**< Buffers in use -- cannot alloc */
66734@@ -1079,7 +1082,7 @@ struct drm_device {
66735 /*@{ */
66736 unsigned long counters;
66737 enum drm_stat_type types[15];
66738- atomic_t counts[15];
66739+ atomic_unchecked_t counts[15];
66740 /*@} */
66741
66742 struct list_head filelist;
66743diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66744index f43d556..94d9343 100644
66745--- a/include/drm/drm_crtc_helper.h
66746+++ b/include/drm/drm_crtc_helper.h
66747@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66748 struct drm_connector *connector);
66749 /* disable encoder when not in use - more explicit than dpms off */
66750 void (*disable)(struct drm_encoder *encoder);
66751-};
66752+} __no_const;
66753
66754 /**
66755 * drm_connector_helper_funcs - helper operations for connectors
66756diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66757index 72dcbe8..8db58d7 100644
66758--- a/include/drm/ttm/ttm_memory.h
66759+++ b/include/drm/ttm/ttm_memory.h
66760@@ -48,7 +48,7 @@
66761
66762 struct ttm_mem_shrink {
66763 int (*do_shrink) (struct ttm_mem_shrink *);
66764-};
66765+} __no_const;
66766
66767 /**
66768 * struct ttm_mem_global - Global memory accounting structure.
66769diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66770index 4b840e8..155d235 100644
66771--- a/include/keys/asymmetric-subtype.h
66772+++ b/include/keys/asymmetric-subtype.h
66773@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66774 /* Verify the signature on a key of this subtype (optional) */
66775 int (*verify_signature)(const struct key *key,
66776 const struct public_key_signature *sig);
66777-};
66778+} __do_const;
66779
66780 /**
66781 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66782diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66783index c1da539..1dcec55 100644
66784--- a/include/linux/atmdev.h
66785+++ b/include/linux/atmdev.h
66786@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66787 #endif
66788
66789 struct k_atm_aal_stats {
66790-#define __HANDLE_ITEM(i) atomic_t i
66791+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66792 __AAL_STAT_ITEMS
66793 #undef __HANDLE_ITEM
66794 };
66795@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66796 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66797 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66798 struct module *owner;
66799-};
66800+} __do_const ;
66801
66802 struct atmphy_ops {
66803 int (*start)(struct atm_dev *dev);
66804diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66805index 0530b98..96a8ac0 100644
66806--- a/include/linux/binfmts.h
66807+++ b/include/linux/binfmts.h
66808@@ -73,8 +73,9 @@ struct linux_binfmt {
66809 int (*load_binary)(struct linux_binprm *);
66810 int (*load_shlib)(struct file *);
66811 int (*core_dump)(struct coredump_params *cprm);
66812+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66813 unsigned long min_coredump; /* minimal dump size */
66814-};
66815+} __do_const;
66816
66817 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66818
66819diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66820index f94bc83..62b9cfe 100644
66821--- a/include/linux/blkdev.h
66822+++ b/include/linux/blkdev.h
66823@@ -1498,7 +1498,7 @@ struct block_device_operations {
66824 /* this callback is with swap_lock and sometimes page table lock held */
66825 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66826 struct module *owner;
66827-};
66828+} __do_const;
66829
66830 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66831 unsigned long);
66832diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66833index 7c2e030..b72475d 100644
66834--- a/include/linux/blktrace_api.h
66835+++ b/include/linux/blktrace_api.h
66836@@ -23,7 +23,7 @@ struct blk_trace {
66837 struct dentry *dir;
66838 struct dentry *dropped_file;
66839 struct dentry *msg_file;
66840- atomic_t dropped;
66841+ atomic_unchecked_t dropped;
66842 };
66843
66844 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66845diff --git a/include/linux/cache.h b/include/linux/cache.h
66846index 4c57065..4307975 100644
66847--- a/include/linux/cache.h
66848+++ b/include/linux/cache.h
66849@@ -16,6 +16,10 @@
66850 #define __read_mostly
66851 #endif
66852
66853+#ifndef __read_only
66854+#define __read_only __read_mostly
66855+#endif
66856+
66857 #ifndef ____cacheline_aligned
66858 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66859 #endif
66860diff --git a/include/linux/capability.h b/include/linux/capability.h
66861index 98503b7..cc36d18 100644
66862--- a/include/linux/capability.h
66863+++ b/include/linux/capability.h
66864@@ -211,8 +211,13 @@ extern bool capable(int cap);
66865 extern bool ns_capable(struct user_namespace *ns, int cap);
66866 extern bool nsown_capable(int cap);
66867 extern bool inode_capable(const struct inode *inode, int cap);
66868+extern bool capable_nolog(int cap);
66869+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66870+extern bool inode_capable_nolog(const struct inode *inode, int cap);
66871
66872 /* audit system wants to get cap info from files as well */
66873 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66874
66875+extern int is_privileged_binary(const struct dentry *dentry);
66876+
66877 #endif /* !_LINUX_CAPABILITY_H */
66878diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66879index 8609d57..86e4d79 100644
66880--- a/include/linux/cdrom.h
66881+++ b/include/linux/cdrom.h
66882@@ -87,7 +87,6 @@ struct cdrom_device_ops {
66883
66884 /* driver specifications */
66885 const int capability; /* capability flags */
66886- int n_minors; /* number of active minor devices */
66887 /* handle uniform packets for scsi type devices (scsi,atapi) */
66888 int (*generic_packet) (struct cdrom_device_info *,
66889 struct packet_command *);
66890diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66891index 42e55de..1cd0e66 100644
66892--- a/include/linux/cleancache.h
66893+++ b/include/linux/cleancache.h
66894@@ -31,7 +31,7 @@ struct cleancache_ops {
66895 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66896 void (*invalidate_inode)(int, struct cleancache_filekey);
66897 void (*invalidate_fs)(int);
66898-};
66899+} __no_const;
66900
66901 extern struct cleancache_ops
66902 cleancache_register_ops(struct cleancache_ops *ops);
66903diff --git a/include/linux/compat.h b/include/linux/compat.h
66904index dec7e2d..45db13f 100644
66905--- a/include/linux/compat.h
66906+++ b/include/linux/compat.h
66907@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
66908 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
66909 int version, void __user *uptr);
66910 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
66911- void __user *uptr);
66912+ void __user *uptr) __intentional_overflow(0);
66913 #else
66914 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
66915 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
66916 compat_ssize_t msgsz, int msgflg);
66917 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
66918 compat_ssize_t msgsz, long msgtyp, int msgflg);
66919-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
66920+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
66921 #endif
66922 long compat_sys_msgctl(int first, int second, void __user *uptr);
66923 long compat_sys_shmctl(int first, int second, void __user *uptr);
66924@@ -414,7 +414,7 @@ extern int compat_ptrace_request(struct task_struct *child,
66925 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
66926 compat_ulong_t addr, compat_ulong_t data);
66927 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
66928- compat_long_t addr, compat_long_t data);
66929+ compat_ulong_t addr, compat_ulong_t data);
66930
66931 /*
66932 * epoll (fs/eventpoll.c) compat bits follow ...
66933diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66934index 662fd1b..e801992 100644
66935--- a/include/linux/compiler-gcc4.h
66936+++ b/include/linux/compiler-gcc4.h
66937@@ -34,6 +34,21 @@
66938 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66939
66940 #if __GNUC_MINOR__ >= 5
66941+
66942+#ifdef CONSTIFY_PLUGIN
66943+#define __no_const __attribute__((no_const))
66944+#define __do_const __attribute__((do_const))
66945+#endif
66946+
66947+#ifdef SIZE_OVERFLOW_PLUGIN
66948+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66949+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66950+#endif
66951+
66952+#ifdef LATENT_ENTROPY_PLUGIN
66953+#define __latent_entropy __attribute__((latent_entropy))
66954+#endif
66955+
66956 /*
66957 * Mark a position in code as unreachable. This can be used to
66958 * suppress control flow warnings after asm blocks that transfer
66959@@ -49,6 +64,11 @@
66960 #define __noclone __attribute__((__noclone__))
66961
66962 #endif
66963+
66964+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
66965+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
66966+#define __bos0(ptr) __bos((ptr), 0)
66967+#define __bos1(ptr) __bos((ptr), 1)
66968 #endif
66969
66970 #if __GNUC_MINOR__ >= 6
66971diff --git a/include/linux/compiler.h b/include/linux/compiler.h
66972index dd852b7..72924c0 100644
66973--- a/include/linux/compiler.h
66974+++ b/include/linux/compiler.h
66975@@ -5,11 +5,14 @@
66976
66977 #ifdef __CHECKER__
66978 # define __user __attribute__((noderef, address_space(1)))
66979+# define __force_user __force __user
66980 # define __kernel __attribute__((address_space(0)))
66981+# define __force_kernel __force __kernel
66982 # define __safe __attribute__((safe))
66983 # define __force __attribute__((force))
66984 # define __nocast __attribute__((nocast))
66985 # define __iomem __attribute__((noderef, address_space(2)))
66986+# define __force_iomem __force __iomem
66987 # define __must_hold(x) __attribute__((context(x,1,1)))
66988 # define __acquires(x) __attribute__((context(x,0,1)))
66989 # define __releases(x) __attribute__((context(x,1,0)))
66990@@ -17,20 +20,48 @@
66991 # define __release(x) __context__(x,-1)
66992 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
66993 # define __percpu __attribute__((noderef, address_space(3)))
66994+# define __force_percpu __force __percpu
66995 #ifdef CONFIG_SPARSE_RCU_POINTER
66996 # define __rcu __attribute__((noderef, address_space(4)))
66997+# define __force_rcu __force __rcu
66998 #else
66999 # define __rcu
67000+# define __force_rcu
67001 #endif
67002 extern void __chk_user_ptr(const volatile void __user *);
67003 extern void __chk_io_ptr(const volatile void __iomem *);
67004+#elif defined(CHECKER_PLUGIN)
67005+//# define __user
67006+//# define __force_user
67007+//# define __kernel
67008+//# define __force_kernel
67009+# define __safe
67010+# define __force
67011+# define __nocast
67012+# define __iomem
67013+# define __force_iomem
67014+# define __chk_user_ptr(x) (void)0
67015+# define __chk_io_ptr(x) (void)0
67016+# define __builtin_warning(x, y...) (1)
67017+# define __acquires(x)
67018+# define __releases(x)
67019+# define __acquire(x) (void)0
67020+# define __release(x) (void)0
67021+# define __cond_lock(x,c) (c)
67022+# define __percpu
67023+# define __force_percpu
67024+# define __rcu
67025+# define __force_rcu
67026 #else
67027 # define __user
67028+# define __force_user
67029 # define __kernel
67030+# define __force_kernel
67031 # define __safe
67032 # define __force
67033 # define __nocast
67034 # define __iomem
67035+# define __force_iomem
67036 # define __chk_user_ptr(x) (void)0
67037 # define __chk_io_ptr(x) (void)0
67038 # define __builtin_warning(x, y...) (1)
67039@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
67040 # define __release(x) (void)0
67041 # define __cond_lock(x,c) (c)
67042 # define __percpu
67043+# define __force_percpu
67044 # define __rcu
67045+# define __force_rcu
67046 #endif
67047
67048 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
67049@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67050 # define __attribute_const__ /* unimplemented */
67051 #endif
67052
67053+#ifndef __no_const
67054+# define __no_const
67055+#endif
67056+
67057+#ifndef __do_const
67058+# define __do_const
67059+#endif
67060+
67061+#ifndef __size_overflow
67062+# define __size_overflow(...)
67063+#endif
67064+
67065+#ifndef __intentional_overflow
67066+# define __intentional_overflow(...)
67067+#endif
67068+
67069+#ifndef __latent_entropy
67070+# define __latent_entropy
67071+#endif
67072+
67073 /*
67074 * Tell gcc if a function is cold. The compiler will assume any path
67075 * directly leading to the call is unlikely.
67076@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67077 #define __cold
67078 #endif
67079
67080+#ifndef __alloc_size
67081+#define __alloc_size(...)
67082+#endif
67083+
67084+#ifndef __bos
67085+#define __bos(ptr, arg)
67086+#endif
67087+
67088+#ifndef __bos0
67089+#define __bos0(ptr)
67090+#endif
67091+
67092+#ifndef __bos1
67093+#define __bos1(ptr)
67094+#endif
67095+
67096 /* Simple shorthand for a section definition */
67097 #ifndef __section
67098 # define __section(S) __attribute__ ((__section__(#S)))
67099@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67100 * use is to mediate communication between process-level code and irq/NMI
67101 * handlers, all running on the same CPU.
67102 */
67103-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
67104+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
67105+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
67106
67107 #endif /* __LINUX_COMPILER_H */
67108diff --git a/include/linux/completion.h b/include/linux/completion.h
67109index 51494e6..0fd1b61 100644
67110--- a/include/linux/completion.h
67111+++ b/include/linux/completion.h
67112@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
67113
67114 extern void wait_for_completion(struct completion *);
67115 extern int wait_for_completion_interruptible(struct completion *x);
67116-extern int wait_for_completion_killable(struct completion *x);
67117+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
67118 extern unsigned long wait_for_completion_timeout(struct completion *x,
67119 unsigned long timeout);
67120 extern long wait_for_completion_interruptible_timeout(
67121- struct completion *x, unsigned long timeout);
67122+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67123 extern long wait_for_completion_killable_timeout(
67124- struct completion *x, unsigned long timeout);
67125+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67126 extern bool try_wait_for_completion(struct completion *x);
67127 extern bool completion_done(struct completion *x);
67128
67129diff --git a/include/linux/configfs.h b/include/linux/configfs.h
67130index 34025df..d94bbbc 100644
67131--- a/include/linux/configfs.h
67132+++ b/include/linux/configfs.h
67133@@ -125,7 +125,7 @@ struct configfs_attribute {
67134 const char *ca_name;
67135 struct module *ca_owner;
67136 umode_t ca_mode;
67137-};
67138+} __do_const;
67139
67140 /*
67141 * Users often need to create attribute structures for their configurable
67142diff --git a/include/linux/cpu.h b/include/linux/cpu.h
67143index ce7a074..01ab8ac 100644
67144--- a/include/linux/cpu.h
67145+++ b/include/linux/cpu.h
67146@@ -115,7 +115,7 @@ enum {
67147 /* Need to know about CPUs going up/down? */
67148 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
67149 #define cpu_notifier(fn, pri) { \
67150- static struct notifier_block fn##_nb __cpuinitdata = \
67151+ static struct notifier_block fn##_nb = \
67152 { .notifier_call = fn, .priority = pri }; \
67153 register_cpu_notifier(&fn##_nb); \
67154 }
67155diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
67156index a55b88e..fba90c5 100644
67157--- a/include/linux/cpufreq.h
67158+++ b/include/linux/cpufreq.h
67159@@ -240,7 +240,7 @@ struct cpufreq_driver {
67160 int (*suspend) (struct cpufreq_policy *policy);
67161 int (*resume) (struct cpufreq_policy *policy);
67162 struct freq_attr **attr;
67163-};
67164+} __do_const;
67165
67166 /* flags */
67167
67168@@ -299,6 +299,7 @@ struct global_attr {
67169 ssize_t (*store)(struct kobject *a, struct attribute *b,
67170 const char *c, size_t count);
67171 };
67172+typedef struct global_attr __no_const global_attr_no_const;
67173
67174 #define define_one_global_ro(_name) \
67175 static struct global_attr _name = \
67176diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
67177index 24cd1037..20a63aae 100644
67178--- a/include/linux/cpuidle.h
67179+++ b/include/linux/cpuidle.h
67180@@ -54,7 +54,8 @@ struct cpuidle_state {
67181 int index);
67182
67183 int (*enter_dead) (struct cpuidle_device *dev, int index);
67184-};
67185+} __do_const;
67186+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
67187
67188 /* Idle State Flags */
67189 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
67190@@ -216,7 +217,7 @@ struct cpuidle_governor {
67191 void (*reflect) (struct cpuidle_device *dev, int index);
67192
67193 struct module *owner;
67194-};
67195+} __do_const;
67196
67197 #ifdef CONFIG_CPU_IDLE
67198
67199diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
67200index 0325602..5e9feff 100644
67201--- a/include/linux/cpumask.h
67202+++ b/include/linux/cpumask.h
67203@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67204 }
67205
67206 /* Valid inputs for n are -1 and 0. */
67207-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67208+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67209 {
67210 return n+1;
67211 }
67212
67213-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67214+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67215 {
67216 return n+1;
67217 }
67218
67219-static inline unsigned int cpumask_next_and(int n,
67220+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
67221 const struct cpumask *srcp,
67222 const struct cpumask *andp)
67223 {
67224@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67225 *
67226 * Returns >= nr_cpu_ids if no further cpus set.
67227 */
67228-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67229+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67230 {
67231 /* -1 is a legal arg here. */
67232 if (n != -1)
67233@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67234 *
67235 * Returns >= nr_cpu_ids if no further cpus unset.
67236 */
67237-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67238+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67239 {
67240 /* -1 is a legal arg here. */
67241 if (n != -1)
67242@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67243 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
67244 }
67245
67246-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
67247+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
67248 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
67249
67250 /**
67251diff --git a/include/linux/cred.h b/include/linux/cred.h
67252index 04421e8..6bce4ef 100644
67253--- a/include/linux/cred.h
67254+++ b/include/linux/cred.h
67255@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
67256 static inline void validate_process_creds(void)
67257 {
67258 }
67259+static inline void validate_task_creds(struct task_struct *task)
67260+{
67261+}
67262 #endif
67263
67264 /**
67265diff --git a/include/linux/crypto.h b/include/linux/crypto.h
67266index b92eadf..b4ecdc1 100644
67267--- a/include/linux/crypto.h
67268+++ b/include/linux/crypto.h
67269@@ -373,7 +373,7 @@ struct cipher_tfm {
67270 const u8 *key, unsigned int keylen);
67271 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67272 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67273-};
67274+} __no_const;
67275
67276 struct hash_tfm {
67277 int (*init)(struct hash_desc *desc);
67278@@ -394,13 +394,13 @@ struct compress_tfm {
67279 int (*cot_decompress)(struct crypto_tfm *tfm,
67280 const u8 *src, unsigned int slen,
67281 u8 *dst, unsigned int *dlen);
67282-};
67283+} __no_const;
67284
67285 struct rng_tfm {
67286 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
67287 unsigned int dlen);
67288 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
67289-};
67290+} __no_const;
67291
67292 #define crt_ablkcipher crt_u.ablkcipher
67293 #define crt_aead crt_u.aead
67294diff --git a/include/linux/ctype.h b/include/linux/ctype.h
67295index 8acfe31..6ffccd63 100644
67296--- a/include/linux/ctype.h
67297+++ b/include/linux/ctype.h
67298@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
67299 * Fast implementation of tolower() for internal usage. Do not use in your
67300 * code.
67301 */
67302-static inline char _tolower(const char c)
67303+static inline unsigned char _tolower(const unsigned char c)
67304 {
67305 return c | 0x20;
67306 }
67307diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
67308index 7925bf0..d5143d2 100644
67309--- a/include/linux/decompress/mm.h
67310+++ b/include/linux/decompress/mm.h
67311@@ -77,7 +77,7 @@ static void free(void *where)
67312 * warnings when not needed (indeed large_malloc / large_free are not
67313 * needed by inflate */
67314
67315-#define malloc(a) kmalloc(a, GFP_KERNEL)
67316+#define malloc(a) kmalloc((a), GFP_KERNEL)
67317 #define free(a) kfree(a)
67318
67319 #define large_malloc(a) vmalloc(a)
67320diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
67321index e83ef39..33e0eb3 100644
67322--- a/include/linux/devfreq.h
67323+++ b/include/linux/devfreq.h
67324@@ -114,7 +114,7 @@ struct devfreq_governor {
67325 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
67326 int (*event_handler)(struct devfreq *devfreq,
67327 unsigned int event, void *data);
67328-};
67329+} __do_const;
67330
67331 /**
67332 * struct devfreq - Device devfreq structure
67333diff --git a/include/linux/device.h b/include/linux/device.h
67334index 43dcda9..7a1fb65 100644
67335--- a/include/linux/device.h
67336+++ b/include/linux/device.h
67337@@ -294,7 +294,7 @@ struct subsys_interface {
67338 struct list_head node;
67339 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
67340 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
67341-};
67342+} __do_const;
67343
67344 int subsys_interface_register(struct subsys_interface *sif);
67345 void subsys_interface_unregister(struct subsys_interface *sif);
67346@@ -474,7 +474,7 @@ struct device_type {
67347 void (*release)(struct device *dev);
67348
67349 const struct dev_pm_ops *pm;
67350-};
67351+} __do_const;
67352
67353 /* interface for exporting device attributes */
67354 struct device_attribute {
67355@@ -484,11 +484,12 @@ struct device_attribute {
67356 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
67357 const char *buf, size_t count);
67358 };
67359+typedef struct device_attribute __no_const device_attribute_no_const;
67360
67361 struct dev_ext_attribute {
67362 struct device_attribute attr;
67363 void *var;
67364-};
67365+} __do_const;
67366
67367 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
67368 char *buf);
67369diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
67370index 94af418..b1ca7a2 100644
67371--- a/include/linux/dma-mapping.h
67372+++ b/include/linux/dma-mapping.h
67373@@ -54,7 +54,7 @@ struct dma_map_ops {
67374 u64 (*get_required_mask)(struct device *dev);
67375 #endif
67376 int is_phys;
67377-};
67378+} __do_const;
67379
67380 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
67381
67382diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
67383index d3201e4..8281e63 100644
67384--- a/include/linux/dmaengine.h
67385+++ b/include/linux/dmaengine.h
67386@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
67387 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
67388 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
67389
67390-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67391+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67392 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
67393-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67394+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67395 struct dma_pinned_list *pinned_list, struct page *page,
67396 unsigned int offset, size_t len);
67397
67398diff --git a/include/linux/efi.h b/include/linux/efi.h
67399index 7a9498a..155713d 100644
67400--- a/include/linux/efi.h
67401+++ b/include/linux/efi.h
67402@@ -733,6 +733,7 @@ struct efivar_operations {
67403 efi_set_variable_t *set_variable;
67404 efi_query_variable_info_t *query_variable_info;
67405 };
67406+typedef struct efivar_operations __no_const efivar_operations_no_const;
67407
67408 struct efivars {
67409 /*
67410diff --git a/include/linux/elf.h b/include/linux/elf.h
67411index 8c9048e..16a4665 100644
67412--- a/include/linux/elf.h
67413+++ b/include/linux/elf.h
67414@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
67415 #define elf_note elf32_note
67416 #define elf_addr_t Elf32_Off
67417 #define Elf_Half Elf32_Half
67418+#define elf_dyn Elf32_Dyn
67419
67420 #else
67421
67422@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
67423 #define elf_note elf64_note
67424 #define elf_addr_t Elf64_Off
67425 #define Elf_Half Elf64_Half
67426+#define elf_dyn Elf64_Dyn
67427
67428 #endif
67429
67430diff --git a/include/linux/err.h b/include/linux/err.h
67431index f2edce2..cc2082c 100644
67432--- a/include/linux/err.h
67433+++ b/include/linux/err.h
67434@@ -19,12 +19,12 @@
67435
67436 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
67437
67438-static inline void * __must_check ERR_PTR(long error)
67439+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
67440 {
67441 return (void *) error;
67442 }
67443
67444-static inline long __must_check PTR_ERR(const void *ptr)
67445+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
67446 {
67447 return (long) ptr;
67448 }
67449diff --git a/include/linux/extcon.h b/include/linux/extcon.h
67450index fcb51c8..bdafcf6 100644
67451--- a/include/linux/extcon.h
67452+++ b/include/linux/extcon.h
67453@@ -134,7 +134,7 @@ struct extcon_dev {
67454 /* /sys/class/extcon/.../mutually_exclusive/... */
67455 struct attribute_group attr_g_muex;
67456 struct attribute **attrs_muex;
67457- struct device_attribute *d_attrs_muex;
67458+ device_attribute_no_const *d_attrs_muex;
67459 };
67460
67461 /**
67462diff --git a/include/linux/fb.h b/include/linux/fb.h
67463index c7a9571..02eeffe 100644
67464--- a/include/linux/fb.h
67465+++ b/include/linux/fb.h
67466@@ -302,7 +302,7 @@ struct fb_ops {
67467 /* called at KDB enter and leave time to prepare the console */
67468 int (*fb_debug_enter)(struct fb_info *info);
67469 int (*fb_debug_leave)(struct fb_info *info);
67470-};
67471+} __do_const;
67472
67473 #ifdef CONFIG_FB_TILEBLITTING
67474 #define FB_TILE_CURSOR_NONE 0
67475diff --git a/include/linux/filter.h b/include/linux/filter.h
67476index c45eabc..baa0be5 100644
67477--- a/include/linux/filter.h
67478+++ b/include/linux/filter.h
67479@@ -20,6 +20,7 @@ struct compat_sock_fprog {
67480
67481 struct sk_buff;
67482 struct sock;
67483+struct bpf_jit_work;
67484
67485 struct sk_filter
67486 {
67487@@ -27,6 +28,9 @@ struct sk_filter
67488 unsigned int len; /* Number of filter blocks */
67489 unsigned int (*bpf_func)(const struct sk_buff *skb,
67490 const struct sock_filter *filter);
67491+#ifdef CONFIG_BPF_JIT
67492+ struct bpf_jit_work *work;
67493+#endif
67494 struct rcu_head rcu;
67495 struct sock_filter insns[0];
67496 };
67497diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
67498index 3044254..9767f41 100644
67499--- a/include/linux/frontswap.h
67500+++ b/include/linux/frontswap.h
67501@@ -11,7 +11,7 @@ struct frontswap_ops {
67502 int (*load)(unsigned, pgoff_t, struct page *);
67503 void (*invalidate_page)(unsigned, pgoff_t);
67504 void (*invalidate_area)(unsigned);
67505-};
67506+} __no_const;
67507
67508 extern bool frontswap_enabled;
67509 extern struct frontswap_ops
67510diff --git a/include/linux/fs.h b/include/linux/fs.h
67511index 7617ee0..b575199 100644
67512--- a/include/linux/fs.h
67513+++ b/include/linux/fs.h
67514@@ -1541,7 +1541,8 @@ struct file_operations {
67515 long (*fallocate)(struct file *file, int mode, loff_t offset,
67516 loff_t len);
67517 int (*show_fdinfo)(struct seq_file *m, struct file *f);
67518-};
67519+} __do_const;
67520+typedef struct file_operations __no_const file_operations_no_const;
67521
67522 struct inode_operations {
67523 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
67524@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
67525 inode->i_flags |= S_NOSEC;
67526 }
67527
67528+static inline bool is_sidechannel_device(const struct inode *inode)
67529+{
67530+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
67531+ umode_t mode = inode->i_mode;
67532+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
67533+#else
67534+ return false;
67535+#endif
67536+}
67537+
67538 #endif /* _LINUX_FS_H */
67539diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
67540index d0ae3a8..0244b34 100644
67541--- a/include/linux/fs_struct.h
67542+++ b/include/linux/fs_struct.h
67543@@ -6,7 +6,7 @@
67544 #include <linux/seqlock.h>
67545
67546 struct fs_struct {
67547- int users;
67548+ atomic_t users;
67549 spinlock_t lock;
67550 seqcount_t seq;
67551 int umask;
67552diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
67553index 5dfa0aa..6acf322 100644
67554--- a/include/linux/fscache-cache.h
67555+++ b/include/linux/fscache-cache.h
67556@@ -112,7 +112,7 @@ struct fscache_operation {
67557 fscache_operation_release_t release;
67558 };
67559
67560-extern atomic_t fscache_op_debug_id;
67561+extern atomic_unchecked_t fscache_op_debug_id;
67562 extern void fscache_op_work_func(struct work_struct *work);
67563
67564 extern void fscache_enqueue_operation(struct fscache_operation *);
67565@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
67566 INIT_WORK(&op->work, fscache_op_work_func);
67567 atomic_set(&op->usage, 1);
67568 op->state = FSCACHE_OP_ST_INITIALISED;
67569- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
67570+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
67571 op->processor = processor;
67572 op->release = release;
67573 INIT_LIST_HEAD(&op->pend_link);
67574diff --git a/include/linux/fscache.h b/include/linux/fscache.h
67575index 7a08623..4c07b0f 100644
67576--- a/include/linux/fscache.h
67577+++ b/include/linux/fscache.h
67578@@ -152,7 +152,7 @@ struct fscache_cookie_def {
67579 * - this is mandatory for any object that may have data
67580 */
67581 void (*now_uncached)(void *cookie_netfs_data);
67582-};
67583+} __do_const;
67584
67585 /*
67586 * fscache cached network filesystem type
67587diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
67588index 0fbfb46..508eb0d 100644
67589--- a/include/linux/fsnotify.h
67590+++ b/include/linux/fsnotify.h
67591@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
67592 struct inode *inode = path->dentry->d_inode;
67593 __u32 mask = FS_ACCESS;
67594
67595+ if (is_sidechannel_device(inode))
67596+ return;
67597+
67598 if (S_ISDIR(inode->i_mode))
67599 mask |= FS_ISDIR;
67600
67601@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
67602 struct inode *inode = path->dentry->d_inode;
67603 __u32 mask = FS_MODIFY;
67604
67605+ if (is_sidechannel_device(inode))
67606+ return;
67607+
67608 if (S_ISDIR(inode->i_mode))
67609 mask |= FS_ISDIR;
67610
67611@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
67612 */
67613 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
67614 {
67615- return kstrdup(name, GFP_KERNEL);
67616+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
67617 }
67618
67619 /*
67620diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
67621index a3d4895..ddd2a50 100644
67622--- a/include/linux/ftrace_event.h
67623+++ b/include/linux/ftrace_event.h
67624@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
67625 extern int trace_add_event_call(struct ftrace_event_call *call);
67626 extern void trace_remove_event_call(struct ftrace_event_call *call);
67627
67628-#define is_signed_type(type) (((type)(-1)) < 0)
67629+#define is_signed_type(type) (((type)(-1)) < (type)1)
67630
67631 int trace_set_clr_event(const char *system, const char *event, int set);
67632
67633diff --git a/include/linux/genhd.h b/include/linux/genhd.h
67634index 79b8bba..86b539e 100644
67635--- a/include/linux/genhd.h
67636+++ b/include/linux/genhd.h
67637@@ -194,7 +194,7 @@ struct gendisk {
67638 struct kobject *slave_dir;
67639
67640 struct timer_rand_state *random;
67641- atomic_t sync_io; /* RAID */
67642+ atomic_unchecked_t sync_io; /* RAID */
67643 struct disk_events *ev;
67644 #ifdef CONFIG_BLK_DEV_INTEGRITY
67645 struct blk_integrity *integrity;
67646diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
67647index 023bc34..b02b46a 100644
67648--- a/include/linux/genl_magic_func.h
67649+++ b/include/linux/genl_magic_func.h
67650@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
67651 },
67652
67653 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
67654-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
67655+static struct genl_ops ZZZ_genl_ops[] = {
67656 #include GENL_MAGIC_INCLUDE_FILE
67657 };
67658
67659diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67660index 0f615eb..5c3832f 100644
67661--- a/include/linux/gfp.h
67662+++ b/include/linux/gfp.h
67663@@ -35,6 +35,13 @@ struct vm_area_struct;
67664 #define ___GFP_NO_KSWAPD 0x400000u
67665 #define ___GFP_OTHER_NODE 0x800000u
67666 #define ___GFP_WRITE 0x1000000u
67667+
67668+#ifdef CONFIG_PAX_USERCOPY_SLABS
67669+#define ___GFP_USERCOPY 0x2000000u
67670+#else
67671+#define ___GFP_USERCOPY 0
67672+#endif
67673+
67674 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67675
67676 /*
67677@@ -92,6 +99,7 @@ struct vm_area_struct;
67678 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67679 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67680 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67681+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67682
67683 /*
67684 * This may seem redundant, but it's a way of annotating false positives vs.
67685@@ -99,7 +107,7 @@ struct vm_area_struct;
67686 */
67687 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67688
67689-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67690+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67691 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67692
67693 /* This equals 0, but use constants in case they ever change */
67694@@ -153,6 +161,8 @@ struct vm_area_struct;
67695 /* 4GB DMA on some platforms */
67696 #define GFP_DMA32 __GFP_DMA32
67697
67698+#define GFP_USERCOPY __GFP_USERCOPY
67699+
67700 /* Convert GFP flags to their corresponding migrate type */
67701 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67702 {
67703diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67704new file mode 100644
67705index 0000000..ebe6d72
67706--- /dev/null
67707+++ b/include/linux/gracl.h
67708@@ -0,0 +1,319 @@
67709+#ifndef GR_ACL_H
67710+#define GR_ACL_H
67711+
67712+#include <linux/grdefs.h>
67713+#include <linux/resource.h>
67714+#include <linux/capability.h>
67715+#include <linux/dcache.h>
67716+#include <asm/resource.h>
67717+
67718+/* Major status information */
67719+
67720+#define GR_VERSION "grsecurity 2.9.1"
67721+#define GRSECURITY_VERSION 0x2901
67722+
67723+enum {
67724+ GR_SHUTDOWN = 0,
67725+ GR_ENABLE = 1,
67726+ GR_SPROLE = 2,
67727+ GR_RELOAD = 3,
67728+ GR_SEGVMOD = 4,
67729+ GR_STATUS = 5,
67730+ GR_UNSPROLE = 6,
67731+ GR_PASSSET = 7,
67732+ GR_SPROLEPAM = 8,
67733+};
67734+
67735+/* Password setup definitions
67736+ * kernel/grhash.c */
67737+enum {
67738+ GR_PW_LEN = 128,
67739+ GR_SALT_LEN = 16,
67740+ GR_SHA_LEN = 32,
67741+};
67742+
67743+enum {
67744+ GR_SPROLE_LEN = 64,
67745+};
67746+
67747+enum {
67748+ GR_NO_GLOB = 0,
67749+ GR_REG_GLOB,
67750+ GR_CREATE_GLOB
67751+};
67752+
67753+#define GR_NLIMITS 32
67754+
67755+/* Begin Data Structures */
67756+
67757+struct sprole_pw {
67758+ unsigned char *rolename;
67759+ unsigned char salt[GR_SALT_LEN];
67760+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67761+};
67762+
67763+struct name_entry {
67764+ __u32 key;
67765+ ino_t inode;
67766+ dev_t device;
67767+ char *name;
67768+ __u16 len;
67769+ __u8 deleted;
67770+ struct name_entry *prev;
67771+ struct name_entry *next;
67772+};
67773+
67774+struct inodev_entry {
67775+ struct name_entry *nentry;
67776+ struct inodev_entry *prev;
67777+ struct inodev_entry *next;
67778+};
67779+
67780+struct acl_role_db {
67781+ struct acl_role_label **r_hash;
67782+ __u32 r_size;
67783+};
67784+
67785+struct inodev_db {
67786+ struct inodev_entry **i_hash;
67787+ __u32 i_size;
67788+};
67789+
67790+struct name_db {
67791+ struct name_entry **n_hash;
67792+ __u32 n_size;
67793+};
67794+
67795+struct crash_uid {
67796+ uid_t uid;
67797+ unsigned long expires;
67798+};
67799+
67800+struct gr_hash_struct {
67801+ void **table;
67802+ void **nametable;
67803+ void *first;
67804+ __u32 table_size;
67805+ __u32 used_size;
67806+ int type;
67807+};
67808+
67809+/* Userspace Grsecurity ACL data structures */
67810+
67811+struct acl_subject_label {
67812+ char *filename;
67813+ ino_t inode;
67814+ dev_t device;
67815+ __u32 mode;
67816+ kernel_cap_t cap_mask;
67817+ kernel_cap_t cap_lower;
67818+ kernel_cap_t cap_invert_audit;
67819+
67820+ struct rlimit res[GR_NLIMITS];
67821+ __u32 resmask;
67822+
67823+ __u8 user_trans_type;
67824+ __u8 group_trans_type;
67825+ uid_t *user_transitions;
67826+ gid_t *group_transitions;
67827+ __u16 user_trans_num;
67828+ __u16 group_trans_num;
67829+
67830+ __u32 sock_families[2];
67831+ __u32 ip_proto[8];
67832+ __u32 ip_type;
67833+ struct acl_ip_label **ips;
67834+ __u32 ip_num;
67835+ __u32 inaddr_any_override;
67836+
67837+ __u32 crashes;
67838+ unsigned long expires;
67839+
67840+ struct acl_subject_label *parent_subject;
67841+ struct gr_hash_struct *hash;
67842+ struct acl_subject_label *prev;
67843+ struct acl_subject_label *next;
67844+
67845+ struct acl_object_label **obj_hash;
67846+ __u32 obj_hash_size;
67847+ __u16 pax_flags;
67848+};
67849+
67850+struct role_allowed_ip {
67851+ __u32 addr;
67852+ __u32 netmask;
67853+
67854+ struct role_allowed_ip *prev;
67855+ struct role_allowed_ip *next;
67856+};
67857+
67858+struct role_transition {
67859+ char *rolename;
67860+
67861+ struct role_transition *prev;
67862+ struct role_transition *next;
67863+};
67864+
67865+struct acl_role_label {
67866+ char *rolename;
67867+ uid_t uidgid;
67868+ __u16 roletype;
67869+
67870+ __u16 auth_attempts;
67871+ unsigned long expires;
67872+
67873+ struct acl_subject_label *root_label;
67874+ struct gr_hash_struct *hash;
67875+
67876+ struct acl_role_label *prev;
67877+ struct acl_role_label *next;
67878+
67879+ struct role_transition *transitions;
67880+ struct role_allowed_ip *allowed_ips;
67881+ uid_t *domain_children;
67882+ __u16 domain_child_num;
67883+
67884+ umode_t umask;
67885+
67886+ struct acl_subject_label **subj_hash;
67887+ __u32 subj_hash_size;
67888+};
67889+
67890+struct user_acl_role_db {
67891+ struct acl_role_label **r_table;
67892+ __u32 num_pointers; /* Number of allocations to track */
67893+ __u32 num_roles; /* Number of roles */
67894+ __u32 num_domain_children; /* Number of domain children */
67895+ __u32 num_subjects; /* Number of subjects */
67896+ __u32 num_objects; /* Number of objects */
67897+};
67898+
67899+struct acl_object_label {
67900+ char *filename;
67901+ ino_t inode;
67902+ dev_t device;
67903+ __u32 mode;
67904+
67905+ struct acl_subject_label *nested;
67906+ struct acl_object_label *globbed;
67907+
67908+ /* next two structures not used */
67909+
67910+ struct acl_object_label *prev;
67911+ struct acl_object_label *next;
67912+};
67913+
67914+struct acl_ip_label {
67915+ char *iface;
67916+ __u32 addr;
67917+ __u32 netmask;
67918+ __u16 low, high;
67919+ __u8 mode;
67920+ __u32 type;
67921+ __u32 proto[8];
67922+
67923+ /* next two structures not used */
67924+
67925+ struct acl_ip_label *prev;
67926+ struct acl_ip_label *next;
67927+};
67928+
67929+struct gr_arg {
67930+ struct user_acl_role_db role_db;
67931+ unsigned char pw[GR_PW_LEN];
67932+ unsigned char salt[GR_SALT_LEN];
67933+ unsigned char sum[GR_SHA_LEN];
67934+ unsigned char sp_role[GR_SPROLE_LEN];
67935+ struct sprole_pw *sprole_pws;
67936+ dev_t segv_device;
67937+ ino_t segv_inode;
67938+ uid_t segv_uid;
67939+ __u16 num_sprole_pws;
67940+ __u16 mode;
67941+};
67942+
67943+struct gr_arg_wrapper {
67944+ struct gr_arg *arg;
67945+ __u32 version;
67946+ __u32 size;
67947+};
67948+
67949+struct subject_map {
67950+ struct acl_subject_label *user;
67951+ struct acl_subject_label *kernel;
67952+ struct subject_map *prev;
67953+ struct subject_map *next;
67954+};
67955+
67956+struct acl_subj_map_db {
67957+ struct subject_map **s_hash;
67958+ __u32 s_size;
67959+};
67960+
67961+/* End Data Structures Section */
67962+
67963+/* Hash functions generated by empirical testing by Brad Spengler
67964+ Makes good use of the low bits of the inode. Generally 0-1 times
67965+ in loop for successful match. 0-3 for unsuccessful match.
67966+ Shift/add algorithm with modulus of table size and an XOR*/
67967+
67968+static __inline__ unsigned int
67969+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
67970+{
67971+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
67972+}
67973+
67974+ static __inline__ unsigned int
67975+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
67976+{
67977+ return ((const unsigned long)userp % sz);
67978+}
67979+
67980+static __inline__ unsigned int
67981+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
67982+{
67983+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
67984+}
67985+
67986+static __inline__ unsigned int
67987+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
67988+{
67989+ return full_name_hash((const unsigned char *)name, len) % sz;
67990+}
67991+
67992+#define FOR_EACH_ROLE_START(role) \
67993+ role = role_list; \
67994+ while (role) {
67995+
67996+#define FOR_EACH_ROLE_END(role) \
67997+ role = role->prev; \
67998+ }
67999+
68000+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68001+ subj = NULL; \
68002+ iter = 0; \
68003+ while (iter < role->subj_hash_size) { \
68004+ if (subj == NULL) \
68005+ subj = role->subj_hash[iter]; \
68006+ if (subj == NULL) { \
68007+ iter++; \
68008+ continue; \
68009+ }
68010+
68011+#define FOR_EACH_SUBJECT_END(subj,iter) \
68012+ subj = subj->next; \
68013+ if (subj == NULL) \
68014+ iter++; \
68015+ }
68016+
68017+
68018+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
68019+ subj = role->hash->first; \
68020+ while (subj != NULL) {
68021+
68022+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
68023+ subj = subj->next; \
68024+ }
68025+
68026+#endif
68027+
68028diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
68029new file mode 100644
68030index 0000000..323ecf2
68031--- /dev/null
68032+++ b/include/linux/gralloc.h
68033@@ -0,0 +1,9 @@
68034+#ifndef __GRALLOC_H
68035+#define __GRALLOC_H
68036+
68037+void acl_free_all(void);
68038+int acl_alloc_stack_init(unsigned long size);
68039+void *acl_alloc(unsigned long len);
68040+void *acl_alloc_num(unsigned long num, unsigned long len);
68041+
68042+#endif
68043diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
68044new file mode 100644
68045index 0000000..be66033
68046--- /dev/null
68047+++ b/include/linux/grdefs.h
68048@@ -0,0 +1,140 @@
68049+#ifndef GRDEFS_H
68050+#define GRDEFS_H
68051+
68052+/* Begin grsecurity status declarations */
68053+
68054+enum {
68055+ GR_READY = 0x01,
68056+ GR_STATUS_INIT = 0x00 // disabled state
68057+};
68058+
68059+/* Begin ACL declarations */
68060+
68061+/* Role flags */
68062+
68063+enum {
68064+ GR_ROLE_USER = 0x0001,
68065+ GR_ROLE_GROUP = 0x0002,
68066+ GR_ROLE_DEFAULT = 0x0004,
68067+ GR_ROLE_SPECIAL = 0x0008,
68068+ GR_ROLE_AUTH = 0x0010,
68069+ GR_ROLE_NOPW = 0x0020,
68070+ GR_ROLE_GOD = 0x0040,
68071+ GR_ROLE_LEARN = 0x0080,
68072+ GR_ROLE_TPE = 0x0100,
68073+ GR_ROLE_DOMAIN = 0x0200,
68074+ GR_ROLE_PAM = 0x0400,
68075+ GR_ROLE_PERSIST = 0x0800
68076+};
68077+
68078+/* ACL Subject and Object mode flags */
68079+enum {
68080+ GR_DELETED = 0x80000000
68081+};
68082+
68083+/* ACL Object-only mode flags */
68084+enum {
68085+ GR_READ = 0x00000001,
68086+ GR_APPEND = 0x00000002,
68087+ GR_WRITE = 0x00000004,
68088+ GR_EXEC = 0x00000008,
68089+ GR_FIND = 0x00000010,
68090+ GR_INHERIT = 0x00000020,
68091+ GR_SETID = 0x00000040,
68092+ GR_CREATE = 0x00000080,
68093+ GR_DELETE = 0x00000100,
68094+ GR_LINK = 0x00000200,
68095+ GR_AUDIT_READ = 0x00000400,
68096+ GR_AUDIT_APPEND = 0x00000800,
68097+ GR_AUDIT_WRITE = 0x00001000,
68098+ GR_AUDIT_EXEC = 0x00002000,
68099+ GR_AUDIT_FIND = 0x00004000,
68100+ GR_AUDIT_INHERIT= 0x00008000,
68101+ GR_AUDIT_SETID = 0x00010000,
68102+ GR_AUDIT_CREATE = 0x00020000,
68103+ GR_AUDIT_DELETE = 0x00040000,
68104+ GR_AUDIT_LINK = 0x00080000,
68105+ GR_PTRACERD = 0x00100000,
68106+ GR_NOPTRACE = 0x00200000,
68107+ GR_SUPPRESS = 0x00400000,
68108+ GR_NOLEARN = 0x00800000,
68109+ GR_INIT_TRANSFER= 0x01000000
68110+};
68111+
68112+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
68113+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
68114+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
68115+
68116+/* ACL subject-only mode flags */
68117+enum {
68118+ GR_KILL = 0x00000001,
68119+ GR_VIEW = 0x00000002,
68120+ GR_PROTECTED = 0x00000004,
68121+ GR_LEARN = 0x00000008,
68122+ GR_OVERRIDE = 0x00000010,
68123+ /* just a placeholder, this mode is only used in userspace */
68124+ GR_DUMMY = 0x00000020,
68125+ GR_PROTSHM = 0x00000040,
68126+ GR_KILLPROC = 0x00000080,
68127+ GR_KILLIPPROC = 0x00000100,
68128+ /* just a placeholder, this mode is only used in userspace */
68129+ GR_NOTROJAN = 0x00000200,
68130+ GR_PROTPROCFD = 0x00000400,
68131+ GR_PROCACCT = 0x00000800,
68132+ GR_RELAXPTRACE = 0x00001000,
68133+ //GR_NESTED = 0x00002000,
68134+ GR_INHERITLEARN = 0x00004000,
68135+ GR_PROCFIND = 0x00008000,
68136+ GR_POVERRIDE = 0x00010000,
68137+ GR_KERNELAUTH = 0x00020000,
68138+ GR_ATSECURE = 0x00040000,
68139+ GR_SHMEXEC = 0x00080000
68140+};
68141+
68142+enum {
68143+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
68144+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
68145+ GR_PAX_ENABLE_MPROTECT = 0x0004,
68146+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
68147+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
68148+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
68149+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
68150+ GR_PAX_DISABLE_MPROTECT = 0x0400,
68151+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
68152+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
68153+};
68154+
68155+enum {
68156+ GR_ID_USER = 0x01,
68157+ GR_ID_GROUP = 0x02,
68158+};
68159+
68160+enum {
68161+ GR_ID_ALLOW = 0x01,
68162+ GR_ID_DENY = 0x02,
68163+};
68164+
68165+#define GR_CRASH_RES 31
68166+#define GR_UIDTABLE_MAX 500
68167+
68168+/* begin resource learning section */
68169+enum {
68170+ GR_RLIM_CPU_BUMP = 60,
68171+ GR_RLIM_FSIZE_BUMP = 50000,
68172+ GR_RLIM_DATA_BUMP = 10000,
68173+ GR_RLIM_STACK_BUMP = 1000,
68174+ GR_RLIM_CORE_BUMP = 10000,
68175+ GR_RLIM_RSS_BUMP = 500000,
68176+ GR_RLIM_NPROC_BUMP = 1,
68177+ GR_RLIM_NOFILE_BUMP = 5,
68178+ GR_RLIM_MEMLOCK_BUMP = 50000,
68179+ GR_RLIM_AS_BUMP = 500000,
68180+ GR_RLIM_LOCKS_BUMP = 2,
68181+ GR_RLIM_SIGPENDING_BUMP = 5,
68182+ GR_RLIM_MSGQUEUE_BUMP = 10000,
68183+ GR_RLIM_NICE_BUMP = 1,
68184+ GR_RLIM_RTPRIO_BUMP = 1,
68185+ GR_RLIM_RTTIME_BUMP = 1000000
68186+};
68187+
68188+#endif
68189diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
68190new file mode 100644
68191index 0000000..9bb6662
68192--- /dev/null
68193+++ b/include/linux/grinternal.h
68194@@ -0,0 +1,215 @@
68195+#ifndef __GRINTERNAL_H
68196+#define __GRINTERNAL_H
68197+
68198+#ifdef CONFIG_GRKERNSEC
68199+
68200+#include <linux/fs.h>
68201+#include <linux/mnt_namespace.h>
68202+#include <linux/nsproxy.h>
68203+#include <linux/gracl.h>
68204+#include <linux/grdefs.h>
68205+#include <linux/grmsg.h>
68206+
68207+void gr_add_learn_entry(const char *fmt, ...)
68208+ __attribute__ ((format (printf, 1, 2)));
68209+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
68210+ const struct vfsmount *mnt);
68211+__u32 gr_check_create(const struct dentry *new_dentry,
68212+ const struct dentry *parent,
68213+ const struct vfsmount *mnt, const __u32 mode);
68214+int gr_check_protected_task(const struct task_struct *task);
68215+__u32 to_gr_audit(const __u32 reqmode);
68216+int gr_set_acls(const int type);
68217+int gr_apply_subject_to_task(struct task_struct *task);
68218+int gr_acl_is_enabled(void);
68219+char gr_roletype_to_char(void);
68220+
68221+void gr_handle_alertkill(struct task_struct *task);
68222+char *gr_to_filename(const struct dentry *dentry,
68223+ const struct vfsmount *mnt);
68224+char *gr_to_filename1(const struct dentry *dentry,
68225+ const struct vfsmount *mnt);
68226+char *gr_to_filename2(const struct dentry *dentry,
68227+ const struct vfsmount *mnt);
68228+char *gr_to_filename3(const struct dentry *dentry,
68229+ const struct vfsmount *mnt);
68230+
68231+extern int grsec_enable_ptrace_readexec;
68232+extern int grsec_enable_harden_ptrace;
68233+extern int grsec_enable_link;
68234+extern int grsec_enable_fifo;
68235+extern int grsec_enable_execve;
68236+extern int grsec_enable_shm;
68237+extern int grsec_enable_execlog;
68238+extern int grsec_enable_signal;
68239+extern int grsec_enable_audit_ptrace;
68240+extern int grsec_enable_forkfail;
68241+extern int grsec_enable_time;
68242+extern int grsec_enable_rofs;
68243+extern int grsec_enable_chroot_shmat;
68244+extern int grsec_enable_chroot_mount;
68245+extern int grsec_enable_chroot_double;
68246+extern int grsec_enable_chroot_pivot;
68247+extern int grsec_enable_chroot_chdir;
68248+extern int grsec_enable_chroot_chmod;
68249+extern int grsec_enable_chroot_mknod;
68250+extern int grsec_enable_chroot_fchdir;
68251+extern int grsec_enable_chroot_nice;
68252+extern int grsec_enable_chroot_execlog;
68253+extern int grsec_enable_chroot_caps;
68254+extern int grsec_enable_chroot_sysctl;
68255+extern int grsec_enable_chroot_unix;
68256+extern int grsec_enable_symlinkown;
68257+extern kgid_t grsec_symlinkown_gid;
68258+extern int grsec_enable_tpe;
68259+extern kgid_t grsec_tpe_gid;
68260+extern int grsec_enable_tpe_all;
68261+extern int grsec_enable_tpe_invert;
68262+extern int grsec_enable_socket_all;
68263+extern kgid_t grsec_socket_all_gid;
68264+extern int grsec_enable_socket_client;
68265+extern kgid_t grsec_socket_client_gid;
68266+extern int grsec_enable_socket_server;
68267+extern kgid_t grsec_socket_server_gid;
68268+extern kgid_t grsec_audit_gid;
68269+extern int grsec_enable_group;
68270+extern int grsec_enable_audit_textrel;
68271+extern int grsec_enable_log_rwxmaps;
68272+extern int grsec_enable_mount;
68273+extern int grsec_enable_chdir;
68274+extern int grsec_resource_logging;
68275+extern int grsec_enable_blackhole;
68276+extern int grsec_lastack_retries;
68277+extern int grsec_enable_brute;
68278+extern int grsec_lock;
68279+
68280+extern spinlock_t grsec_alert_lock;
68281+extern unsigned long grsec_alert_wtime;
68282+extern unsigned long grsec_alert_fyet;
68283+
68284+extern spinlock_t grsec_audit_lock;
68285+
68286+extern rwlock_t grsec_exec_file_lock;
68287+
68288+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
68289+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
68290+ (tsk)->exec_file->f_vfsmnt) : "/")
68291+
68292+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
68293+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
68294+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68295+
68296+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
68297+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
68298+ (tsk)->exec_file->f_vfsmnt) : "/")
68299+
68300+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
68301+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
68302+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68303+
68304+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
68305+
68306+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
68307+
68308+#define GR_CHROOT_CAPS {{ \
68309+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
68310+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
68311+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
68312+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
68313+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
68314+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
68315+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
68316+
68317+#define security_learn(normal_msg,args...) \
68318+({ \
68319+ read_lock(&grsec_exec_file_lock); \
68320+ gr_add_learn_entry(normal_msg "\n", ## args); \
68321+ read_unlock(&grsec_exec_file_lock); \
68322+})
68323+
68324+enum {
68325+ GR_DO_AUDIT,
68326+ GR_DONT_AUDIT,
68327+ /* used for non-audit messages that we shouldn't kill the task on */
68328+ GR_DONT_AUDIT_GOOD
68329+};
68330+
68331+enum {
68332+ GR_TTYSNIFF,
68333+ GR_RBAC,
68334+ GR_RBAC_STR,
68335+ GR_STR_RBAC,
68336+ GR_RBAC_MODE2,
68337+ GR_RBAC_MODE3,
68338+ GR_FILENAME,
68339+ GR_SYSCTL_HIDDEN,
68340+ GR_NOARGS,
68341+ GR_ONE_INT,
68342+ GR_ONE_INT_TWO_STR,
68343+ GR_ONE_STR,
68344+ GR_STR_INT,
68345+ GR_TWO_STR_INT,
68346+ GR_TWO_INT,
68347+ GR_TWO_U64,
68348+ GR_THREE_INT,
68349+ GR_FIVE_INT_TWO_STR,
68350+ GR_TWO_STR,
68351+ GR_THREE_STR,
68352+ GR_FOUR_STR,
68353+ GR_STR_FILENAME,
68354+ GR_FILENAME_STR,
68355+ GR_FILENAME_TWO_INT,
68356+ GR_FILENAME_TWO_INT_STR,
68357+ GR_TEXTREL,
68358+ GR_PTRACE,
68359+ GR_RESOURCE,
68360+ GR_CAP,
68361+ GR_SIG,
68362+ GR_SIG2,
68363+ GR_CRASH1,
68364+ GR_CRASH2,
68365+ GR_PSACCT,
68366+ GR_RWXMAP
68367+};
68368+
68369+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
68370+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
68371+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
68372+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
68373+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
68374+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
68375+#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)
68376+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
68377+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
68378+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
68379+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
68380+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
68381+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
68382+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
68383+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
68384+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
68385+#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)
68386+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
68387+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
68388+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
68389+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
68390+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
68391+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
68392+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
68393+#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)
68394+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
68395+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
68396+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
68397+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
68398+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
68399+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
68400+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
68401+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
68402+#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)
68403+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
68404+
68405+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
68406+
68407+#endif
68408+
68409+#endif
68410diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
68411new file mode 100644
68412index 0000000..2bd4c8d
68413--- /dev/null
68414+++ b/include/linux/grmsg.h
68415@@ -0,0 +1,111 @@
68416+#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"
68417+#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"
68418+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
68419+#define GR_STOPMOD_MSG "denied modification of module state by "
68420+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
68421+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
68422+#define GR_IOPERM_MSG "denied use of ioperm() by "
68423+#define GR_IOPL_MSG "denied use of iopl() by "
68424+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
68425+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
68426+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
68427+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
68428+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
68429+#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"
68430+#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"
68431+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
68432+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
68433+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
68434+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
68435+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
68436+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
68437+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
68438+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
68439+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
68440+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
68441+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
68442+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
68443+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
68444+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
68445+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
68446+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
68447+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
68448+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
68449+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
68450+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
68451+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
68452+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
68453+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
68454+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
68455+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
68456+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
68457+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
68458+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
68459+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
68460+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
68461+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
68462+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
68463+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
68464+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
68465+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
68466+#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"
68467+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
68468+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
68469+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
68470+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
68471+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
68472+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
68473+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
68474+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
68475+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
68476+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
68477+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
68478+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
68479+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
68480+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
68481+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
68482+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
68483+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
68484+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
68485+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
68486+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
68487+#define GR_FAILFORK_MSG "failed fork with errno %s by "
68488+#define GR_NICE_CHROOT_MSG "denied priority change by "
68489+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
68490+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
68491+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
68492+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
68493+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
68494+#define GR_TIME_MSG "time set by "
68495+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
68496+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
68497+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
68498+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
68499+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
68500+#define GR_BIND_MSG "denied bind() by "
68501+#define GR_CONNECT_MSG "denied connect() by "
68502+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
68503+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
68504+#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"
68505+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
68506+#define GR_CAP_ACL_MSG "use of %s denied for "
68507+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
68508+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
68509+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
68510+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
68511+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
68512+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
68513+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
68514+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
68515+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
68516+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
68517+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
68518+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
68519+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
68520+#define GR_VM86_MSG "denied use of vm86 by "
68521+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
68522+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
68523+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
68524+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
68525+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
68526+#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 "
68527diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
68528new file mode 100644
68529index 0000000..8da63a4
68530--- /dev/null
68531+++ b/include/linux/grsecurity.h
68532@@ -0,0 +1,242 @@
68533+#ifndef GR_SECURITY_H
68534+#define GR_SECURITY_H
68535+#include <linux/fs.h>
68536+#include <linux/fs_struct.h>
68537+#include <linux/binfmts.h>
68538+#include <linux/gracl.h>
68539+
68540+/* notify of brain-dead configs */
68541+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68542+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
68543+#endif
68544+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
68545+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
68546+#endif
68547+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
68548+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
68549+#endif
68550+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
68551+#error "CONFIG_PAX enabled, but no PaX options are enabled."
68552+#endif
68553+
68554+void gr_handle_brute_attach(unsigned long mm_flags);
68555+void gr_handle_brute_check(void);
68556+void gr_handle_kernel_exploit(void);
68557+int gr_process_user_ban(void);
68558+
68559+char gr_roletype_to_char(void);
68560+
68561+int gr_acl_enable_at_secure(void);
68562+
68563+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
68564+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
68565+
68566+void gr_del_task_from_ip_table(struct task_struct *p);
68567+
68568+int gr_pid_is_chrooted(struct task_struct *p);
68569+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
68570+int gr_handle_chroot_nice(void);
68571+int gr_handle_chroot_sysctl(const int op);
68572+int gr_handle_chroot_setpriority(struct task_struct *p,
68573+ const int niceval);
68574+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
68575+int gr_handle_chroot_chroot(const struct dentry *dentry,
68576+ const struct vfsmount *mnt);
68577+void gr_handle_chroot_chdir(struct path *path);
68578+int gr_handle_chroot_chmod(const struct dentry *dentry,
68579+ const struct vfsmount *mnt, const int mode);
68580+int gr_handle_chroot_mknod(const struct dentry *dentry,
68581+ const struct vfsmount *mnt, const int mode);
68582+int gr_handle_chroot_mount(const struct dentry *dentry,
68583+ const struct vfsmount *mnt,
68584+ const char *dev_name);
68585+int gr_handle_chroot_pivot(void);
68586+int gr_handle_chroot_unix(const pid_t pid);
68587+
68588+int gr_handle_rawio(const struct inode *inode);
68589+
68590+void gr_handle_ioperm(void);
68591+void gr_handle_iopl(void);
68592+
68593+umode_t gr_acl_umask(void);
68594+
68595+int gr_tpe_allow(const struct file *file);
68596+
68597+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
68598+void gr_clear_chroot_entries(struct task_struct *task);
68599+
68600+void gr_log_forkfail(const int retval);
68601+void gr_log_timechange(void);
68602+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
68603+void gr_log_chdir(const struct dentry *dentry,
68604+ const struct vfsmount *mnt);
68605+void gr_log_chroot_exec(const struct dentry *dentry,
68606+ const struct vfsmount *mnt);
68607+void gr_log_remount(const char *devname, const int retval);
68608+void gr_log_unmount(const char *devname, const int retval);
68609+void gr_log_mount(const char *from, const char *to, const int retval);
68610+void gr_log_textrel(struct vm_area_struct *vma);
68611+void gr_log_rwxmmap(struct file *file);
68612+void gr_log_rwxmprotect(struct file *file);
68613+
68614+int gr_handle_follow_link(const struct inode *parent,
68615+ const struct inode *inode,
68616+ const struct dentry *dentry,
68617+ const struct vfsmount *mnt);
68618+int gr_handle_fifo(const struct dentry *dentry,
68619+ const struct vfsmount *mnt,
68620+ const struct dentry *dir, const int flag,
68621+ const int acc_mode);
68622+int gr_handle_hardlink(const struct dentry *dentry,
68623+ const struct vfsmount *mnt,
68624+ struct inode *inode,
68625+ const int mode, const struct filename *to);
68626+
68627+int gr_is_capable(const int cap);
68628+int gr_is_capable_nolog(const int cap);
68629+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68630+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
68631+
68632+void gr_copy_label(struct task_struct *tsk);
68633+void gr_handle_crash(struct task_struct *task, const int sig);
68634+int gr_handle_signal(const struct task_struct *p, const int sig);
68635+int gr_check_crash_uid(const kuid_t uid);
68636+int gr_check_protected_task(const struct task_struct *task);
68637+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
68638+int gr_acl_handle_mmap(const struct file *file,
68639+ const unsigned long prot);
68640+int gr_acl_handle_mprotect(const struct file *file,
68641+ const unsigned long prot);
68642+int gr_check_hidden_task(const struct task_struct *tsk);
68643+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68644+ const struct vfsmount *mnt);
68645+__u32 gr_acl_handle_utime(const struct dentry *dentry,
68646+ const struct vfsmount *mnt);
68647+__u32 gr_acl_handle_access(const struct dentry *dentry,
68648+ const struct vfsmount *mnt, const int fmode);
68649+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68650+ const struct vfsmount *mnt, umode_t *mode);
68651+__u32 gr_acl_handle_chown(const struct dentry *dentry,
68652+ const struct vfsmount *mnt);
68653+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68654+ const struct vfsmount *mnt);
68655+int gr_handle_ptrace(struct task_struct *task, const long request);
68656+int gr_handle_proc_ptrace(struct task_struct *task);
68657+__u32 gr_acl_handle_execve(const struct dentry *dentry,
68658+ const struct vfsmount *mnt);
68659+int gr_check_crash_exec(const struct file *filp);
68660+int gr_acl_is_enabled(void);
68661+void gr_set_kernel_label(struct task_struct *task);
68662+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68663+ const kgid_t gid);
68664+int gr_set_proc_label(const struct dentry *dentry,
68665+ const struct vfsmount *mnt,
68666+ const int unsafe_flags);
68667+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68668+ const struct vfsmount *mnt);
68669+__u32 gr_acl_handle_open(const struct dentry *dentry,
68670+ const struct vfsmount *mnt, int acc_mode);
68671+__u32 gr_acl_handle_creat(const struct dentry *dentry,
68672+ const struct dentry *p_dentry,
68673+ const struct vfsmount *p_mnt,
68674+ int open_flags, int acc_mode, const int imode);
68675+void gr_handle_create(const struct dentry *dentry,
68676+ const struct vfsmount *mnt);
68677+void gr_handle_proc_create(const struct dentry *dentry,
68678+ const struct inode *inode);
68679+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68680+ const struct dentry *parent_dentry,
68681+ const struct vfsmount *parent_mnt,
68682+ const int mode);
68683+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68684+ const struct dentry *parent_dentry,
68685+ const struct vfsmount *parent_mnt);
68686+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68687+ const struct vfsmount *mnt);
68688+void gr_handle_delete(const ino_t ino, const dev_t dev);
68689+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68690+ const struct vfsmount *mnt);
68691+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68692+ const struct dentry *parent_dentry,
68693+ const struct vfsmount *parent_mnt,
68694+ const struct filename *from);
68695+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68696+ const struct dentry *parent_dentry,
68697+ const struct vfsmount *parent_mnt,
68698+ const struct dentry *old_dentry,
68699+ const struct vfsmount *old_mnt, const struct filename *to);
68700+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68701+int gr_acl_handle_rename(struct dentry *new_dentry,
68702+ struct dentry *parent_dentry,
68703+ const struct vfsmount *parent_mnt,
68704+ struct dentry *old_dentry,
68705+ struct inode *old_parent_inode,
68706+ struct vfsmount *old_mnt, const struct filename *newname);
68707+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68708+ struct dentry *old_dentry,
68709+ struct dentry *new_dentry,
68710+ struct vfsmount *mnt, const __u8 replace);
68711+__u32 gr_check_link(const struct dentry *new_dentry,
68712+ const struct dentry *parent_dentry,
68713+ const struct vfsmount *parent_mnt,
68714+ const struct dentry *old_dentry,
68715+ const struct vfsmount *old_mnt);
68716+int gr_acl_handle_filldir(const struct file *file, const char *name,
68717+ const unsigned int namelen, const ino_t ino);
68718+
68719+__u32 gr_acl_handle_unix(const struct dentry *dentry,
68720+ const struct vfsmount *mnt);
68721+void gr_acl_handle_exit(void);
68722+void gr_acl_handle_psacct(struct task_struct *task, const long code);
68723+int gr_acl_handle_procpidmem(const struct task_struct *task);
68724+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68725+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68726+void gr_audit_ptrace(struct task_struct *task);
68727+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68728+void gr_put_exec_file(struct task_struct *task);
68729+
68730+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68731+
68732+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68733+extern void gr_learn_resource(const struct task_struct *task, const int res,
68734+ const unsigned long wanted, const int gt);
68735+#else
68736+static inline void gr_learn_resource(const struct task_struct *task, const int res,
68737+ const unsigned long wanted, const int gt)
68738+{
68739+}
68740+#endif
68741+
68742+#ifdef CONFIG_GRKERNSEC_RESLOG
68743+extern void gr_log_resource(const struct task_struct *task, const int res,
68744+ const unsigned long wanted, const int gt);
68745+#else
68746+static inline void gr_log_resource(const struct task_struct *task, const int res,
68747+ const unsigned long wanted, const int gt)
68748+{
68749+}
68750+#endif
68751+
68752+#ifdef CONFIG_GRKERNSEC
68753+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68754+void gr_handle_vm86(void);
68755+void gr_handle_mem_readwrite(u64 from, u64 to);
68756+
68757+void gr_log_badprocpid(const char *entry);
68758+
68759+extern int grsec_enable_dmesg;
68760+extern int grsec_disable_privio;
68761+
68762+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68763+extern kgid_t grsec_proc_gid;
68764+#endif
68765+
68766+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68767+extern int grsec_enable_chroot_findtask;
68768+#endif
68769+#ifdef CONFIG_GRKERNSEC_SETXID
68770+extern int grsec_enable_setxid;
68771+#endif
68772+#endif
68773+
68774+#endif
68775diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68776new file mode 100644
68777index 0000000..e7ffaaf
68778--- /dev/null
68779+++ b/include/linux/grsock.h
68780@@ -0,0 +1,19 @@
68781+#ifndef __GRSOCK_H
68782+#define __GRSOCK_H
68783+
68784+extern void gr_attach_curr_ip(const struct sock *sk);
68785+extern int gr_handle_sock_all(const int family, const int type,
68786+ const int protocol);
68787+extern int gr_handle_sock_server(const struct sockaddr *sck);
68788+extern int gr_handle_sock_server_other(const struct sock *sck);
68789+extern int gr_handle_sock_client(const struct sockaddr *sck);
68790+extern int gr_search_connect(struct socket * sock,
68791+ struct sockaddr_in * addr);
68792+extern int gr_search_bind(struct socket * sock,
68793+ struct sockaddr_in * addr);
68794+extern int gr_search_listen(struct socket * sock);
68795+extern int gr_search_accept(struct socket * sock);
68796+extern int gr_search_socket(const int domain, const int type,
68797+ const int protocol);
68798+
68799+#endif
68800diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68801index ef788b5..ac41b7b 100644
68802--- a/include/linux/highmem.h
68803+++ b/include/linux/highmem.h
68804@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68805 kunmap_atomic(kaddr);
68806 }
68807
68808+static inline void sanitize_highpage(struct page *page)
68809+{
68810+ void *kaddr;
68811+ unsigned long flags;
68812+
68813+ local_irq_save(flags);
68814+ kaddr = kmap_atomic(page);
68815+ clear_page(kaddr);
68816+ kunmap_atomic(kaddr);
68817+ local_irq_restore(flags);
68818+}
68819+
68820 static inline void zero_user_segments(struct page *page,
68821 unsigned start1, unsigned end1,
68822 unsigned start2, unsigned end2)
68823diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68824index 1c7b89a..7f52502 100644
68825--- a/include/linux/hwmon-sysfs.h
68826+++ b/include/linux/hwmon-sysfs.h
68827@@ -25,7 +25,8 @@
68828 struct sensor_device_attribute{
68829 struct device_attribute dev_attr;
68830 int index;
68831-};
68832+} __do_const;
68833+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68834 #define to_sensor_dev_attr(_dev_attr) \
68835 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68836
68837@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68838 struct device_attribute dev_attr;
68839 u8 index;
68840 u8 nr;
68841-};
68842+} __do_const;
68843 #define to_sensor_dev_attr_2(_dev_attr) \
68844 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68845
68846diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68847index d0c4db7..61b3577 100644
68848--- a/include/linux/i2c.h
68849+++ b/include/linux/i2c.h
68850@@ -369,6 +369,7 @@ struct i2c_algorithm {
68851 /* To determine what the adapter supports */
68852 u32 (*functionality) (struct i2c_adapter *);
68853 };
68854+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68855
68856 /*
68857 * i2c_adapter is the structure used to identify a physical i2c bus along
68858diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68859index d23c3c2..eb63c81 100644
68860--- a/include/linux/i2o.h
68861+++ b/include/linux/i2o.h
68862@@ -565,7 +565,7 @@ struct i2o_controller {
68863 struct i2o_device *exec; /* Executive */
68864 #if BITS_PER_LONG == 64
68865 spinlock_t context_list_lock; /* lock for context_list */
68866- atomic_t context_list_counter; /* needed for unique contexts */
68867+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68868 struct list_head context_list; /* list of context id's
68869 and pointers */
68870 #endif
68871diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68872index aff7ad8..3942bbd 100644
68873--- a/include/linux/if_pppox.h
68874+++ b/include/linux/if_pppox.h
68875@@ -76,7 +76,7 @@ struct pppox_proto {
68876 int (*ioctl)(struct socket *sock, unsigned int cmd,
68877 unsigned long arg);
68878 struct module *owner;
68879-};
68880+} __do_const;
68881
68882 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68883 extern void unregister_pppox_proto(int proto_num);
68884diff --git a/include/linux/init.h b/include/linux/init.h
68885index 10ed4f4..8e8490d 100644
68886--- a/include/linux/init.h
68887+++ b/include/linux/init.h
68888@@ -39,9 +39,36 @@
68889 * Also note, that this data cannot be "const".
68890 */
68891
68892+#ifdef MODULE
68893+#define add_init_latent_entropy
68894+#define add_devinit_latent_entropy
68895+#define add_cpuinit_latent_entropy
68896+#define add_meminit_latent_entropy
68897+#else
68898+#define add_init_latent_entropy __latent_entropy
68899+
68900+#ifdef CONFIG_HOTPLUG
68901+#define add_devinit_latent_entropy
68902+#else
68903+#define add_devinit_latent_entropy __latent_entropy
68904+#endif
68905+
68906+#ifdef CONFIG_HOTPLUG_CPU
68907+#define add_cpuinit_latent_entropy
68908+#else
68909+#define add_cpuinit_latent_entropy __latent_entropy
68910+#endif
68911+
68912+#ifdef CONFIG_MEMORY_HOTPLUG
68913+#define add_meminit_latent_entropy
68914+#else
68915+#define add_meminit_latent_entropy __latent_entropy
68916+#endif
68917+#endif
68918+
68919 /* These are for everybody (although not all archs will actually
68920 discard it in modules) */
68921-#define __init __section(.init.text) __cold notrace
68922+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68923 #define __initdata __section(.init.data)
68924 #define __initconst __constsection(.init.rodata)
68925 #define __exitdata __section(.exit.data)
68926@@ -94,7 +121,7 @@
68927 #define __exit __section(.exit.text) __exitused __cold notrace
68928
68929 /* Used for HOTPLUG_CPU */
68930-#define __cpuinit __section(.cpuinit.text) __cold notrace
68931+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68932 #define __cpuinitdata __section(.cpuinit.data)
68933 #define __cpuinitconst __constsection(.cpuinit.rodata)
68934 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68935@@ -102,7 +129,7 @@
68936 #define __cpuexitconst __constsection(.cpuexit.rodata)
68937
68938 /* Used for MEMORY_HOTPLUG */
68939-#define __meminit __section(.meminit.text) __cold notrace
68940+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68941 #define __meminitdata __section(.meminit.data)
68942 #define __meminitconst __constsection(.meminit.rodata)
68943 #define __memexit __section(.memexit.text) __exitused __cold notrace
68944diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68945index 6d087c5..401cab8 100644
68946--- a/include/linux/init_task.h
68947+++ b/include/linux/init_task.h
68948@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68949
68950 #define INIT_TASK_COMM "swapper"
68951
68952+#ifdef CONFIG_X86
68953+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68954+#else
68955+#define INIT_TASK_THREAD_INFO
68956+#endif
68957+
68958 /*
68959 * INIT_TASK is used to set up the first task table, touch at
68960 * your own risk!. Base=0, limit=0x1fffff (=2MB)
68961@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
68962 RCU_POINTER_INITIALIZER(cred, &init_cred), \
68963 .comm = INIT_TASK_COMM, \
68964 .thread = INIT_THREAD, \
68965+ INIT_TASK_THREAD_INFO \
68966 .fs = &init_fs, \
68967 .files = &init_files, \
68968 .signal = &init_signals, \
68969diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
68970index 5fa5afe..ac55b25 100644
68971--- a/include/linux/interrupt.h
68972+++ b/include/linux/interrupt.h
68973@@ -430,7 +430,7 @@ enum
68974 /* map softirq index to softirq name. update 'softirq_to_name' in
68975 * kernel/softirq.c when adding a new softirq.
68976 */
68977-extern char *softirq_to_name[NR_SOFTIRQS];
68978+extern const char * const softirq_to_name[NR_SOFTIRQS];
68979
68980 /* softirq mask and active fields moved to irq_cpustat_t in
68981 * asm/hardirq.h to get better cache usage. KAO
68982@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
68983
68984 struct softirq_action
68985 {
68986- void (*action)(struct softirq_action *);
68987-};
68988+ void (*action)(void);
68989+} __no_const;
68990
68991 asmlinkage void do_softirq(void);
68992 asmlinkage void __do_softirq(void);
68993-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
68994+extern void open_softirq(int nr, void (*action)(void));
68995 extern void softirq_init(void);
68996 extern void __raise_softirq_irqoff(unsigned int nr);
68997
68998diff --git a/include/linux/iommu.h b/include/linux/iommu.h
68999index f3b99e1..9b73cee 100644
69000--- a/include/linux/iommu.h
69001+++ b/include/linux/iommu.h
69002@@ -101,7 +101,7 @@ struct iommu_ops {
69003 int (*domain_set_attr)(struct iommu_domain *domain,
69004 enum iommu_attr attr, void *data);
69005 unsigned long pgsize_bitmap;
69006-};
69007+} __do_const;
69008
69009 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
69010 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
69011diff --git a/include/linux/irq.h b/include/linux/irq.h
69012index fdf2c4a..5332486 100644
69013--- a/include/linux/irq.h
69014+++ b/include/linux/irq.h
69015@@ -328,7 +328,8 @@ struct irq_chip {
69016 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
69017
69018 unsigned long flags;
69019-};
69020+} __do_const;
69021+typedef struct irq_chip __no_const irq_chip_no_const;
69022
69023 /*
69024 * irq_chip specific flags
69025diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
69026index 6883e19..06992b1 100644
69027--- a/include/linux/kallsyms.h
69028+++ b/include/linux/kallsyms.h
69029@@ -15,7 +15,8 @@
69030
69031 struct module;
69032
69033-#ifdef CONFIG_KALLSYMS
69034+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
69035+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69036 /* Lookup the address for a symbol. Returns 0 if not found. */
69037 unsigned long kallsyms_lookup_name(const char *name);
69038
69039@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
69040 /* Stupid that this does nothing, but I didn't create this mess. */
69041 #define __print_symbol(fmt, addr)
69042 #endif /*CONFIG_KALLSYMS*/
69043+#else /* when included by kallsyms.c, vsnprintf.c, or
69044+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
69045+extern void __print_symbol(const char *fmt, unsigned long address);
69046+extern int sprint_backtrace(char *buffer, unsigned long address);
69047+extern int sprint_symbol(char *buffer, unsigned long address);
69048+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
69049+const char *kallsyms_lookup(unsigned long addr,
69050+ unsigned long *symbolsize,
69051+ unsigned long *offset,
69052+ char **modname, char *namebuf);
69053+#endif
69054
69055 /* This macro allows us to keep printk typechecking */
69056 static __printf(1, 2)
69057diff --git a/include/linux/key-type.h b/include/linux/key-type.h
69058index 518a53a..5e28358 100644
69059--- a/include/linux/key-type.h
69060+++ b/include/linux/key-type.h
69061@@ -125,7 +125,7 @@ struct key_type {
69062 /* internal fields */
69063 struct list_head link; /* link in types list */
69064 struct lock_class_key lock_class; /* key->sem lock class */
69065-};
69066+} __do_const;
69067
69068 extern struct key_type key_type_keyring;
69069
69070diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
69071index 4dff0c6..1ca9b72 100644
69072--- a/include/linux/kgdb.h
69073+++ b/include/linux/kgdb.h
69074@@ -53,7 +53,7 @@ extern int kgdb_connected;
69075 extern int kgdb_io_module_registered;
69076
69077 extern atomic_t kgdb_setting_breakpoint;
69078-extern atomic_t kgdb_cpu_doing_single_step;
69079+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
69080
69081 extern struct task_struct *kgdb_usethread;
69082 extern struct task_struct *kgdb_contthread;
69083@@ -255,7 +255,7 @@ struct kgdb_arch {
69084 void (*correct_hw_break)(void);
69085
69086 void (*enable_nmi)(bool on);
69087-};
69088+} __do_const;
69089
69090 /**
69091 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
69092@@ -280,7 +280,7 @@ struct kgdb_io {
69093 void (*pre_exception) (void);
69094 void (*post_exception) (void);
69095 int is_console;
69096-};
69097+} __do_const;
69098
69099 extern struct kgdb_arch arch_kgdb_ops;
69100
69101diff --git a/include/linux/kmod.h b/include/linux/kmod.h
69102index 5398d58..5883a34 100644
69103--- a/include/linux/kmod.h
69104+++ b/include/linux/kmod.h
69105@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
69106 * usually useless though. */
69107 extern __printf(2, 3)
69108 int __request_module(bool wait, const char *name, ...);
69109+extern __printf(3, 4)
69110+int ___request_module(bool wait, char *param_name, const char *name, ...);
69111 #define request_module(mod...) __request_module(true, mod)
69112 #define request_module_nowait(mod...) __request_module(false, mod)
69113 #define try_then_request_module(x, mod...) \
69114diff --git a/include/linux/kobject.h b/include/linux/kobject.h
69115index 939b112..ed6ed51 100644
69116--- a/include/linux/kobject.h
69117+++ b/include/linux/kobject.h
69118@@ -111,7 +111,7 @@ struct kobj_type {
69119 struct attribute **default_attrs;
69120 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
69121 const void *(*namespace)(struct kobject *kobj);
69122-};
69123+} __do_const;
69124
69125 struct kobj_uevent_env {
69126 char *envp[UEVENT_NUM_ENVP];
69127@@ -134,6 +134,7 @@ struct kobj_attribute {
69128 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
69129 const char *buf, size_t count);
69130 };
69131+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
69132
69133 extern const struct sysfs_ops kobj_sysfs_ops;
69134
69135diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
69136index f66b065..c2c29b4 100644
69137--- a/include/linux/kobject_ns.h
69138+++ b/include/linux/kobject_ns.h
69139@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
69140 const void *(*netlink_ns)(struct sock *sk);
69141 const void *(*initial_ns)(void);
69142 void (*drop_ns)(void *);
69143-};
69144+} __do_const;
69145
69146 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
69147 int kobj_ns_type_registered(enum kobj_ns_type type);
69148diff --git a/include/linux/kref.h b/include/linux/kref.h
69149index 4972e6e..de4d19b 100644
69150--- a/include/linux/kref.h
69151+++ b/include/linux/kref.h
69152@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
69153 static inline int kref_sub(struct kref *kref, unsigned int count,
69154 void (*release)(struct kref *kref))
69155 {
69156- WARN_ON(release == NULL);
69157+ BUG_ON(release == NULL);
69158
69159 if (atomic_sub_and_test((int) count, &kref->refcount)) {
69160 release(kref);
69161diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
69162index 2c497ab..afe32f5 100644
69163--- a/include/linux/kvm_host.h
69164+++ b/include/linux/kvm_host.h
69165@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
69166 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
69167 void vcpu_put(struct kvm_vcpu *vcpu);
69168
69169-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69170+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69171 struct module *module);
69172 void kvm_exit(void);
69173
69174@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
69175 struct kvm_guest_debug *dbg);
69176 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
69177
69178-int kvm_arch_init(void *opaque);
69179+int kvm_arch_init(const void *opaque);
69180 void kvm_arch_exit(void);
69181
69182 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
69183diff --git a/include/linux/libata.h b/include/linux/libata.h
69184index 649e5f8..ead5194 100644
69185--- a/include/linux/libata.h
69186+++ b/include/linux/libata.h
69187@@ -915,7 +915,7 @@ struct ata_port_operations {
69188 * fields must be pointers.
69189 */
69190 const struct ata_port_operations *inherits;
69191-};
69192+} __do_const;
69193
69194 struct ata_port_info {
69195 unsigned long flags;
69196diff --git a/include/linux/list.h b/include/linux/list.h
69197index cc6d2aa..c10ee83 100644
69198--- a/include/linux/list.h
69199+++ b/include/linux/list.h
69200@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
69201 extern void list_del(struct list_head *entry);
69202 #endif
69203
69204+extern void __pax_list_add(struct list_head *new,
69205+ struct list_head *prev,
69206+ struct list_head *next);
69207+static inline void pax_list_add(struct list_head *new, struct list_head *head)
69208+{
69209+ __pax_list_add(new, head, head->next);
69210+}
69211+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
69212+{
69213+ __pax_list_add(new, head->prev, head);
69214+}
69215+extern void pax_list_del(struct list_head *entry);
69216+
69217 /**
69218 * list_replace - replace old entry by new one
69219 * @old : the element to be replaced
69220@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
69221 INIT_LIST_HEAD(entry);
69222 }
69223
69224+extern void pax_list_del_init(struct list_head *entry);
69225+
69226 /**
69227 * list_move - delete from one list and add as another's head
69228 * @list: the entry to move
69229diff --git a/include/linux/math64.h b/include/linux/math64.h
69230index b8ba855..0148090 100644
69231--- a/include/linux/math64.h
69232+++ b/include/linux/math64.h
69233@@ -14,7 +14,7 @@
69234 * This is commonly provided by 32bit archs to provide an optimized 64bit
69235 * divide.
69236 */
69237-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69238+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69239 {
69240 *remainder = dividend % divisor;
69241 return dividend / divisor;
69242@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
69243 #define div64_long(x,y) div_s64((x),(y))
69244
69245 #ifndef div_u64_rem
69246-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69247+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69248 {
69249 *remainder = do_div(dividend, divisor);
69250 return dividend;
69251@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
69252 * divide.
69253 */
69254 #ifndef div_u64
69255-static inline u64 div_u64(u64 dividend, u32 divisor)
69256+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
69257 {
69258 u32 remainder;
69259 return div_u64_rem(dividend, divisor, &remainder);
69260diff --git a/include/linux/mm.h b/include/linux/mm.h
69261index 66e2f7c..a398fb2 100644
69262--- a/include/linux/mm.h
69263+++ b/include/linux/mm.h
69264@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
69265 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
69266 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
69267 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
69268+
69269+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69270+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
69271+#endif
69272+
69273 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
69274
69275 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
69276@@ -231,6 +236,7 @@ struct vm_operations_struct {
69277 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
69278 unsigned long size, pgoff_t pgoff);
69279 };
69280+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
69281
69282 struct mmu_gather;
69283 struct inode;
69284@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
69285 int set_page_dirty_lock(struct page *page);
69286 int clear_page_dirty_for_io(struct page *page);
69287
69288-/* Is the vma a continuation of the stack vma above it? */
69289-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
69290-{
69291- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
69292-}
69293-
69294-static inline int stack_guard_page_start(struct vm_area_struct *vma,
69295- unsigned long addr)
69296-{
69297- return (vma->vm_flags & VM_GROWSDOWN) &&
69298- (vma->vm_start == addr) &&
69299- !vma_growsdown(vma->vm_prev, addr);
69300-}
69301-
69302-/* Is the vma a continuation of the stack vma below it? */
69303-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
69304-{
69305- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
69306-}
69307-
69308-static inline int stack_guard_page_end(struct vm_area_struct *vma,
69309- unsigned long addr)
69310-{
69311- return (vma->vm_flags & VM_GROWSUP) &&
69312- (vma->vm_end == addr) &&
69313- !vma_growsup(vma->vm_next, addr);
69314-}
69315-
69316 extern pid_t
69317 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
69318
69319@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
69320 }
69321 #endif
69322
69323+#ifdef CONFIG_MMU
69324+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
69325+#else
69326+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
69327+{
69328+ return __pgprot(0);
69329+}
69330+#endif
69331+
69332 int vma_wants_writenotify(struct vm_area_struct *vma);
69333
69334 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
69335@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
69336 {
69337 return 0;
69338 }
69339+
69340+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
69341+ unsigned long address)
69342+{
69343+ return 0;
69344+}
69345 #else
69346 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69347+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69348 #endif
69349
69350 #ifdef __PAGETABLE_PMD_FOLDED
69351@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
69352 {
69353 return 0;
69354 }
69355+
69356+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
69357+ unsigned long address)
69358+{
69359+ return 0;
69360+}
69361 #else
69362 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
69363+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
69364 #endif
69365
69366 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
69367@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
69368 NULL: pud_offset(pgd, address);
69369 }
69370
69371+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
69372+{
69373+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
69374+ NULL: pud_offset(pgd, address);
69375+}
69376+
69377 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
69378 {
69379 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
69380 NULL: pmd_offset(pud, address);
69381 }
69382+
69383+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
69384+{
69385+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
69386+ NULL: pmd_offset(pud, address);
69387+}
69388 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
69389
69390 #if USE_SPLIT_PTLOCKS
69391@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
69392 unsigned long, unsigned long,
69393 unsigned long, unsigned long);
69394 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
69395+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
69396
69397 /* These take the mm semaphore themselves */
69398 extern unsigned long vm_brk(unsigned long, unsigned long);
69399@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
69400 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
69401 struct vm_area_struct **pprev);
69402
69403+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
69404+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
69405+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
69406+
69407 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
69408 NULL if none. Assume start_addr < end_addr. */
69409 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
69410@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
69411 return vma;
69412 }
69413
69414-#ifdef CONFIG_MMU
69415-pgprot_t vm_get_page_prot(unsigned long vm_flags);
69416-#else
69417-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
69418-{
69419- return __pgprot(0);
69420-}
69421-#endif
69422-
69423 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
69424 unsigned long change_prot_numa(struct vm_area_struct *vma,
69425 unsigned long start, unsigned long end);
69426@@ -1649,6 +1658,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
69427 static inline void vm_stat_account(struct mm_struct *mm,
69428 unsigned long flags, struct file *file, long pages)
69429 {
69430+
69431+#ifdef CONFIG_PAX_RANDMMAP
69432+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
69433+#endif
69434+
69435 mm->total_vm += pages;
69436 }
69437 #endif /* CONFIG_PROC_FS */
69438@@ -1721,7 +1735,7 @@ extern int unpoison_memory(unsigned long pfn);
69439 extern int sysctl_memory_failure_early_kill;
69440 extern int sysctl_memory_failure_recovery;
69441 extern void shake_page(struct page *p, int access);
69442-extern atomic_long_t mce_bad_pages;
69443+extern atomic_long_unchecked_t mce_bad_pages;
69444 extern int soft_offline_page(struct page *page, int flags);
69445
69446 extern void dump_page(struct page *page);
69447@@ -1752,5 +1766,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
69448 static inline bool page_is_guard(struct page *page) { return false; }
69449 #endif /* CONFIG_DEBUG_PAGEALLOC */
69450
69451+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69452+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
69453+#else
69454+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
69455+#endif
69456+
69457 #endif /* __KERNEL__ */
69458 #endif /* _LINUX_MM_H */
69459diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
69460index f8f5162..3aaf20f 100644
69461--- a/include/linux/mm_types.h
69462+++ b/include/linux/mm_types.h
69463@@ -288,6 +288,8 @@ struct vm_area_struct {
69464 #ifdef CONFIG_NUMA
69465 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
69466 #endif
69467+
69468+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
69469 };
69470
69471 struct core_thread {
69472@@ -436,6 +438,24 @@ struct mm_struct {
69473 int first_nid;
69474 #endif
69475 struct uprobes_state uprobes_state;
69476+
69477+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69478+ unsigned long pax_flags;
69479+#endif
69480+
69481+#ifdef CONFIG_PAX_DLRESOLVE
69482+ unsigned long call_dl_resolve;
69483+#endif
69484+
69485+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
69486+ unsigned long call_syscall;
69487+#endif
69488+
69489+#ifdef CONFIG_PAX_ASLR
69490+ unsigned long delta_mmap; /* randomized offset */
69491+ unsigned long delta_stack; /* randomized offset */
69492+#endif
69493+
69494 };
69495
69496 /* first nid will either be a valid NID or one of these values */
69497diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
69498index c5d5278..f0b68c8 100644
69499--- a/include/linux/mmiotrace.h
69500+++ b/include/linux/mmiotrace.h
69501@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
69502 /* Called from ioremap.c */
69503 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
69504 void __iomem *addr);
69505-extern void mmiotrace_iounmap(volatile void __iomem *addr);
69506+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
69507
69508 /* For anyone to insert markers. Remember trailing newline. */
69509 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
69510@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
69511 {
69512 }
69513
69514-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
69515+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
69516 {
69517 }
69518
69519diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
69520index 73b64a3..6562925 100644
69521--- a/include/linux/mmzone.h
69522+++ b/include/linux/mmzone.h
69523@@ -412,7 +412,7 @@ struct zone {
69524 unsigned long flags; /* zone flags, see below */
69525
69526 /* Zone statistics */
69527- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69528+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69529
69530 /*
69531 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
69532diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
69533index fed3def..c933f99 100644
69534--- a/include/linux/mod_devicetable.h
69535+++ b/include/linux/mod_devicetable.h
69536@@ -12,7 +12,7 @@
69537 typedef unsigned long kernel_ulong_t;
69538 #endif
69539
69540-#define PCI_ANY_ID (~0)
69541+#define PCI_ANY_ID ((__u16)~0)
69542
69543 struct pci_device_id {
69544 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
69545@@ -139,7 +139,7 @@ struct usb_device_id {
69546 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
69547 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
69548
69549-#define HID_ANY_ID (~0)
69550+#define HID_ANY_ID (~0U)
69551 #define HID_BUS_ANY 0xffff
69552 #define HID_GROUP_ANY 0x0000
69553
69554@@ -498,7 +498,7 @@ struct dmi_system_id {
69555 const char *ident;
69556 struct dmi_strmatch matches[4];
69557 void *driver_data;
69558-};
69559+} __do_const;
69560 /*
69561 * struct dmi_device_id appears during expansion of
69562 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
69563diff --git a/include/linux/module.h b/include/linux/module.h
69564index 1375ee3..ced8177 100644
69565--- a/include/linux/module.h
69566+++ b/include/linux/module.h
69567@@ -17,9 +17,11 @@
69568 #include <linux/moduleparam.h>
69569 #include <linux/tracepoint.h>
69570 #include <linux/export.h>
69571+#include <linux/fs.h>
69572
69573 #include <linux/percpu.h>
69574 #include <asm/module.h>
69575+#include <asm/pgtable.h>
69576
69577 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
69578 #define MODULE_SIG_STRING "~Module signature appended~\n"
69579@@ -54,12 +56,13 @@ struct module_attribute {
69580 int (*test)(struct module *);
69581 void (*free)(struct module *);
69582 };
69583+typedef struct module_attribute __no_const module_attribute_no_const;
69584
69585 struct module_version_attribute {
69586 struct module_attribute mattr;
69587 const char *module_name;
69588 const char *version;
69589-} __attribute__ ((__aligned__(sizeof(void *))));
69590+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
69591
69592 extern ssize_t __modver_version_show(struct module_attribute *,
69593 struct module_kobject *, char *);
69594@@ -232,7 +235,7 @@ struct module
69595
69596 /* Sysfs stuff. */
69597 struct module_kobject mkobj;
69598- struct module_attribute *modinfo_attrs;
69599+ module_attribute_no_const *modinfo_attrs;
69600 const char *version;
69601 const char *srcversion;
69602 struct kobject *holders_dir;
69603@@ -281,19 +284,16 @@ struct module
69604 int (*init)(void);
69605
69606 /* If this is non-NULL, vfree after init() returns */
69607- void *module_init;
69608+ void *module_init_rx, *module_init_rw;
69609
69610 /* Here is the actual code + data, vfree'd on unload. */
69611- void *module_core;
69612+ void *module_core_rx, *module_core_rw;
69613
69614 /* Here are the sizes of the init and core sections */
69615- unsigned int init_size, core_size;
69616+ unsigned int init_size_rw, core_size_rw;
69617
69618 /* The size of the executable code in each section. */
69619- unsigned int init_text_size, core_text_size;
69620-
69621- /* Size of RO sections of the module (text+rodata) */
69622- unsigned int init_ro_size, core_ro_size;
69623+ unsigned int init_size_rx, core_size_rx;
69624
69625 /* Arch-specific module values */
69626 struct mod_arch_specific arch;
69627@@ -349,6 +349,10 @@ struct module
69628 #ifdef CONFIG_EVENT_TRACING
69629 struct ftrace_event_call **trace_events;
69630 unsigned int num_trace_events;
69631+ struct file_operations trace_id;
69632+ struct file_operations trace_enable;
69633+ struct file_operations trace_format;
69634+ struct file_operations trace_filter;
69635 #endif
69636 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69637 unsigned int num_ftrace_callsites;
69638@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
69639 bool is_module_percpu_address(unsigned long addr);
69640 bool is_module_text_address(unsigned long addr);
69641
69642+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
69643+{
69644+
69645+#ifdef CONFIG_PAX_KERNEXEC
69646+ if (ktla_ktva(addr) >= (unsigned long)start &&
69647+ ktla_ktva(addr) < (unsigned long)start + size)
69648+ return 1;
69649+#endif
69650+
69651+ return ((void *)addr >= start && (void *)addr < start + size);
69652+}
69653+
69654+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
69655+{
69656+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
69657+}
69658+
69659+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
69660+{
69661+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
69662+}
69663+
69664+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
69665+{
69666+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
69667+}
69668+
69669+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
69670+{
69671+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
69672+}
69673+
69674 static inline int within_module_core(unsigned long addr, struct module *mod)
69675 {
69676- return (unsigned long)mod->module_core <= addr &&
69677- addr < (unsigned long)mod->module_core + mod->core_size;
69678+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69679 }
69680
69681 static inline int within_module_init(unsigned long addr, struct module *mod)
69682 {
69683- return (unsigned long)mod->module_init <= addr &&
69684- addr < (unsigned long)mod->module_init + mod->init_size;
69685+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69686 }
69687
69688 /* Search for module by name: must hold module_mutex. */
69689diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69690index 560ca53..5ee8d73 100644
69691--- a/include/linux/moduleloader.h
69692+++ b/include/linux/moduleloader.h
69693@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69694
69695 /* Allocator used for allocating struct module, core sections and init
69696 sections. Returns NULL on failure. */
69697-void *module_alloc(unsigned long size);
69698+void *module_alloc(unsigned long size) __size_overflow(1);
69699+
69700+#ifdef CONFIG_PAX_KERNEXEC
69701+void *module_alloc_exec(unsigned long size) __size_overflow(1);
69702+#else
69703+#define module_alloc_exec(x) module_alloc(x)
69704+#endif
69705
69706 /* Free memory returned from module_alloc. */
69707 void module_free(struct module *mod, void *module_region);
69708
69709+#ifdef CONFIG_PAX_KERNEXEC
69710+void module_free_exec(struct module *mod, void *module_region);
69711+#else
69712+#define module_free_exec(x, y) module_free((x), (y))
69713+#endif
69714+
69715 /*
69716 * Apply the given relocation to the (simplified) ELF. Return -error
69717 * or 0.
69718@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69719 unsigned int relsec,
69720 struct module *me)
69721 {
69722+#ifdef CONFIG_MODULES
69723 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69724+#endif
69725 return -ENOEXEC;
69726 }
69727 #endif
69728@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69729 unsigned int relsec,
69730 struct module *me)
69731 {
69732+#ifdef CONFIG_MODULES
69733 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69734+#endif
69735 return -ENOEXEC;
69736 }
69737 #endif
69738diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69739index 137b419..fe663ec 100644
69740--- a/include/linux/moduleparam.h
69741+++ b/include/linux/moduleparam.h
69742@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69743 * @len is usually just sizeof(string).
69744 */
69745 #define module_param_string(name, string, len, perm) \
69746- static const struct kparam_string __param_string_##name \
69747+ static const struct kparam_string __param_string_##name __used \
69748 = { len, string }; \
69749 __module_param_call(MODULE_PARAM_PREFIX, name, \
69750 &param_ops_string, \
69751@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69752 */
69753 #define module_param_array_named(name, array, type, nump, perm) \
69754 param_check_##type(name, &(array)[0]); \
69755- static const struct kparam_array __param_arr_##name \
69756+ static const struct kparam_array __param_arr_##name __used \
69757 = { .max = ARRAY_SIZE(array), .num = nump, \
69758 .ops = &param_ops_##type, \
69759 .elemsize = sizeof(array[0]), .elem = array }; \
69760diff --git a/include/linux/namei.h b/include/linux/namei.h
69761index 5a5ff57..5ae5070 100644
69762--- a/include/linux/namei.h
69763+++ b/include/linux/namei.h
69764@@ -19,7 +19,7 @@ struct nameidata {
69765 unsigned seq;
69766 int last_type;
69767 unsigned depth;
69768- char *saved_names[MAX_NESTED_LINKS + 1];
69769+ const char *saved_names[MAX_NESTED_LINKS + 1];
69770 };
69771
69772 /*
69773@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69774
69775 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69776
69777-static inline void nd_set_link(struct nameidata *nd, char *path)
69778+static inline void nd_set_link(struct nameidata *nd, const char *path)
69779 {
69780 nd->saved_names[nd->depth] = path;
69781 }
69782
69783-static inline char *nd_get_link(struct nameidata *nd)
69784+static inline const char *nd_get_link(const struct nameidata *nd)
69785 {
69786 return nd->saved_names[nd->depth];
69787 }
69788diff --git a/include/linux/net.h b/include/linux/net.h
69789index aa16731..514b875 100644
69790--- a/include/linux/net.h
69791+++ b/include/linux/net.h
69792@@ -183,7 +183,7 @@ struct net_proto_family {
69793 int (*create)(struct net *net, struct socket *sock,
69794 int protocol, int kern);
69795 struct module *owner;
69796-};
69797+} __do_const;
69798
69799 struct iovec;
69800 struct kvec;
69801diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69802index 9ef07d0..130a5d9 100644
69803--- a/include/linux/netdevice.h
69804+++ b/include/linux/netdevice.h
69805@@ -1012,6 +1012,7 @@ struct net_device_ops {
69806 u32 pid, u32 seq,
69807 struct net_device *dev);
69808 };
69809+typedef struct net_device_ops __no_const net_device_ops_no_const;
69810
69811 /*
69812 * The DEVICE structure.
69813@@ -1078,7 +1079,7 @@ struct net_device {
69814 int iflink;
69815
69816 struct net_device_stats stats;
69817- atomic_long_t rx_dropped; /* dropped packets by core network
69818+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69819 * Do not use this in drivers.
69820 */
69821
69822diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69823index ee14284..bc65d63 100644
69824--- a/include/linux/netfilter.h
69825+++ b/include/linux/netfilter.h
69826@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69827 #endif
69828 /* Use the module struct to lock set/get code in place */
69829 struct module *owner;
69830-};
69831+} __do_const;
69832
69833 /* Function to register/unregister hook points. */
69834 int nf_register_hook(struct nf_hook_ops *reg);
69835diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69836index 7958e84..ed74d7a 100644
69837--- a/include/linux/netfilter/ipset/ip_set.h
69838+++ b/include/linux/netfilter/ipset/ip_set.h
69839@@ -98,7 +98,7 @@ struct ip_set_type_variant {
69840 /* Return true if "b" set is the same as "a"
69841 * according to the create set parameters */
69842 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69843-};
69844+} __do_const;
69845
69846 /* The core set type structure */
69847 struct ip_set_type {
69848diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69849index 4966dde..7d8ce06 100644
69850--- a/include/linux/netfilter/nfnetlink.h
69851+++ b/include/linux/netfilter/nfnetlink.h
69852@@ -16,7 +16,7 @@ struct nfnl_callback {
69853 const struct nlattr * const cda[]);
69854 const struct nla_policy *policy; /* netlink attribute policy */
69855 const u_int16_t attr_count; /* number of nlattr's */
69856-};
69857+} __do_const;
69858
69859 struct nfnetlink_subsystem {
69860 const char *name;
69861diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69862new file mode 100644
69863index 0000000..33f4af8
69864--- /dev/null
69865+++ b/include/linux/netfilter/xt_gradm.h
69866@@ -0,0 +1,9 @@
69867+#ifndef _LINUX_NETFILTER_XT_GRADM_H
69868+#define _LINUX_NETFILTER_XT_GRADM_H 1
69869+
69870+struct xt_gradm_mtinfo {
69871+ __u16 flags;
69872+ __u16 invflags;
69873+};
69874+
69875+#endif
69876diff --git a/include/linux/nls.h b/include/linux/nls.h
69877index 5dc635f..35f5e11 100644
69878--- a/include/linux/nls.h
69879+++ b/include/linux/nls.h
69880@@ -31,7 +31,7 @@ struct nls_table {
69881 const unsigned char *charset2upper;
69882 struct module *owner;
69883 struct nls_table *next;
69884-};
69885+} __do_const;
69886
69887 /* this value hold the maximum octet of charset */
69888 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69889diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69890index d65746e..62e72c2 100644
69891--- a/include/linux/notifier.h
69892+++ b/include/linux/notifier.h
69893@@ -51,7 +51,8 @@ struct notifier_block {
69894 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69895 struct notifier_block __rcu *next;
69896 int priority;
69897-};
69898+} __do_const;
69899+typedef struct notifier_block __no_const notifier_block_no_const;
69900
69901 struct atomic_notifier_head {
69902 spinlock_t lock;
69903diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69904index a4c5624..79d6d88 100644
69905--- a/include/linux/oprofile.h
69906+++ b/include/linux/oprofile.h
69907@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69908 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69909 char const * name, ulong * val);
69910
69911-/** Create a file for read-only access to an atomic_t. */
69912+/** Create a file for read-only access to an atomic_unchecked_t. */
69913 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69914- char const * name, atomic_t * val);
69915+ char const * name, atomic_unchecked_t * val);
69916
69917 /** create a directory */
69918 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69919diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69920index 45fc162..01a4068 100644
69921--- a/include/linux/pci_hotplug.h
69922+++ b/include/linux/pci_hotplug.h
69923@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69924 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69925 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69926 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69927-};
69928+} __do_const;
69929+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69930
69931 /**
69932 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69933diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69934index a280650..2b67b91 100644
69935--- a/include/linux/perf_event.h
69936+++ b/include/linux/perf_event.h
69937@@ -328,8 +328,8 @@ struct perf_event {
69938
69939 enum perf_event_active_state state;
69940 unsigned int attach_state;
69941- local64_t count;
69942- atomic64_t child_count;
69943+ local64_t count; /* PaX: fix it one day */
69944+ atomic64_unchecked_t child_count;
69945
69946 /*
69947 * These are the total time in nanoseconds that the event
69948@@ -380,8 +380,8 @@ struct perf_event {
69949 * These accumulate total time (in nanoseconds) that children
69950 * events have been enabled and running, respectively.
69951 */
69952- atomic64_t child_total_time_enabled;
69953- atomic64_t child_total_time_running;
69954+ atomic64_unchecked_t child_total_time_enabled;
69955+ atomic64_unchecked_t child_total_time_running;
69956
69957 /*
69958 * Protect attach/detach and child_list:
69959@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
69960 */
69961 #define perf_cpu_notifier(fn) \
69962 do { \
69963- static struct notifier_block fn##_nb __cpuinitdata = \
69964+ static struct notifier_block fn##_nb = \
69965 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
69966 unsigned long cpu = smp_processor_id(); \
69967 unsigned long flags; \
69968diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
69969index ad1a427..6419649 100644
69970--- a/include/linux/pipe_fs_i.h
69971+++ b/include/linux/pipe_fs_i.h
69972@@ -45,9 +45,9 @@ struct pipe_buffer {
69973 struct pipe_inode_info {
69974 wait_queue_head_t wait;
69975 unsigned int nrbufs, curbuf, buffers;
69976- unsigned int readers;
69977- unsigned int writers;
69978- unsigned int waiting_writers;
69979+ atomic_t readers;
69980+ atomic_t writers;
69981+ atomic_t waiting_writers;
69982 unsigned int r_counter;
69983 unsigned int w_counter;
69984 struct page *tmp_page;
69985diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
69986index 5f28cae..3d23723 100644
69987--- a/include/linux/platform_data/usb-ehci-s5p.h
69988+++ b/include/linux/platform_data/usb-ehci-s5p.h
69989@@ -14,7 +14,7 @@
69990 struct s5p_ehci_platdata {
69991 int (*phy_init)(struct platform_device *pdev, int type);
69992 int (*phy_exit)(struct platform_device *pdev, int type);
69993-};
69994+} __no_const;
69995
69996 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
69997
69998diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
69999index c256c59..8ea94c7 100644
70000--- a/include/linux/platform_data/usb-exynos.h
70001+++ b/include/linux/platform_data/usb-exynos.h
70002@@ -14,7 +14,7 @@
70003 struct exynos4_ohci_platdata {
70004 int (*phy_init)(struct platform_device *pdev, int type);
70005 int (*phy_exit)(struct platform_device *pdev, int type);
70006-};
70007+} __no_const;
70008
70009 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
70010
70011diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
70012index 7c1d252..c5c773e 100644
70013--- a/include/linux/pm_domain.h
70014+++ b/include/linux/pm_domain.h
70015@@ -48,7 +48,7 @@ struct gpd_dev_ops {
70016
70017 struct gpd_cpu_data {
70018 unsigned int saved_exit_latency;
70019- struct cpuidle_state *idle_state;
70020+ cpuidle_state_no_const *idle_state;
70021 };
70022
70023 struct generic_pm_domain {
70024diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
70025index f271860..6b3bec5 100644
70026--- a/include/linux/pm_runtime.h
70027+++ b/include/linux/pm_runtime.h
70028@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
70029
70030 static inline void pm_runtime_mark_last_busy(struct device *dev)
70031 {
70032- ACCESS_ONCE(dev->power.last_busy) = jiffies;
70033+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
70034 }
70035
70036 #else /* !CONFIG_PM_RUNTIME */
70037diff --git a/include/linux/pnp.h b/include/linux/pnp.h
70038index 195aafc..49a7bc2 100644
70039--- a/include/linux/pnp.h
70040+++ b/include/linux/pnp.h
70041@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
70042 struct pnp_fixup {
70043 char id[7];
70044 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
70045-};
70046+} __do_const;
70047
70048 /* config parameters */
70049 #define PNP_CONFIG_NORMAL 0x0001
70050diff --git a/include/linux/poison.h b/include/linux/poison.h
70051index 2110a81..13a11bb 100644
70052--- a/include/linux/poison.h
70053+++ b/include/linux/poison.h
70054@@ -19,8 +19,8 @@
70055 * under normal circumstances, used to verify that nobody uses
70056 * non-initialized list entries.
70057 */
70058-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
70059-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
70060+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
70061+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
70062
70063 /********** include/linux/timer.h **********/
70064 /*
70065diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
70066index c0f44c2..1572583 100644
70067--- a/include/linux/power/smartreflex.h
70068+++ b/include/linux/power/smartreflex.h
70069@@ -238,7 +238,7 @@ struct omap_sr_class_data {
70070 int (*notify)(struct omap_sr *sr, u32 status);
70071 u8 notify_flags;
70072 u8 class_type;
70073-};
70074+} __do_const;
70075
70076 /**
70077 * struct omap_sr_nvalue_table - Smartreflex n-target value info
70078diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
70079index 4ea1d37..80f4b33 100644
70080--- a/include/linux/ppp-comp.h
70081+++ b/include/linux/ppp-comp.h
70082@@ -84,7 +84,7 @@ struct compressor {
70083 struct module *owner;
70084 /* Extra skb space needed by the compressor algorithm */
70085 unsigned int comp_extra;
70086-};
70087+} __do_const;
70088
70089 /*
70090 * The return value from decompress routine is the length of the
70091diff --git a/include/linux/printk.h b/include/linux/printk.h
70092index 9afc01e..92c32e8 100644
70093--- a/include/linux/printk.h
70094+++ b/include/linux/printk.h
70095@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
70096 extern int printk_needs_cpu(int cpu);
70097 extern void printk_tick(void);
70098
70099+extern int kptr_restrict;
70100+
70101 #ifdef CONFIG_PRINTK
70102 asmlinkage __printf(5, 0)
70103 int vprintk_emit(int facility, int level,
70104@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
70105
70106 extern int printk_delay_msec;
70107 extern int dmesg_restrict;
70108-extern int kptr_restrict;
70109
70110 void log_buf_kexec_setup(void);
70111 void __init setup_log_buf(int early);
70112diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
70113index 32676b3..8f7a182 100644
70114--- a/include/linux/proc_fs.h
70115+++ b/include/linux/proc_fs.h
70116@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
70117 return proc_create_data(name, mode, parent, proc_fops, NULL);
70118 }
70119
70120+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
70121+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
70122+{
70123+#ifdef CONFIG_GRKERNSEC_PROC_USER
70124+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
70125+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70126+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
70127+#else
70128+ return proc_create_data(name, mode, parent, proc_fops, NULL);
70129+#endif
70130+}
70131+
70132 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
70133 umode_t mode, struct proc_dir_entry *base,
70134 read_proc_t *read_proc, void * data)
70135diff --git a/include/linux/random.h b/include/linux/random.h
70136index d984608..d6f0042 100644
70137--- a/include/linux/random.h
70138+++ b/include/linux/random.h
70139@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
70140 u32 prandom_u32_state(struct rnd_state *);
70141 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
70142
70143+static inline unsigned long pax_get_random_long(void)
70144+{
70145+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
70146+}
70147+
70148 /*
70149 * Handle minimum values for seeds
70150 */
70151diff --git a/include/linux/rculist.h b/include/linux/rculist.h
70152index c92dd28..08f4eab 100644
70153--- a/include/linux/rculist.h
70154+++ b/include/linux/rculist.h
70155@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
70156 struct list_head *prev, struct list_head *next);
70157 #endif
70158
70159+extern void __pax_list_add_rcu(struct list_head *new,
70160+ struct list_head *prev, struct list_head *next);
70161+
70162 /**
70163 * list_add_rcu - add a new entry to rcu-protected list
70164 * @new: new entry to be added
70165@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
70166 __list_add_rcu(new, head, head->next);
70167 }
70168
70169+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
70170+{
70171+ __pax_list_add_rcu(new, head, head->next);
70172+}
70173+
70174 /**
70175 * list_add_tail_rcu - add a new entry to rcu-protected list
70176 * @new: new entry to be added
70177@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
70178 __list_add_rcu(new, head->prev, head);
70179 }
70180
70181+static inline void pax_list_add_tail_rcu(struct list_head *new,
70182+ struct list_head *head)
70183+{
70184+ __pax_list_add_rcu(new, head->prev, head);
70185+}
70186+
70187 /**
70188 * list_del_rcu - deletes entry from list without re-initialization
70189 * @entry: the element to delete from the list.
70190@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
70191 entry->prev = LIST_POISON2;
70192 }
70193
70194+extern void pax_list_del_rcu(struct list_head *entry);
70195+
70196 /**
70197 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
70198 * @n: the element to delete from the hash list.
70199diff --git a/include/linux/reboot.h b/include/linux/reboot.h
70200index 23b3630..e1bc12b 100644
70201--- a/include/linux/reboot.h
70202+++ b/include/linux/reboot.h
70203@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
70204 * Architecture-specific implementations of sys_reboot commands.
70205 */
70206
70207-extern void machine_restart(char *cmd);
70208-extern void machine_halt(void);
70209-extern void machine_power_off(void);
70210+extern void machine_restart(char *cmd) __noreturn;
70211+extern void machine_halt(void) __noreturn;
70212+extern void machine_power_off(void) __noreturn;
70213
70214 extern void machine_shutdown(void);
70215 struct pt_regs;
70216@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
70217 */
70218
70219 extern void kernel_restart_prepare(char *cmd);
70220-extern void kernel_restart(char *cmd);
70221-extern void kernel_halt(void);
70222-extern void kernel_power_off(void);
70223+extern void kernel_restart(char *cmd) __noreturn;
70224+extern void kernel_halt(void) __noreturn;
70225+extern void kernel_power_off(void) __noreturn;
70226
70227 extern int C_A_D; /* for sysctl */
70228 void ctrl_alt_del(void);
70229@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
70230 * Emergency restart, callable from an interrupt handler.
70231 */
70232
70233-extern void emergency_restart(void);
70234+extern void emergency_restart(void) __noreturn;
70235 #include <asm/emergency-restart.h>
70236
70237 #endif /* _LINUX_REBOOT_H */
70238diff --git a/include/linux/regset.h b/include/linux/regset.h
70239index 8e0c9fe..ac4d221 100644
70240--- a/include/linux/regset.h
70241+++ b/include/linux/regset.h
70242@@ -161,7 +161,8 @@ struct user_regset {
70243 unsigned int align;
70244 unsigned int bias;
70245 unsigned int core_note_type;
70246-};
70247+} __do_const;
70248+typedef struct user_regset __no_const user_regset_no_const;
70249
70250 /**
70251 * struct user_regset_view - available regsets
70252diff --git a/include/linux/relay.h b/include/linux/relay.h
70253index 91cacc3..b55ff74 100644
70254--- a/include/linux/relay.h
70255+++ b/include/linux/relay.h
70256@@ -160,7 +160,7 @@ struct rchan_callbacks
70257 * The callback should return 0 if successful, negative if not.
70258 */
70259 int (*remove_buf_file)(struct dentry *dentry);
70260-};
70261+} __no_const;
70262
70263 /*
70264 * CONFIG_RELAY kernel API, kernel/relay.c
70265diff --git a/include/linux/rio.h b/include/linux/rio.h
70266index a3e7842..d973ca6 100644
70267--- a/include/linux/rio.h
70268+++ b/include/linux/rio.h
70269@@ -339,7 +339,7 @@ struct rio_ops {
70270 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
70271 u64 rstart, u32 size, u32 flags);
70272 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
70273-};
70274+} __no_const;
70275
70276 #define RIO_RESOURCE_MEM 0x00000100
70277 #define RIO_RESOURCE_DOORBELL 0x00000200
70278diff --git a/include/linux/rmap.h b/include/linux/rmap.h
70279index c20635c..2f5def4 100644
70280--- a/include/linux/rmap.h
70281+++ b/include/linux/rmap.h
70282@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
70283 void anon_vma_init(void); /* create anon_vma_cachep */
70284 int anon_vma_prepare(struct vm_area_struct *);
70285 void unlink_anon_vmas(struct vm_area_struct *);
70286-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
70287-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
70288+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
70289+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
70290
70291 static inline void anon_vma_merge(struct vm_area_struct *vma,
70292 struct vm_area_struct *next)
70293diff --git a/include/linux/sched.h b/include/linux/sched.h
70294index d211247..eac6c2c 100644
70295--- a/include/linux/sched.h
70296+++ b/include/linux/sched.h
70297@@ -61,6 +61,7 @@ struct bio_list;
70298 struct fs_struct;
70299 struct perf_event_context;
70300 struct blk_plug;
70301+struct linux_binprm;
70302
70303 /*
70304 * List of flags we want to share for kernel threads,
70305@@ -327,7 +328,7 @@ extern char __sched_text_start[], __sched_text_end[];
70306 extern int in_sched_functions(unsigned long addr);
70307
70308 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
70309-extern signed long schedule_timeout(signed long timeout);
70310+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
70311 extern signed long schedule_timeout_interruptible(signed long timeout);
70312 extern signed long schedule_timeout_killable(signed long timeout);
70313 extern signed long schedule_timeout_uninterruptible(signed long timeout);
70314@@ -354,10 +355,23 @@ struct user_namespace;
70315 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
70316
70317 extern int sysctl_max_map_count;
70318+extern unsigned long sysctl_heap_stack_gap;
70319
70320 #include <linux/aio.h>
70321
70322 #ifdef CONFIG_MMU
70323+
70324+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
70325+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
70326+#else
70327+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
70328+{
70329+ return 0;
70330+}
70331+#endif
70332+
70333+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
70334+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
70335 extern void arch_pick_mmap_layout(struct mm_struct *mm);
70336 extern unsigned long
70337 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
70338@@ -639,6 +653,17 @@ struct signal_struct {
70339 #ifdef CONFIG_TASKSTATS
70340 struct taskstats *stats;
70341 #endif
70342+
70343+#ifdef CONFIG_GRKERNSEC
70344+ u32 curr_ip;
70345+ u32 saved_ip;
70346+ u32 gr_saddr;
70347+ u32 gr_daddr;
70348+ u16 gr_sport;
70349+ u16 gr_dport;
70350+ u8 used_accept:1;
70351+#endif
70352+
70353 #ifdef CONFIG_AUDIT
70354 unsigned audit_tty;
70355 struct tty_audit_buf *tty_audit_buf;
70356@@ -717,6 +742,11 @@ struct user_struct {
70357 struct key *session_keyring; /* UID's default session keyring */
70358 #endif
70359
70360+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
70361+ unsigned int banned;
70362+ unsigned long ban_expires;
70363+#endif
70364+
70365 /* Hash table maintenance information */
70366 struct hlist_node uidhash_node;
70367 kuid_t uid;
70368@@ -1116,7 +1146,7 @@ struct sched_class {
70369 #ifdef CONFIG_FAIR_GROUP_SCHED
70370 void (*task_move_group) (struct task_struct *p, int on_rq);
70371 #endif
70372-};
70373+} __do_const;
70374
70375 struct load_weight {
70376 unsigned long weight, inv_weight;
70377@@ -1360,8 +1390,8 @@ struct task_struct {
70378 struct list_head thread_group;
70379
70380 struct completion *vfork_done; /* for vfork() */
70381- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
70382- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70383+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
70384+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70385
70386 cputime_t utime, stime, utimescaled, stimescaled;
70387 cputime_t gtime;
70388@@ -1377,11 +1407,6 @@ struct task_struct {
70389 struct task_cputime cputime_expires;
70390 struct list_head cpu_timers[3];
70391
70392-/* process credentials */
70393- const struct cred __rcu *real_cred; /* objective and real subjective task
70394- * credentials (COW) */
70395- const struct cred __rcu *cred; /* effective (overridable) subjective task
70396- * credentials (COW) */
70397 char comm[TASK_COMM_LEN]; /* executable name excluding path
70398 - access with [gs]et_task_comm (which lock
70399 it with task_lock())
70400@@ -1398,6 +1423,10 @@ struct task_struct {
70401 #endif
70402 /* CPU-specific state of this task */
70403 struct thread_struct thread;
70404+/* thread_info moved to task_struct */
70405+#ifdef CONFIG_X86
70406+ struct thread_info tinfo;
70407+#endif
70408 /* filesystem information */
70409 struct fs_struct *fs;
70410 /* open file information */
70411@@ -1471,6 +1500,10 @@ struct task_struct {
70412 gfp_t lockdep_reclaim_gfp;
70413 #endif
70414
70415+/* process credentials */
70416+ const struct cred __rcu *real_cred; /* objective and real subjective task
70417+ * credentials (COW) */
70418+
70419 /* journalling filesystem info */
70420 void *journal_info;
70421
70422@@ -1509,6 +1542,10 @@ struct task_struct {
70423 /* cg_list protected by css_set_lock and tsk->alloc_lock */
70424 struct list_head cg_list;
70425 #endif
70426+
70427+ const struct cred __rcu *cred; /* effective (overridable) subjective task
70428+ * credentials (COW) */
70429+
70430 #ifdef CONFIG_FUTEX
70431 struct robust_list_head __user *robust_list;
70432 #ifdef CONFIG_COMPAT
70433@@ -1605,8 +1642,74 @@ struct task_struct {
70434 #ifdef CONFIG_UPROBES
70435 struct uprobe_task *utask;
70436 #endif
70437+
70438+#ifdef CONFIG_GRKERNSEC
70439+ /* grsecurity */
70440+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70441+ u64 exec_id;
70442+#endif
70443+#ifdef CONFIG_GRKERNSEC_SETXID
70444+ const struct cred *delayed_cred;
70445+#endif
70446+ struct dentry *gr_chroot_dentry;
70447+ struct acl_subject_label *acl;
70448+ struct acl_role_label *role;
70449+ struct file *exec_file;
70450+ unsigned long brute_expires;
70451+ u16 acl_role_id;
70452+ /* is this the task that authenticated to the special role */
70453+ u8 acl_sp_role;
70454+ u8 is_writable;
70455+ u8 brute;
70456+ u8 gr_is_chrooted;
70457+#endif
70458+
70459 };
70460
70461+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
70462+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
70463+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
70464+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
70465+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
70466+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
70467+
70468+#ifdef CONFIG_PAX_SOFTMODE
70469+extern int pax_softmode;
70470+#endif
70471+
70472+extern int pax_check_flags(unsigned long *);
70473+
70474+/* if tsk != current then task_lock must be held on it */
70475+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70476+static inline unsigned long pax_get_flags(struct task_struct *tsk)
70477+{
70478+ if (likely(tsk->mm))
70479+ return tsk->mm->pax_flags;
70480+ else
70481+ return 0UL;
70482+}
70483+
70484+/* if tsk != current then task_lock must be held on it */
70485+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
70486+{
70487+ if (likely(tsk->mm)) {
70488+ tsk->mm->pax_flags = flags;
70489+ return 0;
70490+ }
70491+ return -EINVAL;
70492+}
70493+#endif
70494+
70495+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70496+extern void pax_set_initial_flags(struct linux_binprm *bprm);
70497+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
70498+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
70499+#endif
70500+
70501+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
70502+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
70503+extern void pax_report_refcount_overflow(struct pt_regs *regs);
70504+
70505 /* Future-safe accessor for struct task_struct's cpus_allowed. */
70506 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
70507
70508@@ -1696,7 +1799,7 @@ struct pid_namespace;
70509 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
70510 struct pid_namespace *ns);
70511
70512-static inline pid_t task_pid_nr(struct task_struct *tsk)
70513+static inline pid_t task_pid_nr(const struct task_struct *tsk)
70514 {
70515 return tsk->pid;
70516 }
70517@@ -2155,7 +2258,9 @@ void yield(void);
70518 extern struct exec_domain default_exec_domain;
70519
70520 union thread_union {
70521+#ifndef CONFIG_X86
70522 struct thread_info thread_info;
70523+#endif
70524 unsigned long stack[THREAD_SIZE/sizeof(long)];
70525 };
70526
70527@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
70528 */
70529
70530 extern struct task_struct *find_task_by_vpid(pid_t nr);
70531+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
70532 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
70533 struct pid_namespace *ns);
70534
70535@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
70536 extern void exit_itimers(struct signal_struct *);
70537 extern void flush_itimer_signals(void);
70538
70539-extern void do_group_exit(int);
70540+extern __noreturn void do_group_exit(int);
70541
70542 extern int allow_signal(int);
70543 extern int disallow_signal(int);
70544@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
70545
70546 #endif
70547
70548-static inline int object_is_on_stack(void *obj)
70549+static inline int object_starts_on_stack(void *obj)
70550 {
70551- void *stack = task_stack_page(current);
70552+ const void *stack = task_stack_page(current);
70553
70554 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
70555 }
70556diff --git a/include/linux/security.h b/include/linux/security.h
70557index eee7478..290f7ba 100644
70558--- a/include/linux/security.h
70559+++ b/include/linux/security.h
70560@@ -26,6 +26,7 @@
70561 #include <linux/capability.h>
70562 #include <linux/slab.h>
70563 #include <linux/err.h>
70564+#include <linux/grsecurity.h>
70565
70566 struct linux_binprm;
70567 struct cred;
70568diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
70569index 68a04a3..866e6a1 100644
70570--- a/include/linux/seq_file.h
70571+++ b/include/linux/seq_file.h
70572@@ -26,6 +26,9 @@ struct seq_file {
70573 struct mutex lock;
70574 const struct seq_operations *op;
70575 int poll_event;
70576+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70577+ u64 exec_id;
70578+#endif
70579 #ifdef CONFIG_USER_NS
70580 struct user_namespace *user_ns;
70581 #endif
70582@@ -38,6 +41,7 @@ struct seq_operations {
70583 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
70584 int (*show) (struct seq_file *m, void *v);
70585 };
70586+typedef struct seq_operations __no_const seq_operations_no_const;
70587
70588 #define SEQ_SKIP 1
70589
70590diff --git a/include/linux/shm.h b/include/linux/shm.h
70591index 429c199..4d42e38 100644
70592--- a/include/linux/shm.h
70593+++ b/include/linux/shm.h
70594@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
70595
70596 /* The task created the shm object. NULL if the task is dead. */
70597 struct task_struct *shm_creator;
70598+#ifdef CONFIG_GRKERNSEC
70599+ time_t shm_createtime;
70600+ pid_t shm_lapid;
70601+#endif
70602 };
70603
70604 /* shm_mode upper byte flags */
70605diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
70606index 320e976..fd52553 100644
70607--- a/include/linux/skbuff.h
70608+++ b/include/linux/skbuff.h
70609@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
70610 extern struct sk_buff *__alloc_skb(unsigned int size,
70611 gfp_t priority, int flags, int node);
70612 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
70613-static inline struct sk_buff *alloc_skb(unsigned int size,
70614+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
70615 gfp_t priority)
70616 {
70617 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
70618@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
70619 */
70620 static inline int skb_queue_empty(const struct sk_buff_head *list)
70621 {
70622- return list->next == (struct sk_buff *)list;
70623+ return list->next == (const struct sk_buff *)list;
70624 }
70625
70626 /**
70627@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
70628 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70629 const struct sk_buff *skb)
70630 {
70631- return skb->next == (struct sk_buff *)list;
70632+ return skb->next == (const struct sk_buff *)list;
70633 }
70634
70635 /**
70636@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70637 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
70638 const struct sk_buff *skb)
70639 {
70640- return skb->prev == (struct sk_buff *)list;
70641+ return skb->prev == (const struct sk_buff *)list;
70642 }
70643
70644 /**
70645@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
70646 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
70647 */
70648 #ifndef NET_SKB_PAD
70649-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
70650+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
70651 #endif
70652
70653 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
70654@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
70655 int noblock, int *err);
70656 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
70657 struct poll_table_struct *wait);
70658-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
70659+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
70660 int offset, struct iovec *to,
70661 int size);
70662 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
70663diff --git a/include/linux/slab.h b/include/linux/slab.h
70664index 5d168d7..720bff3 100644
70665--- a/include/linux/slab.h
70666+++ b/include/linux/slab.h
70667@@ -12,13 +12,20 @@
70668 #include <linux/gfp.h>
70669 #include <linux/types.h>
70670 #include <linux/workqueue.h>
70671-
70672+#include <linux/err.h>
70673
70674 /*
70675 * Flags to pass to kmem_cache_create().
70676 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
70677 */
70678 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
70679+
70680+#ifdef CONFIG_PAX_USERCOPY_SLABS
70681+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
70682+#else
70683+#define SLAB_USERCOPY 0x00000000UL
70684+#endif
70685+
70686 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70687 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70688 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70689@@ -89,10 +96,13 @@
70690 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70691 * Both make kfree a no-op.
70692 */
70693-#define ZERO_SIZE_PTR ((void *)16)
70694+#define ZERO_SIZE_PTR \
70695+({ \
70696+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70697+ (void *)(-MAX_ERRNO-1L); \
70698+})
70699
70700-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70701- (unsigned long)ZERO_SIZE_PTR)
70702+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70703
70704 /*
70705 * Common fields provided in kmem_cache by all slab allocators
70706@@ -112,7 +122,7 @@ struct kmem_cache {
70707 unsigned int align; /* Alignment as calculated */
70708 unsigned long flags; /* Active flags on the slab */
70709 const char *name; /* Slab name for sysfs */
70710- int refcount; /* Use counter */
70711+ atomic_t refcount; /* Use counter */
70712 void (*ctor)(void *); /* Called on object slot creation */
70713 struct list_head list; /* List of all slab caches on the system */
70714 };
70715@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70716 void kfree(const void *);
70717 void kzfree(const void *);
70718 size_t ksize(const void *);
70719+const char *check_heap_object(const void *ptr, unsigned long n);
70720+bool is_usercopy_object(const void *ptr);
70721
70722 /*
70723 * Allocator specific definitions. These are mainly used to establish optimized
70724@@ -311,6 +323,7 @@ size_t ksize(const void *);
70725 * for general use, and so are not documented here. For a full list of
70726 * potential flags, always refer to linux/gfp.h.
70727 */
70728+
70729 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70730 {
70731 if (size != 0 && n > SIZE_MAX / size)
70732@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70733 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70734 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70735 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70736-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70737+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70738 #define kmalloc_track_caller(size, flags) \
70739 __kmalloc_track_caller(size, flags, _RET_IP_)
70740 #else
70741@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70742 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70743 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70744 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70745-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70746+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70747 #define kmalloc_node_track_caller(size, flags, node) \
70748 __kmalloc_node_track_caller(size, flags, node, \
70749 _RET_IP_)
70750diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70751index 8bb6e0e..8eb0dbe 100644
70752--- a/include/linux/slab_def.h
70753+++ b/include/linux/slab_def.h
70754@@ -52,7 +52,7 @@ struct kmem_cache {
70755 /* 4) cache creation/removal */
70756 const char *name;
70757 struct list_head list;
70758- int refcount;
70759+ atomic_t refcount;
70760 int object_size;
70761 int align;
70762
70763@@ -68,10 +68,10 @@ struct kmem_cache {
70764 unsigned long node_allocs;
70765 unsigned long node_frees;
70766 unsigned long node_overflow;
70767- atomic_t allochit;
70768- atomic_t allocmiss;
70769- atomic_t freehit;
70770- atomic_t freemiss;
70771+ atomic_unchecked_t allochit;
70772+ atomic_unchecked_t allocmiss;
70773+ atomic_unchecked_t freehit;
70774+ atomic_unchecked_t freemiss;
70775
70776 /*
70777 * If debugging is enabled, then the allocator can add additional
70778@@ -111,11 +111,16 @@ struct cache_sizes {
70779 #ifdef CONFIG_ZONE_DMA
70780 struct kmem_cache *cs_dmacachep;
70781 #endif
70782+
70783+#ifdef CONFIG_PAX_USERCOPY_SLABS
70784+ struct kmem_cache *cs_usercopycachep;
70785+#endif
70786+
70787 };
70788 extern struct cache_sizes malloc_sizes[];
70789
70790 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70791-void *__kmalloc(size_t size, gfp_t flags);
70792+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70793
70794 #ifdef CONFIG_TRACING
70795 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70796@@ -152,6 +157,13 @@ found:
70797 cachep = malloc_sizes[i].cs_dmacachep;
70798 else
70799 #endif
70800+
70801+#ifdef CONFIG_PAX_USERCOPY_SLABS
70802+ if (flags & GFP_USERCOPY)
70803+ cachep = malloc_sizes[i].cs_usercopycachep;
70804+ else
70805+#endif
70806+
70807 cachep = malloc_sizes[i].cs_cachep;
70808
70809 ret = kmem_cache_alloc_trace(cachep, flags, size);
70810@@ -162,7 +174,7 @@ found:
70811 }
70812
70813 #ifdef CONFIG_NUMA
70814-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70815+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70816 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70817
70818 #ifdef CONFIG_TRACING
70819@@ -205,6 +217,13 @@ found:
70820 cachep = malloc_sizes[i].cs_dmacachep;
70821 else
70822 #endif
70823+
70824+#ifdef CONFIG_PAX_USERCOPY_SLABS
70825+ if (flags & GFP_USERCOPY)
70826+ cachep = malloc_sizes[i].cs_usercopycachep;
70827+ else
70828+#endif
70829+
70830 cachep = malloc_sizes[i].cs_cachep;
70831
70832 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70833diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70834index f28e14a..7831211 100644
70835--- a/include/linux/slob_def.h
70836+++ b/include/linux/slob_def.h
70837@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70838 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70839 }
70840
70841-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70842+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70843
70844 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70845 {
70846@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70847 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70848 }
70849
70850-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70851+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70852 {
70853 return kmalloc(size, flags);
70854 }
70855diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70856index 9db4825..ed42fb5 100644
70857--- a/include/linux/slub_def.h
70858+++ b/include/linux/slub_def.h
70859@@ -91,7 +91,7 @@ struct kmem_cache {
70860 struct kmem_cache_order_objects max;
70861 struct kmem_cache_order_objects min;
70862 gfp_t allocflags; /* gfp flags to use on each alloc */
70863- int refcount; /* Refcount for slab cache destroy */
70864+ atomic_t refcount; /* Refcount for slab cache destroy */
70865 void (*ctor)(void *);
70866 int inuse; /* Offset to metadata */
70867 int align; /* Alignment */
70868@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70869 * Sorry that the following has to be that ugly but some versions of GCC
70870 * have trouble with constant propagation and loops.
70871 */
70872-static __always_inline int kmalloc_index(size_t size)
70873+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70874 {
70875 if (!size)
70876 return 0;
70877@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70878 }
70879
70880 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70881-void *__kmalloc(size_t size, gfp_t flags);
70882+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70883
70884 static __always_inline void *
70885 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70886@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70887 }
70888 #endif
70889
70890-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70891+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70892 {
70893 unsigned int order = get_order(size);
70894 return kmalloc_order_trace(size, flags, order);
70895@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70896 }
70897
70898 #ifdef CONFIG_NUMA
70899-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70900+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70901 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70902
70903 #ifdef CONFIG_TRACING
70904diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70905index e8d702e..0a56eb4 100644
70906--- a/include/linux/sock_diag.h
70907+++ b/include/linux/sock_diag.h
70908@@ -10,7 +10,7 @@ struct sock;
70909 struct sock_diag_handler {
70910 __u8 family;
70911 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70912-};
70913+} __do_const;
70914
70915 int sock_diag_register(const struct sock_diag_handler *h);
70916 void sock_diag_unregister(const struct sock_diag_handler *h);
70917diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70918index 680f9a3..f13aeb0 100644
70919--- a/include/linux/sonet.h
70920+++ b/include/linux/sonet.h
70921@@ -7,7 +7,7 @@
70922 #include <uapi/linux/sonet.h>
70923
70924 struct k_sonet_stats {
70925-#define __HANDLE_ITEM(i) atomic_t i
70926+#define __HANDLE_ITEM(i) atomic_unchecked_t i
70927 __SONET_ITEMS
70928 #undef __HANDLE_ITEM
70929 };
70930diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70931index 34206b8..3db7f1c 100644
70932--- a/include/linux/sunrpc/clnt.h
70933+++ b/include/linux/sunrpc/clnt.h
70934@@ -96,7 +96,7 @@ struct rpc_procinfo {
70935 unsigned int p_timer; /* Which RTT timer to use */
70936 u32 p_statidx; /* Which procedure to account */
70937 const char * p_name; /* name of procedure */
70938-};
70939+} __do_const;
70940
70941 #ifdef __KERNEL__
70942
70943@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70944 {
70945 switch (sap->sa_family) {
70946 case AF_INET:
70947- return ntohs(((struct sockaddr_in *)sap)->sin_port);
70948+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70949 case AF_INET6:
70950- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70951+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70952 }
70953 return 0;
70954 }
70955@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70956 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70957 const struct sockaddr *src)
70958 {
70959- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70960+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
70961 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
70962
70963 dsin->sin_family = ssin->sin_family;
70964@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
70965 if (sa->sa_family != AF_INET6)
70966 return 0;
70967
70968- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
70969+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
70970 }
70971
70972 #endif /* __KERNEL__ */
70973diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
70974index 676ddf5..4c519a1 100644
70975--- a/include/linux/sunrpc/svc.h
70976+++ b/include/linux/sunrpc/svc.h
70977@@ -410,7 +410,7 @@ struct svc_procedure {
70978 unsigned int pc_count; /* call count */
70979 unsigned int pc_cachetype; /* cache info (NFS) */
70980 unsigned int pc_xdrressize; /* maximum size of XDR reply */
70981-};
70982+} __do_const;
70983
70984 /*
70985 * Function prototypes.
70986diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
70987index 0b8e3e6..33e0a01 100644
70988--- a/include/linux/sunrpc/svc_rdma.h
70989+++ b/include/linux/sunrpc/svc_rdma.h
70990@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
70991 extern unsigned int svcrdma_max_requests;
70992 extern unsigned int svcrdma_max_req_size;
70993
70994-extern atomic_t rdma_stat_recv;
70995-extern atomic_t rdma_stat_read;
70996-extern atomic_t rdma_stat_write;
70997-extern atomic_t rdma_stat_sq_starve;
70998-extern atomic_t rdma_stat_rq_starve;
70999-extern atomic_t rdma_stat_rq_poll;
71000-extern atomic_t rdma_stat_rq_prod;
71001-extern atomic_t rdma_stat_sq_poll;
71002-extern atomic_t rdma_stat_sq_prod;
71003+extern atomic_unchecked_t rdma_stat_recv;
71004+extern atomic_unchecked_t rdma_stat_read;
71005+extern atomic_unchecked_t rdma_stat_write;
71006+extern atomic_unchecked_t rdma_stat_sq_starve;
71007+extern atomic_unchecked_t rdma_stat_rq_starve;
71008+extern atomic_unchecked_t rdma_stat_rq_poll;
71009+extern atomic_unchecked_t rdma_stat_rq_prod;
71010+extern atomic_unchecked_t rdma_stat_sq_poll;
71011+extern atomic_unchecked_t rdma_stat_sq_prod;
71012
71013 #define RPCRDMA_VERSION 1
71014
71015diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
71016index dd74084a..7f509d5 100644
71017--- a/include/linux/sunrpc/svcauth.h
71018+++ b/include/linux/sunrpc/svcauth.h
71019@@ -109,7 +109,7 @@ struct auth_ops {
71020 int (*release)(struct svc_rqst *rq);
71021 void (*domain_release)(struct auth_domain *);
71022 int (*set_client)(struct svc_rqst *rq);
71023-};
71024+} __do_const;
71025
71026 #define SVC_GARBAGE 1
71027 #define SVC_SYSERR 2
71028diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
71029index 071d62c..4ccc7ac 100644
71030--- a/include/linux/swiotlb.h
71031+++ b/include/linux/swiotlb.h
71032@@ -59,7 +59,8 @@ extern void
71033
71034 extern void
71035 swiotlb_free_coherent(struct device *hwdev, size_t size,
71036- void *vaddr, dma_addr_t dma_handle);
71037+ void *vaddr, dma_addr_t dma_handle,
71038+ struct dma_attrs *attrs);
71039
71040 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
71041 unsigned long offset, size_t size,
71042diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
71043index 27b3b0b..e093dd9 100644
71044--- a/include/linux/syscore_ops.h
71045+++ b/include/linux/syscore_ops.h
71046@@ -16,7 +16,7 @@ struct syscore_ops {
71047 int (*suspend)(void);
71048 void (*resume)(void);
71049 void (*shutdown)(void);
71050-};
71051+} __do_const;
71052
71053 extern void register_syscore_ops(struct syscore_ops *ops);
71054 extern void unregister_syscore_ops(struct syscore_ops *ops);
71055diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
71056index 14a8ff2..af52bad 100644
71057--- a/include/linux/sysctl.h
71058+++ b/include/linux/sysctl.h
71059@@ -34,13 +34,13 @@ struct ctl_table_root;
71060 struct ctl_table_header;
71061 struct ctl_dir;
71062
71063-typedef struct ctl_table ctl_table;
71064-
71065 typedef int proc_handler (struct ctl_table *ctl, int write,
71066 void __user *buffer, size_t *lenp, loff_t *ppos);
71067
71068 extern int proc_dostring(struct ctl_table *, int,
71069 void __user *, size_t *, loff_t *);
71070+extern int proc_dostring_modpriv(struct ctl_table *, int,
71071+ void __user *, size_t *, loff_t *);
71072 extern int proc_dointvec(struct ctl_table *, int,
71073 void __user *, size_t *, loff_t *);
71074 extern int proc_dointvec_minmax(struct ctl_table *, int,
71075@@ -115,7 +115,9 @@ struct ctl_table
71076 struct ctl_table_poll *poll;
71077 void *extra1;
71078 void *extra2;
71079-};
71080+} __do_const;
71081+typedef struct ctl_table __no_const ctl_table_no_const;
71082+typedef struct ctl_table ctl_table;
71083
71084 struct ctl_node {
71085 struct rb_node node;
71086diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
71087index 381f06d..dc16cc7 100644
71088--- a/include/linux/sysfs.h
71089+++ b/include/linux/sysfs.h
71090@@ -31,7 +31,8 @@ struct attribute {
71091 struct lock_class_key *key;
71092 struct lock_class_key skey;
71093 #endif
71094-};
71095+} __do_const;
71096+typedef struct attribute __no_const attribute_no_const;
71097
71098 /**
71099 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
71100@@ -59,8 +60,8 @@ struct attribute_group {
71101 umode_t (*is_visible)(struct kobject *,
71102 struct attribute *, int);
71103 struct attribute **attrs;
71104-};
71105-
71106+} __do_const;
71107+typedef struct attribute_group __no_const attribute_group_no_const;
71108
71109
71110 /**
71111@@ -107,7 +108,8 @@ struct bin_attribute {
71112 char *, loff_t, size_t);
71113 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
71114 struct vm_area_struct *vma);
71115-};
71116+} __do_const;
71117+typedef struct bin_attribute __no_const bin_attribute_no_const;
71118
71119 /**
71120 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
71121diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
71122index 7faf933..4657127 100644
71123--- a/include/linux/sysrq.h
71124+++ b/include/linux/sysrq.h
71125@@ -15,7 +15,9 @@
71126 #define _LINUX_SYSRQ_H
71127
71128 #include <linux/errno.h>
71129+#include <linux/compiler.h>
71130 #include <linux/types.h>
71131+#include <linux/compiler.h>
71132
71133 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
71134 #define SYSRQ_DEFAULT_ENABLE 1
71135@@ -36,7 +38,7 @@ struct sysrq_key_op {
71136 char *help_msg;
71137 char *action_msg;
71138 int enable_mask;
71139-};
71140+} __do_const;
71141
71142 #ifdef CONFIG_MAGIC_SYSRQ
71143
71144diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
71145index e7e0473..39b7b52 100644
71146--- a/include/linux/thread_info.h
71147+++ b/include/linux/thread_info.h
71148@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
71149 #error "no set_restore_sigmask() provided and default one won't work"
71150 #endif
71151
71152+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
71153+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
71154+{
71155+#ifndef CONFIG_PAX_USERCOPY_DEBUG
71156+ if (!__builtin_constant_p(n))
71157+#endif
71158+ __check_object_size(ptr, n, to);
71159+}
71160+
71161 #endif /* __KERNEL__ */
71162
71163 #endif /* _LINUX_THREAD_INFO_H */
71164diff --git a/include/linux/tty.h b/include/linux/tty.h
71165index 8db1b56..c16a040 100644
71166--- a/include/linux/tty.h
71167+++ b/include/linux/tty.h
71168@@ -194,7 +194,7 @@ struct tty_port {
71169 const struct tty_port_operations *ops; /* Port operations */
71170 spinlock_t lock; /* Lock protecting tty field */
71171 int blocked_open; /* Waiting to open */
71172- int count; /* Usage count */
71173+ atomic_t count; /* Usage count */
71174 wait_queue_head_t open_wait; /* Open waiters */
71175 wait_queue_head_t close_wait; /* Close waiters */
71176 wait_queue_head_t delta_msr_wait; /* Modem status change */
71177@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
71178 struct tty_struct *tty, struct file *filp);
71179 static inline int tty_port_users(struct tty_port *port)
71180 {
71181- return port->count + port->blocked_open;
71182+ return atomic_read(&port->count) + port->blocked_open;
71183 }
71184
71185 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
71186diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
71187index dd976cf..e272742 100644
71188--- a/include/linux/tty_driver.h
71189+++ b/include/linux/tty_driver.h
71190@@ -284,7 +284,7 @@ struct tty_operations {
71191 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
71192 #endif
71193 const struct file_operations *proc_fops;
71194-};
71195+} __do_const;
71196
71197 struct tty_driver {
71198 int magic; /* magic number for this structure */
71199diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
71200index fb79dd8d..07d4773 100644
71201--- a/include/linux/tty_ldisc.h
71202+++ b/include/linux/tty_ldisc.h
71203@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
71204
71205 struct module *owner;
71206
71207- int refcount;
71208+ atomic_t refcount;
71209 };
71210
71211 struct tty_ldisc {
71212diff --git a/include/linux/types.h b/include/linux/types.h
71213index 4d118ba..c3ee9bf 100644
71214--- a/include/linux/types.h
71215+++ b/include/linux/types.h
71216@@ -176,10 +176,26 @@ typedef struct {
71217 int counter;
71218 } atomic_t;
71219
71220+#ifdef CONFIG_PAX_REFCOUNT
71221+typedef struct {
71222+ int counter;
71223+} atomic_unchecked_t;
71224+#else
71225+typedef atomic_t atomic_unchecked_t;
71226+#endif
71227+
71228 #ifdef CONFIG_64BIT
71229 typedef struct {
71230 long counter;
71231 } atomic64_t;
71232+
71233+#ifdef CONFIG_PAX_REFCOUNT
71234+typedef struct {
71235+ long counter;
71236+} atomic64_unchecked_t;
71237+#else
71238+typedef atomic64_t atomic64_unchecked_t;
71239+#endif
71240 #endif
71241
71242 struct list_head {
71243diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
71244index 5ca0951..ab496a5 100644
71245--- a/include/linux/uaccess.h
71246+++ b/include/linux/uaccess.h
71247@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
71248 long ret; \
71249 mm_segment_t old_fs = get_fs(); \
71250 \
71251- set_fs(KERNEL_DS); \
71252 pagefault_disable(); \
71253- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
71254- pagefault_enable(); \
71255+ set_fs(KERNEL_DS); \
71256+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
71257 set_fs(old_fs); \
71258+ pagefault_enable(); \
71259 ret; \
71260 })
71261
71262diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
71263index 8e522cbc..aa8572d 100644
71264--- a/include/linux/uidgid.h
71265+++ b/include/linux/uidgid.h
71266@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
71267
71268 #endif /* CONFIG_USER_NS */
71269
71270+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
71271+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
71272+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
71273+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
71274+
71275 #endif /* _LINUX_UIDGID_H */
71276diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
71277index 99c1b4d..562e6f3 100644
71278--- a/include/linux/unaligned/access_ok.h
71279+++ b/include/linux/unaligned/access_ok.h
71280@@ -4,34 +4,34 @@
71281 #include <linux/kernel.h>
71282 #include <asm/byteorder.h>
71283
71284-static inline u16 get_unaligned_le16(const void *p)
71285+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
71286 {
71287- return le16_to_cpup((__le16 *)p);
71288+ return le16_to_cpup((const __le16 *)p);
71289 }
71290
71291-static inline u32 get_unaligned_le32(const void *p)
71292+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
71293 {
71294- return le32_to_cpup((__le32 *)p);
71295+ return le32_to_cpup((const __le32 *)p);
71296 }
71297
71298-static inline u64 get_unaligned_le64(const void *p)
71299+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
71300 {
71301- return le64_to_cpup((__le64 *)p);
71302+ return le64_to_cpup((const __le64 *)p);
71303 }
71304
71305-static inline u16 get_unaligned_be16(const void *p)
71306+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
71307 {
71308- return be16_to_cpup((__be16 *)p);
71309+ return be16_to_cpup((const __be16 *)p);
71310 }
71311
71312-static inline u32 get_unaligned_be32(const void *p)
71313+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
71314 {
71315- return be32_to_cpup((__be32 *)p);
71316+ return be32_to_cpup((const __be32 *)p);
71317 }
71318
71319-static inline u64 get_unaligned_be64(const void *p)
71320+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
71321 {
71322- return be64_to_cpup((__be64 *)p);
71323+ return be64_to_cpup((const __be64 *)p);
71324 }
71325
71326 static inline void put_unaligned_le16(u16 val, void *p)
71327diff --git a/include/linux/usb.h b/include/linux/usb.h
71328index 4d22d0f..8d0e8f8 100644
71329--- a/include/linux/usb.h
71330+++ b/include/linux/usb.h
71331@@ -554,7 +554,7 @@ struct usb_device {
71332 int maxchild;
71333
71334 u32 quirks;
71335- atomic_t urbnum;
71336+ atomic_unchecked_t urbnum;
71337
71338 unsigned long active_duration;
71339
71340@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
71341
71342 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
71343 __u8 request, __u8 requesttype, __u16 value, __u16 index,
71344- void *data, __u16 size, int timeout);
71345+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
71346 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
71347 void *data, int len, int *actual_length, int timeout);
71348 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
71349diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
71350index c5d36c6..108f4f9 100644
71351--- a/include/linux/usb/renesas_usbhs.h
71352+++ b/include/linux/usb/renesas_usbhs.h
71353@@ -39,7 +39,7 @@ enum {
71354 */
71355 struct renesas_usbhs_driver_callback {
71356 int (*notify_hotplug)(struct platform_device *pdev);
71357-};
71358+} __no_const;
71359
71360 /*
71361 * callback functions for platform
71362diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
71363index b9bd2e6..4ce0093 100644
71364--- a/include/linux/user_namespace.h
71365+++ b/include/linux/user_namespace.h
71366@@ -21,7 +21,7 @@ struct user_namespace {
71367 struct uid_gid_map uid_map;
71368 struct uid_gid_map gid_map;
71369 struct uid_gid_map projid_map;
71370- struct kref kref;
71371+ atomic_t count;
71372 struct user_namespace *parent;
71373 kuid_t owner;
71374 kgid_t group;
71375@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
71376 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
71377 {
71378 if (ns)
71379- kref_get(&ns->kref);
71380+ atomic_inc(&ns->count);
71381 return ns;
71382 }
71383
71384 extern int create_user_ns(struct cred *new);
71385 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
71386-extern void free_user_ns(struct kref *kref);
71387+extern void free_user_ns(struct user_namespace *ns);
71388
71389 static inline void put_user_ns(struct user_namespace *ns)
71390 {
71391- if (ns)
71392- kref_put(&ns->kref, free_user_ns);
71393+ if (ns && atomic_dec_and_test(&ns->count))
71394+ free_user_ns(ns);
71395 }
71396
71397 struct seq_operations;
71398diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
71399index 6f8fbcf..8259001 100644
71400--- a/include/linux/vermagic.h
71401+++ b/include/linux/vermagic.h
71402@@ -25,9 +25,35 @@
71403 #define MODULE_ARCH_VERMAGIC ""
71404 #endif
71405
71406+#ifdef CONFIG_PAX_REFCOUNT
71407+#define MODULE_PAX_REFCOUNT "REFCOUNT "
71408+#else
71409+#define MODULE_PAX_REFCOUNT ""
71410+#endif
71411+
71412+#ifdef CONSTIFY_PLUGIN
71413+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
71414+#else
71415+#define MODULE_CONSTIFY_PLUGIN ""
71416+#endif
71417+
71418+#ifdef STACKLEAK_PLUGIN
71419+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
71420+#else
71421+#define MODULE_STACKLEAK_PLUGIN ""
71422+#endif
71423+
71424+#ifdef CONFIG_GRKERNSEC
71425+#define MODULE_GRSEC "GRSEC "
71426+#else
71427+#define MODULE_GRSEC ""
71428+#endif
71429+
71430 #define VERMAGIC_STRING \
71431 UTS_RELEASE " " \
71432 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
71433 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
71434- MODULE_ARCH_VERMAGIC
71435+ MODULE_ARCH_VERMAGIC \
71436+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
71437+ MODULE_GRSEC
71438
71439diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
71440index 6071e91..ca6a489 100644
71441--- a/include/linux/vmalloc.h
71442+++ b/include/linux/vmalloc.h
71443@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
71444 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
71445 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
71446 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
71447+
71448+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71449+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
71450+#endif
71451+
71452 /* bits [20..32] reserved for arch specific ioremap internals */
71453
71454 /*
71455@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
71456 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
71457 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
71458 unsigned long start, unsigned long end, gfp_t gfp_mask,
71459- pgprot_t prot, int node, const void *caller);
71460+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
71461 extern void vfree(const void *addr);
71462
71463 extern void *vmap(struct page **pages, unsigned int count,
71464@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
71465 extern void free_vm_area(struct vm_struct *area);
71466
71467 /* for /dev/kmem */
71468-extern long vread(char *buf, char *addr, unsigned long count);
71469-extern long vwrite(char *buf, char *addr, unsigned long count);
71470+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
71471+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
71472
71473 /*
71474 * Internals. Dont't use..
71475diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
71476index a13291f..af51fa3 100644
71477--- a/include/linux/vmstat.h
71478+++ b/include/linux/vmstat.h
71479@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
71480 /*
71481 * Zone based page accounting with per cpu differentials.
71482 */
71483-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71484+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71485
71486 static inline void zone_page_state_add(long x, struct zone *zone,
71487 enum zone_stat_item item)
71488 {
71489- atomic_long_add(x, &zone->vm_stat[item]);
71490- atomic_long_add(x, &vm_stat[item]);
71491+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
71492+ atomic_long_add_unchecked(x, &vm_stat[item]);
71493 }
71494
71495 static inline unsigned long global_page_state(enum zone_stat_item item)
71496 {
71497- long x = atomic_long_read(&vm_stat[item]);
71498+ long x = atomic_long_read_unchecked(&vm_stat[item]);
71499 #ifdef CONFIG_SMP
71500 if (x < 0)
71501 x = 0;
71502@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
71503 static inline unsigned long zone_page_state(struct zone *zone,
71504 enum zone_stat_item item)
71505 {
71506- long x = atomic_long_read(&zone->vm_stat[item]);
71507+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71508 #ifdef CONFIG_SMP
71509 if (x < 0)
71510 x = 0;
71511@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
71512 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
71513 enum zone_stat_item item)
71514 {
71515- long x = atomic_long_read(&zone->vm_stat[item]);
71516+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71517
71518 #ifdef CONFIG_SMP
71519 int cpu;
71520@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
71521
71522 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
71523 {
71524- atomic_long_inc(&zone->vm_stat[item]);
71525- atomic_long_inc(&vm_stat[item]);
71526+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
71527+ atomic_long_inc_unchecked(&vm_stat[item]);
71528 }
71529
71530 static inline void __inc_zone_page_state(struct page *page,
71531@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
71532
71533 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
71534 {
71535- atomic_long_dec(&zone->vm_stat[item]);
71536- atomic_long_dec(&vm_stat[item]);
71537+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
71538+ atomic_long_dec_unchecked(&vm_stat[item]);
71539 }
71540
71541 static inline void __dec_zone_page_state(struct page *page,
71542diff --git a/include/linux/xattr.h b/include/linux/xattr.h
71543index fdbafc6..b7ffd47 100644
71544--- a/include/linux/xattr.h
71545+++ b/include/linux/xattr.h
71546@@ -28,7 +28,7 @@ struct xattr_handler {
71547 size_t size, int handler_flags);
71548 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
71549 size_t size, int flags, int handler_flags);
71550-};
71551+} __do_const;
71552
71553 struct xattr {
71554 char *name;
71555diff --git a/include/linux/zlib.h b/include/linux/zlib.h
71556index 9c5a6b4..09c9438 100644
71557--- a/include/linux/zlib.h
71558+++ b/include/linux/zlib.h
71559@@ -31,6 +31,7 @@
71560 #define _ZLIB_H
71561
71562 #include <linux/zconf.h>
71563+#include <linux/compiler.h>
71564
71565 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
71566 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
71567@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
71568
71569 /* basic functions */
71570
71571-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
71572+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
71573 /*
71574 Returns the number of bytes that needs to be allocated for a per-
71575 stream workspace with the specified parameters. A pointer to this
71576diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
71577index 95d1c91..6798cca 100644
71578--- a/include/media/v4l2-dev.h
71579+++ b/include/media/v4l2-dev.h
71580@@ -76,7 +76,7 @@ struct v4l2_file_operations {
71581 int (*mmap) (struct file *, struct vm_area_struct *);
71582 int (*open) (struct file *);
71583 int (*release) (struct file *);
71584-};
71585+} __do_const;
71586
71587 /*
71588 * Newer version of video_device, handled by videodev2.c
71589diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
71590index 4118ad1..cb7e25f 100644
71591--- a/include/media/v4l2-ioctl.h
71592+++ b/include/media/v4l2-ioctl.h
71593@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
71594 bool valid_prio, int cmd, void *arg);
71595 };
71596
71597-
71598 /* v4l debugging and diagnostics */
71599
71600 /* Debug bitmask flags to be used on V4L2 */
71601diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
71602index adcbb20..62c2559 100644
71603--- a/include/net/9p/transport.h
71604+++ b/include/net/9p/transport.h
71605@@ -57,7 +57,7 @@ struct p9_trans_module {
71606 int (*cancel) (struct p9_client *, struct p9_req_t *req);
71607 int (*zc_request)(struct p9_client *, struct p9_req_t *,
71608 char *, char *, int , int, int, int);
71609-};
71610+} __do_const;
71611
71612 void v9fs_register_trans(struct p9_trans_module *m);
71613 void v9fs_unregister_trans(struct p9_trans_module *m);
71614diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
71615index 7588ef4..e62d35f 100644
71616--- a/include/net/bluetooth/l2cap.h
71617+++ b/include/net/bluetooth/l2cap.h
71618@@ -552,7 +552,7 @@ struct l2cap_ops {
71619 void (*defer) (struct l2cap_chan *chan);
71620 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
71621 unsigned long len, int nb);
71622-};
71623+} __do_const;
71624
71625 struct l2cap_conn {
71626 struct hci_conn *hcon;
71627diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
71628index 9e5425b..8136ffc 100644
71629--- a/include/net/caif/cfctrl.h
71630+++ b/include/net/caif/cfctrl.h
71631@@ -52,7 +52,7 @@ struct cfctrl_rsp {
71632 void (*radioset_rsp)(void);
71633 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
71634 struct cflayer *client_layer);
71635-};
71636+} __no_const;
71637
71638 /* Link Setup Parameters for CAIF-Links. */
71639 struct cfctrl_link_param {
71640@@ -101,8 +101,8 @@ struct cfctrl_request_info {
71641 struct cfctrl {
71642 struct cfsrvl serv;
71643 struct cfctrl_rsp res;
71644- atomic_t req_seq_no;
71645- atomic_t rsp_seq_no;
71646+ atomic_unchecked_t req_seq_no;
71647+ atomic_unchecked_t rsp_seq_no;
71648 struct list_head list;
71649 /* Protects from simultaneous access to first_req list */
71650 spinlock_t info_list_lock;
71651diff --git a/include/net/flow.h b/include/net/flow.h
71652index 628e11b..4c475df 100644
71653--- a/include/net/flow.h
71654+++ b/include/net/flow.h
71655@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
71656
71657 extern void flow_cache_flush(void);
71658 extern void flow_cache_flush_deferred(void);
71659-extern atomic_t flow_cache_genid;
71660+extern atomic_unchecked_t flow_cache_genid;
71661
71662 #endif
71663diff --git a/include/net/genetlink.h b/include/net/genetlink.h
71664index bdfbe68..4402ebe 100644
71665--- a/include/net/genetlink.h
71666+++ b/include/net/genetlink.h
71667@@ -118,7 +118,7 @@ struct genl_ops {
71668 struct netlink_callback *cb);
71669 int (*done)(struct netlink_callback *cb);
71670 struct list_head ops_list;
71671-};
71672+} __do_const;
71673
71674 extern int genl_register_family(struct genl_family *family);
71675 extern int genl_register_family_with_ops(struct genl_family *family,
71676diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
71677index e5062c9..48a9a4b 100644
71678--- a/include/net/gro_cells.h
71679+++ b/include/net/gro_cells.h
71680@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
71681 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
71682
71683 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
71684- atomic_long_inc(&dev->rx_dropped);
71685+ atomic_long_inc_unchecked(&dev->rx_dropped);
71686 kfree_skb(skb);
71687 return;
71688 }
71689@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
71690 int i;
71691
71692 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
71693- gcells->cells = kcalloc(sizeof(struct gro_cell),
71694- gcells->gro_cells_mask + 1,
71695+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
71696+ sizeof(struct gro_cell),
71697 GFP_KERNEL);
71698 if (!gcells->cells)
71699 return -ENOMEM;
71700diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
71701index 1832927..ce39aea 100644
71702--- a/include/net/inet_connection_sock.h
71703+++ b/include/net/inet_connection_sock.h
71704@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
71705 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
71706 int (*bind_conflict)(const struct sock *sk,
71707 const struct inet_bind_bucket *tb, bool relax);
71708-};
71709+} __do_const;
71710
71711 /** inet_connection_sock - INET connection oriented sock
71712 *
71713diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
71714index 53f464d..ba76aaa 100644
71715--- a/include/net/inetpeer.h
71716+++ b/include/net/inetpeer.h
71717@@ -47,8 +47,8 @@ struct inet_peer {
71718 */
71719 union {
71720 struct {
71721- atomic_t rid; /* Frag reception counter */
71722- atomic_t ip_id_count; /* IP ID for the next packet */
71723+ atomic_unchecked_t rid; /* Frag reception counter */
71724+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71725 };
71726 struct rcu_head rcu;
71727 struct inet_peer *gc_next;
71728@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71729 more++;
71730 inet_peer_refcheck(p);
71731 do {
71732- old = atomic_read(&p->ip_id_count);
71733+ old = atomic_read_unchecked(&p->ip_id_count);
71734 new = old + more;
71735 if (!new)
71736 new = 1;
71737- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71738+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71739 return new;
71740 }
71741
71742diff --git a/include/net/ip.h b/include/net/ip.h
71743index a68f838..74518ab 100644
71744--- a/include/net/ip.h
71745+++ b/include/net/ip.h
71746@@ -202,7 +202,7 @@ extern struct local_ports {
71747 } sysctl_local_ports;
71748 extern void inet_get_local_port_range(int *low, int *high);
71749
71750-extern unsigned long *sysctl_local_reserved_ports;
71751+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71752 static inline int inet_is_reserved_local_port(int port)
71753 {
71754 return test_bit(port, sysctl_local_reserved_ports);
71755diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71756index 9497be1..5a4fafe 100644
71757--- a/include/net/ip_fib.h
71758+++ b/include/net/ip_fib.h
71759@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71760
71761 #define FIB_RES_SADDR(net, res) \
71762 ((FIB_RES_NH(res).nh_saddr_genid == \
71763- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71764+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71765 FIB_RES_NH(res).nh_saddr : \
71766 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71767 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71768diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71769index 68c69d5..bdab192 100644
71770--- a/include/net/ip_vs.h
71771+++ b/include/net/ip_vs.h
71772@@ -599,7 +599,7 @@ struct ip_vs_conn {
71773 struct ip_vs_conn *control; /* Master control connection */
71774 atomic_t n_control; /* Number of controlled ones */
71775 struct ip_vs_dest *dest; /* real server */
71776- atomic_t in_pkts; /* incoming packet counter */
71777+ atomic_unchecked_t in_pkts; /* incoming packet counter */
71778
71779 /* packet transmitter for different forwarding methods. If it
71780 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71781@@ -737,7 +737,7 @@ struct ip_vs_dest {
71782 __be16 port; /* port number of the server */
71783 union nf_inet_addr addr; /* IP address of the server */
71784 volatile unsigned int flags; /* dest status flags */
71785- atomic_t conn_flags; /* flags to copy to conn */
71786+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
71787 atomic_t weight; /* server weight */
71788
71789 atomic_t refcnt; /* reference counter */
71790@@ -980,11 +980,11 @@ struct netns_ipvs {
71791 /* ip_vs_lblc */
71792 int sysctl_lblc_expiration;
71793 struct ctl_table_header *lblc_ctl_header;
71794- struct ctl_table *lblc_ctl_table;
71795+ ctl_table_no_const *lblc_ctl_table;
71796 /* ip_vs_lblcr */
71797 int sysctl_lblcr_expiration;
71798 struct ctl_table_header *lblcr_ctl_header;
71799- struct ctl_table *lblcr_ctl_table;
71800+ ctl_table_no_const *lblcr_ctl_table;
71801 /* ip_vs_est */
71802 struct list_head est_list; /* estimator list */
71803 spinlock_t est_lock;
71804diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71805index 80ffde3..968b0f4 100644
71806--- a/include/net/irda/ircomm_tty.h
71807+++ b/include/net/irda/ircomm_tty.h
71808@@ -35,6 +35,7 @@
71809 #include <linux/termios.h>
71810 #include <linux/timer.h>
71811 #include <linux/tty.h> /* struct tty_struct */
71812+#include <asm/local.h>
71813
71814 #include <net/irda/irias_object.h>
71815 #include <net/irda/ircomm_core.h>
71816diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71817index cc7c197..9f2da2a 100644
71818--- a/include/net/iucv/af_iucv.h
71819+++ b/include/net/iucv/af_iucv.h
71820@@ -141,7 +141,7 @@ struct iucv_sock {
71821 struct iucv_sock_list {
71822 struct hlist_head head;
71823 rwlock_t lock;
71824- atomic_t autobind_name;
71825+ atomic_unchecked_t autobind_name;
71826 };
71827
71828 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71829diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71830index df83f69..9b640b8 100644
71831--- a/include/net/llc_c_ac.h
71832+++ b/include/net/llc_c_ac.h
71833@@ -87,7 +87,7 @@
71834 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
71835 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
71836
71837-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71838+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71839
71840 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
71841 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71842diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71843index 6ca3113..f8026dd 100644
71844--- a/include/net/llc_c_ev.h
71845+++ b/include/net/llc_c_ev.h
71846@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71847 return (struct llc_conn_state_ev *)skb->cb;
71848 }
71849
71850-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71851-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71852+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71853+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71854
71855 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71856 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71857diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71858index 0e79cfb..f46db31 100644
71859--- a/include/net/llc_c_st.h
71860+++ b/include/net/llc_c_st.h
71861@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71862 u8 next_state;
71863 llc_conn_ev_qfyr_t *ev_qualifiers;
71864 llc_conn_action_t *ev_actions;
71865-};
71866+} __do_const;
71867
71868 struct llc_conn_state {
71869 u8 current_state;
71870diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71871index 37a3bbd..55a4241 100644
71872--- a/include/net/llc_s_ac.h
71873+++ b/include/net/llc_s_ac.h
71874@@ -23,7 +23,7 @@
71875 #define SAP_ACT_TEST_IND 9
71876
71877 /* All action functions must look like this */
71878-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71879+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71880
71881 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71882 struct sk_buff *skb);
71883diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71884index 567c681..cd73ac0 100644
71885--- a/include/net/llc_s_st.h
71886+++ b/include/net/llc_s_st.h
71887@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71888 llc_sap_ev_t ev;
71889 u8 next_state;
71890 llc_sap_action_t *ev_actions;
71891-};
71892+} __do_const;
71893
71894 struct llc_sap_state {
71895 u8 curr_state;
71896diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71897index ee50c5e..1bc3b1a 100644
71898--- a/include/net/mac80211.h
71899+++ b/include/net/mac80211.h
71900@@ -3996,7 +3996,7 @@ struct rate_control_ops {
71901 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71902 struct dentry *dir);
71903 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71904-};
71905+} __do_const;
71906
71907 static inline int rate_supported(struct ieee80211_sta *sta,
71908 enum ieee80211_band band,
71909diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71910index 0dab173..1b76af0 100644
71911--- a/include/net/neighbour.h
71912+++ b/include/net/neighbour.h
71913@@ -123,7 +123,7 @@ struct neigh_ops {
71914 void (*error_report)(struct neighbour *, struct sk_buff *);
71915 int (*output)(struct neighbour *, struct sk_buff *);
71916 int (*connected_output)(struct neighbour *, struct sk_buff *);
71917-};
71918+} __do_const;
71919
71920 struct pneigh_entry {
71921 struct pneigh_entry *next;
71922diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71923index de644bc..351fd4e 100644
71924--- a/include/net/net_namespace.h
71925+++ b/include/net/net_namespace.h
71926@@ -115,7 +115,7 @@ struct net {
71927 #endif
71928 struct netns_ipvs *ipvs;
71929 struct sock *diag_nlsk;
71930- atomic_t rt_genid;
71931+ atomic_unchecked_t rt_genid;
71932 };
71933
71934 /*
71935@@ -282,7 +282,7 @@ struct pernet_operations {
71936 void (*exit_batch)(struct list_head *net_exit_list);
71937 int *id;
71938 size_t size;
71939-};
71940+} __do_const;
71941
71942 /*
71943 * Use these carefully. If you implement a network device and it
71944@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71945
71946 static inline int rt_genid(struct net *net)
71947 {
71948- return atomic_read(&net->rt_genid);
71949+ return atomic_read_unchecked(&net->rt_genid);
71950 }
71951
71952 static inline void rt_genid_bump(struct net *net)
71953 {
71954- atomic_inc(&net->rt_genid);
71955+ atomic_inc_unchecked(&net->rt_genid);
71956 }
71957
71958 #endif /* __NET_NET_NAMESPACE_H */
71959diff --git a/include/net/netdma.h b/include/net/netdma.h
71960index 8ba8ce2..99b7fff 100644
71961--- a/include/net/netdma.h
71962+++ b/include/net/netdma.h
71963@@ -24,7 +24,7 @@
71964 #include <linux/dmaengine.h>
71965 #include <linux/skbuff.h>
71966
71967-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71968+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71969 struct sk_buff *skb, int offset, struct iovec *to,
71970 size_t len, struct dma_pinned_list *pinned_list);
71971
71972diff --git a/include/net/netlink.h b/include/net/netlink.h
71973index 9690b0f..87aded7 100644
71974--- a/include/net/netlink.h
71975+++ b/include/net/netlink.h
71976@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
71977 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
71978 {
71979 if (mark)
71980- skb_trim(skb, (unsigned char *) mark - skb->data);
71981+ skb_trim(skb, (const unsigned char *) mark - skb->data);
71982 }
71983
71984 /**
71985diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
71986index 923cb20..deae816 100644
71987--- a/include/net/netns/conntrack.h
71988+++ b/include/net/netns/conntrack.h
71989@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
71990 struct nf_proto_net {
71991 #ifdef CONFIG_SYSCTL
71992 struct ctl_table_header *ctl_table_header;
71993- struct ctl_table *ctl_table;
71994+ ctl_table_no_const *ctl_table;
71995 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
71996 struct ctl_table_header *ctl_compat_header;
71997- struct ctl_table *ctl_compat_table;
71998+ ctl_table_no_const *ctl_compat_table;
71999 #endif
72000 #endif
72001 unsigned int users;
72002@@ -58,7 +58,7 @@ struct nf_ip_net {
72003 struct nf_icmp_net icmpv6;
72004 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
72005 struct ctl_table_header *ctl_table_header;
72006- struct ctl_table *ctl_table;
72007+ ctl_table_no_const *ctl_table;
72008 #endif
72009 };
72010
72011diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
72012index 2ae2b83..dbdc85e 100644
72013--- a/include/net/netns/ipv4.h
72014+++ b/include/net/netns/ipv4.h
72015@@ -64,7 +64,7 @@ struct netns_ipv4 {
72016 kgid_t sysctl_ping_group_range[2];
72017 long sysctl_tcp_mem[3];
72018
72019- atomic_t dev_addr_genid;
72020+ atomic_unchecked_t dev_addr_genid;
72021
72022 #ifdef CONFIG_IP_MROUTE
72023 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
72024diff --git a/include/net/protocol.h b/include/net/protocol.h
72025index 047c047..b9dad15 100644
72026--- a/include/net/protocol.h
72027+++ b/include/net/protocol.h
72028@@ -44,7 +44,7 @@ struct net_protocol {
72029 void (*err_handler)(struct sk_buff *skb, u32 info);
72030 unsigned int no_policy:1,
72031 netns_ok:1;
72032-};
72033+} __do_const;
72034
72035 #if IS_ENABLED(CONFIG_IPV6)
72036 struct inet6_protocol {
72037@@ -57,7 +57,7 @@ struct inet6_protocol {
72038 u8 type, u8 code, int offset,
72039 __be32 info);
72040 unsigned int flags; /* INET6_PROTO_xxx */
72041-};
72042+} __do_const;
72043
72044 #define INET6_PROTO_NOPOLICY 0x1
72045 #define INET6_PROTO_FINAL 0x2
72046diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
72047index 5a15fab..d799ea7 100644
72048--- a/include/net/rtnetlink.h
72049+++ b/include/net/rtnetlink.h
72050@@ -81,7 +81,7 @@ struct rtnl_link_ops {
72051 const struct net_device *dev);
72052 unsigned int (*get_num_tx_queues)(void);
72053 unsigned int (*get_num_rx_queues)(void);
72054-};
72055+} __do_const;
72056
72057 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
72058 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
72059diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
72060index 7fdf298..197e9f7 100644
72061--- a/include/net/sctp/sctp.h
72062+++ b/include/net/sctp/sctp.h
72063@@ -330,9 +330,9 @@ do { \
72064
72065 #else /* SCTP_DEBUG */
72066
72067-#define SCTP_DEBUG_PRINTK(whatever...)
72068-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
72069-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
72070+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
72071+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
72072+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
72073 #define SCTP_ENABLE_DEBUG
72074 #define SCTP_DISABLE_DEBUG
72075 #define SCTP_ASSERT(expr, str, func)
72076diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
72077index 2a82d13..62a31c2 100644
72078--- a/include/net/sctp/sm.h
72079+++ b/include/net/sctp/sm.h
72080@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
72081 typedef struct {
72082 sctp_state_fn_t *fn;
72083 const char *name;
72084-} sctp_sm_table_entry_t;
72085+} __do_const sctp_sm_table_entry_t;
72086
72087 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
72088 * currently in use.
72089@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
72090 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
72091
72092 /* Extern declarations for major data structures. */
72093-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72094+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72095
72096
72097 /* Get the size of a DATA chunk payload. */
72098diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
72099index fdeb85a..1329d95 100644
72100--- a/include/net/sctp/structs.h
72101+++ b/include/net/sctp/structs.h
72102@@ -517,7 +517,7 @@ struct sctp_pf {
72103 struct sctp_association *asoc);
72104 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
72105 struct sctp_af *af;
72106-};
72107+} __do_const;
72108
72109
72110 /* Structure to track chunk fragments that have been acked, but peer
72111diff --git a/include/net/sock.h b/include/net/sock.h
72112index 25afaa0..8bb0070 100644
72113--- a/include/net/sock.h
72114+++ b/include/net/sock.h
72115@@ -322,7 +322,7 @@ struct sock {
72116 #ifdef CONFIG_RPS
72117 __u32 sk_rxhash;
72118 #endif
72119- atomic_t sk_drops;
72120+ atomic_unchecked_t sk_drops;
72121 int sk_rcvbuf;
72122
72123 struct sk_filter __rcu *sk_filter;
72124@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
72125 }
72126
72127 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
72128- char __user *from, char *to,
72129+ char __user *from, unsigned char *to,
72130 int copy, int offset)
72131 {
72132 if (skb->ip_summed == CHECKSUM_NONE) {
72133@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
72134 }
72135 }
72136
72137-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72138+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72139
72140 /**
72141 * sk_page_frag - return an appropriate page_frag
72142diff --git a/include/net/tcp.h b/include/net/tcp.h
72143index aed42c7..43890c6 100644
72144--- a/include/net/tcp.h
72145+++ b/include/net/tcp.h
72146@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
72147 extern void tcp_xmit_retransmit_queue(struct sock *);
72148 extern void tcp_simple_retransmit(struct sock *);
72149 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
72150-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72151+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72152
72153 extern void tcp_send_probe0(struct sock *);
72154 extern void tcp_send_partial(struct sock *);
72155@@ -701,8 +701,8 @@ struct tcp_skb_cb {
72156 struct inet6_skb_parm h6;
72157 #endif
72158 } header; /* For incoming frames */
72159- __u32 seq; /* Starting sequence number */
72160- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
72161+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
72162+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
72163 __u32 when; /* used to compute rtt's */
72164 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
72165
72166@@ -716,7 +716,7 @@ struct tcp_skb_cb {
72167
72168 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
72169 /* 1 byte hole */
72170- __u32 ack_seq; /* Sequence number ACK'd */
72171+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
72172 };
72173
72174 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
72175diff --git a/include/net/xfrm.h b/include/net/xfrm.h
72176index 63445ed..d6fc34f 100644
72177--- a/include/net/xfrm.h
72178+++ b/include/net/xfrm.h
72179@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
72180 struct net_device *dev,
72181 const struct flowi *fl);
72182 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
72183-};
72184+} __do_const;
72185
72186 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
72187 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
72188@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
72189 struct sk_buff *skb);
72190 int (*transport_finish)(struct sk_buff *skb,
72191 int async);
72192-};
72193+} __do_const;
72194
72195 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
72196 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
72197@@ -423,7 +423,7 @@ struct xfrm_mode {
72198 struct module *owner;
72199 unsigned int encap;
72200 int flags;
72201-};
72202+} __do_const;
72203
72204 /* Flags for xfrm_mode. */
72205 enum {
72206@@ -514,7 +514,7 @@ struct xfrm_policy {
72207 struct timer_list timer;
72208
72209 struct flow_cache_object flo;
72210- atomic_t genid;
72211+ atomic_unchecked_t genid;
72212 u32 priority;
72213 u32 index;
72214 struct xfrm_mark mark;
72215diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
72216index 1a046b1..ee0bef0 100644
72217--- a/include/rdma/iw_cm.h
72218+++ b/include/rdma/iw_cm.h
72219@@ -122,7 +122,7 @@ struct iw_cm_verbs {
72220 int backlog);
72221
72222 int (*destroy_listen)(struct iw_cm_id *cm_id);
72223-};
72224+} __no_const;
72225
72226 /**
72227 * iw_create_cm_id - Create an IW CM identifier.
72228diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
72229index 399162b..b337f1a 100644
72230--- a/include/scsi/libfc.h
72231+++ b/include/scsi/libfc.h
72232@@ -762,6 +762,7 @@ struct libfc_function_template {
72233 */
72234 void (*disc_stop_final) (struct fc_lport *);
72235 };
72236+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
72237
72238 /**
72239 * struct fc_disc - Discovery context
72240@@ -866,7 +867,7 @@ struct fc_lport {
72241 struct fc_vport *vport;
72242
72243 /* Operational Information */
72244- struct libfc_function_template tt;
72245+ libfc_function_template_no_const tt;
72246 u8 link_up;
72247 u8 qfull;
72248 enum fc_lport_state state;
72249diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
72250index e65c62e..aa2e5a2 100644
72251--- a/include/scsi/scsi_device.h
72252+++ b/include/scsi/scsi_device.h
72253@@ -170,9 +170,9 @@ struct scsi_device {
72254 unsigned int max_device_blocked; /* what device_blocked counts down from */
72255 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
72256
72257- atomic_t iorequest_cnt;
72258- atomic_t iodone_cnt;
72259- atomic_t ioerr_cnt;
72260+ atomic_unchecked_t iorequest_cnt;
72261+ atomic_unchecked_t iodone_cnt;
72262+ atomic_unchecked_t ioerr_cnt;
72263
72264 struct device sdev_gendev,
72265 sdev_dev;
72266diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
72267index b797e8f..8e2c3aa 100644
72268--- a/include/scsi/scsi_transport_fc.h
72269+++ b/include/scsi/scsi_transport_fc.h
72270@@ -751,7 +751,8 @@ struct fc_function_template {
72271 unsigned long show_host_system_hostname:1;
72272
72273 unsigned long disable_target_scan:1;
72274-};
72275+} __do_const;
72276+typedef struct fc_function_template __no_const fc_function_template_no_const;
72277
72278
72279 /**
72280diff --git a/include/sound/soc.h b/include/sound/soc.h
72281index bc56738..a4be132 100644
72282--- a/include/sound/soc.h
72283+++ b/include/sound/soc.h
72284@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
72285 /* probe ordering - for components with runtime dependencies */
72286 int probe_order;
72287 int remove_order;
72288-};
72289+} __do_const;
72290
72291 /* SoC platform interface */
72292 struct snd_soc_platform_driver {
72293@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
72294 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
72295 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
72296 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
72297-};
72298+} __do_const;
72299
72300 struct snd_soc_platform {
72301 const char *name;
72302diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
72303index 663e34a..91b306a 100644
72304--- a/include/target/target_core_base.h
72305+++ b/include/target/target_core_base.h
72306@@ -654,7 +654,7 @@ struct se_device {
72307 spinlock_t stats_lock;
72308 /* Active commands on this virtual SE device */
72309 atomic_t simple_cmds;
72310- atomic_t dev_ordered_id;
72311+ atomic_unchecked_t dev_ordered_id;
72312 atomic_t dev_ordered_sync;
72313 atomic_t dev_qf_count;
72314 int export_count;
72315diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
72316new file mode 100644
72317index 0000000..fb634b7
72318--- /dev/null
72319+++ b/include/trace/events/fs.h
72320@@ -0,0 +1,53 @@
72321+#undef TRACE_SYSTEM
72322+#define TRACE_SYSTEM fs
72323+
72324+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
72325+#define _TRACE_FS_H
72326+
72327+#include <linux/fs.h>
72328+#include <linux/tracepoint.h>
72329+
72330+TRACE_EVENT(do_sys_open,
72331+
72332+ TP_PROTO(const char *filename, int flags, int mode),
72333+
72334+ TP_ARGS(filename, flags, mode),
72335+
72336+ TP_STRUCT__entry(
72337+ __string( filename, filename )
72338+ __field( int, flags )
72339+ __field( int, mode )
72340+ ),
72341+
72342+ TP_fast_assign(
72343+ __assign_str(filename, filename);
72344+ __entry->flags = flags;
72345+ __entry->mode = mode;
72346+ ),
72347+
72348+ TP_printk("\"%s\" %x %o",
72349+ __get_str(filename), __entry->flags, __entry->mode)
72350+);
72351+
72352+TRACE_EVENT(open_exec,
72353+
72354+ TP_PROTO(const char *filename),
72355+
72356+ TP_ARGS(filename),
72357+
72358+ TP_STRUCT__entry(
72359+ __string( filename, filename )
72360+ ),
72361+
72362+ TP_fast_assign(
72363+ __assign_str(filename, filename);
72364+ ),
72365+
72366+ TP_printk("\"%s\"",
72367+ __get_str(filename))
72368+);
72369+
72370+#endif /* _TRACE_FS_H */
72371+
72372+/* This part must be outside protection */
72373+#include <trace/define_trace.h>
72374diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
72375index 1c09820..7f5ec79 100644
72376--- a/include/trace/events/irq.h
72377+++ b/include/trace/events/irq.h
72378@@ -36,7 +36,7 @@ struct softirq_action;
72379 */
72380 TRACE_EVENT(irq_handler_entry,
72381
72382- TP_PROTO(int irq, struct irqaction *action),
72383+ TP_PROTO(int irq, const struct irqaction *action),
72384
72385 TP_ARGS(irq, action),
72386
72387@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
72388 */
72389 TRACE_EVENT(irq_handler_exit,
72390
72391- TP_PROTO(int irq, struct irqaction *action, int ret),
72392+ TP_PROTO(int irq, const struct irqaction *action, int ret),
72393
72394 TP_ARGS(irq, action, ret),
72395
72396diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
72397index 7caf44c..23c6f27 100644
72398--- a/include/uapi/linux/a.out.h
72399+++ b/include/uapi/linux/a.out.h
72400@@ -39,6 +39,14 @@ enum machine_type {
72401 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
72402 };
72403
72404+/* Constants for the N_FLAGS field */
72405+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72406+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
72407+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
72408+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
72409+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72410+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72411+
72412 #if !defined (N_MAGIC)
72413 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
72414 #endif
72415diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
72416index d876736..ccce5c0 100644
72417--- a/include/uapi/linux/byteorder/little_endian.h
72418+++ b/include/uapi/linux/byteorder/little_endian.h
72419@@ -42,51 +42,51 @@
72420
72421 static inline __le64 __cpu_to_le64p(const __u64 *p)
72422 {
72423- return (__force __le64)*p;
72424+ return (__force const __le64)*p;
72425 }
72426-static inline __u64 __le64_to_cpup(const __le64 *p)
72427+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
72428 {
72429- return (__force __u64)*p;
72430+ return (__force const __u64)*p;
72431 }
72432 static inline __le32 __cpu_to_le32p(const __u32 *p)
72433 {
72434- return (__force __le32)*p;
72435+ return (__force const __le32)*p;
72436 }
72437 static inline __u32 __le32_to_cpup(const __le32 *p)
72438 {
72439- return (__force __u32)*p;
72440+ return (__force const __u32)*p;
72441 }
72442 static inline __le16 __cpu_to_le16p(const __u16 *p)
72443 {
72444- return (__force __le16)*p;
72445+ return (__force const __le16)*p;
72446 }
72447 static inline __u16 __le16_to_cpup(const __le16 *p)
72448 {
72449- return (__force __u16)*p;
72450+ return (__force const __u16)*p;
72451 }
72452 static inline __be64 __cpu_to_be64p(const __u64 *p)
72453 {
72454- return (__force __be64)__swab64p(p);
72455+ return (__force const __be64)__swab64p(p);
72456 }
72457 static inline __u64 __be64_to_cpup(const __be64 *p)
72458 {
72459- return __swab64p((__u64 *)p);
72460+ return __swab64p((const __u64 *)p);
72461 }
72462 static inline __be32 __cpu_to_be32p(const __u32 *p)
72463 {
72464- return (__force __be32)__swab32p(p);
72465+ return (__force const __be32)__swab32p(p);
72466 }
72467-static inline __u32 __be32_to_cpup(const __be32 *p)
72468+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
72469 {
72470- return __swab32p((__u32 *)p);
72471+ return __swab32p((const __u32 *)p);
72472 }
72473 static inline __be16 __cpu_to_be16p(const __u16 *p)
72474 {
72475- return (__force __be16)__swab16p(p);
72476+ return (__force const __be16)__swab16p(p);
72477 }
72478 static inline __u16 __be16_to_cpup(const __be16 *p)
72479 {
72480- return __swab16p((__u16 *)p);
72481+ return __swab16p((const __u16 *)p);
72482 }
72483 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
72484 #define __le64_to_cpus(x) do { (void)(x); } while (0)
72485diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
72486index 126a817..d522bd1 100644
72487--- a/include/uapi/linux/elf.h
72488+++ b/include/uapi/linux/elf.h
72489@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
72490 #define PT_GNU_EH_FRAME 0x6474e550
72491
72492 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
72493+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
72494+
72495+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
72496+
72497+/* Constants for the e_flags field */
72498+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72499+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
72500+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
72501+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
72502+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72503+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72504
72505 /*
72506 * Extended Numbering
72507@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
72508 #define DT_DEBUG 21
72509 #define DT_TEXTREL 22
72510 #define DT_JMPREL 23
72511+#define DT_FLAGS 30
72512+ #define DF_TEXTREL 0x00000004
72513 #define DT_ENCODING 32
72514 #define OLD_DT_LOOS 0x60000000
72515 #define DT_LOOS 0x6000000d
72516@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
72517 #define PF_W 0x2
72518 #define PF_X 0x1
72519
72520+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
72521+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
72522+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
72523+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
72524+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
72525+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
72526+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
72527+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
72528+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
72529+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
72530+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
72531+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
72532+
72533 typedef struct elf32_phdr{
72534 Elf32_Word p_type;
72535 Elf32_Off p_offset;
72536@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
72537 #define EI_OSABI 7
72538 #define EI_PAD 8
72539
72540+#define EI_PAX 14
72541+
72542 #define ELFMAG0 0x7f /* EI_MAG */
72543 #define ELFMAG1 'E'
72544 #define ELFMAG2 'L'
72545diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
72546index aa169c4..6a2771d 100644
72547--- a/include/uapi/linux/personality.h
72548+++ b/include/uapi/linux/personality.h
72549@@ -30,6 +30,7 @@ enum {
72550 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
72551 ADDR_NO_RANDOMIZE | \
72552 ADDR_COMPAT_LAYOUT | \
72553+ ADDR_LIMIT_3GB | \
72554 MMAP_PAGE_ZERO)
72555
72556 /*
72557diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
72558index 7530e74..e714828 100644
72559--- a/include/uapi/linux/screen_info.h
72560+++ b/include/uapi/linux/screen_info.h
72561@@ -43,7 +43,8 @@ struct screen_info {
72562 __u16 pages; /* 0x32 */
72563 __u16 vesa_attributes; /* 0x34 */
72564 __u32 capabilities; /* 0x36 */
72565- __u8 _reserved[6]; /* 0x3a */
72566+ __u16 vesapm_size; /* 0x3a */
72567+ __u8 _reserved[4]; /* 0x3c */
72568 } __attribute__((packed));
72569
72570 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
72571diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
72572index 0e011eb..82681b1 100644
72573--- a/include/uapi/linux/swab.h
72574+++ b/include/uapi/linux/swab.h
72575@@ -43,7 +43,7 @@
72576 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
72577 */
72578
72579-static inline __attribute_const__ __u16 __fswab16(__u16 val)
72580+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
72581 {
72582 #ifdef __HAVE_BUILTIN_BSWAP16__
72583 return __builtin_bswap16(val);
72584@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
72585 #endif
72586 }
72587
72588-static inline __attribute_const__ __u32 __fswab32(__u32 val)
72589+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
72590 {
72591 #ifdef __HAVE_BUILTIN_BSWAP32__
72592 return __builtin_bswap32(val);
72593@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
72594 #endif
72595 }
72596
72597-static inline __attribute_const__ __u64 __fswab64(__u64 val)
72598+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
72599 {
72600 #ifdef __HAVE_BUILTIN_BSWAP64__
72601 return __builtin_bswap64(val);
72602diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
72603index 6d67213..8dab561 100644
72604--- a/include/uapi/linux/sysctl.h
72605+++ b/include/uapi/linux/sysctl.h
72606@@ -155,7 +155,11 @@ enum
72607 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
72608 };
72609
72610-
72611+#ifdef CONFIG_PAX_SOFTMODE
72612+enum {
72613+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
72614+};
72615+#endif
72616
72617 /* CTL_VM names: */
72618 enum
72619diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
72620index 26607bd..588b65f 100644
72621--- a/include/uapi/linux/xattr.h
72622+++ b/include/uapi/linux/xattr.h
72623@@ -60,5 +60,9 @@
72624 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
72625 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
72626
72627+/* User namespace */
72628+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
72629+#define XATTR_PAX_FLAGS_SUFFIX "flags"
72630+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
72631
72632 #endif /* _UAPI_LINUX_XATTR_H */
72633diff --git a/include/video/udlfb.h b/include/video/udlfb.h
72634index f9466fa..f4e2b81 100644
72635--- a/include/video/udlfb.h
72636+++ b/include/video/udlfb.h
72637@@ -53,10 +53,10 @@ struct dlfb_data {
72638 u32 pseudo_palette[256];
72639 int blank_mode; /*one of FB_BLANK_ */
72640 /* blit-only rendering path metrics, exposed through sysfs */
72641- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72642- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
72643- atomic_t bytes_sent; /* to usb, after compression including overhead */
72644- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
72645+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72646+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
72647+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
72648+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
72649 };
72650
72651 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
72652diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
72653index 0993a22..32ba2fe 100644
72654--- a/include/video/uvesafb.h
72655+++ b/include/video/uvesafb.h
72656@@ -177,6 +177,7 @@ struct uvesafb_par {
72657 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
72658 u8 pmi_setpal; /* PMI for palette changes */
72659 u16 *pmi_base; /* protected mode interface location */
72660+ u8 *pmi_code; /* protected mode code location */
72661 void *pmi_start;
72662 void *pmi_pal;
72663 u8 *vbe_state_orig; /*
72664diff --git a/init/Kconfig b/init/Kconfig
72665index be8b7f5..1eeca9b 100644
72666--- a/init/Kconfig
72667+++ b/init/Kconfig
72668@@ -990,6 +990,7 @@ endif # CGROUPS
72669
72670 config CHECKPOINT_RESTORE
72671 bool "Checkpoint/restore support" if EXPERT
72672+ depends on !GRKERNSEC
72673 default n
72674 help
72675 Enables additional kernel features in a sake of checkpoint/restore.
72676@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
72677
72678 config COMPAT_BRK
72679 bool "Disable heap randomization"
72680- default y
72681+ default n
72682 help
72683 Randomizing heap placement makes heap exploits harder, but it
72684 also breaks ancient binaries (including anything libc5 based).
72685@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
72686 config STOP_MACHINE
72687 bool
72688 default y
72689- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
72690+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
72691 help
72692 Need stop_machine() primitive.
72693
72694diff --git a/init/Makefile b/init/Makefile
72695index 7bc47ee..6da2dc7 100644
72696--- a/init/Makefile
72697+++ b/init/Makefile
72698@@ -2,6 +2,9 @@
72699 # Makefile for the linux kernel.
72700 #
72701
72702+ccflags-y := $(GCC_PLUGINS_CFLAGS)
72703+asflags-y := $(GCC_PLUGINS_AFLAGS)
72704+
72705 obj-y := main.o version.o mounts.o
72706 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
72707 obj-y += noinitramfs.o
72708diff --git a/init/do_mounts.c b/init/do_mounts.c
72709index 1d1b634..a1c810f 100644
72710--- a/init/do_mounts.c
72711+++ b/init/do_mounts.c
72712@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
72713 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
72714 {
72715 struct super_block *s;
72716- int err = sys_mount(name, "/root", fs, flags, data);
72717+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
72718 if (err)
72719 return err;
72720
72721- sys_chdir("/root");
72722+ sys_chdir((const char __force_user *)"/root");
72723 s = current->fs->pwd.dentry->d_sb;
72724 ROOT_DEV = s->s_dev;
72725 printk(KERN_INFO
72726@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
72727 va_start(args, fmt);
72728 vsprintf(buf, fmt, args);
72729 va_end(args);
72730- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
72731+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
72732 if (fd >= 0) {
72733 sys_ioctl(fd, FDEJECT, 0);
72734 sys_close(fd);
72735 }
72736 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
72737- fd = sys_open("/dev/console", O_RDWR, 0);
72738+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
72739 if (fd >= 0) {
72740 sys_ioctl(fd, TCGETS, (long)&termios);
72741 termios.c_lflag &= ~ICANON;
72742 sys_ioctl(fd, TCSETSF, (long)&termios);
72743- sys_read(fd, &c, 1);
72744+ sys_read(fd, (char __user *)&c, 1);
72745 termios.c_lflag |= ICANON;
72746 sys_ioctl(fd, TCSETSF, (long)&termios);
72747 sys_close(fd);
72748@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
72749 mount_root();
72750 out:
72751 devtmpfs_mount("dev");
72752- sys_mount(".", "/", NULL, MS_MOVE, NULL);
72753- sys_chroot(".");
72754+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72755+ sys_chroot((const char __force_user *)".");
72756 }
72757diff --git a/init/do_mounts.h b/init/do_mounts.h
72758index f5b978a..69dbfe8 100644
72759--- a/init/do_mounts.h
72760+++ b/init/do_mounts.h
72761@@ -15,15 +15,15 @@ extern int root_mountflags;
72762
72763 static inline int create_dev(char *name, dev_t dev)
72764 {
72765- sys_unlink(name);
72766- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72767+ sys_unlink((char __force_user *)name);
72768+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72769 }
72770
72771 #if BITS_PER_LONG == 32
72772 static inline u32 bstat(char *name)
72773 {
72774 struct stat64 stat;
72775- if (sys_stat64(name, &stat) != 0)
72776+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72777 return 0;
72778 if (!S_ISBLK(stat.st_mode))
72779 return 0;
72780@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72781 static inline u32 bstat(char *name)
72782 {
72783 struct stat stat;
72784- if (sys_newstat(name, &stat) != 0)
72785+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72786 return 0;
72787 if (!S_ISBLK(stat.st_mode))
72788 return 0;
72789diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72790index f9acf71..1e19144 100644
72791--- a/init/do_mounts_initrd.c
72792+++ b/init/do_mounts_initrd.c
72793@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72794 create_dev("/dev/root.old", Root_RAM0);
72795 /* mount initrd on rootfs' /root */
72796 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72797- sys_mkdir("/old", 0700);
72798- sys_chdir("/old");
72799+ sys_mkdir((const char __force_user *)"/old", 0700);
72800+ sys_chdir((const char __force_user *)"/old");
72801
72802 /*
72803 * In case that a resume from disk is carried out by linuxrc or one of
72804@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72805 current->flags &= ~PF_FREEZER_SKIP;
72806
72807 /* move initrd to rootfs' /old */
72808- sys_mount("..", ".", NULL, MS_MOVE, NULL);
72809+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72810 /* switch root and cwd back to / of rootfs */
72811- sys_chroot("..");
72812+ sys_chroot((const char __force_user *)"..");
72813
72814 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72815- sys_chdir("/old");
72816+ sys_chdir((const char __force_user *)"/old");
72817 return;
72818 }
72819
72820- sys_chdir("/");
72821+ sys_chdir((const char __force_user *)"/");
72822 ROOT_DEV = new_decode_dev(real_root_dev);
72823 mount_root();
72824
72825 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
72826- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
72827+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
72828 if (!error)
72829 printk("okay\n");
72830 else {
72831- int fd = sys_open("/dev/root.old", O_RDWR, 0);
72832+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
72833 if (error == -ENOENT)
72834 printk("/initrd does not exist. Ignored.\n");
72835 else
72836 printk("failed\n");
72837 printk(KERN_NOTICE "Unmounting old root\n");
72838- sys_umount("/old", MNT_DETACH);
72839+ sys_umount((char __force_user *)"/old", MNT_DETACH);
72840 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
72841 if (fd < 0) {
72842 error = fd;
72843@@ -120,11 +120,11 @@ int __init initrd_load(void)
72844 * mounted in the normal path.
72845 */
72846 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
72847- sys_unlink("/initrd.image");
72848+ sys_unlink((const char __force_user *)"/initrd.image");
72849 handle_initrd();
72850 return 1;
72851 }
72852 }
72853- sys_unlink("/initrd.image");
72854+ sys_unlink((const char __force_user *)"/initrd.image");
72855 return 0;
72856 }
72857diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
72858index 8cb6db5..d729f50 100644
72859--- a/init/do_mounts_md.c
72860+++ b/init/do_mounts_md.c
72861@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
72862 partitioned ? "_d" : "", minor,
72863 md_setup_args[ent].device_names);
72864
72865- fd = sys_open(name, 0, 0);
72866+ fd = sys_open((char __force_user *)name, 0, 0);
72867 if (fd < 0) {
72868 printk(KERN_ERR "md: open failed - cannot start "
72869 "array %s\n", name);
72870@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
72871 * array without it
72872 */
72873 sys_close(fd);
72874- fd = sys_open(name, 0, 0);
72875+ fd = sys_open((char __force_user *)name, 0, 0);
72876 sys_ioctl(fd, BLKRRPART, 0);
72877 }
72878 sys_close(fd);
72879@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72880
72881 wait_for_device_probe();
72882
72883- fd = sys_open("/dev/md0", 0, 0);
72884+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72885 if (fd >= 0) {
72886 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72887 sys_close(fd);
72888diff --git a/init/init_task.c b/init/init_task.c
72889index 8b2f399..f0797c9 100644
72890--- a/init/init_task.c
72891+++ b/init/init_task.c
72892@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72893 * Initial thread structure. Alignment of this is handled by a special
72894 * linker map entry.
72895 */
72896+#ifdef CONFIG_X86
72897+union thread_union init_thread_union __init_task_data;
72898+#else
72899 union thread_union init_thread_union __init_task_data =
72900 { INIT_THREAD_INFO(init_task) };
72901+#endif
72902diff --git a/init/initramfs.c b/init/initramfs.c
72903index 84c6bf1..8899338 100644
72904--- a/init/initramfs.c
72905+++ b/init/initramfs.c
72906@@ -84,7 +84,7 @@ static void __init free_hash(void)
72907 }
72908 }
72909
72910-static long __init do_utime(char *filename, time_t mtime)
72911+static long __init do_utime(char __force_user *filename, time_t mtime)
72912 {
72913 struct timespec t[2];
72914
72915@@ -119,7 +119,7 @@ static void __init dir_utime(void)
72916 struct dir_entry *de, *tmp;
72917 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72918 list_del(&de->list);
72919- do_utime(de->name, de->mtime);
72920+ do_utime((char __force_user *)de->name, de->mtime);
72921 kfree(de->name);
72922 kfree(de);
72923 }
72924@@ -281,7 +281,7 @@ static int __init maybe_link(void)
72925 if (nlink >= 2) {
72926 char *old = find_link(major, minor, ino, mode, collected);
72927 if (old)
72928- return (sys_link(old, collected) < 0) ? -1 : 1;
72929+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72930 }
72931 return 0;
72932 }
72933@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72934 {
72935 struct stat st;
72936
72937- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72938+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72939 if (S_ISDIR(st.st_mode))
72940- sys_rmdir(path);
72941+ sys_rmdir((char __force_user *)path);
72942 else
72943- sys_unlink(path);
72944+ sys_unlink((char __force_user *)path);
72945 }
72946 }
72947
72948@@ -315,7 +315,7 @@ static int __init do_name(void)
72949 int openflags = O_WRONLY|O_CREAT;
72950 if (ml != 1)
72951 openflags |= O_TRUNC;
72952- wfd = sys_open(collected, openflags, mode);
72953+ wfd = sys_open((char __force_user *)collected, openflags, mode);
72954
72955 if (wfd >= 0) {
72956 sys_fchown(wfd, uid, gid);
72957@@ -327,17 +327,17 @@ static int __init do_name(void)
72958 }
72959 }
72960 } else if (S_ISDIR(mode)) {
72961- sys_mkdir(collected, mode);
72962- sys_chown(collected, uid, gid);
72963- sys_chmod(collected, mode);
72964+ sys_mkdir((char __force_user *)collected, mode);
72965+ sys_chown((char __force_user *)collected, uid, gid);
72966+ sys_chmod((char __force_user *)collected, mode);
72967 dir_add(collected, mtime);
72968 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
72969 S_ISFIFO(mode) || S_ISSOCK(mode)) {
72970 if (maybe_link() == 0) {
72971- sys_mknod(collected, mode, rdev);
72972- sys_chown(collected, uid, gid);
72973- sys_chmod(collected, mode);
72974- do_utime(collected, mtime);
72975+ sys_mknod((char __force_user *)collected, mode, rdev);
72976+ sys_chown((char __force_user *)collected, uid, gid);
72977+ sys_chmod((char __force_user *)collected, mode);
72978+ do_utime((char __force_user *)collected, mtime);
72979 }
72980 }
72981 return 0;
72982@@ -346,15 +346,15 @@ static int __init do_name(void)
72983 static int __init do_copy(void)
72984 {
72985 if (count >= body_len) {
72986- sys_write(wfd, victim, body_len);
72987+ sys_write(wfd, (char __force_user *)victim, body_len);
72988 sys_close(wfd);
72989- do_utime(vcollected, mtime);
72990+ do_utime((char __force_user *)vcollected, mtime);
72991 kfree(vcollected);
72992 eat(body_len);
72993 state = SkipIt;
72994 return 0;
72995 } else {
72996- sys_write(wfd, victim, count);
72997+ sys_write(wfd, (char __force_user *)victim, count);
72998 body_len -= count;
72999 eat(count);
73000 return 1;
73001@@ -365,9 +365,9 @@ static int __init do_symlink(void)
73002 {
73003 collected[N_ALIGN(name_len) + body_len] = '\0';
73004 clean_path(collected, 0);
73005- sys_symlink(collected + N_ALIGN(name_len), collected);
73006- sys_lchown(collected, uid, gid);
73007- do_utime(collected, mtime);
73008+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
73009+ sys_lchown((char __force_user *)collected, uid, gid);
73010+ do_utime((char __force_user *)collected, mtime);
73011 state = SkipIt;
73012 next_state = Reset;
73013 return 0;
73014diff --git a/init/main.c b/init/main.c
73015index cee4b5c..360e10a 100644
73016--- a/init/main.c
73017+++ b/init/main.c
73018@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
73019 extern void tc_init(void);
73020 #endif
73021
73022+extern void grsecurity_init(void);
73023+
73024 /*
73025 * Debug helper: via this flag we know that we are in 'early bootup code'
73026 * where only the boot processor is running with IRQ disabled. This means
73027@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
73028
73029 __setup("reset_devices", set_reset_devices);
73030
73031+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73032+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
73033+static int __init setup_grsec_proc_gid(char *str)
73034+{
73035+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
73036+ return 1;
73037+}
73038+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
73039+#endif
73040+
73041+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
73042+extern char pax_enter_kernel_user[];
73043+extern char pax_exit_kernel_user[];
73044+extern pgdval_t clone_pgd_mask;
73045+#endif
73046+
73047+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
73048+static int __init setup_pax_nouderef(char *str)
73049+{
73050+#ifdef CONFIG_X86_32
73051+ unsigned int cpu;
73052+ struct desc_struct *gdt;
73053+
73054+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
73055+ gdt = get_cpu_gdt_table(cpu);
73056+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
73057+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
73058+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
73059+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
73060+ }
73061+ loadsegment(ds, __KERNEL_DS);
73062+ loadsegment(es, __KERNEL_DS);
73063+ loadsegment(ss, __KERNEL_DS);
73064+#else
73065+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
73066+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
73067+ clone_pgd_mask = ~(pgdval_t)0UL;
73068+#endif
73069+
73070+ return 0;
73071+}
73072+early_param("pax_nouderef", setup_pax_nouderef);
73073+#endif
73074+
73075+#ifdef CONFIG_PAX_SOFTMODE
73076+int pax_softmode;
73077+
73078+static int __init setup_pax_softmode(char *str)
73079+{
73080+ get_option(&str, &pax_softmode);
73081+ return 1;
73082+}
73083+__setup("pax_softmode=", setup_pax_softmode);
73084+#endif
73085+
73086 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
73087 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
73088 static const char *panic_later, *panic_param;
73089@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
73090 {
73091 int count = preempt_count();
73092 int ret;
73093+ const char *msg1 = "", *msg2 = "";
73094
73095 if (initcall_debug)
73096 ret = do_one_initcall_debug(fn);
73097@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
73098 sprintf(msgbuf, "error code %d ", ret);
73099
73100 if (preempt_count() != count) {
73101- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
73102+ msg1 = " preemption imbalance";
73103 preempt_count() = count;
73104 }
73105 if (irqs_disabled()) {
73106- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
73107+ msg2 = " disabled interrupts";
73108 local_irq_enable();
73109 }
73110- if (msgbuf[0]) {
73111- printk("initcall %pF returned with %s\n", fn, msgbuf);
73112+ if (msgbuf[0] || *msg1 || *msg2) {
73113+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
73114 }
73115
73116 return ret;
73117@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
73118 level, level,
73119 &repair_env_string);
73120
73121- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
73122+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
73123 do_one_initcall(*fn);
73124+
73125+#ifdef LATENT_ENTROPY_PLUGIN
73126+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73127+#endif
73128+
73129+ }
73130 }
73131
73132 static void __init do_initcalls(void)
73133@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
73134 {
73135 initcall_t *fn;
73136
73137- for (fn = __initcall_start; fn < __initcall0_start; fn++)
73138+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
73139 do_one_initcall(*fn);
73140+
73141+#ifdef LATENT_ENTROPY_PLUGIN
73142+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73143+#endif
73144+
73145+ }
73146 }
73147
73148 static int run_init_process(const char *init_filename)
73149@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
73150 do_basic_setup();
73151
73152 /* Open the /dev/console on the rootfs, this should never fail */
73153- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
73154+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
73155 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
73156
73157 (void) sys_dup(0);
73158@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
73159 if (!ramdisk_execute_command)
73160 ramdisk_execute_command = "/init";
73161
73162- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
73163+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
73164 ramdisk_execute_command = NULL;
73165 prepare_namespace();
73166 }
73167
73168+ grsecurity_init();
73169+
73170 /*
73171 * Ok, we have completed the initial bootup, and
73172 * we're essentially up and running. Get rid of the
73173diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
73174index 130dfec..cc88451 100644
73175--- a/ipc/ipc_sysctl.c
73176+++ b/ipc/ipc_sysctl.c
73177@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
73178 static int proc_ipc_dointvec(ctl_table *table, int write,
73179 void __user *buffer, size_t *lenp, loff_t *ppos)
73180 {
73181- struct ctl_table ipc_table;
73182+ ctl_table_no_const ipc_table;
73183
73184 memcpy(&ipc_table, table, sizeof(ipc_table));
73185 ipc_table.data = get_ipc(table);
73186@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
73187 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
73188 void __user *buffer, size_t *lenp, loff_t *ppos)
73189 {
73190- struct ctl_table ipc_table;
73191+ ctl_table_no_const ipc_table;
73192
73193 memcpy(&ipc_table, table, sizeof(ipc_table));
73194 ipc_table.data = get_ipc(table);
73195@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
73196 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73197 void __user *buffer, size_t *lenp, loff_t *ppos)
73198 {
73199- struct ctl_table ipc_table;
73200+ ctl_table_no_const ipc_table;
73201 size_t lenp_bef = *lenp;
73202 int rc;
73203
73204@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73205 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
73206 void __user *buffer, size_t *lenp, loff_t *ppos)
73207 {
73208- struct ctl_table ipc_table;
73209+ ctl_table_no_const ipc_table;
73210 memcpy(&ipc_table, table, sizeof(ipc_table));
73211 ipc_table.data = get_ipc(table);
73212
73213@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
73214 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
73215 void __user *buffer, size_t *lenp, loff_t *ppos)
73216 {
73217- struct ctl_table ipc_table;
73218+ ctl_table_no_const ipc_table;
73219 size_t lenp_bef = *lenp;
73220 int oldval;
73221 int rc;
73222diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
73223index 383d638..943fdbb 100644
73224--- a/ipc/mq_sysctl.c
73225+++ b/ipc/mq_sysctl.c
73226@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
73227 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
73228 void __user *buffer, size_t *lenp, loff_t *ppos)
73229 {
73230- struct ctl_table mq_table;
73231+ ctl_table_no_const mq_table;
73232 memcpy(&mq_table, table, sizeof(mq_table));
73233 mq_table.data = get_mq(table);
73234
73235diff --git a/ipc/mqueue.c b/ipc/mqueue.c
73236index 71a3ca1..cc330ee 100644
73237--- a/ipc/mqueue.c
73238+++ b/ipc/mqueue.c
73239@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
73240 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
73241 info->attr.mq_msgsize);
73242
73243+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
73244 spin_lock(&mq_lock);
73245 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
73246 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
73247diff --git a/ipc/msg.c b/ipc/msg.c
73248index 31cd1bf..362ea07 100644
73249--- a/ipc/msg.c
73250+++ b/ipc/msg.c
73251@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
73252 return security_msg_queue_associate(msq, msgflg);
73253 }
73254
73255+static struct ipc_ops msg_ops = {
73256+ .getnew = newque,
73257+ .associate = msg_security,
73258+ .more_checks = NULL
73259+};
73260+
73261 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
73262 {
73263 struct ipc_namespace *ns;
73264- struct ipc_ops msg_ops;
73265 struct ipc_params msg_params;
73266
73267 ns = current->nsproxy->ipc_ns;
73268
73269- msg_ops.getnew = newque;
73270- msg_ops.associate = msg_security;
73271- msg_ops.more_checks = NULL;
73272-
73273 msg_params.key = key;
73274 msg_params.flg = msgflg;
73275
73276diff --git a/ipc/sem.c b/ipc/sem.c
73277index 58d31f1..cce7a55 100644
73278--- a/ipc/sem.c
73279+++ b/ipc/sem.c
73280@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
73281 return 0;
73282 }
73283
73284+static struct ipc_ops sem_ops = {
73285+ .getnew = newary,
73286+ .associate = sem_security,
73287+ .more_checks = sem_more_checks
73288+};
73289+
73290 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73291 {
73292 struct ipc_namespace *ns;
73293- struct ipc_ops sem_ops;
73294 struct ipc_params sem_params;
73295
73296 ns = current->nsproxy->ipc_ns;
73297@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73298 if (nsems < 0 || nsems > ns->sc_semmsl)
73299 return -EINVAL;
73300
73301- sem_ops.getnew = newary;
73302- sem_ops.associate = sem_security;
73303- sem_ops.more_checks = sem_more_checks;
73304-
73305 sem_params.key = key;
73306 sem_params.flg = semflg;
73307 sem_params.u.nsems = nsems;
73308diff --git a/ipc/shm.c b/ipc/shm.c
73309index 4fa6d8f..55cff14 100644
73310--- a/ipc/shm.c
73311+++ b/ipc/shm.c
73312@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
73313 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
73314 #endif
73315
73316+#ifdef CONFIG_GRKERNSEC
73317+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73318+ const time_t shm_createtime, const kuid_t cuid,
73319+ const int shmid);
73320+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73321+ const time_t shm_createtime);
73322+#endif
73323+
73324 void shm_init_ns(struct ipc_namespace *ns)
73325 {
73326 ns->shm_ctlmax = SHMMAX;
73327@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
73328 shp->shm_lprid = 0;
73329 shp->shm_atim = shp->shm_dtim = 0;
73330 shp->shm_ctim = get_seconds();
73331+#ifdef CONFIG_GRKERNSEC
73332+ {
73333+ struct timespec timeval;
73334+ do_posix_clock_monotonic_gettime(&timeval);
73335+
73336+ shp->shm_createtime = timeval.tv_sec;
73337+ }
73338+#endif
73339 shp->shm_segsz = size;
73340 shp->shm_nattch = 0;
73341 shp->shm_file = file;
73342@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
73343 return 0;
73344 }
73345
73346+static struct ipc_ops shm_ops = {
73347+ .getnew = newseg,
73348+ .associate = shm_security,
73349+ .more_checks = shm_more_checks
73350+};
73351+
73352 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
73353 {
73354 struct ipc_namespace *ns;
73355- struct ipc_ops shm_ops;
73356 struct ipc_params shm_params;
73357
73358 ns = current->nsproxy->ipc_ns;
73359
73360- shm_ops.getnew = newseg;
73361- shm_ops.associate = shm_security;
73362- shm_ops.more_checks = shm_more_checks;
73363-
73364 shm_params.key = key;
73365 shm_params.flg = shmflg;
73366 shm_params.u.size = size;
73367@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73368 f_mode = FMODE_READ | FMODE_WRITE;
73369 }
73370 if (shmflg & SHM_EXEC) {
73371+
73372+#ifdef CONFIG_PAX_MPROTECT
73373+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
73374+ goto out;
73375+#endif
73376+
73377 prot |= PROT_EXEC;
73378 acc_mode |= S_IXUGO;
73379 }
73380@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73381 if (err)
73382 goto out_unlock;
73383
73384+#ifdef CONFIG_GRKERNSEC
73385+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
73386+ shp->shm_perm.cuid, shmid) ||
73387+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
73388+ err = -EACCES;
73389+ goto out_unlock;
73390+ }
73391+#endif
73392+
73393 path = shp->shm_file->f_path;
73394 path_get(&path);
73395 shp->shm_nattch++;
73396+#ifdef CONFIG_GRKERNSEC
73397+ shp->shm_lapid = current->pid;
73398+#endif
73399 size = i_size_read(path.dentry->d_inode);
73400 shm_unlock(shp);
73401
73402diff --git a/kernel/acct.c b/kernel/acct.c
73403index 051e071..15e0920 100644
73404--- a/kernel/acct.c
73405+++ b/kernel/acct.c
73406@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
73407 */
73408 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
73409 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
73410- file->f_op->write(file, (char *)&ac,
73411+ file->f_op->write(file, (char __force_user *)&ac,
73412 sizeof(acct_t), &file->f_pos);
73413 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
73414 set_fs(fs);
73415diff --git a/kernel/audit.c b/kernel/audit.c
73416index d596e53..dbef3c3 100644
73417--- a/kernel/audit.c
73418+++ b/kernel/audit.c
73419@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
73420 3) suppressed due to audit_rate_limit
73421 4) suppressed due to audit_backlog_limit
73422 */
73423-static atomic_t audit_lost = ATOMIC_INIT(0);
73424+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
73425
73426 /* The netlink socket. */
73427 static struct sock *audit_sock;
73428@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
73429 unsigned long now;
73430 int print;
73431
73432- atomic_inc(&audit_lost);
73433+ atomic_inc_unchecked(&audit_lost);
73434
73435 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
73436
73437@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
73438 printk(KERN_WARNING
73439 "audit: audit_lost=%d audit_rate_limit=%d "
73440 "audit_backlog_limit=%d\n",
73441- atomic_read(&audit_lost),
73442+ atomic_read_unchecked(&audit_lost),
73443 audit_rate_limit,
73444 audit_backlog_limit);
73445 audit_panic(message);
73446@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
73447 status_set.pid = audit_pid;
73448 status_set.rate_limit = audit_rate_limit;
73449 status_set.backlog_limit = audit_backlog_limit;
73450- status_set.lost = atomic_read(&audit_lost);
73451+ status_set.lost = atomic_read_unchecked(&audit_lost);
73452 status_set.backlog = skb_queue_len(&audit_skb_queue);
73453 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
73454 &status_set, sizeof(status_set));
73455diff --git a/kernel/auditsc.c b/kernel/auditsc.c
73456index a371f85..da826c1 100644
73457--- a/kernel/auditsc.c
73458+++ b/kernel/auditsc.c
73459@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
73460 }
73461
73462 /* global counter which is incremented every time something logs in */
73463-static atomic_t session_id = ATOMIC_INIT(0);
73464+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
73465
73466 /**
73467 * audit_set_loginuid - set current task's audit_context loginuid
73468@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
73469 return -EPERM;
73470 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
73471
73472- sessionid = atomic_inc_return(&session_id);
73473+ sessionid = atomic_inc_return_unchecked(&session_id);
73474 if (context && context->in_syscall) {
73475 struct audit_buffer *ab;
73476
73477diff --git a/kernel/capability.c b/kernel/capability.c
73478index 493d972..f87dfbd 100644
73479--- a/kernel/capability.c
73480+++ b/kernel/capability.c
73481@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
73482 * before modification is attempted and the application
73483 * fails.
73484 */
73485+ if (tocopy > ARRAY_SIZE(kdata))
73486+ return -EFAULT;
73487+
73488 if (copy_to_user(dataptr, kdata, tocopy
73489 * sizeof(struct __user_cap_data_struct))) {
73490 return -EFAULT;
73491@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
73492 int ret;
73493
73494 rcu_read_lock();
73495- ret = security_capable(__task_cred(t), ns, cap);
73496+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
73497+ gr_task_is_capable(t, __task_cred(t), cap);
73498 rcu_read_unlock();
73499
73500- return (ret == 0);
73501+ return ret;
73502 }
73503
73504 /**
73505@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
73506 int ret;
73507
73508 rcu_read_lock();
73509- ret = security_capable_noaudit(__task_cred(t), ns, cap);
73510+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
73511 rcu_read_unlock();
73512
73513- return (ret == 0);
73514+ return ret;
73515 }
73516
73517 /**
73518@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
73519 BUG();
73520 }
73521
73522- if (security_capable(current_cred(), ns, cap) == 0) {
73523+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
73524 current->flags |= PF_SUPERPRIV;
73525 return true;
73526 }
73527@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
73528 }
73529 EXPORT_SYMBOL(ns_capable);
73530
73531+bool ns_capable_nolog(struct user_namespace *ns, int cap)
73532+{
73533+ if (unlikely(!cap_valid(cap))) {
73534+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
73535+ BUG();
73536+ }
73537+
73538+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
73539+ current->flags |= PF_SUPERPRIV;
73540+ return true;
73541+ }
73542+ return false;
73543+}
73544+EXPORT_SYMBOL(ns_capable_nolog);
73545+
73546 /**
73547 * capable - Determine if the current task has a superior capability in effect
73548 * @cap: The capability to be tested for
73549@@ -408,6 +427,12 @@ bool capable(int cap)
73550 }
73551 EXPORT_SYMBOL(capable);
73552
73553+bool capable_nolog(int cap)
73554+{
73555+ return ns_capable_nolog(&init_user_ns, cap);
73556+}
73557+EXPORT_SYMBOL(capable_nolog);
73558+
73559 /**
73560 * nsown_capable - Check superior capability to one's own user_ns
73561 * @cap: The capability in question
73562@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
73563
73564 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73565 }
73566+
73567+bool inode_capable_nolog(const struct inode *inode, int cap)
73568+{
73569+ struct user_namespace *ns = current_user_ns();
73570+
73571+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73572+}
73573diff --git a/kernel/cgroup.c b/kernel/cgroup.c
73574index 1e23664..570a83d 100644
73575--- a/kernel/cgroup.c
73576+++ b/kernel/cgroup.c
73577@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
73578 struct css_set *cg = link->cg;
73579 struct task_struct *task;
73580 int count = 0;
73581- seq_printf(seq, "css_set %p\n", cg);
73582+ seq_printf(seq, "css_set %pK\n", cg);
73583 list_for_each_entry(task, &cg->tasks, cg_list) {
73584 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
73585 seq_puts(seq, " ...\n");
73586diff --git a/kernel/compat.c b/kernel/compat.c
73587index 36700e9..73d770c 100644
73588--- a/kernel/compat.c
73589+++ b/kernel/compat.c
73590@@ -13,6 +13,7 @@
73591
73592 #include <linux/linkage.h>
73593 #include <linux/compat.h>
73594+#include <linux/module.h>
73595 #include <linux/errno.h>
73596 #include <linux/time.h>
73597 #include <linux/signal.h>
73598@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
73599 mm_segment_t oldfs;
73600 long ret;
73601
73602- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
73603+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
73604 oldfs = get_fs();
73605 set_fs(KERNEL_DS);
73606 ret = hrtimer_nanosleep_restart(restart);
73607@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
73608 oldfs = get_fs();
73609 set_fs(KERNEL_DS);
73610 ret = hrtimer_nanosleep(&tu,
73611- rmtp ? (struct timespec __user *)&rmt : NULL,
73612+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
73613 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
73614 set_fs(oldfs);
73615
73616@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
73617 mm_segment_t old_fs = get_fs();
73618
73619 set_fs(KERNEL_DS);
73620- ret = sys_sigpending((old_sigset_t __user *) &s);
73621+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
73622 set_fs(old_fs);
73623 if (ret == 0)
73624 ret = put_user(s, set);
73625@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
73626 mm_segment_t old_fs = get_fs();
73627
73628 set_fs(KERNEL_DS);
73629- ret = sys_old_getrlimit(resource, &r);
73630+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
73631 set_fs(old_fs);
73632
73633 if (!ret) {
73634@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
73635 mm_segment_t old_fs = get_fs();
73636
73637 set_fs(KERNEL_DS);
73638- ret = sys_getrusage(who, (struct rusage __user *) &r);
73639+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
73640 set_fs(old_fs);
73641
73642 if (ret)
73643@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
73644 set_fs (KERNEL_DS);
73645 ret = sys_wait4(pid,
73646 (stat_addr ?
73647- (unsigned int __user *) &status : NULL),
73648- options, (struct rusage __user *) &r);
73649+ (unsigned int __force_user *) &status : NULL),
73650+ options, (struct rusage __force_user *) &r);
73651 set_fs (old_fs);
73652
73653 if (ret > 0) {
73654@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
73655 memset(&info, 0, sizeof(info));
73656
73657 set_fs(KERNEL_DS);
73658- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
73659- uru ? (struct rusage __user *)&ru : NULL);
73660+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
73661+ uru ? (struct rusage __force_user *)&ru : NULL);
73662 set_fs(old_fs);
73663
73664 if ((ret < 0) || (info.si_signo == 0))
73665@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
73666 oldfs = get_fs();
73667 set_fs(KERNEL_DS);
73668 err = sys_timer_settime(timer_id, flags,
73669- (struct itimerspec __user *) &newts,
73670- (struct itimerspec __user *) &oldts);
73671+ (struct itimerspec __force_user *) &newts,
73672+ (struct itimerspec __force_user *) &oldts);
73673 set_fs(oldfs);
73674 if (!err && old && put_compat_itimerspec(old, &oldts))
73675 return -EFAULT;
73676@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
73677 oldfs = get_fs();
73678 set_fs(KERNEL_DS);
73679 err = sys_timer_gettime(timer_id,
73680- (struct itimerspec __user *) &ts);
73681+ (struct itimerspec __force_user *) &ts);
73682 set_fs(oldfs);
73683 if (!err && put_compat_itimerspec(setting, &ts))
73684 return -EFAULT;
73685@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
73686 oldfs = get_fs();
73687 set_fs(KERNEL_DS);
73688 err = sys_clock_settime(which_clock,
73689- (struct timespec __user *) &ts);
73690+ (struct timespec __force_user *) &ts);
73691 set_fs(oldfs);
73692 return err;
73693 }
73694@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
73695 oldfs = get_fs();
73696 set_fs(KERNEL_DS);
73697 err = sys_clock_gettime(which_clock,
73698- (struct timespec __user *) &ts);
73699+ (struct timespec __force_user *) &ts);
73700 set_fs(oldfs);
73701 if (!err && put_compat_timespec(&ts, tp))
73702 return -EFAULT;
73703@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
73704
73705 oldfs = get_fs();
73706 set_fs(KERNEL_DS);
73707- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
73708+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
73709 set_fs(oldfs);
73710
73711 err = compat_put_timex(utp, &txc);
73712@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
73713 oldfs = get_fs();
73714 set_fs(KERNEL_DS);
73715 err = sys_clock_getres(which_clock,
73716- (struct timespec __user *) &ts);
73717+ (struct timespec __force_user *) &ts);
73718 set_fs(oldfs);
73719 if (!err && tp && put_compat_timespec(&ts, tp))
73720 return -EFAULT;
73721@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
73722 long err;
73723 mm_segment_t oldfs;
73724 struct timespec tu;
73725- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
73726+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
73727
73728- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
73729+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
73730 oldfs = get_fs();
73731 set_fs(KERNEL_DS);
73732 err = clock_nanosleep_restart(restart);
73733@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
73734 oldfs = get_fs();
73735 set_fs(KERNEL_DS);
73736 err = sys_clock_nanosleep(which_clock, flags,
73737- (struct timespec __user *) &in,
73738- (struct timespec __user *) &out);
73739+ (struct timespec __force_user *) &in,
73740+ (struct timespec __force_user *) &out);
73741 set_fs(oldfs);
73742
73743 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
73744diff --git a/kernel/configs.c b/kernel/configs.c
73745index 42e8fa0..9e7406b 100644
73746--- a/kernel/configs.c
73747+++ b/kernel/configs.c
73748@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
73749 struct proc_dir_entry *entry;
73750
73751 /* create the current config file */
73752+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
73753+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
73754+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73755+ &ikconfig_file_ops);
73756+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73757+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73758+ &ikconfig_file_ops);
73759+#endif
73760+#else
73761 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73762 &ikconfig_file_ops);
73763+#endif
73764+
73765 if (!entry)
73766 return -ENOMEM;
73767
73768diff --git a/kernel/cred.c b/kernel/cred.c
73769index e0573a4..3874e41 100644
73770--- a/kernel/cred.c
73771+++ b/kernel/cred.c
73772@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73773 validate_creds(cred);
73774 alter_cred_subscribers(cred, -1);
73775 put_cred(cred);
73776+
73777+#ifdef CONFIG_GRKERNSEC_SETXID
73778+ cred = (struct cred *) tsk->delayed_cred;
73779+ if (cred != NULL) {
73780+ tsk->delayed_cred = NULL;
73781+ validate_creds(cred);
73782+ alter_cred_subscribers(cred, -1);
73783+ put_cred(cred);
73784+ }
73785+#endif
73786 }
73787
73788 /**
73789@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73790 * Always returns 0 thus allowing this function to be tail-called at the end
73791 * of, say, sys_setgid().
73792 */
73793-int commit_creds(struct cred *new)
73794+static int __commit_creds(struct cred *new)
73795 {
73796 struct task_struct *task = current;
73797 const struct cred *old = task->real_cred;
73798@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73799
73800 get_cred(new); /* we will require a ref for the subj creds too */
73801
73802+ gr_set_role_label(task, new->uid, new->gid);
73803+
73804 /* dumpability changes */
73805 if (!uid_eq(old->euid, new->euid) ||
73806 !gid_eq(old->egid, new->egid) ||
73807@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73808 put_cred(old);
73809 return 0;
73810 }
73811+#ifdef CONFIG_GRKERNSEC_SETXID
73812+extern int set_user(struct cred *new);
73813+
73814+void gr_delayed_cred_worker(void)
73815+{
73816+ const struct cred *new = current->delayed_cred;
73817+ struct cred *ncred;
73818+
73819+ current->delayed_cred = NULL;
73820+
73821+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73822+ // from doing get_cred on it when queueing this
73823+ put_cred(new);
73824+ return;
73825+ } else if (new == NULL)
73826+ return;
73827+
73828+ ncred = prepare_creds();
73829+ if (!ncred)
73830+ goto die;
73831+ // uids
73832+ ncred->uid = new->uid;
73833+ ncred->euid = new->euid;
73834+ ncred->suid = new->suid;
73835+ ncred->fsuid = new->fsuid;
73836+ // gids
73837+ ncred->gid = new->gid;
73838+ ncred->egid = new->egid;
73839+ ncred->sgid = new->sgid;
73840+ ncred->fsgid = new->fsgid;
73841+ // groups
73842+ if (set_groups(ncred, new->group_info) < 0) {
73843+ abort_creds(ncred);
73844+ goto die;
73845+ }
73846+ // caps
73847+ ncred->securebits = new->securebits;
73848+ ncred->cap_inheritable = new->cap_inheritable;
73849+ ncred->cap_permitted = new->cap_permitted;
73850+ ncred->cap_effective = new->cap_effective;
73851+ ncred->cap_bset = new->cap_bset;
73852+
73853+ if (set_user(ncred)) {
73854+ abort_creds(ncred);
73855+ goto die;
73856+ }
73857+
73858+ // from doing get_cred on it when queueing this
73859+ put_cred(new);
73860+
73861+ __commit_creds(ncred);
73862+ return;
73863+die:
73864+ // from doing get_cred on it when queueing this
73865+ put_cred(new);
73866+ do_group_exit(SIGKILL);
73867+}
73868+#endif
73869+
73870+int commit_creds(struct cred *new)
73871+{
73872+#ifdef CONFIG_GRKERNSEC_SETXID
73873+ int ret;
73874+ int schedule_it = 0;
73875+ struct task_struct *t;
73876+
73877+ /* we won't get called with tasklist_lock held for writing
73878+ and interrupts disabled as the cred struct in that case is
73879+ init_cred
73880+ */
73881+ if (grsec_enable_setxid && !current_is_single_threaded() &&
73882+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73883+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73884+ schedule_it = 1;
73885+ }
73886+ ret = __commit_creds(new);
73887+ if (schedule_it) {
73888+ rcu_read_lock();
73889+ read_lock(&tasklist_lock);
73890+ for (t = next_thread(current); t != current;
73891+ t = next_thread(t)) {
73892+ if (t->delayed_cred == NULL) {
73893+ t->delayed_cred = get_cred(new);
73894+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73895+ set_tsk_need_resched(t);
73896+ }
73897+ }
73898+ read_unlock(&tasklist_lock);
73899+ rcu_read_unlock();
73900+ }
73901+ return ret;
73902+#else
73903+ return __commit_creds(new);
73904+#endif
73905+}
73906+
73907 EXPORT_SYMBOL(commit_creds);
73908
73909 /**
73910diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73911index 9a61738..c5c8f3a 100644
73912--- a/kernel/debug/debug_core.c
73913+++ b/kernel/debug/debug_core.c
73914@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73915 */
73916 static atomic_t masters_in_kgdb;
73917 static atomic_t slaves_in_kgdb;
73918-static atomic_t kgdb_break_tasklet_var;
73919+static atomic_unchecked_t kgdb_break_tasklet_var;
73920 atomic_t kgdb_setting_breakpoint;
73921
73922 struct task_struct *kgdb_usethread;
73923@@ -132,7 +132,7 @@ int kgdb_single_step;
73924 static pid_t kgdb_sstep_pid;
73925
73926 /* to keep track of the CPU which is doing the single stepping*/
73927-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73928+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73929
73930 /*
73931 * If you are debugging a problem where roundup (the collection of
73932@@ -540,7 +540,7 @@ return_normal:
73933 * kernel will only try for the value of sstep_tries before
73934 * giving up and continuing on.
73935 */
73936- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73937+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73938 (kgdb_info[cpu].task &&
73939 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73940 atomic_set(&kgdb_active, -1);
73941@@ -634,8 +634,8 @@ cpu_master_loop:
73942 }
73943
73944 kgdb_restore:
73945- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73946- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73947+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73948+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73949 if (kgdb_info[sstep_cpu].task)
73950 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73951 else
73952@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73953 static void kgdb_tasklet_bpt(unsigned long ing)
73954 {
73955 kgdb_breakpoint();
73956- atomic_set(&kgdb_break_tasklet_var, 0);
73957+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73958 }
73959
73960 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
73961
73962 void kgdb_schedule_breakpoint(void)
73963 {
73964- if (atomic_read(&kgdb_break_tasklet_var) ||
73965+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
73966 atomic_read(&kgdb_active) != -1 ||
73967 atomic_read(&kgdb_setting_breakpoint))
73968 return;
73969- atomic_inc(&kgdb_break_tasklet_var);
73970+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
73971 tasklet_schedule(&kgdb_tasklet_breakpoint);
73972 }
73973 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
73974diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
73975index 8875254..7cf4928 100644
73976--- a/kernel/debug/kdb/kdb_main.c
73977+++ b/kernel/debug/kdb/kdb_main.c
73978@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
73979 continue;
73980
73981 kdb_printf("%-20s%8u 0x%p ", mod->name,
73982- mod->core_size, (void *)mod);
73983+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
73984 #ifdef CONFIG_MODULE_UNLOAD
73985 kdb_printf("%4ld ", module_refcount(mod));
73986 #endif
73987@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
73988 kdb_printf(" (Loading)");
73989 else
73990 kdb_printf(" (Live)");
73991- kdb_printf(" 0x%p", mod->module_core);
73992+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
73993
73994 #ifdef CONFIG_MODULE_UNLOAD
73995 {
73996diff --git a/kernel/events/core.c b/kernel/events/core.c
73997index 7b6646a..3cb1135 100644
73998--- a/kernel/events/core.c
73999+++ b/kernel/events/core.c
74000@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
74001 return 0;
74002 }
74003
74004-static atomic64_t perf_event_id;
74005+static atomic64_unchecked_t perf_event_id;
74006
74007 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
74008 enum event_type_t event_type);
74009@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
74010
74011 static inline u64 perf_event_count(struct perf_event *event)
74012 {
74013- return local64_read(&event->count) + atomic64_read(&event->child_count);
74014+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
74015 }
74016
74017 static u64 perf_event_read(struct perf_event *event)
74018@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
74019 mutex_lock(&event->child_mutex);
74020 total += perf_event_read(event);
74021 *enabled += event->total_time_enabled +
74022- atomic64_read(&event->child_total_time_enabled);
74023+ atomic64_read_unchecked(&event->child_total_time_enabled);
74024 *running += event->total_time_running +
74025- atomic64_read(&event->child_total_time_running);
74026+ atomic64_read_unchecked(&event->child_total_time_running);
74027
74028 list_for_each_entry(child, &event->child_list, child_list) {
74029 total += perf_event_read(child);
74030@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
74031 userpg->offset -= local64_read(&event->hw.prev_count);
74032
74033 userpg->time_enabled = enabled +
74034- atomic64_read(&event->child_total_time_enabled);
74035+ atomic64_read_unchecked(&event->child_total_time_enabled);
74036
74037 userpg->time_running = running +
74038- atomic64_read(&event->child_total_time_running);
74039+ atomic64_read_unchecked(&event->child_total_time_running);
74040
74041 arch_perf_update_userpage(userpg, now);
74042
74043@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
74044 values[n++] = perf_event_count(event);
74045 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
74046 values[n++] = enabled +
74047- atomic64_read(&event->child_total_time_enabled);
74048+ atomic64_read_unchecked(&event->child_total_time_enabled);
74049 }
74050 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
74051 values[n++] = running +
74052- atomic64_read(&event->child_total_time_running);
74053+ atomic64_read_unchecked(&event->child_total_time_running);
74054 }
74055 if (read_format & PERF_FORMAT_ID)
74056 values[n++] = primary_event_id(event);
74057@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
74058 * need to add enough zero bytes after the string to handle
74059 * the 64bit alignment we do later.
74060 */
74061- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
74062+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
74063 if (!buf) {
74064 name = strncpy(tmp, "//enomem", sizeof(tmp));
74065 goto got_name;
74066 }
74067- name = d_path(&file->f_path, buf, PATH_MAX);
74068+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
74069 if (IS_ERR(name)) {
74070 name = strncpy(tmp, "//toolong", sizeof(tmp));
74071 goto got_name;
74072@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
74073 event->parent = parent_event;
74074
74075 event->ns = get_pid_ns(task_active_pid_ns(current));
74076- event->id = atomic64_inc_return(&perf_event_id);
74077+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
74078
74079 event->state = PERF_EVENT_STATE_INACTIVE;
74080
74081@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
74082 /*
74083 * Add back the child's count to the parent's count:
74084 */
74085- atomic64_add(child_val, &parent_event->child_count);
74086- atomic64_add(child_event->total_time_enabled,
74087+ atomic64_add_unchecked(child_val, &parent_event->child_count);
74088+ atomic64_add_unchecked(child_event->total_time_enabled,
74089 &parent_event->child_total_time_enabled);
74090- atomic64_add(child_event->total_time_running,
74091+ atomic64_add_unchecked(child_event->total_time_running,
74092 &parent_event->child_total_time_running);
74093
74094 /*
74095diff --git a/kernel/exit.c b/kernel/exit.c
74096index b4df219..f13c02d 100644
74097--- a/kernel/exit.c
74098+++ b/kernel/exit.c
74099@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
74100 struct task_struct *leader;
74101 int zap_leader;
74102 repeat:
74103+#ifdef CONFIG_NET
74104+ gr_del_task_from_ip_table(p);
74105+#endif
74106+
74107 /* don't need to get the RCU readlock here - the process is dead and
74108 * can't be modifying its own credentials. But shut RCU-lockdep up */
74109 rcu_read_lock();
74110@@ -338,7 +342,7 @@ int allow_signal(int sig)
74111 * know it'll be handled, so that they don't get converted to
74112 * SIGKILL or just silently dropped.
74113 */
74114- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
74115+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
74116 recalc_sigpending();
74117 spin_unlock_irq(&current->sighand->siglock);
74118 return 0;
74119@@ -708,6 +712,8 @@ void do_exit(long code)
74120 struct task_struct *tsk = current;
74121 int group_dead;
74122
74123+ set_fs(USER_DS);
74124+
74125 profile_task_exit(tsk);
74126
74127 WARN_ON(blk_needs_flush_plug(tsk));
74128@@ -724,7 +730,6 @@ void do_exit(long code)
74129 * mm_release()->clear_child_tid() from writing to a user-controlled
74130 * kernel address.
74131 */
74132- set_fs(USER_DS);
74133
74134 ptrace_event(PTRACE_EVENT_EXIT, code);
74135
74136@@ -783,6 +788,9 @@ void do_exit(long code)
74137 tsk->exit_code = code;
74138 taskstats_exit(tsk, group_dead);
74139
74140+ gr_acl_handle_psacct(tsk, code);
74141+ gr_acl_handle_exit();
74142+
74143 exit_mm(tsk);
74144
74145 if (group_dead)
74146@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
74147 * Take down every thread in the group. This is called by fatal signals
74148 * as well as by sys_exit_group (below).
74149 */
74150-void
74151+__noreturn void
74152 do_group_exit(int exit_code)
74153 {
74154 struct signal_struct *sig = current->signal;
74155diff --git a/kernel/fork.c b/kernel/fork.c
74156index 5630e52..0cee608 100644
74157--- a/kernel/fork.c
74158+++ b/kernel/fork.c
74159@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
74160 *stackend = STACK_END_MAGIC; /* for overflow detection */
74161
74162 #ifdef CONFIG_CC_STACKPROTECTOR
74163- tsk->stack_canary = get_random_int();
74164+ tsk->stack_canary = pax_get_random_long();
74165 #endif
74166
74167 /*
74168@@ -344,13 +344,81 @@ free_tsk:
74169 }
74170
74171 #ifdef CONFIG_MMU
74172+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
74173+{
74174+ struct vm_area_struct *tmp;
74175+ unsigned long charge;
74176+ struct mempolicy *pol;
74177+ struct file *file;
74178+
74179+ charge = 0;
74180+ if (mpnt->vm_flags & VM_ACCOUNT) {
74181+ unsigned long len = vma_pages(mpnt);
74182+
74183+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74184+ goto fail_nomem;
74185+ charge = len;
74186+ }
74187+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74188+ if (!tmp)
74189+ goto fail_nomem;
74190+ *tmp = *mpnt;
74191+ tmp->vm_mm = mm;
74192+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
74193+ pol = mpol_dup(vma_policy(mpnt));
74194+ if (IS_ERR(pol))
74195+ goto fail_nomem_policy;
74196+ vma_set_policy(tmp, pol);
74197+ if (anon_vma_fork(tmp, mpnt))
74198+ goto fail_nomem_anon_vma_fork;
74199+ tmp->vm_flags &= ~VM_LOCKED;
74200+ tmp->vm_next = tmp->vm_prev = NULL;
74201+ tmp->vm_mirror = NULL;
74202+ file = tmp->vm_file;
74203+ if (file) {
74204+ struct inode *inode = file->f_path.dentry->d_inode;
74205+ struct address_space *mapping = file->f_mapping;
74206+
74207+ get_file(file);
74208+ if (tmp->vm_flags & VM_DENYWRITE)
74209+ atomic_dec(&inode->i_writecount);
74210+ mutex_lock(&mapping->i_mmap_mutex);
74211+ if (tmp->vm_flags & VM_SHARED)
74212+ mapping->i_mmap_writable++;
74213+ flush_dcache_mmap_lock(mapping);
74214+ /* insert tmp into the share list, just after mpnt */
74215+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74216+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
74217+ else
74218+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
74219+ flush_dcache_mmap_unlock(mapping);
74220+ mutex_unlock(&mapping->i_mmap_mutex);
74221+ }
74222+
74223+ /*
74224+ * Clear hugetlb-related page reserves for children. This only
74225+ * affects MAP_PRIVATE mappings. Faults generated by the child
74226+ * are not guaranteed to succeed, even if read-only
74227+ */
74228+ if (is_vm_hugetlb_page(tmp))
74229+ reset_vma_resv_huge_pages(tmp);
74230+
74231+ return tmp;
74232+
74233+fail_nomem_anon_vma_fork:
74234+ mpol_put(pol);
74235+fail_nomem_policy:
74236+ kmem_cache_free(vm_area_cachep, tmp);
74237+fail_nomem:
74238+ vm_unacct_memory(charge);
74239+ return NULL;
74240+}
74241+
74242 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74243 {
74244 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
74245 struct rb_node **rb_link, *rb_parent;
74246 int retval;
74247- unsigned long charge;
74248- struct mempolicy *pol;
74249
74250 uprobe_start_dup_mmap();
74251 down_write(&oldmm->mmap_sem);
74252@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74253 mm->locked_vm = 0;
74254 mm->mmap = NULL;
74255 mm->mmap_cache = NULL;
74256- mm->free_area_cache = oldmm->mmap_base;
74257- mm->cached_hole_size = ~0UL;
74258+ mm->free_area_cache = oldmm->free_area_cache;
74259+ mm->cached_hole_size = oldmm->cached_hole_size;
74260 mm->map_count = 0;
74261 cpumask_clear(mm_cpumask(mm));
74262 mm->mm_rb = RB_ROOT;
74263@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74264
74265 prev = NULL;
74266 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
74267- struct file *file;
74268-
74269 if (mpnt->vm_flags & VM_DONTCOPY) {
74270 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
74271 -vma_pages(mpnt));
74272 continue;
74273 }
74274- charge = 0;
74275- if (mpnt->vm_flags & VM_ACCOUNT) {
74276- unsigned long len = vma_pages(mpnt);
74277-
74278- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74279- goto fail_nomem;
74280- charge = len;
74281- }
74282- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74283- if (!tmp)
74284- goto fail_nomem;
74285- *tmp = *mpnt;
74286- INIT_LIST_HEAD(&tmp->anon_vma_chain);
74287- pol = mpol_dup(vma_policy(mpnt));
74288- retval = PTR_ERR(pol);
74289- if (IS_ERR(pol))
74290- goto fail_nomem_policy;
74291- vma_set_policy(tmp, pol);
74292- tmp->vm_mm = mm;
74293- if (anon_vma_fork(tmp, mpnt))
74294- goto fail_nomem_anon_vma_fork;
74295- tmp->vm_flags &= ~VM_LOCKED;
74296- tmp->vm_next = tmp->vm_prev = NULL;
74297- file = tmp->vm_file;
74298- if (file) {
74299- struct inode *inode = file->f_path.dentry->d_inode;
74300- struct address_space *mapping = file->f_mapping;
74301-
74302- get_file(file);
74303- if (tmp->vm_flags & VM_DENYWRITE)
74304- atomic_dec(&inode->i_writecount);
74305- mutex_lock(&mapping->i_mmap_mutex);
74306- if (tmp->vm_flags & VM_SHARED)
74307- mapping->i_mmap_writable++;
74308- flush_dcache_mmap_lock(mapping);
74309- /* insert tmp into the share list, just after mpnt */
74310- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74311- vma_nonlinear_insert(tmp,
74312- &mapping->i_mmap_nonlinear);
74313- else
74314- vma_interval_tree_insert_after(tmp, mpnt,
74315- &mapping->i_mmap);
74316- flush_dcache_mmap_unlock(mapping);
74317- mutex_unlock(&mapping->i_mmap_mutex);
74318+ tmp = dup_vma(mm, oldmm, mpnt);
74319+ if (!tmp) {
74320+ retval = -ENOMEM;
74321+ goto out;
74322 }
74323
74324 /*
74325@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74326 if (retval)
74327 goto out;
74328 }
74329+
74330+#ifdef CONFIG_PAX_SEGMEXEC
74331+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
74332+ struct vm_area_struct *mpnt_m;
74333+
74334+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
74335+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
74336+
74337+ if (!mpnt->vm_mirror)
74338+ continue;
74339+
74340+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
74341+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
74342+ mpnt->vm_mirror = mpnt_m;
74343+ } else {
74344+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
74345+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
74346+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
74347+ mpnt->vm_mirror->vm_mirror = mpnt;
74348+ }
74349+ }
74350+ BUG_ON(mpnt_m);
74351+ }
74352+#endif
74353+
74354 /* a new mm has just been created */
74355 arch_dup_mmap(oldmm, mm);
74356 retval = 0;
74357@@ -472,14 +523,6 @@ out:
74358 up_write(&oldmm->mmap_sem);
74359 uprobe_end_dup_mmap();
74360 return retval;
74361-fail_nomem_anon_vma_fork:
74362- mpol_put(pol);
74363-fail_nomem_policy:
74364- kmem_cache_free(vm_area_cachep, tmp);
74365-fail_nomem:
74366- retval = -ENOMEM;
74367- vm_unacct_memory(charge);
74368- goto out;
74369 }
74370
74371 static inline int mm_alloc_pgd(struct mm_struct *mm)
74372@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
74373 return ERR_PTR(err);
74374
74375 mm = get_task_mm(task);
74376- if (mm && mm != current->mm &&
74377- !ptrace_may_access(task, mode)) {
74378+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
74379+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
74380 mmput(mm);
74381 mm = ERR_PTR(-EACCES);
74382 }
74383@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
74384 spin_unlock(&fs->lock);
74385 return -EAGAIN;
74386 }
74387- fs->users++;
74388+ atomic_inc(&fs->users);
74389 spin_unlock(&fs->lock);
74390 return 0;
74391 }
74392 tsk->fs = copy_fs_struct(fs);
74393 if (!tsk->fs)
74394 return -ENOMEM;
74395+ /* Carry through gr_chroot_dentry and is_chrooted instead
74396+ of recomputing it here. Already copied when the task struct
74397+ is duplicated. This allows pivot_root to not be treated as
74398+ a chroot
74399+ */
74400+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
74401+
74402 return 0;
74403 }
74404
74405@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74406 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
74407 #endif
74408 retval = -EAGAIN;
74409+
74410+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
74411+
74412 if (atomic_read(&p->real_cred->user->processes) >=
74413 task_rlimit(p, RLIMIT_NPROC)) {
74414 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
74415@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74416 goto bad_fork_free_pid;
74417 }
74418
74419+ /* synchronizes with gr_set_acls()
74420+ we need to call this past the point of no return for fork()
74421+ */
74422+ gr_copy_label(p);
74423+
74424 if (clone_flags & CLONE_THREAD) {
74425 current->signal->nr_threads++;
74426 atomic_inc(&current->signal->live);
74427@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
74428 bad_fork_free:
74429 free_task(p);
74430 fork_out:
74431+ gr_log_forkfail(retval);
74432+
74433 return ERR_PTR(retval);
74434 }
74435
74436@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
74437 return -EINVAL;
74438 }
74439
74440+#ifdef CONFIG_GRKERNSEC
74441+ if (clone_flags & CLONE_NEWUSER) {
74442+ /*
74443+ * This doesn't really inspire confidence:
74444+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
74445+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
74446+ * Increases kernel attack surface in areas developers
74447+ * previously cared little about ("low importance due
74448+ * to requiring "root" capability")
74449+ * To be removed when this code receives *proper* review
74450+ */
74451+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
74452+ !capable(CAP_SETGID))
74453+ return -EPERM;
74454+ }
74455+#endif
74456+
74457 /*
74458 * Determine whether and which event to report to ptracer. When
74459 * called from kernel_thread or CLONE_UNTRACED is explicitly
74460@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
74461 if (clone_flags & CLONE_PARENT_SETTID)
74462 put_user(nr, parent_tidptr);
74463
74464+ gr_handle_brute_check();
74465+
74466 if (clone_flags & CLONE_VFORK) {
74467 p->vfork_done = &vfork;
74468 init_completion(&vfork);
74469@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
74470 return 0;
74471
74472 /* don't need lock here; in the worst case we'll do useless copy */
74473- if (fs->users == 1)
74474+ if (atomic_read(&fs->users) == 1)
74475 return 0;
74476
74477 *new_fsp = copy_fs_struct(fs);
74478@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
74479 fs = current->fs;
74480 spin_lock(&fs->lock);
74481 current->fs = new_fs;
74482- if (--fs->users)
74483+ gr_set_chroot_entries(current, &current->fs->root);
74484+ if (atomic_dec_return(&fs->users))
74485 new_fs = NULL;
74486 else
74487 new_fs = fs;
74488diff --git a/kernel/futex.c b/kernel/futex.c
74489index 8879430..31696f1 100644
74490--- a/kernel/futex.c
74491+++ b/kernel/futex.c
74492@@ -54,6 +54,7 @@
74493 #include <linux/mount.h>
74494 #include <linux/pagemap.h>
74495 #include <linux/syscalls.h>
74496+#include <linux/ptrace.h>
74497 #include <linux/signal.h>
74498 #include <linux/export.h>
74499 #include <linux/magic.h>
74500@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
74501 struct page *page, *page_head;
74502 int err, ro = 0;
74503
74504+#ifdef CONFIG_PAX_SEGMEXEC
74505+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
74506+ return -EFAULT;
74507+#endif
74508+
74509 /*
74510 * The futex address must be "naturally" aligned.
74511 */
74512@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
74513 {
74514 u32 curval;
74515 int i;
74516+ mm_segment_t oldfs;
74517
74518 /*
74519 * This will fail and we want it. Some arch implementations do
74520@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
74521 * implementation, the non-functional ones will return
74522 * -ENOSYS.
74523 */
74524+ oldfs = get_fs();
74525+ set_fs(USER_DS);
74526 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
74527 futex_cmpxchg_enabled = 1;
74528+ set_fs(oldfs);
74529
74530 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
74531 plist_head_init(&futex_queues[i].chain);
74532diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
74533index 9b22d03..6295b62 100644
74534--- a/kernel/gcov/base.c
74535+++ b/kernel/gcov/base.c
74536@@ -102,11 +102,6 @@ void gcov_enable_events(void)
74537 }
74538
74539 #ifdef CONFIG_MODULES
74540-static inline int within(void *addr, void *start, unsigned long size)
74541-{
74542- return ((addr >= start) && (addr < start + size));
74543-}
74544-
74545 /* Update list and generate events when modules are unloaded. */
74546 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74547 void *data)
74548@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74549 prev = NULL;
74550 /* Remove entries located in module from linked list. */
74551 for (info = gcov_info_head; info; info = info->next) {
74552- if (within(info, mod->module_core, mod->core_size)) {
74553+ if (within_module_core_rw((unsigned long)info, mod)) {
74554 if (prev)
74555 prev->next = info->next;
74556 else
74557diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
74558index cdd5607..c3fc919 100644
74559--- a/kernel/hrtimer.c
74560+++ b/kernel/hrtimer.c
74561@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
74562 local_irq_restore(flags);
74563 }
74564
74565-static void run_hrtimer_softirq(struct softirq_action *h)
74566+static void run_hrtimer_softirq(void)
74567 {
74568 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
74569
74570@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
74571 return NOTIFY_OK;
74572 }
74573
74574-static struct notifier_block __cpuinitdata hrtimers_nb = {
74575+static struct notifier_block hrtimers_nb = {
74576 .notifier_call = hrtimer_cpu_notify,
74577 };
74578
74579diff --git a/kernel/jump_label.c b/kernel/jump_label.c
74580index 60f48fa..7f3a770 100644
74581--- a/kernel/jump_label.c
74582+++ b/kernel/jump_label.c
74583@@ -13,6 +13,7 @@
74584 #include <linux/sort.h>
74585 #include <linux/err.h>
74586 #include <linux/static_key.h>
74587+#include <linux/mm.h>
74588
74589 #ifdef HAVE_JUMP_LABEL
74590
74591@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
74592
74593 size = (((unsigned long)stop - (unsigned long)start)
74594 / sizeof(struct jump_entry));
74595+ pax_open_kernel();
74596 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
74597+ pax_close_kernel();
74598 }
74599
74600 static void jump_label_update(struct static_key *key, int enable);
74601@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
74602 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
74603 struct jump_entry *iter;
74604
74605+ pax_open_kernel();
74606 for (iter = iter_start; iter < iter_stop; iter++) {
74607 if (within_module_init(iter->code, mod))
74608 iter->code = 0;
74609 }
74610+ pax_close_kernel();
74611 }
74612
74613 static int
74614diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
74615index 2169fee..706ccca 100644
74616--- a/kernel/kallsyms.c
74617+++ b/kernel/kallsyms.c
74618@@ -11,6 +11,9 @@
74619 * Changed the compression method from stem compression to "table lookup"
74620 * compression (see scripts/kallsyms.c for a more complete description)
74621 */
74622+#ifdef CONFIG_GRKERNSEC_HIDESYM
74623+#define __INCLUDED_BY_HIDESYM 1
74624+#endif
74625 #include <linux/kallsyms.h>
74626 #include <linux/module.h>
74627 #include <linux/init.h>
74628@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
74629
74630 static inline int is_kernel_inittext(unsigned long addr)
74631 {
74632+ if (system_state != SYSTEM_BOOTING)
74633+ return 0;
74634+
74635 if (addr >= (unsigned long)_sinittext
74636 && addr <= (unsigned long)_einittext)
74637 return 1;
74638 return 0;
74639 }
74640
74641+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74642+#ifdef CONFIG_MODULES
74643+static inline int is_module_text(unsigned long addr)
74644+{
74645+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
74646+ return 1;
74647+
74648+ addr = ktla_ktva(addr);
74649+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
74650+}
74651+#else
74652+static inline int is_module_text(unsigned long addr)
74653+{
74654+ return 0;
74655+}
74656+#endif
74657+#endif
74658+
74659 static inline int is_kernel_text(unsigned long addr)
74660 {
74661 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
74662@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
74663
74664 static inline int is_kernel(unsigned long addr)
74665 {
74666+
74667+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74668+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
74669+ return 1;
74670+
74671+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
74672+#else
74673 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
74674+#endif
74675+
74676 return 1;
74677 return in_gate_area_no_mm(addr);
74678 }
74679
74680 static int is_ksym_addr(unsigned long addr)
74681 {
74682+
74683+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74684+ if (is_module_text(addr))
74685+ return 0;
74686+#endif
74687+
74688 if (all_var)
74689 return is_kernel(addr);
74690
74691@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
74692
74693 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
74694 {
74695- iter->name[0] = '\0';
74696 iter->nameoff = get_symbol_offset(new_pos);
74697 iter->pos = new_pos;
74698 }
74699@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
74700 {
74701 struct kallsym_iter *iter = m->private;
74702
74703+#ifdef CONFIG_GRKERNSEC_HIDESYM
74704+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
74705+ return 0;
74706+#endif
74707+
74708 /* Some debugging symbols have no name. Ignore them. */
74709 if (!iter->name[0])
74710 return 0;
74711@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
74712 */
74713 type = iter->exported ? toupper(iter->type) :
74714 tolower(iter->type);
74715+
74716 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
74717 type, iter->name, iter->module_name);
74718 } else
74719@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
74720 struct kallsym_iter *iter;
74721 int ret;
74722
74723- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
74724+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
74725 if (!iter)
74726 return -ENOMEM;
74727 reset_iter(iter, 0);
74728diff --git a/kernel/kcmp.c b/kernel/kcmp.c
74729index e30ac0f..3528cac 100644
74730--- a/kernel/kcmp.c
74731+++ b/kernel/kcmp.c
74732@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
74733 struct task_struct *task1, *task2;
74734 int ret;
74735
74736+#ifdef CONFIG_GRKERNSEC
74737+ return -ENOSYS;
74738+#endif
74739+
74740 rcu_read_lock();
74741
74742 /*
74743diff --git a/kernel/kexec.c b/kernel/kexec.c
74744index 5e4bd78..00c5b91 100644
74745--- a/kernel/kexec.c
74746+++ b/kernel/kexec.c
74747@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
74748 unsigned long flags)
74749 {
74750 struct compat_kexec_segment in;
74751- struct kexec_segment out, __user *ksegments;
74752+ struct kexec_segment out;
74753+ struct kexec_segment __user *ksegments;
74754 unsigned long i, result;
74755
74756 /* Don't allow clients that don't understand the native
74757diff --git a/kernel/kmod.c b/kernel/kmod.c
74758index 0023a87..9c0c068 100644
74759--- a/kernel/kmod.c
74760+++ b/kernel/kmod.c
74761@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74762 kfree(info->argv);
74763 }
74764
74765-static int call_modprobe(char *module_name, int wait)
74766+static int call_modprobe(char *module_name, char *module_param, int wait)
74767 {
74768 static char *envp[] = {
74769 "HOME=/",
74770@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74771 NULL
74772 };
74773
74774- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74775+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74776 if (!argv)
74777 goto out;
74778
74779@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74780 argv[1] = "-q";
74781 argv[2] = "--";
74782 argv[3] = module_name; /* check free_modprobe_argv() */
74783- argv[4] = NULL;
74784+ argv[4] = module_param;
74785+ argv[5] = NULL;
74786
74787 return call_usermodehelper_fns(modprobe_path, argv, envp,
74788 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74789@@ -120,9 +121,8 @@ out:
74790 * If module auto-loading support is disabled then this function
74791 * becomes a no-operation.
74792 */
74793-int __request_module(bool wait, const char *fmt, ...)
74794+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74795 {
74796- va_list args;
74797 char module_name[MODULE_NAME_LEN];
74798 unsigned int max_modprobes;
74799 int ret;
74800@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74801 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74802 static int kmod_loop_msg;
74803
74804- va_start(args, fmt);
74805- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74806- va_end(args);
74807+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74808 if (ret >= MODULE_NAME_LEN)
74809 return -ENAMETOOLONG;
74810
74811@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
74812 if (ret)
74813 return ret;
74814
74815+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74816+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74817+ /* hack to workaround consolekit/udisks stupidity */
74818+ read_lock(&tasklist_lock);
74819+ if (!strcmp(current->comm, "mount") &&
74820+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
74821+ read_unlock(&tasklist_lock);
74822+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
74823+ return -EPERM;
74824+ }
74825+ read_unlock(&tasklist_lock);
74826+ }
74827+#endif
74828+
74829 /* If modprobe needs a service that is in a module, we get a recursive
74830 * loop. Limit the number of running kmod threads to max_threads/2 or
74831 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
74832@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
74833
74834 trace_module_request(module_name, wait, _RET_IP_);
74835
74836- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74837+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74838
74839 atomic_dec(&kmod_concurrent);
74840 return ret;
74841 }
74842+
74843+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
74844+{
74845+ va_list args;
74846+ int ret;
74847+
74848+ va_start(args, fmt);
74849+ ret = ____request_module(wait, module_param, fmt, args);
74850+ va_end(args);
74851+
74852+ return ret;
74853+}
74854+
74855+int __request_module(bool wait, const char *fmt, ...)
74856+{
74857+ va_list args;
74858+ int ret;
74859+
74860+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74861+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74862+ char module_param[MODULE_NAME_LEN];
74863+
74864+ memset(module_param, 0, sizeof(module_param));
74865+
74866+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74867+
74868+ va_start(args, fmt);
74869+ ret = ____request_module(wait, module_param, fmt, args);
74870+ va_end(args);
74871+
74872+ return ret;
74873+ }
74874+#endif
74875+
74876+ va_start(args, fmt);
74877+ ret = ____request_module(wait, NULL, fmt, args);
74878+ va_end(args);
74879+
74880+ return ret;
74881+}
74882+
74883 EXPORT_SYMBOL(__request_module);
74884 #endif /* CONFIG_MODULES */
74885
74886@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74887 *
74888 * Thus the __user pointer cast is valid here.
74889 */
74890- sys_wait4(pid, (int __user *)&ret, 0, NULL);
74891+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74892
74893 /*
74894 * If ret is 0, either ____call_usermodehelper failed and the
74895@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74896 static int proc_cap_handler(struct ctl_table *table, int write,
74897 void __user *buffer, size_t *lenp, loff_t *ppos)
74898 {
74899- struct ctl_table t;
74900+ ctl_table_no_const t;
74901 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74902 kernel_cap_t new_cap;
74903 int err, i;
74904diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74905index 098f396..fe85ff1 100644
74906--- a/kernel/kprobes.c
74907+++ b/kernel/kprobes.c
74908@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74909 * kernel image and loaded module images reside. This is required
74910 * so x86_64 can correctly handle the %rip-relative fixups.
74911 */
74912- kip->insns = module_alloc(PAGE_SIZE);
74913+ kip->insns = module_alloc_exec(PAGE_SIZE);
74914 if (!kip->insns) {
74915 kfree(kip);
74916 return NULL;
74917@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74918 */
74919 if (!list_is_singular(&kip->list)) {
74920 list_del(&kip->list);
74921- module_free(NULL, kip->insns);
74922+ module_free_exec(NULL, kip->insns);
74923 kfree(kip);
74924 }
74925 return 1;
74926@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74927 {
74928 int i, err = 0;
74929 unsigned long offset = 0, size = 0;
74930- char *modname, namebuf[128];
74931+ char *modname, namebuf[KSYM_NAME_LEN];
74932 const char *symbol_name;
74933 void *addr;
74934 struct kprobe_blackpoint *kb;
74935@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74936 kprobe_type = "k";
74937
74938 if (sym)
74939- seq_printf(pi, "%p %s %s+0x%x %s ",
74940+ seq_printf(pi, "%pK %s %s+0x%x %s ",
74941 p->addr, kprobe_type, sym, offset,
74942 (modname ? modname : " "));
74943 else
74944- seq_printf(pi, "%p %s %p ",
74945+ seq_printf(pi, "%pK %s %pK ",
74946 p->addr, kprobe_type, p->addr);
74947
74948 if (!pp)
74949@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74950 const char *sym = NULL;
74951 unsigned int i = *(loff_t *) v;
74952 unsigned long offset = 0;
74953- char *modname, namebuf[128];
74954+ char *modname, namebuf[KSYM_NAME_LEN];
74955
74956 head = &kprobe_table[i];
74957 preempt_disable();
74958diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74959index 6ada93c..dce7d5d 100644
74960--- a/kernel/ksysfs.c
74961+++ b/kernel/ksysfs.c
74962@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
74963 {
74964 if (count+1 > UEVENT_HELPER_PATH_LEN)
74965 return -ENOENT;
74966+ if (!capable(CAP_SYS_ADMIN))
74967+ return -EPERM;
74968 memcpy(uevent_helper, buf, count);
74969 uevent_helper[count] = '\0';
74970 if (count && uevent_helper[count-1] == '\n')
74971@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
74972 return count;
74973 }
74974
74975-static struct bin_attribute notes_attr = {
74976+static bin_attribute_no_const notes_attr __read_only = {
74977 .attr = {
74978 .name = "notes",
74979 .mode = S_IRUGO,
74980diff --git a/kernel/lockdep.c b/kernel/lockdep.c
74981index 7981e5b..7f2105c 100644
74982--- a/kernel/lockdep.c
74983+++ b/kernel/lockdep.c
74984@@ -590,6 +590,10 @@ static int static_obj(void *obj)
74985 end = (unsigned long) &_end,
74986 addr = (unsigned long) obj;
74987
74988+#ifdef CONFIG_PAX_KERNEXEC
74989+ start = ktla_ktva(start);
74990+#endif
74991+
74992 /*
74993 * static variable?
74994 */
74995@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
74996 if (!static_obj(lock->key)) {
74997 debug_locks_off();
74998 printk("INFO: trying to register non-static key.\n");
74999+ printk("lock:%pS key:%pS.\n", lock, lock->key);
75000 printk("the code is fine but needs lockdep annotation.\n");
75001 printk("turning off the locking correctness validator.\n");
75002 dump_stack();
75003@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
75004 if (!class)
75005 return 0;
75006 }
75007- atomic_inc((atomic_t *)&class->ops);
75008+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
75009 if (very_verbose(class)) {
75010 printk("\nacquire class [%p] %s", class->key, class->name);
75011 if (class->name_version > 1)
75012diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
75013index b2c71c5..7b88d63 100644
75014--- a/kernel/lockdep_proc.c
75015+++ b/kernel/lockdep_proc.c
75016@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
75017 return 0;
75018 }
75019
75020- seq_printf(m, "%p", class->key);
75021+ seq_printf(m, "%pK", class->key);
75022 #ifdef CONFIG_DEBUG_LOCKDEP
75023 seq_printf(m, " OPS:%8ld", class->ops);
75024 #endif
75025@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
75026
75027 list_for_each_entry(entry, &class->locks_after, entry) {
75028 if (entry->distance == 1) {
75029- seq_printf(m, " -> [%p] ", entry->class->key);
75030+ seq_printf(m, " -> [%pK] ", entry->class->key);
75031 print_name(m, entry->class);
75032 seq_puts(m, "\n");
75033 }
75034@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
75035 if (!class->key)
75036 continue;
75037
75038- seq_printf(m, "[%p] ", class->key);
75039+ seq_printf(m, "[%pK] ", class->key);
75040 print_name(m, class);
75041 seq_puts(m, "\n");
75042 }
75043@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75044 if (!i)
75045 seq_line(m, '-', 40-namelen, namelen);
75046
75047- snprintf(ip, sizeof(ip), "[<%p>]",
75048+ snprintf(ip, sizeof(ip), "[<%pK>]",
75049 (void *)class->contention_point[i]);
75050 seq_printf(m, "%40s %14lu %29s %pS\n",
75051 name, stats->contention_point[i],
75052@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75053 if (!i)
75054 seq_line(m, '-', 40-namelen, namelen);
75055
75056- snprintf(ip, sizeof(ip), "[<%p>]",
75057+ snprintf(ip, sizeof(ip), "[<%pK>]",
75058 (void *)class->contending_point[i]);
75059 seq_printf(m, "%40s %14lu %29s %pS\n",
75060 name, stats->contending_point[i],
75061diff --git a/kernel/module.c b/kernel/module.c
75062index eab0827..f488603 100644
75063--- a/kernel/module.c
75064+++ b/kernel/module.c
75065@@ -61,6 +61,7 @@
75066 #include <linux/pfn.h>
75067 #include <linux/bsearch.h>
75068 #include <linux/fips.h>
75069+#include <linux/grsecurity.h>
75070 #include <uapi/linux/module.h>
75071 #include "module-internal.h"
75072
75073@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
75074
75075 /* Bounds of module allocation, for speeding __module_address.
75076 * Protected by module_mutex. */
75077-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
75078+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
75079+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
75080
75081 int register_module_notifier(struct notifier_block * nb)
75082 {
75083@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75084 return true;
75085
75086 list_for_each_entry_rcu(mod, &modules, list) {
75087- struct symsearch arr[] = {
75088+ struct symsearch modarr[] = {
75089 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
75090 NOT_GPL_ONLY, false },
75091 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
75092@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75093 if (mod->state == MODULE_STATE_UNFORMED)
75094 continue;
75095
75096- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
75097+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
75098 return true;
75099 }
75100 return false;
75101@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
75102 static int percpu_modalloc(struct module *mod,
75103 unsigned long size, unsigned long align)
75104 {
75105- if (align > PAGE_SIZE) {
75106+ if (align-1 >= PAGE_SIZE) {
75107 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
75108 mod->name, align, PAGE_SIZE);
75109 align = PAGE_SIZE;
75110@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
75111 static ssize_t show_coresize(struct module_attribute *mattr,
75112 struct module_kobject *mk, char *buffer)
75113 {
75114- return sprintf(buffer, "%u\n", mk->mod->core_size);
75115+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
75116 }
75117
75118 static struct module_attribute modinfo_coresize =
75119@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
75120 static ssize_t show_initsize(struct module_attribute *mattr,
75121 struct module_kobject *mk, char *buffer)
75122 {
75123- return sprintf(buffer, "%u\n", mk->mod->init_size);
75124+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
75125 }
75126
75127 static struct module_attribute modinfo_initsize =
75128@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
75129 */
75130 #ifdef CONFIG_SYSFS
75131
75132-#ifdef CONFIG_KALLSYMS
75133+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75134 static inline bool sect_empty(const Elf_Shdr *sect)
75135 {
75136 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
75137@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
75138 {
75139 unsigned int notes, loaded, i;
75140 struct module_notes_attrs *notes_attrs;
75141- struct bin_attribute *nattr;
75142+ bin_attribute_no_const *nattr;
75143
75144 /* failed to create section attributes, so can't create notes */
75145 if (!mod->sect_attrs)
75146@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
75147 static int module_add_modinfo_attrs(struct module *mod)
75148 {
75149 struct module_attribute *attr;
75150- struct module_attribute *temp_attr;
75151+ module_attribute_no_const *temp_attr;
75152 int error = 0;
75153 int i;
75154
75155@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
75156
75157 static void unset_module_core_ro_nx(struct module *mod)
75158 {
75159- set_page_attributes(mod->module_core + mod->core_text_size,
75160- mod->module_core + mod->core_size,
75161+ set_page_attributes(mod->module_core_rw,
75162+ mod->module_core_rw + mod->core_size_rw,
75163 set_memory_x);
75164- set_page_attributes(mod->module_core,
75165- mod->module_core + mod->core_ro_size,
75166+ set_page_attributes(mod->module_core_rx,
75167+ mod->module_core_rx + mod->core_size_rx,
75168 set_memory_rw);
75169 }
75170
75171 static void unset_module_init_ro_nx(struct module *mod)
75172 {
75173- set_page_attributes(mod->module_init + mod->init_text_size,
75174- mod->module_init + mod->init_size,
75175+ set_page_attributes(mod->module_init_rw,
75176+ mod->module_init_rw + mod->init_size_rw,
75177 set_memory_x);
75178- set_page_attributes(mod->module_init,
75179- mod->module_init + mod->init_ro_size,
75180+ set_page_attributes(mod->module_init_rx,
75181+ mod->module_init_rx + mod->init_size_rx,
75182 set_memory_rw);
75183 }
75184
75185@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
75186 list_for_each_entry_rcu(mod, &modules, list) {
75187 if (mod->state == MODULE_STATE_UNFORMED)
75188 continue;
75189- if ((mod->module_core) && (mod->core_text_size)) {
75190- set_page_attributes(mod->module_core,
75191- mod->module_core + mod->core_text_size,
75192+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75193+ set_page_attributes(mod->module_core_rx,
75194+ mod->module_core_rx + mod->core_size_rx,
75195 set_memory_rw);
75196 }
75197- if ((mod->module_init) && (mod->init_text_size)) {
75198- set_page_attributes(mod->module_init,
75199- mod->module_init + mod->init_text_size,
75200+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75201+ set_page_attributes(mod->module_init_rx,
75202+ mod->module_init_rx + mod->init_size_rx,
75203 set_memory_rw);
75204 }
75205 }
75206@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
75207 list_for_each_entry_rcu(mod, &modules, list) {
75208 if (mod->state == MODULE_STATE_UNFORMED)
75209 continue;
75210- if ((mod->module_core) && (mod->core_text_size)) {
75211- set_page_attributes(mod->module_core,
75212- mod->module_core + mod->core_text_size,
75213+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75214+ set_page_attributes(mod->module_core_rx,
75215+ mod->module_core_rx + mod->core_size_rx,
75216 set_memory_ro);
75217 }
75218- if ((mod->module_init) && (mod->init_text_size)) {
75219- set_page_attributes(mod->module_init,
75220- mod->module_init + mod->init_text_size,
75221+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75222+ set_page_attributes(mod->module_init_rx,
75223+ mod->module_init_rx + mod->init_size_rx,
75224 set_memory_ro);
75225 }
75226 }
75227@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
75228
75229 /* This may be NULL, but that's OK */
75230 unset_module_init_ro_nx(mod);
75231- module_free(mod, mod->module_init);
75232+ module_free(mod, mod->module_init_rw);
75233+ module_free_exec(mod, mod->module_init_rx);
75234 kfree(mod->args);
75235 percpu_modfree(mod);
75236
75237 /* Free lock-classes: */
75238- lockdep_free_key_range(mod->module_core, mod->core_size);
75239+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
75240+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
75241
75242 /* Finally, free the core (containing the module structure) */
75243 unset_module_core_ro_nx(mod);
75244- module_free(mod, mod->module_core);
75245+ module_free_exec(mod, mod->module_core_rx);
75246+ module_free(mod, mod->module_core_rw);
75247
75248 #ifdef CONFIG_MPU
75249 update_protections(current->mm);
75250@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75251 int ret = 0;
75252 const struct kernel_symbol *ksym;
75253
75254+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75255+ int is_fs_load = 0;
75256+ int register_filesystem_found = 0;
75257+ char *p;
75258+
75259+ p = strstr(mod->args, "grsec_modharden_fs");
75260+ if (p) {
75261+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
75262+ /* copy \0 as well */
75263+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
75264+ is_fs_load = 1;
75265+ }
75266+#endif
75267+
75268 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
75269 const char *name = info->strtab + sym[i].st_name;
75270
75271+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75272+ /* it's a real shame this will never get ripped and copied
75273+ upstream! ;(
75274+ */
75275+ if (is_fs_load && !strcmp(name, "register_filesystem"))
75276+ register_filesystem_found = 1;
75277+#endif
75278+
75279 switch (sym[i].st_shndx) {
75280 case SHN_COMMON:
75281 /* We compiled with -fno-common. These are not
75282@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75283 ksym = resolve_symbol_wait(mod, info, name);
75284 /* Ok if resolved. */
75285 if (ksym && !IS_ERR(ksym)) {
75286+ pax_open_kernel();
75287 sym[i].st_value = ksym->value;
75288+ pax_close_kernel();
75289 break;
75290 }
75291
75292@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75293 secbase = (unsigned long)mod_percpu(mod);
75294 else
75295 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
75296+ pax_open_kernel();
75297 sym[i].st_value += secbase;
75298+ pax_close_kernel();
75299 break;
75300 }
75301 }
75302
75303+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75304+ if (is_fs_load && !register_filesystem_found) {
75305+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
75306+ ret = -EPERM;
75307+ }
75308+#endif
75309+
75310 return ret;
75311 }
75312
75313@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
75314 || s->sh_entsize != ~0UL
75315 || strstarts(sname, ".init"))
75316 continue;
75317- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
75318+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75319+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
75320+ else
75321+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
75322 pr_debug("\t%s\n", sname);
75323 }
75324- switch (m) {
75325- case 0: /* executable */
75326- mod->core_size = debug_align(mod->core_size);
75327- mod->core_text_size = mod->core_size;
75328- break;
75329- case 1: /* RO: text and ro-data */
75330- mod->core_size = debug_align(mod->core_size);
75331- mod->core_ro_size = mod->core_size;
75332- break;
75333- case 3: /* whole core */
75334- mod->core_size = debug_align(mod->core_size);
75335- break;
75336- }
75337 }
75338
75339 pr_debug("Init section allocation order:\n");
75340@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
75341 || s->sh_entsize != ~0UL
75342 || !strstarts(sname, ".init"))
75343 continue;
75344- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
75345- | INIT_OFFSET_MASK);
75346+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75347+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
75348+ else
75349+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
75350+ s->sh_entsize |= INIT_OFFSET_MASK;
75351 pr_debug("\t%s\n", sname);
75352 }
75353- switch (m) {
75354- case 0: /* executable */
75355- mod->init_size = debug_align(mod->init_size);
75356- mod->init_text_size = mod->init_size;
75357- break;
75358- case 1: /* RO: text and ro-data */
75359- mod->init_size = debug_align(mod->init_size);
75360- mod->init_ro_size = mod->init_size;
75361- break;
75362- case 3: /* whole init */
75363- mod->init_size = debug_align(mod->init_size);
75364- break;
75365- }
75366 }
75367 }
75368
75369@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75370
75371 /* Put symbol section at end of init part of module. */
75372 symsect->sh_flags |= SHF_ALLOC;
75373- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
75374+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
75375 info->index.sym) | INIT_OFFSET_MASK;
75376 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
75377
75378@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75379 }
75380
75381 /* Append room for core symbols at end of core part. */
75382- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
75383- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
75384- mod->core_size += strtab_size;
75385+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
75386+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
75387+ mod->core_size_rx += strtab_size;
75388
75389 /* Put string table section at end of init part of module. */
75390 strsect->sh_flags |= SHF_ALLOC;
75391- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
75392+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
75393 info->index.str) | INIT_OFFSET_MASK;
75394 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
75395 }
75396@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75397 /* Make sure we get permanent strtab: don't use info->strtab. */
75398 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
75399
75400+ pax_open_kernel();
75401+
75402 /* Set types up while we still have access to sections. */
75403 for (i = 0; i < mod->num_symtab; i++)
75404 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
75405
75406- mod->core_symtab = dst = mod->module_core + info->symoffs;
75407- mod->core_strtab = s = mod->module_core + info->stroffs;
75408+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
75409+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
75410 src = mod->symtab;
75411 for (ndst = i = 0; i < mod->num_symtab; i++) {
75412 if (i == 0 ||
75413@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75414 }
75415 }
75416 mod->core_num_syms = ndst;
75417+
75418+ pax_close_kernel();
75419 }
75420 #else
75421 static inline void layout_symtab(struct module *mod, struct load_info *info)
75422@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
75423 return vmalloc_exec(size);
75424 }
75425
75426-static void *module_alloc_update_bounds(unsigned long size)
75427+static void *module_alloc_update_bounds_rw(unsigned long size)
75428 {
75429 void *ret = module_alloc(size);
75430
75431 if (ret) {
75432 mutex_lock(&module_mutex);
75433 /* Update module bounds. */
75434- if ((unsigned long)ret < module_addr_min)
75435- module_addr_min = (unsigned long)ret;
75436- if ((unsigned long)ret + size > module_addr_max)
75437- module_addr_max = (unsigned long)ret + size;
75438+ if ((unsigned long)ret < module_addr_min_rw)
75439+ module_addr_min_rw = (unsigned long)ret;
75440+ if ((unsigned long)ret + size > module_addr_max_rw)
75441+ module_addr_max_rw = (unsigned long)ret + size;
75442+ mutex_unlock(&module_mutex);
75443+ }
75444+ return ret;
75445+}
75446+
75447+static void *module_alloc_update_bounds_rx(unsigned long size)
75448+{
75449+ void *ret = module_alloc_exec(size);
75450+
75451+ if (ret) {
75452+ mutex_lock(&module_mutex);
75453+ /* Update module bounds. */
75454+ if ((unsigned long)ret < module_addr_min_rx)
75455+ module_addr_min_rx = (unsigned long)ret;
75456+ if ((unsigned long)ret + size > module_addr_max_rx)
75457+ module_addr_max_rx = (unsigned long)ret + size;
75458 mutex_unlock(&module_mutex);
75459 }
75460 return ret;
75461@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
75462 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75463 {
75464 const char *modmagic = get_modinfo(info, "vermagic");
75465+ const char *license = get_modinfo(info, "license");
75466 int err;
75467
75468+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
75469+ if (!license || !license_is_gpl_compatible(license))
75470+ return -ENOEXEC;
75471+#endif
75472+
75473 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
75474 modmagic = NULL;
75475
75476@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75477 }
75478
75479 /* Set up license info based on the info section */
75480- set_license(mod, get_modinfo(info, "license"));
75481+ set_license(mod, license);
75482
75483 return 0;
75484 }
75485@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
75486 void *ptr;
75487
75488 /* Do the allocs. */
75489- ptr = module_alloc_update_bounds(mod->core_size);
75490+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
75491 /*
75492 * The pointer to this block is stored in the module structure
75493 * which is inside the block. Just mark it as not being a
75494@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
75495 if (!ptr)
75496 return -ENOMEM;
75497
75498- memset(ptr, 0, mod->core_size);
75499- mod->module_core = ptr;
75500+ memset(ptr, 0, mod->core_size_rw);
75501+ mod->module_core_rw = ptr;
75502
75503- if (mod->init_size) {
75504- ptr = module_alloc_update_bounds(mod->init_size);
75505+ if (mod->init_size_rw) {
75506+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
75507 /*
75508 * The pointer to this block is stored in the module structure
75509 * which is inside the block. This block doesn't need to be
75510@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
75511 */
75512 kmemleak_ignore(ptr);
75513 if (!ptr) {
75514- module_free(mod, mod->module_core);
75515+ module_free(mod, mod->module_core_rw);
75516 return -ENOMEM;
75517 }
75518- memset(ptr, 0, mod->init_size);
75519- mod->module_init = ptr;
75520+ memset(ptr, 0, mod->init_size_rw);
75521+ mod->module_init_rw = ptr;
75522 } else
75523- mod->module_init = NULL;
75524+ mod->module_init_rw = NULL;
75525+
75526+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
75527+ kmemleak_not_leak(ptr);
75528+ if (!ptr) {
75529+ if (mod->module_init_rw)
75530+ module_free(mod, mod->module_init_rw);
75531+ module_free(mod, mod->module_core_rw);
75532+ return -ENOMEM;
75533+ }
75534+
75535+ pax_open_kernel();
75536+ memset(ptr, 0, mod->core_size_rx);
75537+ pax_close_kernel();
75538+ mod->module_core_rx = ptr;
75539+
75540+ if (mod->init_size_rx) {
75541+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
75542+ kmemleak_ignore(ptr);
75543+ if (!ptr && mod->init_size_rx) {
75544+ module_free_exec(mod, mod->module_core_rx);
75545+ if (mod->module_init_rw)
75546+ module_free(mod, mod->module_init_rw);
75547+ module_free(mod, mod->module_core_rw);
75548+ return -ENOMEM;
75549+ }
75550+
75551+ pax_open_kernel();
75552+ memset(ptr, 0, mod->init_size_rx);
75553+ pax_close_kernel();
75554+ mod->module_init_rx = ptr;
75555+ } else
75556+ mod->module_init_rx = NULL;
75557
75558 /* Transfer each section which specifies SHF_ALLOC */
75559 pr_debug("final section addresses:\n");
75560@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
75561 if (!(shdr->sh_flags & SHF_ALLOC))
75562 continue;
75563
75564- if (shdr->sh_entsize & INIT_OFFSET_MASK)
75565- dest = mod->module_init
75566- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75567- else
75568- dest = mod->module_core + shdr->sh_entsize;
75569+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
75570+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75571+ dest = mod->module_init_rw
75572+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75573+ else
75574+ dest = mod->module_init_rx
75575+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75576+ } else {
75577+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75578+ dest = mod->module_core_rw + shdr->sh_entsize;
75579+ else
75580+ dest = mod->module_core_rx + shdr->sh_entsize;
75581+ }
75582+
75583+ if (shdr->sh_type != SHT_NOBITS) {
75584+
75585+#ifdef CONFIG_PAX_KERNEXEC
75586+#ifdef CONFIG_X86_64
75587+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
75588+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
75589+#endif
75590+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
75591+ pax_open_kernel();
75592+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75593+ pax_close_kernel();
75594+ } else
75595+#endif
75596
75597- if (shdr->sh_type != SHT_NOBITS)
75598 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75599+ }
75600 /* Update sh_addr to point to copy in image. */
75601- shdr->sh_addr = (unsigned long)dest;
75602+
75603+#ifdef CONFIG_PAX_KERNEXEC
75604+ if (shdr->sh_flags & SHF_EXECINSTR)
75605+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
75606+ else
75607+#endif
75608+
75609+ shdr->sh_addr = (unsigned long)dest;
75610 pr_debug("\t0x%lx %s\n",
75611 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
75612 }
75613@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
75614 * Do it before processing of module parameters, so the module
75615 * can provide parameter accessor functions of its own.
75616 */
75617- if (mod->module_init)
75618- flush_icache_range((unsigned long)mod->module_init,
75619- (unsigned long)mod->module_init
75620- + mod->init_size);
75621- flush_icache_range((unsigned long)mod->module_core,
75622- (unsigned long)mod->module_core + mod->core_size);
75623+ if (mod->module_init_rx)
75624+ flush_icache_range((unsigned long)mod->module_init_rx,
75625+ (unsigned long)mod->module_init_rx
75626+ + mod->init_size_rx);
75627+ flush_icache_range((unsigned long)mod->module_core_rx,
75628+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
75629
75630 set_fs(old_fs);
75631 }
75632@@ -2983,8 +3088,10 @@ out:
75633 static void module_deallocate(struct module *mod, struct load_info *info)
75634 {
75635 percpu_modfree(mod);
75636- module_free(mod, mod->module_init);
75637- module_free(mod, mod->module_core);
75638+ module_free_exec(mod, mod->module_init_rx);
75639+ module_free_exec(mod, mod->module_core_rx);
75640+ module_free(mod, mod->module_init_rw);
75641+ module_free(mod, mod->module_core_rw);
75642 }
75643
75644 int __weak module_finalize(const Elf_Ehdr *hdr,
75645@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
75646 static int post_relocation(struct module *mod, const struct load_info *info)
75647 {
75648 /* Sort exception table now relocations are done. */
75649+ pax_open_kernel();
75650 sort_extable(mod->extable, mod->extable + mod->num_exentries);
75651+ pax_close_kernel();
75652
75653 /* Copy relocated percpu area over. */
75654 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
75655@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
75656 MODULE_STATE_COMING, mod);
75657
75658 /* Set RO and NX regions for core */
75659- set_section_ro_nx(mod->module_core,
75660- mod->core_text_size,
75661- mod->core_ro_size,
75662- mod->core_size);
75663+ set_section_ro_nx(mod->module_core_rx,
75664+ mod->core_size_rx,
75665+ mod->core_size_rx,
75666+ mod->core_size_rx);
75667
75668 /* Set RO and NX regions for init */
75669- set_section_ro_nx(mod->module_init,
75670- mod->init_text_size,
75671- mod->init_ro_size,
75672- mod->init_size);
75673+ set_section_ro_nx(mod->module_init_rx,
75674+ mod->init_size_rx,
75675+ mod->init_size_rx,
75676+ mod->init_size_rx);
75677
75678 do_mod_ctors(mod);
75679 /* Start the module */
75680@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
75681 mod->strtab = mod->core_strtab;
75682 #endif
75683 unset_module_init_ro_nx(mod);
75684- module_free(mod, mod->module_init);
75685- mod->module_init = NULL;
75686- mod->init_size = 0;
75687- mod->init_ro_size = 0;
75688- mod->init_text_size = 0;
75689+ module_free(mod, mod->module_init_rw);
75690+ module_free_exec(mod, mod->module_init_rx);
75691+ mod->module_init_rw = NULL;
75692+ mod->module_init_rx = NULL;
75693+ mod->init_size_rw = 0;
75694+ mod->init_size_rx = 0;
75695 mutex_unlock(&module_mutex);
75696 wake_up_all(&module_wq);
75697
75698@@ -3209,9 +3319,38 @@ again:
75699 if (err)
75700 goto free_unload;
75701
75702+ /* Now copy in args */
75703+ mod->args = strndup_user(uargs, ~0UL >> 1);
75704+ if (IS_ERR(mod->args)) {
75705+ err = PTR_ERR(mod->args);
75706+ goto free_unload;
75707+ }
75708+
75709 /* Set up MODINFO_ATTR fields */
75710 setup_modinfo(mod, info);
75711
75712+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75713+ {
75714+ char *p, *p2;
75715+
75716+ if (strstr(mod->args, "grsec_modharden_netdev")) {
75717+ 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);
75718+ err = -EPERM;
75719+ goto free_modinfo;
75720+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
75721+ p += sizeof("grsec_modharden_normal") - 1;
75722+ p2 = strstr(p, "_");
75723+ if (p2) {
75724+ *p2 = '\0';
75725+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
75726+ *p2 = '_';
75727+ }
75728+ err = -EPERM;
75729+ goto free_modinfo;
75730+ }
75731+ }
75732+#endif
75733+
75734 /* Fix up syms, so that st_value is a pointer to location. */
75735 err = simplify_symbols(mod, info);
75736 if (err < 0)
75737@@ -3227,13 +3366,6 @@ again:
75738
75739 flush_module_icache(mod);
75740
75741- /* Now copy in args */
75742- mod->args = strndup_user(uargs, ~0UL >> 1);
75743- if (IS_ERR(mod->args)) {
75744- err = PTR_ERR(mod->args);
75745- goto free_arch_cleanup;
75746- }
75747-
75748 dynamic_debug_setup(info->debug, info->num_debug);
75749
75750 mutex_lock(&module_mutex);
75751@@ -3278,11 +3410,10 @@ again:
75752 mutex_unlock(&module_mutex);
75753 dynamic_debug_remove(info->debug);
75754 synchronize_sched();
75755- kfree(mod->args);
75756- free_arch_cleanup:
75757 module_arch_cleanup(mod);
75758 free_modinfo:
75759 free_modinfo(mod);
75760+ kfree(mod->args);
75761 free_unload:
75762 module_unload_free(mod);
75763 unlink_mod:
75764@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75765 unsigned long nextval;
75766
75767 /* At worse, next value is at end of module */
75768- if (within_module_init(addr, mod))
75769- nextval = (unsigned long)mod->module_init+mod->init_text_size;
75770+ if (within_module_init_rx(addr, mod))
75771+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75772+ else if (within_module_init_rw(addr, mod))
75773+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75774+ else if (within_module_core_rx(addr, mod))
75775+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75776+ else if (within_module_core_rw(addr, mod))
75777+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75778 else
75779- nextval = (unsigned long)mod->module_core+mod->core_text_size;
75780+ return NULL;
75781
75782 /* Scan for closest preceding symbol, and next symbol. (ELF
75783 starts real symbols at 1). */
75784@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75785 return 0;
75786
75787 seq_printf(m, "%s %u",
75788- mod->name, mod->init_size + mod->core_size);
75789+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75790 print_unload_info(m, mod);
75791
75792 /* Informative for users. */
75793@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75794 mod->state == MODULE_STATE_COMING ? "Loading":
75795 "Live");
75796 /* Used by oprofile and other similar tools. */
75797- seq_printf(m, " 0x%pK", mod->module_core);
75798+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75799
75800 /* Taints info */
75801 if (mod->taints)
75802@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75803
75804 static int __init proc_modules_init(void)
75805 {
75806+#ifndef CONFIG_GRKERNSEC_HIDESYM
75807+#ifdef CONFIG_GRKERNSEC_PROC_USER
75808+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75809+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75810+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
75811+#else
75812 proc_create("modules", 0, NULL, &proc_modules_operations);
75813+#endif
75814+#else
75815+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75816+#endif
75817 return 0;
75818 }
75819 module_init(proc_modules_init);
75820@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
75821 {
75822 struct module *mod;
75823
75824- if (addr < module_addr_min || addr > module_addr_max)
75825+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
75826+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
75827 return NULL;
75828
75829 list_for_each_entry_rcu(mod, &modules, list) {
75830 if (mod->state == MODULE_STATE_UNFORMED)
75831 continue;
75832- if (within_module_core(addr, mod)
75833- || within_module_init(addr, mod))
75834+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
75835 return mod;
75836 }
75837 return NULL;
75838@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
75839 */
75840 struct module *__module_text_address(unsigned long addr)
75841 {
75842- struct module *mod = __module_address(addr);
75843+ struct module *mod;
75844+
75845+#ifdef CONFIG_X86_32
75846+ addr = ktla_ktva(addr);
75847+#endif
75848+
75849+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
75850+ return NULL;
75851+
75852+ mod = __module_address(addr);
75853+
75854 if (mod) {
75855 /* Make sure it's within the text section. */
75856- if (!within(addr, mod->module_init, mod->init_text_size)
75857- && !within(addr, mod->module_core, mod->core_text_size))
75858+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
75859 mod = NULL;
75860 }
75861 return mod;
75862diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
75863index 7e3443f..b2a1e6b 100644
75864--- a/kernel/mutex-debug.c
75865+++ b/kernel/mutex-debug.c
75866@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75867 }
75868
75869 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75870- struct thread_info *ti)
75871+ struct task_struct *task)
75872 {
75873 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75874
75875 /* Mark the current thread as blocked on the lock: */
75876- ti->task->blocked_on = waiter;
75877+ task->blocked_on = waiter;
75878 }
75879
75880 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75881- struct thread_info *ti)
75882+ struct task_struct *task)
75883 {
75884 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75885- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75886- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75887- ti->task->blocked_on = NULL;
75888+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
75889+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75890+ task->blocked_on = NULL;
75891
75892 list_del_init(&waiter->list);
75893 waiter->task = NULL;
75894diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75895index 0799fd3..d06ae3b 100644
75896--- a/kernel/mutex-debug.h
75897+++ b/kernel/mutex-debug.h
75898@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75899 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75900 extern void debug_mutex_add_waiter(struct mutex *lock,
75901 struct mutex_waiter *waiter,
75902- struct thread_info *ti);
75903+ struct task_struct *task);
75904 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75905- struct thread_info *ti);
75906+ struct task_struct *task);
75907 extern void debug_mutex_unlock(struct mutex *lock);
75908 extern void debug_mutex_init(struct mutex *lock, const char *name,
75909 struct lock_class_key *key);
75910diff --git a/kernel/mutex.c b/kernel/mutex.c
75911index a307cc9..27fd2e9 100644
75912--- a/kernel/mutex.c
75913+++ b/kernel/mutex.c
75914@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75915 spin_lock_mutex(&lock->wait_lock, flags);
75916
75917 debug_mutex_lock_common(lock, &waiter);
75918- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75919+ debug_mutex_add_waiter(lock, &waiter, task);
75920
75921 /* add waiting tasks to the end of the waitqueue (FIFO): */
75922 list_add_tail(&waiter.list, &lock->wait_list);
75923@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75924 * TASK_UNINTERRUPTIBLE case.)
75925 */
75926 if (unlikely(signal_pending_state(state, task))) {
75927- mutex_remove_waiter(lock, &waiter,
75928- task_thread_info(task));
75929+ mutex_remove_waiter(lock, &waiter, task);
75930 mutex_release(&lock->dep_map, 1, ip);
75931 spin_unlock_mutex(&lock->wait_lock, flags);
75932
75933@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75934 done:
75935 lock_acquired(&lock->dep_map, ip);
75936 /* got the lock - rejoice! */
75937- mutex_remove_waiter(lock, &waiter, current_thread_info());
75938+ mutex_remove_waiter(lock, &waiter, task);
75939 mutex_set_owner(lock);
75940
75941 /* set it to 0 if there are no waiters left: */
75942diff --git a/kernel/notifier.c b/kernel/notifier.c
75943index 2d5cc4c..d9ea600 100644
75944--- a/kernel/notifier.c
75945+++ b/kernel/notifier.c
75946@@ -5,6 +5,7 @@
75947 #include <linux/rcupdate.h>
75948 #include <linux/vmalloc.h>
75949 #include <linux/reboot.h>
75950+#include <linux/mm.h>
75951
75952 /*
75953 * Notifier list for kernel code which wants to be called
75954@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75955 while ((*nl) != NULL) {
75956 if (n->priority > (*nl)->priority)
75957 break;
75958- nl = &((*nl)->next);
75959+ nl = (struct notifier_block **)&((*nl)->next);
75960 }
75961- n->next = *nl;
75962+ pax_open_kernel();
75963+ *(const void **)&n->next = *nl;
75964 rcu_assign_pointer(*nl, n);
75965+ pax_close_kernel();
75966 return 0;
75967 }
75968
75969@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
75970 return 0;
75971 if (n->priority > (*nl)->priority)
75972 break;
75973- nl = &((*nl)->next);
75974+ nl = (struct notifier_block **)&((*nl)->next);
75975 }
75976- n->next = *nl;
75977+ pax_open_kernel();
75978+ *(const void **)&n->next = *nl;
75979 rcu_assign_pointer(*nl, n);
75980+ pax_close_kernel();
75981 return 0;
75982 }
75983
75984@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
75985 {
75986 while ((*nl) != NULL) {
75987 if ((*nl) == n) {
75988+ pax_open_kernel();
75989 rcu_assign_pointer(*nl, n->next);
75990+ pax_close_kernel();
75991 return 0;
75992 }
75993- nl = &((*nl)->next);
75994+ nl = (struct notifier_block **)&((*nl)->next);
75995 }
75996 return -ENOENT;
75997 }
75998diff --git a/kernel/panic.c b/kernel/panic.c
75999index e1b2822..5edc1d9 100644
76000--- a/kernel/panic.c
76001+++ b/kernel/panic.c
76002@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
76003 const char *board;
76004
76005 printk(KERN_WARNING "------------[ cut here ]------------\n");
76006- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
76007+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
76008 board = dmi_get_system_info(DMI_PRODUCT_NAME);
76009 if (board)
76010 printk(KERN_WARNING "Hardware name: %s\n", board);
76011@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
76012 */
76013 void __stack_chk_fail(void)
76014 {
76015- panic("stack-protector: Kernel stack is corrupted in: %p\n",
76016+ dump_stack();
76017+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
76018 __builtin_return_address(0));
76019 }
76020 EXPORT_SYMBOL(__stack_chk_fail);
76021diff --git a/kernel/pid.c b/kernel/pid.c
76022index f2c6a68..4922d97 100644
76023--- a/kernel/pid.c
76024+++ b/kernel/pid.c
76025@@ -33,6 +33,7 @@
76026 #include <linux/rculist.h>
76027 #include <linux/bootmem.h>
76028 #include <linux/hash.h>
76029+#include <linux/security.h>
76030 #include <linux/pid_namespace.h>
76031 #include <linux/init_task.h>
76032 #include <linux/syscalls.h>
76033@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
76034
76035 int pid_max = PID_MAX_DEFAULT;
76036
76037-#define RESERVED_PIDS 300
76038+#define RESERVED_PIDS 500
76039
76040 int pid_max_min = RESERVED_PIDS + 1;
76041 int pid_max_max = PID_MAX_LIMIT;
76042@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
76043 */
76044 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
76045 {
76046+ struct task_struct *task;
76047+
76048 rcu_lockdep_assert(rcu_read_lock_held(),
76049 "find_task_by_pid_ns() needs rcu_read_lock()"
76050 " protection");
76051- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76052+
76053+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76054+
76055+ if (gr_pid_is_chrooted(task))
76056+ return NULL;
76057+
76058+ return task;
76059 }
76060
76061 struct task_struct *find_task_by_vpid(pid_t vnr)
76062@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
76063 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
76064 }
76065
76066+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
76067+{
76068+ rcu_lockdep_assert(rcu_read_lock_held(),
76069+ "find_task_by_pid_ns() needs rcu_read_lock()"
76070+ " protection");
76071+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
76072+}
76073+
76074 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
76075 {
76076 struct pid *pid;
76077diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
76078index c1c3dc1..bbeaf31 100644
76079--- a/kernel/pid_namespace.c
76080+++ b/kernel/pid_namespace.c
76081@@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
76082 void __user *buffer, size_t *lenp, loff_t *ppos)
76083 {
76084 struct pid_namespace *pid_ns = task_active_pid_ns(current);
76085- struct ctl_table tmp = *table;
76086+ ctl_table_no_const tmp = *table;
76087
76088 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
76089 return -EPERM;
76090diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
76091index 942ca27..111e609 100644
76092--- a/kernel/posix-cpu-timers.c
76093+++ b/kernel/posix-cpu-timers.c
76094@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
76095
76096 static __init int init_posix_cpu_timers(void)
76097 {
76098- struct k_clock process = {
76099+ static struct k_clock process = {
76100 .clock_getres = process_cpu_clock_getres,
76101 .clock_get = process_cpu_clock_get,
76102 .timer_create = process_cpu_timer_create,
76103 .nsleep = process_cpu_nsleep,
76104 .nsleep_restart = process_cpu_nsleep_restart,
76105 };
76106- struct k_clock thread = {
76107+ static struct k_clock thread = {
76108 .clock_getres = thread_cpu_clock_getres,
76109 .clock_get = thread_cpu_clock_get,
76110 .timer_create = thread_cpu_timer_create,
76111diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
76112index e885be1..380fe76 100644
76113--- a/kernel/posix-timers.c
76114+++ b/kernel/posix-timers.c
76115@@ -43,6 +43,7 @@
76116 #include <linux/idr.h>
76117 #include <linux/posix-clock.h>
76118 #include <linux/posix-timers.h>
76119+#include <linux/grsecurity.h>
76120 #include <linux/syscalls.h>
76121 #include <linux/wait.h>
76122 #include <linux/workqueue.h>
76123@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
76124 * which we beg off on and pass to do_sys_settimeofday().
76125 */
76126
76127-static struct k_clock posix_clocks[MAX_CLOCKS];
76128+static struct k_clock *posix_clocks[MAX_CLOCKS];
76129
76130 /*
76131 * These ones are defined below.
76132@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
76133 */
76134 static __init int init_posix_timers(void)
76135 {
76136- struct k_clock clock_realtime = {
76137+ static struct k_clock clock_realtime = {
76138 .clock_getres = hrtimer_get_res,
76139 .clock_get = posix_clock_realtime_get,
76140 .clock_set = posix_clock_realtime_set,
76141@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
76142 .timer_get = common_timer_get,
76143 .timer_del = common_timer_del,
76144 };
76145- struct k_clock clock_monotonic = {
76146+ static struct k_clock clock_monotonic = {
76147 .clock_getres = hrtimer_get_res,
76148 .clock_get = posix_ktime_get_ts,
76149 .nsleep = common_nsleep,
76150@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
76151 .timer_get = common_timer_get,
76152 .timer_del = common_timer_del,
76153 };
76154- struct k_clock clock_monotonic_raw = {
76155+ static struct k_clock clock_monotonic_raw = {
76156 .clock_getres = hrtimer_get_res,
76157 .clock_get = posix_get_monotonic_raw,
76158 };
76159- struct k_clock clock_realtime_coarse = {
76160+ static struct k_clock clock_realtime_coarse = {
76161 .clock_getres = posix_get_coarse_res,
76162 .clock_get = posix_get_realtime_coarse,
76163 };
76164- struct k_clock clock_monotonic_coarse = {
76165+ static struct k_clock clock_monotonic_coarse = {
76166 .clock_getres = posix_get_coarse_res,
76167 .clock_get = posix_get_monotonic_coarse,
76168 };
76169- struct k_clock clock_boottime = {
76170+ static struct k_clock clock_boottime = {
76171 .clock_getres = hrtimer_get_res,
76172 .clock_get = posix_get_boottime,
76173 .nsleep = common_nsleep,
76174@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
76175 return;
76176 }
76177
76178- posix_clocks[clock_id] = *new_clock;
76179+ posix_clocks[clock_id] = new_clock;
76180 }
76181 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
76182
76183@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
76184 return (id & CLOCKFD_MASK) == CLOCKFD ?
76185 &clock_posix_dynamic : &clock_posix_cpu;
76186
76187- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
76188+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
76189 return NULL;
76190- return &posix_clocks[id];
76191+ return posix_clocks[id];
76192 }
76193
76194 static int common_timer_create(struct k_itimer *new_timer)
76195@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
76196 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
76197 return -EFAULT;
76198
76199+ /* only the CLOCK_REALTIME clock can be set, all other clocks
76200+ have their clock_set fptr set to a nosettime dummy function
76201+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
76202+ call common_clock_set, which calls do_sys_settimeofday, which
76203+ we hook
76204+ */
76205+
76206 return kc->clock_set(which_clock, &new_tp);
76207 }
76208
76209diff --git a/kernel/power/process.c b/kernel/power/process.c
76210index d5a258b..4271191 100644
76211--- a/kernel/power/process.c
76212+++ b/kernel/power/process.c
76213@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
76214 u64 elapsed_csecs64;
76215 unsigned int elapsed_csecs;
76216 bool wakeup = false;
76217+ bool timedout = false;
76218
76219 do_gettimeofday(&start);
76220
76221@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
76222
76223 while (true) {
76224 todo = 0;
76225+ if (time_after(jiffies, end_time))
76226+ timedout = true;
76227 read_lock(&tasklist_lock);
76228 do_each_thread(g, p) {
76229 if (p == current || !freeze_task(p))
76230 continue;
76231
76232- if (!freezer_should_skip(p))
76233+ if (!freezer_should_skip(p)) {
76234 todo++;
76235+ if (timedout) {
76236+ printk(KERN_ERR "Task refusing to freeze:\n");
76237+ sched_show_task(p);
76238+ }
76239+ }
76240 } while_each_thread(g, p);
76241 read_unlock(&tasklist_lock);
76242
76243@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
76244 todo += wq_busy;
76245 }
76246
76247- if (!todo || time_after(jiffies, end_time))
76248+ if (!todo || timedout)
76249 break;
76250
76251 if (pm_wakeup_pending()) {
76252diff --git a/kernel/printk.c b/kernel/printk.c
76253index 267ce78..2487112 100644
76254--- a/kernel/printk.c
76255+++ b/kernel/printk.c
76256@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
76257 return ret;
76258 }
76259
76260+static int check_syslog_permissions(int type, bool from_file);
76261+
76262 static int devkmsg_open(struct inode *inode, struct file *file)
76263 {
76264 struct devkmsg_user *user;
76265 int err;
76266
76267+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
76268+ if (err)
76269+ return err;
76270+
76271 /* write-only does not need any file context */
76272 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
76273 return 0;
76274@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
76275 if (dmesg_restrict)
76276 return 1;
76277 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
76278- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76279+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76280 }
76281
76282 static int check_syslog_permissions(int type, bool from_file)
76283@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
76284 if (from_file && type != SYSLOG_ACTION_OPEN)
76285 return 0;
76286
76287+#ifdef CONFIG_GRKERNSEC_DMESG
76288+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
76289+ return -EPERM;
76290+#endif
76291+
76292 if (syslog_action_restricted(type)) {
76293 if (capable(CAP_SYSLOG))
76294 return 0;
76295diff --git a/kernel/profile.c b/kernel/profile.c
76296index 1f39181..86093471 100644
76297--- a/kernel/profile.c
76298+++ b/kernel/profile.c
76299@@ -40,7 +40,7 @@ struct profile_hit {
76300 /* Oprofile timer tick hook */
76301 static int (*timer_hook)(struct pt_regs *) __read_mostly;
76302
76303-static atomic_t *prof_buffer;
76304+static atomic_unchecked_t *prof_buffer;
76305 static unsigned long prof_len, prof_shift;
76306
76307 int prof_on __read_mostly;
76308@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
76309 hits[i].pc = 0;
76310 continue;
76311 }
76312- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76313+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76314 hits[i].hits = hits[i].pc = 0;
76315 }
76316 }
76317@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76318 * Add the current hit(s) and flush the write-queue out
76319 * to the global buffer:
76320 */
76321- atomic_add(nr_hits, &prof_buffer[pc]);
76322+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
76323 for (i = 0; i < NR_PROFILE_HIT; ++i) {
76324- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76325+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76326 hits[i].pc = hits[i].hits = 0;
76327 }
76328 out:
76329@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76330 {
76331 unsigned long pc;
76332 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
76333- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76334+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76335 }
76336 #endif /* !CONFIG_SMP */
76337
76338@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
76339 return -EFAULT;
76340 buf++; p++; count--; read++;
76341 }
76342- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
76343+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
76344 if (copy_to_user(buf, (void *)pnt, count))
76345 return -EFAULT;
76346 read += count;
76347@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
76348 }
76349 #endif
76350 profile_discard_flip_buffers();
76351- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
76352+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
76353 return count;
76354 }
76355
76356diff --git a/kernel/ptrace.c b/kernel/ptrace.c
76357index 6cbeaae..cfe7ff0 100644
76358--- a/kernel/ptrace.c
76359+++ b/kernel/ptrace.c
76360@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
76361 if (seize)
76362 flags |= PT_SEIZED;
76363 rcu_read_lock();
76364- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76365+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76366 flags |= PT_PTRACE_CAP;
76367 rcu_read_unlock();
76368 task->ptrace = flags;
76369@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
76370 break;
76371 return -EIO;
76372 }
76373- if (copy_to_user(dst, buf, retval))
76374+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
76375 return -EFAULT;
76376 copied += retval;
76377 src += retval;
76378@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
76379 bool seized = child->ptrace & PT_SEIZED;
76380 int ret = -EIO;
76381 siginfo_t siginfo, *si;
76382- void __user *datavp = (void __user *) data;
76383+ void __user *datavp = (__force void __user *) data;
76384 unsigned long __user *datalp = datavp;
76385 unsigned long flags;
76386
76387@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
76388 goto out;
76389 }
76390
76391+ if (gr_handle_ptrace(child, request)) {
76392+ ret = -EPERM;
76393+ goto out_put_task_struct;
76394+ }
76395+
76396 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76397 ret = ptrace_attach(child, request, addr, data);
76398 /*
76399 * Some architectures need to do book-keeping after
76400 * a ptrace attach.
76401 */
76402- if (!ret)
76403+ if (!ret) {
76404 arch_ptrace_attach(child);
76405+ gr_audit_ptrace(child);
76406+ }
76407 goto out_put_task_struct;
76408 }
76409
76410@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
76411 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
76412 if (copied != sizeof(tmp))
76413 return -EIO;
76414- return put_user(tmp, (unsigned long __user *)data);
76415+ return put_user(tmp, (__force unsigned long __user *)data);
76416 }
76417
76418 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
76419@@ -1051,7 +1058,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
76420 }
76421
76422 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76423- compat_long_t addr, compat_long_t data)
76424+ compat_ulong_t addr, compat_ulong_t data)
76425 {
76426 struct task_struct *child;
76427 long ret;
76428@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76429 goto out;
76430 }
76431
76432+ if (gr_handle_ptrace(child, request)) {
76433+ ret = -EPERM;
76434+ goto out_put_task_struct;
76435+ }
76436+
76437 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76438 ret = ptrace_attach(child, request, addr, data);
76439 /*
76440 * Some architectures need to do book-keeping after
76441 * a ptrace attach.
76442 */
76443- if (!ret)
76444+ if (!ret) {
76445 arch_ptrace_attach(child);
76446+ gr_audit_ptrace(child);
76447+ }
76448 goto out_put_task_struct;
76449 }
76450
76451diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
76452index e7dce58..ad0d7b7 100644
76453--- a/kernel/rcutiny.c
76454+++ b/kernel/rcutiny.c
76455@@ -46,7 +46,7 @@
76456 struct rcu_ctrlblk;
76457 static void invoke_rcu_callbacks(void);
76458 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
76459-static void rcu_process_callbacks(struct softirq_action *unused);
76460+static void rcu_process_callbacks(void);
76461 static void __call_rcu(struct rcu_head *head,
76462 void (*func)(struct rcu_head *rcu),
76463 struct rcu_ctrlblk *rcp);
76464@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
76465 rcu_is_callbacks_kthread()));
76466 }
76467
76468-static void rcu_process_callbacks(struct softirq_action *unused)
76469+static void rcu_process_callbacks(void)
76470 {
76471 __rcu_process_callbacks(&rcu_sched_ctrlblk);
76472 __rcu_process_callbacks(&rcu_bh_ctrlblk);
76473diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
76474index f85016a..91cb03b 100644
76475--- a/kernel/rcutiny_plugin.h
76476+++ b/kernel/rcutiny_plugin.h
76477@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
76478 have_rcu_kthread_work = morework;
76479 local_irq_restore(flags);
76480 if (work)
76481- rcu_process_callbacks(NULL);
76482+ rcu_process_callbacks();
76483 schedule_timeout_interruptible(1); /* Leave CPU for others. */
76484 }
76485
76486diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
76487index 31dea01..ad91ffb 100644
76488--- a/kernel/rcutorture.c
76489+++ b/kernel/rcutorture.c
76490@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
76491 { 0 };
76492 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
76493 { 0 };
76494-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76495-static atomic_t n_rcu_torture_alloc;
76496-static atomic_t n_rcu_torture_alloc_fail;
76497-static atomic_t n_rcu_torture_free;
76498-static atomic_t n_rcu_torture_mberror;
76499-static atomic_t n_rcu_torture_error;
76500+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76501+static atomic_unchecked_t n_rcu_torture_alloc;
76502+static atomic_unchecked_t n_rcu_torture_alloc_fail;
76503+static atomic_unchecked_t n_rcu_torture_free;
76504+static atomic_unchecked_t n_rcu_torture_mberror;
76505+static atomic_unchecked_t n_rcu_torture_error;
76506 static long n_rcu_torture_barrier_error;
76507 static long n_rcu_torture_boost_ktrerror;
76508 static long n_rcu_torture_boost_rterror;
76509@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
76510
76511 spin_lock_bh(&rcu_torture_lock);
76512 if (list_empty(&rcu_torture_freelist)) {
76513- atomic_inc(&n_rcu_torture_alloc_fail);
76514+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
76515 spin_unlock_bh(&rcu_torture_lock);
76516 return NULL;
76517 }
76518- atomic_inc(&n_rcu_torture_alloc);
76519+ atomic_inc_unchecked(&n_rcu_torture_alloc);
76520 p = rcu_torture_freelist.next;
76521 list_del_init(p);
76522 spin_unlock_bh(&rcu_torture_lock);
76523@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
76524 static void
76525 rcu_torture_free(struct rcu_torture *p)
76526 {
76527- atomic_inc(&n_rcu_torture_free);
76528+ atomic_inc_unchecked(&n_rcu_torture_free);
76529 spin_lock_bh(&rcu_torture_lock);
76530 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
76531 spin_unlock_bh(&rcu_torture_lock);
76532@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
76533 i = rp->rtort_pipe_count;
76534 if (i > RCU_TORTURE_PIPE_LEN)
76535 i = RCU_TORTURE_PIPE_LEN;
76536- atomic_inc(&rcu_torture_wcount[i]);
76537+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76538 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76539 rp->rtort_mbtest = 0;
76540 rcu_torture_free(rp);
76541@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
76542 i = rp->rtort_pipe_count;
76543 if (i > RCU_TORTURE_PIPE_LEN)
76544 i = RCU_TORTURE_PIPE_LEN;
76545- atomic_inc(&rcu_torture_wcount[i]);
76546+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76547 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76548 rp->rtort_mbtest = 0;
76549 list_del(&rp->rtort_free);
76550@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
76551 i = old_rp->rtort_pipe_count;
76552 if (i > RCU_TORTURE_PIPE_LEN)
76553 i = RCU_TORTURE_PIPE_LEN;
76554- atomic_inc(&rcu_torture_wcount[i]);
76555+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76556 old_rp->rtort_pipe_count++;
76557 cur_ops->deferred_free(old_rp);
76558 }
76559@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
76560 }
76561 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76562 if (p->rtort_mbtest == 0)
76563- atomic_inc(&n_rcu_torture_mberror);
76564+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76565 spin_lock(&rand_lock);
76566 cur_ops->read_delay(&rand);
76567 n_rcu_torture_timers++;
76568@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
76569 }
76570 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76571 if (p->rtort_mbtest == 0)
76572- atomic_inc(&n_rcu_torture_mberror);
76573+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76574 cur_ops->read_delay(&rand);
76575 preempt_disable();
76576 pipe_count = p->rtort_pipe_count;
76577@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
76578 rcu_torture_current,
76579 rcu_torture_current_version,
76580 list_empty(&rcu_torture_freelist),
76581- atomic_read(&n_rcu_torture_alloc),
76582- atomic_read(&n_rcu_torture_alloc_fail),
76583- atomic_read(&n_rcu_torture_free));
76584+ atomic_read_unchecked(&n_rcu_torture_alloc),
76585+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
76586+ atomic_read_unchecked(&n_rcu_torture_free));
76587 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
76588- atomic_read(&n_rcu_torture_mberror),
76589+ atomic_read_unchecked(&n_rcu_torture_mberror),
76590 n_rcu_torture_boost_ktrerror,
76591 n_rcu_torture_boost_rterror);
76592 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
76593@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
76594 n_barrier_attempts,
76595 n_rcu_torture_barrier_error);
76596 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
76597- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
76598+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
76599 n_rcu_torture_barrier_error != 0 ||
76600 n_rcu_torture_boost_ktrerror != 0 ||
76601 n_rcu_torture_boost_rterror != 0 ||
76602 n_rcu_torture_boost_failure != 0 ||
76603 i > 1) {
76604 cnt += sprintf(&page[cnt], "!!! ");
76605- atomic_inc(&n_rcu_torture_error);
76606+ atomic_inc_unchecked(&n_rcu_torture_error);
76607 WARN_ON_ONCE(1);
76608 }
76609 cnt += sprintf(&page[cnt], "Reader Pipe: ");
76610@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
76611 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
76612 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76613 cnt += sprintf(&page[cnt], " %d",
76614- atomic_read(&rcu_torture_wcount[i]));
76615+ atomic_read_unchecked(&rcu_torture_wcount[i]));
76616 }
76617 cnt += sprintf(&page[cnt], "\n");
76618 if (cur_ops->stats)
76619@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
76620
76621 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
76622
76623- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76624+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76625 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
76626 else if (n_online_successes != n_online_attempts ||
76627 n_offline_successes != n_offline_attempts)
76628@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
76629
76630 rcu_torture_current = NULL;
76631 rcu_torture_current_version = 0;
76632- atomic_set(&n_rcu_torture_alloc, 0);
76633- atomic_set(&n_rcu_torture_alloc_fail, 0);
76634- atomic_set(&n_rcu_torture_free, 0);
76635- atomic_set(&n_rcu_torture_mberror, 0);
76636- atomic_set(&n_rcu_torture_error, 0);
76637+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
76638+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
76639+ atomic_set_unchecked(&n_rcu_torture_free, 0);
76640+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
76641+ atomic_set_unchecked(&n_rcu_torture_error, 0);
76642 n_rcu_torture_barrier_error = 0;
76643 n_rcu_torture_boost_ktrerror = 0;
76644 n_rcu_torture_boost_rterror = 0;
76645 n_rcu_torture_boost_failure = 0;
76646 n_rcu_torture_boosts = 0;
76647 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
76648- atomic_set(&rcu_torture_wcount[i], 0);
76649+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
76650 for_each_possible_cpu(cpu) {
76651 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76652 per_cpu(rcu_torture_count, cpu)[i] = 0;
76653diff --git a/kernel/rcutree.c b/kernel/rcutree.c
76654index e441b77..dd54f17 100644
76655--- a/kernel/rcutree.c
76656+++ b/kernel/rcutree.c
76657@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
76658 rcu_prepare_for_idle(smp_processor_id());
76659 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76660 smp_mb__before_atomic_inc(); /* See above. */
76661- atomic_inc(&rdtp->dynticks);
76662+ atomic_inc_unchecked(&rdtp->dynticks);
76663 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
76664- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76665+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76666
76667 /*
76668 * It is illegal to enter an extended quiescent state while
76669@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
76670 int user)
76671 {
76672 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
76673- atomic_inc(&rdtp->dynticks);
76674+ atomic_inc_unchecked(&rdtp->dynticks);
76675 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76676 smp_mb__after_atomic_inc(); /* See above. */
76677- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76678+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76679 rcu_cleanup_after_idle(smp_processor_id());
76680 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
76681 if (!user && !is_idle_task(current)) {
76682@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
76683 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
76684
76685 if (rdtp->dynticks_nmi_nesting == 0 &&
76686- (atomic_read(&rdtp->dynticks) & 0x1))
76687+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
76688 return;
76689 rdtp->dynticks_nmi_nesting++;
76690 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
76691- atomic_inc(&rdtp->dynticks);
76692+ atomic_inc_unchecked(&rdtp->dynticks);
76693 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76694 smp_mb__after_atomic_inc(); /* See above. */
76695- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76696+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76697 }
76698
76699 /**
76700@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
76701 return;
76702 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76703 smp_mb__before_atomic_inc(); /* See above. */
76704- atomic_inc(&rdtp->dynticks);
76705+ atomic_inc_unchecked(&rdtp->dynticks);
76706 smp_mb__after_atomic_inc(); /* Force delay to next write. */
76707- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76708+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76709 }
76710
76711 /**
76712@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
76713 int ret;
76714
76715 preempt_disable();
76716- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76717+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76718 preempt_enable();
76719 return ret;
76720 }
76721@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
76722 */
76723 static int dyntick_save_progress_counter(struct rcu_data *rdp)
76724 {
76725- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
76726+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76727 return (rdp->dynticks_snap & 0x1) == 0;
76728 }
76729
76730@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
76731 unsigned int curr;
76732 unsigned int snap;
76733
76734- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
76735+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76736 snap = (unsigned int)rdp->dynticks_snap;
76737
76738 /*
76739@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
76740 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
76741 */
76742 if (till_stall_check < 3) {
76743- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
76744+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
76745 till_stall_check = 3;
76746 } else if (till_stall_check > 300) {
76747- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
76748+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
76749 till_stall_check = 300;
76750 }
76751 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
76752@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
76753 rsp->qlen += rdp->qlen;
76754 rdp->n_cbs_orphaned += rdp->qlen;
76755 rdp->qlen_lazy = 0;
76756- ACCESS_ONCE(rdp->qlen) = 0;
76757+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76758 }
76759
76760 /*
76761@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
76762 }
76763 smp_mb(); /* List handling before counting for rcu_barrier(). */
76764 rdp->qlen_lazy -= count_lazy;
76765- ACCESS_ONCE(rdp->qlen) -= count;
76766+ ACCESS_ONCE_RW(rdp->qlen) -= count;
76767 rdp->n_cbs_invoked += count;
76768
76769 /* Reinstate batch limit if we have worked down the excess. */
76770@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76771 /*
76772 * Do RCU core processing for the current CPU.
76773 */
76774-static void rcu_process_callbacks(struct softirq_action *unused)
76775+static void rcu_process_callbacks(void)
76776 {
76777 struct rcu_state *rsp;
76778
76779@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76780 local_irq_restore(flags);
76781 return;
76782 }
76783- ACCESS_ONCE(rdp->qlen)++;
76784+ ACCESS_ONCE_RW(rdp->qlen)++;
76785 if (lazy)
76786 rdp->qlen_lazy++;
76787 else
76788@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76789 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76790 * course be required on a 64-bit system.
76791 */
76792- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76793+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76794 (ulong)atomic_long_read(&rsp->expedited_done) +
76795 ULONG_MAX / 8)) {
76796 synchronize_sched();
76797- atomic_long_inc(&rsp->expedited_wrap);
76798+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
76799 return;
76800 }
76801
76802@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76803 * Take a ticket. Note that atomic_inc_return() implies a
76804 * full memory barrier.
76805 */
76806- snap = atomic_long_inc_return(&rsp->expedited_start);
76807+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76808 firstsnap = snap;
76809 get_online_cpus();
76810 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
76811@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
76812 synchronize_sched_expedited_cpu_stop,
76813 NULL) == -EAGAIN) {
76814 put_online_cpus();
76815- atomic_long_inc(&rsp->expedited_tryfail);
76816+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
76817
76818 /* Check to see if someone else did our work for us. */
76819 s = atomic_long_read(&rsp->expedited_done);
76820 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76821 /* ensure test happens before caller kfree */
76822 smp_mb__before_atomic_inc(); /* ^^^ */
76823- atomic_long_inc(&rsp->expedited_workdone1);
76824+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
76825 return;
76826 }
76827
76828@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
76829 udelay(trycount * num_online_cpus());
76830 } else {
76831 wait_rcu_gp(call_rcu_sched);
76832- atomic_long_inc(&rsp->expedited_normal);
76833+ atomic_long_inc_unchecked(&rsp->expedited_normal);
76834 return;
76835 }
76836
76837@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
76838 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76839 /* ensure test happens before caller kfree */
76840 smp_mb__before_atomic_inc(); /* ^^^ */
76841- atomic_long_inc(&rsp->expedited_workdone2);
76842+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
76843 return;
76844 }
76845
76846@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
76847 * period works for us.
76848 */
76849 get_online_cpus();
76850- snap = atomic_long_read(&rsp->expedited_start);
76851+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
76852 smp_mb(); /* ensure read is before try_stop_cpus(). */
76853 }
76854- atomic_long_inc(&rsp->expedited_stoppedcpus);
76855+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
76856
76857 /*
76858 * Everyone up to our most recent fetch is covered by our grace
76859@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
76860 * than we did already did their update.
76861 */
76862 do {
76863- atomic_long_inc(&rsp->expedited_done_tries);
76864+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
76865 s = atomic_long_read(&rsp->expedited_done);
76866 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
76867 /* ensure test happens before caller kfree */
76868 smp_mb__before_atomic_inc(); /* ^^^ */
76869- atomic_long_inc(&rsp->expedited_done_lost);
76870+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
76871 break;
76872 }
76873 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76874- atomic_long_inc(&rsp->expedited_done_exit);
76875+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76876
76877 put_online_cpus();
76878 }
76879@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76880 * ACCESS_ONCE() to prevent the compiler from speculating
76881 * the increment to precede the early-exit check.
76882 */
76883- ACCESS_ONCE(rsp->n_barrier_done)++;
76884+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76885 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76886 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76887 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76888@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76889
76890 /* Increment ->n_barrier_done to prevent duplicate work. */
76891 smp_mb(); /* Keep increment after above mechanism. */
76892- ACCESS_ONCE(rsp->n_barrier_done)++;
76893+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76894 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76895 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76896 smp_mb(); /* Keep increment before caller's subsequent code. */
76897@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76898 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76899 init_callback_list(rdp);
76900 rdp->qlen_lazy = 0;
76901- ACCESS_ONCE(rdp->qlen) = 0;
76902+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76903 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76904 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76905- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76906+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76907 #ifdef CONFIG_RCU_USER_QS
76908 WARN_ON_ONCE(rdp->dynticks->in_user);
76909 #endif
76910@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76911 rdp->blimit = blimit;
76912 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76913 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76914- atomic_set(&rdp->dynticks->dynticks,
76915- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76916+ atomic_set_unchecked(&rdp->dynticks->dynticks,
76917+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76918 rcu_prepare_for_idle_init(cpu);
76919 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76920
76921diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76922index 4b69291..704c92e 100644
76923--- a/kernel/rcutree.h
76924+++ b/kernel/rcutree.h
76925@@ -86,7 +86,7 @@ struct rcu_dynticks {
76926 long long dynticks_nesting; /* Track irq/process nesting level. */
76927 /* Process level is worth LLONG_MAX/2. */
76928 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76929- atomic_t dynticks; /* Even value for idle, else odd. */
76930+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76931 #ifdef CONFIG_RCU_FAST_NO_HZ
76932 int dyntick_drain; /* Prepare-for-idle state variable. */
76933 unsigned long dyntick_holdoff;
76934@@ -423,17 +423,17 @@ struct rcu_state {
76935 /* _rcu_barrier(). */
76936 /* End of fields guarded by barrier_mutex. */
76937
76938- atomic_long_t expedited_start; /* Starting ticket. */
76939- atomic_long_t expedited_done; /* Done ticket. */
76940- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76941- atomic_long_t expedited_tryfail; /* # acquisition failures. */
76942- atomic_long_t expedited_workdone1; /* # done by others #1. */
76943- atomic_long_t expedited_workdone2; /* # done by others #2. */
76944- atomic_long_t expedited_normal; /* # fallbacks to normal. */
76945- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76946- atomic_long_t expedited_done_tries; /* # tries to update _done. */
76947- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76948- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76949+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76950+ atomic_long_t expedited_done; /* Done ticket. */
76951+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76952+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76953+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76954+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76955+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76956+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76957+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76958+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76959+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76960
76961 unsigned long jiffies_force_qs; /* Time at which to invoke */
76962 /* force_quiescent_state(). */
76963diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
76964index c1cc7e1..f62e436 100644
76965--- a/kernel/rcutree_plugin.h
76966+++ b/kernel/rcutree_plugin.h
76967@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
76968
76969 /* Clean up and exit. */
76970 smp_mb(); /* ensure expedited GP seen before counter increment. */
76971- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
76972+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
76973 unlock_mb_ret:
76974 mutex_unlock(&sync_rcu_preempt_exp_mutex);
76975 mb_ret:
76976@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
76977 free_cpumask_var(cm);
76978 }
76979
76980-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
76981+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
76982 .store = &rcu_cpu_kthread_task,
76983 .thread_should_run = rcu_cpu_kthread_should_run,
76984 .thread_fn = rcu_cpu_kthread,
76985@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
76986 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
76987 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
76988 cpu, ticks_value, ticks_title,
76989- atomic_read(&rdtp->dynticks) & 0xfff,
76990+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
76991 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
76992 fast_no_hz);
76993 }
76994@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
76995
76996 /* Enqueue the callback on the nocb list and update counts. */
76997 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
76998- ACCESS_ONCE(*old_rhpp) = rhp;
76999+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
77000 atomic_long_add(rhcount, &rdp->nocb_q_count);
77001 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
77002
77003@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
77004 * Extract queued callbacks, update counts, and wait
77005 * for a grace period to elapse.
77006 */
77007- ACCESS_ONCE(rdp->nocb_head) = NULL;
77008+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
77009 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
77010 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
77011 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
77012- ACCESS_ONCE(rdp->nocb_p_count) += c;
77013- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
77014+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
77015+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
77016 wait_rcu_gp(rdp->rsp->call_remote);
77017
77018 /* Each pass through the following loop invokes a callback. */
77019@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
77020 list = next;
77021 }
77022 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
77023- ACCESS_ONCE(rdp->nocb_p_count) -= c;
77024- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
77025+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
77026+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
77027 rdp->n_nocbs_invoked += c;
77028 }
77029 return 0;
77030@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
77031 rdp = per_cpu_ptr(rsp->rda, cpu);
77032 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
77033 BUG_ON(IS_ERR(t));
77034- ACCESS_ONCE(rdp->nocb_kthread) = t;
77035+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
77036 }
77037 }
77038
77039diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
77040index 0d095dc..1985b19 100644
77041--- a/kernel/rcutree_trace.c
77042+++ b/kernel/rcutree_trace.c
77043@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
77044 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
77045 rdp->passed_quiesce, rdp->qs_pending);
77046 seq_printf(m, " dt=%d/%llx/%d df=%lu",
77047- atomic_read(&rdp->dynticks->dynticks),
77048+ atomic_read_unchecked(&rdp->dynticks->dynticks),
77049 rdp->dynticks->dynticks_nesting,
77050 rdp->dynticks->dynticks_nmi_nesting,
77051 rdp->dynticks_fqs);
77052@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
77053 struct rcu_state *rsp = (struct rcu_state *)m->private;
77054
77055 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",
77056- atomic_long_read(&rsp->expedited_start),
77057+ atomic_long_read_unchecked(&rsp->expedited_start),
77058 atomic_long_read(&rsp->expedited_done),
77059- atomic_long_read(&rsp->expedited_wrap),
77060- atomic_long_read(&rsp->expedited_tryfail),
77061- atomic_long_read(&rsp->expedited_workdone1),
77062- atomic_long_read(&rsp->expedited_workdone2),
77063- atomic_long_read(&rsp->expedited_normal),
77064- atomic_long_read(&rsp->expedited_stoppedcpus),
77065- atomic_long_read(&rsp->expedited_done_tries),
77066- atomic_long_read(&rsp->expedited_done_lost),
77067- atomic_long_read(&rsp->expedited_done_exit));
77068+ atomic_long_read_unchecked(&rsp->expedited_wrap),
77069+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
77070+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
77071+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
77072+ atomic_long_read_unchecked(&rsp->expedited_normal),
77073+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
77074+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
77075+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
77076+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
77077 return 0;
77078 }
77079
77080diff --git a/kernel/resource.c b/kernel/resource.c
77081index 73f35d4..4684fc4 100644
77082--- a/kernel/resource.c
77083+++ b/kernel/resource.c
77084@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
77085
77086 static int __init ioresources_init(void)
77087 {
77088+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77089+#ifdef CONFIG_GRKERNSEC_PROC_USER
77090+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
77091+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
77092+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77093+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
77094+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
77095+#endif
77096+#else
77097 proc_create("ioports", 0, NULL, &proc_ioports_operations);
77098 proc_create("iomem", 0, NULL, &proc_iomem_operations);
77099+#endif
77100 return 0;
77101 }
77102 __initcall(ioresources_init);
77103diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
77104index 98ec494..4241d6d 100644
77105--- a/kernel/rtmutex-tester.c
77106+++ b/kernel/rtmutex-tester.c
77107@@ -20,7 +20,7 @@
77108 #define MAX_RT_TEST_MUTEXES 8
77109
77110 static spinlock_t rttest_lock;
77111-static atomic_t rttest_event;
77112+static atomic_unchecked_t rttest_event;
77113
77114 struct test_thread_data {
77115 int opcode;
77116@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77117
77118 case RTTEST_LOCKCONT:
77119 td->mutexes[td->opdata] = 1;
77120- td->event = atomic_add_return(1, &rttest_event);
77121+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77122 return 0;
77123
77124 case RTTEST_RESET:
77125@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77126 return 0;
77127
77128 case RTTEST_RESETEVENT:
77129- atomic_set(&rttest_event, 0);
77130+ atomic_set_unchecked(&rttest_event, 0);
77131 return 0;
77132
77133 default:
77134@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77135 return ret;
77136
77137 td->mutexes[id] = 1;
77138- td->event = atomic_add_return(1, &rttest_event);
77139+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77140 rt_mutex_lock(&mutexes[id]);
77141- td->event = atomic_add_return(1, &rttest_event);
77142+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77143 td->mutexes[id] = 4;
77144 return 0;
77145
77146@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77147 return ret;
77148
77149 td->mutexes[id] = 1;
77150- td->event = atomic_add_return(1, &rttest_event);
77151+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77152 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
77153- td->event = atomic_add_return(1, &rttest_event);
77154+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77155 td->mutexes[id] = ret ? 0 : 4;
77156 return ret ? -EINTR : 0;
77157
77158@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77159 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
77160 return ret;
77161
77162- td->event = atomic_add_return(1, &rttest_event);
77163+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77164 rt_mutex_unlock(&mutexes[id]);
77165- td->event = atomic_add_return(1, &rttest_event);
77166+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77167 td->mutexes[id] = 0;
77168 return 0;
77169
77170@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77171 break;
77172
77173 td->mutexes[dat] = 2;
77174- td->event = atomic_add_return(1, &rttest_event);
77175+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77176 break;
77177
77178 default:
77179@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77180 return;
77181
77182 td->mutexes[dat] = 3;
77183- td->event = atomic_add_return(1, &rttest_event);
77184+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77185 break;
77186
77187 case RTTEST_LOCKNOWAIT:
77188@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77189 return;
77190
77191 td->mutexes[dat] = 1;
77192- td->event = atomic_add_return(1, &rttest_event);
77193+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77194 return;
77195
77196 default:
77197diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
77198index 0984a21..939f183 100644
77199--- a/kernel/sched/auto_group.c
77200+++ b/kernel/sched/auto_group.c
77201@@ -11,7 +11,7 @@
77202
77203 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
77204 static struct autogroup autogroup_default;
77205-static atomic_t autogroup_seq_nr;
77206+static atomic_unchecked_t autogroup_seq_nr;
77207
77208 void __init autogroup_init(struct task_struct *init_task)
77209 {
77210@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
77211
77212 kref_init(&ag->kref);
77213 init_rwsem(&ag->lock);
77214- ag->id = atomic_inc_return(&autogroup_seq_nr);
77215+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
77216 ag->tg = tg;
77217 #ifdef CONFIG_RT_GROUP_SCHED
77218 /*
77219diff --git a/kernel/sched/core.c b/kernel/sched/core.c
77220index 26058d0..e315889 100644
77221--- a/kernel/sched/core.c
77222+++ b/kernel/sched/core.c
77223@@ -3367,7 +3367,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
77224 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77225 * positive (at least 1, or number of jiffies left till timeout) if completed.
77226 */
77227-long __sched
77228+long __sched __intentional_overflow(-1)
77229 wait_for_completion_interruptible_timeout(struct completion *x,
77230 unsigned long timeout)
77231 {
77232@@ -3384,7 +3384,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
77233 *
77234 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
77235 */
77236-int __sched wait_for_completion_killable(struct completion *x)
77237+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
77238 {
77239 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
77240 if (t == -ERESTARTSYS)
77241@@ -3405,7 +3405,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
77242 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77243 * positive (at least 1, or number of jiffies left till timeout) if completed.
77244 */
77245-long __sched
77246+long __sched __intentional_overflow(-1)
77247 wait_for_completion_killable_timeout(struct completion *x,
77248 unsigned long timeout)
77249 {
77250@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
77251 /* convert nice value [19,-20] to rlimit style value [1,40] */
77252 int nice_rlim = 20 - nice;
77253
77254+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
77255+
77256 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
77257 capable(CAP_SYS_NICE));
77258 }
77259@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
77260 if (nice > 19)
77261 nice = 19;
77262
77263- if (increment < 0 && !can_nice(current, nice))
77264+ if (increment < 0 && (!can_nice(current, nice) ||
77265+ gr_handle_chroot_nice()))
77266 return -EPERM;
77267
77268 retval = security_task_setnice(current, nice);
77269@@ -3818,6 +3821,7 @@ recheck:
77270 unsigned long rlim_rtprio =
77271 task_rlimit(p, RLIMIT_RTPRIO);
77272
77273+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
77274 /* can't set/change the rt policy */
77275 if (policy != p->policy && !rlim_rtprio)
77276 return -EPERM;
77277@@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
77278
77279 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
77280
77281-static struct ctl_table sd_ctl_dir[] = {
77282+static ctl_table_no_const sd_ctl_dir[] __read_only = {
77283 {
77284 .procname = "sched_domain",
77285 .mode = 0555,
77286@@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
77287 {}
77288 };
77289
77290-static struct ctl_table *sd_alloc_ctl_entry(int n)
77291+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
77292 {
77293- struct ctl_table *entry =
77294+ ctl_table_no_const *entry =
77295 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
77296
77297 return entry;
77298 }
77299
77300-static void sd_free_ctl_entry(struct ctl_table **tablep)
77301+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
77302 {
77303- struct ctl_table *entry;
77304+ ctl_table_no_const *entry;
77305
77306 /*
77307 * In the intermediate directories, both the child directory and
77308@@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
77309 * will always be set. In the lowest directory the names are
77310 * static strings and all have proc handlers.
77311 */
77312- for (entry = *tablep; entry->mode; entry++) {
77313- if (entry->child)
77314- sd_free_ctl_entry(&entry->child);
77315+ for (entry = tablep; entry->mode; entry++) {
77316+ if (entry->child) {
77317+ sd_free_ctl_entry(entry->child);
77318+ pax_open_kernel();
77319+ entry->child = NULL;
77320+ pax_close_kernel();
77321+ }
77322 if (entry->proc_handler == NULL)
77323 kfree(entry->procname);
77324 }
77325
77326- kfree(*tablep);
77327- *tablep = NULL;
77328+ kfree(tablep);
77329 }
77330
77331 static int min_load_idx = 0;
77332 static int max_load_idx = CPU_LOAD_IDX_MAX;
77333
77334 static void
77335-set_table_entry(struct ctl_table *entry,
77336+set_table_entry(ctl_table_no_const *entry,
77337 const char *procname, void *data, int maxlen,
77338 umode_t mode, proc_handler *proc_handler,
77339 bool load_idx)
77340@@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
77341 static struct ctl_table *
77342 sd_alloc_ctl_domain_table(struct sched_domain *sd)
77343 {
77344- struct ctl_table *table = sd_alloc_ctl_entry(13);
77345+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
77346
77347 if (table == NULL)
77348 return NULL;
77349@@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
77350 return table;
77351 }
77352
77353-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
77354+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
77355 {
77356- struct ctl_table *entry, *table;
77357+ ctl_table_no_const *entry, *table;
77358 struct sched_domain *sd;
77359 int domain_num = 0, i;
77360 char buf[32];
77361@@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
77362 static void register_sched_domain_sysctl(void)
77363 {
77364 int i, cpu_num = num_possible_cpus();
77365- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
77366+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
77367 char buf[32];
77368
77369 WARN_ON(sd_ctl_dir[0].child);
77370+ pax_open_kernel();
77371 sd_ctl_dir[0].child = entry;
77372+ pax_close_kernel();
77373
77374 if (entry == NULL)
77375 return;
77376@@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
77377 if (sd_sysctl_header)
77378 unregister_sysctl_table(sd_sysctl_header);
77379 sd_sysctl_header = NULL;
77380- if (sd_ctl_dir[0].child)
77381- sd_free_ctl_entry(&sd_ctl_dir[0].child);
77382+ if (sd_ctl_dir[0].child) {
77383+ sd_free_ctl_entry(sd_ctl_dir[0].child);
77384+ pax_open_kernel();
77385+ sd_ctl_dir[0].child = NULL;
77386+ pax_close_kernel();
77387+ }
77388 }
77389 #else
77390 static void register_sched_domain_sysctl(void)
77391@@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
77392 * happens before everything else. This has to be lower priority than
77393 * the notifier in the perf_event subsystem, though.
77394 */
77395-static struct notifier_block __cpuinitdata migration_notifier = {
77396+static struct notifier_block migration_notifier = {
77397 .notifier_call = migration_call,
77398 .priority = CPU_PRI_MIGRATION,
77399 };
77400diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
77401index 81fa536..6ccf96a 100644
77402--- a/kernel/sched/fair.c
77403+++ b/kernel/sched/fair.c
77404@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
77405
77406 static void reset_ptenuma_scan(struct task_struct *p)
77407 {
77408- ACCESS_ONCE(p->mm->numa_scan_seq)++;
77409+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
77410 p->mm->numa_scan_offset = 0;
77411 }
77412
77413@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
77414 */
77415 static int select_idle_sibling(struct task_struct *p, int target)
77416 {
77417- int cpu = smp_processor_id();
77418- int prev_cpu = task_cpu(p);
77419 struct sched_domain *sd;
77420 struct sched_group *sg;
77421- int i;
77422+ int i = task_cpu(p);
77423
77424- /*
77425- * If the task is going to be woken-up on this cpu and if it is
77426- * already idle, then it is the right target.
77427- */
77428- if (target == cpu && idle_cpu(cpu))
77429- return cpu;
77430+ if (idle_cpu(target))
77431+ return target;
77432
77433 /*
77434- * If the task is going to be woken-up on the cpu where it previously
77435- * ran and if it is currently idle, then it the right target.
77436+ * If the prevous cpu is cache affine and idle, don't be stupid.
77437 */
77438- if (target == prev_cpu && idle_cpu(prev_cpu))
77439- return prev_cpu;
77440+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
77441+ return i;
77442
77443 /*
77444 * Otherwise, iterate the domains and find an elegible idle cpu.
77445@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
77446 goto next;
77447
77448 for_each_cpu(i, sched_group_cpus(sg)) {
77449- if (!idle_cpu(i))
77450+ if (i == target || !idle_cpu(i))
77451 goto next;
77452 }
77453
77454@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
77455 * run_rebalance_domains is triggered when needed from the scheduler tick.
77456 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
77457 */
77458-static void run_rebalance_domains(struct softirq_action *h)
77459+static void run_rebalance_domains(void)
77460 {
77461 int this_cpu = smp_processor_id();
77462 struct rq *this_rq = cpu_rq(this_cpu);
77463diff --git a/kernel/signal.c b/kernel/signal.c
77464index 7591ccc..8988390 100644
77465--- a/kernel/signal.c
77466+++ b/kernel/signal.c
77467@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
77468
77469 int print_fatal_signals __read_mostly;
77470
77471-static void __user *sig_handler(struct task_struct *t, int sig)
77472+static __sighandler_t sig_handler(struct task_struct *t, int sig)
77473 {
77474 return t->sighand->action[sig - 1].sa.sa_handler;
77475 }
77476
77477-static int sig_handler_ignored(void __user *handler, int sig)
77478+static int sig_handler_ignored(__sighandler_t handler, int sig)
77479 {
77480 /* Is it explicitly or implicitly ignored? */
77481 return handler == SIG_IGN ||
77482@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
77483
77484 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
77485 {
77486- void __user *handler;
77487+ __sighandler_t handler;
77488
77489 handler = sig_handler(t, sig);
77490
77491@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
77492 atomic_inc(&user->sigpending);
77493 rcu_read_unlock();
77494
77495+ if (!override_rlimit)
77496+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
77497+
77498 if (override_rlimit ||
77499 atomic_read(&user->sigpending) <=
77500 task_rlimit(t, RLIMIT_SIGPENDING)) {
77501@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
77502
77503 int unhandled_signal(struct task_struct *tsk, int sig)
77504 {
77505- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
77506+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
77507 if (is_global_init(tsk))
77508 return 1;
77509 if (handler != SIG_IGN && handler != SIG_DFL)
77510@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
77511 }
77512 }
77513
77514+ /* allow glibc communication via tgkill to other threads in our
77515+ thread group */
77516+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
77517+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
77518+ && gr_handle_signal(t, sig))
77519+ return -EPERM;
77520+
77521 return security_task_kill(t, info, sig, 0);
77522 }
77523
77524@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77525 return send_signal(sig, info, p, 1);
77526 }
77527
77528-static int
77529+int
77530 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77531 {
77532 return send_signal(sig, info, t, 0);
77533@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77534 unsigned long int flags;
77535 int ret, blocked, ignored;
77536 struct k_sigaction *action;
77537+ int is_unhandled = 0;
77538
77539 spin_lock_irqsave(&t->sighand->siglock, flags);
77540 action = &t->sighand->action[sig-1];
77541@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77542 }
77543 if (action->sa.sa_handler == SIG_DFL)
77544 t->signal->flags &= ~SIGNAL_UNKILLABLE;
77545+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
77546+ is_unhandled = 1;
77547 ret = specific_send_sig_info(sig, info, t);
77548 spin_unlock_irqrestore(&t->sighand->siglock, flags);
77549
77550+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
77551+ normal operation */
77552+ if (is_unhandled) {
77553+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
77554+ gr_handle_crash(t, sig);
77555+ }
77556+
77557 return ret;
77558 }
77559
77560@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77561 ret = check_kill_permission(sig, info, p);
77562 rcu_read_unlock();
77563
77564- if (!ret && sig)
77565+ if (!ret && sig) {
77566 ret = do_send_sig_info(sig, info, p, true);
77567+ if (!ret)
77568+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
77569+ }
77570
77571 return ret;
77572 }
77573@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
77574 int error = -ESRCH;
77575
77576 rcu_read_lock();
77577- p = find_task_by_vpid(pid);
77578+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77579+ /* allow glibc communication via tgkill to other threads in our
77580+ thread group */
77581+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
77582+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
77583+ p = find_task_by_vpid_unrestricted(pid);
77584+ else
77585+#endif
77586+ p = find_task_by_vpid(pid);
77587 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
77588 error = check_kill_permission(sig, info, p);
77589 /*
77590@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
77591 }
77592 seg = get_fs();
77593 set_fs(KERNEL_DS);
77594- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
77595- (stack_t __force __user *) &uoss,
77596+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
77597+ (stack_t __force_user *) &uoss,
77598 compat_user_stack_pointer());
77599 set_fs(seg);
77600 if (ret >= 0 && uoss_ptr) {
77601diff --git a/kernel/smp.c b/kernel/smp.c
77602index 69f38bd..77bbf12 100644
77603--- a/kernel/smp.c
77604+++ b/kernel/smp.c
77605@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
77606 return NOTIFY_OK;
77607 }
77608
77609-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
77610+static struct notifier_block hotplug_cfd_notifier = {
77611 .notifier_call = hotplug_cfd,
77612 };
77613
77614diff --git a/kernel/smpboot.c b/kernel/smpboot.c
77615index d6c5fc0..530560c 100644
77616--- a/kernel/smpboot.c
77617+++ b/kernel/smpboot.c
77618@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
77619 }
77620 smpboot_unpark_thread(plug_thread, cpu);
77621 }
77622- list_add(&plug_thread->list, &hotplug_threads);
77623+ pax_list_add(&plug_thread->list, &hotplug_threads);
77624 out:
77625 mutex_unlock(&smpboot_threads_lock);
77626 return ret;
77627@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
77628 {
77629 get_online_cpus();
77630 mutex_lock(&smpboot_threads_lock);
77631- list_del(&plug_thread->list);
77632+ pax_list_del(&plug_thread->list);
77633 smpboot_destroy_threads(plug_thread);
77634 mutex_unlock(&smpboot_threads_lock);
77635 put_online_cpus();
77636diff --git a/kernel/softirq.c b/kernel/softirq.c
77637index ed567ba..e71dabf 100644
77638--- a/kernel/softirq.c
77639+++ b/kernel/softirq.c
77640@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
77641 EXPORT_SYMBOL(irq_stat);
77642 #endif
77643
77644-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
77645+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
77646
77647 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
77648
77649-char *softirq_to_name[NR_SOFTIRQS] = {
77650+const char * const softirq_to_name[NR_SOFTIRQS] = {
77651 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
77652 "TASKLET", "SCHED", "HRTIMER", "RCU"
77653 };
77654@@ -244,7 +244,7 @@ restart:
77655 kstat_incr_softirqs_this_cpu(vec_nr);
77656
77657 trace_softirq_entry(vec_nr);
77658- h->action(h);
77659+ h->action();
77660 trace_softirq_exit(vec_nr);
77661 if (unlikely(prev_count != preempt_count())) {
77662 printk(KERN_ERR "huh, entered softirq %u %s %p"
77663@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
77664 or_softirq_pending(1UL << nr);
77665 }
77666
77667-void open_softirq(int nr, void (*action)(struct softirq_action *))
77668+void __init open_softirq(int nr, void (*action)(void))
77669 {
77670 softirq_vec[nr].action = action;
77671 }
77672@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
77673
77674 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
77675
77676-static void tasklet_action(struct softirq_action *a)
77677+static void tasklet_action(void)
77678 {
77679 struct tasklet_struct *list;
77680
77681@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
77682 }
77683 }
77684
77685-static void tasklet_hi_action(struct softirq_action *a)
77686+static void tasklet_hi_action(void)
77687 {
77688 struct tasklet_struct *list;
77689
77690@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
77691 return NOTIFY_OK;
77692 }
77693
77694-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
77695+static struct notifier_block remote_softirq_cpu_notifier = {
77696 .notifier_call = remote_softirq_cpu_notify,
77697 };
77698
77699@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
77700 return NOTIFY_OK;
77701 }
77702
77703-static struct notifier_block __cpuinitdata cpu_nfb = {
77704+static struct notifier_block cpu_nfb = {
77705 .notifier_call = cpu_callback
77706 };
77707
77708-static struct smp_hotplug_thread softirq_threads = {
77709+static struct smp_hotplug_thread softirq_threads __read_only = {
77710 .store = &ksoftirqd,
77711 .thread_should_run = ksoftirqd_should_run,
77712 .thread_fn = run_ksoftirqd,
77713diff --git a/kernel/srcu.c b/kernel/srcu.c
77714index 2b85982..d52ab26 100644
77715--- a/kernel/srcu.c
77716+++ b/kernel/srcu.c
77717@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
77718 preempt_disable();
77719 idx = rcu_dereference_index_check(sp->completed,
77720 rcu_read_lock_sched_held()) & 0x1;
77721- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77722+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77723 smp_mb(); /* B */ /* Avoid leaking the critical section. */
77724- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77725+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77726 preempt_enable();
77727 return idx;
77728 }
77729@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
77730 {
77731 preempt_disable();
77732 smp_mb(); /* C */ /* Avoid leaking the critical section. */
77733- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77734+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77735 preempt_enable();
77736 }
77737 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
77738diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
77739index 2f194e9..2c05ea9 100644
77740--- a/kernel/stop_machine.c
77741+++ b/kernel/stop_machine.c
77742@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
77743 * cpu notifiers. It currently shares the same priority as sched
77744 * migration_notifier.
77745 */
77746-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
77747+static struct notifier_block cpu_stop_cpu_notifier = {
77748 .notifier_call = cpu_stop_cpu_callback,
77749 .priority = 10,
77750 };
77751diff --git a/kernel/sys.c b/kernel/sys.c
77752index 265b376..4e42ef5 100644
77753--- a/kernel/sys.c
77754+++ b/kernel/sys.c
77755@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
77756 error = -EACCES;
77757 goto out;
77758 }
77759+
77760+ if (gr_handle_chroot_setpriority(p, niceval)) {
77761+ error = -EACCES;
77762+ goto out;
77763+ }
77764+
77765 no_nice = security_task_setnice(p, niceval);
77766 if (no_nice) {
77767 error = no_nice;
77768@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
77769 goto error;
77770 }
77771
77772+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
77773+ goto error;
77774+
77775 if (rgid != (gid_t) -1 ||
77776 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
77777 new->sgid = new->egid;
77778@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
77779 old = current_cred();
77780
77781 retval = -EPERM;
77782+
77783+ if (gr_check_group_change(kgid, kgid, kgid))
77784+ goto error;
77785+
77786 if (nsown_capable(CAP_SETGID))
77787 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77788 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77789@@ -647,7 +660,7 @@ error:
77790 /*
77791 * change the user struct in a credentials set to match the new UID
77792 */
77793-static int set_user(struct cred *new)
77794+int set_user(struct cred *new)
77795 {
77796 struct user_struct *new_user;
77797
77798@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77799 goto error;
77800 }
77801
77802+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77803+ goto error;
77804+
77805 if (!uid_eq(new->uid, old->uid)) {
77806 retval = set_user(new);
77807 if (retval < 0)
77808@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77809 old = current_cred();
77810
77811 retval = -EPERM;
77812+
77813+ if (gr_check_crash_uid(kuid))
77814+ goto error;
77815+ if (gr_check_user_change(kuid, kuid, kuid))
77816+ goto error;
77817+
77818 if (nsown_capable(CAP_SETUID)) {
77819 new->suid = new->uid = kuid;
77820 if (!uid_eq(kuid, old->uid)) {
77821@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
77822 goto error;
77823 }
77824
77825+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
77826+ goto error;
77827+
77828 if (ruid != (uid_t) -1) {
77829 new->uid = kruid;
77830 if (!uid_eq(kruid, old->uid)) {
77831@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
77832 goto error;
77833 }
77834
77835+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
77836+ goto error;
77837+
77838 if (rgid != (gid_t) -1)
77839 new->gid = krgid;
77840 if (egid != (gid_t) -1)
77841@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77842 if (!uid_valid(kuid))
77843 return old_fsuid;
77844
77845+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
77846+ goto error;
77847+
77848 new = prepare_creds();
77849 if (!new)
77850 return old_fsuid;
77851@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77852 }
77853 }
77854
77855+error:
77856 abort_creds(new);
77857 return old_fsuid;
77858
77859@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
77860 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
77861 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
77862 nsown_capable(CAP_SETGID)) {
77863+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
77864+ goto error;
77865+
77866 if (!gid_eq(kgid, old->fsgid)) {
77867 new->fsgid = kgid;
77868 goto change_okay;
77869 }
77870 }
77871
77872+error:
77873 abort_creds(new);
77874 return old_fsgid;
77875
77876@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
77877 return -EFAULT;
77878
77879 down_read(&uts_sem);
77880- error = __copy_to_user(&name->sysname, &utsname()->sysname,
77881+ error = __copy_to_user(name->sysname, &utsname()->sysname,
77882 __OLD_UTS_LEN);
77883 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
77884- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
77885+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
77886 __OLD_UTS_LEN);
77887 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
77888- error |= __copy_to_user(&name->release, &utsname()->release,
77889+ error |= __copy_to_user(name->release, &utsname()->release,
77890 __OLD_UTS_LEN);
77891 error |= __put_user(0, name->release + __OLD_UTS_LEN);
77892- error |= __copy_to_user(&name->version, &utsname()->version,
77893+ error |= __copy_to_user(name->version, &utsname()->version,
77894 __OLD_UTS_LEN);
77895 error |= __put_user(0, name->version + __OLD_UTS_LEN);
77896- error |= __copy_to_user(&name->machine, &utsname()->machine,
77897+ error |= __copy_to_user(name->machine, &utsname()->machine,
77898 __OLD_UTS_LEN);
77899 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77900 up_read(&uts_sem);
77901@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77902 error = get_dumpable(me->mm);
77903 break;
77904 case PR_SET_DUMPABLE:
77905- if (arg2 < 0 || arg2 > 1) {
77906+ if (arg2 > 1) {
77907 error = -EINVAL;
77908 break;
77909 }
77910diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77911index c88878d..e4fa5d1 100644
77912--- a/kernel/sysctl.c
77913+++ b/kernel/sysctl.c
77914@@ -92,7 +92,6 @@
77915
77916
77917 #if defined(CONFIG_SYSCTL)
77918-
77919 /* External variables not in a header file. */
77920 extern int sysctl_overcommit_memory;
77921 extern int sysctl_overcommit_ratio;
77922@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77923 void __user *buffer, size_t *lenp, loff_t *ppos);
77924 #endif
77925
77926-#ifdef CONFIG_PRINTK
77927 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77928 void __user *buffer, size_t *lenp, loff_t *ppos);
77929-#endif
77930
77931 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77932 void __user *buffer, size_t *lenp, loff_t *ppos);
77933@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77934
77935 #endif
77936
77937+extern struct ctl_table grsecurity_table[];
77938+
77939 static struct ctl_table kern_table[];
77940 static struct ctl_table vm_table[];
77941 static struct ctl_table fs_table[];
77942@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77943 int sysctl_legacy_va_layout;
77944 #endif
77945
77946+#ifdef CONFIG_PAX_SOFTMODE
77947+static ctl_table pax_table[] = {
77948+ {
77949+ .procname = "softmode",
77950+ .data = &pax_softmode,
77951+ .maxlen = sizeof(unsigned int),
77952+ .mode = 0600,
77953+ .proc_handler = &proc_dointvec,
77954+ },
77955+
77956+ { }
77957+};
77958+#endif
77959+
77960 /* The default sysctl tables: */
77961
77962 static struct ctl_table sysctl_base_table[] = {
77963@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
77964 #endif
77965
77966 static struct ctl_table kern_table[] = {
77967+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
77968+ {
77969+ .procname = "grsecurity",
77970+ .mode = 0500,
77971+ .child = grsecurity_table,
77972+ },
77973+#endif
77974+
77975+#ifdef CONFIG_PAX_SOFTMODE
77976+ {
77977+ .procname = "pax",
77978+ .mode = 0500,
77979+ .child = pax_table,
77980+ },
77981+#endif
77982+
77983 {
77984 .procname = "sched_child_runs_first",
77985 .data = &sysctl_sched_child_runs_first,
77986@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
77987 .data = &modprobe_path,
77988 .maxlen = KMOD_PATH_LEN,
77989 .mode = 0644,
77990- .proc_handler = proc_dostring,
77991+ .proc_handler = proc_dostring_modpriv,
77992 },
77993 {
77994 .procname = "modules_disabled",
77995@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
77996 .extra1 = &zero,
77997 .extra2 = &one,
77998 },
77999+#endif
78000 {
78001 .procname = "kptr_restrict",
78002 .data = &kptr_restrict,
78003 .maxlen = sizeof(int),
78004 .mode = 0644,
78005 .proc_handler = proc_dointvec_minmax_sysadmin,
78006+#ifdef CONFIG_GRKERNSEC_HIDESYM
78007+ .extra1 = &two,
78008+#else
78009 .extra1 = &zero,
78010+#endif
78011 .extra2 = &two,
78012 },
78013-#endif
78014 {
78015 .procname = "ngroups_max",
78016 .data = &ngroups_max,
78017@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
78018 .proc_handler = proc_dointvec_minmax,
78019 .extra1 = &zero,
78020 },
78021+ {
78022+ .procname = "heap_stack_gap",
78023+ .data = &sysctl_heap_stack_gap,
78024+ .maxlen = sizeof(sysctl_heap_stack_gap),
78025+ .mode = 0644,
78026+ .proc_handler = proc_doulongvec_minmax,
78027+ },
78028 #else
78029 {
78030 .procname = "nr_trim_pages",
78031@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
78032 buffer, lenp, ppos);
78033 }
78034
78035+int proc_dostring_modpriv(struct ctl_table *table, int write,
78036+ void __user *buffer, size_t *lenp, loff_t *ppos)
78037+{
78038+ if (write && !capable(CAP_SYS_MODULE))
78039+ return -EPERM;
78040+
78041+ return _proc_do_string(table->data, table->maxlen, write,
78042+ buffer, lenp, ppos);
78043+}
78044+
78045 static size_t proc_skip_spaces(char **buf)
78046 {
78047 size_t ret;
78048@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
78049 len = strlen(tmp);
78050 if (len > *size)
78051 len = *size;
78052+ if (len > sizeof(tmp))
78053+ len = sizeof(tmp);
78054 if (copy_to_user(*buf, tmp, len))
78055 return -EFAULT;
78056 *size -= len;
78057@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
78058 static int proc_taint(struct ctl_table *table, int write,
78059 void __user *buffer, size_t *lenp, loff_t *ppos)
78060 {
78061- struct ctl_table t;
78062+ ctl_table_no_const t;
78063 unsigned long tmptaint = get_taint();
78064 int err;
78065
78066@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
78067 return err;
78068 }
78069
78070-#ifdef CONFIG_PRINTK
78071 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78072 void __user *buffer, size_t *lenp, loff_t *ppos)
78073 {
78074@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78075
78076 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
78077 }
78078-#endif
78079
78080 struct do_proc_dointvec_minmax_conv_param {
78081 int *min;
78082@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
78083 *i = val;
78084 } else {
78085 val = convdiv * (*i) / convmul;
78086- if (!first)
78087+ if (!first) {
78088 err = proc_put_char(&buffer, &left, '\t');
78089+ if (err)
78090+ break;
78091+ }
78092 err = proc_put_long(&buffer, &left, val, false);
78093 if (err)
78094 break;
78095@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
78096 return -ENOSYS;
78097 }
78098
78099+int proc_dostring_modpriv(struct ctl_table *table, int write,
78100+ void __user *buffer, size_t *lenp, loff_t *ppos)
78101+{
78102+ return -ENOSYS;
78103+}
78104+
78105 int proc_dointvec(struct ctl_table *table, int write,
78106 void __user *buffer, size_t *lenp, loff_t *ppos)
78107 {
78108@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
78109 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
78110 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
78111 EXPORT_SYMBOL(proc_dostring);
78112+EXPORT_SYMBOL(proc_dostring_modpriv);
78113 EXPORT_SYMBOL(proc_doulongvec_minmax);
78114 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
78115diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
78116index 0ddf3a0..a199f50 100644
78117--- a/kernel/sysctl_binary.c
78118+++ b/kernel/sysctl_binary.c
78119@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
78120 int i;
78121
78122 set_fs(KERNEL_DS);
78123- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78124+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78125 set_fs(old_fs);
78126 if (result < 0)
78127 goto out_kfree;
78128@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
78129 }
78130
78131 set_fs(KERNEL_DS);
78132- result = vfs_write(file, buffer, str - buffer, &pos);
78133+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78134 set_fs(old_fs);
78135 if (result < 0)
78136 goto out_kfree;
78137@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
78138 int i;
78139
78140 set_fs(KERNEL_DS);
78141- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78142+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78143 set_fs(old_fs);
78144 if (result < 0)
78145 goto out_kfree;
78146@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
78147 }
78148
78149 set_fs(KERNEL_DS);
78150- result = vfs_write(file, buffer, str - buffer, &pos);
78151+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78152 set_fs(old_fs);
78153 if (result < 0)
78154 goto out_kfree;
78155@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
78156 int i;
78157
78158 set_fs(KERNEL_DS);
78159- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78160+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78161 set_fs(old_fs);
78162 if (result < 0)
78163 goto out;
78164@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78165 __le16 dnaddr;
78166
78167 set_fs(KERNEL_DS);
78168- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78169+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78170 set_fs(old_fs);
78171 if (result < 0)
78172 goto out;
78173@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78174 le16_to_cpu(dnaddr) & 0x3ff);
78175
78176 set_fs(KERNEL_DS);
78177- result = vfs_write(file, buf, len, &pos);
78178+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
78179 set_fs(old_fs);
78180 if (result < 0)
78181 goto out;
78182diff --git a/kernel/taskstats.c b/kernel/taskstats.c
78183index 145bb4d..b2aa969 100644
78184--- a/kernel/taskstats.c
78185+++ b/kernel/taskstats.c
78186@@ -28,9 +28,12 @@
78187 #include <linux/fs.h>
78188 #include <linux/file.h>
78189 #include <linux/pid_namespace.h>
78190+#include <linux/grsecurity.h>
78191 #include <net/genetlink.h>
78192 #include <linux/atomic.h>
78193
78194+extern int gr_is_taskstats_denied(int pid);
78195+
78196 /*
78197 * Maximum length of a cpumask that can be specified in
78198 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
78199@@ -570,6 +573,9 @@ err:
78200
78201 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
78202 {
78203+ if (gr_is_taskstats_denied(current->pid))
78204+ return -EACCES;
78205+
78206 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
78207 return cmd_attr_register_cpumask(info);
78208 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
78209diff --git a/kernel/time.c b/kernel/time.c
78210index d226c6a..2f0d217 100644
78211--- a/kernel/time.c
78212+++ b/kernel/time.c
78213@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
78214 return error;
78215
78216 if (tz) {
78217+ /* we log in do_settimeofday called below, so don't log twice
78218+ */
78219+ if (!tv)
78220+ gr_log_timechange();
78221+
78222 sys_tz = *tz;
78223 update_vsyscall_tz();
78224 if (firsttime) {
78225@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
78226 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
78227 * value to a scaled second value.
78228 */
78229-unsigned long
78230+unsigned long __intentional_overflow(-1)
78231 timespec_to_jiffies(const struct timespec *value)
78232 {
78233 unsigned long sec = value->tv_sec;
78234diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
78235index f11d83b..d016d91 100644
78236--- a/kernel/time/alarmtimer.c
78237+++ b/kernel/time/alarmtimer.c
78238@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
78239 struct platform_device *pdev;
78240 int error = 0;
78241 int i;
78242- struct k_clock alarm_clock = {
78243+ static struct k_clock alarm_clock = {
78244 .clock_getres = alarm_clock_getres,
78245 .clock_get = alarm_clock_get,
78246 .timer_create = alarm_timer_create,
78247diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
78248index f113755..ec24223 100644
78249--- a/kernel/time/tick-broadcast.c
78250+++ b/kernel/time/tick-broadcast.c
78251@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
78252 * then clear the broadcast bit.
78253 */
78254 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
78255- int cpu = smp_processor_id();
78256+ cpu = smp_processor_id();
78257
78258 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
78259 tick_broadcast_clear_oneshot(cpu);
78260diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
78261index cbc6acb..3a77191 100644
78262--- a/kernel/time/timekeeping.c
78263+++ b/kernel/time/timekeeping.c
78264@@ -15,6 +15,7 @@
78265 #include <linux/init.h>
78266 #include <linux/mm.h>
78267 #include <linux/sched.h>
78268+#include <linux/grsecurity.h>
78269 #include <linux/syscore_ops.h>
78270 #include <linux/clocksource.h>
78271 #include <linux/jiffies.h>
78272@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
78273 if (!timespec_valid_strict(tv))
78274 return -EINVAL;
78275
78276+ gr_log_timechange();
78277+
78278 write_seqlock_irqsave(&tk->lock, flags);
78279
78280 timekeeping_forward_now(tk);
78281diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
78282index af5a7e9..715611a 100644
78283--- a/kernel/time/timer_list.c
78284+++ b/kernel/time/timer_list.c
78285@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
78286
78287 static void print_name_offset(struct seq_file *m, void *sym)
78288 {
78289+#ifdef CONFIG_GRKERNSEC_HIDESYM
78290+ SEQ_printf(m, "<%p>", NULL);
78291+#else
78292 char symname[KSYM_NAME_LEN];
78293
78294 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
78295 SEQ_printf(m, "<%pK>", sym);
78296 else
78297 SEQ_printf(m, "%s", symname);
78298+#endif
78299 }
78300
78301 static void
78302@@ -112,7 +116,11 @@ next_one:
78303 static void
78304 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
78305 {
78306+#ifdef CONFIG_GRKERNSEC_HIDESYM
78307+ SEQ_printf(m, " .base: %p\n", NULL);
78308+#else
78309 SEQ_printf(m, " .base: %pK\n", base);
78310+#endif
78311 SEQ_printf(m, " .index: %d\n",
78312 base->index);
78313 SEQ_printf(m, " .resolution: %Lu nsecs\n",
78314@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
78315 {
78316 struct proc_dir_entry *pe;
78317
78318+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78319+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
78320+#else
78321 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
78322+#endif
78323 if (!pe)
78324 return -ENOMEM;
78325 return 0;
78326diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
78327index 0b537f2..40d6c20 100644
78328--- a/kernel/time/timer_stats.c
78329+++ b/kernel/time/timer_stats.c
78330@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
78331 static unsigned long nr_entries;
78332 static struct entry entries[MAX_ENTRIES];
78333
78334-static atomic_t overflow_count;
78335+static atomic_unchecked_t overflow_count;
78336
78337 /*
78338 * The entries are in a hash-table, for fast lookup:
78339@@ -140,7 +140,7 @@ static void reset_entries(void)
78340 nr_entries = 0;
78341 memset(entries, 0, sizeof(entries));
78342 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
78343- atomic_set(&overflow_count, 0);
78344+ atomic_set_unchecked(&overflow_count, 0);
78345 }
78346
78347 static struct entry *alloc_entry(void)
78348@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78349 if (likely(entry))
78350 entry->count++;
78351 else
78352- atomic_inc(&overflow_count);
78353+ atomic_inc_unchecked(&overflow_count);
78354
78355 out_unlock:
78356 raw_spin_unlock_irqrestore(lock, flags);
78357@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78358
78359 static void print_name_offset(struct seq_file *m, unsigned long addr)
78360 {
78361+#ifdef CONFIG_GRKERNSEC_HIDESYM
78362+ seq_printf(m, "<%p>", NULL);
78363+#else
78364 char symname[KSYM_NAME_LEN];
78365
78366 if (lookup_symbol_name(addr, symname) < 0)
78367- seq_printf(m, "<%p>", (void *)addr);
78368+ seq_printf(m, "<%pK>", (void *)addr);
78369 else
78370 seq_printf(m, "%s", symname);
78371+#endif
78372 }
78373
78374 static int tstats_show(struct seq_file *m, void *v)
78375@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
78376
78377 seq_puts(m, "Timer Stats Version: v0.2\n");
78378 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
78379- if (atomic_read(&overflow_count))
78380+ if (atomic_read_unchecked(&overflow_count))
78381 seq_printf(m, "Overflow: %d entries\n",
78382- atomic_read(&overflow_count));
78383+ atomic_read_unchecked(&overflow_count));
78384
78385 for (i = 0; i < nr_entries; i++) {
78386 entry = entries + i;
78387@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
78388 {
78389 struct proc_dir_entry *pe;
78390
78391+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78392+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
78393+#else
78394 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
78395+#endif
78396 if (!pe)
78397 return -ENOMEM;
78398 return 0;
78399diff --git a/kernel/timer.c b/kernel/timer.c
78400index 367d008..5dee98f 100644
78401--- a/kernel/timer.c
78402+++ b/kernel/timer.c
78403@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
78404 /*
78405 * This function runs timers and the timer-tq in bottom half context.
78406 */
78407-static void run_timer_softirq(struct softirq_action *h)
78408+static void run_timer_softirq(void)
78409 {
78410 struct tvec_base *base = __this_cpu_read(tvec_bases);
78411
78412@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
78413 *
78414 * In all cases the return value is guaranteed to be non-negative.
78415 */
78416-signed long __sched schedule_timeout(signed long timeout)
78417+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
78418 {
78419 struct timer_list timer;
78420 unsigned long expire;
78421@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
78422 return NOTIFY_OK;
78423 }
78424
78425-static struct notifier_block __cpuinitdata timers_nb = {
78426+static struct notifier_block timers_nb = {
78427 .notifier_call = timer_cpu_notify,
78428 };
78429
78430diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
78431index c0bd030..62a1927 100644
78432--- a/kernel/trace/blktrace.c
78433+++ b/kernel/trace/blktrace.c
78434@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
78435 struct blk_trace *bt = filp->private_data;
78436 char buf[16];
78437
78438- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
78439+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
78440
78441 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
78442 }
78443@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
78444 return 1;
78445
78446 bt = buf->chan->private_data;
78447- atomic_inc(&bt->dropped);
78448+ atomic_inc_unchecked(&bt->dropped);
78449 return 0;
78450 }
78451
78452@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
78453
78454 bt->dir = dir;
78455 bt->dev = dev;
78456- atomic_set(&bt->dropped, 0);
78457+ atomic_set_unchecked(&bt->dropped, 0);
78458
78459 ret = -EIO;
78460 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
78461diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
78462index 43defd1..76da436 100644
78463--- a/kernel/trace/ftrace.c
78464+++ b/kernel/trace/ftrace.c
78465@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
78466 if (unlikely(ftrace_disabled))
78467 return 0;
78468
78469+ ret = ftrace_arch_code_modify_prepare();
78470+ FTRACE_WARN_ON(ret);
78471+ if (ret)
78472+ return 0;
78473+
78474 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
78475+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
78476 if (ret) {
78477 ftrace_bug(ret, ip);
78478- return 0;
78479 }
78480- return 1;
78481+ return ret ? 0 : 1;
78482 }
78483
78484 /*
78485@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
78486
78487 int
78488 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
78489- void *data)
78490+ void *data)
78491 {
78492 struct ftrace_func_probe *entry;
78493 struct ftrace_page *pg;
78494@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
78495 if (!count)
78496 return 0;
78497
78498+ pax_open_kernel();
78499 sort(start, count, sizeof(*start),
78500 ftrace_cmp_ips, ftrace_swap_ips);
78501+ pax_close_kernel();
78502
78503 start_pg = ftrace_allocate_pages(count);
78504 if (!start_pg)
78505@@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
78506 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
78507
78508 static int ftrace_graph_active;
78509-static struct notifier_block ftrace_suspend_notifier;
78510-
78511 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
78512 {
78513 return 0;
78514@@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
78515 return NOTIFY_DONE;
78516 }
78517
78518+static struct notifier_block ftrace_suspend_notifier = {
78519+ .notifier_call = ftrace_suspend_notifier_call
78520+};
78521+
78522 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78523 trace_func_graph_ent_t entryfunc)
78524 {
78525@@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78526 goto out;
78527 }
78528
78529- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
78530 register_pm_notifier(&ftrace_suspend_notifier);
78531
78532 ftrace_graph_active++;
78533diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
78534index ce8514f..8233573 100644
78535--- a/kernel/trace/ring_buffer.c
78536+++ b/kernel/trace/ring_buffer.c
78537@@ -346,9 +346,9 @@ struct buffer_data_page {
78538 */
78539 struct buffer_page {
78540 struct list_head list; /* list of buffer pages */
78541- local_t write; /* index for next write */
78542+ local_unchecked_t write; /* index for next write */
78543 unsigned read; /* index for next read */
78544- local_t entries; /* entries on this page */
78545+ local_unchecked_t entries; /* entries on this page */
78546 unsigned long real_end; /* real end of data */
78547 struct buffer_data_page *page; /* Actual data page */
78548 };
78549@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
78550 unsigned long last_overrun;
78551 local_t entries_bytes;
78552 local_t entries;
78553- local_t overrun;
78554- local_t commit_overrun;
78555+ local_unchecked_t overrun;
78556+ local_unchecked_t commit_overrun;
78557 local_t dropped_events;
78558 local_t committing;
78559 local_t commits;
78560@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78561 *
78562 * We add a counter to the write field to denote this.
78563 */
78564- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
78565- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
78566+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
78567+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
78568
78569 /*
78570 * Just make sure we have seen our old_write and synchronize
78571@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78572 * cmpxchg to only update if an interrupt did not already
78573 * do it for us. If the cmpxchg fails, we don't care.
78574 */
78575- (void)local_cmpxchg(&next_page->write, old_write, val);
78576- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
78577+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
78578+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
78579
78580 /*
78581 * No need to worry about races with clearing out the commit.
78582@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
78583
78584 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
78585 {
78586- return local_read(&bpage->entries) & RB_WRITE_MASK;
78587+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
78588 }
78589
78590 static inline unsigned long rb_page_write(struct buffer_page *bpage)
78591 {
78592- return local_read(&bpage->write) & RB_WRITE_MASK;
78593+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
78594 }
78595
78596 static int
78597@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
78598 * bytes consumed in ring buffer from here.
78599 * Increment overrun to account for the lost events.
78600 */
78601- local_add(page_entries, &cpu_buffer->overrun);
78602+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
78603 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78604 }
78605
78606@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
78607 * it is our responsibility to update
78608 * the counters.
78609 */
78610- local_add(entries, &cpu_buffer->overrun);
78611+ local_add_unchecked(entries, &cpu_buffer->overrun);
78612 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78613
78614 /*
78615@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78616 if (tail == BUF_PAGE_SIZE)
78617 tail_page->real_end = 0;
78618
78619- local_sub(length, &tail_page->write);
78620+ local_sub_unchecked(length, &tail_page->write);
78621 return;
78622 }
78623
78624@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78625 rb_event_set_padding(event);
78626
78627 /* Set the write back to the previous setting */
78628- local_sub(length, &tail_page->write);
78629+ local_sub_unchecked(length, &tail_page->write);
78630 return;
78631 }
78632
78633@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78634
78635 /* Set write to end of buffer */
78636 length = (tail + length) - BUF_PAGE_SIZE;
78637- local_sub(length, &tail_page->write);
78638+ local_sub_unchecked(length, &tail_page->write);
78639 }
78640
78641 /*
78642@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78643 * about it.
78644 */
78645 if (unlikely(next_page == commit_page)) {
78646- local_inc(&cpu_buffer->commit_overrun);
78647+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78648 goto out_reset;
78649 }
78650
78651@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78652 cpu_buffer->tail_page) &&
78653 (cpu_buffer->commit_page ==
78654 cpu_buffer->reader_page))) {
78655- local_inc(&cpu_buffer->commit_overrun);
78656+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78657 goto out_reset;
78658 }
78659 }
78660@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78661 length += RB_LEN_TIME_EXTEND;
78662
78663 tail_page = cpu_buffer->tail_page;
78664- write = local_add_return(length, &tail_page->write);
78665+ write = local_add_return_unchecked(length, &tail_page->write);
78666
78667 /* set write to only the index of the write */
78668 write &= RB_WRITE_MASK;
78669@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78670 kmemcheck_annotate_bitfield(event, bitfield);
78671 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
78672
78673- local_inc(&tail_page->entries);
78674+ local_inc_unchecked(&tail_page->entries);
78675
78676 /*
78677 * If this is the first commit on the page, then update
78678@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78679
78680 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
78681 unsigned long write_mask =
78682- local_read(&bpage->write) & ~RB_WRITE_MASK;
78683+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
78684 unsigned long event_length = rb_event_length(event);
78685 /*
78686 * This is on the tail page. It is possible that
78687@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78688 */
78689 old_index += write_mask;
78690 new_index += write_mask;
78691- index = local_cmpxchg(&bpage->write, old_index, new_index);
78692+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
78693 if (index == old_index) {
78694 /* update counters */
78695 local_sub(event_length, &cpu_buffer->entries_bytes);
78696@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78697
78698 /* Do the likely case first */
78699 if (likely(bpage->page == (void *)addr)) {
78700- local_dec(&bpage->entries);
78701+ local_dec_unchecked(&bpage->entries);
78702 return;
78703 }
78704
78705@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78706 start = bpage;
78707 do {
78708 if (bpage->page == (void *)addr) {
78709- local_dec(&bpage->entries);
78710+ local_dec_unchecked(&bpage->entries);
78711 return;
78712 }
78713 rb_inc_page(cpu_buffer, &bpage);
78714@@ -2926,7 +2926,7 @@ static inline unsigned long
78715 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
78716 {
78717 return local_read(&cpu_buffer->entries) -
78718- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
78719+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
78720 }
78721
78722 /**
78723@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
78724 return 0;
78725
78726 cpu_buffer = buffer->buffers[cpu];
78727- ret = local_read(&cpu_buffer->overrun);
78728+ ret = local_read_unchecked(&cpu_buffer->overrun);
78729
78730 return ret;
78731 }
78732@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
78733 return 0;
78734
78735 cpu_buffer = buffer->buffers[cpu];
78736- ret = local_read(&cpu_buffer->commit_overrun);
78737+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
78738
78739 return ret;
78740 }
78741@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
78742 /* if you care about this being correct, lock the buffer */
78743 for_each_buffer_cpu(buffer, cpu) {
78744 cpu_buffer = buffer->buffers[cpu];
78745- overruns += local_read(&cpu_buffer->overrun);
78746+ overruns += local_read_unchecked(&cpu_buffer->overrun);
78747 }
78748
78749 return overruns;
78750@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78751 /*
78752 * Reset the reader page to size zero.
78753 */
78754- local_set(&cpu_buffer->reader_page->write, 0);
78755- local_set(&cpu_buffer->reader_page->entries, 0);
78756+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78757+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78758 local_set(&cpu_buffer->reader_page->page->commit, 0);
78759 cpu_buffer->reader_page->real_end = 0;
78760
78761@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78762 * want to compare with the last_overrun.
78763 */
78764 smp_mb();
78765- overwrite = local_read(&(cpu_buffer->overrun));
78766+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
78767
78768 /*
78769 * Here's the tricky part.
78770@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78771
78772 cpu_buffer->head_page
78773 = list_entry(cpu_buffer->pages, struct buffer_page, list);
78774- local_set(&cpu_buffer->head_page->write, 0);
78775- local_set(&cpu_buffer->head_page->entries, 0);
78776+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
78777+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
78778 local_set(&cpu_buffer->head_page->page->commit, 0);
78779
78780 cpu_buffer->head_page->read = 0;
78781@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78782
78783 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
78784 INIT_LIST_HEAD(&cpu_buffer->new_pages);
78785- local_set(&cpu_buffer->reader_page->write, 0);
78786- local_set(&cpu_buffer->reader_page->entries, 0);
78787+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78788+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78789 local_set(&cpu_buffer->reader_page->page->commit, 0);
78790 cpu_buffer->reader_page->read = 0;
78791
78792 local_set(&cpu_buffer->entries_bytes, 0);
78793- local_set(&cpu_buffer->overrun, 0);
78794- local_set(&cpu_buffer->commit_overrun, 0);
78795+ local_set_unchecked(&cpu_buffer->overrun, 0);
78796+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
78797 local_set(&cpu_buffer->dropped_events, 0);
78798 local_set(&cpu_buffer->entries, 0);
78799 local_set(&cpu_buffer->committing, 0);
78800@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78801 rb_init_page(bpage);
78802 bpage = reader->page;
78803 reader->page = *data_page;
78804- local_set(&reader->write, 0);
78805- local_set(&reader->entries, 0);
78806+ local_set_unchecked(&reader->write, 0);
78807+ local_set_unchecked(&reader->entries, 0);
78808 reader->read = 0;
78809 *data_page = bpage;
78810
78811diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
78812index 3c13e46..883d039 100644
78813--- a/kernel/trace/trace.c
78814+++ b/kernel/trace/trace.c
78815@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
78816 };
78817 #endif
78818
78819-static struct dentry *d_tracer;
78820-
78821 struct dentry *tracing_init_dentry(void)
78822 {
78823+ static struct dentry *d_tracer;
78824 static int once;
78825
78826 if (d_tracer)
78827@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
78828 return d_tracer;
78829 }
78830
78831-static struct dentry *d_percpu;
78832-
78833 struct dentry *tracing_dentry_percpu(void)
78834 {
78835+ static struct dentry *d_percpu;
78836 static int once;
78837 struct dentry *d_tracer;
78838
78839diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
78840index 880073d..42db7c3 100644
78841--- a/kernel/trace/trace_events.c
78842+++ b/kernel/trace/trace_events.c
78843@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
78844 struct ftrace_module_file_ops {
78845 struct list_head list;
78846 struct module *mod;
78847- struct file_operations id;
78848- struct file_operations enable;
78849- struct file_operations format;
78850- struct file_operations filter;
78851 };
78852
78853 static struct ftrace_module_file_ops *
78854@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
78855
78856 file_ops->mod = mod;
78857
78858- file_ops->id = ftrace_event_id_fops;
78859- file_ops->id.owner = mod;
78860-
78861- file_ops->enable = ftrace_enable_fops;
78862- file_ops->enable.owner = mod;
78863-
78864- file_ops->filter = ftrace_event_filter_fops;
78865- file_ops->filter.owner = mod;
78866-
78867- file_ops->format = ftrace_event_format_fops;
78868- file_ops->format.owner = mod;
78869+ pax_open_kernel();
78870+ mod->trace_id.owner = mod;
78871+ mod->trace_enable.owner = mod;
78872+ mod->trace_filter.owner = mod;
78873+ mod->trace_format.owner = mod;
78874+ pax_close_kernel();
78875
78876 list_add(&file_ops->list, &ftrace_module_file_list);
78877
78878@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
78879
78880 for_each_event(call, start, end) {
78881 __trace_add_event_call(*call, mod,
78882- &file_ops->id, &file_ops->enable,
78883- &file_ops->filter, &file_ops->format);
78884+ &mod->trace_id, &mod->trace_enable,
78885+ &mod->trace_filter, &mod->trace_format);
78886 }
78887 }
78888
78889diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
78890index fd3c8aa..5f324a6 100644
78891--- a/kernel/trace/trace_mmiotrace.c
78892+++ b/kernel/trace/trace_mmiotrace.c
78893@@ -24,7 +24,7 @@ struct header_iter {
78894 static struct trace_array *mmio_trace_array;
78895 static bool overrun_detected;
78896 static unsigned long prev_overruns;
78897-static atomic_t dropped_count;
78898+static atomic_unchecked_t dropped_count;
78899
78900 static void mmio_reset_data(struct trace_array *tr)
78901 {
78902@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
78903
78904 static unsigned long count_overruns(struct trace_iterator *iter)
78905 {
78906- unsigned long cnt = atomic_xchg(&dropped_count, 0);
78907+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
78908 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
78909
78910 if (over > prev_overruns)
78911@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
78912 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
78913 sizeof(*entry), 0, pc);
78914 if (!event) {
78915- atomic_inc(&dropped_count);
78916+ atomic_inc_unchecked(&dropped_count);
78917 return;
78918 }
78919 entry = ring_buffer_event_data(event);
78920@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78921 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78922 sizeof(*entry), 0, pc);
78923 if (!event) {
78924- atomic_inc(&dropped_count);
78925+ atomic_inc_unchecked(&dropped_count);
78926 return;
78927 }
78928 entry = ring_buffer_event_data(event);
78929diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78930index 194d796..76edb8f 100644
78931--- a/kernel/trace/trace_output.c
78932+++ b/kernel/trace/trace_output.c
78933@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78934
78935 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78936 if (!IS_ERR(p)) {
78937- p = mangle_path(s->buffer + s->len, p, "\n");
78938+ p = mangle_path(s->buffer + s->len, p, "\n\\");
78939 if (p) {
78940 s->len = p - s->buffer;
78941 return 1;
78942@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78943 goto out;
78944 }
78945
78946+ pax_open_kernel();
78947 if (event->funcs->trace == NULL)
78948- event->funcs->trace = trace_nop_print;
78949+ *(void **)&event->funcs->trace = trace_nop_print;
78950 if (event->funcs->raw == NULL)
78951- event->funcs->raw = trace_nop_print;
78952+ *(void **)&event->funcs->raw = trace_nop_print;
78953 if (event->funcs->hex == NULL)
78954- event->funcs->hex = trace_nop_print;
78955+ *(void **)&event->funcs->hex = trace_nop_print;
78956 if (event->funcs->binary == NULL)
78957- event->funcs->binary = trace_nop_print;
78958+ *(void **)&event->funcs->binary = trace_nop_print;
78959+ pax_close_kernel();
78960
78961 key = event->type & (EVENT_HASHSIZE - 1);
78962
78963diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
78964index 42ca822..cdcacc6 100644
78965--- a/kernel/trace/trace_stack.c
78966+++ b/kernel/trace/trace_stack.c
78967@@ -52,7 +52,7 @@ static inline void check_stack(void)
78968 return;
78969
78970 /* we do not handle interrupt stacks yet */
78971- if (!object_is_on_stack(&this_size))
78972+ if (!object_starts_on_stack(&this_size))
78973 return;
78974
78975 local_irq_save(flags);
78976diff --git a/kernel/user.c b/kernel/user.c
78977index 33acb5e..57ebfd4 100644
78978--- a/kernel/user.c
78979+++ b/kernel/user.c
78980@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
78981 .count = 4294967295U,
78982 },
78983 },
78984- .kref = {
78985- .refcount = ATOMIC_INIT(3),
78986- },
78987+ .count = ATOMIC_INIT(3),
78988 .owner = GLOBAL_ROOT_UID,
78989 .group = GLOBAL_ROOT_GID,
78990 .proc_inum = PROC_USER_INIT_INO,
78991diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
78992index dbfe36a7..2a3c1df 100644
78993--- a/kernel/user_namespace.c
78994+++ b/kernel/user_namespace.c
78995@@ -79,7 +79,7 @@ int create_user_ns(struct cred *new)
78996 return ret;
78997 }
78998
78999- kref_init(&ns->kref);
79000+ atomic_set(&ns->count, 1);
79001 /* Leave the new->user_ns reference with the new user namespace. */
79002 ns->parent = parent_ns;
79003 ns->owner = owner;
79004@@ -105,15 +105,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
79005 return create_user_ns(cred);
79006 }
79007
79008-void free_user_ns(struct kref *kref)
79009+void free_user_ns(struct user_namespace *ns)
79010 {
79011- struct user_namespace *parent, *ns =
79012- container_of(kref, struct user_namespace, kref);
79013+ struct user_namespace *parent;
79014
79015- parent = ns->parent;
79016- proc_free_inum(ns->proc_inum);
79017- kmem_cache_free(user_ns_cachep, ns);
79018- put_user_ns(parent);
79019+ do {
79020+ parent = ns->parent;
79021+ proc_free_inum(ns->proc_inum);
79022+ kmem_cache_free(user_ns_cachep, ns);
79023+ ns = parent;
79024+ } while (atomic_dec_and_test(&parent->count));
79025 }
79026 EXPORT_SYMBOL(free_user_ns);
79027
79028@@ -804,7 +805,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
79029 if (atomic_read(&current->mm->mm_users) > 1)
79030 return -EINVAL;
79031
79032- if (current->fs->users != 1)
79033+ if (atomic_read(&current->fs->users) != 1)
79034 return -EINVAL;
79035
79036 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
79037diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
79038index 63da38c..639904e 100644
79039--- a/kernel/utsname_sysctl.c
79040+++ b/kernel/utsname_sysctl.c
79041@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
79042 static int proc_do_uts_string(ctl_table *table, int write,
79043 void __user *buffer, size_t *lenp, loff_t *ppos)
79044 {
79045- struct ctl_table uts_table;
79046+ ctl_table_no_const uts_table;
79047 int r;
79048 memcpy(&uts_table, table, sizeof(uts_table));
79049 uts_table.data = get_uts(table, write);
79050diff --git a/kernel/watchdog.c b/kernel/watchdog.c
79051index 75a2ab3..5961da7 100644
79052--- a/kernel/watchdog.c
79053+++ b/kernel/watchdog.c
79054@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
79055 }
79056 #endif /* CONFIG_SYSCTL */
79057
79058-static struct smp_hotplug_thread watchdog_threads = {
79059+static struct smp_hotplug_thread watchdog_threads __read_only = {
79060 .store = &softlockup_watchdog,
79061 .thread_should_run = watchdog_should_run,
79062 .thread_fn = watchdog,
79063diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
79064index 67604e5..fe94fb1 100644
79065--- a/lib/Kconfig.debug
79066+++ b/lib/Kconfig.debug
79067@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
79068
79069 config DEBUG_LOCK_ALLOC
79070 bool "Lock debugging: detect incorrect freeing of live locks"
79071- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79072+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79073 select DEBUG_SPINLOCK
79074 select DEBUG_MUTEXES
79075 select LOCKDEP
79076@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
79077
79078 config PROVE_LOCKING
79079 bool "Lock debugging: prove locking correctness"
79080- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79081+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79082 select LOCKDEP
79083 select DEBUG_SPINLOCK
79084 select DEBUG_MUTEXES
79085@@ -670,7 +670,7 @@ config LOCKDEP
79086
79087 config LOCK_STAT
79088 bool "Lock usage statistics"
79089- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79090+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79091 select LOCKDEP
79092 select DEBUG_SPINLOCK
79093 select DEBUG_MUTEXES
79094@@ -1278,6 +1278,7 @@ config LATENCYTOP
79095 depends on DEBUG_KERNEL
79096 depends on STACKTRACE_SUPPORT
79097 depends on PROC_FS
79098+ depends on !GRKERNSEC_HIDESYM
79099 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
79100 select KALLSYMS
79101 select KALLSYMS_ALL
79102@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
79103
79104 config PROVIDE_OHCI1394_DMA_INIT
79105 bool "Remote debugging over FireWire early on boot"
79106- depends on PCI && X86
79107+ depends on PCI && X86 && !GRKERNSEC
79108 help
79109 If you want to debug problems which hang or crash the kernel early
79110 on boot and the crashing machine has a FireWire port, you can use
79111@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
79112
79113 config FIREWIRE_OHCI_REMOTE_DMA
79114 bool "Remote debugging over FireWire with firewire-ohci"
79115- depends on FIREWIRE_OHCI
79116+ depends on FIREWIRE_OHCI && !GRKERNSEC
79117 help
79118 This option lets you use the FireWire bus for remote debugging
79119 with help of the firewire-ohci driver. It enables unfiltered
79120diff --git a/lib/Makefile b/lib/Makefile
79121index 02ed6c0..bd243da 100644
79122--- a/lib/Makefile
79123+++ b/lib/Makefile
79124@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
79125
79126 obj-$(CONFIG_BTREE) += btree.o
79127 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
79128-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
79129+obj-y += list_debug.o
79130 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
79131
79132 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
79133diff --git a/lib/bitmap.c b/lib/bitmap.c
79134index 06f7e4f..f3cf2b0 100644
79135--- a/lib/bitmap.c
79136+++ b/lib/bitmap.c
79137@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
79138 {
79139 int c, old_c, totaldigits, ndigits, nchunks, nbits;
79140 u32 chunk;
79141- const char __user __force *ubuf = (const char __user __force *)buf;
79142+ const char __user *ubuf = (const char __force_user *)buf;
79143
79144 bitmap_zero(maskp, nmaskbits);
79145
79146@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
79147 {
79148 if (!access_ok(VERIFY_READ, ubuf, ulen))
79149 return -EFAULT;
79150- return __bitmap_parse((const char __force *)ubuf,
79151+ return __bitmap_parse((const char __force_kernel *)ubuf,
79152 ulen, 1, maskp, nmaskbits);
79153
79154 }
79155@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
79156 {
79157 unsigned a, b;
79158 int c, old_c, totaldigits;
79159- const char __user __force *ubuf = (const char __user __force *)buf;
79160+ const char __user *ubuf = (const char __force_user *)buf;
79161 int exp_digit, in_range;
79162
79163 totaldigits = c = 0;
79164@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
79165 {
79166 if (!access_ok(VERIFY_READ, ubuf, ulen))
79167 return -EFAULT;
79168- return __bitmap_parselist((const char __force *)ubuf,
79169+ return __bitmap_parselist((const char __force_kernel *)ubuf,
79170 ulen, 1, maskp, nmaskbits);
79171 }
79172 EXPORT_SYMBOL(bitmap_parselist_user);
79173diff --git a/lib/bug.c b/lib/bug.c
79174index d0cdf14..4d07bd2 100644
79175--- a/lib/bug.c
79176+++ b/lib/bug.c
79177@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
79178 return BUG_TRAP_TYPE_NONE;
79179
79180 bug = find_bug(bugaddr);
79181+ if (!bug)
79182+ return BUG_TRAP_TYPE_NONE;
79183
79184 file = NULL;
79185 line = 0;
79186diff --git a/lib/debugobjects.c b/lib/debugobjects.c
79187index d11808c..dc2d6f8 100644
79188--- a/lib/debugobjects.c
79189+++ b/lib/debugobjects.c
79190@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
79191 if (limit > 4)
79192 return;
79193
79194- is_on_stack = object_is_on_stack(addr);
79195+ is_on_stack = object_starts_on_stack(addr);
79196 if (is_on_stack == onstack)
79197 return;
79198
79199diff --git a/lib/devres.c b/lib/devres.c
79200index 80b9c76..9e32279 100644
79201--- a/lib/devres.c
79202+++ b/lib/devres.c
79203@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
79204 void devm_iounmap(struct device *dev, void __iomem *addr)
79205 {
79206 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
79207- (void *)addr));
79208+ (void __force *)addr));
79209 iounmap(addr);
79210 }
79211 EXPORT_SYMBOL(devm_iounmap);
79212@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
79213 {
79214 ioport_unmap(addr);
79215 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
79216- devm_ioport_map_match, (void *)addr));
79217+ devm_ioport_map_match, (void __force *)addr));
79218 }
79219 EXPORT_SYMBOL(devm_ioport_unmap);
79220
79221diff --git a/lib/div64.c b/lib/div64.c
79222index a163b6c..9618fa5 100644
79223--- a/lib/div64.c
79224+++ b/lib/div64.c
79225@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
79226 EXPORT_SYMBOL(__div64_32);
79227
79228 #ifndef div_s64_rem
79229-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79230+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79231 {
79232 u64 quotient;
79233
79234@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
79235 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
79236 */
79237 #ifndef div64_u64
79238-u64 div64_u64(u64 dividend, u64 divisor)
79239+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79240 {
79241 u32 high = divisor >> 32;
79242 u64 quot;
79243diff --git a/lib/dma-debug.c b/lib/dma-debug.c
79244index 5e396ac..58d5de1 100644
79245--- a/lib/dma-debug.c
79246+++ b/lib/dma-debug.c
79247@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
79248
79249 void dma_debug_add_bus(struct bus_type *bus)
79250 {
79251- struct notifier_block *nb;
79252+ notifier_block_no_const *nb;
79253
79254 if (global_disable)
79255 return;
79256@@ -942,7 +942,7 @@ out:
79257
79258 static void check_for_stack(struct device *dev, void *addr)
79259 {
79260- if (object_is_on_stack(addr))
79261+ if (object_starts_on_stack(addr))
79262 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
79263 "stack [addr=%p]\n", addr);
79264 }
79265diff --git a/lib/inflate.c b/lib/inflate.c
79266index 013a761..c28f3fc 100644
79267--- a/lib/inflate.c
79268+++ b/lib/inflate.c
79269@@ -269,7 +269,7 @@ static void free(void *where)
79270 malloc_ptr = free_mem_ptr;
79271 }
79272 #else
79273-#define malloc(a) kmalloc(a, GFP_KERNEL)
79274+#define malloc(a) kmalloc((a), GFP_KERNEL)
79275 #define free(a) kfree(a)
79276 #endif
79277
79278diff --git a/lib/ioremap.c b/lib/ioremap.c
79279index 0c9216c..863bd89 100644
79280--- a/lib/ioremap.c
79281+++ b/lib/ioremap.c
79282@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
79283 unsigned long next;
79284
79285 phys_addr -= addr;
79286- pmd = pmd_alloc(&init_mm, pud, addr);
79287+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79288 if (!pmd)
79289 return -ENOMEM;
79290 do {
79291@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
79292 unsigned long next;
79293
79294 phys_addr -= addr;
79295- pud = pud_alloc(&init_mm, pgd, addr);
79296+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79297 if (!pud)
79298 return -ENOMEM;
79299 do {
79300diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
79301index bd2bea9..6b3c95e 100644
79302--- a/lib/is_single_threaded.c
79303+++ b/lib/is_single_threaded.c
79304@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
79305 struct task_struct *p, *t;
79306 bool ret;
79307
79308+ if (!mm)
79309+ return true;
79310+
79311 if (atomic_read(&task->signal->live) != 1)
79312 return false;
79313
79314diff --git a/lib/kobject.c b/lib/kobject.c
79315index e07ee1f..998489d 100644
79316--- a/lib/kobject.c
79317+++ b/lib/kobject.c
79318@@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
79319
79320
79321 static DEFINE_SPINLOCK(kobj_ns_type_lock);
79322-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
79323+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
79324
79325-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79326+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79327 {
79328 enum kobj_ns_type type = ops->type;
79329 int error;
79330diff --git a/lib/list_debug.c b/lib/list_debug.c
79331index c24c2f7..0475b78 100644
79332--- a/lib/list_debug.c
79333+++ b/lib/list_debug.c
79334@@ -11,7 +11,9 @@
79335 #include <linux/bug.h>
79336 #include <linux/kernel.h>
79337 #include <linux/rculist.h>
79338+#include <linux/mm.h>
79339
79340+#ifdef CONFIG_DEBUG_LIST
79341 /*
79342 * Insert a new entry between two known consecutive entries.
79343 *
79344@@ -19,21 +21,32 @@
79345 * the prev/next entries already!
79346 */
79347
79348-void __list_add(struct list_head *new,
79349- struct list_head *prev,
79350- struct list_head *next)
79351+static bool __list_add_debug(struct list_head *new,
79352+ struct list_head *prev,
79353+ struct list_head *next)
79354 {
79355- WARN(next->prev != prev,
79356+ if (WARN(next->prev != prev,
79357 "list_add corruption. next->prev should be "
79358 "prev (%p), but was %p. (next=%p).\n",
79359- prev, next->prev, next);
79360- WARN(prev->next != next,
79361+ prev, next->prev, next) ||
79362+ WARN(prev->next != next,
79363 "list_add corruption. prev->next should be "
79364 "next (%p), but was %p. (prev=%p).\n",
79365- next, prev->next, prev);
79366- WARN(new == prev || new == next,
79367+ next, prev->next, prev) ||
79368+ WARN(new == prev || new == next,
79369 "list_add double add: new=%p, prev=%p, next=%p.\n",
79370- new, prev, next);
79371+ new, prev, next))
79372+ return false;
79373+ return true;
79374+}
79375+
79376+void __list_add(struct list_head *new,
79377+ struct list_head *prev,
79378+ struct list_head *next)
79379+{
79380+ if (!__list_add_debug(new, prev, next))
79381+ return;
79382+
79383 next->prev = new;
79384 new->next = next;
79385 new->prev = prev;
79386@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
79387 }
79388 EXPORT_SYMBOL(__list_add);
79389
79390-void __list_del_entry(struct list_head *entry)
79391+static bool __list_del_entry_debug(struct list_head *entry)
79392 {
79393 struct list_head *prev, *next;
79394
79395@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
79396 WARN(next->prev != entry,
79397 "list_del corruption. next->prev should be %p, "
79398 "but was %p\n", entry, next->prev))
79399+ return false;
79400+ return true;
79401+}
79402+
79403+void __list_del_entry(struct list_head *entry)
79404+{
79405+ if (!__list_del_entry_debug(entry))
79406 return;
79407
79408- __list_del(prev, next);
79409+ __list_del(entry->prev, entry->next);
79410 }
79411 EXPORT_SYMBOL(__list_del_entry);
79412
79413@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
79414 void __list_add_rcu(struct list_head *new,
79415 struct list_head *prev, struct list_head *next)
79416 {
79417- WARN(next->prev != prev,
79418- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
79419- prev, next->prev, next);
79420- WARN(prev->next != next,
79421- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
79422- next, prev->next, prev);
79423+ if (!__list_add_debug(new, prev, next))
79424+ return;
79425+
79426 new->next = next;
79427 new->prev = prev;
79428 rcu_assign_pointer(list_next_rcu(prev), new);
79429 next->prev = new;
79430 }
79431 EXPORT_SYMBOL(__list_add_rcu);
79432+#endif
79433+
79434+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
79435+{
79436+#ifdef CONFIG_DEBUG_LIST
79437+ if (!__list_add_debug(new, prev, next))
79438+ return;
79439+#endif
79440+
79441+ pax_open_kernel();
79442+ next->prev = new;
79443+ new->next = next;
79444+ new->prev = prev;
79445+ prev->next = new;
79446+ pax_close_kernel();
79447+}
79448+EXPORT_SYMBOL(__pax_list_add);
79449+
79450+void pax_list_del(struct list_head *entry)
79451+{
79452+#ifdef CONFIG_DEBUG_LIST
79453+ if (!__list_del_entry_debug(entry))
79454+ return;
79455+#endif
79456+
79457+ pax_open_kernel();
79458+ __list_del(entry->prev, entry->next);
79459+ entry->next = LIST_POISON1;
79460+ entry->prev = LIST_POISON2;
79461+ pax_close_kernel();
79462+}
79463+EXPORT_SYMBOL(pax_list_del);
79464+
79465+void pax_list_del_init(struct list_head *entry)
79466+{
79467+ pax_open_kernel();
79468+ __list_del(entry->prev, entry->next);
79469+ INIT_LIST_HEAD(entry);
79470+ pax_close_kernel();
79471+}
79472+EXPORT_SYMBOL(pax_list_del_init);
79473+
79474+void __pax_list_add_rcu(struct list_head *new,
79475+ struct list_head *prev, struct list_head *next)
79476+{
79477+#ifdef CONFIG_DEBUG_LIST
79478+ if (!__list_add_debug(new, prev, next))
79479+ return;
79480+#endif
79481+
79482+ pax_open_kernel();
79483+ new->next = next;
79484+ new->prev = prev;
79485+ rcu_assign_pointer(list_next_rcu(prev), new);
79486+ next->prev = new;
79487+ pax_close_kernel();
79488+}
79489+EXPORT_SYMBOL(__pax_list_add_rcu);
79490+
79491+void pax_list_del_rcu(struct list_head *entry)
79492+{
79493+#ifdef CONFIG_DEBUG_LIST
79494+ if (!__list_del_entry_debug(entry))
79495+ return;
79496+#endif
79497+
79498+ pax_open_kernel();
79499+ __list_del(entry->prev, entry->next);
79500+ entry->next = LIST_POISON1;
79501+ entry->prev = LIST_POISON2;
79502+ pax_close_kernel();
79503+}
79504+EXPORT_SYMBOL(pax_list_del_rcu);
79505diff --git a/lib/radix-tree.c b/lib/radix-tree.c
79506index e796429..6e38f9f 100644
79507--- a/lib/radix-tree.c
79508+++ b/lib/radix-tree.c
79509@@ -92,7 +92,7 @@ struct radix_tree_preload {
79510 int nr;
79511 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
79512 };
79513-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
79514+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
79515
79516 static inline void *ptr_to_indirect(void *ptr)
79517 {
79518diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
79519index bb2b201..46abaf9 100644
79520--- a/lib/strncpy_from_user.c
79521+++ b/lib/strncpy_from_user.c
79522@@ -21,7 +21,7 @@
79523 */
79524 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
79525 {
79526- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79527+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79528 long res = 0;
79529
79530 /*
79531diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
79532index a28df52..3d55877 100644
79533--- a/lib/strnlen_user.c
79534+++ b/lib/strnlen_user.c
79535@@ -26,7 +26,7 @@
79536 */
79537 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
79538 {
79539- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79540+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79541 long align, res = 0;
79542 unsigned long c;
79543
79544diff --git a/lib/swiotlb.c b/lib/swiotlb.c
79545index 196b069..358f342 100644
79546--- a/lib/swiotlb.c
79547+++ b/lib/swiotlb.c
79548@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
79549
79550 void
79551 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
79552- dma_addr_t dev_addr)
79553+ dma_addr_t dev_addr, struct dma_attrs *attrs)
79554 {
79555 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
79556
79557diff --git a/lib/vsprintf.c b/lib/vsprintf.c
79558index fab33a9..3b5fe68 100644
79559--- a/lib/vsprintf.c
79560+++ b/lib/vsprintf.c
79561@@ -16,6 +16,9 @@
79562 * - scnprintf and vscnprintf
79563 */
79564
79565+#ifdef CONFIG_GRKERNSEC_HIDESYM
79566+#define __INCLUDED_BY_HIDESYM 1
79567+#endif
79568 #include <stdarg.h>
79569 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
79570 #include <linux/types.h>
79571@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
79572 char sym[KSYM_SYMBOL_LEN];
79573 if (ext == 'B')
79574 sprint_backtrace(sym, value);
79575- else if (ext != 'f' && ext != 's')
79576+ else if (ext != 'f' && ext != 's' && ext != 'a')
79577 sprint_symbol(sym, value);
79578 else
79579 sprint_symbol_no_offset(sym, value);
79580@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
79581 return number(buf, end, *(const netdev_features_t *)addr, spec);
79582 }
79583
79584+#ifdef CONFIG_GRKERNSEC_HIDESYM
79585+int kptr_restrict __read_mostly = 2;
79586+#else
79587 int kptr_restrict __read_mostly;
79588+#endif
79589
79590 /*
79591 * Show a '%p' thing. A kernel extension is that the '%p' is followed
79592@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
79593 * - 'S' For symbolic direct pointers with offset
79594 * - 's' For symbolic direct pointers without offset
79595 * - 'B' For backtraced symbolic direct pointers with offset
79596+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
79597+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
79598 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
79599 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
79600 * - 'M' For a 6-byte MAC address, it prints the address in the
79601@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79602
79603 if (!ptr && *fmt != 'K') {
79604 /*
79605- * Print (null) with the same width as a pointer so it makes
79606+ * Print (nil) with the same width as a pointer so it makes
79607 * tabular output look nice.
79608 */
79609 if (spec.field_width == -1)
79610 spec.field_width = default_width;
79611- return string(buf, end, "(null)", spec);
79612+ return string(buf, end, "(nil)", spec);
79613 }
79614
79615 switch (*fmt) {
79616@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79617 /* Fallthrough */
79618 case 'S':
79619 case 's':
79620+#ifdef CONFIG_GRKERNSEC_HIDESYM
79621+ break;
79622+#else
79623+ return symbol_string(buf, end, ptr, spec, *fmt);
79624+#endif
79625+ case 'A':
79626+ case 'a':
79627 case 'B':
79628 return symbol_string(buf, end, ptr, spec, *fmt);
79629 case 'R':
79630@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79631 va_end(va);
79632 return buf;
79633 }
79634+ case 'P':
79635+ break;
79636 case 'K':
79637 /*
79638 * %pK cannot be used in IRQ context because its test
79639@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79640 }
79641 break;
79642 }
79643+
79644+#ifdef CONFIG_GRKERNSEC_HIDESYM
79645+ /* 'P' = approved pointers to copy to userland,
79646+ as in the /proc/kallsyms case, as we make it display nothing
79647+ for non-root users, and the real contents for root users
79648+ Also ignore 'K' pointers, since we force their NULLing for non-root users
79649+ above
79650+ */
79651+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
79652+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
79653+ dump_stack();
79654+ ptr = NULL;
79655+ }
79656+#endif
79657+
79658 spec.flags |= SMALL;
79659 if (spec.field_width == -1) {
79660 spec.field_width = default_width;
79661@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79662 typeof(type) value; \
79663 if (sizeof(type) == 8) { \
79664 args = PTR_ALIGN(args, sizeof(u32)); \
79665- *(u32 *)&value = *(u32 *)args; \
79666- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
79667+ *(u32 *)&value = *(const u32 *)args; \
79668+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
79669 } else { \
79670 args = PTR_ALIGN(args, sizeof(type)); \
79671- value = *(typeof(type) *)args; \
79672+ value = *(const typeof(type) *)args; \
79673 } \
79674 args += sizeof(type); \
79675 value; \
79676@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79677 case FORMAT_TYPE_STR: {
79678 const char *str_arg = args;
79679 args += strlen(str_arg) + 1;
79680- str = string(str, end, (char *)str_arg, spec);
79681+ str = string(str, end, str_arg, spec);
79682 break;
79683 }
79684
79685diff --git a/localversion-grsec b/localversion-grsec
79686new file mode 100644
79687index 0000000..7cd6065
79688--- /dev/null
79689+++ b/localversion-grsec
79690@@ -0,0 +1 @@
79691+-grsec
79692diff --git a/mm/Kconfig b/mm/Kconfig
79693index 278e3ab..87c384d 100644
79694--- a/mm/Kconfig
79695+++ b/mm/Kconfig
79696@@ -286,10 +286,10 @@ config KSM
79697 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
79698
79699 config DEFAULT_MMAP_MIN_ADDR
79700- int "Low address space to protect from user allocation"
79701+ int "Low address space to protect from user allocation"
79702 depends on MMU
79703- default 4096
79704- help
79705+ default 65536
79706+ help
79707 This is the portion of low virtual memory which should be protected
79708 from userspace allocation. Keeping a user from writing to low pages
79709 can help reduce the impact of kernel NULL pointer bugs.
79710@@ -320,7 +320,7 @@ config MEMORY_FAILURE
79711
79712 config HWPOISON_INJECT
79713 tristate "HWPoison pages injector"
79714- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
79715+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
79716 select PROC_PAGE_MONITOR
79717
79718 config NOMMU_INITIAL_TRIM_EXCESS
79719diff --git a/mm/filemap.c b/mm/filemap.c
79720index 83efee7..3f99381 100644
79721--- a/mm/filemap.c
79722+++ b/mm/filemap.c
79723@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
79724 struct address_space *mapping = file->f_mapping;
79725
79726 if (!mapping->a_ops->readpage)
79727- return -ENOEXEC;
79728+ return -ENODEV;
79729 file_accessed(file);
79730 vma->vm_ops = &generic_file_vm_ops;
79731 return 0;
79732@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
79733 *pos = i_size_read(inode);
79734
79735 if (limit != RLIM_INFINITY) {
79736+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
79737 if (*pos >= limit) {
79738 send_sig(SIGXFSZ, current, 0);
79739 return -EFBIG;
79740diff --git a/mm/fremap.c b/mm/fremap.c
79741index a0aaf0e..20325c3 100644
79742--- a/mm/fremap.c
79743+++ b/mm/fremap.c
79744@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
79745 retry:
79746 vma = find_vma(mm, start);
79747
79748+#ifdef CONFIG_PAX_SEGMEXEC
79749+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
79750+ goto out;
79751+#endif
79752+
79753 /*
79754 * Make sure the vma is shared, that it supports prefaulting,
79755 * and that the remapped range is valid and fully within
79756diff --git a/mm/highmem.c b/mm/highmem.c
79757index b32b70c..e512eb0 100644
79758--- a/mm/highmem.c
79759+++ b/mm/highmem.c
79760@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
79761 * So no dangers, even with speculative execution.
79762 */
79763 page = pte_page(pkmap_page_table[i]);
79764+ pax_open_kernel();
79765 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
79766-
79767+ pax_close_kernel();
79768 set_page_address(page, NULL);
79769 need_flush = 1;
79770 }
79771@@ -198,9 +199,11 @@ start:
79772 }
79773 }
79774 vaddr = PKMAP_ADDR(last_pkmap_nr);
79775+
79776+ pax_open_kernel();
79777 set_pte_at(&init_mm, vaddr,
79778 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
79779-
79780+ pax_close_kernel();
79781 pkmap_count[last_pkmap_nr] = 1;
79782 set_page_address(page, (void *)vaddr);
79783
79784diff --git a/mm/hugetlb.c b/mm/hugetlb.c
79785index 546db81..34830af 100644
79786--- a/mm/hugetlb.c
79787+++ b/mm/hugetlb.c
79788@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
79789 struct hstate *h = &default_hstate;
79790 unsigned long tmp;
79791 int ret;
79792+ ctl_table_no_const hugetlb_table;
79793
79794 tmp = h->max_huge_pages;
79795
79796 if (write && h->order >= MAX_ORDER)
79797 return -EINVAL;
79798
79799- table->data = &tmp;
79800- table->maxlen = sizeof(unsigned long);
79801- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79802+ hugetlb_table = *table;
79803+ hugetlb_table.data = &tmp;
79804+ hugetlb_table.maxlen = sizeof(unsigned long);
79805+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79806 if (ret)
79807 goto out;
79808
79809@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
79810 struct hstate *h = &default_hstate;
79811 unsigned long tmp;
79812 int ret;
79813+ ctl_table_no_const hugetlb_table;
79814
79815 tmp = h->nr_overcommit_huge_pages;
79816
79817 if (write && h->order >= MAX_ORDER)
79818 return -EINVAL;
79819
79820- table->data = &tmp;
79821- table->maxlen = sizeof(unsigned long);
79822- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79823+ hugetlb_table = *table;
79824+ hugetlb_table.data = &tmp;
79825+ hugetlb_table.maxlen = sizeof(unsigned long);
79826+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79827 if (ret)
79828 goto out;
79829
79830@@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
79831 return 1;
79832 }
79833
79834+#ifdef CONFIG_PAX_SEGMEXEC
79835+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
79836+{
79837+ struct mm_struct *mm = vma->vm_mm;
79838+ struct vm_area_struct *vma_m;
79839+ unsigned long address_m;
79840+ pte_t *ptep_m;
79841+
79842+ vma_m = pax_find_mirror_vma(vma);
79843+ if (!vma_m)
79844+ return;
79845+
79846+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79847+ address_m = address + SEGMEXEC_TASK_SIZE;
79848+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
79849+ get_page(page_m);
79850+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
79851+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
79852+}
79853+#endif
79854+
79855 /*
79856 * Hugetlb_cow() should be called with page lock of the original hugepage held.
79857 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
79858@@ -2629,6 +2654,11 @@ retry_avoidcopy:
79859 make_huge_pte(vma, new_page, 1));
79860 page_remove_rmap(old_page);
79861 hugepage_add_new_anon_rmap(new_page, vma, address);
79862+
79863+#ifdef CONFIG_PAX_SEGMEXEC
79864+ pax_mirror_huge_pte(vma, address, new_page);
79865+#endif
79866+
79867 /* Make the old page be freed below */
79868 new_page = old_page;
79869 }
79870@@ -2788,6 +2818,10 @@ retry:
79871 && (vma->vm_flags & VM_SHARED)));
79872 set_huge_pte_at(mm, address, ptep, new_pte);
79873
79874+#ifdef CONFIG_PAX_SEGMEXEC
79875+ pax_mirror_huge_pte(vma, address, page);
79876+#endif
79877+
79878 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
79879 /* Optimization, do the COW without a second fault */
79880 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
79881@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79882 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
79883 struct hstate *h = hstate_vma(vma);
79884
79885+#ifdef CONFIG_PAX_SEGMEXEC
79886+ struct vm_area_struct *vma_m;
79887+#endif
79888+
79889 address &= huge_page_mask(h);
79890
79891 ptep = huge_pte_offset(mm, address);
79892@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79893 VM_FAULT_SET_HINDEX(hstate_index(h));
79894 }
79895
79896+#ifdef CONFIG_PAX_SEGMEXEC
79897+ vma_m = pax_find_mirror_vma(vma);
79898+ if (vma_m) {
79899+ unsigned long address_m;
79900+
79901+ if (vma->vm_start > vma_m->vm_start) {
79902+ address_m = address;
79903+ address -= SEGMEXEC_TASK_SIZE;
79904+ vma = vma_m;
79905+ h = hstate_vma(vma);
79906+ } else
79907+ address_m = address + SEGMEXEC_TASK_SIZE;
79908+
79909+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
79910+ return VM_FAULT_OOM;
79911+ address_m &= HPAGE_MASK;
79912+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
79913+ }
79914+#endif
79915+
79916 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
79917 if (!ptep)
79918 return VM_FAULT_OOM;
79919diff --git a/mm/internal.h b/mm/internal.h
79920index 9ba2110..eaf0674 100644
79921--- a/mm/internal.h
79922+++ b/mm/internal.h
79923@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
79924 * in mm/page_alloc.c
79925 */
79926 extern void __free_pages_bootmem(struct page *page, unsigned int order);
79927+extern void free_compound_page(struct page *page);
79928 extern void prep_compound_page(struct page *page, unsigned long order);
79929 #ifdef CONFIG_MEMORY_FAILURE
79930 extern bool is_free_buddy_page(struct page *page);
79931diff --git a/mm/kmemleak.c b/mm/kmemleak.c
79932index 752a705..6c3102e 100644
79933--- a/mm/kmemleak.c
79934+++ b/mm/kmemleak.c
79935@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
79936
79937 for (i = 0; i < object->trace_len; i++) {
79938 void *ptr = (void *)object->trace[i];
79939- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
79940+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
79941 }
79942 }
79943
79944@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
79945 return -ENOMEM;
79946 }
79947
79948- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79949+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79950 &kmemleak_fops);
79951 if (!dentry)
79952 pr_warning("Failed to create the debugfs kmemleak file\n");
79953diff --git a/mm/maccess.c b/mm/maccess.c
79954index d53adf9..03a24bf 100644
79955--- a/mm/maccess.c
79956+++ b/mm/maccess.c
79957@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79958 set_fs(KERNEL_DS);
79959 pagefault_disable();
79960 ret = __copy_from_user_inatomic(dst,
79961- (__force const void __user *)src, size);
79962+ (const void __force_user *)src, size);
79963 pagefault_enable();
79964 set_fs(old_fs);
79965
79966@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
79967
79968 set_fs(KERNEL_DS);
79969 pagefault_disable();
79970- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
79971+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
79972 pagefault_enable();
79973 set_fs(old_fs);
79974
79975diff --git a/mm/madvise.c b/mm/madvise.c
79976index 03dfa5c..b032917 100644
79977--- a/mm/madvise.c
79978+++ b/mm/madvise.c
79979@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
79980 pgoff_t pgoff;
79981 unsigned long new_flags = vma->vm_flags;
79982
79983+#ifdef CONFIG_PAX_SEGMEXEC
79984+ struct vm_area_struct *vma_m;
79985+#endif
79986+
79987 switch (behavior) {
79988 case MADV_NORMAL:
79989 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
79990@@ -123,6 +127,13 @@ success:
79991 /*
79992 * vm_flags is protected by the mmap_sem held in write mode.
79993 */
79994+
79995+#ifdef CONFIG_PAX_SEGMEXEC
79996+ vma_m = pax_find_mirror_vma(vma);
79997+ if (vma_m)
79998+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
79999+#endif
80000+
80001 vma->vm_flags = new_flags;
80002
80003 out:
80004@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80005 struct vm_area_struct ** prev,
80006 unsigned long start, unsigned long end)
80007 {
80008+
80009+#ifdef CONFIG_PAX_SEGMEXEC
80010+ struct vm_area_struct *vma_m;
80011+#endif
80012+
80013 *prev = vma;
80014 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
80015 return -EINVAL;
80016@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80017 zap_page_range(vma, start, end - start, &details);
80018 } else
80019 zap_page_range(vma, start, end - start, NULL);
80020+
80021+#ifdef CONFIG_PAX_SEGMEXEC
80022+ vma_m = pax_find_mirror_vma(vma);
80023+ if (vma_m) {
80024+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
80025+ struct zap_details details = {
80026+ .nonlinear_vma = vma_m,
80027+ .last_index = ULONG_MAX,
80028+ };
80029+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
80030+ } else
80031+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
80032+ }
80033+#endif
80034+
80035 return 0;
80036 }
80037
80038@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
80039 if (end < start)
80040 goto out;
80041
80042+#ifdef CONFIG_PAX_SEGMEXEC
80043+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
80044+ if (end > SEGMEXEC_TASK_SIZE)
80045+ goto out;
80046+ } else
80047+#endif
80048+
80049+ if (end > TASK_SIZE)
80050+ goto out;
80051+
80052 error = 0;
80053 if (end == start)
80054 goto out;
80055diff --git a/mm/memory-failure.c b/mm/memory-failure.c
80056index c6e4dd3..1f41988 100644
80057--- a/mm/memory-failure.c
80058+++ b/mm/memory-failure.c
80059@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
80060
80061 int sysctl_memory_failure_recovery __read_mostly = 1;
80062
80063-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
80064+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
80065
80066 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
80067
80068@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
80069 pfn, t->comm, t->pid);
80070 si.si_signo = SIGBUS;
80071 si.si_errno = 0;
80072- si.si_addr = (void *)addr;
80073+ si.si_addr = (void __user *)addr;
80074 #ifdef __ARCH_SI_TRAPNO
80075 si.si_trapno = trapno;
80076 #endif
80077@@ -760,7 +760,7 @@ static struct page_state {
80078 unsigned long res;
80079 char *msg;
80080 int (*action)(struct page *p, unsigned long pfn);
80081-} error_states[] = {
80082+} __do_const error_states[] = {
80083 { reserved, reserved, "reserved kernel", me_kernel },
80084 /*
80085 * free pages are specially detected outside this table:
80086@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80087 }
80088
80089 nr_pages = 1 << compound_trans_order(hpage);
80090- atomic_long_add(nr_pages, &mce_bad_pages);
80091+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
80092
80093 /*
80094 * We need/can do nothing about count=0 pages.
80095@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80096 if (!PageHWPoison(hpage)
80097 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
80098 || (p != hpage && TestSetPageHWPoison(hpage))) {
80099- atomic_long_sub(nr_pages, &mce_bad_pages);
80100+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80101 return 0;
80102 }
80103 set_page_hwpoison_huge_page(hpage);
80104@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80105 }
80106 if (hwpoison_filter(p)) {
80107 if (TestClearPageHWPoison(p))
80108- atomic_long_sub(nr_pages, &mce_bad_pages);
80109+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80110 unlock_page(hpage);
80111 put_page(hpage);
80112 return 0;
80113@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
80114 return 0;
80115 }
80116 if (TestClearPageHWPoison(p))
80117- atomic_long_sub(nr_pages, &mce_bad_pages);
80118+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80119 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
80120 return 0;
80121 }
80122@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
80123 */
80124 if (TestClearPageHWPoison(page)) {
80125 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
80126- atomic_long_sub(nr_pages, &mce_bad_pages);
80127+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80128 freeit = 1;
80129 if (PageHuge(page))
80130 clear_page_hwpoison_huge_page(page);
80131@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
80132 }
80133 done:
80134 if (!PageHWPoison(hpage))
80135- atomic_long_add(1 << compound_trans_order(hpage),
80136+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80137 &mce_bad_pages);
80138 set_page_hwpoison_huge_page(hpage);
80139 dequeue_hwpoisoned_huge_page(hpage);
80140@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
80141 return ret;
80142
80143 done:
80144- atomic_long_add(1, &mce_bad_pages);
80145+ atomic_long_add_unchecked(1, &mce_bad_pages);
80146 SetPageHWPoison(page);
80147 /* keep elevated page count for bad page */
80148 return ret;
80149diff --git a/mm/memory.c b/mm/memory.c
80150index bb1369f..efb96b5 100644
80151--- a/mm/memory.c
80152+++ b/mm/memory.c
80153@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80154 free_pte_range(tlb, pmd, addr);
80155 } while (pmd++, addr = next, addr != end);
80156
80157+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
80158 start &= PUD_MASK;
80159 if (start < floor)
80160 return;
80161@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80162 pmd = pmd_offset(pud, start);
80163 pud_clear(pud);
80164 pmd_free_tlb(tlb, pmd, start);
80165+#endif
80166+
80167 }
80168
80169 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80170@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80171 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
80172 } while (pud++, addr = next, addr != end);
80173
80174+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
80175 start &= PGDIR_MASK;
80176 if (start < floor)
80177 return;
80178@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80179 pud = pud_offset(pgd, start);
80180 pgd_clear(pgd);
80181 pud_free_tlb(tlb, pud, start);
80182+#endif
80183+
80184 }
80185
80186 /*
80187@@ -1618,12 +1624,6 @@ no_page_table:
80188 return page;
80189 }
80190
80191-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
80192-{
80193- return stack_guard_page_start(vma, addr) ||
80194- stack_guard_page_end(vma, addr+PAGE_SIZE);
80195-}
80196-
80197 /**
80198 * __get_user_pages() - pin user pages in memory
80199 * @tsk: task_struct of target task
80200@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80201
80202 i = 0;
80203
80204- do {
80205+ while (nr_pages) {
80206 struct vm_area_struct *vma;
80207
80208- vma = find_extend_vma(mm, start);
80209+ vma = find_vma(mm, start);
80210 if (!vma && in_gate_area(mm, start)) {
80211 unsigned long pg = start & PAGE_MASK;
80212 pgd_t *pgd;
80213@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80214 goto next_page;
80215 }
80216
80217- if (!vma ||
80218+ if (!vma || start < vma->vm_start ||
80219 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
80220 !(vm_flags & vma->vm_flags))
80221 return i ? : -EFAULT;
80222@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80223 int ret;
80224 unsigned int fault_flags = 0;
80225
80226- /* For mlock, just skip the stack guard page. */
80227- if (foll_flags & FOLL_MLOCK) {
80228- if (stack_guard_page(vma, start))
80229- goto next_page;
80230- }
80231 if (foll_flags & FOLL_WRITE)
80232 fault_flags |= FAULT_FLAG_WRITE;
80233 if (nonblocking)
80234@@ -1865,7 +1860,7 @@ next_page:
80235 start += PAGE_SIZE;
80236 nr_pages--;
80237 } while (nr_pages && start < vma->vm_end);
80238- } while (nr_pages);
80239+ }
80240 return i;
80241 }
80242 EXPORT_SYMBOL(__get_user_pages);
80243@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
80244 page_add_file_rmap(page);
80245 set_pte_at(mm, addr, pte, mk_pte(page, prot));
80246
80247+#ifdef CONFIG_PAX_SEGMEXEC
80248+ pax_mirror_file_pte(vma, addr, page, ptl);
80249+#endif
80250+
80251 retval = 0;
80252 pte_unmap_unlock(pte, ptl);
80253 return retval;
80254@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
80255 if (!page_count(page))
80256 return -EINVAL;
80257 if (!(vma->vm_flags & VM_MIXEDMAP)) {
80258+
80259+#ifdef CONFIG_PAX_SEGMEXEC
80260+ struct vm_area_struct *vma_m;
80261+#endif
80262+
80263 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
80264 BUG_ON(vma->vm_flags & VM_PFNMAP);
80265 vma->vm_flags |= VM_MIXEDMAP;
80266+
80267+#ifdef CONFIG_PAX_SEGMEXEC
80268+ vma_m = pax_find_mirror_vma(vma);
80269+ if (vma_m)
80270+ vma_m->vm_flags |= VM_MIXEDMAP;
80271+#endif
80272+
80273 }
80274 return insert_page(vma, addr, page, vma->vm_page_prot);
80275 }
80276@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
80277 unsigned long pfn)
80278 {
80279 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
80280+ BUG_ON(vma->vm_mirror);
80281
80282 if (addr < vma->vm_start || addr >= vma->vm_end)
80283 return -EFAULT;
80284@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
80285
80286 BUG_ON(pud_huge(*pud));
80287
80288- pmd = pmd_alloc(mm, pud, addr);
80289+ pmd = (mm == &init_mm) ?
80290+ pmd_alloc_kernel(mm, pud, addr) :
80291+ pmd_alloc(mm, pud, addr);
80292 if (!pmd)
80293 return -ENOMEM;
80294 do {
80295@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
80296 unsigned long next;
80297 int err;
80298
80299- pud = pud_alloc(mm, pgd, addr);
80300+ pud = (mm == &init_mm) ?
80301+ pud_alloc_kernel(mm, pgd, addr) :
80302+ pud_alloc(mm, pgd, addr);
80303 if (!pud)
80304 return -ENOMEM;
80305 do {
80306@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
80307 copy_user_highpage(dst, src, va, vma);
80308 }
80309
80310+#ifdef CONFIG_PAX_SEGMEXEC
80311+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
80312+{
80313+ struct mm_struct *mm = vma->vm_mm;
80314+ spinlock_t *ptl;
80315+ pte_t *pte, entry;
80316+
80317+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
80318+ entry = *pte;
80319+ if (!pte_present(entry)) {
80320+ if (!pte_none(entry)) {
80321+ BUG_ON(pte_file(entry));
80322+ free_swap_and_cache(pte_to_swp_entry(entry));
80323+ pte_clear_not_present_full(mm, address, pte, 0);
80324+ }
80325+ } else {
80326+ struct page *page;
80327+
80328+ flush_cache_page(vma, address, pte_pfn(entry));
80329+ entry = ptep_clear_flush(vma, address, pte);
80330+ BUG_ON(pte_dirty(entry));
80331+ page = vm_normal_page(vma, address, entry);
80332+ if (page) {
80333+ update_hiwater_rss(mm);
80334+ if (PageAnon(page))
80335+ dec_mm_counter_fast(mm, MM_ANONPAGES);
80336+ else
80337+ dec_mm_counter_fast(mm, MM_FILEPAGES);
80338+ page_remove_rmap(page);
80339+ page_cache_release(page);
80340+ }
80341+ }
80342+ pte_unmap_unlock(pte, ptl);
80343+}
80344+
80345+/* PaX: if vma is mirrored, synchronize the mirror's PTE
80346+ *
80347+ * the ptl of the lower mapped page is held on entry and is not released on exit
80348+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
80349+ */
80350+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80351+{
80352+ struct mm_struct *mm = vma->vm_mm;
80353+ unsigned long address_m;
80354+ spinlock_t *ptl_m;
80355+ struct vm_area_struct *vma_m;
80356+ pmd_t *pmd_m;
80357+ pte_t *pte_m, entry_m;
80358+
80359+ BUG_ON(!page_m || !PageAnon(page_m));
80360+
80361+ vma_m = pax_find_mirror_vma(vma);
80362+ if (!vma_m)
80363+ return;
80364+
80365+ BUG_ON(!PageLocked(page_m));
80366+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80367+ address_m = address + SEGMEXEC_TASK_SIZE;
80368+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80369+ pte_m = pte_offset_map(pmd_m, address_m);
80370+ ptl_m = pte_lockptr(mm, pmd_m);
80371+ if (ptl != ptl_m) {
80372+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80373+ if (!pte_none(*pte_m))
80374+ goto out;
80375+ }
80376+
80377+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80378+ page_cache_get(page_m);
80379+ page_add_anon_rmap(page_m, vma_m, address_m);
80380+ inc_mm_counter_fast(mm, MM_ANONPAGES);
80381+ set_pte_at(mm, address_m, pte_m, entry_m);
80382+ update_mmu_cache(vma_m, address_m, entry_m);
80383+out:
80384+ if (ptl != ptl_m)
80385+ spin_unlock(ptl_m);
80386+ pte_unmap(pte_m);
80387+ unlock_page(page_m);
80388+}
80389+
80390+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80391+{
80392+ struct mm_struct *mm = vma->vm_mm;
80393+ unsigned long address_m;
80394+ spinlock_t *ptl_m;
80395+ struct vm_area_struct *vma_m;
80396+ pmd_t *pmd_m;
80397+ pte_t *pte_m, entry_m;
80398+
80399+ BUG_ON(!page_m || PageAnon(page_m));
80400+
80401+ vma_m = pax_find_mirror_vma(vma);
80402+ if (!vma_m)
80403+ return;
80404+
80405+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80406+ address_m = address + SEGMEXEC_TASK_SIZE;
80407+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80408+ pte_m = pte_offset_map(pmd_m, address_m);
80409+ ptl_m = pte_lockptr(mm, pmd_m);
80410+ if (ptl != ptl_m) {
80411+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80412+ if (!pte_none(*pte_m))
80413+ goto out;
80414+ }
80415+
80416+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80417+ page_cache_get(page_m);
80418+ page_add_file_rmap(page_m);
80419+ inc_mm_counter_fast(mm, MM_FILEPAGES);
80420+ set_pte_at(mm, address_m, pte_m, entry_m);
80421+ update_mmu_cache(vma_m, address_m, entry_m);
80422+out:
80423+ if (ptl != ptl_m)
80424+ spin_unlock(ptl_m);
80425+ pte_unmap(pte_m);
80426+}
80427+
80428+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
80429+{
80430+ struct mm_struct *mm = vma->vm_mm;
80431+ unsigned long address_m;
80432+ spinlock_t *ptl_m;
80433+ struct vm_area_struct *vma_m;
80434+ pmd_t *pmd_m;
80435+ pte_t *pte_m, entry_m;
80436+
80437+ vma_m = pax_find_mirror_vma(vma);
80438+ if (!vma_m)
80439+ return;
80440+
80441+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80442+ address_m = address + SEGMEXEC_TASK_SIZE;
80443+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80444+ pte_m = pte_offset_map(pmd_m, address_m);
80445+ ptl_m = pte_lockptr(mm, pmd_m);
80446+ if (ptl != ptl_m) {
80447+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80448+ if (!pte_none(*pte_m))
80449+ goto out;
80450+ }
80451+
80452+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
80453+ set_pte_at(mm, address_m, pte_m, entry_m);
80454+out:
80455+ if (ptl != ptl_m)
80456+ spin_unlock(ptl_m);
80457+ pte_unmap(pte_m);
80458+}
80459+
80460+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
80461+{
80462+ struct page *page_m;
80463+ pte_t entry;
80464+
80465+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
80466+ goto out;
80467+
80468+ entry = *pte;
80469+ page_m = vm_normal_page(vma, address, entry);
80470+ if (!page_m)
80471+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
80472+ else if (PageAnon(page_m)) {
80473+ if (pax_find_mirror_vma(vma)) {
80474+ pte_unmap_unlock(pte, ptl);
80475+ lock_page(page_m);
80476+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
80477+ if (pte_same(entry, *pte))
80478+ pax_mirror_anon_pte(vma, address, page_m, ptl);
80479+ else
80480+ unlock_page(page_m);
80481+ }
80482+ } else
80483+ pax_mirror_file_pte(vma, address, page_m, ptl);
80484+
80485+out:
80486+ pte_unmap_unlock(pte, ptl);
80487+}
80488+#endif
80489+
80490 /*
80491 * This routine handles present pages, when users try to write
80492 * to a shared page. It is done by copying the page to a new address
80493@@ -2725,6 +2921,12 @@ gotten:
80494 */
80495 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80496 if (likely(pte_same(*page_table, orig_pte))) {
80497+
80498+#ifdef CONFIG_PAX_SEGMEXEC
80499+ if (pax_find_mirror_vma(vma))
80500+ BUG_ON(!trylock_page(new_page));
80501+#endif
80502+
80503 if (old_page) {
80504 if (!PageAnon(old_page)) {
80505 dec_mm_counter_fast(mm, MM_FILEPAGES);
80506@@ -2776,6 +2978,10 @@ gotten:
80507 page_remove_rmap(old_page);
80508 }
80509
80510+#ifdef CONFIG_PAX_SEGMEXEC
80511+ pax_mirror_anon_pte(vma, address, new_page, ptl);
80512+#endif
80513+
80514 /* Free the old page.. */
80515 new_page = old_page;
80516 ret |= VM_FAULT_WRITE;
80517@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80518 swap_free(entry);
80519 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
80520 try_to_free_swap(page);
80521+
80522+#ifdef CONFIG_PAX_SEGMEXEC
80523+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
80524+#endif
80525+
80526 unlock_page(page);
80527 if (swapcache) {
80528 /*
80529@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80530
80531 /* No need to invalidate - it was non-present before */
80532 update_mmu_cache(vma, address, page_table);
80533+
80534+#ifdef CONFIG_PAX_SEGMEXEC
80535+ pax_mirror_anon_pte(vma, address, page, ptl);
80536+#endif
80537+
80538 unlock:
80539 pte_unmap_unlock(page_table, ptl);
80540 out:
80541@@ -3093,40 +3309,6 @@ out_release:
80542 }
80543
80544 /*
80545- * This is like a special single-page "expand_{down|up}wards()",
80546- * except we must first make sure that 'address{-|+}PAGE_SIZE'
80547- * doesn't hit another vma.
80548- */
80549-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
80550-{
80551- address &= PAGE_MASK;
80552- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
80553- struct vm_area_struct *prev = vma->vm_prev;
80554-
80555- /*
80556- * Is there a mapping abutting this one below?
80557- *
80558- * That's only ok if it's the same stack mapping
80559- * that has gotten split..
80560- */
80561- if (prev && prev->vm_end == address)
80562- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
80563-
80564- expand_downwards(vma, address - PAGE_SIZE);
80565- }
80566- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
80567- struct vm_area_struct *next = vma->vm_next;
80568-
80569- /* As VM_GROWSDOWN but s/below/above/ */
80570- if (next && next->vm_start == address + PAGE_SIZE)
80571- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
80572-
80573- expand_upwards(vma, address + PAGE_SIZE);
80574- }
80575- return 0;
80576-}
80577-
80578-/*
80579 * We enter with non-exclusive mmap_sem (to exclude vma changes,
80580 * but allow concurrent faults), and pte mapped but not yet locked.
80581 * We return with mmap_sem still held, but pte unmapped and unlocked.
80582@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80583 unsigned long address, pte_t *page_table, pmd_t *pmd,
80584 unsigned int flags)
80585 {
80586- struct page *page;
80587+ struct page *page = NULL;
80588 spinlock_t *ptl;
80589 pte_t entry;
80590
80591- pte_unmap(page_table);
80592-
80593- /* Check if we need to add a guard page to the stack */
80594- if (check_stack_guard_page(vma, address) < 0)
80595- return VM_FAULT_SIGBUS;
80596-
80597- /* Use the zero-page for reads */
80598 if (!(flags & FAULT_FLAG_WRITE)) {
80599 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
80600 vma->vm_page_prot));
80601- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80602+ ptl = pte_lockptr(mm, pmd);
80603+ spin_lock(ptl);
80604 if (!pte_none(*page_table))
80605 goto unlock;
80606 goto setpte;
80607 }
80608
80609 /* Allocate our own private page. */
80610+ pte_unmap(page_table);
80611+
80612 if (unlikely(anon_vma_prepare(vma)))
80613 goto oom;
80614 page = alloc_zeroed_user_highpage_movable(vma, address);
80615@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80616 if (!pte_none(*page_table))
80617 goto release;
80618
80619+#ifdef CONFIG_PAX_SEGMEXEC
80620+ if (pax_find_mirror_vma(vma))
80621+ BUG_ON(!trylock_page(page));
80622+#endif
80623+
80624 inc_mm_counter_fast(mm, MM_ANONPAGES);
80625 page_add_new_anon_rmap(page, vma, address);
80626 setpte:
80627@@ -3181,6 +3364,12 @@ setpte:
80628
80629 /* No need to invalidate - it was non-present before */
80630 update_mmu_cache(vma, address, page_table);
80631+
80632+#ifdef CONFIG_PAX_SEGMEXEC
80633+ if (page)
80634+ pax_mirror_anon_pte(vma, address, page, ptl);
80635+#endif
80636+
80637 unlock:
80638 pte_unmap_unlock(page_table, ptl);
80639 return 0;
80640@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80641 */
80642 /* Only go through if we didn't race with anybody else... */
80643 if (likely(pte_same(*page_table, orig_pte))) {
80644+
80645+#ifdef CONFIG_PAX_SEGMEXEC
80646+ if (anon && pax_find_mirror_vma(vma))
80647+ BUG_ON(!trylock_page(page));
80648+#endif
80649+
80650 flush_icache_page(vma, page);
80651 entry = mk_pte(page, vma->vm_page_prot);
80652 if (flags & FAULT_FLAG_WRITE)
80653@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80654
80655 /* no need to invalidate: a not-present page won't be cached */
80656 update_mmu_cache(vma, address, page_table);
80657+
80658+#ifdef CONFIG_PAX_SEGMEXEC
80659+ if (anon)
80660+ pax_mirror_anon_pte(vma, address, page, ptl);
80661+ else
80662+ pax_mirror_file_pte(vma, address, page, ptl);
80663+#endif
80664+
80665 } else {
80666 if (cow_page)
80667 mem_cgroup_uncharge_page(cow_page);
80668@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
80669 if (flags & FAULT_FLAG_WRITE)
80670 flush_tlb_fix_spurious_fault(vma, address);
80671 }
80672+
80673+#ifdef CONFIG_PAX_SEGMEXEC
80674+ pax_mirror_pte(vma, address, pte, pmd, ptl);
80675+ return 0;
80676+#endif
80677+
80678 unlock:
80679 pte_unmap_unlock(pte, ptl);
80680 return 0;
80681@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80682 pmd_t *pmd;
80683 pte_t *pte;
80684
80685+#ifdef CONFIG_PAX_SEGMEXEC
80686+ struct vm_area_struct *vma_m;
80687+#endif
80688+
80689 __set_current_state(TASK_RUNNING);
80690
80691 count_vm_event(PGFAULT);
80692@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80693 if (unlikely(is_vm_hugetlb_page(vma)))
80694 return hugetlb_fault(mm, vma, address, flags);
80695
80696+#ifdef CONFIG_PAX_SEGMEXEC
80697+ vma_m = pax_find_mirror_vma(vma);
80698+ if (vma_m) {
80699+ unsigned long address_m;
80700+ pgd_t *pgd_m;
80701+ pud_t *pud_m;
80702+ pmd_t *pmd_m;
80703+
80704+ if (vma->vm_start > vma_m->vm_start) {
80705+ address_m = address;
80706+ address -= SEGMEXEC_TASK_SIZE;
80707+ vma = vma_m;
80708+ } else
80709+ address_m = address + SEGMEXEC_TASK_SIZE;
80710+
80711+ pgd_m = pgd_offset(mm, address_m);
80712+ pud_m = pud_alloc(mm, pgd_m, address_m);
80713+ if (!pud_m)
80714+ return VM_FAULT_OOM;
80715+ pmd_m = pmd_alloc(mm, pud_m, address_m);
80716+ if (!pmd_m)
80717+ return VM_FAULT_OOM;
80718+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
80719+ return VM_FAULT_OOM;
80720+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
80721+ }
80722+#endif
80723+
80724 retry:
80725 pgd = pgd_offset(mm, address);
80726 pud = pud_alloc(mm, pgd, address);
80727@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80728 spin_unlock(&mm->page_table_lock);
80729 return 0;
80730 }
80731+
80732+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80733+{
80734+ pud_t *new = pud_alloc_one(mm, address);
80735+ if (!new)
80736+ return -ENOMEM;
80737+
80738+ smp_wmb(); /* See comment in __pte_alloc */
80739+
80740+ spin_lock(&mm->page_table_lock);
80741+ if (pgd_present(*pgd)) /* Another has populated it */
80742+ pud_free(mm, new);
80743+ else
80744+ pgd_populate_kernel(mm, pgd, new);
80745+ spin_unlock(&mm->page_table_lock);
80746+ return 0;
80747+}
80748 #endif /* __PAGETABLE_PUD_FOLDED */
80749
80750 #ifndef __PAGETABLE_PMD_FOLDED
80751@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80752 spin_unlock(&mm->page_table_lock);
80753 return 0;
80754 }
80755+
80756+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80757+{
80758+ pmd_t *new = pmd_alloc_one(mm, address);
80759+ if (!new)
80760+ return -ENOMEM;
80761+
80762+ smp_wmb(); /* See comment in __pte_alloc */
80763+
80764+ spin_lock(&mm->page_table_lock);
80765+#ifndef __ARCH_HAS_4LEVEL_HACK
80766+ if (pud_present(*pud)) /* Another has populated it */
80767+ pmd_free(mm, new);
80768+ else
80769+ pud_populate_kernel(mm, pud, new);
80770+#else
80771+ if (pgd_present(*pud)) /* Another has populated it */
80772+ pmd_free(mm, new);
80773+ else
80774+ pgd_populate_kernel(mm, pud, new);
80775+#endif /* __ARCH_HAS_4LEVEL_HACK */
80776+ spin_unlock(&mm->page_table_lock);
80777+ return 0;
80778+}
80779 #endif /* __PAGETABLE_PMD_FOLDED */
80780
80781 int make_pages_present(unsigned long addr, unsigned long end)
80782@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
80783 gate_vma.vm_start = FIXADDR_USER_START;
80784 gate_vma.vm_end = FIXADDR_USER_END;
80785 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
80786- gate_vma.vm_page_prot = __P101;
80787+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
80788
80789 return 0;
80790 }
80791diff --git a/mm/mempolicy.c b/mm/mempolicy.c
80792index 3df6d12..a11056a 100644
80793--- a/mm/mempolicy.c
80794+++ b/mm/mempolicy.c
80795@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80796 unsigned long vmstart;
80797 unsigned long vmend;
80798
80799+#ifdef CONFIG_PAX_SEGMEXEC
80800+ struct vm_area_struct *vma_m;
80801+#endif
80802+
80803 vma = find_vma(mm, start);
80804 if (!vma || vma->vm_start > start)
80805 return -EFAULT;
80806@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80807 if (err)
80808 goto out;
80809 }
80810+
80811 err = vma_replace_policy(vma, new_pol);
80812 if (err)
80813 goto out;
80814+
80815+#ifdef CONFIG_PAX_SEGMEXEC
80816+ vma_m = pax_find_mirror_vma(vma);
80817+ if (vma_m) {
80818+ err = vma_replace_policy(vma_m, new_pol);
80819+ if (err)
80820+ goto out;
80821+ }
80822+#endif
80823+
80824 }
80825
80826 out:
80827@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
80828
80829 if (end < start)
80830 return -EINVAL;
80831+
80832+#ifdef CONFIG_PAX_SEGMEXEC
80833+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80834+ if (end > SEGMEXEC_TASK_SIZE)
80835+ return -EINVAL;
80836+ } else
80837+#endif
80838+
80839+ if (end > TASK_SIZE)
80840+ return -EINVAL;
80841+
80842 if (end == start)
80843 return 0;
80844
80845@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80846 */
80847 tcred = __task_cred(task);
80848 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80849- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80850- !capable(CAP_SYS_NICE)) {
80851+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80852 rcu_read_unlock();
80853 err = -EPERM;
80854 goto out_put;
80855@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80856 goto out;
80857 }
80858
80859+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80860+ if (mm != current->mm &&
80861+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
80862+ mmput(mm);
80863+ err = -EPERM;
80864+ goto out;
80865+ }
80866+#endif
80867+
80868 err = do_migrate_pages(mm, old, new,
80869 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
80870
80871diff --git a/mm/migrate.c b/mm/migrate.c
80872index 2fd8b4a..d70358f 100644
80873--- a/mm/migrate.c
80874+++ b/mm/migrate.c
80875@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
80876 */
80877 tcred = __task_cred(task);
80878 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80879- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80880- !capable(CAP_SYS_NICE)) {
80881+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80882 rcu_read_unlock();
80883 err = -EPERM;
80884 goto out;
80885diff --git a/mm/mlock.c b/mm/mlock.c
80886index c9bd528..da8d069 100644
80887--- a/mm/mlock.c
80888+++ b/mm/mlock.c
80889@@ -13,6 +13,7 @@
80890 #include <linux/pagemap.h>
80891 #include <linux/mempolicy.h>
80892 #include <linux/syscalls.h>
80893+#include <linux/security.h>
80894 #include <linux/sched.h>
80895 #include <linux/export.h>
80896 #include <linux/rmap.h>
80897@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
80898 {
80899 unsigned long nstart, end, tmp;
80900 struct vm_area_struct * vma, * prev;
80901- int error;
80902+ int error = 0;
80903
80904 VM_BUG_ON(start & ~PAGE_MASK);
80905 VM_BUG_ON(len != PAGE_ALIGN(len));
80906@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
80907 return -EINVAL;
80908 if (end == start)
80909 return 0;
80910+ if (end > TASK_SIZE)
80911+ return -EINVAL;
80912+
80913 vma = find_vma(current->mm, start);
80914 if (!vma || vma->vm_start > start)
80915 return -ENOMEM;
80916@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
80917 for (nstart = start ; ; ) {
80918 vm_flags_t newflags;
80919
80920+#ifdef CONFIG_PAX_SEGMEXEC
80921+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80922+ break;
80923+#endif
80924+
80925 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
80926
80927 newflags = vma->vm_flags | VM_LOCKED;
80928@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
80929 lock_limit >>= PAGE_SHIFT;
80930
80931 /* check against resource limits */
80932+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
80933 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
80934 error = do_mlock(start, len, 1);
80935 up_write(&current->mm->mmap_sem);
80936@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
80937 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
80938 vm_flags_t newflags;
80939
80940+#ifdef CONFIG_PAX_SEGMEXEC
80941+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80942+ break;
80943+#endif
80944+
80945+ BUG_ON(vma->vm_end > TASK_SIZE);
80946 newflags = vma->vm_flags | VM_LOCKED;
80947 if (!(flags & MCL_CURRENT))
80948 newflags &= ~VM_LOCKED;
80949@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80950 lock_limit >>= PAGE_SHIFT;
80951
80952 ret = -ENOMEM;
80953+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80954 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80955 capable(CAP_IPC_LOCK))
80956 ret = do_mlockall(flags);
80957diff --git a/mm/mmap.c b/mm/mmap.c
80958index 8832b87..4bbb1b2 100644
80959--- a/mm/mmap.c
80960+++ b/mm/mmap.c
80961@@ -32,6 +32,7 @@
80962 #include <linux/khugepaged.h>
80963 #include <linux/uprobes.h>
80964 #include <linux/rbtree_augmented.h>
80965+#include <linux/random.h>
80966
80967 #include <asm/uaccess.h>
80968 #include <asm/cacheflush.h>
80969@@ -48,6 +49,16 @@
80970 #define arch_rebalance_pgtables(addr, len) (addr)
80971 #endif
80972
80973+static inline void verify_mm_writelocked(struct mm_struct *mm)
80974+{
80975+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
80976+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80977+ up_read(&mm->mmap_sem);
80978+ BUG();
80979+ }
80980+#endif
80981+}
80982+
80983 static void unmap_region(struct mm_struct *mm,
80984 struct vm_area_struct *vma, struct vm_area_struct *prev,
80985 unsigned long start, unsigned long end);
80986@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
80987 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
80988 *
80989 */
80990-pgprot_t protection_map[16] = {
80991+pgprot_t protection_map[16] __read_only = {
80992 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
80993 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
80994 };
80995
80996-pgprot_t vm_get_page_prot(unsigned long vm_flags)
80997+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80998 {
80999- return __pgprot(pgprot_val(protection_map[vm_flags &
81000+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
81001 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
81002 pgprot_val(arch_vm_get_page_prot(vm_flags)));
81003+
81004+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81005+ if (!(__supported_pte_mask & _PAGE_NX) &&
81006+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
81007+ (vm_flags & (VM_READ | VM_WRITE)))
81008+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
81009+#endif
81010+
81011+ return prot;
81012 }
81013 EXPORT_SYMBOL(vm_get_page_prot);
81014
81015 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
81016 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
81017 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
81018+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
81019 /*
81020 * Make sure vm_committed_as in one cacheline and not cacheline shared with
81021 * other variables. It can be updated by several CPUs frequently.
81022@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
81023 struct vm_area_struct *next = vma->vm_next;
81024
81025 might_sleep();
81026+ BUG_ON(vma->vm_mirror);
81027 if (vma->vm_ops && vma->vm_ops->close)
81028 vma->vm_ops->close(vma);
81029 if (vma->vm_file)
81030@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
81031 * not page aligned -Ram Gupta
81032 */
81033 rlim = rlimit(RLIMIT_DATA);
81034+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
81035 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
81036 (mm->end_data - mm->start_data) > rlim)
81037 goto out;
81038@@ -888,6 +911,12 @@ static int
81039 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
81040 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81041 {
81042+
81043+#ifdef CONFIG_PAX_SEGMEXEC
81044+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
81045+ return 0;
81046+#endif
81047+
81048 if (is_mergeable_vma(vma, file, vm_flags) &&
81049 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81050 if (vma->vm_pgoff == vm_pgoff)
81051@@ -907,6 +936,12 @@ static int
81052 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81053 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81054 {
81055+
81056+#ifdef CONFIG_PAX_SEGMEXEC
81057+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
81058+ return 0;
81059+#endif
81060+
81061 if (is_mergeable_vma(vma, file, vm_flags) &&
81062 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81063 pgoff_t vm_pglen;
81064@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81065 struct vm_area_struct *vma_merge(struct mm_struct *mm,
81066 struct vm_area_struct *prev, unsigned long addr,
81067 unsigned long end, unsigned long vm_flags,
81068- struct anon_vma *anon_vma, struct file *file,
81069+ struct anon_vma *anon_vma, struct file *file,
81070 pgoff_t pgoff, struct mempolicy *policy)
81071 {
81072 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
81073 struct vm_area_struct *area, *next;
81074 int err;
81075
81076+#ifdef CONFIG_PAX_SEGMEXEC
81077+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
81078+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
81079+
81080+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
81081+#endif
81082+
81083 /*
81084 * We later require that vma->vm_flags == vm_flags,
81085 * so this tests vma->vm_flags & VM_SPECIAL, too.
81086@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81087 if (next && next->vm_end == end) /* cases 6, 7, 8 */
81088 next = next->vm_next;
81089
81090+#ifdef CONFIG_PAX_SEGMEXEC
81091+ if (prev)
81092+ prev_m = pax_find_mirror_vma(prev);
81093+ if (area)
81094+ area_m = pax_find_mirror_vma(area);
81095+ if (next)
81096+ next_m = pax_find_mirror_vma(next);
81097+#endif
81098+
81099 /*
81100 * Can it merge with the predecessor?
81101 */
81102@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81103 /* cases 1, 6 */
81104 err = vma_adjust(prev, prev->vm_start,
81105 next->vm_end, prev->vm_pgoff, NULL);
81106- } else /* cases 2, 5, 7 */
81107+
81108+#ifdef CONFIG_PAX_SEGMEXEC
81109+ if (!err && prev_m)
81110+ err = vma_adjust(prev_m, prev_m->vm_start,
81111+ next_m->vm_end, prev_m->vm_pgoff, NULL);
81112+#endif
81113+
81114+ } else { /* cases 2, 5, 7 */
81115 err = vma_adjust(prev, prev->vm_start,
81116 end, prev->vm_pgoff, NULL);
81117+
81118+#ifdef CONFIG_PAX_SEGMEXEC
81119+ if (!err && prev_m)
81120+ err = vma_adjust(prev_m, prev_m->vm_start,
81121+ end_m, prev_m->vm_pgoff, NULL);
81122+#endif
81123+
81124+ }
81125 if (err)
81126 return NULL;
81127 khugepaged_enter_vma_merge(prev);
81128@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81129 mpol_equal(policy, vma_policy(next)) &&
81130 can_vma_merge_before(next, vm_flags,
81131 anon_vma, file, pgoff+pglen)) {
81132- if (prev && addr < prev->vm_end) /* case 4 */
81133+ if (prev && addr < prev->vm_end) { /* case 4 */
81134 err = vma_adjust(prev, prev->vm_start,
81135 addr, prev->vm_pgoff, NULL);
81136- else /* cases 3, 8 */
81137+
81138+#ifdef CONFIG_PAX_SEGMEXEC
81139+ if (!err && prev_m)
81140+ err = vma_adjust(prev_m, prev_m->vm_start,
81141+ addr_m, prev_m->vm_pgoff, NULL);
81142+#endif
81143+
81144+ } else { /* cases 3, 8 */
81145 err = vma_adjust(area, addr, next->vm_end,
81146 next->vm_pgoff - pglen, NULL);
81147+
81148+#ifdef CONFIG_PAX_SEGMEXEC
81149+ if (!err && area_m)
81150+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
81151+ next_m->vm_pgoff - pglen, NULL);
81152+#endif
81153+
81154+ }
81155 if (err)
81156 return NULL;
81157 khugepaged_enter_vma_merge(area);
81158@@ -1120,8 +1201,10 @@ none:
81159 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81160 struct file *file, long pages)
81161 {
81162- const unsigned long stack_flags
81163- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
81164+
81165+#ifdef CONFIG_PAX_RANDMMAP
81166+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81167+#endif
81168
81169 mm->total_vm += pages;
81170
81171@@ -1129,7 +1212,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81172 mm->shared_vm += pages;
81173 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
81174 mm->exec_vm += pages;
81175- } else if (flags & stack_flags)
81176+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
81177 mm->stack_vm += pages;
81178 }
81179 #endif /* CONFIG_PROC_FS */
81180@@ -1165,7 +1248,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81181 * (the exception is when the underlying filesystem is noexec
81182 * mounted, in which case we dont add PROT_EXEC.)
81183 */
81184- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81185+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81186 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
81187 prot |= PROT_EXEC;
81188
81189@@ -1191,7 +1274,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81190 /* Obtain the address to map to. we verify (or select) it and ensure
81191 * that it represents a valid section of the address space.
81192 */
81193- addr = get_unmapped_area(file, addr, len, pgoff, flags);
81194+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
81195 if (addr & ~PAGE_MASK)
81196 return addr;
81197
81198@@ -1202,6 +1285,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81199 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
81200 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
81201
81202+#ifdef CONFIG_PAX_MPROTECT
81203+ if (mm->pax_flags & MF_PAX_MPROTECT) {
81204+#ifndef CONFIG_PAX_MPROTECT_COMPAT
81205+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
81206+ gr_log_rwxmmap(file);
81207+
81208+#ifdef CONFIG_PAX_EMUPLT
81209+ vm_flags &= ~VM_EXEC;
81210+#else
81211+ return -EPERM;
81212+#endif
81213+
81214+ }
81215+
81216+ if (!(vm_flags & VM_EXEC))
81217+ vm_flags &= ~VM_MAYEXEC;
81218+#else
81219+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81220+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81221+#endif
81222+ else
81223+ vm_flags &= ~VM_MAYWRITE;
81224+ }
81225+#endif
81226+
81227+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81228+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
81229+ vm_flags &= ~VM_PAGEEXEC;
81230+#endif
81231+
81232 if (flags & MAP_LOCKED)
81233 if (!can_do_mlock())
81234 return -EPERM;
81235@@ -1213,6 +1326,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81236 locked += mm->locked_vm;
81237 lock_limit = rlimit(RLIMIT_MEMLOCK);
81238 lock_limit >>= PAGE_SHIFT;
81239+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81240 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
81241 return -EAGAIN;
81242 }
81243@@ -1279,6 +1393,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81244 }
81245 }
81246
81247+ if (!gr_acl_handle_mmap(file, prot))
81248+ return -EACCES;
81249+
81250 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
81251 }
81252
81253@@ -1356,7 +1473,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
81254 vm_flags_t vm_flags = vma->vm_flags;
81255
81256 /* If it was private or non-writable, the write bit is already clear */
81257- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
81258+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
81259 return 0;
81260
81261 /* The backer wishes to know when pages are first written to? */
81262@@ -1405,16 +1522,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
81263 unsigned long charged = 0;
81264 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
81265
81266+#ifdef CONFIG_PAX_SEGMEXEC
81267+ struct vm_area_struct *vma_m = NULL;
81268+#endif
81269+
81270+ /*
81271+ * mm->mmap_sem is required to protect against another thread
81272+ * changing the mappings in case we sleep.
81273+ */
81274+ verify_mm_writelocked(mm);
81275+
81276 /* Clear old maps */
81277 error = -ENOMEM;
81278-munmap_back:
81279 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81280 if (do_munmap(mm, addr, len))
81281 return -ENOMEM;
81282- goto munmap_back;
81283+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81284 }
81285
81286 /* Check against address space limit. */
81287+
81288+#ifdef CONFIG_PAX_RANDMMAP
81289+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81290+#endif
81291+
81292 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81293 return -ENOMEM;
81294
81295@@ -1460,6 +1591,16 @@ munmap_back:
81296 goto unacct_error;
81297 }
81298
81299+#ifdef CONFIG_PAX_SEGMEXEC
81300+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
81301+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81302+ if (!vma_m) {
81303+ error = -ENOMEM;
81304+ goto free_vma;
81305+ }
81306+ }
81307+#endif
81308+
81309 vma->vm_mm = mm;
81310 vma->vm_start = addr;
81311 vma->vm_end = addr + len;
81312@@ -1484,6 +1625,13 @@ munmap_back:
81313 if (error)
81314 goto unmap_and_free_vma;
81315
81316+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81317+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
81318+ vma->vm_flags |= VM_PAGEEXEC;
81319+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81320+ }
81321+#endif
81322+
81323 /* Can addr have changed??
81324 *
81325 * Answer: Yes, several device drivers can do it in their
81326@@ -1522,6 +1670,11 @@ munmap_back:
81327 vma_link(mm, vma, prev, rb_link, rb_parent);
81328 file = vma->vm_file;
81329
81330+#ifdef CONFIG_PAX_SEGMEXEC
81331+ if (vma_m)
81332+ BUG_ON(pax_mirror_vma(vma_m, vma));
81333+#endif
81334+
81335 /* Once vma denies write, undo our temporary denial count */
81336 if (correct_wcount)
81337 atomic_inc(&inode->i_writecount);
81338@@ -1529,6 +1682,7 @@ out:
81339 perf_event_mmap(vma);
81340
81341 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
81342+ track_exec_limit(mm, addr, addr + len, vm_flags);
81343 if (vm_flags & VM_LOCKED) {
81344 if (!mlock_vma_pages_range(vma, addr, addr + len))
81345 mm->locked_vm += (len >> PAGE_SHIFT);
81346@@ -1550,6 +1704,12 @@ unmap_and_free_vma:
81347 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
81348 charged = 0;
81349 free_vma:
81350+
81351+#ifdef CONFIG_PAX_SEGMEXEC
81352+ if (vma_m)
81353+ kmem_cache_free(vm_area_cachep, vma_m);
81354+#endif
81355+
81356 kmem_cache_free(vm_area_cachep, vma);
81357 unacct_error:
81358 if (charged)
81359@@ -1557,6 +1717,62 @@ unacct_error:
81360 return error;
81361 }
81362
81363+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81364+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81365+{
81366+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
81367+ return (random32() & 0xFF) << PAGE_SHIFT;
81368+
81369+ return 0;
81370+}
81371+#endif
81372+
81373+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
81374+{
81375+ if (!vma) {
81376+#ifdef CONFIG_STACK_GROWSUP
81377+ if (addr > sysctl_heap_stack_gap)
81378+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
81379+ else
81380+ vma = find_vma(current->mm, 0);
81381+ if (vma && (vma->vm_flags & VM_GROWSUP))
81382+ return false;
81383+#endif
81384+ return true;
81385+ }
81386+
81387+ if (addr + len > vma->vm_start)
81388+ return false;
81389+
81390+ if (vma->vm_flags & VM_GROWSDOWN)
81391+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
81392+#ifdef CONFIG_STACK_GROWSUP
81393+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
81394+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
81395+#endif
81396+ else if (offset)
81397+ return offset <= vma->vm_start - addr - len;
81398+
81399+ return true;
81400+}
81401+
81402+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
81403+{
81404+ if (vma->vm_start < len)
81405+ return -ENOMEM;
81406+
81407+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
81408+ if (offset <= vma->vm_start - len)
81409+ return vma->vm_start - len - offset;
81410+ else
81411+ return -ENOMEM;
81412+ }
81413+
81414+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
81415+ return vma->vm_start - len - sysctl_heap_stack_gap;
81416+ return -ENOMEM;
81417+}
81418+
81419 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
81420 {
81421 /*
81422@@ -1776,6 +1992,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81423 struct mm_struct *mm = current->mm;
81424 struct vm_area_struct *vma;
81425 struct vm_unmapped_area_info info;
81426+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81427
81428 if (len > TASK_SIZE)
81429 return -ENOMEM;
81430@@ -1783,17 +2000,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81431 if (flags & MAP_FIXED)
81432 return addr;
81433
81434+#ifdef CONFIG_PAX_RANDMMAP
81435+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81436+#endif
81437+
81438 if (addr) {
81439 addr = PAGE_ALIGN(addr);
81440 vma = find_vma(mm, addr);
81441- if (TASK_SIZE - len >= addr &&
81442- (!vma || addr + len <= vma->vm_start))
81443+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81444 return addr;
81445 }
81446
81447 info.flags = 0;
81448 info.length = len;
81449 info.low_limit = TASK_UNMAPPED_BASE;
81450+
81451+#ifdef CONFIG_PAX_RANDMMAP
81452+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81453+ info.low_limit += mm->delta_mmap;
81454+#endif
81455+
81456 info.high_limit = TASK_SIZE;
81457 info.align_mask = 0;
81458 return vm_unmapped_area(&info);
81459@@ -1802,10 +2028,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81460
81461 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
81462 {
81463+
81464+#ifdef CONFIG_PAX_SEGMEXEC
81465+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81466+ return;
81467+#endif
81468+
81469 /*
81470 * Is this a new hole at the lowest possible address?
81471 */
81472- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
81473+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
81474 mm->free_area_cache = addr;
81475 }
81476
81477@@ -1823,6 +2055,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81478 struct mm_struct *mm = current->mm;
81479 unsigned long addr = addr0;
81480 struct vm_unmapped_area_info info;
81481+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81482
81483 /* requested length too big for entire address space */
81484 if (len > TASK_SIZE)
81485@@ -1831,12 +2064,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81486 if (flags & MAP_FIXED)
81487 return addr;
81488
81489+#ifdef CONFIG_PAX_RANDMMAP
81490+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81491+#endif
81492+
81493 /* requesting a specific address */
81494 if (addr) {
81495 addr = PAGE_ALIGN(addr);
81496 vma = find_vma(mm, addr);
81497- if (TASK_SIZE - len >= addr &&
81498- (!vma || addr + len <= vma->vm_start))
81499+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81500 return addr;
81501 }
81502
81503@@ -1857,6 +2093,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81504 VM_BUG_ON(addr != -ENOMEM);
81505 info.flags = 0;
81506 info.low_limit = TASK_UNMAPPED_BASE;
81507+
81508+#ifdef CONFIG_PAX_RANDMMAP
81509+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81510+ info.low_limit += mm->delta_mmap;
81511+#endif
81512+
81513 info.high_limit = TASK_SIZE;
81514 addr = vm_unmapped_area(&info);
81515 }
81516@@ -1867,6 +2109,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81517
81518 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81519 {
81520+
81521+#ifdef CONFIG_PAX_SEGMEXEC
81522+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81523+ return;
81524+#endif
81525+
81526 /*
81527 * Is this a new hole at the highest possible address?
81528 */
81529@@ -1874,8 +2122,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81530 mm->free_area_cache = addr;
81531
81532 /* dont allow allocations above current base */
81533- if (mm->free_area_cache > mm->mmap_base)
81534+ if (mm->free_area_cache > mm->mmap_base) {
81535 mm->free_area_cache = mm->mmap_base;
81536+ mm->cached_hole_size = ~0UL;
81537+ }
81538 }
81539
81540 unsigned long
81541@@ -1974,6 +2224,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
81542 return vma;
81543 }
81544
81545+#ifdef CONFIG_PAX_SEGMEXEC
81546+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
81547+{
81548+ struct vm_area_struct *vma_m;
81549+
81550+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
81551+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
81552+ BUG_ON(vma->vm_mirror);
81553+ return NULL;
81554+ }
81555+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
81556+ vma_m = vma->vm_mirror;
81557+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
81558+ BUG_ON(vma->vm_file != vma_m->vm_file);
81559+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
81560+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
81561+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
81562+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
81563+ return vma_m;
81564+}
81565+#endif
81566+
81567 /*
81568 * Verify that the stack growth is acceptable and
81569 * update accounting. This is shared with both the
81570@@ -1990,6 +2262,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81571 return -ENOMEM;
81572
81573 /* Stack limit test */
81574+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
81575 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
81576 return -ENOMEM;
81577
81578@@ -2000,6 +2273,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81579 locked = mm->locked_vm + grow;
81580 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
81581 limit >>= PAGE_SHIFT;
81582+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81583 if (locked > limit && !capable(CAP_IPC_LOCK))
81584 return -ENOMEM;
81585 }
81586@@ -2029,37 +2303,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81587 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
81588 * vma is the last one with address > vma->vm_end. Have to extend vma.
81589 */
81590+#ifndef CONFIG_IA64
81591+static
81592+#endif
81593 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81594 {
81595 int error;
81596+ bool locknext;
81597
81598 if (!(vma->vm_flags & VM_GROWSUP))
81599 return -EFAULT;
81600
81601+ /* Also guard against wrapping around to address 0. */
81602+ if (address < PAGE_ALIGN(address+1))
81603+ address = PAGE_ALIGN(address+1);
81604+ else
81605+ return -ENOMEM;
81606+
81607 /*
81608 * We must make sure the anon_vma is allocated
81609 * so that the anon_vma locking is not a noop.
81610 */
81611 if (unlikely(anon_vma_prepare(vma)))
81612 return -ENOMEM;
81613+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
81614+ if (locknext && anon_vma_prepare(vma->vm_next))
81615+ return -ENOMEM;
81616 vma_lock_anon_vma(vma);
81617+ if (locknext)
81618+ vma_lock_anon_vma(vma->vm_next);
81619
81620 /*
81621 * vma->vm_start/vm_end cannot change under us because the caller
81622 * is required to hold the mmap_sem in read mode. We need the
81623- * anon_vma lock to serialize against concurrent expand_stacks.
81624- * Also guard against wrapping around to address 0.
81625+ * anon_vma locks to serialize against concurrent expand_stacks
81626+ * and expand_upwards.
81627 */
81628- if (address < PAGE_ALIGN(address+4))
81629- address = PAGE_ALIGN(address+4);
81630- else {
81631- vma_unlock_anon_vma(vma);
81632- return -ENOMEM;
81633- }
81634 error = 0;
81635
81636 /* Somebody else might have raced and expanded it already */
81637- if (address > vma->vm_end) {
81638+ 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)
81639+ error = -ENOMEM;
81640+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
81641 unsigned long size, grow;
81642
81643 size = address - vma->vm_start;
81644@@ -2094,6 +2379,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81645 }
81646 }
81647 }
81648+ if (locknext)
81649+ vma_unlock_anon_vma(vma->vm_next);
81650 vma_unlock_anon_vma(vma);
81651 khugepaged_enter_vma_merge(vma);
81652 validate_mm(vma->vm_mm);
81653@@ -2108,6 +2395,8 @@ int expand_downwards(struct vm_area_struct *vma,
81654 unsigned long address)
81655 {
81656 int error;
81657+ bool lockprev = false;
81658+ struct vm_area_struct *prev;
81659
81660 /*
81661 * We must make sure the anon_vma is allocated
81662@@ -2121,6 +2410,15 @@ int expand_downwards(struct vm_area_struct *vma,
81663 if (error)
81664 return error;
81665
81666+ prev = vma->vm_prev;
81667+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
81668+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
81669+#endif
81670+ if (lockprev && anon_vma_prepare(prev))
81671+ return -ENOMEM;
81672+ if (lockprev)
81673+ vma_lock_anon_vma(prev);
81674+
81675 vma_lock_anon_vma(vma);
81676
81677 /*
81678@@ -2130,9 +2428,17 @@ int expand_downwards(struct vm_area_struct *vma,
81679 */
81680
81681 /* Somebody else might have raced and expanded it already */
81682- if (address < vma->vm_start) {
81683+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
81684+ error = -ENOMEM;
81685+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
81686 unsigned long size, grow;
81687
81688+#ifdef CONFIG_PAX_SEGMEXEC
81689+ struct vm_area_struct *vma_m;
81690+
81691+ vma_m = pax_find_mirror_vma(vma);
81692+#endif
81693+
81694 size = vma->vm_end - address;
81695 grow = (vma->vm_start - address) >> PAGE_SHIFT;
81696
81697@@ -2157,6 +2463,18 @@ int expand_downwards(struct vm_area_struct *vma,
81698 vma->vm_pgoff -= grow;
81699 anon_vma_interval_tree_post_update_vma(vma);
81700 vma_gap_update(vma);
81701+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
81702+
81703+#ifdef CONFIG_PAX_SEGMEXEC
81704+ if (vma_m) {
81705+ anon_vma_interval_tree_pre_update_vma(vma_m);
81706+ vma_m->vm_start -= grow << PAGE_SHIFT;
81707+ vma_m->vm_pgoff -= grow;
81708+ anon_vma_interval_tree_post_update_vma(vma_m);
81709+ vma_gap_update(vma_m);
81710+ }
81711+#endif
81712+
81713 spin_unlock(&vma->vm_mm->page_table_lock);
81714
81715 perf_event_mmap(vma);
81716@@ -2263,6 +2581,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
81717 do {
81718 long nrpages = vma_pages(vma);
81719
81720+#ifdef CONFIG_PAX_SEGMEXEC
81721+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
81722+ vma = remove_vma(vma);
81723+ continue;
81724+ }
81725+#endif
81726+
81727 if (vma->vm_flags & VM_ACCOUNT)
81728 nr_accounted += nrpages;
81729 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
81730@@ -2308,6 +2633,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
81731 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
81732 vma->vm_prev = NULL;
81733 do {
81734+
81735+#ifdef CONFIG_PAX_SEGMEXEC
81736+ if (vma->vm_mirror) {
81737+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
81738+ vma->vm_mirror->vm_mirror = NULL;
81739+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
81740+ vma->vm_mirror = NULL;
81741+ }
81742+#endif
81743+
81744 vma_rb_erase(vma, &mm->mm_rb);
81745 mm->map_count--;
81746 tail_vma = vma;
81747@@ -2339,14 +2674,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81748 struct vm_area_struct *new;
81749 int err = -ENOMEM;
81750
81751+#ifdef CONFIG_PAX_SEGMEXEC
81752+ struct vm_area_struct *vma_m, *new_m = NULL;
81753+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
81754+#endif
81755+
81756 if (is_vm_hugetlb_page(vma) && (addr &
81757 ~(huge_page_mask(hstate_vma(vma)))))
81758 return -EINVAL;
81759
81760+#ifdef CONFIG_PAX_SEGMEXEC
81761+ vma_m = pax_find_mirror_vma(vma);
81762+#endif
81763+
81764 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81765 if (!new)
81766 goto out_err;
81767
81768+#ifdef CONFIG_PAX_SEGMEXEC
81769+ if (vma_m) {
81770+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81771+ if (!new_m) {
81772+ kmem_cache_free(vm_area_cachep, new);
81773+ goto out_err;
81774+ }
81775+ }
81776+#endif
81777+
81778 /* most fields are the same, copy all, and then fixup */
81779 *new = *vma;
81780
81781@@ -2359,6 +2713,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81782 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
81783 }
81784
81785+#ifdef CONFIG_PAX_SEGMEXEC
81786+ if (vma_m) {
81787+ *new_m = *vma_m;
81788+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
81789+ new_m->vm_mirror = new;
81790+ new->vm_mirror = new_m;
81791+
81792+ if (new_below)
81793+ new_m->vm_end = addr_m;
81794+ else {
81795+ new_m->vm_start = addr_m;
81796+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
81797+ }
81798+ }
81799+#endif
81800+
81801 pol = mpol_dup(vma_policy(vma));
81802 if (IS_ERR(pol)) {
81803 err = PTR_ERR(pol);
81804@@ -2381,6 +2751,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81805 else
81806 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
81807
81808+#ifdef CONFIG_PAX_SEGMEXEC
81809+ if (!err && vma_m) {
81810+ if (anon_vma_clone(new_m, vma_m))
81811+ goto out_free_mpol;
81812+
81813+ mpol_get(pol);
81814+ vma_set_policy(new_m, pol);
81815+
81816+ if (new_m->vm_file)
81817+ get_file(new_m->vm_file);
81818+
81819+ if (new_m->vm_ops && new_m->vm_ops->open)
81820+ new_m->vm_ops->open(new_m);
81821+
81822+ if (new_below)
81823+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
81824+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
81825+ else
81826+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
81827+
81828+ if (err) {
81829+ if (new_m->vm_ops && new_m->vm_ops->close)
81830+ new_m->vm_ops->close(new_m);
81831+ if (new_m->vm_file)
81832+ fput(new_m->vm_file);
81833+ mpol_put(pol);
81834+ }
81835+ }
81836+#endif
81837+
81838 /* Success. */
81839 if (!err)
81840 return 0;
81841@@ -2390,10 +2790,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81842 new->vm_ops->close(new);
81843 if (new->vm_file)
81844 fput(new->vm_file);
81845- unlink_anon_vmas(new);
81846 out_free_mpol:
81847 mpol_put(pol);
81848 out_free_vma:
81849+
81850+#ifdef CONFIG_PAX_SEGMEXEC
81851+ if (new_m) {
81852+ unlink_anon_vmas(new_m);
81853+ kmem_cache_free(vm_area_cachep, new_m);
81854+ }
81855+#endif
81856+
81857+ unlink_anon_vmas(new);
81858 kmem_cache_free(vm_area_cachep, new);
81859 out_err:
81860 return err;
81861@@ -2406,6 +2814,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81862 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81863 unsigned long addr, int new_below)
81864 {
81865+
81866+#ifdef CONFIG_PAX_SEGMEXEC
81867+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81868+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
81869+ if (mm->map_count >= sysctl_max_map_count-1)
81870+ return -ENOMEM;
81871+ } else
81872+#endif
81873+
81874 if (mm->map_count >= sysctl_max_map_count)
81875 return -ENOMEM;
81876
81877@@ -2417,11 +2834,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81878 * work. This now handles partial unmappings.
81879 * Jeremy Fitzhardinge <jeremy@goop.org>
81880 */
81881+#ifdef CONFIG_PAX_SEGMEXEC
81882 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81883 {
81884+ int ret = __do_munmap(mm, start, len);
81885+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
81886+ return ret;
81887+
81888+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
81889+}
81890+
81891+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81892+#else
81893+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81894+#endif
81895+{
81896 unsigned long end;
81897 struct vm_area_struct *vma, *prev, *last;
81898
81899+ /*
81900+ * mm->mmap_sem is required to protect against another thread
81901+ * changing the mappings in case we sleep.
81902+ */
81903+ verify_mm_writelocked(mm);
81904+
81905 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
81906 return -EINVAL;
81907
81908@@ -2496,6 +2932,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81909 /* Fix up all other VM information */
81910 remove_vma_list(mm, vma);
81911
81912+ track_exec_limit(mm, start, end, 0UL);
81913+
81914 return 0;
81915 }
81916
81917@@ -2504,6 +2942,13 @@ int vm_munmap(unsigned long start, size_t len)
81918 int ret;
81919 struct mm_struct *mm = current->mm;
81920
81921+
81922+#ifdef CONFIG_PAX_SEGMEXEC
81923+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
81924+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
81925+ return -EINVAL;
81926+#endif
81927+
81928 down_write(&mm->mmap_sem);
81929 ret = do_munmap(mm, start, len);
81930 up_write(&mm->mmap_sem);
81931@@ -2517,16 +2962,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
81932 return vm_munmap(addr, len);
81933 }
81934
81935-static inline void verify_mm_writelocked(struct mm_struct *mm)
81936-{
81937-#ifdef CONFIG_DEBUG_VM
81938- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81939- WARN_ON(1);
81940- up_read(&mm->mmap_sem);
81941- }
81942-#endif
81943-}
81944-
81945 /*
81946 * this is really a simplified "do_mmap". it only handles
81947 * anonymous maps. eventually we may be able to do some
81948@@ -2540,6 +2975,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81949 struct rb_node ** rb_link, * rb_parent;
81950 pgoff_t pgoff = addr >> PAGE_SHIFT;
81951 int error;
81952+ unsigned long charged;
81953
81954 len = PAGE_ALIGN(len);
81955 if (!len)
81956@@ -2547,16 +2983,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81957
81958 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
81959
81960+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
81961+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
81962+ flags &= ~VM_EXEC;
81963+
81964+#ifdef CONFIG_PAX_MPROTECT
81965+ if (mm->pax_flags & MF_PAX_MPROTECT)
81966+ flags &= ~VM_MAYEXEC;
81967+#endif
81968+
81969+ }
81970+#endif
81971+
81972 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
81973 if (error & ~PAGE_MASK)
81974 return error;
81975
81976+ charged = len >> PAGE_SHIFT;
81977+
81978 /*
81979 * mlock MCL_FUTURE?
81980 */
81981 if (mm->def_flags & VM_LOCKED) {
81982 unsigned long locked, lock_limit;
81983- locked = len >> PAGE_SHIFT;
81984+ locked = charged;
81985 locked += mm->locked_vm;
81986 lock_limit = rlimit(RLIMIT_MEMLOCK);
81987 lock_limit >>= PAGE_SHIFT;
81988@@ -2573,21 +3023,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81989 /*
81990 * Clear old maps. this also does some error checking for us
81991 */
81992- munmap_back:
81993 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81994 if (do_munmap(mm, addr, len))
81995 return -ENOMEM;
81996- goto munmap_back;
81997+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81998 }
81999
82000 /* Check against address space limits *after* clearing old maps... */
82001- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82002+ if (!may_expand_vm(mm, charged))
82003 return -ENOMEM;
82004
82005 if (mm->map_count > sysctl_max_map_count)
82006 return -ENOMEM;
82007
82008- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
82009+ if (security_vm_enough_memory_mm(mm, charged))
82010 return -ENOMEM;
82011
82012 /* Can we just expand an old private anonymous mapping? */
82013@@ -2601,7 +3050,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82014 */
82015 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82016 if (!vma) {
82017- vm_unacct_memory(len >> PAGE_SHIFT);
82018+ vm_unacct_memory(charged);
82019 return -ENOMEM;
82020 }
82021
82022@@ -2615,11 +3064,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82023 vma_link(mm, vma, prev, rb_link, rb_parent);
82024 out:
82025 perf_event_mmap(vma);
82026- mm->total_vm += len >> PAGE_SHIFT;
82027+ mm->total_vm += charged;
82028 if (flags & VM_LOCKED) {
82029 if (!mlock_vma_pages_range(vma, addr, addr + len))
82030- mm->locked_vm += (len >> PAGE_SHIFT);
82031+ mm->locked_vm += charged;
82032 }
82033+ track_exec_limit(mm, addr, addr + len, flags);
82034 return addr;
82035 }
82036
82037@@ -2677,6 +3127,7 @@ void exit_mmap(struct mm_struct *mm)
82038 while (vma) {
82039 if (vma->vm_flags & VM_ACCOUNT)
82040 nr_accounted += vma_pages(vma);
82041+ vma->vm_mirror = NULL;
82042 vma = remove_vma(vma);
82043 }
82044 vm_unacct_memory(nr_accounted);
82045@@ -2693,6 +3144,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82046 struct vm_area_struct *prev;
82047 struct rb_node **rb_link, *rb_parent;
82048
82049+#ifdef CONFIG_PAX_SEGMEXEC
82050+ struct vm_area_struct *vma_m = NULL;
82051+#endif
82052+
82053+ if (security_mmap_addr(vma->vm_start))
82054+ return -EPERM;
82055+
82056 /*
82057 * The vm_pgoff of a purely anonymous vma should be irrelevant
82058 * until its first write fault, when page's anon_vma and index
82059@@ -2716,7 +3174,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82060 security_vm_enough_memory_mm(mm, vma_pages(vma)))
82061 return -ENOMEM;
82062
82063+#ifdef CONFIG_PAX_SEGMEXEC
82064+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
82065+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82066+ if (!vma_m)
82067+ return -ENOMEM;
82068+ }
82069+#endif
82070+
82071 vma_link(mm, vma, prev, rb_link, rb_parent);
82072+
82073+#ifdef CONFIG_PAX_SEGMEXEC
82074+ if (vma_m)
82075+ BUG_ON(pax_mirror_vma(vma_m, vma));
82076+#endif
82077+
82078 return 0;
82079 }
82080
82081@@ -2736,6 +3208,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82082 struct mempolicy *pol;
82083 bool faulted_in_anon_vma = true;
82084
82085+ BUG_ON(vma->vm_mirror);
82086+
82087 /*
82088 * If anonymous vma has not yet been faulted, update new pgoff
82089 * to match new location, to increase its chance of merging.
82090@@ -2802,6 +3276,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82091 return NULL;
82092 }
82093
82094+#ifdef CONFIG_PAX_SEGMEXEC
82095+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
82096+{
82097+ struct vm_area_struct *prev_m;
82098+ struct rb_node **rb_link_m, *rb_parent_m;
82099+ struct mempolicy *pol_m;
82100+
82101+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
82102+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
82103+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
82104+ *vma_m = *vma;
82105+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
82106+ if (anon_vma_clone(vma_m, vma))
82107+ return -ENOMEM;
82108+ pol_m = vma_policy(vma_m);
82109+ mpol_get(pol_m);
82110+ vma_set_policy(vma_m, pol_m);
82111+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
82112+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
82113+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
82114+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
82115+ if (vma_m->vm_file)
82116+ get_file(vma_m->vm_file);
82117+ if (vma_m->vm_ops && vma_m->vm_ops->open)
82118+ vma_m->vm_ops->open(vma_m);
82119+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
82120+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
82121+ vma_m->vm_mirror = vma;
82122+ vma->vm_mirror = vma_m;
82123+ return 0;
82124+}
82125+#endif
82126+
82127 /*
82128 * Return true if the calling process may expand its vm space by the passed
82129 * number of pages
82130@@ -2813,6 +3320,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
82131
82132 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
82133
82134+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
82135 if (cur + npages > lim)
82136 return 0;
82137 return 1;
82138@@ -2883,6 +3391,22 @@ int install_special_mapping(struct mm_struct *mm,
82139 vma->vm_start = addr;
82140 vma->vm_end = addr + len;
82141
82142+#ifdef CONFIG_PAX_MPROTECT
82143+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82144+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82145+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
82146+ return -EPERM;
82147+ if (!(vm_flags & VM_EXEC))
82148+ vm_flags &= ~VM_MAYEXEC;
82149+#else
82150+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82151+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82152+#endif
82153+ else
82154+ vm_flags &= ~VM_MAYWRITE;
82155+ }
82156+#endif
82157+
82158 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
82159 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82160
82161diff --git a/mm/mprotect.c b/mm/mprotect.c
82162index 94722a4..9837984 100644
82163--- a/mm/mprotect.c
82164+++ b/mm/mprotect.c
82165@@ -23,10 +23,17 @@
82166 #include <linux/mmu_notifier.h>
82167 #include <linux/migrate.h>
82168 #include <linux/perf_event.h>
82169+
82170+#ifdef CONFIG_PAX_MPROTECT
82171+#include <linux/elf.h>
82172+#include <linux/binfmts.h>
82173+#endif
82174+
82175 #include <asm/uaccess.h>
82176 #include <asm/pgtable.h>
82177 #include <asm/cacheflush.h>
82178 #include <asm/tlbflush.h>
82179+#include <asm/mmu_context.h>
82180
82181 #ifndef pgprot_modify
82182 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
82183@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
82184 return pages;
82185 }
82186
82187+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82188+/* called while holding the mmap semaphor for writing except stack expansion */
82189+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
82190+{
82191+ unsigned long oldlimit, newlimit = 0UL;
82192+
82193+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
82194+ return;
82195+
82196+ spin_lock(&mm->page_table_lock);
82197+ oldlimit = mm->context.user_cs_limit;
82198+ if ((prot & VM_EXEC) && oldlimit < end)
82199+ /* USER_CS limit moved up */
82200+ newlimit = end;
82201+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
82202+ /* USER_CS limit moved down */
82203+ newlimit = start;
82204+
82205+ if (newlimit) {
82206+ mm->context.user_cs_limit = newlimit;
82207+
82208+#ifdef CONFIG_SMP
82209+ wmb();
82210+ cpus_clear(mm->context.cpu_user_cs_mask);
82211+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
82212+#endif
82213+
82214+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
82215+ }
82216+ spin_unlock(&mm->page_table_lock);
82217+ if (newlimit == end) {
82218+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
82219+
82220+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
82221+ if (is_vm_hugetlb_page(vma))
82222+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
82223+ else
82224+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
82225+ }
82226+}
82227+#endif
82228+
82229 int
82230 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82231 unsigned long start, unsigned long end, unsigned long newflags)
82232@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82233 int error;
82234 int dirty_accountable = 0;
82235
82236+#ifdef CONFIG_PAX_SEGMEXEC
82237+ struct vm_area_struct *vma_m = NULL;
82238+ unsigned long start_m, end_m;
82239+
82240+ start_m = start + SEGMEXEC_TASK_SIZE;
82241+ end_m = end + SEGMEXEC_TASK_SIZE;
82242+#endif
82243+
82244 if (newflags == oldflags) {
82245 *pprev = vma;
82246 return 0;
82247 }
82248
82249+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
82250+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
82251+
82252+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
82253+ return -ENOMEM;
82254+
82255+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
82256+ return -ENOMEM;
82257+ }
82258+
82259 /*
82260 * If we make a private mapping writable we increase our commit;
82261 * but (without finer accounting) cannot reduce our commit if we
82262@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82263 }
82264 }
82265
82266+#ifdef CONFIG_PAX_SEGMEXEC
82267+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
82268+ if (start != vma->vm_start) {
82269+ error = split_vma(mm, vma, start, 1);
82270+ if (error)
82271+ goto fail;
82272+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
82273+ *pprev = (*pprev)->vm_next;
82274+ }
82275+
82276+ if (end != vma->vm_end) {
82277+ error = split_vma(mm, vma, end, 0);
82278+ if (error)
82279+ goto fail;
82280+ }
82281+
82282+ if (pax_find_mirror_vma(vma)) {
82283+ error = __do_munmap(mm, start_m, end_m - start_m);
82284+ if (error)
82285+ goto fail;
82286+ } else {
82287+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82288+ if (!vma_m) {
82289+ error = -ENOMEM;
82290+ goto fail;
82291+ }
82292+ vma->vm_flags = newflags;
82293+ error = pax_mirror_vma(vma_m, vma);
82294+ if (error) {
82295+ vma->vm_flags = oldflags;
82296+ goto fail;
82297+ }
82298+ }
82299+ }
82300+#endif
82301+
82302 /*
82303 * First try to merge with previous and/or next vma.
82304 */
82305@@ -296,9 +399,21 @@ success:
82306 * vm_flags and vm_page_prot are protected by the mmap_sem
82307 * held in write mode.
82308 */
82309+
82310+#ifdef CONFIG_PAX_SEGMEXEC
82311+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
82312+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
82313+#endif
82314+
82315 vma->vm_flags = newflags;
82316+
82317+#ifdef CONFIG_PAX_MPROTECT
82318+ if (mm->binfmt && mm->binfmt->handle_mprotect)
82319+ mm->binfmt->handle_mprotect(vma, newflags);
82320+#endif
82321+
82322 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
82323- vm_get_page_prot(newflags));
82324+ vm_get_page_prot(vma->vm_flags));
82325
82326 if (vma_wants_writenotify(vma)) {
82327 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
82328@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82329 end = start + len;
82330 if (end <= start)
82331 return -ENOMEM;
82332+
82333+#ifdef CONFIG_PAX_SEGMEXEC
82334+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
82335+ if (end > SEGMEXEC_TASK_SIZE)
82336+ return -EINVAL;
82337+ } else
82338+#endif
82339+
82340+ if (end > TASK_SIZE)
82341+ return -EINVAL;
82342+
82343 if (!arch_validate_prot(prot))
82344 return -EINVAL;
82345
82346@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82347 /*
82348 * Does the application expect PROT_READ to imply PROT_EXEC:
82349 */
82350- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82351+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82352 prot |= PROT_EXEC;
82353
82354 vm_flags = calc_vm_prot_bits(prot);
82355@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82356 if (start > vma->vm_start)
82357 prev = vma;
82358
82359+#ifdef CONFIG_PAX_MPROTECT
82360+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
82361+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
82362+#endif
82363+
82364 for (nstart = start ; ; ) {
82365 unsigned long newflags;
82366
82367@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82368
82369 /* newflags >> 4 shift VM_MAY% in place of VM_% */
82370 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
82371+ if (prot & (PROT_WRITE | PROT_EXEC))
82372+ gr_log_rwxmprotect(vma->vm_file);
82373+
82374+ error = -EACCES;
82375+ goto out;
82376+ }
82377+
82378+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
82379 error = -EACCES;
82380 goto out;
82381 }
82382@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82383 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
82384 if (error)
82385 goto out;
82386+
82387+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
82388+
82389 nstart = tmp;
82390
82391 if (nstart < prev->vm_end)
82392diff --git a/mm/mremap.c b/mm/mremap.c
82393index e1031e1..1f2a0a1 100644
82394--- a/mm/mremap.c
82395+++ b/mm/mremap.c
82396@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
82397 continue;
82398 pte = ptep_get_and_clear(mm, old_addr, old_pte);
82399 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
82400+
82401+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82402+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
82403+ pte = pte_exprotect(pte);
82404+#endif
82405+
82406 set_pte_at(mm, new_addr, new_pte, pte);
82407 }
82408
82409@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
82410 if (is_vm_hugetlb_page(vma))
82411 goto Einval;
82412
82413+#ifdef CONFIG_PAX_SEGMEXEC
82414+ if (pax_find_mirror_vma(vma))
82415+ goto Einval;
82416+#endif
82417+
82418 /* We can't remap across vm area boundaries */
82419 if (old_len > vma->vm_end - addr)
82420 goto Efault;
82421@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
82422 unsigned long ret = -EINVAL;
82423 unsigned long charged = 0;
82424 unsigned long map_flags;
82425+ unsigned long pax_task_size = TASK_SIZE;
82426
82427 if (new_addr & ~PAGE_MASK)
82428 goto out;
82429
82430- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
82431+#ifdef CONFIG_PAX_SEGMEXEC
82432+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82433+ pax_task_size = SEGMEXEC_TASK_SIZE;
82434+#endif
82435+
82436+ pax_task_size -= PAGE_SIZE;
82437+
82438+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
82439 goto out;
82440
82441 /* Check if the location we're moving into overlaps the
82442 * old location at all, and fail if it does.
82443 */
82444- if ((new_addr <= addr) && (new_addr+new_len) > addr)
82445- goto out;
82446-
82447- if ((addr <= new_addr) && (addr+old_len) > new_addr)
82448+ if (addr + old_len > new_addr && new_addr + new_len > addr)
82449 goto out;
82450
82451 ret = do_munmap(mm, new_addr, new_len);
82452@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82453 struct vm_area_struct *vma;
82454 unsigned long ret = -EINVAL;
82455 unsigned long charged = 0;
82456+ unsigned long pax_task_size = TASK_SIZE;
82457
82458 down_write(&current->mm->mmap_sem);
82459
82460@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82461 if (!new_len)
82462 goto out;
82463
82464+#ifdef CONFIG_PAX_SEGMEXEC
82465+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82466+ pax_task_size = SEGMEXEC_TASK_SIZE;
82467+#endif
82468+
82469+ pax_task_size -= PAGE_SIZE;
82470+
82471+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
82472+ old_len > pax_task_size || addr > pax_task_size-old_len)
82473+ goto out;
82474+
82475 if (flags & MREMAP_FIXED) {
82476 if (flags & MREMAP_MAYMOVE)
82477 ret = mremap_to(addr, old_len, new_addr, new_len);
82478@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82479 addr + new_len);
82480 }
82481 ret = addr;
82482+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
82483 goto out;
82484 }
82485 }
82486@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82487 goto out;
82488 }
82489
82490+ map_flags = vma->vm_flags;
82491 ret = move_vma(vma, addr, old_len, new_len, new_addr);
82492+ if (!(ret & ~PAGE_MASK)) {
82493+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
82494+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
82495+ }
82496 }
82497 out:
82498 if (ret & ~PAGE_MASK)
82499diff --git a/mm/nommu.c b/mm/nommu.c
82500index 79c3cac..4d357e0 100644
82501--- a/mm/nommu.c
82502+++ b/mm/nommu.c
82503@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
82504 int sysctl_overcommit_ratio = 50; /* default is 50% */
82505 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
82506 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
82507-int heap_stack_gap = 0;
82508
82509 atomic_long_t mmap_pages_allocated;
82510
82511@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
82512 EXPORT_SYMBOL(find_vma);
82513
82514 /*
82515- * find a VMA
82516- * - we don't extend stack VMAs under NOMMU conditions
82517- */
82518-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
82519-{
82520- return find_vma(mm, addr);
82521-}
82522-
82523-/*
82524 * expand a stack to a given address
82525 * - not supported under NOMMU conditions
82526 */
82527@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82528
82529 /* most fields are the same, copy all, and then fixup */
82530 *new = *vma;
82531+ INIT_LIST_HEAD(&new->anon_vma_chain);
82532 *region = *vma->vm_region;
82533 new->vm_region = region;
82534
82535diff --git a/mm/page-writeback.c b/mm/page-writeback.c
82536index 0713bfb..b95bb87 100644
82537--- a/mm/page-writeback.c
82538+++ b/mm/page-writeback.c
82539@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
82540 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
82541 * - the bdi dirty thresh drops quickly due to change of JBOD workload
82542 */
82543-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
82544+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
82545 unsigned long thresh,
82546 unsigned long bg_thresh,
82547 unsigned long dirty,
82548@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
82549 }
82550 }
82551
82552-static struct notifier_block __cpuinitdata ratelimit_nb = {
82553+static struct notifier_block ratelimit_nb = {
82554 .notifier_call = ratelimit_handler,
82555 .next = NULL,
82556 };
82557diff --git a/mm/page_alloc.c b/mm/page_alloc.c
82558index 6a83cd3..3ab04ef 100644
82559--- a/mm/page_alloc.c
82560+++ b/mm/page_alloc.c
82561@@ -58,6 +58,7 @@
82562 #include <linux/prefetch.h>
82563 #include <linux/migrate.h>
82564 #include <linux/page-debug-flags.h>
82565+#include <linux/random.h>
82566
82567 #include <asm/tlbflush.h>
82568 #include <asm/div64.h>
82569@@ -338,7 +339,7 @@ out:
82570 * This usage means that zero-order pages may not be compound.
82571 */
82572
82573-static void free_compound_page(struct page *page)
82574+void free_compound_page(struct page *page)
82575 {
82576 __free_pages_ok(page, compound_order(page));
82577 }
82578@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82579 int i;
82580 int bad = 0;
82581
82582+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82583+ unsigned long index = 1UL << order;
82584+#endif
82585+
82586 trace_mm_page_free(page, order);
82587 kmemcheck_free_shadow(page, order);
82588
82589@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82590 debug_check_no_obj_freed(page_address(page),
82591 PAGE_SIZE << order);
82592 }
82593+
82594+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82595+ for (; index; --index)
82596+ sanitize_highpage(page + index - 1);
82597+#endif
82598+
82599 arch_free_page(page, order);
82600 kernel_map_pages(page, 1 << order, 0);
82601
82602@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
82603 local_irq_restore(flags);
82604 }
82605
82606+#ifdef CONFIG_PAX_LATENT_ENTROPY
82607+bool __meminitdata extra_latent_entropy;
82608+
82609+static int __init setup_pax_extra_latent_entropy(char *str)
82610+{
82611+ extra_latent_entropy = true;
82612+ return 0;
82613+}
82614+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
82615+
82616+volatile u64 latent_entropy;
82617+#endif
82618+
82619 /*
82620 * Read access to zone->managed_pages is safe because it's unsigned long,
82621 * but we still need to serialize writers. Currently all callers of
82622@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
82623 set_page_count(p, 0);
82624 }
82625
82626+#ifdef CONFIG_PAX_LATENT_ENTROPY
82627+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
82628+ u64 hash = 0;
82629+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
82630+ const u64 *data = lowmem_page_address(page);
82631+
82632+ for (index = 0; index < end; index++)
82633+ hash ^= hash + data[index];
82634+ latent_entropy ^= hash;
82635+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82636+ }
82637+#endif
82638+
82639 page_zone(page)->managed_pages += 1 << order;
82640 set_page_refcounted(page);
82641 __free_pages(page, order);
82642@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
82643 arch_alloc_page(page, order);
82644 kernel_map_pages(page, 1 << order, 1);
82645
82646+#ifndef CONFIG_PAX_MEMORY_SANITIZE
82647 if (gfp_flags & __GFP_ZERO)
82648 prep_zero_page(page, order, gfp_flags);
82649+#endif
82650
82651 if (order && (gfp_flags & __GFP_COMP))
82652 prep_compound_page(page, order);
82653@@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
82654 unsigned long pfn;
82655
82656 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
82657+#ifdef CONFIG_X86_32
82658+ /* boot failures in VMware 8 on 32bit vanilla since
82659+ this change */
82660+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
82661+#else
82662 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
82663+#endif
82664 return 1;
82665 }
82666 return 0;
82667diff --git a/mm/percpu.c b/mm/percpu.c
82668index 8c8e08f..73a5cda 100644
82669--- a/mm/percpu.c
82670+++ b/mm/percpu.c
82671@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
82672 static unsigned int pcpu_high_unit_cpu __read_mostly;
82673
82674 /* the address of the first chunk which starts with the kernel static area */
82675-void *pcpu_base_addr __read_mostly;
82676+void *pcpu_base_addr __read_only;
82677 EXPORT_SYMBOL_GPL(pcpu_base_addr);
82678
82679 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
82680diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
82681index fd26d04..0cea1b0 100644
82682--- a/mm/process_vm_access.c
82683+++ b/mm/process_vm_access.c
82684@@ -13,6 +13,7 @@
82685 #include <linux/uio.h>
82686 #include <linux/sched.h>
82687 #include <linux/highmem.h>
82688+#include <linux/security.h>
82689 #include <linux/ptrace.h>
82690 #include <linux/slab.h>
82691 #include <linux/syscalls.h>
82692@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82693 size_t iov_l_curr_offset = 0;
82694 ssize_t iov_len;
82695
82696+ return -ENOSYS; // PaX: until properly audited
82697+
82698 /*
82699 * Work out how many pages of struct pages we're going to need
82700 * when eventually calling get_user_pages
82701 */
82702 for (i = 0; i < riovcnt; i++) {
82703 iov_len = rvec[i].iov_len;
82704- if (iov_len > 0) {
82705- nr_pages_iov = ((unsigned long)rvec[i].iov_base
82706- + iov_len)
82707- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
82708- / PAGE_SIZE + 1;
82709- nr_pages = max(nr_pages, nr_pages_iov);
82710- }
82711+ if (iov_len <= 0)
82712+ continue;
82713+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
82714+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
82715+ nr_pages = max(nr_pages, nr_pages_iov);
82716 }
82717
82718 if (nr_pages == 0)
82719@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82720 goto free_proc_pages;
82721 }
82722
82723+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
82724+ rc = -EPERM;
82725+ goto put_task_struct;
82726+ }
82727+
82728 mm = mm_access(task, PTRACE_MODE_ATTACH);
82729 if (!mm || IS_ERR(mm)) {
82730 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
82731diff --git a/mm/rmap.c b/mm/rmap.c
82732index 2c78f8c..9e9c624 100644
82733--- a/mm/rmap.c
82734+++ b/mm/rmap.c
82735@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82736 struct anon_vma *anon_vma = vma->anon_vma;
82737 struct anon_vma_chain *avc;
82738
82739+#ifdef CONFIG_PAX_SEGMEXEC
82740+ struct anon_vma_chain *avc_m = NULL;
82741+#endif
82742+
82743 might_sleep();
82744 if (unlikely(!anon_vma)) {
82745 struct mm_struct *mm = vma->vm_mm;
82746@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82747 if (!avc)
82748 goto out_enomem;
82749
82750+#ifdef CONFIG_PAX_SEGMEXEC
82751+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
82752+ if (!avc_m)
82753+ goto out_enomem_free_avc;
82754+#endif
82755+
82756 anon_vma = find_mergeable_anon_vma(vma);
82757 allocated = NULL;
82758 if (!anon_vma) {
82759@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82760 /* page_table_lock to protect against threads */
82761 spin_lock(&mm->page_table_lock);
82762 if (likely(!vma->anon_vma)) {
82763+
82764+#ifdef CONFIG_PAX_SEGMEXEC
82765+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
82766+
82767+ if (vma_m) {
82768+ BUG_ON(vma_m->anon_vma);
82769+ vma_m->anon_vma = anon_vma;
82770+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
82771+ avc_m = NULL;
82772+ }
82773+#endif
82774+
82775 vma->anon_vma = anon_vma;
82776 anon_vma_chain_link(vma, avc, anon_vma);
82777 allocated = NULL;
82778@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82779
82780 if (unlikely(allocated))
82781 put_anon_vma(allocated);
82782+
82783+#ifdef CONFIG_PAX_SEGMEXEC
82784+ if (unlikely(avc_m))
82785+ anon_vma_chain_free(avc_m);
82786+#endif
82787+
82788 if (unlikely(avc))
82789 anon_vma_chain_free(avc);
82790 }
82791 return 0;
82792
82793 out_enomem_free_avc:
82794+
82795+#ifdef CONFIG_PAX_SEGMEXEC
82796+ if (avc_m)
82797+ anon_vma_chain_free(avc_m);
82798+#endif
82799+
82800 anon_vma_chain_free(avc);
82801 out_enomem:
82802 return -ENOMEM;
82803@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
82804 * Attach the anon_vmas from src to dst.
82805 * Returns 0 on success, -ENOMEM on failure.
82806 */
82807-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82808+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
82809 {
82810 struct anon_vma_chain *avc, *pavc;
82811 struct anon_vma *root = NULL;
82812@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82813 * the corresponding VMA in the parent process is attached to.
82814 * Returns 0 on success, non-zero on failure.
82815 */
82816-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
82817+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
82818 {
82819 struct anon_vma_chain *avc;
82820 struct anon_vma *anon_vma;
82821diff --git a/mm/shmem.c b/mm/shmem.c
82822index efd0b3a..994b702 100644
82823--- a/mm/shmem.c
82824+++ b/mm/shmem.c
82825@@ -31,7 +31,7 @@
82826 #include <linux/export.h>
82827 #include <linux/swap.h>
82828
82829-static struct vfsmount *shm_mnt;
82830+struct vfsmount *shm_mnt;
82831
82832 #ifdef CONFIG_SHMEM
82833 /*
82834@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
82835 #define BOGO_DIRENT_SIZE 20
82836
82837 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
82838-#define SHORT_SYMLINK_LEN 128
82839+#define SHORT_SYMLINK_LEN 64
82840
82841 /*
82842 * shmem_fallocate and shmem_writepage communicate via inode->i_private
82843@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
82844 static int shmem_xattr_validate(const char *name)
82845 {
82846 struct { const char *prefix; size_t len; } arr[] = {
82847+
82848+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82849+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
82850+#endif
82851+
82852 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
82853 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
82854 };
82855@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
82856 if (err)
82857 return err;
82858
82859+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82860+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
82861+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
82862+ return -EOPNOTSUPP;
82863+ if (size > 8)
82864+ return -EINVAL;
82865+ }
82866+#endif
82867+
82868 return simple_xattr_set(&info->xattrs, name, value, size, flags);
82869 }
82870
82871@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
82872 int err = -ENOMEM;
82873
82874 /* Round up to L1_CACHE_BYTES to resist false sharing */
82875- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
82876- L1_CACHE_BYTES), GFP_KERNEL);
82877+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
82878 if (!sbinfo)
82879 return -ENOMEM;
82880
82881diff --git a/mm/slab.c b/mm/slab.c
82882index e7667a3..b62c169 100644
82883--- a/mm/slab.c
82884+++ b/mm/slab.c
82885@@ -306,7 +306,7 @@ struct kmem_list3 {
82886 * Need this for bootstrapping a per node allocator.
82887 */
82888 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
82889-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
82890+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
82891 #define CACHE_CACHE 0
82892 #define SIZE_AC MAX_NUMNODES
82893 #define SIZE_L3 (2 * MAX_NUMNODES)
82894@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
82895 if ((x)->max_freeable < i) \
82896 (x)->max_freeable = i; \
82897 } while (0)
82898-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
82899-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
82900-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
82901-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
82902+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
82903+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
82904+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
82905+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
82906 #else
82907 #define STATS_INC_ACTIVE(x) do { } while (0)
82908 #define STATS_DEC_ACTIVE(x) do { } while (0)
82909@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
82910 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
82911 */
82912 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
82913- const struct slab *slab, void *obj)
82914+ const struct slab *slab, const void *obj)
82915 {
82916 u32 offset = (obj - slab->s_mem);
82917 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
82918@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
82919 struct cache_names {
82920 char *name;
82921 char *name_dma;
82922+ char *name_usercopy;
82923 };
82924
82925 static struct cache_names __initdata cache_names[] = {
82926-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
82927+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
82928 #include <linux/kmalloc_sizes.h>
82929- {NULL,}
82930+ {NULL}
82931 #undef CACHE
82932 };
82933
82934@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
82935 if (unlikely(gfpflags & GFP_DMA))
82936 return csizep->cs_dmacachep;
82937 #endif
82938+
82939+#ifdef CONFIG_PAX_USERCOPY_SLABS
82940+ if (unlikely(gfpflags & GFP_USERCOPY))
82941+ return csizep->cs_usercopycachep;
82942+#endif
82943+
82944 return csizep->cs_cachep;
82945 }
82946
82947@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
82948 return notifier_from_errno(err);
82949 }
82950
82951-static struct notifier_block __cpuinitdata cpucache_notifier = {
82952+static struct notifier_block cpucache_notifier = {
82953 &cpuup_callback, NULL, 0
82954 };
82955
82956@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
82957 */
82958
82959 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
82960- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
82961+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82962
82963 if (INDEX_AC != INDEX_L3)
82964 sizes[INDEX_L3].cs_cachep =
82965 create_kmalloc_cache(names[INDEX_L3].name,
82966- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
82967+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82968
82969 slab_early_init = 0;
82970
82971@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
82972 */
82973 if (!sizes->cs_cachep)
82974 sizes->cs_cachep = create_kmalloc_cache(names->name,
82975- sizes->cs_size, ARCH_KMALLOC_FLAGS);
82976+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82977
82978 #ifdef CONFIG_ZONE_DMA
82979 sizes->cs_dmacachep = create_kmalloc_cache(
82980 names->name_dma, sizes->cs_size,
82981 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
82982 #endif
82983+
82984+#ifdef CONFIG_PAX_USERCOPY_SLABS
82985+ sizes->cs_usercopycachep = create_kmalloc_cache(
82986+ names->name_usercopy, sizes->cs_size,
82987+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82988+#endif
82989+
82990 sizes++;
82991 names++;
82992 }
82993@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
82994 }
82995 /* cpu stats */
82996 {
82997- unsigned long allochit = atomic_read(&cachep->allochit);
82998- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
82999- unsigned long freehit = atomic_read(&cachep->freehit);
83000- unsigned long freemiss = atomic_read(&cachep->freemiss);
83001+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
83002+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
83003+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
83004+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
83005
83006 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
83007 allochit, allocmiss, freehit, freemiss);
83008@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
83009 static int __init slab_proc_init(void)
83010 {
83011 #ifdef CONFIG_DEBUG_SLAB_LEAK
83012- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
83013+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
83014 #endif
83015 return 0;
83016 }
83017 module_init(slab_proc_init);
83018 #endif
83019
83020+bool is_usercopy_object(const void *ptr)
83021+{
83022+ struct page *page;
83023+ struct kmem_cache *cachep;
83024+
83025+ if (ZERO_OR_NULL_PTR(ptr))
83026+ return false;
83027+
83028+ if (!slab_is_available())
83029+ return false;
83030+
83031+ if (!virt_addr_valid(ptr))
83032+ return false;
83033+
83034+ page = virt_to_head_page(ptr);
83035+
83036+ if (!PageSlab(page))
83037+ return false;
83038+
83039+ cachep = page->slab_cache;
83040+ return cachep->flags & SLAB_USERCOPY;
83041+}
83042+
83043+#ifdef CONFIG_PAX_USERCOPY
83044+const char *check_heap_object(const void *ptr, unsigned long n)
83045+{
83046+ struct page *page;
83047+ struct kmem_cache *cachep;
83048+ struct slab *slabp;
83049+ unsigned int objnr;
83050+ unsigned long offset;
83051+
83052+ if (ZERO_OR_NULL_PTR(ptr))
83053+ return "<null>";
83054+
83055+ if (!virt_addr_valid(ptr))
83056+ return NULL;
83057+
83058+ page = virt_to_head_page(ptr);
83059+
83060+ if (!PageSlab(page))
83061+ return NULL;
83062+
83063+ cachep = page->slab_cache;
83064+ if (!(cachep->flags & SLAB_USERCOPY))
83065+ return cachep->name;
83066+
83067+ slabp = page->slab_page;
83068+ objnr = obj_to_index(cachep, slabp, ptr);
83069+ BUG_ON(objnr >= cachep->num);
83070+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
83071+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
83072+ return NULL;
83073+
83074+ return cachep->name;
83075+}
83076+#endif
83077+
83078 /**
83079 * ksize - get the actual amount of memory allocated for a given object
83080 * @objp: Pointer to the object
83081diff --git a/mm/slab.h b/mm/slab.h
83082index 34a98d6..73633d1 100644
83083--- a/mm/slab.h
83084+++ b/mm/slab.h
83085@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83086
83087 /* Legal flag mask for kmem_cache_create(), for various configurations */
83088 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
83089- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
83090+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
83091
83092 #if defined(CONFIG_DEBUG_SLAB)
83093 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
83094@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
83095 return s;
83096
83097 page = virt_to_head_page(x);
83098+
83099+ BUG_ON(!PageSlab(page));
83100+
83101 cachep = page->slab_cache;
83102 if (slab_equal_or_root(cachep, s))
83103 return cachep;
83104diff --git a/mm/slab_common.c b/mm/slab_common.c
83105index 3f3cd97..93b0236 100644
83106--- a/mm/slab_common.c
83107+++ b/mm/slab_common.c
83108@@ -22,7 +22,7 @@
83109
83110 #include "slab.h"
83111
83112-enum slab_state slab_state;
83113+enum slab_state slab_state __read_only;
83114 LIST_HEAD(slab_caches);
83115 DEFINE_MUTEX(slab_mutex);
83116 struct kmem_cache *kmem_cache;
83117@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
83118
83119 err = __kmem_cache_create(s, flags);
83120 if (!err) {
83121- s->refcount = 1;
83122+ atomic_set(&s->refcount, 1);
83123 list_add(&s->list, &slab_caches);
83124 memcg_cache_list_add(memcg, s);
83125 } else {
83126@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
83127
83128 get_online_cpus();
83129 mutex_lock(&slab_mutex);
83130- s->refcount--;
83131- if (!s->refcount) {
83132+ if (atomic_dec_and_test(&s->refcount)) {
83133 list_del(&s->list);
83134
83135 if (!__kmem_cache_shutdown(s)) {
83136@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
83137 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
83138 name, size, err);
83139
83140- s->refcount = -1; /* Exempt from merging for now */
83141+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
83142 }
83143
83144 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83145@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83146
83147 create_boot_cache(s, name, size, flags);
83148 list_add(&s->list, &slab_caches);
83149- s->refcount = 1;
83150+ atomic_set(&s->refcount, 1);
83151 return s;
83152 }
83153
83154diff --git a/mm/slob.c b/mm/slob.c
83155index a99fdf7..f5b6577 100644
83156--- a/mm/slob.c
83157+++ b/mm/slob.c
83158@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
83159 /*
83160 * Return the size of a slob block.
83161 */
83162-static slobidx_t slob_units(slob_t *s)
83163+static slobidx_t slob_units(const slob_t *s)
83164 {
83165 if (s->units > 0)
83166 return s->units;
83167@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
83168 /*
83169 * Return the next free slob block pointer after this one.
83170 */
83171-static slob_t *slob_next(slob_t *s)
83172+static slob_t *slob_next(const slob_t *s)
83173 {
83174 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
83175 slobidx_t next;
83176@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
83177 /*
83178 * Returns true if s is the last free block in its page.
83179 */
83180-static int slob_last(slob_t *s)
83181+static int slob_last(const slob_t *s)
83182 {
83183 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
83184 }
83185
83186-static void *slob_new_pages(gfp_t gfp, int order, int node)
83187+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
83188 {
83189- void *page;
83190+ struct page *page;
83191
83192 #ifdef CONFIG_NUMA
83193 if (node != NUMA_NO_NODE)
83194@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
83195 if (!page)
83196 return NULL;
83197
83198- return page_address(page);
83199+ __SetPageSlab(page);
83200+ return page;
83201 }
83202
83203-static void slob_free_pages(void *b, int order)
83204+static void slob_free_pages(struct page *sp, int order)
83205 {
83206 if (current->reclaim_state)
83207 current->reclaim_state->reclaimed_slab += 1 << order;
83208- free_pages((unsigned long)b, order);
83209+ __ClearPageSlab(sp);
83210+ reset_page_mapcount(sp);
83211+ sp->private = 0;
83212+ __free_pages(sp, order);
83213 }
83214
83215 /*
83216@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
83217
83218 /* Not enough space: must allocate a new page */
83219 if (!b) {
83220- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83221- if (!b)
83222+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83223+ if (!sp)
83224 return NULL;
83225- sp = virt_to_page(b);
83226- __SetPageSlab(sp);
83227+ b = page_address(sp);
83228
83229 spin_lock_irqsave(&slob_lock, flags);
83230 sp->units = SLOB_UNITS(PAGE_SIZE);
83231 sp->freelist = b;
83232+ sp->private = 0;
83233 INIT_LIST_HEAD(&sp->list);
83234 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
83235 set_slob_page_free(sp, slob_list);
83236@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
83237 if (slob_page_free(sp))
83238 clear_slob_page_free(sp);
83239 spin_unlock_irqrestore(&slob_lock, flags);
83240- __ClearPageSlab(sp);
83241- reset_page_mapcount(sp);
83242- slob_free_pages(b, 0);
83243+ slob_free_pages(sp, 0);
83244 return;
83245 }
83246
83247@@ -424,11 +426,10 @@ out:
83248 */
83249
83250 static __always_inline void *
83251-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83252+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
83253 {
83254- unsigned int *m;
83255- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83256- void *ret;
83257+ slob_t *m;
83258+ void *ret = NULL;
83259
83260 gfp &= gfp_allowed_mask;
83261
83262@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83263
83264 if (!m)
83265 return NULL;
83266- *m = size;
83267+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
83268+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
83269+ m[0].units = size;
83270+ m[1].units = align;
83271 ret = (void *)m + align;
83272
83273 trace_kmalloc_node(caller, ret,
83274 size, size + align, gfp, node);
83275 } else {
83276 unsigned int order = get_order(size);
83277+ struct page *page;
83278
83279 if (likely(order))
83280 gfp |= __GFP_COMP;
83281- ret = slob_new_pages(gfp, order, node);
83282+ page = slob_new_pages(gfp, order, node);
83283+ if (page) {
83284+ ret = page_address(page);
83285+ page->private = size;
83286+ }
83287
83288 trace_kmalloc_node(caller, ret,
83289 size, PAGE_SIZE << order, gfp, node);
83290 }
83291
83292- kmemleak_alloc(ret, size, 1, gfp);
83293+ return ret;
83294+}
83295+
83296+static __always_inline void *
83297+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83298+{
83299+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83300+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
83301+
83302+ if (!ZERO_OR_NULL_PTR(ret))
83303+ kmemleak_alloc(ret, size, 1, gfp);
83304 return ret;
83305 }
83306
83307@@ -494,33 +513,110 @@ void kfree(const void *block)
83308 kmemleak_free(block);
83309
83310 sp = virt_to_page(block);
83311- if (PageSlab(sp)) {
83312+ VM_BUG_ON(!PageSlab(sp));
83313+ if (!sp->private) {
83314 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83315- unsigned int *m = (unsigned int *)(block - align);
83316- slob_free(m, *m + align);
83317- } else
83318+ slob_t *m = (slob_t *)(block - align);
83319+ slob_free(m, m[0].units + align);
83320+ } else {
83321+ __ClearPageSlab(sp);
83322+ reset_page_mapcount(sp);
83323+ sp->private = 0;
83324 __free_pages(sp, compound_order(sp));
83325+ }
83326 }
83327 EXPORT_SYMBOL(kfree);
83328
83329+bool is_usercopy_object(const void *ptr)
83330+{
83331+ if (!slab_is_available())
83332+ return false;
83333+
83334+ // PAX: TODO
83335+
83336+ return false;
83337+}
83338+
83339+#ifdef CONFIG_PAX_USERCOPY
83340+const char *check_heap_object(const void *ptr, unsigned long n)
83341+{
83342+ struct page *page;
83343+ const slob_t *free;
83344+ const void *base;
83345+ unsigned long flags;
83346+
83347+ if (ZERO_OR_NULL_PTR(ptr))
83348+ return "<null>";
83349+
83350+ if (!virt_addr_valid(ptr))
83351+ return NULL;
83352+
83353+ page = virt_to_head_page(ptr);
83354+ if (!PageSlab(page))
83355+ return NULL;
83356+
83357+ if (page->private) {
83358+ base = page;
83359+ if (base <= ptr && n <= page->private - (ptr - base))
83360+ return NULL;
83361+ return "<slob>";
83362+ }
83363+
83364+ /* some tricky double walking to find the chunk */
83365+ spin_lock_irqsave(&slob_lock, flags);
83366+ base = (void *)((unsigned long)ptr & PAGE_MASK);
83367+ free = page->freelist;
83368+
83369+ while (!slob_last(free) && (void *)free <= ptr) {
83370+ base = free + slob_units(free);
83371+ free = slob_next(free);
83372+ }
83373+
83374+ while (base < (void *)free) {
83375+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
83376+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
83377+ int offset;
83378+
83379+ if (ptr < base + align)
83380+ break;
83381+
83382+ offset = ptr - base - align;
83383+ if (offset >= m) {
83384+ base += size;
83385+ continue;
83386+ }
83387+
83388+ if (n > m - offset)
83389+ break;
83390+
83391+ spin_unlock_irqrestore(&slob_lock, flags);
83392+ return NULL;
83393+ }
83394+
83395+ spin_unlock_irqrestore(&slob_lock, flags);
83396+ return "<slob>";
83397+}
83398+#endif
83399+
83400 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
83401 size_t ksize(const void *block)
83402 {
83403 struct page *sp;
83404 int align;
83405- unsigned int *m;
83406+ slob_t *m;
83407
83408 BUG_ON(!block);
83409 if (unlikely(block == ZERO_SIZE_PTR))
83410 return 0;
83411
83412 sp = virt_to_page(block);
83413- if (unlikely(!PageSlab(sp)))
83414- return PAGE_SIZE << compound_order(sp);
83415+ VM_BUG_ON(!PageSlab(sp));
83416+ if (sp->private)
83417+ return sp->private;
83418
83419 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83420- m = (unsigned int *)(block - align);
83421- return SLOB_UNITS(*m) * SLOB_UNIT;
83422+ m = (slob_t *)(block - align);
83423+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
83424 }
83425 EXPORT_SYMBOL(ksize);
83426
83427@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
83428
83429 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
83430 {
83431- void *b;
83432+ void *b = NULL;
83433
83434 flags &= gfp_allowed_mask;
83435
83436 lockdep_trace_alloc(flags);
83437
83438+#ifdef CONFIG_PAX_USERCOPY_SLABS
83439+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
83440+#else
83441 if (c->size < PAGE_SIZE) {
83442 b = slob_alloc(c->size, flags, c->align, node);
83443 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83444 SLOB_UNITS(c->size) * SLOB_UNIT,
83445 flags, node);
83446 } else {
83447- b = slob_new_pages(flags, get_order(c->size), node);
83448+ struct page *sp;
83449+
83450+ sp = slob_new_pages(flags, get_order(c->size), node);
83451+ if (sp) {
83452+ b = page_address(sp);
83453+ sp->private = c->size;
83454+ }
83455 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83456 PAGE_SIZE << get_order(c->size),
83457 flags, node);
83458 }
83459+#endif
83460
83461 if (c->ctor)
83462 c->ctor(b);
83463@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
83464
83465 static void __kmem_cache_free(void *b, int size)
83466 {
83467- if (size < PAGE_SIZE)
83468+ struct page *sp;
83469+
83470+ sp = virt_to_page(b);
83471+ BUG_ON(!PageSlab(sp));
83472+ if (!sp->private)
83473 slob_free(b, size);
83474 else
83475- slob_free_pages(b, get_order(size));
83476+ slob_free_pages(sp, get_order(size));
83477 }
83478
83479 static void kmem_rcu_free(struct rcu_head *head)
83480@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
83481
83482 void kmem_cache_free(struct kmem_cache *c, void *b)
83483 {
83484+ int size = c->size;
83485+
83486+#ifdef CONFIG_PAX_USERCOPY_SLABS
83487+ if (size + c->align < PAGE_SIZE) {
83488+ size += c->align;
83489+ b -= c->align;
83490+ }
83491+#endif
83492+
83493 kmemleak_free_recursive(b, c->flags);
83494 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
83495 struct slob_rcu *slob_rcu;
83496- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
83497- slob_rcu->size = c->size;
83498+ slob_rcu = b + (size - sizeof(struct slob_rcu));
83499+ slob_rcu->size = size;
83500 call_rcu(&slob_rcu->head, kmem_rcu_free);
83501 } else {
83502- __kmem_cache_free(b, c->size);
83503+ __kmem_cache_free(b, size);
83504 }
83505
83506+#ifdef CONFIG_PAX_USERCOPY_SLABS
83507+ trace_kfree(_RET_IP_, b);
83508+#else
83509 trace_kmem_cache_free(_RET_IP_, b);
83510+#endif
83511+
83512 }
83513 EXPORT_SYMBOL(kmem_cache_free);
83514
83515diff --git a/mm/slub.c b/mm/slub.c
83516index ba2ca53..00b1f4e 100644
83517--- a/mm/slub.c
83518+++ b/mm/slub.c
83519@@ -197,7 +197,7 @@ struct track {
83520
83521 enum track_item { TRACK_ALLOC, TRACK_FREE };
83522
83523-#ifdef CONFIG_SYSFS
83524+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83525 static int sysfs_slab_add(struct kmem_cache *);
83526 static int sysfs_slab_alias(struct kmem_cache *, const char *);
83527 static void sysfs_slab_remove(struct kmem_cache *);
83528@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
83529 if (!t->addr)
83530 return;
83531
83532- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
83533+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
83534 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
83535 #ifdef CONFIG_STACKTRACE
83536 {
83537@@ -2653,7 +2653,7 @@ static int slub_min_objects;
83538 * Merge control. If this is set then no merging of slab caches will occur.
83539 * (Could be removed. This was introduced to pacify the merge skeptics.)
83540 */
83541-static int slub_nomerge;
83542+static int slub_nomerge = 1;
83543
83544 /*
83545 * Calculate the order of allocation given an slab object size.
83546@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
83547 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
83548 #endif
83549
83550+#ifdef CONFIG_PAX_USERCOPY_SLABS
83551+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
83552+#endif
83553+
83554 static int __init setup_slub_min_order(char *str)
83555 {
83556 get_option(&str, &slub_min_order);
83557@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
83558 return kmalloc_dma_caches[index];
83559
83560 #endif
83561+
83562+#ifdef CONFIG_PAX_USERCOPY_SLABS
83563+ if (flags & SLAB_USERCOPY)
83564+ return kmalloc_usercopy_caches[index];
83565+
83566+#endif
83567+
83568 return kmalloc_caches[index];
83569 }
83570
83571@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
83572 EXPORT_SYMBOL(__kmalloc_node);
83573 #endif
83574
83575+bool is_usercopy_object(const void *ptr)
83576+{
83577+ struct page *page;
83578+ struct kmem_cache *s;
83579+
83580+ if (ZERO_OR_NULL_PTR(ptr))
83581+ return false;
83582+
83583+ if (!slab_is_available())
83584+ return false;
83585+
83586+ if (!virt_addr_valid(ptr))
83587+ return false;
83588+
83589+ page = virt_to_head_page(ptr);
83590+
83591+ if (!PageSlab(page))
83592+ return false;
83593+
83594+ s = page->slab_cache;
83595+ return s->flags & SLAB_USERCOPY;
83596+}
83597+
83598+#ifdef CONFIG_PAX_USERCOPY
83599+const char *check_heap_object(const void *ptr, unsigned long n)
83600+{
83601+ struct page *page;
83602+ struct kmem_cache *s;
83603+ unsigned long offset;
83604+
83605+ if (ZERO_OR_NULL_PTR(ptr))
83606+ return "<null>";
83607+
83608+ if (!virt_addr_valid(ptr))
83609+ return NULL;
83610+
83611+ page = virt_to_head_page(ptr);
83612+
83613+ if (!PageSlab(page))
83614+ return NULL;
83615+
83616+ s = page->slab_cache;
83617+ if (!(s->flags & SLAB_USERCOPY))
83618+ return s->name;
83619+
83620+ offset = (ptr - page_address(page)) % s->size;
83621+ if (offset <= s->object_size && n <= s->object_size - offset)
83622+ return NULL;
83623+
83624+ return s->name;
83625+}
83626+#endif
83627+
83628 size_t ksize(const void *object)
83629 {
83630 struct page *page;
83631@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
83632
83633 /* Caches that are not of the two-to-the-power-of size */
83634 if (KMALLOC_MIN_SIZE <= 32) {
83635- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
83636+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
83637 caches++;
83638 }
83639
83640 if (KMALLOC_MIN_SIZE <= 64) {
83641- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
83642+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
83643 caches++;
83644 }
83645
83646 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
83647- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
83648+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
83649 caches++;
83650 }
83651
83652@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
83653 }
83654 }
83655 #endif
83656+
83657+#ifdef CONFIG_PAX_USERCOPY_SLABS
83658+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
83659+ struct kmem_cache *s = kmalloc_caches[i];
83660+
83661+ if (s && s->size) {
83662+ char *name = kasprintf(GFP_NOWAIT,
83663+ "usercopy-kmalloc-%d", s->object_size);
83664+
83665+ BUG_ON(!name);
83666+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
83667+ s->object_size, SLAB_USERCOPY);
83668+ }
83669+ }
83670+#endif
83671+
83672 printk(KERN_INFO
83673 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
83674 " CPUs=%d, Nodes=%d\n",
83675@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
83676 /*
83677 * We may have set a slab to be unmergeable during bootstrap.
83678 */
83679- if (s->refcount < 0)
83680+ if (atomic_read(&s->refcount) < 0)
83681 return 1;
83682
83683 return 0;
83684@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83685
83686 s = find_mergeable(memcg, size, align, flags, name, ctor);
83687 if (s) {
83688- s->refcount++;
83689+ atomic_inc(&s->refcount);
83690 /*
83691 * Adjust the object sizes so that we clear
83692 * the complete object on kzalloc.
83693@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83694 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
83695
83696 if (sysfs_slab_alias(s, name)) {
83697- s->refcount--;
83698+ atomic_dec(&s->refcount);
83699 s = NULL;
83700 }
83701 }
83702@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
83703 return NOTIFY_OK;
83704 }
83705
83706-static struct notifier_block __cpuinitdata slab_notifier = {
83707+static struct notifier_block slab_notifier = {
83708 .notifier_call = slab_cpuup_callback
83709 };
83710
83711@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
83712 }
83713 #endif
83714
83715-#ifdef CONFIG_SYSFS
83716+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83717 static int count_inuse(struct page *page)
83718 {
83719 return page->inuse;
83720@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
83721 validate_slab_cache(kmalloc_caches[9]);
83722 }
83723 #else
83724-#ifdef CONFIG_SYSFS
83725+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83726 static void resiliency_test(void) {};
83727 #endif
83728 #endif
83729
83730-#ifdef CONFIG_SYSFS
83731+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83732 enum slab_stat_type {
83733 SL_ALL, /* All slabs */
83734 SL_PARTIAL, /* Only partially allocated slabs */
83735@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
83736
83737 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
83738 {
83739- return sprintf(buf, "%d\n", s->refcount - 1);
83740+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
83741 }
83742 SLAB_ATTR_RO(aliases);
83743
83744@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
83745 return name;
83746 }
83747
83748+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83749 static int sysfs_slab_add(struct kmem_cache *s)
83750 {
83751 int err;
83752@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
83753 kobject_del(&s->kobj);
83754 kobject_put(&s->kobj);
83755 }
83756+#endif
83757
83758 /*
83759 * Need to buffer aliases during bootup until sysfs becomes
83760@@ -5336,6 +5418,7 @@ struct saved_alias {
83761
83762 static struct saved_alias *alias_list;
83763
83764+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83765 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83766 {
83767 struct saved_alias *al;
83768@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83769 alias_list = al;
83770 return 0;
83771 }
83772+#endif
83773
83774 static int __init slab_sysfs_init(void)
83775 {
83776diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
83777index 1b7e22a..3fcd4f3 100644
83778--- a/mm/sparse-vmemmap.c
83779+++ b/mm/sparse-vmemmap.c
83780@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
83781 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83782 if (!p)
83783 return NULL;
83784- pud_populate(&init_mm, pud, p);
83785+ pud_populate_kernel(&init_mm, pud, p);
83786 }
83787 return pud;
83788 }
83789@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
83790 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83791 if (!p)
83792 return NULL;
83793- pgd_populate(&init_mm, pgd, p);
83794+ pgd_populate_kernel(&init_mm, pgd, p);
83795 }
83796 return pgd;
83797 }
83798diff --git a/mm/sparse.c b/mm/sparse.c
83799index 6b5fb76..db0c190 100644
83800--- a/mm/sparse.c
83801+++ b/mm/sparse.c
83802@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
83803
83804 for (i = 0; i < PAGES_PER_SECTION; i++) {
83805 if (PageHWPoison(&memmap[i])) {
83806- atomic_long_sub(1, &mce_bad_pages);
83807+ atomic_long_sub_unchecked(1, &mce_bad_pages);
83808 ClearPageHWPoison(&memmap[i]);
83809 }
83810 }
83811diff --git a/mm/swap.c b/mm/swap.c
83812index 6310dc2..3662b3f 100644
83813--- a/mm/swap.c
83814+++ b/mm/swap.c
83815@@ -30,6 +30,7 @@
83816 #include <linux/backing-dev.h>
83817 #include <linux/memcontrol.h>
83818 #include <linux/gfp.h>
83819+#include <linux/hugetlb.h>
83820
83821 #include "internal.h"
83822
83823@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
83824
83825 __page_cache_release(page);
83826 dtor = get_compound_page_dtor(page);
83827+ if (!PageHuge(page))
83828+ BUG_ON(dtor != free_compound_page);
83829 (*dtor)(page);
83830 }
83831
83832diff --git a/mm/swapfile.c b/mm/swapfile.c
83833index e97a0e5..b50e796 100644
83834--- a/mm/swapfile.c
83835+++ b/mm/swapfile.c
83836@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
83837
83838 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
83839 /* Activity counter to indicate that a swapon or swapoff has occurred */
83840-static atomic_t proc_poll_event = ATOMIC_INIT(0);
83841+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
83842
83843 static inline unsigned char swap_count(unsigned char ent)
83844 {
83845@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
83846 }
83847 filp_close(swap_file, NULL);
83848 err = 0;
83849- atomic_inc(&proc_poll_event);
83850+ atomic_inc_unchecked(&proc_poll_event);
83851 wake_up_interruptible(&proc_poll_wait);
83852
83853 out_dput:
83854@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
83855
83856 poll_wait(file, &proc_poll_wait, wait);
83857
83858- if (seq->poll_event != atomic_read(&proc_poll_event)) {
83859- seq->poll_event = atomic_read(&proc_poll_event);
83860+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
83861+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83862 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
83863 }
83864
83865@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
83866 return ret;
83867
83868 seq = file->private_data;
83869- seq->poll_event = atomic_read(&proc_poll_event);
83870+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83871 return 0;
83872 }
83873
83874@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
83875 (frontswap_map) ? "FS" : "");
83876
83877 mutex_unlock(&swapon_mutex);
83878- atomic_inc(&proc_poll_event);
83879+ atomic_inc_unchecked(&proc_poll_event);
83880 wake_up_interruptible(&proc_poll_wait);
83881
83882 if (S_ISREG(inode->i_mode))
83883diff --git a/mm/util.c b/mm/util.c
83884index c55e26b..3f913a9 100644
83885--- a/mm/util.c
83886+++ b/mm/util.c
83887@@ -292,6 +292,12 @@ done:
83888 void arch_pick_mmap_layout(struct mm_struct *mm)
83889 {
83890 mm->mmap_base = TASK_UNMAPPED_BASE;
83891+
83892+#ifdef CONFIG_PAX_RANDMMAP
83893+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83894+ mm->mmap_base += mm->delta_mmap;
83895+#endif
83896+
83897 mm->get_unmapped_area = arch_get_unmapped_area;
83898 mm->unmap_area = arch_unmap_area;
83899 }
83900diff --git a/mm/vmalloc.c b/mm/vmalloc.c
83901index 5123a16..f234a48 100644
83902--- a/mm/vmalloc.c
83903+++ b/mm/vmalloc.c
83904@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
83905
83906 pte = pte_offset_kernel(pmd, addr);
83907 do {
83908- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83909- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83910+
83911+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83912+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
83913+ BUG_ON(!pte_exec(*pte));
83914+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
83915+ continue;
83916+ }
83917+#endif
83918+
83919+ {
83920+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83921+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83922+ }
83923 } while (pte++, addr += PAGE_SIZE, addr != end);
83924 }
83925
83926@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
83927 pte = pte_alloc_kernel(pmd, addr);
83928 if (!pte)
83929 return -ENOMEM;
83930+
83931+ pax_open_kernel();
83932 do {
83933 struct page *page = pages[*nr];
83934
83935- if (WARN_ON(!pte_none(*pte)))
83936+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83937+ if (pgprot_val(prot) & _PAGE_NX)
83938+#endif
83939+
83940+ if (!pte_none(*pte)) {
83941+ pax_close_kernel();
83942+ WARN_ON(1);
83943 return -EBUSY;
83944- if (WARN_ON(!page))
83945+ }
83946+ if (!page) {
83947+ pax_close_kernel();
83948+ WARN_ON(1);
83949 return -ENOMEM;
83950+ }
83951 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
83952 (*nr)++;
83953 } while (pte++, addr += PAGE_SIZE, addr != end);
83954+ pax_close_kernel();
83955 return 0;
83956 }
83957
83958@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
83959 pmd_t *pmd;
83960 unsigned long next;
83961
83962- pmd = pmd_alloc(&init_mm, pud, addr);
83963+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
83964 if (!pmd)
83965 return -ENOMEM;
83966 do {
83967@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
83968 pud_t *pud;
83969 unsigned long next;
83970
83971- pud = pud_alloc(&init_mm, pgd, addr);
83972+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
83973 if (!pud)
83974 return -ENOMEM;
83975 do {
83976@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
83977 * and fall back on vmalloc() if that fails. Others
83978 * just put it in the vmalloc space.
83979 */
83980-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
83981+#ifdef CONFIG_MODULES
83982+#ifdef MODULES_VADDR
83983 unsigned long addr = (unsigned long)x;
83984 if (addr >= MODULES_VADDR && addr < MODULES_END)
83985 return 1;
83986 #endif
83987+
83988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83989+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
83990+ return 1;
83991+#endif
83992+
83993+#endif
83994+
83995 return is_vmalloc_addr(x);
83996 }
83997
83998@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
83999
84000 if (!pgd_none(*pgd)) {
84001 pud_t *pud = pud_offset(pgd, addr);
84002+#ifdef CONFIG_X86
84003+ if (!pud_large(*pud))
84004+#endif
84005 if (!pud_none(*pud)) {
84006 pmd_t *pmd = pmd_offset(pud, addr);
84007+#ifdef CONFIG_X86
84008+ if (!pmd_large(*pmd))
84009+#endif
84010 if (!pmd_none(*pmd)) {
84011 pte_t *ptep, pte;
84012
84013@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
84014 * Allocate a region of KVA of the specified size and alignment, within the
84015 * vstart and vend.
84016 */
84017-static struct vmap_area *alloc_vmap_area(unsigned long size,
84018+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
84019 unsigned long align,
84020 unsigned long vstart, unsigned long vend,
84021 int node, gfp_t gfp_mask)
84022@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
84023 struct vm_struct *area;
84024
84025 BUG_ON(in_interrupt());
84026+
84027+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84028+ if (flags & VM_KERNEXEC) {
84029+ if (start != VMALLOC_START || end != VMALLOC_END)
84030+ return NULL;
84031+ start = (unsigned long)MODULES_EXEC_VADDR;
84032+ end = (unsigned long)MODULES_EXEC_END;
84033+ }
84034+#endif
84035+
84036 if (flags & VM_IOREMAP) {
84037 int bit = fls(size);
84038
84039@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
84040 if (count > totalram_pages)
84041 return NULL;
84042
84043+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84044+ if (!(pgprot_val(prot) & _PAGE_NX))
84045+ flags |= VM_KERNEXEC;
84046+#endif
84047+
84048 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
84049 __builtin_return_address(0));
84050 if (!area)
84051@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
84052 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
84053 goto fail;
84054
84055+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84056+ if (!(pgprot_val(prot) & _PAGE_NX))
84057+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
84058+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
84059+ else
84060+#endif
84061+
84062 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
84063 start, end, node, gfp_mask, caller);
84064 if (!area)
84065@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
84066 * For tight control over page level allocator and protection flags
84067 * use __vmalloc() instead.
84068 */
84069-
84070 void *vmalloc_exec(unsigned long size)
84071 {
84072- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
84073+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
84074 -1, __builtin_return_address(0));
84075 }
84076
84077@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
84078 unsigned long uaddr = vma->vm_start;
84079 unsigned long usize = vma->vm_end - vma->vm_start;
84080
84081+ BUG_ON(vma->vm_mirror);
84082+
84083 if ((PAGE_SIZE-1) & (unsigned long)addr)
84084 return -EINVAL;
84085
84086@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
84087 v->addr, v->addr + v->size, v->size);
84088
84089 if (v->caller)
84090+#ifdef CONFIG_GRKERNSEC_HIDESYM
84091+ seq_printf(m, " %pK", v->caller);
84092+#else
84093 seq_printf(m, " %pS", v->caller);
84094+#endif
84095
84096 if (v->nr_pages)
84097 seq_printf(m, " pages=%d", v->nr_pages);
84098diff --git a/mm/vmstat.c b/mm/vmstat.c
84099index 9800306..76b4b27 100644
84100--- a/mm/vmstat.c
84101+++ b/mm/vmstat.c
84102@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
84103 *
84104 * vm_stat contains the global counters
84105 */
84106-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84107+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84108 EXPORT_SYMBOL(vm_stat);
84109
84110 #ifdef CONFIG_SMP
84111@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
84112 v = p->vm_stat_diff[i];
84113 p->vm_stat_diff[i] = 0;
84114 local_irq_restore(flags);
84115- atomic_long_add(v, &zone->vm_stat[i]);
84116+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84117 global_diff[i] += v;
84118 #ifdef CONFIG_NUMA
84119 /* 3 seconds idle till flush */
84120@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
84121
84122 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
84123 if (global_diff[i])
84124- atomic_long_add(global_diff[i], &vm_stat[i]);
84125+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
84126 }
84127
84128 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84129@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84130 if (pset->vm_stat_diff[i]) {
84131 int v = pset->vm_stat_diff[i];
84132 pset->vm_stat_diff[i] = 0;
84133- atomic_long_add(v, &zone->vm_stat[i]);
84134- atomic_long_add(v, &vm_stat[i]);
84135+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84136+ atomic_long_add_unchecked(v, &vm_stat[i]);
84137 }
84138 }
84139 #endif
84140@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
84141 return NOTIFY_OK;
84142 }
84143
84144-static struct notifier_block __cpuinitdata vmstat_notifier =
84145+static struct notifier_block vmstat_notifier =
84146 { &vmstat_cpuup_callback, NULL, 0 };
84147 #endif
84148
84149@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
84150 start_cpu_timer(cpu);
84151 #endif
84152 #ifdef CONFIG_PROC_FS
84153- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
84154- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
84155- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
84156- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
84157+ {
84158+ mode_t gr_mode = S_IRUGO;
84159+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84160+ gr_mode = S_IRUSR;
84161+#endif
84162+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
84163+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
84164+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84165+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
84166+#else
84167+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
84168+#endif
84169+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
84170+ }
84171 #endif
84172 return 0;
84173 }
84174diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
84175index a292e80..785ee68 100644
84176--- a/net/8021q/vlan.c
84177+++ b/net/8021q/vlan.c
84178@@ -485,7 +485,7 @@ out:
84179 return NOTIFY_DONE;
84180 }
84181
84182-static struct notifier_block vlan_notifier_block __read_mostly = {
84183+static struct notifier_block vlan_notifier_block = {
84184 .notifier_call = vlan_device_event,
84185 };
84186
84187@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
84188 err = -EPERM;
84189 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
84190 break;
84191- if ((args.u.name_type >= 0) &&
84192- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
84193+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
84194 struct vlan_net *vn;
84195
84196 vn = net_generic(net, vlan_net_id);
84197diff --git a/net/9p/mod.c b/net/9p/mod.c
84198index 6ab36ae..6f1841b 100644
84199--- a/net/9p/mod.c
84200+++ b/net/9p/mod.c
84201@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
84202 void v9fs_register_trans(struct p9_trans_module *m)
84203 {
84204 spin_lock(&v9fs_trans_lock);
84205- list_add_tail(&m->list, &v9fs_trans_list);
84206+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
84207 spin_unlock(&v9fs_trans_lock);
84208 }
84209 EXPORT_SYMBOL(v9fs_register_trans);
84210@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
84211 void v9fs_unregister_trans(struct p9_trans_module *m)
84212 {
84213 spin_lock(&v9fs_trans_lock);
84214- list_del_init(&m->list);
84215+ pax_list_del_init((struct list_head *)&m->list);
84216 spin_unlock(&v9fs_trans_lock);
84217 }
84218 EXPORT_SYMBOL(v9fs_unregister_trans);
84219diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
84220index 02efb25..41541a9 100644
84221--- a/net/9p/trans_fd.c
84222+++ b/net/9p/trans_fd.c
84223@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
84224 oldfs = get_fs();
84225 set_fs(get_ds());
84226 /* The cast to a user pointer is valid due to the set_fs() */
84227- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
84228+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
84229 set_fs(oldfs);
84230
84231 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
84232diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
84233index 876fbe8..8bbea9f 100644
84234--- a/net/atm/atm_misc.c
84235+++ b/net/atm/atm_misc.c
84236@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
84237 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
84238 return 1;
84239 atm_return(vcc, truesize);
84240- atomic_inc(&vcc->stats->rx_drop);
84241+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84242 return 0;
84243 }
84244 EXPORT_SYMBOL(atm_charge);
84245@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
84246 }
84247 }
84248 atm_return(vcc, guess);
84249- atomic_inc(&vcc->stats->rx_drop);
84250+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84251 return NULL;
84252 }
84253 EXPORT_SYMBOL(atm_alloc_charge);
84254@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
84255
84256 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84257 {
84258-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84259+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84260 __SONET_ITEMS
84261 #undef __HANDLE_ITEM
84262 }
84263@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
84264
84265 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84266 {
84267-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84268+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
84269 __SONET_ITEMS
84270 #undef __HANDLE_ITEM
84271 }
84272diff --git a/net/atm/lec.h b/net/atm/lec.h
84273index a86aff9..3a0d6f6 100644
84274--- a/net/atm/lec.h
84275+++ b/net/atm/lec.h
84276@@ -48,7 +48,7 @@ struct lane2_ops {
84277 const u8 *tlvs, u32 sizeoftlvs);
84278 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
84279 const u8 *tlvs, u32 sizeoftlvs);
84280-};
84281+} __no_const;
84282
84283 /*
84284 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
84285diff --git a/net/atm/proc.c b/net/atm/proc.c
84286index 0d020de..011c7bb 100644
84287--- a/net/atm/proc.c
84288+++ b/net/atm/proc.c
84289@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
84290 const struct k_atm_aal_stats *stats)
84291 {
84292 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
84293- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
84294- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
84295- atomic_read(&stats->rx_drop));
84296+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
84297+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
84298+ atomic_read_unchecked(&stats->rx_drop));
84299 }
84300
84301 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
84302diff --git a/net/atm/resources.c b/net/atm/resources.c
84303index 0447d5d..3cf4728 100644
84304--- a/net/atm/resources.c
84305+++ b/net/atm/resources.c
84306@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
84307 static void copy_aal_stats(struct k_atm_aal_stats *from,
84308 struct atm_aal_stats *to)
84309 {
84310-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84311+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84312 __AAL_STAT_ITEMS
84313 #undef __HANDLE_ITEM
84314 }
84315@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
84316 static void subtract_aal_stats(struct k_atm_aal_stats *from,
84317 struct atm_aal_stats *to)
84318 {
84319-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84320+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
84321 __AAL_STAT_ITEMS
84322 #undef __HANDLE_ITEM
84323 }
84324diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
84325index d5744b7..506bae3 100644
84326--- a/net/ax25/sysctl_net_ax25.c
84327+++ b/net/ax25/sysctl_net_ax25.c
84328@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
84329 {
84330 char path[sizeof("net/ax25/") + IFNAMSIZ];
84331 int k;
84332- struct ctl_table *table;
84333+ ctl_table_no_const *table;
84334
84335 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
84336 if (!table)
84337diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
84338index 7d02ebd..4d4cc01 100644
84339--- a/net/batman-adv/bat_iv_ogm.c
84340+++ b/net/batman-adv/bat_iv_ogm.c
84341@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
84342
84343 /* randomize initial seqno to avoid collision */
84344 get_random_bytes(&random_seqno, sizeof(random_seqno));
84345- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84346+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84347
84348 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
84349 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
84350@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
84351 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
84352
84353 /* change sequence number to network order */
84354- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
84355+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
84356 batadv_ogm_packet->seqno = htonl(seqno);
84357- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
84358+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
84359
84360 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
84361 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
84362@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
84363 return;
84364
84365 /* could be changed by schedule_own_packet() */
84366- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
84367+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
84368
84369 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
84370 has_directlink_flag = 1;
84371diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
84372index f1d37cd..4190879 100644
84373--- a/net/batman-adv/hard-interface.c
84374+++ b/net/batman-adv/hard-interface.c
84375@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
84376 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
84377 dev_add_pack(&hard_iface->batman_adv_ptype);
84378
84379- atomic_set(&hard_iface->frag_seqno, 1);
84380+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
84381 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
84382 hard_iface->net_dev->name);
84383
84384@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
84385 /* This can't be called via a bat_priv callback because
84386 * we have no bat_priv yet.
84387 */
84388- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
84389+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
84390 hard_iface->bat_iv.ogm_buff = NULL;
84391
84392 return hard_iface;
84393diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
84394index 6b548fd..fc32c8d 100644
84395--- a/net/batman-adv/soft-interface.c
84396+++ b/net/batman-adv/soft-interface.c
84397@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
84398 primary_if->net_dev->dev_addr, ETH_ALEN);
84399
84400 /* set broadcast sequence number */
84401- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
84402+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
84403 bcast_packet->seqno = htonl(seqno);
84404
84405 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
84406@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
84407 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
84408
84409 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
84410- atomic_set(&bat_priv->bcast_seqno, 1);
84411+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
84412 atomic_set(&bat_priv->tt.vn, 0);
84413 atomic_set(&bat_priv->tt.local_changes, 0);
84414 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
84415diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
84416index ae9ac9a..11e0fe7 100644
84417--- a/net/batman-adv/types.h
84418+++ b/net/batman-adv/types.h
84419@@ -48,7 +48,7 @@
84420 struct batadv_hard_iface_bat_iv {
84421 unsigned char *ogm_buff;
84422 int ogm_buff_len;
84423- atomic_t ogm_seqno;
84424+ atomic_unchecked_t ogm_seqno;
84425 };
84426
84427 struct batadv_hard_iface {
84428@@ -56,7 +56,7 @@ struct batadv_hard_iface {
84429 int16_t if_num;
84430 char if_status;
84431 struct net_device *net_dev;
84432- atomic_t frag_seqno;
84433+ atomic_unchecked_t frag_seqno;
84434 struct kobject *hardif_obj;
84435 atomic_t refcount;
84436 struct packet_type batman_adv_ptype;
84437@@ -284,7 +284,7 @@ struct batadv_priv {
84438 atomic_t orig_interval; /* uint */
84439 atomic_t hop_penalty; /* uint */
84440 atomic_t log_level; /* uint */
84441- atomic_t bcast_seqno;
84442+ atomic_unchecked_t bcast_seqno;
84443 atomic_t bcast_queue_left;
84444 atomic_t batman_queue_left;
84445 char num_ifaces;
84446diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
84447index 10aff49..ea8e021 100644
84448--- a/net/batman-adv/unicast.c
84449+++ b/net/batman-adv/unicast.c
84450@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
84451 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
84452 frag2->flags = large_tail;
84453
84454- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
84455+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
84456 frag1->seqno = htons(seqno - 1);
84457 frag2->seqno = htons(seqno);
84458
84459diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
84460index 07f0739..3c42e34 100644
84461--- a/net/bluetooth/hci_sock.c
84462+++ b/net/bluetooth/hci_sock.c
84463@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
84464 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
84465 }
84466
84467- len = min_t(unsigned int, len, sizeof(uf));
84468+ len = min((size_t)len, sizeof(uf));
84469 if (copy_from_user(&uf, optval, len)) {
84470 err = -EFAULT;
84471 break;
84472diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
84473index 22e6583..426e2f3 100644
84474--- a/net/bluetooth/l2cap_core.c
84475+++ b/net/bluetooth/l2cap_core.c
84476@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
84477 break;
84478
84479 case L2CAP_CONF_RFC:
84480- if (olen == sizeof(rfc))
84481- memcpy(&rfc, (void *)val, olen);
84482+ if (olen != sizeof(rfc))
84483+ break;
84484+
84485+ memcpy(&rfc, (void *)val, olen);
84486
84487 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
84488 rfc.mode != chan->mode)
84489diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
84490index 1bcfb84..dad9f98 100644
84491--- a/net/bluetooth/l2cap_sock.c
84492+++ b/net/bluetooth/l2cap_sock.c
84493@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84494 struct sock *sk = sock->sk;
84495 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
84496 struct l2cap_options opts;
84497- int len, err = 0;
84498+ int err = 0;
84499+ size_t len = optlen;
84500 u32 opt;
84501
84502 BT_DBG("sk %p", sk);
84503@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84504 opts.max_tx = chan->max_tx;
84505 opts.txwin_size = chan->tx_win;
84506
84507- len = min_t(unsigned int, sizeof(opts), optlen);
84508+ len = min(sizeof(opts), len);
84509 if (copy_from_user((char *) &opts, optval, len)) {
84510 err = -EFAULT;
84511 break;
84512@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84513 struct bt_security sec;
84514 struct bt_power pwr;
84515 struct l2cap_conn *conn;
84516- int len, err = 0;
84517+ int err = 0;
84518+ size_t len = optlen;
84519 u32 opt;
84520
84521 BT_DBG("sk %p", sk);
84522@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84523
84524 sec.level = BT_SECURITY_LOW;
84525
84526- len = min_t(unsigned int, sizeof(sec), optlen);
84527+ len = min(sizeof(sec), len);
84528 if (copy_from_user((char *) &sec, optval, len)) {
84529 err = -EFAULT;
84530 break;
84531@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84532
84533 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
84534
84535- len = min_t(unsigned int, sizeof(pwr), optlen);
84536+ len = min(sizeof(pwr), len);
84537 if (copy_from_user((char *) &pwr, optval, len)) {
84538 err = -EFAULT;
84539 break;
84540diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
84541index ce3f665..2c7d08f 100644
84542--- a/net/bluetooth/rfcomm/sock.c
84543+++ b/net/bluetooth/rfcomm/sock.c
84544@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84545 struct sock *sk = sock->sk;
84546 struct bt_security sec;
84547 int err = 0;
84548- size_t len;
84549+ size_t len = optlen;
84550 u32 opt;
84551
84552 BT_DBG("sk %p", sk);
84553@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84554
84555 sec.level = BT_SECURITY_LOW;
84556
84557- len = min_t(unsigned int, sizeof(sec), optlen);
84558+ len = min(sizeof(sec), len);
84559 if (copy_from_user((char *) &sec, optval, len)) {
84560 err = -EFAULT;
84561 break;
84562diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
84563index bd6fd0f..6492cba 100644
84564--- a/net/bluetooth/rfcomm/tty.c
84565+++ b/net/bluetooth/rfcomm/tty.c
84566@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
84567 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
84568
84569 spin_lock_irqsave(&dev->port.lock, flags);
84570- if (dev->port.count > 0) {
84571+ if (atomic_read(&dev->port.count) > 0) {
84572 spin_unlock_irqrestore(&dev->port.lock, flags);
84573 return;
84574 }
84575@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
84576 return -ENODEV;
84577
84578 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
84579- dev->channel, dev->port.count);
84580+ dev->channel, atomic_read(&dev->port.count));
84581
84582 spin_lock_irqsave(&dev->port.lock, flags);
84583- if (++dev->port.count > 1) {
84584+ if (atomic_inc_return(&dev->port.count) > 1) {
84585 spin_unlock_irqrestore(&dev->port.lock, flags);
84586 return 0;
84587 }
84588@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
84589 return;
84590
84591 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
84592- dev->port.count);
84593+ atomic_read(&dev->port.count));
84594
84595 spin_lock_irqsave(&dev->port.lock, flags);
84596- if (!--dev->port.count) {
84597+ if (!atomic_dec_return(&dev->port.count)) {
84598 spin_unlock_irqrestore(&dev->port.lock, flags);
84599 if (dev->tty_dev->parent)
84600 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
84601diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
84602index 5fe2ff3..121d696 100644
84603--- a/net/bridge/netfilter/ebtables.c
84604+++ b/net/bridge/netfilter/ebtables.c
84605@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
84606 tmp.valid_hooks = t->table->valid_hooks;
84607 }
84608 mutex_unlock(&ebt_mutex);
84609- if (copy_to_user(user, &tmp, *len) != 0){
84610+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
84611 BUGPRINT("c2u Didn't work\n");
84612 ret = -EFAULT;
84613 break;
84614@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84615 goto out;
84616 tmp.valid_hooks = t->valid_hooks;
84617
84618- if (copy_to_user(user, &tmp, *len) != 0) {
84619+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84620 ret = -EFAULT;
84621 break;
84622 }
84623@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84624 tmp.entries_size = t->table->entries_size;
84625 tmp.valid_hooks = t->table->valid_hooks;
84626
84627- if (copy_to_user(user, &tmp, *len) != 0) {
84628+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84629 ret = -EFAULT;
84630 break;
84631 }
84632diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
84633index a376ec1..1fbd6be 100644
84634--- a/net/caif/cfctrl.c
84635+++ b/net/caif/cfctrl.c
84636@@ -10,6 +10,7 @@
84637 #include <linux/spinlock.h>
84638 #include <linux/slab.h>
84639 #include <linux/pkt_sched.h>
84640+#include <linux/sched.h>
84641 #include <net/caif/caif_layer.h>
84642 #include <net/caif/cfpkt.h>
84643 #include <net/caif/cfctrl.h>
84644@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
84645 memset(&dev_info, 0, sizeof(dev_info));
84646 dev_info.id = 0xff;
84647 cfsrvl_init(&this->serv, 0, &dev_info, false);
84648- atomic_set(&this->req_seq_no, 1);
84649- atomic_set(&this->rsp_seq_no, 1);
84650+ atomic_set_unchecked(&this->req_seq_no, 1);
84651+ atomic_set_unchecked(&this->rsp_seq_no, 1);
84652 this->serv.layer.receive = cfctrl_recv;
84653 sprintf(this->serv.layer.name, "ctrl");
84654 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
84655@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
84656 struct cfctrl_request_info *req)
84657 {
84658 spin_lock_bh(&ctrl->info_list_lock);
84659- atomic_inc(&ctrl->req_seq_no);
84660- req->sequence_no = atomic_read(&ctrl->req_seq_no);
84661+ atomic_inc_unchecked(&ctrl->req_seq_no);
84662+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
84663 list_add_tail(&req->list, &ctrl->list);
84664 spin_unlock_bh(&ctrl->info_list_lock);
84665 }
84666@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
84667 if (p != first)
84668 pr_warn("Requests are not received in order\n");
84669
84670- atomic_set(&ctrl->rsp_seq_no,
84671+ atomic_set_unchecked(&ctrl->rsp_seq_no,
84672 p->sequence_no);
84673 list_del(&p->list);
84674 goto out;
84675diff --git a/net/can/af_can.c b/net/can/af_can.c
84676index ddac1ee..3ee0a78 100644
84677--- a/net/can/af_can.c
84678+++ b/net/can/af_can.c
84679@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
84680 };
84681
84682 /* notifier block for netdevice event */
84683-static struct notifier_block can_netdev_notifier __read_mostly = {
84684+static struct notifier_block can_netdev_notifier = {
84685 .notifier_call = can_notifier,
84686 };
84687
84688diff --git a/net/can/gw.c b/net/can/gw.c
84689index 574dda78e..3d2b3da 100644
84690--- a/net/can/gw.c
84691+++ b/net/can/gw.c
84692@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
84693 MODULE_ALIAS("can-gw");
84694
84695 static HLIST_HEAD(cgw_list);
84696-static struct notifier_block notifier;
84697
84698 static struct kmem_cache *cgw_cache __read_mostly;
84699
84700@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
84701 return err;
84702 }
84703
84704+static struct notifier_block notifier = {
84705+ .notifier_call = cgw_notifier
84706+};
84707+
84708 static __init int cgw_module_init(void)
84709 {
84710 printk(banner);
84711@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
84712 return -ENOMEM;
84713
84714 /* set notifier */
84715- notifier.notifier_call = cgw_notifier;
84716 register_netdevice_notifier(&notifier);
84717
84718 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
84719diff --git a/net/compat.c b/net/compat.c
84720index 79ae884..17c5c09 100644
84721--- a/net/compat.c
84722+++ b/net/compat.c
84723@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
84724 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
84725 __get_user(kmsg->msg_flags, &umsg->msg_flags))
84726 return -EFAULT;
84727- kmsg->msg_name = compat_ptr(tmp1);
84728- kmsg->msg_iov = compat_ptr(tmp2);
84729- kmsg->msg_control = compat_ptr(tmp3);
84730+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
84731+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
84732+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
84733 return 0;
84734 }
84735
84736@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84737
84738 if (kern_msg->msg_namelen) {
84739 if (mode == VERIFY_READ) {
84740- int err = move_addr_to_kernel(kern_msg->msg_name,
84741+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
84742 kern_msg->msg_namelen,
84743 kern_address);
84744 if (err < 0)
84745@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84746 kern_msg->msg_name = NULL;
84747
84748 tot_len = iov_from_user_compat_to_kern(kern_iov,
84749- (struct compat_iovec __user *)kern_msg->msg_iov,
84750+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
84751 kern_msg->msg_iovlen);
84752 if (tot_len >= 0)
84753 kern_msg->msg_iov = kern_iov;
84754@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84755
84756 #define CMSG_COMPAT_FIRSTHDR(msg) \
84757 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
84758- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
84759+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
84760 (struct compat_cmsghdr __user *)NULL)
84761
84762 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
84763 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
84764 (ucmlen) <= (unsigned long) \
84765 ((mhdr)->msg_controllen - \
84766- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
84767+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
84768
84769 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
84770 struct compat_cmsghdr __user *cmsg, int cmsg_len)
84771 {
84772 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
84773- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
84774+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
84775 msg->msg_controllen)
84776 return NULL;
84777 return (struct compat_cmsghdr __user *)ptr;
84778@@ -219,7 +219,7 @@ Efault:
84779
84780 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
84781 {
84782- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84783+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84784 struct compat_cmsghdr cmhdr;
84785 struct compat_timeval ctv;
84786 struct compat_timespec cts[3];
84787@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
84788
84789 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
84790 {
84791- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84792+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84793 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
84794 int fdnum = scm->fp->count;
84795 struct file **fp = scm->fp->fp;
84796@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
84797 return -EFAULT;
84798 old_fs = get_fs();
84799 set_fs(KERNEL_DS);
84800- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
84801+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
84802 set_fs(old_fs);
84803
84804 return err;
84805@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
84806 len = sizeof(ktime);
84807 old_fs = get_fs();
84808 set_fs(KERNEL_DS);
84809- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
84810+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
84811 set_fs(old_fs);
84812
84813 if (!err) {
84814@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84815 case MCAST_JOIN_GROUP:
84816 case MCAST_LEAVE_GROUP:
84817 {
84818- struct compat_group_req __user *gr32 = (void *)optval;
84819+ struct compat_group_req __user *gr32 = (void __user *)optval;
84820 struct group_req __user *kgr =
84821 compat_alloc_user_space(sizeof(struct group_req));
84822 u32 interface;
84823@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84824 case MCAST_BLOCK_SOURCE:
84825 case MCAST_UNBLOCK_SOURCE:
84826 {
84827- struct compat_group_source_req __user *gsr32 = (void *)optval;
84828+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
84829 struct group_source_req __user *kgsr = compat_alloc_user_space(
84830 sizeof(struct group_source_req));
84831 u32 interface;
84832@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84833 }
84834 case MCAST_MSFILTER:
84835 {
84836- struct compat_group_filter __user *gf32 = (void *)optval;
84837+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84838 struct group_filter __user *kgf;
84839 u32 interface, fmode, numsrc;
84840
84841@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
84842 char __user *optval, int __user *optlen,
84843 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
84844 {
84845- struct compat_group_filter __user *gf32 = (void *)optval;
84846+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84847 struct group_filter __user *kgf;
84848 int __user *koptlen;
84849 u32 interface, fmode, numsrc;
84850@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
84851
84852 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
84853 return -EINVAL;
84854- if (copy_from_user(a, args, nas[call]))
84855+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
84856 return -EFAULT;
84857 a0 = a[0];
84858 a1 = a[1];
84859diff --git a/net/core/datagram.c b/net/core/datagram.c
84860index 368f9c3..f82d4a3 100644
84861--- a/net/core/datagram.c
84862+++ b/net/core/datagram.c
84863@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
84864 }
84865
84866 kfree_skb(skb);
84867- atomic_inc(&sk->sk_drops);
84868+ atomic_inc_unchecked(&sk->sk_drops);
84869 sk_mem_reclaim_partial(sk);
84870
84871 return err;
84872diff --git a/net/core/dev.c b/net/core/dev.c
84873index 1339f77..6fd27dc 100644
84874--- a/net/core/dev.c
84875+++ b/net/core/dev.c
84876@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
84877 if (no_module && capable(CAP_NET_ADMIN))
84878 no_module = request_module("netdev-%s", name);
84879 if (no_module && capable(CAP_SYS_MODULE)) {
84880+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84881+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
84882+#else
84883 if (!request_module("%s", name))
84884 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
84885 name);
84886+#endif
84887 }
84888 }
84889 EXPORT_SYMBOL(dev_load);
84890@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84891 {
84892 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
84893 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
84894- atomic_long_inc(&dev->rx_dropped);
84895+ atomic_long_inc_unchecked(&dev->rx_dropped);
84896 kfree_skb(skb);
84897 return NET_RX_DROP;
84898 }
84899@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84900 nf_reset(skb);
84901
84902 if (unlikely(!is_skb_forwardable(dev, skb))) {
84903- atomic_long_inc(&dev->rx_dropped);
84904+ atomic_long_inc_unchecked(&dev->rx_dropped);
84905 kfree_skb(skb);
84906 return NET_RX_DROP;
84907 }
84908@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
84909
84910 struct dev_gso_cb {
84911 void (*destructor)(struct sk_buff *skb);
84912-};
84913+} __no_const;
84914
84915 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
84916
84917@@ -3053,7 +3057,7 @@ enqueue:
84918
84919 local_irq_restore(flags);
84920
84921- atomic_long_inc(&skb->dev->rx_dropped);
84922+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84923 kfree_skb(skb);
84924 return NET_RX_DROP;
84925 }
84926@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
84927 }
84928 EXPORT_SYMBOL(netif_rx_ni);
84929
84930-static void net_tx_action(struct softirq_action *h)
84931+static void net_tx_action(void)
84932 {
84933 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84934
84935@@ -3457,7 +3461,7 @@ ncls:
84936 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
84937 } else {
84938 drop:
84939- atomic_long_inc(&skb->dev->rx_dropped);
84940+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84941 kfree_skb(skb);
84942 /* Jamal, now you will not able to escape explaining
84943 * me how you were going to use this. :-)
84944@@ -4040,7 +4044,7 @@ void netif_napi_del(struct napi_struct *napi)
84945 }
84946 EXPORT_SYMBOL(netif_napi_del);
84947
84948-static void net_rx_action(struct softirq_action *h)
84949+static void net_rx_action(void)
84950 {
84951 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84952 unsigned long time_limit = jiffies + 2;
84953@@ -4524,8 +4528,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
84954 else
84955 seq_printf(seq, "%04x", ntohs(pt->type));
84956
84957+#ifdef CONFIG_GRKERNSEC_HIDESYM
84958+ seq_printf(seq, " %-8s %p\n",
84959+ pt->dev ? pt->dev->name : "", NULL);
84960+#else
84961 seq_printf(seq, " %-8s %pF\n",
84962 pt->dev ? pt->dev->name : "", pt->func);
84963+#endif
84964 }
84965
84966 return 0;
84967@@ -6097,7 +6106,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
84968 } else {
84969 netdev_stats_to_stats64(storage, &dev->stats);
84970 }
84971- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
84972+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
84973 return storage;
84974 }
84975 EXPORT_SYMBOL(dev_get_stats);
84976diff --git a/net/core/flow.c b/net/core/flow.c
84977index b0901ee..7d3c2ca 100644
84978--- a/net/core/flow.c
84979+++ b/net/core/flow.c
84980@@ -61,7 +61,7 @@ struct flow_cache {
84981 struct timer_list rnd_timer;
84982 };
84983
84984-atomic_t flow_cache_genid = ATOMIC_INIT(0);
84985+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
84986 EXPORT_SYMBOL(flow_cache_genid);
84987 static struct flow_cache flow_cache_global;
84988 static struct kmem_cache *flow_cachep __read_mostly;
84989@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
84990
84991 static int flow_entry_valid(struct flow_cache_entry *fle)
84992 {
84993- if (atomic_read(&flow_cache_genid) != fle->genid)
84994+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
84995 return 0;
84996 if (fle->object && !fle->object->ops->check(fle->object))
84997 return 0;
84998@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
84999 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
85000 fcp->hash_count++;
85001 }
85002- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
85003+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
85004 flo = fle->object;
85005 if (!flo)
85006 goto ret_object;
85007@@ -280,7 +280,7 @@ nocache:
85008 }
85009 flo = resolver(net, key, family, dir, flo, ctx);
85010 if (fle) {
85011- fle->genid = atomic_read(&flow_cache_genid);
85012+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
85013 if (!IS_ERR(flo))
85014 fle->object = flo;
85015 else
85016diff --git a/net/core/iovec.c b/net/core/iovec.c
85017index 7e7aeb0..2a998cb 100644
85018--- a/net/core/iovec.c
85019+++ b/net/core/iovec.c
85020@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85021 if (m->msg_namelen) {
85022 if (mode == VERIFY_READ) {
85023 void __user *namep;
85024- namep = (void __user __force *) m->msg_name;
85025+ namep = (void __force_user *) m->msg_name;
85026 err = move_addr_to_kernel(namep, m->msg_namelen,
85027 address);
85028 if (err < 0)
85029@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85030 }
85031
85032 size = m->msg_iovlen * sizeof(struct iovec);
85033- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
85034+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
85035 return -EFAULT;
85036
85037 m->msg_iov = iov;
85038diff --git a/net/core/neighbour.c b/net/core/neighbour.c
85039index c815f28..e6403f2 100644
85040--- a/net/core/neighbour.c
85041+++ b/net/core/neighbour.c
85042@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
85043 size_t *lenp, loff_t *ppos)
85044 {
85045 int size, ret;
85046- ctl_table tmp = *ctl;
85047+ ctl_table_no_const tmp = *ctl;
85048
85049 tmp.extra1 = &zero;
85050 tmp.extra2 = &unres_qlen_max;
85051diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
85052index 28c5f5a..7edf2e2 100644
85053--- a/net/core/net-sysfs.c
85054+++ b/net/core/net-sysfs.c
85055@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
85056 }
85057 EXPORT_SYMBOL(netdev_class_remove_file);
85058
85059-int netdev_kobject_init(void)
85060+int __init netdev_kobject_init(void)
85061 {
85062 kobj_ns_type_register(&net_ns_type_operations);
85063 return class_register(&net_class);
85064diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
85065index 8acce01..2e306bb 100644
85066--- a/net/core/net_namespace.c
85067+++ b/net/core/net_namespace.c
85068@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
85069 int error;
85070 LIST_HEAD(net_exit_list);
85071
85072- list_add_tail(&ops->list, list);
85073+ pax_list_add_tail((struct list_head *)&ops->list, list);
85074 if (ops->init || (ops->id && ops->size)) {
85075 for_each_net(net) {
85076 error = ops_init(ops, net);
85077@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
85078
85079 out_undo:
85080 /* If I have an error cleanup all namespaces I initialized */
85081- list_del(&ops->list);
85082+ pax_list_del((struct list_head *)&ops->list);
85083 ops_exit_list(ops, &net_exit_list);
85084 ops_free_list(ops, &net_exit_list);
85085 return error;
85086@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
85087 struct net *net;
85088 LIST_HEAD(net_exit_list);
85089
85090- list_del(&ops->list);
85091+ pax_list_del((struct list_head *)&ops->list);
85092 for_each_net(net)
85093 list_add_tail(&net->exit_list, &net_exit_list);
85094 ops_exit_list(ops, &net_exit_list);
85095@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
85096 mutex_lock(&net_mutex);
85097 error = register_pernet_operations(&pernet_list, ops);
85098 if (!error && (first_device == &pernet_list))
85099- first_device = &ops->list;
85100+ first_device = (struct list_head *)&ops->list;
85101 mutex_unlock(&net_mutex);
85102 return error;
85103 }
85104diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
85105index 798f920..e2261f5 100644
85106--- a/net/core/rtnetlink.c
85107+++ b/net/core/rtnetlink.c
85108@@ -58,7 +58,7 @@ struct rtnl_link {
85109 rtnl_doit_func doit;
85110 rtnl_dumpit_func dumpit;
85111 rtnl_calcit_func calcit;
85112-};
85113+} __no_const;
85114
85115 static DEFINE_MUTEX(rtnl_mutex);
85116
85117@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
85118 if (rtnl_link_ops_get(ops->kind))
85119 return -EEXIST;
85120
85121- if (!ops->dellink)
85122- ops->dellink = unregister_netdevice_queue;
85123+ if (!ops->dellink) {
85124+ pax_open_kernel();
85125+ *(void **)&ops->dellink = unregister_netdevice_queue;
85126+ pax_close_kernel();
85127+ }
85128
85129- list_add_tail(&ops->list, &link_ops);
85130+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
85131 return 0;
85132 }
85133 EXPORT_SYMBOL_GPL(__rtnl_link_register);
85134@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
85135 for_each_net(net) {
85136 __rtnl_kill_links(net, ops);
85137 }
85138- list_del(&ops->list);
85139+ pax_list_del((struct list_head *)&ops->list);
85140 }
85141 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
85142
85143diff --git a/net/core/scm.c b/net/core/scm.c
85144index 905dcc6..14ee2d6 100644
85145--- a/net/core/scm.c
85146+++ b/net/core/scm.c
85147@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
85148 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85149 {
85150 struct cmsghdr __user *cm
85151- = (__force struct cmsghdr __user *)msg->msg_control;
85152+ = (struct cmsghdr __force_user *)msg->msg_control;
85153 struct cmsghdr cmhdr;
85154 int cmlen = CMSG_LEN(len);
85155 int err;
85156@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85157 err = -EFAULT;
85158 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
85159 goto out;
85160- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
85161+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
85162 goto out;
85163 cmlen = CMSG_SPACE(len);
85164 if (msg->msg_controllen < cmlen)
85165@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
85166 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85167 {
85168 struct cmsghdr __user *cm
85169- = (__force struct cmsghdr __user*)msg->msg_control;
85170+ = (struct cmsghdr __force_user *)msg->msg_control;
85171
85172 int fdmax = 0;
85173 int fdnum = scm->fp->count;
85174@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85175 if (fdnum < fdmax)
85176 fdmax = fdnum;
85177
85178- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
85179+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
85180 i++, cmfptr++)
85181 {
85182 struct socket *sock;
85183diff --git a/net/core/sock.c b/net/core/sock.c
85184index bc131d4..029e378 100644
85185--- a/net/core/sock.c
85186+++ b/net/core/sock.c
85187@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85188 struct sk_buff_head *list = &sk->sk_receive_queue;
85189
85190 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
85191- atomic_inc(&sk->sk_drops);
85192+ atomic_inc_unchecked(&sk->sk_drops);
85193 trace_sock_rcvqueue_full(sk, skb);
85194 return -ENOMEM;
85195 }
85196@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85197 return err;
85198
85199 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
85200- atomic_inc(&sk->sk_drops);
85201+ atomic_inc_unchecked(&sk->sk_drops);
85202 return -ENOBUFS;
85203 }
85204
85205@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85206 skb_dst_force(skb);
85207
85208 spin_lock_irqsave(&list->lock, flags);
85209- skb->dropcount = atomic_read(&sk->sk_drops);
85210+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
85211 __skb_queue_tail(list, skb);
85212 spin_unlock_irqrestore(&list->lock, flags);
85213
85214@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85215 skb->dev = NULL;
85216
85217 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
85218- atomic_inc(&sk->sk_drops);
85219+ atomic_inc_unchecked(&sk->sk_drops);
85220 goto discard_and_relse;
85221 }
85222 if (nested)
85223@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85224 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
85225 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
85226 bh_unlock_sock(sk);
85227- atomic_inc(&sk->sk_drops);
85228+ atomic_inc_unchecked(&sk->sk_drops);
85229 goto discard_and_relse;
85230 }
85231
85232@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85233 struct timeval tm;
85234 } v;
85235
85236- int lv = sizeof(int);
85237- int len;
85238+ unsigned int lv = sizeof(int);
85239+ unsigned int len;
85240
85241 if (get_user(len, optlen))
85242 return -EFAULT;
85243- if (len < 0)
85244+ if (len > INT_MAX)
85245 return -EINVAL;
85246
85247 memset(&v, 0, sizeof(v));
85248@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85249
85250 case SO_PEERNAME:
85251 {
85252- char address[128];
85253+ char address[_K_SS_MAXSIZE];
85254
85255 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
85256 return -ENOTCONN;
85257- if (lv < len)
85258+ if (lv < len || sizeof address < len)
85259 return -EINVAL;
85260 if (copy_to_user(optval, address, len))
85261 return -EFAULT;
85262@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85263
85264 if (len > lv)
85265 len = lv;
85266- if (copy_to_user(optval, &v, len))
85267+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
85268 return -EFAULT;
85269 lenout:
85270 if (put_user(len, optlen))
85271@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
85272 */
85273 smp_wmb();
85274 atomic_set(&sk->sk_refcnt, 1);
85275- atomic_set(&sk->sk_drops, 0);
85276+ atomic_set_unchecked(&sk->sk_drops, 0);
85277 }
85278 EXPORT_SYMBOL(sock_init_data);
85279
85280diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
85281index 750f44f..922399c 100644
85282--- a/net/core/sock_diag.c
85283+++ b/net/core/sock_diag.c
85284@@ -9,26 +9,33 @@
85285 #include <linux/inet_diag.h>
85286 #include <linux/sock_diag.h>
85287
85288-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
85289+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
85290 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
85291 static DEFINE_MUTEX(sock_diag_table_mutex);
85292
85293 int sock_diag_check_cookie(void *sk, __u32 *cookie)
85294 {
85295+#ifndef CONFIG_GRKERNSEC_HIDESYM
85296 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
85297 cookie[1] != INET_DIAG_NOCOOKIE) &&
85298 ((u32)(unsigned long)sk != cookie[0] ||
85299 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
85300 return -ESTALE;
85301 else
85302+#endif
85303 return 0;
85304 }
85305 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
85306
85307 void sock_diag_save_cookie(void *sk, __u32 *cookie)
85308 {
85309+#ifdef CONFIG_GRKERNSEC_HIDESYM
85310+ cookie[0] = 0;
85311+ cookie[1] = 0;
85312+#else
85313 cookie[0] = (u32)(unsigned long)sk;
85314 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
85315+#endif
85316 }
85317 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
85318
85319@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
85320 mutex_lock(&sock_diag_table_mutex);
85321 if (sock_diag_handlers[hndl->family])
85322 err = -EBUSY;
85323- else
85324+ else {
85325+ pax_open_kernel();
85326 sock_diag_handlers[hndl->family] = hndl;
85327+ pax_close_kernel();
85328+ }
85329 mutex_unlock(&sock_diag_table_mutex);
85330
85331 return err;
85332@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
85333
85334 mutex_lock(&sock_diag_table_mutex);
85335 BUG_ON(sock_diag_handlers[family] != hnld);
85336+ pax_open_kernel();
85337 sock_diag_handlers[family] = NULL;
85338+ pax_close_kernel();
85339 mutex_unlock(&sock_diag_table_mutex);
85340 }
85341 EXPORT_SYMBOL_GPL(sock_diag_unregister);
85342
85343-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
85344-{
85345- if (sock_diag_handlers[family] == NULL)
85346- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85347- NETLINK_SOCK_DIAG, family);
85348-
85349- mutex_lock(&sock_diag_table_mutex);
85350- return sock_diag_handlers[family];
85351-}
85352-
85353-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
85354-{
85355- mutex_unlock(&sock_diag_table_mutex);
85356-}
85357-
85358 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85359 {
85360 int err;
85361@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85362 if (req->sdiag_family >= AF_MAX)
85363 return -EINVAL;
85364
85365- hndl = sock_diag_lock_handler(req->sdiag_family);
85366+ if (sock_diag_handlers[req->sdiag_family] == NULL)
85367+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85368+ NETLINK_SOCK_DIAG, req->sdiag_family);
85369+
85370+ mutex_lock(&sock_diag_table_mutex);
85371+ hndl = sock_diag_handlers[req->sdiag_family];
85372 if (hndl == NULL)
85373 err = -ENOENT;
85374 else
85375 err = hndl->dump(skb, nlh);
85376- sock_diag_unlock_handler(hndl);
85377+ mutex_unlock(&sock_diag_table_mutex);
85378
85379 return err;
85380 }
85381diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
85382index d1b0804..4aed0a5 100644
85383--- a/net/core/sysctl_net_core.c
85384+++ b/net/core/sysctl_net_core.c
85385@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
85386 {
85387 unsigned int orig_size, size;
85388 int ret, i;
85389- ctl_table tmp = {
85390+ ctl_table_no_const tmp = {
85391 .data = &size,
85392 .maxlen = sizeof(size),
85393 .mode = table->mode
85394@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
85395
85396 static __net_init int sysctl_core_net_init(struct net *net)
85397 {
85398- struct ctl_table *tbl;
85399+ ctl_table_no_const *tbl = NULL;
85400
85401 net->core.sysctl_somaxconn = SOMAXCONN;
85402
85403- tbl = netns_core_table;
85404 if (!net_eq(net, &init_net)) {
85405- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
85406+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
85407 if (tbl == NULL)
85408 goto err_dup;
85409
85410@@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
85411 if (net->user_ns != &init_user_ns) {
85412 tbl[0].procname = NULL;
85413 }
85414- }
85415-
85416- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85417+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85418+ } else
85419+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
85420 if (net->core.sysctl_hdr == NULL)
85421 goto err_reg;
85422
85423 return 0;
85424
85425 err_reg:
85426- if (tbl != netns_core_table)
85427+ if (tbl)
85428 kfree(tbl);
85429 err_dup:
85430 return -ENOMEM;
85431@@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
85432 kfree(tbl);
85433 }
85434
85435-static __net_initdata struct pernet_operations sysctl_core_ops = {
85436+static __net_initconst struct pernet_operations sysctl_core_ops = {
85437 .init = sysctl_core_net_init,
85438 .exit = sysctl_core_net_exit,
85439 };
85440diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
85441index 307c322..78a4c6f 100644
85442--- a/net/decnet/af_decnet.c
85443+++ b/net/decnet/af_decnet.c
85444@@ -468,6 +468,7 @@ static struct proto dn_proto = {
85445 .sysctl_rmem = sysctl_decnet_rmem,
85446 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
85447 .obj_size = sizeof(struct dn_sock),
85448+ .slab_flags = SLAB_USERCOPY,
85449 };
85450
85451 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
85452diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
85453index a55eecc..dd8428c 100644
85454--- a/net/decnet/sysctl_net_decnet.c
85455+++ b/net/decnet/sysctl_net_decnet.c
85456@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
85457
85458 if (len > *lenp) len = *lenp;
85459
85460- if (copy_to_user(buffer, addr, len))
85461+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
85462 return -EFAULT;
85463
85464 *lenp = len;
85465@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
85466
85467 if (len > *lenp) len = *lenp;
85468
85469- if (copy_to_user(buffer, devname, len))
85470+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
85471 return -EFAULT;
85472
85473 *lenp = len;
85474diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
85475index fcf104e..95552d4 100644
85476--- a/net/ipv4/af_inet.c
85477+++ b/net/ipv4/af_inet.c
85478@@ -1717,13 +1717,9 @@ static int __init inet_init(void)
85479
85480 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
85481
85482- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
85483- if (!sysctl_local_reserved_ports)
85484- goto out;
85485-
85486 rc = proto_register(&tcp_prot, 1);
85487 if (rc)
85488- goto out_free_reserved_ports;
85489+ goto out;
85490
85491 rc = proto_register(&udp_prot, 1);
85492 if (rc)
85493@@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
85494 proto_unregister(&udp_prot);
85495 out_unregister_tcp_proto:
85496 proto_unregister(&tcp_prot);
85497-out_free_reserved_ports:
85498- kfree(sysctl_local_reserved_ports);
85499 goto out;
85500 }
85501
85502diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
85503index a69b4e4..dbccba5 100644
85504--- a/net/ipv4/ah4.c
85505+++ b/net/ipv4/ah4.c
85506@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
85507 return;
85508
85509 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85510- atomic_inc(&flow_cache_genid);
85511+ atomic_inc_unchecked(&flow_cache_genid);
85512 rt_genid_bump(net);
85513
85514 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
85515diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
85516index a8e4f26..25e5f40 100644
85517--- a/net/ipv4/devinet.c
85518+++ b/net/ipv4/devinet.c
85519@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
85520 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
85521 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
85522
85523-static struct devinet_sysctl_table {
85524+static const struct devinet_sysctl_table {
85525 struct ctl_table_header *sysctl_header;
85526 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
85527 } devinet_sysctl = {
85528@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
85529 int err;
85530 struct ipv4_devconf *all, *dflt;
85531 #ifdef CONFIG_SYSCTL
85532- struct ctl_table *tbl = ctl_forward_entry;
85533+ ctl_table_no_const *tbl = NULL;
85534 struct ctl_table_header *forw_hdr;
85535 #endif
85536
85537@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
85538 goto err_alloc_dflt;
85539
85540 #ifdef CONFIG_SYSCTL
85541- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
85542+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
85543 if (tbl == NULL)
85544 goto err_alloc_ctl;
85545
85546@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
85547 goto err_reg_dflt;
85548
85549 err = -ENOMEM;
85550- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85551+ if (!net_eq(net, &init_net))
85552+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85553+ else
85554+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
85555 if (forw_hdr == NULL)
85556 goto err_reg_ctl;
85557 net->ipv4.forw_hdr = forw_hdr;
85558@@ -1935,8 +1938,7 @@ err_reg_ctl:
85559 err_reg_dflt:
85560 __devinet_sysctl_unregister(all);
85561 err_reg_all:
85562- if (tbl != ctl_forward_entry)
85563- kfree(tbl);
85564+ kfree(tbl);
85565 err_alloc_ctl:
85566 #endif
85567 if (dflt != &ipv4_devconf_dflt)
85568diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
85569index 3b4f0cd..8cb864c 100644
85570--- a/net/ipv4/esp4.c
85571+++ b/net/ipv4/esp4.c
85572@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
85573 return;
85574
85575 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85576- atomic_inc(&flow_cache_genid);
85577+ atomic_inc_unchecked(&flow_cache_genid);
85578 rt_genid_bump(net);
85579
85580 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
85581diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
85582index 5cd75e2..f57ef39 100644
85583--- a/net/ipv4/fib_frontend.c
85584+++ b/net/ipv4/fib_frontend.c
85585@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
85586 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85587 fib_sync_up(dev);
85588 #endif
85589- atomic_inc(&net->ipv4.dev_addr_genid);
85590+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85591 rt_cache_flush(dev_net(dev));
85592 break;
85593 case NETDEV_DOWN:
85594 fib_del_ifaddr(ifa, NULL);
85595- atomic_inc(&net->ipv4.dev_addr_genid);
85596+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85597 if (ifa->ifa_dev->ifa_list == NULL) {
85598 /* Last address was deleted from this interface.
85599 * Disable IP.
85600@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
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(net);
85607 break;
85608 case NETDEV_DOWN:
85609diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
85610index 4797a80..2bd54e9 100644
85611--- a/net/ipv4/fib_semantics.c
85612+++ b/net/ipv4/fib_semantics.c
85613@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
85614 nh->nh_saddr = inet_select_addr(nh->nh_dev,
85615 nh->nh_gw,
85616 nh->nh_parent->fib_scope);
85617- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
85618+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
85619
85620 return nh->nh_saddr;
85621 }
85622diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
85623index d0670f0..744ac80 100644
85624--- a/net/ipv4/inet_connection_sock.c
85625+++ b/net/ipv4/inet_connection_sock.c
85626@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
85627 .range = { 32768, 61000 },
85628 };
85629
85630-unsigned long *sysctl_local_reserved_ports;
85631+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
85632 EXPORT_SYMBOL(sysctl_local_reserved_ports);
85633
85634 void inet_get_local_port_range(int *low, int *high)
85635diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
85636index fa3ae81..0dbe6b8 100644
85637--- a/net/ipv4/inet_hashtables.c
85638+++ b/net/ipv4/inet_hashtables.c
85639@@ -18,12 +18,15 @@
85640 #include <linux/sched.h>
85641 #include <linux/slab.h>
85642 #include <linux/wait.h>
85643+#include <linux/security.h>
85644
85645 #include <net/inet_connection_sock.h>
85646 #include <net/inet_hashtables.h>
85647 #include <net/secure_seq.h>
85648 #include <net/ip.h>
85649
85650+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
85651+
85652 /*
85653 * Allocate and initialize a new local port bind bucket.
85654 * The bindhash mutex for snum's hash chain must be held here.
85655@@ -540,6 +543,8 @@ ok:
85656 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
85657 spin_unlock(&head->lock);
85658
85659+ gr_update_task_in_ip_table(current, inet_sk(sk));
85660+
85661 if (tw) {
85662 inet_twsk_deschedule(tw, death_row);
85663 while (twrefcnt) {
85664diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
85665index 000e3d2..5472da3 100644
85666--- a/net/ipv4/inetpeer.c
85667+++ b/net/ipv4/inetpeer.c
85668@@ -503,8 +503,8 @@ relookup:
85669 if (p) {
85670 p->daddr = *daddr;
85671 atomic_set(&p->refcnt, 1);
85672- atomic_set(&p->rid, 0);
85673- atomic_set(&p->ip_id_count,
85674+ atomic_set_unchecked(&p->rid, 0);
85675+ atomic_set_unchecked(&p->ip_id_count,
85676 (daddr->family == AF_INET) ?
85677 secure_ip_id(daddr->addr.a4) :
85678 secure_ipv6_id(daddr->addr.a6));
85679diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
85680index eb9d63a..31c5372 100644
85681--- a/net/ipv4/ip_fragment.c
85682+++ b/net/ipv4/ip_fragment.c
85683@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
85684 return 0;
85685
85686 start = qp->rid;
85687- end = atomic_inc_return(&peer->rid);
85688+ end = atomic_inc_return_unchecked(&peer->rid);
85689 qp->rid = end;
85690
85691 rc = qp->q.fragments && (end - start) > max;
85692@@ -789,12 +789,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
85693
85694 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85695 {
85696- struct ctl_table *table;
85697+ ctl_table_no_const *table = NULL;
85698 struct ctl_table_header *hdr;
85699
85700- table = ip4_frags_ns_ctl_table;
85701 if (!net_eq(net, &init_net)) {
85702- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85703+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85704 if (table == NULL)
85705 goto err_alloc;
85706
85707@@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85708 /* Don't export sysctls to unprivileged users */
85709 if (net->user_ns != &init_user_ns)
85710 table[0].procname = NULL;
85711- }
85712+ hdr = register_net_sysctl(net, "net/ipv4", table);
85713+ } else
85714+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
85715
85716- hdr = register_net_sysctl(net, "net/ipv4", table);
85717 if (hdr == NULL)
85718 goto err_reg;
85719
85720@@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85721 return 0;
85722
85723 err_reg:
85724- if (!net_eq(net, &init_net))
85725- kfree(table);
85726+ kfree(table);
85727 err_alloc:
85728 return -ENOMEM;
85729 }
85730diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
85731index e81b1ca..6f3b5b9 100644
85732--- a/net/ipv4/ip_gre.c
85733+++ b/net/ipv4/ip_gre.c
85734@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85735 module_param(log_ecn_error, bool, 0644);
85736 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85737
85738-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85739+static struct rtnl_link_ops ipgre_link_ops;
85740 static int ipgre_tunnel_init(struct net_device *dev);
85741 static void ipgre_tunnel_setup(struct net_device *dev);
85742 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85743@@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85744 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85745 };
85746
85747-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85748+static struct rtnl_link_ops ipgre_link_ops = {
85749 .kind = "gre",
85750 .maxtype = IFLA_GRE_MAX,
85751 .policy = ipgre_policy,
85752@@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85753 .fill_info = ipgre_fill_info,
85754 };
85755
85756-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85757+static struct rtnl_link_ops ipgre_tap_ops = {
85758 .kind = "gretap",
85759 .maxtype = IFLA_GRE_MAX,
85760 .policy = ipgre_policy,
85761diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85762index d9c4f11..02b82db 100644
85763--- a/net/ipv4/ip_sockglue.c
85764+++ b/net/ipv4/ip_sockglue.c
85765@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85766 len = min_t(unsigned int, len, opt->optlen);
85767 if (put_user(len, optlen))
85768 return -EFAULT;
85769- if (copy_to_user(optval, opt->__data, len))
85770+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85771+ copy_to_user(optval, opt->__data, len))
85772 return -EFAULT;
85773 return 0;
85774 }
85775@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85776 if (sk->sk_type != SOCK_STREAM)
85777 return -ENOPROTOOPT;
85778
85779- msg.msg_control = optval;
85780+ msg.msg_control = (void __force_kernel *)optval;
85781 msg.msg_controllen = len;
85782 msg.msg_flags = flags;
85783
85784diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85785index c3a4233..1412161 100644
85786--- a/net/ipv4/ip_vti.c
85787+++ b/net/ipv4/ip_vti.c
85788@@ -47,7 +47,7 @@
85789 #define HASH_SIZE 16
85790 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
85791
85792-static struct rtnl_link_ops vti_link_ops __read_mostly;
85793+static struct rtnl_link_ops vti_link_ops;
85794
85795 static int vti_net_id __read_mostly;
85796 struct vti_net {
85797@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
85798 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
85799 };
85800
85801-static struct rtnl_link_ops vti_link_ops __read_mostly = {
85802+static struct rtnl_link_ops vti_link_ops = {
85803 .kind = "vti",
85804 .maxtype = IFLA_VTI_MAX,
85805 .policy = vti_policy,
85806diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
85807index 9a46dae..5f793a0 100644
85808--- a/net/ipv4/ipcomp.c
85809+++ b/net/ipv4/ipcomp.c
85810@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
85811 return;
85812
85813 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85814- atomic_inc(&flow_cache_genid);
85815+ atomic_inc_unchecked(&flow_cache_genid);
85816 rt_genid_bump(net);
85817
85818 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
85819diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
85820index a2e50ae..e152b7c 100644
85821--- a/net/ipv4/ipconfig.c
85822+++ b/net/ipv4/ipconfig.c
85823@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
85824
85825 mm_segment_t oldfs = get_fs();
85826 set_fs(get_ds());
85827- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85828+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85829 set_fs(oldfs);
85830 return res;
85831 }
85832@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
85833
85834 mm_segment_t oldfs = get_fs();
85835 set_fs(get_ds());
85836- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85837+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85838 set_fs(oldfs);
85839 return res;
85840 }
85841@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
85842
85843 mm_segment_t oldfs = get_fs();
85844 set_fs(get_ds());
85845- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
85846+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
85847 set_fs(oldfs);
85848 return res;
85849 }
85850diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
85851index 191fc24..1b3b804 100644
85852--- a/net/ipv4/ipip.c
85853+++ b/net/ipv4/ipip.c
85854@@ -138,7 +138,7 @@ struct ipip_net {
85855 static int ipip_tunnel_init(struct net_device *dev);
85856 static void ipip_tunnel_setup(struct net_device *dev);
85857 static void ipip_dev_free(struct net_device *dev);
85858-static struct rtnl_link_ops ipip_link_ops __read_mostly;
85859+static struct rtnl_link_ops ipip_link_ops;
85860
85861 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
85862 struct rtnl_link_stats64 *tot)
85863@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
85864 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
85865 };
85866
85867-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
85868+static struct rtnl_link_ops ipip_link_ops = {
85869 .kind = "ipip",
85870 .maxtype = IFLA_IPTUN_MAX,
85871 .policy = ipip_policy,
85872diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
85873index 3ea4127..849297b 100644
85874--- a/net/ipv4/netfilter/arp_tables.c
85875+++ b/net/ipv4/netfilter/arp_tables.c
85876@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
85877 #endif
85878
85879 static int get_info(struct net *net, void __user *user,
85880- const int *len, int compat)
85881+ int len, int compat)
85882 {
85883 char name[XT_TABLE_MAXNAMELEN];
85884 struct xt_table *t;
85885 int ret;
85886
85887- if (*len != sizeof(struct arpt_getinfo)) {
85888- duprintf("length %u != %Zu\n", *len,
85889+ if (len != sizeof(struct arpt_getinfo)) {
85890+ duprintf("length %u != %Zu\n", len,
85891 sizeof(struct arpt_getinfo));
85892 return -EINVAL;
85893 }
85894@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
85895 info.size = private->size;
85896 strcpy(info.name, name);
85897
85898- if (copy_to_user(user, &info, *len) != 0)
85899+ if (copy_to_user(user, &info, len) != 0)
85900 ret = -EFAULT;
85901 else
85902 ret = 0;
85903@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
85904
85905 switch (cmd) {
85906 case ARPT_SO_GET_INFO:
85907- ret = get_info(sock_net(sk), user, len, 1);
85908+ ret = get_info(sock_net(sk), user, *len, 1);
85909 break;
85910 case ARPT_SO_GET_ENTRIES:
85911 ret = compat_get_entries(sock_net(sk), user, len);
85912@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
85913
85914 switch (cmd) {
85915 case ARPT_SO_GET_INFO:
85916- ret = get_info(sock_net(sk), user, len, 0);
85917+ ret = get_info(sock_net(sk), user, *len, 0);
85918 break;
85919
85920 case ARPT_SO_GET_ENTRIES:
85921diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
85922index 17c5e06..1b91206 100644
85923--- a/net/ipv4/netfilter/ip_tables.c
85924+++ b/net/ipv4/netfilter/ip_tables.c
85925@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
85926 #endif
85927
85928 static int get_info(struct net *net, void __user *user,
85929- const int *len, int compat)
85930+ int len, int compat)
85931 {
85932 char name[XT_TABLE_MAXNAMELEN];
85933 struct xt_table *t;
85934 int ret;
85935
85936- if (*len != sizeof(struct ipt_getinfo)) {
85937- duprintf("length %u != %zu\n", *len,
85938+ if (len != sizeof(struct ipt_getinfo)) {
85939+ duprintf("length %u != %zu\n", len,
85940 sizeof(struct ipt_getinfo));
85941 return -EINVAL;
85942 }
85943@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
85944 info.size = private->size;
85945 strcpy(info.name, name);
85946
85947- if (copy_to_user(user, &info, *len) != 0)
85948+ if (copy_to_user(user, &info, len) != 0)
85949 ret = -EFAULT;
85950 else
85951 ret = 0;
85952@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85953
85954 switch (cmd) {
85955 case IPT_SO_GET_INFO:
85956- ret = get_info(sock_net(sk), user, len, 1);
85957+ ret = get_info(sock_net(sk), user, *len, 1);
85958 break;
85959 case IPT_SO_GET_ENTRIES:
85960 ret = compat_get_entries(sock_net(sk), user, len);
85961@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85962
85963 switch (cmd) {
85964 case IPT_SO_GET_INFO:
85965- ret = get_info(sock_net(sk), user, len, 0);
85966+ ret = get_info(sock_net(sk), user, *len, 0);
85967 break;
85968
85969 case IPT_SO_GET_ENTRIES:
85970diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
85971index dc454cc..5bb917f 100644
85972--- a/net/ipv4/ping.c
85973+++ b/net/ipv4/ping.c
85974@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
85975 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85976 0, sock_i_ino(sp),
85977 atomic_read(&sp->sk_refcnt), sp,
85978- atomic_read(&sp->sk_drops), len);
85979+ atomic_read_unchecked(&sp->sk_drops), len);
85980 }
85981
85982 static int ping_seq_show(struct seq_file *seq, void *v)
85983diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
85984index 6f08991..55867ad 100644
85985--- a/net/ipv4/raw.c
85986+++ b/net/ipv4/raw.c
85987@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
85988 int raw_rcv(struct sock *sk, struct sk_buff *skb)
85989 {
85990 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
85991- atomic_inc(&sk->sk_drops);
85992+ atomic_inc_unchecked(&sk->sk_drops);
85993 kfree_skb(skb);
85994 return NET_RX_DROP;
85995 }
85996@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
85997
85998 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
85999 {
86000+ struct icmp_filter filter;
86001+
86002 if (optlen > sizeof(struct icmp_filter))
86003 optlen = sizeof(struct icmp_filter);
86004- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
86005+ if (copy_from_user(&filter, optval, optlen))
86006 return -EFAULT;
86007+ raw_sk(sk)->filter = filter;
86008 return 0;
86009 }
86010
86011 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
86012 {
86013 int len, ret = -EFAULT;
86014+ struct icmp_filter filter;
86015
86016 if (get_user(len, optlen))
86017 goto out;
86018@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
86019 if (len > sizeof(struct icmp_filter))
86020 len = sizeof(struct icmp_filter);
86021 ret = -EFAULT;
86022- if (put_user(len, optlen) ||
86023- copy_to_user(optval, &raw_sk(sk)->filter, len))
86024+ filter = raw_sk(sk)->filter;
86025+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
86026 goto out;
86027 ret = 0;
86028 out: return ret;
86029@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86030 0, 0L, 0,
86031 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86032 0, sock_i_ino(sp),
86033- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86034+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86035 }
86036
86037 static int raw_seq_show(struct seq_file *seq, void *v)
86038diff --git a/net/ipv4/route.c b/net/ipv4/route.c
86039index a0fcc47..32e2c89 100644
86040--- a/net/ipv4/route.c
86041+++ b/net/ipv4/route.c
86042@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
86043 .maxlen = sizeof(int),
86044 .mode = 0200,
86045 .proc_handler = ipv4_sysctl_rtcache_flush,
86046+ .extra1 = &init_net,
86047 },
86048 { },
86049 };
86050
86051 static __net_init int sysctl_route_net_init(struct net *net)
86052 {
86053- struct ctl_table *tbl;
86054+ ctl_table_no_const *tbl = NULL;
86055
86056- tbl = ipv4_route_flush_table;
86057 if (!net_eq(net, &init_net)) {
86058- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86059+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86060 if (tbl == NULL)
86061 goto err_dup;
86062
86063 /* Don't export sysctls to unprivileged users */
86064 if (net->user_ns != &init_user_ns)
86065 tbl[0].procname = NULL;
86066- }
86067- tbl[0].extra1 = net;
86068+ tbl[0].extra1 = net;
86069+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86070+ } else
86071+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
86072
86073- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86074 if (net->ipv4.route_hdr == NULL)
86075 goto err_reg;
86076 return 0;
86077
86078 err_reg:
86079- if (tbl != ipv4_route_flush_table)
86080- kfree(tbl);
86081+ kfree(tbl);
86082 err_dup:
86083 return -ENOMEM;
86084 }
86085@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
86086
86087 static __net_init int rt_genid_init(struct net *net)
86088 {
86089- atomic_set(&net->rt_genid, 0);
86090+ atomic_set_unchecked(&net->rt_genid, 0);
86091 get_random_bytes(&net->ipv4.dev_addr_genid,
86092 sizeof(net->ipv4.dev_addr_genid));
86093 return 0;
86094diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
86095index d84400b..62e066e 100644
86096--- a/net/ipv4/sysctl_net_ipv4.c
86097+++ b/net/ipv4/sysctl_net_ipv4.c
86098@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
86099 {
86100 int ret;
86101 int range[2];
86102- ctl_table tmp = {
86103+ ctl_table_no_const tmp = {
86104 .data = &range,
86105 .maxlen = sizeof(range),
86106 .mode = table->mode,
86107@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
86108 int ret;
86109 gid_t urange[2];
86110 kgid_t low, high;
86111- ctl_table tmp = {
86112+ ctl_table_no_const tmp = {
86113 .data = &urange,
86114 .maxlen = sizeof(urange),
86115 .mode = table->mode,
86116@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
86117 void __user *buffer, size_t *lenp, loff_t *ppos)
86118 {
86119 char val[TCP_CA_NAME_MAX];
86120- ctl_table tbl = {
86121+ ctl_table_no_const tbl = {
86122 .data = val,
86123 .maxlen = TCP_CA_NAME_MAX,
86124 };
86125@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
86126 void __user *buffer, size_t *lenp,
86127 loff_t *ppos)
86128 {
86129- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
86130+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
86131 int ret;
86132
86133 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86134@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
86135 void __user *buffer, size_t *lenp,
86136 loff_t *ppos)
86137 {
86138- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
86139+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
86140 int ret;
86141
86142 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86143@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86144 struct mem_cgroup *memcg;
86145 #endif
86146
86147- ctl_table tmp = {
86148+ ctl_table_no_const tmp = {
86149 .data = &vec,
86150 .maxlen = sizeof(vec),
86151 .mode = ctl->mode,
86152 };
86153
86154 if (!write) {
86155- ctl->data = &net->ipv4.sysctl_tcp_mem;
86156- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
86157+ ctl_table_no_const tcp_mem = *ctl;
86158+
86159+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
86160+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
86161 }
86162
86163 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
86164@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86165 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
86166 size_t *lenp, loff_t *ppos)
86167 {
86168- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86169+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86170 struct tcp_fastopen_context *ctxt;
86171 int ret;
86172 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
86173@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
86174 },
86175 {
86176 .procname = "ip_local_reserved_ports",
86177- .data = NULL, /* initialized in sysctl_ipv4_init */
86178+ .data = sysctl_local_reserved_ports,
86179 .maxlen = 65536,
86180 .mode = 0644,
86181 .proc_handler = proc_do_large_bitmap,
86182@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
86183
86184 static __net_init int ipv4_sysctl_init_net(struct net *net)
86185 {
86186- struct ctl_table *table;
86187+ ctl_table_no_const *table = NULL;
86188
86189- table = ipv4_net_table;
86190 if (!net_eq(net, &init_net)) {
86191- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
86192+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
86193 if (table == NULL)
86194 goto err_alloc;
86195
86196@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
86197
86198 tcp_init_mem(net);
86199
86200- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86201+ if (!net_eq(net, &init_net))
86202+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86203+ else
86204+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
86205 if (net->ipv4.ipv4_hdr == NULL)
86206 goto err_reg;
86207
86208 return 0;
86209
86210 err_reg:
86211- if (!net_eq(net, &init_net))
86212- kfree(table);
86213+ kfree(table);
86214 err_alloc:
86215 return -ENOMEM;
86216 }
86217@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
86218 static __init int sysctl_ipv4_init(void)
86219 {
86220 struct ctl_table_header *hdr;
86221- struct ctl_table *i;
86222-
86223- for (i = ipv4_table; i->procname; i++) {
86224- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
86225- i->data = sysctl_local_reserved_ports;
86226- break;
86227- }
86228- }
86229- if (!i->procname)
86230- return -EINVAL;
86231
86232 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
86233 if (hdr == NULL)
86234diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
86235index 66702d3..31ff8f9 100644
86236--- a/net/ipv4/tcp_input.c
86237+++ b/net/ipv4/tcp_input.c
86238@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
86239 * simplifies code)
86240 */
86241 static void
86242-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86243+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86244 struct sk_buff *head, struct sk_buff *tail,
86245 u32 start, u32 end)
86246 {
86247@@ -5850,6 +5850,7 @@ discard:
86248 tcp_paws_reject(&tp->rx_opt, 0))
86249 goto discard_and_undo;
86250
86251+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
86252 if (th->syn) {
86253 /* We see SYN without ACK. It is attempt of
86254 * simultaneous connect with crossed SYNs.
86255@@ -5900,6 +5901,7 @@ discard:
86256 goto discard;
86257 #endif
86258 }
86259+#endif
86260 /* "fifth, if neither of the SYN or RST bits is set then
86261 * drop the segment and return."
86262 */
86263@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
86264 goto discard;
86265
86266 if (th->syn) {
86267- if (th->fin)
86268+ if (th->fin || th->urg || th->psh)
86269 goto discard;
86270 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
86271 return 1;
86272diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
86273index eadb693..e8f7251 100644
86274--- a/net/ipv4/tcp_ipv4.c
86275+++ b/net/ipv4/tcp_ipv4.c
86276@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
86277 EXPORT_SYMBOL(sysctl_tcp_low_latency);
86278
86279
86280+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86281+extern int grsec_enable_blackhole;
86282+#endif
86283+
86284 #ifdef CONFIG_TCP_MD5SIG
86285 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
86286 __be32 daddr, __be32 saddr, const struct tcphdr *th);
86287@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
86288 return 0;
86289
86290 reset:
86291+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86292+ if (!grsec_enable_blackhole)
86293+#endif
86294 tcp_v4_send_reset(rsk, skb);
86295 discard:
86296 kfree_skb(skb);
86297@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
86298 TCP_SKB_CB(skb)->sacked = 0;
86299
86300 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86301- if (!sk)
86302+ if (!sk) {
86303+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86304+ ret = 1;
86305+#endif
86306 goto no_tcp_socket;
86307-
86308+ }
86309 process:
86310- if (sk->sk_state == TCP_TIME_WAIT)
86311+ if (sk->sk_state == TCP_TIME_WAIT) {
86312+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86313+ ret = 2;
86314+#endif
86315 goto do_time_wait;
86316+ }
86317
86318 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
86319 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86320@@ -2050,6 +2064,10 @@ no_tcp_socket:
86321 bad_packet:
86322 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86323 } else {
86324+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86325+ if (!grsec_enable_blackhole || (ret == 1 &&
86326+ (skb->dev->flags & IFF_LOOPBACK)))
86327+#endif
86328 tcp_v4_send_reset(NULL, skb);
86329 }
86330
86331diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
86332index f35f2df..ccb5ca6 100644
86333--- a/net/ipv4/tcp_minisocks.c
86334+++ b/net/ipv4/tcp_minisocks.c
86335@@ -27,6 +27,10 @@
86336 #include <net/inet_common.h>
86337 #include <net/xfrm.h>
86338
86339+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86340+extern int grsec_enable_blackhole;
86341+#endif
86342+
86343 int sysctl_tcp_syncookies __read_mostly = 1;
86344 EXPORT_SYMBOL(sysctl_tcp_syncookies);
86345
86346@@ -742,7 +746,10 @@ embryonic_reset:
86347 * avoid becoming vulnerable to outside attack aiming at
86348 * resetting legit local connections.
86349 */
86350- req->rsk_ops->send_reset(sk, skb);
86351+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86352+ if (!grsec_enable_blackhole)
86353+#endif
86354+ req->rsk_ops->send_reset(sk, skb);
86355 } else if (fastopen) { /* received a valid RST pkt */
86356 reqsk_fastopen_remove(sk, req, true);
86357 tcp_reset(sk);
86358diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
86359index 4526fe6..1a34e43 100644
86360--- a/net/ipv4/tcp_probe.c
86361+++ b/net/ipv4/tcp_probe.c
86362@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
86363 if (cnt + width >= len)
86364 break;
86365
86366- if (copy_to_user(buf + cnt, tbuf, width))
86367+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
86368 return -EFAULT;
86369 cnt += width;
86370 }
86371diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
86372index b78aac3..e18230b 100644
86373--- a/net/ipv4/tcp_timer.c
86374+++ b/net/ipv4/tcp_timer.c
86375@@ -22,6 +22,10 @@
86376 #include <linux/gfp.h>
86377 #include <net/tcp.h>
86378
86379+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86380+extern int grsec_lastack_retries;
86381+#endif
86382+
86383 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
86384 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
86385 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
86386@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
86387 }
86388 }
86389
86390+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86391+ if ((sk->sk_state == TCP_LAST_ACK) &&
86392+ (grsec_lastack_retries > 0) &&
86393+ (grsec_lastack_retries < retry_until))
86394+ retry_until = grsec_lastack_retries;
86395+#endif
86396+
86397 if (retransmits_timed_out(sk, retry_until,
86398 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
86399 /* Has it gone just too far? */
86400diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
86401index 1f4d405..3524677 100644
86402--- a/net/ipv4/udp.c
86403+++ b/net/ipv4/udp.c
86404@@ -87,6 +87,7 @@
86405 #include <linux/types.h>
86406 #include <linux/fcntl.h>
86407 #include <linux/module.h>
86408+#include <linux/security.h>
86409 #include <linux/socket.h>
86410 #include <linux/sockios.h>
86411 #include <linux/igmp.h>
86412@@ -111,6 +112,10 @@
86413 #include <trace/events/skb.h>
86414 #include "udp_impl.h"
86415
86416+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86417+extern int grsec_enable_blackhole;
86418+#endif
86419+
86420 struct udp_table udp_table __read_mostly;
86421 EXPORT_SYMBOL(udp_table);
86422
86423@@ -569,6 +574,9 @@ found:
86424 return s;
86425 }
86426
86427+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
86428+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
86429+
86430 /*
86431 * This routine is called by the ICMP module when it gets some
86432 * sort of error condition. If err < 0 then the socket should
86433@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
86434 dport = usin->sin_port;
86435 if (dport == 0)
86436 return -EINVAL;
86437+
86438+ err = gr_search_udp_sendmsg(sk, usin);
86439+ if (err)
86440+ return err;
86441 } else {
86442 if (sk->sk_state != TCP_ESTABLISHED)
86443 return -EDESTADDRREQ;
86444+
86445+ err = gr_search_udp_sendmsg(sk, NULL);
86446+ if (err)
86447+ return err;
86448+
86449 daddr = inet->inet_daddr;
86450 dport = inet->inet_dport;
86451 /* Open fast path for connected socket.
86452@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
86453 udp_lib_checksum_complete(skb)) {
86454 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86455 IS_UDPLITE(sk));
86456- atomic_inc(&sk->sk_drops);
86457+ atomic_inc_unchecked(&sk->sk_drops);
86458 __skb_unlink(skb, rcvq);
86459 __skb_queue_tail(&list_kill, skb);
86460 }
86461@@ -1194,6 +1211,10 @@ try_again:
86462 if (!skb)
86463 goto out;
86464
86465+ err = gr_search_udp_recvmsg(sk, skb);
86466+ if (err)
86467+ goto out_free;
86468+
86469 ulen = skb->len - sizeof(struct udphdr);
86470 copied = len;
86471 if (copied > ulen)
86472@@ -1227,7 +1248,7 @@ try_again:
86473 if (unlikely(err)) {
86474 trace_kfree_skb(skb, udp_recvmsg);
86475 if (!peeked) {
86476- atomic_inc(&sk->sk_drops);
86477+ atomic_inc_unchecked(&sk->sk_drops);
86478 UDP_INC_STATS_USER(sock_net(sk),
86479 UDP_MIB_INERRORS, is_udplite);
86480 }
86481@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86482
86483 drop:
86484 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86485- atomic_inc(&sk->sk_drops);
86486+ atomic_inc_unchecked(&sk->sk_drops);
86487 kfree_skb(skb);
86488 return -1;
86489 }
86490@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86491 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86492
86493 if (!skb1) {
86494- atomic_inc(&sk->sk_drops);
86495+ atomic_inc_unchecked(&sk->sk_drops);
86496 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86497 IS_UDPLITE(sk));
86498 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86499@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86500 goto csum_error;
86501
86502 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86503+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86504+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86505+#endif
86506 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
86507
86508 /*
86509@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
86510 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86511 0, sock_i_ino(sp),
86512 atomic_read(&sp->sk_refcnt), sp,
86513- atomic_read(&sp->sk_drops), len);
86514+ atomic_read_unchecked(&sp->sk_drops), len);
86515 }
86516
86517 int udp4_seq_show(struct seq_file *seq, void *v)
86518diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
86519index 1b5d8cb..ffb0833 100644
86520--- a/net/ipv6/addrconf.c
86521+++ b/net/ipv6/addrconf.c
86522@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
86523 p.iph.ihl = 5;
86524 p.iph.protocol = IPPROTO_IPV6;
86525 p.iph.ttl = 64;
86526- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
86527+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
86528
86529 if (ops->ndo_do_ioctl) {
86530 mm_segment_t oldfs = get_fs();
86531@@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
86532 int *valp = ctl->data;
86533 int val = *valp;
86534 loff_t pos = *ppos;
86535- ctl_table lctl;
86536+ ctl_table_no_const lctl;
86537 int ret;
86538
86539 /*
86540@@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
86541 int *valp = ctl->data;
86542 int val = *valp;
86543 loff_t pos = *ppos;
86544- ctl_table lctl;
86545+ ctl_table_no_const lctl;
86546 int ret;
86547
86548 /*
86549diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
86550index fff5bdd..15194fb 100644
86551--- a/net/ipv6/icmp.c
86552+++ b/net/ipv6/icmp.c
86553@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
86554
86555 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
86556 {
86557- struct ctl_table *table;
86558+ ctl_table_no_const *table;
86559
86560 table = kmemdup(ipv6_icmp_table_template,
86561 sizeof(ipv6_icmp_table_template),
86562diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
86563index 131dd09..f7ed64f 100644
86564--- a/net/ipv6/ip6_gre.c
86565+++ b/net/ipv6/ip6_gre.c
86566@@ -73,7 +73,7 @@ struct ip6gre_net {
86567 struct net_device *fb_tunnel_dev;
86568 };
86569
86570-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
86571+static struct rtnl_link_ops ip6gre_link_ops;
86572 static int ip6gre_tunnel_init(struct net_device *dev);
86573 static void ip6gre_tunnel_setup(struct net_device *dev);
86574 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
86575@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
86576 }
86577
86578
86579-static struct inet6_protocol ip6gre_protocol __read_mostly = {
86580+static struct inet6_protocol ip6gre_protocol = {
86581 .handler = ip6gre_rcv,
86582 .err_handler = ip6gre_err,
86583 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
86584@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
86585 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
86586 };
86587
86588-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86589+static struct rtnl_link_ops ip6gre_link_ops = {
86590 .kind = "ip6gre",
86591 .maxtype = IFLA_GRE_MAX,
86592 .policy = ip6gre_policy,
86593@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86594 .fill_info = ip6gre_fill_info,
86595 };
86596
86597-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
86598+static struct rtnl_link_ops ip6gre_tap_ops = {
86599 .kind = "ip6gretap",
86600 .maxtype = IFLA_GRE_MAX,
86601 .policy = ip6gre_policy,
86602diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
86603index a14f28b..b4b8956 100644
86604--- a/net/ipv6/ip6_tunnel.c
86605+++ b/net/ipv6/ip6_tunnel.c
86606@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
86607
86608 static int ip6_tnl_dev_init(struct net_device *dev);
86609 static void ip6_tnl_dev_setup(struct net_device *dev);
86610-static struct rtnl_link_ops ip6_link_ops __read_mostly;
86611+static struct rtnl_link_ops ip6_link_ops;
86612
86613 static int ip6_tnl_net_id __read_mostly;
86614 struct ip6_tnl_net {
86615@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
86616 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
86617 };
86618
86619-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
86620+static struct rtnl_link_ops ip6_link_ops = {
86621 .kind = "ip6tnl",
86622 .maxtype = IFLA_IPTUN_MAX,
86623 .policy = ip6_tnl_policy,
86624diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
86625index d1e2e8e..51c19ae 100644
86626--- a/net/ipv6/ipv6_sockglue.c
86627+++ b/net/ipv6/ipv6_sockglue.c
86628@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
86629 if (sk->sk_type != SOCK_STREAM)
86630 return -ENOPROTOOPT;
86631
86632- msg.msg_control = optval;
86633+ msg.msg_control = (void __force_kernel *)optval;
86634 msg.msg_controllen = len;
86635 msg.msg_flags = flags;
86636
86637diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
86638index 125a90d..2a11f36 100644
86639--- a/net/ipv6/netfilter/ip6_tables.c
86640+++ b/net/ipv6/netfilter/ip6_tables.c
86641@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
86642 #endif
86643
86644 static int get_info(struct net *net, void __user *user,
86645- const int *len, int compat)
86646+ int len, int compat)
86647 {
86648 char name[XT_TABLE_MAXNAMELEN];
86649 struct xt_table *t;
86650 int ret;
86651
86652- if (*len != sizeof(struct ip6t_getinfo)) {
86653- duprintf("length %u != %zu\n", *len,
86654+ if (len != sizeof(struct ip6t_getinfo)) {
86655+ duprintf("length %u != %zu\n", len,
86656 sizeof(struct ip6t_getinfo));
86657 return -EINVAL;
86658 }
86659@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
86660 info.size = private->size;
86661 strcpy(info.name, name);
86662
86663- if (copy_to_user(user, &info, *len) != 0)
86664+ if (copy_to_user(user, &info, len) != 0)
86665 ret = -EFAULT;
86666 else
86667 ret = 0;
86668@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86669
86670 switch (cmd) {
86671 case IP6T_SO_GET_INFO:
86672- ret = get_info(sock_net(sk), user, len, 1);
86673+ ret = get_info(sock_net(sk), user, *len, 1);
86674 break;
86675 case IP6T_SO_GET_ENTRIES:
86676 ret = compat_get_entries(sock_net(sk), user, len);
86677@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86678
86679 switch (cmd) {
86680 case IP6T_SO_GET_INFO:
86681- ret = get_info(sock_net(sk), user, len, 0);
86682+ ret = get_info(sock_net(sk), user, *len, 0);
86683 break;
86684
86685 case IP6T_SO_GET_ENTRIES:
86686diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
86687index 3dacecc..2939087 100644
86688--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
86689+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
86690@@ -87,12 +87,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
86691
86692 static int nf_ct_frag6_sysctl_register(struct net *net)
86693 {
86694- struct ctl_table *table;
86695+ ctl_table_no_const *table = NULL;
86696 struct ctl_table_header *hdr;
86697
86698- table = nf_ct_frag6_sysctl_table;
86699 if (!net_eq(net, &init_net)) {
86700- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
86701+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
86702 GFP_KERNEL);
86703 if (table == NULL)
86704 goto err_alloc;
86705@@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86706 table[0].data = &net->ipv6.frags.high_thresh;
86707 table[1].data = &net->ipv6.frags.low_thresh;
86708 table[2].data = &net->ipv6.frags.timeout;
86709- }
86710-
86711- hdr = register_net_sysctl(net, "net/netfilter", table);
86712+ hdr = register_net_sysctl(net, "net/netfilter", table);
86713+ } else
86714+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
86715 if (hdr == NULL)
86716 goto err_reg;
86717
86718@@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86719 return 0;
86720
86721 err_reg:
86722- if (!net_eq(net, &init_net))
86723- kfree(table);
86724+ kfree(table);
86725 err_alloc:
86726 return -ENOMEM;
86727 }
86728diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
86729index 70fa814..d70c28c 100644
86730--- a/net/ipv6/raw.c
86731+++ b/net/ipv6/raw.c
86732@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
86733 {
86734 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86735 skb_checksum_complete(skb)) {
86736- atomic_inc(&sk->sk_drops);
86737+ atomic_inc_unchecked(&sk->sk_drops);
86738 kfree_skb(skb);
86739 return NET_RX_DROP;
86740 }
86741@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86742 struct raw6_sock *rp = raw6_sk(sk);
86743
86744 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86745- atomic_inc(&sk->sk_drops);
86746+ atomic_inc_unchecked(&sk->sk_drops);
86747 kfree_skb(skb);
86748 return NET_RX_DROP;
86749 }
86750@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86751
86752 if (inet->hdrincl) {
86753 if (skb_checksum_complete(skb)) {
86754- atomic_inc(&sk->sk_drops);
86755+ atomic_inc_unchecked(&sk->sk_drops);
86756 kfree_skb(skb);
86757 return NET_RX_DROP;
86758 }
86759@@ -604,7 +604,7 @@ out:
86760 return err;
86761 }
86762
86763-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86764+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86765 struct flowi6 *fl6, struct dst_entry **dstp,
86766 unsigned int flags)
86767 {
86768@@ -916,12 +916,15 @@ do_confirm:
86769 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86770 char __user *optval, int optlen)
86771 {
86772+ struct icmp6_filter filter;
86773+
86774 switch (optname) {
86775 case ICMPV6_FILTER:
86776 if (optlen > sizeof(struct icmp6_filter))
86777 optlen = sizeof(struct icmp6_filter);
86778- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86779+ if (copy_from_user(&filter, optval, optlen))
86780 return -EFAULT;
86781+ raw6_sk(sk)->filter = filter;
86782 return 0;
86783 default:
86784 return -ENOPROTOOPT;
86785@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86786 char __user *optval, int __user *optlen)
86787 {
86788 int len;
86789+ struct icmp6_filter filter;
86790
86791 switch (optname) {
86792 case ICMPV6_FILTER:
86793@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86794 len = sizeof(struct icmp6_filter);
86795 if (put_user(len, optlen))
86796 return -EFAULT;
86797- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
86798+ filter = raw6_sk(sk)->filter;
86799+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
86800 return -EFAULT;
86801 return 0;
86802 default:
86803@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86804 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86805 0,
86806 sock_i_ino(sp),
86807- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86808+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86809 }
86810
86811 static int raw6_seq_show(struct seq_file *seq, void *v)
86812diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
86813index e5253ec..0410257 100644
86814--- a/net/ipv6/reassembly.c
86815+++ b/net/ipv6/reassembly.c
86816@@ -604,12 +604,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
86817
86818 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86819 {
86820- struct ctl_table *table;
86821+ ctl_table_no_const *table = NULL;
86822 struct ctl_table_header *hdr;
86823
86824- table = ip6_frags_ns_ctl_table;
86825 if (!net_eq(net, &init_net)) {
86826- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86827+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86828 if (table == NULL)
86829 goto err_alloc;
86830
86831@@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86832 /* Don't export sysctls to unprivileged users */
86833 if (net->user_ns != &init_user_ns)
86834 table[0].procname = NULL;
86835- }
86836+ hdr = register_net_sysctl(net, "net/ipv6", table);
86837+ } else
86838+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
86839
86840- hdr = register_net_sysctl(net, "net/ipv6", table);
86841 if (hdr == NULL)
86842 goto err_reg;
86843
86844@@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86845 return 0;
86846
86847 err_reg:
86848- if (!net_eq(net, &init_net))
86849- kfree(table);
86850+ kfree(table);
86851 err_alloc:
86852 return -ENOMEM;
86853 }
86854diff --git a/net/ipv6/route.c b/net/ipv6/route.c
86855index 5845613..3af8fc7 100644
86856--- a/net/ipv6/route.c
86857+++ b/net/ipv6/route.c
86858@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
86859
86860 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
86861 {
86862- struct ctl_table *table;
86863+ ctl_table_no_const *table;
86864
86865 table = kmemdup(ipv6_route_table_template,
86866 sizeof(ipv6_route_table_template),
86867diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
86868index cfba99b..20ca511 100644
86869--- a/net/ipv6/sit.c
86870+++ b/net/ipv6/sit.c
86871@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86872 static int ipip6_tunnel_init(struct net_device *dev);
86873 static void ipip6_tunnel_setup(struct net_device *dev);
86874 static void ipip6_dev_free(struct net_device *dev);
86875-static struct rtnl_link_ops sit_link_ops __read_mostly;
86876+static struct rtnl_link_ops sit_link_ops;
86877
86878 static int sit_net_id __read_mostly;
86879 struct sit_net {
86880@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
86881 #endif
86882 };
86883
86884-static struct rtnl_link_ops sit_link_ops __read_mostly = {
86885+static struct rtnl_link_ops sit_link_ops = {
86886 .kind = "sit",
86887 .maxtype = IFLA_IPTUN_MAX,
86888 .policy = ipip6_policy,
86889diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
86890index e85c48b..b8268d3 100644
86891--- a/net/ipv6/sysctl_net_ipv6.c
86892+++ b/net/ipv6/sysctl_net_ipv6.c
86893@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
86894
86895 static int __net_init ipv6_sysctl_net_init(struct net *net)
86896 {
86897- struct ctl_table *ipv6_table;
86898+ ctl_table_no_const *ipv6_table;
86899 struct ctl_table *ipv6_route_table;
86900 struct ctl_table *ipv6_icmp_table;
86901 int err;
86902diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
86903index 4f435371..5de9da7 100644
86904--- a/net/ipv6/tcp_ipv6.c
86905+++ b/net/ipv6/tcp_ipv6.c
86906@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
86907 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
86908 }
86909
86910+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86911+extern int grsec_enable_blackhole;
86912+#endif
86913+
86914 static void tcp_v6_hash(struct sock *sk)
86915 {
86916 if (sk->sk_state != TCP_CLOSE) {
86917@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
86918 return 0;
86919
86920 reset:
86921+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86922+ if (!grsec_enable_blackhole)
86923+#endif
86924 tcp_v6_send_reset(sk, skb);
86925 discard:
86926 if (opt_skb)
86927@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
86928 TCP_SKB_CB(skb)->sacked = 0;
86929
86930 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86931- if (!sk)
86932+ if (!sk) {
86933+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86934+ ret = 1;
86935+#endif
86936 goto no_tcp_socket;
86937+ }
86938
86939 process:
86940- if (sk->sk_state == TCP_TIME_WAIT)
86941+ if (sk->sk_state == TCP_TIME_WAIT) {
86942+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86943+ ret = 2;
86944+#endif
86945 goto do_time_wait;
86946+ }
86947
86948 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
86949 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86950@@ -1568,6 +1583,10 @@ no_tcp_socket:
86951 bad_packet:
86952 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86953 } else {
86954+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86955+ if (!grsec_enable_blackhole || (ret == 1 &&
86956+ (skb->dev->flags & IFF_LOOPBACK)))
86957+#endif
86958 tcp_v6_send_reset(NULL, skb);
86959 }
86960
86961diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
86962index fb08329..2d6919e 100644
86963--- a/net/ipv6/udp.c
86964+++ b/net/ipv6/udp.c
86965@@ -51,6 +51,10 @@
86966 #include <trace/events/skb.h>
86967 #include "udp_impl.h"
86968
86969+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86970+extern int grsec_enable_blackhole;
86971+#endif
86972+
86973 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
86974 {
86975 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
86976@@ -395,7 +399,7 @@ try_again:
86977 if (unlikely(err)) {
86978 trace_kfree_skb(skb, udpv6_recvmsg);
86979 if (!peeked) {
86980- atomic_inc(&sk->sk_drops);
86981+ atomic_inc_unchecked(&sk->sk_drops);
86982 if (is_udp4)
86983 UDP_INC_STATS_USER(sock_net(sk),
86984 UDP_MIB_INERRORS,
86985@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86986 return rc;
86987 drop:
86988 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86989- atomic_inc(&sk->sk_drops);
86990+ atomic_inc_unchecked(&sk->sk_drops);
86991 kfree_skb(skb);
86992 return -1;
86993 }
86994@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86995 if (likely(skb1 == NULL))
86996 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86997 if (!skb1) {
86998- atomic_inc(&sk->sk_drops);
86999+ atomic_inc_unchecked(&sk->sk_drops);
87000 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87001 IS_UDPLITE(sk));
87002 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87003@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87004 goto discard;
87005
87006 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87007+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87008+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87009+#endif
87010 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
87011
87012 kfree_skb(skb);
87013@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
87014 0,
87015 sock_i_ino(sp),
87016 atomic_read(&sp->sk_refcnt), sp,
87017- atomic_read(&sp->sk_drops));
87018+ atomic_read_unchecked(&sp->sk_drops));
87019 }
87020
87021 int udp6_seq_show(struct seq_file *seq, void *v)
87022diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
87023index b833677..4d04105 100644
87024--- a/net/irda/af_irda.c
87025+++ b/net/irda/af_irda.c
87026@@ -2584,8 +2584,10 @@ bed:
87027 NULL, NULL, NULL);
87028
87029 /* Check if the we got some results */
87030- if (!self->cachedaddr)
87031- return -EAGAIN; /* Didn't find any devices */
87032+ if (!self->cachedaddr) {
87033+ err = -EAGAIN; /* Didn't find any devices */
87034+ goto out;
87035+ }
87036 daddr = self->cachedaddr;
87037 /* Cleanup */
87038 self->cachedaddr = 0;
87039diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
87040index a68c88c..d55b0c5 100644
87041--- a/net/irda/ircomm/ircomm_tty.c
87042+++ b/net/irda/ircomm/ircomm_tty.c
87043@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87044 add_wait_queue(&port->open_wait, &wait);
87045
87046 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
87047- __FILE__, __LINE__, tty->driver->name, port->count);
87048+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87049
87050 spin_lock_irqsave(&port->lock, flags);
87051 if (!tty_hung_up_p(filp)) {
87052 extra_count = 1;
87053- port->count--;
87054+ atomic_dec(&port->count);
87055 }
87056 spin_unlock_irqrestore(&port->lock, flags);
87057 port->blocked_open++;
87058@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87059 }
87060
87061 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking 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 schedule();
87066 }
87067@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87068 if (extra_count) {
87069 /* ++ is not atomic, so this should be protected - Jean II */
87070 spin_lock_irqsave(&port->lock, flags);
87071- port->count++;
87072+ atomic_inc(&port->count);
87073 spin_unlock_irqrestore(&port->lock, flags);
87074 }
87075 port->blocked_open--;
87076
87077 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
87078- __FILE__, __LINE__, tty->driver->name, port->count);
87079+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87080
87081 if (!retval)
87082 port->flags |= ASYNC_NORMAL_ACTIVE;
87083@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
87084
87085 /* ++ is not atomic, so this should be protected - Jean II */
87086 spin_lock_irqsave(&self->port.lock, flags);
87087- self->port.count++;
87088+ atomic_inc(&self->port.count);
87089 spin_unlock_irqrestore(&self->port.lock, flags);
87090 tty_port_tty_set(&self->port, tty);
87091
87092 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
87093- self->line, self->port.count);
87094+ self->line, atomic_read(&self->port.count));
87095
87096 /* Not really used by us, but lets do it anyway */
87097 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
87098@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
87099 tty_kref_put(port->tty);
87100 }
87101 port->tty = NULL;
87102- port->count = 0;
87103+ atomic_set(&port->count, 0);
87104 spin_unlock_irqrestore(&port->lock, flags);
87105
87106 wake_up_interruptible(&port->open_wait);
87107@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
87108 seq_putc(m, '\n');
87109
87110 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
87111- seq_printf(m, "Open count: %d\n", self->port.count);
87112+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
87113 seq_printf(m, "Max data size: %d\n", self->max_data_size);
87114 seq_printf(m, "Max header size: %d\n", self->max_header_size);
87115
87116diff --git a/net/irda/iriap.c b/net/irda/iriap.c
87117index e71e85b..29340a9 100644
87118--- a/net/irda/iriap.c
87119+++ b/net/irda/iriap.c
87120@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
87121 /* case CS_ISO_8859_9: */
87122 /* case CS_UNICODE: */
87123 default:
87124- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
87125- __func__, ias_charset_types[charset]);
87126+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
87127+ __func__, charset,
87128+ charset < ARRAY_SIZE(ias_charset_types) ?
87129+ ias_charset_types[charset] :
87130+ "(unknown)");
87131
87132 /* Aborting, close connection! */
87133 iriap_disconnect_request(self);
87134diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
87135index cd6f7a9..e63fe89 100644
87136--- a/net/iucv/af_iucv.c
87137+++ b/net/iucv/af_iucv.c
87138@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
87139
87140 write_lock_bh(&iucv_sk_list.lock);
87141
87142- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
87143+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87144 while (__iucv_get_sock_by_name(name)) {
87145 sprintf(name, "%08x",
87146- atomic_inc_return(&iucv_sk_list.autobind_name));
87147+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87148 }
87149
87150 write_unlock_bh(&iucv_sk_list.lock);
87151diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
87152index df08250..02021fe 100644
87153--- a/net/iucv/iucv.c
87154+++ b/net/iucv/iucv.c
87155@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
87156 return NOTIFY_OK;
87157 }
87158
87159-static struct notifier_block __refdata iucv_cpu_notifier = {
87160+static struct notifier_block iucv_cpu_notifier = {
87161 .notifier_call = iucv_cpu_notify,
87162 };
87163
87164diff --git a/net/key/af_key.c b/net/key/af_key.c
87165index 5b426a6..970032b 100644
87166--- a/net/key/af_key.c
87167+++ b/net/key/af_key.c
87168@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
87169 static u32 get_acqseq(void)
87170 {
87171 u32 res;
87172- static atomic_t acqseq;
87173+ static atomic_unchecked_t acqseq;
87174
87175 do {
87176- res = atomic_inc_return(&acqseq);
87177+ res = atomic_inc_return_unchecked(&acqseq);
87178 } while (!res);
87179 return res;
87180 }
87181diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
87182index 0479c64..d031db6 100644
87183--- a/net/mac80211/cfg.c
87184+++ b/net/mac80211/cfg.c
87185@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
87186 ret = ieee80211_vif_use_channel(sdata, chandef,
87187 IEEE80211_CHANCTX_EXCLUSIVE);
87188 }
87189- } else if (local->open_count == local->monitors) {
87190+ } else if (local_read(&local->open_count) == local->monitors) {
87191 local->_oper_channel = chandef->chan;
87192 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
87193 ieee80211_hw_config(local, 0);
87194@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
87195 else
87196 local->probe_req_reg--;
87197
87198- if (!local->open_count)
87199+ if (!local_read(&local->open_count))
87200 break;
87201
87202 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
87203diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
87204index 2ed065c..948177f 100644
87205--- a/net/mac80211/ieee80211_i.h
87206+++ b/net/mac80211/ieee80211_i.h
87207@@ -28,6 +28,7 @@
87208 #include <net/ieee80211_radiotap.h>
87209 #include <net/cfg80211.h>
87210 #include <net/mac80211.h>
87211+#include <asm/local.h>
87212 #include "key.h"
87213 #include "sta_info.h"
87214 #include "debug.h"
87215@@ -909,7 +910,7 @@ struct ieee80211_local {
87216 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
87217 spinlock_t queue_stop_reason_lock;
87218
87219- int open_count;
87220+ local_t open_count;
87221 int monitors, cooked_mntrs;
87222 /* number of interfaces with corresponding FIF_ flags */
87223 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
87224diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
87225index 8be854e..ad72a69 100644
87226--- a/net/mac80211/iface.c
87227+++ b/net/mac80211/iface.c
87228@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87229 break;
87230 }
87231
87232- if (local->open_count == 0) {
87233+ if (local_read(&local->open_count) == 0) {
87234 res = drv_start(local);
87235 if (res)
87236 goto err_del_bss;
87237@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87238 break;
87239 }
87240
87241- if (local->monitors == 0 && local->open_count == 0) {
87242+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
87243 res = ieee80211_add_virtual_monitor(local);
87244 if (res)
87245 goto err_stop;
87246@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87247 mutex_unlock(&local->mtx);
87248
87249 if (coming_up)
87250- local->open_count++;
87251+ local_inc(&local->open_count);
87252
87253 if (hw_reconf_flags)
87254 ieee80211_hw_config(local, hw_reconf_flags);
87255@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87256 err_del_interface:
87257 drv_remove_interface(local, sdata);
87258 err_stop:
87259- if (!local->open_count)
87260+ if (!local_read(&local->open_count))
87261 drv_stop(local);
87262 err_del_bss:
87263 sdata->bss = NULL;
87264@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87265 }
87266
87267 if (going_down)
87268- local->open_count--;
87269+ local_dec(&local->open_count);
87270
87271 switch (sdata->vif.type) {
87272 case NL80211_IFTYPE_AP_VLAN:
87273@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87274
87275 ieee80211_recalc_ps(local, -1);
87276
87277- if (local->open_count == 0) {
87278+ if (local_read(&local->open_count) == 0) {
87279 if (local->ops->napi_poll)
87280 napi_disable(&local->napi);
87281 ieee80211_clear_tx_pending(local);
87282@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87283 }
87284 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
87285
87286- if (local->monitors == local->open_count && local->monitors > 0)
87287+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
87288 ieee80211_add_virtual_monitor(local);
87289 }
87290
87291diff --git a/net/mac80211/main.c b/net/mac80211/main.c
87292index 1b087ff..bf600e9 100644
87293--- a/net/mac80211/main.c
87294+++ b/net/mac80211/main.c
87295@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
87296 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
87297 IEEE80211_CONF_CHANGE_POWER);
87298
87299- if (changed && local->open_count) {
87300+ if (changed && local_read(&local->open_count)) {
87301 ret = drv_config(local, changed);
87302 /*
87303 * Goal:
87304diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
87305index 79a48f3..5e185c9 100644
87306--- a/net/mac80211/pm.c
87307+++ b/net/mac80211/pm.c
87308@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87309 struct sta_info *sta;
87310 struct ieee80211_chanctx *ctx;
87311
87312- if (!local->open_count)
87313+ if (!local_read(&local->open_count))
87314 goto suspend;
87315
87316 ieee80211_scan_cancel(local);
87317@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87318 cancel_work_sync(&local->dynamic_ps_enable_work);
87319 del_timer_sync(&local->dynamic_ps_timer);
87320
87321- local->wowlan = wowlan && local->open_count;
87322+ local->wowlan = wowlan && local_read(&local->open_count);
87323 if (local->wowlan) {
87324 int err = drv_suspend(local, wowlan);
87325 if (err < 0) {
87326@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87327 mutex_unlock(&local->chanctx_mtx);
87328
87329 /* stop hardware - this must stop RX */
87330- if (local->open_count)
87331+ if (local_read(&local->open_count))
87332 ieee80211_stop_device(local);
87333
87334 suspend:
87335diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
87336index dd88381..eef4dd6 100644
87337--- a/net/mac80211/rate.c
87338+++ b/net/mac80211/rate.c
87339@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
87340
87341 ASSERT_RTNL();
87342
87343- if (local->open_count)
87344+ if (local_read(&local->open_count))
87345 return -EBUSY;
87346
87347 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
87348diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
87349index c97a065..ff61928 100644
87350--- a/net/mac80211/rc80211_pid_debugfs.c
87351+++ b/net/mac80211/rc80211_pid_debugfs.c
87352@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
87353
87354 spin_unlock_irqrestore(&events->lock, status);
87355
87356- if (copy_to_user(buf, pb, p))
87357+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
87358 return -EFAULT;
87359
87360 return p;
87361diff --git a/net/mac80211/util.c b/net/mac80211/util.c
87362index f11e8c5..08d0013 100644
87363--- a/net/mac80211/util.c
87364+++ b/net/mac80211/util.c
87365@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
87366 }
87367 #endif
87368 /* everything else happens only if HW was up & running */
87369- if (!local->open_count)
87370+ if (!local_read(&local->open_count))
87371 goto wake_up;
87372
87373 /*
87374diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
87375index 49e96df..63a51c3 100644
87376--- a/net/netfilter/Kconfig
87377+++ b/net/netfilter/Kconfig
87378@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
87379
87380 To compile it as a module, choose M here. If unsure, say N.
87381
87382+config NETFILTER_XT_MATCH_GRADM
87383+ tristate '"gradm" match support'
87384+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
87385+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
87386+ ---help---
87387+ The gradm match allows to match on grsecurity RBAC being enabled.
87388+ It is useful when iptables rules are applied early on bootup to
87389+ prevent connections to the machine (except from a trusted host)
87390+ while the RBAC system is disabled.
87391+
87392 config NETFILTER_XT_MATCH_HASHLIMIT
87393 tristate '"hashlimit" match support'
87394 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
87395diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
87396index 3259697..54d5393 100644
87397--- a/net/netfilter/Makefile
87398+++ b/net/netfilter/Makefile
87399@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
87400 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
87401 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
87402 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
87403+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
87404 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
87405 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
87406 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
87407diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
87408index 6d6d8f2..a676749 100644
87409--- a/net/netfilter/ipset/ip_set_core.c
87410+++ b/net/netfilter/ipset/ip_set_core.c
87411@@ -1800,7 +1800,7 @@ done:
87412 return ret;
87413 }
87414
87415-static struct nf_sockopt_ops so_set __read_mostly = {
87416+static struct nf_sockopt_ops so_set = {
87417 .pf = PF_INET,
87418 .get_optmin = SO_IP_SET,
87419 .get_optmax = SO_IP_SET + 1,
87420diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
87421index 30e764a..c3b6a9d 100644
87422--- a/net/netfilter/ipvs/ip_vs_conn.c
87423+++ b/net/netfilter/ipvs/ip_vs_conn.c
87424@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
87425 /* Increase the refcnt counter of the dest */
87426 atomic_inc(&dest->refcnt);
87427
87428- conn_flags = atomic_read(&dest->conn_flags);
87429+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
87430 if (cp->protocol != IPPROTO_UDP)
87431 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
87432 flags = cp->flags;
87433@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
87434 atomic_set(&cp->refcnt, 1);
87435
87436 atomic_set(&cp->n_control, 0);
87437- atomic_set(&cp->in_pkts, 0);
87438+ atomic_set_unchecked(&cp->in_pkts, 0);
87439
87440 atomic_inc(&ipvs->conn_count);
87441 if (flags & IP_VS_CONN_F_NO_CPORT)
87442@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
87443
87444 /* Don't drop the entry if its number of incoming packets is not
87445 located in [0, 8] */
87446- i = atomic_read(&cp->in_pkts);
87447+ i = atomic_read_unchecked(&cp->in_pkts);
87448 if (i > 8 || i < 0) return 0;
87449
87450 if (!todrop_rate[i]) return 0;
87451diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
87452index 47edf5a..235b07d 100644
87453--- a/net/netfilter/ipvs/ip_vs_core.c
87454+++ b/net/netfilter/ipvs/ip_vs_core.c
87455@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
87456 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
87457 /* do not touch skb anymore */
87458
87459- atomic_inc(&cp->in_pkts);
87460+ atomic_inc_unchecked(&cp->in_pkts);
87461 ip_vs_conn_put(cp);
87462 return ret;
87463 }
87464@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
87465 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
87466 pkts = sysctl_sync_threshold(ipvs);
87467 else
87468- pkts = atomic_add_return(1, &cp->in_pkts);
87469+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87470
87471 if (ipvs->sync_state & IP_VS_STATE_MASTER)
87472 ip_vs_sync_conn(net, cp, pkts);
87473diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
87474index ec664cb..7f34a77 100644
87475--- a/net/netfilter/ipvs/ip_vs_ctl.c
87476+++ b/net/netfilter/ipvs/ip_vs_ctl.c
87477@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
87478 ip_vs_rs_hash(ipvs, dest);
87479 write_unlock_bh(&ipvs->rs_lock);
87480 }
87481- atomic_set(&dest->conn_flags, conn_flags);
87482+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
87483
87484 /* bind the service */
87485 if (!dest->svc) {
87486@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
87487 * align with netns init in ip_vs_control_net_init()
87488 */
87489
87490-static struct ctl_table vs_vars[] = {
87491+static ctl_table_no_const vs_vars[] __read_only = {
87492 {
87493 .procname = "amemthresh",
87494 .maxlen = sizeof(int),
87495@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87496 " %-7s %-6d %-10d %-10d\n",
87497 &dest->addr.in6,
87498 ntohs(dest->port),
87499- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87500+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87501 atomic_read(&dest->weight),
87502 atomic_read(&dest->activeconns),
87503 atomic_read(&dest->inactconns));
87504@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87505 "%-7s %-6d %-10d %-10d\n",
87506 ntohl(dest->addr.ip),
87507 ntohs(dest->port),
87508- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87509+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87510 atomic_read(&dest->weight),
87511 atomic_read(&dest->activeconns),
87512 atomic_read(&dest->inactconns));
87513@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
87514
87515 entry.addr = dest->addr.ip;
87516 entry.port = dest->port;
87517- entry.conn_flags = atomic_read(&dest->conn_flags);
87518+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
87519 entry.weight = atomic_read(&dest->weight);
87520 entry.u_threshold = dest->u_threshold;
87521 entry.l_threshold = dest->l_threshold;
87522@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
87523 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
87524 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
87525 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
87526- (atomic_read(&dest->conn_flags) &
87527+ (atomic_read_unchecked(&dest->conn_flags) &
87528 IP_VS_CONN_F_FWD_MASK)) ||
87529 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
87530 atomic_read(&dest->weight)) ||
87531@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
87532 {
87533 int idx;
87534 struct netns_ipvs *ipvs = net_ipvs(net);
87535- struct ctl_table *tbl;
87536+ ctl_table_no_const *tbl;
87537
87538 atomic_set(&ipvs->dropentry, 0);
87539 spin_lock_init(&ipvs->dropentry_lock);
87540diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
87541index fdd89b9..bd96aa9 100644
87542--- a/net/netfilter/ipvs/ip_vs_lblc.c
87543+++ b/net/netfilter/ipvs/ip_vs_lblc.c
87544@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
87545 * IPVS LBLC sysctl table
87546 */
87547 #ifdef CONFIG_SYSCTL
87548-static ctl_table vs_vars_table[] = {
87549+static ctl_table_no_const vs_vars_table[] __read_only = {
87550 {
87551 .procname = "lblc_expiration",
87552 .data = NULL,
87553diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
87554index c03b6a3..8ce3681 100644
87555--- a/net/netfilter/ipvs/ip_vs_lblcr.c
87556+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
87557@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
87558 * IPVS LBLCR sysctl table
87559 */
87560
87561-static ctl_table vs_vars_table[] = {
87562+static ctl_table_no_const vs_vars_table[] __read_only = {
87563 {
87564 .procname = "lblcr_expiration",
87565 .data = NULL,
87566diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
87567index 44fd10c..2a163b3 100644
87568--- a/net/netfilter/ipvs/ip_vs_sync.c
87569+++ b/net/netfilter/ipvs/ip_vs_sync.c
87570@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
87571 cp = cp->control;
87572 if (cp) {
87573 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87574- pkts = atomic_add_return(1, &cp->in_pkts);
87575+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87576 else
87577 pkts = sysctl_sync_threshold(ipvs);
87578 ip_vs_sync_conn(net, cp->control, pkts);
87579@@ -758,7 +758,7 @@ control:
87580 if (!cp)
87581 return;
87582 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87583- pkts = atomic_add_return(1, &cp->in_pkts);
87584+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87585 else
87586 pkts = sysctl_sync_threshold(ipvs);
87587 goto sloop;
87588@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
87589
87590 if (opt)
87591 memcpy(&cp->in_seq, opt, sizeof(*opt));
87592- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87593+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87594 cp->state = state;
87595 cp->old_state = cp->state;
87596 /*
87597diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
87598index ee6b7a9..f9a89f6 100644
87599--- a/net/netfilter/ipvs/ip_vs_xmit.c
87600+++ b/net/netfilter/ipvs/ip_vs_xmit.c
87601@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
87602 else
87603 rc = NF_ACCEPT;
87604 /* do not touch skb anymore */
87605- atomic_inc(&cp->in_pkts);
87606+ atomic_inc_unchecked(&cp->in_pkts);
87607 goto out;
87608 }
87609
87610@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
87611 else
87612 rc = NF_ACCEPT;
87613 /* do not touch skb anymore */
87614- atomic_inc(&cp->in_pkts);
87615+ atomic_inc_unchecked(&cp->in_pkts);
87616 goto out;
87617 }
87618
87619diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
87620index 7df424e..a527b02 100644
87621--- a/net/netfilter/nf_conntrack_acct.c
87622+++ b/net/netfilter/nf_conntrack_acct.c
87623@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
87624 #ifdef CONFIG_SYSCTL
87625 static int nf_conntrack_acct_init_sysctl(struct net *net)
87626 {
87627- struct ctl_table *table;
87628+ ctl_table_no_const *table;
87629
87630 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
87631 GFP_KERNEL);
87632diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
87633index e4a0c4f..c263f28 100644
87634--- a/net/netfilter/nf_conntrack_core.c
87635+++ b/net/netfilter/nf_conntrack_core.c
87636@@ -1529,6 +1529,10 @@ err_extend:
87637 #define DYING_NULLS_VAL ((1<<30)+1)
87638 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
87639
87640+#ifdef CONFIG_GRKERNSEC_HIDESYM
87641+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
87642+#endif
87643+
87644 static int nf_conntrack_init_net(struct net *net)
87645 {
87646 int ret;
87647@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
87648 goto err_stat;
87649 }
87650
87651+#ifdef CONFIG_GRKERNSEC_HIDESYM
87652+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
87653+#else
87654 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
87655+#endif
87656 if (!net->ct.slabname) {
87657 ret = -ENOMEM;
87658 goto err_slabname;
87659diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
87660index faa978f..1afb18f 100644
87661--- a/net/netfilter/nf_conntrack_ecache.c
87662+++ b/net/netfilter/nf_conntrack_ecache.c
87663@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
87664 #ifdef CONFIG_SYSCTL
87665 static int nf_conntrack_event_init_sysctl(struct net *net)
87666 {
87667- struct ctl_table *table;
87668+ ctl_table_no_const *table;
87669
87670 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
87671 GFP_KERNEL);
87672diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
87673index 884f2b3..d53b33a 100644
87674--- a/net/netfilter/nf_conntrack_helper.c
87675+++ b/net/netfilter/nf_conntrack_helper.c
87676@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
87677
87678 static int nf_conntrack_helper_init_sysctl(struct net *net)
87679 {
87680- struct ctl_table *table;
87681+ ctl_table_no_const *table;
87682
87683 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
87684 GFP_KERNEL);
87685diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
87686index 51e928d..72a413a 100644
87687--- a/net/netfilter/nf_conntrack_proto.c
87688+++ b/net/netfilter/nf_conntrack_proto.c
87689@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
87690
87691 static void
87692 nf_ct_unregister_sysctl(struct ctl_table_header **header,
87693- struct ctl_table **table,
87694+ ctl_table_no_const **table,
87695 unsigned int users)
87696 {
87697 if (users > 0)
87698diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
87699index e7185c6..4ad6c9c 100644
87700--- a/net/netfilter/nf_conntrack_standalone.c
87701+++ b/net/netfilter/nf_conntrack_standalone.c
87702@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
87703
87704 static int nf_conntrack_standalone_init_sysctl(struct net *net)
87705 {
87706- struct ctl_table *table;
87707+ ctl_table_no_const *table;
87708
87709 if (net_eq(net, &init_net)) {
87710 nf_ct_netfilter_header =
87711diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
87712index 7ea8026..bc9512d 100644
87713--- a/net/netfilter/nf_conntrack_timestamp.c
87714+++ b/net/netfilter/nf_conntrack_timestamp.c
87715@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
87716 #ifdef CONFIG_SYSCTL
87717 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
87718 {
87719- struct ctl_table *table;
87720+ ctl_table_no_const *table;
87721
87722 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
87723 GFP_KERNEL);
87724diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
87725index 9e31269..bc4c1b7 100644
87726--- a/net/netfilter/nf_log.c
87727+++ b/net/netfilter/nf_log.c
87728@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
87729
87730 #ifdef CONFIG_SYSCTL
87731 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
87732-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
87733+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
87734 static struct ctl_table_header *nf_log_dir_header;
87735
87736 static int nf_log_proc_dostring(ctl_table *table, int write,
87737@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
87738 rcu_assign_pointer(nf_loggers[tindex], logger);
87739 mutex_unlock(&nf_log_mutex);
87740 } else {
87741+ ctl_table_no_const nf_log_table = *table;
87742+
87743 mutex_lock(&nf_log_mutex);
87744 logger = rcu_dereference_protected(nf_loggers[tindex],
87745 lockdep_is_held(&nf_log_mutex));
87746 if (!logger)
87747- table->data = "NONE";
87748+ nf_log_table.data = "NONE";
87749 else
87750- table->data = logger->name;
87751- r = proc_dostring(table, write, buffer, lenp, ppos);
87752+ nf_log_table.data = logger->name;
87753+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87754 mutex_unlock(&nf_log_mutex);
87755 }
87756
87757diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87758index f042ae5..30ea486 100644
87759--- a/net/netfilter/nf_sockopt.c
87760+++ b/net/netfilter/nf_sockopt.c
87761@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87762 }
87763 }
87764
87765- list_add(&reg->list, &nf_sockopts);
87766+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87767 out:
87768 mutex_unlock(&nf_sockopt_mutex);
87769 return ret;
87770@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87771 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87772 {
87773 mutex_lock(&nf_sockopt_mutex);
87774- list_del(&reg->list);
87775+ pax_list_del((struct list_head *)&reg->list);
87776 mutex_unlock(&nf_sockopt_mutex);
87777 }
87778 EXPORT_SYMBOL(nf_unregister_sockopt);
87779diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87780index 92fd8ec..3f6ea4b 100644
87781--- a/net/netfilter/nfnetlink_log.c
87782+++ b/net/netfilter/nfnetlink_log.c
87783@@ -72,7 +72,7 @@ struct nfulnl_instance {
87784 };
87785
87786 static DEFINE_SPINLOCK(instances_lock);
87787-static atomic_t global_seq;
87788+static atomic_unchecked_t global_seq;
87789
87790 #define INSTANCE_BUCKETS 16
87791 static struct hlist_head instance_table[INSTANCE_BUCKETS];
87792@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
87793 /* global sequence number */
87794 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
87795 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
87796- htonl(atomic_inc_return(&global_seq))))
87797+ htonl(atomic_inc_return_unchecked(&global_seq))))
87798 goto nla_put_failure;
87799
87800 if (data_len) {
87801diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
87802new file mode 100644
87803index 0000000..c566332
87804--- /dev/null
87805+++ b/net/netfilter/xt_gradm.c
87806@@ -0,0 +1,51 @@
87807+/*
87808+ * gradm match for netfilter
87809