]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.4-201303231310.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.4-201303231310.patch
CommitLineData
a1e42536
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..7090f4a 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+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
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..27af8a5 100644
34996--- a/drivers/gpu/drm/i915/i915_debugfs.c
34997+++ b/drivers/gpu/drm/i915/i915_debugfs.c
34998@@ -103,7 +103,7 @@ static const char *cache_level_str(int type)
34999 static void
35000 describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
35001 {
35002- seq_printf(m, "%p: %s%s %8zdKiB %04x %04x %d %d %d%s%s%s",
35003+ seq_printf(m, "%pK: %s%s %8zdKiB %04x %04x %d %d %d%s%s%s",
35004 &obj->base,
35005 get_pin_flag(obj),
35006 get_tiling_flag(obj),
35007@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35008 I915_READ(GTIMR));
35009 }
35010 seq_printf(m, "Interrupts received: %d\n",
35011- atomic_read(&dev_priv->irq_received));
35012+ atomic_read_unchecked(&dev_priv->irq_received));
35013 for_each_ring(ring, dev_priv, i) {
35014 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35015 seq_printf(m,
35016diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35017index 99daa89..84ebd44 100644
35018--- a/drivers/gpu/drm/i915/i915_dma.c
35019+++ b/drivers/gpu/drm/i915/i915_dma.c
35020@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35021 bool can_switch;
35022
35023 spin_lock(&dev->count_lock);
35024- can_switch = (dev->open_count == 0);
35025+ can_switch = (local_read(&dev->open_count) == 0);
35026 spin_unlock(&dev->count_lock);
35027 return can_switch;
35028 }
35029diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35030index 7339a4b..445aaba 100644
35031--- a/drivers/gpu/drm/i915/i915_drv.h
35032+++ b/drivers/gpu/drm/i915/i915_drv.h
35033@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
35034 drm_dma_handle_t *status_page_dmah;
35035 struct resource mch_res;
35036
35037- atomic_t irq_received;
35038+ atomic_unchecked_t irq_received;
35039
35040 /* protects the irq masks */
35041 spinlock_t irq_lock;
35042@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
35043 * will be page flipped away on the next vblank. When it
35044 * reaches 0, dev_priv->pending_flip_queue will be woken up.
35045 */
35046- atomic_t pending_flip;
35047+ atomic_unchecked_t pending_flip;
35048 };
35049 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
35050
35051@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35052 struct drm_i915_private *dev_priv, unsigned port);
35053 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35054 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35055-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35056+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35057 {
35058 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35059 }
35060diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35061index 26d08bb..e24fb51 100644
35062--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35063+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35064@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
35065 i915_gem_clflush_object(obj);
35066
35067 if (obj->base.pending_write_domain)
35068- flips |= atomic_read(&obj->pending_flip);
35069+ flips |= atomic_read_unchecked(&obj->pending_flip);
35070
35071 flush_domains |= obj->base.write_domain;
35072 }
35073@@ -703,18 +703,23 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35074
35075 static int
35076 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35077- int count)
35078+ unsigned int count)
35079 {
35080- int i;
35081+ unsigned int i;
35082+ int relocs_total = 0;
35083+ int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35084
35085 for (i = 0; i < count; i++) {
35086 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
35087 int length; /* limited by fault_in_pages_readable() */
35088
35089- /* First check for malicious input causing overflow */
35090- if (exec[i].relocation_count >
35091- INT_MAX / sizeof(struct drm_i915_gem_relocation_entry))
35092+ /* First check for malicious input causing overflow in
35093+ * the worst case where we need to allocate the entire
35094+ * relocation tree as a single array.
35095+ */
35096+ if (exec[i].relocation_count > relocs_max - relocs_total)
35097 return -EINVAL;
35098+ relocs_total += exec[i].relocation_count;
35099
35100 length = exec[i].relocation_count *
35101 sizeof(struct drm_i915_gem_relocation_entry);
35102@@ -1197,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35103 return -ENOMEM;
35104 }
35105 ret = copy_from_user(exec2_list,
35106- (struct drm_i915_relocation_entry __user *)
35107+ (struct drm_i915_gem_exec_object2 __user *)
35108 (uintptr_t) args->buffers_ptr,
35109 sizeof(*exec2_list) * args->buffer_count);
35110 if (ret != 0) {
35111diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35112index 3c59584..500f2e9 100644
35113--- a/drivers/gpu/drm/i915/i915_ioc32.c
35114+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35115@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35116 (unsigned long)request);
35117 }
35118
35119-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35120+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35121 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35122 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35123 [DRM_I915_GETPARAM] = compat_i915_getparam,
35124@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35125 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35126 {
35127 unsigned int nr = DRM_IOCTL_NR(cmd);
35128- drm_ioctl_compat_t *fn = NULL;
35129 int ret;
35130
35131 if (nr < DRM_COMMAND_BASE)
35132 return drm_compat_ioctl(filp, cmd, arg);
35133
35134- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35135- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35136-
35137- if (fn != NULL)
35138+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35139+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35140 ret = (*fn) (filp, cmd, arg);
35141- else
35142+ } else
35143 ret = drm_ioctl(filp, cmd, arg);
35144
35145 return ret;
35146diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35147index fe84338..a863190 100644
35148--- a/drivers/gpu/drm/i915/i915_irq.c
35149+++ b/drivers/gpu/drm/i915/i915_irq.c
35150@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35151 u32 pipe_stats[I915_MAX_PIPES];
35152 bool blc_event;
35153
35154- atomic_inc(&dev_priv->irq_received);
35155+ atomic_inc_unchecked(&dev_priv->irq_received);
35156
35157 while (true) {
35158 iir = I915_READ(VLV_IIR);
35159@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35160 irqreturn_t ret = IRQ_NONE;
35161 int i;
35162
35163- atomic_inc(&dev_priv->irq_received);
35164+ atomic_inc_unchecked(&dev_priv->irq_received);
35165
35166 /* disable master interrupt before clearing iir */
35167 de_ier = I915_READ(DEIER);
35168@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35169 int ret = IRQ_NONE;
35170 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
35171
35172- atomic_inc(&dev_priv->irq_received);
35173+ atomic_inc_unchecked(&dev_priv->irq_received);
35174
35175 /* disable master interrupt before clearing iir */
35176 de_ier = I915_READ(DEIER);
35177@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35178 {
35179 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35180
35181- atomic_set(&dev_priv->irq_received, 0);
35182+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35183
35184 I915_WRITE(HWSTAM, 0xeffe);
35185
35186@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35187 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35188 int pipe;
35189
35190- atomic_set(&dev_priv->irq_received, 0);
35191+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35192
35193 /* VLV magic */
35194 I915_WRITE(VLV_IMR, 0);
35195@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35196 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35197 int pipe;
35198
35199- atomic_set(&dev_priv->irq_received, 0);
35200+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35201
35202 for_each_pipe(pipe)
35203 I915_WRITE(PIPESTAT(pipe), 0);
35204@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35205 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35206 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35207
35208- atomic_inc(&dev_priv->irq_received);
35209+ atomic_inc_unchecked(&dev_priv->irq_received);
35210
35211 iir = I915_READ16(IIR);
35212 if (iir == 0)
35213@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35214 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35215 int pipe;
35216
35217- atomic_set(&dev_priv->irq_received, 0);
35218+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35219
35220 if (I915_HAS_HOTPLUG(dev)) {
35221 I915_WRITE(PORT_HOTPLUG_EN, 0);
35222@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35223 };
35224 int pipe, ret = IRQ_NONE;
35225
35226- atomic_inc(&dev_priv->irq_received);
35227+ atomic_inc_unchecked(&dev_priv->irq_received);
35228
35229 iir = I915_READ(IIR);
35230 do {
35231@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35232 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35233 int pipe;
35234
35235- atomic_set(&dev_priv->irq_received, 0);
35236+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35237
35238 I915_WRITE(PORT_HOTPLUG_EN, 0);
35239 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35240@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35241 int irq_received;
35242 int ret = IRQ_NONE, pipe;
35243
35244- atomic_inc(&dev_priv->irq_received);
35245+ atomic_inc_unchecked(&dev_priv->irq_received);
35246
35247 iir = I915_READ(IIR);
35248
35249diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35250index 80aa1fc..85cfce3 100644
35251--- a/drivers/gpu/drm/i915/intel_display.c
35252+++ b/drivers/gpu/drm/i915/intel_display.c
35253@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35254
35255 wait_event(dev_priv->pending_flip_queue,
35256 atomic_read(&dev_priv->mm.wedged) ||
35257- atomic_read(&obj->pending_flip) == 0);
35258+ atomic_read_unchecked(&obj->pending_flip) == 0);
35259
35260 /* Big Hammer, we also need to ensure that any pending
35261 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35262@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35263
35264 obj = work->old_fb_obj;
35265
35266- atomic_clear_mask(1 << intel_crtc->plane,
35267- &obj->pending_flip.counter);
35268+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35269 wake_up(&dev_priv->pending_flip_queue);
35270
35271 queue_work(dev_priv->wq, &work->work);
35272@@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35273 /* Block clients from rendering to the new back buffer until
35274 * the flip occurs and the object is no longer visible.
35275 */
35276- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35277+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35278 atomic_inc(&intel_crtc->unpin_work_count);
35279
35280 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35281@@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35282
35283 cleanup_pending:
35284 atomic_dec(&intel_crtc->unpin_work_count);
35285- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35286+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35287 drm_gem_object_unreference(&work->old_fb_obj->base);
35288 drm_gem_object_unreference(&obj->base);
35289 mutex_unlock(&dev->struct_mutex);
35290@@ -8849,13 +8848,13 @@ struct intel_quirk {
35291 int subsystem_vendor;
35292 int subsystem_device;
35293 void (*hook)(struct drm_device *dev);
35294-};
35295+} __do_const;
35296
35297 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35298 struct intel_dmi_quirk {
35299 void (*hook)(struct drm_device *dev);
35300 const struct dmi_system_id (*dmi_id_list)[];
35301-};
35302+} __do_const;
35303
35304 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35305 {
35306@@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35307 return 1;
35308 }
35309
35310+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35311+ {
35312+ .callback = intel_dmi_reverse_brightness,
35313+ .ident = "NCR Corporation",
35314+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35315+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35316+ },
35317+ },
35318+ { } /* terminating entry */
35319+};
35320+
35321 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35322 {
35323- .dmi_id_list = &(const struct dmi_system_id[]) {
35324- {
35325- .callback = intel_dmi_reverse_brightness,
35326- .ident = "NCR Corporation",
35327- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35328- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35329- },
35330- },
35331- { } /* terminating entry */
35332- },
35333+ .dmi_id_list = &intel_dmi_quirks_table,
35334 .hook = quirk_invert_brightness,
35335 },
35336 };
35337diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35338index 54558a0..2d97005 100644
35339--- a/drivers/gpu/drm/mga/mga_drv.h
35340+++ b/drivers/gpu/drm/mga/mga_drv.h
35341@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35342 u32 clear_cmd;
35343 u32 maccess;
35344
35345- atomic_t vbl_received; /**< Number of vblanks received. */
35346+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35347 wait_queue_head_t fence_queue;
35348- atomic_t last_fence_retired;
35349+ atomic_unchecked_t last_fence_retired;
35350 u32 next_fence_to_post;
35351
35352 unsigned int fb_cpp;
35353diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35354index 709e90d..89a1c0d 100644
35355--- a/drivers/gpu/drm/mga/mga_ioc32.c
35356+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35357@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35358 return 0;
35359 }
35360
35361-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35362+drm_ioctl_compat_t mga_compat_ioctls[] = {
35363 [DRM_MGA_INIT] = compat_mga_init,
35364 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35365 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35366@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35367 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35368 {
35369 unsigned int nr = DRM_IOCTL_NR(cmd);
35370- drm_ioctl_compat_t *fn = NULL;
35371 int ret;
35372
35373 if (nr < DRM_COMMAND_BASE)
35374 return drm_compat_ioctl(filp, cmd, arg);
35375
35376- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35377- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35378-
35379- if (fn != NULL)
35380+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35381+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35382 ret = (*fn) (filp, cmd, arg);
35383- else
35384+ } else
35385 ret = drm_ioctl(filp, cmd, arg);
35386
35387 return ret;
35388diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35389index 598c281..60d590e 100644
35390--- a/drivers/gpu/drm/mga/mga_irq.c
35391+++ b/drivers/gpu/drm/mga/mga_irq.c
35392@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35393 if (crtc != 0)
35394 return 0;
35395
35396- return atomic_read(&dev_priv->vbl_received);
35397+ return atomic_read_unchecked(&dev_priv->vbl_received);
35398 }
35399
35400
35401@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35402 /* VBLANK interrupt */
35403 if (status & MGA_VLINEPEN) {
35404 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35405- atomic_inc(&dev_priv->vbl_received);
35406+ atomic_inc_unchecked(&dev_priv->vbl_received);
35407 drm_handle_vblank(dev, 0);
35408 handled = 1;
35409 }
35410@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35411 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35412 MGA_WRITE(MGA_PRIMEND, prim_end);
35413
35414- atomic_inc(&dev_priv->last_fence_retired);
35415+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35416 DRM_WAKEUP(&dev_priv->fence_queue);
35417 handled = 1;
35418 }
35419@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35420 * using fences.
35421 */
35422 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35423- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35424+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35425 - *sequence) <= (1 << 23)));
35426
35427 *sequence = cur_fence;
35428diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35429index 865eddf..62c4cc3 100644
35430--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35431+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35432@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35433 struct bit_table {
35434 const char id;
35435 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35436-};
35437+} __no_const;
35438
35439 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35440
35441diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35442index aa89eb9..d45d38b 100644
35443--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35444+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35445@@ -80,7 +80,7 @@ struct nouveau_drm {
35446 struct drm_global_reference mem_global_ref;
35447 struct ttm_bo_global_ref bo_global_ref;
35448 struct ttm_bo_device bdev;
35449- atomic_t validate_sequence;
35450+ atomic_unchecked_t validate_sequence;
35451 int (*move)(struct nouveau_channel *,
35452 struct ttm_buffer_object *,
35453 struct ttm_mem_reg *, struct ttm_mem_reg *);
35454diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35455index cdb83ac..27f0a16 100644
35456--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35457+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35458@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35459 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35460 struct nouveau_channel *);
35461 u32 (*read)(struct nouveau_channel *);
35462-};
35463+} __no_const;
35464
35465 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35466
35467diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35468index 8bf695c..9fbc90a 100644
35469--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35470+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35471@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35472 int trycnt = 0;
35473 int ret, i;
35474
35475- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35476+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35477 retry:
35478 if (++trycnt > 100000) {
35479 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35480diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35481index 08214bc..9208577 100644
35482--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35483+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35484@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35485 unsigned long arg)
35486 {
35487 unsigned int nr = DRM_IOCTL_NR(cmd);
35488- drm_ioctl_compat_t *fn = NULL;
35489+ drm_ioctl_compat_t fn = NULL;
35490 int ret;
35491
35492 if (nr < DRM_COMMAND_BASE)
35493diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35494index 25d3495..d81aaf6 100644
35495--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35496+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35497@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35498 bool can_switch;
35499
35500 spin_lock(&dev->count_lock);
35501- can_switch = (dev->open_count == 0);
35502+ can_switch = (local_read(&dev->open_count) == 0);
35503 spin_unlock(&dev->count_lock);
35504 return can_switch;
35505 }
35506diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35507index d4660cf..70dbe65 100644
35508--- a/drivers/gpu/drm/r128/r128_cce.c
35509+++ b/drivers/gpu/drm/r128/r128_cce.c
35510@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35511
35512 /* GH: Simple idle check.
35513 */
35514- atomic_set(&dev_priv->idle_count, 0);
35515+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35516
35517 /* We don't support anything other than bus-mastering ring mode,
35518 * but the ring can be in either AGP or PCI space for the ring
35519diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35520index 930c71b..499aded 100644
35521--- a/drivers/gpu/drm/r128/r128_drv.h
35522+++ b/drivers/gpu/drm/r128/r128_drv.h
35523@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35524 int is_pci;
35525 unsigned long cce_buffers_offset;
35526
35527- atomic_t idle_count;
35528+ atomic_unchecked_t idle_count;
35529
35530 int page_flipping;
35531 int current_page;
35532 u32 crtc_offset;
35533 u32 crtc_offset_cntl;
35534
35535- atomic_t vbl_received;
35536+ atomic_unchecked_t vbl_received;
35537
35538 u32 color_fmt;
35539 unsigned int front_offset;
35540diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35541index a954c54..9cc595c 100644
35542--- a/drivers/gpu/drm/r128/r128_ioc32.c
35543+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35544@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35545 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35546 }
35547
35548-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35549+drm_ioctl_compat_t r128_compat_ioctls[] = {
35550 [DRM_R128_INIT] = compat_r128_init,
35551 [DRM_R128_DEPTH] = compat_r128_depth,
35552 [DRM_R128_STIPPLE] = compat_r128_stipple,
35553@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35554 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35555 {
35556 unsigned int nr = DRM_IOCTL_NR(cmd);
35557- drm_ioctl_compat_t *fn = NULL;
35558 int ret;
35559
35560 if (nr < DRM_COMMAND_BASE)
35561 return drm_compat_ioctl(filp, cmd, arg);
35562
35563- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35564- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35565-
35566- if (fn != NULL)
35567+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35568+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35569 ret = (*fn) (filp, cmd, arg);
35570- else
35571+ } else
35572 ret = drm_ioctl(filp, cmd, arg);
35573
35574 return ret;
35575diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35576index 2ea4f09..d391371 100644
35577--- a/drivers/gpu/drm/r128/r128_irq.c
35578+++ b/drivers/gpu/drm/r128/r128_irq.c
35579@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35580 if (crtc != 0)
35581 return 0;
35582
35583- return atomic_read(&dev_priv->vbl_received);
35584+ return atomic_read_unchecked(&dev_priv->vbl_received);
35585 }
35586
35587 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35588@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35589 /* VBLANK interrupt */
35590 if (status & R128_CRTC_VBLANK_INT) {
35591 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35592- atomic_inc(&dev_priv->vbl_received);
35593+ atomic_inc_unchecked(&dev_priv->vbl_received);
35594 drm_handle_vblank(dev, 0);
35595 return IRQ_HANDLED;
35596 }
35597diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35598index 19bb7e6..de7e2a2 100644
35599--- a/drivers/gpu/drm/r128/r128_state.c
35600+++ b/drivers/gpu/drm/r128/r128_state.c
35601@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35602
35603 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35604 {
35605- if (atomic_read(&dev_priv->idle_count) == 0)
35606+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35607 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35608 else
35609- atomic_set(&dev_priv->idle_count, 0);
35610+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35611 }
35612
35613 #endif
35614diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35615index 5a82b6b..9e69c73 100644
35616--- a/drivers/gpu/drm/radeon/mkregtable.c
35617+++ b/drivers/gpu/drm/radeon/mkregtable.c
35618@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35619 regex_t mask_rex;
35620 regmatch_t match[4];
35621 char buf[1024];
35622- size_t end;
35623+ long end;
35624 int len;
35625 int done = 0;
35626 int r;
35627 unsigned o;
35628 struct offset *offset;
35629 char last_reg_s[10];
35630- int last_reg;
35631+ unsigned long last_reg;
35632
35633 if (regcomp
35634 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35635diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35636index 0d6562b..a154330 100644
35637--- a/drivers/gpu/drm/radeon/radeon_device.c
35638+++ b/drivers/gpu/drm/radeon/radeon_device.c
35639@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35640 bool can_switch;
35641
35642 spin_lock(&dev->count_lock);
35643- can_switch = (dev->open_count == 0);
35644+ can_switch = (local_read(&dev->open_count) == 0);
35645 spin_unlock(&dev->count_lock);
35646 return can_switch;
35647 }
35648diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35649index e7fdf16..f4f6490 100644
35650--- a/drivers/gpu/drm/radeon/radeon_drv.h
35651+++ b/drivers/gpu/drm/radeon/radeon_drv.h
35652@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35653
35654 /* SW interrupt */
35655 wait_queue_head_t swi_queue;
35656- atomic_t swi_emitted;
35657+ atomic_unchecked_t swi_emitted;
35658 int vblank_crtc;
35659 uint32_t irq_enable_reg;
35660 uint32_t r500_disp_irq_reg;
35661diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35662index c180df8..5fd8186 100644
35663--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35664+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35665@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35666 request = compat_alloc_user_space(sizeof(*request));
35667 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35668 || __put_user(req32.param, &request->param)
35669- || __put_user((void __user *)(unsigned long)req32.value,
35670+ || __put_user((unsigned long)req32.value,
35671 &request->value))
35672 return -EFAULT;
35673
35674@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35675 #define compat_radeon_cp_setparam NULL
35676 #endif /* X86_64 || IA64 */
35677
35678-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35679+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35680 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35681 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35682 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35683@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35684 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35685 {
35686 unsigned int nr = DRM_IOCTL_NR(cmd);
35687- drm_ioctl_compat_t *fn = NULL;
35688 int ret;
35689
35690 if (nr < DRM_COMMAND_BASE)
35691 return drm_compat_ioctl(filp, cmd, arg);
35692
35693- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35694- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35695-
35696- if (fn != NULL)
35697+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35698+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35699 ret = (*fn) (filp, cmd, arg);
35700- else
35701+ } else
35702 ret = drm_ioctl(filp, cmd, arg);
35703
35704 return ret;
35705diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35706index e771033..a0bc6b3 100644
35707--- a/drivers/gpu/drm/radeon/radeon_irq.c
35708+++ b/drivers/gpu/drm/radeon/radeon_irq.c
35709@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35710 unsigned int ret;
35711 RING_LOCALS;
35712
35713- atomic_inc(&dev_priv->swi_emitted);
35714- ret = atomic_read(&dev_priv->swi_emitted);
35715+ atomic_inc_unchecked(&dev_priv->swi_emitted);
35716+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35717
35718 BEGIN_RING(4);
35719 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35720@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35721 drm_radeon_private_t *dev_priv =
35722 (drm_radeon_private_t *) dev->dev_private;
35723
35724- atomic_set(&dev_priv->swi_emitted, 0);
35725+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35726 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35727
35728 dev->max_vblank_count = 0x001fffff;
35729diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35730index 8e9057b..af6dacb 100644
35731--- a/drivers/gpu/drm/radeon/radeon_state.c
35732+++ b/drivers/gpu/drm/radeon/radeon_state.c
35733@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35734 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35735 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35736
35737- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35738+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35739 sarea_priv->nbox * sizeof(depth_boxes[0])))
35740 return -EFAULT;
35741
35742@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35743 {
35744 drm_radeon_private_t *dev_priv = dev->dev_private;
35745 drm_radeon_getparam_t *param = data;
35746- int value;
35747+ int value = 0;
35748
35749 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35750
35751diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35752index 93f760e..8088227 100644
35753--- a/drivers/gpu/drm/radeon/radeon_ttm.c
35754+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35755@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35756 man->size = size >> PAGE_SHIFT;
35757 }
35758
35759-static struct vm_operations_struct radeon_ttm_vm_ops;
35760+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35761 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35762
35763 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35764@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35765 }
35766 if (unlikely(ttm_vm_ops == NULL)) {
35767 ttm_vm_ops = vma->vm_ops;
35768+ pax_open_kernel();
35769 radeon_ttm_vm_ops = *ttm_vm_ops;
35770 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35771+ pax_close_kernel();
35772 }
35773 vma->vm_ops = &radeon_ttm_vm_ops;
35774 return 0;
35775@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35776 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35777 else
35778 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35779- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35780- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35781- radeon_mem_types_list[i].driver_features = 0;
35782+ pax_open_kernel();
35783+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35784+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35785+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35786 if (i == 0)
35787- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35788+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35789 else
35790- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35791-
35792+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35793+ pax_close_kernel();
35794 }
35795 /* Add ttm page pool to debugfs */
35796 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35797- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35798- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35799- radeon_mem_types_list[i].driver_features = 0;
35800- radeon_mem_types_list[i++].data = NULL;
35801+ pax_open_kernel();
35802+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35803+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35804+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35805+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35806+ pax_close_kernel();
35807 #ifdef CONFIG_SWIOTLB
35808 if (swiotlb_nr_tbl()) {
35809 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35810- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35811- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35812- radeon_mem_types_list[i].driver_features = 0;
35813- radeon_mem_types_list[i++].data = NULL;
35814+ pax_open_kernel();
35815+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35816+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35817+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35818+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35819+ pax_close_kernel();
35820 }
35821 #endif
35822 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35823diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35824index 5706d2a..17aedaa 100644
35825--- a/drivers/gpu/drm/radeon/rs690.c
35826+++ b/drivers/gpu/drm/radeon/rs690.c
35827@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35828 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35829 rdev->pm.sideport_bandwidth.full)
35830 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35831- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35832+ read_delay_latency.full = dfixed_const(800 * 1000);
35833 read_delay_latency.full = dfixed_div(read_delay_latency,
35834 rdev->pm.igp_sideport_mclk);
35835+ a.full = dfixed_const(370);
35836+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35837 } else {
35838 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35839 rdev->pm.k8_bandwidth.full)
35840diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35841index bd2a3b4..122d9ad 100644
35842--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35843+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35844@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35845 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35846 struct shrink_control *sc)
35847 {
35848- static atomic_t start_pool = ATOMIC_INIT(0);
35849+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35850 unsigned i;
35851- unsigned pool_offset = atomic_add_return(1, &start_pool);
35852+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35853 struct ttm_page_pool *pool;
35854 int shrink_pages = sc->nr_to_scan;
35855
35856diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35857index 1eb060c..188b1fc 100644
35858--- a/drivers/gpu/drm/udl/udl_fb.c
35859+++ b/drivers/gpu/drm/udl/udl_fb.c
35860@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35861 fb_deferred_io_cleanup(info);
35862 kfree(info->fbdefio);
35863 info->fbdefio = NULL;
35864- info->fbops->fb_mmap = udl_fb_mmap;
35865 }
35866
35867 pr_warn("released /dev/fb%d user=%d count=%d\n",
35868diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35869index 893a650..6190d3b 100644
35870--- a/drivers/gpu/drm/via/via_drv.h
35871+++ b/drivers/gpu/drm/via/via_drv.h
35872@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35873 typedef uint32_t maskarray_t[5];
35874
35875 typedef struct drm_via_irq {
35876- atomic_t irq_received;
35877+ atomic_unchecked_t irq_received;
35878 uint32_t pending_mask;
35879 uint32_t enable_mask;
35880 wait_queue_head_t irq_queue;
35881@@ -75,7 +75,7 @@ typedef struct drm_via_private {
35882 struct timeval last_vblank;
35883 int last_vblank_valid;
35884 unsigned usec_per_vblank;
35885- atomic_t vbl_received;
35886+ atomic_unchecked_t vbl_received;
35887 drm_via_state_t hc_state;
35888 char pci_buf[VIA_PCI_BUF_SIZE];
35889 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35890diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35891index ac98964..5dbf512 100644
35892--- a/drivers/gpu/drm/via/via_irq.c
35893+++ b/drivers/gpu/drm/via/via_irq.c
35894@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35895 if (crtc != 0)
35896 return 0;
35897
35898- return atomic_read(&dev_priv->vbl_received);
35899+ return atomic_read_unchecked(&dev_priv->vbl_received);
35900 }
35901
35902 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35903@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35904
35905 status = VIA_READ(VIA_REG_INTERRUPT);
35906 if (status & VIA_IRQ_VBLANK_PENDING) {
35907- atomic_inc(&dev_priv->vbl_received);
35908- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35909+ atomic_inc_unchecked(&dev_priv->vbl_received);
35910+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35911 do_gettimeofday(&cur_vblank);
35912 if (dev_priv->last_vblank_valid) {
35913 dev_priv->usec_per_vblank =
35914@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35915 dev_priv->last_vblank = cur_vblank;
35916 dev_priv->last_vblank_valid = 1;
35917 }
35918- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35919+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35920 DRM_DEBUG("US per vblank is: %u\n",
35921 dev_priv->usec_per_vblank);
35922 }
35923@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35924
35925 for (i = 0; i < dev_priv->num_irqs; ++i) {
35926 if (status & cur_irq->pending_mask) {
35927- atomic_inc(&cur_irq->irq_received);
35928+ atomic_inc_unchecked(&cur_irq->irq_received);
35929 DRM_WAKEUP(&cur_irq->irq_queue);
35930 handled = 1;
35931 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35932@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35933 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35934 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35935 masks[irq][4]));
35936- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35937+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35938 } else {
35939 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35940 (((cur_irq_sequence =
35941- atomic_read(&cur_irq->irq_received)) -
35942+ atomic_read_unchecked(&cur_irq->irq_received)) -
35943 *sequence) <= (1 << 23)));
35944 }
35945 *sequence = cur_irq_sequence;
35946@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35947 }
35948
35949 for (i = 0; i < dev_priv->num_irqs; ++i) {
35950- atomic_set(&cur_irq->irq_received, 0);
35951+ atomic_set_unchecked(&cur_irq->irq_received, 0);
35952 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35953 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35954 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35955@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35956 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35957 case VIA_IRQ_RELATIVE:
35958 irqwait->request.sequence +=
35959- atomic_read(&cur_irq->irq_received);
35960+ atomic_read_unchecked(&cur_irq->irq_received);
35961 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35962 case VIA_IRQ_ABSOLUTE:
35963 break;
35964diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35965index 13aeda7..4a952d1 100644
35966--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35967+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35968@@ -290,7 +290,7 @@ struct vmw_private {
35969 * Fencing and IRQs.
35970 */
35971
35972- atomic_t marker_seq;
35973+ atomic_unchecked_t marker_seq;
35974 wait_queue_head_t fence_queue;
35975 wait_queue_head_t fifo_queue;
35976 int fence_queue_waiters; /* Protected by hw_mutex */
35977diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35978index 3eb1486..0a47ee9 100644
35979--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35980+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35981@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35982 (unsigned int) min,
35983 (unsigned int) fifo->capabilities);
35984
35985- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35986+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35987 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35988 vmw_marker_queue_init(&fifo->marker_queue);
35989 return vmw_fifo_send_fence(dev_priv, &dummy);
35990@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35991 if (reserveable)
35992 iowrite32(bytes, fifo_mem +
35993 SVGA_FIFO_RESERVED);
35994- return fifo_mem + (next_cmd >> 2);
35995+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
35996 } else {
35997 need_bounce = true;
35998 }
35999@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36000
36001 fm = vmw_fifo_reserve(dev_priv, bytes);
36002 if (unlikely(fm == NULL)) {
36003- *seqno = atomic_read(&dev_priv->marker_seq);
36004+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36005 ret = -ENOMEM;
36006 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36007 false, 3*HZ);
36008@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36009 }
36010
36011 do {
36012- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36013+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36014 } while (*seqno == 0);
36015
36016 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36017diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36018index 4640adb..e1384ed 100644
36019--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36020+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36021@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36022 * emitted. Then the fence is stale and signaled.
36023 */
36024
36025- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36026+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36027 > VMW_FENCE_WRAP);
36028
36029 return ret;
36030@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36031
36032 if (fifo_idle)
36033 down_read(&fifo_state->rwsem);
36034- signal_seq = atomic_read(&dev_priv->marker_seq);
36035+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36036 ret = 0;
36037
36038 for (;;) {
36039diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36040index 8a8725c..afed796 100644
36041--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36042+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36043@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36044 while (!vmw_lag_lt(queue, us)) {
36045 spin_lock(&queue->lock);
36046 if (list_empty(&queue->head))
36047- seqno = atomic_read(&dev_priv->marker_seq);
36048+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36049 else {
36050 marker = list_first_entry(&queue->head,
36051 struct vmw_marker, head);
36052diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36053index ceb3040..6160c5c 100644
36054--- a/drivers/hid/hid-core.c
36055+++ b/drivers/hid/hid-core.c
36056@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36057
36058 int hid_add_device(struct hid_device *hdev)
36059 {
36060- static atomic_t id = ATOMIC_INIT(0);
36061+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36062 int ret;
36063
36064 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36065@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
36066 /* XXX hack, any other cleaner solution after the driver core
36067 * is converted to allow more than 20 bytes as the device name? */
36068 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36069- hdev->vendor, hdev->product, atomic_inc_return(&id));
36070+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36071
36072 hid_debug_register(hdev, dev_name(&hdev->dev));
36073 ret = device_add(&hdev->dev);
36074diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36075index eec3291..8ed706b 100644
36076--- a/drivers/hid/hid-wiimote-debug.c
36077+++ b/drivers/hid/hid-wiimote-debug.c
36078@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36079 else if (size == 0)
36080 return -EIO;
36081
36082- if (copy_to_user(u, buf, size))
36083+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36084 return -EFAULT;
36085
36086 *off += size;
36087diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36088index 773a2f2..7ce08bc 100644
36089--- a/drivers/hv/channel.c
36090+++ b/drivers/hv/channel.c
36091@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36092 int ret = 0;
36093 int t;
36094
36095- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36096- atomic_inc(&vmbus_connection.next_gpadl_handle);
36097+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36098+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36099
36100 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36101 if (ret)
36102diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36103index 3648f8f..30ef30d 100644
36104--- a/drivers/hv/hv.c
36105+++ b/drivers/hv/hv.c
36106@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36107 u64 output_address = (output) ? virt_to_phys(output) : 0;
36108 u32 output_address_hi = output_address >> 32;
36109 u32 output_address_lo = output_address & 0xFFFFFFFF;
36110- void *hypercall_page = hv_context.hypercall_page;
36111+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36112
36113 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36114 "=a"(hv_status_lo) : "d" (control_hi),
36115diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36116index d8d1fad..b91caf7 100644
36117--- a/drivers/hv/hyperv_vmbus.h
36118+++ b/drivers/hv/hyperv_vmbus.h
36119@@ -594,7 +594,7 @@ enum vmbus_connect_state {
36120 struct vmbus_connection {
36121 enum vmbus_connect_state conn_state;
36122
36123- atomic_t next_gpadl_handle;
36124+ atomic_unchecked_t next_gpadl_handle;
36125
36126 /*
36127 * Represents channel interrupts. Each bit position represents a
36128diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36129index 8e1a9ec..4687821 100644
36130--- a/drivers/hv/vmbus_drv.c
36131+++ b/drivers/hv/vmbus_drv.c
36132@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36133 {
36134 int ret = 0;
36135
36136- static atomic_t device_num = ATOMIC_INIT(0);
36137+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36138
36139 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36140- atomic_inc_return(&device_num));
36141+ atomic_inc_return_unchecked(&device_num));
36142
36143 child_device_obj->device.bus = &hv_bus;
36144 child_device_obj->device.parent = &hv_acpi_dev->dev;
36145diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36146index 1672e2a..4a6297c 100644
36147--- a/drivers/hwmon/acpi_power_meter.c
36148+++ b/drivers/hwmon/acpi_power_meter.c
36149@@ -117,7 +117,7 @@ struct sensor_template {
36150 struct device_attribute *devattr,
36151 const char *buf, size_t count);
36152 int index;
36153-};
36154+} __do_const;
36155
36156 /* Averaging interval */
36157 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36158@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36159 struct sensor_template *attrs)
36160 {
36161 struct device *dev = &resource->acpi_dev->dev;
36162- struct sensor_device_attribute *sensors =
36163+ sensor_device_attribute_no_const *sensors =
36164 &resource->sensors[resource->num_sensors];
36165 int res = 0;
36166
36167diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36168index b41baff..4953e4d 100644
36169--- a/drivers/hwmon/applesmc.c
36170+++ b/drivers/hwmon/applesmc.c
36171@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36172 {
36173 struct applesmc_node_group *grp;
36174 struct applesmc_dev_attr *node;
36175- struct attribute *attr;
36176+ attribute_no_const *attr;
36177 int ret, i;
36178
36179 for (grp = groups; grp->format; grp++) {
36180diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36181index 56dbcfb..9874bf1 100644
36182--- a/drivers/hwmon/asus_atk0110.c
36183+++ b/drivers/hwmon/asus_atk0110.c
36184@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36185 struct atk_sensor_data {
36186 struct list_head list;
36187 struct atk_data *data;
36188- struct device_attribute label_attr;
36189- struct device_attribute input_attr;
36190- struct device_attribute limit1_attr;
36191- struct device_attribute limit2_attr;
36192+ device_attribute_no_const label_attr;
36193+ device_attribute_no_const input_attr;
36194+ device_attribute_no_const limit1_attr;
36195+ device_attribute_no_const limit2_attr;
36196 char label_attr_name[ATTR_NAME_SIZE];
36197 char input_attr_name[ATTR_NAME_SIZE];
36198 char limit1_attr_name[ATTR_NAME_SIZE];
36199@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36200 static struct device_attribute atk_name_attr =
36201 __ATTR(name, 0444, atk_name_show, NULL);
36202
36203-static void atk_init_attribute(struct device_attribute *attr, char *name,
36204+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36205 sysfs_show_func show)
36206 {
36207 sysfs_attr_init(&attr->attr);
36208diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36209index d64923d..72591e8 100644
36210--- a/drivers/hwmon/coretemp.c
36211+++ b/drivers/hwmon/coretemp.c
36212@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36213 return NOTIFY_OK;
36214 }
36215
36216-static struct notifier_block coretemp_cpu_notifier __refdata = {
36217+static struct notifier_block coretemp_cpu_notifier = {
36218 .notifier_call = coretemp_cpu_callback,
36219 };
36220
36221diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36222index a14f634..2916ee2 100644
36223--- a/drivers/hwmon/ibmaem.c
36224+++ b/drivers/hwmon/ibmaem.c
36225@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36226 struct aem_rw_sensor_template *rw)
36227 {
36228 struct device *dev = &data->pdev->dev;
36229- struct sensor_device_attribute *sensors = data->sensors;
36230+ sensor_device_attribute_no_const *sensors = data->sensors;
36231 int err;
36232
36233 /* Set up read-only sensors */
36234diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36235index 7d19b1b..8fdaaac 100644
36236--- a/drivers/hwmon/pmbus/pmbus_core.c
36237+++ b/drivers/hwmon/pmbus/pmbus_core.c
36238@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36239
36240 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36241 do { \
36242- struct sensor_device_attribute *a \
36243+ sensor_device_attribute_no_const *a \
36244 = &data->_type##s[data->num_##_type##s].attribute; \
36245 BUG_ON(data->num_attributes >= data->max_attributes); \
36246 sysfs_attr_init(&a->dev_attr.attr); \
36247diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36248index 8047fed..1e956f0 100644
36249--- a/drivers/hwmon/sht15.c
36250+++ b/drivers/hwmon/sht15.c
36251@@ -169,7 +169,7 @@ struct sht15_data {
36252 int supply_uV;
36253 bool supply_uV_valid;
36254 struct work_struct update_supply_work;
36255- atomic_t interrupt_handled;
36256+ atomic_unchecked_t interrupt_handled;
36257 };
36258
36259 /**
36260@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36261 return ret;
36262
36263 gpio_direction_input(data->pdata->gpio_data);
36264- atomic_set(&data->interrupt_handled, 0);
36265+ atomic_set_unchecked(&data->interrupt_handled, 0);
36266
36267 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36268 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36269 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36270 /* Only relevant if the interrupt hasn't occurred. */
36271- if (!atomic_read(&data->interrupt_handled))
36272+ if (!atomic_read_unchecked(&data->interrupt_handled))
36273 schedule_work(&data->read_work);
36274 }
36275 ret = wait_event_timeout(data->wait_queue,
36276@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36277
36278 /* First disable the interrupt */
36279 disable_irq_nosync(irq);
36280- atomic_inc(&data->interrupt_handled);
36281+ atomic_inc_unchecked(&data->interrupt_handled);
36282 /* Then schedule a reading work struct */
36283 if (data->state != SHT15_READING_NOTHING)
36284 schedule_work(&data->read_work);
36285@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36286 * If not, then start the interrupt again - care here as could
36287 * have gone low in meantime so verify it hasn't!
36288 */
36289- atomic_set(&data->interrupt_handled, 0);
36290+ atomic_set_unchecked(&data->interrupt_handled, 0);
36291 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36292 /* If still not occurred or another handler was scheduled */
36293 if (gpio_get_value(data->pdata->gpio_data)
36294- || atomic_read(&data->interrupt_handled))
36295+ || atomic_read_unchecked(&data->interrupt_handled))
36296 return;
36297 }
36298
36299diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36300index 76f157b..9c0db1b 100644
36301--- a/drivers/hwmon/via-cputemp.c
36302+++ b/drivers/hwmon/via-cputemp.c
36303@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36304 return NOTIFY_OK;
36305 }
36306
36307-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36308+static struct notifier_block via_cputemp_cpu_notifier = {
36309 .notifier_call = via_cputemp_cpu_callback,
36310 };
36311
36312diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36313index 378fcb5..5e91fa8 100644
36314--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36315+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36316@@ -43,7 +43,7 @@
36317 extern struct i2c_adapter amd756_smbus;
36318
36319 static struct i2c_adapter *s4882_adapter;
36320-static struct i2c_algorithm *s4882_algo;
36321+static i2c_algorithm_no_const *s4882_algo;
36322
36323 /* Wrapper access functions for multiplexed SMBus */
36324 static DEFINE_MUTEX(amd756_lock);
36325diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36326index 29015eb..af2d8e9 100644
36327--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36328+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36329@@ -41,7 +41,7 @@
36330 extern struct i2c_adapter *nforce2_smbus;
36331
36332 static struct i2c_adapter *s4985_adapter;
36333-static struct i2c_algorithm *s4985_algo;
36334+static i2c_algorithm_no_const *s4985_algo;
36335
36336 /* Wrapper access functions for multiplexed SMBus */
36337 static DEFINE_MUTEX(nforce2_lock);
36338diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36339index 8126824..55a2798 100644
36340--- a/drivers/ide/ide-cd.c
36341+++ b/drivers/ide/ide-cd.c
36342@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36343 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36344 if ((unsigned long)buf & alignment
36345 || blk_rq_bytes(rq) & q->dma_pad_mask
36346- || object_is_on_stack(buf))
36347+ || object_starts_on_stack(buf))
36348 drive->dma = 0;
36349 }
36350 }
36351diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36352index 8848f16..f8e6dd8 100644
36353--- a/drivers/iio/industrialio-core.c
36354+++ b/drivers/iio/industrialio-core.c
36355@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36356 }
36357
36358 static
36359-int __iio_device_attr_init(struct device_attribute *dev_attr,
36360+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36361 const char *postfix,
36362 struct iio_chan_spec const *chan,
36363 ssize_t (*readfunc)(struct device *dev,
36364diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36365index 394fea2..c833880 100644
36366--- a/drivers/infiniband/core/cm.c
36367+++ b/drivers/infiniband/core/cm.c
36368@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36369
36370 struct cm_counter_group {
36371 struct kobject obj;
36372- atomic_long_t counter[CM_ATTR_COUNT];
36373+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36374 };
36375
36376 struct cm_counter_attribute {
36377@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36378 struct ib_mad_send_buf *msg = NULL;
36379 int ret;
36380
36381- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36382+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36383 counter[CM_REQ_COUNTER]);
36384
36385 /* Quick state check to discard duplicate REQs. */
36386@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36387 if (!cm_id_priv)
36388 return;
36389
36390- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36391+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36392 counter[CM_REP_COUNTER]);
36393 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36394 if (ret)
36395@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36396 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36397 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36398 spin_unlock_irq(&cm_id_priv->lock);
36399- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36400+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36401 counter[CM_RTU_COUNTER]);
36402 goto out;
36403 }
36404@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36405 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36406 dreq_msg->local_comm_id);
36407 if (!cm_id_priv) {
36408- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36409+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36410 counter[CM_DREQ_COUNTER]);
36411 cm_issue_drep(work->port, work->mad_recv_wc);
36412 return -EINVAL;
36413@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36414 case IB_CM_MRA_REP_RCVD:
36415 break;
36416 case IB_CM_TIMEWAIT:
36417- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36418+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36419 counter[CM_DREQ_COUNTER]);
36420 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36421 goto unlock;
36422@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36423 cm_free_msg(msg);
36424 goto deref;
36425 case IB_CM_DREQ_RCVD:
36426- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36427+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36428 counter[CM_DREQ_COUNTER]);
36429 goto unlock;
36430 default:
36431@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36432 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36433 cm_id_priv->msg, timeout)) {
36434 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36435- atomic_long_inc(&work->port->
36436+ atomic_long_inc_unchecked(&work->port->
36437 counter_group[CM_RECV_DUPLICATES].
36438 counter[CM_MRA_COUNTER]);
36439 goto out;
36440@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36441 break;
36442 case IB_CM_MRA_REQ_RCVD:
36443 case IB_CM_MRA_REP_RCVD:
36444- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36445+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36446 counter[CM_MRA_COUNTER]);
36447 /* fall through */
36448 default:
36449@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36450 case IB_CM_LAP_IDLE:
36451 break;
36452 case IB_CM_MRA_LAP_SENT:
36453- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36454+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36455 counter[CM_LAP_COUNTER]);
36456 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36457 goto unlock;
36458@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36459 cm_free_msg(msg);
36460 goto deref;
36461 case IB_CM_LAP_RCVD:
36462- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36463+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36464 counter[CM_LAP_COUNTER]);
36465 goto unlock;
36466 default:
36467@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36468 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36469 if (cur_cm_id_priv) {
36470 spin_unlock_irq(&cm.lock);
36471- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36472+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36473 counter[CM_SIDR_REQ_COUNTER]);
36474 goto out; /* Duplicate message. */
36475 }
36476@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36477 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36478 msg->retries = 1;
36479
36480- atomic_long_add(1 + msg->retries,
36481+ atomic_long_add_unchecked(1 + msg->retries,
36482 &port->counter_group[CM_XMIT].counter[attr_index]);
36483 if (msg->retries)
36484- atomic_long_add(msg->retries,
36485+ atomic_long_add_unchecked(msg->retries,
36486 &port->counter_group[CM_XMIT_RETRIES].
36487 counter[attr_index]);
36488
36489@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36490 }
36491
36492 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36493- atomic_long_inc(&port->counter_group[CM_RECV].
36494+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36495 counter[attr_id - CM_ATTR_ID_OFFSET]);
36496
36497 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36498@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36499 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36500
36501 return sprintf(buf, "%ld\n",
36502- atomic_long_read(&group->counter[cm_attr->index]));
36503+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36504 }
36505
36506 static const struct sysfs_ops cm_counter_ops = {
36507diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36508index 176c8f9..2627b62 100644
36509--- a/drivers/infiniband/core/fmr_pool.c
36510+++ b/drivers/infiniband/core/fmr_pool.c
36511@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36512
36513 struct task_struct *thread;
36514
36515- atomic_t req_ser;
36516- atomic_t flush_ser;
36517+ atomic_unchecked_t req_ser;
36518+ atomic_unchecked_t flush_ser;
36519
36520 wait_queue_head_t force_wait;
36521 };
36522@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36523 struct ib_fmr_pool *pool = pool_ptr;
36524
36525 do {
36526- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36527+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36528 ib_fmr_batch_release(pool);
36529
36530- atomic_inc(&pool->flush_ser);
36531+ atomic_inc_unchecked(&pool->flush_ser);
36532 wake_up_interruptible(&pool->force_wait);
36533
36534 if (pool->flush_function)
36535@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36536 }
36537
36538 set_current_state(TASK_INTERRUPTIBLE);
36539- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36540+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36541 !kthread_should_stop())
36542 schedule();
36543 __set_current_state(TASK_RUNNING);
36544@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36545 pool->dirty_watermark = params->dirty_watermark;
36546 pool->dirty_len = 0;
36547 spin_lock_init(&pool->pool_lock);
36548- atomic_set(&pool->req_ser, 0);
36549- atomic_set(&pool->flush_ser, 0);
36550+ atomic_set_unchecked(&pool->req_ser, 0);
36551+ atomic_set_unchecked(&pool->flush_ser, 0);
36552 init_waitqueue_head(&pool->force_wait);
36553
36554 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36555@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36556 }
36557 spin_unlock_irq(&pool->pool_lock);
36558
36559- serial = atomic_inc_return(&pool->req_ser);
36560+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36561 wake_up_process(pool->thread);
36562
36563 if (wait_event_interruptible(pool->force_wait,
36564- atomic_read(&pool->flush_ser) - serial >= 0))
36565+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36566 return -EINTR;
36567
36568 return 0;
36569@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36570 } else {
36571 list_add_tail(&fmr->list, &pool->dirty_list);
36572 if (++pool->dirty_len >= pool->dirty_watermark) {
36573- atomic_inc(&pool->req_ser);
36574+ atomic_inc_unchecked(&pool->req_ser);
36575 wake_up_process(pool->thread);
36576 }
36577 }
36578diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36579index afd8179..598063f 100644
36580--- a/drivers/infiniband/hw/cxgb4/mem.c
36581+++ b/drivers/infiniband/hw/cxgb4/mem.c
36582@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36583 int err;
36584 struct fw_ri_tpte tpt;
36585 u32 stag_idx;
36586- static atomic_t key;
36587+ static atomic_unchecked_t key;
36588
36589 if (c4iw_fatal_error(rdev))
36590 return -EIO;
36591@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36592 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36593 rdev->stats.stag.max = rdev->stats.stag.cur;
36594 mutex_unlock(&rdev->stats.lock);
36595- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36596+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36597 }
36598 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36599 __func__, stag_state, type, pdid, stag_idx);
36600diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36601index 79b3dbc..96e5fcc 100644
36602--- a/drivers/infiniband/hw/ipath/ipath_rc.c
36603+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36604@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36605 struct ib_atomic_eth *ateth;
36606 struct ipath_ack_entry *e;
36607 u64 vaddr;
36608- atomic64_t *maddr;
36609+ atomic64_unchecked_t *maddr;
36610 u64 sdata;
36611 u32 rkey;
36612 u8 next;
36613@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36614 IB_ACCESS_REMOTE_ATOMIC)))
36615 goto nack_acc_unlck;
36616 /* Perform atomic OP and save result. */
36617- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36618+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36619 sdata = be64_to_cpu(ateth->swap_data);
36620 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36621 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36622- (u64) atomic64_add_return(sdata, maddr) - sdata :
36623+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36624 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36625 be64_to_cpu(ateth->compare_data),
36626 sdata);
36627diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36628index 1f95bba..9530f87 100644
36629--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36630+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36631@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36632 unsigned long flags;
36633 struct ib_wc wc;
36634 u64 sdata;
36635- atomic64_t *maddr;
36636+ atomic64_unchecked_t *maddr;
36637 enum ib_wc_status send_status;
36638
36639 /*
36640@@ -382,11 +382,11 @@ again:
36641 IB_ACCESS_REMOTE_ATOMIC)))
36642 goto acc_err;
36643 /* Perform atomic OP and save result. */
36644- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36645+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36646 sdata = wqe->wr.wr.atomic.compare_add;
36647 *(u64 *) sqp->s_sge.sge.vaddr =
36648 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36649- (u64) atomic64_add_return(sdata, maddr) - sdata :
36650+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36651 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36652 sdata, wqe->wr.wr.atomic.swap);
36653 goto send_comp;
36654diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
36655index 9d3e5c1..d9afe4a 100644
36656--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
36657+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
36658@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
36659 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
36660 }
36661
36662-int mthca_QUERY_FW(struct mthca_dev *dev)
36663+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
36664 {
36665 struct mthca_mailbox *mailbox;
36666 u32 *outbox;
36667diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
36668index ed9a989..e0c5871 100644
36669--- a/drivers/infiniband/hw/mthca/mthca_mr.c
36670+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
36671@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
36672 return key;
36673 }
36674
36675-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36676+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36677 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
36678 {
36679 struct mthca_mailbox *mailbox;
36680diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36681index 5b152a3..c1f3e83 100644
36682--- a/drivers/infiniband/hw/nes/nes.c
36683+++ b/drivers/infiniband/hw/nes/nes.c
36684@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36685 LIST_HEAD(nes_adapter_list);
36686 static LIST_HEAD(nes_dev_list);
36687
36688-atomic_t qps_destroyed;
36689+atomic_unchecked_t qps_destroyed;
36690
36691 static unsigned int ee_flsh_adapter;
36692 static unsigned int sysfs_nonidx_addr;
36693@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36694 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36695 struct nes_adapter *nesadapter = nesdev->nesadapter;
36696
36697- atomic_inc(&qps_destroyed);
36698+ atomic_inc_unchecked(&qps_destroyed);
36699
36700 /* Free the control structures */
36701
36702diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36703index 33cc589..3bd6538 100644
36704--- a/drivers/infiniband/hw/nes/nes.h
36705+++ b/drivers/infiniband/hw/nes/nes.h
36706@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36707 extern unsigned int wqm_quanta;
36708 extern struct list_head nes_adapter_list;
36709
36710-extern atomic_t cm_connects;
36711-extern atomic_t cm_accepts;
36712-extern atomic_t cm_disconnects;
36713-extern atomic_t cm_closes;
36714-extern atomic_t cm_connecteds;
36715-extern atomic_t cm_connect_reqs;
36716-extern atomic_t cm_rejects;
36717-extern atomic_t mod_qp_timouts;
36718-extern atomic_t qps_created;
36719-extern atomic_t qps_destroyed;
36720-extern atomic_t sw_qps_destroyed;
36721+extern atomic_unchecked_t cm_connects;
36722+extern atomic_unchecked_t cm_accepts;
36723+extern atomic_unchecked_t cm_disconnects;
36724+extern atomic_unchecked_t cm_closes;
36725+extern atomic_unchecked_t cm_connecteds;
36726+extern atomic_unchecked_t cm_connect_reqs;
36727+extern atomic_unchecked_t cm_rejects;
36728+extern atomic_unchecked_t mod_qp_timouts;
36729+extern atomic_unchecked_t qps_created;
36730+extern atomic_unchecked_t qps_destroyed;
36731+extern atomic_unchecked_t sw_qps_destroyed;
36732 extern u32 mh_detected;
36733 extern u32 mh_pauses_sent;
36734 extern u32 cm_packets_sent;
36735@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36736 extern u32 cm_packets_received;
36737 extern u32 cm_packets_dropped;
36738 extern u32 cm_packets_retrans;
36739-extern atomic_t cm_listens_created;
36740-extern atomic_t cm_listens_destroyed;
36741+extern atomic_unchecked_t cm_listens_created;
36742+extern atomic_unchecked_t cm_listens_destroyed;
36743 extern u32 cm_backlog_drops;
36744-extern atomic_t cm_loopbacks;
36745-extern atomic_t cm_nodes_created;
36746-extern atomic_t cm_nodes_destroyed;
36747-extern atomic_t cm_accel_dropped_pkts;
36748-extern atomic_t cm_resets_recvd;
36749-extern atomic_t pau_qps_created;
36750-extern atomic_t pau_qps_destroyed;
36751+extern atomic_unchecked_t cm_loopbacks;
36752+extern atomic_unchecked_t cm_nodes_created;
36753+extern atomic_unchecked_t cm_nodes_destroyed;
36754+extern atomic_unchecked_t cm_accel_dropped_pkts;
36755+extern atomic_unchecked_t cm_resets_recvd;
36756+extern atomic_unchecked_t pau_qps_created;
36757+extern atomic_unchecked_t pau_qps_destroyed;
36758
36759 extern u32 int_mod_timer_init;
36760 extern u32 int_mod_cq_depth_256;
36761diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36762index 22ea67e..dcbe3bc 100644
36763--- a/drivers/infiniband/hw/nes/nes_cm.c
36764+++ b/drivers/infiniband/hw/nes/nes_cm.c
36765@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36766 u32 cm_packets_retrans;
36767 u32 cm_packets_created;
36768 u32 cm_packets_received;
36769-atomic_t cm_listens_created;
36770-atomic_t cm_listens_destroyed;
36771+atomic_unchecked_t cm_listens_created;
36772+atomic_unchecked_t cm_listens_destroyed;
36773 u32 cm_backlog_drops;
36774-atomic_t cm_loopbacks;
36775-atomic_t cm_nodes_created;
36776-atomic_t cm_nodes_destroyed;
36777-atomic_t cm_accel_dropped_pkts;
36778-atomic_t cm_resets_recvd;
36779+atomic_unchecked_t cm_loopbacks;
36780+atomic_unchecked_t cm_nodes_created;
36781+atomic_unchecked_t cm_nodes_destroyed;
36782+atomic_unchecked_t cm_accel_dropped_pkts;
36783+atomic_unchecked_t cm_resets_recvd;
36784
36785 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36786 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36787@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36788
36789 static struct nes_cm_core *g_cm_core;
36790
36791-atomic_t cm_connects;
36792-atomic_t cm_accepts;
36793-atomic_t cm_disconnects;
36794-atomic_t cm_closes;
36795-atomic_t cm_connecteds;
36796-atomic_t cm_connect_reqs;
36797-atomic_t cm_rejects;
36798+atomic_unchecked_t cm_connects;
36799+atomic_unchecked_t cm_accepts;
36800+atomic_unchecked_t cm_disconnects;
36801+atomic_unchecked_t cm_closes;
36802+atomic_unchecked_t cm_connecteds;
36803+atomic_unchecked_t cm_connect_reqs;
36804+atomic_unchecked_t cm_rejects;
36805
36806 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36807 {
36808@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36809 kfree(listener);
36810 listener = NULL;
36811 ret = 0;
36812- atomic_inc(&cm_listens_destroyed);
36813+ atomic_inc_unchecked(&cm_listens_destroyed);
36814 } else {
36815 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36816 }
36817@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36818 cm_node->rem_mac);
36819
36820 add_hte_node(cm_core, cm_node);
36821- atomic_inc(&cm_nodes_created);
36822+ atomic_inc_unchecked(&cm_nodes_created);
36823
36824 return cm_node;
36825 }
36826@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36827 }
36828
36829 atomic_dec(&cm_core->node_cnt);
36830- atomic_inc(&cm_nodes_destroyed);
36831+ atomic_inc_unchecked(&cm_nodes_destroyed);
36832 nesqp = cm_node->nesqp;
36833 if (nesqp) {
36834 nesqp->cm_node = NULL;
36835@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36836
36837 static void drop_packet(struct sk_buff *skb)
36838 {
36839- atomic_inc(&cm_accel_dropped_pkts);
36840+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36841 dev_kfree_skb_any(skb);
36842 }
36843
36844@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36845 {
36846
36847 int reset = 0; /* whether to send reset in case of err.. */
36848- atomic_inc(&cm_resets_recvd);
36849+ atomic_inc_unchecked(&cm_resets_recvd);
36850 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36851 " refcnt=%d\n", cm_node, cm_node->state,
36852 atomic_read(&cm_node->ref_count));
36853@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36854 rem_ref_cm_node(cm_node->cm_core, cm_node);
36855 return NULL;
36856 }
36857- atomic_inc(&cm_loopbacks);
36858+ atomic_inc_unchecked(&cm_loopbacks);
36859 loopbackremotenode->loopbackpartner = cm_node;
36860 loopbackremotenode->tcp_cntxt.rcv_wscale =
36861 NES_CM_DEFAULT_RCV_WND_SCALE;
36862@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36863 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36864 else {
36865 rem_ref_cm_node(cm_core, cm_node);
36866- atomic_inc(&cm_accel_dropped_pkts);
36867+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36868 dev_kfree_skb_any(skb);
36869 }
36870 break;
36871@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36872
36873 if ((cm_id) && (cm_id->event_handler)) {
36874 if (issue_disconn) {
36875- atomic_inc(&cm_disconnects);
36876+ atomic_inc_unchecked(&cm_disconnects);
36877 cm_event.event = IW_CM_EVENT_DISCONNECT;
36878 cm_event.status = disconn_status;
36879 cm_event.local_addr = cm_id->local_addr;
36880@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36881 }
36882
36883 if (issue_close) {
36884- atomic_inc(&cm_closes);
36885+ atomic_inc_unchecked(&cm_closes);
36886 nes_disconnect(nesqp, 1);
36887
36888 cm_id->provider_data = nesqp;
36889@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36890
36891 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36892 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36893- atomic_inc(&cm_accepts);
36894+ atomic_inc_unchecked(&cm_accepts);
36895
36896 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36897 netdev_refcnt_read(nesvnic->netdev));
36898@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36899 struct nes_cm_core *cm_core;
36900 u8 *start_buff;
36901
36902- atomic_inc(&cm_rejects);
36903+ atomic_inc_unchecked(&cm_rejects);
36904 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36905 loopback = cm_node->loopbackpartner;
36906 cm_core = cm_node->cm_core;
36907@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36908 ntohl(cm_id->local_addr.sin_addr.s_addr),
36909 ntohs(cm_id->local_addr.sin_port));
36910
36911- atomic_inc(&cm_connects);
36912+ atomic_inc_unchecked(&cm_connects);
36913 nesqp->active_conn = 1;
36914
36915 /* cache the cm_id in the qp */
36916@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36917 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36918 return err;
36919 }
36920- atomic_inc(&cm_listens_created);
36921+ atomic_inc_unchecked(&cm_listens_created);
36922 }
36923
36924 cm_id->add_ref(cm_id);
36925@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36926
36927 if (nesqp->destroyed)
36928 return;
36929- atomic_inc(&cm_connecteds);
36930+ atomic_inc_unchecked(&cm_connecteds);
36931 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36932 " local port 0x%04X. jiffies = %lu.\n",
36933 nesqp->hwqp.qp_id,
36934@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36935
36936 cm_id->add_ref(cm_id);
36937 ret = cm_id->event_handler(cm_id, &cm_event);
36938- atomic_inc(&cm_closes);
36939+ atomic_inc_unchecked(&cm_closes);
36940 cm_event.event = IW_CM_EVENT_CLOSE;
36941 cm_event.status = 0;
36942 cm_event.provider_data = cm_id->provider_data;
36943@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36944 return;
36945 cm_id = cm_node->cm_id;
36946
36947- atomic_inc(&cm_connect_reqs);
36948+ atomic_inc_unchecked(&cm_connect_reqs);
36949 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36950 cm_node, cm_id, jiffies);
36951
36952@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
36953 return;
36954 cm_id = cm_node->cm_id;
36955
36956- atomic_inc(&cm_connect_reqs);
36957+ atomic_inc_unchecked(&cm_connect_reqs);
36958 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36959 cm_node, cm_id, jiffies);
36960
36961diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36962index 4166452..fc952c3 100644
36963--- a/drivers/infiniband/hw/nes/nes_mgt.c
36964+++ b/drivers/infiniband/hw/nes/nes_mgt.c
36965@@ -40,8 +40,8 @@
36966 #include "nes.h"
36967 #include "nes_mgt.h"
36968
36969-atomic_t pau_qps_created;
36970-atomic_t pau_qps_destroyed;
36971+atomic_unchecked_t pau_qps_created;
36972+atomic_unchecked_t pau_qps_destroyed;
36973
36974 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36975 {
36976@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36977 {
36978 struct sk_buff *skb;
36979 unsigned long flags;
36980- atomic_inc(&pau_qps_destroyed);
36981+ atomic_inc_unchecked(&pau_qps_destroyed);
36982
36983 /* Free packets that have not yet been forwarded */
36984 /* Lock is acquired by skb_dequeue when removing the skb */
36985@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36986 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36987 skb_queue_head_init(&nesqp->pau_list);
36988 spin_lock_init(&nesqp->pau_lock);
36989- atomic_inc(&pau_qps_created);
36990+ atomic_inc_unchecked(&pau_qps_created);
36991 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
36992 }
36993
36994diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
36995index 9542e16..a008c40 100644
36996--- a/drivers/infiniband/hw/nes/nes_nic.c
36997+++ b/drivers/infiniband/hw/nes/nes_nic.c
36998@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
36999 target_stat_values[++index] = mh_detected;
37000 target_stat_values[++index] = mh_pauses_sent;
37001 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37002- target_stat_values[++index] = atomic_read(&cm_connects);
37003- target_stat_values[++index] = atomic_read(&cm_accepts);
37004- target_stat_values[++index] = atomic_read(&cm_disconnects);
37005- target_stat_values[++index] = atomic_read(&cm_connecteds);
37006- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37007- target_stat_values[++index] = atomic_read(&cm_rejects);
37008- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37009- target_stat_values[++index] = atomic_read(&qps_created);
37010- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37011- target_stat_values[++index] = atomic_read(&qps_destroyed);
37012- target_stat_values[++index] = atomic_read(&cm_closes);
37013+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37014+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37015+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37016+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37017+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37018+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37019+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37020+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37021+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37022+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37023+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37024 target_stat_values[++index] = cm_packets_sent;
37025 target_stat_values[++index] = cm_packets_bounced;
37026 target_stat_values[++index] = cm_packets_created;
37027 target_stat_values[++index] = cm_packets_received;
37028 target_stat_values[++index] = cm_packets_dropped;
37029 target_stat_values[++index] = cm_packets_retrans;
37030- target_stat_values[++index] = atomic_read(&cm_listens_created);
37031- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37032+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37033+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37034 target_stat_values[++index] = cm_backlog_drops;
37035- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37036- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37037- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37038- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37039- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37040+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37041+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37042+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37043+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37044+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37045 target_stat_values[++index] = nesadapter->free_4kpbl;
37046 target_stat_values[++index] = nesadapter->free_256pbl;
37047 target_stat_values[++index] = int_mod_timer_init;
37048 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37049 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37050 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37051- target_stat_values[++index] = atomic_read(&pau_qps_created);
37052- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37053+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37054+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37055 }
37056
37057 /**
37058diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37059index 07e4fba..685f041 100644
37060--- a/drivers/infiniband/hw/nes/nes_verbs.c
37061+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37062@@ -46,9 +46,9 @@
37063
37064 #include <rdma/ib_umem.h>
37065
37066-atomic_t mod_qp_timouts;
37067-atomic_t qps_created;
37068-atomic_t sw_qps_destroyed;
37069+atomic_unchecked_t mod_qp_timouts;
37070+atomic_unchecked_t qps_created;
37071+atomic_unchecked_t sw_qps_destroyed;
37072
37073 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37074
37075@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37076 if (init_attr->create_flags)
37077 return ERR_PTR(-EINVAL);
37078
37079- atomic_inc(&qps_created);
37080+ atomic_inc_unchecked(&qps_created);
37081 switch (init_attr->qp_type) {
37082 case IB_QPT_RC:
37083 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37084@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37085 struct iw_cm_event cm_event;
37086 int ret = 0;
37087
37088- atomic_inc(&sw_qps_destroyed);
37089+ atomic_inc_unchecked(&sw_qps_destroyed);
37090 nesqp->destroyed = 1;
37091
37092 /* Blow away the connection if it exists. */
37093diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37094index 4d11575..3e890e5 100644
37095--- a/drivers/infiniband/hw/qib/qib.h
37096+++ b/drivers/infiniband/hw/qib/qib.h
37097@@ -51,6 +51,7 @@
37098 #include <linux/completion.h>
37099 #include <linux/kref.h>
37100 #include <linux/sched.h>
37101+#include <linux/slab.h>
37102
37103 #include "qib_common.h"
37104 #include "qib_verbs.h"
37105diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37106index da739d9..da1c7f4 100644
37107--- a/drivers/input/gameport/gameport.c
37108+++ b/drivers/input/gameport/gameport.c
37109@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37110 */
37111 static void gameport_init_port(struct gameport *gameport)
37112 {
37113- static atomic_t gameport_no = ATOMIC_INIT(0);
37114+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37115
37116 __module_get(THIS_MODULE);
37117
37118 mutex_init(&gameport->drv_mutex);
37119 device_initialize(&gameport->dev);
37120 dev_set_name(&gameport->dev, "gameport%lu",
37121- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37122+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37123 gameport->dev.bus = &gameport_bus;
37124 gameport->dev.release = gameport_release_port;
37125 if (gameport->parent)
37126diff --git a/drivers/input/input.c b/drivers/input/input.c
37127index c044699..174d71a 100644
37128--- a/drivers/input/input.c
37129+++ b/drivers/input/input.c
37130@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37131 */
37132 int input_register_device(struct input_dev *dev)
37133 {
37134- static atomic_t input_no = ATOMIC_INIT(0);
37135+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37136 struct input_devres *devres = NULL;
37137 struct input_handler *handler;
37138 unsigned int packet_size;
37139@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37140 dev->setkeycode = input_default_setkeycode;
37141
37142 dev_set_name(&dev->dev, "input%ld",
37143- (unsigned long) atomic_inc_return(&input_no) - 1);
37144+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37145
37146 error = device_add(&dev->dev);
37147 if (error)
37148diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37149index 04c69af..5f92d00 100644
37150--- a/drivers/input/joystick/sidewinder.c
37151+++ b/drivers/input/joystick/sidewinder.c
37152@@ -30,6 +30,7 @@
37153 #include <linux/kernel.h>
37154 #include <linux/module.h>
37155 #include <linux/slab.h>
37156+#include <linux/sched.h>
37157 #include <linux/init.h>
37158 #include <linux/input.h>
37159 #include <linux/gameport.h>
37160diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37161index d6cbfe9..6225402 100644
37162--- a/drivers/input/joystick/xpad.c
37163+++ b/drivers/input/joystick/xpad.c
37164@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37165
37166 static int xpad_led_probe(struct usb_xpad *xpad)
37167 {
37168- static atomic_t led_seq = ATOMIC_INIT(0);
37169+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37170 long led_no;
37171 struct xpad_led *led;
37172 struct led_classdev *led_cdev;
37173@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37174 if (!led)
37175 return -ENOMEM;
37176
37177- led_no = (long)atomic_inc_return(&led_seq) - 1;
37178+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37179
37180 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37181 led->xpad = xpad;
37182diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37183index fe1df23..5b710f3 100644
37184--- a/drivers/input/mouse/psmouse.h
37185+++ b/drivers/input/mouse/psmouse.h
37186@@ -115,7 +115,7 @@ struct psmouse_attribute {
37187 ssize_t (*set)(struct psmouse *psmouse, void *data,
37188 const char *buf, size_t count);
37189 bool protect;
37190-};
37191+} __do_const;
37192 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37193
37194 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37195diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37196index 4c842c3..590b0bf 100644
37197--- a/drivers/input/mousedev.c
37198+++ b/drivers/input/mousedev.c
37199@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37200
37201 spin_unlock_irq(&client->packet_lock);
37202
37203- if (copy_to_user(buffer, data, count))
37204+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37205 return -EFAULT;
37206
37207 return count;
37208diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37209index 25fc597..558bf3b 100644
37210--- a/drivers/input/serio/serio.c
37211+++ b/drivers/input/serio/serio.c
37212@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37213 */
37214 static void serio_init_port(struct serio *serio)
37215 {
37216- static atomic_t serio_no = ATOMIC_INIT(0);
37217+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37218
37219 __module_get(THIS_MODULE);
37220
37221@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37222 mutex_init(&serio->drv_mutex);
37223 device_initialize(&serio->dev);
37224 dev_set_name(&serio->dev, "serio%ld",
37225- (long)atomic_inc_return(&serio_no) - 1);
37226+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37227 serio->dev.bus = &serio_bus;
37228 serio->dev.release = serio_release_port;
37229 serio->dev.groups = serio_device_attr_groups;
37230diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37231index ddbdaca..be18a78 100644
37232--- a/drivers/iommu/iommu.c
37233+++ b/drivers/iommu/iommu.c
37234@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37235 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37236 {
37237 bus_register_notifier(bus, &iommu_bus_nb);
37238- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37239+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37240 }
37241
37242 /**
37243diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37244index 89562a8..218999b 100644
37245--- a/drivers/isdn/capi/capi.c
37246+++ b/drivers/isdn/capi/capi.c
37247@@ -81,8 +81,8 @@ struct capiminor {
37248
37249 struct capi20_appl *ap;
37250 u32 ncci;
37251- atomic_t datahandle;
37252- atomic_t msgid;
37253+ atomic_unchecked_t datahandle;
37254+ atomic_unchecked_t msgid;
37255
37256 struct tty_port port;
37257 int ttyinstop;
37258@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37259 capimsg_setu16(s, 2, mp->ap->applid);
37260 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37261 capimsg_setu8 (s, 5, CAPI_RESP);
37262- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37263+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37264 capimsg_setu32(s, 8, mp->ncci);
37265 capimsg_setu16(s, 12, datahandle);
37266 }
37267@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37268 mp->outbytes -= len;
37269 spin_unlock_bh(&mp->outlock);
37270
37271- datahandle = atomic_inc_return(&mp->datahandle);
37272+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37273 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37274 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37275 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37276 capimsg_setu16(skb->data, 2, mp->ap->applid);
37277 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37278 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37279- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37280+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37281 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37282 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37283 capimsg_setu16(skb->data, 16, len); /* Data length */
37284diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37285index 67abf3f..076b3a6 100644
37286--- a/drivers/isdn/gigaset/interface.c
37287+++ b/drivers/isdn/gigaset/interface.c
37288@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37289 }
37290 tty->driver_data = cs;
37291
37292- ++cs->port.count;
37293+ atomic_inc(&cs->port.count);
37294
37295- if (cs->port.count == 1) {
37296+ if (atomic_read(&cs->port.count) == 1) {
37297 tty_port_tty_set(&cs->port, tty);
37298 tty->low_latency = 1;
37299 }
37300@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37301
37302 if (!cs->connected)
37303 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37304- else if (!cs->port.count)
37305+ else if (!atomic_read(&cs->port.count))
37306 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37307- else if (!--cs->port.count)
37308+ else if (!atomic_dec_return(&cs->port.count))
37309 tty_port_tty_set(&cs->port, NULL);
37310
37311 mutex_unlock(&cs->mutex);
37312diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37313index 821f7ac..28d4030 100644
37314--- a/drivers/isdn/hardware/avm/b1.c
37315+++ b/drivers/isdn/hardware/avm/b1.c
37316@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37317 }
37318 if (left) {
37319 if (t4file->user) {
37320- if (copy_from_user(buf, dp, left))
37321+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37322 return -EFAULT;
37323 } else {
37324 memcpy(buf, dp, left);
37325@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37326 }
37327 if (left) {
37328 if (config->user) {
37329- if (copy_from_user(buf, dp, left))
37330+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37331 return -EFAULT;
37332 } else {
37333 memcpy(buf, dp, left);
37334diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37335index e09dc8a..15e2efb 100644
37336--- a/drivers/isdn/i4l/isdn_tty.c
37337+++ b/drivers/isdn/i4l/isdn_tty.c
37338@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37339
37340 #ifdef ISDN_DEBUG_MODEM_OPEN
37341 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37342- port->count);
37343+ atomic_read(&port->count));
37344 #endif
37345- port->count++;
37346+ atomic_inc(&port->count);
37347 port->tty = tty;
37348 /*
37349 * Start up serial port
37350@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37351 #endif
37352 return;
37353 }
37354- if ((tty->count == 1) && (port->count != 1)) {
37355+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37356 /*
37357 * Uh, oh. tty->count is 1, which means that the tty
37358 * structure will be freed. Info->count should always
37359@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37360 * serial port won't be shutdown.
37361 */
37362 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37363- "info->count is %d\n", port->count);
37364- port->count = 1;
37365+ "info->count is %d\n", atomic_read(&port->count));
37366+ atomic_set(&port->count, 1);
37367 }
37368- if (--port->count < 0) {
37369+ if (atomic_dec_return(&port->count) < 0) {
37370 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37371- info->line, port->count);
37372- port->count = 0;
37373+ info->line, atomic_read(&port->count));
37374+ atomic_set(&port->count, 0);
37375 }
37376- if (port->count) {
37377+ if (atomic_read(&port->count)) {
37378 #ifdef ISDN_DEBUG_MODEM_OPEN
37379 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37380 #endif
37381@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37382 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37383 return;
37384 isdn_tty_shutdown(info);
37385- port->count = 0;
37386+ atomic_set(&port->count, 0);
37387 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37388 port->tty = NULL;
37389 wake_up_interruptible(&port->open_wait);
37390@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37391 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37392 modem_info *info = &dev->mdm.info[i];
37393
37394- if (info->port.count == 0)
37395+ if (atomic_read(&info->port.count) == 0)
37396 continue;
37397 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37398 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37399diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37400index e74df7c..03a03ba 100644
37401--- a/drivers/isdn/icn/icn.c
37402+++ b/drivers/isdn/icn/icn.c
37403@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37404 if (count > len)
37405 count = len;
37406 if (user) {
37407- if (copy_from_user(msg, buf, count))
37408+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37409 return -EFAULT;
37410 } else
37411 memcpy(msg, buf, count);
37412diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37413index 6a8405d..0bd1c7e 100644
37414--- a/drivers/leds/leds-clevo-mail.c
37415+++ b/drivers/leds/leds-clevo-mail.c
37416@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37417 * detected as working, but in reality it is not) as low as
37418 * possible.
37419 */
37420-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37421+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37422 {
37423 .callback = clevo_mail_led_dmi_callback,
37424 .ident = "Clevo D410J",
37425diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37426index ec9b287..65c9bf4 100644
37427--- a/drivers/leds/leds-ss4200.c
37428+++ b/drivers/leds/leds-ss4200.c
37429@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37430 * detected as working, but in reality it is not) as low as
37431 * possible.
37432 */
37433-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37434+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37435 {
37436 .callback = ss4200_led_dmi_callback,
37437 .ident = "Intel SS4200-E",
37438diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37439index a5ebc00..982886f 100644
37440--- a/drivers/lguest/core.c
37441+++ b/drivers/lguest/core.c
37442@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37443 * it's worked so far. The end address needs +1 because __get_vm_area
37444 * allocates an extra guard page, so we need space for that.
37445 */
37446+
37447+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37448+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37449+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37450+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37451+#else
37452 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37453 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37454 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37455+#endif
37456+
37457 if (!switcher_vma) {
37458 err = -ENOMEM;
37459 printk("lguest: could not map switcher pages high\n");
37460@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37461 * Now the Switcher is mapped at the right address, we can't fail!
37462 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37463 */
37464- memcpy(switcher_vma->addr, start_switcher_text,
37465+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37466 end_switcher_text - start_switcher_text);
37467
37468 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37469diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37470index 3b62be16..e33134a 100644
37471--- a/drivers/lguest/page_tables.c
37472+++ b/drivers/lguest/page_tables.c
37473@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37474 /*:*/
37475
37476 #ifdef CONFIG_X86_PAE
37477-static void release_pmd(pmd_t *spmd)
37478+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37479 {
37480 /* If the entry's not present, there's nothing to release. */
37481 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37482diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37483index 4af12e1..0e89afe 100644
37484--- a/drivers/lguest/x86/core.c
37485+++ b/drivers/lguest/x86/core.c
37486@@ -59,7 +59,7 @@ static struct {
37487 /* Offset from where switcher.S was compiled to where we've copied it */
37488 static unsigned long switcher_offset(void)
37489 {
37490- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37491+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37492 }
37493
37494 /* This cpu's struct lguest_pages. */
37495@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37496 * These copies are pretty cheap, so we do them unconditionally: */
37497 /* Save the current Host top-level page directory.
37498 */
37499+
37500+#ifdef CONFIG_PAX_PER_CPU_PGD
37501+ pages->state.host_cr3 = read_cr3();
37502+#else
37503 pages->state.host_cr3 = __pa(current->mm->pgd);
37504+#endif
37505+
37506 /*
37507 * Set up the Guest's page tables to see this CPU's pages (and no
37508 * other CPU's pages).
37509@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37510 * compiled-in switcher code and the high-mapped copy we just made.
37511 */
37512 for (i = 0; i < IDT_ENTRIES; i++)
37513- default_idt_entries[i] += switcher_offset();
37514+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37515
37516 /*
37517 * Set up the Switcher's per-cpu areas.
37518@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37519 * it will be undisturbed when we switch. To change %cs and jump we
37520 * need this structure to feed to Intel's "lcall" instruction.
37521 */
37522- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37523+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37524 lguest_entry.segment = LGUEST_CS;
37525
37526 /*
37527diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37528index 40634b0..4f5855e 100644
37529--- a/drivers/lguest/x86/switcher_32.S
37530+++ b/drivers/lguest/x86/switcher_32.S
37531@@ -87,6 +87,7 @@
37532 #include <asm/page.h>
37533 #include <asm/segment.h>
37534 #include <asm/lguest.h>
37535+#include <asm/processor-flags.h>
37536
37537 // We mark the start of the code to copy
37538 // It's placed in .text tho it's never run here
37539@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37540 // Changes type when we load it: damn Intel!
37541 // For after we switch over our page tables
37542 // That entry will be read-only: we'd crash.
37543+
37544+#ifdef CONFIG_PAX_KERNEXEC
37545+ mov %cr0, %edx
37546+ xor $X86_CR0_WP, %edx
37547+ mov %edx, %cr0
37548+#endif
37549+
37550 movl $(GDT_ENTRY_TSS*8), %edx
37551 ltr %dx
37552
37553@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37554 // Let's clear it again for our return.
37555 // The GDT descriptor of the Host
37556 // Points to the table after two "size" bytes
37557- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37558+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37559 // Clear "used" from type field (byte 5, bit 2)
37560- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37561+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37562+
37563+#ifdef CONFIG_PAX_KERNEXEC
37564+ mov %cr0, %eax
37565+ xor $X86_CR0_WP, %eax
37566+ mov %eax, %cr0
37567+#endif
37568
37569 // Once our page table's switched, the Guest is live!
37570 // The Host fades as we run this final step.
37571@@ -295,13 +309,12 @@ deliver_to_host:
37572 // I consulted gcc, and it gave
37573 // These instructions, which I gladly credit:
37574 leal (%edx,%ebx,8), %eax
37575- movzwl (%eax),%edx
37576- movl 4(%eax), %eax
37577- xorw %ax, %ax
37578- orl %eax, %edx
37579+ movl 4(%eax), %edx
37580+ movw (%eax), %dx
37581 // Now the address of the handler's in %edx
37582 // We call it now: its "iret" drops us home.
37583- jmp *%edx
37584+ ljmp $__KERNEL_CS, $1f
37585+1: jmp *%edx
37586
37587 // Every interrupt can come to us here
37588 // But we must truly tell each apart.
37589diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37590index 7155945..4bcc562 100644
37591--- a/drivers/md/bitmap.c
37592+++ b/drivers/md/bitmap.c
37593@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37594 chunk_kb ? "KB" : "B");
37595 if (bitmap->storage.file) {
37596 seq_printf(seq, ", file: ");
37597- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37598+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37599 }
37600
37601 seq_printf(seq, "\n");
37602diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37603index eee353d..74504c4 100644
37604--- a/drivers/md/dm-ioctl.c
37605+++ b/drivers/md/dm-ioctl.c
37606@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37607 cmd == DM_LIST_VERSIONS_CMD)
37608 return 0;
37609
37610- if ((cmd == DM_DEV_CREATE_CMD)) {
37611+ if (cmd == DM_DEV_CREATE_CMD) {
37612 if (!*param->name) {
37613 DMWARN("name not supplied when creating device");
37614 return -EINVAL;
37615diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37616index 7f24190..0e18099 100644
37617--- a/drivers/md/dm-raid1.c
37618+++ b/drivers/md/dm-raid1.c
37619@@ -40,7 +40,7 @@ enum dm_raid1_error {
37620
37621 struct mirror {
37622 struct mirror_set *ms;
37623- atomic_t error_count;
37624+ atomic_unchecked_t error_count;
37625 unsigned long error_type;
37626 struct dm_dev *dev;
37627 sector_t offset;
37628@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37629 struct mirror *m;
37630
37631 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37632- if (!atomic_read(&m->error_count))
37633+ if (!atomic_read_unchecked(&m->error_count))
37634 return m;
37635
37636 return NULL;
37637@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37638 * simple way to tell if a device has encountered
37639 * errors.
37640 */
37641- atomic_inc(&m->error_count);
37642+ atomic_inc_unchecked(&m->error_count);
37643
37644 if (test_and_set_bit(error_type, &m->error_type))
37645 return;
37646@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37647 struct mirror *m = get_default_mirror(ms);
37648
37649 do {
37650- if (likely(!atomic_read(&m->error_count)))
37651+ if (likely(!atomic_read_unchecked(&m->error_count)))
37652 return m;
37653
37654 if (m-- == ms->mirror)
37655@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37656 {
37657 struct mirror *default_mirror = get_default_mirror(m->ms);
37658
37659- return !atomic_read(&default_mirror->error_count);
37660+ return !atomic_read_unchecked(&default_mirror->error_count);
37661 }
37662
37663 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37664@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37665 */
37666 if (likely(region_in_sync(ms, region, 1)))
37667 m = choose_mirror(ms, bio->bi_sector);
37668- else if (m && atomic_read(&m->error_count))
37669+ else if (m && atomic_read_unchecked(&m->error_count))
37670 m = NULL;
37671
37672 if (likely(m))
37673@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37674 }
37675
37676 ms->mirror[mirror].ms = ms;
37677- atomic_set(&(ms->mirror[mirror].error_count), 0);
37678+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37679 ms->mirror[mirror].error_type = 0;
37680 ms->mirror[mirror].offset = offset;
37681
37682@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37683 */
37684 static char device_status_char(struct mirror *m)
37685 {
37686- if (!atomic_read(&(m->error_count)))
37687+ if (!atomic_read_unchecked(&(m->error_count)))
37688 return 'A';
37689
37690 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37691diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37692index aaecefa..23b3026 100644
37693--- a/drivers/md/dm-stripe.c
37694+++ b/drivers/md/dm-stripe.c
37695@@ -20,7 +20,7 @@ struct stripe {
37696 struct dm_dev *dev;
37697 sector_t physical_start;
37698
37699- atomic_t error_count;
37700+ atomic_unchecked_t error_count;
37701 };
37702
37703 struct stripe_c {
37704@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37705 kfree(sc);
37706 return r;
37707 }
37708- atomic_set(&(sc->stripe[i].error_count), 0);
37709+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37710 }
37711
37712 ti->private = sc;
37713@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
37714 DMEMIT("%d ", sc->stripes);
37715 for (i = 0; i < sc->stripes; i++) {
37716 DMEMIT("%s ", sc->stripe[i].dev->name);
37717- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37718+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37719 'D' : 'A';
37720 }
37721 buffer[i] = '\0';
37722@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37723 */
37724 for (i = 0; i < sc->stripes; i++)
37725 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37726- atomic_inc(&(sc->stripe[i].error_count));
37727- if (atomic_read(&(sc->stripe[i].error_count)) <
37728+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
37729+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37730 DM_IO_ERROR_THRESHOLD)
37731 schedule_work(&sc->trigger_event);
37732 }
37733diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37734index daf25d0..d74f49f 100644
37735--- a/drivers/md/dm-table.c
37736+++ b/drivers/md/dm-table.c
37737@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37738 if (!dev_size)
37739 return 0;
37740
37741- if ((start >= dev_size) || (start + len > dev_size)) {
37742+ if ((start >= dev_size) || (len > dev_size - start)) {
37743 DMWARN("%s: %s too small for target: "
37744 "start=%llu, len=%llu, dev_size=%llu",
37745 dm_device_name(ti->table->md), bdevname(bdev, b),
37746diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37747index 4d6e853..a234157 100644
37748--- a/drivers/md/dm-thin-metadata.c
37749+++ b/drivers/md/dm-thin-metadata.c
37750@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37751 {
37752 pmd->info.tm = pmd->tm;
37753 pmd->info.levels = 2;
37754- pmd->info.value_type.context = pmd->data_sm;
37755+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37756 pmd->info.value_type.size = sizeof(__le64);
37757 pmd->info.value_type.inc = data_block_inc;
37758 pmd->info.value_type.dec = data_block_dec;
37759@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37760
37761 pmd->bl_info.tm = pmd->tm;
37762 pmd->bl_info.levels = 1;
37763- pmd->bl_info.value_type.context = pmd->data_sm;
37764+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37765 pmd->bl_info.value_type.size = sizeof(__le64);
37766 pmd->bl_info.value_type.inc = data_block_inc;
37767 pmd->bl_info.value_type.dec = data_block_dec;
37768diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37769index 0d8f086..f5a91d5 100644
37770--- a/drivers/md/dm.c
37771+++ b/drivers/md/dm.c
37772@@ -170,9 +170,9 @@ struct mapped_device {
37773 /*
37774 * Event handling.
37775 */
37776- atomic_t event_nr;
37777+ atomic_unchecked_t event_nr;
37778 wait_queue_head_t eventq;
37779- atomic_t uevent_seq;
37780+ atomic_unchecked_t uevent_seq;
37781 struct list_head uevent_list;
37782 spinlock_t uevent_lock; /* Protect access to uevent_list */
37783
37784@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37785 rwlock_init(&md->map_lock);
37786 atomic_set(&md->holders, 1);
37787 atomic_set(&md->open_count, 0);
37788- atomic_set(&md->event_nr, 0);
37789- atomic_set(&md->uevent_seq, 0);
37790+ atomic_set_unchecked(&md->event_nr, 0);
37791+ atomic_set_unchecked(&md->uevent_seq, 0);
37792 INIT_LIST_HEAD(&md->uevent_list);
37793 spin_lock_init(&md->uevent_lock);
37794
37795@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
37796
37797 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37798
37799- atomic_inc(&md->event_nr);
37800+ atomic_inc_unchecked(&md->event_nr);
37801 wake_up(&md->eventq);
37802 }
37803
37804@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37805
37806 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37807 {
37808- return atomic_add_return(1, &md->uevent_seq);
37809+ return atomic_add_return_unchecked(1, &md->uevent_seq);
37810 }
37811
37812 uint32_t dm_get_event_nr(struct mapped_device *md)
37813 {
37814- return atomic_read(&md->event_nr);
37815+ return atomic_read_unchecked(&md->event_nr);
37816 }
37817
37818 int dm_wait_event(struct mapped_device *md, int event_nr)
37819 {
37820 return wait_event_interruptible(md->eventq,
37821- (event_nr != atomic_read(&md->event_nr)));
37822+ (event_nr != atomic_read_unchecked(&md->event_nr)));
37823 }
37824
37825 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37826diff --git a/drivers/md/md.c b/drivers/md/md.c
37827index f363135..9b38815 100644
37828--- a/drivers/md/md.c
37829+++ b/drivers/md/md.c
37830@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37831 * start build, activate spare
37832 */
37833 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37834-static atomic_t md_event_count;
37835+static atomic_unchecked_t md_event_count;
37836 void md_new_event(struct mddev *mddev)
37837 {
37838- atomic_inc(&md_event_count);
37839+ atomic_inc_unchecked(&md_event_count);
37840 wake_up(&md_event_waiters);
37841 }
37842 EXPORT_SYMBOL_GPL(md_new_event);
37843@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37844 */
37845 static void md_new_event_inintr(struct mddev *mddev)
37846 {
37847- atomic_inc(&md_event_count);
37848+ atomic_inc_unchecked(&md_event_count);
37849 wake_up(&md_event_waiters);
37850 }
37851
37852@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37853 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37854 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37855 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37856- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37857+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37858
37859 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37860 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37861@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37862 else
37863 sb->resync_offset = cpu_to_le64(0);
37864
37865- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37866+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37867
37868 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37869 sb->size = cpu_to_le64(mddev->dev_sectors);
37870@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37871 static ssize_t
37872 errors_show(struct md_rdev *rdev, char *page)
37873 {
37874- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37875+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37876 }
37877
37878 static ssize_t
37879@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37880 char *e;
37881 unsigned long n = simple_strtoul(buf, &e, 10);
37882 if (*buf && (*e == 0 || *e == '\n')) {
37883- atomic_set(&rdev->corrected_errors, n);
37884+ atomic_set_unchecked(&rdev->corrected_errors, n);
37885 return len;
37886 }
37887 return -EINVAL;
37888@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
37889 rdev->sb_loaded = 0;
37890 rdev->bb_page = NULL;
37891 atomic_set(&rdev->nr_pending, 0);
37892- atomic_set(&rdev->read_errors, 0);
37893- atomic_set(&rdev->corrected_errors, 0);
37894+ atomic_set_unchecked(&rdev->read_errors, 0);
37895+ atomic_set_unchecked(&rdev->corrected_errors, 0);
37896
37897 INIT_LIST_HEAD(&rdev->same_set);
37898 init_waitqueue_head(&rdev->blocked_wait);
37899@@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37900
37901 spin_unlock(&pers_lock);
37902 seq_printf(seq, "\n");
37903- seq->poll_event = atomic_read(&md_event_count);
37904+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37905 return 0;
37906 }
37907 if (v == (void*)2) {
37908@@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37909 return error;
37910
37911 seq = file->private_data;
37912- seq->poll_event = atomic_read(&md_event_count);
37913+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37914 return error;
37915 }
37916
37917@@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37918 /* always allow read */
37919 mask = POLLIN | POLLRDNORM;
37920
37921- if (seq->poll_event != atomic_read(&md_event_count))
37922+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37923 mask |= POLLERR | POLLPRI;
37924 return mask;
37925 }
37926@@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37927 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37928 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37929 (int)part_stat_read(&disk->part0, sectors[1]) -
37930- atomic_read(&disk->sync_io);
37931+ atomic_read_unchecked(&disk->sync_io);
37932 /* sync IO will cause sync_io to increase before the disk_stats
37933 * as sync_io is counted when a request starts, and
37934 * disk_stats is counted when it completes.
37935diff --git a/drivers/md/md.h b/drivers/md/md.h
37936index eca59c3..7c42285 100644
37937--- a/drivers/md/md.h
37938+++ b/drivers/md/md.h
37939@@ -94,13 +94,13 @@ struct md_rdev {
37940 * only maintained for arrays that
37941 * support hot removal
37942 */
37943- atomic_t read_errors; /* number of consecutive read errors that
37944+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
37945 * we have tried to ignore.
37946 */
37947 struct timespec last_read_error; /* monotonic time since our
37948 * last read error
37949 */
37950- atomic_t corrected_errors; /* number of corrected read errors,
37951+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37952 * for reporting to userspace and storing
37953 * in superblock.
37954 */
37955@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37956
37957 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37958 {
37959- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37960+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37961 }
37962
37963 struct md_personality
37964diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37965index 1cbfc6b..56e1dbb 100644
37966--- a/drivers/md/persistent-data/dm-space-map.h
37967+++ b/drivers/md/persistent-data/dm-space-map.h
37968@@ -60,6 +60,7 @@ struct dm_space_map {
37969 int (*root_size)(struct dm_space_map *sm, size_t *result);
37970 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37971 };
37972+typedef struct dm_space_map __no_const dm_space_map_no_const;
37973
37974 /*----------------------------------------------------------------*/
37975
37976diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37977index 75b1f89..00ba344 100644
37978--- a/drivers/md/raid1.c
37979+++ b/drivers/md/raid1.c
37980@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37981 if (r1_sync_page_io(rdev, sect, s,
37982 bio->bi_io_vec[idx].bv_page,
37983 READ) != 0)
37984- atomic_add(s, &rdev->corrected_errors);
37985+ atomic_add_unchecked(s, &rdev->corrected_errors);
37986 }
37987 sectors -= s;
37988 sect += s;
37989@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37990 test_bit(In_sync, &rdev->flags)) {
37991 if (r1_sync_page_io(rdev, sect, s,
37992 conf->tmppage, READ)) {
37993- atomic_add(s, &rdev->corrected_errors);
37994+ atomic_add_unchecked(s, &rdev->corrected_errors);
37995 printk(KERN_INFO
37996 "md/raid1:%s: read error corrected "
37997 "(%d sectors at %llu on %s)\n",
37998diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
37999index 8d925dc..11d674f 100644
38000--- a/drivers/md/raid10.c
38001+++ b/drivers/md/raid10.c
38002@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
38003 /* The write handler will notice the lack of
38004 * R10BIO_Uptodate and record any errors etc
38005 */
38006- atomic_add(r10_bio->sectors,
38007+ atomic_add_unchecked(r10_bio->sectors,
38008 &conf->mirrors[d].rdev->corrected_errors);
38009
38010 /* for reconstruct, we always reschedule after a read.
38011@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38012 {
38013 struct timespec cur_time_mon;
38014 unsigned long hours_since_last;
38015- unsigned int read_errors = atomic_read(&rdev->read_errors);
38016+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38017
38018 ktime_get_ts(&cur_time_mon);
38019
38020@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38021 * overflowing the shift of read_errors by hours_since_last.
38022 */
38023 if (hours_since_last >= 8 * sizeof(read_errors))
38024- atomic_set(&rdev->read_errors, 0);
38025+ atomic_set_unchecked(&rdev->read_errors, 0);
38026 else
38027- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38028+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38029 }
38030
38031 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38032@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38033 return;
38034
38035 check_decay_read_errors(mddev, rdev);
38036- atomic_inc(&rdev->read_errors);
38037- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38038+ atomic_inc_unchecked(&rdev->read_errors);
38039+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38040 char b[BDEVNAME_SIZE];
38041 bdevname(rdev->bdev, b);
38042
38043@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38044 "md/raid10:%s: %s: Raid device exceeded "
38045 "read_error threshold [cur %d:max %d]\n",
38046 mdname(mddev), b,
38047- atomic_read(&rdev->read_errors), max_read_errors);
38048+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38049 printk(KERN_NOTICE
38050 "md/raid10:%s: %s: Failing raid device\n",
38051 mdname(mddev), b);
38052@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38053 sect +
38054 choose_data_offset(r10_bio, rdev)),
38055 bdevname(rdev->bdev, b));
38056- atomic_add(s, &rdev->corrected_errors);
38057+ atomic_add_unchecked(s, &rdev->corrected_errors);
38058 }
38059
38060 rdev_dec_pending(rdev, mddev);
38061diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38062index 19d77a0..56051b92 100644
38063--- a/drivers/md/raid5.c
38064+++ b/drivers/md/raid5.c
38065@@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38066 mdname(conf->mddev), STRIPE_SECTORS,
38067 (unsigned long long)s,
38068 bdevname(rdev->bdev, b));
38069- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38070+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38071 clear_bit(R5_ReadError, &sh->dev[i].flags);
38072 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38073 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38074 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38075
38076- if (atomic_read(&rdev->read_errors))
38077- atomic_set(&rdev->read_errors, 0);
38078+ if (atomic_read_unchecked(&rdev->read_errors))
38079+ atomic_set_unchecked(&rdev->read_errors, 0);
38080 } else {
38081 const char *bdn = bdevname(rdev->bdev, b);
38082 int retry = 0;
38083 int set_bad = 0;
38084
38085 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38086- atomic_inc(&rdev->read_errors);
38087+ atomic_inc_unchecked(&rdev->read_errors);
38088 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38089 printk_ratelimited(
38090 KERN_WARNING
38091@@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38092 mdname(conf->mddev),
38093 (unsigned long long)s,
38094 bdn);
38095- } else if (atomic_read(&rdev->read_errors)
38096+ } else if (atomic_read_unchecked(&rdev->read_errors)
38097 > conf->max_nr_stripes)
38098 printk(KERN_WARNING
38099 "md/raid:%s: Too many read errors, failing device %s.\n",
38100diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38101index d33101a..6b13069 100644
38102--- a/drivers/media/dvb-core/dvbdev.c
38103+++ b/drivers/media/dvb-core/dvbdev.c
38104@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38105 const struct dvb_device *template, void *priv, int type)
38106 {
38107 struct dvb_device *dvbdev;
38108- struct file_operations *dvbdevfops;
38109+ file_operations_no_const *dvbdevfops;
38110 struct device *clsdev;
38111 int minor;
38112 int id;
38113diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38114index 404f63a..4796533 100644
38115--- a/drivers/media/dvb-frontends/dib3000.h
38116+++ b/drivers/media/dvb-frontends/dib3000.h
38117@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38118 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38119 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38120 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38121-};
38122+} __no_const;
38123
38124 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
38125 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38126diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38127index 8e9a668..78d6310 100644
38128--- a/drivers/media/platform/omap/omap_vout.c
38129+++ b/drivers/media/platform/omap/omap_vout.c
38130@@ -63,7 +63,6 @@ enum omap_vout_channels {
38131 OMAP_VIDEO2,
38132 };
38133
38134-static struct videobuf_queue_ops video_vbq_ops;
38135 /* Variables configurable through module params*/
38136 static u32 video1_numbuffers = 3;
38137 static u32 video2_numbuffers = 3;
38138@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38139 {
38140 struct videobuf_queue *q;
38141 struct omap_vout_device *vout = NULL;
38142+ static struct videobuf_queue_ops video_vbq_ops = {
38143+ .buf_setup = omap_vout_buffer_setup,
38144+ .buf_prepare = omap_vout_buffer_prepare,
38145+ .buf_release = omap_vout_buffer_release,
38146+ .buf_queue = omap_vout_buffer_queue,
38147+ };
38148
38149 vout = video_drvdata(file);
38150 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38151@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38152 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38153
38154 q = &vout->vbq;
38155- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38156- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38157- video_vbq_ops.buf_release = omap_vout_buffer_release;
38158- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38159 spin_lock_init(&vout->vbq_lock);
38160
38161 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38162diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38163index b671e20..34088b7 100644
38164--- a/drivers/media/platform/s5p-tv/mixer.h
38165+++ b/drivers/media/platform/s5p-tv/mixer.h
38166@@ -155,7 +155,7 @@ struct mxr_layer {
38167 /** layer index (unique identifier) */
38168 int idx;
38169 /** callbacks for layer methods */
38170- struct mxr_layer_ops ops;
38171+ struct mxr_layer_ops *ops;
38172 /** format array */
38173 const struct mxr_format **fmt_array;
38174 /** size of format array */
38175diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38176index b93a21f..2535195 100644
38177--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38178+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38179@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38180 {
38181 struct mxr_layer *layer;
38182 int ret;
38183- struct mxr_layer_ops ops = {
38184+ static struct mxr_layer_ops ops = {
38185 .release = mxr_graph_layer_release,
38186 .buffer_set = mxr_graph_buffer_set,
38187 .stream_set = mxr_graph_stream_set,
38188diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38189index 3b1670a..595c939 100644
38190--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38191+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38192@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38193 layer->update_buf = next;
38194 }
38195
38196- layer->ops.buffer_set(layer, layer->update_buf);
38197+ layer->ops->buffer_set(layer, layer->update_buf);
38198
38199 if (done && done != layer->shadow_buf)
38200 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38201diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38202index 1f3b743..e839271 100644
38203--- a/drivers/media/platform/s5p-tv/mixer_video.c
38204+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38205@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38206 layer->geo.src.height = layer->geo.src.full_height;
38207
38208 mxr_geometry_dump(mdev, &layer->geo);
38209- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38210+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38211 mxr_geometry_dump(mdev, &layer->geo);
38212 }
38213
38214@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38215 layer->geo.dst.full_width = mbus_fmt.width;
38216 layer->geo.dst.full_height = mbus_fmt.height;
38217 layer->geo.dst.field = mbus_fmt.field;
38218- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38219+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38220
38221 mxr_geometry_dump(mdev, &layer->geo);
38222 }
38223@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38224 /* set source size to highest accepted value */
38225 geo->src.full_width = max(geo->dst.full_width, pix->width);
38226 geo->src.full_height = max(geo->dst.full_height, pix->height);
38227- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38228+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38229 mxr_geometry_dump(mdev, &layer->geo);
38230 /* set cropping to total visible screen */
38231 geo->src.width = pix->width;
38232@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38233 geo->src.x_offset = 0;
38234 geo->src.y_offset = 0;
38235 /* assure consistency of geometry */
38236- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38237+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38238 mxr_geometry_dump(mdev, &layer->geo);
38239 /* set full size to lowest possible value */
38240 geo->src.full_width = 0;
38241 geo->src.full_height = 0;
38242- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38243+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38244 mxr_geometry_dump(mdev, &layer->geo);
38245
38246 /* returning results */
38247@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38248 target->width = s->r.width;
38249 target->height = s->r.height;
38250
38251- layer->ops.fix_geometry(layer, stage, s->flags);
38252+ layer->ops->fix_geometry(layer, stage, s->flags);
38253
38254 /* retrieve update selection rectangle */
38255 res.left = target->x_offset;
38256@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38257 mxr_output_get(mdev);
38258
38259 mxr_layer_update_output(layer);
38260- layer->ops.format_set(layer);
38261+ layer->ops->format_set(layer);
38262 /* enabling layer in hardware */
38263 spin_lock_irqsave(&layer->enq_slock, flags);
38264 layer->state = MXR_LAYER_STREAMING;
38265 spin_unlock_irqrestore(&layer->enq_slock, flags);
38266
38267- layer->ops.stream_set(layer, MXR_ENABLE);
38268+ layer->ops->stream_set(layer, MXR_ENABLE);
38269 mxr_streamer_get(mdev);
38270
38271 return 0;
38272@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38273 spin_unlock_irqrestore(&layer->enq_slock, flags);
38274
38275 /* disabling layer in hardware */
38276- layer->ops.stream_set(layer, MXR_DISABLE);
38277+ layer->ops->stream_set(layer, MXR_DISABLE);
38278 /* remove one streamer */
38279 mxr_streamer_put(mdev);
38280 /* allow changes in output configuration */
38281@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38282
38283 void mxr_layer_release(struct mxr_layer *layer)
38284 {
38285- if (layer->ops.release)
38286- layer->ops.release(layer);
38287+ if (layer->ops->release)
38288+ layer->ops->release(layer);
38289 }
38290
38291 void mxr_base_layer_release(struct mxr_layer *layer)
38292@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38293
38294 layer->mdev = mdev;
38295 layer->idx = idx;
38296- layer->ops = *ops;
38297+ layer->ops = ops;
38298
38299 spin_lock_init(&layer->enq_slock);
38300 INIT_LIST_HEAD(&layer->enq_list);
38301diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38302index 3d13a63..da31bf1 100644
38303--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38304+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38305@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38306 {
38307 struct mxr_layer *layer;
38308 int ret;
38309- struct mxr_layer_ops ops = {
38310+ static struct mxr_layer_ops ops = {
38311 .release = mxr_vp_layer_release,
38312 .buffer_set = mxr_vp_buffer_set,
38313 .stream_set = mxr_vp_stream_set,
38314diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38315index 643d80a..56bb96b 100644
38316--- a/drivers/media/radio/radio-cadet.c
38317+++ b/drivers/media/radio/radio-cadet.c
38318@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38319 unsigned char readbuf[RDS_BUFFER];
38320 int i = 0;
38321
38322+ if (count > RDS_BUFFER)
38323+ return -EFAULT;
38324 mutex_lock(&dev->lock);
38325 if (dev->rdsstat == 0)
38326 cadet_start_rds(dev);
38327@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38328 while (i < count && dev->rdsin != dev->rdsout)
38329 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38330
38331- if (i && copy_to_user(data, readbuf, i))
38332+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38333 i = -EFAULT;
38334 unlock:
38335 mutex_unlock(&dev->lock);
38336diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38337index 3940bb0..fb3952a 100644
38338--- a/drivers/media/usb/dvb-usb/cxusb.c
38339+++ b/drivers/media/usb/dvb-usb/cxusb.c
38340@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38341
38342 struct dib0700_adapter_state {
38343 int (*set_param_save) (struct dvb_frontend *);
38344-};
38345+} __no_const;
38346
38347 static int dib7070_set_param_override(struct dvb_frontend *fe)
38348 {
38349diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38350index 9382895..ac8093c 100644
38351--- a/drivers/media/usb/dvb-usb/dw2102.c
38352+++ b/drivers/media/usb/dvb-usb/dw2102.c
38353@@ -95,7 +95,7 @@ struct su3000_state {
38354
38355 struct s6x0_state {
38356 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38357-};
38358+} __no_const;
38359
38360 /* debug */
38361 static int dvb_usb_dw2102_debug;
38362diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38363index aa6e7c7..4cd8061 100644
38364--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38365+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38366@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38367 struct file *file, void *fh, void *p);
38368 } u;
38369 void (*debug)(const void *arg, bool write_only);
38370-};
38371+} __do_const;
38372+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38373
38374 /* This control needs a priority check */
38375 #define INFO_FL_PRIO (1 << 0)
38376@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38377 struct video_device *vfd = video_devdata(file);
38378 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38379 bool write_only = false;
38380- struct v4l2_ioctl_info default_info;
38381+ v4l2_ioctl_info_no_const default_info;
38382 const struct v4l2_ioctl_info *info;
38383 void *fh = file->private_data;
38384 struct v4l2_fh *vfh = NULL;
38385diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38386index 29b2172..a7c5b31 100644
38387--- a/drivers/memstick/host/r592.c
38388+++ b/drivers/memstick/host/r592.c
38389@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38390 /* Executes one TPC (data is read/written from small or large fifo) */
38391 static void r592_execute_tpc(struct r592_device *dev)
38392 {
38393- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38394+ bool is_write;
38395 int len, error;
38396 u32 status, reg;
38397
38398@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38399 return;
38400 }
38401
38402+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38403 len = dev->req->long_data ?
38404 dev->req->sg.length : dev->req->data_len;
38405
38406diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38407index fb69baa..3aeea2e 100644
38408--- a/drivers/message/fusion/mptbase.c
38409+++ b/drivers/message/fusion/mptbase.c
38410@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38411 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38412 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38413
38414+#ifdef CONFIG_GRKERNSEC_HIDESYM
38415+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38416+#else
38417 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38418 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38419+#endif
38420+
38421 /*
38422 * Rounding UP to nearest 4-kB boundary here...
38423 */
38424@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38425 ioc->facts.GlobalCredits);
38426
38427 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38428+#ifdef CONFIG_GRKERNSEC_HIDESYM
38429+ NULL, NULL);
38430+#else
38431 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38432+#endif
38433 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38434 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38435 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38436diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38437index fa43c39..daeb158 100644
38438--- a/drivers/message/fusion/mptsas.c
38439+++ b/drivers/message/fusion/mptsas.c
38440@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38441 return 0;
38442 }
38443
38444+static inline void
38445+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38446+{
38447+ if (phy_info->port_details) {
38448+ phy_info->port_details->rphy = rphy;
38449+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38450+ ioc->name, rphy));
38451+ }
38452+
38453+ if (rphy) {
38454+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38455+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38456+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38457+ ioc->name, rphy, rphy->dev.release));
38458+ }
38459+}
38460+
38461 /* no mutex */
38462 static void
38463 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38464@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38465 return NULL;
38466 }
38467
38468-static inline void
38469-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38470-{
38471- if (phy_info->port_details) {
38472- phy_info->port_details->rphy = rphy;
38473- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38474- ioc->name, rphy));
38475- }
38476-
38477- if (rphy) {
38478- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38479- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38480- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38481- ioc->name, rphy, rphy->dev.release));
38482- }
38483-}
38484-
38485 static inline struct sas_port *
38486 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38487 {
38488diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38489index 164afa7..b6b2e74 100644
38490--- a/drivers/message/fusion/mptscsih.c
38491+++ b/drivers/message/fusion/mptscsih.c
38492@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38493
38494 h = shost_priv(SChost);
38495
38496- if (h) {
38497- if (h->info_kbuf == NULL)
38498- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38499- return h->info_kbuf;
38500- h->info_kbuf[0] = '\0';
38501+ if (!h)
38502+ return NULL;
38503
38504- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38505- h->info_kbuf[size-1] = '\0';
38506- }
38507+ if (h->info_kbuf == NULL)
38508+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38509+ return h->info_kbuf;
38510+ h->info_kbuf[0] = '\0';
38511+
38512+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38513+ h->info_kbuf[size-1] = '\0';
38514
38515 return h->info_kbuf;
38516 }
38517diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38518index 8001aa6..b137580 100644
38519--- a/drivers/message/i2o/i2o_proc.c
38520+++ b/drivers/message/i2o/i2o_proc.c
38521@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38522 "Array Controller Device"
38523 };
38524
38525-static char *chtostr(char *tmp, u8 *chars, int n)
38526-{
38527- tmp[0] = 0;
38528- return strncat(tmp, (char *)chars, n);
38529-}
38530-
38531 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38532 char *group)
38533 {
38534@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38535 } *result;
38536
38537 i2o_exec_execute_ddm_table ddm_table;
38538- char tmp[28 + 1];
38539
38540 result = kmalloc(sizeof(*result), GFP_KERNEL);
38541 if (!result)
38542@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38543
38544 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38545 seq_printf(seq, "%-#8x", ddm_table.module_id);
38546- seq_printf(seq, "%-29s",
38547- chtostr(tmp, ddm_table.module_name_version, 28));
38548+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38549 seq_printf(seq, "%9d ", ddm_table.data_size);
38550 seq_printf(seq, "%8d", ddm_table.code_size);
38551
38552@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38553
38554 i2o_driver_result_table *result;
38555 i2o_driver_store_table *dst;
38556- char tmp[28 + 1];
38557
38558 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38559 if (result == NULL)
38560@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38561
38562 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38563 seq_printf(seq, "%-#8x", dst->module_id);
38564- seq_printf(seq, "%-29s",
38565- chtostr(tmp, dst->module_name_version, 28));
38566- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38567+ seq_printf(seq, "%-.28s", dst->module_name_version);
38568+ seq_printf(seq, "%-.8s", dst->date);
38569 seq_printf(seq, "%8d ", dst->module_size);
38570 seq_printf(seq, "%8d ", dst->mpb_size);
38571 seq_printf(seq, "0x%04x", dst->module_flags);
38572@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38573 // == (allow) 512d bytes (max)
38574 static u16 *work16 = (u16 *) work32;
38575 int token;
38576- char tmp[16 + 1];
38577
38578 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38579
38580@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38581 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38582 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38583 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38584- seq_printf(seq, "Vendor info : %s\n",
38585- chtostr(tmp, (u8 *) (work32 + 2), 16));
38586- seq_printf(seq, "Product info : %s\n",
38587- chtostr(tmp, (u8 *) (work32 + 6), 16));
38588- seq_printf(seq, "Description : %s\n",
38589- chtostr(tmp, (u8 *) (work32 + 10), 16));
38590- seq_printf(seq, "Product rev. : %s\n",
38591- chtostr(tmp, (u8 *) (work32 + 14), 8));
38592+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38593+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38594+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38595+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38596
38597 seq_printf(seq, "Serial number : ");
38598 print_serial_number(seq, (u8 *) (work32 + 16),
38599@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38600 u8 pad[256]; // allow up to 256 byte (max) serial number
38601 } result;
38602
38603- char tmp[24 + 1];
38604-
38605 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38606
38607 if (token < 0) {
38608@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38609 }
38610
38611 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38612- seq_printf(seq, "Module name : %s\n",
38613- chtostr(tmp, result.module_name, 24));
38614- seq_printf(seq, "Module revision : %s\n",
38615- chtostr(tmp, result.module_rev, 8));
38616+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
38617+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38618
38619 seq_printf(seq, "Serial number : ");
38620 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38621@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38622 u8 instance_number[4];
38623 } result;
38624
38625- char tmp[64 + 1];
38626-
38627 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38628
38629 if (token < 0) {
38630@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38631 return 0;
38632 }
38633
38634- seq_printf(seq, "Device name : %s\n",
38635- chtostr(tmp, result.device_name, 64));
38636- seq_printf(seq, "Service name : %s\n",
38637- chtostr(tmp, result.service_name, 64));
38638- seq_printf(seq, "Physical name : %s\n",
38639- chtostr(tmp, result.physical_location, 64));
38640- seq_printf(seq, "Instance number : %s\n",
38641- chtostr(tmp, result.instance_number, 4));
38642+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
38643+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
38644+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38645+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38646
38647 return 0;
38648 }
38649diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38650index a8c08f3..155fe3d 100644
38651--- a/drivers/message/i2o/iop.c
38652+++ b/drivers/message/i2o/iop.c
38653@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38654
38655 spin_lock_irqsave(&c->context_list_lock, flags);
38656
38657- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38658- atomic_inc(&c->context_list_counter);
38659+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38660+ atomic_inc_unchecked(&c->context_list_counter);
38661
38662- entry->context = atomic_read(&c->context_list_counter);
38663+ entry->context = atomic_read_unchecked(&c->context_list_counter);
38664
38665 list_add(&entry->list, &c->context_list);
38666
38667@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38668
38669 #if BITS_PER_LONG == 64
38670 spin_lock_init(&c->context_list_lock);
38671- atomic_set(&c->context_list_counter, 0);
38672+ atomic_set_unchecked(&c->context_list_counter, 0);
38673 INIT_LIST_HEAD(&c->context_list);
38674 #endif
38675
38676diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38677index 45ece11..8efa218 100644
38678--- a/drivers/mfd/janz-cmodio.c
38679+++ b/drivers/mfd/janz-cmodio.c
38680@@ -13,6 +13,7 @@
38681
38682 #include <linux/kernel.h>
38683 #include <linux/module.h>
38684+#include <linux/slab.h>
38685 #include <linux/init.h>
38686 #include <linux/pci.h>
38687 #include <linux/interrupt.h>
38688diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38689index a5f9888..1c0ed56 100644
38690--- a/drivers/mfd/twl4030-irq.c
38691+++ b/drivers/mfd/twl4030-irq.c
38692@@ -35,6 +35,7 @@
38693 #include <linux/of.h>
38694 #include <linux/irqdomain.h>
38695 #include <linux/i2c/twl.h>
38696+#include <asm/pgtable.h>
38697
38698 #include "twl-core.h"
38699
38700@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38701 * Install an irq handler for each of the SIH modules;
38702 * clone dummy irq_chip since PIH can't *do* anything
38703 */
38704- twl4030_irq_chip = dummy_irq_chip;
38705- twl4030_irq_chip.name = "twl4030";
38706+ pax_open_kernel();
38707+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38708+ *(const char **)&twl4030_irq_chip.name = "twl4030";
38709
38710- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38711+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38712+ pax_close_kernel();
38713
38714 for (i = irq_base; i < irq_end; i++) {
38715 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38716diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38717index 277a8db..0e0b754 100644
38718--- a/drivers/mfd/twl6030-irq.c
38719+++ b/drivers/mfd/twl6030-irq.c
38720@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38721 * install an irq handler for each of the modules;
38722 * clone dummy irq_chip since PIH can't *do* anything
38723 */
38724- twl6030_irq_chip = dummy_irq_chip;
38725- twl6030_irq_chip.name = "twl6030";
38726- twl6030_irq_chip.irq_set_type = NULL;
38727- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38728+ pax_open_kernel();
38729+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38730+ *(const char **)&twl6030_irq_chip.name = "twl6030";
38731+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38732+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38733+ pax_close_kernel();
38734
38735 for (i = irq_base; i < irq_end; i++) {
38736 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38737diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38738index f428d86..274c368 100644
38739--- a/drivers/misc/c2port/core.c
38740+++ b/drivers/misc/c2port/core.c
38741@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38742 mutex_init(&c2dev->mutex);
38743
38744 /* Create binary file */
38745- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38746+ pax_open_kernel();
38747+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38748+ pax_close_kernel();
38749 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38750 if (unlikely(ret))
38751 goto error_device_create_bin_file;
38752diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38753index 3aa9a96..59cf685 100644
38754--- a/drivers/misc/kgdbts.c
38755+++ b/drivers/misc/kgdbts.c
38756@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38757 char before[BREAK_INSTR_SIZE];
38758 char after[BREAK_INSTR_SIZE];
38759
38760- probe_kernel_read(before, (char *)kgdbts_break_test,
38761+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38762 BREAK_INSTR_SIZE);
38763 init_simple_test();
38764 ts.tst = plant_and_detach_test;
38765@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38766 /* Activate test with initial breakpoint */
38767 if (!is_early)
38768 kgdb_breakpoint();
38769- probe_kernel_read(after, (char *)kgdbts_break_test,
38770+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38771 BREAK_INSTR_SIZE);
38772 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38773 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38774diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38775index 4a87e5c..76bdf5c 100644
38776--- a/drivers/misc/lis3lv02d/lis3lv02d.c
38777+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38778@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38779 * the lid is closed. This leads to interrupts as soon as a little move
38780 * is done.
38781 */
38782- atomic_inc(&lis3->count);
38783+ atomic_inc_unchecked(&lis3->count);
38784
38785 wake_up_interruptible(&lis3->misc_wait);
38786 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38787@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38788 if (lis3->pm_dev)
38789 pm_runtime_get_sync(lis3->pm_dev);
38790
38791- atomic_set(&lis3->count, 0);
38792+ atomic_set_unchecked(&lis3->count, 0);
38793 return 0;
38794 }
38795
38796@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38797 add_wait_queue(&lis3->misc_wait, &wait);
38798 while (true) {
38799 set_current_state(TASK_INTERRUPTIBLE);
38800- data = atomic_xchg(&lis3->count, 0);
38801+ data = atomic_xchg_unchecked(&lis3->count, 0);
38802 if (data)
38803 break;
38804
38805@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38806 struct lis3lv02d, miscdev);
38807
38808 poll_wait(file, &lis3->misc_wait, wait);
38809- if (atomic_read(&lis3->count))
38810+ if (atomic_read_unchecked(&lis3->count))
38811 return POLLIN | POLLRDNORM;
38812 return 0;
38813 }
38814diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38815index c439c82..1f20f57 100644
38816--- a/drivers/misc/lis3lv02d/lis3lv02d.h
38817+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38818@@ -297,7 +297,7 @@ struct lis3lv02d {
38819 struct input_polled_dev *idev; /* input device */
38820 struct platform_device *pdev; /* platform device */
38821 struct regulator_bulk_data regulators[2];
38822- atomic_t count; /* interrupt count after last read */
38823+ atomic_unchecked_t count; /* interrupt count after last read */
38824 union axis_conversion ac; /* hw -> logical axis */
38825 int mapped_btns[3];
38826
38827diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38828index 2f30bad..c4c13d0 100644
38829--- a/drivers/misc/sgi-gru/gruhandles.c
38830+++ b/drivers/misc/sgi-gru/gruhandles.c
38831@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38832 unsigned long nsec;
38833
38834 nsec = CLKS2NSEC(clks);
38835- atomic_long_inc(&mcs_op_statistics[op].count);
38836- atomic_long_add(nsec, &mcs_op_statistics[op].total);
38837+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38838+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38839 if (mcs_op_statistics[op].max < nsec)
38840 mcs_op_statistics[op].max = nsec;
38841 }
38842diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38843index 950dbe9..eeef0f8 100644
38844--- a/drivers/misc/sgi-gru/gruprocfs.c
38845+++ b/drivers/misc/sgi-gru/gruprocfs.c
38846@@ -32,9 +32,9 @@
38847
38848 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38849
38850-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38851+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38852 {
38853- unsigned long val = atomic_long_read(v);
38854+ unsigned long val = atomic_long_read_unchecked(v);
38855
38856 seq_printf(s, "%16lu %s\n", val, id);
38857 }
38858@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38859
38860 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38861 for (op = 0; op < mcsop_last; op++) {
38862- count = atomic_long_read(&mcs_op_statistics[op].count);
38863- total = atomic_long_read(&mcs_op_statistics[op].total);
38864+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38865+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38866 max = mcs_op_statistics[op].max;
38867 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38868 count ? total / count : 0, max);
38869diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38870index 5c3ce24..4915ccb 100644
38871--- a/drivers/misc/sgi-gru/grutables.h
38872+++ b/drivers/misc/sgi-gru/grutables.h
38873@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38874 * GRU statistics.
38875 */
38876 struct gru_stats_s {
38877- atomic_long_t vdata_alloc;
38878- atomic_long_t vdata_free;
38879- atomic_long_t gts_alloc;
38880- atomic_long_t gts_free;
38881- atomic_long_t gms_alloc;
38882- atomic_long_t gms_free;
38883- atomic_long_t gts_double_allocate;
38884- atomic_long_t assign_context;
38885- atomic_long_t assign_context_failed;
38886- atomic_long_t free_context;
38887- atomic_long_t load_user_context;
38888- atomic_long_t load_kernel_context;
38889- atomic_long_t lock_kernel_context;
38890- atomic_long_t unlock_kernel_context;
38891- atomic_long_t steal_user_context;
38892- atomic_long_t steal_kernel_context;
38893- atomic_long_t steal_context_failed;
38894- atomic_long_t nopfn;
38895- atomic_long_t asid_new;
38896- atomic_long_t asid_next;
38897- atomic_long_t asid_wrap;
38898- atomic_long_t asid_reuse;
38899- atomic_long_t intr;
38900- atomic_long_t intr_cbr;
38901- atomic_long_t intr_tfh;
38902- atomic_long_t intr_spurious;
38903- atomic_long_t intr_mm_lock_failed;
38904- atomic_long_t call_os;
38905- atomic_long_t call_os_wait_queue;
38906- atomic_long_t user_flush_tlb;
38907- atomic_long_t user_unload_context;
38908- atomic_long_t user_exception;
38909- atomic_long_t set_context_option;
38910- atomic_long_t check_context_retarget_intr;
38911- atomic_long_t check_context_unload;
38912- atomic_long_t tlb_dropin;
38913- atomic_long_t tlb_preload_page;
38914- atomic_long_t tlb_dropin_fail_no_asid;
38915- atomic_long_t tlb_dropin_fail_upm;
38916- atomic_long_t tlb_dropin_fail_invalid;
38917- atomic_long_t tlb_dropin_fail_range_active;
38918- atomic_long_t tlb_dropin_fail_idle;
38919- atomic_long_t tlb_dropin_fail_fmm;
38920- atomic_long_t tlb_dropin_fail_no_exception;
38921- atomic_long_t tfh_stale_on_fault;
38922- atomic_long_t mmu_invalidate_range;
38923- atomic_long_t mmu_invalidate_page;
38924- atomic_long_t flush_tlb;
38925- atomic_long_t flush_tlb_gru;
38926- atomic_long_t flush_tlb_gru_tgh;
38927- atomic_long_t flush_tlb_gru_zero_asid;
38928+ atomic_long_unchecked_t vdata_alloc;
38929+ atomic_long_unchecked_t vdata_free;
38930+ atomic_long_unchecked_t gts_alloc;
38931+ atomic_long_unchecked_t gts_free;
38932+ atomic_long_unchecked_t gms_alloc;
38933+ atomic_long_unchecked_t gms_free;
38934+ atomic_long_unchecked_t gts_double_allocate;
38935+ atomic_long_unchecked_t assign_context;
38936+ atomic_long_unchecked_t assign_context_failed;
38937+ atomic_long_unchecked_t free_context;
38938+ atomic_long_unchecked_t load_user_context;
38939+ atomic_long_unchecked_t load_kernel_context;
38940+ atomic_long_unchecked_t lock_kernel_context;
38941+ atomic_long_unchecked_t unlock_kernel_context;
38942+ atomic_long_unchecked_t steal_user_context;
38943+ atomic_long_unchecked_t steal_kernel_context;
38944+ atomic_long_unchecked_t steal_context_failed;
38945+ atomic_long_unchecked_t nopfn;
38946+ atomic_long_unchecked_t asid_new;
38947+ atomic_long_unchecked_t asid_next;
38948+ atomic_long_unchecked_t asid_wrap;
38949+ atomic_long_unchecked_t asid_reuse;
38950+ atomic_long_unchecked_t intr;
38951+ atomic_long_unchecked_t intr_cbr;
38952+ atomic_long_unchecked_t intr_tfh;
38953+ atomic_long_unchecked_t intr_spurious;
38954+ atomic_long_unchecked_t intr_mm_lock_failed;
38955+ atomic_long_unchecked_t call_os;
38956+ atomic_long_unchecked_t call_os_wait_queue;
38957+ atomic_long_unchecked_t user_flush_tlb;
38958+ atomic_long_unchecked_t user_unload_context;
38959+ atomic_long_unchecked_t user_exception;
38960+ atomic_long_unchecked_t set_context_option;
38961+ atomic_long_unchecked_t check_context_retarget_intr;
38962+ atomic_long_unchecked_t check_context_unload;
38963+ atomic_long_unchecked_t tlb_dropin;
38964+ atomic_long_unchecked_t tlb_preload_page;
38965+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38966+ atomic_long_unchecked_t tlb_dropin_fail_upm;
38967+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
38968+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
38969+ atomic_long_unchecked_t tlb_dropin_fail_idle;
38970+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
38971+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38972+ atomic_long_unchecked_t tfh_stale_on_fault;
38973+ atomic_long_unchecked_t mmu_invalidate_range;
38974+ atomic_long_unchecked_t mmu_invalidate_page;
38975+ atomic_long_unchecked_t flush_tlb;
38976+ atomic_long_unchecked_t flush_tlb_gru;
38977+ atomic_long_unchecked_t flush_tlb_gru_tgh;
38978+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38979
38980- atomic_long_t copy_gpa;
38981- atomic_long_t read_gpa;
38982+ atomic_long_unchecked_t copy_gpa;
38983+ atomic_long_unchecked_t read_gpa;
38984
38985- atomic_long_t mesq_receive;
38986- atomic_long_t mesq_receive_none;
38987- atomic_long_t mesq_send;
38988- atomic_long_t mesq_send_failed;
38989- atomic_long_t mesq_noop;
38990- atomic_long_t mesq_send_unexpected_error;
38991- atomic_long_t mesq_send_lb_overflow;
38992- atomic_long_t mesq_send_qlimit_reached;
38993- atomic_long_t mesq_send_amo_nacked;
38994- atomic_long_t mesq_send_put_nacked;
38995- atomic_long_t mesq_page_overflow;
38996- atomic_long_t mesq_qf_locked;
38997- atomic_long_t mesq_qf_noop_not_full;
38998- atomic_long_t mesq_qf_switch_head_failed;
38999- atomic_long_t mesq_qf_unexpected_error;
39000- atomic_long_t mesq_noop_unexpected_error;
39001- atomic_long_t mesq_noop_lb_overflow;
39002- atomic_long_t mesq_noop_qlimit_reached;
39003- atomic_long_t mesq_noop_amo_nacked;
39004- atomic_long_t mesq_noop_put_nacked;
39005- atomic_long_t mesq_noop_page_overflow;
39006+ atomic_long_unchecked_t mesq_receive;
39007+ atomic_long_unchecked_t mesq_receive_none;
39008+ atomic_long_unchecked_t mesq_send;
39009+ atomic_long_unchecked_t mesq_send_failed;
39010+ atomic_long_unchecked_t mesq_noop;
39011+ atomic_long_unchecked_t mesq_send_unexpected_error;
39012+ atomic_long_unchecked_t mesq_send_lb_overflow;
39013+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39014+ atomic_long_unchecked_t mesq_send_amo_nacked;
39015+ atomic_long_unchecked_t mesq_send_put_nacked;
39016+ atomic_long_unchecked_t mesq_page_overflow;
39017+ atomic_long_unchecked_t mesq_qf_locked;
39018+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39019+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39020+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39021+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39022+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39023+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39024+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39025+ atomic_long_unchecked_t mesq_noop_put_nacked;
39026+ atomic_long_unchecked_t mesq_noop_page_overflow;
39027
39028 };
39029
39030@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39031 tghop_invalidate, mcsop_last};
39032
39033 struct mcs_op_statistic {
39034- atomic_long_t count;
39035- atomic_long_t total;
39036+ atomic_long_unchecked_t count;
39037+ atomic_long_unchecked_t total;
39038 unsigned long max;
39039 };
39040
39041@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39042
39043 #define STAT(id) do { \
39044 if (gru_options & OPT_STATS) \
39045- atomic_long_inc(&gru_stats.id); \
39046+ atomic_long_inc_unchecked(&gru_stats.id); \
39047 } while (0)
39048
39049 #ifdef CONFIG_SGI_GRU_DEBUG
39050diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39051index c862cd4..0d176fe 100644
39052--- a/drivers/misc/sgi-xp/xp.h
39053+++ b/drivers/misc/sgi-xp/xp.h
39054@@ -288,7 +288,7 @@ struct xpc_interface {
39055 xpc_notify_func, void *);
39056 void (*received) (short, int, void *);
39057 enum xp_retval (*partid_to_nasids) (short, void *);
39058-};
39059+} __no_const;
39060
39061 extern struct xpc_interface xpc_interface;
39062
39063diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39064index b94d5f7..7f494c5 100644
39065--- a/drivers/misc/sgi-xp/xpc.h
39066+++ b/drivers/misc/sgi-xp/xpc.h
39067@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39068 void (*received_payload) (struct xpc_channel *, void *);
39069 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39070 };
39071+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39072
39073 /* struct xpc_partition act_state values (for XPC HB) */
39074
39075@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39076 /* found in xpc_main.c */
39077 extern struct device *xpc_part;
39078 extern struct device *xpc_chan;
39079-extern struct xpc_arch_operations xpc_arch_ops;
39080+extern xpc_arch_operations_no_const xpc_arch_ops;
39081 extern int xpc_disengage_timelimit;
39082 extern int xpc_disengage_timedout;
39083 extern int xpc_activate_IRQ_rcvd;
39084diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39085index d971817..33bdca5 100644
39086--- a/drivers/misc/sgi-xp/xpc_main.c
39087+++ b/drivers/misc/sgi-xp/xpc_main.c
39088@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39089 .notifier_call = xpc_system_die,
39090 };
39091
39092-struct xpc_arch_operations xpc_arch_ops;
39093+xpc_arch_operations_no_const xpc_arch_ops;
39094
39095 /*
39096 * Timer function to enforce the timelimit on the partition disengage.
39097@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39098
39099 if (((die_args->trapnr == X86_TRAP_MF) ||
39100 (die_args->trapnr == X86_TRAP_XF)) &&
39101- !user_mode_vm(die_args->regs))
39102+ !user_mode(die_args->regs))
39103 xpc_die_deactivate();
39104
39105 break;
39106diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39107index 6d8f701..35b6369 100644
39108--- a/drivers/mmc/core/mmc_ops.c
39109+++ b/drivers/mmc/core/mmc_ops.c
39110@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39111 void *data_buf;
39112 int is_on_stack;
39113
39114- is_on_stack = object_is_on_stack(buf);
39115+ is_on_stack = object_starts_on_stack(buf);
39116 if (is_on_stack) {
39117 /*
39118 * dma onto stack is unsafe/nonportable, but callers to this
39119diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39120index 53b8fd9..615b462 100644
39121--- a/drivers/mmc/host/dw_mmc.h
39122+++ b/drivers/mmc/host/dw_mmc.h
39123@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39124 int (*parse_dt)(struct dw_mci *host);
39125 int (*setup_bus)(struct dw_mci *host,
39126 struct device_node *slot_np, u8 bus_width);
39127-};
39128+} __do_const;
39129 #endif /* _DW_MMC_H_ */
39130diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39131index 82a8de1..3c56ccb 100644
39132--- a/drivers/mmc/host/sdhci-s3c.c
39133+++ b/drivers/mmc/host/sdhci-s3c.c
39134@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39135 * we can use overriding functions instead of default.
39136 */
39137 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39138- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39139- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39140- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39141+ pax_open_kernel();
39142+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39143+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39144+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39145+ pax_close_kernel();
39146 }
39147
39148 /* It supports additional host capabilities if needed */
39149diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39150index a4eb8b5..8c0628f 100644
39151--- a/drivers/mtd/devices/doc2000.c
39152+++ b/drivers/mtd/devices/doc2000.c
39153@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39154
39155 /* The ECC will not be calculated correctly if less than 512 is written */
39156 /* DBB-
39157- if (len != 0x200 && eccbuf)
39158+ if (len != 0x200)
39159 printk(KERN_WARNING
39160 "ECC needs a full sector write (adr: %lx size %lx)\n",
39161 (long) to, (long) len);
39162diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39163index 0c8bb6b..6f35deb 100644
39164--- a/drivers/mtd/nand/denali.c
39165+++ b/drivers/mtd/nand/denali.c
39166@@ -24,6 +24,7 @@
39167 #include <linux/slab.h>
39168 #include <linux/mtd/mtd.h>
39169 #include <linux/module.h>
39170+#include <linux/slab.h>
39171
39172 #include "denali.h"
39173
39174diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39175index 51b9d6a..52af9a7 100644
39176--- a/drivers/mtd/nftlmount.c
39177+++ b/drivers/mtd/nftlmount.c
39178@@ -24,6 +24,7 @@
39179 #include <asm/errno.h>
39180 #include <linux/delay.h>
39181 #include <linux/slab.h>
39182+#include <linux/sched.h>
39183 #include <linux/mtd/mtd.h>
39184 #include <linux/mtd/nand.h>
39185 #include <linux/mtd/nftl.h>
39186diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39187index 8dd6ba5..419cc1d 100644
39188--- a/drivers/mtd/sm_ftl.c
39189+++ b/drivers/mtd/sm_ftl.c
39190@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39191 #define SM_CIS_VENDOR_OFFSET 0x59
39192 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39193 {
39194- struct attribute_group *attr_group;
39195+ attribute_group_no_const *attr_group;
39196 struct attribute **attributes;
39197 struct sm_sysfs_attribute *vendor_attribute;
39198
39199diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39200index a079da17..f86ffd5 100644
39201--- a/drivers/net/bonding/bond_main.c
39202+++ b/drivers/net/bonding/bond_main.c
39203@@ -4862,7 +4862,7 @@ static unsigned int bond_get_num_tx_queues(void)
39204 return tx_queues;
39205 }
39206
39207-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39208+static struct rtnl_link_ops bond_link_ops = {
39209 .kind = "bond",
39210 .priv_size = sizeof(struct bonding),
39211 .setup = bond_setup,
39212diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39213index 70dba5d..11a0919 100644
39214--- a/drivers/net/ethernet/8390/ax88796.c
39215+++ b/drivers/net/ethernet/8390/ax88796.c
39216@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39217 if (ax->plat->reg_offsets)
39218 ei_local->reg_offset = ax->plat->reg_offsets;
39219 else {
39220+ resource_size_t _mem_size = mem_size;
39221+ do_div(_mem_size, 0x18);
39222 ei_local->reg_offset = ax->reg_offsets;
39223 for (ret = 0; ret < 0x18; ret++)
39224- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39225+ ax->reg_offsets[ret] = _mem_size * ret;
39226 }
39227
39228 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39229diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39230index 0991534..8098e92 100644
39231--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39232+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39233@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39234 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39235 {
39236 /* RX_MODE controlling object */
39237- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39238+ bnx2x_init_rx_mode_obj(bp);
39239
39240 /* multicast configuration controlling object */
39241 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39242diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39243index 09b625e..15b16fe 100644
39244--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39245+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39246@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39247 return rc;
39248 }
39249
39250-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39251- struct bnx2x_rx_mode_obj *o)
39252+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39253 {
39254 if (CHIP_IS_E1x(bp)) {
39255- o->wait_comp = bnx2x_empty_rx_mode_wait;
39256- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39257+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39258+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39259 } else {
39260- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39261- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39262+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39263+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39264 }
39265 }
39266
39267diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39268index adbd91b..58ec94a 100644
39269--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39270+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39271@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39272
39273 /********************* RX MODE ****************/
39274
39275-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39276- struct bnx2x_rx_mode_obj *o);
39277+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39278
39279 /**
39280 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39281diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
39282index f0b38fa..3a312b5 100644
39283--- a/drivers/net/ethernet/broadcom/tg3.c
39284+++ b/drivers/net/ethernet/broadcom/tg3.c
39285@@ -14395,8 +14395,10 @@ static void tg3_read_vpd(struct tg3 *tp)
39286 if (j + len > block_end)
39287 goto partno;
39288
39289- memcpy(tp->fw_ver, &vpd_data[j], len);
39290- strncat(tp->fw_ver, " bc ", vpdlen - len - 1);
39291+ if (len >= sizeof(tp->fw_ver))
39292+ len = sizeof(tp->fw_ver) - 1;
39293+ memset(tp->fw_ver, 0, sizeof(tp->fw_ver));
39294+ snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len, &vpd_data[j]);
39295 }
39296
39297 partno:
39298diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39299index d330e81..ce1fb9a 100644
39300--- a/drivers/net/ethernet/broadcom/tg3.h
39301+++ b/drivers/net/ethernet/broadcom/tg3.h
39302@@ -146,6 +146,7 @@
39303 #define CHIPREV_ID_5750_A0 0x4000
39304 #define CHIPREV_ID_5750_A1 0x4001
39305 #define CHIPREV_ID_5750_A3 0x4003
39306+#define CHIPREV_ID_5750_C1 0x4201
39307 #define CHIPREV_ID_5750_C2 0x4202
39308 #define CHIPREV_ID_5752_A0_HW 0x5000
39309 #define CHIPREV_ID_5752_A0 0x6000
39310diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39311index 8cffcdf..aadf043 100644
39312--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39313+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39314@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39315 */
39316 struct l2t_skb_cb {
39317 arp_failure_handler_func arp_failure_handler;
39318-};
39319+} __no_const;
39320
39321 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39322
39323diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39324index 4c83003..2a2a5b9 100644
39325--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39326+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39327@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39328 for (i=0; i<ETH_ALEN; i++) {
39329 tmp.addr[i] = dev->dev_addr[i];
39330 }
39331- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39332+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39333 break;
39334
39335 case DE4X5_SET_HWADDR: /* Set the hardware address */
39336@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39337 spin_lock_irqsave(&lp->lock, flags);
39338 memcpy(&statbuf, &lp->pktStats, ioc->len);
39339 spin_unlock_irqrestore(&lp->lock, flags);
39340- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39341+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39342 return -EFAULT;
39343 break;
39344 }
39345diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39346index 4d6f3c5..6169e60 100644
39347--- a/drivers/net/ethernet/emulex/benet/be_main.c
39348+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39349@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39350
39351 if (wrapped)
39352 newacc += 65536;
39353- ACCESS_ONCE(*acc) = newacc;
39354+ ACCESS_ONCE_RW(*acc) = newacc;
39355 }
39356
39357 void be_parse_stats(struct be_adapter *adapter)
39358diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39359index 74d749e..eefb1bd 100644
39360--- a/drivers/net/ethernet/faraday/ftgmac100.c
39361+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39362@@ -31,6 +31,8 @@
39363 #include <linux/netdevice.h>
39364 #include <linux/phy.h>
39365 #include <linux/platform_device.h>
39366+#include <linux/interrupt.h>
39367+#include <linux/irqreturn.h>
39368 #include <net/ip.h>
39369
39370 #include "ftgmac100.h"
39371diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39372index b901a01..1ff32ee 100644
39373--- a/drivers/net/ethernet/faraday/ftmac100.c
39374+++ b/drivers/net/ethernet/faraday/ftmac100.c
39375@@ -31,6 +31,8 @@
39376 #include <linux/module.h>
39377 #include <linux/netdevice.h>
39378 #include <linux/platform_device.h>
39379+#include <linux/interrupt.h>
39380+#include <linux/irqreturn.h>
39381
39382 #include "ftmac100.h"
39383
39384diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39385index bb9256a..56d8752 100644
39386--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39387+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39388@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39389 }
39390
39391 /* update the base incval used to calculate frequency adjustment */
39392- ACCESS_ONCE(adapter->base_incval) = incval;
39393+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39394 smp_mb();
39395
39396 /* need lock to prevent incorrect read while modifying cyclecounter */
39397diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39398index fbe5363..266b4e3 100644
39399--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39400+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39401@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39402 struct __vxge_hw_fifo *fifo;
39403 struct vxge_hw_fifo_config *config;
39404 u32 txdl_size, txdl_per_memblock;
39405- struct vxge_hw_mempool_cbs fifo_mp_callback;
39406+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39407+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39408+ };
39409+
39410 struct __vxge_hw_virtualpath *vpath;
39411
39412 if ((vp == NULL) || (attr == NULL)) {
39413@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39414 goto exit;
39415 }
39416
39417- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39418-
39419 fifo->mempool =
39420 __vxge_hw_mempool_create(vpath->hldev,
39421 fifo->config->memblock_size,
39422diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39423index 998974f..ecd26db 100644
39424--- a/drivers/net/ethernet/realtek/r8169.c
39425+++ b/drivers/net/ethernet/realtek/r8169.c
39426@@ -741,22 +741,22 @@ struct rtl8169_private {
39427 struct mdio_ops {
39428 void (*write)(struct rtl8169_private *, int, int);
39429 int (*read)(struct rtl8169_private *, int);
39430- } mdio_ops;
39431+ } __no_const mdio_ops;
39432
39433 struct pll_power_ops {
39434 void (*down)(struct rtl8169_private *);
39435 void (*up)(struct rtl8169_private *);
39436- } pll_power_ops;
39437+ } __no_const pll_power_ops;
39438
39439 struct jumbo_ops {
39440 void (*enable)(struct rtl8169_private *);
39441 void (*disable)(struct rtl8169_private *);
39442- } jumbo_ops;
39443+ } __no_const jumbo_ops;
39444
39445 struct csi_ops {
39446 void (*write)(struct rtl8169_private *, int, int);
39447 u32 (*read)(struct rtl8169_private *, int);
39448- } csi_ops;
39449+ } __no_const csi_ops;
39450
39451 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39452 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39453diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39454index 0767043f..08c2553 100644
39455--- a/drivers/net/ethernet/sfc/ptp.c
39456+++ b/drivers/net/ethernet/sfc/ptp.c
39457@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39458 (u32)((u64)ptp->start.dma_addr >> 32));
39459
39460 /* Clear flag that signals MC ready */
39461- ACCESS_ONCE(*start) = 0;
39462+ ACCESS_ONCE_RW(*start) = 0;
39463 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39464 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39465
39466diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39467index 0c74a70..3bc6f68 100644
39468--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39469+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39470@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39471
39472 writel(value, ioaddr + MMC_CNTRL);
39473
39474- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39475- MMC_CNTRL, value);
39476+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39477+// MMC_CNTRL, value);
39478 }
39479
39480 /* To mask all all interrupts.*/
39481diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39482index e6fe0d8..2b7d752 100644
39483--- a/drivers/net/hyperv/hyperv_net.h
39484+++ b/drivers/net/hyperv/hyperv_net.h
39485@@ -101,7 +101,7 @@ struct rndis_device {
39486
39487 enum rndis_device_state state;
39488 bool link_state;
39489- atomic_t new_req_id;
39490+ atomic_unchecked_t new_req_id;
39491
39492 spinlock_t request_lock;
39493 struct list_head req_list;
39494diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39495index 2b657d4..9903bc0 100644
39496--- a/drivers/net/hyperv/rndis_filter.c
39497+++ b/drivers/net/hyperv/rndis_filter.c
39498@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39499 * template
39500 */
39501 set = &rndis_msg->msg.set_req;
39502- set->req_id = atomic_inc_return(&dev->new_req_id);
39503+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39504
39505 /* Add to the request list */
39506 spin_lock_irqsave(&dev->request_lock, flags);
39507@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39508
39509 /* Setup the rndis set */
39510 halt = &request->request_msg.msg.halt_req;
39511- halt->req_id = atomic_inc_return(&dev->new_req_id);
39512+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39513
39514 /* Ignore return since this msg is optional. */
39515 rndis_filter_send_request(dev, request);
39516diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39517index 1e9cb0b..7839125 100644
39518--- a/drivers/net/ieee802154/fakehard.c
39519+++ b/drivers/net/ieee802154/fakehard.c
39520@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39521 phy->transmit_power = 0xbf;
39522
39523 dev->netdev_ops = &fake_ops;
39524- dev->ml_priv = &fake_mlme;
39525+ dev->ml_priv = (void *)&fake_mlme;
39526
39527 priv = netdev_priv(dev);
39528 priv->phy = phy;
39529diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39530index e5cb723..1fc0461 100644
39531--- a/drivers/net/macvlan.c
39532+++ b/drivers/net/macvlan.c
39533@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39534 int macvlan_link_register(struct rtnl_link_ops *ops)
39535 {
39536 /* common fields */
39537- ops->priv_size = sizeof(struct macvlan_dev);
39538- ops->validate = macvlan_validate;
39539- ops->maxtype = IFLA_MACVLAN_MAX;
39540- ops->policy = macvlan_policy;
39541- ops->changelink = macvlan_changelink;
39542- ops->get_size = macvlan_get_size;
39543- ops->fill_info = macvlan_fill_info;
39544+ pax_open_kernel();
39545+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39546+ *(void **)&ops->validate = macvlan_validate;
39547+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39548+ *(const void **)&ops->policy = macvlan_policy;
39549+ *(void **)&ops->changelink = macvlan_changelink;
39550+ *(void **)&ops->get_size = macvlan_get_size;
39551+ *(void **)&ops->fill_info = macvlan_fill_info;
39552+ pax_close_kernel();
39553
39554 return rtnl_link_register(ops);
39555 };
39556@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39557 return NOTIFY_DONE;
39558 }
39559
39560-static struct notifier_block macvlan_notifier_block __read_mostly = {
39561+static struct notifier_block macvlan_notifier_block = {
39562 .notifier_call = macvlan_device_event,
39563 };
39564
39565diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39566index 0f0f9ce..0ca5819 100644
39567--- a/drivers/net/macvtap.c
39568+++ b/drivers/net/macvtap.c
39569@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39570 return NOTIFY_DONE;
39571 }
39572
39573-static struct notifier_block macvtap_notifier_block __read_mostly = {
39574+static struct notifier_block macvtap_notifier_block = {
39575 .notifier_call = macvtap_device_event,
39576 };
39577
39578diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39579index daec9b0..6428fcb 100644
39580--- a/drivers/net/phy/mdio-bitbang.c
39581+++ b/drivers/net/phy/mdio-bitbang.c
39582@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39583 struct mdiobb_ctrl *ctrl = bus->priv;
39584
39585 module_put(ctrl->ops->owner);
39586+ mdiobus_unregister(bus);
39587 mdiobus_free(bus);
39588 }
39589 EXPORT_SYMBOL(free_mdio_bitbang);
39590diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39591index 508570e..f706dc7 100644
39592--- a/drivers/net/ppp/ppp_generic.c
39593+++ b/drivers/net/ppp/ppp_generic.c
39594@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39595 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39596 struct ppp_stats stats;
39597 struct ppp_comp_stats cstats;
39598- char *vers;
39599
39600 switch (cmd) {
39601 case SIOCGPPPSTATS:
39602@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39603 break;
39604
39605 case SIOCGPPPVER:
39606- vers = PPP_VERSION;
39607- if (copy_to_user(addr, vers, strlen(vers) + 1))
39608+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39609 break;
39610 err = 0;
39611 break;
39612diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39613index 8efe47a..a8075c5 100644
39614--- a/drivers/net/team/team.c
39615+++ b/drivers/net/team/team.c
39616@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
39617 return NOTIFY_DONE;
39618 }
39619
39620-static struct notifier_block team_notifier_block __read_mostly = {
39621+static struct notifier_block team_notifier_block = {
39622 .notifier_call = team_device_event,
39623 };
39624
39625diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39626index cb95fe5..a5bdab5 100644
39627--- a/drivers/net/tun.c
39628+++ b/drivers/net/tun.c
39629@@ -1838,7 +1838,7 @@ unlock:
39630 }
39631
39632 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39633- unsigned long arg, int ifreq_len)
39634+ unsigned long arg, size_t ifreq_len)
39635 {
39636 struct tun_file *tfile = file->private_data;
39637 struct tun_struct *tun;
39638@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39639 int vnet_hdr_sz;
39640 int ret;
39641
39642+ if (ifreq_len > sizeof ifr)
39643+ return -EFAULT;
39644+
39645 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39646 if (copy_from_user(&ifr, argp, ifreq_len))
39647 return -EFAULT;
39648diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39649index cd8ccb2..cff5144 100644
39650--- a/drivers/net/usb/hso.c
39651+++ b/drivers/net/usb/hso.c
39652@@ -71,7 +71,7 @@
39653 #include <asm/byteorder.h>
39654 #include <linux/serial_core.h>
39655 #include <linux/serial.h>
39656-
39657+#include <asm/local.h>
39658
39659 #define MOD_AUTHOR "Option Wireless"
39660 #define MOD_DESCRIPTION "USB High Speed Option driver"
39661@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39662 struct urb *urb;
39663
39664 urb = serial->rx_urb[0];
39665- if (serial->port.count > 0) {
39666+ if (atomic_read(&serial->port.count) > 0) {
39667 count = put_rxbuf_data(urb, serial);
39668 if (count == -1)
39669 return;
39670@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39671 DUMP1(urb->transfer_buffer, urb->actual_length);
39672
39673 /* Anyone listening? */
39674- if (serial->port.count == 0)
39675+ if (atomic_read(&serial->port.count) == 0)
39676 return;
39677
39678 if (status == 0) {
39679@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39680 tty_port_tty_set(&serial->port, tty);
39681
39682 /* check for port already opened, if not set the termios */
39683- serial->port.count++;
39684- if (serial->port.count == 1) {
39685+ if (atomic_inc_return(&serial->port.count) == 1) {
39686 serial->rx_state = RX_IDLE;
39687 /* Force default termio settings */
39688 _hso_serial_set_termios(tty, NULL);
39689@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39690 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39691 if (result) {
39692 hso_stop_serial_device(serial->parent);
39693- serial->port.count--;
39694+ atomic_dec(&serial->port.count);
39695 kref_put(&serial->parent->ref, hso_serial_ref_free);
39696 }
39697 } else {
39698@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39699
39700 /* reset the rts and dtr */
39701 /* do the actual close */
39702- serial->port.count--;
39703+ atomic_dec(&serial->port.count);
39704
39705- if (serial->port.count <= 0) {
39706- serial->port.count = 0;
39707+ if (atomic_read(&serial->port.count) <= 0) {
39708+ atomic_set(&serial->port.count, 0);
39709 tty_port_tty_set(&serial->port, NULL);
39710 if (!usb_gone)
39711 hso_stop_serial_device(serial->parent);
39712@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39713
39714 /* the actual setup */
39715 spin_lock_irqsave(&serial->serial_lock, flags);
39716- if (serial->port.count)
39717+ if (atomic_read(&serial->port.count))
39718 _hso_serial_set_termios(tty, old);
39719 else
39720 tty->termios = *old;
39721@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39722 D1("Pending read interrupt on port %d\n", i);
39723 spin_lock(&serial->serial_lock);
39724 if (serial->rx_state == RX_IDLE &&
39725- serial->port.count > 0) {
39726+ atomic_read(&serial->port.count) > 0) {
39727 /* Setup and send a ctrl req read on
39728 * port i */
39729 if (!serial->rx_urb_filled[0]) {
39730@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39731 /* Start all serial ports */
39732 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39733 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39734- if (dev2ser(serial_table[i])->port.count) {
39735+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39736 result =
39737 hso_start_serial_device(serial_table[i], GFP_NOIO);
39738 hso_kick_transmit(dev2ser(serial_table[i]));
39739diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39740index 6993bfa..9053a34 100644
39741--- a/drivers/net/vxlan.c
39742+++ b/drivers/net/vxlan.c
39743@@ -1428,7 +1428,7 @@ nla_put_failure:
39744 return -EMSGSIZE;
39745 }
39746
39747-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39748+static struct rtnl_link_ops vxlan_link_ops = {
39749 .kind = "vxlan",
39750 .maxtype = IFLA_VXLAN_MAX,
39751 .policy = vxlan_policy,
39752diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
39753index 77fa428..996b355 100644
39754--- a/drivers/net/wireless/at76c50x-usb.c
39755+++ b/drivers/net/wireless/at76c50x-usb.c
39756@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
39757 }
39758
39759 /* Convert timeout from the DFU status to jiffies */
39760-static inline unsigned long at76_get_timeout(struct dfu_status *s)
39761+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
39762 {
39763 return msecs_to_jiffies((s->poll_timeout[2] << 16)
39764 | (s->poll_timeout[1] << 8)
39765diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39766index 8d78253..bebbb68 100644
39767--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39768+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39769@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39770 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39771 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39772
39773- ACCESS_ONCE(ads->ds_link) = i->link;
39774- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39775+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
39776+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39777
39778 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39779 ctl6 = SM(i->keytype, AR_EncrType);
39780@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39781
39782 if ((i->is_first || i->is_last) &&
39783 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39784- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39785+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39786 | set11nTries(i->rates, 1)
39787 | set11nTries(i->rates, 2)
39788 | set11nTries(i->rates, 3)
39789 | (i->dur_update ? AR_DurUpdateEna : 0)
39790 | SM(0, AR_BurstDur);
39791
39792- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39793+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39794 | set11nRate(i->rates, 1)
39795 | set11nRate(i->rates, 2)
39796 | set11nRate(i->rates, 3);
39797 } else {
39798- ACCESS_ONCE(ads->ds_ctl2) = 0;
39799- ACCESS_ONCE(ads->ds_ctl3) = 0;
39800+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39801+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39802 }
39803
39804 if (!i->is_first) {
39805- ACCESS_ONCE(ads->ds_ctl0) = 0;
39806- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39807- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39808+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39809+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39810+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39811 return;
39812 }
39813
39814@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39815 break;
39816 }
39817
39818- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39819+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39820 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39821 | SM(i->txpower, AR_XmitPower)
39822 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39823@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39824 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39825 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39826
39827- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39828- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39829+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39830+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39831
39832 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39833 return;
39834
39835- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39836+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39837 | set11nPktDurRTSCTS(i->rates, 1);
39838
39839- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39840+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39841 | set11nPktDurRTSCTS(i->rates, 3);
39842
39843- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39844+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39845 | set11nRateFlags(i->rates, 1)
39846 | set11nRateFlags(i->rates, 2)
39847 | set11nRateFlags(i->rates, 3)
39848diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39849index 301bf72..3f5654f 100644
39850--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39851+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39852@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39853 (i->qcu << AR_TxQcuNum_S) | desc_len;
39854
39855 checksum += val;
39856- ACCESS_ONCE(ads->info) = val;
39857+ ACCESS_ONCE_RW(ads->info) = val;
39858
39859 checksum += i->link;
39860- ACCESS_ONCE(ads->link) = i->link;
39861+ ACCESS_ONCE_RW(ads->link) = i->link;
39862
39863 checksum += i->buf_addr[0];
39864- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39865+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39866 checksum += i->buf_addr[1];
39867- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39868+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39869 checksum += i->buf_addr[2];
39870- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39871+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39872 checksum += i->buf_addr[3];
39873- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39874+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39875
39876 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39877- ACCESS_ONCE(ads->ctl3) = val;
39878+ ACCESS_ONCE_RW(ads->ctl3) = val;
39879 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39880- ACCESS_ONCE(ads->ctl5) = val;
39881+ ACCESS_ONCE_RW(ads->ctl5) = val;
39882 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39883- ACCESS_ONCE(ads->ctl7) = val;
39884+ ACCESS_ONCE_RW(ads->ctl7) = val;
39885 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39886- ACCESS_ONCE(ads->ctl9) = val;
39887+ ACCESS_ONCE_RW(ads->ctl9) = val;
39888
39889 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39890- ACCESS_ONCE(ads->ctl10) = checksum;
39891+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
39892
39893 if (i->is_first || i->is_last) {
39894- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39895+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39896 | set11nTries(i->rates, 1)
39897 | set11nTries(i->rates, 2)
39898 | set11nTries(i->rates, 3)
39899 | (i->dur_update ? AR_DurUpdateEna : 0)
39900 | SM(0, AR_BurstDur);
39901
39902- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39903+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39904 | set11nRate(i->rates, 1)
39905 | set11nRate(i->rates, 2)
39906 | set11nRate(i->rates, 3);
39907 } else {
39908- ACCESS_ONCE(ads->ctl13) = 0;
39909- ACCESS_ONCE(ads->ctl14) = 0;
39910+ ACCESS_ONCE_RW(ads->ctl13) = 0;
39911+ ACCESS_ONCE_RW(ads->ctl14) = 0;
39912 }
39913
39914 ads->ctl20 = 0;
39915@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39916
39917 ctl17 = SM(i->keytype, AR_EncrType);
39918 if (!i->is_first) {
39919- ACCESS_ONCE(ads->ctl11) = 0;
39920- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39921- ACCESS_ONCE(ads->ctl15) = 0;
39922- ACCESS_ONCE(ads->ctl16) = 0;
39923- ACCESS_ONCE(ads->ctl17) = ctl17;
39924- ACCESS_ONCE(ads->ctl18) = 0;
39925- ACCESS_ONCE(ads->ctl19) = 0;
39926+ ACCESS_ONCE_RW(ads->ctl11) = 0;
39927+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39928+ ACCESS_ONCE_RW(ads->ctl15) = 0;
39929+ ACCESS_ONCE_RW(ads->ctl16) = 0;
39930+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39931+ ACCESS_ONCE_RW(ads->ctl18) = 0;
39932+ ACCESS_ONCE_RW(ads->ctl19) = 0;
39933 return;
39934 }
39935
39936- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39937+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39938 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39939 | SM(i->txpower, AR_XmitPower)
39940 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39941@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39942 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39943 ctl12 |= SM(val, AR_PAPRDChainMask);
39944
39945- ACCESS_ONCE(ads->ctl12) = ctl12;
39946- ACCESS_ONCE(ads->ctl17) = ctl17;
39947+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39948+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39949
39950- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39951+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39952 | set11nPktDurRTSCTS(i->rates, 1);
39953
39954- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39955+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39956 | set11nPktDurRTSCTS(i->rates, 3);
39957
39958- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39959+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39960 | set11nRateFlags(i->rates, 1)
39961 | set11nRateFlags(i->rates, 2)
39962 | set11nRateFlags(i->rates, 3)
39963 | SM(i->rtscts_rate, AR_RTSCTSRate);
39964
39965- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39966+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39967 }
39968
39969 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39970diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39971index 9d26fc5..60d9f14 100644
39972--- a/drivers/net/wireless/ath/ath9k/hw.h
39973+++ b/drivers/net/wireless/ath/ath9k/hw.h
39974@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39975
39976 /* ANI */
39977 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39978-};
39979+} __no_const;
39980
39981 /**
39982 * struct ath_hw_ops - callbacks used by hardware code and driver code
39983@@ -688,7 +688,7 @@ struct ath_hw_ops {
39984 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39985 struct ath_hw_antcomb_conf *antconf);
39986 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39987-};
39988+} __no_const;
39989
39990 struct ath_nf_limits {
39991 s16 max;
39992diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
39993index 3726cd6..b655808 100644
39994--- a/drivers/net/wireless/iwlegacy/3945-mac.c
39995+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
39996@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39997 */
39998 if (il3945_mod_params.disable_hw_scan) {
39999 D_INFO("Disabling hw_scan\n");
40000- il3945_mac_ops.hw_scan = NULL;
40001+ pax_open_kernel();
40002+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40003+ pax_close_kernel();
40004 }
40005
40006 D_INFO("*** LOAD DRIVER ***\n");
40007diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40008index 5b9533e..7733880 100644
40009--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40010+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40011@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40012 {
40013 struct iwl_priv *priv = file->private_data;
40014 char buf[64];
40015- int buf_size;
40016+ size_t buf_size;
40017 u32 offset, len;
40018
40019 memset(buf, 0, sizeof(buf));
40020@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40021 struct iwl_priv *priv = file->private_data;
40022
40023 char buf[8];
40024- int buf_size;
40025+ size_t buf_size;
40026 u32 reset_flag;
40027
40028 memset(buf, 0, sizeof(buf));
40029@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40030 {
40031 struct iwl_priv *priv = file->private_data;
40032 char buf[8];
40033- int buf_size;
40034+ size_t buf_size;
40035 int ht40;
40036
40037 memset(buf, 0, sizeof(buf));
40038@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40039 {
40040 struct iwl_priv *priv = file->private_data;
40041 char buf[8];
40042- int buf_size;
40043+ size_t buf_size;
40044 int value;
40045
40046 memset(buf, 0, sizeof(buf));
40047@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40048 {
40049 struct iwl_priv *priv = file->private_data;
40050 char buf[8];
40051- int buf_size;
40052+ size_t buf_size;
40053 int clear;
40054
40055 memset(buf, 0, sizeof(buf));
40056@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40057 {
40058 struct iwl_priv *priv = file->private_data;
40059 char buf[8];
40060- int buf_size;
40061+ size_t buf_size;
40062 int trace;
40063
40064 memset(buf, 0, sizeof(buf));
40065@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40066 {
40067 struct iwl_priv *priv = file->private_data;
40068 char buf[8];
40069- int buf_size;
40070+ size_t buf_size;
40071 int missed;
40072
40073 memset(buf, 0, sizeof(buf));
40074@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40075
40076 struct iwl_priv *priv = file->private_data;
40077 char buf[8];
40078- int buf_size;
40079+ size_t buf_size;
40080 int plcp;
40081
40082 memset(buf, 0, sizeof(buf));
40083@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40084
40085 struct iwl_priv *priv = file->private_data;
40086 char buf[8];
40087- int buf_size;
40088+ size_t buf_size;
40089 int flush;
40090
40091 memset(buf, 0, sizeof(buf));
40092@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40093
40094 struct iwl_priv *priv = file->private_data;
40095 char buf[8];
40096- int buf_size;
40097+ size_t buf_size;
40098 int rts;
40099
40100 if (!priv->cfg->ht_params)
40101@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40102 {
40103 struct iwl_priv *priv = file->private_data;
40104 char buf[8];
40105- int buf_size;
40106+ size_t buf_size;
40107
40108 memset(buf, 0, sizeof(buf));
40109 buf_size = min(count, sizeof(buf) - 1);
40110@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40111 struct iwl_priv *priv = file->private_data;
40112 u32 event_log_flag;
40113 char buf[8];
40114- int buf_size;
40115+ size_t buf_size;
40116
40117 /* check that the interface is up */
40118 if (!iwl_is_ready(priv))
40119@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40120 struct iwl_priv *priv = file->private_data;
40121 char buf[8];
40122 u32 calib_disabled;
40123- int buf_size;
40124+ size_t buf_size;
40125
40126 memset(buf, 0, sizeof(buf));
40127 buf_size = min(count, sizeof(buf) - 1);
40128diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40129index 35708b9..31f7754 100644
40130--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40131+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40132@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40133 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40134
40135 char buf[8];
40136- int buf_size;
40137+ size_t buf_size;
40138 u32 reset_flag;
40139
40140 memset(buf, 0, sizeof(buf));
40141@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40142 {
40143 struct iwl_trans *trans = file->private_data;
40144 char buf[8];
40145- int buf_size;
40146+ size_t buf_size;
40147 int csr;
40148
40149 memset(buf, 0, sizeof(buf));
40150diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40151index ff90855..e46d223 100644
40152--- a/drivers/net/wireless/mac80211_hwsim.c
40153+++ b/drivers/net/wireless/mac80211_hwsim.c
40154@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
40155
40156 if (channels > 1) {
40157 hwsim_if_comb.num_different_channels = channels;
40158- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40159- mac80211_hwsim_ops.cancel_hw_scan =
40160- mac80211_hwsim_cancel_hw_scan;
40161- mac80211_hwsim_ops.sw_scan_start = NULL;
40162- mac80211_hwsim_ops.sw_scan_complete = NULL;
40163- mac80211_hwsim_ops.remain_on_channel =
40164- mac80211_hwsim_roc;
40165- mac80211_hwsim_ops.cancel_remain_on_channel =
40166- mac80211_hwsim_croc;
40167- mac80211_hwsim_ops.add_chanctx =
40168- mac80211_hwsim_add_chanctx;
40169- mac80211_hwsim_ops.remove_chanctx =
40170- mac80211_hwsim_remove_chanctx;
40171- mac80211_hwsim_ops.change_chanctx =
40172- mac80211_hwsim_change_chanctx;
40173- mac80211_hwsim_ops.assign_vif_chanctx =
40174- mac80211_hwsim_assign_vif_chanctx;
40175- mac80211_hwsim_ops.unassign_vif_chanctx =
40176- mac80211_hwsim_unassign_vif_chanctx;
40177+ pax_open_kernel();
40178+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40179+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40180+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40181+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40182+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40183+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40184+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40185+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40186+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40187+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40188+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40189+ pax_close_kernel();
40190 }
40191
40192 spin_lock_init(&hwsim_radio_lock);
40193diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40194index abe1d03..fb02c22 100644
40195--- a/drivers/net/wireless/rndis_wlan.c
40196+++ b/drivers/net/wireless/rndis_wlan.c
40197@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40198
40199 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40200
40201- if (rts_threshold < 0 || rts_threshold > 2347)
40202+ if (rts_threshold > 2347)
40203 rts_threshold = 2347;
40204
40205 tmp = cpu_to_le32(rts_threshold);
40206diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40207index 0751b35..246ba3e 100644
40208--- a/drivers/net/wireless/rt2x00/rt2x00.h
40209+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40210@@ -398,7 +398,7 @@ struct rt2x00_intf {
40211 * for hardware which doesn't support hardware
40212 * sequence counting.
40213 */
40214- atomic_t seqno;
40215+ atomic_unchecked_t seqno;
40216 };
40217
40218 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40219diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40220index e488b94..14b6a0c 100644
40221--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40222+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40223@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40224 * sequence counter given by mac80211.
40225 */
40226 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40227- seqno = atomic_add_return(0x10, &intf->seqno);
40228+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40229 else
40230- seqno = atomic_read(&intf->seqno);
40231+ seqno = atomic_read_unchecked(&intf->seqno);
40232
40233 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40234 hdr->seq_ctrl |= cpu_to_le16(seqno);
40235diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40236index e57ee48..541cf6c 100644
40237--- a/drivers/net/wireless/ti/wl1251/sdio.c
40238+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40239@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40240
40241 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40242
40243- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40244- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40245+ pax_open_kernel();
40246+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40247+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40248+ pax_close_kernel();
40249
40250 wl1251_info("using dedicated interrupt line");
40251 } else {
40252- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40253- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40254+ pax_open_kernel();
40255+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40256+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40257+ pax_close_kernel();
40258
40259 wl1251_info("using SDIO interrupt");
40260 }
40261diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40262index e5f5f8f..fdf15b7 100644
40263--- a/drivers/net/wireless/ti/wl12xx/main.c
40264+++ b/drivers/net/wireless/ti/wl12xx/main.c
40265@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40266 sizeof(wl->conf.mem));
40267
40268 /* read data preparation is only needed by wl127x */
40269- wl->ops->prepare_read = wl127x_prepare_read;
40270+ pax_open_kernel();
40271+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40272+ pax_close_kernel();
40273
40274 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40275 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40276@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40277 sizeof(wl->conf.mem));
40278
40279 /* read data preparation is only needed by wl127x */
40280- wl->ops->prepare_read = wl127x_prepare_read;
40281+ pax_open_kernel();
40282+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40283+ pax_close_kernel();
40284
40285 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40286 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40287diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
40288index 8d8c1f8..e754844 100644
40289--- a/drivers/net/wireless/ti/wl18xx/main.c
40290+++ b/drivers/net/wireless/ti/wl18xx/main.c
40291@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
40292 }
40293
40294 if (!checksum_param) {
40295- wl18xx_ops.set_rx_csum = NULL;
40296- wl18xx_ops.init_vif = NULL;
40297+ pax_open_kernel();
40298+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
40299+ *(void **)&wl18xx_ops.init_vif = NULL;
40300+ pax_close_kernel();
40301 }
40302
40303 /* Enable 11a Band only if we have 5G antennas */
40304diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
40305index ef2b171..bb513a6 100644
40306--- a/drivers/net/wireless/zd1211rw/zd_usb.c
40307+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
40308@@ -387,7 +387,7 @@ static inline void handle_regs_int(struct urb *urb)
40309 {
40310 struct zd_usb *usb = urb->context;
40311 struct zd_usb_interrupt *intr = &usb->intr;
40312- int len;
40313+ unsigned int len;
40314 u16 int_num;
40315
40316 ZD_ASSERT(in_interrupt());
40317diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
40318index d93b2b6..ae50401 100644
40319--- a/drivers/oprofile/buffer_sync.c
40320+++ b/drivers/oprofile/buffer_sync.c
40321@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
40322 if (cookie == NO_COOKIE)
40323 offset = pc;
40324 if (cookie == INVALID_COOKIE) {
40325- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40326+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40327 offset = pc;
40328 }
40329 if (cookie != last_cookie) {
40330@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
40331 /* add userspace sample */
40332
40333 if (!mm) {
40334- atomic_inc(&oprofile_stats.sample_lost_no_mm);
40335+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
40336 return 0;
40337 }
40338
40339 cookie = lookup_dcookie(mm, s->eip, &offset);
40340
40341 if (cookie == INVALID_COOKIE) {
40342- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40343+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40344 return 0;
40345 }
40346
40347@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
40348 /* ignore backtraces if failed to add a sample */
40349 if (state == sb_bt_start) {
40350 state = sb_bt_ignore;
40351- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
40352+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
40353 }
40354 }
40355 release_mm(mm);
40356diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
40357index c0cc4e7..44d4e54 100644
40358--- a/drivers/oprofile/event_buffer.c
40359+++ b/drivers/oprofile/event_buffer.c
40360@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
40361 }
40362
40363 if (buffer_pos == buffer_size) {
40364- atomic_inc(&oprofile_stats.event_lost_overflow);
40365+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
40366 return;
40367 }
40368
40369diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
40370index ed2c3ec..deda85a 100644
40371--- a/drivers/oprofile/oprof.c
40372+++ b/drivers/oprofile/oprof.c
40373@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
40374 if (oprofile_ops.switch_events())
40375 return;
40376
40377- atomic_inc(&oprofile_stats.multiplex_counter);
40378+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
40379 start_switch_worker();
40380 }
40381
40382diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
40383index 84a208d..d61b0a1 100644
40384--- a/drivers/oprofile/oprofile_files.c
40385+++ b/drivers/oprofile/oprofile_files.c
40386@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
40387
40388 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
40389
40390-static ssize_t timeout_read(struct file *file, char __user *buf,
40391+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
40392 size_t count, loff_t *offset)
40393 {
40394 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
40395diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
40396index 917d28e..d62d981 100644
40397--- a/drivers/oprofile/oprofile_stats.c
40398+++ b/drivers/oprofile/oprofile_stats.c
40399@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
40400 cpu_buf->sample_invalid_eip = 0;
40401 }
40402
40403- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
40404- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
40405- atomic_set(&oprofile_stats.event_lost_overflow, 0);
40406- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
40407- atomic_set(&oprofile_stats.multiplex_counter, 0);
40408+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
40409+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
40410+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
40411+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
40412+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
40413 }
40414
40415
40416diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
40417index 38b6fc0..b5cbfce 100644
40418--- a/drivers/oprofile/oprofile_stats.h
40419+++ b/drivers/oprofile/oprofile_stats.h
40420@@ -13,11 +13,11 @@
40421 #include <linux/atomic.h>
40422
40423 struct oprofile_stat_struct {
40424- atomic_t sample_lost_no_mm;
40425- atomic_t sample_lost_no_mapping;
40426- atomic_t bt_lost_no_mapping;
40427- atomic_t event_lost_overflow;
40428- atomic_t multiplex_counter;
40429+ atomic_unchecked_t sample_lost_no_mm;
40430+ atomic_unchecked_t sample_lost_no_mapping;
40431+ atomic_unchecked_t bt_lost_no_mapping;
40432+ atomic_unchecked_t event_lost_overflow;
40433+ atomic_unchecked_t multiplex_counter;
40434 };
40435
40436 extern struct oprofile_stat_struct oprofile_stats;
40437diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40438index 849357c..b83c1e0 100644
40439--- a/drivers/oprofile/oprofilefs.c
40440+++ b/drivers/oprofile/oprofilefs.c
40441@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
40442
40443
40444 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40445- char const *name, atomic_t *val)
40446+ char const *name, atomic_unchecked_t *val)
40447 {
40448 return __oprofilefs_create_file(sb, root, name,
40449 &atomic_ro_fops, 0444, val);
40450diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40451index 93404f7..4a313d8 100644
40452--- a/drivers/oprofile/timer_int.c
40453+++ b/drivers/oprofile/timer_int.c
40454@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40455 return NOTIFY_OK;
40456 }
40457
40458-static struct notifier_block __refdata oprofile_cpu_notifier = {
40459+static struct notifier_block oprofile_cpu_notifier = {
40460 .notifier_call = oprofile_cpu_notify,
40461 };
40462
40463diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40464index 3f56bc0..707d642 100644
40465--- a/drivers/parport/procfs.c
40466+++ b/drivers/parport/procfs.c
40467@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40468
40469 *ppos += len;
40470
40471- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40472+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40473 }
40474
40475 #ifdef CONFIG_PARPORT_1284
40476@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
40477
40478 *ppos += len;
40479
40480- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
40481+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
40482 }
40483 #endif /* IEEE1284.3 support. */
40484
40485diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40486index c35e8ad..fc33beb 100644
40487--- a/drivers/pci/hotplug/acpiphp_ibm.c
40488+++ b/drivers/pci/hotplug/acpiphp_ibm.c
40489@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40490 goto init_cleanup;
40491 }
40492
40493- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40494+ pax_open_kernel();
40495+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40496+ pax_close_kernel();
40497 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40498
40499 return retval;
40500diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40501index a6a71c4..c91097b 100644
40502--- a/drivers/pci/hotplug/cpcihp_generic.c
40503+++ b/drivers/pci/hotplug/cpcihp_generic.c
40504@@ -73,7 +73,6 @@ static u16 port;
40505 static unsigned int enum_bit;
40506 static u8 enum_mask;
40507
40508-static struct cpci_hp_controller_ops generic_hpc_ops;
40509 static struct cpci_hp_controller generic_hpc;
40510
40511 static int __init validate_parameters(void)
40512@@ -139,6 +138,10 @@ static int query_enum(void)
40513 return ((value & enum_mask) == enum_mask);
40514 }
40515
40516+static struct cpci_hp_controller_ops generic_hpc_ops = {
40517+ .query_enum = query_enum,
40518+};
40519+
40520 static int __init cpcihp_generic_init(void)
40521 {
40522 int status;
40523@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40524 pci_dev_put(dev);
40525
40526 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40527- generic_hpc_ops.query_enum = query_enum;
40528 generic_hpc.ops = &generic_hpc_ops;
40529
40530 status = cpci_hp_register_controller(&generic_hpc);
40531diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40532index 449b4bb..257e2e8 100644
40533--- a/drivers/pci/hotplug/cpcihp_zt5550.c
40534+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40535@@ -59,7 +59,6 @@
40536 /* local variables */
40537 static bool debug;
40538 static bool poll;
40539-static struct cpci_hp_controller_ops zt5550_hpc_ops;
40540 static struct cpci_hp_controller zt5550_hpc;
40541
40542 /* Primary cPCI bus bridge device */
40543@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40544 return 0;
40545 }
40546
40547+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40548+ .query_enum = zt5550_hc_query_enum,
40549+};
40550+
40551 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40552 {
40553 int status;
40554@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40555 dbg("returned from zt5550_hc_config");
40556
40557 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40558- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40559 zt5550_hpc.ops = &zt5550_hpc_ops;
40560 if(!poll) {
40561 zt5550_hpc.irq = hc_dev->irq;
40562 zt5550_hpc.irq_flags = IRQF_SHARED;
40563 zt5550_hpc.dev_id = hc_dev;
40564
40565- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40566- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40567- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40568+ pax_open_kernel();
40569+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40570+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40571+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40572+ pax_open_kernel();
40573 } else {
40574 info("using ENUM# polling mode");
40575 }
40576diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40577index 76ba8a1..20ca857 100644
40578--- a/drivers/pci/hotplug/cpqphp_nvram.c
40579+++ b/drivers/pci/hotplug/cpqphp_nvram.c
40580@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40581
40582 void compaq_nvram_init (void __iomem *rom_start)
40583 {
40584+
40585+#ifndef CONFIG_PAX_KERNEXEC
40586 if (rom_start) {
40587 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40588 }
40589+#endif
40590+
40591 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40592
40593 /* initialize our int15 lock */
40594diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40595index 202f4a9..8ee47d0 100644
40596--- a/drivers/pci/hotplug/pci_hotplug_core.c
40597+++ b/drivers/pci/hotplug/pci_hotplug_core.c
40598@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40599 return -EINVAL;
40600 }
40601
40602- slot->ops->owner = owner;
40603- slot->ops->mod_name = mod_name;
40604+ pax_open_kernel();
40605+ *(struct module **)&slot->ops->owner = owner;
40606+ *(const char **)&slot->ops->mod_name = mod_name;
40607+ pax_close_kernel();
40608
40609 mutex_lock(&pci_hp_mutex);
40610 /*
40611diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40612index 939bd1d..a1459c9 100644
40613--- a/drivers/pci/hotplug/pciehp_core.c
40614+++ b/drivers/pci/hotplug/pciehp_core.c
40615@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40616 struct slot *slot = ctrl->slot;
40617 struct hotplug_slot *hotplug = NULL;
40618 struct hotplug_slot_info *info = NULL;
40619- struct hotplug_slot_ops *ops = NULL;
40620+ hotplug_slot_ops_no_const *ops = NULL;
40621 char name[SLOT_NAME_SIZE];
40622 int retval = -ENOMEM;
40623
40624diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40625index 9c6e9bb..2916736 100644
40626--- a/drivers/pci/pci-sysfs.c
40627+++ b/drivers/pci/pci-sysfs.c
40628@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40629 {
40630 /* allocate attribute structure, piggyback attribute name */
40631 int name_len = write_combine ? 13 : 10;
40632- struct bin_attribute *res_attr;
40633+ bin_attribute_no_const *res_attr;
40634 int retval;
40635
40636 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40637@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40638 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40639 {
40640 int retval;
40641- struct bin_attribute *attr;
40642+ bin_attribute_no_const *attr;
40643
40644 /* If the device has VPD, try to expose it in sysfs. */
40645 if (dev->vpd) {
40646@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40647 {
40648 int retval;
40649 int rom_size = 0;
40650- struct bin_attribute *attr;
40651+ bin_attribute_no_const *attr;
40652
40653 if (!sysfs_initialized)
40654 return -EACCES;
40655diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40656index e851829..a1a7196 100644
40657--- a/drivers/pci/pci.h
40658+++ b/drivers/pci/pci.h
40659@@ -98,7 +98,7 @@ struct pci_vpd_ops {
40660 struct pci_vpd {
40661 unsigned int len;
40662 const struct pci_vpd_ops *ops;
40663- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40664+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40665 };
40666
40667 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40668diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40669index 8474b6a..ee81993 100644
40670--- a/drivers/pci/pcie/aspm.c
40671+++ b/drivers/pci/pcie/aspm.c
40672@@ -27,9 +27,9 @@
40673 #define MODULE_PARAM_PREFIX "pcie_aspm."
40674
40675 /* Note: those are not register definitions */
40676-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40677-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40678-#define ASPM_STATE_L1 (4) /* L1 state */
40679+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40680+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40681+#define ASPM_STATE_L1 (4U) /* L1 state */
40682 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40683 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40684
40685diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40686index 6186f03..1a78714 100644
40687--- a/drivers/pci/probe.c
40688+++ b/drivers/pci/probe.c
40689@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40690 struct pci_bus_region region;
40691 bool bar_too_big = false, bar_disabled = false;
40692
40693- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40694+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40695
40696 /* No printks while decoding is disabled! */
40697 if (!dev->mmio_always_on) {
40698diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40699index 9b8505c..f00870a 100644
40700--- a/drivers/pci/proc.c
40701+++ b/drivers/pci/proc.c
40702@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40703 static int __init pci_proc_init(void)
40704 {
40705 struct pci_dev *dev = NULL;
40706+
40707+#ifdef CONFIG_GRKERNSEC_PROC_ADD
40708+#ifdef CONFIG_GRKERNSEC_PROC_USER
40709+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40710+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40711+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40712+#endif
40713+#else
40714 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40715+#endif
40716 proc_create("devices", 0, proc_bus_pci_dir,
40717 &proc_bus_pci_dev_operations);
40718 proc_initialized = 1;
40719diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40720index 2111dbb..79e434b 100644
40721--- a/drivers/platform/x86/msi-laptop.c
40722+++ b/drivers/platform/x86/msi-laptop.c
40723@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40724 int result;
40725
40726 /* allow userland write sysfs file */
40727- dev_attr_bluetooth.store = store_bluetooth;
40728- dev_attr_wlan.store = store_wlan;
40729- dev_attr_threeg.store = store_threeg;
40730- dev_attr_bluetooth.attr.mode |= S_IWUSR;
40731- dev_attr_wlan.attr.mode |= S_IWUSR;
40732- dev_attr_threeg.attr.mode |= S_IWUSR;
40733+ pax_open_kernel();
40734+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40735+ *(void **)&dev_attr_wlan.store = store_wlan;
40736+ *(void **)&dev_attr_threeg.store = store_threeg;
40737+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40738+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40739+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40740+ pax_close_kernel();
40741
40742 /* disable hardware control by fn key */
40743 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40744diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40745index 0fe987f..6f3d5c3 100644
40746--- a/drivers/platform/x86/sony-laptop.c
40747+++ b/drivers/platform/x86/sony-laptop.c
40748@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40749 }
40750
40751 /* High speed charging function */
40752-static struct device_attribute *hsc_handle;
40753+static device_attribute_no_const *hsc_handle;
40754
40755 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40756 struct device_attribute *attr,
40757diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40758index f946ca7..f25c833 100644
40759--- a/drivers/platform/x86/thinkpad_acpi.c
40760+++ b/drivers/platform/x86/thinkpad_acpi.c
40761@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40762 return 0;
40763 }
40764
40765-void static hotkey_mask_warn_incomplete_mask(void)
40766+static void hotkey_mask_warn_incomplete_mask(void)
40767 {
40768 /* log only what the user can fix... */
40769 const u32 wantedmask = hotkey_driver_mask &
40770@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40771 }
40772 }
40773
40774-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40775- struct tp_nvram_state *newn,
40776- const u32 event_mask)
40777-{
40778-
40779 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40780 do { \
40781 if ((event_mask & (1 << __scancode)) && \
40782@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40783 tpacpi_hotkey_send_key(__scancode); \
40784 } while (0)
40785
40786- void issue_volchange(const unsigned int oldvol,
40787- const unsigned int newvol)
40788- {
40789- unsigned int i = oldvol;
40790+static void issue_volchange(const unsigned int oldvol,
40791+ const unsigned int newvol,
40792+ const u32 event_mask)
40793+{
40794+ unsigned int i = oldvol;
40795
40796- while (i > newvol) {
40797- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40798- i--;
40799- }
40800- while (i < newvol) {
40801- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40802- i++;
40803- }
40804+ while (i > newvol) {
40805+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40806+ i--;
40807 }
40808+ while (i < newvol) {
40809+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40810+ i++;
40811+ }
40812+}
40813
40814- void issue_brightnesschange(const unsigned int oldbrt,
40815- const unsigned int newbrt)
40816- {
40817- unsigned int i = oldbrt;
40818+static void issue_brightnesschange(const unsigned int oldbrt,
40819+ const unsigned int newbrt,
40820+ const u32 event_mask)
40821+{
40822+ unsigned int i = oldbrt;
40823
40824- while (i > newbrt) {
40825- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40826- i--;
40827- }
40828- while (i < newbrt) {
40829- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40830- i++;
40831- }
40832+ while (i > newbrt) {
40833+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40834+ i--;
40835+ }
40836+ while (i < newbrt) {
40837+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40838+ i++;
40839 }
40840+}
40841
40842+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40843+ struct tp_nvram_state *newn,
40844+ const u32 event_mask)
40845+{
40846 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40847 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40848 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40849@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40850 oldn->volume_level != newn->volume_level) {
40851 /* recently muted, or repeated mute keypress, or
40852 * multiple presses ending in mute */
40853- issue_volchange(oldn->volume_level, newn->volume_level);
40854+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40855 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40856 }
40857 } else {
40858@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40859 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40860 }
40861 if (oldn->volume_level != newn->volume_level) {
40862- issue_volchange(oldn->volume_level, newn->volume_level);
40863+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40864 } else if (oldn->volume_toggle != newn->volume_toggle) {
40865 /* repeated vol up/down keypress at end of scale ? */
40866 if (newn->volume_level == 0)
40867@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40868 /* handle brightness */
40869 if (oldn->brightness_level != newn->brightness_level) {
40870 issue_brightnesschange(oldn->brightness_level,
40871- newn->brightness_level);
40872+ newn->brightness_level,
40873+ event_mask);
40874 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40875 /* repeated key presses that didn't change state */
40876 if (newn->brightness_level == 0)
40877@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40878 && !tp_features.bright_unkfw)
40879 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40880 }
40881+}
40882
40883 #undef TPACPI_COMPARE_KEY
40884 #undef TPACPI_MAY_SEND_KEY
40885-}
40886
40887 /*
40888 * Polling driver
40889diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40890index 769d265..a3a05ca 100644
40891--- a/drivers/pnp/pnpbios/bioscalls.c
40892+++ b/drivers/pnp/pnpbios/bioscalls.c
40893@@ -58,7 +58,7 @@ do { \
40894 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40895 } while(0)
40896
40897-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40898+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40899 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40900
40901 /*
40902@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40903
40904 cpu = get_cpu();
40905 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40906+
40907+ pax_open_kernel();
40908 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40909+ pax_close_kernel();
40910
40911 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40912 spin_lock_irqsave(&pnp_bios_lock, flags);
40913@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40914 :"memory");
40915 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40916
40917+ pax_open_kernel();
40918 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40919+ pax_close_kernel();
40920+
40921 put_cpu();
40922
40923 /* If we get here and this is set then the PnP BIOS faulted on us. */
40924@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40925 return status;
40926 }
40927
40928-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40929+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40930 {
40931 int i;
40932
40933@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40934 pnp_bios_callpoint.offset = header->fields.pm16offset;
40935 pnp_bios_callpoint.segment = PNP_CS16;
40936
40937+ pax_open_kernel();
40938+
40939 for_each_possible_cpu(i) {
40940 struct desc_struct *gdt = get_cpu_gdt_table(i);
40941 if (!gdt)
40942@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40943 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40944 (unsigned long)__va(header->fields.pm16dseg));
40945 }
40946+
40947+ pax_close_kernel();
40948 }
40949diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40950index 3e6db1c..1fbbdae 100644
40951--- a/drivers/pnp/resource.c
40952+++ b/drivers/pnp/resource.c
40953@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40954 return 1;
40955
40956 /* check if the resource is valid */
40957- if (*irq < 0 || *irq > 15)
40958+ if (*irq > 15)
40959 return 0;
40960
40961 /* check if the resource is reserved */
40962@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40963 return 1;
40964
40965 /* check if the resource is valid */
40966- if (*dma < 0 || *dma == 4 || *dma > 7)
40967+ if (*dma == 4 || *dma > 7)
40968 return 0;
40969
40970 /* check if the resource is reserved */
40971diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40972index 7df7c5f..bd48c47 100644
40973--- a/drivers/power/pda_power.c
40974+++ b/drivers/power/pda_power.c
40975@@ -37,7 +37,11 @@ static int polling;
40976
40977 #ifdef CONFIG_USB_OTG_UTILS
40978 static struct usb_phy *transceiver;
40979-static struct notifier_block otg_nb;
40980+static int otg_handle_notification(struct notifier_block *nb,
40981+ unsigned long event, void *unused);
40982+static struct notifier_block otg_nb = {
40983+ .notifier_call = otg_handle_notification
40984+};
40985 #endif
40986
40987 static struct regulator *ac_draw;
40988@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40989
40990 #ifdef CONFIG_USB_OTG_UTILS
40991 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
40992- otg_nb.notifier_call = otg_handle_notification;
40993 ret = usb_register_notifier(transceiver, &otg_nb);
40994 if (ret) {
40995 dev_err(dev, "failure to register otg notifier\n");
40996diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
40997index cc439fd..8fa30df 100644
40998--- a/drivers/power/power_supply.h
40999+++ b/drivers/power/power_supply.h
41000@@ -16,12 +16,12 @@ struct power_supply;
41001
41002 #ifdef CONFIG_SYSFS
41003
41004-extern void power_supply_init_attrs(struct device_type *dev_type);
41005+extern void power_supply_init_attrs(void);
41006 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41007
41008 #else
41009
41010-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41011+static inline void power_supply_init_attrs(void) {}
41012 #define power_supply_uevent NULL
41013
41014 #endif /* CONFIG_SYSFS */
41015diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41016index 8a7cfb3..72e6e9b 100644
41017--- a/drivers/power/power_supply_core.c
41018+++ b/drivers/power/power_supply_core.c
41019@@ -24,7 +24,10 @@
41020 struct class *power_supply_class;
41021 EXPORT_SYMBOL_GPL(power_supply_class);
41022
41023-static struct device_type power_supply_dev_type;
41024+extern const struct attribute_group *power_supply_attr_groups[];
41025+static struct device_type power_supply_dev_type = {
41026+ .groups = power_supply_attr_groups,
41027+};
41028
41029 static int __power_supply_changed_work(struct device *dev, void *data)
41030 {
41031@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41032 return PTR_ERR(power_supply_class);
41033
41034 power_supply_class->dev_uevent = power_supply_uevent;
41035- power_supply_init_attrs(&power_supply_dev_type);
41036+ power_supply_init_attrs();
41037
41038 return 0;
41039 }
41040diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41041index 40fa3b7..d9c2e0e 100644
41042--- a/drivers/power/power_supply_sysfs.c
41043+++ b/drivers/power/power_supply_sysfs.c
41044@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
41045 .is_visible = power_supply_attr_is_visible,
41046 };
41047
41048-static const struct attribute_group *power_supply_attr_groups[] = {
41049+const struct attribute_group *power_supply_attr_groups[] = {
41050 &power_supply_attr_group,
41051 NULL,
41052 };
41053
41054-void power_supply_init_attrs(struct device_type *dev_type)
41055+void power_supply_init_attrs(void)
41056 {
41057 int i;
41058
41059- dev_type->groups = power_supply_attr_groups;
41060-
41061 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41062 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41063 }
41064diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41065index 4d7c635..9860196 100644
41066--- a/drivers/regulator/max8660.c
41067+++ b/drivers/regulator/max8660.c
41068@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41069 max8660->shadow_regs[MAX8660_OVER1] = 5;
41070 } else {
41071 /* Otherwise devices can be toggled via software */
41072- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41073- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41074+ pax_open_kernel();
41075+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41076+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41077+ pax_close_kernel();
41078 }
41079
41080 /*
41081diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41082index 9a8ea91..c483dd9 100644
41083--- a/drivers/regulator/max8973-regulator.c
41084+++ b/drivers/regulator/max8973-regulator.c
41085@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41086 if (!pdata->enable_ext_control) {
41087 max->desc.enable_reg = MAX8973_VOUT;
41088 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41089- max8973_dcdc_ops.enable = regulator_enable_regmap;
41090- max8973_dcdc_ops.disable = regulator_disable_regmap;
41091- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41092+ pax_open_kernel();
41093+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41094+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41095+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41096+ pax_close_kernel();
41097 }
41098
41099 max->enable_external_control = pdata->enable_ext_control;
41100diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41101index 0d84b1f..c2da6ac 100644
41102--- a/drivers/regulator/mc13892-regulator.c
41103+++ b/drivers/regulator/mc13892-regulator.c
41104@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41105 }
41106 mc13xxx_unlock(mc13892);
41107
41108- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41109+ pax_open_kernel();
41110+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41111 = mc13892_vcam_set_mode;
41112- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41113+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41114 = mc13892_vcam_get_mode;
41115+ pax_close_kernel();
41116
41117 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41118 ARRAY_SIZE(mc13892_regulators));
41119diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41120index 16630aa..6afc992 100644
41121--- a/drivers/rtc/rtc-cmos.c
41122+++ b/drivers/rtc/rtc-cmos.c
41123@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41124 hpet_rtc_timer_init();
41125
41126 /* export at least the first block of NVRAM */
41127- nvram.size = address_space - NVRAM_OFFSET;
41128+ pax_open_kernel();
41129+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41130+ pax_close_kernel();
41131 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41132 if (retval < 0) {
41133 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41134diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41135index 9a86b4b..3a383dc 100644
41136--- a/drivers/rtc/rtc-dev.c
41137+++ b/drivers/rtc/rtc-dev.c
41138@@ -14,6 +14,7 @@
41139 #include <linux/module.h>
41140 #include <linux/rtc.h>
41141 #include <linux/sched.h>
41142+#include <linux/grsecurity.h>
41143 #include "rtc-core.h"
41144
41145 static dev_t rtc_devt;
41146@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
41147 if (copy_from_user(&tm, uarg, sizeof(tm)))
41148 return -EFAULT;
41149
41150+ gr_log_timechange();
41151+
41152 return rtc_set_time(rtc, &tm);
41153
41154 case RTC_PIE_ON:
41155diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41156index e0d0ba4..3c65868 100644
41157--- a/drivers/rtc/rtc-ds1307.c
41158+++ b/drivers/rtc/rtc-ds1307.c
41159@@ -106,7 +106,7 @@ struct ds1307 {
41160 u8 offset; /* register's offset */
41161 u8 regs[11];
41162 u16 nvram_offset;
41163- struct bin_attribute *nvram;
41164+ bin_attribute_no_const *nvram;
41165 enum ds_type type;
41166 unsigned long flags;
41167 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41168diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41169index 130f29a..6179d03 100644
41170--- a/drivers/rtc/rtc-m48t59.c
41171+++ b/drivers/rtc/rtc-m48t59.c
41172@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41173 goto out;
41174 }
41175
41176- m48t59_nvram_attr.size = pdata->offset;
41177+ pax_open_kernel();
41178+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41179+ pax_close_kernel();
41180
41181 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41182 if (ret) {
41183diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41184index e693af6..2e525b6 100644
41185--- a/drivers/scsi/bfa/bfa_fcpim.h
41186+++ b/drivers/scsi/bfa/bfa_fcpim.h
41187@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41188
41189 struct bfa_itn_s {
41190 bfa_isr_func_t isr;
41191-};
41192+} __no_const;
41193
41194 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41195 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41196diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41197index 23a90e7..9cf04ee 100644
41198--- a/drivers/scsi/bfa/bfa_ioc.h
41199+++ b/drivers/scsi/bfa/bfa_ioc.h
41200@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41201 bfa_ioc_disable_cbfn_t disable_cbfn;
41202 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41203 bfa_ioc_reset_cbfn_t reset_cbfn;
41204-};
41205+} __no_const;
41206
41207 /*
41208 * IOC event notification mechanism.
41209@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41210 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41211 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41212 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41213-};
41214+} __no_const;
41215
41216 /*
41217 * Queue element to wait for room in request queue. FIFO order is
41218diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41219index 593085a..47aa999 100644
41220--- a/drivers/scsi/hosts.c
41221+++ b/drivers/scsi/hosts.c
41222@@ -42,7 +42,7 @@
41223 #include "scsi_logging.h"
41224
41225
41226-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41227+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41228
41229
41230 static void scsi_host_cls_release(struct device *dev)
41231@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41232 * subtract one because we increment first then return, but we need to
41233 * know what the next host number was before increment
41234 */
41235- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41236+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41237 shost->dma_channel = 0xff;
41238
41239 /* These three are default values which can be overridden */
41240diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41241index 4f33806..afd6f60 100644
41242--- a/drivers/scsi/hpsa.c
41243+++ b/drivers/scsi/hpsa.c
41244@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41245 unsigned long flags;
41246
41247 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41248- return h->access.command_completed(h, q);
41249+ return h->access->command_completed(h, q);
41250
41251 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41252 a = rq->head[rq->current_entry];
41253@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
41254 while (!list_empty(&h->reqQ)) {
41255 c = list_entry(h->reqQ.next, struct CommandList, list);
41256 /* can't do anything if fifo is full */
41257- if ((h->access.fifo_full(h))) {
41258+ if ((h->access->fifo_full(h))) {
41259 dev_warn(&h->pdev->dev, "fifo full\n");
41260 break;
41261 }
41262@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
41263
41264 /* Tell the controller execute command */
41265 spin_unlock_irqrestore(&h->lock, flags);
41266- h->access.submit_command(h, c);
41267+ h->access->submit_command(h, c);
41268 spin_lock_irqsave(&h->lock, flags);
41269 }
41270 spin_unlock_irqrestore(&h->lock, flags);
41271@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
41272
41273 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
41274 {
41275- return h->access.command_completed(h, q);
41276+ return h->access->command_completed(h, q);
41277 }
41278
41279 static inline bool interrupt_pending(struct ctlr_info *h)
41280 {
41281- return h->access.intr_pending(h);
41282+ return h->access->intr_pending(h);
41283 }
41284
41285 static inline long interrupt_not_for_us(struct ctlr_info *h)
41286 {
41287- return (h->access.intr_pending(h) == 0) ||
41288+ return (h->access->intr_pending(h) == 0) ||
41289 (h->interrupts_enabled == 0);
41290 }
41291
41292@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
41293 if (prod_index < 0)
41294 return -ENODEV;
41295 h->product_name = products[prod_index].product_name;
41296- h->access = *(products[prod_index].access);
41297+ h->access = products[prod_index].access;
41298
41299 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
41300 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
41301@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
41302
41303 assert_spin_locked(&lockup_detector_lock);
41304 remove_ctlr_from_lockup_detector_list(h);
41305- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41306+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41307 spin_lock_irqsave(&h->lock, flags);
41308 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
41309 spin_unlock_irqrestore(&h->lock, flags);
41310@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
41311 }
41312
41313 /* make sure the board interrupts are off */
41314- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41315+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41316
41317 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
41318 goto clean2;
41319@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
41320 * fake ones to scoop up any residual completions.
41321 */
41322 spin_lock_irqsave(&h->lock, flags);
41323- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41324+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41325 spin_unlock_irqrestore(&h->lock, flags);
41326 free_irqs(h);
41327 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
41328@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
41329 dev_info(&h->pdev->dev, "Board READY.\n");
41330 dev_info(&h->pdev->dev,
41331 "Waiting for stale completions to drain.\n");
41332- h->access.set_intr_mask(h, HPSA_INTR_ON);
41333+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41334 msleep(10000);
41335- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41336+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41337
41338 rc = controller_reset_failed(h->cfgtable);
41339 if (rc)
41340@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
41341 }
41342
41343 /* Turn the interrupts on so we can service requests */
41344- h->access.set_intr_mask(h, HPSA_INTR_ON);
41345+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41346
41347 hpsa_hba_inquiry(h);
41348 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
41349@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
41350 * To write all data in the battery backed cache to disks
41351 */
41352 hpsa_flush_cache(h);
41353- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41354+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41355 hpsa_free_irqs_and_disable_msix(h);
41356 }
41357
41358@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
41359 return;
41360 }
41361 /* Change the access methods to the performant access methods */
41362- h->access = SA5_performant_access;
41363+ h->access = &SA5_performant_access;
41364 h->transMethod = CFGTBL_Trans_Performant;
41365 }
41366
41367diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
41368index 9816479..c5d4e97 100644
41369--- a/drivers/scsi/hpsa.h
41370+++ b/drivers/scsi/hpsa.h
41371@@ -79,7 +79,7 @@ struct ctlr_info {
41372 unsigned int msix_vector;
41373 unsigned int msi_vector;
41374 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
41375- struct access_method access;
41376+ struct access_method *access;
41377
41378 /* queue and queue Info */
41379 struct list_head reqQ;
41380diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
41381index c772d8d..35c362c 100644
41382--- a/drivers/scsi/libfc/fc_exch.c
41383+++ b/drivers/scsi/libfc/fc_exch.c
41384@@ -100,12 +100,12 @@ struct fc_exch_mgr {
41385 u16 pool_max_index;
41386
41387 struct {
41388- atomic_t no_free_exch;
41389- atomic_t no_free_exch_xid;
41390- atomic_t xid_not_found;
41391- atomic_t xid_busy;
41392- atomic_t seq_not_found;
41393- atomic_t non_bls_resp;
41394+ atomic_unchecked_t no_free_exch;
41395+ atomic_unchecked_t no_free_exch_xid;
41396+ atomic_unchecked_t xid_not_found;
41397+ atomic_unchecked_t xid_busy;
41398+ atomic_unchecked_t seq_not_found;
41399+ atomic_unchecked_t non_bls_resp;
41400 } stats;
41401 };
41402
41403@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
41404 /* allocate memory for exchange */
41405 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
41406 if (!ep) {
41407- atomic_inc(&mp->stats.no_free_exch);
41408+ atomic_inc_unchecked(&mp->stats.no_free_exch);
41409 goto out;
41410 }
41411 memset(ep, 0, sizeof(*ep));
41412@@ -786,7 +786,7 @@ out:
41413 return ep;
41414 err:
41415 spin_unlock_bh(&pool->lock);
41416- atomic_inc(&mp->stats.no_free_exch_xid);
41417+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
41418 mempool_free(ep, mp->ep_pool);
41419 return NULL;
41420 }
41421@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41422 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41423 ep = fc_exch_find(mp, xid);
41424 if (!ep) {
41425- atomic_inc(&mp->stats.xid_not_found);
41426+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41427 reject = FC_RJT_OX_ID;
41428 goto out;
41429 }
41430@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41431 ep = fc_exch_find(mp, xid);
41432 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41433 if (ep) {
41434- atomic_inc(&mp->stats.xid_busy);
41435+ atomic_inc_unchecked(&mp->stats.xid_busy);
41436 reject = FC_RJT_RX_ID;
41437 goto rel;
41438 }
41439@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41440 }
41441 xid = ep->xid; /* get our XID */
41442 } else if (!ep) {
41443- atomic_inc(&mp->stats.xid_not_found);
41444+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41445 reject = FC_RJT_RX_ID; /* XID not found */
41446 goto out;
41447 }
41448@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41449 } else {
41450 sp = &ep->seq;
41451 if (sp->id != fh->fh_seq_id) {
41452- atomic_inc(&mp->stats.seq_not_found);
41453+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41454 if (f_ctl & FC_FC_END_SEQ) {
41455 /*
41456 * Update sequence_id based on incoming last
41457@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41458
41459 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41460 if (!ep) {
41461- atomic_inc(&mp->stats.xid_not_found);
41462+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41463 goto out;
41464 }
41465 if (ep->esb_stat & ESB_ST_COMPLETE) {
41466- atomic_inc(&mp->stats.xid_not_found);
41467+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41468 goto rel;
41469 }
41470 if (ep->rxid == FC_XID_UNKNOWN)
41471 ep->rxid = ntohs(fh->fh_rx_id);
41472 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41473- atomic_inc(&mp->stats.xid_not_found);
41474+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41475 goto rel;
41476 }
41477 if (ep->did != ntoh24(fh->fh_s_id) &&
41478 ep->did != FC_FID_FLOGI) {
41479- atomic_inc(&mp->stats.xid_not_found);
41480+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41481 goto rel;
41482 }
41483 sof = fr_sof(fp);
41484@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41485 sp->ssb_stat |= SSB_ST_RESP;
41486 sp->id = fh->fh_seq_id;
41487 } else if (sp->id != fh->fh_seq_id) {
41488- atomic_inc(&mp->stats.seq_not_found);
41489+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41490 goto rel;
41491 }
41492
41493@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41494 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41495
41496 if (!sp)
41497- atomic_inc(&mp->stats.xid_not_found);
41498+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41499 else
41500- atomic_inc(&mp->stats.non_bls_resp);
41501+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
41502
41503 fc_frame_free(fp);
41504 }
41505@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41506
41507 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41508 mp = ema->mp;
41509- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
41510+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
41511 st->fc_no_free_exch_xid +=
41512- atomic_read(&mp->stats.no_free_exch_xid);
41513- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
41514- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
41515- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
41516- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
41517+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
41518+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
41519+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
41520+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
41521+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
41522 }
41523 }
41524 EXPORT_SYMBOL(fc_exch_update_stats);
41525diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
41526index bdb81cd..d3c7c2c 100644
41527--- a/drivers/scsi/libsas/sas_ata.c
41528+++ b/drivers/scsi/libsas/sas_ata.c
41529@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
41530 .postreset = ata_std_postreset,
41531 .error_handler = ata_std_error_handler,
41532 .post_internal_cmd = sas_ata_post_internal,
41533- .qc_defer = ata_std_qc_defer,
41534+ .qc_defer = ata_std_qc_defer,
41535 .qc_prep = ata_noop_qc_prep,
41536 .qc_issue = sas_ata_qc_issue,
41537 .qc_fill_rtf = sas_ata_qc_fill_rtf,
41538diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
41539index df4c13a..a51e90c 100644
41540--- a/drivers/scsi/lpfc/lpfc.h
41541+++ b/drivers/scsi/lpfc/lpfc.h
41542@@ -424,7 +424,7 @@ struct lpfc_vport {
41543 struct dentry *debug_nodelist;
41544 struct dentry *vport_debugfs_root;
41545 struct lpfc_debugfs_trc *disc_trc;
41546- atomic_t disc_trc_cnt;
41547+ atomic_unchecked_t disc_trc_cnt;
41548 #endif
41549 uint8_t stat_data_enabled;
41550 uint8_t stat_data_blocked;
41551@@ -842,8 +842,8 @@ struct lpfc_hba {
41552 struct timer_list fabric_block_timer;
41553 unsigned long bit_flags;
41554 #define FABRIC_COMANDS_BLOCKED 0
41555- atomic_t num_rsrc_err;
41556- atomic_t num_cmd_success;
41557+ atomic_unchecked_t num_rsrc_err;
41558+ atomic_unchecked_t num_cmd_success;
41559 unsigned long last_rsrc_error_time;
41560 unsigned long last_ramp_down_time;
41561 unsigned long last_ramp_up_time;
41562@@ -879,7 +879,7 @@ struct lpfc_hba {
41563
41564 struct dentry *debug_slow_ring_trc;
41565 struct lpfc_debugfs_trc *slow_ring_trc;
41566- atomic_t slow_ring_trc_cnt;
41567+ atomic_unchecked_t slow_ring_trc_cnt;
41568 /* iDiag debugfs sub-directory */
41569 struct dentry *idiag_root;
41570 struct dentry *idiag_pci_cfg;
41571diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41572index f63f5ff..de29189 100644
41573--- a/drivers/scsi/lpfc/lpfc_debugfs.c
41574+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41575@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41576
41577 #include <linux/debugfs.h>
41578
41579-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41580+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41581 static unsigned long lpfc_debugfs_start_time = 0L;
41582
41583 /* iDiag */
41584@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41585 lpfc_debugfs_enable = 0;
41586
41587 len = 0;
41588- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41589+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41590 (lpfc_debugfs_max_disc_trc - 1);
41591 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41592 dtp = vport->disc_trc + i;
41593@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41594 lpfc_debugfs_enable = 0;
41595
41596 len = 0;
41597- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41598+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41599 (lpfc_debugfs_max_slow_ring_trc - 1);
41600 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41601 dtp = phba->slow_ring_trc + i;
41602@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41603 !vport || !vport->disc_trc)
41604 return;
41605
41606- index = atomic_inc_return(&vport->disc_trc_cnt) &
41607+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41608 (lpfc_debugfs_max_disc_trc - 1);
41609 dtp = vport->disc_trc + index;
41610 dtp->fmt = fmt;
41611 dtp->data1 = data1;
41612 dtp->data2 = data2;
41613 dtp->data3 = data3;
41614- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41615+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41616 dtp->jif = jiffies;
41617 #endif
41618 return;
41619@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41620 !phba || !phba->slow_ring_trc)
41621 return;
41622
41623- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41624+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41625 (lpfc_debugfs_max_slow_ring_trc - 1);
41626 dtp = phba->slow_ring_trc + index;
41627 dtp->fmt = fmt;
41628 dtp->data1 = data1;
41629 dtp->data2 = data2;
41630 dtp->data3 = data3;
41631- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41632+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41633 dtp->jif = jiffies;
41634 #endif
41635 return;
41636@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41637 "slow_ring buffer\n");
41638 goto debug_failed;
41639 }
41640- atomic_set(&phba->slow_ring_trc_cnt, 0);
41641+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41642 memset(phba->slow_ring_trc, 0,
41643 (sizeof(struct lpfc_debugfs_trc) *
41644 lpfc_debugfs_max_slow_ring_trc));
41645@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41646 "buffer\n");
41647 goto debug_failed;
41648 }
41649- atomic_set(&vport->disc_trc_cnt, 0);
41650+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41651
41652 snprintf(name, sizeof(name), "discovery_trace");
41653 vport->debug_disc_trc =
41654diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41655index 89ad558..76956c4 100644
41656--- a/drivers/scsi/lpfc/lpfc_init.c
41657+++ b/drivers/scsi/lpfc/lpfc_init.c
41658@@ -10618,8 +10618,10 @@ lpfc_init(void)
41659 "misc_register returned with status %d", error);
41660
41661 if (lpfc_enable_npiv) {
41662- lpfc_transport_functions.vport_create = lpfc_vport_create;
41663- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41664+ pax_open_kernel();
41665+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41666+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41667+ pax_close_kernel();
41668 }
41669 lpfc_transport_template =
41670 fc_attach_transport(&lpfc_transport_functions);
41671diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41672index 60e5a17..ff7a793 100644
41673--- a/drivers/scsi/lpfc/lpfc_scsi.c
41674+++ b/drivers/scsi/lpfc/lpfc_scsi.c
41675@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41676 uint32_t evt_posted;
41677
41678 spin_lock_irqsave(&phba->hbalock, flags);
41679- atomic_inc(&phba->num_rsrc_err);
41680+ atomic_inc_unchecked(&phba->num_rsrc_err);
41681 phba->last_rsrc_error_time = jiffies;
41682
41683 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41684@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41685 unsigned long flags;
41686 struct lpfc_hba *phba = vport->phba;
41687 uint32_t evt_posted;
41688- atomic_inc(&phba->num_cmd_success);
41689+ atomic_inc_unchecked(&phba->num_cmd_success);
41690
41691 if (vport->cfg_lun_queue_depth <= queue_depth)
41692 return;
41693@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41694 unsigned long num_rsrc_err, num_cmd_success;
41695 int i;
41696
41697- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41698- num_cmd_success = atomic_read(&phba->num_cmd_success);
41699+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41700+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41701
41702 /*
41703 * The error and success command counters are global per
41704@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41705 }
41706 }
41707 lpfc_destroy_vport_work_array(phba, vports);
41708- atomic_set(&phba->num_rsrc_err, 0);
41709- atomic_set(&phba->num_cmd_success, 0);
41710+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41711+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41712 }
41713
41714 /**
41715@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41716 }
41717 }
41718 lpfc_destroy_vport_work_array(phba, vports);
41719- atomic_set(&phba->num_rsrc_err, 0);
41720- atomic_set(&phba->num_cmd_success, 0);
41721+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41722+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41723 }
41724
41725 /**
41726diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41727index b46f5e9..c4c4ccb 100644
41728--- a/drivers/scsi/pmcraid.c
41729+++ b/drivers/scsi/pmcraid.c
41730@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41731 res->scsi_dev = scsi_dev;
41732 scsi_dev->hostdata = res;
41733 res->change_detected = 0;
41734- atomic_set(&res->read_failures, 0);
41735- atomic_set(&res->write_failures, 0);
41736+ atomic_set_unchecked(&res->read_failures, 0);
41737+ atomic_set_unchecked(&res->write_failures, 0);
41738 rc = 0;
41739 }
41740 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41741@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41742
41743 /* If this was a SCSI read/write command keep count of errors */
41744 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41745- atomic_inc(&res->read_failures);
41746+ atomic_inc_unchecked(&res->read_failures);
41747 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41748- atomic_inc(&res->write_failures);
41749+ atomic_inc_unchecked(&res->write_failures);
41750
41751 if (!RES_IS_GSCSI(res->cfg_entry) &&
41752 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41753@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41754 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41755 * hrrq_id assigned here in queuecommand
41756 */
41757- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41758+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41759 pinstance->num_hrrq;
41760 cmd->cmd_done = pmcraid_io_done;
41761
41762@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
41763 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41764 * hrrq_id assigned here in queuecommand
41765 */
41766- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41767+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41768 pinstance->num_hrrq;
41769
41770 if (request_size) {
41771@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41772
41773 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41774 /* add resources only after host is added into system */
41775- if (!atomic_read(&pinstance->expose_resources))
41776+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41777 return;
41778
41779 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41780@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41781 init_waitqueue_head(&pinstance->reset_wait_q);
41782
41783 atomic_set(&pinstance->outstanding_cmds, 0);
41784- atomic_set(&pinstance->last_message_id, 0);
41785- atomic_set(&pinstance->expose_resources, 0);
41786+ atomic_set_unchecked(&pinstance->last_message_id, 0);
41787+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41788
41789 INIT_LIST_HEAD(&pinstance->free_res_q);
41790 INIT_LIST_HEAD(&pinstance->used_res_q);
41791@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41792 /* Schedule worker thread to handle CCN and take care of adding and
41793 * removing devices to OS
41794 */
41795- atomic_set(&pinstance->expose_resources, 1);
41796+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41797 schedule_work(&pinstance->worker_q);
41798 return rc;
41799
41800diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41801index e1d150f..6c6df44 100644
41802--- a/drivers/scsi/pmcraid.h
41803+++ b/drivers/scsi/pmcraid.h
41804@@ -748,7 +748,7 @@ struct pmcraid_instance {
41805 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41806
41807 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41808- atomic_t last_message_id;
41809+ atomic_unchecked_t last_message_id;
41810
41811 /* configuration table */
41812 struct pmcraid_config_table *cfg_table;
41813@@ -777,7 +777,7 @@ struct pmcraid_instance {
41814 atomic_t outstanding_cmds;
41815
41816 /* should add/delete resources to mid-layer now ?*/
41817- atomic_t expose_resources;
41818+ atomic_unchecked_t expose_resources;
41819
41820
41821
41822@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41823 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41824 };
41825 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41826- atomic_t read_failures; /* count of failed READ commands */
41827- atomic_t write_failures; /* count of failed WRITE commands */
41828+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41829+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41830
41831 /* To indicate add/delete/modify during CCN */
41832 u8 change_detected;
41833diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41834index 83d7984..a27d947 100644
41835--- a/drivers/scsi/qla2xxx/qla_attr.c
41836+++ b/drivers/scsi/qla2xxx/qla_attr.c
41837@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41838 return 0;
41839 }
41840
41841-struct fc_function_template qla2xxx_transport_functions = {
41842+fc_function_template_no_const qla2xxx_transport_functions = {
41843
41844 .show_host_node_name = 1,
41845 .show_host_port_name = 1,
41846@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41847 .bsg_timeout = qla24xx_bsg_timeout,
41848 };
41849
41850-struct fc_function_template qla2xxx_transport_vport_functions = {
41851+fc_function_template_no_const qla2xxx_transport_vport_functions = {
41852
41853 .show_host_node_name = 1,
41854 .show_host_port_name = 1,
41855diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41856index 2411d1a..4673766 100644
41857--- a/drivers/scsi/qla2xxx/qla_gbl.h
41858+++ b/drivers/scsi/qla2xxx/qla_gbl.h
41859@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41860 struct device_attribute;
41861 extern struct device_attribute *qla2x00_host_attrs[];
41862 struct fc_function_template;
41863-extern struct fc_function_template qla2xxx_transport_functions;
41864-extern struct fc_function_template qla2xxx_transport_vport_functions;
41865+extern fc_function_template_no_const qla2xxx_transport_functions;
41866+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41867 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41868 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41869 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41870diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41871index 10d23f8..a7d5d4c 100644
41872--- a/drivers/scsi/qla2xxx/qla_os.c
41873+++ b/drivers/scsi/qla2xxx/qla_os.c
41874@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41875 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41876 /* Ok, a 64bit DMA mask is applicable. */
41877 ha->flags.enable_64bit_addressing = 1;
41878- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41879- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41880+ pax_open_kernel();
41881+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41882+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41883+ pax_close_kernel();
41884 return;
41885 }
41886 }
41887diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41888index 329d553..f20d31d 100644
41889--- a/drivers/scsi/qla4xxx/ql4_def.h
41890+++ b/drivers/scsi/qla4xxx/ql4_def.h
41891@@ -273,7 +273,7 @@ struct ddb_entry {
41892 * (4000 only) */
41893 atomic_t relogin_timer; /* Max Time to wait for
41894 * relogin to complete */
41895- atomic_t relogin_retry_count; /* Num of times relogin has been
41896+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41897 * retried */
41898 uint32_t default_time2wait; /* Default Min time between
41899 * relogins (+aens) */
41900diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41901index 4cec123..7c1329f 100644
41902--- a/drivers/scsi/qla4xxx/ql4_os.c
41903+++ b/drivers/scsi/qla4xxx/ql4_os.c
41904@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41905 */
41906 if (!iscsi_is_session_online(cls_sess)) {
41907 /* Reset retry relogin timer */
41908- atomic_inc(&ddb_entry->relogin_retry_count);
41909+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41910 DEBUG2(ql4_printk(KERN_INFO, ha,
41911 "%s: index[%d] relogin timed out-retrying"
41912 " relogin (%d), retry (%d)\n", __func__,
41913 ddb_entry->fw_ddb_index,
41914- atomic_read(&ddb_entry->relogin_retry_count),
41915+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41916 ddb_entry->default_time2wait + 4));
41917 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41918 atomic_set(&ddb_entry->retry_relogin_timer,
41919@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41920
41921 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41922 atomic_set(&ddb_entry->relogin_timer, 0);
41923- atomic_set(&ddb_entry->relogin_retry_count, 0);
41924+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41925 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41926 ddb_entry->default_relogin_timeout =
41927 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41928diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41929index 2c0d0ec..4e8681a 100644
41930--- a/drivers/scsi/scsi.c
41931+++ b/drivers/scsi/scsi.c
41932@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41933 unsigned long timeout;
41934 int rtn = 0;
41935
41936- atomic_inc(&cmd->device->iorequest_cnt);
41937+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41938
41939 /* check if the device is still usable */
41940 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41941diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41942index f1bf5af..f67e943 100644
41943--- a/drivers/scsi/scsi_lib.c
41944+++ b/drivers/scsi/scsi_lib.c
41945@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41946 shost = sdev->host;
41947 scsi_init_cmd_errh(cmd);
41948 cmd->result = DID_NO_CONNECT << 16;
41949- atomic_inc(&cmd->device->iorequest_cnt);
41950+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41951
41952 /*
41953 * SCSI request completion path will do scsi_device_unbusy(),
41954@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41955
41956 INIT_LIST_HEAD(&cmd->eh_entry);
41957
41958- atomic_inc(&cmd->device->iodone_cnt);
41959+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41960 if (cmd->result)
41961- atomic_inc(&cmd->device->ioerr_cnt);
41962+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41963
41964 disposition = scsi_decide_disposition(cmd);
41965 if (disposition != SUCCESS &&
41966diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41967index 931a7d9..0c2a754 100644
41968--- a/drivers/scsi/scsi_sysfs.c
41969+++ b/drivers/scsi/scsi_sysfs.c
41970@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41971 char *buf) \
41972 { \
41973 struct scsi_device *sdev = to_scsi_device(dev); \
41974- unsigned long long count = atomic_read(&sdev->field); \
41975+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41976 return snprintf(buf, 20, "0x%llx\n", count); \
41977 } \
41978 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41979diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41980index 84a1fdf..693b0d6 100644
41981--- a/drivers/scsi/scsi_tgt_lib.c
41982+++ b/drivers/scsi/scsi_tgt_lib.c
41983@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41984 int err;
41985
41986 dprintk("%lx %u\n", uaddr, len);
41987- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41988+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41989 if (err) {
41990 /*
41991 * TODO: need to fixup sg_tablesize, max_segment_size,
41992diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41993index e894ca7..de9d7660 100644
41994--- a/drivers/scsi/scsi_transport_fc.c
41995+++ b/drivers/scsi/scsi_transport_fc.c
41996@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
41997 * Netlink Infrastructure
41998 */
41999
42000-static atomic_t fc_event_seq;
42001+static atomic_unchecked_t fc_event_seq;
42002
42003 /**
42004 * fc_get_event_number - Obtain the next sequential FC event number
42005@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42006 u32
42007 fc_get_event_number(void)
42008 {
42009- return atomic_add_return(1, &fc_event_seq);
42010+ return atomic_add_return_unchecked(1, &fc_event_seq);
42011 }
42012 EXPORT_SYMBOL(fc_get_event_number);
42013
42014@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42015 {
42016 int error;
42017
42018- atomic_set(&fc_event_seq, 0);
42019+ atomic_set_unchecked(&fc_event_seq, 0);
42020
42021 error = transport_class_register(&fc_host_class);
42022 if (error)
42023@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42024 char *cp;
42025
42026 *val = simple_strtoul(buf, &cp, 0);
42027- if ((*cp && (*cp != '\n')) || (*val < 0))
42028+ if (*cp && (*cp != '\n'))
42029 return -EINVAL;
42030 /*
42031 * Check for overflow; dev_loss_tmo is u32
42032diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42033index 31969f2..2b348f0 100644
42034--- a/drivers/scsi/scsi_transport_iscsi.c
42035+++ b/drivers/scsi/scsi_transport_iscsi.c
42036@@ -79,7 +79,7 @@ struct iscsi_internal {
42037 struct transport_container session_cont;
42038 };
42039
42040-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42041+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42042 static struct workqueue_struct *iscsi_eh_timer_workq;
42043
42044 static DEFINE_IDA(iscsi_sess_ida);
42045@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42046 int err;
42047
42048 ihost = shost->shost_data;
42049- session->sid = atomic_add_return(1, &iscsi_session_nr);
42050+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42051
42052 if (target_id == ISCSI_MAX_TARGET) {
42053 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42054@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
42055 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42056 ISCSI_TRANSPORT_VERSION);
42057
42058- atomic_set(&iscsi_session_nr, 0);
42059+ atomic_set_unchecked(&iscsi_session_nr, 0);
42060
42061 err = class_register(&iscsi_transport_class);
42062 if (err)
42063diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42064index f379c7f..e8fc69c 100644
42065--- a/drivers/scsi/scsi_transport_srp.c
42066+++ b/drivers/scsi/scsi_transport_srp.c
42067@@ -33,7 +33,7 @@
42068 #include "scsi_transport_srp_internal.h"
42069
42070 struct srp_host_attrs {
42071- atomic_t next_port_id;
42072+ atomic_unchecked_t next_port_id;
42073 };
42074 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42075
42076@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42077 struct Scsi_Host *shost = dev_to_shost(dev);
42078 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42079
42080- atomic_set(&srp_host->next_port_id, 0);
42081+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42082 return 0;
42083 }
42084
42085@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42086 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42087 rport->roles = ids->roles;
42088
42089- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42090+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42091 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42092
42093 transport_setup_device(&rport->dev);
42094diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42095index 7992635..609faf8 100644
42096--- a/drivers/scsi/sd.c
42097+++ b/drivers/scsi/sd.c
42098@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
42099 sdkp->disk = gd;
42100 sdkp->index = index;
42101 atomic_set(&sdkp->openers, 0);
42102- atomic_set(&sdkp->device->ioerr_cnt, 0);
42103+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42104
42105 if (!sdp->request_queue->rq_timeout) {
42106 if (sdp->type != TYPE_MOD)
42107diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42108index be2c9a6..275525c 100644
42109--- a/drivers/scsi/sg.c
42110+++ b/drivers/scsi/sg.c
42111@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42112 sdp->disk->disk_name,
42113 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42114 NULL,
42115- (char *)arg);
42116+ (char __user *)arg);
42117 case BLKTRACESTART:
42118 return blk_trace_startstop(sdp->device->request_queue, 1);
42119 case BLKTRACESTOP:
42120diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42121index 19ee901..6e8c2ef 100644
42122--- a/drivers/spi/spi.c
42123+++ b/drivers/spi/spi.c
42124@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
42125 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42126
42127 /* portable code must never pass more than 32 bytes */
42128-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42129+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42130
42131 static u8 *buf;
42132
42133diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42134index c7a5f97..71ecd35 100644
42135--- a/drivers/staging/iio/iio_hwmon.c
42136+++ b/drivers/staging/iio/iio_hwmon.c
42137@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
42138 static int iio_hwmon_probe(struct platform_device *pdev)
42139 {
42140 struct iio_hwmon_state *st;
42141- struct sensor_device_attribute *a;
42142+ sensor_device_attribute_no_const *a;
42143 int ret, i;
42144 int in_i = 1, temp_i = 1, curr_i = 1;
42145 enum iio_chan_type type;
42146diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42147index 34afc16..ffe44dd 100644
42148--- a/drivers/staging/octeon/ethernet-rx.c
42149+++ b/drivers/staging/octeon/ethernet-rx.c
42150@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42151 /* Increment RX stats for virtual ports */
42152 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42153 #ifdef CONFIG_64BIT
42154- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42155- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42156+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42157+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42158 #else
42159- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42160- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42161+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42162+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42163 #endif
42164 }
42165 netif_receive_skb(skb);
42166@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42167 dev->name);
42168 */
42169 #ifdef CONFIG_64BIT
42170- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42171+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42172 #else
42173- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42174+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42175 #endif
42176 dev_kfree_skb_irq(skb);
42177 }
42178diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42179index ef32dc1..a159d68 100644
42180--- a/drivers/staging/octeon/ethernet.c
42181+++ b/drivers/staging/octeon/ethernet.c
42182@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42183 * since the RX tasklet also increments it.
42184 */
42185 #ifdef CONFIG_64BIT
42186- atomic64_add(rx_status.dropped_packets,
42187- (atomic64_t *)&priv->stats.rx_dropped);
42188+ atomic64_add_unchecked(rx_status.dropped_packets,
42189+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42190 #else
42191- atomic_add(rx_status.dropped_packets,
42192- (atomic_t *)&priv->stats.rx_dropped);
42193+ atomic_add_unchecked(rx_status.dropped_packets,
42194+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42195 #endif
42196 }
42197
42198diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42199index a2b7e03..aaf3630 100644
42200--- a/drivers/staging/ramster/tmem.c
42201+++ b/drivers/staging/ramster/tmem.c
42202@@ -50,25 +50,25 @@
42203 * A tmem host implementation must use this function to register callbacks
42204 * for memory allocation.
42205 */
42206-static struct tmem_hostops tmem_hostops;
42207+static struct tmem_hostops *tmem_hostops;
42208
42209 static void tmem_objnode_tree_init(void);
42210
42211 void tmem_register_hostops(struct tmem_hostops *m)
42212 {
42213 tmem_objnode_tree_init();
42214- tmem_hostops = *m;
42215+ tmem_hostops = m;
42216 }
42217
42218 /*
42219 * A tmem host implementation must use this function to register
42220 * callbacks for a page-accessible memory (PAM) implementation.
42221 */
42222-static struct tmem_pamops tmem_pamops;
42223+static struct tmem_pamops *tmem_pamops;
42224
42225 void tmem_register_pamops(struct tmem_pamops *m)
42226 {
42227- tmem_pamops = *m;
42228+ tmem_pamops = m;
42229 }
42230
42231 /*
42232@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42233 obj->pampd_count = 0;
42234 #ifdef CONFIG_RAMSTER
42235 if (tmem_pamops.new_obj != NULL)
42236- (*tmem_pamops.new_obj)(obj);
42237+ (tmem_pamops->new_obj)(obj);
42238 #endif
42239 SET_SENTINEL(obj, OBJ);
42240
42241@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42242 rbnode = rb_next(rbnode);
42243 tmem_pampd_destroy_all_in_obj(obj, true);
42244 tmem_obj_free(obj, hb);
42245- (*tmem_hostops.obj_free)(obj, pool);
42246+ (tmem_hostops->obj_free)(obj, pool);
42247 }
42248 spin_unlock(&hb->lock);
42249 }
42250@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
42251 ASSERT_SENTINEL(obj, OBJ);
42252 BUG_ON(obj->pool == NULL);
42253 ASSERT_SENTINEL(obj->pool, POOL);
42254- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
42255+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
42256 if (unlikely(objnode == NULL))
42257 goto out;
42258 objnode->obj = obj;
42259@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
42260 ASSERT_SENTINEL(pool, POOL);
42261 objnode->obj->objnode_count--;
42262 objnode->obj = NULL;
42263- (*tmem_hostops.objnode_free)(objnode, pool);
42264+ (tmem_hostops->objnode_free)(objnode, pool);
42265 }
42266
42267 /*
42268@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
42269 void *old_pampd = *(void **)slot;
42270 *(void **)slot = new_pampd;
42271 if (!no_free)
42272- (*tmem_pamops.free)(old_pampd, obj->pool,
42273+ (tmem_pamops->free)(old_pampd, obj->pool,
42274 NULL, 0, false);
42275 ret = new_pampd;
42276 }
42277@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
42278 if (objnode->slots[i]) {
42279 if (ht == 1) {
42280 obj->pampd_count--;
42281- (*tmem_pamops.free)(objnode->slots[i],
42282+ (tmem_pamops->free)(objnode->slots[i],
42283 obj->pool, NULL, 0, true);
42284 objnode->slots[i] = NULL;
42285 continue;
42286@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42287 return;
42288 if (obj->objnode_tree_height == 0) {
42289 obj->pampd_count--;
42290- (*tmem_pamops.free)(obj->objnode_tree_root,
42291+ (tmem_pamops->free)(obj->objnode_tree_root,
42292 obj->pool, NULL, 0, true);
42293 } else {
42294 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
42295@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42296 obj->objnode_tree_root = NULL;
42297 #ifdef CONFIG_RAMSTER
42298 if (tmem_pamops.free_obj != NULL)
42299- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
42300+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
42301 #endif
42302 }
42303
42304@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42305 /* if found, is a dup put, flush the old one */
42306 pampd_del = tmem_pampd_delete_from_obj(obj, index);
42307 BUG_ON(pampd_del != pampd);
42308- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42309+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42310 if (obj->pampd_count == 0) {
42311 objnew = obj;
42312 objfound = NULL;
42313@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42314 pampd = NULL;
42315 }
42316 } else {
42317- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
42318+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
42319 if (unlikely(obj == NULL)) {
42320 ret = -ENOMEM;
42321 goto out;
42322@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42323 if (unlikely(ret == -ENOMEM))
42324 /* may have partially built objnode tree ("stump") */
42325 goto delete_and_free;
42326- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
42327+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
42328 goto out;
42329
42330 delete_and_free:
42331 (void)tmem_pampd_delete_from_obj(obj, index);
42332 if (pampd)
42333- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
42334+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
42335 if (objnew) {
42336 tmem_obj_free(objnew, hb);
42337- (*tmem_hostops.obj_free)(objnew, pool);
42338+ (tmem_hostops->obj_free)(objnew, pool);
42339 }
42340 out:
42341 spin_unlock(&hb->lock);
42342@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
42343 if (pampd != NULL) {
42344 BUG_ON(obj == NULL);
42345 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
42346- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
42347+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
42348 } else if (delete) {
42349 BUG_ON(obj == NULL);
42350 (void)tmem_pampd_delete_from_obj(obj, index);
42351@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42352 int ret = 0;
42353
42354 if (!is_ephemeral(pool))
42355- new_pampd = (*tmem_pamops.repatriate_preload)(
42356+ new_pampd = (tmem_pamops->repatriate_preload)(
42357 old_pampd, pool, oidp, index, &intransit);
42358 if (intransit)
42359 ret = -EAGAIN;
42360@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42361 /* must release the hb->lock else repatriate can't sleep */
42362 spin_unlock(&hb->lock);
42363 if (!intransit)
42364- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
42365+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
42366 oidp, index, free, data);
42367 if (ret == -EAGAIN) {
42368 /* rare I think, but should cond_resched()??? */
42369@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
42370 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
42371 /* if we bug here, pamops wasn't properly set up for ramster */
42372 BUG_ON(tmem_pamops.replace_in_obj == NULL);
42373- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
42374+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
42375 out:
42376 spin_unlock(&hb->lock);
42377 return ret;
42378@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42379 if (free) {
42380 if (obj->pampd_count == 0) {
42381 tmem_obj_free(obj, hb);
42382- (*tmem_hostops.obj_free)(obj, pool);
42383+ (tmem_hostops->obj_free)(obj, pool);
42384 obj = NULL;
42385 }
42386 }
42387 if (free)
42388- ret = (*tmem_pamops.get_data_and_free)(
42389+ ret = (tmem_pamops->get_data_and_free)(
42390 data, sizep, raw, pampd, pool, oidp, index);
42391 else
42392- ret = (*tmem_pamops.get_data)(
42393+ ret = (tmem_pamops->get_data)(
42394 data, sizep, raw, pampd, pool, oidp, index);
42395 if (ret < 0)
42396 goto out;
42397@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
42398 pampd = tmem_pampd_delete_from_obj(obj, index);
42399 if (pampd == NULL)
42400 goto out;
42401- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42402+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42403 if (obj->pampd_count == 0) {
42404 tmem_obj_free(obj, hb);
42405- (*tmem_hostops.obj_free)(obj, pool);
42406+ (tmem_hostops->obj_free)(obj, pool);
42407 }
42408 ret = 0;
42409
42410@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
42411 goto out;
42412 tmem_pampd_destroy_all_in_obj(obj, false);
42413 tmem_obj_free(obj, hb);
42414- (*tmem_hostops.obj_free)(obj, pool);
42415+ (tmem_hostops->obj_free)(obj, pool);
42416 ret = 0;
42417
42418 out:
42419diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
42420index dc23395..cf7e9b1 100644
42421--- a/drivers/staging/rtl8712/rtl871x_io.h
42422+++ b/drivers/staging/rtl8712/rtl871x_io.h
42423@@ -108,7 +108,7 @@ struct _io_ops {
42424 u8 *pmem);
42425 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42426 u8 *pmem);
42427-};
42428+} __no_const;
42429
42430 struct io_req {
42431 struct list_head list;
42432diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42433index 1f5088b..0e59820 100644
42434--- a/drivers/staging/sbe-2t3e3/netdev.c
42435+++ b/drivers/staging/sbe-2t3e3/netdev.c
42436@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42437 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42438
42439 if (rlen)
42440- if (copy_to_user(data, &resp, rlen))
42441+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42442 return -EFAULT;
42443
42444 return 0;
42445diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42446index 5dddc4d..34fcb2f 100644
42447--- a/drivers/staging/usbip/vhci.h
42448+++ b/drivers/staging/usbip/vhci.h
42449@@ -83,7 +83,7 @@ struct vhci_hcd {
42450 unsigned resuming:1;
42451 unsigned long re_timeout;
42452
42453- atomic_t seqnum;
42454+ atomic_unchecked_t seqnum;
42455
42456 /*
42457 * NOTE:
42458diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42459index c3aa219..bf8b3de 100644
42460--- a/drivers/staging/usbip/vhci_hcd.c
42461+++ b/drivers/staging/usbip/vhci_hcd.c
42462@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
42463 return;
42464 }
42465
42466- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42467+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42468 if (priv->seqnum == 0xffff)
42469 dev_info(&urb->dev->dev, "seqnum max\n");
42470
42471@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42472 return -ENOMEM;
42473 }
42474
42475- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42476+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42477 if (unlink->seqnum == 0xffff)
42478 pr_info("seqnum max\n");
42479
42480@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
42481 vdev->rhport = rhport;
42482 }
42483
42484- atomic_set(&vhci->seqnum, 0);
42485+ atomic_set_unchecked(&vhci->seqnum, 0);
42486 spin_lock_init(&vhci->lock);
42487
42488 hcd->power_budget = 0; /* no limit */
42489diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42490index ba5f1c0..11d8122 100644
42491--- a/drivers/staging/usbip/vhci_rx.c
42492+++ b/drivers/staging/usbip/vhci_rx.c
42493@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42494 if (!urb) {
42495 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42496 pr_info("max seqnum %d\n",
42497- atomic_read(&the_controller->seqnum));
42498+ atomic_read_unchecked(&the_controller->seqnum));
42499 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42500 return;
42501 }
42502diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42503index 5f13890..36a044b 100644
42504--- a/drivers/staging/vt6655/hostap.c
42505+++ b/drivers/staging/vt6655/hostap.c
42506@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42507 *
42508 */
42509
42510+static net_device_ops_no_const apdev_netdev_ops;
42511+
42512 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42513 {
42514 PSDevice apdev_priv;
42515 struct net_device *dev = pDevice->dev;
42516 int ret;
42517- const struct net_device_ops apdev_netdev_ops = {
42518- .ndo_start_xmit = pDevice->tx_80211,
42519- };
42520
42521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42522
42523@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42524 *apdev_priv = *pDevice;
42525 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42526
42527+ /* only half broken now */
42528+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42529 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42530
42531 pDevice->apdev->type = ARPHRD_IEEE80211;
42532diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42533index 26a7d0e..897b083 100644
42534--- a/drivers/staging/vt6656/hostap.c
42535+++ b/drivers/staging/vt6656/hostap.c
42536@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42537 *
42538 */
42539
42540+static net_device_ops_no_const apdev_netdev_ops;
42541+
42542 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42543 {
42544 PSDevice apdev_priv;
42545 struct net_device *dev = pDevice->dev;
42546 int ret;
42547- const struct net_device_ops apdev_netdev_ops = {
42548- .ndo_start_xmit = pDevice->tx_80211,
42549- };
42550
42551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42552
42553@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42554 *apdev_priv = *pDevice;
42555 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42556
42557+ /* only half broken now */
42558+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42559 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42560
42561 pDevice->apdev->type = ARPHRD_IEEE80211;
42562diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42563index 56c8e60..1920c63 100644
42564--- a/drivers/staging/zcache/tmem.c
42565+++ b/drivers/staging/zcache/tmem.c
42566@@ -39,7 +39,7 @@
42567 * A tmem host implementation must use this function to register callbacks
42568 * for memory allocation.
42569 */
42570-static struct tmem_hostops tmem_hostops;
42571+static tmem_hostops_no_const tmem_hostops;
42572
42573 static void tmem_objnode_tree_init(void);
42574
42575@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42576 * A tmem host implementation must use this function to register
42577 * callbacks for a page-accessible memory (PAM) implementation
42578 */
42579-static struct tmem_pamops tmem_pamops;
42580+static tmem_pamops_no_const tmem_pamops;
42581
42582 void tmem_register_pamops(struct tmem_pamops *m)
42583 {
42584diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42585index 0d4aa82..f7832d4 100644
42586--- a/drivers/staging/zcache/tmem.h
42587+++ b/drivers/staging/zcache/tmem.h
42588@@ -180,6 +180,7 @@ struct tmem_pamops {
42589 void (*new_obj)(struct tmem_obj *);
42590 int (*replace_in_obj)(void *, struct tmem_obj *);
42591 };
42592+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42593 extern void tmem_register_pamops(struct tmem_pamops *m);
42594
42595 /* memory allocation methods provided by the host implementation */
42596@@ -189,6 +190,7 @@ struct tmem_hostops {
42597 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42598 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42599 };
42600+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42601 extern void tmem_register_hostops(struct tmem_hostops *m);
42602
42603 /* core tmem accessor functions */
42604diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42605index 96f4981..4daaa7e 100644
42606--- a/drivers/target/target_core_device.c
42607+++ b/drivers/target/target_core_device.c
42608@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42609 spin_lock_init(&dev->se_port_lock);
42610 spin_lock_init(&dev->se_tmr_lock);
42611 spin_lock_init(&dev->qf_cmd_lock);
42612- atomic_set(&dev->dev_ordered_id, 0);
42613+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
42614 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42615 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42616 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42617diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42618index bd587b7..173daf3 100644
42619--- a/drivers/target/target_core_transport.c
42620+++ b/drivers/target/target_core_transport.c
42621@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42622 * Used to determine when ORDERED commands should go from
42623 * Dormant to Active status.
42624 */
42625- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42626+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42627 smp_mb__after_atomic_inc();
42628 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42629 cmd->se_ordered_id, cmd->sam_task_attr,
42630diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42631index b09c8d1f..c4225c0 100644
42632--- a/drivers/tty/cyclades.c
42633+++ b/drivers/tty/cyclades.c
42634@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42635 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42636 info->port.count);
42637 #endif
42638- info->port.count++;
42639+ atomic_inc(&info->port.count);
42640 #ifdef CY_DEBUG_COUNT
42641 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42642- current->pid, info->port.count);
42643+ current->pid, atomic_read(&info->port.count));
42644 #endif
42645
42646 /*
42647@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42648 for (j = 0; j < cy_card[i].nports; j++) {
42649 info = &cy_card[i].ports[j];
42650
42651- if (info->port.count) {
42652+ if (atomic_read(&info->port.count)) {
42653 /* XXX is the ldisc num worth this? */
42654 struct tty_struct *tty;
42655 struct tty_ldisc *ld;
42656diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42657index 13ee53b..418d164 100644
42658--- a/drivers/tty/hvc/hvc_console.c
42659+++ b/drivers/tty/hvc/hvc_console.c
42660@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42661
42662 spin_lock_irqsave(&hp->port.lock, flags);
42663 /* Check and then increment for fast path open. */
42664- if (hp->port.count++ > 0) {
42665+ if (atomic_inc_return(&hp->port.count) > 1) {
42666 spin_unlock_irqrestore(&hp->port.lock, flags);
42667 hvc_kick();
42668 return 0;
42669@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42670
42671 spin_lock_irqsave(&hp->port.lock, flags);
42672
42673- if (--hp->port.count == 0) {
42674+ if (atomic_dec_return(&hp->port.count) == 0) {
42675 spin_unlock_irqrestore(&hp->port.lock, flags);
42676 /* We are done with the tty pointer now. */
42677 tty_port_tty_set(&hp->port, NULL);
42678@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42679 */
42680 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42681 } else {
42682- if (hp->port.count < 0)
42683+ if (atomic_read(&hp->port.count) < 0)
42684 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42685- hp->vtermno, hp->port.count);
42686+ hp->vtermno, atomic_read(&hp->port.count));
42687 spin_unlock_irqrestore(&hp->port.lock, flags);
42688 }
42689 }
42690@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42691 * open->hangup case this can be called after the final close so prevent
42692 * that from happening for now.
42693 */
42694- if (hp->port.count <= 0) {
42695+ if (atomic_read(&hp->port.count) <= 0) {
42696 spin_unlock_irqrestore(&hp->port.lock, flags);
42697 return;
42698 }
42699
42700- hp->port.count = 0;
42701+ atomic_set(&hp->port.count, 0);
42702 spin_unlock_irqrestore(&hp->port.lock, flags);
42703 tty_port_tty_set(&hp->port, NULL);
42704
42705@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42706 return -EPIPE;
42707
42708 /* FIXME what's this (unprotected) check for? */
42709- if (hp->port.count <= 0)
42710+ if (atomic_read(&hp->port.count) <= 0)
42711 return -EIO;
42712
42713 spin_lock_irqsave(&hp->lock, flags);
42714diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42715index 8776357..b2d4afd 100644
42716--- a/drivers/tty/hvc/hvcs.c
42717+++ b/drivers/tty/hvc/hvcs.c
42718@@ -83,6 +83,7 @@
42719 #include <asm/hvcserver.h>
42720 #include <asm/uaccess.h>
42721 #include <asm/vio.h>
42722+#include <asm/local.h>
42723
42724 /*
42725 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42726@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42727
42728 spin_lock_irqsave(&hvcsd->lock, flags);
42729
42730- if (hvcsd->port.count > 0) {
42731+ if (atomic_read(&hvcsd->port.count) > 0) {
42732 spin_unlock_irqrestore(&hvcsd->lock, flags);
42733 printk(KERN_INFO "HVCS: vterm state unchanged. "
42734 "The hvcs device node is still in use.\n");
42735@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42736 }
42737 }
42738
42739- hvcsd->port.count = 0;
42740+ atomic_set(&hvcsd->port.count, 0);
42741 hvcsd->port.tty = tty;
42742 tty->driver_data = hvcsd;
42743
42744@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42745 unsigned long flags;
42746
42747 spin_lock_irqsave(&hvcsd->lock, flags);
42748- hvcsd->port.count++;
42749+ atomic_inc(&hvcsd->port.count);
42750 hvcsd->todo_mask |= HVCS_SCHED_READ;
42751 spin_unlock_irqrestore(&hvcsd->lock, flags);
42752
42753@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42754 hvcsd = tty->driver_data;
42755
42756 spin_lock_irqsave(&hvcsd->lock, flags);
42757- if (--hvcsd->port.count == 0) {
42758+ if (atomic_dec_and_test(&hvcsd->port.count)) {
42759
42760 vio_disable_interrupts(hvcsd->vdev);
42761
42762@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42763
42764 free_irq(irq, hvcsd);
42765 return;
42766- } else if (hvcsd->port.count < 0) {
42767+ } else if (atomic_read(&hvcsd->port.count) < 0) {
42768 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42769 " is missmanaged.\n",
42770- hvcsd->vdev->unit_address, hvcsd->port.count);
42771+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42772 }
42773
42774 spin_unlock_irqrestore(&hvcsd->lock, flags);
42775@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42776
42777 spin_lock_irqsave(&hvcsd->lock, flags);
42778 /* Preserve this so that we know how many kref refs to put */
42779- temp_open_count = hvcsd->port.count;
42780+ temp_open_count = atomic_read(&hvcsd->port.count);
42781
42782 /*
42783 * Don't kref put inside the spinlock because the destruction
42784@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42785 tty->driver_data = NULL;
42786 hvcsd->port.tty = NULL;
42787
42788- hvcsd->port.count = 0;
42789+ atomic_set(&hvcsd->port.count, 0);
42790
42791 /* This will drop any buffered data on the floor which is OK in a hangup
42792 * scenario. */
42793@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42794 * the middle of a write operation? This is a crummy place to do this
42795 * but we want to keep it all in the spinlock.
42796 */
42797- if (hvcsd->port.count <= 0) {
42798+ if (atomic_read(&hvcsd->port.count) <= 0) {
42799 spin_unlock_irqrestore(&hvcsd->lock, flags);
42800 return -ENODEV;
42801 }
42802@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42803 {
42804 struct hvcs_struct *hvcsd = tty->driver_data;
42805
42806- if (!hvcsd || hvcsd->port.count <= 0)
42807+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42808 return 0;
42809
42810 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42811diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42812index 2cde13d..645d78f 100644
42813--- a/drivers/tty/ipwireless/tty.c
42814+++ b/drivers/tty/ipwireless/tty.c
42815@@ -29,6 +29,7 @@
42816 #include <linux/tty_driver.h>
42817 #include <linux/tty_flip.h>
42818 #include <linux/uaccess.h>
42819+#include <asm/local.h>
42820
42821 #include "tty.h"
42822 #include "network.h"
42823@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42824 mutex_unlock(&tty->ipw_tty_mutex);
42825 return -ENODEV;
42826 }
42827- if (tty->port.count == 0)
42828+ if (atomic_read(&tty->port.count) == 0)
42829 tty->tx_bytes_queued = 0;
42830
42831- tty->port.count++;
42832+ atomic_inc(&tty->port.count);
42833
42834 tty->port.tty = linux_tty;
42835 linux_tty->driver_data = tty;
42836@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42837
42838 static void do_ipw_close(struct ipw_tty *tty)
42839 {
42840- tty->port.count--;
42841-
42842- if (tty->port.count == 0) {
42843+ if (atomic_dec_return(&tty->port.count) == 0) {
42844 struct tty_struct *linux_tty = tty->port.tty;
42845
42846 if (linux_tty != NULL) {
42847@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42848 return;
42849
42850 mutex_lock(&tty->ipw_tty_mutex);
42851- if (tty->port.count == 0) {
42852+ if (atomic_read(&tty->port.count) == 0) {
42853 mutex_unlock(&tty->ipw_tty_mutex);
42854 return;
42855 }
42856@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42857 return;
42858 }
42859
42860- if (!tty->port.count) {
42861+ if (!atomic_read(&tty->port.count)) {
42862 mutex_unlock(&tty->ipw_tty_mutex);
42863 return;
42864 }
42865@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42866 return -ENODEV;
42867
42868 mutex_lock(&tty->ipw_tty_mutex);
42869- if (!tty->port.count) {
42870+ if (!atomic_read(&tty->port.count)) {
42871 mutex_unlock(&tty->ipw_tty_mutex);
42872 return -EINVAL;
42873 }
42874@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42875 if (!tty)
42876 return -ENODEV;
42877
42878- if (!tty->port.count)
42879+ if (!atomic_read(&tty->port.count))
42880 return -EINVAL;
42881
42882 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42883@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42884 if (!tty)
42885 return 0;
42886
42887- if (!tty->port.count)
42888+ if (!atomic_read(&tty->port.count))
42889 return 0;
42890
42891 return tty->tx_bytes_queued;
42892@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42893 if (!tty)
42894 return -ENODEV;
42895
42896- if (!tty->port.count)
42897+ if (!atomic_read(&tty->port.count))
42898 return -EINVAL;
42899
42900 return get_control_lines(tty);
42901@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
42902 if (!tty)
42903 return -ENODEV;
42904
42905- if (!tty->port.count)
42906+ if (!atomic_read(&tty->port.count))
42907 return -EINVAL;
42908
42909 return set_control_lines(tty, set, clear);
42910@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
42911 if (!tty)
42912 return -ENODEV;
42913
42914- if (!tty->port.count)
42915+ if (!atomic_read(&tty->port.count))
42916 return -EINVAL;
42917
42918 /* FIXME: Exactly how is the tty object locked here .. */
42919@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42920 * are gone */
42921 mutex_lock(&ttyj->ipw_tty_mutex);
42922 }
42923- while (ttyj->port.count)
42924+ while (atomic_read(&ttyj->port.count))
42925 do_ipw_close(ttyj);
42926 ipwireless_disassociate_network_ttys(network,
42927 ttyj->channel_idx);
42928diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42929index f9d2850..b006f04 100644
42930--- a/drivers/tty/moxa.c
42931+++ b/drivers/tty/moxa.c
42932@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42933 }
42934
42935 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42936- ch->port.count++;
42937+ atomic_inc(&ch->port.count);
42938 tty->driver_data = ch;
42939 tty_port_tty_set(&ch->port, tty);
42940 mutex_lock(&ch->port.mutex);
42941diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42942index bfd6771..e0d93c4 100644
42943--- a/drivers/tty/n_gsm.c
42944+++ b/drivers/tty/n_gsm.c
42945@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42946 spin_lock_init(&dlci->lock);
42947 mutex_init(&dlci->mutex);
42948 dlci->fifo = &dlci->_fifo;
42949- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42950+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42951 kfree(dlci);
42952 return NULL;
42953 }
42954@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42955 struct gsm_dlci *dlci = tty->driver_data;
42956 struct tty_port *port = &dlci->port;
42957
42958- port->count++;
42959+ atomic_inc(&port->count);
42960 dlci_get(dlci);
42961 dlci_get(dlci->gsm->dlci[0]);
42962 mux_get(dlci->gsm);
42963diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42964index 19083ef..6e34e97 100644
42965--- a/drivers/tty/n_tty.c
42966+++ b/drivers/tty/n_tty.c
42967@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42968 {
42969 *ops = tty_ldisc_N_TTY;
42970 ops->owner = NULL;
42971- ops->refcount = ops->flags = 0;
42972+ atomic_set(&ops->refcount, 0);
42973+ ops->flags = 0;
42974 }
42975 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42976diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42977index ac35c90..c47deac 100644
42978--- a/drivers/tty/pty.c
42979+++ b/drivers/tty/pty.c
42980@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
42981 panic("Couldn't register Unix98 pts driver");
42982
42983 /* Now create the /dev/ptmx special device */
42984+ pax_open_kernel();
42985 tty_default_fops(&ptmx_fops);
42986- ptmx_fops.open = ptmx_open;
42987+ *(void **)&ptmx_fops.open = ptmx_open;
42988+ pax_close_kernel();
42989
42990 cdev_init(&ptmx_cdev, &ptmx_fops);
42991 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
42992diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
42993index e42009a..566a036 100644
42994--- a/drivers/tty/rocket.c
42995+++ b/drivers/tty/rocket.c
42996@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42997 tty->driver_data = info;
42998 tty_port_tty_set(port, tty);
42999
43000- if (port->count++ == 0) {
43001+ if (atomic_inc_return(&port->count) == 1) {
43002 atomic_inc(&rp_num_ports_open);
43003
43004 #ifdef ROCKET_DEBUG_OPEN
43005@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43006 #endif
43007 }
43008 #ifdef ROCKET_DEBUG_OPEN
43009- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43010+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43011 #endif
43012
43013 /*
43014@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
43015 spin_unlock_irqrestore(&info->port.lock, flags);
43016 return;
43017 }
43018- if (info->port.count)
43019+ if (atomic_read(&info->port.count))
43020 atomic_dec(&rp_num_ports_open);
43021 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43022 spin_unlock_irqrestore(&info->port.lock, flags);
43023diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43024index 1002054..dd644a8 100644
43025--- a/drivers/tty/serial/kgdboc.c
43026+++ b/drivers/tty/serial/kgdboc.c
43027@@ -24,8 +24,9 @@
43028 #define MAX_CONFIG_LEN 40
43029
43030 static struct kgdb_io kgdboc_io_ops;
43031+static struct kgdb_io kgdboc_io_ops_console;
43032
43033-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43034+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43035 static int configured = -1;
43036
43037 static char config[MAX_CONFIG_LEN];
43038@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43039 kgdboc_unregister_kbd();
43040 if (configured == 1)
43041 kgdb_unregister_io_module(&kgdboc_io_ops);
43042+ else if (configured == 2)
43043+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43044 }
43045
43046 static int configure_kgdboc(void)
43047@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43048 int err;
43049 char *cptr = config;
43050 struct console *cons;
43051+ int is_console = 0;
43052
43053 err = kgdboc_option_setup(config);
43054 if (err || !strlen(config) || isspace(config[0]))
43055 goto noconfig;
43056
43057 err = -ENODEV;
43058- kgdboc_io_ops.is_console = 0;
43059 kgdb_tty_driver = NULL;
43060
43061 kgdboc_use_kms = 0;
43062@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43063 int idx;
43064 if (cons->device && cons->device(cons, &idx) == p &&
43065 idx == tty_line) {
43066- kgdboc_io_ops.is_console = 1;
43067+ is_console = 1;
43068 break;
43069 }
43070 cons = cons->next;
43071@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43072 kgdb_tty_line = tty_line;
43073
43074 do_register:
43075- err = kgdb_register_io_module(&kgdboc_io_ops);
43076+ if (is_console) {
43077+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43078+ configured = 2;
43079+ } else {
43080+ err = kgdb_register_io_module(&kgdboc_io_ops);
43081+ configured = 1;
43082+ }
43083 if (err)
43084 goto noconfig;
43085
43086@@ -205,8 +214,6 @@ do_register:
43087 if (err)
43088 goto nmi_con_failed;
43089
43090- configured = 1;
43091-
43092 return 0;
43093
43094 nmi_con_failed:
43095@@ -223,7 +230,7 @@ noconfig:
43096 static int __init init_kgdboc(void)
43097 {
43098 /* Already configured? */
43099- if (configured == 1)
43100+ if (configured >= 1)
43101 return 0;
43102
43103 return configure_kgdboc();
43104@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43105 if (config[len - 1] == '\n')
43106 config[len - 1] = '\0';
43107
43108- if (configured == 1)
43109+ if (configured >= 1)
43110 cleanup_kgdboc();
43111
43112 /* Go and configure with the new params. */
43113@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43114 .post_exception = kgdboc_post_exp_handler,
43115 };
43116
43117+static struct kgdb_io kgdboc_io_ops_console = {
43118+ .name = "kgdboc",
43119+ .read_char = kgdboc_get_char,
43120+ .write_char = kgdboc_put_char,
43121+ .pre_exception = kgdboc_pre_exp_handler,
43122+ .post_exception = kgdboc_post_exp_handler,
43123+ .is_console = 1
43124+};
43125+
43126 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43127 /* This is only available if kgdboc is a built in for early debugging */
43128 static int __init kgdboc_early_init(char *opt)
43129diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43130index e514b3a..c73d614 100644
43131--- a/drivers/tty/serial/samsung.c
43132+++ b/drivers/tty/serial/samsung.c
43133@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43134 }
43135 }
43136
43137+static int s3c64xx_serial_startup(struct uart_port *port);
43138 static int s3c24xx_serial_startup(struct uart_port *port)
43139 {
43140 struct s3c24xx_uart_port *ourport = to_ourport(port);
43141 int ret;
43142
43143+ /* Startup sequence is different for s3c64xx and higher SoC's */
43144+ if (s3c24xx_serial_has_interrupt_mask(port))
43145+ return s3c64xx_serial_startup(port);
43146+
43147 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43148 port->mapbase, port->membase);
43149
43150@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43151 /* setup info for port */
43152 port->dev = &platdev->dev;
43153
43154- /* Startup sequence is different for s3c64xx and higher SoC's */
43155- if (s3c24xx_serial_has_interrupt_mask(port))
43156- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43157-
43158 port->uartclk = 1;
43159
43160 if (cfg->uart_flags & UPF_CONS_FLOW) {
43161diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43162index 2c7230a..2104f16 100644
43163--- a/drivers/tty/serial/serial_core.c
43164+++ b/drivers/tty/serial/serial_core.c
43165@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
43166 uart_flush_buffer(tty);
43167 uart_shutdown(tty, state);
43168 spin_lock_irqsave(&port->lock, flags);
43169- port->count = 0;
43170+ atomic_set(&port->count, 0);
43171 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43172 spin_unlock_irqrestore(&port->lock, flags);
43173 tty_port_tty_set(port, NULL);
43174@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43175 goto end;
43176 }
43177
43178- port->count++;
43179+ atomic_inc(&port->count);
43180 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43181 retval = -ENXIO;
43182 goto err_dec_count;
43183@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43184 /*
43185 * Make sure the device is in D0 state.
43186 */
43187- if (port->count == 1)
43188+ if (atomic_read(&port->count) == 1)
43189 uart_change_pm(state, 0);
43190
43191 /*
43192@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43193 end:
43194 return retval;
43195 err_dec_count:
43196- port->count--;
43197+ atomic_inc(&port->count);
43198 mutex_unlock(&port->mutex);
43199 goto end;
43200 }
43201diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43202index 9e071f6..f30ae69 100644
43203--- a/drivers/tty/synclink.c
43204+++ b/drivers/tty/synclink.c
43205@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43206
43207 if (debug_level >= DEBUG_LEVEL_INFO)
43208 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43209- __FILE__,__LINE__, info->device_name, info->port.count);
43210+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43211
43212 if (tty_port_close_start(&info->port, tty, filp) == 0)
43213 goto cleanup;
43214@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43215 cleanup:
43216 if (debug_level >= DEBUG_LEVEL_INFO)
43217 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43218- tty->driver->name, info->port.count);
43219+ tty->driver->name, atomic_read(&info->port.count));
43220
43221 } /* end of mgsl_close() */
43222
43223@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43224
43225 mgsl_flush_buffer(tty);
43226 shutdown(info);
43227-
43228- info->port.count = 0;
43229+
43230+ atomic_set(&info->port.count, 0);
43231 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43232 info->port.tty = NULL;
43233
43234@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43235
43236 if (debug_level >= DEBUG_LEVEL_INFO)
43237 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43238- __FILE__,__LINE__, tty->driver->name, port->count );
43239+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43240
43241 spin_lock_irqsave(&info->irq_spinlock, flags);
43242 if (!tty_hung_up_p(filp)) {
43243 extra_count = true;
43244- port->count--;
43245+ atomic_dec(&port->count);
43246 }
43247 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43248 port->blocked_open++;
43249@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43250
43251 if (debug_level >= DEBUG_LEVEL_INFO)
43252 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43253- __FILE__,__LINE__, tty->driver->name, port->count );
43254+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43255
43256 tty_unlock(tty);
43257 schedule();
43258@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43259
43260 /* FIXME: Racy on hangup during close wait */
43261 if (extra_count)
43262- port->count++;
43263+ atomic_inc(&port->count);
43264 port->blocked_open--;
43265
43266 if (debug_level >= DEBUG_LEVEL_INFO)
43267 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43268- __FILE__,__LINE__, tty->driver->name, port->count );
43269+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43270
43271 if (!retval)
43272 port->flags |= ASYNC_NORMAL_ACTIVE;
43273@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43274
43275 if (debug_level >= DEBUG_LEVEL_INFO)
43276 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43277- __FILE__,__LINE__,tty->driver->name, info->port.count);
43278+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43279
43280 /* If port is closing, signal caller to try again */
43281 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43282@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43283 spin_unlock_irqrestore(&info->netlock, flags);
43284 goto cleanup;
43285 }
43286- info->port.count++;
43287+ atomic_inc(&info->port.count);
43288 spin_unlock_irqrestore(&info->netlock, flags);
43289
43290- if (info->port.count == 1) {
43291+ if (atomic_read(&info->port.count) == 1) {
43292 /* 1st open on this device, init hardware */
43293 retval = startup(info);
43294 if (retval < 0)
43295@@ -3451,8 +3451,8 @@ cleanup:
43296 if (retval) {
43297 if (tty->count == 1)
43298 info->port.tty = NULL; /* tty layer will release tty struct */
43299- if(info->port.count)
43300- info->port.count--;
43301+ if (atomic_read(&info->port.count))
43302+ atomic_dec(&info->port.count);
43303 }
43304
43305 return retval;
43306@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43307 unsigned short new_crctype;
43308
43309 /* return error if TTY interface open */
43310- if (info->port.count)
43311+ if (atomic_read(&info->port.count))
43312 return -EBUSY;
43313
43314 switch (encoding)
43315@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
43316
43317 /* arbitrate between network and tty opens */
43318 spin_lock_irqsave(&info->netlock, flags);
43319- if (info->port.count != 0 || info->netcount != 0) {
43320+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43321 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43322 spin_unlock_irqrestore(&info->netlock, flags);
43323 return -EBUSY;
43324@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43325 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43326
43327 /* return error if TTY interface open */
43328- if (info->port.count)
43329+ if (atomic_read(&info->port.count))
43330 return -EBUSY;
43331
43332 if (cmd != SIOCWANDEV)
43333diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43334index aba1e59..877ac33 100644
43335--- a/drivers/tty/synclink_gt.c
43336+++ b/drivers/tty/synclink_gt.c
43337@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43338 tty->driver_data = info;
43339 info->port.tty = tty;
43340
43341- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43342+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43343
43344 /* If port is closing, signal caller to try again */
43345 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43346@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43347 mutex_unlock(&info->port.mutex);
43348 goto cleanup;
43349 }
43350- info->port.count++;
43351+ atomic_inc(&info->port.count);
43352 spin_unlock_irqrestore(&info->netlock, flags);
43353
43354- if (info->port.count == 1) {
43355+ if (atomic_read(&info->port.count) == 1) {
43356 /* 1st open on this device, init hardware */
43357 retval = startup(info);
43358 if (retval < 0) {
43359@@ -716,8 +716,8 @@ cleanup:
43360 if (retval) {
43361 if (tty->count == 1)
43362 info->port.tty = NULL; /* tty layer will release tty struct */
43363- if(info->port.count)
43364- info->port.count--;
43365+ if(atomic_read(&info->port.count))
43366+ atomic_dec(&info->port.count);
43367 }
43368
43369 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43370@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43371
43372 if (sanity_check(info, tty->name, "close"))
43373 return;
43374- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43375+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43376
43377 if (tty_port_close_start(&info->port, tty, filp) == 0)
43378 goto cleanup;
43379@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43380 tty_port_close_end(&info->port, tty);
43381 info->port.tty = NULL;
43382 cleanup:
43383- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
43384+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
43385 }
43386
43387 static void hangup(struct tty_struct *tty)
43388@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
43389 shutdown(info);
43390
43391 spin_lock_irqsave(&info->port.lock, flags);
43392- info->port.count = 0;
43393+ atomic_set(&info->port.count, 0);
43394 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43395 info->port.tty = NULL;
43396 spin_unlock_irqrestore(&info->port.lock, flags);
43397@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43398 unsigned short new_crctype;
43399
43400 /* return error if TTY interface open */
43401- if (info->port.count)
43402+ if (atomic_read(&info->port.count))
43403 return -EBUSY;
43404
43405 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
43406@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
43407
43408 /* arbitrate between network and tty opens */
43409 spin_lock_irqsave(&info->netlock, flags);
43410- if (info->port.count != 0 || info->netcount != 0) {
43411+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43412 DBGINFO(("%s hdlc_open busy\n", dev->name));
43413 spin_unlock_irqrestore(&info->netlock, flags);
43414 return -EBUSY;
43415@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43416 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
43417
43418 /* return error if TTY interface open */
43419- if (info->port.count)
43420+ if (atomic_read(&info->port.count))
43421 return -EBUSY;
43422
43423 if (cmd != SIOCWANDEV)
43424@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43425 if (port == NULL)
43426 continue;
43427 spin_lock(&port->lock);
43428- if ((port->port.count || port->netcount) &&
43429+ if ((atomic_read(&port->port.count) || port->netcount) &&
43430 port->pending_bh && !port->bh_running &&
43431 !port->bh_requested) {
43432 DBGISR(("%s bh queued\n", port->device_name));
43433@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43434 spin_lock_irqsave(&info->lock, flags);
43435 if (!tty_hung_up_p(filp)) {
43436 extra_count = true;
43437- port->count--;
43438+ atomic_dec(&port->count);
43439 }
43440 spin_unlock_irqrestore(&info->lock, flags);
43441 port->blocked_open++;
43442@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43443 remove_wait_queue(&port->open_wait, &wait);
43444
43445 if (extra_count)
43446- port->count++;
43447+ atomic_inc(&port->count);
43448 port->blocked_open--;
43449
43450 if (!retval)
43451diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43452index fd43fb6..34704ad 100644
43453--- a/drivers/tty/synclinkmp.c
43454+++ b/drivers/tty/synclinkmp.c
43455@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43456
43457 if (debug_level >= DEBUG_LEVEL_INFO)
43458 printk("%s(%d):%s open(), old ref count = %d\n",
43459- __FILE__,__LINE__,tty->driver->name, info->port.count);
43460+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43461
43462 /* If port is closing, signal caller to try again */
43463 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43464@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43465 spin_unlock_irqrestore(&info->netlock, flags);
43466 goto cleanup;
43467 }
43468- info->port.count++;
43469+ atomic_inc(&info->port.count);
43470 spin_unlock_irqrestore(&info->netlock, flags);
43471
43472- if (info->port.count == 1) {
43473+ if (atomic_read(&info->port.count) == 1) {
43474 /* 1st open on this device, init hardware */
43475 retval = startup(info);
43476 if (retval < 0)
43477@@ -797,8 +797,8 @@ cleanup:
43478 if (retval) {
43479 if (tty->count == 1)
43480 info->port.tty = NULL; /* tty layer will release tty struct */
43481- if(info->port.count)
43482- info->port.count--;
43483+ if(atomic_read(&info->port.count))
43484+ atomic_dec(&info->port.count);
43485 }
43486
43487 return retval;
43488@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43489
43490 if (debug_level >= DEBUG_LEVEL_INFO)
43491 printk("%s(%d):%s close() entry, count=%d\n",
43492- __FILE__,__LINE__, info->device_name, info->port.count);
43493+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43494
43495 if (tty_port_close_start(&info->port, tty, filp) == 0)
43496 goto cleanup;
43497@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43498 cleanup:
43499 if (debug_level >= DEBUG_LEVEL_INFO)
43500 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43501- tty->driver->name, info->port.count);
43502+ tty->driver->name, atomic_read(&info->port.count));
43503 }
43504
43505 /* Called by tty_hangup() when a hangup is signaled.
43506@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
43507 shutdown(info);
43508
43509 spin_lock_irqsave(&info->port.lock, flags);
43510- info->port.count = 0;
43511+ atomic_set(&info->port.count, 0);
43512 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43513 info->port.tty = NULL;
43514 spin_unlock_irqrestore(&info->port.lock, flags);
43515@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43516 unsigned short new_crctype;
43517
43518 /* return error if TTY interface open */
43519- if (info->port.count)
43520+ if (atomic_read(&info->port.count))
43521 return -EBUSY;
43522
43523 switch (encoding)
43524@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
43525
43526 /* arbitrate between network and tty opens */
43527 spin_lock_irqsave(&info->netlock, flags);
43528- if (info->port.count != 0 || info->netcount != 0) {
43529+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43530 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43531 spin_unlock_irqrestore(&info->netlock, flags);
43532 return -EBUSY;
43533@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43534 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43535
43536 /* return error if TTY interface open */
43537- if (info->port.count)
43538+ if (atomic_read(&info->port.count))
43539 return -EBUSY;
43540
43541 if (cmd != SIOCWANDEV)
43542@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43543 * do not request bottom half processing if the
43544 * device is not open in a normal mode.
43545 */
43546- if ( port && (port->port.count || port->netcount) &&
43547+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43548 port->pending_bh && !port->bh_running &&
43549 !port->bh_requested ) {
43550 if ( debug_level >= DEBUG_LEVEL_ISR )
43551@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43552
43553 if (debug_level >= DEBUG_LEVEL_INFO)
43554 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43555- __FILE__,__LINE__, tty->driver->name, port->count );
43556+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43557
43558 spin_lock_irqsave(&info->lock, flags);
43559 if (!tty_hung_up_p(filp)) {
43560 extra_count = true;
43561- port->count--;
43562+ atomic_dec(&port->count);
43563 }
43564 spin_unlock_irqrestore(&info->lock, flags);
43565 port->blocked_open++;
43566@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43567
43568 if (debug_level >= DEBUG_LEVEL_INFO)
43569 printk("%s(%d):%s block_til_ready() count=%d\n",
43570- __FILE__,__LINE__, tty->driver->name, port->count );
43571+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43572
43573 tty_unlock(tty);
43574 schedule();
43575@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43576 remove_wait_queue(&port->open_wait, &wait);
43577
43578 if (extra_count)
43579- port->count++;
43580+ atomic_inc(&port->count);
43581 port->blocked_open--;
43582
43583 if (debug_level >= DEBUG_LEVEL_INFO)
43584 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43585- __FILE__,__LINE__, tty->driver->name, port->count );
43586+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43587
43588 if (!retval)
43589 port->flags |= ASYNC_NORMAL_ACTIVE;
43590diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43591index b3c4a25..723916f 100644
43592--- a/drivers/tty/sysrq.c
43593+++ b/drivers/tty/sysrq.c
43594@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43595 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43596 size_t count, loff_t *ppos)
43597 {
43598- if (count) {
43599+ if (count && capable(CAP_SYS_ADMIN)) {
43600 char c;
43601
43602 if (get_user(c, buf))
43603diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43604index da9fde8..c07975f 100644
43605--- a/drivers/tty/tty_io.c
43606+++ b/drivers/tty/tty_io.c
43607@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43608
43609 void tty_default_fops(struct file_operations *fops)
43610 {
43611- *fops = tty_fops;
43612+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43613 }
43614
43615 /*
43616diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43617index c578229..45aa9ee 100644
43618--- a/drivers/tty/tty_ldisc.c
43619+++ b/drivers/tty/tty_ldisc.c
43620@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43621 if (atomic_dec_and_test(&ld->users)) {
43622 struct tty_ldisc_ops *ldo = ld->ops;
43623
43624- ldo->refcount--;
43625+ atomic_dec(&ldo->refcount);
43626 module_put(ldo->owner);
43627 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43628
43629@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43630 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43631 tty_ldiscs[disc] = new_ldisc;
43632 new_ldisc->num = disc;
43633- new_ldisc->refcount = 0;
43634+ atomic_set(&new_ldisc->refcount, 0);
43635 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43636
43637 return ret;
43638@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43639 return -EINVAL;
43640
43641 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43642- if (tty_ldiscs[disc]->refcount)
43643+ if (atomic_read(&tty_ldiscs[disc]->refcount))
43644 ret = -EBUSY;
43645 else
43646 tty_ldiscs[disc] = NULL;
43647@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43648 if (ldops) {
43649 ret = ERR_PTR(-EAGAIN);
43650 if (try_module_get(ldops->owner)) {
43651- ldops->refcount++;
43652+ atomic_inc(&ldops->refcount);
43653 ret = ldops;
43654 }
43655 }
43656@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43657 unsigned long flags;
43658
43659 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43660- ldops->refcount--;
43661+ atomic_dec(&ldops->refcount);
43662 module_put(ldops->owner);
43663 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43664 }
43665diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43666index b7ff59d..7c6105e 100644
43667--- a/drivers/tty/tty_port.c
43668+++ b/drivers/tty/tty_port.c
43669@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43670 unsigned long flags;
43671
43672 spin_lock_irqsave(&port->lock, flags);
43673- port->count = 0;
43674+ atomic_set(&port->count, 0);
43675 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43676 if (port->tty) {
43677 set_bit(TTY_IO_ERROR, &port->tty->flags);
43678@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43679 /* The port lock protects the port counts */
43680 spin_lock_irqsave(&port->lock, flags);
43681 if (!tty_hung_up_p(filp))
43682- port->count--;
43683+ atomic_dec(&port->count);
43684 port->blocked_open++;
43685 spin_unlock_irqrestore(&port->lock, flags);
43686
43687@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43688 we must not mess that up further */
43689 spin_lock_irqsave(&port->lock, flags);
43690 if (!tty_hung_up_p(filp))
43691- port->count++;
43692+ atomic_inc(&port->count);
43693 port->blocked_open--;
43694 if (retval == 0)
43695 port->flags |= ASYNC_NORMAL_ACTIVE;
43696@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43697 return 0;
43698 }
43699
43700- if (tty->count == 1 && port->count != 1) {
43701+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
43702 printk(KERN_WARNING
43703 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43704- port->count);
43705- port->count = 1;
43706+ atomic_read(&port->count));
43707+ atomic_set(&port->count, 1);
43708 }
43709- if (--port->count < 0) {
43710+ if (atomic_dec_return(&port->count) < 0) {
43711 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43712- port->count);
43713- port->count = 0;
43714+ atomic_read(&port->count));
43715+ atomic_set(&port->count, 0);
43716 }
43717
43718- if (port->count) {
43719+ if (atomic_read(&port->count)) {
43720 spin_unlock_irqrestore(&port->lock, flags);
43721 if (port->ops->drop)
43722 port->ops->drop(port);
43723@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43724 {
43725 spin_lock_irq(&port->lock);
43726 if (!tty_hung_up_p(filp))
43727- ++port->count;
43728+ atomic_inc(&port->count);
43729 spin_unlock_irq(&port->lock);
43730 tty_port_tty_set(port, tty);
43731
43732diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43733index 681765b..d3ccdf2 100644
43734--- a/drivers/tty/vt/keyboard.c
43735+++ b/drivers/tty/vt/keyboard.c
43736@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43737 kbd->kbdmode == VC_OFF) &&
43738 value != KVAL(K_SAK))
43739 return; /* SAK is allowed even in raw mode */
43740+
43741+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43742+ {
43743+ void *func = fn_handler[value];
43744+ if (func == fn_show_state || func == fn_show_ptregs ||
43745+ func == fn_show_mem)
43746+ return;
43747+ }
43748+#endif
43749+
43750 fn_handler[value](vc);
43751 }
43752
43753@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43754 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43755 return -EFAULT;
43756
43757- if (!capable(CAP_SYS_TTY_CONFIG))
43758- perm = 0;
43759-
43760 switch (cmd) {
43761 case KDGKBENT:
43762 /* Ensure another thread doesn't free it under us */
43763@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43764 spin_unlock_irqrestore(&kbd_event_lock, flags);
43765 return put_user(val, &user_kbe->kb_value);
43766 case KDSKBENT:
43767+ if (!capable(CAP_SYS_TTY_CONFIG))
43768+ perm = 0;
43769+
43770 if (!perm)
43771 return -EPERM;
43772 if (!i && v == K_NOSUCHMAP) {
43773@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43774 int i, j, k;
43775 int ret;
43776
43777- if (!capable(CAP_SYS_TTY_CONFIG))
43778- perm = 0;
43779-
43780 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43781 if (!kbs) {
43782 ret = -ENOMEM;
43783@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43784 kfree(kbs);
43785 return ((p && *p) ? -EOVERFLOW : 0);
43786 case KDSKBSENT:
43787+ if (!capable(CAP_SYS_TTY_CONFIG))
43788+ perm = 0;
43789+
43790 if (!perm) {
43791 ret = -EPERM;
43792 goto reterr;
43793diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43794index 5110f36..8dc0a74 100644
43795--- a/drivers/uio/uio.c
43796+++ b/drivers/uio/uio.c
43797@@ -25,6 +25,7 @@
43798 #include <linux/kobject.h>
43799 #include <linux/cdev.h>
43800 #include <linux/uio_driver.h>
43801+#include <asm/local.h>
43802
43803 #define UIO_MAX_DEVICES (1U << MINORBITS)
43804
43805@@ -32,10 +33,10 @@ struct uio_device {
43806 struct module *owner;
43807 struct device *dev;
43808 int minor;
43809- atomic_t event;
43810+ atomic_unchecked_t event;
43811 struct fasync_struct *async_queue;
43812 wait_queue_head_t wait;
43813- int vma_count;
43814+ local_t vma_count;
43815 struct uio_info *info;
43816 struct kobject *map_dir;
43817 struct kobject *portio_dir;
43818@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43819 struct device_attribute *attr, char *buf)
43820 {
43821 struct uio_device *idev = dev_get_drvdata(dev);
43822- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43823+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43824 }
43825
43826 static struct device_attribute uio_class_attributes[] = {
43827@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43828 {
43829 struct uio_device *idev = info->uio_dev;
43830
43831- atomic_inc(&idev->event);
43832+ atomic_inc_unchecked(&idev->event);
43833 wake_up_interruptible(&idev->wait);
43834 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43835 }
43836@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43837 }
43838
43839 listener->dev = idev;
43840- listener->event_count = atomic_read(&idev->event);
43841+ listener->event_count = atomic_read_unchecked(&idev->event);
43842 filep->private_data = listener;
43843
43844 if (idev->info->open) {
43845@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43846 return -EIO;
43847
43848 poll_wait(filep, &idev->wait, wait);
43849- if (listener->event_count != atomic_read(&idev->event))
43850+ if (listener->event_count != atomic_read_unchecked(&idev->event))
43851 return POLLIN | POLLRDNORM;
43852 return 0;
43853 }
43854@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43855 do {
43856 set_current_state(TASK_INTERRUPTIBLE);
43857
43858- event_count = atomic_read(&idev->event);
43859+ event_count = atomic_read_unchecked(&idev->event);
43860 if (event_count != listener->event_count) {
43861 if (copy_to_user(buf, &event_count, count))
43862 retval = -EFAULT;
43863@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43864 static void uio_vma_open(struct vm_area_struct *vma)
43865 {
43866 struct uio_device *idev = vma->vm_private_data;
43867- idev->vma_count++;
43868+ local_inc(&idev->vma_count);
43869 }
43870
43871 static void uio_vma_close(struct vm_area_struct *vma)
43872 {
43873 struct uio_device *idev = vma->vm_private_data;
43874- idev->vma_count--;
43875+ local_dec(&idev->vma_count);
43876 }
43877
43878 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43879@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43880 idev->owner = owner;
43881 idev->info = info;
43882 init_waitqueue_head(&idev->wait);
43883- atomic_set(&idev->event, 0);
43884+ atomic_set_unchecked(&idev->event, 0);
43885
43886 ret = uio_get_minor(idev);
43887 if (ret)
43888diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43889index b7eb86a..36d28af 100644
43890--- a/drivers/usb/atm/cxacru.c
43891+++ b/drivers/usb/atm/cxacru.c
43892@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43893 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43894 if (ret < 2)
43895 return -EINVAL;
43896- if (index < 0 || index > 0x7f)
43897+ if (index > 0x7f)
43898 return -EINVAL;
43899 pos += tmp;
43900
43901diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43902index 35f10bf..6a38a0b 100644
43903--- a/drivers/usb/atm/usbatm.c
43904+++ b/drivers/usb/atm/usbatm.c
43905@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43906 if (printk_ratelimit())
43907 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43908 __func__, vpi, vci);
43909- atomic_inc(&vcc->stats->rx_err);
43910+ atomic_inc_unchecked(&vcc->stats->rx_err);
43911 return;
43912 }
43913
43914@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43915 if (length > ATM_MAX_AAL5_PDU) {
43916 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43917 __func__, length, vcc);
43918- atomic_inc(&vcc->stats->rx_err);
43919+ atomic_inc_unchecked(&vcc->stats->rx_err);
43920 goto out;
43921 }
43922
43923@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43924 if (sarb->len < pdu_length) {
43925 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43926 __func__, pdu_length, sarb->len, vcc);
43927- atomic_inc(&vcc->stats->rx_err);
43928+ atomic_inc_unchecked(&vcc->stats->rx_err);
43929 goto out;
43930 }
43931
43932 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43933 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43934 __func__, vcc);
43935- atomic_inc(&vcc->stats->rx_err);
43936+ atomic_inc_unchecked(&vcc->stats->rx_err);
43937 goto out;
43938 }
43939
43940@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43941 if (printk_ratelimit())
43942 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43943 __func__, length);
43944- atomic_inc(&vcc->stats->rx_drop);
43945+ atomic_inc_unchecked(&vcc->stats->rx_drop);
43946 goto out;
43947 }
43948
43949@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43950
43951 vcc->push(vcc, skb);
43952
43953- atomic_inc(&vcc->stats->rx);
43954+ atomic_inc_unchecked(&vcc->stats->rx);
43955 out:
43956 skb_trim(sarb, 0);
43957 }
43958@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43959 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43960
43961 usbatm_pop(vcc, skb);
43962- atomic_inc(&vcc->stats->tx);
43963+ atomic_inc_unchecked(&vcc->stats->tx);
43964
43965 skb = skb_dequeue(&instance->sndqueue);
43966 }
43967@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43968 if (!left--)
43969 return sprintf(page,
43970 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43971- atomic_read(&atm_dev->stats.aal5.tx),
43972- atomic_read(&atm_dev->stats.aal5.tx_err),
43973- atomic_read(&atm_dev->stats.aal5.rx),
43974- atomic_read(&atm_dev->stats.aal5.rx_err),
43975- atomic_read(&atm_dev->stats.aal5.rx_drop));
43976+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43977+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43978+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43979+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43980+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43981
43982 if (!left--) {
43983 if (instance->disconnected)
43984diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43985index cbacea9..246cccd 100644
43986--- a/drivers/usb/core/devices.c
43987+++ b/drivers/usb/core/devices.c
43988@@ -126,7 +126,7 @@ static const char format_endpt[] =
43989 * time it gets called.
43990 */
43991 static struct device_connect_event {
43992- atomic_t count;
43993+ atomic_unchecked_t count;
43994 wait_queue_head_t wait;
43995 } device_event = {
43996 .count = ATOMIC_INIT(1),
43997@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
43998
43999 void usbfs_conn_disc_event(void)
44000 {
44001- atomic_add(2, &device_event.count);
44002+ atomic_add_unchecked(2, &device_event.count);
44003 wake_up(&device_event.wait);
44004 }
44005
44006@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
44007
44008 poll_wait(file, &device_event.wait, wait);
44009
44010- event_count = atomic_read(&device_event.count);
44011+ event_count = atomic_read_unchecked(&device_event.count);
44012 if (file->f_version != event_count) {
44013 file->f_version = event_count;
44014 return POLLIN | POLLRDNORM;
44015diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44016index 8e64adf..9a33a3c 100644
44017--- a/drivers/usb/core/hcd.c
44018+++ b/drivers/usb/core/hcd.c
44019@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44020 */
44021 usb_get_urb(urb);
44022 atomic_inc(&urb->use_count);
44023- atomic_inc(&urb->dev->urbnum);
44024+ atomic_inc_unchecked(&urb->dev->urbnum);
44025 usbmon_urb_submit(&hcd->self, urb);
44026
44027 /* NOTE requirements on root-hub callers (usbfs and the hub
44028@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44029 urb->hcpriv = NULL;
44030 INIT_LIST_HEAD(&urb->urb_list);
44031 atomic_dec(&urb->use_count);
44032- atomic_dec(&urb->dev->urbnum);
44033+ atomic_dec_unchecked(&urb->dev->urbnum);
44034 if (atomic_read(&urb->reject))
44035 wake_up(&usb_kill_urb_queue);
44036 usb_put_urb(urb);
44037diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44038index 131f736..99004c3 100644
44039--- a/drivers/usb/core/message.c
44040+++ b/drivers/usb/core/message.c
44041@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44042 * method can wait for it to complete. Since you don't have a handle on the
44043 * URB used, you can't cancel the request.
44044 */
44045-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44046+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44047 __u8 requesttype, __u16 value, __u16 index, void *data,
44048 __u16 size, int timeout)
44049 {
44050diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44051index 818e4a0..0fc9589 100644
44052--- a/drivers/usb/core/sysfs.c
44053+++ b/drivers/usb/core/sysfs.c
44054@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44055 struct usb_device *udev;
44056
44057 udev = to_usb_device(dev);
44058- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44059+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44060 }
44061 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44062
44063diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44064index f81b925..78d22ec 100644
44065--- a/drivers/usb/core/usb.c
44066+++ b/drivers/usb/core/usb.c
44067@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44068 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44069 dev->state = USB_STATE_ATTACHED;
44070 dev->lpm_disable_count = 1;
44071- atomic_set(&dev->urbnum, 0);
44072+ atomic_set_unchecked(&dev->urbnum, 0);
44073
44074 INIT_LIST_HEAD(&dev->ep0.urb_list);
44075 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44076diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44077index 5e29dde..eca992f 100644
44078--- a/drivers/usb/early/ehci-dbgp.c
44079+++ b/drivers/usb/early/ehci-dbgp.c
44080@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44081
44082 #ifdef CONFIG_KGDB
44083 static struct kgdb_io kgdbdbgp_io_ops;
44084-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44085+static struct kgdb_io kgdbdbgp_io_ops_console;
44086+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44087 #else
44088 #define dbgp_kgdb_mode (0)
44089 #endif
44090@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44091 .write_char = kgdbdbgp_write_char,
44092 };
44093
44094+static struct kgdb_io kgdbdbgp_io_ops_console = {
44095+ .name = "kgdbdbgp",
44096+ .read_char = kgdbdbgp_read_char,
44097+ .write_char = kgdbdbgp_write_char,
44098+ .is_console = 1
44099+};
44100+
44101 static int kgdbdbgp_wait_time;
44102
44103 static int __init kgdbdbgp_parse_config(char *str)
44104@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44105 ptr++;
44106 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44107 }
44108- kgdb_register_io_module(&kgdbdbgp_io_ops);
44109- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44110+ if (early_dbgp_console.index != -1)
44111+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44112+ else
44113+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44114
44115 return 0;
44116 }
44117diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44118index 598dcc1..032dd4f 100644
44119--- a/drivers/usb/gadget/u_serial.c
44120+++ b/drivers/usb/gadget/u_serial.c
44121@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44122 spin_lock_irq(&port->port_lock);
44123
44124 /* already open? Great. */
44125- if (port->port.count) {
44126+ if (atomic_read(&port->port.count)) {
44127 status = 0;
44128- port->port.count++;
44129+ atomic_inc(&port->port.count);
44130
44131 /* currently opening/closing? wait ... */
44132 } else if (port->openclose) {
44133@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44134 tty->driver_data = port;
44135 port->port.tty = tty;
44136
44137- port->port.count = 1;
44138+ atomic_set(&port->port.count, 1);
44139 port->openclose = false;
44140
44141 /* if connected, start the I/O stream */
44142@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44143
44144 spin_lock_irq(&port->port_lock);
44145
44146- if (port->port.count != 1) {
44147- if (port->port.count == 0)
44148+ if (atomic_read(&port->port.count) != 1) {
44149+ if (atomic_read(&port->port.count) == 0)
44150 WARN_ON(1);
44151 else
44152- --port->port.count;
44153+ atomic_dec(&port->port.count);
44154 goto exit;
44155 }
44156
44157@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44158 * and sleep if necessary
44159 */
44160 port->openclose = true;
44161- port->port.count = 0;
44162+ atomic_set(&port->port.count, 0);
44163
44164 gser = port->port_usb;
44165 if (gser && gser->disconnect)
44166@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44167 int cond;
44168
44169 spin_lock_irq(&port->port_lock);
44170- cond = (port->port.count == 0) && !port->openclose;
44171+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44172 spin_unlock_irq(&port->port_lock);
44173 return cond;
44174 }
44175@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44176 /* if it's already open, start I/O ... and notify the serial
44177 * protocol about open/close status (connect/disconnect).
44178 */
44179- if (port->port.count) {
44180+ if (atomic_read(&port->port.count)) {
44181 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44182 gs_start_io(port);
44183 if (gser->connect)
44184@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44185
44186 port->port_usb = NULL;
44187 gser->ioport = NULL;
44188- if (port->port.count > 0 || port->openclose) {
44189+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44190 wake_up_interruptible(&port->drain_wait);
44191 if (port->port.tty)
44192 tty_hangup(port->port.tty);
44193@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44194
44195 /* finally, free any unused/unusable I/O buffers */
44196 spin_lock_irqsave(&port->port_lock, flags);
44197- if (port->port.count == 0 && !port->openclose)
44198+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44199 gs_buf_free(&port->port_write_buf);
44200 gs_free_requests(gser->out, &port->read_pool, NULL);
44201 gs_free_requests(gser->out, &port->read_queue, NULL);
44202diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44203index 5f3bcd3..bfca43f 100644
44204--- a/drivers/usb/serial/console.c
44205+++ b/drivers/usb/serial/console.c
44206@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44207
44208 info->port = port;
44209
44210- ++port->port.count;
44211+ atomic_inc(&port->port.count);
44212 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44213 if (serial->type->set_termios) {
44214 /*
44215@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44216 }
44217 /* Now that any required fake tty operations are completed restore
44218 * the tty port count */
44219- --port->port.count;
44220+ atomic_dec(&port->port.count);
44221 /* The console is special in terms of closing the device so
44222 * indicate this port is now acting as a system console. */
44223 port->port.console = 1;
44224@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44225 free_tty:
44226 kfree(tty);
44227 reset_open_count:
44228- port->port.count = 0;
44229+ atomic_set(&port->port.count, 0);
44230 usb_autopm_put_interface(serial->interface);
44231 error_get_interface:
44232 usb_serial_put(serial);
44233diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44234index 75f70f0..d467e1a 100644
44235--- a/drivers/usb/storage/usb.h
44236+++ b/drivers/usb/storage/usb.h
44237@@ -63,7 +63,7 @@ struct us_unusual_dev {
44238 __u8 useProtocol;
44239 __u8 useTransport;
44240 int (*initFunction)(struct us_data *);
44241-};
44242+} __do_const;
44243
44244
44245 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44246diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44247index d6bea3e..60b250e 100644
44248--- a/drivers/usb/wusbcore/wa-hc.h
44249+++ b/drivers/usb/wusbcore/wa-hc.h
44250@@ -192,7 +192,7 @@ struct wahc {
44251 struct list_head xfer_delayed_list;
44252 spinlock_t xfer_list_lock;
44253 struct work_struct xfer_work;
44254- atomic_t xfer_id_count;
44255+ atomic_unchecked_t xfer_id_count;
44256 };
44257
44258
44259@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44260 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44261 spin_lock_init(&wa->xfer_list_lock);
44262 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44263- atomic_set(&wa->xfer_id_count, 1);
44264+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44265 }
44266
44267 /**
44268diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44269index 57c01ab..8a05959 100644
44270--- a/drivers/usb/wusbcore/wa-xfer.c
44271+++ b/drivers/usb/wusbcore/wa-xfer.c
44272@@ -296,7 +296,7 @@ out:
44273 */
44274 static void wa_xfer_id_init(struct wa_xfer *xfer)
44275 {
44276- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44277+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44278 }
44279
44280 /*
44281diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44282index 8c55011..eed4ae1a 100644
44283--- a/drivers/video/aty/aty128fb.c
44284+++ b/drivers/video/aty/aty128fb.c
44285@@ -149,7 +149,7 @@ enum {
44286 };
44287
44288 /* Must match above enum */
44289-static char * const r128_family[] = {
44290+static const char * const r128_family[] = {
44291 "AGP",
44292 "PCI",
44293 "PRO AGP",
44294diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44295index 4f27fdc..d3537e6 100644
44296--- a/drivers/video/aty/atyfb_base.c
44297+++ b/drivers/video/aty/atyfb_base.c
44298@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44299 par->accel_flags = var->accel_flags; /* hack */
44300
44301 if (var->accel_flags) {
44302- info->fbops->fb_sync = atyfb_sync;
44303+ pax_open_kernel();
44304+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44305+ pax_close_kernel();
44306 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44307 } else {
44308- info->fbops->fb_sync = NULL;
44309+ pax_open_kernel();
44310+ *(void **)&info->fbops->fb_sync = NULL;
44311+ pax_close_kernel();
44312 info->flags |= FBINFO_HWACCEL_DISABLED;
44313 }
44314
44315diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44316index 95ec042..e6affdd 100644
44317--- a/drivers/video/aty/mach64_cursor.c
44318+++ b/drivers/video/aty/mach64_cursor.c
44319@@ -7,6 +7,7 @@
44320 #include <linux/string.h>
44321
44322 #include <asm/io.h>
44323+#include <asm/pgtable.h>
44324
44325 #ifdef __sparc__
44326 #include <asm/fbio.h>
44327@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44328 info->sprite.buf_align = 16; /* and 64 lines tall. */
44329 info->sprite.flags = FB_PIXMAP_IO;
44330
44331- info->fbops->fb_cursor = atyfb_cursor;
44332+ pax_open_kernel();
44333+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44334+ pax_close_kernel();
44335
44336 return 0;
44337 }
44338diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44339index 6c5ed6b..b727c88 100644
44340--- a/drivers/video/backlight/kb3886_bl.c
44341+++ b/drivers/video/backlight/kb3886_bl.c
44342@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44343 static unsigned long kb3886bl_flags;
44344 #define KB3886BL_SUSPENDED 0x01
44345
44346-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44347+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44348 {
44349 .ident = "Sahara Touch-iT",
44350 .matches = {
44351diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44352index 88cad6b..dd746c7 100644
44353--- a/drivers/video/fb_defio.c
44354+++ b/drivers/video/fb_defio.c
44355@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44356
44357 BUG_ON(!fbdefio);
44358 mutex_init(&fbdefio->lock);
44359- info->fbops->fb_mmap = fb_deferred_io_mmap;
44360+ pax_open_kernel();
44361+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44362+ pax_close_kernel();
44363 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
44364 INIT_LIST_HEAD(&fbdefio->pagelist);
44365 if (fbdefio->delay == 0) /* set a default of 1 s */
44366@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
44367 page->mapping = NULL;
44368 }
44369
44370- info->fbops->fb_mmap = NULL;
44371+ *(void **)&info->fbops->fb_mmap = NULL;
44372 mutex_destroy(&fbdefio->lock);
44373 }
44374 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
44375diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
44376index 5c3960d..15cf8fc 100644
44377--- a/drivers/video/fbcmap.c
44378+++ b/drivers/video/fbcmap.c
44379@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
44380 rc = -ENODEV;
44381 goto out;
44382 }
44383- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
44384- !info->fbops->fb_setcmap)) {
44385+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
44386 rc = -EINVAL;
44387 goto out1;
44388 }
44389diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
44390index dc61c12..e29796e 100644
44391--- a/drivers/video/fbmem.c
44392+++ b/drivers/video/fbmem.c
44393@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44394 image->dx += image->width + 8;
44395 }
44396 } else if (rotate == FB_ROTATE_UD) {
44397- for (x = 0; x < num && image->dx >= 0; x++) {
44398+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
44399 info->fbops->fb_imageblit(info, image);
44400 image->dx -= image->width + 8;
44401 }
44402@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44403 image->dy += image->height + 8;
44404 }
44405 } else if (rotate == FB_ROTATE_CCW) {
44406- for (x = 0; x < num && image->dy >= 0; x++) {
44407+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
44408 info->fbops->fb_imageblit(info, image);
44409 image->dy -= image->height + 8;
44410 }
44411@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
44412 return -EFAULT;
44413 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
44414 return -EINVAL;
44415- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
44416+ if (con2fb.framebuffer >= FB_MAX)
44417 return -EINVAL;
44418 if (!registered_fb[con2fb.framebuffer])
44419 request_module("fb%d", con2fb.framebuffer);
44420diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
44421index 7672d2e..b56437f 100644
44422--- a/drivers/video/i810/i810_accel.c
44423+++ b/drivers/video/i810/i810_accel.c
44424@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
44425 }
44426 }
44427 printk("ringbuffer lockup!!!\n");
44428+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
44429 i810_report_error(mmio);
44430 par->dev_flags |= LOCKUP;
44431 info->pixmap.scan_align = 1;
44432diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
44433index 3c14e43..eafa544 100644
44434--- a/drivers/video/logo/logo_linux_clut224.ppm
44435+++ b/drivers/video/logo/logo_linux_clut224.ppm
44436@@ -1,1604 +1,1123 @@
44437 P3
44438-# Standard 224-color Linux logo
44439 80 80
44440 255
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 0 0 0 0 0 0 0
44444- 0 0 0 0 0 0 0 0 0 0 0 0
44445- 0 0 0 0 0 0 0 0 0 0 0 0
44446- 0 0 0 0 0 0 0 0 0 0 0 0
44447- 0 0 0 0 0 0 0 0 0 0 0 0
44448- 0 0 0 0 0 0 0 0 0 0 0 0
44449- 0 0 0 0 0 0 0 0 0 0 0 0
44450- 6 6 6 6 6 6 10 10 10 10 10 10
44451- 10 10 10 6 6 6 6 6 6 6 6 6
44452- 0 0 0 0 0 0 0 0 0 0 0 0
44453- 0 0 0 0 0 0 0 0 0 0 0 0
44454- 0 0 0 0 0 0 0 0 0 0 0 0
44455- 0 0 0 0 0 0 0 0 0 0 0 0
44456- 0 0 0 0 0 0 0 0 0 0 0 0
44457- 0 0 0 0 0 0 0 0 0 0 0 0
44458- 0 0 0 0 0 0 0 0 0 0 0 0
44459- 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 0 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 6 6 6 10 10 10 14 14 14
44470- 22 22 22 26 26 26 30 30 30 34 34 34
44471- 30 30 30 30 30 30 26 26 26 18 18 18
44472- 14 14 14 10 10 10 6 6 6 0 0 0
44473- 0 0 0 0 0 0 0 0 0 0 0 0
44474- 0 0 0 0 0 0 0 0 0 0 0 0
44475- 0 0 0 0 0 0 0 0 0 0 0 0
44476- 0 0 0 0 0 0 0 0 0 0 0 0
44477- 0 0 0 0 0 0 0 0 0 0 0 0
44478- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
44483- 0 0 0 0 0 0 0 0 0 0 0 0
44484- 0 0 0 0 0 0 0 0 0 0 0 0
44485- 0 0 0 0 0 0 0 0 0 0 0 0
44486- 0 0 0 0 0 0 0 0 0 0 0 0
44487- 0 0 0 0 0 0 0 0 0 0 0 0
44488- 0 0 0 0 0 0 0 0 0 0 0 0
44489- 6 6 6 14 14 14 26 26 26 42 42 42
44490- 54 54 54 66 66 66 78 78 78 78 78 78
44491- 78 78 78 74 74 74 66 66 66 54 54 54
44492- 42 42 42 26 26 26 18 18 18 10 10 10
44493- 6 6 6 0 0 0 0 0 0 0 0 0
44494- 0 0 0 0 0 0 0 0 0 0 0 0
44495- 0 0 0 0 0 0 0 0 0 0 0 0
44496- 0 0 0 0 0 0 0 0 0 0 0 0
44497- 0 0 0 0 0 0 0 0 0 0 0 0
44498- 0 0 0 0 0 0 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 1 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 10 10 10
44509- 22 22 22 42 42 42 66 66 66 86 86 86
44510- 66 66 66 38 38 38 38 38 38 22 22 22
44511- 26 26 26 34 34 34 54 54 54 66 66 66
44512- 86 86 86 70 70 70 46 46 46 26 26 26
44513- 14 14 14 6 6 6 0 0 0 0 0 0
44514- 0 0 0 0 0 0 0 0 0 0 0 0
44515- 0 0 0 0 0 0 0 0 0 0 0 0
44516- 0 0 0 0 0 0 0 0 0 0 0 0
44517- 0 0 0 0 0 0 0 0 0 0 0 0
44518- 0 0 0 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 1 0 0 1 0 0 1 0 0 0
44523- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
44529- 50 50 50 82 82 82 58 58 58 6 6 6
44530- 2 2 6 2 2 6 2 2 6 2 2 6
44531- 2 2 6 2 2 6 2 2 6 2 2 6
44532- 6 6 6 54 54 54 86 86 86 66 66 66
44533- 38 38 38 18 18 18 6 6 6 0 0 0
44534- 0 0 0 0 0 0 0 0 0 0 0 0
44535- 0 0 0 0 0 0 0 0 0 0 0 0
44536- 0 0 0 0 0 0 0 0 0 0 0 0
44537- 0 0 0 0 0 0 0 0 0 0 0 0
44538- 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 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
44549- 78 78 78 34 34 34 2 2 6 2 2 6
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 6 6 6 70 70 70
44553- 78 78 78 46 46 46 22 22 22 6 6 6
44554- 0 0 0 0 0 0 0 0 0 0 0 0
44555- 0 0 0 0 0 0 0 0 0 0 0 0
44556- 0 0 0 0 0 0 0 0 0 0 0 0
44557- 0 0 0 0 0 0 0 0 0 0 0 0
44558- 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 1 0 0 1 0 0 1 0 0 0
44563- 0 0 0 0 0 0 0 0 0 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- 6 6 6 18 18 18 42 42 42 82 82 82
44569- 26 26 26 2 2 6 2 2 6 2 2 6
44570- 2 2 6 2 2 6 2 2 6 2 2 6
44571- 2 2 6 2 2 6 2 2 6 14 14 14
44572- 46 46 46 34 34 34 6 6 6 2 2 6
44573- 42 42 42 78 78 78 42 42 42 18 18 18
44574- 6 6 6 0 0 0 0 0 0 0 0 0
44575- 0 0 0 0 0 0 0 0 0 0 0 0
44576- 0 0 0 0 0 0 0 0 0 0 0 0
44577- 0 0 0 0 0 0 0 0 0 0 0 0
44578- 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 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
44589- 2 2 6 2 2 6 2 2 6 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 26 26 26
44592- 86 86 86 101 101 101 46 46 46 10 10 10
44593- 2 2 6 58 58 58 70 70 70 34 34 34
44594- 10 10 10 0 0 0 0 0 0 0 0 0
44595- 0 0 0 0 0 0 0 0 0 0 0 0
44596- 0 0 0 0 0 0 0 0 0 0 0 0
44597- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
44603- 0 0 0 0 0 0 0 0 0 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- 14 14 14 42 42 42 86 86 86 10 10 10
44609- 2 2 6 2 2 6 2 2 6 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 30 30 30
44612- 94 94 94 94 94 94 58 58 58 26 26 26
44613- 2 2 6 6 6 6 78 78 78 54 54 54
44614- 22 22 22 6 6 6 0 0 0 0 0 0
44615- 0 0 0 0 0 0 0 0 0 0 0 0
44616- 0 0 0 0 0 0 0 0 0 0 0 0
44617- 0 0 0 0 0 0 0 0 0 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 0 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 6 6 6
44628- 22 22 22 62 62 62 62 62 62 2 2 6
44629- 2 2 6 2 2 6 2 2 6 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 26 26 26
44632- 54 54 54 38 38 38 18 18 18 10 10 10
44633- 2 2 6 2 2 6 34 34 34 82 82 82
44634- 38 38 38 14 14 14 0 0 0 0 0 0
44635- 0 0 0 0 0 0 0 0 0 0 0 0
44636- 0 0 0 0 0 0 0 0 0 0 0 0
44637- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
44643- 0 0 0 0 0 0 0 0 0 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 6 6 6
44648- 30 30 30 78 78 78 30 30 30 2 2 6
44649- 2 2 6 2 2 6 2 2 6 2 2 6
44650- 2 2 6 2 2 6 2 2 6 2 2 6
44651- 2 2 6 2 2 6 2 2 6 10 10 10
44652- 10 10 10 2 2 6 2 2 6 2 2 6
44653- 2 2 6 2 2 6 2 2 6 78 78 78
44654- 50 50 50 18 18 18 6 6 6 0 0 0
44655- 0 0 0 0 0 0 0 0 0 0 0 0
44656- 0 0 0 0 0 0 0 0 0 0 0 0
44657- 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
44663- 0 0 0 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 10 10 10
44668- 38 38 38 86 86 86 14 14 14 2 2 6
44669- 2 2 6 2 2 6 2 2 6 2 2 6
44670- 2 2 6 2 2 6 2 2 6 2 2 6
44671- 2 2 6 2 2 6 2 2 6 2 2 6
44672- 2 2 6 2 2 6 2 2 6 2 2 6
44673- 2 2 6 2 2 6 2 2 6 54 54 54
44674- 66 66 66 26 26 26 6 6 6 0 0 0
44675- 0 0 0 0 0 0 0 0 0 0 0 0
44676- 0 0 0 0 0 0 0 0 0 0 0 0
44677- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
44683- 0 0 0 0 0 0 0 0 0 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 14 14 14
44688- 42 42 42 82 82 82 2 2 6 2 2 6
44689- 2 2 6 6 6 6 10 10 10 2 2 6
44690- 2 2 6 2 2 6 2 2 6 2 2 6
44691- 2 2 6 2 2 6 2 2 6 6 6 6
44692- 14 14 14 10 10 10 2 2 6 2 2 6
44693- 2 2 6 2 2 6 2 2 6 18 18 18
44694- 82 82 82 34 34 34 10 10 10 0 0 0
44695- 0 0 0 0 0 0 0 0 0 0 0 0
44696- 0 0 0 0 0 0 0 0 0 0 0 0
44697- 0 0 0 0 0 0 0 0 0 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 1 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 14 14 14
44708- 46 46 46 86 86 86 2 2 6 2 2 6
44709- 6 6 6 6 6 6 22 22 22 34 34 34
44710- 6 6 6 2 2 6 2 2 6 2 2 6
44711- 2 2 6 2 2 6 18 18 18 34 34 34
44712- 10 10 10 50 50 50 22 22 22 2 2 6
44713- 2 2 6 2 2 6 2 2 6 10 10 10
44714- 86 86 86 42 42 42 14 14 14 0 0 0
44715- 0 0 0 0 0 0 0 0 0 0 0 0
44716- 0 0 0 0 0 0 0 0 0 0 0 0
44717- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
44723- 0 0 0 0 0 0 0 0 0 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 14 14 14
44728- 46 46 46 86 86 86 2 2 6 2 2 6
44729- 38 38 38 116 116 116 94 94 94 22 22 22
44730- 22 22 22 2 2 6 2 2 6 2 2 6
44731- 14 14 14 86 86 86 138 138 138 162 162 162
44732-154 154 154 38 38 38 26 26 26 6 6 6
44733- 2 2 6 2 2 6 2 2 6 2 2 6
44734- 86 86 86 46 46 46 14 14 14 0 0 0
44735- 0 0 0 0 0 0 0 0 0 0 0 0
44736- 0 0 0 0 0 0 0 0 0 0 0 0
44737- 0 0 0 0 0 0 0 0 0 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 14 14 14
44748- 46 46 46 86 86 86 2 2 6 14 14 14
44749-134 134 134 198 198 198 195 195 195 116 116 116
44750- 10 10 10 2 2 6 2 2 6 6 6 6
44751-101 98 89 187 187 187 210 210 210 218 218 218
44752-214 214 214 134 134 134 14 14 14 6 6 6
44753- 2 2 6 2 2 6 2 2 6 2 2 6
44754- 86 86 86 50 50 50 18 18 18 6 6 6
44755- 0 0 0 0 0 0 0 0 0 0 0 0
44756- 0 0 0 0 0 0 0 0 0 0 0 0
44757- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
44762- 0 0 1 0 0 1 0 0 1 0 0 0
44763- 0 0 0 0 0 0 0 0 0 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 14 14 14
44768- 46 46 46 86 86 86 2 2 6 54 54 54
44769-218 218 218 195 195 195 226 226 226 246 246 246
44770- 58 58 58 2 2 6 2 2 6 30 30 30
44771-210 210 210 253 253 253 174 174 174 123 123 123
44772-221 221 221 234 234 234 74 74 74 2 2 6
44773- 2 2 6 2 2 6 2 2 6 2 2 6
44774- 70 70 70 58 58 58 22 22 22 6 6 6
44775- 0 0 0 0 0 0 0 0 0 0 0 0
44776- 0 0 0 0 0 0 0 0 0 0 0 0
44777- 0 0 0 0 0 0 0 0 0 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 0 0 0 0
44783- 0 0 0 0 0 0 0 0 0 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 14 14 14
44788- 46 46 46 82 82 82 2 2 6 106 106 106
44789-170 170 170 26 26 26 86 86 86 226 226 226
44790-123 123 123 10 10 10 14 14 14 46 46 46
44791-231 231 231 190 190 190 6 6 6 70 70 70
44792- 90 90 90 238 238 238 158 158 158 2 2 6
44793- 2 2 6 2 2 6 2 2 6 2 2 6
44794- 70 70 70 58 58 58 22 22 22 6 6 6
44795- 0 0 0 0 0 0 0 0 0 0 0 0
44796- 0 0 0 0 0 0 0 0 0 0 0 0
44797- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
44802- 0 0 1 0 0 1 0 0 1 0 0 0
44803- 0 0 0 0 0 0 0 0 0 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 14 14 14
44808- 42 42 42 86 86 86 6 6 6 116 116 116
44809-106 106 106 6 6 6 70 70 70 149 149 149
44810-128 128 128 18 18 18 38 38 38 54 54 54
44811-221 221 221 106 106 106 2 2 6 14 14 14
44812- 46 46 46 190 190 190 198 198 198 2 2 6
44813- 2 2 6 2 2 6 2 2 6 2 2 6
44814- 74 74 74 62 62 62 22 22 22 6 6 6
44815- 0 0 0 0 0 0 0 0 0 0 0 0
44816- 0 0 0 0 0 0 0 0 0 0 0 0
44817- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
44822- 0 0 1 0 0 0 0 0 1 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 14 14 14
44828- 42 42 42 94 94 94 14 14 14 101 101 101
44829-128 128 128 2 2 6 18 18 18 116 116 116
44830-118 98 46 121 92 8 121 92 8 98 78 10
44831-162 162 162 106 106 106 2 2 6 2 2 6
44832- 2 2 6 195 195 195 195 195 195 6 6 6
44833- 2 2 6 2 2 6 2 2 6 2 2 6
44834- 74 74 74 62 62 62 22 22 22 6 6 6
44835- 0 0 0 0 0 0 0 0 0 0 0 0
44836- 0 0 0 0 0 0 0 0 0 0 0 0
44837- 0 0 0 0 0 0 0 0 0 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 1 0 0 1
44842- 0 0 1 0 0 0 0 0 1 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 10 10 10
44848- 38 38 38 90 90 90 14 14 14 58 58 58
44849-210 210 210 26 26 26 54 38 6 154 114 10
44850-226 170 11 236 186 11 225 175 15 184 144 12
44851-215 174 15 175 146 61 37 26 9 2 2 6
44852- 70 70 70 246 246 246 138 138 138 2 2 6
44853- 2 2 6 2 2 6 2 2 6 2 2 6
44854- 70 70 70 66 66 66 26 26 26 6 6 6
44855- 0 0 0 0 0 0 0 0 0 0 0 0
44856- 0 0 0 0 0 0 0 0 0 0 0 0
44857- 0 0 0 0 0 0 0 0 0 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 10 10 10
44868- 38 38 38 86 86 86 14 14 14 10 10 10
44869-195 195 195 188 164 115 192 133 9 225 175 15
44870-239 182 13 234 190 10 232 195 16 232 200 30
44871-245 207 45 241 208 19 232 195 16 184 144 12
44872-218 194 134 211 206 186 42 42 42 2 2 6
44873- 2 2 6 2 2 6 2 2 6 2 2 6
44874- 50 50 50 74 74 74 30 30 30 6 6 6
44875- 0 0 0 0 0 0 0 0 0 0 0 0
44876- 0 0 0 0 0 0 0 0 0 0 0 0
44877- 0 0 0 0 0 0 0 0 0 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 10 10 10
44888- 34 34 34 86 86 86 14 14 14 2 2 6
44889-121 87 25 192 133 9 219 162 10 239 182 13
44890-236 186 11 232 195 16 241 208 19 244 214 54
44891-246 218 60 246 218 38 246 215 20 241 208 19
44892-241 208 19 226 184 13 121 87 25 2 2 6
44893- 2 2 6 2 2 6 2 2 6 2 2 6
44894- 50 50 50 82 82 82 34 34 34 10 10 10
44895- 0 0 0 0 0 0 0 0 0 0 0 0
44896- 0 0 0 0 0 0 0 0 0 0 0 0
44897- 0 0 0 0 0 0 0 0 0 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 10 10 10
44908- 34 34 34 82 82 82 30 30 30 61 42 6
44909-180 123 7 206 145 10 230 174 11 239 182 13
44910-234 190 10 238 202 15 241 208 19 246 218 74
44911-246 218 38 246 215 20 246 215 20 246 215 20
44912-226 184 13 215 174 15 184 144 12 6 6 6
44913- 2 2 6 2 2 6 2 2 6 2 2 6
44914- 26 26 26 94 94 94 42 42 42 14 14 14
44915- 0 0 0 0 0 0 0 0 0 0 0 0
44916- 0 0 0 0 0 0 0 0 0 0 0 0
44917- 0 0 0 0 0 0 0 0 0 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 10 10 10
44928- 30 30 30 78 78 78 50 50 50 104 69 6
44929-192 133 9 216 158 10 236 178 12 236 186 11
44930-232 195 16 241 208 19 244 214 54 245 215 43
44931-246 215 20 246 215 20 241 208 19 198 155 10
44932-200 144 11 216 158 10 156 118 10 2 2 6
44933- 2 2 6 2 2 6 2 2 6 2 2 6
44934- 6 6 6 90 90 90 54 54 54 18 18 18
44935- 6 6 6 0 0 0 0 0 0 0 0 0
44936- 0 0 0 0 0 0 0 0 0 0 0 0
44937- 0 0 0 0 0 0 0 0 0 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 10 10 10
44948- 30 30 30 78 78 78 46 46 46 22 22 22
44949-137 92 6 210 162 10 239 182 13 238 190 10
44950-238 202 15 241 208 19 246 215 20 246 215 20
44951-241 208 19 203 166 17 185 133 11 210 150 10
44952-216 158 10 210 150 10 102 78 10 2 2 6
44953- 6 6 6 54 54 54 14 14 14 2 2 6
44954- 2 2 6 62 62 62 74 74 74 30 30 30
44955- 10 10 10 0 0 0 0 0 0 0 0 0
44956- 0 0 0 0 0 0 0 0 0 0 0 0
44957- 0 0 0 0 0 0 0 0 0 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 10 10 10
44968- 34 34 34 78 78 78 50 50 50 6 6 6
44969- 94 70 30 139 102 15 190 146 13 226 184 13
44970-232 200 30 232 195 16 215 174 15 190 146 13
44971-168 122 10 192 133 9 210 150 10 213 154 11
44972-202 150 34 182 157 106 101 98 89 2 2 6
44973- 2 2 6 78 78 78 116 116 116 58 58 58
44974- 2 2 6 22 22 22 90 90 90 46 46 46
44975- 18 18 18 6 6 6 0 0 0 0 0 0
44976- 0 0 0 0 0 0 0 0 0 0 0 0
44977- 0 0 0 0 0 0 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 10 10 10
44988- 38 38 38 86 86 86 50 50 50 6 6 6
44989-128 128 128 174 154 114 156 107 11 168 122 10
44990-198 155 10 184 144 12 197 138 11 200 144 11
44991-206 145 10 206 145 10 197 138 11 188 164 115
44992-195 195 195 198 198 198 174 174 174 14 14 14
44993- 2 2 6 22 22 22 116 116 116 116 116 116
44994- 22 22 22 2 2 6 74 74 74 70 70 70
44995- 30 30 30 10 10 10 0 0 0 0 0 0
44996- 0 0 0 0 0 0 0 0 0 0 0 0
44997- 0 0 0 0 0 0 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 6 6 6 18 18 18
45008- 50 50 50 101 101 101 26 26 26 10 10 10
45009-138 138 138 190 190 190 174 154 114 156 107 11
45010-197 138 11 200 144 11 197 138 11 192 133 9
45011-180 123 7 190 142 34 190 178 144 187 187 187
45012-202 202 202 221 221 221 214 214 214 66 66 66
45013- 2 2 6 2 2 6 50 50 50 62 62 62
45014- 6 6 6 2 2 6 10 10 10 90 90 90
45015- 50 50 50 18 18 18 6 6 6 0 0 0
45016- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
45028- 74 74 74 74 74 74 2 2 6 6 6 6
45029-144 144 144 198 198 198 190 190 190 178 166 146
45030-154 121 60 156 107 11 156 107 11 168 124 44
45031-174 154 114 187 187 187 190 190 190 210 210 210
45032-246 246 246 253 253 253 253 253 253 182 182 182
45033- 6 6 6 2 2 6 2 2 6 2 2 6
45034- 2 2 6 2 2 6 2 2 6 62 62 62
45035- 74 74 74 34 34 34 14 14 14 0 0 0
45036- 0 0 0 0 0 0 0 0 0 0 0 0
45037- 0 0 0 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 10 10 10 22 22 22 54 54 54
45048- 94 94 94 18 18 18 2 2 6 46 46 46
45049-234 234 234 221 221 221 190 190 190 190 190 190
45050-190 190 190 187 187 187 187 187 187 190 190 190
45051-190 190 190 195 195 195 214 214 214 242 242 242
45052-253 253 253 253 253 253 253 253 253 253 253 253
45053- 82 82 82 2 2 6 2 2 6 2 2 6
45054- 2 2 6 2 2 6 2 2 6 14 14 14
45055- 86 86 86 54 54 54 22 22 22 6 6 6
45056- 0 0 0 0 0 0 0 0 0 0 0 0
45057- 0 0 0 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
45068- 46 46 46 18 18 18 6 6 6 182 182 182
45069-253 253 253 246 246 246 206 206 206 190 190 190
45070-190 190 190 190 190 190 190 190 190 190 190 190
45071-206 206 206 231 231 231 250 250 250 253 253 253
45072-253 253 253 253 253 253 253 253 253 253 253 253
45073-202 202 202 14 14 14 2 2 6 2 2 6
45074- 2 2 6 2 2 6 2 2 6 2 2 6
45075- 42 42 42 86 86 86 42 42 42 18 18 18
45076- 6 6 6 0 0 0 0 0 0 0 0 0
45077- 0 0 0 0 0 0 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 6 6 6
45087- 14 14 14 38 38 38 74 74 74 66 66 66
45088- 2 2 6 6 6 6 90 90 90 250 250 250
45089-253 253 253 253 253 253 238 238 238 198 198 198
45090-190 190 190 190 190 190 195 195 195 221 221 221
45091-246 246 246 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 82 82 82 2 2 6 2 2 6
45094- 2 2 6 2 2 6 2 2 6 2 2 6
45095- 2 2 6 78 78 78 70 70 70 34 34 34
45096- 14 14 14 6 6 6 0 0 0 0 0 0
45097- 0 0 0 0 0 0 0 0 0 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 14 14 14
45107- 34 34 34 66 66 66 78 78 78 6 6 6
45108- 2 2 6 18 18 18 218 218 218 253 253 253
45109-253 253 253 253 253 253 253 253 253 246 246 246
45110-226 226 226 231 231 231 246 246 246 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 178 178 178 2 2 6 2 2 6
45114- 2 2 6 2 2 6 2 2 6 2 2 6
45115- 2 2 6 18 18 18 90 90 90 62 62 62
45116- 30 30 30 10 10 10 0 0 0 0 0 0
45117- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 26 26 26
45127- 58 58 58 90 90 90 18 18 18 2 2 6
45128- 2 2 6 110 110 110 253 253 253 253 253 253
45129-253 253 253 253 253 253 253 253 253 253 253 253
45130-250 250 250 253 253 253 253 253 253 253 253 253
45131-253 253 253 253 253 253 253 253 253 253 253 253
45132-253 253 253 253 253 253 253 253 253 253 253 253
45133-253 253 253 231 231 231 18 18 18 2 2 6
45134- 2 2 6 2 2 6 2 2 6 2 2 6
45135- 2 2 6 2 2 6 18 18 18 94 94 94
45136- 54 54 54 26 26 26 10 10 10 0 0 0
45137- 0 0 0 0 0 0 0 0 0 0 0 0
45138- 0 0 0 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 6 6 6 22 22 22 50 50 50
45147- 90 90 90 26 26 26 2 2 6 2 2 6
45148- 14 14 14 195 195 195 250 250 250 253 253 253
45149-253 253 253 253 253 253 253 253 253 253 253 253
45150-253 253 253 253 253 253 253 253 253 253 253 253
45151-253 253 253 253 253 253 253 253 253 253 253 253
45152-253 253 253 253 253 253 253 253 253 253 253 253
45153-250 250 250 242 242 242 54 54 54 2 2 6
45154- 2 2 6 2 2 6 2 2 6 2 2 6
45155- 2 2 6 2 2 6 2 2 6 38 38 38
45156- 86 86 86 50 50 50 22 22 22 6 6 6
45157- 0 0 0 0 0 0 0 0 0 0 0 0
45158- 0 0 0 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- 6 6 6 14 14 14 38 38 38 82 82 82
45167- 34 34 34 2 2 6 2 2 6 2 2 6
45168- 42 42 42 195 195 195 246 246 246 253 253 253
45169-253 253 253 253 253 253 253 253 253 250 250 250
45170-242 242 242 242 242 242 250 250 250 253 253 253
45171-253 253 253 253 253 253 253 253 253 253 253 253
45172-253 253 253 250 250 250 246 246 246 238 238 238
45173-226 226 226 231 231 231 101 101 101 6 6 6
45174- 2 2 6 2 2 6 2 2 6 2 2 6
45175- 2 2 6 2 2 6 2 2 6 2 2 6
45176- 38 38 38 82 82 82 42 42 42 14 14 14
45177- 6 6 6 0 0 0 0 0 0 0 0 0
45178- 0 0 0 0 0 0 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- 10 10 10 26 26 26 62 62 62 66 66 66
45187- 2 2 6 2 2 6 2 2 6 6 6 6
45188- 70 70 70 170 170 170 206 206 206 234 234 234
45189-246 246 246 250 250 250 250 250 250 238 238 238
45190-226 226 226 231 231 231 238 238 238 250 250 250
45191-250 250 250 250 250 250 246 246 246 231 231 231
45192-214 214 214 206 206 206 202 202 202 202 202 202
45193-198 198 198 202 202 202 182 182 182 18 18 18
45194- 2 2 6 2 2 6 2 2 6 2 2 6
45195- 2 2 6 2 2 6 2 2 6 2 2 6
45196- 2 2 6 62 62 62 66 66 66 30 30 30
45197- 10 10 10 0 0 0 0 0 0 0 0 0
45198- 0 0 0 0 0 0 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- 14 14 14 42 42 42 82 82 82 18 18 18
45207- 2 2 6 2 2 6 2 2 6 10 10 10
45208- 94 94 94 182 182 182 218 218 218 242 242 242
45209-250 250 250 253 253 253 253 253 253 250 250 250
45210-234 234 234 253 253 253 253 253 253 253 253 253
45211-253 253 253 253 253 253 253 253 253 246 246 246
45212-238 238 238 226 226 226 210 210 210 202 202 202
45213-195 195 195 195 195 195 210 210 210 158 158 158
45214- 6 6 6 14 14 14 50 50 50 14 14 14
45215- 2 2 6 2 2 6 2 2 6 2 2 6
45216- 2 2 6 6 6 6 86 86 86 46 46 46
45217- 18 18 18 6 6 6 0 0 0 0 0 0
45218- 0 0 0 0 0 0 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 6 6 6
45226- 22 22 22 54 54 54 70 70 70 2 2 6
45227- 2 2 6 10 10 10 2 2 6 22 22 22
45228-166 166 166 231 231 231 250 250 250 253 253 253
45229-253 253 253 253 253 253 253 253 253 250 250 250
45230-242 242 242 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 246 246 246
45233-231 231 231 206 206 206 198 198 198 226 226 226
45234- 94 94 94 2 2 6 6 6 6 38 38 38
45235- 30 30 30 2 2 6 2 2 6 2 2 6
45236- 2 2 6 2 2 6 62 62 62 66 66 66
45237- 26 26 26 10 10 10 0 0 0 0 0 0
45238- 0 0 0 0 0 0 0 0 0 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 10 10 10
45246- 30 30 30 74 74 74 50 50 50 2 2 6
45247- 26 26 26 26 26 26 2 2 6 106 106 106
45248-238 238 238 253 253 253 253 253 253 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 246 246 246 218 218 218 202 202 202
45254-210 210 210 14 14 14 2 2 6 2 2 6
45255- 30 30 30 22 22 22 2 2 6 2 2 6
45256- 2 2 6 2 2 6 18 18 18 86 86 86
45257- 42 42 42 14 14 14 0 0 0 0 0 0
45258- 0 0 0 0 0 0 0 0 0 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 14 14 14
45266- 42 42 42 90 90 90 22 22 22 2 2 6
45267- 42 42 42 2 2 6 18 18 18 218 218 218
45268-253 253 253 253 253 253 253 253 253 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 253 253 253
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 250 250 250 221 221 221
45274-218 218 218 101 101 101 2 2 6 14 14 14
45275- 18 18 18 38 38 38 10 10 10 2 2 6
45276- 2 2 6 2 2 6 2 2 6 78 78 78
45277- 58 58 58 22 22 22 6 6 6 0 0 0
45278- 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
45286- 54 54 54 82 82 82 2 2 6 26 26 26
45287- 22 22 22 2 2 6 123 123 123 253 253 253
45288-253 253 253 253 253 253 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 253 253 253 253 253 253
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 250 250 250
45294-238 238 238 198 198 198 6 6 6 38 38 38
45295- 58 58 58 26 26 26 38 38 38 2 2 6
45296- 2 2 6 2 2 6 2 2 6 46 46 46
45297- 78 78 78 30 30 30 10 10 10 0 0 0
45298- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 30 30 30
45306- 74 74 74 58 58 58 2 2 6 42 42 42
45307- 2 2 6 22 22 22 231 231 231 253 253 253
45308-253 253 253 253 253 253 253 253 253 253 253 253
45309-253 253 253 253 253 253 253 253 253 250 250 250
45310-253 253 253 253 253 253 253 253 253 253 253 253
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 246 246 246 46 46 46 38 38 38
45315- 42 42 42 14 14 14 38 38 38 14 14 14
45316- 2 2 6 2 2 6 2 2 6 6 6 6
45317- 86 86 86 46 46 46 14 14 14 0 0 0
45318- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 14 14 14 42 42 42
45326- 90 90 90 18 18 18 18 18 18 26 26 26
45327- 2 2 6 116 116 116 253 253 253 253 253 253
45328-253 253 253 253 253 253 253 253 253 253 253 253
45329-253 253 253 253 253 253 250 250 250 238 238 238
45330-253 253 253 253 253 253 253 253 253 253 253 253
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 94 94 94 6 6 6
45335- 2 2 6 2 2 6 10 10 10 34 34 34
45336- 2 2 6 2 2 6 2 2 6 2 2 6
45337- 74 74 74 58 58 58 22 22 22 6 6 6
45338- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 26 26 26 66 66 66
45346- 82 82 82 2 2 6 38 38 38 6 6 6
45347- 14 14 14 210 210 210 253 253 253 253 253 253
45348-253 253 253 253 253 253 253 253 253 253 253 253
45349-253 253 253 253 253 253 246 246 246 242 242 242
45350-253 253 253 253 253 253 253 253 253 253 253 253
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 144 144 144 2 2 6
45355- 2 2 6 2 2 6 2 2 6 46 46 46
45356- 2 2 6 2 2 6 2 2 6 2 2 6
45357- 42 42 42 74 74 74 30 30 30 10 10 10
45358- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 14 14 14 42 42 42 90 90 90
45366- 26 26 26 6 6 6 42 42 42 2 2 6
45367- 74 74 74 250 250 250 253 253 253 253 253 253
45368-253 253 253 253 253 253 253 253 253 253 253 253
45369-253 253 253 253 253 253 242 242 242 242 242 242
45370-253 253 253 253 253 253 253 253 253 253 253 253
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 182 182 182 2 2 6
45375- 2 2 6 2 2 6 2 2 6 46 46 46
45376- 2 2 6 2 2 6 2 2 6 2 2 6
45377- 10 10 10 86 86 86 38 38 38 10 10 10
45378- 0 0 0 0 0 0 0 0 0 0 0 0
45379- 0 0 0 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- 10 10 10 26 26 26 66 66 66 82 82 82
45386- 2 2 6 22 22 22 18 18 18 2 2 6
45387-149 149 149 253 253 253 253 253 253 253 253 253
45388-253 253 253 253 253 253 253 253 253 253 253 253
45389-253 253 253 253 253 253 234 234 234 242 242 242
45390-253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
45395- 2 2 6 2 2 6 2 2 6 38 38 38
45396- 2 2 6 2 2 6 2 2 6 2 2 6
45397- 6 6 6 86 86 86 46 46 46 14 14 14
45398- 0 0 0 0 0 0 0 0 0 0 0 0
45399- 0 0 0 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 6 6 6
45405- 18 18 18 46 46 46 86 86 86 18 18 18
45406- 2 2 6 34 34 34 10 10 10 6 6 6
45407-210 210 210 253 253 253 253 253 253 253 253 253
45408-253 253 253 253 253 253 253 253 253 253 253 253
45409-253 253 253 253 253 253 234 234 234 242 242 242
45410-253 253 253 253 253 253 253 253 253 253 253 253
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 221 221 221 6 6 6
45415- 2 2 6 2 2 6 6 6 6 30 30 30
45416- 2 2 6 2 2 6 2 2 6 2 2 6
45417- 2 2 6 82 82 82 54 54 54 18 18 18
45418- 6 6 6 0 0 0 0 0 0 0 0 0
45419- 0 0 0 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 10 10 10
45425- 26 26 26 66 66 66 62 62 62 2 2 6
45426- 2 2 6 38 38 38 10 10 10 26 26 26
45427-238 238 238 253 253 253 253 253 253 253 253 253
45428-253 253 253 253 253 253 253 253 253 253 253 253
45429-253 253 253 253 253 253 231 231 231 238 238 238
45430-253 253 253 253 253 253 253 253 253 253 253 253
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 231 231 231 6 6 6
45435- 2 2 6 2 2 6 10 10 10 30 30 30
45436- 2 2 6 2 2 6 2 2 6 2 2 6
45437- 2 2 6 66 66 66 58 58 58 22 22 22
45438- 6 6 6 0 0 0 0 0 0 0 0 0
45439- 0 0 0 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 10 10 10
45445- 38 38 38 78 78 78 6 6 6 2 2 6
45446- 2 2 6 46 46 46 14 14 14 42 42 42
45447-246 246 246 253 253 253 253 253 253 253 253 253
45448-253 253 253 253 253 253 253 253 253 253 253 253
45449-253 253 253 253 253 253 231 231 231 242 242 242
45450-253 253 253 253 253 253 253 253 253 253 253 253
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 234 234 234 10 10 10
45455- 2 2 6 2 2 6 22 22 22 14 14 14
45456- 2 2 6 2 2 6 2 2 6 2 2 6
45457- 2 2 6 66 66 66 62 62 62 22 22 22
45458- 6 6 6 0 0 0 0 0 0 0 0 0
45459- 0 0 0 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 6 6 6 18 18 18
45465- 50 50 50 74 74 74 2 2 6 2 2 6
45466- 14 14 14 70 70 70 34 34 34 62 62 62
45467-250 250 250 253 253 253 253 253 253 253 253 253
45468-253 253 253 253 253 253 253 253 253 253 253 253
45469-253 253 253 253 253 253 231 231 231 246 246 246
45470-253 253 253 253 253 253 253 253 253 253 253 253
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 234 234 234 14 14 14
45475- 2 2 6 2 2 6 30 30 30 2 2 6
45476- 2 2 6 2 2 6 2 2 6 2 2 6
45477- 2 2 6 66 66 66 62 62 62 22 22 22
45478- 6 6 6 0 0 0 0 0 0 0 0 0
45479- 0 0 0 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 6 6 6 18 18 18
45485- 54 54 54 62 62 62 2 2 6 2 2 6
45486- 2 2 6 30 30 30 46 46 46 70 70 70
45487-250 250 250 253 253 253 253 253 253 253 253 253
45488-253 253 253 253 253 253 253 253 253 253 253 253
45489-253 253 253 253 253 253 231 231 231 246 246 246
45490-253 253 253 253 253 253 253 253 253 253 253 253
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 226 226 226 10 10 10
45495- 2 2 6 6 6 6 30 30 30 2 2 6
45496- 2 2 6 2 2 6 2 2 6 2 2 6
45497- 2 2 6 66 66 66 58 58 58 22 22 22
45498- 6 6 6 0 0 0 0 0 0 0 0 0
45499- 0 0 0 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 6 6 6 22 22 22
45505- 58 58 58 62 62 62 2 2 6 2 2 6
45506- 2 2 6 2 2 6 30 30 30 78 78 78
45507-250 250 250 253 253 253 253 253 253 253 253 253
45508-253 253 253 253 253 253 253 253 253 253 253 253
45509-253 253 253 253 253 253 231 231 231 246 246 246
45510-253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
45515- 22 22 22 34 34 34 18 14 6 22 22 22
45516- 26 26 26 18 18 18 6 6 6 2 2 6
45517- 2 2 6 82 82 82 54 54 54 18 18 18
45518- 6 6 6 0 0 0 0 0 0 0 0 0
45519- 0 0 0 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 0 0 0 6 6 6 26 26 26
45525- 62 62 62 106 106 106 74 54 14 185 133 11
45526-210 162 10 121 92 8 6 6 6 62 62 62
45527-238 238 238 253 253 253 253 253 253 253 253 253
45528-253 253 253 253 253 253 253 253 253 253 253 253
45529-253 253 253 253 253 253 231 231 231 246 246 246
45530-253 253 253 253 253 253 253 253 253 253 253 253
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 158 158 158 18 18 18
45535- 14 14 14 2 2 6 2 2 6 2 2 6
45536- 6 6 6 18 18 18 66 66 66 38 38 38
45537- 6 6 6 94 94 94 50 50 50 18 18 18
45538- 6 6 6 0 0 0 0 0 0 0 0 0
45539- 0 0 0 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 6 6 6
45544- 10 10 10 10 10 10 18 18 18 38 38 38
45545- 78 78 78 142 134 106 216 158 10 242 186 14
45546-246 190 14 246 190 14 156 118 10 10 10 10
45547- 90 90 90 238 238 238 253 253 253 253 253 253
45548-253 253 253 253 253 253 253 253 253 253 253 253
45549-253 253 253 253 253 253 231 231 231 250 250 250
45550-253 253 253 253 253 253 253 253 253 253 253 253
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 246 230 190
45554-238 204 91 238 204 91 181 142 44 37 26 9
45555- 2 2 6 2 2 6 2 2 6 2 2 6
45556- 2 2 6 2 2 6 38 38 38 46 46 46
45557- 26 26 26 106 106 106 54 54 54 18 18 18
45558- 6 6 6 0 0 0 0 0 0 0 0 0
45559- 0 0 0 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 6 6 6 14 14 14 22 22 22
45564- 30 30 30 38 38 38 50 50 50 70 70 70
45565-106 106 106 190 142 34 226 170 11 242 186 14
45566-246 190 14 246 190 14 246 190 14 154 114 10
45567- 6 6 6 74 74 74 226 226 226 253 253 253
45568-253 253 253 253 253 253 253 253 253 253 253 253
45569-253 253 253 253 253 253 231 231 231 250 250 250
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 228 184 62
45574-241 196 14 241 208 19 232 195 16 38 30 10
45575- 2 2 6 2 2 6 2 2 6 2 2 6
45576- 2 2 6 6 6 6 30 30 30 26 26 26
45577-203 166 17 154 142 90 66 66 66 26 26 26
45578- 6 6 6 0 0 0 0 0 0 0 0 0
45579- 0 0 0 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- 6 6 6 18 18 18 38 38 38 58 58 58
45584- 78 78 78 86 86 86 101 101 101 123 123 123
45585-175 146 61 210 150 10 234 174 13 246 186 14
45586-246 190 14 246 190 14 246 190 14 238 190 10
45587-102 78 10 2 2 6 46 46 46 198 198 198
45588-253 253 253 253 253 253 253 253 253 253 253 253
45589-253 253 253 253 253 253 234 234 234 242 242 242
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 224 178 62
45594-242 186 14 241 196 14 210 166 10 22 18 6
45595- 2 2 6 2 2 6 2 2 6 2 2 6
45596- 2 2 6 2 2 6 6 6 6 121 92 8
45597-238 202 15 232 195 16 82 82 82 34 34 34
45598- 10 10 10 0 0 0 0 0 0 0 0 0
45599- 0 0 0 0 0 0 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- 14 14 14 38 38 38 70 70 70 154 122 46
45604-190 142 34 200 144 11 197 138 11 197 138 11
45605-213 154 11 226 170 11 242 186 14 246 190 14
45606-246 190 14 246 190 14 246 190 14 246 190 14
45607-225 175 15 46 32 6 2 2 6 22 22 22
45608-158 158 158 250 250 250 253 253 253 253 253 253
45609-253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 242 242 242 224 178 62
45614-239 182 13 236 186 11 213 154 11 46 32 6
45615- 2 2 6 2 2 6 2 2 6 2 2 6
45616- 2 2 6 2 2 6 61 42 6 225 175 15
45617-238 190 10 236 186 11 112 100 78 42 42 42
45618- 14 14 14 0 0 0 0 0 0 0 0 0
45619- 0 0 0 0 0 0 0 0 0 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 6 6 6
45623- 22 22 22 54 54 54 154 122 46 213 154 11
45624-226 170 11 230 174 11 226 170 11 226 170 11
45625-236 178 12 242 186 14 246 190 14 246 190 14
45626-246 190 14 246 190 14 246 190 14 246 190 14
45627-241 196 14 184 144 12 10 10 10 2 2 6
45628- 6 6 6 116 116 116 242 242 242 253 253 253
45629-253 253 253 253 253 253 253 253 253 253 253 253
45630-253 253 253 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 231 231 231 198 198 198 214 170 54
45634-236 178 12 236 178 12 210 150 10 137 92 6
45635- 18 14 6 2 2 6 2 2 6 2 2 6
45636- 6 6 6 70 47 6 200 144 11 236 178 12
45637-239 182 13 239 182 13 124 112 88 58 58 58
45638- 22 22 22 6 6 6 0 0 0 0 0 0
45639- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
45643- 30 30 30 70 70 70 180 133 36 226 170 11
45644-239 182 13 242 186 14 242 186 14 246 186 14
45645-246 190 14 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 232 195 16 98 70 6 2 2 6
45648- 2 2 6 2 2 6 66 66 66 221 221 221
45649-253 253 253 253 253 253 253 253 253 253 253 253
45650-253 253 253 253 253 253 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 206 206 206 198 198 198 214 166 58
45654-230 174 11 230 174 11 216 158 10 192 133 9
45655-163 110 8 116 81 8 102 78 10 116 81 8
45656-167 114 7 197 138 11 226 170 11 239 182 13
45657-242 186 14 242 186 14 162 146 94 78 78 78
45658- 34 34 34 14 14 14 6 6 6 0 0 0
45659- 0 0 0 0 0 0 0 0 0 0 0 0
45660- 0 0 0 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 6 6 6
45663- 30 30 30 78 78 78 190 142 34 226 170 11
45664-239 182 13 246 190 14 246 190 14 246 190 14
45665-246 190 14 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 241 196 14 203 166 17 22 18 6
45668- 2 2 6 2 2 6 2 2 6 38 38 38
45669-218 218 218 253 253 253 253 253 253 253 253 253
45670-253 253 253 253 253 253 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-250 250 250 206 206 206 198 198 198 202 162 69
45674-226 170 11 236 178 12 224 166 10 210 150 10
45675-200 144 11 197 138 11 192 133 9 197 138 11
45676-210 150 10 226 170 11 242 186 14 246 190 14
45677-246 190 14 246 186 14 225 175 15 124 112 88
45678- 62 62 62 30 30 30 14 14 14 6 6 6
45679- 0 0 0 0 0 0 0 0 0 0 0 0
45680- 0 0 0 0 0 0 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 10 10 10
45683- 30 30 30 78 78 78 174 135 50 224 166 10
45684-239 182 13 246 190 14 246 190 14 246 190 14
45685-246 190 14 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 241 196 14 139 102 15
45688- 2 2 6 2 2 6 2 2 6 2 2 6
45689- 78 78 78 250 250 250 253 253 253 253 253 253
45690-253 253 253 253 253 253 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-250 250 250 214 214 214 198 198 198 190 150 46
45694-219 162 10 236 178 12 234 174 13 224 166 10
45695-216 158 10 213 154 11 213 154 11 216 158 10
45696-226 170 11 239 182 13 246 190 14 246 190 14
45697-246 190 14 246 190 14 242 186 14 206 162 42
45698-101 101 101 58 58 58 30 30 30 14 14 14
45699- 6 6 6 0 0 0 0 0 0 0 0 0
45700- 0 0 0 0 0 0 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 10 10 10
45703- 30 30 30 74 74 74 174 135 50 216 158 10
45704-236 178 12 246 190 14 246 190 14 246 190 14
45705-246 190 14 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 241 196 14 226 184 13
45708- 61 42 6 2 2 6 2 2 6 2 2 6
45709- 22 22 22 238 238 238 253 253 253 253 253 253
45710-253 253 253 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 226 226 226 187 187 187 180 133 36
45714-216 158 10 236 178 12 239 182 13 236 178 12
45715-230 174 11 226 170 11 226 170 11 230 174 11
45716-236 178 12 242 186 14 246 190 14 246 190 14
45717-246 190 14 246 190 14 246 186 14 239 182 13
45718-206 162 42 106 106 106 66 66 66 34 34 34
45719- 14 14 14 6 6 6 0 0 0 0 0 0
45720- 0 0 0 0 0 0 0 0 0 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 6 6 6
45723- 26 26 26 70 70 70 163 133 67 213 154 11
45724-236 178 12 246 190 14 246 190 14 246 190 14
45725-246 190 14 246 190 14 246 190 14 246 190 14
45726-246 190 14 246 190 14 246 190 14 246 190 14
45727-246 190 14 246 190 14 246 190 14 241 196 14
45728-190 146 13 18 14 6 2 2 6 2 2 6
45729- 46 46 46 246 246 246 253 253 253 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 221 221 221 86 86 86 156 107 11
45734-216 158 10 236 178 12 242 186 14 246 186 14
45735-242 186 14 239 182 13 239 182 13 242 186 14
45736-242 186 14 246 186 14 246 190 14 246 190 14
45737-246 190 14 246 190 14 246 190 14 246 190 14
45738-242 186 14 225 175 15 142 122 72 66 66 66
45739- 30 30 30 10 10 10 0 0 0 0 0 0
45740- 0 0 0 0 0 0 0 0 0 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 6 6 6
45743- 26 26 26 70 70 70 163 133 67 210 150 10
45744-236 178 12 246 190 14 246 190 14 246 190 14
45745-246 190 14 246 190 14 246 190 14 246 190 14
45746-246 190 14 246 190 14 246 190 14 246 190 14
45747-246 190 14 246 190 14 246 190 14 246 190 14
45748-232 195 16 121 92 8 34 34 34 106 106 106
45749-221 221 221 253 253 253 253 253 253 253 253 253
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-242 242 242 82 82 82 18 14 6 163 110 8
45754-216 158 10 236 178 12 242 186 14 246 190 14
45755-246 190 14 246 190 14 246 190 14 246 190 14
45756-246 190 14 246 190 14 246 190 14 246 190 14
45757-246 190 14 246 190 14 246 190 14 246 190 14
45758-246 190 14 246 190 14 242 186 14 163 133 67
45759- 46 46 46 18 18 18 6 6 6 0 0 0
45760- 0 0 0 0 0 0 0 0 0 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 10 10 10
45763- 30 30 30 78 78 78 163 133 67 210 150 10
45764-236 178 12 246 186 14 246 190 14 246 190 14
45765-246 190 14 246 190 14 246 190 14 246 190 14
45766-246 190 14 246 190 14 246 190 14 246 190 14
45767-246 190 14 246 190 14 246 190 14 246 190 14
45768-241 196 14 215 174 15 190 178 144 253 253 253
45769-253 253 253 253 253 253 253 253 253 253 253 253
45770-253 253 253 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 218 218 218
45773- 58 58 58 2 2 6 22 18 6 167 114 7
45774-216 158 10 236 178 12 246 186 14 246 190 14
45775-246 190 14 246 190 14 246 190 14 246 190 14
45776-246 190 14 246 190 14 246 190 14 246 190 14
45777-246 190 14 246 190 14 246 190 14 246 190 14
45778-246 190 14 246 186 14 242 186 14 190 150 46
45779- 54 54 54 22 22 22 6 6 6 0 0 0
45780- 0 0 0 0 0 0 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 14 14 14
45783- 38 38 38 86 86 86 180 133 36 213 154 11
45784-236 178 12 246 186 14 246 190 14 246 190 14
45785-246 190 14 246 190 14 246 190 14 246 190 14
45786-246 190 14 246 190 14 246 190 14 246 190 14
45787-246 190 14 246 190 14 246 190 14 246 190 14
45788-246 190 14 232 195 16 190 146 13 214 214 214
45789-253 253 253 253 253 253 253 253 253 253 253 253
45790-253 253 253 253 253 253 253 253 253 253 253 253
45791-253 253 253 253 253 253 253 253 253 253 253 253
45792-253 253 253 250 250 250 170 170 170 26 26 26
45793- 2 2 6 2 2 6 37 26 9 163 110 8
45794-219 162 10 239 182 13 246 186 14 246 190 14
45795-246 190 14 246 190 14 246 190 14 246 190 14
45796-246 190 14 246 190 14 246 190 14 246 190 14
45797-246 190 14 246 190 14 246 190 14 246 190 14
45798-246 186 14 236 178 12 224 166 10 142 122 72
45799- 46 46 46 18 18 18 6 6 6 0 0 0
45800- 0 0 0 0 0 0 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 6 6 6 18 18 18
45803- 50 50 50 109 106 95 192 133 9 224 166 10
45804-242 186 14 246 190 14 246 190 14 246 190 14
45805-246 190 14 246 190 14 246 190 14 246 190 14
45806-246 190 14 246 190 14 246 190 14 246 190 14
45807-246 190 14 246 190 14 246 190 14 246 190 14
45808-242 186 14 226 184 13 210 162 10 142 110 46
45809-226 226 226 253 253 253 253 253 253 253 253 253
45810-253 253 253 253 253 253 253 253 253 253 253 253
45811-253 253 253 253 253 253 253 253 253 253 253 253
45812-198 198 198 66 66 66 2 2 6 2 2 6
45813- 2 2 6 2 2 6 50 34 6 156 107 11
45814-219 162 10 239 182 13 246 186 14 246 190 14
45815-246 190 14 246 190 14 246 190 14 246 190 14
45816-246 190 14 246 190 14 246 190 14 246 190 14
45817-246 190 14 246 190 14 246 190 14 242 186 14
45818-234 174 13 213 154 11 154 122 46 66 66 66
45819- 30 30 30 10 10 10 0 0 0 0 0 0
45820- 0 0 0 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 6 6 6 22 22 22
45823- 58 58 58 154 121 60 206 145 10 234 174 13
45824-242 186 14 246 186 14 246 190 14 246 190 14
45825-246 190 14 246 190 14 246 190 14 246 190 14
45826-246 190 14 246 190 14 246 190 14 246 190 14
45827-246 190 14 246 190 14 246 190 14 246 190 14
45828-246 186 14 236 178 12 210 162 10 163 110 8
45829- 61 42 6 138 138 138 218 218 218 250 250 250
45830-253 253 253 253 253 253 253 253 253 250 250 250
45831-242 242 242 210 210 210 144 144 144 66 66 66
45832- 6 6 6 2 2 6 2 2 6 2 2 6
45833- 2 2 6 2 2 6 61 42 6 163 110 8
45834-216 158 10 236 178 12 246 190 14 246 190 14
45835-246 190 14 246 190 14 246 190 14 246 190 14
45836-246 190 14 246 190 14 246 190 14 246 190 14
45837-246 190 14 239 182 13 230 174 11 216 158 10
45838-190 142 34 124 112 88 70 70 70 38 38 38
45839- 18 18 18 6 6 6 0 0 0 0 0 0
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 6 6 6 22 22 22
45843- 62 62 62 168 124 44 206 145 10 224 166 10
45844-236 178 12 239 182 13 242 186 14 242 186 14
45845-246 186 14 246 190 14 246 190 14 246 190 14
45846-246 190 14 246 190 14 246 190 14 246 190 14
45847-246 190 14 246 190 14 246 190 14 246 190 14
45848-246 190 14 236 178 12 216 158 10 175 118 6
45849- 80 54 7 2 2 6 6 6 6 30 30 30
45850- 54 54 54 62 62 62 50 50 50 38 38 38
45851- 14 14 14 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 6 6 6 80 54 7 167 114 7
45854-213 154 11 236 178 12 246 190 14 246 190 14
45855-246 190 14 246 190 14 246 190 14 246 190 14
45856-246 190 14 242 186 14 239 182 13 239 182 13
45857-230 174 11 210 150 10 174 135 50 124 112 88
45858- 82 82 82 54 54 54 34 34 34 18 18 18
45859- 6 6 6 0 0 0 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 6 6 6 18 18 18
45863- 50 50 50 158 118 36 192 133 9 200 144 11
45864-216 158 10 219 162 10 224 166 10 226 170 11
45865-230 174 11 236 178 12 239 182 13 239 182 13
45866-242 186 14 246 186 14 246 190 14 246 190 14
45867-246 190 14 246 190 14 246 190 14 246 190 14
45868-246 186 14 230 174 11 210 150 10 163 110 8
45869-104 69 6 10 10 10 2 2 6 2 2 6
45870- 2 2 6 2 2 6 2 2 6 2 2 6
45871- 2 2 6 2 2 6 2 2 6 2 2 6
45872- 2 2 6 2 2 6 2 2 6 2 2 6
45873- 2 2 6 6 6 6 91 60 6 167 114 7
45874-206 145 10 230 174 11 242 186 14 246 190 14
45875-246 190 14 246 190 14 246 186 14 242 186 14
45876-239 182 13 230 174 11 224 166 10 213 154 11
45877-180 133 36 124 112 88 86 86 86 58 58 58
45878- 38 38 38 22 22 22 10 10 10 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 14 14 14
45883- 34 34 34 70 70 70 138 110 50 158 118 36
45884-167 114 7 180 123 7 192 133 9 197 138 11
45885-200 144 11 206 145 10 213 154 11 219 162 10
45886-224 166 10 230 174 11 239 182 13 242 186 14
45887-246 186 14 246 186 14 246 186 14 246 186 14
45888-239 182 13 216 158 10 185 133 11 152 99 6
45889-104 69 6 18 14 6 2 2 6 2 2 6
45890- 2 2 6 2 2 6 2 2 6 2 2 6
45891- 2 2 6 2 2 6 2 2 6 2 2 6
45892- 2 2 6 2 2 6 2 2 6 2 2 6
45893- 2 2 6 6 6 6 80 54 7 152 99 6
45894-192 133 9 219 162 10 236 178 12 239 182 13
45895-246 186 14 242 186 14 239 182 13 236 178 12
45896-224 166 10 206 145 10 192 133 9 154 121 60
45897- 94 94 94 62 62 62 42 42 42 22 22 22
45898- 14 14 14 6 6 6 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 6 6 6
45903- 18 18 18 34 34 34 58 58 58 78 78 78
45904-101 98 89 124 112 88 142 110 46 156 107 11
45905-163 110 8 167 114 7 175 118 6 180 123 7
45906-185 133 11 197 138 11 210 150 10 219 162 10
45907-226 170 11 236 178 12 236 178 12 234 174 13
45908-219 162 10 197 138 11 163 110 8 130 83 6
45909- 91 60 6 10 10 10 2 2 6 2 2 6
45910- 18 18 18 38 38 38 38 38 38 38 38 38
45911- 38 38 38 38 38 38 38 38 38 38 38 38
45912- 38 38 38 38 38 38 26 26 26 2 2 6
45913- 2 2 6 6 6 6 70 47 6 137 92 6
45914-175 118 6 200 144 11 219 162 10 230 174 11
45915-234 174 13 230 174 11 219 162 10 210 150 10
45916-192 133 9 163 110 8 124 112 88 82 82 82
45917- 50 50 50 30 30 30 14 14 14 6 6 6
45918- 0 0 0 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- 6 6 6 14 14 14 22 22 22 34 34 34
45924- 42 42 42 58 58 58 74 74 74 86 86 86
45925-101 98 89 122 102 70 130 98 46 121 87 25
45926-137 92 6 152 99 6 163 110 8 180 123 7
45927-185 133 11 197 138 11 206 145 10 200 144 11
45928-180 123 7 156 107 11 130 83 6 104 69 6
45929- 50 34 6 54 54 54 110 110 110 101 98 89
45930- 86 86 86 82 82 82 78 78 78 78 78 78
45931- 78 78 78 78 78 78 78 78 78 78 78 78
45932- 78 78 78 82 82 82 86 86 86 94 94 94
45933-106 106 106 101 101 101 86 66 34 124 80 6
45934-156 107 11 180 123 7 192 133 9 200 144 11
45935-206 145 10 200 144 11 192 133 9 175 118 6
45936-139 102 15 109 106 95 70 70 70 42 42 42
45937- 22 22 22 10 10 10 0 0 0 0 0 0
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 6 6 6 10 10 10
45944- 14 14 14 22 22 22 30 30 30 38 38 38
45945- 50 50 50 62 62 62 74 74 74 90 90 90
45946-101 98 89 112 100 78 121 87 25 124 80 6
45947-137 92 6 152 99 6 152 99 6 152 99 6
45948-138 86 6 124 80 6 98 70 6 86 66 30
45949-101 98 89 82 82 82 58 58 58 46 46 46
45950- 38 38 38 34 34 34 34 34 34 34 34 34
45951- 34 34 34 34 34 34 34 34 34 34 34 34
45952- 34 34 34 34 34 34 38 38 38 42 42 42
45953- 54 54 54 82 82 82 94 86 76 91 60 6
45954-134 86 6 156 107 11 167 114 7 175 118 6
45955-175 118 6 167 114 7 152 99 6 121 87 25
45956-101 98 89 62 62 62 34 34 34 18 18 18
45957- 6 6 6 0 0 0 0 0 0 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 6 6 6 6 6 6 10 10 10
45965- 18 18 18 22 22 22 30 30 30 42 42 42
45966- 50 50 50 66 66 66 86 86 86 101 98 89
45967-106 86 58 98 70 6 104 69 6 104 69 6
45968-104 69 6 91 60 6 82 62 34 90 90 90
45969- 62 62 62 38 38 38 22 22 22 14 14 14
45970- 10 10 10 10 10 10 10 10 10 10 10 10
45971- 10 10 10 10 10 10 6 6 6 10 10 10
45972- 10 10 10 10 10 10 10 10 10 14 14 14
45973- 22 22 22 42 42 42 70 70 70 89 81 66
45974- 80 54 7 104 69 6 124 80 6 137 92 6
45975-134 86 6 116 81 8 100 82 52 86 86 86
45976- 58 58 58 30 30 30 14 14 14 6 6 6
45977- 0 0 0 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 6 6 6 10 10 10 14 14 14
45986- 18 18 18 26 26 26 38 38 38 54 54 54
45987- 70 70 70 86 86 86 94 86 76 89 81 66
45988- 89 81 66 86 86 86 74 74 74 50 50 50
45989- 30 30 30 14 14 14 6 6 6 0 0 0
45990- 0 0 0 0 0 0 0 0 0 0 0 0
45991- 0 0 0 0 0 0 0 0 0 0 0 0
45992- 0 0 0 0 0 0 0 0 0 0 0 0
45993- 6 6 6 18 18 18 34 34 34 58 58 58
45994- 82 82 82 89 81 66 89 81 66 89 81 66
45995- 94 86 66 94 86 76 74 74 74 50 50 50
45996- 26 26 26 14 14 14 6 6 6 0 0 0
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- 0 0 0 0 0 0 0 0 0 0 0 0
46003- 0 0 0 0 0 0 0 0 0 0 0 0
46004- 0 0 0 0 0 0 0 0 0 0 0 0
46005- 0 0 0 0 0 0 0 0 0 0 0 0
46006- 6 6 6 6 6 6 14 14 14 18 18 18
46007- 30 30 30 38 38 38 46 46 46 54 54 54
46008- 50 50 50 42 42 42 30 30 30 18 18 18
46009- 10 10 10 0 0 0 0 0 0 0 0 0
46010- 0 0 0 0 0 0 0 0 0 0 0 0
46011- 0 0 0 0 0 0 0 0 0 0 0 0
46012- 0 0 0 0 0 0 0 0 0 0 0 0
46013- 0 0 0 6 6 6 14 14 14 26 26 26
46014- 38 38 38 50 50 50 58 58 58 58 58 58
46015- 54 54 54 42 42 42 30 30 30 18 18 18
46016- 10 10 10 0 0 0 0 0 0 0 0 0
46017- 0 0 0 0 0 0 0 0 0 0 0 0
46018- 0 0 0 0 0 0 0 0 0 0 0 0
46019- 0 0 0 0 0 0 0 0 0 0 0 0
46020- 0 0 0 0 0 0 0 0 0 0 0 0
46021- 0 0 0 0 0 0 0 0 0 0 0 0
46022- 0 0 0 0 0 0 0 0 0 0 0 0
46023- 0 0 0 0 0 0 0 0 0 0 0 0
46024- 0 0 0 0 0 0 0 0 0 0 0 0
46025- 0 0 0 0 0 0 0 0 0 0 0 0
46026- 0 0 0 0 0 0 0 0 0 6 6 6
46027- 6 6 6 10 10 10 14 14 14 18 18 18
46028- 18 18 18 14 14 14 10 10 10 6 6 6
46029- 0 0 0 0 0 0 0 0 0 0 0 0
46030- 0 0 0 0 0 0 0 0 0 0 0 0
46031- 0 0 0 0 0 0 0 0 0 0 0 0
46032- 0 0 0 0 0 0 0 0 0 0 0 0
46033- 0 0 0 0 0 0 0 0 0 6 6 6
46034- 14 14 14 18 18 18 22 22 22 22 22 22
46035- 18 18 18 14 14 14 10 10 10 6 6 6
46036- 0 0 0 0 0 0 0 0 0 0 0 0
46037- 0 0 0 0 0 0 0 0 0 0 0 0
46038- 0 0 0 0 0 0 0 0 0 0 0 0
46039- 0 0 0 0 0 0 0 0 0 0 0 0
46040- 0 0 0 0 0 0 0 0 0 0 0 0
46041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46052+4 4 4 4 4 4 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
46055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46066+4 4 4 4 4 4 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
46069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46080+4 4 4 4 4 4 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
46083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46094+4 4 4 4 4 4 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 4 4 4 4 4 4
46096+4 4 4 4 4 4
46097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46099+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46106+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46110+4 4 4 4 4 4
46111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46113+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46120+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46124+4 4 4 4 4 4
46125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46127+4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
46130+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46134+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46135+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46136+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46138+4 4 4 4 4 4
46139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46141+4 4 4 4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
46144+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46145+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46148+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46149+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46150+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46151+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46152+4 4 4 4 4 4
46153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46155+4 4 4 4 4 4 4 4 4 4 4 4 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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46158+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46159+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46162+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46163+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46164+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46165+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46166+4 4 4 4 4 4
46167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46170+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46171+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46172+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46173+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46175+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46176+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46177+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46178+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46179+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46180+4 4 4 4 4 4
46181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46184+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46185+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46186+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46187+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46188+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46189+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46190+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46191+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46192+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46193+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46194+4 4 4 4 4 4
46195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46198+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46199+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46200+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46201+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46202+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46203+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46204+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46205+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46206+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46207+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46208+4 4 4 4 4 4
46209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46211+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46212+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46213+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46214+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46215+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46216+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46217+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46218+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46219+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46220+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46221+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46222+4 4 4 4 4 4
46223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46225+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46226+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46227+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46228+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46229+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46230+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46231+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46232+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46233+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46234+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46235+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46236+4 4 4 4 4 4
46237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46239+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46240+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46241+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46242+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46243+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46244+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46245+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46246+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46247+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46248+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46249+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46250+4 4 4 4 4 4
46251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46253+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46254+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46255+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46256+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46257+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46258+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46259+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46260+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46261+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46262+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46263+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46264+4 4 4 4 4 4
46265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46266+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46267+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46268+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46269+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46270+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46271+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46272+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46273+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46274+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46275+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46276+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46277+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46278+4 4 4 4 4 4
46279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46280+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46281+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46282+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46283+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46284+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46285+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46286+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46287+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46288+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46289+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46290+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46291+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46292+0 0 0 4 4 4
46293+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46294+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46295+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46296+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46297+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46298+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46299+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46300+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46301+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46302+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46303+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46304+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46305+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46306+2 0 0 0 0 0
46307+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46308+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46309+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46310+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46311+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46312+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46313+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46314+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46315+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46316+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46317+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46318+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46319+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46320+37 38 37 0 0 0
46321+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46322+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46323+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46324+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46325+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46326+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46327+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46328+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46329+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46330+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46331+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46332+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46333+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46334+85 115 134 4 0 0
46335+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46336+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46337+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46338+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46339+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46340+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46341+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46342+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46343+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46344+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46345+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46346+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46347+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46348+60 73 81 4 0 0
46349+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46350+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46351+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46352+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46353+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46354+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46355+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46356+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46357+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46358+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46359+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46360+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46361+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46362+16 19 21 4 0 0
46363+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
46364+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
46365+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
46366+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
46367+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
46368+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
46369+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
46370+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
46371+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
46372+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
46373+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
46374+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
46375+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
46376+4 0 0 4 3 3
46377+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
46378+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
46379+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
46380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
46381+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
46382+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
46383+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
46384+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
46385+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
46386+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
46387+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
46388+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
46389+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
46390+3 2 2 4 4 4
46391+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
46392+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
46393+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
46394+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46395+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
46396+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
46397+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
46398+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
46399+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
46400+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
46401+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
46402+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
46403+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
46404+4 4 4 4 4 4
46405+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
46406+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
46407+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
46408+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
46409+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
46410+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
46411+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
46412+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
46413+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
46414+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
46415+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
46416+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
46417+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
46418+4 4 4 4 4 4
46419+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
46420+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
46421+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
46422+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
46423+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
46424+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46425+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
46426+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
46427+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
46428+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
46429+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
46430+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
46431+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
46432+5 5 5 5 5 5
46433+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
46434+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46435+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46436+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46437+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46438+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46439+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46440+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46441+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46442+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46443+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46444+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46445+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46446+5 5 5 4 4 4
46447+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46448+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46449+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46450+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46451+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46452+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46453+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46454+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46455+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46456+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46457+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46458+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46460+4 4 4 4 4 4
46461+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46462+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46463+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46464+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46465+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46466+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46467+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46468+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46469+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46470+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46471+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46472+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46474+4 4 4 4 4 4
46475+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46476+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46477+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46478+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46479+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46480+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46481+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46482+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46483+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46484+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46485+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46488+4 4 4 4 4 4
46489+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46490+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46491+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46492+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46493+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46494+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46495+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46496+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46497+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46498+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46499+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46502+4 4 4 4 4 4
46503+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46504+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46505+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46506+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46507+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46508+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46509+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46510+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46511+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46512+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46513+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46516+4 4 4 4 4 4
46517+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46518+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46519+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46520+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46521+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46522+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46523+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46524+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46525+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46526+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46527+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46530+4 4 4 4 4 4
46531+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46532+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46533+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46534+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46535+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46536+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46537+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46538+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46539+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46540+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46541+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46544+4 4 4 4 4 4
46545+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46546+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46547+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46548+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46549+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46550+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46551+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46552+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46553+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46554+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46555+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46558+4 4 4 4 4 4
46559+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46560+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46561+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46562+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46563+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46564+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46565+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46566+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46567+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46568+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46569+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46572+4 4 4 4 4 4
46573+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46574+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46575+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46576+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46577+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46578+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46579+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46580+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46581+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46582+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46583+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46586+4 4 4 4 4 4
46587+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46588+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46589+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46590+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46591+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46592+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46593+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46594+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46595+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46596+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46597+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46600+4 4 4 4 4 4
46601+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46602+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46603+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46604+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46605+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46606+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46607+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46608+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46609+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46610+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46611+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46614+4 4 4 4 4 4
46615+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46616+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46617+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46618+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46619+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46620+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46621+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46622+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46623+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46624+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46625+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46628+4 4 4 4 4 4
46629+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46630+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46631+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46632+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46633+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46634+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46635+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46636+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46637+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46638+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46639+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46642+4 4 4 4 4 4
46643+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46644+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46645+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46646+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46647+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46648+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46649+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46650+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46651+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46652+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46653+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46656+4 4 4 4 4 4
46657+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46658+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46659+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46660+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46661+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46662+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46663+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46664+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46665+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46666+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46667+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46670+4 4 4 4 4 4
46671+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46672+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46673+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46674+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46675+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46676+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46677+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46678+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46679+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46680+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46681+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46684+4 4 4 4 4 4
46685+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46686+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46687+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46688+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46689+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46690+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46691+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46692+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46693+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46694+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46695+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46698+4 4 4 4 4 4
46699+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46700+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46701+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46702+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46703+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46704+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46705+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46706+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46707+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46708+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46709+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46712+4 4 4 4 4 4
46713+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46714+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46715+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46716+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46717+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46718+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46719+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46720+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46721+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46722+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46723+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46726+4 4 4 4 4 4
46727+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46728+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46729+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46730+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46731+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46732+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46733+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46734+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46735+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46736+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46737+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46740+4 4 4 4 4 4
46741+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46742+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46743+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46744+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46745+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46746+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46747+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46748+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46749+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46750+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46751+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46754+4 4 4 4 4 4
46755+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46756+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46757+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46758+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46759+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46760+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46761+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46762+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46763+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46764+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46765+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46768+4 4 4 4 4 4
46769+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46770+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46771+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46772+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46773+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46774+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46775+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46776+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46777+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46778+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46779+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46782+4 4 4 4 4 4
46783+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46784+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46785+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46786+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46787+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46788+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46789+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46790+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46791+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46792+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46793+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46796+4 4 4 4 4 4
46797+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46798+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46799+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46800+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46801+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46802+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46803+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46804+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46805+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46806+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46807+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46810+4 4 4 4 4 4
46811+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46812+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46813+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46814+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46815+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46816+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46817+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46818+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46819+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46820+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46821+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46824+4 4 4 4 4 4
46825+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46826+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46827+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46828+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46829+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46830+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46831+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46833+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46834+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46835+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46838+4 4 4 4 4 4
46839+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46840+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46841+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46842+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46843+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46844+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46845+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46846+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46847+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46848+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46849+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46852+4 4 4 4 4 4
46853+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46854+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46855+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46856+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46857+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46858+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46859+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46860+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46861+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46862+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
46863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46866+4 4 4 4 4 4
46867+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46868+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46869+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46870+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46871+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46872+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46873+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46874+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46875+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46876+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
46881+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46882+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46883+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46884+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46885+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46886+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46887+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46888+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46889+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46890+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46892+4 4 4 4 4 4 4 4 4 4 4 4 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
46895+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46896+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46897+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46898+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46899+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46900+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46901+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46902+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46903+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46904+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46906+4 4 4 4 4 4 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
46909+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46910+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46911+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46912+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46913+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46914+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46915+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46916+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46917+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
46918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46920+4 4 4 4 4 4 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
46923+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46924+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46925+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46926+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46927+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46928+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46929+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46930+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46931+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
46932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46934+4 4 4 4 4 4 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
46937+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46938+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46939+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46940+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46941+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46942+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46943+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46944+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46945+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46948+4 4 4 4 4 4 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
46951+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46952+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46953+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46954+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46955+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46956+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46957+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46958+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
46959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46962+4 4 4 4 4 4 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
46965+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46966+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46967+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46968+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46969+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46970+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46971+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46972+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46976+4 4 4 4 4 4 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
46979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46980+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
46981+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46982+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
46983+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
46984+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
46985+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
46986+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
46987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46990+4 4 4 4 4 4 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
46993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46994+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
46995+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
46996+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
46997+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
46998+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
46999+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47000+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47004+4 4 4 4 4 4 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
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 5 5 5 5 5 5 5 5 5
47009+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47010+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47011+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47012+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47013+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47014+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47018+4 4 4 4 4 4 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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47024+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47025+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47026+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47027+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47028+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47032+4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 5 5 5
47038+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47039+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47040+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47041+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47046+4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
47052+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47053+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47054+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47055+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47060+4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
47066+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47067+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47068+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47069+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47074+4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
47080+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47081+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47082+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47083+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47088+4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
47094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47095+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47096+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47097+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47102+4 4 4 4 4 4 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
47105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47107+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47110+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47111+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47116+4 4 4 4 4 4 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
47119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47123+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47124+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47125+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47132+4 4 4 4 4 4
47133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47137+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47138+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47146+4 4 4 4 4 4
47147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47151+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47152+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47160+4 4 4 4 4 4
47161diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47162index fe92eed..106e085 100644
47163--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47164+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47165@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47166 struct mb862xxfb_par *par = info->par;
47167
47168 if (info->var.bits_per_pixel == 32) {
47169- info->fbops->fb_fillrect = cfb_fillrect;
47170- info->fbops->fb_copyarea = cfb_copyarea;
47171- info->fbops->fb_imageblit = cfb_imageblit;
47172+ pax_open_kernel();
47173+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47174+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47175+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47176+ pax_close_kernel();
47177 } else {
47178 outreg(disp, GC_L0EM, 3);
47179- info->fbops->fb_fillrect = mb86290fb_fillrect;
47180- info->fbops->fb_copyarea = mb86290fb_copyarea;
47181- info->fbops->fb_imageblit = mb86290fb_imageblit;
47182+ pax_open_kernel();
47183+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47184+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47185+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47186+ pax_close_kernel();
47187 }
47188 outreg(draw, GDC_REG_DRAW_BASE, 0);
47189 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47190diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47191index ff22871..b129bed 100644
47192--- a/drivers/video/nvidia/nvidia.c
47193+++ b/drivers/video/nvidia/nvidia.c
47194@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47195 info->fix.line_length = (info->var.xres_virtual *
47196 info->var.bits_per_pixel) >> 3;
47197 if (info->var.accel_flags) {
47198- info->fbops->fb_imageblit = nvidiafb_imageblit;
47199- info->fbops->fb_fillrect = nvidiafb_fillrect;
47200- info->fbops->fb_copyarea = nvidiafb_copyarea;
47201- info->fbops->fb_sync = nvidiafb_sync;
47202+ pax_open_kernel();
47203+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47204+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47205+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47206+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47207+ pax_close_kernel();
47208 info->pixmap.scan_align = 4;
47209 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47210 info->flags |= FBINFO_READS_FAST;
47211 NVResetGraphics(info);
47212 } else {
47213- info->fbops->fb_imageblit = cfb_imageblit;
47214- info->fbops->fb_fillrect = cfb_fillrect;
47215- info->fbops->fb_copyarea = cfb_copyarea;
47216- info->fbops->fb_sync = NULL;
47217+ pax_open_kernel();
47218+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47219+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47220+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47221+ *(void **)&info->fbops->fb_sync = NULL;
47222+ pax_close_kernel();
47223 info->pixmap.scan_align = 1;
47224 info->flags |= FBINFO_HWACCEL_DISABLED;
47225 info->flags &= ~FBINFO_READS_FAST;
47226@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47227 info->pixmap.size = 8 * 1024;
47228 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47229
47230- if (!hwcur)
47231- info->fbops->fb_cursor = NULL;
47232+ if (!hwcur) {
47233+ pax_open_kernel();
47234+ *(void **)&info->fbops->fb_cursor = NULL;
47235+ pax_close_kernel();
47236+ }
47237
47238 info->var.accel_flags = (!noaccel);
47239
47240diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47241index 76d9053..dec2bfd 100644
47242--- a/drivers/video/s1d13xxxfb.c
47243+++ b/drivers/video/s1d13xxxfb.c
47244@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47245
47246 switch(prod_id) {
47247 case S1D13506_PROD_ID: /* activate acceleration */
47248- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47249- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47250+ pax_open_kernel();
47251+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47252+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47253+ pax_close_kernel();
47254 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47255 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47256 break;
47257diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47258index 97bd662..39fab85 100644
47259--- a/drivers/video/smscufx.c
47260+++ b/drivers/video/smscufx.c
47261@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47262 fb_deferred_io_cleanup(info);
47263 kfree(info->fbdefio);
47264 info->fbdefio = NULL;
47265- info->fbops->fb_mmap = ufx_ops_mmap;
47266+ pax_open_kernel();
47267+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47268+ pax_close_kernel();
47269 }
47270
47271 pr_debug("released /dev/fb%d user=%d count=%d",
47272diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47273index 86d449e..8e04dc5 100644
47274--- a/drivers/video/udlfb.c
47275+++ b/drivers/video/udlfb.c
47276@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47277 dlfb_urb_completion(urb);
47278
47279 error:
47280- atomic_add(bytes_sent, &dev->bytes_sent);
47281- atomic_add(bytes_identical, &dev->bytes_identical);
47282- atomic_add(width*height*2, &dev->bytes_rendered);
47283+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47284+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47285+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47286 end_cycles = get_cycles();
47287- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47288+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47289 >> 10)), /* Kcycles */
47290 &dev->cpu_kcycles_used);
47291
47292@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47293 dlfb_urb_completion(urb);
47294
47295 error:
47296- atomic_add(bytes_sent, &dev->bytes_sent);
47297- atomic_add(bytes_identical, &dev->bytes_identical);
47298- atomic_add(bytes_rendered, &dev->bytes_rendered);
47299+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47300+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47301+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47302 end_cycles = get_cycles();
47303- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47304+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47305 >> 10)), /* Kcycles */
47306 &dev->cpu_kcycles_used);
47307 }
47308@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47309 fb_deferred_io_cleanup(info);
47310 kfree(info->fbdefio);
47311 info->fbdefio = NULL;
47312- info->fbops->fb_mmap = dlfb_ops_mmap;
47313+ pax_open_kernel();
47314+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47315+ pax_close_kernel();
47316 }
47317
47318 pr_warn("released /dev/fb%d user=%d count=%d\n",
47319@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47320 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47321 struct dlfb_data *dev = fb_info->par;
47322 return snprintf(buf, PAGE_SIZE, "%u\n",
47323- atomic_read(&dev->bytes_rendered));
47324+ atomic_read_unchecked(&dev->bytes_rendered));
47325 }
47326
47327 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47328@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47329 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47330 struct dlfb_data *dev = fb_info->par;
47331 return snprintf(buf, PAGE_SIZE, "%u\n",
47332- atomic_read(&dev->bytes_identical));
47333+ atomic_read_unchecked(&dev->bytes_identical));
47334 }
47335
47336 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47337@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47338 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47339 struct dlfb_data *dev = fb_info->par;
47340 return snprintf(buf, PAGE_SIZE, "%u\n",
47341- atomic_read(&dev->bytes_sent));
47342+ atomic_read_unchecked(&dev->bytes_sent));
47343 }
47344
47345 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47346@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47347 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47348 struct dlfb_data *dev = fb_info->par;
47349 return snprintf(buf, PAGE_SIZE, "%u\n",
47350- atomic_read(&dev->cpu_kcycles_used));
47351+ atomic_read_unchecked(&dev->cpu_kcycles_used));
47352 }
47353
47354 static ssize_t edid_show(
47355@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
47356 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47357 struct dlfb_data *dev = fb_info->par;
47358
47359- atomic_set(&dev->bytes_rendered, 0);
47360- atomic_set(&dev->bytes_identical, 0);
47361- atomic_set(&dev->bytes_sent, 0);
47362- atomic_set(&dev->cpu_kcycles_used, 0);
47363+ atomic_set_unchecked(&dev->bytes_rendered, 0);
47364+ atomic_set_unchecked(&dev->bytes_identical, 0);
47365+ atomic_set_unchecked(&dev->bytes_sent, 0);
47366+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
47367
47368 return count;
47369 }
47370diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
47371index b75db01..ad2f34a 100644
47372--- a/drivers/video/uvesafb.c
47373+++ b/drivers/video/uvesafb.c
47374@@ -19,6 +19,7 @@
47375 #include <linux/io.h>
47376 #include <linux/mutex.h>
47377 #include <linux/slab.h>
47378+#include <linux/moduleloader.h>
47379 #include <video/edid.h>
47380 #include <video/uvesafb.h>
47381 #ifdef CONFIG_X86
47382@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
47383 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
47384 par->pmi_setpal = par->ypan = 0;
47385 } else {
47386+
47387+#ifdef CONFIG_PAX_KERNEXEC
47388+#ifdef CONFIG_MODULES
47389+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
47390+#endif
47391+ if (!par->pmi_code) {
47392+ par->pmi_setpal = par->ypan = 0;
47393+ return 0;
47394+ }
47395+#endif
47396+
47397 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
47398 + task->t.regs.edi);
47399+
47400+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47401+ pax_open_kernel();
47402+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
47403+ pax_close_kernel();
47404+
47405+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
47406+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
47407+#else
47408 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
47409 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
47410+#endif
47411+
47412 printk(KERN_INFO "uvesafb: protected mode interface info at "
47413 "%04x:%04x\n",
47414 (u16)task->t.regs.es, (u16)task->t.regs.edi);
47415@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
47416 par->ypan = ypan;
47417
47418 if (par->pmi_setpal || par->ypan) {
47419+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
47420 if (__supported_pte_mask & _PAGE_NX) {
47421 par->pmi_setpal = par->ypan = 0;
47422 printk(KERN_WARNING "uvesafb: NX protection is actively."
47423 "We have better not to use the PMI.\n");
47424- } else {
47425+ } else
47426+#endif
47427 uvesafb_vbe_getpmi(task, par);
47428- }
47429 }
47430 #else
47431 /* The protected mode interface is not available on non-x86. */
47432@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47433 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
47434
47435 /* Disable blanking if the user requested so. */
47436- if (!blank)
47437- info->fbops->fb_blank = NULL;
47438+ if (!blank) {
47439+ pax_open_kernel();
47440+ *(void **)&info->fbops->fb_blank = NULL;
47441+ pax_close_kernel();
47442+ }
47443
47444 /*
47445 * Find out how much IO memory is required for the mode with
47446@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47447 info->flags = FBINFO_FLAG_DEFAULT |
47448 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47449
47450- if (!par->ypan)
47451- info->fbops->fb_pan_display = NULL;
47452+ if (!par->ypan) {
47453+ pax_open_kernel();
47454+ *(void **)&info->fbops->fb_pan_display = NULL;
47455+ pax_close_kernel();
47456+ }
47457 }
47458
47459 static void uvesafb_init_mtrr(struct fb_info *info)
47460@@ -1836,6 +1866,11 @@ out:
47461 if (par->vbe_modes)
47462 kfree(par->vbe_modes);
47463
47464+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47465+ if (par->pmi_code)
47466+ module_free_exec(NULL, par->pmi_code);
47467+#endif
47468+
47469 framebuffer_release(info);
47470 return err;
47471 }
47472@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47473 kfree(par->vbe_state_orig);
47474 if (par->vbe_state_saved)
47475 kfree(par->vbe_state_saved);
47476+
47477+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47478+ if (par->pmi_code)
47479+ module_free_exec(NULL, par->pmi_code);
47480+#endif
47481+
47482 }
47483
47484 framebuffer_release(info);
47485diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47486index 501b340..d80aa17 100644
47487--- a/drivers/video/vesafb.c
47488+++ b/drivers/video/vesafb.c
47489@@ -9,6 +9,7 @@
47490 */
47491
47492 #include <linux/module.h>
47493+#include <linux/moduleloader.h>
47494 #include <linux/kernel.h>
47495 #include <linux/errno.h>
47496 #include <linux/string.h>
47497@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47498 static int vram_total __initdata; /* Set total amount of memory */
47499 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47500 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47501-static void (*pmi_start)(void) __read_mostly;
47502-static void (*pmi_pal) (void) __read_mostly;
47503+static void (*pmi_start)(void) __read_only;
47504+static void (*pmi_pal) (void) __read_only;
47505 static int depth __read_mostly;
47506 static int vga_compat __read_mostly;
47507 /* --------------------------------------------------------------------- */
47508@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47509 unsigned int size_vmode;
47510 unsigned int size_remap;
47511 unsigned int size_total;
47512+ void *pmi_code = NULL;
47513
47514 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47515 return -ENODEV;
47516@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47517 size_remap = size_total;
47518 vesafb_fix.smem_len = size_remap;
47519
47520-#ifndef __i386__
47521- screen_info.vesapm_seg = 0;
47522-#endif
47523-
47524 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47525 printk(KERN_WARNING
47526 "vesafb: cannot reserve video memory at 0x%lx\n",
47527@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47528 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47529 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47530
47531+#ifdef __i386__
47532+
47533+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47534+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
47535+ if (!pmi_code)
47536+#elif !defined(CONFIG_PAX_KERNEXEC)
47537+ if (0)
47538+#endif
47539+
47540+#endif
47541+ screen_info.vesapm_seg = 0;
47542+
47543 if (screen_info.vesapm_seg) {
47544- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47545- screen_info.vesapm_seg,screen_info.vesapm_off);
47546+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47547+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47548 }
47549
47550 if (screen_info.vesapm_seg < 0xc000)
47551@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47552
47553 if (ypan || pmi_setpal) {
47554 unsigned short *pmi_base;
47555+
47556 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47557- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47558- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47559+
47560+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47561+ pax_open_kernel();
47562+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47563+#else
47564+ pmi_code = pmi_base;
47565+#endif
47566+
47567+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47568+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47569+
47570+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47571+ pmi_start = ktva_ktla(pmi_start);
47572+ pmi_pal = ktva_ktla(pmi_pal);
47573+ pax_close_kernel();
47574+#endif
47575+
47576 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47577 if (pmi_base[3]) {
47578 printk(KERN_INFO "vesafb: pmi: ports = ");
47579@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47580 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47581 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47582
47583- if (!ypan)
47584- info->fbops->fb_pan_display = NULL;
47585+ if (!ypan) {
47586+ pax_open_kernel();
47587+ *(void **)&info->fbops->fb_pan_display = NULL;
47588+ pax_close_kernel();
47589+ }
47590
47591 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47592 err = -ENOMEM;
47593@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47594 info->node, info->fix.id);
47595 return 0;
47596 err:
47597+
47598+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47599+ module_free_exec(NULL, pmi_code);
47600+#endif
47601+
47602 if (info->screen_base)
47603 iounmap(info->screen_base);
47604 framebuffer_release(info);
47605diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47606index 88714ae..16c2e11 100644
47607--- a/drivers/video/via/via_clock.h
47608+++ b/drivers/video/via/via_clock.h
47609@@ -56,7 +56,7 @@ struct via_clock {
47610
47611 void (*set_engine_pll_state)(u8 state);
47612 void (*set_engine_pll)(struct via_pll_config config);
47613-};
47614+} __no_const;
47615
47616
47617 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47618diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47619index fef20db..d28b1ab 100644
47620--- a/drivers/xen/xenfs/xenstored.c
47621+++ b/drivers/xen/xenfs/xenstored.c
47622@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47623 static int xsd_kva_open(struct inode *inode, struct file *file)
47624 {
47625 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47626+#ifdef CONFIG_GRKERNSEC_HIDESYM
47627+ NULL);
47628+#else
47629 xen_store_interface);
47630+#endif
47631+
47632 if (!file->private_data)
47633 return -ENOMEM;
47634 return 0;
47635diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47636index 890bed5..17ae73e 100644
47637--- a/fs/9p/vfs_inode.c
47638+++ b/fs/9p/vfs_inode.c
47639@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47640 void
47641 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47642 {
47643- char *s = nd_get_link(nd);
47644+ const char *s = nd_get_link(nd);
47645
47646 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47647 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47648diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47649index 0efd152..b5802ad 100644
47650--- a/fs/Kconfig.binfmt
47651+++ b/fs/Kconfig.binfmt
47652@@ -89,7 +89,7 @@ config HAVE_AOUT
47653
47654 config BINFMT_AOUT
47655 tristate "Kernel support for a.out and ECOFF binaries"
47656- depends on HAVE_AOUT
47657+ depends on HAVE_AOUT && BROKEN
47658 ---help---
47659 A.out (Assembler.OUTput) is a set of formats for libraries and
47660 executables used in the earliest versions of UNIX. Linux used
47661diff --git a/fs/aio.c b/fs/aio.c
47662index 71f613c..9d01f1f 100644
47663--- a/fs/aio.c
47664+++ b/fs/aio.c
47665@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47666 size += sizeof(struct io_event) * nr_events;
47667 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47668
47669- if (nr_pages < 0)
47670+ if (nr_pages <= 0)
47671 return -EINVAL;
47672
47673 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47674@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47675 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47676 {
47677 ssize_t ret;
47678+ struct iovec iovstack;
47679
47680 #ifdef CONFIG_COMPAT
47681 if (compat)
47682 ret = compat_rw_copy_check_uvector(type,
47683 (struct compat_iovec __user *)kiocb->ki_buf,
47684- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47685+ kiocb->ki_nbytes, 1, &iovstack,
47686 &kiocb->ki_iovec);
47687 else
47688 #endif
47689 ret = rw_copy_check_uvector(type,
47690 (struct iovec __user *)kiocb->ki_buf,
47691- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47692+ kiocb->ki_nbytes, 1, &iovstack,
47693 &kiocb->ki_iovec);
47694 if (ret < 0)
47695 goto out;
47696@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47697 if (ret < 0)
47698 goto out;
47699
47700+ if (kiocb->ki_iovec == &iovstack) {
47701+ kiocb->ki_inline_vec = iovstack;
47702+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
47703+ }
47704 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47705 kiocb->ki_cur_seg = 0;
47706 /* ki_nbytes/left now reflect bytes instead of segs */
47707diff --git a/fs/attr.c b/fs/attr.c
47708index 1449adb..a2038c2 100644
47709--- a/fs/attr.c
47710+++ b/fs/attr.c
47711@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47712 unsigned long limit;
47713
47714 limit = rlimit(RLIMIT_FSIZE);
47715+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47716 if (limit != RLIM_INFINITY && offset > limit)
47717 goto out_sig;
47718 if (offset > inode->i_sb->s_maxbytes)
47719diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47720index 03bc1d3..6205356 100644
47721--- a/fs/autofs4/waitq.c
47722+++ b/fs/autofs4/waitq.c
47723@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47724 {
47725 unsigned long sigpipe, flags;
47726 mm_segment_t fs;
47727- const char *data = (const char *)addr;
47728+ const char __user *data = (const char __force_user *)addr;
47729 ssize_t wr = 0;
47730
47731 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47732@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47733 return 1;
47734 }
47735
47736+#ifdef CONFIG_GRKERNSEC_HIDESYM
47737+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47738+#endif
47739+
47740 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47741 enum autofs_notify notify)
47742 {
47743@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47744
47745 /* If this is a direct mount request create a dummy name */
47746 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47747+#ifdef CONFIG_GRKERNSEC_HIDESYM
47748+ /* this name does get written to userland via autofs4_write() */
47749+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47750+#else
47751 qstr.len = sprintf(name, "%p", dentry);
47752+#endif
47753 else {
47754 qstr.len = autofs4_getpath(sbi, dentry, &name);
47755 if (!qstr.len) {
47756diff --git a/fs/befs/endian.h b/fs/befs/endian.h
47757index 2722387..c8dd2a7 100644
47758--- a/fs/befs/endian.h
47759+++ b/fs/befs/endian.h
47760@@ -11,7 +11,7 @@
47761
47762 #include <asm/byteorder.h>
47763
47764-static inline u64
47765+static inline u64 __intentional_overflow(-1)
47766 fs64_to_cpu(const struct super_block *sb, fs64 n)
47767 {
47768 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47769@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
47770 return (__force fs64)cpu_to_be64(n);
47771 }
47772
47773-static inline u32
47774+static inline u32 __intentional_overflow(-1)
47775 fs32_to_cpu(const struct super_block *sb, fs32 n)
47776 {
47777 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47778diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47779index 2b3bda8..6a2d4be 100644
47780--- a/fs/befs/linuxvfs.c
47781+++ b/fs/befs/linuxvfs.c
47782@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47783 {
47784 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47785 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47786- char *link = nd_get_link(nd);
47787+ const char *link = nd_get_link(nd);
47788 if (!IS_ERR(link))
47789 kfree(link);
47790 }
47791diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47792index 6043567..16a9239 100644
47793--- a/fs/binfmt_aout.c
47794+++ b/fs/binfmt_aout.c
47795@@ -16,6 +16,7 @@
47796 #include <linux/string.h>
47797 #include <linux/fs.h>
47798 #include <linux/file.h>
47799+#include <linux/security.h>
47800 #include <linux/stat.h>
47801 #include <linux/fcntl.h>
47802 #include <linux/ptrace.h>
47803@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47804 #endif
47805 # define START_STACK(u) ((void __user *)u.start_stack)
47806
47807+ memset(&dump, 0, sizeof(dump));
47808+
47809 fs = get_fs();
47810 set_fs(KERNEL_DS);
47811 has_dumped = 1;
47812@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47813
47814 /* If the size of the dump file exceeds the rlimit, then see what would happen
47815 if we wrote the stack, but not the data area. */
47816+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47817 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47818 dump.u_dsize = 0;
47819
47820 /* Make sure we have enough room to write the stack and data areas. */
47821+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47822 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47823 dump.u_ssize = 0;
47824
47825@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47826 rlim = rlimit(RLIMIT_DATA);
47827 if (rlim >= RLIM_INFINITY)
47828 rlim = ~0;
47829+
47830+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47831 if (ex.a_data + ex.a_bss > rlim)
47832 return -ENOMEM;
47833
47834@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47835
47836 install_exec_creds(bprm);
47837
47838+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47839+ current->mm->pax_flags = 0UL;
47840+#endif
47841+
47842+#ifdef CONFIG_PAX_PAGEEXEC
47843+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47844+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47845+
47846+#ifdef CONFIG_PAX_EMUTRAMP
47847+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47848+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47849+#endif
47850+
47851+#ifdef CONFIG_PAX_MPROTECT
47852+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47853+ current->mm->pax_flags |= MF_PAX_MPROTECT;
47854+#endif
47855+
47856+ }
47857+#endif
47858+
47859 if (N_MAGIC(ex) == OMAGIC) {
47860 unsigned long text_addr, map_size;
47861 loff_t pos;
47862@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47863 }
47864
47865 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47866- PROT_READ | PROT_WRITE | PROT_EXEC,
47867+ PROT_READ | PROT_WRITE,
47868 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47869 fd_offset + ex.a_text);
47870 if (error != N_DATADDR(ex)) {
47871diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47872index 0c42cdb..12478dd 100644
47873--- a/fs/binfmt_elf.c
47874+++ b/fs/binfmt_elf.c
47875@@ -33,6 +33,7 @@
47876 #include <linux/elf.h>
47877 #include <linux/utsname.h>
47878 #include <linux/coredump.h>
47879+#include <linux/xattr.h>
47880 #include <asm/uaccess.h>
47881 #include <asm/param.h>
47882 #include <asm/page.h>
47883@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47884 #define elf_core_dump NULL
47885 #endif
47886
47887+#ifdef CONFIG_PAX_MPROTECT
47888+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47889+#endif
47890+
47891 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47892 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47893 #else
47894@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47895 .load_binary = load_elf_binary,
47896 .load_shlib = load_elf_library,
47897 .core_dump = elf_core_dump,
47898+
47899+#ifdef CONFIG_PAX_MPROTECT
47900+ .handle_mprotect= elf_handle_mprotect,
47901+#endif
47902+
47903 .min_coredump = ELF_EXEC_PAGESIZE,
47904 };
47905
47906@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47907
47908 static int set_brk(unsigned long start, unsigned long end)
47909 {
47910+ unsigned long e = end;
47911+
47912 start = ELF_PAGEALIGN(start);
47913 end = ELF_PAGEALIGN(end);
47914 if (end > start) {
47915@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47916 if (BAD_ADDR(addr))
47917 return addr;
47918 }
47919- current->mm->start_brk = current->mm->brk = end;
47920+ current->mm->start_brk = current->mm->brk = e;
47921 return 0;
47922 }
47923
47924@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47925 elf_addr_t __user *u_rand_bytes;
47926 const char *k_platform = ELF_PLATFORM;
47927 const char *k_base_platform = ELF_BASE_PLATFORM;
47928- unsigned char k_rand_bytes[16];
47929+ u32 k_rand_bytes[4];
47930 int items;
47931 elf_addr_t *elf_info;
47932 int ei_index = 0;
47933 const struct cred *cred = current_cred();
47934 struct vm_area_struct *vma;
47935+ unsigned long saved_auxv[AT_VECTOR_SIZE];
47936
47937 /*
47938 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47939@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47940 * Generate 16 random bytes for userspace PRNG seeding.
47941 */
47942 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47943- u_rand_bytes = (elf_addr_t __user *)
47944- STACK_ALLOC(p, sizeof(k_rand_bytes));
47945+ srandom32(k_rand_bytes[0] ^ random32());
47946+ srandom32(k_rand_bytes[1] ^ random32());
47947+ srandom32(k_rand_bytes[2] ^ random32());
47948+ srandom32(k_rand_bytes[3] ^ random32());
47949+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
47950+ u_rand_bytes = (elf_addr_t __user *) p;
47951 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47952 return -EFAULT;
47953
47954@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47955 return -EFAULT;
47956 current->mm->env_end = p;
47957
47958+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47959+
47960 /* Put the elf_info on the stack in the right place. */
47961 sp = (elf_addr_t __user *)envp + 1;
47962- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47963+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47964 return -EFAULT;
47965 return 0;
47966 }
47967@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47968 an ELF header */
47969
47970 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47971- struct file *interpreter, unsigned long *interp_map_addr,
47972- unsigned long no_base)
47973+ struct file *interpreter, unsigned long no_base)
47974 {
47975 struct elf_phdr *elf_phdata;
47976 struct elf_phdr *eppnt;
47977- unsigned long load_addr = 0;
47978+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
47979 int load_addr_set = 0;
47980 unsigned long last_bss = 0, elf_bss = 0;
47981- unsigned long error = ~0UL;
47982+ unsigned long error = -EINVAL;
47983 unsigned long total_size;
47984 int retval, i, size;
47985
47986@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47987 goto out_close;
47988 }
47989
47990+#ifdef CONFIG_PAX_SEGMEXEC
47991+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
47992+ pax_task_size = SEGMEXEC_TASK_SIZE;
47993+#endif
47994+
47995 eppnt = elf_phdata;
47996 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
47997 if (eppnt->p_type == PT_LOAD) {
47998@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47999 map_addr = elf_map(interpreter, load_addr + vaddr,
48000 eppnt, elf_prot, elf_type, total_size);
48001 total_size = 0;
48002- if (!*interp_map_addr)
48003- *interp_map_addr = map_addr;
48004 error = map_addr;
48005 if (BAD_ADDR(map_addr))
48006 goto out_close;
48007@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48008 k = load_addr + eppnt->p_vaddr;
48009 if (BAD_ADDR(k) ||
48010 eppnt->p_filesz > eppnt->p_memsz ||
48011- eppnt->p_memsz > TASK_SIZE ||
48012- TASK_SIZE - eppnt->p_memsz < k) {
48013+ eppnt->p_memsz > pax_task_size ||
48014+ pax_task_size - eppnt->p_memsz < k) {
48015 error = -ENOMEM;
48016 goto out_close;
48017 }
48018@@ -530,6 +551,315 @@ out:
48019 return error;
48020 }
48021
48022+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48023+#ifdef CONFIG_PAX_SOFTMODE
48024+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48025+{
48026+ unsigned long pax_flags = 0UL;
48027+
48028+#ifdef CONFIG_PAX_PAGEEXEC
48029+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48030+ pax_flags |= MF_PAX_PAGEEXEC;
48031+#endif
48032+
48033+#ifdef CONFIG_PAX_SEGMEXEC
48034+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48035+ pax_flags |= MF_PAX_SEGMEXEC;
48036+#endif
48037+
48038+#ifdef CONFIG_PAX_EMUTRAMP
48039+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48040+ pax_flags |= MF_PAX_EMUTRAMP;
48041+#endif
48042+
48043+#ifdef CONFIG_PAX_MPROTECT
48044+ if (elf_phdata->p_flags & PF_MPROTECT)
48045+ pax_flags |= MF_PAX_MPROTECT;
48046+#endif
48047+
48048+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48049+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48050+ pax_flags |= MF_PAX_RANDMMAP;
48051+#endif
48052+
48053+ return pax_flags;
48054+}
48055+#endif
48056+
48057+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48058+{
48059+ unsigned long pax_flags = 0UL;
48060+
48061+#ifdef CONFIG_PAX_PAGEEXEC
48062+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48063+ pax_flags |= MF_PAX_PAGEEXEC;
48064+#endif
48065+
48066+#ifdef CONFIG_PAX_SEGMEXEC
48067+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48068+ pax_flags |= MF_PAX_SEGMEXEC;
48069+#endif
48070+
48071+#ifdef CONFIG_PAX_EMUTRAMP
48072+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48073+ pax_flags |= MF_PAX_EMUTRAMP;
48074+#endif
48075+
48076+#ifdef CONFIG_PAX_MPROTECT
48077+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48078+ pax_flags |= MF_PAX_MPROTECT;
48079+#endif
48080+
48081+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48082+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48083+ pax_flags |= MF_PAX_RANDMMAP;
48084+#endif
48085+
48086+ return pax_flags;
48087+}
48088+#endif
48089+
48090+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48091+#ifdef CONFIG_PAX_SOFTMODE
48092+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48093+{
48094+ unsigned long pax_flags = 0UL;
48095+
48096+#ifdef CONFIG_PAX_PAGEEXEC
48097+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48098+ pax_flags |= MF_PAX_PAGEEXEC;
48099+#endif
48100+
48101+#ifdef CONFIG_PAX_SEGMEXEC
48102+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48103+ pax_flags |= MF_PAX_SEGMEXEC;
48104+#endif
48105+
48106+#ifdef CONFIG_PAX_EMUTRAMP
48107+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
48108+ pax_flags |= MF_PAX_EMUTRAMP;
48109+#endif
48110+
48111+#ifdef CONFIG_PAX_MPROTECT
48112+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48113+ pax_flags |= MF_PAX_MPROTECT;
48114+#endif
48115+
48116+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48117+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48118+ pax_flags |= MF_PAX_RANDMMAP;
48119+#endif
48120+
48121+ return pax_flags;
48122+}
48123+#endif
48124+
48125+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48126+{
48127+ unsigned long pax_flags = 0UL;
48128+
48129+#ifdef CONFIG_PAX_PAGEEXEC
48130+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48131+ pax_flags |= MF_PAX_PAGEEXEC;
48132+#endif
48133+
48134+#ifdef CONFIG_PAX_SEGMEXEC
48135+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48136+ pax_flags |= MF_PAX_SEGMEXEC;
48137+#endif
48138+
48139+#ifdef CONFIG_PAX_EMUTRAMP
48140+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48141+ pax_flags |= MF_PAX_EMUTRAMP;
48142+#endif
48143+
48144+#ifdef CONFIG_PAX_MPROTECT
48145+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48146+ pax_flags |= MF_PAX_MPROTECT;
48147+#endif
48148+
48149+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48150+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48151+ pax_flags |= MF_PAX_RANDMMAP;
48152+#endif
48153+
48154+ return pax_flags;
48155+}
48156+#endif
48157+
48158+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48159+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48160+{
48161+ unsigned long pax_flags = 0UL;
48162+
48163+#ifdef CONFIG_PAX_EI_PAX
48164+
48165+#ifdef CONFIG_PAX_PAGEEXEC
48166+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48167+ pax_flags |= MF_PAX_PAGEEXEC;
48168+#endif
48169+
48170+#ifdef CONFIG_PAX_SEGMEXEC
48171+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48172+ pax_flags |= MF_PAX_SEGMEXEC;
48173+#endif
48174+
48175+#ifdef CONFIG_PAX_EMUTRAMP
48176+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48177+ pax_flags |= MF_PAX_EMUTRAMP;
48178+#endif
48179+
48180+#ifdef CONFIG_PAX_MPROTECT
48181+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48182+ pax_flags |= MF_PAX_MPROTECT;
48183+#endif
48184+
48185+#ifdef CONFIG_PAX_ASLR
48186+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48187+ pax_flags |= MF_PAX_RANDMMAP;
48188+#endif
48189+
48190+#else
48191+
48192+#ifdef CONFIG_PAX_PAGEEXEC
48193+ pax_flags |= MF_PAX_PAGEEXEC;
48194+#endif
48195+
48196+#ifdef CONFIG_PAX_SEGMEXEC
48197+ pax_flags |= MF_PAX_SEGMEXEC;
48198+#endif
48199+
48200+#ifdef CONFIG_PAX_MPROTECT
48201+ pax_flags |= MF_PAX_MPROTECT;
48202+#endif
48203+
48204+#ifdef CONFIG_PAX_RANDMMAP
48205+ if (randomize_va_space)
48206+ pax_flags |= MF_PAX_RANDMMAP;
48207+#endif
48208+
48209+#endif
48210+
48211+ return pax_flags;
48212+}
48213+
48214+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48215+{
48216+
48217+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48218+ unsigned long i;
48219+
48220+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48221+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48222+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48223+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48224+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48225+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48226+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48227+ return ~0UL;
48228+
48229+#ifdef CONFIG_PAX_SOFTMODE
48230+ if (pax_softmode)
48231+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48232+ else
48233+#endif
48234+
48235+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48236+ break;
48237+ }
48238+#endif
48239+
48240+ return ~0UL;
48241+}
48242+
48243+static unsigned long pax_parse_xattr_pax(struct file * const file)
48244+{
48245+
48246+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48247+ ssize_t xattr_size, i;
48248+ unsigned char xattr_value[5];
48249+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48250+
48251+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
48252+ if (xattr_size <= 0 || xattr_size > 5)
48253+ return ~0UL;
48254+
48255+ for (i = 0; i < xattr_size; i++)
48256+ switch (xattr_value[i]) {
48257+ default:
48258+ return ~0UL;
48259+
48260+#define parse_flag(option1, option2, flag) \
48261+ case option1: \
48262+ if (pax_flags_hardmode & MF_PAX_##flag) \
48263+ return ~0UL; \
48264+ pax_flags_hardmode |= MF_PAX_##flag; \
48265+ break; \
48266+ case option2: \
48267+ if (pax_flags_softmode & MF_PAX_##flag) \
48268+ return ~0UL; \
48269+ pax_flags_softmode |= MF_PAX_##flag; \
48270+ break;
48271+
48272+ parse_flag('p', 'P', PAGEEXEC);
48273+ parse_flag('e', 'E', EMUTRAMP);
48274+ parse_flag('m', 'M', MPROTECT);
48275+ parse_flag('r', 'R', RANDMMAP);
48276+ parse_flag('s', 'S', SEGMEXEC);
48277+
48278+#undef parse_flag
48279+ }
48280+
48281+ if (pax_flags_hardmode & pax_flags_softmode)
48282+ return ~0UL;
48283+
48284+#ifdef CONFIG_PAX_SOFTMODE
48285+ if (pax_softmode)
48286+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48287+ else
48288+#endif
48289+
48290+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48291+#else
48292+ return ~0UL;
48293+#endif
48294+
48295+}
48296+
48297+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48298+{
48299+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48300+
48301+ pax_flags = pax_parse_ei_pax(elf_ex);
48302+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48303+ xattr_pax_flags = pax_parse_xattr_pax(file);
48304+
48305+ if (pt_pax_flags == ~0UL)
48306+ pt_pax_flags = xattr_pax_flags;
48307+ else if (xattr_pax_flags == ~0UL)
48308+ xattr_pax_flags = pt_pax_flags;
48309+ if (pt_pax_flags != xattr_pax_flags)
48310+ return -EINVAL;
48311+ if (pt_pax_flags != ~0UL)
48312+ pax_flags = pt_pax_flags;
48313+
48314+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48315+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48316+ if ((__supported_pte_mask & _PAGE_NX))
48317+ pax_flags &= ~MF_PAX_SEGMEXEC;
48318+ else
48319+ pax_flags &= ~MF_PAX_PAGEEXEC;
48320+ }
48321+#endif
48322+
48323+ if (0 > pax_check_flags(&pax_flags))
48324+ return -EINVAL;
48325+
48326+ current->mm->pax_flags = pax_flags;
48327+ return 0;
48328+}
48329+#endif
48330+
48331 /*
48332 * These are the functions used to load ELF style executables and shared
48333 * libraries. There is no binary dependent code anywhere else.
48334@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48335 {
48336 unsigned int random_variable = 0;
48337
48338+#ifdef CONFIG_PAX_RANDUSTACK
48339+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
48340+ return stack_top - current->mm->delta_stack;
48341+#endif
48342+
48343 if ((current->flags & PF_RANDOMIZE) &&
48344 !(current->personality & ADDR_NO_RANDOMIZE)) {
48345 random_variable = get_random_int() & STACK_RND_MASK;
48346@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
48347 unsigned long load_addr = 0, load_bias = 0;
48348 int load_addr_set = 0;
48349 char * elf_interpreter = NULL;
48350- unsigned long error;
48351+ unsigned long error = 0;
48352 struct elf_phdr *elf_ppnt, *elf_phdata;
48353 unsigned long elf_bss, elf_brk;
48354 int retval, i;
48355@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
48356 unsigned long start_code, end_code, start_data, end_data;
48357 unsigned long reloc_func_desc __maybe_unused = 0;
48358 int executable_stack = EXSTACK_DEFAULT;
48359- unsigned long def_flags = 0;
48360 struct pt_regs *regs = current_pt_regs();
48361 struct {
48362 struct elfhdr elf_ex;
48363 struct elfhdr interp_elf_ex;
48364 } *loc;
48365+ unsigned long pax_task_size = TASK_SIZE;
48366
48367 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
48368 if (!loc) {
48369@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
48370 goto out_free_dentry;
48371
48372 /* OK, This is the point of no return */
48373- current->mm->def_flags = def_flags;
48374+
48375+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48376+ current->mm->pax_flags = 0UL;
48377+#endif
48378+
48379+#ifdef CONFIG_PAX_DLRESOLVE
48380+ current->mm->call_dl_resolve = 0UL;
48381+#endif
48382+
48383+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
48384+ current->mm->call_syscall = 0UL;
48385+#endif
48386+
48387+#ifdef CONFIG_PAX_ASLR
48388+ current->mm->delta_mmap = 0UL;
48389+ current->mm->delta_stack = 0UL;
48390+#endif
48391+
48392+ current->mm->def_flags = 0;
48393+
48394+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48395+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
48396+ send_sig(SIGKILL, current, 0);
48397+ goto out_free_dentry;
48398+ }
48399+#endif
48400+
48401+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
48402+ pax_set_initial_flags(bprm);
48403+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
48404+ if (pax_set_initial_flags_func)
48405+ (pax_set_initial_flags_func)(bprm);
48406+#endif
48407+
48408+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48409+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
48410+ current->mm->context.user_cs_limit = PAGE_SIZE;
48411+ current->mm->def_flags |= VM_PAGEEXEC;
48412+ }
48413+#endif
48414+
48415+#ifdef CONFIG_PAX_SEGMEXEC
48416+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
48417+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
48418+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
48419+ pax_task_size = SEGMEXEC_TASK_SIZE;
48420+ current->mm->def_flags |= VM_NOHUGEPAGE;
48421+ }
48422+#endif
48423+
48424+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
48425+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48426+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
48427+ put_cpu();
48428+ }
48429+#endif
48430
48431 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
48432 may depend on the personality. */
48433 SET_PERSONALITY(loc->elf_ex);
48434+
48435+#ifdef CONFIG_PAX_ASLR
48436+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48437+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
48438+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
48439+ }
48440+#endif
48441+
48442+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48443+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48444+ executable_stack = EXSTACK_DISABLE_X;
48445+ current->personality &= ~READ_IMPLIES_EXEC;
48446+ } else
48447+#endif
48448+
48449 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
48450 current->personality |= READ_IMPLIES_EXEC;
48451
48452@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
48453 #else
48454 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
48455 #endif
48456+
48457+#ifdef CONFIG_PAX_RANDMMAP
48458+ /* PaX: randomize base address at the default exe base if requested */
48459+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48460+#ifdef CONFIG_SPARC64
48461+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48462+#else
48463+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48464+#endif
48465+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48466+ elf_flags |= MAP_FIXED;
48467+ }
48468+#endif
48469+
48470 }
48471
48472 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48473@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48474 * allowed task size. Note that p_filesz must always be
48475 * <= p_memsz so it is only necessary to check p_memsz.
48476 */
48477- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48478- elf_ppnt->p_memsz > TASK_SIZE ||
48479- TASK_SIZE - elf_ppnt->p_memsz < k) {
48480+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48481+ elf_ppnt->p_memsz > pax_task_size ||
48482+ pax_task_size - elf_ppnt->p_memsz < k) {
48483 /* set_brk can never work. Avoid overflows. */
48484 send_sig(SIGKILL, current, 0);
48485 retval = -EINVAL;
48486@@ -883,17 +1302,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
48487 goto out_free_dentry;
48488 }
48489 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48490- send_sig(SIGSEGV, current, 0);
48491- retval = -EFAULT; /* Nobody gets to see this, but.. */
48492- goto out_free_dentry;
48493+ /*
48494+ * This bss-zeroing can fail if the ELF
48495+ * file specifies odd protections. So
48496+ * we don't check the return value
48497+ */
48498 }
48499
48500+#ifdef CONFIG_PAX_RANDMMAP
48501+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48502+ unsigned long start, size, flags, vm_flags;
48503+
48504+ start = ELF_PAGEALIGN(elf_brk);
48505+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48506+ flags = MAP_FIXED | MAP_PRIVATE;
48507+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
48508+
48509+ down_write(&current->mm->mmap_sem);
48510+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
48511+ retval = -ENOMEM;
48512+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48513+// if (current->personality & ADDR_NO_RANDOMIZE)
48514+// vm_flags |= VM_READ | VM_MAYREAD;
48515+ start = mmap_region(NULL, start, PAGE_ALIGN(size), flags, vm_flags, 0);
48516+ up_write(&current->mm->mmap_sem);
48517+ retval = IS_ERR_VALUE(start) ? start : 0;
48518+ } else
48519+ up_write(&current->mm->mmap_sem);
48520+ if (retval == 0)
48521+ retval = set_brk(start + size, start + size + PAGE_SIZE);
48522+ if (retval < 0) {
48523+ send_sig(SIGKILL, current, 0);
48524+ goto out_free_dentry;
48525+ }
48526+ }
48527+#endif
48528+
48529 if (elf_interpreter) {
48530- unsigned long interp_map_addr = 0;
48531-
48532 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48533 interpreter,
48534- &interp_map_addr,
48535 load_bias);
48536 if (!IS_ERR((void *)elf_entry)) {
48537 /*
48538@@ -1115,7 +1562,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48539 * Decide what to dump of a segment, part, all or none.
48540 */
48541 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48542- unsigned long mm_flags)
48543+ unsigned long mm_flags, long signr)
48544 {
48545 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48546
48547@@ -1152,7 +1599,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48548 if (vma->vm_file == NULL)
48549 return 0;
48550
48551- if (FILTER(MAPPED_PRIVATE))
48552+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48553 goto whole;
48554
48555 /*
48556@@ -1374,9 +1821,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48557 {
48558 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48559 int i = 0;
48560- do
48561+ do {
48562 i += 2;
48563- while (auxv[i - 2] != AT_NULL);
48564+ } while (auxv[i - 2] != AT_NULL);
48565 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48566 }
48567
48568@@ -2006,14 +2453,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48569 }
48570
48571 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48572- unsigned long mm_flags)
48573+ struct coredump_params *cprm)
48574 {
48575 struct vm_area_struct *vma;
48576 size_t size = 0;
48577
48578 for (vma = first_vma(current, gate_vma); vma != NULL;
48579 vma = next_vma(vma, gate_vma))
48580- size += vma_dump_size(vma, mm_flags);
48581+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48582 return size;
48583 }
48584
48585@@ -2107,7 +2554,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48586
48587 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48588
48589- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48590+ offset += elf_core_vma_data_size(gate_vma, cprm);
48591 offset += elf_core_extra_data_size();
48592 e_shoff = offset;
48593
48594@@ -2121,10 +2568,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48595 offset = dataoff;
48596
48597 size += sizeof(*elf);
48598+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48599 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48600 goto end_coredump;
48601
48602 size += sizeof(*phdr4note);
48603+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48604 if (size > cprm->limit
48605 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48606 goto end_coredump;
48607@@ -2138,7 +2587,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48608 phdr.p_offset = offset;
48609 phdr.p_vaddr = vma->vm_start;
48610 phdr.p_paddr = 0;
48611- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48612+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48613 phdr.p_memsz = vma->vm_end - vma->vm_start;
48614 offset += phdr.p_filesz;
48615 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48616@@ -2149,6 +2598,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48617 phdr.p_align = ELF_EXEC_PAGESIZE;
48618
48619 size += sizeof(phdr);
48620+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48621 if (size > cprm->limit
48622 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48623 goto end_coredump;
48624@@ -2173,7 +2623,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48625 unsigned long addr;
48626 unsigned long end;
48627
48628- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48629+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48630
48631 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48632 struct page *page;
48633@@ -2182,6 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48634 page = get_dump_page(addr);
48635 if (page) {
48636 void *kaddr = kmap(page);
48637+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48638 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48639 !dump_write(cprm->file, kaddr,
48640 PAGE_SIZE);
48641@@ -2199,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48642
48643 if (e_phnum == PN_XNUM) {
48644 size += sizeof(*shdr4extnum);
48645+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48646 if (size > cprm->limit
48647 || !dump_write(cprm->file, shdr4extnum,
48648 sizeof(*shdr4extnum)))
48649@@ -2219,6 +2671,97 @@ out:
48650
48651 #endif /* CONFIG_ELF_CORE */
48652
48653+#ifdef CONFIG_PAX_MPROTECT
48654+/* PaX: non-PIC ELF libraries need relocations on their executable segments
48655+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48656+ * we'll remove VM_MAYWRITE for good on RELRO segments.
48657+ *
48658+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48659+ * basis because we want to allow the common case and not the special ones.
48660+ */
48661+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48662+{
48663+ struct elfhdr elf_h;
48664+ struct elf_phdr elf_p;
48665+ unsigned long i;
48666+ unsigned long oldflags;
48667+ bool is_textrel_rw, is_textrel_rx, is_relro;
48668+
48669+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48670+ return;
48671+
48672+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48673+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48674+
48675+#ifdef CONFIG_PAX_ELFRELOCS
48676+ /* possible TEXTREL */
48677+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48678+ 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);
48679+#else
48680+ is_textrel_rw = false;
48681+ is_textrel_rx = false;
48682+#endif
48683+
48684+ /* possible RELRO */
48685+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48686+
48687+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48688+ return;
48689+
48690+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48691+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48692+
48693+#ifdef CONFIG_PAX_ETEXECRELOCS
48694+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48695+#else
48696+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48697+#endif
48698+
48699+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48700+ !elf_check_arch(&elf_h) ||
48701+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48702+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48703+ return;
48704+
48705+ for (i = 0UL; i < elf_h.e_phnum; i++) {
48706+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48707+ return;
48708+ switch (elf_p.p_type) {
48709+ case PT_DYNAMIC:
48710+ if (!is_textrel_rw && !is_textrel_rx)
48711+ continue;
48712+ i = 0UL;
48713+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48714+ elf_dyn dyn;
48715+
48716+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48717+ return;
48718+ if (dyn.d_tag == DT_NULL)
48719+ return;
48720+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48721+ gr_log_textrel(vma);
48722+ if (is_textrel_rw)
48723+ vma->vm_flags |= VM_MAYWRITE;
48724+ else
48725+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48726+ vma->vm_flags &= ~VM_MAYWRITE;
48727+ return;
48728+ }
48729+ i++;
48730+ }
48731+ return;
48732+
48733+ case PT_GNU_RELRO:
48734+ if (!is_relro)
48735+ continue;
48736+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48737+ vma->vm_flags &= ~VM_MAYWRITE;
48738+ return;
48739+ }
48740+ }
48741+}
48742+#endif
48743+
48744 static int __init init_elf_binfmt(void)
48745 {
48746 register_binfmt(&elf_format);
48747diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48748index b563719..3868998 100644
48749--- a/fs/binfmt_flat.c
48750+++ b/fs/binfmt_flat.c
48751@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48752 realdatastart = (unsigned long) -ENOMEM;
48753 printk("Unable to allocate RAM for process data, errno %d\n",
48754 (int)-realdatastart);
48755+ down_write(&current->mm->mmap_sem);
48756 vm_munmap(textpos, text_len);
48757+ up_write(&current->mm->mmap_sem);
48758 ret = realdatastart;
48759 goto err;
48760 }
48761@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48762 }
48763 if (IS_ERR_VALUE(result)) {
48764 printk("Unable to read data+bss, errno %d\n", (int)-result);
48765+ down_write(&current->mm->mmap_sem);
48766 vm_munmap(textpos, text_len);
48767 vm_munmap(realdatastart, len);
48768+ up_write(&current->mm->mmap_sem);
48769 ret = result;
48770 goto err;
48771 }
48772@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48773 }
48774 if (IS_ERR_VALUE(result)) {
48775 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48776+ down_write(&current->mm->mmap_sem);
48777 vm_munmap(textpos, text_len + data_len + extra +
48778 MAX_SHARED_LIBS * sizeof(unsigned long));
48779+ up_write(&current->mm->mmap_sem);
48780 ret = result;
48781 goto err;
48782 }
48783diff --git a/fs/bio.c b/fs/bio.c
48784index b96fc6c..431d628 100644
48785--- a/fs/bio.c
48786+++ b/fs/bio.c
48787@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48788 /*
48789 * Overflow, abort
48790 */
48791- if (end < start)
48792+ if (end < start || end - start > INT_MAX - nr_pages)
48793 return ERR_PTR(-EINVAL);
48794
48795 nr_pages += end - start;
48796@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48797 /*
48798 * Overflow, abort
48799 */
48800- if (end < start)
48801+ if (end < start || end - start > INT_MAX - nr_pages)
48802 return ERR_PTR(-EINVAL);
48803
48804 nr_pages += end - start;
48805@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48806 const int read = bio_data_dir(bio) == READ;
48807 struct bio_map_data *bmd = bio->bi_private;
48808 int i;
48809- char *p = bmd->sgvecs[0].iov_base;
48810+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48811
48812 __bio_for_each_segment(bvec, bio, i, 0) {
48813 char *addr = page_address(bvec->bv_page);
48814diff --git a/fs/block_dev.c b/fs/block_dev.c
48815index 78edf76..da14f3f 100644
48816--- a/fs/block_dev.c
48817+++ b/fs/block_dev.c
48818@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48819 else if (bdev->bd_contains == bdev)
48820 return true; /* is a whole device which isn't held */
48821
48822- else if (whole->bd_holder == bd_may_claim)
48823+ else if (whole->bd_holder == (void *)bd_may_claim)
48824 return true; /* is a partition of a device that is being partitioned */
48825 else if (whole->bd_holder != NULL)
48826 return false; /* is a partition of a held device */
48827diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48828index eea5da7..88fead70 100644
48829--- a/fs/btrfs/ctree.c
48830+++ b/fs/btrfs/ctree.c
48831@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48832 free_extent_buffer(buf);
48833 add_root_to_dirty_list(root);
48834 } else {
48835- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48836- parent_start = parent->start;
48837- else
48838+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48839+ if (parent)
48840+ parent_start = parent->start;
48841+ else
48842+ parent_start = 0;
48843+ } else
48844 parent_start = 0;
48845
48846 WARN_ON(trans->transid != btrfs_header_generation(parent));
48847diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48848index 659ea81..0f63c1a 100644
48849--- a/fs/btrfs/inode.c
48850+++ b/fs/btrfs/inode.c
48851@@ -7300,7 +7300,7 @@ fail:
48852 return -ENOMEM;
48853 }
48854
48855-static int btrfs_getattr(struct vfsmount *mnt,
48856+int btrfs_getattr(struct vfsmount *mnt,
48857 struct dentry *dentry, struct kstat *stat)
48858 {
48859 struct inode *inode = dentry->d_inode;
48860@@ -7314,6 +7314,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48861 return 0;
48862 }
48863
48864+EXPORT_SYMBOL(btrfs_getattr);
48865+
48866+dev_t get_btrfs_dev_from_inode(struct inode *inode)
48867+{
48868+ return BTRFS_I(inode)->root->anon_dev;
48869+}
48870+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48871+
48872 /*
48873 * If a file is moved, it will inherit the cow and compression flags of the new
48874 * directory.
48875diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48876index 338f259..b657640 100644
48877--- a/fs/btrfs/ioctl.c
48878+++ b/fs/btrfs/ioctl.c
48879@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48880 for (i = 0; i < num_types; i++) {
48881 struct btrfs_space_info *tmp;
48882
48883+ /* Don't copy in more than we allocated */
48884 if (!slot_count)
48885 break;
48886
48887+ slot_count--;
48888+
48889 info = NULL;
48890 rcu_read_lock();
48891 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48892@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48893 memcpy(dest, &space, sizeof(space));
48894 dest++;
48895 space_args.total_spaces++;
48896- slot_count--;
48897 }
48898- if (!slot_count)
48899- break;
48900 }
48901 up_read(&info->groups_sem);
48902 }
48903diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48904index 300e09a..9fe4539 100644
48905--- a/fs/btrfs/relocation.c
48906+++ b/fs/btrfs/relocation.c
48907@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48908 }
48909 spin_unlock(&rc->reloc_root_tree.lock);
48910
48911- BUG_ON((struct btrfs_root *)node->data != root);
48912+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
48913
48914 if (!del) {
48915 spin_lock(&rc->reloc_root_tree.lock);
48916diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48917index d8982e9..29a85fa 100644
48918--- a/fs/btrfs/super.c
48919+++ b/fs/btrfs/super.c
48920@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48921 function, line, errstr);
48922 return;
48923 }
48924- ACCESS_ONCE(trans->transaction->aborted) = errno;
48925+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48926 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48927 }
48928 /*
48929diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48930index 622f469..e8d2d55 100644
48931--- a/fs/cachefiles/bind.c
48932+++ b/fs/cachefiles/bind.c
48933@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48934 args);
48935
48936 /* start by checking things over */
48937- ASSERT(cache->fstop_percent >= 0 &&
48938- cache->fstop_percent < cache->fcull_percent &&
48939+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
48940 cache->fcull_percent < cache->frun_percent &&
48941 cache->frun_percent < 100);
48942
48943- ASSERT(cache->bstop_percent >= 0 &&
48944- cache->bstop_percent < cache->bcull_percent &&
48945+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
48946 cache->bcull_percent < cache->brun_percent &&
48947 cache->brun_percent < 100);
48948
48949diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48950index 0a1467b..6a53245 100644
48951--- a/fs/cachefiles/daemon.c
48952+++ b/fs/cachefiles/daemon.c
48953@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48954 if (n > buflen)
48955 return -EMSGSIZE;
48956
48957- if (copy_to_user(_buffer, buffer, n) != 0)
48958+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48959 return -EFAULT;
48960
48961 return n;
48962@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48963 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48964 return -EIO;
48965
48966- if (datalen < 0 || datalen > PAGE_SIZE - 1)
48967+ if (datalen > PAGE_SIZE - 1)
48968 return -EOPNOTSUPP;
48969
48970 /* drag the command string into the kernel so we can parse it */
48971@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48972 if (args[0] != '%' || args[1] != '\0')
48973 return -EINVAL;
48974
48975- if (fstop < 0 || fstop >= cache->fcull_percent)
48976+ if (fstop >= cache->fcull_percent)
48977 return cachefiles_daemon_range_error(cache, args);
48978
48979 cache->fstop_percent = fstop;
48980@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48981 if (args[0] != '%' || args[1] != '\0')
48982 return -EINVAL;
48983
48984- if (bstop < 0 || bstop >= cache->bcull_percent)
48985+ if (bstop >= cache->bcull_percent)
48986 return cachefiles_daemon_range_error(cache, args);
48987
48988 cache->bstop_percent = bstop;
48989diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48990index 4938251..7e01445 100644
48991--- a/fs/cachefiles/internal.h
48992+++ b/fs/cachefiles/internal.h
48993@@ -59,7 +59,7 @@ struct cachefiles_cache {
48994 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48995 struct rb_root active_nodes; /* active nodes (can't be culled) */
48996 rwlock_t active_lock; /* lock for active_nodes */
48997- atomic_t gravecounter; /* graveyard uniquifier */
48998+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48999 unsigned frun_percent; /* when to stop culling (% files) */
49000 unsigned fcull_percent; /* when to start culling (% files) */
49001 unsigned fstop_percent; /* when to stop allocating (% files) */
49002@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49003 * proc.c
49004 */
49005 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49006-extern atomic_t cachefiles_lookup_histogram[HZ];
49007-extern atomic_t cachefiles_mkdir_histogram[HZ];
49008-extern atomic_t cachefiles_create_histogram[HZ];
49009+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49010+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49011+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49012
49013 extern int __init cachefiles_proc_init(void);
49014 extern void cachefiles_proc_cleanup(void);
49015 static inline
49016-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49017+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49018 {
49019 unsigned long jif = jiffies - start_jif;
49020 if (jif >= HZ)
49021 jif = HZ - 1;
49022- atomic_inc(&histogram[jif]);
49023+ atomic_inc_unchecked(&histogram[jif]);
49024 }
49025
49026 #else
49027diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49028index 8c01c5fc..15f982e 100644
49029--- a/fs/cachefiles/namei.c
49030+++ b/fs/cachefiles/namei.c
49031@@ -317,7 +317,7 @@ try_again:
49032 /* first step is to make up a grave dentry in the graveyard */
49033 sprintf(nbuffer, "%08x%08x",
49034 (uint32_t) get_seconds(),
49035- (uint32_t) atomic_inc_return(&cache->gravecounter));
49036+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49037
49038 /* do the multiway lock magic */
49039 trap = lock_rename(cache->graveyard, dir);
49040diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49041index eccd339..4c1d995 100644
49042--- a/fs/cachefiles/proc.c
49043+++ b/fs/cachefiles/proc.c
49044@@ -14,9 +14,9 @@
49045 #include <linux/seq_file.h>
49046 #include "internal.h"
49047
49048-atomic_t cachefiles_lookup_histogram[HZ];
49049-atomic_t cachefiles_mkdir_histogram[HZ];
49050-atomic_t cachefiles_create_histogram[HZ];
49051+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49052+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49053+atomic_unchecked_t cachefiles_create_histogram[HZ];
49054
49055 /*
49056 * display the latency histogram
49057@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49058 return 0;
49059 default:
49060 index = (unsigned long) v - 3;
49061- x = atomic_read(&cachefiles_lookup_histogram[index]);
49062- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49063- z = atomic_read(&cachefiles_create_histogram[index]);
49064+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49065+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49066+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49067 if (x == 0 && y == 0 && z == 0)
49068 return 0;
49069
49070diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49071index 4809922..aab2c39 100644
49072--- a/fs/cachefiles/rdwr.c
49073+++ b/fs/cachefiles/rdwr.c
49074@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49075 old_fs = get_fs();
49076 set_fs(KERNEL_DS);
49077 ret = file->f_op->write(
49078- file, (const void __user *) data, len, &pos);
49079+ file, (const void __force_user *) data, len, &pos);
49080 set_fs(old_fs);
49081 kunmap(page);
49082 if (ret != len)
49083diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49084index 8c1aabe..bbf856a 100644
49085--- a/fs/ceph/dir.c
49086+++ b/fs/ceph/dir.c
49087@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49088 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49089 struct ceph_mds_client *mdsc = fsc->mdsc;
49090 unsigned frag = fpos_frag(filp->f_pos);
49091- int off = fpos_off(filp->f_pos);
49092+ unsigned int off = fpos_off(filp->f_pos);
49093 int err;
49094 u32 ftype;
49095 struct ceph_mds_reply_info_parsed *rinfo;
49096diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49097index d9ea6ed..1e6c8ac 100644
49098--- a/fs/cifs/cifs_debug.c
49099+++ b/fs/cifs/cifs_debug.c
49100@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49101
49102 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49103 #ifdef CONFIG_CIFS_STATS2
49104- atomic_set(&totBufAllocCount, 0);
49105- atomic_set(&totSmBufAllocCount, 0);
49106+ atomic_set_unchecked(&totBufAllocCount, 0);
49107+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49108 #endif /* CONFIG_CIFS_STATS2 */
49109 spin_lock(&cifs_tcp_ses_lock);
49110 list_for_each(tmp1, &cifs_tcp_ses_list) {
49111@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49112 tcon = list_entry(tmp3,
49113 struct cifs_tcon,
49114 tcon_list);
49115- atomic_set(&tcon->num_smbs_sent, 0);
49116+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49117 if (server->ops->clear_stats)
49118 server->ops->clear_stats(tcon);
49119 }
49120@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49121 smBufAllocCount.counter, cifs_min_small);
49122 #ifdef CONFIG_CIFS_STATS2
49123 seq_printf(m, "Total Large %d Small %d Allocations\n",
49124- atomic_read(&totBufAllocCount),
49125- atomic_read(&totSmBufAllocCount));
49126+ atomic_read_unchecked(&totBufAllocCount),
49127+ atomic_read_unchecked(&totSmBufAllocCount));
49128 #endif /* CONFIG_CIFS_STATS2 */
49129
49130 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49131@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49132 if (tcon->need_reconnect)
49133 seq_puts(m, "\tDISCONNECTED ");
49134 seq_printf(m, "\nSMBs: %d",
49135- atomic_read(&tcon->num_smbs_sent));
49136+ atomic_read_unchecked(&tcon->num_smbs_sent));
49137 if (server->ops->print_stats)
49138 server->ops->print_stats(m, tcon);
49139 }
49140diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49141index e328339..322228b 100644
49142--- a/fs/cifs/cifsfs.c
49143+++ b/fs/cifs/cifsfs.c
49144@@ -1002,7 +1002,7 @@ cifs_init_request_bufs(void)
49145 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49146 cifs_req_cachep = kmem_cache_create("cifs_request",
49147 CIFSMaxBufSize + max_hdr_size, 0,
49148- SLAB_HWCACHE_ALIGN, NULL);
49149+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49150 if (cifs_req_cachep == NULL)
49151 return -ENOMEM;
49152
49153@@ -1029,7 +1029,7 @@ cifs_init_request_bufs(void)
49154 efficient to alloc 1 per page off the slab compared to 17K (5page)
49155 alloc of large cifs buffers even when page debugging is on */
49156 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49157- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49158+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49159 NULL);
49160 if (cifs_sm_req_cachep == NULL) {
49161 mempool_destroy(cifs_req_poolp);
49162@@ -1114,8 +1114,8 @@ init_cifs(void)
49163 atomic_set(&bufAllocCount, 0);
49164 atomic_set(&smBufAllocCount, 0);
49165 #ifdef CONFIG_CIFS_STATS2
49166- atomic_set(&totBufAllocCount, 0);
49167- atomic_set(&totSmBufAllocCount, 0);
49168+ atomic_set_unchecked(&totBufAllocCount, 0);
49169+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49170 #endif /* CONFIG_CIFS_STATS2 */
49171
49172 atomic_set(&midCount, 0);
49173diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49174index e6899ce..d6b2920 100644
49175--- a/fs/cifs/cifsglob.h
49176+++ b/fs/cifs/cifsglob.h
49177@@ -751,35 +751,35 @@ struct cifs_tcon {
49178 __u16 Flags; /* optional support bits */
49179 enum statusEnum tidStatus;
49180 #ifdef CONFIG_CIFS_STATS
49181- atomic_t num_smbs_sent;
49182+ atomic_unchecked_t num_smbs_sent;
49183 union {
49184 struct {
49185- atomic_t num_writes;
49186- atomic_t num_reads;
49187- atomic_t num_flushes;
49188- atomic_t num_oplock_brks;
49189- atomic_t num_opens;
49190- atomic_t num_closes;
49191- atomic_t num_deletes;
49192- atomic_t num_mkdirs;
49193- atomic_t num_posixopens;
49194- atomic_t num_posixmkdirs;
49195- atomic_t num_rmdirs;
49196- atomic_t num_renames;
49197- atomic_t num_t2renames;
49198- atomic_t num_ffirst;
49199- atomic_t num_fnext;
49200- atomic_t num_fclose;
49201- atomic_t num_hardlinks;
49202- atomic_t num_symlinks;
49203- atomic_t num_locks;
49204- atomic_t num_acl_get;
49205- atomic_t num_acl_set;
49206+ atomic_unchecked_t num_writes;
49207+ atomic_unchecked_t num_reads;
49208+ atomic_unchecked_t num_flushes;
49209+ atomic_unchecked_t num_oplock_brks;
49210+ atomic_unchecked_t num_opens;
49211+ atomic_unchecked_t num_closes;
49212+ atomic_unchecked_t num_deletes;
49213+ atomic_unchecked_t num_mkdirs;
49214+ atomic_unchecked_t num_posixopens;
49215+ atomic_unchecked_t num_posixmkdirs;
49216+ atomic_unchecked_t num_rmdirs;
49217+ atomic_unchecked_t num_renames;
49218+ atomic_unchecked_t num_t2renames;
49219+ atomic_unchecked_t num_ffirst;
49220+ atomic_unchecked_t num_fnext;
49221+ atomic_unchecked_t num_fclose;
49222+ atomic_unchecked_t num_hardlinks;
49223+ atomic_unchecked_t num_symlinks;
49224+ atomic_unchecked_t num_locks;
49225+ atomic_unchecked_t num_acl_get;
49226+ atomic_unchecked_t num_acl_set;
49227 } cifs_stats;
49228 #ifdef CONFIG_CIFS_SMB2
49229 struct {
49230- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49231- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49232+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49233+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49234 } smb2_stats;
49235 #endif /* CONFIG_CIFS_SMB2 */
49236 } stats;
49237@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49238 }
49239
49240 #ifdef CONFIG_CIFS_STATS
49241-#define cifs_stats_inc atomic_inc
49242+#define cifs_stats_inc atomic_inc_unchecked
49243
49244 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49245 unsigned int bytes)
49246@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49247 /* Various Debug counters */
49248 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49249 #ifdef CONFIG_CIFS_STATS2
49250-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49251-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49252+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49253+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49254 #endif
49255 GLOBAL_EXTERN atomic_t smBufAllocCount;
49256 GLOBAL_EXTERN atomic_t midCount;
49257diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49258index 51dc2fb..1e12a33 100644
49259--- a/fs/cifs/link.c
49260+++ b/fs/cifs/link.c
49261@@ -616,7 +616,7 @@ symlink_exit:
49262
49263 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49264 {
49265- char *p = nd_get_link(nd);
49266+ const char *p = nd_get_link(nd);
49267 if (!IS_ERR(p))
49268 kfree(p);
49269 }
49270diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49271index 3a00c0d..42d901c 100644
49272--- a/fs/cifs/misc.c
49273+++ b/fs/cifs/misc.c
49274@@ -169,7 +169,7 @@ cifs_buf_get(void)
49275 memset(ret_buf, 0, buf_size + 3);
49276 atomic_inc(&bufAllocCount);
49277 #ifdef CONFIG_CIFS_STATS2
49278- atomic_inc(&totBufAllocCount);
49279+ atomic_inc_unchecked(&totBufAllocCount);
49280 #endif /* CONFIG_CIFS_STATS2 */
49281 }
49282
49283@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49284 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49285 atomic_inc(&smBufAllocCount);
49286 #ifdef CONFIG_CIFS_STATS2
49287- atomic_inc(&totSmBufAllocCount);
49288+ atomic_inc_unchecked(&totSmBufAllocCount);
49289 #endif /* CONFIG_CIFS_STATS2 */
49290
49291 }
49292diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49293index 47bc5a8..10decbe 100644
49294--- a/fs/cifs/smb1ops.c
49295+++ b/fs/cifs/smb1ops.c
49296@@ -586,27 +586,27 @@ static void
49297 cifs_clear_stats(struct cifs_tcon *tcon)
49298 {
49299 #ifdef CONFIG_CIFS_STATS
49300- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49301- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49302- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49303- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49304- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49305- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49306- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49307- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49308- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49309- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49310- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49311- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49312- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49313- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49314- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49315- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49316- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49317- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49318- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49319- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49320- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49321+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49322+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49323+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49324+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49325+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49326+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49327+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49328+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49329+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49330+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49331+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49332+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49333+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49334+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49335+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49336+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49337+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49338+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49339+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49340+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49341+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49342 #endif
49343 }
49344
49345@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49346 {
49347 #ifdef CONFIG_CIFS_STATS
49348 seq_printf(m, " Oplocks breaks: %d",
49349- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49350+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49351 seq_printf(m, "\nReads: %d Bytes: %llu",
49352- atomic_read(&tcon->stats.cifs_stats.num_reads),
49353+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49354 (long long)(tcon->bytes_read));
49355 seq_printf(m, "\nWrites: %d Bytes: %llu",
49356- atomic_read(&tcon->stats.cifs_stats.num_writes),
49357+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49358 (long long)(tcon->bytes_written));
49359 seq_printf(m, "\nFlushes: %d",
49360- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49361+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49362 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49363- atomic_read(&tcon->stats.cifs_stats.num_locks),
49364- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49365- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49366+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49367+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49368+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49369 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
49370- atomic_read(&tcon->stats.cifs_stats.num_opens),
49371- atomic_read(&tcon->stats.cifs_stats.num_closes),
49372- atomic_read(&tcon->stats.cifs_stats.num_deletes));
49373+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
49374+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
49375+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
49376 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
49377- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
49378- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
49379+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
49380+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
49381 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
49382- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
49383- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
49384+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
49385+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
49386 seq_printf(m, "\nRenames: %d T2 Renames %d",
49387- atomic_read(&tcon->stats.cifs_stats.num_renames),
49388- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
49389+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
49390+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
49391 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
49392- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
49393- atomic_read(&tcon->stats.cifs_stats.num_fnext),
49394- atomic_read(&tcon->stats.cifs_stats.num_fclose));
49395+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
49396+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
49397+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
49398 #endif
49399 }
49400
49401diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
49402index bceffe7..cd1ae59 100644
49403--- a/fs/cifs/smb2ops.c
49404+++ b/fs/cifs/smb2ops.c
49405@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
49406 #ifdef CONFIG_CIFS_STATS
49407 int i;
49408 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
49409- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49410- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49411+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49412+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49413 }
49414 #endif
49415 }
49416@@ -284,66 +284,66 @@ static void
49417 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49418 {
49419 #ifdef CONFIG_CIFS_STATS
49420- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49421- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49422+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49423+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49424 seq_printf(m, "\nNegotiates: %d sent %d failed",
49425- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
49426- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
49427+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
49428+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
49429 seq_printf(m, "\nSessionSetups: %d sent %d failed",
49430- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
49431- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
49432+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
49433+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
49434 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
49435 seq_printf(m, "\nLogoffs: %d sent %d failed",
49436- atomic_read(&sent[SMB2_LOGOFF_HE]),
49437- atomic_read(&failed[SMB2_LOGOFF_HE]));
49438+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
49439+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
49440 seq_printf(m, "\nTreeConnects: %d sent %d failed",
49441- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
49442- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
49443+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
49444+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
49445 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
49446- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
49447- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
49448+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
49449+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
49450 seq_printf(m, "\nCreates: %d sent %d failed",
49451- atomic_read(&sent[SMB2_CREATE_HE]),
49452- atomic_read(&failed[SMB2_CREATE_HE]));
49453+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
49454+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
49455 seq_printf(m, "\nCloses: %d sent %d failed",
49456- atomic_read(&sent[SMB2_CLOSE_HE]),
49457- atomic_read(&failed[SMB2_CLOSE_HE]));
49458+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49459+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49460 seq_printf(m, "\nFlushes: %d sent %d failed",
49461- atomic_read(&sent[SMB2_FLUSH_HE]),
49462- atomic_read(&failed[SMB2_FLUSH_HE]));
49463+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49464+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49465 seq_printf(m, "\nReads: %d sent %d failed",
49466- atomic_read(&sent[SMB2_READ_HE]),
49467- atomic_read(&failed[SMB2_READ_HE]));
49468+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
49469+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
49470 seq_printf(m, "\nWrites: %d sent %d failed",
49471- atomic_read(&sent[SMB2_WRITE_HE]),
49472- atomic_read(&failed[SMB2_WRITE_HE]));
49473+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49474+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49475 seq_printf(m, "\nLocks: %d sent %d failed",
49476- atomic_read(&sent[SMB2_LOCK_HE]),
49477- atomic_read(&failed[SMB2_LOCK_HE]));
49478+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49479+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49480 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49481- atomic_read(&sent[SMB2_IOCTL_HE]),
49482- atomic_read(&failed[SMB2_IOCTL_HE]));
49483+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49484+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49485 seq_printf(m, "\nCancels: %d sent %d failed",
49486- atomic_read(&sent[SMB2_CANCEL_HE]),
49487- atomic_read(&failed[SMB2_CANCEL_HE]));
49488+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49489+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49490 seq_printf(m, "\nEchos: %d sent %d failed",
49491- atomic_read(&sent[SMB2_ECHO_HE]),
49492- atomic_read(&failed[SMB2_ECHO_HE]));
49493+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49494+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49495 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49496- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49497- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49498+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49499+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49500 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49501- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49502- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49503+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49504+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49505 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49506- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49507- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49508+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49509+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49510 seq_printf(m, "\nSetInfos: %d sent %d failed",
49511- atomic_read(&sent[SMB2_SET_INFO_HE]),
49512- atomic_read(&failed[SMB2_SET_INFO_HE]));
49513+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49514+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49515 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49516- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49517- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49518+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49519+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49520 #endif
49521 }
49522
49523diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49524index 41d9d07..dbb4772 100644
49525--- a/fs/cifs/smb2pdu.c
49526+++ b/fs/cifs/smb2pdu.c
49527@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49528 default:
49529 cERROR(1, "info level %u isn't supported",
49530 srch_inf->info_level);
49531- rc = -EINVAL;
49532- goto qdir_exit;
49533+ return -EINVAL;
49534 }
49535
49536 req->FileIndex = cpu_to_le32(index);
49537diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49538index 958ae0e..505c9d0 100644
49539--- a/fs/coda/cache.c
49540+++ b/fs/coda/cache.c
49541@@ -24,7 +24,7 @@
49542 #include "coda_linux.h"
49543 #include "coda_cache.h"
49544
49545-static atomic_t permission_epoch = ATOMIC_INIT(0);
49546+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49547
49548 /* replace or extend an acl cache hit */
49549 void coda_cache_enter(struct inode *inode, int mask)
49550@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49551 struct coda_inode_info *cii = ITOC(inode);
49552
49553 spin_lock(&cii->c_lock);
49554- cii->c_cached_epoch = atomic_read(&permission_epoch);
49555+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49556 if (cii->c_uid != current_fsuid()) {
49557 cii->c_uid = current_fsuid();
49558 cii->c_cached_perm = mask;
49559@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49560 {
49561 struct coda_inode_info *cii = ITOC(inode);
49562 spin_lock(&cii->c_lock);
49563- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49564+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49565 spin_unlock(&cii->c_lock);
49566 }
49567
49568 /* remove all acl caches */
49569 void coda_cache_clear_all(struct super_block *sb)
49570 {
49571- atomic_inc(&permission_epoch);
49572+ atomic_inc_unchecked(&permission_epoch);
49573 }
49574
49575
49576@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49577 spin_lock(&cii->c_lock);
49578 hit = (mask & cii->c_cached_perm) == mask &&
49579 cii->c_uid == current_fsuid() &&
49580- cii->c_cached_epoch == atomic_read(&permission_epoch);
49581+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49582 spin_unlock(&cii->c_lock);
49583
49584 return hit;
49585diff --git a/fs/compat.c b/fs/compat.c
49586index a06dcbc..dacb6d3 100644
49587--- a/fs/compat.c
49588+++ b/fs/compat.c
49589@@ -54,7 +54,7 @@
49590 #include <asm/ioctls.h>
49591 #include "internal.h"
49592
49593-int compat_log = 1;
49594+int compat_log = 0;
49595
49596 int compat_printk(const char *fmt, ...)
49597 {
49598@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49599
49600 set_fs(KERNEL_DS);
49601 /* The __user pointer cast is valid because of the set_fs() */
49602- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49603+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49604 set_fs(oldfs);
49605 /* truncating is ok because it's a user address */
49606 if (!ret)
49607@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49608 goto out;
49609
49610 ret = -EINVAL;
49611- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49612+ if (nr_segs > UIO_MAXIOV)
49613 goto out;
49614 if (nr_segs > fast_segs) {
49615 ret = -ENOMEM;
49616@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
49617
49618 struct compat_readdir_callback {
49619 struct compat_old_linux_dirent __user *dirent;
49620+ struct file * file;
49621 int result;
49622 };
49623
49624@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49625 buf->result = -EOVERFLOW;
49626 return -EOVERFLOW;
49627 }
49628+
49629+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49630+ return 0;
49631+
49632 buf->result++;
49633 dirent = buf->dirent;
49634 if (!access_ok(VERIFY_WRITE, dirent,
49635@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49636
49637 buf.result = 0;
49638 buf.dirent = dirent;
49639+ buf.file = f.file;
49640
49641 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49642 if (buf.result)
49643@@ -901,6 +907,7 @@ struct compat_linux_dirent {
49644 struct compat_getdents_callback {
49645 struct compat_linux_dirent __user *current_dir;
49646 struct compat_linux_dirent __user *previous;
49647+ struct file * file;
49648 int count;
49649 int error;
49650 };
49651@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49652 buf->error = -EOVERFLOW;
49653 return -EOVERFLOW;
49654 }
49655+
49656+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49657+ return 0;
49658+
49659 dirent = buf->previous;
49660 if (dirent) {
49661 if (__put_user(offset, &dirent->d_off))
49662@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49663 buf.previous = NULL;
49664 buf.count = count;
49665 buf.error = 0;
49666+ buf.file = f.file;
49667
49668 error = vfs_readdir(f.file, compat_filldir, &buf);
49669 if (error >= 0)
49670@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49671 struct compat_getdents_callback64 {
49672 struct linux_dirent64 __user *current_dir;
49673 struct linux_dirent64 __user *previous;
49674+ struct file * file;
49675 int count;
49676 int error;
49677 };
49678@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49679 buf->error = -EINVAL; /* only used if we fail.. */
49680 if (reclen > buf->count)
49681 return -EINVAL;
49682+
49683+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49684+ return 0;
49685+
49686 dirent = buf->previous;
49687
49688 if (dirent) {
49689@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49690 buf.previous = NULL;
49691 buf.count = count;
49692 buf.error = 0;
49693+ buf.file = f.file;
49694
49695 error = vfs_readdir(f.file, compat_filldir64, &buf);
49696 if (error >= 0)
49697 error = buf.error;
49698 lastdirent = buf.previous;
49699 if (lastdirent) {
49700- typeof(lastdirent->d_off) d_off = f.file->f_pos;
49701+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49702 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49703 error = -EFAULT;
49704 else
49705diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49706index a81147e..20bf2b5 100644
49707--- a/fs/compat_binfmt_elf.c
49708+++ b/fs/compat_binfmt_elf.c
49709@@ -30,11 +30,13 @@
49710 #undef elf_phdr
49711 #undef elf_shdr
49712 #undef elf_note
49713+#undef elf_dyn
49714 #undef elf_addr_t
49715 #define elfhdr elf32_hdr
49716 #define elf_phdr elf32_phdr
49717 #define elf_shdr elf32_shdr
49718 #define elf_note elf32_note
49719+#define elf_dyn Elf32_Dyn
49720 #define elf_addr_t Elf32_Addr
49721
49722 /*
49723diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49724index e2f57a0..3c78771 100644
49725--- a/fs/compat_ioctl.c
49726+++ b/fs/compat_ioctl.c
49727@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49728 return -EFAULT;
49729 if (__get_user(udata, &ss32->iomem_base))
49730 return -EFAULT;
49731- ss.iomem_base = compat_ptr(udata);
49732+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49733 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49734 __get_user(ss.port_high, &ss32->port_high))
49735 return -EFAULT;
49736@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49737 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49738 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49739 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49740- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49741+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49742 return -EFAULT;
49743
49744 return ioctl_preallocate(file, p);
49745@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49746 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49747 {
49748 unsigned int a, b;
49749- a = *(unsigned int *)p;
49750- b = *(unsigned int *)q;
49751+ a = *(const unsigned int *)p;
49752+ b = *(const unsigned int *)q;
49753 if (a > b)
49754 return 1;
49755 if (a < b)
49756diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49757index 712b10f..c33c4ca 100644
49758--- a/fs/configfs/dir.c
49759+++ b/fs/configfs/dir.c
49760@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49761 static int configfs_depend_prep(struct dentry *origin,
49762 struct config_item *target)
49763 {
49764- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49765+ struct configfs_dirent *child_sd, *sd;
49766 int ret = 0;
49767
49768- BUG_ON(!origin || !sd);
49769+ BUG_ON(!origin || !origin->d_fsdata);
49770+ sd = origin->d_fsdata;
49771
49772 if (sd->s_element == target) /* Boo-yah */
49773 goto out;
49774@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49775 }
49776 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49777 struct configfs_dirent *next;
49778- const char * name;
49779+ const unsigned char * name;
49780+ char d_name[sizeof(next->s_dentry->d_iname)];
49781 int len;
49782 struct inode *inode = NULL;
49783
49784@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49785 continue;
49786
49787 name = configfs_get_name(next);
49788- len = strlen(name);
49789+ if (next->s_dentry && name == next->s_dentry->d_iname) {
49790+ len = next->s_dentry->d_name.len;
49791+ memcpy(d_name, name, len);
49792+ name = d_name;
49793+ } else
49794+ len = strlen(name);
49795
49796 /*
49797 * We'll have a dentry and an inode for
49798diff --git a/fs/coredump.c b/fs/coredump.c
49799index 1774932..5812106 100644
49800--- a/fs/coredump.c
49801+++ b/fs/coredump.c
49802@@ -52,7 +52,7 @@ struct core_name {
49803 char *corename;
49804 int used, size;
49805 };
49806-static atomic_t call_count = ATOMIC_INIT(1);
49807+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49808
49809 /* The maximal length of core_pattern is also specified in sysctl.c */
49810
49811@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49812 {
49813 char *old_corename = cn->corename;
49814
49815- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49816+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49817 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49818
49819 if (!cn->corename) {
49820@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49821 int pid_in_pattern = 0;
49822 int err = 0;
49823
49824- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49825+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49826 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49827 cn->used = 0;
49828
49829@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49830 pipe = file->f_path.dentry->d_inode->i_pipe;
49831
49832 pipe_lock(pipe);
49833- pipe->readers++;
49834- pipe->writers--;
49835+ atomic_inc(&pipe->readers);
49836+ atomic_dec(&pipe->writers);
49837
49838- while ((pipe->readers > 1) && (!signal_pending(current))) {
49839+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49840 wake_up_interruptible_sync(&pipe->wait);
49841 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49842 pipe_wait(pipe);
49843 }
49844
49845- pipe->readers--;
49846- pipe->writers++;
49847+ atomic_dec(&pipe->readers);
49848+ atomic_inc(&pipe->writers);
49849 pipe_unlock(pipe);
49850
49851 }
49852@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49853 int ispipe;
49854 struct files_struct *displaced;
49855 bool need_nonrelative = false;
49856- static atomic_t core_dump_count = ATOMIC_INIT(0);
49857+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49858+ long signr = siginfo->si_signo;
49859 struct coredump_params cprm = {
49860 .siginfo = siginfo,
49861 .regs = signal_pt_regs(),
49862@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49863 .mm_flags = mm->flags,
49864 };
49865
49866- audit_core_dumps(siginfo->si_signo);
49867+ audit_core_dumps(signr);
49868+
49869+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49870+ gr_handle_brute_attach(cprm.mm_flags);
49871
49872 binfmt = mm->binfmt;
49873 if (!binfmt || !binfmt->core_dump)
49874@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49875 need_nonrelative = true;
49876 }
49877
49878- retval = coredump_wait(siginfo->si_signo, &core_state);
49879+ retval = coredump_wait(signr, &core_state);
49880 if (retval < 0)
49881 goto fail_creds;
49882
49883@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49884 }
49885 cprm.limit = RLIM_INFINITY;
49886
49887- dump_count = atomic_inc_return(&core_dump_count);
49888+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
49889 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49890 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49891 task_tgid_vnr(current), current->comm);
49892@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49893 } else {
49894 struct inode *inode;
49895
49896+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49897+
49898 if (cprm.limit < binfmt->min_coredump)
49899 goto fail_unlock;
49900
49901@@ -640,7 +646,7 @@ close_fail:
49902 filp_close(cprm.file, NULL);
49903 fail_dropcount:
49904 if (ispipe)
49905- atomic_dec(&core_dump_count);
49906+ atomic_dec_unchecked(&core_dump_count);
49907 fail_unlock:
49908 kfree(cn.corename);
49909 fail_corename:
49910@@ -659,7 +665,7 @@ fail:
49911 */
49912 int dump_write(struct file *file, const void *addr, int nr)
49913 {
49914- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49915+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49916 }
49917 EXPORT_SYMBOL(dump_write);
49918
49919diff --git a/fs/dcache.c b/fs/dcache.c
49920index 19153a0..428c2f5 100644
49921--- a/fs/dcache.c
49922+++ b/fs/dcache.c
49923@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49924 mempages -= reserve;
49925
49926 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49927- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49928+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49929
49930 dcache_init();
49931 inode_init();
49932diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49933index a5f12b7..4ee8a6f 100644
49934--- a/fs/debugfs/inode.c
49935+++ b/fs/debugfs/inode.c
49936@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49937 */
49938 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49939 {
49940+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49941+ return __create_file(name, S_IFDIR | S_IRWXU,
49942+#else
49943 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49944+#endif
49945 parent, NULL, NULL);
49946 }
49947 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49948diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49949index cc7709e..7e7211f 100644
49950--- a/fs/ecryptfs/inode.c
49951+++ b/fs/ecryptfs/inode.c
49952@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49953 old_fs = get_fs();
49954 set_fs(get_ds());
49955 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49956- (char __user *)lower_buf,
49957+ (char __force_user *)lower_buf,
49958 PATH_MAX);
49959 set_fs(old_fs);
49960 if (rc < 0)
49961@@ -706,7 +706,7 @@ out:
49962 static void
49963 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49964 {
49965- char *buf = nd_get_link(nd);
49966+ const char *buf = nd_get_link(nd);
49967 if (!IS_ERR(buf)) {
49968 /* Free the char* */
49969 kfree(buf);
49970diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49971index 412e6ed..4292d22 100644
49972--- a/fs/ecryptfs/miscdev.c
49973+++ b/fs/ecryptfs/miscdev.c
49974@@ -315,7 +315,7 @@ check_list:
49975 goto out_unlock_msg_ctx;
49976 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49977 if (msg_ctx->msg) {
49978- if (copy_to_user(&buf[i], packet_length, packet_length_size))
49979+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49980 goto out_unlock_msg_ctx;
49981 i += packet_length_size;
49982 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49983diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49984index b2a34a1..162fa69 100644
49985--- a/fs/ecryptfs/read_write.c
49986+++ b/fs/ecryptfs/read_write.c
49987@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49988 return -EIO;
49989 fs_save = get_fs();
49990 set_fs(get_ds());
49991- rc = vfs_write(lower_file, data, size, &offset);
49992+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49993 set_fs(fs_save);
49994 mark_inode_dirty_sync(ecryptfs_inode);
49995 return rc;
49996@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49997 return -EIO;
49998 fs_save = get_fs();
49999 set_fs(get_ds());
50000- rc = vfs_read(lower_file, data, size, &offset);
50001+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50002 set_fs(fs_save);
50003 return rc;
50004 }
50005diff --git a/fs/exec.c b/fs/exec.c
50006index 20df02c..09b65a1 100644
50007--- a/fs/exec.c
50008+++ b/fs/exec.c
50009@@ -55,6 +55,17 @@
50010 #include <linux/pipe_fs_i.h>
50011 #include <linux/oom.h>
50012 #include <linux/compat.h>
50013+#include <linux/random.h>
50014+#include <linux/seq_file.h>
50015+#include <linux/coredump.h>
50016+#include <linux/mman.h>
50017+
50018+#ifdef CONFIG_PAX_REFCOUNT
50019+#include <linux/kallsyms.h>
50020+#include <linux/kdebug.h>
50021+#endif
50022+
50023+#include <trace/events/fs.h>
50024
50025 #include <asm/uaccess.h>
50026 #include <asm/mmu_context.h>
50027@@ -66,6 +77,18 @@
50028
50029 #include <trace/events/sched.h>
50030
50031+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50032+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50033+{
50034+ 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");
50035+}
50036+#endif
50037+
50038+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50039+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50040+EXPORT_SYMBOL(pax_set_initial_flags_func);
50041+#endif
50042+
50043 int suid_dumpable = 0;
50044
50045 static LIST_HEAD(formats);
50046@@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50047 {
50048 BUG_ON(!fmt);
50049 write_lock(&binfmt_lock);
50050- insert ? list_add(&fmt->lh, &formats) :
50051- list_add_tail(&fmt->lh, &formats);
50052+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50053+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50054 write_unlock(&binfmt_lock);
50055 }
50056
50057@@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
50058 void unregister_binfmt(struct linux_binfmt * fmt)
50059 {
50060 write_lock(&binfmt_lock);
50061- list_del(&fmt->lh);
50062+ pax_list_del((struct list_head *)&fmt->lh);
50063 write_unlock(&binfmt_lock);
50064 }
50065
50066@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50067 int write)
50068 {
50069 struct page *page;
50070- int ret;
50071
50072-#ifdef CONFIG_STACK_GROWSUP
50073- if (write) {
50074- ret = expand_downwards(bprm->vma, pos);
50075- if (ret < 0)
50076- return NULL;
50077- }
50078-#endif
50079- ret = get_user_pages(current, bprm->mm, pos,
50080- 1, write, 1, &page, NULL);
50081- if (ret <= 0)
50082+ if (0 > expand_downwards(bprm->vma, pos))
50083+ return NULL;
50084+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50085 return NULL;
50086
50087 if (write) {
50088@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50089 if (size <= ARG_MAX)
50090 return page;
50091
50092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50093+ // only allow 512KB for argv+env on suid/sgid binaries
50094+ // to prevent easy ASLR exhaustion
50095+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50096+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50097+ (size > (512 * 1024))) {
50098+ put_page(page);
50099+ return NULL;
50100+ }
50101+#endif
50102+
50103 /*
50104 * Limit to 1/4-th the stack size for the argv+env strings.
50105 * This ensures that:
50106@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50107 vma->vm_end = STACK_TOP_MAX;
50108 vma->vm_start = vma->vm_end - PAGE_SIZE;
50109 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50110+
50111+#ifdef CONFIG_PAX_SEGMEXEC
50112+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50113+#endif
50114+
50115 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50116 INIT_LIST_HEAD(&vma->anon_vma_chain);
50117
50118@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50119 mm->stack_vm = mm->total_vm = 1;
50120 up_write(&mm->mmap_sem);
50121 bprm->p = vma->vm_end - sizeof(void *);
50122+
50123+#ifdef CONFIG_PAX_RANDUSTACK
50124+ if (randomize_va_space)
50125+ bprm->p ^= random32() & ~PAGE_MASK;
50126+#endif
50127+
50128 return 0;
50129 err:
50130 up_write(&mm->mmap_sem);
50131@@ -396,7 +433,7 @@ struct user_arg_ptr {
50132 } ptr;
50133 };
50134
50135-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50136+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50137 {
50138 const char __user *native;
50139
50140@@ -405,14 +442,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50141 compat_uptr_t compat;
50142
50143 if (get_user(compat, argv.ptr.compat + nr))
50144- return ERR_PTR(-EFAULT);
50145+ return (const char __force_user *)ERR_PTR(-EFAULT);
50146
50147 return compat_ptr(compat);
50148 }
50149 #endif
50150
50151 if (get_user(native, argv.ptr.native + nr))
50152- return ERR_PTR(-EFAULT);
50153+ return (const char __force_user *)ERR_PTR(-EFAULT);
50154
50155 return native;
50156 }
50157@@ -431,7 +468,7 @@ static int count(struct user_arg_ptr argv, int max)
50158 if (!p)
50159 break;
50160
50161- if (IS_ERR(p))
50162+ if (IS_ERR((const char __force_kernel *)p))
50163 return -EFAULT;
50164
50165 if (i >= max)
50166@@ -466,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50167
50168 ret = -EFAULT;
50169 str = get_user_arg_ptr(argv, argc);
50170- if (IS_ERR(str))
50171+ if (IS_ERR((const char __force_kernel *)str))
50172 goto out;
50173
50174 len = strnlen_user(str, MAX_ARG_STRLEN);
50175@@ -548,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50176 int r;
50177 mm_segment_t oldfs = get_fs();
50178 struct user_arg_ptr argv = {
50179- .ptr.native = (const char __user *const __user *)__argv,
50180+ .ptr.native = (const char __force_user *const __force_user *)__argv,
50181 };
50182
50183 set_fs(KERNEL_DS);
50184@@ -583,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50185 unsigned long new_end = old_end - shift;
50186 struct mmu_gather tlb;
50187
50188- BUG_ON(new_start > new_end);
50189+ if (new_start >= new_end || new_start < mmap_min_addr)
50190+ return -ENOMEM;
50191
50192 /*
50193 * ensure there are no vmas between where we want to go
50194@@ -592,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50195 if (vma != find_vma(mm, new_start))
50196 return -EFAULT;
50197
50198+#ifdef CONFIG_PAX_SEGMEXEC
50199+ BUG_ON(pax_find_mirror_vma(vma));
50200+#endif
50201+
50202 /*
50203 * cover the whole range: [new_start, old_end)
50204 */
50205@@ -672,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50206 stack_top = arch_align_stack(stack_top);
50207 stack_top = PAGE_ALIGN(stack_top);
50208
50209- if (unlikely(stack_top < mmap_min_addr) ||
50210- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50211- return -ENOMEM;
50212-
50213 stack_shift = vma->vm_end - stack_top;
50214
50215 bprm->p -= stack_shift;
50216@@ -687,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50217 bprm->exec -= stack_shift;
50218
50219 down_write(&mm->mmap_sem);
50220+
50221+ /* Move stack pages down in memory. */
50222+ if (stack_shift) {
50223+ ret = shift_arg_pages(vma, stack_shift);
50224+ if (ret)
50225+ goto out_unlock;
50226+ }
50227+
50228 vm_flags = VM_STACK_FLAGS;
50229
50230+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50231+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50232+ vm_flags &= ~VM_EXEC;
50233+
50234+#ifdef CONFIG_PAX_MPROTECT
50235+ if (mm->pax_flags & MF_PAX_MPROTECT)
50236+ vm_flags &= ~VM_MAYEXEC;
50237+#endif
50238+
50239+ }
50240+#endif
50241+
50242 /*
50243 * Adjust stack execute permissions; explicitly enable for
50244 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50245@@ -707,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50246 goto out_unlock;
50247 BUG_ON(prev != vma);
50248
50249- /* Move stack pages down in memory. */
50250- if (stack_shift) {
50251- ret = shift_arg_pages(vma, stack_shift);
50252- if (ret)
50253- goto out_unlock;
50254- }
50255-
50256 /* mprotect_fixup is overkill to remove the temporary stack flags */
50257 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50258
50259@@ -737,6 +788,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50260 #endif
50261 current->mm->start_stack = bprm->p;
50262 ret = expand_stack(vma, stack_base);
50263+
50264+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50265+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50266+ unsigned long size, flags, vm_flags;
50267+
50268+ size = STACK_TOP - vma->vm_end;
50269+ flags = MAP_FIXED | MAP_PRIVATE;
50270+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50271+
50272+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
50273+
50274+#ifdef CONFIG_X86
50275+ if (!ret) {
50276+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50277+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), flags, vm_flags, 0);
50278+ }
50279+#endif
50280+
50281+ }
50282+#endif
50283+
50284 if (ret)
50285 ret = -EFAULT;
50286
50287@@ -772,6 +844,8 @@ struct file *open_exec(const char *name)
50288
50289 fsnotify_open(file);
50290
50291+ trace_open_exec(name);
50292+
50293 err = deny_write_access(file);
50294 if (err)
50295 goto exit;
50296@@ -795,7 +869,7 @@ int kernel_read(struct file *file, loff_t offset,
50297 old_fs = get_fs();
50298 set_fs(get_ds());
50299 /* The cast to a user pointer is valid due to the set_fs() */
50300- result = vfs_read(file, (void __user *)addr, count, &pos);
50301+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50302 set_fs(old_fs);
50303 return result;
50304 }
50305@@ -1247,7 +1321,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50306 }
50307 rcu_read_unlock();
50308
50309- if (p->fs->users > n_fs) {
50310+ if (atomic_read(&p->fs->users) > n_fs) {
50311 bprm->unsafe |= LSM_UNSAFE_SHARE;
50312 } else {
50313 res = -EAGAIN;
50314@@ -1447,6 +1521,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50315
50316 EXPORT_SYMBOL(search_binary_handler);
50317
50318+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50319+static DEFINE_PER_CPU(u64, exec_counter);
50320+static int __init init_exec_counters(void)
50321+{
50322+ unsigned int cpu;
50323+
50324+ for_each_possible_cpu(cpu) {
50325+ per_cpu(exec_counter, cpu) = (u64)cpu;
50326+ }
50327+
50328+ return 0;
50329+}
50330+early_initcall(init_exec_counters);
50331+static inline void increment_exec_counter(void)
50332+{
50333+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50334+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50335+}
50336+#else
50337+static inline void increment_exec_counter(void) {}
50338+#endif
50339+
50340+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50341+ struct user_arg_ptr argv);
50342+
50343 /*
50344 * sys_execve() executes a new program.
50345 */
50346@@ -1454,6 +1553,11 @@ static int do_execve_common(const char *filename,
50347 struct user_arg_ptr argv,
50348 struct user_arg_ptr envp)
50349 {
50350+#ifdef CONFIG_GRKERNSEC
50351+ struct file *old_exec_file;
50352+ struct acl_subject_label *old_acl;
50353+ struct rlimit old_rlim[RLIM_NLIMITS];
50354+#endif
50355 struct linux_binprm *bprm;
50356 struct file *file;
50357 struct files_struct *displaced;
50358@@ -1461,6 +1565,8 @@ static int do_execve_common(const char *filename,
50359 int retval;
50360 const struct cred *cred = current_cred();
50361
50362+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
50363+
50364 /*
50365 * We move the actual failure in case of RLIMIT_NPROC excess from
50366 * set*uid() to execve() because too many poorly written programs
50367@@ -1501,12 +1607,27 @@ static int do_execve_common(const char *filename,
50368 if (IS_ERR(file))
50369 goto out_unmark;
50370
50371+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50372+ retval = -EPERM;
50373+ goto out_file;
50374+ }
50375+
50376 sched_exec();
50377
50378 bprm->file = file;
50379 bprm->filename = filename;
50380 bprm->interp = filename;
50381
50382+ if (gr_process_user_ban()) {
50383+ retval = -EPERM;
50384+ goto out_file;
50385+ }
50386+
50387+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
50388+ retval = -EACCES;
50389+ goto out_file;
50390+ }
50391+
50392 retval = bprm_mm_init(bprm);
50393 if (retval)
50394 goto out_file;
50395@@ -1523,24 +1644,65 @@ static int do_execve_common(const char *filename,
50396 if (retval < 0)
50397 goto out;
50398
50399+#ifdef CONFIG_GRKERNSEC
50400+ old_acl = current->acl;
50401+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
50402+ old_exec_file = current->exec_file;
50403+ get_file(file);
50404+ current->exec_file = file;
50405+#endif
50406+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50407+ /* limit suid stack to 8MB
50408+ * we saved the old limits above and will restore them if this exec fails
50409+ */
50410+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
50411+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
50412+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
50413+#endif
50414+
50415+ if (!gr_tpe_allow(file)) {
50416+ retval = -EACCES;
50417+ goto out_fail;
50418+ }
50419+
50420+ if (gr_check_crash_exec(file)) {
50421+ retval = -EACCES;
50422+ goto out_fail;
50423+ }
50424+
50425+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
50426+ bprm->unsafe);
50427+ if (retval < 0)
50428+ goto out_fail;
50429+
50430 retval = copy_strings_kernel(1, &bprm->filename, bprm);
50431 if (retval < 0)
50432- goto out;
50433+ goto out_fail;
50434
50435 bprm->exec = bprm->p;
50436 retval = copy_strings(bprm->envc, envp, bprm);
50437 if (retval < 0)
50438- goto out;
50439+ goto out_fail;
50440
50441 retval = copy_strings(bprm->argc, argv, bprm);
50442 if (retval < 0)
50443- goto out;
50444+ goto out_fail;
50445+
50446+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
50447+
50448+ gr_handle_exec_args(bprm, argv);
50449
50450 retval = search_binary_handler(bprm);
50451 if (retval < 0)
50452- goto out;
50453+ goto out_fail;
50454+#ifdef CONFIG_GRKERNSEC
50455+ if (old_exec_file)
50456+ fput(old_exec_file);
50457+#endif
50458
50459 /* execve succeeded */
50460+
50461+ increment_exec_counter();
50462 current->fs->in_exec = 0;
50463 current->in_execve = 0;
50464 acct_update_integrals(current);
50465@@ -1549,6 +1711,14 @@ static int do_execve_common(const char *filename,
50466 put_files_struct(displaced);
50467 return retval;
50468
50469+out_fail:
50470+#ifdef CONFIG_GRKERNSEC
50471+ current->acl = old_acl;
50472+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50473+ fput(current->exec_file);
50474+ current->exec_file = old_exec_file;
50475+#endif
50476+
50477 out:
50478 if (bprm->mm) {
50479 acct_arg_size(bprm, 0);
50480@@ -1697,3 +1867,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50481 return error;
50482 }
50483 #endif
50484+
50485+int pax_check_flags(unsigned long *flags)
50486+{
50487+ int retval = 0;
50488+
50489+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50490+ if (*flags & MF_PAX_SEGMEXEC)
50491+ {
50492+ *flags &= ~MF_PAX_SEGMEXEC;
50493+ retval = -EINVAL;
50494+ }
50495+#endif
50496+
50497+ if ((*flags & MF_PAX_PAGEEXEC)
50498+
50499+#ifdef CONFIG_PAX_PAGEEXEC
50500+ && (*flags & MF_PAX_SEGMEXEC)
50501+#endif
50502+
50503+ )
50504+ {
50505+ *flags &= ~MF_PAX_PAGEEXEC;
50506+ retval = -EINVAL;
50507+ }
50508+
50509+ if ((*flags & MF_PAX_MPROTECT)
50510+
50511+#ifdef CONFIG_PAX_MPROTECT
50512+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50513+#endif
50514+
50515+ )
50516+ {
50517+ *flags &= ~MF_PAX_MPROTECT;
50518+ retval = -EINVAL;
50519+ }
50520+
50521+ if ((*flags & MF_PAX_EMUTRAMP)
50522+
50523+#ifdef CONFIG_PAX_EMUTRAMP
50524+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50525+#endif
50526+
50527+ )
50528+ {
50529+ *flags &= ~MF_PAX_EMUTRAMP;
50530+ retval = -EINVAL;
50531+ }
50532+
50533+ return retval;
50534+}
50535+
50536+EXPORT_SYMBOL(pax_check_flags);
50537+
50538+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50539+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50540+{
50541+ struct task_struct *tsk = current;
50542+ struct mm_struct *mm = current->mm;
50543+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50544+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50545+ char *path_exec = NULL;
50546+ char *path_fault = NULL;
50547+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
50548+ siginfo_t info = { };
50549+
50550+ if (buffer_exec && buffer_fault) {
50551+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50552+
50553+ down_read(&mm->mmap_sem);
50554+ vma = mm->mmap;
50555+ while (vma && (!vma_exec || !vma_fault)) {
50556+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50557+ vma_exec = vma;
50558+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50559+ vma_fault = vma;
50560+ vma = vma->vm_next;
50561+ }
50562+ if (vma_exec) {
50563+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50564+ if (IS_ERR(path_exec))
50565+ path_exec = "<path too long>";
50566+ else {
50567+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50568+ if (path_exec) {
50569+ *path_exec = 0;
50570+ path_exec = buffer_exec;
50571+ } else
50572+ path_exec = "<path too long>";
50573+ }
50574+ }
50575+ if (vma_fault) {
50576+ start = vma_fault->vm_start;
50577+ end = vma_fault->vm_end;
50578+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50579+ if (vma_fault->vm_file) {
50580+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50581+ if (IS_ERR(path_fault))
50582+ path_fault = "<path too long>";
50583+ else {
50584+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50585+ if (path_fault) {
50586+ *path_fault = 0;
50587+ path_fault = buffer_fault;
50588+ } else
50589+ path_fault = "<path too long>";
50590+ }
50591+ } else
50592+ path_fault = "<anonymous mapping>";
50593+ }
50594+ up_read(&mm->mmap_sem);
50595+ }
50596+ if (tsk->signal->curr_ip)
50597+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50598+ else
50599+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50600+ 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),
50601+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
50602+ free_page((unsigned long)buffer_exec);
50603+ free_page((unsigned long)buffer_fault);
50604+ pax_report_insns(regs, pc, sp);
50605+ info.si_signo = SIGKILL;
50606+ info.si_errno = 0;
50607+ info.si_code = SI_KERNEL;
50608+ info.si_pid = 0;
50609+ info.si_uid = 0;
50610+ do_coredump(&info);
50611+}
50612+#endif
50613+
50614+#ifdef CONFIG_PAX_REFCOUNT
50615+void pax_report_refcount_overflow(struct pt_regs *regs)
50616+{
50617+ if (current->signal->curr_ip)
50618+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50619+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
50620+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50621+ else
50622+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50623+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50624+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50625+ show_regs(regs);
50626+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50627+}
50628+#endif
50629+
50630+#ifdef CONFIG_PAX_USERCOPY
50631+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50632+static noinline int check_stack_object(const void *obj, unsigned long len)
50633+{
50634+ const void * const stack = task_stack_page(current);
50635+ const void * const stackend = stack + THREAD_SIZE;
50636+
50637+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50638+ const void *frame = NULL;
50639+ const void *oldframe;
50640+#endif
50641+
50642+ if (obj + len < obj)
50643+ return -1;
50644+
50645+ if (obj + len <= stack || stackend <= obj)
50646+ return 0;
50647+
50648+ if (obj < stack || stackend < obj + len)
50649+ return -1;
50650+
50651+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50652+ oldframe = __builtin_frame_address(1);
50653+ if (oldframe)
50654+ frame = __builtin_frame_address(2);
50655+ /*
50656+ low ----------------------------------------------> high
50657+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
50658+ ^----------------^
50659+ allow copies only within here
50660+ */
50661+ while (stack <= frame && frame < stackend) {
50662+ /* if obj + len extends past the last frame, this
50663+ check won't pass and the next frame will be 0,
50664+ causing us to bail out and correctly report
50665+ the copy as invalid
50666+ */
50667+ if (obj + len <= frame)
50668+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50669+ oldframe = frame;
50670+ frame = *(const void * const *)frame;
50671+ }
50672+ return -1;
50673+#else
50674+ return 1;
50675+#endif
50676+}
50677+
50678+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50679+{
50680+ if (current->signal->curr_ip)
50681+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50682+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50683+ else
50684+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50685+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50686+ dump_stack();
50687+ gr_handle_kernel_exploit();
50688+ do_group_exit(SIGKILL);
50689+}
50690+#endif
50691+
50692+void __check_object_size(const void *ptr, unsigned long n, bool to)
50693+{
50694+
50695+#ifdef CONFIG_PAX_USERCOPY
50696+ const char *type;
50697+
50698+ if (!n)
50699+ return;
50700+
50701+ type = check_heap_object(ptr, n);
50702+ if (!type) {
50703+ if (check_stack_object(ptr, n) != -1)
50704+ return;
50705+ type = "<process stack>";
50706+ }
50707+
50708+ pax_report_usercopy(ptr, n, to, type);
50709+#endif
50710+
50711+}
50712+EXPORT_SYMBOL(__check_object_size);
50713+
50714+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50715+void pax_track_stack(void)
50716+{
50717+ unsigned long sp = (unsigned long)&sp;
50718+ if (sp < current_thread_info()->lowest_stack &&
50719+ sp > (unsigned long)task_stack_page(current))
50720+ current_thread_info()->lowest_stack = sp;
50721+}
50722+EXPORT_SYMBOL(pax_track_stack);
50723+#endif
50724+
50725+#ifdef CONFIG_PAX_SIZE_OVERFLOW
50726+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50727+{
50728+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50729+ dump_stack();
50730+ do_group_exit(SIGKILL);
50731+}
50732+EXPORT_SYMBOL(report_size_overflow);
50733+#endif
50734diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50735index 2616d0e..2ffdec9 100644
50736--- a/fs/ext2/balloc.c
50737+++ b/fs/ext2/balloc.c
50738@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50739
50740 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50741 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50742- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50743+ if (free_blocks < root_blocks + 1 &&
50744 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50745 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50746- !in_group_p (sbi->s_resgid))) {
50747+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50748 return 0;
50749 }
50750 return 1;
50751diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50752index 22548f5..41521d8 100644
50753--- a/fs/ext3/balloc.c
50754+++ b/fs/ext3/balloc.c
50755@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50756
50757 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50758 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50759- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50760+ if (free_blocks < root_blocks + 1 &&
50761 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50762 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50763- !in_group_p (sbi->s_resgid))) {
50764+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50765 return 0;
50766 }
50767 return 1;
50768diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50769index 92e68b3..115d987 100644
50770--- a/fs/ext4/balloc.c
50771+++ b/fs/ext4/balloc.c
50772@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50773 /* Hm, nope. Are (enough) root reserved clusters available? */
50774 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50775 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50776- capable(CAP_SYS_RESOURCE) ||
50777- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50778+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50779+ capable_nolog(CAP_SYS_RESOURCE)) {
50780
50781 if (free_clusters >= (nclusters + dirty_clusters))
50782 return 1;
50783diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50784index 8462eb3..4a71af6 100644
50785--- a/fs/ext4/ext4.h
50786+++ b/fs/ext4/ext4.h
50787@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50788 unsigned long s_mb_last_start;
50789
50790 /* stats for buddy allocator */
50791- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50792- atomic_t s_bal_success; /* we found long enough chunks */
50793- atomic_t s_bal_allocated; /* in blocks */
50794- atomic_t s_bal_ex_scanned; /* total extents scanned */
50795- atomic_t s_bal_goals; /* goal hits */
50796- atomic_t s_bal_breaks; /* too long searches */
50797- atomic_t s_bal_2orders; /* 2^order hits */
50798+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50799+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50800+ atomic_unchecked_t s_bal_allocated; /* in blocks */
50801+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50802+ atomic_unchecked_t s_bal_goals; /* goal hits */
50803+ atomic_unchecked_t s_bal_breaks; /* too long searches */
50804+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50805 spinlock_t s_bal_lock;
50806 unsigned long s_mb_buddies_generated;
50807 unsigned long long s_mb_generation_time;
50808- atomic_t s_mb_lost_chunks;
50809- atomic_t s_mb_preallocated;
50810- atomic_t s_mb_discarded;
50811+ atomic_unchecked_t s_mb_lost_chunks;
50812+ atomic_unchecked_t s_mb_preallocated;
50813+ atomic_unchecked_t s_mb_discarded;
50814 atomic_t s_lock_busy;
50815
50816 /* locality groups */
50817diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50818index 28bbf9b..75ca7c1 100644
50819--- a/fs/ext4/mballoc.c
50820+++ b/fs/ext4/mballoc.c
50821@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50822 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50823
50824 if (EXT4_SB(sb)->s_mb_stats)
50825- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50826+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50827
50828 break;
50829 }
50830@@ -2044,7 +2044,7 @@ repeat:
50831 ac->ac_status = AC_STATUS_CONTINUE;
50832 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50833 cr = 3;
50834- atomic_inc(&sbi->s_mb_lost_chunks);
50835+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50836 goto repeat;
50837 }
50838 }
50839@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50840 if (sbi->s_mb_stats) {
50841 ext4_msg(sb, KERN_INFO,
50842 "mballoc: %u blocks %u reqs (%u success)",
50843- atomic_read(&sbi->s_bal_allocated),
50844- atomic_read(&sbi->s_bal_reqs),
50845- atomic_read(&sbi->s_bal_success));
50846+ atomic_read_unchecked(&sbi->s_bal_allocated),
50847+ atomic_read_unchecked(&sbi->s_bal_reqs),
50848+ atomic_read_unchecked(&sbi->s_bal_success));
50849 ext4_msg(sb, KERN_INFO,
50850 "mballoc: %u extents scanned, %u goal hits, "
50851 "%u 2^N hits, %u breaks, %u lost",
50852- atomic_read(&sbi->s_bal_ex_scanned),
50853- atomic_read(&sbi->s_bal_goals),
50854- atomic_read(&sbi->s_bal_2orders),
50855- atomic_read(&sbi->s_bal_breaks),
50856- atomic_read(&sbi->s_mb_lost_chunks));
50857+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50858+ atomic_read_unchecked(&sbi->s_bal_goals),
50859+ atomic_read_unchecked(&sbi->s_bal_2orders),
50860+ atomic_read_unchecked(&sbi->s_bal_breaks),
50861+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50862 ext4_msg(sb, KERN_INFO,
50863 "mballoc: %lu generated and it took %Lu",
50864 sbi->s_mb_buddies_generated,
50865 sbi->s_mb_generation_time);
50866 ext4_msg(sb, KERN_INFO,
50867 "mballoc: %u preallocated, %u discarded",
50868- atomic_read(&sbi->s_mb_preallocated),
50869- atomic_read(&sbi->s_mb_discarded));
50870+ atomic_read_unchecked(&sbi->s_mb_preallocated),
50871+ atomic_read_unchecked(&sbi->s_mb_discarded));
50872 }
50873
50874 free_percpu(sbi->s_locality_groups);
50875@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50876 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50877
50878 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50879- atomic_inc(&sbi->s_bal_reqs);
50880- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50881+ atomic_inc_unchecked(&sbi->s_bal_reqs);
50882+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50883 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50884- atomic_inc(&sbi->s_bal_success);
50885- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50886+ atomic_inc_unchecked(&sbi->s_bal_success);
50887+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50888 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50889 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50890- atomic_inc(&sbi->s_bal_goals);
50891+ atomic_inc_unchecked(&sbi->s_bal_goals);
50892 if (ac->ac_found > sbi->s_mb_max_to_scan)
50893- atomic_inc(&sbi->s_bal_breaks);
50894+ atomic_inc_unchecked(&sbi->s_bal_breaks);
50895 }
50896
50897 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50898@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50899 trace_ext4_mb_new_inode_pa(ac, pa);
50900
50901 ext4_mb_use_inode_pa(ac, pa);
50902- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50903+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50904
50905 ei = EXT4_I(ac->ac_inode);
50906 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50907@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50908 trace_ext4_mb_new_group_pa(ac, pa);
50909
50910 ext4_mb_use_group_pa(ac, pa);
50911- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50912+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50913
50914 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50915 lg = ac->ac_lg;
50916@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50917 * from the bitmap and continue.
50918 */
50919 }
50920- atomic_add(free, &sbi->s_mb_discarded);
50921+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
50922
50923 return err;
50924 }
50925@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50926 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50927 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50928 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50929- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50930+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50931 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50932
50933 return 0;
50934diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50935index 5fa223d..12fa738 100644
50936--- a/fs/ext4/super.c
50937+++ b/fs/ext4/super.c
50938@@ -2429,7 +2429,7 @@ struct ext4_attr {
50939 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50940 const char *, size_t);
50941 int offset;
50942-};
50943+} __do_const;
50944
50945 static int parse_strtoul(const char *buf,
50946 unsigned long max, unsigned long *value)
50947diff --git a/fs/fcntl.c b/fs/fcntl.c
50948index 71a600a..20d87b1 100644
50949--- a/fs/fcntl.c
50950+++ b/fs/fcntl.c
50951@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50952 if (err)
50953 return err;
50954
50955+ if (gr_handle_chroot_fowner(pid, type))
50956+ return -ENOENT;
50957+ if (gr_check_protected_task_fowner(pid, type))
50958+ return -EACCES;
50959+
50960 f_modown(filp, pid, type, force);
50961 return 0;
50962 }
50963diff --git a/fs/fhandle.c b/fs/fhandle.c
50964index 999ff5c..41f4109 100644
50965--- a/fs/fhandle.c
50966+++ b/fs/fhandle.c
50967@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50968 } else
50969 retval = 0;
50970 /* copy the mount id */
50971- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50972- sizeof(*mnt_id)) ||
50973+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50974 copy_to_user(ufh, handle,
50975 sizeof(struct file_handle) + handle_bytes))
50976 retval = -EFAULT;
50977diff --git a/fs/fifo.c b/fs/fifo.c
50978index cf6f434..3d7942c 100644
50979--- a/fs/fifo.c
50980+++ b/fs/fifo.c
50981@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50982 */
50983 filp->f_op = &read_pipefifo_fops;
50984 pipe->r_counter++;
50985- if (pipe->readers++ == 0)
50986+ if (atomic_inc_return(&pipe->readers) == 1)
50987 wake_up_partner(inode);
50988
50989- if (!pipe->writers) {
50990+ if (!atomic_read(&pipe->writers)) {
50991 if ((filp->f_flags & O_NONBLOCK)) {
50992 /* suppress POLLHUP until we have
50993 * seen a writer */
50994@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50995 * errno=ENXIO when there is no process reading the FIFO.
50996 */
50997 ret = -ENXIO;
50998- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50999+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51000 goto err;
51001
51002 filp->f_op = &write_pipefifo_fops;
51003 pipe->w_counter++;
51004- if (!pipe->writers++)
51005+ if (atomic_inc_return(&pipe->writers) == 1)
51006 wake_up_partner(inode);
51007
51008- if (!pipe->readers) {
51009+ if (!atomic_read(&pipe->readers)) {
51010 if (wait_for_partner(inode, &pipe->r_counter))
51011 goto err_wr;
51012 }
51013@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51014 */
51015 filp->f_op = &rdwr_pipefifo_fops;
51016
51017- pipe->readers++;
51018- pipe->writers++;
51019+ atomic_inc(&pipe->readers);
51020+ atomic_inc(&pipe->writers);
51021 pipe->r_counter++;
51022 pipe->w_counter++;
51023- if (pipe->readers == 1 || pipe->writers == 1)
51024+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51025 wake_up_partner(inode);
51026 break;
51027
51028@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51029 return 0;
51030
51031 err_rd:
51032- if (!--pipe->readers)
51033+ if (atomic_dec_and_test(&pipe->readers))
51034 wake_up_interruptible(&pipe->wait);
51035 ret = -ERESTARTSYS;
51036 goto err;
51037
51038 err_wr:
51039- if (!--pipe->writers)
51040+ if (atomic_dec_and_test(&pipe->writers))
51041 wake_up_interruptible(&pipe->wait);
51042 ret = -ERESTARTSYS;
51043 goto err;
51044
51045 err:
51046- if (!pipe->readers && !pipe->writers)
51047+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51048 free_pipe_info(inode);
51049
51050 err_nocleanup:
51051diff --git a/fs/file.c b/fs/file.c
51052index 2b3570b..c57924b 100644
51053--- a/fs/file.c
51054+++ b/fs/file.c
51055@@ -16,6 +16,7 @@
51056 #include <linux/slab.h>
51057 #include <linux/vmalloc.h>
51058 #include <linux/file.h>
51059+#include <linux/security.h>
51060 #include <linux/fdtable.h>
51061 #include <linux/bitops.h>
51062 #include <linux/interrupt.h>
51063@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51064 if (!file)
51065 return __close_fd(files, fd);
51066
51067+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51068 if (fd >= rlimit(RLIMIT_NOFILE))
51069 return -EBADF;
51070
51071@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51072 if (unlikely(oldfd == newfd))
51073 return -EINVAL;
51074
51075+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51076 if (newfd >= rlimit(RLIMIT_NOFILE))
51077 return -EBADF;
51078
51079@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51080 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51081 {
51082 int err;
51083+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51084 if (from >= rlimit(RLIMIT_NOFILE))
51085 return -EINVAL;
51086 err = alloc_fd(from, flags);
51087diff --git a/fs/filesystems.c b/fs/filesystems.c
51088index da165f6..3671bdb 100644
51089--- a/fs/filesystems.c
51090+++ b/fs/filesystems.c
51091@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
51092 int len = dot ? dot - name : strlen(name);
51093
51094 fs = __get_fs_type(name, len);
51095+
51096+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51097+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
51098+#else
51099 if (!fs && (request_module("%.*s", len, name) == 0))
51100+#endif
51101 fs = __get_fs_type(name, len);
51102
51103 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51104diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51105index fe6ca58..65318cf 100644
51106--- a/fs/fs_struct.c
51107+++ b/fs/fs_struct.c
51108@@ -4,6 +4,7 @@
51109 #include <linux/path.h>
51110 #include <linux/slab.h>
51111 #include <linux/fs_struct.h>
51112+#include <linux/grsecurity.h>
51113 #include "internal.h"
51114
51115 /*
51116@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51117 write_seqcount_begin(&fs->seq);
51118 old_root = fs->root;
51119 fs->root = *path;
51120+ gr_set_chroot_entries(current, path);
51121 write_seqcount_end(&fs->seq);
51122 spin_unlock(&fs->lock);
51123 if (old_root.dentry)
51124@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51125 return 1;
51126 }
51127
51128+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51129+{
51130+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51131+ return 0;
51132+ *p = *new;
51133+
51134+ /* This function is only called from pivot_root(). Leave our
51135+ gr_chroot_dentry and is_chrooted flags as-is, so that a
51136+ pivoted root isn't treated as a chroot
51137+ */
51138+ //gr_set_chroot_entries(task, new);
51139+
51140+ return 1;
51141+}
51142+
51143 void chroot_fs_refs(struct path *old_root, struct path *new_root)
51144 {
51145 struct task_struct *g, *p;
51146@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
51147 int hits = 0;
51148 spin_lock(&fs->lock);
51149 write_seqcount_begin(&fs->seq);
51150- hits += replace_path(&fs->root, old_root, new_root);
51151+ hits += replace_root_path(p, &fs->root, old_root, new_root);
51152 hits += replace_path(&fs->pwd, old_root, new_root);
51153 write_seqcount_end(&fs->seq);
51154 while (hits--) {
51155@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
51156 task_lock(tsk);
51157 spin_lock(&fs->lock);
51158 tsk->fs = NULL;
51159- kill = !--fs->users;
51160+ gr_clear_chroot_entries(tsk);
51161+ kill = !atomic_dec_return(&fs->users);
51162 spin_unlock(&fs->lock);
51163 task_unlock(tsk);
51164 if (kill)
51165@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51166 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51167 /* We don't need to lock fs - think why ;-) */
51168 if (fs) {
51169- fs->users = 1;
51170+ atomic_set(&fs->users, 1);
51171 fs->in_exec = 0;
51172 spin_lock_init(&fs->lock);
51173 seqcount_init(&fs->seq);
51174@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51175 spin_lock(&old->lock);
51176 fs->root = old->root;
51177 path_get(&fs->root);
51178+ /* instead of calling gr_set_chroot_entries here,
51179+ we call it from every caller of this function
51180+ */
51181 fs->pwd = old->pwd;
51182 path_get(&fs->pwd);
51183 spin_unlock(&old->lock);
51184@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
51185
51186 task_lock(current);
51187 spin_lock(&fs->lock);
51188- kill = !--fs->users;
51189+ kill = !atomic_dec_return(&fs->users);
51190 current->fs = new_fs;
51191+ gr_set_chroot_entries(current, &new_fs->root);
51192 spin_unlock(&fs->lock);
51193 task_unlock(current);
51194
51195@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51196
51197 int current_umask(void)
51198 {
51199- return current->fs->umask;
51200+ return current->fs->umask | gr_acl_umask();
51201 }
51202 EXPORT_SYMBOL(current_umask);
51203
51204 /* to be mentioned only in INIT_TASK */
51205 struct fs_struct init_fs = {
51206- .users = 1,
51207+ .users = ATOMIC_INIT(1),
51208 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51209 .seq = SEQCNT_ZERO,
51210 .umask = 0022,
51211diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51212index 8dcb114..b1072e2 100644
51213--- a/fs/fscache/cookie.c
51214+++ b/fs/fscache/cookie.c
51215@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51216 parent ? (char *) parent->def->name : "<no-parent>",
51217 def->name, netfs_data);
51218
51219- fscache_stat(&fscache_n_acquires);
51220+ fscache_stat_unchecked(&fscache_n_acquires);
51221
51222 /* if there's no parent cookie, then we don't create one here either */
51223 if (!parent) {
51224- fscache_stat(&fscache_n_acquires_null);
51225+ fscache_stat_unchecked(&fscache_n_acquires_null);
51226 _leave(" [no parent]");
51227 return NULL;
51228 }
51229@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51230 /* allocate and initialise a cookie */
51231 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51232 if (!cookie) {
51233- fscache_stat(&fscache_n_acquires_oom);
51234+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51235 _leave(" [ENOMEM]");
51236 return NULL;
51237 }
51238@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51239
51240 switch (cookie->def->type) {
51241 case FSCACHE_COOKIE_TYPE_INDEX:
51242- fscache_stat(&fscache_n_cookie_index);
51243+ fscache_stat_unchecked(&fscache_n_cookie_index);
51244 break;
51245 case FSCACHE_COOKIE_TYPE_DATAFILE:
51246- fscache_stat(&fscache_n_cookie_data);
51247+ fscache_stat_unchecked(&fscache_n_cookie_data);
51248 break;
51249 default:
51250- fscache_stat(&fscache_n_cookie_special);
51251+ fscache_stat_unchecked(&fscache_n_cookie_special);
51252 break;
51253 }
51254
51255@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51256 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51257 atomic_dec(&parent->n_children);
51258 __fscache_cookie_put(cookie);
51259- fscache_stat(&fscache_n_acquires_nobufs);
51260+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51261 _leave(" = NULL");
51262 return NULL;
51263 }
51264 }
51265
51266- fscache_stat(&fscache_n_acquires_ok);
51267+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51268 _leave(" = %p", cookie);
51269 return cookie;
51270 }
51271@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51272 cache = fscache_select_cache_for_object(cookie->parent);
51273 if (!cache) {
51274 up_read(&fscache_addremove_sem);
51275- fscache_stat(&fscache_n_acquires_no_cache);
51276+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51277 _leave(" = -ENOMEDIUM [no cache]");
51278 return -ENOMEDIUM;
51279 }
51280@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51281 object = cache->ops->alloc_object(cache, cookie);
51282 fscache_stat_d(&fscache_n_cop_alloc_object);
51283 if (IS_ERR(object)) {
51284- fscache_stat(&fscache_n_object_no_alloc);
51285+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51286 ret = PTR_ERR(object);
51287 goto error;
51288 }
51289
51290- fscache_stat(&fscache_n_object_alloc);
51291+ fscache_stat_unchecked(&fscache_n_object_alloc);
51292
51293 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51294
51295@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51296
51297 _enter("{%s}", cookie->def->name);
51298
51299- fscache_stat(&fscache_n_invalidates);
51300+ fscache_stat_unchecked(&fscache_n_invalidates);
51301
51302 /* Only permit invalidation of data files. Invalidating an index will
51303 * require the caller to release all its attachments to the tree rooted
51304@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51305 struct fscache_object *object;
51306 struct hlist_node *_p;
51307
51308- fscache_stat(&fscache_n_updates);
51309+ fscache_stat_unchecked(&fscache_n_updates);
51310
51311 if (!cookie) {
51312- fscache_stat(&fscache_n_updates_null);
51313+ fscache_stat_unchecked(&fscache_n_updates_null);
51314 _leave(" [no cookie]");
51315 return;
51316 }
51317@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51318 struct fscache_object *object;
51319 unsigned long event;
51320
51321- fscache_stat(&fscache_n_relinquishes);
51322+ fscache_stat_unchecked(&fscache_n_relinquishes);
51323 if (retire)
51324- fscache_stat(&fscache_n_relinquishes_retire);
51325+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51326
51327 if (!cookie) {
51328- fscache_stat(&fscache_n_relinquishes_null);
51329+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51330 _leave(" [no cookie]");
51331 return;
51332 }
51333@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51334
51335 /* wait for the cookie to finish being instantiated (or to fail) */
51336 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51337- fscache_stat(&fscache_n_relinquishes_waitcrt);
51338+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51339 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
51340 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
51341 }
51342diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
51343index ee38fef..0a326d4 100644
51344--- a/fs/fscache/internal.h
51345+++ b/fs/fscache/internal.h
51346@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
51347 * stats.c
51348 */
51349 #ifdef CONFIG_FSCACHE_STATS
51350-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51351-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51352+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51353+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51354
51355-extern atomic_t fscache_n_op_pend;
51356-extern atomic_t fscache_n_op_run;
51357-extern atomic_t fscache_n_op_enqueue;
51358-extern atomic_t fscache_n_op_deferred_release;
51359-extern atomic_t fscache_n_op_release;
51360-extern atomic_t fscache_n_op_gc;
51361-extern atomic_t fscache_n_op_cancelled;
51362-extern atomic_t fscache_n_op_rejected;
51363+extern atomic_unchecked_t fscache_n_op_pend;
51364+extern atomic_unchecked_t fscache_n_op_run;
51365+extern atomic_unchecked_t fscache_n_op_enqueue;
51366+extern atomic_unchecked_t fscache_n_op_deferred_release;
51367+extern atomic_unchecked_t fscache_n_op_release;
51368+extern atomic_unchecked_t fscache_n_op_gc;
51369+extern atomic_unchecked_t fscache_n_op_cancelled;
51370+extern atomic_unchecked_t fscache_n_op_rejected;
51371
51372-extern atomic_t fscache_n_attr_changed;
51373-extern atomic_t fscache_n_attr_changed_ok;
51374-extern atomic_t fscache_n_attr_changed_nobufs;
51375-extern atomic_t fscache_n_attr_changed_nomem;
51376-extern atomic_t fscache_n_attr_changed_calls;
51377+extern atomic_unchecked_t fscache_n_attr_changed;
51378+extern atomic_unchecked_t fscache_n_attr_changed_ok;
51379+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
51380+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
51381+extern atomic_unchecked_t fscache_n_attr_changed_calls;
51382
51383-extern atomic_t fscache_n_allocs;
51384-extern atomic_t fscache_n_allocs_ok;
51385-extern atomic_t fscache_n_allocs_wait;
51386-extern atomic_t fscache_n_allocs_nobufs;
51387-extern atomic_t fscache_n_allocs_intr;
51388-extern atomic_t fscache_n_allocs_object_dead;
51389-extern atomic_t fscache_n_alloc_ops;
51390-extern atomic_t fscache_n_alloc_op_waits;
51391+extern atomic_unchecked_t fscache_n_allocs;
51392+extern atomic_unchecked_t fscache_n_allocs_ok;
51393+extern atomic_unchecked_t fscache_n_allocs_wait;
51394+extern atomic_unchecked_t fscache_n_allocs_nobufs;
51395+extern atomic_unchecked_t fscache_n_allocs_intr;
51396+extern atomic_unchecked_t fscache_n_allocs_object_dead;
51397+extern atomic_unchecked_t fscache_n_alloc_ops;
51398+extern atomic_unchecked_t fscache_n_alloc_op_waits;
51399
51400-extern atomic_t fscache_n_retrievals;
51401-extern atomic_t fscache_n_retrievals_ok;
51402-extern atomic_t fscache_n_retrievals_wait;
51403-extern atomic_t fscache_n_retrievals_nodata;
51404-extern atomic_t fscache_n_retrievals_nobufs;
51405-extern atomic_t fscache_n_retrievals_intr;
51406-extern atomic_t fscache_n_retrievals_nomem;
51407-extern atomic_t fscache_n_retrievals_object_dead;
51408-extern atomic_t fscache_n_retrieval_ops;
51409-extern atomic_t fscache_n_retrieval_op_waits;
51410+extern atomic_unchecked_t fscache_n_retrievals;
51411+extern atomic_unchecked_t fscache_n_retrievals_ok;
51412+extern atomic_unchecked_t fscache_n_retrievals_wait;
51413+extern atomic_unchecked_t fscache_n_retrievals_nodata;
51414+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
51415+extern atomic_unchecked_t fscache_n_retrievals_intr;
51416+extern atomic_unchecked_t fscache_n_retrievals_nomem;
51417+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
51418+extern atomic_unchecked_t fscache_n_retrieval_ops;
51419+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
51420
51421-extern atomic_t fscache_n_stores;
51422-extern atomic_t fscache_n_stores_ok;
51423-extern atomic_t fscache_n_stores_again;
51424-extern atomic_t fscache_n_stores_nobufs;
51425-extern atomic_t fscache_n_stores_oom;
51426-extern atomic_t fscache_n_store_ops;
51427-extern atomic_t fscache_n_store_calls;
51428-extern atomic_t fscache_n_store_pages;
51429-extern atomic_t fscache_n_store_radix_deletes;
51430-extern atomic_t fscache_n_store_pages_over_limit;
51431+extern atomic_unchecked_t fscache_n_stores;
51432+extern atomic_unchecked_t fscache_n_stores_ok;
51433+extern atomic_unchecked_t fscache_n_stores_again;
51434+extern atomic_unchecked_t fscache_n_stores_nobufs;
51435+extern atomic_unchecked_t fscache_n_stores_oom;
51436+extern atomic_unchecked_t fscache_n_store_ops;
51437+extern atomic_unchecked_t fscache_n_store_calls;
51438+extern atomic_unchecked_t fscache_n_store_pages;
51439+extern atomic_unchecked_t fscache_n_store_radix_deletes;
51440+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
51441
51442-extern atomic_t fscache_n_store_vmscan_not_storing;
51443-extern atomic_t fscache_n_store_vmscan_gone;
51444-extern atomic_t fscache_n_store_vmscan_busy;
51445-extern atomic_t fscache_n_store_vmscan_cancelled;
51446-extern atomic_t fscache_n_store_vmscan_wait;
51447+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51448+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51449+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51450+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51451+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51452
51453-extern atomic_t fscache_n_marks;
51454-extern atomic_t fscache_n_uncaches;
51455+extern atomic_unchecked_t fscache_n_marks;
51456+extern atomic_unchecked_t fscache_n_uncaches;
51457
51458-extern atomic_t fscache_n_acquires;
51459-extern atomic_t fscache_n_acquires_null;
51460-extern atomic_t fscache_n_acquires_no_cache;
51461-extern atomic_t fscache_n_acquires_ok;
51462-extern atomic_t fscache_n_acquires_nobufs;
51463-extern atomic_t fscache_n_acquires_oom;
51464+extern atomic_unchecked_t fscache_n_acquires;
51465+extern atomic_unchecked_t fscache_n_acquires_null;
51466+extern atomic_unchecked_t fscache_n_acquires_no_cache;
51467+extern atomic_unchecked_t fscache_n_acquires_ok;
51468+extern atomic_unchecked_t fscache_n_acquires_nobufs;
51469+extern atomic_unchecked_t fscache_n_acquires_oom;
51470
51471-extern atomic_t fscache_n_invalidates;
51472-extern atomic_t fscache_n_invalidates_run;
51473+extern atomic_unchecked_t fscache_n_invalidates;
51474+extern atomic_unchecked_t fscache_n_invalidates_run;
51475
51476-extern atomic_t fscache_n_updates;
51477-extern atomic_t fscache_n_updates_null;
51478-extern atomic_t fscache_n_updates_run;
51479+extern atomic_unchecked_t fscache_n_updates;
51480+extern atomic_unchecked_t fscache_n_updates_null;
51481+extern atomic_unchecked_t fscache_n_updates_run;
51482
51483-extern atomic_t fscache_n_relinquishes;
51484-extern atomic_t fscache_n_relinquishes_null;
51485-extern atomic_t fscache_n_relinquishes_waitcrt;
51486-extern atomic_t fscache_n_relinquishes_retire;
51487+extern atomic_unchecked_t fscache_n_relinquishes;
51488+extern atomic_unchecked_t fscache_n_relinquishes_null;
51489+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51490+extern atomic_unchecked_t fscache_n_relinquishes_retire;
51491
51492-extern atomic_t fscache_n_cookie_index;
51493-extern atomic_t fscache_n_cookie_data;
51494-extern atomic_t fscache_n_cookie_special;
51495+extern atomic_unchecked_t fscache_n_cookie_index;
51496+extern atomic_unchecked_t fscache_n_cookie_data;
51497+extern atomic_unchecked_t fscache_n_cookie_special;
51498
51499-extern atomic_t fscache_n_object_alloc;
51500-extern atomic_t fscache_n_object_no_alloc;
51501-extern atomic_t fscache_n_object_lookups;
51502-extern atomic_t fscache_n_object_lookups_negative;
51503-extern atomic_t fscache_n_object_lookups_positive;
51504-extern atomic_t fscache_n_object_lookups_timed_out;
51505-extern atomic_t fscache_n_object_created;
51506-extern atomic_t fscache_n_object_avail;
51507-extern atomic_t fscache_n_object_dead;
51508+extern atomic_unchecked_t fscache_n_object_alloc;
51509+extern atomic_unchecked_t fscache_n_object_no_alloc;
51510+extern atomic_unchecked_t fscache_n_object_lookups;
51511+extern atomic_unchecked_t fscache_n_object_lookups_negative;
51512+extern atomic_unchecked_t fscache_n_object_lookups_positive;
51513+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51514+extern atomic_unchecked_t fscache_n_object_created;
51515+extern atomic_unchecked_t fscache_n_object_avail;
51516+extern atomic_unchecked_t fscache_n_object_dead;
51517
51518-extern atomic_t fscache_n_checkaux_none;
51519-extern atomic_t fscache_n_checkaux_okay;
51520-extern atomic_t fscache_n_checkaux_update;
51521-extern atomic_t fscache_n_checkaux_obsolete;
51522+extern atomic_unchecked_t fscache_n_checkaux_none;
51523+extern atomic_unchecked_t fscache_n_checkaux_okay;
51524+extern atomic_unchecked_t fscache_n_checkaux_update;
51525+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51526
51527 extern atomic_t fscache_n_cop_alloc_object;
51528 extern atomic_t fscache_n_cop_lookup_object;
51529@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51530 atomic_inc(stat);
51531 }
51532
51533+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51534+{
51535+ atomic_inc_unchecked(stat);
51536+}
51537+
51538 static inline void fscache_stat_d(atomic_t *stat)
51539 {
51540 atomic_dec(stat);
51541@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51542
51543 #define __fscache_stat(stat) (NULL)
51544 #define fscache_stat(stat) do {} while (0)
51545+#define fscache_stat_unchecked(stat) do {} while (0)
51546 #define fscache_stat_d(stat) do {} while (0)
51547 #endif
51548
51549diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51550index 50d41c1..10ee117 100644
51551--- a/fs/fscache/object.c
51552+++ b/fs/fscache/object.c
51553@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51554 /* Invalidate an object on disk */
51555 case FSCACHE_OBJECT_INVALIDATING:
51556 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51557- fscache_stat(&fscache_n_invalidates_run);
51558+ fscache_stat_unchecked(&fscache_n_invalidates_run);
51559 fscache_stat(&fscache_n_cop_invalidate_object);
51560 fscache_invalidate_object(object);
51561 fscache_stat_d(&fscache_n_cop_invalidate_object);
51562@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51563 /* update the object metadata on disk */
51564 case FSCACHE_OBJECT_UPDATING:
51565 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51566- fscache_stat(&fscache_n_updates_run);
51567+ fscache_stat_unchecked(&fscache_n_updates_run);
51568 fscache_stat(&fscache_n_cop_update_object);
51569 object->cache->ops->update_object(object);
51570 fscache_stat_d(&fscache_n_cop_update_object);
51571@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51572 spin_lock(&object->lock);
51573 object->state = FSCACHE_OBJECT_DEAD;
51574 spin_unlock(&object->lock);
51575- fscache_stat(&fscache_n_object_dead);
51576+ fscache_stat_unchecked(&fscache_n_object_dead);
51577 goto terminal_transit;
51578
51579 /* handle the parent cache of this object being withdrawn from
51580@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51581 spin_lock(&object->lock);
51582 object->state = FSCACHE_OBJECT_DEAD;
51583 spin_unlock(&object->lock);
51584- fscache_stat(&fscache_n_object_dead);
51585+ fscache_stat_unchecked(&fscache_n_object_dead);
51586 goto terminal_transit;
51587
51588 /* complain about the object being woken up once it is
51589@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51590 parent->cookie->def->name, cookie->def->name,
51591 object->cache->tag->name);
51592
51593- fscache_stat(&fscache_n_object_lookups);
51594+ fscache_stat_unchecked(&fscache_n_object_lookups);
51595 fscache_stat(&fscache_n_cop_lookup_object);
51596 ret = object->cache->ops->lookup_object(object);
51597 fscache_stat_d(&fscache_n_cop_lookup_object);
51598@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51599 if (ret == -ETIMEDOUT) {
51600 /* probably stuck behind another object, so move this one to
51601 * the back of the queue */
51602- fscache_stat(&fscache_n_object_lookups_timed_out);
51603+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51604 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51605 }
51606
51607@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51608
51609 spin_lock(&object->lock);
51610 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51611- fscache_stat(&fscache_n_object_lookups_negative);
51612+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51613
51614 /* transit here to allow write requests to begin stacking up
51615 * and read requests to begin returning ENODATA */
51616@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51617 * result, in which case there may be data available */
51618 spin_lock(&object->lock);
51619 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51620- fscache_stat(&fscache_n_object_lookups_positive);
51621+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51622
51623 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51624
51625@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51626 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51627 } else {
51628 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51629- fscache_stat(&fscache_n_object_created);
51630+ fscache_stat_unchecked(&fscache_n_object_created);
51631
51632 object->state = FSCACHE_OBJECT_AVAILABLE;
51633 spin_unlock(&object->lock);
51634@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51635 fscache_enqueue_dependents(object);
51636
51637 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51638- fscache_stat(&fscache_n_object_avail);
51639+ fscache_stat_unchecked(&fscache_n_object_avail);
51640
51641 _leave("");
51642 }
51643@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51644 enum fscache_checkaux result;
51645
51646 if (!object->cookie->def->check_aux) {
51647- fscache_stat(&fscache_n_checkaux_none);
51648+ fscache_stat_unchecked(&fscache_n_checkaux_none);
51649 return FSCACHE_CHECKAUX_OKAY;
51650 }
51651
51652@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51653 switch (result) {
51654 /* entry okay as is */
51655 case FSCACHE_CHECKAUX_OKAY:
51656- fscache_stat(&fscache_n_checkaux_okay);
51657+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
51658 break;
51659
51660 /* entry requires update */
51661 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51662- fscache_stat(&fscache_n_checkaux_update);
51663+ fscache_stat_unchecked(&fscache_n_checkaux_update);
51664 break;
51665
51666 /* entry requires deletion */
51667 case FSCACHE_CHECKAUX_OBSOLETE:
51668- fscache_stat(&fscache_n_checkaux_obsolete);
51669+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51670 break;
51671
51672 default:
51673diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51674index 762a9ec..2023284 100644
51675--- a/fs/fscache/operation.c
51676+++ b/fs/fscache/operation.c
51677@@ -17,7 +17,7 @@
51678 #include <linux/slab.h>
51679 #include "internal.h"
51680
51681-atomic_t fscache_op_debug_id;
51682+atomic_unchecked_t fscache_op_debug_id;
51683 EXPORT_SYMBOL(fscache_op_debug_id);
51684
51685 /**
51686@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51687 ASSERTCMP(atomic_read(&op->usage), >, 0);
51688 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51689
51690- fscache_stat(&fscache_n_op_enqueue);
51691+ fscache_stat_unchecked(&fscache_n_op_enqueue);
51692 switch (op->flags & FSCACHE_OP_TYPE) {
51693 case FSCACHE_OP_ASYNC:
51694 _debug("queue async");
51695@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51696 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51697 if (op->processor)
51698 fscache_enqueue_operation(op);
51699- fscache_stat(&fscache_n_op_run);
51700+ fscache_stat_unchecked(&fscache_n_op_run);
51701 }
51702
51703 /*
51704@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51705 if (object->n_in_progress > 0) {
51706 atomic_inc(&op->usage);
51707 list_add_tail(&op->pend_link, &object->pending_ops);
51708- fscache_stat(&fscache_n_op_pend);
51709+ fscache_stat_unchecked(&fscache_n_op_pend);
51710 } else if (!list_empty(&object->pending_ops)) {
51711 atomic_inc(&op->usage);
51712 list_add_tail(&op->pend_link, &object->pending_ops);
51713- fscache_stat(&fscache_n_op_pend);
51714+ fscache_stat_unchecked(&fscache_n_op_pend);
51715 fscache_start_operations(object);
51716 } else {
51717 ASSERTCMP(object->n_in_progress, ==, 0);
51718@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51719 object->n_exclusive++; /* reads and writes must wait */
51720 atomic_inc(&op->usage);
51721 list_add_tail(&op->pend_link, &object->pending_ops);
51722- fscache_stat(&fscache_n_op_pend);
51723+ fscache_stat_unchecked(&fscache_n_op_pend);
51724 ret = 0;
51725 } else {
51726 /* If we're in any other state, there must have been an I/O
51727@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51728 if (object->n_exclusive > 0) {
51729 atomic_inc(&op->usage);
51730 list_add_tail(&op->pend_link, &object->pending_ops);
51731- fscache_stat(&fscache_n_op_pend);
51732+ fscache_stat_unchecked(&fscache_n_op_pend);
51733 } else if (!list_empty(&object->pending_ops)) {
51734 atomic_inc(&op->usage);
51735 list_add_tail(&op->pend_link, &object->pending_ops);
51736- fscache_stat(&fscache_n_op_pend);
51737+ fscache_stat_unchecked(&fscache_n_op_pend);
51738 fscache_start_operations(object);
51739 } else {
51740 ASSERTCMP(object->n_exclusive, ==, 0);
51741@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51742 object->n_ops++;
51743 atomic_inc(&op->usage);
51744 list_add_tail(&op->pend_link, &object->pending_ops);
51745- fscache_stat(&fscache_n_op_pend);
51746+ fscache_stat_unchecked(&fscache_n_op_pend);
51747 ret = 0;
51748 } else if (object->state == FSCACHE_OBJECT_DYING ||
51749 object->state == FSCACHE_OBJECT_LC_DYING ||
51750 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51751- fscache_stat(&fscache_n_op_rejected);
51752+ fscache_stat_unchecked(&fscache_n_op_rejected);
51753 op->state = FSCACHE_OP_ST_CANCELLED;
51754 ret = -ENOBUFS;
51755 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51756@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51757 ret = -EBUSY;
51758 if (op->state == FSCACHE_OP_ST_PENDING) {
51759 ASSERT(!list_empty(&op->pend_link));
51760- fscache_stat(&fscache_n_op_cancelled);
51761+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51762 list_del_init(&op->pend_link);
51763 if (do_cancel)
51764 do_cancel(op);
51765@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51766 while (!list_empty(&object->pending_ops)) {
51767 op = list_entry(object->pending_ops.next,
51768 struct fscache_operation, pend_link);
51769- fscache_stat(&fscache_n_op_cancelled);
51770+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51771 list_del_init(&op->pend_link);
51772
51773 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51774@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51775 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51776 op->state = FSCACHE_OP_ST_DEAD;
51777
51778- fscache_stat(&fscache_n_op_release);
51779+ fscache_stat_unchecked(&fscache_n_op_release);
51780
51781 if (op->release) {
51782 op->release(op);
51783@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51784 * lock, and defer it otherwise */
51785 if (!spin_trylock(&object->lock)) {
51786 _debug("defer put");
51787- fscache_stat(&fscache_n_op_deferred_release);
51788+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
51789
51790 cache = object->cache;
51791 spin_lock(&cache->op_gc_list_lock);
51792@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51793
51794 _debug("GC DEFERRED REL OBJ%x OP%x",
51795 object->debug_id, op->debug_id);
51796- fscache_stat(&fscache_n_op_gc);
51797+ fscache_stat_unchecked(&fscache_n_op_gc);
51798
51799 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51800 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51801diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51802index ff000e5..c44ec6d 100644
51803--- a/fs/fscache/page.c
51804+++ b/fs/fscache/page.c
51805@@ -61,7 +61,7 @@ try_again:
51806 val = radix_tree_lookup(&cookie->stores, page->index);
51807 if (!val) {
51808 rcu_read_unlock();
51809- fscache_stat(&fscache_n_store_vmscan_not_storing);
51810+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51811 __fscache_uncache_page(cookie, page);
51812 return true;
51813 }
51814@@ -91,11 +91,11 @@ try_again:
51815 spin_unlock(&cookie->stores_lock);
51816
51817 if (xpage) {
51818- fscache_stat(&fscache_n_store_vmscan_cancelled);
51819- fscache_stat(&fscache_n_store_radix_deletes);
51820+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51821+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51822 ASSERTCMP(xpage, ==, page);
51823 } else {
51824- fscache_stat(&fscache_n_store_vmscan_gone);
51825+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51826 }
51827
51828 wake_up_bit(&cookie->flags, 0);
51829@@ -110,11 +110,11 @@ page_busy:
51830 * sleeping on memory allocation, so we may need to impose a timeout
51831 * too. */
51832 if (!(gfp & __GFP_WAIT)) {
51833- fscache_stat(&fscache_n_store_vmscan_busy);
51834+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51835 return false;
51836 }
51837
51838- fscache_stat(&fscache_n_store_vmscan_wait);
51839+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51840 __fscache_wait_on_page_write(cookie, page);
51841 gfp &= ~__GFP_WAIT;
51842 goto try_again;
51843@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51844 FSCACHE_COOKIE_STORING_TAG);
51845 if (!radix_tree_tag_get(&cookie->stores, page->index,
51846 FSCACHE_COOKIE_PENDING_TAG)) {
51847- fscache_stat(&fscache_n_store_radix_deletes);
51848+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51849 xpage = radix_tree_delete(&cookie->stores, page->index);
51850 }
51851 spin_unlock(&cookie->stores_lock);
51852@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51853
51854 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51855
51856- fscache_stat(&fscache_n_attr_changed_calls);
51857+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51858
51859 if (fscache_object_is_active(object)) {
51860 fscache_stat(&fscache_n_cop_attr_changed);
51861@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51862
51863 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51864
51865- fscache_stat(&fscache_n_attr_changed);
51866+ fscache_stat_unchecked(&fscache_n_attr_changed);
51867
51868 op = kzalloc(sizeof(*op), GFP_KERNEL);
51869 if (!op) {
51870- fscache_stat(&fscache_n_attr_changed_nomem);
51871+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51872 _leave(" = -ENOMEM");
51873 return -ENOMEM;
51874 }
51875@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51876 if (fscache_submit_exclusive_op(object, op) < 0)
51877 goto nobufs;
51878 spin_unlock(&cookie->lock);
51879- fscache_stat(&fscache_n_attr_changed_ok);
51880+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51881 fscache_put_operation(op);
51882 _leave(" = 0");
51883 return 0;
51884@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51885 nobufs:
51886 spin_unlock(&cookie->lock);
51887 kfree(op);
51888- fscache_stat(&fscache_n_attr_changed_nobufs);
51889+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51890 _leave(" = %d", -ENOBUFS);
51891 return -ENOBUFS;
51892 }
51893@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51894 /* allocate a retrieval operation and attempt to submit it */
51895 op = kzalloc(sizeof(*op), GFP_NOIO);
51896 if (!op) {
51897- fscache_stat(&fscache_n_retrievals_nomem);
51898+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51899 return NULL;
51900 }
51901
51902@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51903 return 0;
51904 }
51905
51906- fscache_stat(&fscache_n_retrievals_wait);
51907+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
51908
51909 jif = jiffies;
51910 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51911 fscache_wait_bit_interruptible,
51912 TASK_INTERRUPTIBLE) != 0) {
51913- fscache_stat(&fscache_n_retrievals_intr);
51914+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51915 _leave(" = -ERESTARTSYS");
51916 return -ERESTARTSYS;
51917 }
51918@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51919 */
51920 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51921 struct fscache_retrieval *op,
51922- atomic_t *stat_op_waits,
51923- atomic_t *stat_object_dead)
51924+ atomic_unchecked_t *stat_op_waits,
51925+ atomic_unchecked_t *stat_object_dead)
51926 {
51927 int ret;
51928
51929@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51930 goto check_if_dead;
51931
51932 _debug(">>> WT");
51933- fscache_stat(stat_op_waits);
51934+ fscache_stat_unchecked(stat_op_waits);
51935 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51936 fscache_wait_bit_interruptible,
51937 TASK_INTERRUPTIBLE) != 0) {
51938@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51939
51940 check_if_dead:
51941 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51942- fscache_stat(stat_object_dead);
51943+ fscache_stat_unchecked(stat_object_dead);
51944 _leave(" = -ENOBUFS [cancelled]");
51945 return -ENOBUFS;
51946 }
51947 if (unlikely(fscache_object_is_dead(object))) {
51948 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51949 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51950- fscache_stat(stat_object_dead);
51951+ fscache_stat_unchecked(stat_object_dead);
51952 return -ENOBUFS;
51953 }
51954 return 0;
51955@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51956
51957 _enter("%p,%p,,,", cookie, page);
51958
51959- fscache_stat(&fscache_n_retrievals);
51960+ fscache_stat_unchecked(&fscache_n_retrievals);
51961
51962 if (hlist_empty(&cookie->backing_objects))
51963 goto nobufs;
51964@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51965 goto nobufs_unlock_dec;
51966 spin_unlock(&cookie->lock);
51967
51968- fscache_stat(&fscache_n_retrieval_ops);
51969+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51970
51971 /* pin the netfs read context in case we need to do the actual netfs
51972 * read because we've encountered a cache read failure */
51973@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51974
51975 error:
51976 if (ret == -ENOMEM)
51977- fscache_stat(&fscache_n_retrievals_nomem);
51978+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51979 else if (ret == -ERESTARTSYS)
51980- fscache_stat(&fscache_n_retrievals_intr);
51981+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51982 else if (ret == -ENODATA)
51983- fscache_stat(&fscache_n_retrievals_nodata);
51984+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51985 else if (ret < 0)
51986- fscache_stat(&fscache_n_retrievals_nobufs);
51987+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51988 else
51989- fscache_stat(&fscache_n_retrievals_ok);
51990+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
51991
51992 fscache_put_retrieval(op);
51993 _leave(" = %d", ret);
51994@@ -467,7 +467,7 @@ nobufs_unlock:
51995 spin_unlock(&cookie->lock);
51996 kfree(op);
51997 nobufs:
51998- fscache_stat(&fscache_n_retrievals_nobufs);
51999+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52000 _leave(" = -ENOBUFS");
52001 return -ENOBUFS;
52002 }
52003@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52004
52005 _enter("%p,,%d,,,", cookie, *nr_pages);
52006
52007- fscache_stat(&fscache_n_retrievals);
52008+ fscache_stat_unchecked(&fscache_n_retrievals);
52009
52010 if (hlist_empty(&cookie->backing_objects))
52011 goto nobufs;
52012@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52013 goto nobufs_unlock_dec;
52014 spin_unlock(&cookie->lock);
52015
52016- fscache_stat(&fscache_n_retrieval_ops);
52017+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52018
52019 /* pin the netfs read context in case we need to do the actual netfs
52020 * read because we've encountered a cache read failure */
52021@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52022
52023 error:
52024 if (ret == -ENOMEM)
52025- fscache_stat(&fscache_n_retrievals_nomem);
52026+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52027 else if (ret == -ERESTARTSYS)
52028- fscache_stat(&fscache_n_retrievals_intr);
52029+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52030 else if (ret == -ENODATA)
52031- fscache_stat(&fscache_n_retrievals_nodata);
52032+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52033 else if (ret < 0)
52034- fscache_stat(&fscache_n_retrievals_nobufs);
52035+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52036 else
52037- fscache_stat(&fscache_n_retrievals_ok);
52038+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52039
52040 fscache_put_retrieval(op);
52041 _leave(" = %d", ret);
52042@@ -591,7 +591,7 @@ nobufs_unlock:
52043 spin_unlock(&cookie->lock);
52044 kfree(op);
52045 nobufs:
52046- fscache_stat(&fscache_n_retrievals_nobufs);
52047+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52048 _leave(" = -ENOBUFS");
52049 return -ENOBUFS;
52050 }
52051@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52052
52053 _enter("%p,%p,,,", cookie, page);
52054
52055- fscache_stat(&fscache_n_allocs);
52056+ fscache_stat_unchecked(&fscache_n_allocs);
52057
52058 if (hlist_empty(&cookie->backing_objects))
52059 goto nobufs;
52060@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52061 goto nobufs_unlock;
52062 spin_unlock(&cookie->lock);
52063
52064- fscache_stat(&fscache_n_alloc_ops);
52065+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52066
52067 ret = fscache_wait_for_retrieval_activation(
52068 object, op,
52069@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52070
52071 error:
52072 if (ret == -ERESTARTSYS)
52073- fscache_stat(&fscache_n_allocs_intr);
52074+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52075 else if (ret < 0)
52076- fscache_stat(&fscache_n_allocs_nobufs);
52077+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52078 else
52079- fscache_stat(&fscache_n_allocs_ok);
52080+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52081
52082 fscache_put_retrieval(op);
52083 _leave(" = %d", ret);
52084@@ -677,7 +677,7 @@ nobufs_unlock:
52085 spin_unlock(&cookie->lock);
52086 kfree(op);
52087 nobufs:
52088- fscache_stat(&fscache_n_allocs_nobufs);
52089+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52090 _leave(" = -ENOBUFS");
52091 return -ENOBUFS;
52092 }
52093@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52094
52095 spin_lock(&cookie->stores_lock);
52096
52097- fscache_stat(&fscache_n_store_calls);
52098+ fscache_stat_unchecked(&fscache_n_store_calls);
52099
52100 /* find a page to store */
52101 page = NULL;
52102@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52103 page = results[0];
52104 _debug("gang %d [%lx]", n, page->index);
52105 if (page->index > op->store_limit) {
52106- fscache_stat(&fscache_n_store_pages_over_limit);
52107+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52108 goto superseded;
52109 }
52110
52111@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52112 spin_unlock(&cookie->stores_lock);
52113 spin_unlock(&object->lock);
52114
52115- fscache_stat(&fscache_n_store_pages);
52116+ fscache_stat_unchecked(&fscache_n_store_pages);
52117 fscache_stat(&fscache_n_cop_write_page);
52118 ret = object->cache->ops->write_page(op, page);
52119 fscache_stat_d(&fscache_n_cop_write_page);
52120@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52121 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52122 ASSERT(PageFsCache(page));
52123
52124- fscache_stat(&fscache_n_stores);
52125+ fscache_stat_unchecked(&fscache_n_stores);
52126
52127 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52128 _leave(" = -ENOBUFS [invalidating]");
52129@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52130 spin_unlock(&cookie->stores_lock);
52131 spin_unlock(&object->lock);
52132
52133- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52134+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52135 op->store_limit = object->store_limit;
52136
52137 if (fscache_submit_op(object, &op->op) < 0)
52138@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52139
52140 spin_unlock(&cookie->lock);
52141 radix_tree_preload_end();
52142- fscache_stat(&fscache_n_store_ops);
52143- fscache_stat(&fscache_n_stores_ok);
52144+ fscache_stat_unchecked(&fscache_n_store_ops);
52145+ fscache_stat_unchecked(&fscache_n_stores_ok);
52146
52147 /* the work queue now carries its own ref on the object */
52148 fscache_put_operation(&op->op);
52149@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52150 return 0;
52151
52152 already_queued:
52153- fscache_stat(&fscache_n_stores_again);
52154+ fscache_stat_unchecked(&fscache_n_stores_again);
52155 already_pending:
52156 spin_unlock(&cookie->stores_lock);
52157 spin_unlock(&object->lock);
52158 spin_unlock(&cookie->lock);
52159 radix_tree_preload_end();
52160 kfree(op);
52161- fscache_stat(&fscache_n_stores_ok);
52162+ fscache_stat_unchecked(&fscache_n_stores_ok);
52163 _leave(" = 0");
52164 return 0;
52165
52166@@ -959,14 +959,14 @@ nobufs:
52167 spin_unlock(&cookie->lock);
52168 radix_tree_preload_end();
52169 kfree(op);
52170- fscache_stat(&fscache_n_stores_nobufs);
52171+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52172 _leave(" = -ENOBUFS");
52173 return -ENOBUFS;
52174
52175 nomem_free:
52176 kfree(op);
52177 nomem:
52178- fscache_stat(&fscache_n_stores_oom);
52179+ fscache_stat_unchecked(&fscache_n_stores_oom);
52180 _leave(" = -ENOMEM");
52181 return -ENOMEM;
52182 }
52183@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52184 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52185 ASSERTCMP(page, !=, NULL);
52186
52187- fscache_stat(&fscache_n_uncaches);
52188+ fscache_stat_unchecked(&fscache_n_uncaches);
52189
52190 /* cache withdrawal may beat us to it */
52191 if (!PageFsCache(page))
52192@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52193 struct fscache_cookie *cookie = op->op.object->cookie;
52194
52195 #ifdef CONFIG_FSCACHE_STATS
52196- atomic_inc(&fscache_n_marks);
52197+ atomic_inc_unchecked(&fscache_n_marks);
52198 #endif
52199
52200 _debug("- mark %p{%lx}", page, page->index);
52201diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52202index 8179e8b..5072cc7 100644
52203--- a/fs/fscache/stats.c
52204+++ b/fs/fscache/stats.c
52205@@ -18,99 +18,99 @@
52206 /*
52207 * operation counters
52208 */
52209-atomic_t fscache_n_op_pend;
52210-atomic_t fscache_n_op_run;
52211-atomic_t fscache_n_op_enqueue;
52212-atomic_t fscache_n_op_requeue;
52213-atomic_t fscache_n_op_deferred_release;
52214-atomic_t fscache_n_op_release;
52215-atomic_t fscache_n_op_gc;
52216-atomic_t fscache_n_op_cancelled;
52217-atomic_t fscache_n_op_rejected;
52218+atomic_unchecked_t fscache_n_op_pend;
52219+atomic_unchecked_t fscache_n_op_run;
52220+atomic_unchecked_t fscache_n_op_enqueue;
52221+atomic_unchecked_t fscache_n_op_requeue;
52222+atomic_unchecked_t fscache_n_op_deferred_release;
52223+atomic_unchecked_t fscache_n_op_release;
52224+atomic_unchecked_t fscache_n_op_gc;
52225+atomic_unchecked_t fscache_n_op_cancelled;
52226+atomic_unchecked_t fscache_n_op_rejected;
52227
52228-atomic_t fscache_n_attr_changed;
52229-atomic_t fscache_n_attr_changed_ok;
52230-atomic_t fscache_n_attr_changed_nobufs;
52231-atomic_t fscache_n_attr_changed_nomem;
52232-atomic_t fscache_n_attr_changed_calls;
52233+atomic_unchecked_t fscache_n_attr_changed;
52234+atomic_unchecked_t fscache_n_attr_changed_ok;
52235+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52236+atomic_unchecked_t fscache_n_attr_changed_nomem;
52237+atomic_unchecked_t fscache_n_attr_changed_calls;
52238
52239-atomic_t fscache_n_allocs;
52240-atomic_t fscache_n_allocs_ok;
52241-atomic_t fscache_n_allocs_wait;
52242-atomic_t fscache_n_allocs_nobufs;
52243-atomic_t fscache_n_allocs_intr;
52244-atomic_t fscache_n_allocs_object_dead;
52245-atomic_t fscache_n_alloc_ops;
52246-atomic_t fscache_n_alloc_op_waits;
52247+atomic_unchecked_t fscache_n_allocs;
52248+atomic_unchecked_t fscache_n_allocs_ok;
52249+atomic_unchecked_t fscache_n_allocs_wait;
52250+atomic_unchecked_t fscache_n_allocs_nobufs;
52251+atomic_unchecked_t fscache_n_allocs_intr;
52252+atomic_unchecked_t fscache_n_allocs_object_dead;
52253+atomic_unchecked_t fscache_n_alloc_ops;
52254+atomic_unchecked_t fscache_n_alloc_op_waits;
52255
52256-atomic_t fscache_n_retrievals;
52257-atomic_t fscache_n_retrievals_ok;
52258-atomic_t fscache_n_retrievals_wait;
52259-atomic_t fscache_n_retrievals_nodata;
52260-atomic_t fscache_n_retrievals_nobufs;
52261-atomic_t fscache_n_retrievals_intr;
52262-atomic_t fscache_n_retrievals_nomem;
52263-atomic_t fscache_n_retrievals_object_dead;
52264-atomic_t fscache_n_retrieval_ops;
52265-atomic_t fscache_n_retrieval_op_waits;
52266+atomic_unchecked_t fscache_n_retrievals;
52267+atomic_unchecked_t fscache_n_retrievals_ok;
52268+atomic_unchecked_t fscache_n_retrievals_wait;
52269+atomic_unchecked_t fscache_n_retrievals_nodata;
52270+atomic_unchecked_t fscache_n_retrievals_nobufs;
52271+atomic_unchecked_t fscache_n_retrievals_intr;
52272+atomic_unchecked_t fscache_n_retrievals_nomem;
52273+atomic_unchecked_t fscache_n_retrievals_object_dead;
52274+atomic_unchecked_t fscache_n_retrieval_ops;
52275+atomic_unchecked_t fscache_n_retrieval_op_waits;
52276
52277-atomic_t fscache_n_stores;
52278-atomic_t fscache_n_stores_ok;
52279-atomic_t fscache_n_stores_again;
52280-atomic_t fscache_n_stores_nobufs;
52281-atomic_t fscache_n_stores_oom;
52282-atomic_t fscache_n_store_ops;
52283-atomic_t fscache_n_store_calls;
52284-atomic_t fscache_n_store_pages;
52285-atomic_t fscache_n_store_radix_deletes;
52286-atomic_t fscache_n_store_pages_over_limit;
52287+atomic_unchecked_t fscache_n_stores;
52288+atomic_unchecked_t fscache_n_stores_ok;
52289+atomic_unchecked_t fscache_n_stores_again;
52290+atomic_unchecked_t fscache_n_stores_nobufs;
52291+atomic_unchecked_t fscache_n_stores_oom;
52292+atomic_unchecked_t fscache_n_store_ops;
52293+atomic_unchecked_t fscache_n_store_calls;
52294+atomic_unchecked_t fscache_n_store_pages;
52295+atomic_unchecked_t fscache_n_store_radix_deletes;
52296+atomic_unchecked_t fscache_n_store_pages_over_limit;
52297
52298-atomic_t fscache_n_store_vmscan_not_storing;
52299-atomic_t fscache_n_store_vmscan_gone;
52300-atomic_t fscache_n_store_vmscan_busy;
52301-atomic_t fscache_n_store_vmscan_cancelled;
52302-atomic_t fscache_n_store_vmscan_wait;
52303+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52304+atomic_unchecked_t fscache_n_store_vmscan_gone;
52305+atomic_unchecked_t fscache_n_store_vmscan_busy;
52306+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52307+atomic_unchecked_t fscache_n_store_vmscan_wait;
52308
52309-atomic_t fscache_n_marks;
52310-atomic_t fscache_n_uncaches;
52311+atomic_unchecked_t fscache_n_marks;
52312+atomic_unchecked_t fscache_n_uncaches;
52313
52314-atomic_t fscache_n_acquires;
52315-atomic_t fscache_n_acquires_null;
52316-atomic_t fscache_n_acquires_no_cache;
52317-atomic_t fscache_n_acquires_ok;
52318-atomic_t fscache_n_acquires_nobufs;
52319-atomic_t fscache_n_acquires_oom;
52320+atomic_unchecked_t fscache_n_acquires;
52321+atomic_unchecked_t fscache_n_acquires_null;
52322+atomic_unchecked_t fscache_n_acquires_no_cache;
52323+atomic_unchecked_t fscache_n_acquires_ok;
52324+atomic_unchecked_t fscache_n_acquires_nobufs;
52325+atomic_unchecked_t fscache_n_acquires_oom;
52326
52327-atomic_t fscache_n_invalidates;
52328-atomic_t fscache_n_invalidates_run;
52329+atomic_unchecked_t fscache_n_invalidates;
52330+atomic_unchecked_t fscache_n_invalidates_run;
52331
52332-atomic_t fscache_n_updates;
52333-atomic_t fscache_n_updates_null;
52334-atomic_t fscache_n_updates_run;
52335+atomic_unchecked_t fscache_n_updates;
52336+atomic_unchecked_t fscache_n_updates_null;
52337+atomic_unchecked_t fscache_n_updates_run;
52338
52339-atomic_t fscache_n_relinquishes;
52340-atomic_t fscache_n_relinquishes_null;
52341-atomic_t fscache_n_relinquishes_waitcrt;
52342-atomic_t fscache_n_relinquishes_retire;
52343+atomic_unchecked_t fscache_n_relinquishes;
52344+atomic_unchecked_t fscache_n_relinquishes_null;
52345+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52346+atomic_unchecked_t fscache_n_relinquishes_retire;
52347
52348-atomic_t fscache_n_cookie_index;
52349-atomic_t fscache_n_cookie_data;
52350-atomic_t fscache_n_cookie_special;
52351+atomic_unchecked_t fscache_n_cookie_index;
52352+atomic_unchecked_t fscache_n_cookie_data;
52353+atomic_unchecked_t fscache_n_cookie_special;
52354
52355-atomic_t fscache_n_object_alloc;
52356-atomic_t fscache_n_object_no_alloc;
52357-atomic_t fscache_n_object_lookups;
52358-atomic_t fscache_n_object_lookups_negative;
52359-atomic_t fscache_n_object_lookups_positive;
52360-atomic_t fscache_n_object_lookups_timed_out;
52361-atomic_t fscache_n_object_created;
52362-atomic_t fscache_n_object_avail;
52363-atomic_t fscache_n_object_dead;
52364+atomic_unchecked_t fscache_n_object_alloc;
52365+atomic_unchecked_t fscache_n_object_no_alloc;
52366+atomic_unchecked_t fscache_n_object_lookups;
52367+atomic_unchecked_t fscache_n_object_lookups_negative;
52368+atomic_unchecked_t fscache_n_object_lookups_positive;
52369+atomic_unchecked_t fscache_n_object_lookups_timed_out;
52370+atomic_unchecked_t fscache_n_object_created;
52371+atomic_unchecked_t fscache_n_object_avail;
52372+atomic_unchecked_t fscache_n_object_dead;
52373
52374-atomic_t fscache_n_checkaux_none;
52375-atomic_t fscache_n_checkaux_okay;
52376-atomic_t fscache_n_checkaux_update;
52377-atomic_t fscache_n_checkaux_obsolete;
52378+atomic_unchecked_t fscache_n_checkaux_none;
52379+atomic_unchecked_t fscache_n_checkaux_okay;
52380+atomic_unchecked_t fscache_n_checkaux_update;
52381+atomic_unchecked_t fscache_n_checkaux_obsolete;
52382
52383 atomic_t fscache_n_cop_alloc_object;
52384 atomic_t fscache_n_cop_lookup_object;
52385@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
52386 seq_puts(m, "FS-Cache statistics\n");
52387
52388 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
52389- atomic_read(&fscache_n_cookie_index),
52390- atomic_read(&fscache_n_cookie_data),
52391- atomic_read(&fscache_n_cookie_special));
52392+ atomic_read_unchecked(&fscache_n_cookie_index),
52393+ atomic_read_unchecked(&fscache_n_cookie_data),
52394+ atomic_read_unchecked(&fscache_n_cookie_special));
52395
52396 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
52397- atomic_read(&fscache_n_object_alloc),
52398- atomic_read(&fscache_n_object_no_alloc),
52399- atomic_read(&fscache_n_object_avail),
52400- atomic_read(&fscache_n_object_dead));
52401+ atomic_read_unchecked(&fscache_n_object_alloc),
52402+ atomic_read_unchecked(&fscache_n_object_no_alloc),
52403+ atomic_read_unchecked(&fscache_n_object_avail),
52404+ atomic_read_unchecked(&fscache_n_object_dead));
52405 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
52406- atomic_read(&fscache_n_checkaux_none),
52407- atomic_read(&fscache_n_checkaux_okay),
52408- atomic_read(&fscache_n_checkaux_update),
52409- atomic_read(&fscache_n_checkaux_obsolete));
52410+ atomic_read_unchecked(&fscache_n_checkaux_none),
52411+ atomic_read_unchecked(&fscache_n_checkaux_okay),
52412+ atomic_read_unchecked(&fscache_n_checkaux_update),
52413+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
52414
52415 seq_printf(m, "Pages : mrk=%u unc=%u\n",
52416- atomic_read(&fscache_n_marks),
52417- atomic_read(&fscache_n_uncaches));
52418+ atomic_read_unchecked(&fscache_n_marks),
52419+ atomic_read_unchecked(&fscache_n_uncaches));
52420
52421 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
52422 " oom=%u\n",
52423- atomic_read(&fscache_n_acquires),
52424- atomic_read(&fscache_n_acquires_null),
52425- atomic_read(&fscache_n_acquires_no_cache),
52426- atomic_read(&fscache_n_acquires_ok),
52427- atomic_read(&fscache_n_acquires_nobufs),
52428- atomic_read(&fscache_n_acquires_oom));
52429+ atomic_read_unchecked(&fscache_n_acquires),
52430+ atomic_read_unchecked(&fscache_n_acquires_null),
52431+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
52432+ atomic_read_unchecked(&fscache_n_acquires_ok),
52433+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
52434+ atomic_read_unchecked(&fscache_n_acquires_oom));
52435
52436 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
52437- atomic_read(&fscache_n_object_lookups),
52438- atomic_read(&fscache_n_object_lookups_negative),
52439- atomic_read(&fscache_n_object_lookups_positive),
52440- atomic_read(&fscache_n_object_created),
52441- atomic_read(&fscache_n_object_lookups_timed_out));
52442+ atomic_read_unchecked(&fscache_n_object_lookups),
52443+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
52444+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
52445+ atomic_read_unchecked(&fscache_n_object_created),
52446+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52447
52448 seq_printf(m, "Invals : n=%u run=%u\n",
52449- atomic_read(&fscache_n_invalidates),
52450- atomic_read(&fscache_n_invalidates_run));
52451+ atomic_read_unchecked(&fscache_n_invalidates),
52452+ atomic_read_unchecked(&fscache_n_invalidates_run));
52453
52454 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52455- atomic_read(&fscache_n_updates),
52456- atomic_read(&fscache_n_updates_null),
52457- atomic_read(&fscache_n_updates_run));
52458+ atomic_read_unchecked(&fscache_n_updates),
52459+ atomic_read_unchecked(&fscache_n_updates_null),
52460+ atomic_read_unchecked(&fscache_n_updates_run));
52461
52462 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52463- atomic_read(&fscache_n_relinquishes),
52464- atomic_read(&fscache_n_relinquishes_null),
52465- atomic_read(&fscache_n_relinquishes_waitcrt),
52466- atomic_read(&fscache_n_relinquishes_retire));
52467+ atomic_read_unchecked(&fscache_n_relinquishes),
52468+ atomic_read_unchecked(&fscache_n_relinquishes_null),
52469+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52470+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
52471
52472 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52473- atomic_read(&fscache_n_attr_changed),
52474- atomic_read(&fscache_n_attr_changed_ok),
52475- atomic_read(&fscache_n_attr_changed_nobufs),
52476- atomic_read(&fscache_n_attr_changed_nomem),
52477- atomic_read(&fscache_n_attr_changed_calls));
52478+ atomic_read_unchecked(&fscache_n_attr_changed),
52479+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
52480+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52481+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52482+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
52483
52484 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52485- atomic_read(&fscache_n_allocs),
52486- atomic_read(&fscache_n_allocs_ok),
52487- atomic_read(&fscache_n_allocs_wait),
52488- atomic_read(&fscache_n_allocs_nobufs),
52489- atomic_read(&fscache_n_allocs_intr));
52490+ atomic_read_unchecked(&fscache_n_allocs),
52491+ atomic_read_unchecked(&fscache_n_allocs_ok),
52492+ atomic_read_unchecked(&fscache_n_allocs_wait),
52493+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
52494+ atomic_read_unchecked(&fscache_n_allocs_intr));
52495 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52496- atomic_read(&fscache_n_alloc_ops),
52497- atomic_read(&fscache_n_alloc_op_waits),
52498- atomic_read(&fscache_n_allocs_object_dead));
52499+ atomic_read_unchecked(&fscache_n_alloc_ops),
52500+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
52501+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
52502
52503 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52504 " int=%u oom=%u\n",
52505- atomic_read(&fscache_n_retrievals),
52506- atomic_read(&fscache_n_retrievals_ok),
52507- atomic_read(&fscache_n_retrievals_wait),
52508- atomic_read(&fscache_n_retrievals_nodata),
52509- atomic_read(&fscache_n_retrievals_nobufs),
52510- atomic_read(&fscache_n_retrievals_intr),
52511- atomic_read(&fscache_n_retrievals_nomem));
52512+ atomic_read_unchecked(&fscache_n_retrievals),
52513+ atomic_read_unchecked(&fscache_n_retrievals_ok),
52514+ atomic_read_unchecked(&fscache_n_retrievals_wait),
52515+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
52516+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52517+ atomic_read_unchecked(&fscache_n_retrievals_intr),
52518+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
52519 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52520- atomic_read(&fscache_n_retrieval_ops),
52521- atomic_read(&fscache_n_retrieval_op_waits),
52522- atomic_read(&fscache_n_retrievals_object_dead));
52523+ atomic_read_unchecked(&fscache_n_retrieval_ops),
52524+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52525+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52526
52527 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52528- atomic_read(&fscache_n_stores),
52529- atomic_read(&fscache_n_stores_ok),
52530- atomic_read(&fscache_n_stores_again),
52531- atomic_read(&fscache_n_stores_nobufs),
52532- atomic_read(&fscache_n_stores_oom));
52533+ atomic_read_unchecked(&fscache_n_stores),
52534+ atomic_read_unchecked(&fscache_n_stores_ok),
52535+ atomic_read_unchecked(&fscache_n_stores_again),
52536+ atomic_read_unchecked(&fscache_n_stores_nobufs),
52537+ atomic_read_unchecked(&fscache_n_stores_oom));
52538 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52539- atomic_read(&fscache_n_store_ops),
52540- atomic_read(&fscache_n_store_calls),
52541- atomic_read(&fscache_n_store_pages),
52542- atomic_read(&fscache_n_store_radix_deletes),
52543- atomic_read(&fscache_n_store_pages_over_limit));
52544+ atomic_read_unchecked(&fscache_n_store_ops),
52545+ atomic_read_unchecked(&fscache_n_store_calls),
52546+ atomic_read_unchecked(&fscache_n_store_pages),
52547+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
52548+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52549
52550 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52551- atomic_read(&fscache_n_store_vmscan_not_storing),
52552- atomic_read(&fscache_n_store_vmscan_gone),
52553- atomic_read(&fscache_n_store_vmscan_busy),
52554- atomic_read(&fscache_n_store_vmscan_cancelled),
52555- atomic_read(&fscache_n_store_vmscan_wait));
52556+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52557+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52558+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52559+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52560+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52561
52562 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52563- atomic_read(&fscache_n_op_pend),
52564- atomic_read(&fscache_n_op_run),
52565- atomic_read(&fscache_n_op_enqueue),
52566- atomic_read(&fscache_n_op_cancelled),
52567- atomic_read(&fscache_n_op_rejected));
52568+ atomic_read_unchecked(&fscache_n_op_pend),
52569+ atomic_read_unchecked(&fscache_n_op_run),
52570+ atomic_read_unchecked(&fscache_n_op_enqueue),
52571+ atomic_read_unchecked(&fscache_n_op_cancelled),
52572+ atomic_read_unchecked(&fscache_n_op_rejected));
52573 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52574- atomic_read(&fscache_n_op_deferred_release),
52575- atomic_read(&fscache_n_op_release),
52576- atomic_read(&fscache_n_op_gc));
52577+ atomic_read_unchecked(&fscache_n_op_deferred_release),
52578+ atomic_read_unchecked(&fscache_n_op_release),
52579+ atomic_read_unchecked(&fscache_n_op_gc));
52580
52581 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52582 atomic_read(&fscache_n_cop_alloc_object),
52583diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52584index e397b67..b0d8709 100644
52585--- a/fs/fuse/cuse.c
52586+++ b/fs/fuse/cuse.c
52587@@ -593,10 +593,12 @@ static int __init cuse_init(void)
52588 INIT_LIST_HEAD(&cuse_conntbl[i]);
52589
52590 /* inherit and extend fuse_dev_operations */
52591- cuse_channel_fops = fuse_dev_operations;
52592- cuse_channel_fops.owner = THIS_MODULE;
52593- cuse_channel_fops.open = cuse_channel_open;
52594- cuse_channel_fops.release = cuse_channel_release;
52595+ pax_open_kernel();
52596+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52597+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52598+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
52599+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
52600+ pax_close_kernel();
52601
52602 cuse_class = class_create(THIS_MODULE, "cuse");
52603 if (IS_ERR(cuse_class))
52604diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52605index e83351a..41e3c9c 100644
52606--- a/fs/fuse/dev.c
52607+++ b/fs/fuse/dev.c
52608@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52609 ret = 0;
52610 pipe_lock(pipe);
52611
52612- if (!pipe->readers) {
52613+ if (!atomic_read(&pipe->readers)) {
52614 send_sig(SIGPIPE, current, 0);
52615 if (!ret)
52616 ret = -EPIPE;
52617diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52618index 315e1f8..91f890c 100644
52619--- a/fs/fuse/dir.c
52620+++ b/fs/fuse/dir.c
52621@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52622 return link;
52623 }
52624
52625-static void free_link(char *link)
52626+static void free_link(const char *link)
52627 {
52628 if (!IS_ERR(link))
52629 free_page((unsigned long) link);
52630diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52631index 2b6f569..fcb4d1f 100644
52632--- a/fs/gfs2/inode.c
52633+++ b/fs/gfs2/inode.c
52634@@ -1499,7 +1499,7 @@ out:
52635
52636 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52637 {
52638- char *s = nd_get_link(nd);
52639+ const char *s = nd_get_link(nd);
52640 if (!IS_ERR(s))
52641 kfree(s);
52642 }
52643diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52644index 78bde32..767e906 100644
52645--- a/fs/hugetlbfs/inode.c
52646+++ b/fs/hugetlbfs/inode.c
52647@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52648 struct mm_struct *mm = current->mm;
52649 struct vm_area_struct *vma;
52650 struct hstate *h = hstate_file(file);
52651+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52652 struct vm_unmapped_area_info info;
52653
52654 if (len & ~huge_page_mask(h))
52655@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52656 return addr;
52657 }
52658
52659+#ifdef CONFIG_PAX_RANDMMAP
52660+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52661+#endif
52662+
52663 if (addr) {
52664 addr = ALIGN(addr, huge_page_size(h));
52665 vma = find_vma(mm, addr);
52666- if (TASK_SIZE - len >= addr &&
52667- (!vma || addr + len <= vma->vm_start))
52668+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52669 return addr;
52670 }
52671
52672 info.flags = 0;
52673 info.length = len;
52674 info.low_limit = TASK_UNMAPPED_BASE;
52675+
52676+#ifdef CONFIG_PAX_RANDMMAP
52677+ if (mm->pax_flags & MF_PAX_RANDMMAP)
52678+ info.low_limit += mm->delta_mmap;
52679+#endif
52680+
52681 info.high_limit = TASK_SIZE;
52682 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52683 info.align_offset = 0;
52684@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52685 .kill_sb = kill_litter_super,
52686 };
52687
52688-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52689+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52690
52691 static int can_do_hugetlb_shm(void)
52692 {
52693diff --git a/fs/inode.c b/fs/inode.c
52694index 14084b7..29af1d9 100644
52695--- a/fs/inode.c
52696+++ b/fs/inode.c
52697@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52698
52699 #ifdef CONFIG_SMP
52700 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52701- static atomic_t shared_last_ino;
52702- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52703+ static atomic_unchecked_t shared_last_ino;
52704+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52705
52706 res = next - LAST_INO_BATCH;
52707 }
52708diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52709index 4a6cf28..d3a29d3 100644
52710--- a/fs/jffs2/erase.c
52711+++ b/fs/jffs2/erase.c
52712@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52713 struct jffs2_unknown_node marker = {
52714 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52715 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52716- .totlen = cpu_to_je32(c->cleanmarker_size)
52717+ .totlen = cpu_to_je32(c->cleanmarker_size),
52718+ .hdr_crc = cpu_to_je32(0)
52719 };
52720
52721 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52722diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52723index a6597d6..41b30ec 100644
52724--- a/fs/jffs2/wbuf.c
52725+++ b/fs/jffs2/wbuf.c
52726@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52727 {
52728 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52729 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52730- .totlen = constant_cpu_to_je32(8)
52731+ .totlen = constant_cpu_to_je32(8),
52732+ .hdr_crc = constant_cpu_to_je32(0)
52733 };
52734
52735 /*
52736diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52737index 1a543be..a4e1363 100644
52738--- a/fs/jfs/super.c
52739+++ b/fs/jfs/super.c
52740@@ -225,7 +225,7 @@ static const match_table_t tokens = {
52741 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52742 int *flag)
52743 {
52744- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52745+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52746 char *p;
52747 struct jfs_sb_info *sbi = JFS_SBI(sb);
52748
52749@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52750 /* Don't do anything ;-) */
52751 break;
52752 case Opt_iocharset:
52753- if (nls_map && nls_map != (void *) -1)
52754+ if (nls_map && nls_map != (const void *) -1)
52755 unload_nls(nls_map);
52756 if (!strcmp(args[0].from, "none"))
52757 nls_map = NULL;
52758@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52759
52760 jfs_inode_cachep =
52761 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52762- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52763+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52764 init_once);
52765 if (jfs_inode_cachep == NULL)
52766 return -ENOMEM;
52767diff --git a/fs/libfs.c b/fs/libfs.c
52768index 916da8c..1588998 100644
52769--- a/fs/libfs.c
52770+++ b/fs/libfs.c
52771@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52772
52773 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52774 struct dentry *next;
52775+ char d_name[sizeof(next->d_iname)];
52776+ const unsigned char *name;
52777+
52778 next = list_entry(p, struct dentry, d_u.d_child);
52779 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52780 if (!simple_positive(next)) {
52781@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52782
52783 spin_unlock(&next->d_lock);
52784 spin_unlock(&dentry->d_lock);
52785- if (filldir(dirent, next->d_name.name,
52786+ name = next->d_name.name;
52787+ if (name == next->d_iname) {
52788+ memcpy(d_name, name, next->d_name.len);
52789+ name = d_name;
52790+ }
52791+ if (filldir(dirent, name,
52792 next->d_name.len, filp->f_pos,
52793 next->d_inode->i_ino,
52794 dt_type(next->d_inode)) < 0)
52795diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52796index 52e5120..808936e 100644
52797--- a/fs/lockd/clntproc.c
52798+++ b/fs/lockd/clntproc.c
52799@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52800 /*
52801 * Cookie counter for NLM requests
52802 */
52803-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52804+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52805
52806 void nlmclnt_next_cookie(struct nlm_cookie *c)
52807 {
52808- u32 cookie = atomic_inc_return(&nlm_cookie);
52809+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52810
52811 memcpy(c->data, &cookie, 4);
52812 c->len=4;
52813diff --git a/fs/locks.c b/fs/locks.c
52814index a94e331..060bce3 100644
52815--- a/fs/locks.c
52816+++ b/fs/locks.c
52817@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52818 return;
52819
52820 if (filp->f_op && filp->f_op->flock) {
52821- struct file_lock fl = {
52822+ struct file_lock flock = {
52823 .fl_pid = current->tgid,
52824 .fl_file = filp,
52825 .fl_flags = FL_FLOCK,
52826 .fl_type = F_UNLCK,
52827 .fl_end = OFFSET_MAX,
52828 };
52829- filp->f_op->flock(filp, F_SETLKW, &fl);
52830- if (fl.fl_ops && fl.fl_ops->fl_release_private)
52831- fl.fl_ops->fl_release_private(&fl);
52832+ filp->f_op->flock(filp, F_SETLKW, &flock);
52833+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
52834+ flock.fl_ops->fl_release_private(&flock);
52835 }
52836
52837 lock_flocks();
52838diff --git a/fs/namei.c b/fs/namei.c
52839index ec97aef..e67718d 100644
52840--- a/fs/namei.c
52841+++ b/fs/namei.c
52842@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52843 if (ret != -EACCES)
52844 return ret;
52845
52846+#ifdef CONFIG_GRKERNSEC
52847+ /* we'll block if we have to log due to a denied capability use */
52848+ if (mask & MAY_NOT_BLOCK)
52849+ return -ECHILD;
52850+#endif
52851+
52852 if (S_ISDIR(inode->i_mode)) {
52853 /* DACs are overridable for directories */
52854- if (inode_capable(inode, CAP_DAC_OVERRIDE))
52855- return 0;
52856 if (!(mask & MAY_WRITE))
52857- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52858+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52859+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52860 return 0;
52861+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
52862+ return 0;
52863 return -EACCES;
52864 }
52865 /*
52866+ * Searching includes executable on directories, else just read.
52867+ */
52868+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52869+ if (mask == MAY_READ)
52870+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52871+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52872+ return 0;
52873+
52874+ /*
52875 * Read/write DACs are always overridable.
52876 * Executable DACs are overridable when there is
52877 * at least one exec bit set.
52878@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52879 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52880 return 0;
52881
52882- /*
52883- * Searching includes executable on directories, else just read.
52884- */
52885- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52886- if (mask == MAY_READ)
52887- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52888- return 0;
52889-
52890 return -EACCES;
52891 }
52892
52893@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52894 {
52895 struct dentry *dentry = link->dentry;
52896 int error;
52897- char *s;
52898+ const char *s;
52899
52900 BUG_ON(nd->flags & LOOKUP_RCU);
52901
52902@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52903 if (error)
52904 goto out_put_nd_path;
52905
52906+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
52907+ dentry->d_inode, dentry, nd->path.mnt)) {
52908+ error = -EACCES;
52909+ goto out_put_nd_path;
52910+ }
52911+
52912 nd->last_type = LAST_BIND;
52913 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52914 error = PTR_ERR(*p);
52915@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52916 break;
52917 res = walk_component(nd, path, &nd->last,
52918 nd->last_type, LOOKUP_FOLLOW);
52919+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52920+ res = -EACCES;
52921 put_link(nd, &link, cookie);
52922 } while (res > 0);
52923
52924@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
52925 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52926 {
52927 unsigned long a, b, adata, bdata, mask, hash, len;
52928- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52929+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52930
52931 hash = a = 0;
52932 len = -sizeof(unsigned long);
52933@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
52934 if (err)
52935 break;
52936 err = lookup_last(nd, &path);
52937+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
52938+ err = -EACCES;
52939 put_link(nd, &link, cookie);
52940 }
52941 }
52942@@ -1984,6 +2002,13 @@ static int path_lookupat(int dfd, const char *name,
52943 if (!err)
52944 err = complete_walk(nd);
52945
52946+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
52947+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52948+ path_put(&nd->path);
52949+ err = -ENOENT;
52950+ }
52951+ }
52952+
52953 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52954 if (!nd->inode->i_op->lookup) {
52955 path_put(&nd->path);
52956@@ -2011,8 +2036,15 @@ static int filename_lookup(int dfd, struct filename *name,
52957 retval = path_lookupat(dfd, name->name,
52958 flags | LOOKUP_REVAL, nd);
52959
52960- if (likely(!retval))
52961+ if (likely(!retval)) {
52962 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52963+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52964+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
52965+ path_put(&nd->path);
52966+ return -ENOENT;
52967+ }
52968+ }
52969+ }
52970 return retval;
52971 }
52972
52973@@ -2390,6 +2422,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52974 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52975 return -EPERM;
52976
52977+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52978+ return -EPERM;
52979+ if (gr_handle_rawio(inode))
52980+ return -EPERM;
52981+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52982+ return -EACCES;
52983+
52984 return 0;
52985 }
52986
52987@@ -2611,7 +2650,7 @@ looked_up:
52988 * cleared otherwise prior to returning.
52989 */
52990 static int lookup_open(struct nameidata *nd, struct path *path,
52991- struct file *file,
52992+ struct path *link, struct file *file,
52993 const struct open_flags *op,
52994 bool got_write, int *opened)
52995 {
52996@@ -2646,6 +2685,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52997 /* Negative dentry, just create the file */
52998 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52999 umode_t mode = op->mode;
53000+
53001+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53002+ error = -EACCES;
53003+ goto out_dput;
53004+ }
53005+
53006+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53007+ error = -EACCES;
53008+ goto out_dput;
53009+ }
53010+
53011 if (!IS_POSIXACL(dir->d_inode))
53012 mode &= ~current_umask();
53013 /*
53014@@ -2667,6 +2717,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53015 nd->flags & LOOKUP_EXCL);
53016 if (error)
53017 goto out_dput;
53018+ else
53019+ gr_handle_create(dentry, nd->path.mnt);
53020 }
53021 out_no_open:
53022 path->dentry = dentry;
53023@@ -2681,7 +2733,7 @@ out_dput:
53024 /*
53025 * Handle the last step of open()
53026 */
53027-static int do_last(struct nameidata *nd, struct path *path,
53028+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53029 struct file *file, const struct open_flags *op,
53030 int *opened, struct filename *name)
53031 {
53032@@ -2710,16 +2762,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53033 error = complete_walk(nd);
53034 if (error)
53035 return error;
53036+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53037+ error = -ENOENT;
53038+ goto out;
53039+ }
53040 audit_inode(name, nd->path.dentry, 0);
53041 if (open_flag & O_CREAT) {
53042 error = -EISDIR;
53043 goto out;
53044 }
53045+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53046+ error = -EACCES;
53047+ goto out;
53048+ }
53049 goto finish_open;
53050 case LAST_BIND:
53051 error = complete_walk(nd);
53052 if (error)
53053 return error;
53054+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53055+ error = -ENOENT;
53056+ goto out;
53057+ }
53058+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53059+ error = -EACCES;
53060+ goto out;
53061+ }
53062 audit_inode(name, dir, 0);
53063 goto finish_open;
53064 }
53065@@ -2768,7 +2836,7 @@ retry_lookup:
53066 */
53067 }
53068 mutex_lock(&dir->d_inode->i_mutex);
53069- error = lookup_open(nd, path, file, op, got_write, opened);
53070+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53071 mutex_unlock(&dir->d_inode->i_mutex);
53072
53073 if (error <= 0) {
53074@@ -2792,11 +2860,28 @@ retry_lookup:
53075 goto finish_open_created;
53076 }
53077
53078+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53079+ error = -ENOENT;
53080+ goto exit_dput;
53081+ }
53082+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53083+ error = -EACCES;
53084+ goto exit_dput;
53085+ }
53086+
53087 /*
53088 * create/update audit record if it already exists.
53089 */
53090- if (path->dentry->d_inode)
53091+ if (path->dentry->d_inode) {
53092+ /* only check if O_CREAT is specified, all other checks need to go
53093+ into may_open */
53094+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53095+ error = -EACCES;
53096+ goto exit_dput;
53097+ }
53098+
53099 audit_inode(name, path->dentry, 0);
53100+ }
53101
53102 /*
53103 * If atomic_open() acquired write access it is dropped now due to
53104@@ -2837,6 +2922,11 @@ finish_lookup:
53105 }
53106 }
53107 BUG_ON(inode != path->dentry->d_inode);
53108+ /* if we're resolving a symlink to another symlink */
53109+ if (link && gr_handle_symlink_owner(link, inode)) {
53110+ error = -EACCES;
53111+ goto out;
53112+ }
53113 return 1;
53114 }
53115
53116@@ -2846,7 +2936,6 @@ finish_lookup:
53117 save_parent.dentry = nd->path.dentry;
53118 save_parent.mnt = mntget(path->mnt);
53119 nd->path.dentry = path->dentry;
53120-
53121 }
53122 nd->inode = inode;
53123 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53124@@ -2855,6 +2944,16 @@ finish_lookup:
53125 path_put(&save_parent);
53126 return error;
53127 }
53128+
53129+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53130+ error = -ENOENT;
53131+ goto out;
53132+ }
53133+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53134+ error = -EACCES;
53135+ goto out;
53136+ }
53137+
53138 error = -EISDIR;
53139 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53140 goto out;
53141@@ -2953,7 +3052,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53142 if (unlikely(error))
53143 goto out;
53144
53145- error = do_last(nd, &path, file, op, &opened, pathname);
53146+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53147 while (unlikely(error > 0)) { /* trailing symlink */
53148 struct path link = path;
53149 void *cookie;
53150@@ -2971,7 +3070,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53151 error = follow_link(&link, nd, &cookie);
53152 if (unlikely(error))
53153 break;
53154- error = do_last(nd, &path, file, op, &opened, pathname);
53155+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53156 put_link(nd, &link, cookie);
53157 }
53158 out:
53159@@ -3071,8 +3170,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53160 goto unlock;
53161
53162 error = -EEXIST;
53163- if (dentry->d_inode)
53164+ if (dentry->d_inode) {
53165+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53166+ error = -ENOENT;
53167+ }
53168 goto fail;
53169+ }
53170 /*
53171 * Special case - lookup gave negative, but... we had foo/bar/
53172 * From the vfs_mknod() POV we just have a negative dentry -
53173@@ -3124,6 +3227,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53174 }
53175 EXPORT_SYMBOL(user_path_create);
53176
53177+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53178+{
53179+ struct filename *tmp = getname(pathname);
53180+ struct dentry *res;
53181+ if (IS_ERR(tmp))
53182+ return ERR_CAST(tmp);
53183+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53184+ if (IS_ERR(res))
53185+ putname(tmp);
53186+ else
53187+ *to = tmp;
53188+ return res;
53189+}
53190+
53191 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53192 {
53193 int error = may_create(dir, dentry);
53194@@ -3186,6 +3303,17 @@ retry:
53195
53196 if (!IS_POSIXACL(path.dentry->d_inode))
53197 mode &= ~current_umask();
53198+
53199+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53200+ error = -EPERM;
53201+ goto out;
53202+ }
53203+
53204+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53205+ error = -EACCES;
53206+ goto out;
53207+ }
53208+
53209 error = security_path_mknod(&path, dentry, mode, dev);
53210 if (error)
53211 goto out;
53212@@ -3202,6 +3330,8 @@ retry:
53213 break;
53214 }
53215 out:
53216+ if (!error)
53217+ gr_handle_create(dentry, path.mnt);
53218 done_path_create(&path, dentry);
53219 if (retry_estale(error, lookup_flags)) {
53220 lookup_flags |= LOOKUP_REVAL;
53221@@ -3254,9 +3384,16 @@ retry:
53222
53223 if (!IS_POSIXACL(path.dentry->d_inode))
53224 mode &= ~current_umask();
53225+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53226+ error = -EACCES;
53227+ goto out;
53228+ }
53229 error = security_path_mkdir(&path, dentry, mode);
53230 if (!error)
53231 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53232+ if (!error)
53233+ gr_handle_create(dentry, path.mnt);
53234+out:
53235 done_path_create(&path, dentry);
53236 if (retry_estale(error, lookup_flags)) {
53237 lookup_flags |= LOOKUP_REVAL;
53238@@ -3337,6 +3474,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53239 struct filename *name;
53240 struct dentry *dentry;
53241 struct nameidata nd;
53242+ ino_t saved_ino = 0;
53243+ dev_t saved_dev = 0;
53244 unsigned int lookup_flags = 0;
53245 retry:
53246 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53247@@ -3369,10 +3508,21 @@ retry:
53248 error = -ENOENT;
53249 goto exit3;
53250 }
53251+
53252+ saved_ino = dentry->d_inode->i_ino;
53253+ saved_dev = gr_get_dev_from_dentry(dentry);
53254+
53255+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53256+ error = -EACCES;
53257+ goto exit3;
53258+ }
53259+
53260 error = security_path_rmdir(&nd.path, dentry);
53261 if (error)
53262 goto exit3;
53263 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53264+ if (!error && (saved_dev || saved_ino))
53265+ gr_handle_delete(saved_ino, saved_dev);
53266 exit3:
53267 dput(dentry);
53268 exit2:
53269@@ -3438,6 +3588,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53270 struct dentry *dentry;
53271 struct nameidata nd;
53272 struct inode *inode = NULL;
53273+ ino_t saved_ino = 0;
53274+ dev_t saved_dev = 0;
53275 unsigned int lookup_flags = 0;
53276 retry:
53277 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53278@@ -3464,10 +3616,22 @@ retry:
53279 if (!inode)
53280 goto slashes;
53281 ihold(inode);
53282+
53283+ if (inode->i_nlink <= 1) {
53284+ saved_ino = inode->i_ino;
53285+ saved_dev = gr_get_dev_from_dentry(dentry);
53286+ }
53287+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53288+ error = -EACCES;
53289+ goto exit2;
53290+ }
53291+
53292 error = security_path_unlink(&nd.path, dentry);
53293 if (error)
53294 goto exit2;
53295 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53296+ if (!error && (saved_ino || saved_dev))
53297+ gr_handle_delete(saved_ino, saved_dev);
53298 exit2:
53299 dput(dentry);
53300 }
53301@@ -3545,9 +3709,17 @@ retry:
53302 if (IS_ERR(dentry))
53303 goto out_putname;
53304
53305+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53306+ error = -EACCES;
53307+ goto out;
53308+ }
53309+
53310 error = security_path_symlink(&path, dentry, from->name);
53311 if (!error)
53312 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
53313+ if (!error)
53314+ gr_handle_create(dentry, path.mnt);
53315+out:
53316 done_path_create(&path, dentry);
53317 if (retry_estale(error, lookup_flags)) {
53318 lookup_flags |= LOOKUP_REVAL;
53319@@ -3621,6 +3793,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53320 {
53321 struct dentry *new_dentry;
53322 struct path old_path, new_path;
53323+ struct filename *to = NULL;
53324 int how = 0;
53325 int error;
53326
53327@@ -3644,7 +3817,7 @@ retry:
53328 if (error)
53329 return error;
53330
53331- new_dentry = user_path_create(newdfd, newname, &new_path,
53332+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53333 (how & LOOKUP_REVAL));
53334 error = PTR_ERR(new_dentry);
53335 if (IS_ERR(new_dentry))
53336@@ -3656,11 +3829,28 @@ retry:
53337 error = may_linkat(&old_path);
53338 if (unlikely(error))
53339 goto out_dput;
53340+
53341+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
53342+ old_path.dentry->d_inode,
53343+ old_path.dentry->d_inode->i_mode, to)) {
53344+ error = -EACCES;
53345+ goto out_dput;
53346+ }
53347+
53348+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
53349+ old_path.dentry, old_path.mnt, to)) {
53350+ error = -EACCES;
53351+ goto out_dput;
53352+ }
53353+
53354 error = security_path_link(old_path.dentry, &new_path, new_dentry);
53355 if (error)
53356 goto out_dput;
53357 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
53358+ if (!error)
53359+ gr_handle_create(new_dentry, new_path.mnt);
53360 out_dput:
53361+ putname(to);
53362 done_path_create(&new_path, new_dentry);
53363 if (retry_estale(error, how)) {
53364 how |= LOOKUP_REVAL;
53365@@ -3906,12 +4096,21 @@ retry:
53366 if (new_dentry == trap)
53367 goto exit5;
53368
53369+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
53370+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
53371+ to);
53372+ if (error)
53373+ goto exit5;
53374+
53375 error = security_path_rename(&oldnd.path, old_dentry,
53376 &newnd.path, new_dentry);
53377 if (error)
53378 goto exit5;
53379 error = vfs_rename(old_dir->d_inode, old_dentry,
53380 new_dir->d_inode, new_dentry);
53381+ if (!error)
53382+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
53383+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
53384 exit5:
53385 dput(new_dentry);
53386 exit4:
53387@@ -3943,6 +4142,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
53388
53389 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
53390 {
53391+ char tmpbuf[64];
53392+ const char *newlink;
53393 int len;
53394
53395 len = PTR_ERR(link);
53396@@ -3952,7 +4153,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
53397 len = strlen(link);
53398 if (len > (unsigned) buflen)
53399 len = buflen;
53400- if (copy_to_user(buffer, link, len))
53401+
53402+ if (len < sizeof(tmpbuf)) {
53403+ memcpy(tmpbuf, link, len);
53404+ newlink = tmpbuf;
53405+ } else
53406+ newlink = link;
53407+
53408+ if (copy_to_user(buffer, newlink, len))
53409 len = -EFAULT;
53410 out:
53411 return len;
53412diff --git a/fs/namespace.c b/fs/namespace.c
53413index a51054f..f9b53e5 100644
53414--- a/fs/namespace.c
53415+++ b/fs/namespace.c
53416@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
53417 if (!(sb->s_flags & MS_RDONLY))
53418 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53419 up_write(&sb->s_umount);
53420+
53421+ gr_log_remount(mnt->mnt_devname, retval);
53422+
53423 return retval;
53424 }
53425
53426@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
53427 br_write_unlock(&vfsmount_lock);
53428 up_write(&namespace_sem);
53429 release_mounts(&umount_list);
53430+
53431+ gr_log_unmount(mnt->mnt_devname, retval);
53432+
53433 return retval;
53434 }
53435
53436@@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53437 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53438 MS_STRICTATIME);
53439
53440+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53441+ retval = -EPERM;
53442+ goto dput_out;
53443+ }
53444+
53445+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53446+ retval = -EPERM;
53447+ goto dput_out;
53448+ }
53449+
53450 if (flags & MS_REMOUNT)
53451 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53452 data_page);
53453@@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53454 dev_name, data_page);
53455 dput_out:
53456 path_put(&path);
53457+
53458+ gr_log_mount(dev_name, dir_name, retval);
53459+
53460 return retval;
53461 }
53462
53463@@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53464 if (error)
53465 goto out2;
53466
53467+ if (gr_handle_chroot_pivot()) {
53468+ error = -EPERM;
53469+ goto out2;
53470+ }
53471+
53472 get_fs_root(current->fs, &root);
53473 error = lock_mount(&old);
53474 if (error)
53475@@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53476 !nsown_capable(CAP_SYS_ADMIN))
53477 return -EPERM;
53478
53479- if (fs->users != 1)
53480+ if (atomic_read(&fs->users) != 1)
53481 return -EINVAL;
53482
53483 get_mnt_ns(mnt_ns);
53484diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53485index 59461c9..b17c57e 100644
53486--- a/fs/nfs/callback_xdr.c
53487+++ b/fs/nfs/callback_xdr.c
53488@@ -51,7 +51,7 @@ struct callback_op {
53489 callback_decode_arg_t decode_args;
53490 callback_encode_res_t encode_res;
53491 long res_maxsize;
53492-};
53493+} __do_const;
53494
53495 static struct callback_op callback_ops[];
53496
53497diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53498index ebeb94c..ff35337 100644
53499--- a/fs/nfs/inode.c
53500+++ b/fs/nfs/inode.c
53501@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53502 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53503 }
53504
53505-static atomic_long_t nfs_attr_generation_counter;
53506+static atomic_long_unchecked_t nfs_attr_generation_counter;
53507
53508 static unsigned long nfs_read_attr_generation_counter(void)
53509 {
53510- return atomic_long_read(&nfs_attr_generation_counter);
53511+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53512 }
53513
53514 unsigned long nfs_inc_attr_generation_counter(void)
53515 {
53516- return atomic_long_inc_return(&nfs_attr_generation_counter);
53517+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53518 }
53519
53520 void nfs_fattr_init(struct nfs_fattr *fattr)
53521diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53522index 9d1c5db..1e13db8 100644
53523--- a/fs/nfsd/nfs4proc.c
53524+++ b/fs/nfsd/nfs4proc.c
53525@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53526 nfsd4op_rsize op_rsize_bop;
53527 stateid_getter op_get_currentstateid;
53528 stateid_setter op_set_currentstateid;
53529-};
53530+} __do_const;
53531
53532 static struct nfsd4_operation nfsd4_ops[];
53533
53534diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53535index 0dc1158..ccf0338 100644
53536--- a/fs/nfsd/nfs4xdr.c
53537+++ b/fs/nfsd/nfs4xdr.c
53538@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53539
53540 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53541
53542-static nfsd4_dec nfsd4_dec_ops[] = {
53543+static const nfsd4_dec nfsd4_dec_ops[] = {
53544 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53545 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53546 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53547@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53548 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53549 };
53550
53551-static nfsd4_dec nfsd41_dec_ops[] = {
53552+static const nfsd4_dec nfsd41_dec_ops[] = {
53553 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53554 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53555 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53556@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53557 };
53558
53559 struct nfsd4_minorversion_ops {
53560- nfsd4_dec *decoders;
53561+ const nfsd4_dec *decoders;
53562 int nops;
53563 };
53564
53565diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53566index d586117..143d568 100644
53567--- a/fs/nfsd/vfs.c
53568+++ b/fs/nfsd/vfs.c
53569@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53570 } else {
53571 oldfs = get_fs();
53572 set_fs(KERNEL_DS);
53573- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53574+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53575 set_fs(oldfs);
53576 }
53577
53578@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53579
53580 /* Write the data. */
53581 oldfs = get_fs(); set_fs(KERNEL_DS);
53582- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53583+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53584 set_fs(oldfs);
53585 if (host_err < 0)
53586 goto out_nfserr;
53587@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53588 */
53589
53590 oldfs = get_fs(); set_fs(KERNEL_DS);
53591- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53592+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53593 set_fs(oldfs);
53594
53595 if (host_err < 0)
53596diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53597index fea6bd5..8ee9d81 100644
53598--- a/fs/nls/nls_base.c
53599+++ b/fs/nls/nls_base.c
53600@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53601
53602 int register_nls(struct nls_table * nls)
53603 {
53604- struct nls_table ** tmp = &tables;
53605+ struct nls_table *tmp = tables;
53606
53607 if (nls->next)
53608 return -EBUSY;
53609
53610 spin_lock(&nls_lock);
53611- while (*tmp) {
53612- if (nls == *tmp) {
53613+ while (tmp) {
53614+ if (nls == tmp) {
53615 spin_unlock(&nls_lock);
53616 return -EBUSY;
53617 }
53618- tmp = &(*tmp)->next;
53619+ tmp = tmp->next;
53620 }
53621- nls->next = tables;
53622+ pax_open_kernel();
53623+ *(struct nls_table **)&nls->next = tables;
53624+ pax_close_kernel();
53625 tables = nls;
53626 spin_unlock(&nls_lock);
53627 return 0;
53628@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53629
53630 int unregister_nls(struct nls_table * nls)
53631 {
53632- struct nls_table ** tmp = &tables;
53633+ struct nls_table * const * tmp = &tables;
53634
53635 spin_lock(&nls_lock);
53636 while (*tmp) {
53637 if (nls == *tmp) {
53638- *tmp = nls->next;
53639+ pax_open_kernel();
53640+ *(struct nls_table **)tmp = nls->next;
53641+ pax_close_kernel();
53642 spin_unlock(&nls_lock);
53643 return 0;
53644 }
53645diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53646index 7424929..35f6be5 100644
53647--- a/fs/nls/nls_euc-jp.c
53648+++ b/fs/nls/nls_euc-jp.c
53649@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53650 p_nls = load_nls("cp932");
53651
53652 if (p_nls) {
53653- table.charset2upper = p_nls->charset2upper;
53654- table.charset2lower = p_nls->charset2lower;
53655+ pax_open_kernel();
53656+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53657+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53658+ pax_close_kernel();
53659 return register_nls(&table);
53660 }
53661
53662diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53663index e7bc1d7..06bd4bb 100644
53664--- a/fs/nls/nls_koi8-ru.c
53665+++ b/fs/nls/nls_koi8-ru.c
53666@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53667 p_nls = load_nls("koi8-u");
53668
53669 if (p_nls) {
53670- table.charset2upper = p_nls->charset2upper;
53671- table.charset2lower = p_nls->charset2lower;
53672+ pax_open_kernel();
53673+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53674+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53675+ pax_close_kernel();
53676 return register_nls(&table);
53677 }
53678
53679diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53680index 9ff4a5e..deb1f0f 100644
53681--- a/fs/notify/fanotify/fanotify_user.c
53682+++ b/fs/notify/fanotify/fanotify_user.c
53683@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53684
53685 fd = fanotify_event_metadata.fd;
53686 ret = -EFAULT;
53687- if (copy_to_user(buf, &fanotify_event_metadata,
53688- fanotify_event_metadata.event_len))
53689+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53690+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53691 goto out_close_fd;
53692
53693 ret = prepare_for_access_response(group, event, fd);
53694diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53695index 7b51b05..5ea5ef6 100644
53696--- a/fs/notify/notification.c
53697+++ b/fs/notify/notification.c
53698@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53699 * get set to 0 so it will never get 'freed'
53700 */
53701 static struct fsnotify_event *q_overflow_event;
53702-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53703+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53704
53705 /**
53706 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53707@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53708 */
53709 u32 fsnotify_get_cookie(void)
53710 {
53711- return atomic_inc_return(&fsnotify_sync_cookie);
53712+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53713 }
53714 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53715
53716diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53717index 99e3610..02c1068 100644
53718--- a/fs/ntfs/dir.c
53719+++ b/fs/ntfs/dir.c
53720@@ -1329,7 +1329,7 @@ find_next_index_buffer:
53721 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53722 ~(s64)(ndir->itype.index.block_size - 1)));
53723 /* Bounds checks. */
53724- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53725+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53726 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53727 "inode 0x%lx or driver bug.", vdir->i_ino);
53728 goto err_out;
53729diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53730index 5b2d4f0..c6de396 100644
53731--- a/fs/ntfs/file.c
53732+++ b/fs/ntfs/file.c
53733@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53734 #endif /* NTFS_RW */
53735 };
53736
53737-const struct file_operations ntfs_empty_file_ops = {};
53738+const struct file_operations ntfs_empty_file_ops __read_only;
53739
53740-const struct inode_operations ntfs_empty_inode_ops = {};
53741+const struct inode_operations ntfs_empty_inode_ops __read_only;
53742diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53743index a9f78c7..ed8a381 100644
53744--- a/fs/ocfs2/localalloc.c
53745+++ b/fs/ocfs2/localalloc.c
53746@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53747 goto bail;
53748 }
53749
53750- atomic_inc(&osb->alloc_stats.moves);
53751+ atomic_inc_unchecked(&osb->alloc_stats.moves);
53752
53753 bail:
53754 if (handle)
53755diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53756index d355e6e..578d905 100644
53757--- a/fs/ocfs2/ocfs2.h
53758+++ b/fs/ocfs2/ocfs2.h
53759@@ -235,11 +235,11 @@ enum ocfs2_vol_state
53760
53761 struct ocfs2_alloc_stats
53762 {
53763- atomic_t moves;
53764- atomic_t local_data;
53765- atomic_t bitmap_data;
53766- atomic_t bg_allocs;
53767- atomic_t bg_extends;
53768+ atomic_unchecked_t moves;
53769+ atomic_unchecked_t local_data;
53770+ atomic_unchecked_t bitmap_data;
53771+ atomic_unchecked_t bg_allocs;
53772+ atomic_unchecked_t bg_extends;
53773 };
53774
53775 enum ocfs2_local_alloc_state
53776diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53777index b7e74b5..19c6536 100644
53778--- a/fs/ocfs2/suballoc.c
53779+++ b/fs/ocfs2/suballoc.c
53780@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53781 mlog_errno(status);
53782 goto bail;
53783 }
53784- atomic_inc(&osb->alloc_stats.bg_extends);
53785+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53786
53787 /* You should never ask for this much metadata */
53788 BUG_ON(bits_wanted >
53789@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53790 mlog_errno(status);
53791 goto bail;
53792 }
53793- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53794+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53795
53796 *suballoc_loc = res.sr_bg_blkno;
53797 *suballoc_bit_start = res.sr_bit_offset;
53798@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53799 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53800 res->sr_bits);
53801
53802- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53803+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53804
53805 BUG_ON(res->sr_bits != 1);
53806
53807@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53808 mlog_errno(status);
53809 goto bail;
53810 }
53811- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53812+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53813
53814 BUG_ON(res.sr_bits != 1);
53815
53816@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53817 cluster_start,
53818 num_clusters);
53819 if (!status)
53820- atomic_inc(&osb->alloc_stats.local_data);
53821+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
53822 } else {
53823 if (min_clusters > (osb->bitmap_cpg - 1)) {
53824 /* The only paths asking for contiguousness
53825@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53826 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53827 res.sr_bg_blkno,
53828 res.sr_bit_offset);
53829- atomic_inc(&osb->alloc_stats.bitmap_data);
53830+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53831 *num_clusters = res.sr_bits;
53832 }
53833 }
53834diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53835index 0e91ec2..f4b3fc6 100644
53836--- a/fs/ocfs2/super.c
53837+++ b/fs/ocfs2/super.c
53838@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53839 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53840 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53841 "Stats",
53842- atomic_read(&osb->alloc_stats.bitmap_data),
53843- atomic_read(&osb->alloc_stats.local_data),
53844- atomic_read(&osb->alloc_stats.bg_allocs),
53845- atomic_read(&osb->alloc_stats.moves),
53846- atomic_read(&osb->alloc_stats.bg_extends));
53847+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53848+ atomic_read_unchecked(&osb->alloc_stats.local_data),
53849+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53850+ atomic_read_unchecked(&osb->alloc_stats.moves),
53851+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53852
53853 out += snprintf(buf + out, len - out,
53854 "%10s => State: %u Descriptor: %llu Size: %u bits "
53855@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53856 spin_lock_init(&osb->osb_xattr_lock);
53857 ocfs2_init_steal_slots(osb);
53858
53859- atomic_set(&osb->alloc_stats.moves, 0);
53860- atomic_set(&osb->alloc_stats.local_data, 0);
53861- atomic_set(&osb->alloc_stats.bitmap_data, 0);
53862- atomic_set(&osb->alloc_stats.bg_allocs, 0);
53863- atomic_set(&osb->alloc_stats.bg_extends, 0);
53864+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53865+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53866+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53867+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53868+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53869
53870 /* Copy the blockcheck stats from the superblock probe */
53871 osb->osb_ecc_stats = *stats;
53872diff --git a/fs/open.c b/fs/open.c
53873index 9b33c0c..2ffcca2 100644
53874--- a/fs/open.c
53875+++ b/fs/open.c
53876@@ -31,6 +31,8 @@
53877 #include <linux/ima.h>
53878 #include <linux/dnotify.h>
53879
53880+#define CREATE_TRACE_POINTS
53881+#include <trace/events/fs.h>
53882 #include "internal.h"
53883
53884 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53885@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53886 error = locks_verify_truncate(inode, NULL, length);
53887 if (!error)
53888 error = security_path_truncate(path);
53889+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53890+ error = -EACCES;
53891 if (!error)
53892 error = do_truncate(path->dentry, length, 0, NULL);
53893
53894@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53895 error = locks_verify_truncate(inode, f.file, length);
53896 if (!error)
53897 error = security_path_truncate(&f.file->f_path);
53898+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53899+ error = -EACCES;
53900 if (!error)
53901 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53902 sb_end_write(inode->i_sb);
53903@@ -373,6 +379,9 @@ retry:
53904 if (__mnt_is_readonly(path.mnt))
53905 res = -EROFS;
53906
53907+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53908+ res = -EACCES;
53909+
53910 out_path_release:
53911 path_put(&path);
53912 if (retry_estale(res, lookup_flags)) {
53913@@ -404,6 +413,8 @@ retry:
53914 if (error)
53915 goto dput_and_out;
53916
53917+ gr_log_chdir(path.dentry, path.mnt);
53918+
53919 set_fs_pwd(current->fs, &path);
53920
53921 dput_and_out:
53922@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53923 goto out_putf;
53924
53925 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53926+
53927+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53928+ error = -EPERM;
53929+
53930+ if (!error)
53931+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53932+
53933 if (!error)
53934 set_fs_pwd(current->fs, &f.file->f_path);
53935 out_putf:
53936@@ -462,7 +480,13 @@ retry:
53937 if (error)
53938 goto dput_and_out;
53939
53940+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53941+ goto dput_and_out;
53942+
53943 set_fs_root(current->fs, &path);
53944+
53945+ gr_handle_chroot_chdir(&path);
53946+
53947 error = 0;
53948 dput_and_out:
53949 path_put(&path);
53950@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53951 if (error)
53952 return error;
53953 mutex_lock(&inode->i_mutex);
53954+
53955+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53956+ error = -EACCES;
53957+ goto out_unlock;
53958+ }
53959+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53960+ error = -EACCES;
53961+ goto out_unlock;
53962+ }
53963+
53964 error = security_path_chmod(path, mode);
53965 if (error)
53966 goto out_unlock;
53967@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53968 uid = make_kuid(current_user_ns(), user);
53969 gid = make_kgid(current_user_ns(), group);
53970
53971+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
53972+ return -EACCES;
53973+
53974 newattrs.ia_valid = ATTR_CTIME;
53975 if (user != (uid_t) -1) {
53976 if (!uid_valid(uid))
53977@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53978 } else {
53979 fsnotify_open(f);
53980 fd_install(fd, f);
53981+ trace_do_sys_open(tmp->name, flags, mode);
53982 }
53983 }
53984 putname(tmp);
53985diff --git a/fs/pipe.c b/fs/pipe.c
53986index 8e2e73f..1ef1048 100644
53987--- a/fs/pipe.c
53988+++ b/fs/pipe.c
53989@@ -438,9 +438,9 @@ redo:
53990 }
53991 if (bufs) /* More to do? */
53992 continue;
53993- if (!pipe->writers)
53994+ if (!atomic_read(&pipe->writers))
53995 break;
53996- if (!pipe->waiting_writers) {
53997+ if (!atomic_read(&pipe->waiting_writers)) {
53998 /* syscall merging: Usually we must not sleep
53999 * if O_NONBLOCK is set, or if we got some data.
54000 * But if a writer sleeps in kernel space, then
54001@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54002 mutex_lock(&inode->i_mutex);
54003 pipe = inode->i_pipe;
54004
54005- if (!pipe->readers) {
54006+ if (!atomic_read(&pipe->readers)) {
54007 send_sig(SIGPIPE, current, 0);
54008 ret = -EPIPE;
54009 goto out;
54010@@ -553,7 +553,7 @@ redo1:
54011 for (;;) {
54012 int bufs;
54013
54014- if (!pipe->readers) {
54015+ if (!atomic_read(&pipe->readers)) {
54016 send_sig(SIGPIPE, current, 0);
54017 if (!ret)
54018 ret = -EPIPE;
54019@@ -644,9 +644,9 @@ redo2:
54020 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54021 do_wakeup = 0;
54022 }
54023- pipe->waiting_writers++;
54024+ atomic_inc(&pipe->waiting_writers);
54025 pipe_wait(pipe);
54026- pipe->waiting_writers--;
54027+ atomic_dec(&pipe->waiting_writers);
54028 }
54029 out:
54030 mutex_unlock(&inode->i_mutex);
54031@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54032 mask = 0;
54033 if (filp->f_mode & FMODE_READ) {
54034 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54035- if (!pipe->writers && filp->f_version != pipe->w_counter)
54036+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54037 mask |= POLLHUP;
54038 }
54039
54040@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54041 * Most Unices do not set POLLERR for FIFOs but on Linux they
54042 * behave exactly like pipes for poll().
54043 */
54044- if (!pipe->readers)
54045+ if (!atomic_read(&pipe->readers))
54046 mask |= POLLERR;
54047 }
54048
54049@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54050
54051 mutex_lock(&inode->i_mutex);
54052 pipe = inode->i_pipe;
54053- pipe->readers -= decr;
54054- pipe->writers -= decw;
54055+ atomic_sub(decr, &pipe->readers);
54056+ atomic_sub(decw, &pipe->writers);
54057
54058- if (!pipe->readers && !pipe->writers) {
54059+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54060 free_pipe_info(inode);
54061 } else {
54062 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54063@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54064
54065 if (inode->i_pipe) {
54066 ret = 0;
54067- inode->i_pipe->readers++;
54068+ atomic_inc(&inode->i_pipe->readers);
54069 }
54070
54071 mutex_unlock(&inode->i_mutex);
54072@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54073
54074 if (inode->i_pipe) {
54075 ret = 0;
54076- inode->i_pipe->writers++;
54077+ atomic_inc(&inode->i_pipe->writers);
54078 }
54079
54080 mutex_unlock(&inode->i_mutex);
54081@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54082 if (inode->i_pipe) {
54083 ret = 0;
54084 if (filp->f_mode & FMODE_READ)
54085- inode->i_pipe->readers++;
54086+ atomic_inc(&inode->i_pipe->readers);
54087 if (filp->f_mode & FMODE_WRITE)
54088- inode->i_pipe->writers++;
54089+ atomic_inc(&inode->i_pipe->writers);
54090 }
54091
54092 mutex_unlock(&inode->i_mutex);
54093@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54094 inode->i_pipe = NULL;
54095 }
54096
54097-static struct vfsmount *pipe_mnt __read_mostly;
54098+struct vfsmount *pipe_mnt __read_mostly;
54099
54100 /*
54101 * pipefs_dname() is called from d_path().
54102@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54103 goto fail_iput;
54104 inode->i_pipe = pipe;
54105
54106- pipe->readers = pipe->writers = 1;
54107+ atomic_set(&pipe->readers, 1);
54108+ atomic_set(&pipe->writers, 1);
54109 inode->i_fop = &rdwr_pipefifo_fops;
54110
54111 /*
54112diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54113index 15af622..0e9f4467 100644
54114--- a/fs/proc/Kconfig
54115+++ b/fs/proc/Kconfig
54116@@ -30,12 +30,12 @@ config PROC_FS
54117
54118 config PROC_KCORE
54119 bool "/proc/kcore support" if !ARM
54120- depends on PROC_FS && MMU
54121+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54122
54123 config PROC_VMCORE
54124 bool "/proc/vmcore support"
54125- depends on PROC_FS && CRASH_DUMP
54126- default y
54127+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54128+ default n
54129 help
54130 Exports the dump image of crashed kernel in ELF format.
54131
54132@@ -59,8 +59,8 @@ config PROC_SYSCTL
54133 limited in memory.
54134
54135 config PROC_PAGE_MONITOR
54136- default y
54137- depends on PROC_FS && MMU
54138+ default n
54139+ depends on PROC_FS && MMU && !GRKERNSEC
54140 bool "Enable /proc page monitoring" if EXPERT
54141 help
54142 Various /proc files exist to monitor process memory utilization:
54143diff --git a/fs/proc/array.c b/fs/proc/array.c
54144index 6a91e6f..e54dbc14 100644
54145--- a/fs/proc/array.c
54146+++ b/fs/proc/array.c
54147@@ -60,6 +60,7 @@
54148 #include <linux/tty.h>
54149 #include <linux/string.h>
54150 #include <linux/mman.h>
54151+#include <linux/grsecurity.h>
54152 #include <linux/proc_fs.h>
54153 #include <linux/ioport.h>
54154 #include <linux/uaccess.h>
54155@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54156 seq_putc(m, '\n');
54157 }
54158
54159+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54160+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54161+{
54162+ if (p->mm)
54163+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54164+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54165+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54166+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54167+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54168+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54169+ else
54170+ seq_printf(m, "PaX:\t-----\n");
54171+}
54172+#endif
54173+
54174 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54175 struct pid *pid, struct task_struct *task)
54176 {
54177@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54178 task_cpus_allowed(m, task);
54179 cpuset_task_status_allowed(m, task);
54180 task_context_switch_counts(m, task);
54181+
54182+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54183+ task_pax(m, task);
54184+#endif
54185+
54186+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54187+ task_grsec_rbac(m, task);
54188+#endif
54189+
54190 return 0;
54191 }
54192
54193+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54194+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54195+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54196+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54197+#endif
54198+
54199 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54200 struct pid *pid, struct task_struct *task, int whole)
54201 {
54202@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54203 char tcomm[sizeof(task->comm)];
54204 unsigned long flags;
54205
54206+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54207+ if (current->exec_id != m->exec_id) {
54208+ gr_log_badprocpid("stat");
54209+ return 0;
54210+ }
54211+#endif
54212+
54213 state = *get_task_state(task);
54214 vsize = eip = esp = 0;
54215 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54216@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54217 gtime = task->gtime;
54218 }
54219
54220+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54221+ if (PAX_RAND_FLAGS(mm)) {
54222+ eip = 0;
54223+ esp = 0;
54224+ wchan = 0;
54225+ }
54226+#endif
54227+#ifdef CONFIG_GRKERNSEC_HIDESYM
54228+ wchan = 0;
54229+ eip =0;
54230+ esp =0;
54231+#endif
54232+
54233 /* scale priority and nice values from timeslices to -20..20 */
54234 /* to make it look like a "normal" Unix priority/nice value */
54235 priority = task_prio(task);
54236@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54237 seq_put_decimal_ull(m, ' ', vsize);
54238 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
54239 seq_put_decimal_ull(m, ' ', rsslim);
54240+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54241+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
54242+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
54243+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
54244+#else
54245 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
54246 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
54247 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
54248+#endif
54249 seq_put_decimal_ull(m, ' ', esp);
54250 seq_put_decimal_ull(m, ' ', eip);
54251 /* The signal information here is obsolete.
54252@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54253 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
54254 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
54255
54256- if (mm && permitted) {
54257+ if (mm && permitted
54258+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54259+ && !PAX_RAND_FLAGS(mm)
54260+#endif
54261+ ) {
54262 seq_put_decimal_ull(m, ' ', mm->start_data);
54263 seq_put_decimal_ull(m, ' ', mm->end_data);
54264 seq_put_decimal_ull(m, ' ', mm->start_brk);
54265@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54266 struct pid *pid, struct task_struct *task)
54267 {
54268 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
54269- struct mm_struct *mm = get_task_mm(task);
54270+ struct mm_struct *mm;
54271
54272+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54273+ if (current->exec_id != m->exec_id) {
54274+ gr_log_badprocpid("statm");
54275+ return 0;
54276+ }
54277+#endif
54278+ mm = get_task_mm(task);
54279 if (mm) {
54280 size = task_statm(mm, &shared, &text, &data, &resident);
54281 mmput(mm);
54282@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54283 return 0;
54284 }
54285
54286+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54287+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
54288+{
54289+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
54290+}
54291+#endif
54292+
54293 #ifdef CONFIG_CHECKPOINT_RESTORE
54294 static struct pid *
54295 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
54296diff --git a/fs/proc/base.c b/fs/proc/base.c
54297index 9b43ff77..ba3e990 100644
54298--- a/fs/proc/base.c
54299+++ b/fs/proc/base.c
54300@@ -111,6 +111,14 @@ struct pid_entry {
54301 union proc_op op;
54302 };
54303
54304+struct getdents_callback {
54305+ struct linux_dirent __user * current_dir;
54306+ struct linux_dirent __user * previous;
54307+ struct file * file;
54308+ int count;
54309+ int error;
54310+};
54311+
54312 #define NOD(NAME, MODE, IOP, FOP, OP) { \
54313 .name = (NAME), \
54314 .len = sizeof(NAME) - 1, \
54315@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
54316 if (!mm->arg_end)
54317 goto out_mm; /* Shh! No looking before we're done */
54318
54319+ if (gr_acl_handle_procpidmem(task))
54320+ goto out_mm;
54321+
54322 len = mm->arg_end - mm->arg_start;
54323
54324 if (len > PAGE_SIZE)
54325@@ -235,12 +246,28 @@ out:
54326 return res;
54327 }
54328
54329+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54330+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54331+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54332+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54333+#endif
54334+
54335 static int proc_pid_auxv(struct task_struct *task, char *buffer)
54336 {
54337 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
54338 int res = PTR_ERR(mm);
54339 if (mm && !IS_ERR(mm)) {
54340 unsigned int nwords = 0;
54341+
54342+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54343+ /* allow if we're currently ptracing this task */
54344+ if (PAX_RAND_FLAGS(mm) &&
54345+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
54346+ mmput(mm);
54347+ return 0;
54348+ }
54349+#endif
54350+
54351 do {
54352 nwords += 2;
54353 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
54354@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
54355 }
54356
54357
54358-#ifdef CONFIG_KALLSYMS
54359+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54360 /*
54361 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
54362 * Returns the resolved symbol. If that fails, simply return the address.
54363@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
54364 mutex_unlock(&task->signal->cred_guard_mutex);
54365 }
54366
54367-#ifdef CONFIG_STACKTRACE
54368+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54369
54370 #define MAX_STACK_TRACE_DEPTH 64
54371
54372@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
54373 return count;
54374 }
54375
54376-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54377+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54378 static int proc_pid_syscall(struct task_struct *task, char *buffer)
54379 {
54380 long nr;
54381@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
54382 /************************************************************************/
54383
54384 /* permission checks */
54385-static int proc_fd_access_allowed(struct inode *inode)
54386+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
54387 {
54388 struct task_struct *task;
54389 int allowed = 0;
54390@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
54391 */
54392 task = get_proc_task(inode);
54393 if (task) {
54394- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54395+ if (log)
54396+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54397+ else
54398+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54399 put_task_struct(task);
54400 }
54401 return allowed;
54402@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
54403 struct task_struct *task,
54404 int hide_pid_min)
54405 {
54406+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54407+ return false;
54408+
54409+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54410+ rcu_read_lock();
54411+ {
54412+ const struct cred *tmpcred = current_cred();
54413+ const struct cred *cred = __task_cred(task);
54414+
54415+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
54416+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54417+ || in_group_p(grsec_proc_gid)
54418+#endif
54419+ ) {
54420+ rcu_read_unlock();
54421+ return true;
54422+ }
54423+ }
54424+ rcu_read_unlock();
54425+
54426+ if (!pid->hide_pid)
54427+ return false;
54428+#endif
54429+
54430 if (pid->hide_pid < hide_pid_min)
54431 return true;
54432 if (in_group_p(pid->pid_gid))
54433 return true;
54434+
54435 return ptrace_may_access(task, PTRACE_MODE_READ);
54436 }
54437
54438@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54439 put_task_struct(task);
54440
54441 if (!has_perms) {
54442+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54443+ {
54444+#else
54445 if (pid->hide_pid == 2) {
54446+#endif
54447 /*
54448 * Let's make getdents(), stat(), and open()
54449 * consistent with each other. If a process
54450@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54451 if (!task)
54452 return -ESRCH;
54453
54454+ if (gr_acl_handle_procpidmem(task)) {
54455+ put_task_struct(task);
54456+ return -EPERM;
54457+ }
54458+
54459 mm = mm_access(task, mode);
54460 put_task_struct(task);
54461
54462@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54463
54464 file->private_data = mm;
54465
54466+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54467+ file->f_version = current->exec_id;
54468+#endif
54469+
54470 return 0;
54471 }
54472
54473@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54474 ssize_t copied;
54475 char *page;
54476
54477+#ifdef CONFIG_GRKERNSEC
54478+ if (write)
54479+ return -EPERM;
54480+#endif
54481+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54482+ if (file->f_version != current->exec_id) {
54483+ gr_log_badprocpid("mem");
54484+ return 0;
54485+ }
54486+#endif
54487+
54488 if (!mm)
54489 return 0;
54490
54491@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54492 if (!mm)
54493 return 0;
54494
54495+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54496+ if (file->f_version != current->exec_id) {
54497+ gr_log_badprocpid("environ");
54498+ return 0;
54499+ }
54500+#endif
54501+
54502 page = (char *)__get_free_page(GFP_TEMPORARY);
54503 if (!page)
54504 return -ENOMEM;
54505@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54506 int error = -EACCES;
54507
54508 /* Are we allowed to snoop on the tasks file descriptors? */
54509- if (!proc_fd_access_allowed(inode))
54510+ if (!proc_fd_access_allowed(inode, 0))
54511 goto out;
54512
54513 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54514@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54515 struct path path;
54516
54517 /* Are we allowed to snoop on the tasks file descriptors? */
54518- if (!proc_fd_access_allowed(inode))
54519- goto out;
54520+ /* logging this is needed for learning on chromium to work properly,
54521+ but we don't want to flood the logs from 'ps' which does a readlink
54522+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54523+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
54524+ */
54525+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54526+ if (!proc_fd_access_allowed(inode,0))
54527+ goto out;
54528+ } else {
54529+ if (!proc_fd_access_allowed(inode,1))
54530+ goto out;
54531+ }
54532
54533 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54534 if (error)
54535@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54536 rcu_read_lock();
54537 cred = __task_cred(task);
54538 inode->i_uid = cred->euid;
54539+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54540+ inode->i_gid = grsec_proc_gid;
54541+#else
54542 inode->i_gid = cred->egid;
54543+#endif
54544 rcu_read_unlock();
54545 }
54546 security_task_to_inode(task, inode);
54547@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54548 return -ENOENT;
54549 }
54550 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54551+#ifdef CONFIG_GRKERNSEC_PROC_USER
54552+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54553+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54554+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54555+#endif
54556 task_dumpable(task)) {
54557 cred = __task_cred(task);
54558 stat->uid = cred->euid;
54559+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54560+ stat->gid = grsec_proc_gid;
54561+#else
54562 stat->gid = cred->egid;
54563+#endif
54564 }
54565 }
54566 rcu_read_unlock();
54567@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54568
54569 if (task) {
54570 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54571+#ifdef CONFIG_GRKERNSEC_PROC_USER
54572+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54573+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54574+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54575+#endif
54576 task_dumpable(task)) {
54577 rcu_read_lock();
54578 cred = __task_cred(task);
54579 inode->i_uid = cred->euid;
54580+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54581+ inode->i_gid = grsec_proc_gid;
54582+#else
54583 inode->i_gid = cred->egid;
54584+#endif
54585 rcu_read_unlock();
54586 } else {
54587 inode->i_uid = GLOBAL_ROOT_UID;
54588@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54589 if (!task)
54590 goto out_no_task;
54591
54592+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54593+ goto out;
54594+
54595 /*
54596 * Yes, it does not scale. And it should not. Don't add
54597 * new entries into /proc/<tgid>/ without very good reasons.
54598@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54599 if (!task)
54600 goto out_no_task;
54601
54602+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54603+ goto out;
54604+
54605 ret = 0;
54606 i = filp->f_pos;
54607 switch (i) {
54608@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54609 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54610 #endif
54611 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54612-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54613+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54614 INF("syscall", S_IRUGO, proc_pid_syscall),
54615 #endif
54616 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54617@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54618 #ifdef CONFIG_SECURITY
54619 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54620 #endif
54621-#ifdef CONFIG_KALLSYMS
54622+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54623 INF("wchan", S_IRUGO, proc_pid_wchan),
54624 #endif
54625-#ifdef CONFIG_STACKTRACE
54626+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54627 ONE("stack", S_IRUGO, proc_pid_stack),
54628 #endif
54629 #ifdef CONFIG_SCHEDSTATS
54630@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54631 #ifdef CONFIG_HARDWALL
54632 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54633 #endif
54634+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54635+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54636+#endif
54637 #ifdef CONFIG_USER_NS
54638 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54639 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54640@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54641 if (!inode)
54642 goto out;
54643
54644+#ifdef CONFIG_GRKERNSEC_PROC_USER
54645+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54646+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54647+ inode->i_gid = grsec_proc_gid;
54648+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54649+#else
54650 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54651+#endif
54652 inode->i_op = &proc_tgid_base_inode_operations;
54653 inode->i_fop = &proc_tgid_base_operations;
54654 inode->i_flags|=S_IMMUTABLE;
54655@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54656 if (!task)
54657 goto out;
54658
54659+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54660+ goto out_put_task;
54661+
54662 result = proc_pid_instantiate(dir, dentry, task, NULL);
54663+out_put_task:
54664 put_task_struct(task);
54665 out:
54666 return result;
54667@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54668 static int fake_filldir(void *buf, const char *name, int namelen,
54669 loff_t offset, u64 ino, unsigned d_type)
54670 {
54671+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
54672+ __buf->error = -EINVAL;
54673 return 0;
54674 }
54675
54676@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54677 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54678 #endif
54679 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54680-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54681+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54682 INF("syscall", S_IRUGO, proc_pid_syscall),
54683 #endif
54684 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54685@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54686 #ifdef CONFIG_SECURITY
54687 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54688 #endif
54689-#ifdef CONFIG_KALLSYMS
54690+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54691 INF("wchan", S_IRUGO, proc_pid_wchan),
54692 #endif
54693-#ifdef CONFIG_STACKTRACE
54694+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54695 ONE("stack", S_IRUGO, proc_pid_stack),
54696 #endif
54697 #ifdef CONFIG_SCHEDSTATS
54698diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54699index 82676e3..5f8518a 100644
54700--- a/fs/proc/cmdline.c
54701+++ b/fs/proc/cmdline.c
54702@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54703
54704 static int __init proc_cmdline_init(void)
54705 {
54706+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54707+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54708+#else
54709 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54710+#endif
54711 return 0;
54712 }
54713 module_init(proc_cmdline_init);
54714diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54715index b143471..bb105e5 100644
54716--- a/fs/proc/devices.c
54717+++ b/fs/proc/devices.c
54718@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54719
54720 static int __init proc_devices_init(void)
54721 {
54722+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54723+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54724+#else
54725 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54726+#endif
54727 return 0;
54728 }
54729 module_init(proc_devices_init);
54730diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54731index d7a4a28..0201742 100644
54732--- a/fs/proc/fd.c
54733+++ b/fs/proc/fd.c
54734@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54735 if (!task)
54736 return -ENOENT;
54737
54738- files = get_files_struct(task);
54739+ if (!gr_acl_handle_procpidmem(task))
54740+ files = get_files_struct(task);
54741 put_task_struct(task);
54742
54743 if (files) {
54744@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54745 */
54746 int proc_fd_permission(struct inode *inode, int mask)
54747 {
54748+ struct task_struct *task;
54749 int rv = generic_permission(inode, mask);
54750- if (rv == 0)
54751- return 0;
54752+
54753 if (task_pid(current) == proc_pid(inode))
54754 rv = 0;
54755+
54756+ task = get_proc_task(inode);
54757+ if (task == NULL)
54758+ return rv;
54759+
54760+ if (gr_acl_handle_procpidmem(task))
54761+ rv = -EACCES;
54762+
54763+ put_task_struct(task);
54764+
54765 return rv;
54766 }
54767
54768diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54769index 439ae688..c21ac36 100644
54770--- a/fs/proc/inode.c
54771+++ b/fs/proc/inode.c
54772@@ -21,11 +21,17 @@
54773 #include <linux/seq_file.h>
54774 #include <linux/slab.h>
54775 #include <linux/mount.h>
54776+#include <linux/grsecurity.h>
54777
54778 #include <asm/uaccess.h>
54779
54780 #include "internal.h"
54781
54782+#ifdef CONFIG_PROC_SYSCTL
54783+extern const struct inode_operations proc_sys_inode_operations;
54784+extern const struct inode_operations proc_sys_dir_operations;
54785+#endif
54786+
54787 static void proc_evict_inode(struct inode *inode)
54788 {
54789 struct proc_dir_entry *de;
54790@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54791 ns = PROC_I(inode)->ns;
54792 if (ns_ops && ns)
54793 ns_ops->put(ns);
54794+
54795+#ifdef CONFIG_PROC_SYSCTL
54796+ if (inode->i_op == &proc_sys_inode_operations ||
54797+ inode->i_op == &proc_sys_dir_operations)
54798+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54799+#endif
54800+
54801 }
54802
54803 static struct kmem_cache * proc_inode_cachep;
54804@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54805 if (de->mode) {
54806 inode->i_mode = de->mode;
54807 inode->i_uid = de->uid;
54808+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54809+ inode->i_gid = grsec_proc_gid;
54810+#else
54811 inode->i_gid = de->gid;
54812+#endif
54813 }
54814 if (de->size)
54815 inode->i_size = de->size;
54816diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54817index 252544c..04395b9 100644
54818--- a/fs/proc/internal.h
54819+++ b/fs/proc/internal.h
54820@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54821 struct pid *pid, struct task_struct *task);
54822 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54823 struct pid *pid, struct task_struct *task);
54824+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54825+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54826+#endif
54827 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54828
54829 extern const struct file_operations proc_tid_children_operations;
54830diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54831index e96d4f1..8b116ed 100644
54832--- a/fs/proc/kcore.c
54833+++ b/fs/proc/kcore.c
54834@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54835 * the addresses in the elf_phdr on our list.
54836 */
54837 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54838- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54839+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54840+ if (tsz > buflen)
54841 tsz = buflen;
54842-
54843+
54844 while (buflen) {
54845 struct kcore_list *m;
54846
54847@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54848 kfree(elf_buf);
54849 } else {
54850 if (kern_addr_valid(start)) {
54851- unsigned long n;
54852+ char *elf_buf;
54853+ mm_segment_t oldfs;
54854
54855- n = copy_to_user(buffer, (char *)start, tsz);
54856- /*
54857- * We cannot distinguish between fault on source
54858- * and fault on destination. When this happens
54859- * we clear too and hope it will trigger the
54860- * EFAULT again.
54861- */
54862- if (n) {
54863- if (clear_user(buffer + tsz - n,
54864- n))
54865+ elf_buf = kmalloc(tsz, GFP_KERNEL);
54866+ if (!elf_buf)
54867+ return -ENOMEM;
54868+ oldfs = get_fs();
54869+ set_fs(KERNEL_DS);
54870+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54871+ set_fs(oldfs);
54872+ if (copy_to_user(buffer, elf_buf, tsz)) {
54873+ kfree(elf_buf);
54874 return -EFAULT;
54875+ }
54876 }
54877+ set_fs(oldfs);
54878+ kfree(elf_buf);
54879 } else {
54880 if (clear_user(buffer, tsz))
54881 return -EFAULT;
54882@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54883
54884 static int open_kcore(struct inode *inode, struct file *filp)
54885 {
54886+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54887+ return -EPERM;
54888+#endif
54889 if (!capable(CAP_SYS_RAWIO))
54890 return -EPERM;
54891 if (kcore_need_update)
54892diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54893index 80e4645..53e5fcf 100644
54894--- a/fs/proc/meminfo.c
54895+++ b/fs/proc/meminfo.c
54896@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54897 vmi.used >> 10,
54898 vmi.largest_chunk >> 10
54899 #ifdef CONFIG_MEMORY_FAILURE
54900- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54901+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54902 #endif
54903 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54904 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54905diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54906index b1822dd..df622cb 100644
54907--- a/fs/proc/nommu.c
54908+++ b/fs/proc/nommu.c
54909@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54910 if (len < 1)
54911 len = 1;
54912 seq_printf(m, "%*c", len, ' ');
54913- seq_path(m, &file->f_path, "");
54914+ seq_path(m, &file->f_path, "\n\\");
54915 }
54916
54917 seq_putc(m, '\n');
54918diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54919index fe72cd0..21b52ff 100644
54920--- a/fs/proc/proc_net.c
54921+++ b/fs/proc/proc_net.c
54922@@ -23,6 +23,7 @@
54923 #include <linux/nsproxy.h>
54924 #include <net/net_namespace.h>
54925 #include <linux/seq_file.h>
54926+#include <linux/grsecurity.h>
54927
54928 #include "internal.h"
54929
54930@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54931 struct task_struct *task;
54932 struct nsproxy *ns;
54933 struct net *net = NULL;
54934+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54935+ const struct cred *cred = current_cred();
54936+#endif
54937+
54938+#ifdef CONFIG_GRKERNSEC_PROC_USER
54939+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54940+ return net;
54941+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54942+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54943+ return net;
54944+#endif
54945
54946 rcu_read_lock();
54947 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54948diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54949index 1827d88..43b0279 100644
54950--- a/fs/proc/proc_sysctl.c
54951+++ b/fs/proc/proc_sysctl.c
54952@@ -12,11 +12,15 @@
54953 #include <linux/module.h>
54954 #include "internal.h"
54955
54956+extern int gr_handle_chroot_sysctl(const int op);
54957+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54958+ const int op);
54959+
54960 static const struct dentry_operations proc_sys_dentry_operations;
54961 static const struct file_operations proc_sys_file_operations;
54962-static const struct inode_operations proc_sys_inode_operations;
54963+const struct inode_operations proc_sys_inode_operations;
54964 static const struct file_operations proc_sys_dir_file_operations;
54965-static const struct inode_operations proc_sys_dir_operations;
54966+const struct inode_operations proc_sys_dir_operations;
54967
54968 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54969 {
54970@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54971
54972 err = NULL;
54973 d_set_d_op(dentry, &proc_sys_dentry_operations);
54974+
54975+ gr_handle_proc_create(dentry, inode);
54976+
54977 d_add(dentry, inode);
54978
54979 out:
54980@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54981 struct inode *inode = filp->f_path.dentry->d_inode;
54982 struct ctl_table_header *head = grab_header(inode);
54983 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54984+ int op = write ? MAY_WRITE : MAY_READ;
54985 ssize_t error;
54986 size_t res;
54987
54988@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54989 * and won't be until we finish.
54990 */
54991 error = -EPERM;
54992- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54993+ if (sysctl_perm(head, table, op))
54994 goto out;
54995
54996 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
54997@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54998 if (!table->proc_handler)
54999 goto out;
55000
55001+#ifdef CONFIG_GRKERNSEC
55002+ error = -EPERM;
55003+ if (gr_handle_chroot_sysctl(op))
55004+ goto out;
55005+ dget(filp->f_path.dentry);
55006+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55007+ dput(filp->f_path.dentry);
55008+ goto out;
55009+ }
55010+ dput(filp->f_path.dentry);
55011+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55012+ goto out;
55013+ if (write && !capable(CAP_SYS_ADMIN))
55014+ goto out;
55015+#endif
55016+
55017 /* careful: calling conventions are nasty here */
55018 res = count;
55019 error = table->proc_handler(table, write, buf, &res, ppos);
55020@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55021 return -ENOMEM;
55022 } else {
55023 d_set_d_op(child, &proc_sys_dentry_operations);
55024+
55025+ gr_handle_proc_create(child, inode);
55026+
55027 d_add(child, inode);
55028 }
55029 } else {
55030@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55031 if ((*pos)++ < file->f_pos)
55032 return 0;
55033
55034+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55035+ return 0;
55036+
55037 if (unlikely(S_ISLNK(table->mode)))
55038 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55039 else
55040@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55041 if (IS_ERR(head))
55042 return PTR_ERR(head);
55043
55044+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55045+ return -ENOENT;
55046+
55047 generic_fillattr(inode, stat);
55048 if (table)
55049 stat->mode = (stat->mode & S_IFMT) | table->mode;
55050@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55051 .llseek = generic_file_llseek,
55052 };
55053
55054-static const struct inode_operations proc_sys_inode_operations = {
55055+const struct inode_operations proc_sys_inode_operations = {
55056 .permission = proc_sys_permission,
55057 .setattr = proc_sys_setattr,
55058 .getattr = proc_sys_getattr,
55059 };
55060
55061-static const struct inode_operations proc_sys_dir_operations = {
55062+const struct inode_operations proc_sys_dir_operations = {
55063 .lookup = proc_sys_lookup,
55064 .permission = proc_sys_permission,
55065 .setattr = proc_sys_setattr,
55066@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55067 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55068 const char *name, int namelen)
55069 {
55070- struct ctl_table *table;
55071+ ctl_table_no_const *table;
55072 struct ctl_dir *new;
55073 struct ctl_node *node;
55074 char *new_name;
55075@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55076 return NULL;
55077
55078 node = (struct ctl_node *)(new + 1);
55079- table = (struct ctl_table *)(node + 1);
55080+ table = (ctl_table_no_const *)(node + 1);
55081 new_name = (char *)(table + 2);
55082 memcpy(new_name, name, namelen);
55083 new_name[namelen] = '\0';
55084@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55085 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55086 struct ctl_table_root *link_root)
55087 {
55088- struct ctl_table *link_table, *entry, *link;
55089+ ctl_table_no_const *link_table, *link;
55090+ struct ctl_table *entry;
55091 struct ctl_table_header *links;
55092 struct ctl_node *node;
55093 char *link_name;
55094@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55095 return NULL;
55096
55097 node = (struct ctl_node *)(links + 1);
55098- link_table = (struct ctl_table *)(node + nr_entries);
55099+ link_table = (ctl_table_no_const *)(node + nr_entries);
55100 link_name = (char *)&link_table[nr_entries + 1];
55101
55102 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55103@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55104 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55105 struct ctl_table *table)
55106 {
55107- struct ctl_table *ctl_table_arg = NULL;
55108- struct ctl_table *entry, *files;
55109+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55110+ struct ctl_table *entry;
55111 int nr_files = 0;
55112 int nr_dirs = 0;
55113 int err = -ENOMEM;
55114@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55115 nr_files++;
55116 }
55117
55118- files = table;
55119 /* If there are mixed files and directories we need a new table */
55120 if (nr_dirs && nr_files) {
55121- struct ctl_table *new;
55122+ ctl_table_no_const *new;
55123 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55124 GFP_KERNEL);
55125 if (!files)
55126@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55127 /* Register everything except a directory full of subdirectories */
55128 if (nr_files || !nr_dirs) {
55129 struct ctl_table_header *header;
55130- header = __register_sysctl_table(set, path, files);
55131+ header = __register_sysctl_table(set, path, files ? files : table);
55132 if (!header) {
55133 kfree(ctl_table_arg);
55134 goto out;
55135diff --git a/fs/proc/root.c b/fs/proc/root.c
55136index c6e9fac..a740964 100644
55137--- a/fs/proc/root.c
55138+++ b/fs/proc/root.c
55139@@ -176,7 +176,15 @@ void __init proc_root_init(void)
55140 #ifdef CONFIG_PROC_DEVICETREE
55141 proc_device_tree_init();
55142 #endif
55143+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55144+#ifdef CONFIG_GRKERNSEC_PROC_USER
55145+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55146+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55147+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55148+#endif
55149+#else
55150 proc_mkdir("bus", NULL);
55151+#endif
55152 proc_sys_init();
55153 }
55154
55155diff --git a/fs/proc/self.c b/fs/proc/self.c
55156index aa5cc3b..c91a5d0 100644
55157--- a/fs/proc/self.c
55158+++ b/fs/proc/self.c
55159@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55160 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55161 void *cookie)
55162 {
55163- char *s = nd_get_link(nd);
55164+ const char *s = nd_get_link(nd);
55165 if (!IS_ERR(s))
55166 kfree(s);
55167 }
55168diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55169index ca5ce7f..02c1cf0 100644
55170--- a/fs/proc/task_mmu.c
55171+++ b/fs/proc/task_mmu.c
55172@@ -11,12 +11,19 @@
55173 #include <linux/rmap.h>
55174 #include <linux/swap.h>
55175 #include <linux/swapops.h>
55176+#include <linux/grsecurity.h>
55177
55178 #include <asm/elf.h>
55179 #include <asm/uaccess.h>
55180 #include <asm/tlbflush.h>
55181 #include "internal.h"
55182
55183+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55184+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55185+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55186+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55187+#endif
55188+
55189 void task_mem(struct seq_file *m, struct mm_struct *mm)
55190 {
55191 unsigned long data, text, lib, swap;
55192@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55193 "VmExe:\t%8lu kB\n"
55194 "VmLib:\t%8lu kB\n"
55195 "VmPTE:\t%8lu kB\n"
55196- "VmSwap:\t%8lu kB\n",
55197- hiwater_vm << (PAGE_SHIFT-10),
55198+ "VmSwap:\t%8lu kB\n"
55199+
55200+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55201+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
55202+#endif
55203+
55204+ ,hiwater_vm << (PAGE_SHIFT-10),
55205 total_vm << (PAGE_SHIFT-10),
55206 mm->locked_vm << (PAGE_SHIFT-10),
55207 mm->pinned_vm << (PAGE_SHIFT-10),
55208@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55209 data << (PAGE_SHIFT-10),
55210 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
55211 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
55212- swap << (PAGE_SHIFT-10));
55213+ swap << (PAGE_SHIFT-10)
55214+
55215+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55216+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55217+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
55218+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
55219+#else
55220+ , mm->context.user_cs_base
55221+ , mm->context.user_cs_limit
55222+#endif
55223+#endif
55224+
55225+ );
55226 }
55227
55228 unsigned long task_vsize(struct mm_struct *mm)
55229@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55230 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
55231 }
55232
55233- /* We don't show the stack guard page in /proc/maps */
55234+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55235+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
55236+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
55237+#else
55238 start = vma->vm_start;
55239- if (stack_guard_page_start(vma, start))
55240- start += PAGE_SIZE;
55241 end = vma->vm_end;
55242- if (stack_guard_page_end(vma, end))
55243- end -= PAGE_SIZE;
55244+#endif
55245
55246 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
55247 start,
55248@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55249 flags & VM_WRITE ? 'w' : '-',
55250 flags & VM_EXEC ? 'x' : '-',
55251 flags & VM_MAYSHARE ? 's' : 'p',
55252+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55253+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
55254+#else
55255 pgoff,
55256+#endif
55257 MAJOR(dev), MINOR(dev), ino, &len);
55258
55259 /*
55260@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55261 */
55262 if (file) {
55263 pad_len_spaces(m, len);
55264- seq_path(m, &file->f_path, "\n");
55265+ seq_path(m, &file->f_path, "\n\\");
55266 goto done;
55267 }
55268
55269@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55270 * Thread stack in /proc/PID/task/TID/maps or
55271 * the main process stack.
55272 */
55273- if (!is_pid || (vma->vm_start <= mm->start_stack &&
55274- vma->vm_end >= mm->start_stack)) {
55275+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
55276+ (vma->vm_start <= mm->start_stack &&
55277+ vma->vm_end >= mm->start_stack)) {
55278 name = "[stack]";
55279 } else {
55280 /* Thread stack in /proc/PID/maps */
55281@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
55282 struct proc_maps_private *priv = m->private;
55283 struct task_struct *task = priv->task;
55284
55285+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55286+ if (current->exec_id != m->exec_id) {
55287+ gr_log_badprocpid("maps");
55288+ return 0;
55289+ }
55290+#endif
55291+
55292 show_map_vma(m, vma, is_pid);
55293
55294 if (m->count < m->size) /* vma is copied successfully */
55295@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55296 .private = &mss,
55297 };
55298
55299+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55300+ if (current->exec_id != m->exec_id) {
55301+ gr_log_badprocpid("smaps");
55302+ return 0;
55303+ }
55304+#endif
55305 memset(&mss, 0, sizeof mss);
55306- mss.vma = vma;
55307- /* mmap_sem is held in m_start */
55308- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55309- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55310-
55311+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55312+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
55313+#endif
55314+ mss.vma = vma;
55315+ /* mmap_sem is held in m_start */
55316+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55317+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55318+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55319+ }
55320+#endif
55321 show_map_vma(m, vma, is_pid);
55322
55323 seq_printf(m,
55324@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55325 "KernelPageSize: %8lu kB\n"
55326 "MMUPageSize: %8lu kB\n"
55327 "Locked: %8lu kB\n",
55328+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55329+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
55330+#else
55331 (vma->vm_end - vma->vm_start) >> 10,
55332+#endif
55333 mss.resident >> 10,
55334 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
55335 mss.shared_clean >> 10,
55336@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55337 int n;
55338 char buffer[50];
55339
55340+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55341+ if (current->exec_id != m->exec_id) {
55342+ gr_log_badprocpid("numa_maps");
55343+ return 0;
55344+ }
55345+#endif
55346+
55347 if (!mm)
55348 return 0;
55349
55350@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55351 mpol_to_str(buffer, sizeof(buffer), pol);
55352 mpol_cond_put(pol);
55353
55354+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55355+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
55356+#else
55357 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
55358+#endif
55359
55360 if (file) {
55361 seq_printf(m, " file=");
55362- seq_path(m, &file->f_path, "\n\t= ");
55363+ seq_path(m, &file->f_path, "\n\t\\= ");
55364 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
55365 seq_printf(m, " heap");
55366 } else {
55367diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
55368index 1ccfa53..0848f95 100644
55369--- a/fs/proc/task_nommu.c
55370+++ b/fs/proc/task_nommu.c
55371@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55372 else
55373 bytes += kobjsize(mm);
55374
55375- if (current->fs && current->fs->users > 1)
55376+ if (current->fs && atomic_read(&current->fs->users) > 1)
55377 sbytes += kobjsize(current->fs);
55378 else
55379 bytes += kobjsize(current->fs);
55380@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
55381
55382 if (file) {
55383 pad_len_spaces(m, len);
55384- seq_path(m, &file->f_path, "");
55385+ seq_path(m, &file->f_path, "\n\\");
55386 } else if (mm) {
55387 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
55388
55389diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
55390index b00fcc9..e0c6381 100644
55391--- a/fs/qnx6/qnx6.h
55392+++ b/fs/qnx6/qnx6.h
55393@@ -74,7 +74,7 @@ enum {
55394 BYTESEX_BE,
55395 };
55396
55397-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55398+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55399 {
55400 if (sbi->s_bytesex == BYTESEX_LE)
55401 return le64_to_cpu((__force __le64)n);
55402@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
55403 return (__force __fs64)cpu_to_be64(n);
55404 }
55405
55406-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55407+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55408 {
55409 if (sbi->s_bytesex == BYTESEX_LE)
55410 return le32_to_cpu((__force __le32)n);
55411diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
55412index 16e8abb..2dcf914 100644
55413--- a/fs/quota/netlink.c
55414+++ b/fs/quota/netlink.c
55415@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
55416 void quota_send_warning(struct kqid qid, dev_t dev,
55417 const char warntype)
55418 {
55419- static atomic_t seq;
55420+ static atomic_unchecked_t seq;
55421 struct sk_buff *skb;
55422 void *msg_head;
55423 int ret;
55424@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
55425 "VFS: Not enough memory to send quota warning.\n");
55426 return;
55427 }
55428- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
55429+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
55430 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
55431 if (!msg_head) {
55432 printk(KERN_ERR
55433diff --git a/fs/readdir.c b/fs/readdir.c
55434index 5e69ef5..e5d9099 100644
55435--- a/fs/readdir.c
55436+++ b/fs/readdir.c
55437@@ -17,6 +17,7 @@
55438 #include <linux/security.h>
55439 #include <linux/syscalls.h>
55440 #include <linux/unistd.h>
55441+#include <linux/namei.h>
55442
55443 #include <asm/uaccess.h>
55444
55445@@ -67,6 +68,7 @@ struct old_linux_dirent {
55446
55447 struct readdir_callback {
55448 struct old_linux_dirent __user * dirent;
55449+ struct file * file;
55450 int result;
55451 };
55452
55453@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55454 buf->result = -EOVERFLOW;
55455 return -EOVERFLOW;
55456 }
55457+
55458+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55459+ return 0;
55460+
55461 buf->result++;
55462 dirent = buf->dirent;
55463 if (!access_ok(VERIFY_WRITE, dirent,
55464@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55465
55466 buf.result = 0;
55467 buf.dirent = dirent;
55468+ buf.file = f.file;
55469
55470 error = vfs_readdir(f.file, fillonedir, &buf);
55471 if (buf.result)
55472@@ -139,6 +146,7 @@ struct linux_dirent {
55473 struct getdents_callback {
55474 struct linux_dirent __user * current_dir;
55475 struct linux_dirent __user * previous;
55476+ struct file * file;
55477 int count;
55478 int error;
55479 };
55480@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55481 buf->error = -EOVERFLOW;
55482 return -EOVERFLOW;
55483 }
55484+
55485+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55486+ return 0;
55487+
55488 dirent = buf->previous;
55489 if (dirent) {
55490 if (__put_user(offset, &dirent->d_off))
55491@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55492 buf.previous = NULL;
55493 buf.count = count;
55494 buf.error = 0;
55495+ buf.file = f.file;
55496
55497 error = vfs_readdir(f.file, filldir, &buf);
55498 if (error >= 0)
55499@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55500 struct getdents_callback64 {
55501 struct linux_dirent64 __user * current_dir;
55502 struct linux_dirent64 __user * previous;
55503+ struct file *file;
55504 int count;
55505 int error;
55506 };
55507@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55508 buf->error = -EINVAL; /* only used if we fail.. */
55509 if (reclen > buf->count)
55510 return -EINVAL;
55511+
55512+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55513+ return 0;
55514+
55515 dirent = buf->previous;
55516 if (dirent) {
55517 if (__put_user(offset, &dirent->d_off))
55518@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55519
55520 buf.current_dir = dirent;
55521 buf.previous = NULL;
55522+ buf.file = f.file;
55523 buf.count = count;
55524 buf.error = 0;
55525
55526@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55527 error = buf.error;
55528 lastdirent = buf.previous;
55529 if (lastdirent) {
55530- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55531+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55532 if (__put_user(d_off, &lastdirent->d_off))
55533 error = -EFAULT;
55534 else
55535diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55536index 2b7882b..1c5ef48 100644
55537--- a/fs/reiserfs/do_balan.c
55538+++ b/fs/reiserfs/do_balan.c
55539@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55540 return;
55541 }
55542
55543- atomic_inc(&(fs_generation(tb->tb_sb)));
55544+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55545 do_balance_starts(tb);
55546
55547 /* balance leaf returns 0 except if combining L R and S into
55548diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55549index e60e870..f40ac16 100644
55550--- a/fs/reiserfs/procfs.c
55551+++ b/fs/reiserfs/procfs.c
55552@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55553 "SMALL_TAILS " : "NO_TAILS ",
55554 replay_only(sb) ? "REPLAY_ONLY " : "",
55555 convert_reiserfs(sb) ? "CONV " : "",
55556- atomic_read(&r->s_generation_counter),
55557+ atomic_read_unchecked(&r->s_generation_counter),
55558 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55559 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55560 SF(s_good_search_by_key_reada), SF(s_bmaps),
55561diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55562index 157e474..65a6114 100644
55563--- a/fs/reiserfs/reiserfs.h
55564+++ b/fs/reiserfs/reiserfs.h
55565@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55566 /* Comment? -Hans */
55567 wait_queue_head_t s_wait;
55568 /* To be obsoleted soon by per buffer seals.. -Hans */
55569- atomic_t s_generation_counter; // increased by one every time the
55570+ atomic_unchecked_t s_generation_counter; // increased by one every time the
55571 // tree gets re-balanced
55572 unsigned long s_properties; /* File system properties. Currently holds
55573 on-disk FS format */
55574@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55575 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55576
55577 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55578-#define get_generation(s) atomic_read (&fs_generation(s))
55579+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55580 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55581 #define __fs_changed(gen,s) (gen != get_generation (s))
55582 #define fs_changed(gen,s) \
55583diff --git a/fs/select.c b/fs/select.c
55584index 2ef72d9..f213b17 100644
55585--- a/fs/select.c
55586+++ b/fs/select.c
55587@@ -20,6 +20,7 @@
55588 #include <linux/export.h>
55589 #include <linux/slab.h>
55590 #include <linux/poll.h>
55591+#include <linux/security.h>
55592 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55593 #include <linux/file.h>
55594 #include <linux/fdtable.h>
55595@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55596 struct poll_list *walk = head;
55597 unsigned long todo = nfds;
55598
55599+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55600 if (nfds > rlimit(RLIMIT_NOFILE))
55601 return -EINVAL;
55602
55603diff --git a/fs/seq_file.c b/fs/seq_file.c
55604index f2bc3df..239d4f6 100644
55605--- a/fs/seq_file.c
55606+++ b/fs/seq_file.c
55607@@ -10,6 +10,7 @@
55608 #include <linux/seq_file.h>
55609 #include <linux/slab.h>
55610 #include <linux/cred.h>
55611+#include <linux/sched.h>
55612
55613 #include <asm/uaccess.h>
55614 #include <asm/page.h>
55615@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55616 #ifdef CONFIG_USER_NS
55617 p->user_ns = file->f_cred->user_ns;
55618 #endif
55619+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55620+ p->exec_id = current->exec_id;
55621+#endif
55622
55623 /*
55624 * Wrappers around seq_open(e.g. swaps_open) need to be
55625@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55626 return 0;
55627 }
55628 if (!m->buf) {
55629- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55630+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55631 if (!m->buf)
55632 return -ENOMEM;
55633 }
55634@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55635 Eoverflow:
55636 m->op->stop(m, p);
55637 kfree(m->buf);
55638- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55639+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55640 return !m->buf ? -ENOMEM : -EAGAIN;
55641 }
55642
55643@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55644
55645 /* grab buffer if we didn't have one */
55646 if (!m->buf) {
55647- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55648+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55649 if (!m->buf)
55650 goto Enomem;
55651 }
55652@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55653 goto Fill;
55654 m->op->stop(m, p);
55655 kfree(m->buf);
55656- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55657+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55658 if (!m->buf)
55659 goto Enomem;
55660 m->count = 0;
55661@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55662 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55663 void *data)
55664 {
55665- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55666+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55667 int res = -ENOMEM;
55668
55669 if (op) {
55670diff --git a/fs/splice.c b/fs/splice.c
55671index 6909d89..5b2e8f9 100644
55672--- a/fs/splice.c
55673+++ b/fs/splice.c
55674@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55675 pipe_lock(pipe);
55676
55677 for (;;) {
55678- if (!pipe->readers) {
55679+ if (!atomic_read(&pipe->readers)) {
55680 send_sig(SIGPIPE, current, 0);
55681 if (!ret)
55682 ret = -EPIPE;
55683@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55684 do_wakeup = 0;
55685 }
55686
55687- pipe->waiting_writers++;
55688+ atomic_inc(&pipe->waiting_writers);
55689 pipe_wait(pipe);
55690- pipe->waiting_writers--;
55691+ atomic_dec(&pipe->waiting_writers);
55692 }
55693
55694 pipe_unlock(pipe);
55695@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55696 old_fs = get_fs();
55697 set_fs(get_ds());
55698 /* The cast to a user pointer is valid due to the set_fs() */
55699- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55700+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55701 set_fs(old_fs);
55702
55703 return res;
55704@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55705 old_fs = get_fs();
55706 set_fs(get_ds());
55707 /* The cast to a user pointer is valid due to the set_fs() */
55708- res = vfs_write(file, (const char __user *)buf, count, &pos);
55709+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55710 set_fs(old_fs);
55711
55712 return res;
55713@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55714 goto err;
55715
55716 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55717- vec[i].iov_base = (void __user *) page_address(page);
55718+ vec[i].iov_base = (void __force_user *) page_address(page);
55719 vec[i].iov_len = this_len;
55720 spd.pages[i] = page;
55721 spd.nr_pages++;
55722@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55723 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55724 {
55725 while (!pipe->nrbufs) {
55726- if (!pipe->writers)
55727+ if (!atomic_read(&pipe->writers))
55728 return 0;
55729
55730- if (!pipe->waiting_writers && sd->num_spliced)
55731+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55732 return 0;
55733
55734 if (sd->flags & SPLICE_F_NONBLOCK)
55735@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55736 * out of the pipe right after the splice_to_pipe(). So set
55737 * PIPE_READERS appropriately.
55738 */
55739- pipe->readers = 1;
55740+ atomic_set(&pipe->readers, 1);
55741
55742 current->splice_pipe = pipe;
55743 }
55744@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55745 ret = -ERESTARTSYS;
55746 break;
55747 }
55748- if (!pipe->writers)
55749+ if (!atomic_read(&pipe->writers))
55750 break;
55751- if (!pipe->waiting_writers) {
55752+ if (!atomic_read(&pipe->waiting_writers)) {
55753 if (flags & SPLICE_F_NONBLOCK) {
55754 ret = -EAGAIN;
55755 break;
55756@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55757 pipe_lock(pipe);
55758
55759 while (pipe->nrbufs >= pipe->buffers) {
55760- if (!pipe->readers) {
55761+ if (!atomic_read(&pipe->readers)) {
55762 send_sig(SIGPIPE, current, 0);
55763 ret = -EPIPE;
55764 break;
55765@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55766 ret = -ERESTARTSYS;
55767 break;
55768 }
55769- pipe->waiting_writers++;
55770+ atomic_inc(&pipe->waiting_writers);
55771 pipe_wait(pipe);
55772- pipe->waiting_writers--;
55773+ atomic_dec(&pipe->waiting_writers);
55774 }
55775
55776 pipe_unlock(pipe);
55777@@ -1823,14 +1823,14 @@ retry:
55778 pipe_double_lock(ipipe, opipe);
55779
55780 do {
55781- if (!opipe->readers) {
55782+ if (!atomic_read(&opipe->readers)) {
55783 send_sig(SIGPIPE, current, 0);
55784 if (!ret)
55785 ret = -EPIPE;
55786 break;
55787 }
55788
55789- if (!ipipe->nrbufs && !ipipe->writers)
55790+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55791 break;
55792
55793 /*
55794@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55795 pipe_double_lock(ipipe, opipe);
55796
55797 do {
55798- if (!opipe->readers) {
55799+ if (!atomic_read(&opipe->readers)) {
55800 send_sig(SIGPIPE, current, 0);
55801 if (!ret)
55802 ret = -EPIPE;
55803@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55804 * return EAGAIN if we have the potential of some data in the
55805 * future, otherwise just return 0
55806 */
55807- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55808+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55809 ret = -EAGAIN;
55810
55811 pipe_unlock(ipipe);
55812diff --git a/fs/stat.c b/fs/stat.c
55813index 14f4545..9b7f55b 100644
55814--- a/fs/stat.c
55815+++ b/fs/stat.c
55816@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55817 stat->gid = inode->i_gid;
55818 stat->rdev = inode->i_rdev;
55819 stat->size = i_size_read(inode);
55820- stat->atime = inode->i_atime;
55821- stat->mtime = inode->i_mtime;
55822+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55823+ stat->atime = inode->i_ctime;
55824+ stat->mtime = inode->i_ctime;
55825+ } else {
55826+ stat->atime = inode->i_atime;
55827+ stat->mtime = inode->i_mtime;
55828+ }
55829 stat->ctime = inode->i_ctime;
55830 stat->blksize = (1 << inode->i_blkbits);
55831 stat->blocks = inode->i_blocks;
55832@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55833 if (retval)
55834 return retval;
55835
55836- if (inode->i_op->getattr)
55837- return inode->i_op->getattr(mnt, dentry, stat);
55838+ if (inode->i_op->getattr) {
55839+ retval = inode->i_op->getattr(mnt, dentry, stat);
55840+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55841+ stat->atime = stat->ctime;
55842+ stat->mtime = stat->ctime;
55843+ }
55844+ return retval;
55845+ }
55846
55847 generic_fillattr(inode, stat);
55848 return 0;
55849diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55850index 2fbdff6..5530a61 100644
55851--- a/fs/sysfs/dir.c
55852+++ b/fs/sysfs/dir.c
55853@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55854 struct sysfs_dirent *sd;
55855 int rc;
55856
55857+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55858+ const char *parent_name = parent_sd->s_name;
55859+
55860+ mode = S_IFDIR | S_IRWXU;
55861+
55862+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55863+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55864+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55865+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55866+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55867+#endif
55868+
55869 /* allocate */
55870 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55871 if (!sd)
55872diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55873index 602f56d..6853db8 100644
55874--- a/fs/sysfs/file.c
55875+++ b/fs/sysfs/file.c
55876@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55877
55878 struct sysfs_open_dirent {
55879 atomic_t refcnt;
55880- atomic_t event;
55881+ atomic_unchecked_t event;
55882 wait_queue_head_t poll;
55883 struct list_head buffers; /* goes through sysfs_buffer.list */
55884 };
55885@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55886 if (!sysfs_get_active(attr_sd))
55887 return -ENODEV;
55888
55889- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55890+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55891 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55892
55893 sysfs_put_active(attr_sd);
55894@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55895 return -ENOMEM;
55896
55897 atomic_set(&new_od->refcnt, 0);
55898- atomic_set(&new_od->event, 1);
55899+ atomic_set_unchecked(&new_od->event, 1);
55900 init_waitqueue_head(&new_od->poll);
55901 INIT_LIST_HEAD(&new_od->buffers);
55902 goto retry;
55903@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55904
55905 sysfs_put_active(attr_sd);
55906
55907- if (buffer->event != atomic_read(&od->event))
55908+ if (buffer->event != atomic_read_unchecked(&od->event))
55909 goto trigger;
55910
55911 return DEFAULT_POLLMASK;
55912@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55913
55914 od = sd->s_attr.open;
55915 if (od) {
55916- atomic_inc(&od->event);
55917+ atomic_inc_unchecked(&od->event);
55918 wake_up_interruptible(&od->poll);
55919 }
55920
55921diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55922index 3c9eb56..9dea5be 100644
55923--- a/fs/sysfs/symlink.c
55924+++ b/fs/sysfs/symlink.c
55925@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55926
55927 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55928 {
55929- char *page = nd_get_link(nd);
55930+ const char *page = nd_get_link(nd);
55931 if (!IS_ERR(page))
55932 free_page((unsigned long)page);
55933 }
55934diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
55935index 69d4889..a810bd4 100644
55936--- a/fs/sysv/sysv.h
55937+++ b/fs/sysv/sysv.h
55938@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
55939 #endif
55940 }
55941
55942-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
55943+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
55944 {
55945 if (sbi->s_bytesex == BYTESEX_PDP)
55946 return PDP_swab((__force __u32)n);
55947diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
55948index e18b988..f1d4ad0f 100644
55949--- a/fs/ubifs/io.c
55950+++ b/fs/ubifs/io.c
55951@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
55952 return err;
55953 }
55954
55955-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
55956+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
55957 {
55958 int err;
55959
55960diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55961index c175b4d..8f36a16 100644
55962--- a/fs/udf/misc.c
55963+++ b/fs/udf/misc.c
55964@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55965
55966 u8 udf_tag_checksum(const struct tag *t)
55967 {
55968- u8 *data = (u8 *)t;
55969+ const u8 *data = (const u8 *)t;
55970 u8 checksum = 0;
55971 int i;
55972 for (i = 0; i < sizeof(struct tag); ++i)
55973diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
55974index 8d974c4..b82f6ec 100644
55975--- a/fs/ufs/swab.h
55976+++ b/fs/ufs/swab.h
55977@@ -22,7 +22,7 @@ enum {
55978 BYTESEX_BE
55979 };
55980
55981-static inline u64
55982+static inline u64 __intentional_overflow(-1)
55983 fs64_to_cpu(struct super_block *sbp, __fs64 n)
55984 {
55985 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
55986@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
55987 return (__force __fs64)cpu_to_be64(n);
55988 }
55989
55990-static inline u32
55991+static inline u32 __intentional_overflow(-1)
55992 fs32_to_cpu(struct super_block *sbp, __fs32 n)
55993 {
55994 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
55995diff --git a/fs/utimes.c b/fs/utimes.c
55996index f4fb7ec..3fe03c0 100644
55997--- a/fs/utimes.c
55998+++ b/fs/utimes.c
55999@@ -1,6 +1,7 @@
56000 #include <linux/compiler.h>
56001 #include <linux/file.h>
56002 #include <linux/fs.h>
56003+#include <linux/security.h>
56004 #include <linux/linkage.h>
56005 #include <linux/mount.h>
56006 #include <linux/namei.h>
56007@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56008 goto mnt_drop_write_and_out;
56009 }
56010 }
56011+
56012+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56013+ error = -EACCES;
56014+ goto mnt_drop_write_and_out;
56015+ }
56016+
56017 mutex_lock(&inode->i_mutex);
56018 error = notify_change(path->dentry, &newattrs);
56019 mutex_unlock(&inode->i_mutex);
56020diff --git a/fs/xattr.c b/fs/xattr.c
56021index 3377dff..4feded6 100644
56022--- a/fs/xattr.c
56023+++ b/fs/xattr.c
56024@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56025 * Extended attribute SET operations
56026 */
56027 static long
56028-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56029+setxattr(struct path *path, const char __user *name, const void __user *value,
56030 size_t size, int flags)
56031 {
56032 int error;
56033@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56034 posix_acl_fix_xattr_from_user(kvalue, size);
56035 }
56036
56037- error = vfs_setxattr(d, kname, kvalue, size, flags);
56038+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56039+ error = -EACCES;
56040+ goto out;
56041+ }
56042+
56043+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56044 out:
56045 if (vvalue)
56046 vfree(vvalue);
56047@@ -377,7 +382,7 @@ retry:
56048 return error;
56049 error = mnt_want_write(path.mnt);
56050 if (!error) {
56051- error = setxattr(path.dentry, name, value, size, flags);
56052+ error = setxattr(&path, name, value, size, flags);
56053 mnt_drop_write(path.mnt);
56054 }
56055 path_put(&path);
56056@@ -401,7 +406,7 @@ retry:
56057 return error;
56058 error = mnt_want_write(path.mnt);
56059 if (!error) {
56060- error = setxattr(path.dentry, name, value, size, flags);
56061+ error = setxattr(&path, name, value, size, flags);
56062 mnt_drop_write(path.mnt);
56063 }
56064 path_put(&path);
56065@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56066 const void __user *,value, size_t, size, int, flags)
56067 {
56068 struct fd f = fdget(fd);
56069- struct dentry *dentry;
56070 int error = -EBADF;
56071
56072 if (!f.file)
56073 return error;
56074- dentry = f.file->f_path.dentry;
56075- audit_inode(NULL, dentry, 0);
56076+ audit_inode(NULL, f.file->f_path.dentry, 0);
56077 error = mnt_want_write_file(f.file);
56078 if (!error) {
56079- error = setxattr(dentry, name, value, size, flags);
56080+ error = setxattr(&f.file->f_path, name, value, size, flags);
56081 mnt_drop_write_file(f.file);
56082 }
56083 fdput(f);
56084diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56085index 9fbea87..6b19972 100644
56086--- a/fs/xattr_acl.c
56087+++ b/fs/xattr_acl.c
56088@@ -76,8 +76,8 @@ struct posix_acl *
56089 posix_acl_from_xattr(struct user_namespace *user_ns,
56090 const void *value, size_t size)
56091 {
56092- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
56093- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
56094+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
56095+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
56096 int count;
56097 struct posix_acl *acl;
56098 struct posix_acl_entry *acl_e;
56099diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
56100index 572a858..12a9b0d 100644
56101--- a/fs/xfs/xfs_bmap.c
56102+++ b/fs/xfs/xfs_bmap.c
56103@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
56104 int nmap,
56105 int ret_nmap);
56106 #else
56107-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
56108+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
56109 #endif /* DEBUG */
56110
56111 STATIC int
56112diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
56113index 1b9fc3e..e1bdde0 100644
56114--- a/fs/xfs/xfs_dir2_sf.c
56115+++ b/fs/xfs/xfs_dir2_sf.c
56116@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
56117 }
56118
56119 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
56120- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56121+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
56122+ char name[sfep->namelen];
56123+ memcpy(name, sfep->name, sfep->namelen);
56124+ if (filldir(dirent, name, sfep->namelen,
56125+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
56126+ *offset = off & 0x7fffffff;
56127+ return 0;
56128+ }
56129+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56130 off & 0x7fffffff, ino, DT_UNKNOWN)) {
56131 *offset = off & 0x7fffffff;
56132 return 0;
56133diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
56134index c1c3ef8..0952438 100644
56135--- a/fs/xfs/xfs_ioctl.c
56136+++ b/fs/xfs/xfs_ioctl.c
56137@@ -127,7 +127,7 @@ xfs_find_handle(
56138 }
56139
56140 error = -EFAULT;
56141- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
56142+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
56143 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
56144 goto out_put;
56145
56146diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
56147index d82efaa..0904a8e 100644
56148--- a/fs/xfs/xfs_iops.c
56149+++ b/fs/xfs/xfs_iops.c
56150@@ -395,7 +395,7 @@ xfs_vn_put_link(
56151 struct nameidata *nd,
56152 void *p)
56153 {
56154- char *s = nd_get_link(nd);
56155+ const char *s = nd_get_link(nd);
56156
56157 if (!IS_ERR(s))
56158 kfree(s);
56159diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
56160new file mode 100644
56161index 0000000..92247e4
56162--- /dev/null
56163+++ b/grsecurity/Kconfig
56164@@ -0,0 +1,1021 @@
56165+#
56166+# grecurity configuration
56167+#
56168+menu "Memory Protections"
56169+depends on GRKERNSEC
56170+
56171+config GRKERNSEC_KMEM
56172+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
56173+ default y if GRKERNSEC_CONFIG_AUTO
56174+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
56175+ help
56176+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
56177+ be written to or read from to modify or leak the contents of the running
56178+ kernel. /dev/port will also not be allowed to be opened and support
56179+ for /dev/cpu/*/msr will be removed. If you have module
56180+ support disabled, enabling this will close up five ways that are
56181+ currently used to insert malicious code into the running kernel.
56182+
56183+ Even with all these features enabled, we still highly recommend that
56184+ you use the RBAC system, as it is still possible for an attacker to
56185+ modify the running kernel through privileged I/O granted by ioperm/iopl.
56186+
56187+ If you are not using XFree86, you may be able to stop this additional
56188+ case by enabling the 'Disable privileged I/O' option. Though nothing
56189+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
56190+ but only to video memory, which is the only writing we allow in this
56191+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
56192+ not be allowed to mprotect it with PROT_WRITE later.
56193+ Enabling this feature will prevent the "cpupower" and "powertop" tools
56194+ from working.
56195+
56196+ It is highly recommended that you say Y here if you meet all the
56197+ conditions above.
56198+
56199+config GRKERNSEC_VM86
56200+ bool "Restrict VM86 mode"
56201+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56202+ depends on X86_32
56203+
56204+ help
56205+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
56206+ make use of a special execution mode on 32bit x86 processors called
56207+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
56208+ video cards and will still work with this option enabled. The purpose
56209+ of the option is to prevent exploitation of emulation errors in
56210+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
56211+ Nearly all users should be able to enable this option.
56212+
56213+config GRKERNSEC_IO
56214+ bool "Disable privileged I/O"
56215+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56216+ depends on X86
56217+ select RTC_CLASS
56218+ select RTC_INTF_DEV
56219+ select RTC_DRV_CMOS
56220+
56221+ help
56222+ If you say Y here, all ioperm and iopl calls will return an error.
56223+ Ioperm and iopl can be used to modify the running kernel.
56224+ Unfortunately, some programs need this access to operate properly,
56225+ the most notable of which are XFree86 and hwclock. hwclock can be
56226+ remedied by having RTC support in the kernel, so real-time
56227+ clock support is enabled if this option is enabled, to ensure
56228+ that hwclock operates correctly. XFree86 still will not
56229+ operate correctly with this option enabled, so DO NOT CHOOSE Y
56230+ IF YOU USE XFree86. If you use XFree86 and you still want to
56231+ protect your kernel against modification, use the RBAC system.
56232+
56233+config GRKERNSEC_JIT_HARDEN
56234+ bool "Harden BPF JIT against spray attacks"
56235+ default y if GRKERNSEC_CONFIG_AUTO
56236+ depends on BPF_JIT
56237+ help
56238+ If you say Y here, the native code generated by the kernel's Berkeley
56239+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
56240+ attacks that attempt to fit attacker-beneficial instructions in
56241+ 32bit immediate fields of JIT-generated native instructions. The
56242+ attacker will generally aim to cause an unintended instruction sequence
56243+ of JIT-generated native code to execute by jumping into the middle of
56244+ a generated instruction. This feature effectively randomizes the 32bit
56245+ immediate constants present in the generated code to thwart such attacks.
56246+
56247+ If you're using KERNEXEC, it's recommended that you enable this option
56248+ to supplement the hardening of the kernel.
56249+
56250+config GRKERNSEC_RAND_THREADSTACK
56251+ bool "Insert random gaps between thread stacks"
56252+ default y if GRKERNSEC_CONFIG_AUTO
56253+ depends on PAX_RANDMMAP && !PPC
56254+ help
56255+ If you say Y here, a random-sized gap will be enforced between allocated
56256+ thread stacks. Glibc's NPTL and other threading libraries that
56257+ pass MAP_STACK to the kernel for thread stack allocation are supported.
56258+ The implementation currently provides 8 bits of entropy for the gap.
56259+
56260+ Many distributions do not compile threaded remote services with the
56261+ -fstack-check argument to GCC, causing the variable-sized stack-based
56262+ allocator, alloca(), to not probe the stack on allocation. This
56263+ permits an unbounded alloca() to skip over any guard page and potentially
56264+ modify another thread's stack reliably. An enforced random gap
56265+ reduces the reliability of such an attack and increases the chance
56266+ that such a read/write to another thread's stack instead lands in
56267+ an unmapped area, causing a crash and triggering grsecurity's
56268+ anti-bruteforcing logic.
56269+
56270+config GRKERNSEC_PROC_MEMMAP
56271+ bool "Harden ASLR against information leaks and entropy reduction"
56272+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
56273+ depends on PAX_NOEXEC || PAX_ASLR
56274+ help
56275+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
56276+ give no information about the addresses of its mappings if
56277+ PaX features that rely on random addresses are enabled on the task.
56278+ In addition to sanitizing this information and disabling other
56279+ dangerous sources of information, this option causes reads of sensitive
56280+ /proc/<pid> entries where the file descriptor was opened in a different
56281+ task than the one performing the read. Such attempts are logged.
56282+ This option also limits argv/env strings for suid/sgid binaries
56283+ to 512KB to prevent a complete exhaustion of the stack entropy provided
56284+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
56285+ binaries to prevent alternative mmap layouts from being abused.
56286+
56287+ If you use PaX it is essential that you say Y here as it closes up
56288+ several holes that make full ASLR useless locally.
56289+
56290+config GRKERNSEC_BRUTE
56291+ bool "Deter exploit bruteforcing"
56292+ default y if GRKERNSEC_CONFIG_AUTO
56293+ help
56294+ If you say Y here, attempts to bruteforce exploits against forking
56295+ daemons such as apache or sshd, as well as against suid/sgid binaries
56296+ will be deterred. When a child of a forking daemon is killed by PaX
56297+ or crashes due to an illegal instruction or other suspicious signal,
56298+ the parent process will be delayed 30 seconds upon every subsequent
56299+ fork until the administrator is able to assess the situation and
56300+ restart the daemon.
56301+ In the suid/sgid case, the attempt is logged, the user has all their
56302+ processes terminated, and they are prevented from executing any further
56303+ processes for 15 minutes.
56304+ It is recommended that you also enable signal logging in the auditing
56305+ section so that logs are generated when a process triggers a suspicious
56306+ signal.
56307+ If the sysctl option is enabled, a sysctl option with name
56308+ "deter_bruteforce" is created.
56309+
56310+
56311+config GRKERNSEC_MODHARDEN
56312+ bool "Harden module auto-loading"
56313+ default y if GRKERNSEC_CONFIG_AUTO
56314+ depends on MODULES
56315+ help
56316+ If you say Y here, module auto-loading in response to use of some
56317+ feature implemented by an unloaded module will be restricted to
56318+ root users. Enabling this option helps defend against attacks
56319+ by unprivileged users who abuse the auto-loading behavior to
56320+ cause a vulnerable module to load that is then exploited.
56321+
56322+ If this option prevents a legitimate use of auto-loading for a
56323+ non-root user, the administrator can execute modprobe manually
56324+ with the exact name of the module mentioned in the alert log.
56325+ Alternatively, the administrator can add the module to the list
56326+ of modules loaded at boot by modifying init scripts.
56327+
56328+ Modification of init scripts will most likely be needed on
56329+ Ubuntu servers with encrypted home directory support enabled,
56330+ as the first non-root user logging in will cause the ecb(aes),
56331+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
56332+
56333+config GRKERNSEC_HIDESYM
56334+ bool "Hide kernel symbols"
56335+ default y if GRKERNSEC_CONFIG_AUTO
56336+ select PAX_USERCOPY_SLABS
56337+ help
56338+ If you say Y here, getting information on loaded modules, and
56339+ displaying all kernel symbols through a syscall will be restricted
56340+ to users with CAP_SYS_MODULE. For software compatibility reasons,
56341+ /proc/kallsyms will be restricted to the root user. The RBAC
56342+ system can hide that entry even from root.
56343+
56344+ This option also prevents leaking of kernel addresses through
56345+ several /proc entries.
56346+
56347+ Note that this option is only effective provided the following
56348+ conditions are met:
56349+ 1) The kernel using grsecurity is not precompiled by some distribution
56350+ 2) You have also enabled GRKERNSEC_DMESG
56351+ 3) You are using the RBAC system and hiding other files such as your
56352+ kernel image and System.map. Alternatively, enabling this option
56353+ causes the permissions on /boot, /lib/modules, and the kernel
56354+ source directory to change at compile time to prevent
56355+ reading by non-root users.
56356+ If the above conditions are met, this option will aid in providing a
56357+ useful protection against local kernel exploitation of overflows
56358+ and arbitrary read/write vulnerabilities.
56359+
56360+config GRKERNSEC_KERN_LOCKOUT
56361+ bool "Active kernel exploit response"
56362+ default y if GRKERNSEC_CONFIG_AUTO
56363+ depends on X86 || ARM || PPC || SPARC
56364+ help
56365+ If you say Y here, when a PaX alert is triggered due to suspicious
56366+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
56367+ or an OOPS occurs due to bad memory accesses, instead of just
56368+ terminating the offending process (and potentially allowing
56369+ a subsequent exploit from the same user), we will take one of two
56370+ actions:
56371+ If the user was root, we will panic the system
56372+ If the user was non-root, we will log the attempt, terminate
56373+ all processes owned by the user, then prevent them from creating
56374+ any new processes until the system is restarted
56375+ This deters repeated kernel exploitation/bruteforcing attempts
56376+ and is useful for later forensics.
56377+
56378+endmenu
56379+menu "Role Based Access Control Options"
56380+depends on GRKERNSEC
56381+
56382+config GRKERNSEC_RBAC_DEBUG
56383+ bool
56384+
56385+config GRKERNSEC_NO_RBAC
56386+ bool "Disable RBAC system"
56387+ help
56388+ If you say Y here, the /dev/grsec device will be removed from the kernel,
56389+ preventing the RBAC system from being enabled. You should only say Y
56390+ here if you have no intention of using the RBAC system, so as to prevent
56391+ an attacker with root access from misusing the RBAC system to hide files
56392+ and processes when loadable module support and /dev/[k]mem have been
56393+ locked down.
56394+
56395+config GRKERNSEC_ACL_HIDEKERN
56396+ bool "Hide kernel processes"
56397+ help
56398+ If you say Y here, all kernel threads will be hidden to all
56399+ processes but those whose subject has the "view hidden processes"
56400+ flag.
56401+
56402+config GRKERNSEC_ACL_MAXTRIES
56403+ int "Maximum tries before password lockout"
56404+ default 3
56405+ help
56406+ This option enforces the maximum number of times a user can attempt
56407+ to authorize themselves with the grsecurity RBAC system before being
56408+ denied the ability to attempt authorization again for a specified time.
56409+ The lower the number, the harder it will be to brute-force a password.
56410+
56411+config GRKERNSEC_ACL_TIMEOUT
56412+ int "Time to wait after max password tries, in seconds"
56413+ default 30
56414+ help
56415+ This option specifies the time the user must wait after attempting to
56416+ authorize to the RBAC system with the maximum number of invalid
56417+ passwords. The higher the number, the harder it will be to brute-force
56418+ a password.
56419+
56420+endmenu
56421+menu "Filesystem Protections"
56422+depends on GRKERNSEC
56423+
56424+config GRKERNSEC_PROC
56425+ bool "Proc restrictions"
56426+ default y if GRKERNSEC_CONFIG_AUTO
56427+ help
56428+ If you say Y here, the permissions of the /proc filesystem
56429+ will be altered to enhance system security and privacy. You MUST
56430+ choose either a user only restriction or a user and group restriction.
56431+ Depending upon the option you choose, you can either restrict users to
56432+ see only the processes they themselves run, or choose a group that can
56433+ view all processes and files normally restricted to root if you choose
56434+ the "restrict to user only" option. NOTE: If you're running identd or
56435+ ntpd as a non-root user, you will have to run it as the group you
56436+ specify here.
56437+
56438+config GRKERNSEC_PROC_USER
56439+ bool "Restrict /proc to user only"
56440+ depends on GRKERNSEC_PROC
56441+ help
56442+ If you say Y here, non-root users will only be able to view their own
56443+ processes, and restricts them from viewing network-related information,
56444+ and viewing kernel symbol and module information.
56445+
56446+config GRKERNSEC_PROC_USERGROUP
56447+ bool "Allow special group"
56448+ default y if GRKERNSEC_CONFIG_AUTO
56449+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56450+ help
56451+ If you say Y here, you will be able to select a group that will be
56452+ able to view all processes and network-related information. If you've
56453+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56454+ remain hidden. This option is useful if you want to run identd as
56455+ a non-root user. The group you select may also be chosen at boot time
56456+ via "grsec_proc_gid=" on the kernel commandline.
56457+
56458+config GRKERNSEC_PROC_GID
56459+ int "GID for special group"
56460+ depends on GRKERNSEC_PROC_USERGROUP
56461+ default 1001
56462+
56463+config GRKERNSEC_PROC_ADD
56464+ bool "Additional restrictions"
56465+ default y if GRKERNSEC_CONFIG_AUTO
56466+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56467+ help
56468+ If you say Y here, additional restrictions will be placed on
56469+ /proc that keep normal users from viewing device information and
56470+ slabinfo information that could be useful for exploits.
56471+
56472+config GRKERNSEC_LINK
56473+ bool "Linking restrictions"
56474+ default y if GRKERNSEC_CONFIG_AUTO
56475+ help
56476+ If you say Y here, /tmp race exploits will be prevented, since users
56477+ will no longer be able to follow symlinks owned by other users in
56478+ world-writable +t directories (e.g. /tmp), unless the owner of the
56479+ symlink is the owner of the directory. users will also not be
56480+ able to hardlink to files they do not own. If the sysctl option is
56481+ enabled, a sysctl option with name "linking_restrictions" is created.
56482+
56483+config GRKERNSEC_SYMLINKOWN
56484+ bool "Kernel-enforced SymlinksIfOwnerMatch"
56485+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56486+ help
56487+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
56488+ that prevents it from being used as a security feature. As Apache
56489+ verifies the symlink by performing a stat() against the target of
56490+ the symlink before it is followed, an attacker can setup a symlink
56491+ to point to a same-owned file, then replace the symlink with one
56492+ that targets another user's file just after Apache "validates" the
56493+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
56494+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56495+ will be in place for the group you specify. If the sysctl option
56496+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
56497+ created.
56498+
56499+config GRKERNSEC_SYMLINKOWN_GID
56500+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56501+ depends on GRKERNSEC_SYMLINKOWN
56502+ default 1006
56503+ help
56504+ Setting this GID determines what group kernel-enforced
56505+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56506+ is enabled, a sysctl option with name "symlinkown_gid" is created.
56507+
56508+config GRKERNSEC_FIFO
56509+ bool "FIFO restrictions"
56510+ default y if GRKERNSEC_CONFIG_AUTO
56511+ help
56512+ If you say Y here, users will not be able to write to FIFOs they don't
56513+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56514+ the FIFO is the same owner of the directory it's held in. If the sysctl
56515+ option is enabled, a sysctl option with name "fifo_restrictions" is
56516+ created.
56517+
56518+config GRKERNSEC_SYSFS_RESTRICT
56519+ bool "Sysfs/debugfs restriction"
56520+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56521+ depends on SYSFS
56522+ help
56523+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56524+ any filesystem normally mounted under it (e.g. debugfs) will be
56525+ mostly accessible only by root. These filesystems generally provide access
56526+ to hardware and debug information that isn't appropriate for unprivileged
56527+ users of the system. Sysfs and debugfs have also become a large source
56528+ of new vulnerabilities, ranging from infoleaks to local compromise.
56529+ There has been very little oversight with an eye toward security involved
56530+ in adding new exporters of information to these filesystems, so their
56531+ use is discouraged.
56532+ For reasons of compatibility, a few directories have been whitelisted
56533+ for access by non-root users:
56534+ /sys/fs/selinux
56535+ /sys/fs/fuse
56536+ /sys/devices/system/cpu
56537+
56538+config GRKERNSEC_ROFS
56539+ bool "Runtime read-only mount protection"
56540+ help
56541+ If you say Y here, a sysctl option with name "romount_protect" will
56542+ be created. By setting this option to 1 at runtime, filesystems
56543+ will be protected in the following ways:
56544+ * No new writable mounts will be allowed
56545+ * Existing read-only mounts won't be able to be remounted read/write
56546+ * Write operations will be denied on all block devices
56547+ This option acts independently of grsec_lock: once it is set to 1,
56548+ it cannot be turned off. Therefore, please be mindful of the resulting
56549+ behavior if this option is enabled in an init script on a read-only
56550+ filesystem. This feature is mainly intended for secure embedded systems.
56551+
56552+config GRKERNSEC_DEVICE_SIDECHANNEL
56553+ bool "Eliminate stat/notify-based device sidechannels"
56554+ default y if GRKERNSEC_CONFIG_AUTO
56555+ help
56556+ If you say Y here, timing analyses on block or character
56557+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56558+ will be thwarted for unprivileged users. If a process without
56559+ CAP_MKNOD stats such a device, the last access and last modify times
56560+ will match the device's create time. No access or modify events
56561+ will be triggered through inotify/dnotify/fanotify for such devices.
56562+ This feature will prevent attacks that may at a minimum
56563+ allow an attacker to determine the administrator's password length.
56564+
56565+config GRKERNSEC_CHROOT
56566+ bool "Chroot jail restrictions"
56567+ default y if GRKERNSEC_CONFIG_AUTO
56568+ help
56569+ If you say Y here, you will be able to choose several options that will
56570+ make breaking out of a chrooted jail much more difficult. If you
56571+ encounter no software incompatibilities with the following options, it
56572+ is recommended that you enable each one.
56573+
56574+config GRKERNSEC_CHROOT_MOUNT
56575+ bool "Deny mounts"
56576+ default y if GRKERNSEC_CONFIG_AUTO
56577+ depends on GRKERNSEC_CHROOT
56578+ help
56579+ If you say Y here, processes inside a chroot will not be able to
56580+ mount or remount filesystems. If the sysctl option is enabled, a
56581+ sysctl option with name "chroot_deny_mount" is created.
56582+
56583+config GRKERNSEC_CHROOT_DOUBLE
56584+ bool "Deny double-chroots"
56585+ default y if GRKERNSEC_CONFIG_AUTO
56586+ depends on GRKERNSEC_CHROOT
56587+ help
56588+ If you say Y here, processes inside a chroot will not be able to chroot
56589+ again outside the chroot. This is a widely used method of breaking
56590+ out of a chroot jail and should not be allowed. If the sysctl
56591+ option is enabled, a sysctl option with name
56592+ "chroot_deny_chroot" is created.
56593+
56594+config GRKERNSEC_CHROOT_PIVOT
56595+ bool "Deny pivot_root in chroot"
56596+ default y if GRKERNSEC_CONFIG_AUTO
56597+ depends on GRKERNSEC_CHROOT
56598+ help
56599+ If you say Y here, processes inside a chroot will not be able to use
56600+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56601+ works similar to chroot in that it changes the root filesystem. This
56602+ function could be misused in a chrooted process to attempt to break out
56603+ of the chroot, and therefore should not be allowed. If the sysctl
56604+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56605+ created.
56606+
56607+config GRKERNSEC_CHROOT_CHDIR
56608+ bool "Enforce chdir(\"/\") on all chroots"
56609+ default y if GRKERNSEC_CONFIG_AUTO
56610+ depends on GRKERNSEC_CHROOT
56611+ help
56612+ If you say Y here, the current working directory of all newly-chrooted
56613+ applications will be set to the the root directory of the chroot.
56614+ The man page on chroot(2) states:
56615+ Note that this call does not change the current working
56616+ directory, so that `.' can be outside the tree rooted at
56617+ `/'. In particular, the super-user can escape from a
56618+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56619+
56620+ It is recommended that you say Y here, since it's not known to break
56621+ any software. If the sysctl option is enabled, a sysctl option with
56622+ name "chroot_enforce_chdir" is created.
56623+
56624+config GRKERNSEC_CHROOT_CHMOD
56625+ bool "Deny (f)chmod +s"
56626+ default y if GRKERNSEC_CONFIG_AUTO
56627+ depends on GRKERNSEC_CHROOT
56628+ help
56629+ If you say Y here, processes inside a chroot will not be able to chmod
56630+ or fchmod files to make them have suid or sgid bits. This protects
56631+ against another published method of breaking a chroot. If the sysctl
56632+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56633+ created.
56634+
56635+config GRKERNSEC_CHROOT_FCHDIR
56636+ bool "Deny fchdir out of chroot"
56637+ default y if GRKERNSEC_CONFIG_AUTO
56638+ depends on GRKERNSEC_CHROOT
56639+ help
56640+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56641+ to a file descriptor of the chrooting process that points to a directory
56642+ outside the filesystem will be stopped. If the sysctl option
56643+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56644+
56645+config GRKERNSEC_CHROOT_MKNOD
56646+ bool "Deny mknod"
56647+ default y if GRKERNSEC_CONFIG_AUTO
56648+ depends on GRKERNSEC_CHROOT
56649+ help
56650+ If you say Y here, processes inside a chroot will not be allowed to
56651+ mknod. The problem with using mknod inside a chroot is that it
56652+ would allow an attacker to create a device entry that is the same
56653+ as one on the physical root of your system, which could range from
56654+ anything from the console device to a device for your harddrive (which
56655+ they could then use to wipe the drive or steal data). It is recommended
56656+ that you say Y here, unless you run into software incompatibilities.
56657+ If the sysctl option is enabled, a sysctl option with name
56658+ "chroot_deny_mknod" is created.
56659+
56660+config GRKERNSEC_CHROOT_SHMAT
56661+ bool "Deny shmat() out of chroot"
56662+ default y if GRKERNSEC_CONFIG_AUTO
56663+ depends on GRKERNSEC_CHROOT
56664+ help
56665+ If you say Y here, processes inside a chroot will not be able to attach
56666+ to shared memory segments that were created outside of the chroot jail.
56667+ It is recommended that you say Y here. If the sysctl option is enabled,
56668+ a sysctl option with name "chroot_deny_shmat" is created.
56669+
56670+config GRKERNSEC_CHROOT_UNIX
56671+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
56672+ default y if GRKERNSEC_CONFIG_AUTO
56673+ depends on GRKERNSEC_CHROOT
56674+ help
56675+ If you say Y here, processes inside a chroot will not be able to
56676+ connect to abstract (meaning not belonging to a filesystem) Unix
56677+ domain sockets that were bound outside of a chroot. It is recommended
56678+ that you say Y here. If the sysctl option is enabled, a sysctl option
56679+ with name "chroot_deny_unix" is created.
56680+
56681+config GRKERNSEC_CHROOT_FINDTASK
56682+ bool "Protect outside processes"
56683+ default y if GRKERNSEC_CONFIG_AUTO
56684+ depends on GRKERNSEC_CHROOT
56685+ help
56686+ If you say Y here, processes inside a chroot will not be able to
56687+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56688+ getsid, or view any process outside of the chroot. If the sysctl
56689+ option is enabled, a sysctl option with name "chroot_findtask" is
56690+ created.
56691+
56692+config GRKERNSEC_CHROOT_NICE
56693+ bool "Restrict priority changes"
56694+ default y if GRKERNSEC_CONFIG_AUTO
56695+ depends on GRKERNSEC_CHROOT
56696+ help
56697+ If you say Y here, processes inside a chroot will not be able to raise
56698+ the priority of processes in the chroot, or alter the priority of
56699+ processes outside the chroot. This provides more security than simply
56700+ removing CAP_SYS_NICE from the process' capability set. If the
56701+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56702+ is created.
56703+
56704+config GRKERNSEC_CHROOT_SYSCTL
56705+ bool "Deny sysctl writes"
56706+ default y if GRKERNSEC_CONFIG_AUTO
56707+ depends on GRKERNSEC_CHROOT
56708+ help
56709+ If you say Y here, an attacker in a chroot will not be able to
56710+ write to sysctl entries, either by sysctl(2) or through a /proc
56711+ interface. It is strongly recommended that you say Y here. If the
56712+ sysctl option is enabled, a sysctl option with name
56713+ "chroot_deny_sysctl" is created.
56714+
56715+config GRKERNSEC_CHROOT_CAPS
56716+ bool "Capability restrictions"
56717+ default y if GRKERNSEC_CONFIG_AUTO
56718+ depends on GRKERNSEC_CHROOT
56719+ help
56720+ If you say Y here, the capabilities on all processes within a
56721+ chroot jail will be lowered to stop module insertion, raw i/o,
56722+ system and net admin tasks, rebooting the system, modifying immutable
56723+ files, modifying IPC owned by another, and changing the system time.
56724+ This is left an option because it can break some apps. Disable this
56725+ if your chrooted apps are having problems performing those kinds of
56726+ tasks. If the sysctl option is enabled, a sysctl option with
56727+ name "chroot_caps" is created.
56728+
56729+endmenu
56730+menu "Kernel Auditing"
56731+depends on GRKERNSEC
56732+
56733+config GRKERNSEC_AUDIT_GROUP
56734+ bool "Single group for auditing"
56735+ help
56736+ If you say Y here, the exec and chdir logging features will only operate
56737+ on a group you specify. This option is recommended if you only want to
56738+ watch certain users instead of having a large amount of logs from the
56739+ entire system. If the sysctl option is enabled, a sysctl option with
56740+ name "audit_group" is created.
56741+
56742+config GRKERNSEC_AUDIT_GID
56743+ int "GID for auditing"
56744+ depends on GRKERNSEC_AUDIT_GROUP
56745+ default 1007
56746+
56747+config GRKERNSEC_EXECLOG
56748+ bool "Exec logging"
56749+ help
56750+ If you say Y here, all execve() calls will be logged (since the
56751+ other exec*() calls are frontends to execve(), all execution
56752+ will be logged). Useful for shell-servers that like to keep track
56753+ of their users. If the sysctl option is enabled, a sysctl option with
56754+ name "exec_logging" is created.
56755+ WARNING: This option when enabled will produce a LOT of logs, especially
56756+ on an active system.
56757+
56758+config GRKERNSEC_RESLOG
56759+ bool "Resource logging"
56760+ default y if GRKERNSEC_CONFIG_AUTO
56761+ help
56762+ If you say Y here, all attempts to overstep resource limits will
56763+ be logged with the resource name, the requested size, and the current
56764+ limit. It is highly recommended that you say Y here. If the sysctl
56765+ option is enabled, a sysctl option with name "resource_logging" is
56766+ created. If the RBAC system is enabled, the sysctl value is ignored.
56767+
56768+config GRKERNSEC_CHROOT_EXECLOG
56769+ bool "Log execs within chroot"
56770+ help
56771+ If you say Y here, all executions inside a chroot jail will be logged
56772+ to syslog. This can cause a large amount of logs if certain
56773+ applications (eg. djb's daemontools) are installed on the system, and
56774+ is therefore left as an option. If the sysctl option is enabled, a
56775+ sysctl option with name "chroot_execlog" is created.
56776+
56777+config GRKERNSEC_AUDIT_PTRACE
56778+ bool "Ptrace logging"
56779+ help
56780+ If you say Y here, all attempts to attach to a process via ptrace
56781+ will be logged. If the sysctl option is enabled, a sysctl option
56782+ with name "audit_ptrace" is created.
56783+
56784+config GRKERNSEC_AUDIT_CHDIR
56785+ bool "Chdir logging"
56786+ help
56787+ If you say Y here, all chdir() calls will be logged. If the sysctl
56788+ option is enabled, a sysctl option with name "audit_chdir" is created.
56789+
56790+config GRKERNSEC_AUDIT_MOUNT
56791+ bool "(Un)Mount logging"
56792+ help
56793+ If you say Y here, all mounts and unmounts will be logged. If the
56794+ sysctl option is enabled, a sysctl option with name "audit_mount" is
56795+ created.
56796+
56797+config GRKERNSEC_SIGNAL
56798+ bool "Signal logging"
56799+ default y if GRKERNSEC_CONFIG_AUTO
56800+ help
56801+ If you say Y here, certain important signals will be logged, such as
56802+ SIGSEGV, which will as a result inform you of when a error in a program
56803+ occurred, which in some cases could mean a possible exploit attempt.
56804+ If the sysctl option is enabled, a sysctl option with name
56805+ "signal_logging" is created.
56806+
56807+config GRKERNSEC_FORKFAIL
56808+ bool "Fork failure logging"
56809+ help
56810+ If you say Y here, all failed fork() attempts will be logged.
56811+ This could suggest a fork bomb, or someone attempting to overstep
56812+ their process limit. If the sysctl option is enabled, a sysctl option
56813+ with name "forkfail_logging" is created.
56814+
56815+config GRKERNSEC_TIME
56816+ bool "Time change logging"
56817+ default y if GRKERNSEC_CONFIG_AUTO
56818+ help
56819+ If you say Y here, any changes of the system clock will be logged.
56820+ If the sysctl option is enabled, a sysctl option with name
56821+ "timechange_logging" is created.
56822+
56823+config GRKERNSEC_PROC_IPADDR
56824+ bool "/proc/<pid>/ipaddr support"
56825+ default y if GRKERNSEC_CONFIG_AUTO
56826+ help
56827+ If you say Y here, a new entry will be added to each /proc/<pid>
56828+ directory that contains the IP address of the person using the task.
56829+ The IP is carried across local TCP and AF_UNIX stream sockets.
56830+ This information can be useful for IDS/IPSes to perform remote response
56831+ to a local attack. The entry is readable by only the owner of the
56832+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56833+ the RBAC system), and thus does not create privacy concerns.
56834+
56835+config GRKERNSEC_RWXMAP_LOG
56836+ bool 'Denied RWX mmap/mprotect logging'
56837+ default y if GRKERNSEC_CONFIG_AUTO
56838+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56839+ help
56840+ If you say Y here, calls to mmap() and mprotect() with explicit
56841+ usage of PROT_WRITE and PROT_EXEC together will be logged when
56842+ denied by the PAX_MPROTECT feature. If the sysctl option is
56843+ enabled, a sysctl option with name "rwxmap_logging" is created.
56844+
56845+config GRKERNSEC_AUDIT_TEXTREL
56846+ bool 'ELF text relocations logging (READ HELP)'
56847+ depends on PAX_MPROTECT
56848+ help
56849+ If you say Y here, text relocations will be logged with the filename
56850+ of the offending library or binary. The purpose of the feature is
56851+ to help Linux distribution developers get rid of libraries and
56852+ binaries that need text relocations which hinder the future progress
56853+ of PaX. Only Linux distribution developers should say Y here, and
56854+ never on a production machine, as this option creates an information
56855+ leak that could aid an attacker in defeating the randomization of
56856+ a single memory region. If the sysctl option is enabled, a sysctl
56857+ option with name "audit_textrel" is created.
56858+
56859+endmenu
56860+
56861+menu "Executable Protections"
56862+depends on GRKERNSEC
56863+
56864+config GRKERNSEC_DMESG
56865+ bool "Dmesg(8) restriction"
56866+ default y if GRKERNSEC_CONFIG_AUTO
56867+ help
56868+ If you say Y here, non-root users will not be able to use dmesg(8)
56869+ to view the contents of the kernel's circular log buffer.
56870+ The kernel's log buffer often contains kernel addresses and other
56871+ identifying information useful to an attacker in fingerprinting a
56872+ system for a targeted exploit.
56873+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
56874+ created.
56875+
56876+config GRKERNSEC_HARDEN_PTRACE
56877+ bool "Deter ptrace-based process snooping"
56878+ default y if GRKERNSEC_CONFIG_AUTO
56879+ help
56880+ If you say Y here, TTY sniffers and other malicious monitoring
56881+ programs implemented through ptrace will be defeated. If you
56882+ have been using the RBAC system, this option has already been
56883+ enabled for several years for all users, with the ability to make
56884+ fine-grained exceptions.
56885+
56886+ This option only affects the ability of non-root users to ptrace
56887+ processes that are not a descendent of the ptracing process.
56888+ This means that strace ./binary and gdb ./binary will still work,
56889+ but attaching to arbitrary processes will not. If the sysctl
56890+ option is enabled, a sysctl option with name "harden_ptrace" is
56891+ created.
56892+
56893+config GRKERNSEC_PTRACE_READEXEC
56894+ bool "Require read access to ptrace sensitive binaries"
56895+ default y if GRKERNSEC_CONFIG_AUTO
56896+ help
56897+ If you say Y here, unprivileged users will not be able to ptrace unreadable
56898+ binaries. This option is useful in environments that
56899+ remove the read bits (e.g. file mode 4711) from suid binaries to
56900+ prevent infoleaking of their contents. This option adds
56901+ consistency to the use of that file mode, as the binary could normally
56902+ be read out when run without privileges while ptracing.
56903+
56904+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56905+ is created.
56906+
56907+config GRKERNSEC_SETXID
56908+ bool "Enforce consistent multithreaded privileges"
56909+ default y if GRKERNSEC_CONFIG_AUTO
56910+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56911+ help
56912+ If you say Y here, a change from a root uid to a non-root uid
56913+ in a multithreaded application will cause the resulting uids,
56914+ gids, supplementary groups, and capabilities in that thread
56915+ to be propagated to the other threads of the process. In most
56916+ cases this is unnecessary, as glibc will emulate this behavior
56917+ on behalf of the application. Other libcs do not act in the
56918+ same way, allowing the other threads of the process to continue
56919+ running with root privileges. If the sysctl option is enabled,
56920+ a sysctl option with name "consistent_setxid" is created.
56921+
56922+config GRKERNSEC_TPE
56923+ bool "Trusted Path Execution (TPE)"
56924+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56925+ help
56926+ If you say Y here, you will be able to choose a gid to add to the
56927+ supplementary groups of users you want to mark as "untrusted."
56928+ These users will not be able to execute any files that are not in
56929+ root-owned directories writable only by root. If the sysctl option
56930+ is enabled, a sysctl option with name "tpe" is created.
56931+
56932+config GRKERNSEC_TPE_ALL
56933+ bool "Partially restrict all non-root users"
56934+ depends on GRKERNSEC_TPE
56935+ help
56936+ If you say Y here, all non-root users will be covered under
56937+ a weaker TPE restriction. This is separate from, and in addition to,
56938+ the main TPE options that you have selected elsewhere. Thus, if a
56939+ "trusted" GID is chosen, this restriction applies to even that GID.
56940+ Under this restriction, all non-root users will only be allowed to
56941+ execute files in directories they own that are not group or
56942+ world-writable, or in directories owned by root and writable only by
56943+ root. If the sysctl option is enabled, a sysctl option with name
56944+ "tpe_restrict_all" is created.
56945+
56946+config GRKERNSEC_TPE_INVERT
56947+ bool "Invert GID option"
56948+ depends on GRKERNSEC_TPE
56949+ help
56950+ If you say Y here, the group you specify in the TPE configuration will
56951+ decide what group TPE restrictions will be *disabled* for. This
56952+ option is useful if you want TPE restrictions to be applied to most
56953+ users on the system. If the sysctl option is enabled, a sysctl option
56954+ with name "tpe_invert" is created. Unlike other sysctl options, this
56955+ entry will default to on for backward-compatibility.
56956+
56957+config GRKERNSEC_TPE_GID
56958+ int
56959+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56960+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56961+
56962+config GRKERNSEC_TPE_UNTRUSTED_GID
56963+ int "GID for TPE-untrusted users"
56964+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56965+ default 1005
56966+ help
56967+ Setting this GID determines what group TPE restrictions will be
56968+ *enabled* for. If the sysctl option is enabled, a sysctl option
56969+ with name "tpe_gid" is created.
56970+
56971+config GRKERNSEC_TPE_TRUSTED_GID
56972+ int "GID for TPE-trusted users"
56973+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56974+ default 1005
56975+ help
56976+ Setting this GID determines what group TPE restrictions will be
56977+ *disabled* for. If the sysctl option is enabled, a sysctl option
56978+ with name "tpe_gid" is created.
56979+
56980+endmenu
56981+menu "Network Protections"
56982+depends on GRKERNSEC
56983+
56984+config GRKERNSEC_RANDNET
56985+ bool "Larger entropy pools"
56986+ default y if GRKERNSEC_CONFIG_AUTO
56987+ help
56988+ If you say Y here, the entropy pools used for many features of Linux
56989+ and grsecurity will be doubled in size. Since several grsecurity
56990+ features use additional randomness, it is recommended that you say Y
56991+ here. Saying Y here has a similar effect as modifying
56992+ /proc/sys/kernel/random/poolsize.
56993+
56994+config GRKERNSEC_BLACKHOLE
56995+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56996+ default y if GRKERNSEC_CONFIG_AUTO
56997+ depends on NET
56998+ help
56999+ If you say Y here, neither TCP resets nor ICMP
57000+ destination-unreachable packets will be sent in response to packets
57001+ sent to ports for which no associated listening process exists.
57002+ This feature supports both IPV4 and IPV6 and exempts the
57003+ loopback interface from blackholing. Enabling this feature
57004+ makes a host more resilient to DoS attacks and reduces network
57005+ visibility against scanners.
57006+
57007+ The blackhole feature as-implemented is equivalent to the FreeBSD
57008+ blackhole feature, as it prevents RST responses to all packets, not
57009+ just SYNs. Under most application behavior this causes no
57010+ problems, but applications (like haproxy) may not close certain
57011+ connections in a way that cleanly terminates them on the remote
57012+ end, leaving the remote host in LAST_ACK state. Because of this
57013+ side-effect and to prevent intentional LAST_ACK DoSes, this
57014+ feature also adds automatic mitigation against such attacks.
57015+ The mitigation drastically reduces the amount of time a socket
57016+ can spend in LAST_ACK state. If you're using haproxy and not
57017+ all servers it connects to have this option enabled, consider
57018+ disabling this feature on the haproxy host.
57019+
57020+ If the sysctl option is enabled, two sysctl options with names
57021+ "ip_blackhole" and "lastack_retries" will be created.
57022+ While "ip_blackhole" takes the standard zero/non-zero on/off
57023+ toggle, "lastack_retries" uses the same kinds of values as
57024+ "tcp_retries1" and "tcp_retries2". The default value of 4
57025+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57026+ state.
57027+
57028+config GRKERNSEC_NO_SIMULT_CONNECT
57029+ bool "Disable TCP Simultaneous Connect"
57030+ default y if GRKERNSEC_CONFIG_AUTO
57031+ depends on NET
57032+ help
57033+ If you say Y here, a feature by Willy Tarreau will be enabled that
57034+ removes a weakness in Linux's strict implementation of TCP that
57035+ allows two clients to connect to each other without either entering
57036+ a listening state. The weakness allows an attacker to easily prevent
57037+ a client from connecting to a known server provided the source port
57038+ for the connection is guessed correctly.
57039+
57040+ As the weakness could be used to prevent an antivirus or IPS from
57041+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57042+ it should be eliminated by enabling this option. Though Linux is
57043+ one of few operating systems supporting simultaneous connect, it
57044+ has no legitimate use in practice and is rarely supported by firewalls.
57045+
57046+config GRKERNSEC_SOCKET
57047+ bool "Socket restrictions"
57048+ depends on NET
57049+ help
57050+ If you say Y here, you will be able to choose from several options.
57051+ If you assign a GID on your system and add it to the supplementary
57052+ groups of users you want to restrict socket access to, this patch
57053+ will perform up to three things, based on the option(s) you choose.
57054+
57055+config GRKERNSEC_SOCKET_ALL
57056+ bool "Deny any sockets to group"
57057+ depends on GRKERNSEC_SOCKET
57058+ help
57059+ If you say Y here, you will be able to choose a GID of whose users will
57060+ be unable to connect to other hosts from your machine or run server
57061+ applications from your machine. If the sysctl option is enabled, a
57062+ sysctl option with name "socket_all" is created.
57063+
57064+config GRKERNSEC_SOCKET_ALL_GID
57065+ int "GID to deny all sockets for"
57066+ depends on GRKERNSEC_SOCKET_ALL
57067+ default 1004
57068+ help
57069+ Here you can choose the GID to disable socket access for. Remember to
57070+ add the users you want socket access disabled for to the GID
57071+ specified here. If the sysctl option is enabled, a sysctl option
57072+ with name "socket_all_gid" is created.
57073+
57074+config GRKERNSEC_SOCKET_CLIENT
57075+ bool "Deny client sockets to group"
57076+ depends on GRKERNSEC_SOCKET
57077+ help
57078+ If you say Y here, you will be able to choose a GID of whose users will
57079+ be unable to connect to other hosts from your machine, but will be
57080+ able to run servers. If this option is enabled, all users in the group
57081+ you specify will have to use passive mode when initiating ftp transfers
57082+ from the shell on your machine. If the sysctl option is enabled, a
57083+ sysctl option with name "socket_client" is created.
57084+
57085+config GRKERNSEC_SOCKET_CLIENT_GID
57086+ int "GID to deny client sockets for"
57087+ depends on GRKERNSEC_SOCKET_CLIENT
57088+ default 1003
57089+ help
57090+ Here you can choose the GID to disable client socket access for.
57091+ Remember to add the users you want client socket access disabled for to
57092+ the GID specified here. If the sysctl option is enabled, a sysctl
57093+ option with name "socket_client_gid" is created.
57094+
57095+config GRKERNSEC_SOCKET_SERVER
57096+ bool "Deny server sockets to group"
57097+ depends on GRKERNSEC_SOCKET
57098+ help
57099+ If you say Y here, you will be able to choose a GID of whose users will
57100+ be unable to run server applications from your machine. If the sysctl
57101+ option is enabled, a sysctl option with name "socket_server" is created.
57102+
57103+config GRKERNSEC_SOCKET_SERVER_GID
57104+ int "GID to deny server sockets for"
57105+ depends on GRKERNSEC_SOCKET_SERVER
57106+ default 1002
57107+ help
57108+ Here you can choose the GID to disable server socket access for.
57109+ Remember to add the users you want server socket access disabled for to
57110+ the GID specified here. If the sysctl option is enabled, a sysctl
57111+ option with name "socket_server_gid" is created.
57112+
57113+endmenu
57114+menu "Sysctl Support"
57115+depends on GRKERNSEC && SYSCTL
57116+
57117+config GRKERNSEC_SYSCTL
57118+ bool "Sysctl support"
57119+ default y if GRKERNSEC_CONFIG_AUTO
57120+ help
57121+ If you say Y here, you will be able to change the options that
57122+ grsecurity runs with at bootup, without having to recompile your
57123+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
57124+ to enable (1) or disable (0) various features. All the sysctl entries
57125+ are mutable until the "grsec_lock" entry is set to a non-zero value.
57126+ All features enabled in the kernel configuration are disabled at boot
57127+ if you do not say Y to the "Turn on features by default" option.
57128+ All options should be set at startup, and the grsec_lock entry should
57129+ be set to a non-zero value after all the options are set.
57130+ *THIS IS EXTREMELY IMPORTANT*
57131+
57132+config GRKERNSEC_SYSCTL_DISTRO
57133+ bool "Extra sysctl support for distro makers (READ HELP)"
57134+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
57135+ help
57136+ If you say Y here, additional sysctl options will be created
57137+ for features that affect processes running as root. Therefore,
57138+ it is critical when using this option that the grsec_lock entry be
57139+ enabled after boot. Only distros with prebuilt kernel packages
57140+ with this option enabled that can ensure grsec_lock is enabled
57141+ after boot should use this option.
57142+ *Failure to set grsec_lock after boot makes all grsec features
57143+ this option covers useless*
57144+
57145+ Currently this option creates the following sysctl entries:
57146+ "Disable Privileged I/O": "disable_priv_io"
57147+
57148+config GRKERNSEC_SYSCTL_ON
57149+ bool "Turn on features by default"
57150+ default y if GRKERNSEC_CONFIG_AUTO
57151+ depends on GRKERNSEC_SYSCTL
57152+ help
57153+ If you say Y here, instead of having all features enabled in the
57154+ kernel configuration disabled at boot time, the features will be
57155+ enabled at boot time. It is recommended you say Y here unless
57156+ there is some reason you would want all sysctl-tunable features to
57157+ be disabled by default. As mentioned elsewhere, it is important
57158+ to enable the grsec_lock entry once you have finished modifying
57159+ the sysctl entries.
57160+
57161+endmenu
57162+menu "Logging Options"
57163+depends on GRKERNSEC
57164+
57165+config GRKERNSEC_FLOODTIME
57166+ int "Seconds in between log messages (minimum)"
57167+ default 10
57168+ help
57169+ This option allows you to enforce the number of seconds between
57170+ grsecurity log messages. The default should be suitable for most
57171+ people, however, if you choose to change it, choose a value small enough
57172+ to allow informative logs to be produced, but large enough to
57173+ prevent flooding.
57174+
57175+config GRKERNSEC_FLOODBURST
57176+ int "Number of messages in a burst (maximum)"
57177+ default 6
57178+ help
57179+ This option allows you to choose the maximum number of messages allowed
57180+ within the flood time interval you chose in a separate option. The
57181+ default should be suitable for most people, however if you find that
57182+ many of your logs are being interpreted as flooding, you may want to
57183+ raise this value.
57184+
57185+endmenu
57186diff --git a/grsecurity/Makefile b/grsecurity/Makefile
57187new file mode 100644
57188index 0000000..1b9afa9
57189--- /dev/null
57190+++ b/grsecurity/Makefile
57191@@ -0,0 +1,38 @@
57192+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
57193+# during 2001-2009 it has been completely redesigned by Brad Spengler
57194+# into an RBAC system
57195+#
57196+# All code in this directory and various hooks inserted throughout the kernel
57197+# are copyright Brad Spengler - Open Source Security, Inc., and released
57198+# under the GPL v2 or higher
57199+
57200+KBUILD_CFLAGS += -Werror
57201+
57202+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
57203+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
57204+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
57205+
57206+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
57207+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
57208+ gracl_learn.o grsec_log.o
57209+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
57210+
57211+ifdef CONFIG_NET
57212+obj-y += grsec_sock.o
57213+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
57214+endif
57215+
57216+ifndef CONFIG_GRKERNSEC
57217+obj-y += grsec_disabled.o
57218+endif
57219+
57220+ifdef CONFIG_GRKERNSEC_HIDESYM
57221+extra-y := grsec_hidesym.o
57222+$(obj)/grsec_hidesym.o:
57223+ @-chmod -f 500 /boot
57224+ @-chmod -f 500 /lib/modules
57225+ @-chmod -f 500 /lib64/modules
57226+ @-chmod -f 500 /lib32/modules
57227+ @-chmod -f 700 .
57228+ @echo ' grsec: protected kernel image paths'
57229+endif
57230diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
57231new file mode 100644
57232index 0000000..ab45812
57233--- /dev/null
57234+++ b/grsecurity/gracl.c
57235@@ -0,0 +1,4071 @@
57236+#include <linux/kernel.h>
57237+#include <linux/module.h>
57238+#include <linux/sched.h>
57239+#include <linux/mm.h>
57240+#include <linux/file.h>
57241+#include <linux/fs.h>
57242+#include <linux/namei.h>
57243+#include <linux/mount.h>
57244+#include <linux/tty.h>
57245+#include <linux/proc_fs.h>
57246+#include <linux/lglock.h>
57247+#include <linux/slab.h>
57248+#include <linux/vmalloc.h>
57249+#include <linux/types.h>
57250+#include <linux/sysctl.h>
57251+#include <linux/netdevice.h>
57252+#include <linux/ptrace.h>
57253+#include <linux/gracl.h>
57254+#include <linux/gralloc.h>
57255+#include <linux/security.h>
57256+#include <linux/grinternal.h>
57257+#include <linux/pid_namespace.h>
57258+#include <linux/stop_machine.h>
57259+#include <linux/fdtable.h>
57260+#include <linux/percpu.h>
57261+#include <linux/lglock.h>
57262+#include <linux/hugetlb.h>
57263+#include <linux/posix-timers.h>
57264+#include "../fs/mount.h"
57265+
57266+#include <asm/uaccess.h>
57267+#include <asm/errno.h>
57268+#include <asm/mman.h>
57269+
57270+extern struct lglock vfsmount_lock;
57271+
57272+static struct acl_role_db acl_role_set;
57273+static struct name_db name_set;
57274+static struct inodev_db inodev_set;
57275+
57276+/* for keeping track of userspace pointers used for subjects, so we
57277+ can share references in the kernel as well
57278+*/
57279+
57280+static struct path real_root;
57281+
57282+static struct acl_subj_map_db subj_map_set;
57283+
57284+static struct acl_role_label *default_role;
57285+
57286+static struct acl_role_label *role_list;
57287+
57288+static u16 acl_sp_role_value;
57289+
57290+extern char *gr_shared_page[4];
57291+static DEFINE_MUTEX(gr_dev_mutex);
57292+DEFINE_RWLOCK(gr_inode_lock);
57293+
57294+struct gr_arg *gr_usermode;
57295+
57296+static unsigned int gr_status __read_only = GR_STATUS_INIT;
57297+
57298+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
57299+extern void gr_clear_learn_entries(void);
57300+
57301+unsigned char *gr_system_salt;
57302+unsigned char *gr_system_sum;
57303+
57304+static struct sprole_pw **acl_special_roles = NULL;
57305+static __u16 num_sprole_pws = 0;
57306+
57307+static struct acl_role_label *kernel_role = NULL;
57308+
57309+static unsigned int gr_auth_attempts = 0;
57310+static unsigned long gr_auth_expires = 0UL;
57311+
57312+#ifdef CONFIG_NET
57313+extern struct vfsmount *sock_mnt;
57314+#endif
57315+
57316+extern struct vfsmount *pipe_mnt;
57317+extern struct vfsmount *shm_mnt;
57318+
57319+#ifdef CONFIG_HUGETLBFS
57320+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57321+#endif
57322+
57323+static struct acl_object_label *fakefs_obj_rw;
57324+static struct acl_object_label *fakefs_obj_rwx;
57325+
57326+extern int gr_init_uidset(void);
57327+extern void gr_free_uidset(void);
57328+extern void gr_remove_uid(uid_t uid);
57329+extern int gr_find_uid(uid_t uid);
57330+
57331+__inline__ int
57332+gr_acl_is_enabled(void)
57333+{
57334+ return (gr_status & GR_READY);
57335+}
57336+
57337+#ifdef CONFIG_BTRFS_FS
57338+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57339+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57340+#endif
57341+
57342+static inline dev_t __get_dev(const struct dentry *dentry)
57343+{
57344+#ifdef CONFIG_BTRFS_FS
57345+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57346+ return get_btrfs_dev_from_inode(dentry->d_inode);
57347+ else
57348+#endif
57349+ return dentry->d_inode->i_sb->s_dev;
57350+}
57351+
57352+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57353+{
57354+ return __get_dev(dentry);
57355+}
57356+
57357+static char gr_task_roletype_to_char(struct task_struct *task)
57358+{
57359+ switch (task->role->roletype &
57360+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
57361+ GR_ROLE_SPECIAL)) {
57362+ case GR_ROLE_DEFAULT:
57363+ return 'D';
57364+ case GR_ROLE_USER:
57365+ return 'U';
57366+ case GR_ROLE_GROUP:
57367+ return 'G';
57368+ case GR_ROLE_SPECIAL:
57369+ return 'S';
57370+ }
57371+
57372+ return 'X';
57373+}
57374+
57375+char gr_roletype_to_char(void)
57376+{
57377+ return gr_task_roletype_to_char(current);
57378+}
57379+
57380+__inline__ int
57381+gr_acl_tpe_check(void)
57382+{
57383+ if (unlikely(!(gr_status & GR_READY)))
57384+ return 0;
57385+ if (current->role->roletype & GR_ROLE_TPE)
57386+ return 1;
57387+ else
57388+ return 0;
57389+}
57390+
57391+int
57392+gr_handle_rawio(const struct inode *inode)
57393+{
57394+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57395+ if (inode && S_ISBLK(inode->i_mode) &&
57396+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57397+ !capable(CAP_SYS_RAWIO))
57398+ return 1;
57399+#endif
57400+ return 0;
57401+}
57402+
57403+static int
57404+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
57405+{
57406+ if (likely(lena != lenb))
57407+ return 0;
57408+
57409+ return !memcmp(a, b, lena);
57410+}
57411+
57412+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
57413+{
57414+ *buflen -= namelen;
57415+ if (*buflen < 0)
57416+ return -ENAMETOOLONG;
57417+ *buffer -= namelen;
57418+ memcpy(*buffer, str, namelen);
57419+ return 0;
57420+}
57421+
57422+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
57423+{
57424+ return prepend(buffer, buflen, name->name, name->len);
57425+}
57426+
57427+static int prepend_path(const struct path *path, struct path *root,
57428+ char **buffer, int *buflen)
57429+{
57430+ struct dentry *dentry = path->dentry;
57431+ struct vfsmount *vfsmnt = path->mnt;
57432+ struct mount *mnt = real_mount(vfsmnt);
57433+ bool slash = false;
57434+ int error = 0;
57435+
57436+ while (dentry != root->dentry || vfsmnt != root->mnt) {
57437+ struct dentry * parent;
57438+
57439+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
57440+ /* Global root? */
57441+ if (!mnt_has_parent(mnt)) {
57442+ goto out;
57443+ }
57444+ dentry = mnt->mnt_mountpoint;
57445+ mnt = mnt->mnt_parent;
57446+ vfsmnt = &mnt->mnt;
57447+ continue;
57448+ }
57449+ parent = dentry->d_parent;
57450+ prefetch(parent);
57451+ spin_lock(&dentry->d_lock);
57452+ error = prepend_name(buffer, buflen, &dentry->d_name);
57453+ spin_unlock(&dentry->d_lock);
57454+ if (!error)
57455+ error = prepend(buffer, buflen, "/", 1);
57456+ if (error)
57457+ break;
57458+
57459+ slash = true;
57460+ dentry = parent;
57461+ }
57462+
57463+out:
57464+ if (!error && !slash)
57465+ error = prepend(buffer, buflen, "/", 1);
57466+
57467+ return error;
57468+}
57469+
57470+/* this must be called with vfsmount_lock and rename_lock held */
57471+
57472+static char *__our_d_path(const struct path *path, struct path *root,
57473+ char *buf, int buflen)
57474+{
57475+ char *res = buf + buflen;
57476+ int error;
57477+
57478+ prepend(&res, &buflen, "\0", 1);
57479+ error = prepend_path(path, root, &res, &buflen);
57480+ if (error)
57481+ return ERR_PTR(error);
57482+
57483+ return res;
57484+}
57485+
57486+static char *
57487+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
57488+{
57489+ char *retval;
57490+
57491+ retval = __our_d_path(path, root, buf, buflen);
57492+ if (unlikely(IS_ERR(retval)))
57493+ retval = strcpy(buf, "<path too long>");
57494+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57495+ retval[1] = '\0';
57496+
57497+ return retval;
57498+}
57499+
57500+static char *
57501+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57502+ char *buf, int buflen)
57503+{
57504+ struct path path;
57505+ char *res;
57506+
57507+ path.dentry = (struct dentry *)dentry;
57508+ path.mnt = (struct vfsmount *)vfsmnt;
57509+
57510+ /* we can use real_root.dentry, real_root.mnt, because this is only called
57511+ by the RBAC system */
57512+ res = gen_full_path(&path, &real_root, buf, buflen);
57513+
57514+ return res;
57515+}
57516+
57517+static char *
57518+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57519+ char *buf, int buflen)
57520+{
57521+ char *res;
57522+ struct path path;
57523+ struct path root;
57524+ struct task_struct *reaper = init_pid_ns.child_reaper;
57525+
57526+ path.dentry = (struct dentry *)dentry;
57527+ path.mnt = (struct vfsmount *)vfsmnt;
57528+
57529+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57530+ get_fs_root(reaper->fs, &root);
57531+
57532+ write_seqlock(&rename_lock);
57533+ br_read_lock(&vfsmount_lock);
57534+ res = gen_full_path(&path, &root, buf, buflen);
57535+ br_read_unlock(&vfsmount_lock);
57536+ write_sequnlock(&rename_lock);
57537+
57538+ path_put(&root);
57539+ return res;
57540+}
57541+
57542+static char *
57543+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57544+{
57545+ char *ret;
57546+ write_seqlock(&rename_lock);
57547+ br_read_lock(&vfsmount_lock);
57548+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57549+ PAGE_SIZE);
57550+ br_read_unlock(&vfsmount_lock);
57551+ write_sequnlock(&rename_lock);
57552+ return ret;
57553+}
57554+
57555+static char *
57556+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57557+{
57558+ char *ret;
57559+ char *buf;
57560+ int buflen;
57561+
57562+ write_seqlock(&rename_lock);
57563+ br_read_lock(&vfsmount_lock);
57564+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57565+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57566+ buflen = (int)(ret - buf);
57567+ if (buflen >= 5)
57568+ prepend(&ret, &buflen, "/proc", 5);
57569+ else
57570+ ret = strcpy(buf, "<path too long>");
57571+ br_read_unlock(&vfsmount_lock);
57572+ write_sequnlock(&rename_lock);
57573+ return ret;
57574+}
57575+
57576+char *
57577+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57578+{
57579+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57580+ PAGE_SIZE);
57581+}
57582+
57583+char *
57584+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57585+{
57586+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57587+ PAGE_SIZE);
57588+}
57589+
57590+char *
57591+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57592+{
57593+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57594+ PAGE_SIZE);
57595+}
57596+
57597+char *
57598+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57599+{
57600+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57601+ PAGE_SIZE);
57602+}
57603+
57604+char *
57605+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57606+{
57607+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57608+ PAGE_SIZE);
57609+}
57610+
57611+__inline__ __u32
57612+to_gr_audit(const __u32 reqmode)
57613+{
57614+ /* masks off auditable permission flags, then shifts them to create
57615+ auditing flags, and adds the special case of append auditing if
57616+ we're requesting write */
57617+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57618+}
57619+
57620+struct acl_subject_label *
57621+lookup_subject_map(const struct acl_subject_label *userp)
57622+{
57623+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
57624+ struct subject_map *match;
57625+
57626+ match = subj_map_set.s_hash[index];
57627+
57628+ while (match && match->user != userp)
57629+ match = match->next;
57630+
57631+ if (match != NULL)
57632+ return match->kernel;
57633+ else
57634+ return NULL;
57635+}
57636+
57637+static void
57638+insert_subj_map_entry(struct subject_map *subjmap)
57639+{
57640+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57641+ struct subject_map **curr;
57642+
57643+ subjmap->prev = NULL;
57644+
57645+ curr = &subj_map_set.s_hash[index];
57646+ if (*curr != NULL)
57647+ (*curr)->prev = subjmap;
57648+
57649+ subjmap->next = *curr;
57650+ *curr = subjmap;
57651+
57652+ return;
57653+}
57654+
57655+static struct acl_role_label *
57656+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57657+ const gid_t gid)
57658+{
57659+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57660+ struct acl_role_label *match;
57661+ struct role_allowed_ip *ipp;
57662+ unsigned int x;
57663+ u32 curr_ip = task->signal->curr_ip;
57664+
57665+ task->signal->saved_ip = curr_ip;
57666+
57667+ match = acl_role_set.r_hash[index];
57668+
57669+ while (match) {
57670+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57671+ for (x = 0; x < match->domain_child_num; x++) {
57672+ if (match->domain_children[x] == uid)
57673+ goto found;
57674+ }
57675+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57676+ break;
57677+ match = match->next;
57678+ }
57679+found:
57680+ if (match == NULL) {
57681+ try_group:
57682+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57683+ match = acl_role_set.r_hash[index];
57684+
57685+ while (match) {
57686+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57687+ for (x = 0; x < match->domain_child_num; x++) {
57688+ if (match->domain_children[x] == gid)
57689+ goto found2;
57690+ }
57691+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57692+ break;
57693+ match = match->next;
57694+ }
57695+found2:
57696+ if (match == NULL)
57697+ match = default_role;
57698+ if (match->allowed_ips == NULL)
57699+ return match;
57700+ else {
57701+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57702+ if (likely
57703+ ((ntohl(curr_ip) & ipp->netmask) ==
57704+ (ntohl(ipp->addr) & ipp->netmask)))
57705+ return match;
57706+ }
57707+ match = default_role;
57708+ }
57709+ } else if (match->allowed_ips == NULL) {
57710+ return match;
57711+ } else {
57712+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57713+ if (likely
57714+ ((ntohl(curr_ip) & ipp->netmask) ==
57715+ (ntohl(ipp->addr) & ipp->netmask)))
57716+ return match;
57717+ }
57718+ goto try_group;
57719+ }
57720+
57721+ return match;
57722+}
57723+
57724+struct acl_subject_label *
57725+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57726+ const struct acl_role_label *role)
57727+{
57728+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57729+ struct acl_subject_label *match;
57730+
57731+ match = role->subj_hash[index];
57732+
57733+ while (match && (match->inode != ino || match->device != dev ||
57734+ (match->mode & GR_DELETED))) {
57735+ match = match->next;
57736+ }
57737+
57738+ if (match && !(match->mode & GR_DELETED))
57739+ return match;
57740+ else
57741+ return NULL;
57742+}
57743+
57744+struct acl_subject_label *
57745+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57746+ const struct acl_role_label *role)
57747+{
57748+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57749+ struct acl_subject_label *match;
57750+
57751+ match = role->subj_hash[index];
57752+
57753+ while (match && (match->inode != ino || match->device != dev ||
57754+ !(match->mode & GR_DELETED))) {
57755+ match = match->next;
57756+ }
57757+
57758+ if (match && (match->mode & GR_DELETED))
57759+ return match;
57760+ else
57761+ return NULL;
57762+}
57763+
57764+static struct acl_object_label *
57765+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57766+ const struct acl_subject_label *subj)
57767+{
57768+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57769+ struct acl_object_label *match;
57770+
57771+ match = subj->obj_hash[index];
57772+
57773+ while (match && (match->inode != ino || match->device != dev ||
57774+ (match->mode & GR_DELETED))) {
57775+ match = match->next;
57776+ }
57777+
57778+ if (match && !(match->mode & GR_DELETED))
57779+ return match;
57780+ else
57781+ return NULL;
57782+}
57783+
57784+static struct acl_object_label *
57785+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57786+ const struct acl_subject_label *subj)
57787+{
57788+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57789+ struct acl_object_label *match;
57790+
57791+ match = subj->obj_hash[index];
57792+
57793+ while (match && (match->inode != ino || match->device != dev ||
57794+ !(match->mode & GR_DELETED))) {
57795+ match = match->next;
57796+ }
57797+
57798+ if (match && (match->mode & GR_DELETED))
57799+ return match;
57800+
57801+ match = subj->obj_hash[index];
57802+
57803+ while (match && (match->inode != ino || match->device != dev ||
57804+ (match->mode & GR_DELETED))) {
57805+ match = match->next;
57806+ }
57807+
57808+ if (match && !(match->mode & GR_DELETED))
57809+ return match;
57810+ else
57811+ return NULL;
57812+}
57813+
57814+static struct name_entry *
57815+lookup_name_entry(const char *name)
57816+{
57817+ unsigned int len = strlen(name);
57818+ unsigned int key = full_name_hash(name, len);
57819+ unsigned int index = key % name_set.n_size;
57820+ struct name_entry *match;
57821+
57822+ match = name_set.n_hash[index];
57823+
57824+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57825+ match = match->next;
57826+
57827+ return match;
57828+}
57829+
57830+static struct name_entry *
57831+lookup_name_entry_create(const char *name)
57832+{
57833+ unsigned int len = strlen(name);
57834+ unsigned int key = full_name_hash(name, len);
57835+ unsigned int index = key % name_set.n_size;
57836+ struct name_entry *match;
57837+
57838+ match = name_set.n_hash[index];
57839+
57840+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57841+ !match->deleted))
57842+ match = match->next;
57843+
57844+ if (match && match->deleted)
57845+ return match;
57846+
57847+ match = name_set.n_hash[index];
57848+
57849+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57850+ match->deleted))
57851+ match = match->next;
57852+
57853+ if (match && !match->deleted)
57854+ return match;
57855+ else
57856+ return NULL;
57857+}
57858+
57859+static struct inodev_entry *
57860+lookup_inodev_entry(const ino_t ino, const dev_t dev)
57861+{
57862+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57863+ struct inodev_entry *match;
57864+
57865+ match = inodev_set.i_hash[index];
57866+
57867+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57868+ match = match->next;
57869+
57870+ return match;
57871+}
57872+
57873+static void
57874+insert_inodev_entry(struct inodev_entry *entry)
57875+{
57876+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57877+ inodev_set.i_size);
57878+ struct inodev_entry **curr;
57879+
57880+ entry->prev = NULL;
57881+
57882+ curr = &inodev_set.i_hash[index];
57883+ if (*curr != NULL)
57884+ (*curr)->prev = entry;
57885+
57886+ entry->next = *curr;
57887+ *curr = entry;
57888+
57889+ return;
57890+}
57891+
57892+static void
57893+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57894+{
57895+ unsigned int index =
57896+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57897+ struct acl_role_label **curr;
57898+ struct acl_role_label *tmp, *tmp2;
57899+
57900+ curr = &acl_role_set.r_hash[index];
57901+
57902+ /* simple case, slot is empty, just set it to our role */
57903+ if (*curr == NULL) {
57904+ *curr = role;
57905+ } else {
57906+ /* example:
57907+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
57908+ 2 -> 3
57909+ */
57910+ /* first check to see if we can already be reached via this slot */
57911+ tmp = *curr;
57912+ while (tmp && tmp != role)
57913+ tmp = tmp->next;
57914+ if (tmp == role) {
57915+ /* we don't need to add ourselves to this slot's chain */
57916+ return;
57917+ }
57918+ /* we need to add ourselves to this chain, two cases */
57919+ if (role->next == NULL) {
57920+ /* simple case, append the current chain to our role */
57921+ role->next = *curr;
57922+ *curr = role;
57923+ } else {
57924+ /* 1 -> 2 -> 3 -> 4
57925+ 2 -> 3 -> 4
57926+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57927+ */
57928+ /* trickier case: walk our role's chain until we find
57929+ the role for the start of the current slot's chain */
57930+ tmp = role;
57931+ tmp2 = *curr;
57932+ while (tmp->next && tmp->next != tmp2)
57933+ tmp = tmp->next;
57934+ if (tmp->next == tmp2) {
57935+ /* from example above, we found 3, so just
57936+ replace this slot's chain with ours */
57937+ *curr = role;
57938+ } else {
57939+ /* we didn't find a subset of our role's chain
57940+ in the current slot's chain, so append their
57941+ chain to ours, and set us as the first role in
57942+ the slot's chain
57943+
57944+ we could fold this case with the case above,
57945+ but making it explicit for clarity
57946+ */
57947+ tmp->next = tmp2;
57948+ *curr = role;
57949+ }
57950+ }
57951+ }
57952+
57953+ return;
57954+}
57955+
57956+static void
57957+insert_acl_role_label(struct acl_role_label *role)
57958+{
57959+ int i;
57960+
57961+ if (role_list == NULL) {
57962+ role_list = role;
57963+ role->prev = NULL;
57964+ } else {
57965+ role->prev = role_list;
57966+ role_list = role;
57967+ }
57968+
57969+ /* used for hash chains */
57970+ role->next = NULL;
57971+
57972+ if (role->roletype & GR_ROLE_DOMAIN) {
57973+ for (i = 0; i < role->domain_child_num; i++)
57974+ __insert_acl_role_label(role, role->domain_children[i]);
57975+ } else
57976+ __insert_acl_role_label(role, role->uidgid);
57977+}
57978+
57979+static int
57980+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57981+{
57982+ struct name_entry **curr, *nentry;
57983+ struct inodev_entry *ientry;
57984+ unsigned int len = strlen(name);
57985+ unsigned int key = full_name_hash(name, len);
57986+ unsigned int index = key % name_set.n_size;
57987+
57988+ curr = &name_set.n_hash[index];
57989+
57990+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57991+ curr = &((*curr)->next);
57992+
57993+ if (*curr != NULL)
57994+ return 1;
57995+
57996+ nentry = acl_alloc(sizeof (struct name_entry));
57997+ if (nentry == NULL)
57998+ return 0;
57999+ ientry = acl_alloc(sizeof (struct inodev_entry));
58000+ if (ientry == NULL)
58001+ return 0;
58002+ ientry->nentry = nentry;
58003+
58004+ nentry->key = key;
58005+ nentry->name = name;
58006+ nentry->inode = inode;
58007+ nentry->device = device;
58008+ nentry->len = len;
58009+ nentry->deleted = deleted;
58010+
58011+ nentry->prev = NULL;
58012+ curr = &name_set.n_hash[index];
58013+ if (*curr != NULL)
58014+ (*curr)->prev = nentry;
58015+ nentry->next = *curr;
58016+ *curr = nentry;
58017+
58018+ /* insert us into the table searchable by inode/dev */
58019+ insert_inodev_entry(ientry);
58020+
58021+ return 1;
58022+}
58023+
58024+static void
58025+insert_acl_obj_label(struct acl_object_label *obj,
58026+ struct acl_subject_label *subj)
58027+{
58028+ unsigned int index =
58029+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58030+ struct acl_object_label **curr;
58031+
58032+
58033+ obj->prev = NULL;
58034+
58035+ curr = &subj->obj_hash[index];
58036+ if (*curr != NULL)
58037+ (*curr)->prev = obj;
58038+
58039+ obj->next = *curr;
58040+ *curr = obj;
58041+
58042+ return;
58043+}
58044+
58045+static void
58046+insert_acl_subj_label(struct acl_subject_label *obj,
58047+ struct acl_role_label *role)
58048+{
58049+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58050+ struct acl_subject_label **curr;
58051+
58052+ obj->prev = NULL;
58053+
58054+ curr = &role->subj_hash[index];
58055+ if (*curr != NULL)
58056+ (*curr)->prev = obj;
58057+
58058+ obj->next = *curr;
58059+ *curr = obj;
58060+
58061+ return;
58062+}
58063+
58064+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
58065+
58066+static void *
58067+create_table(__u32 * len, int elementsize)
58068+{
58069+ unsigned int table_sizes[] = {
58070+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
58071+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
58072+ 4194301, 8388593, 16777213, 33554393, 67108859
58073+ };
58074+ void *newtable = NULL;
58075+ unsigned int pwr = 0;
58076+
58077+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
58078+ table_sizes[pwr] <= *len)
58079+ pwr++;
58080+
58081+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
58082+ return newtable;
58083+
58084+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
58085+ newtable =
58086+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
58087+ else
58088+ newtable = vmalloc(table_sizes[pwr] * elementsize);
58089+
58090+ *len = table_sizes[pwr];
58091+
58092+ return newtable;
58093+}
58094+
58095+static int
58096+init_variables(const struct gr_arg *arg)
58097+{
58098+ struct task_struct *reaper = init_pid_ns.child_reaper;
58099+ unsigned int stacksize;
58100+
58101+ subj_map_set.s_size = arg->role_db.num_subjects;
58102+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
58103+ name_set.n_size = arg->role_db.num_objects;
58104+ inodev_set.i_size = arg->role_db.num_objects;
58105+
58106+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
58107+ !name_set.n_size || !inodev_set.i_size)
58108+ return 1;
58109+
58110+ if (!gr_init_uidset())
58111+ return 1;
58112+
58113+ /* set up the stack that holds allocation info */
58114+
58115+ stacksize = arg->role_db.num_pointers + 5;
58116+
58117+ if (!acl_alloc_stack_init(stacksize))
58118+ return 1;
58119+
58120+ /* grab reference for the real root dentry and vfsmount */
58121+ get_fs_root(reaper->fs, &real_root);
58122+
58123+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58124+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
58125+#endif
58126+
58127+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
58128+ if (fakefs_obj_rw == NULL)
58129+ return 1;
58130+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
58131+
58132+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
58133+ if (fakefs_obj_rwx == NULL)
58134+ return 1;
58135+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
58136+
58137+ subj_map_set.s_hash =
58138+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
58139+ acl_role_set.r_hash =
58140+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
58141+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
58142+ inodev_set.i_hash =
58143+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
58144+
58145+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
58146+ !name_set.n_hash || !inodev_set.i_hash)
58147+ return 1;
58148+
58149+ memset(subj_map_set.s_hash, 0,
58150+ sizeof(struct subject_map *) * subj_map_set.s_size);
58151+ memset(acl_role_set.r_hash, 0,
58152+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
58153+ memset(name_set.n_hash, 0,
58154+ sizeof (struct name_entry *) * name_set.n_size);
58155+ memset(inodev_set.i_hash, 0,
58156+ sizeof (struct inodev_entry *) * inodev_set.i_size);
58157+
58158+ return 0;
58159+}
58160+
58161+/* free information not needed after startup
58162+ currently contains user->kernel pointer mappings for subjects
58163+*/
58164+
58165+static void
58166+free_init_variables(void)
58167+{
58168+ __u32 i;
58169+
58170+ if (subj_map_set.s_hash) {
58171+ for (i = 0; i < subj_map_set.s_size; i++) {
58172+ if (subj_map_set.s_hash[i]) {
58173+ kfree(subj_map_set.s_hash[i]);
58174+ subj_map_set.s_hash[i] = NULL;
58175+ }
58176+ }
58177+
58178+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
58179+ PAGE_SIZE)
58180+ kfree(subj_map_set.s_hash);
58181+ else
58182+ vfree(subj_map_set.s_hash);
58183+ }
58184+
58185+ return;
58186+}
58187+
58188+static void
58189+free_variables(void)
58190+{
58191+ struct acl_subject_label *s;
58192+ struct acl_role_label *r;
58193+ struct task_struct *task, *task2;
58194+ unsigned int x;
58195+
58196+ gr_clear_learn_entries();
58197+
58198+ read_lock(&tasklist_lock);
58199+ do_each_thread(task2, task) {
58200+ task->acl_sp_role = 0;
58201+ task->acl_role_id = 0;
58202+ task->acl = NULL;
58203+ task->role = NULL;
58204+ } while_each_thread(task2, task);
58205+ read_unlock(&tasklist_lock);
58206+
58207+ /* release the reference to the real root dentry and vfsmount */
58208+ path_put(&real_root);
58209+ memset(&real_root, 0, sizeof(real_root));
58210+
58211+ /* free all object hash tables */
58212+
58213+ FOR_EACH_ROLE_START(r)
58214+ if (r->subj_hash == NULL)
58215+ goto next_role;
58216+ FOR_EACH_SUBJECT_START(r, s, x)
58217+ if (s->obj_hash == NULL)
58218+ break;
58219+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58220+ kfree(s->obj_hash);
58221+ else
58222+ vfree(s->obj_hash);
58223+ FOR_EACH_SUBJECT_END(s, x)
58224+ FOR_EACH_NESTED_SUBJECT_START(r, s)
58225+ if (s->obj_hash == NULL)
58226+ break;
58227+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58228+ kfree(s->obj_hash);
58229+ else
58230+ vfree(s->obj_hash);
58231+ FOR_EACH_NESTED_SUBJECT_END(s)
58232+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
58233+ kfree(r->subj_hash);
58234+ else
58235+ vfree(r->subj_hash);
58236+ r->subj_hash = NULL;
58237+next_role:
58238+ FOR_EACH_ROLE_END(r)
58239+
58240+ acl_free_all();
58241+
58242+ if (acl_role_set.r_hash) {
58243+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
58244+ PAGE_SIZE)
58245+ kfree(acl_role_set.r_hash);
58246+ else
58247+ vfree(acl_role_set.r_hash);
58248+ }
58249+ if (name_set.n_hash) {
58250+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
58251+ PAGE_SIZE)
58252+ kfree(name_set.n_hash);
58253+ else
58254+ vfree(name_set.n_hash);
58255+ }
58256+
58257+ if (inodev_set.i_hash) {
58258+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
58259+ PAGE_SIZE)
58260+ kfree(inodev_set.i_hash);
58261+ else
58262+ vfree(inodev_set.i_hash);
58263+ }
58264+
58265+ gr_free_uidset();
58266+
58267+ memset(&name_set, 0, sizeof (struct name_db));
58268+ memset(&inodev_set, 0, sizeof (struct inodev_db));
58269+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
58270+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
58271+
58272+ default_role = NULL;
58273+ kernel_role = NULL;
58274+ role_list = NULL;
58275+
58276+ return;
58277+}
58278+
58279+static __u32
58280+count_user_objs(struct acl_object_label *userp)
58281+{
58282+ struct acl_object_label o_tmp;
58283+ __u32 num = 0;
58284+
58285+ while (userp) {
58286+ if (copy_from_user(&o_tmp, userp,
58287+ sizeof (struct acl_object_label)))
58288+ break;
58289+
58290+ userp = o_tmp.prev;
58291+ num++;
58292+ }
58293+
58294+ return num;
58295+}
58296+
58297+static struct acl_subject_label *
58298+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
58299+
58300+static int
58301+copy_user_glob(struct acl_object_label *obj)
58302+{
58303+ struct acl_object_label *g_tmp, **guser;
58304+ unsigned int len;
58305+ char *tmp;
58306+
58307+ if (obj->globbed == NULL)
58308+ return 0;
58309+
58310+ guser = &obj->globbed;
58311+ while (*guser) {
58312+ g_tmp = (struct acl_object_label *)
58313+ acl_alloc(sizeof (struct acl_object_label));
58314+ if (g_tmp == NULL)
58315+ return -ENOMEM;
58316+
58317+ if (copy_from_user(g_tmp, *guser,
58318+ sizeof (struct acl_object_label)))
58319+ return -EFAULT;
58320+
58321+ len = strnlen_user(g_tmp->filename, PATH_MAX);
58322+
58323+ if (!len || len >= PATH_MAX)
58324+ return -EINVAL;
58325+
58326+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58327+ return -ENOMEM;
58328+
58329+ if (copy_from_user(tmp, g_tmp->filename, len))
58330+ return -EFAULT;
58331+ tmp[len-1] = '\0';
58332+ g_tmp->filename = tmp;
58333+
58334+ *guser = g_tmp;
58335+ guser = &(g_tmp->next);
58336+ }
58337+
58338+ return 0;
58339+}
58340+
58341+static int
58342+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
58343+ struct acl_role_label *role)
58344+{
58345+ struct acl_object_label *o_tmp;
58346+ unsigned int len;
58347+ int ret;
58348+ char *tmp;
58349+
58350+ while (userp) {
58351+ if ((o_tmp = (struct acl_object_label *)
58352+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
58353+ return -ENOMEM;
58354+
58355+ if (copy_from_user(o_tmp, userp,
58356+ sizeof (struct acl_object_label)))
58357+ return -EFAULT;
58358+
58359+ userp = o_tmp->prev;
58360+
58361+ len = strnlen_user(o_tmp->filename, PATH_MAX);
58362+
58363+ if (!len || len >= PATH_MAX)
58364+ return -EINVAL;
58365+
58366+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58367+ return -ENOMEM;
58368+
58369+ if (copy_from_user(tmp, o_tmp->filename, len))
58370+ return -EFAULT;
58371+ tmp[len-1] = '\0';
58372+ o_tmp->filename = tmp;
58373+
58374+ insert_acl_obj_label(o_tmp, subj);
58375+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
58376+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
58377+ return -ENOMEM;
58378+
58379+ ret = copy_user_glob(o_tmp);
58380+ if (ret)
58381+ return ret;
58382+
58383+ if (o_tmp->nested) {
58384+ int already_copied;
58385+
58386+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
58387+ if (IS_ERR(o_tmp->nested))
58388+ return PTR_ERR(o_tmp->nested);
58389+
58390+ /* insert into nested subject list if we haven't copied this one yet
58391+ to prevent duplicate entries */
58392+ if (!already_copied) {
58393+ o_tmp->nested->next = role->hash->first;
58394+ role->hash->first = o_tmp->nested;
58395+ }
58396+ }
58397+ }
58398+
58399+ return 0;
58400+}
58401+
58402+static __u32
58403+count_user_subjs(struct acl_subject_label *userp)
58404+{
58405+ struct acl_subject_label s_tmp;
58406+ __u32 num = 0;
58407+
58408+ while (userp) {
58409+ if (copy_from_user(&s_tmp, userp,
58410+ sizeof (struct acl_subject_label)))
58411+ break;
58412+
58413+ userp = s_tmp.prev;
58414+ }
58415+
58416+ return num;
58417+}
58418+
58419+static int
58420+copy_user_allowedips(struct acl_role_label *rolep)
58421+{
58422+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
58423+
58424+ ruserip = rolep->allowed_ips;
58425+
58426+ while (ruserip) {
58427+ rlast = rtmp;
58428+
58429+ if ((rtmp = (struct role_allowed_ip *)
58430+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
58431+ return -ENOMEM;
58432+
58433+ if (copy_from_user(rtmp, ruserip,
58434+ sizeof (struct role_allowed_ip)))
58435+ return -EFAULT;
58436+
58437+ ruserip = rtmp->prev;
58438+
58439+ if (!rlast) {
58440+ rtmp->prev = NULL;
58441+ rolep->allowed_ips = rtmp;
58442+ } else {
58443+ rlast->next = rtmp;
58444+ rtmp->prev = rlast;
58445+ }
58446+
58447+ if (!ruserip)
58448+ rtmp->next = NULL;
58449+ }
58450+
58451+ return 0;
58452+}
58453+
58454+static int
58455+copy_user_transitions(struct acl_role_label *rolep)
58456+{
58457+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
58458+
58459+ unsigned int len;
58460+ char *tmp;
58461+
58462+ rusertp = rolep->transitions;
58463+
58464+ while (rusertp) {
58465+ rlast = rtmp;
58466+
58467+ if ((rtmp = (struct role_transition *)
58468+ acl_alloc(sizeof (struct role_transition))) == NULL)
58469+ return -ENOMEM;
58470+
58471+ if (copy_from_user(rtmp, rusertp,
58472+ sizeof (struct role_transition)))
58473+ return -EFAULT;
58474+
58475+ rusertp = rtmp->prev;
58476+
58477+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
58478+
58479+ if (!len || len >= GR_SPROLE_LEN)
58480+ return -EINVAL;
58481+
58482+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58483+ return -ENOMEM;
58484+
58485+ if (copy_from_user(tmp, rtmp->rolename, len))
58486+ return -EFAULT;
58487+ tmp[len-1] = '\0';
58488+ rtmp->rolename = tmp;
58489+
58490+ if (!rlast) {
58491+ rtmp->prev = NULL;
58492+ rolep->transitions = rtmp;
58493+ } else {
58494+ rlast->next = rtmp;
58495+ rtmp->prev = rlast;
58496+ }
58497+
58498+ if (!rusertp)
58499+ rtmp->next = NULL;
58500+ }
58501+
58502+ return 0;
58503+}
58504+
58505+static struct acl_subject_label *
58506+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58507+{
58508+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58509+ unsigned int len;
58510+ char *tmp;
58511+ __u32 num_objs;
58512+ struct acl_ip_label **i_tmp, *i_utmp2;
58513+ struct gr_hash_struct ghash;
58514+ struct subject_map *subjmap;
58515+ unsigned int i_num;
58516+ int err;
58517+
58518+ if (already_copied != NULL)
58519+ *already_copied = 0;
58520+
58521+ s_tmp = lookup_subject_map(userp);
58522+
58523+ /* we've already copied this subject into the kernel, just return
58524+ the reference to it, and don't copy it over again
58525+ */
58526+ if (s_tmp) {
58527+ if (already_copied != NULL)
58528+ *already_copied = 1;
58529+ return(s_tmp);
58530+ }
58531+
58532+ if ((s_tmp = (struct acl_subject_label *)
58533+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58534+ return ERR_PTR(-ENOMEM);
58535+
58536+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58537+ if (subjmap == NULL)
58538+ return ERR_PTR(-ENOMEM);
58539+
58540+ subjmap->user = userp;
58541+ subjmap->kernel = s_tmp;
58542+ insert_subj_map_entry(subjmap);
58543+
58544+ if (copy_from_user(s_tmp, userp,
58545+ sizeof (struct acl_subject_label)))
58546+ return ERR_PTR(-EFAULT);
58547+
58548+ len = strnlen_user(s_tmp->filename, PATH_MAX);
58549+
58550+ if (!len || len >= PATH_MAX)
58551+ return ERR_PTR(-EINVAL);
58552+
58553+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58554+ return ERR_PTR(-ENOMEM);
58555+
58556+ if (copy_from_user(tmp, s_tmp->filename, len))
58557+ return ERR_PTR(-EFAULT);
58558+ tmp[len-1] = '\0';
58559+ s_tmp->filename = tmp;
58560+
58561+ if (!strcmp(s_tmp->filename, "/"))
58562+ role->root_label = s_tmp;
58563+
58564+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58565+ return ERR_PTR(-EFAULT);
58566+
58567+ /* copy user and group transition tables */
58568+
58569+ if (s_tmp->user_trans_num) {
58570+ uid_t *uidlist;
58571+
58572+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58573+ if (uidlist == NULL)
58574+ return ERR_PTR(-ENOMEM);
58575+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58576+ return ERR_PTR(-EFAULT);
58577+
58578+ s_tmp->user_transitions = uidlist;
58579+ }
58580+
58581+ if (s_tmp->group_trans_num) {
58582+ gid_t *gidlist;
58583+
58584+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58585+ if (gidlist == NULL)
58586+ return ERR_PTR(-ENOMEM);
58587+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58588+ return ERR_PTR(-EFAULT);
58589+
58590+ s_tmp->group_transitions = gidlist;
58591+ }
58592+
58593+ /* set up object hash table */
58594+ num_objs = count_user_objs(ghash.first);
58595+
58596+ s_tmp->obj_hash_size = num_objs;
58597+ s_tmp->obj_hash =
58598+ (struct acl_object_label **)
58599+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58600+
58601+ if (!s_tmp->obj_hash)
58602+ return ERR_PTR(-ENOMEM);
58603+
58604+ memset(s_tmp->obj_hash, 0,
58605+ s_tmp->obj_hash_size *
58606+ sizeof (struct acl_object_label *));
58607+
58608+ /* add in objects */
58609+ err = copy_user_objs(ghash.first, s_tmp, role);
58610+
58611+ if (err)
58612+ return ERR_PTR(err);
58613+
58614+ /* set pointer for parent subject */
58615+ if (s_tmp->parent_subject) {
58616+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58617+
58618+ if (IS_ERR(s_tmp2))
58619+ return s_tmp2;
58620+
58621+ s_tmp->parent_subject = s_tmp2;
58622+ }
58623+
58624+ /* add in ip acls */
58625+
58626+ if (!s_tmp->ip_num) {
58627+ s_tmp->ips = NULL;
58628+ goto insert;
58629+ }
58630+
58631+ i_tmp =
58632+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58633+ sizeof (struct acl_ip_label *));
58634+
58635+ if (!i_tmp)
58636+ return ERR_PTR(-ENOMEM);
58637+
58638+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58639+ *(i_tmp + i_num) =
58640+ (struct acl_ip_label *)
58641+ acl_alloc(sizeof (struct acl_ip_label));
58642+ if (!*(i_tmp + i_num))
58643+ return ERR_PTR(-ENOMEM);
58644+
58645+ if (copy_from_user
58646+ (&i_utmp2, s_tmp->ips + i_num,
58647+ sizeof (struct acl_ip_label *)))
58648+ return ERR_PTR(-EFAULT);
58649+
58650+ if (copy_from_user
58651+ (*(i_tmp + i_num), i_utmp2,
58652+ sizeof (struct acl_ip_label)))
58653+ return ERR_PTR(-EFAULT);
58654+
58655+ if ((*(i_tmp + i_num))->iface == NULL)
58656+ continue;
58657+
58658+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58659+ if (!len || len >= IFNAMSIZ)
58660+ return ERR_PTR(-EINVAL);
58661+ tmp = acl_alloc(len);
58662+ if (tmp == NULL)
58663+ return ERR_PTR(-ENOMEM);
58664+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58665+ return ERR_PTR(-EFAULT);
58666+ (*(i_tmp + i_num))->iface = tmp;
58667+ }
58668+
58669+ s_tmp->ips = i_tmp;
58670+
58671+insert:
58672+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58673+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58674+ return ERR_PTR(-ENOMEM);
58675+
58676+ return s_tmp;
58677+}
58678+
58679+static int
58680+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58681+{
58682+ struct acl_subject_label s_pre;
58683+ struct acl_subject_label * ret;
58684+ int err;
58685+
58686+ while (userp) {
58687+ if (copy_from_user(&s_pre, userp,
58688+ sizeof (struct acl_subject_label)))
58689+ return -EFAULT;
58690+
58691+ ret = do_copy_user_subj(userp, role, NULL);
58692+
58693+ err = PTR_ERR(ret);
58694+ if (IS_ERR(ret))
58695+ return err;
58696+
58697+ insert_acl_subj_label(ret, role);
58698+
58699+ userp = s_pre.prev;
58700+ }
58701+
58702+ return 0;
58703+}
58704+
58705+static int
58706+copy_user_acl(struct gr_arg *arg)
58707+{
58708+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58709+ struct acl_subject_label *subj_list;
58710+ struct sprole_pw *sptmp;
58711+ struct gr_hash_struct *ghash;
58712+ uid_t *domainlist;
58713+ unsigned int r_num;
58714+ unsigned int len;
58715+ char *tmp;
58716+ int err = 0;
58717+ __u16 i;
58718+ __u32 num_subjs;
58719+
58720+ /* we need a default and kernel role */
58721+ if (arg->role_db.num_roles < 2)
58722+ return -EINVAL;
58723+
58724+ /* copy special role authentication info from userspace */
58725+
58726+ num_sprole_pws = arg->num_sprole_pws;
58727+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58728+
58729+ if (!acl_special_roles && num_sprole_pws)
58730+ return -ENOMEM;
58731+
58732+ for (i = 0; i < num_sprole_pws; i++) {
58733+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58734+ if (!sptmp)
58735+ return -ENOMEM;
58736+ if (copy_from_user(sptmp, arg->sprole_pws + i,
58737+ sizeof (struct sprole_pw)))
58738+ return -EFAULT;
58739+
58740+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58741+
58742+ if (!len || len >= GR_SPROLE_LEN)
58743+ return -EINVAL;
58744+
58745+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58746+ return -ENOMEM;
58747+
58748+ if (copy_from_user(tmp, sptmp->rolename, len))
58749+ return -EFAULT;
58750+
58751+ tmp[len-1] = '\0';
58752+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58753+ printk(KERN_ALERT "Copying special role %s\n", tmp);
58754+#endif
58755+ sptmp->rolename = tmp;
58756+ acl_special_roles[i] = sptmp;
58757+ }
58758+
58759+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58760+
58761+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58762+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
58763+
58764+ if (!r_tmp)
58765+ return -ENOMEM;
58766+
58767+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
58768+ sizeof (struct acl_role_label *)))
58769+ return -EFAULT;
58770+
58771+ if (copy_from_user(r_tmp, r_utmp2,
58772+ sizeof (struct acl_role_label)))
58773+ return -EFAULT;
58774+
58775+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58776+
58777+ if (!len || len >= PATH_MAX)
58778+ return -EINVAL;
58779+
58780+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58781+ return -ENOMEM;
58782+
58783+ if (copy_from_user(tmp, r_tmp->rolename, len))
58784+ return -EFAULT;
58785+
58786+ tmp[len-1] = '\0';
58787+ r_tmp->rolename = tmp;
58788+
58789+ if (!strcmp(r_tmp->rolename, "default")
58790+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58791+ default_role = r_tmp;
58792+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58793+ kernel_role = r_tmp;
58794+ }
58795+
58796+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58797+ return -ENOMEM;
58798+
58799+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58800+ return -EFAULT;
58801+
58802+ r_tmp->hash = ghash;
58803+
58804+ num_subjs = count_user_subjs(r_tmp->hash->first);
58805+
58806+ r_tmp->subj_hash_size = num_subjs;
58807+ r_tmp->subj_hash =
58808+ (struct acl_subject_label **)
58809+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58810+
58811+ if (!r_tmp->subj_hash)
58812+ return -ENOMEM;
58813+
58814+ err = copy_user_allowedips(r_tmp);
58815+ if (err)
58816+ return err;
58817+
58818+ /* copy domain info */
58819+ if (r_tmp->domain_children != NULL) {
58820+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58821+ if (domainlist == NULL)
58822+ return -ENOMEM;
58823+
58824+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58825+ return -EFAULT;
58826+
58827+ r_tmp->domain_children = domainlist;
58828+ }
58829+
58830+ err = copy_user_transitions(r_tmp);
58831+ if (err)
58832+ return err;
58833+
58834+ memset(r_tmp->subj_hash, 0,
58835+ r_tmp->subj_hash_size *
58836+ sizeof (struct acl_subject_label *));
58837+
58838+ /* acquire the list of subjects, then NULL out
58839+ the list prior to parsing the subjects for this role,
58840+ as during this parsing the list is replaced with a list
58841+ of *nested* subjects for the role
58842+ */
58843+ subj_list = r_tmp->hash->first;
58844+
58845+ /* set nested subject list to null */
58846+ r_tmp->hash->first = NULL;
58847+
58848+ err = copy_user_subjs(subj_list, r_tmp);
58849+
58850+ if (err)
58851+ return err;
58852+
58853+ insert_acl_role_label(r_tmp);
58854+ }
58855+
58856+ if (default_role == NULL || kernel_role == NULL)
58857+ return -EINVAL;
58858+
58859+ return err;
58860+}
58861+
58862+static int
58863+gracl_init(struct gr_arg *args)
58864+{
58865+ int error = 0;
58866+
58867+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58868+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58869+
58870+ if (init_variables(args)) {
58871+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58872+ error = -ENOMEM;
58873+ free_variables();
58874+ goto out;
58875+ }
58876+
58877+ error = copy_user_acl(args);
58878+ free_init_variables();
58879+ if (error) {
58880+ free_variables();
58881+ goto out;
58882+ }
58883+
58884+ if ((error = gr_set_acls(0))) {
58885+ free_variables();
58886+ goto out;
58887+ }
58888+
58889+ pax_open_kernel();
58890+ gr_status |= GR_READY;
58891+ pax_close_kernel();
58892+
58893+ out:
58894+ return error;
58895+}
58896+
58897+/* derived from glibc fnmatch() 0: match, 1: no match*/
58898+
58899+static int
58900+glob_match(const char *p, const char *n)
58901+{
58902+ char c;
58903+
58904+ while ((c = *p++) != '\0') {
58905+ switch (c) {
58906+ case '?':
58907+ if (*n == '\0')
58908+ return 1;
58909+ else if (*n == '/')
58910+ return 1;
58911+ break;
58912+ case '\\':
58913+ if (*n != c)
58914+ return 1;
58915+ break;
58916+ case '*':
58917+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
58918+ if (*n == '/')
58919+ return 1;
58920+ else if (c == '?') {
58921+ if (*n == '\0')
58922+ return 1;
58923+ else
58924+ ++n;
58925+ }
58926+ }
58927+ if (c == '\0') {
58928+ return 0;
58929+ } else {
58930+ const char *endp;
58931+
58932+ if ((endp = strchr(n, '/')) == NULL)
58933+ endp = n + strlen(n);
58934+
58935+ if (c == '[') {
58936+ for (--p; n < endp; ++n)
58937+ if (!glob_match(p, n))
58938+ return 0;
58939+ } else if (c == '/') {
58940+ while (*n != '\0' && *n != '/')
58941+ ++n;
58942+ if (*n == '/' && !glob_match(p, n + 1))
58943+ return 0;
58944+ } else {
58945+ for (--p; n < endp; ++n)
58946+ if (*n == c && !glob_match(p, n))
58947+ return 0;
58948+ }
58949+
58950+ return 1;
58951+ }
58952+ case '[':
58953+ {
58954+ int not;
58955+ char cold;
58956+
58957+ if (*n == '\0' || *n == '/')
58958+ return 1;
58959+
58960+ not = (*p == '!' || *p == '^');
58961+ if (not)
58962+ ++p;
58963+
58964+ c = *p++;
58965+ for (;;) {
58966+ unsigned char fn = (unsigned char)*n;
58967+
58968+ if (c == '\0')
58969+ return 1;
58970+ else {
58971+ if (c == fn)
58972+ goto matched;
58973+ cold = c;
58974+ c = *p++;
58975+
58976+ if (c == '-' && *p != ']') {
58977+ unsigned char cend = *p++;
58978+
58979+ if (cend == '\0')
58980+ return 1;
58981+
58982+ if (cold <= fn && fn <= cend)
58983+ goto matched;
58984+
58985+ c = *p++;
58986+ }
58987+ }
58988+
58989+ if (c == ']')
58990+ break;
58991+ }
58992+ if (!not)
58993+ return 1;
58994+ break;
58995+ matched:
58996+ while (c != ']') {
58997+ if (c == '\0')
58998+ return 1;
58999+
59000+ c = *p++;
59001+ }
59002+ if (not)
59003+ return 1;
59004+ }
59005+ break;
59006+ default:
59007+ if (c != *n)
59008+ return 1;
59009+ }
59010+
59011+ ++n;
59012+ }
59013+
59014+ if (*n == '\0')
59015+ return 0;
59016+
59017+ if (*n == '/')
59018+ return 0;
59019+
59020+ return 1;
59021+}
59022+
59023+static struct acl_object_label *
59024+chk_glob_label(struct acl_object_label *globbed,
59025+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59026+{
59027+ struct acl_object_label *tmp;
59028+
59029+ if (*path == NULL)
59030+ *path = gr_to_filename_nolock(dentry, mnt);
59031+
59032+ tmp = globbed;
59033+
59034+ while (tmp) {
59035+ if (!glob_match(tmp->filename, *path))
59036+ return tmp;
59037+ tmp = tmp->next;
59038+ }
59039+
59040+ return NULL;
59041+}
59042+
59043+static struct acl_object_label *
59044+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59045+ const ino_t curr_ino, const dev_t curr_dev,
59046+ const struct acl_subject_label *subj, char **path, const int checkglob)
59047+{
59048+ struct acl_subject_label *tmpsubj;
59049+ struct acl_object_label *retval;
59050+ struct acl_object_label *retval2;
59051+
59052+ tmpsubj = (struct acl_subject_label *) subj;
59053+ read_lock(&gr_inode_lock);
59054+ do {
59055+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59056+ if (retval) {
59057+ if (checkglob && retval->globbed) {
59058+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
59059+ if (retval2)
59060+ retval = retval2;
59061+ }
59062+ break;
59063+ }
59064+ } while ((tmpsubj = tmpsubj->parent_subject));
59065+ read_unlock(&gr_inode_lock);
59066+
59067+ return retval;
59068+}
59069+
59070+static __inline__ struct acl_object_label *
59071+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59072+ struct dentry *curr_dentry,
59073+ const struct acl_subject_label *subj, char **path, const int checkglob)
59074+{
59075+ int newglob = checkglob;
59076+ ino_t inode;
59077+ dev_t device;
59078+
59079+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
59080+ as we don't want a / * rule to match instead of the / object
59081+ don't do this for create lookups that call this function though, since they're looking up
59082+ on the parent and thus need globbing checks on all paths
59083+ */
59084+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
59085+ newglob = GR_NO_GLOB;
59086+
59087+ spin_lock(&curr_dentry->d_lock);
59088+ inode = curr_dentry->d_inode->i_ino;
59089+ device = __get_dev(curr_dentry);
59090+ spin_unlock(&curr_dentry->d_lock);
59091+
59092+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
59093+}
59094+
59095+#ifdef CONFIG_HUGETLBFS
59096+static inline bool
59097+is_hugetlbfs_mnt(const struct vfsmount *mnt)
59098+{
59099+ int i;
59100+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
59101+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
59102+ return true;
59103+ }
59104+
59105+ return false;
59106+}
59107+#endif
59108+
59109+static struct acl_object_label *
59110+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59111+ const struct acl_subject_label *subj, char *path, const int checkglob)
59112+{
59113+ struct dentry *dentry = (struct dentry *) l_dentry;
59114+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59115+ struct mount *real_mnt = real_mount(mnt);
59116+ struct acl_object_label *retval;
59117+ struct dentry *parent;
59118+
59119+ write_seqlock(&rename_lock);
59120+ br_read_lock(&vfsmount_lock);
59121+
59122+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
59123+#ifdef CONFIG_NET
59124+ mnt == sock_mnt ||
59125+#endif
59126+#ifdef CONFIG_HUGETLBFS
59127+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
59128+#endif
59129+ /* ignore Eric Biederman */
59130+ IS_PRIVATE(l_dentry->d_inode))) {
59131+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
59132+ goto out;
59133+ }
59134+
59135+ for (;;) {
59136+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59137+ break;
59138+
59139+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59140+ if (!mnt_has_parent(real_mnt))
59141+ break;
59142+
59143+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59144+ if (retval != NULL)
59145+ goto out;
59146+
59147+ dentry = real_mnt->mnt_mountpoint;
59148+ real_mnt = real_mnt->mnt_parent;
59149+ mnt = &real_mnt->mnt;
59150+ continue;
59151+ }
59152+
59153+ parent = dentry->d_parent;
59154+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59155+ if (retval != NULL)
59156+ goto out;
59157+
59158+ dentry = parent;
59159+ }
59160+
59161+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59162+
59163+ /* real_root is pinned so we don't have to hold a reference */
59164+ if (retval == NULL)
59165+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
59166+out:
59167+ br_read_unlock(&vfsmount_lock);
59168+ write_sequnlock(&rename_lock);
59169+
59170+ BUG_ON(retval == NULL);
59171+
59172+ return retval;
59173+}
59174+
59175+static __inline__ struct acl_object_label *
59176+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59177+ const struct acl_subject_label *subj)
59178+{
59179+ char *path = NULL;
59180+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
59181+}
59182+
59183+static __inline__ struct acl_object_label *
59184+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59185+ const struct acl_subject_label *subj)
59186+{
59187+ char *path = NULL;
59188+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
59189+}
59190+
59191+static __inline__ struct acl_object_label *
59192+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59193+ const struct acl_subject_label *subj, char *path)
59194+{
59195+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
59196+}
59197+
59198+static struct acl_subject_label *
59199+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59200+ const struct acl_role_label *role)
59201+{
59202+ struct dentry *dentry = (struct dentry *) l_dentry;
59203+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59204+ struct mount *real_mnt = real_mount(mnt);
59205+ struct acl_subject_label *retval;
59206+ struct dentry *parent;
59207+
59208+ write_seqlock(&rename_lock);
59209+ br_read_lock(&vfsmount_lock);
59210+
59211+ for (;;) {
59212+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59213+ break;
59214+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59215+ if (!mnt_has_parent(real_mnt))
59216+ break;
59217+
59218+ spin_lock(&dentry->d_lock);
59219+ read_lock(&gr_inode_lock);
59220+ retval =
59221+ lookup_acl_subj_label(dentry->d_inode->i_ino,
59222+ __get_dev(dentry), role);
59223+ read_unlock(&gr_inode_lock);
59224+ spin_unlock(&dentry->d_lock);
59225+ if (retval != NULL)
59226+ goto out;
59227+
59228+ dentry = real_mnt->mnt_mountpoint;
59229+ real_mnt = real_mnt->mnt_parent;
59230+ mnt = &real_mnt->mnt;
59231+ continue;
59232+ }
59233+
59234+ spin_lock(&dentry->d_lock);
59235+ read_lock(&gr_inode_lock);
59236+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59237+ __get_dev(dentry), role);
59238+ read_unlock(&gr_inode_lock);
59239+ parent = dentry->d_parent;
59240+ spin_unlock(&dentry->d_lock);
59241+
59242+ if (retval != NULL)
59243+ goto out;
59244+
59245+ dentry = parent;
59246+ }
59247+
59248+ spin_lock(&dentry->d_lock);
59249+ read_lock(&gr_inode_lock);
59250+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59251+ __get_dev(dentry), role);
59252+ read_unlock(&gr_inode_lock);
59253+ spin_unlock(&dentry->d_lock);
59254+
59255+ if (unlikely(retval == NULL)) {
59256+ /* real_root is pinned, we don't need to hold a reference */
59257+ read_lock(&gr_inode_lock);
59258+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
59259+ __get_dev(real_root.dentry), role);
59260+ read_unlock(&gr_inode_lock);
59261+ }
59262+out:
59263+ br_read_unlock(&vfsmount_lock);
59264+ write_sequnlock(&rename_lock);
59265+
59266+ BUG_ON(retval == NULL);
59267+
59268+ return retval;
59269+}
59270+
59271+static void
59272+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
59273+{
59274+ struct task_struct *task = current;
59275+ const struct cred *cred = current_cred();
59276+
59277+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
59278+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59279+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59280+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
59281+
59282+ return;
59283+}
59284+
59285+static void
59286+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
59287+{
59288+ struct task_struct *task = current;
59289+ const struct cred *cred = current_cred();
59290+
59291+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59292+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59293+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59294+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
59295+
59296+ return;
59297+}
59298+
59299+static void
59300+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
59301+{
59302+ struct task_struct *task = current;
59303+ const struct cred *cred = current_cred();
59304+
59305+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59306+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59307+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59308+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
59309+
59310+ return;
59311+}
59312+
59313+__u32
59314+gr_search_file(const struct dentry * dentry, const __u32 mode,
59315+ const struct vfsmount * mnt)
59316+{
59317+ __u32 retval = mode;
59318+ struct acl_subject_label *curracl;
59319+ struct acl_object_label *currobj;
59320+
59321+ if (unlikely(!(gr_status & GR_READY)))
59322+ return (mode & ~GR_AUDITS);
59323+
59324+ curracl = current->acl;
59325+
59326+ currobj = chk_obj_label(dentry, mnt, curracl);
59327+ retval = currobj->mode & mode;
59328+
59329+ /* if we're opening a specified transfer file for writing
59330+ (e.g. /dev/initctl), then transfer our role to init
59331+ */
59332+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
59333+ current->role->roletype & GR_ROLE_PERSIST)) {
59334+ struct task_struct *task = init_pid_ns.child_reaper;
59335+
59336+ if (task->role != current->role) {
59337+ task->acl_sp_role = 0;
59338+ task->acl_role_id = current->acl_role_id;
59339+ task->role = current->role;
59340+ rcu_read_lock();
59341+ read_lock(&grsec_exec_file_lock);
59342+ gr_apply_subject_to_task(task);
59343+ read_unlock(&grsec_exec_file_lock);
59344+ rcu_read_unlock();
59345+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
59346+ }
59347+ }
59348+
59349+ if (unlikely
59350+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
59351+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
59352+ __u32 new_mode = mode;
59353+
59354+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59355+
59356+ retval = new_mode;
59357+
59358+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
59359+ new_mode |= GR_INHERIT;
59360+
59361+ if (!(mode & GR_NOLEARN))
59362+ gr_log_learn(dentry, mnt, new_mode);
59363+ }
59364+
59365+ return retval;
59366+}
59367+
59368+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
59369+ const struct dentry *parent,
59370+ const struct vfsmount *mnt)
59371+{
59372+ struct name_entry *match;
59373+ struct acl_object_label *matchpo;
59374+ struct acl_subject_label *curracl;
59375+ char *path;
59376+
59377+ if (unlikely(!(gr_status & GR_READY)))
59378+ return NULL;
59379+
59380+ preempt_disable();
59381+ path = gr_to_filename_rbac(new_dentry, mnt);
59382+ match = lookup_name_entry_create(path);
59383+
59384+ curracl = current->acl;
59385+
59386+ if (match) {
59387+ read_lock(&gr_inode_lock);
59388+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
59389+ read_unlock(&gr_inode_lock);
59390+
59391+ if (matchpo) {
59392+ preempt_enable();
59393+ return matchpo;
59394+ }
59395+ }
59396+
59397+ // lookup parent
59398+
59399+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
59400+
59401+ preempt_enable();
59402+ return matchpo;
59403+}
59404+
59405+__u32
59406+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
59407+ const struct vfsmount * mnt, const __u32 mode)
59408+{
59409+ struct acl_object_label *matchpo;
59410+ __u32 retval;
59411+
59412+ if (unlikely(!(gr_status & GR_READY)))
59413+ return (mode & ~GR_AUDITS);
59414+
59415+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
59416+
59417+ retval = matchpo->mode & mode;
59418+
59419+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
59420+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59421+ __u32 new_mode = mode;
59422+
59423+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59424+
59425+ gr_log_learn(new_dentry, mnt, new_mode);
59426+ return new_mode;
59427+ }
59428+
59429+ return retval;
59430+}
59431+
59432+__u32
59433+gr_check_link(const struct dentry * new_dentry,
59434+ const struct dentry * parent_dentry,
59435+ const struct vfsmount * parent_mnt,
59436+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
59437+{
59438+ struct acl_object_label *obj;
59439+ __u32 oldmode, newmode;
59440+ __u32 needmode;
59441+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
59442+ GR_DELETE | GR_INHERIT;
59443+
59444+ if (unlikely(!(gr_status & GR_READY)))
59445+ return (GR_CREATE | GR_LINK);
59446+
59447+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
59448+ oldmode = obj->mode;
59449+
59450+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
59451+ newmode = obj->mode;
59452+
59453+ needmode = newmode & checkmodes;
59454+
59455+ // old name for hardlink must have at least the permissions of the new name
59456+ if ((oldmode & needmode) != needmode)
59457+ goto bad;
59458+
59459+ // if old name had restrictions/auditing, make sure the new name does as well
59460+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
59461+
59462+ // don't allow hardlinking of suid/sgid/fcapped files without permission
59463+ if (is_privileged_binary(old_dentry))
59464+ needmode |= GR_SETID;
59465+
59466+ if ((newmode & needmode) != needmode)
59467+ goto bad;
59468+
59469+ // enforce minimum permissions
59470+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
59471+ return newmode;
59472+bad:
59473+ needmode = oldmode;
59474+ if (is_privileged_binary(old_dentry))
59475+ needmode |= GR_SETID;
59476+
59477+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
59478+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
59479+ return (GR_CREATE | GR_LINK);
59480+ } else if (newmode & GR_SUPPRESS)
59481+ return GR_SUPPRESS;
59482+ else
59483+ return 0;
59484+}
59485+
59486+int
59487+gr_check_hidden_task(const struct task_struct *task)
59488+{
59489+ if (unlikely(!(gr_status & GR_READY)))
59490+ return 0;
59491+
59492+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59493+ return 1;
59494+
59495+ return 0;
59496+}
59497+
59498+int
59499+gr_check_protected_task(const struct task_struct *task)
59500+{
59501+ if (unlikely(!(gr_status & GR_READY) || !task))
59502+ return 0;
59503+
59504+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59505+ task->acl != current->acl)
59506+ return 1;
59507+
59508+ return 0;
59509+}
59510+
59511+int
59512+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59513+{
59514+ struct task_struct *p;
59515+ int ret = 0;
59516+
59517+ if (unlikely(!(gr_status & GR_READY) || !pid))
59518+ return ret;
59519+
59520+ read_lock(&tasklist_lock);
59521+ do_each_pid_task(pid, type, p) {
59522+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59523+ p->acl != current->acl) {
59524+ ret = 1;
59525+ goto out;
59526+ }
59527+ } while_each_pid_task(pid, type, p);
59528+out:
59529+ read_unlock(&tasklist_lock);
59530+
59531+ return ret;
59532+}
59533+
59534+void
59535+gr_copy_label(struct task_struct *tsk)
59536+{
59537+ tsk->signal->used_accept = 0;
59538+ tsk->acl_sp_role = 0;
59539+ tsk->acl_role_id = current->acl_role_id;
59540+ tsk->acl = current->acl;
59541+ tsk->role = current->role;
59542+ tsk->signal->curr_ip = current->signal->curr_ip;
59543+ tsk->signal->saved_ip = current->signal->saved_ip;
59544+ if (current->exec_file)
59545+ get_file(current->exec_file);
59546+ tsk->exec_file = current->exec_file;
59547+ tsk->is_writable = current->is_writable;
59548+ if (unlikely(current->signal->used_accept)) {
59549+ current->signal->curr_ip = 0;
59550+ current->signal->saved_ip = 0;
59551+ }
59552+
59553+ return;
59554+}
59555+
59556+static void
59557+gr_set_proc_res(struct task_struct *task)
59558+{
59559+ struct acl_subject_label *proc;
59560+ unsigned short i;
59561+
59562+ proc = task->acl;
59563+
59564+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59565+ return;
59566+
59567+ for (i = 0; i < RLIM_NLIMITS; i++) {
59568+ if (!(proc->resmask & (1 << i)))
59569+ continue;
59570+
59571+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59572+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59573+
59574+ if (i == RLIMIT_CPU)
59575+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
59576+ }
59577+
59578+ return;
59579+}
59580+
59581+extern int __gr_process_user_ban(struct user_struct *user);
59582+
59583+int
59584+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59585+{
59586+ unsigned int i;
59587+ __u16 num;
59588+ uid_t *uidlist;
59589+ uid_t curuid;
59590+ int realok = 0;
59591+ int effectiveok = 0;
59592+ int fsok = 0;
59593+ uid_t globalreal, globaleffective, globalfs;
59594+
59595+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59596+ struct user_struct *user;
59597+
59598+ if (!uid_valid(real))
59599+ goto skipit;
59600+
59601+ /* find user based on global namespace */
59602+
59603+ globalreal = GR_GLOBAL_UID(real);
59604+
59605+ user = find_user(make_kuid(&init_user_ns, globalreal));
59606+ if (user == NULL)
59607+ goto skipit;
59608+
59609+ if (__gr_process_user_ban(user)) {
59610+ /* for find_user */
59611+ free_uid(user);
59612+ return 1;
59613+ }
59614+
59615+ /* for find_user */
59616+ free_uid(user);
59617+
59618+skipit:
59619+#endif
59620+
59621+ if (unlikely(!(gr_status & GR_READY)))
59622+ return 0;
59623+
59624+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59625+ gr_log_learn_uid_change(real, effective, fs);
59626+
59627+ num = current->acl->user_trans_num;
59628+ uidlist = current->acl->user_transitions;
59629+
59630+ if (uidlist == NULL)
59631+ return 0;
59632+
59633+ if (!uid_valid(real)) {
59634+ realok = 1;
59635+ globalreal = (uid_t)-1;
59636+ } else {
59637+ globalreal = GR_GLOBAL_UID(real);
59638+ }
59639+ if (!uid_valid(effective)) {
59640+ effectiveok = 1;
59641+ globaleffective = (uid_t)-1;
59642+ } else {
59643+ globaleffective = GR_GLOBAL_UID(effective);
59644+ }
59645+ if (!uid_valid(fs)) {
59646+ fsok = 1;
59647+ globalfs = (uid_t)-1;
59648+ } else {
59649+ globalfs = GR_GLOBAL_UID(fs);
59650+ }
59651+
59652+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
59653+ for (i = 0; i < num; i++) {
59654+ curuid = uidlist[i];
59655+ if (globalreal == curuid)
59656+ realok = 1;
59657+ if (globaleffective == curuid)
59658+ effectiveok = 1;
59659+ if (globalfs == curuid)
59660+ fsok = 1;
59661+ }
59662+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
59663+ for (i = 0; i < num; i++) {
59664+ curuid = uidlist[i];
59665+ if (globalreal == curuid)
59666+ break;
59667+ if (globaleffective == curuid)
59668+ break;
59669+ if (globalfs == curuid)
59670+ break;
59671+ }
59672+ /* not in deny list */
59673+ if (i == num) {
59674+ realok = 1;
59675+ effectiveok = 1;
59676+ fsok = 1;
59677+ }
59678+ }
59679+
59680+ if (realok && effectiveok && fsok)
59681+ return 0;
59682+ else {
59683+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59684+ return 1;
59685+ }
59686+}
59687+
59688+int
59689+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59690+{
59691+ unsigned int i;
59692+ __u16 num;
59693+ gid_t *gidlist;
59694+ gid_t curgid;
59695+ int realok = 0;
59696+ int effectiveok = 0;
59697+ int fsok = 0;
59698+ gid_t globalreal, globaleffective, globalfs;
59699+
59700+ if (unlikely(!(gr_status & GR_READY)))
59701+ return 0;
59702+
59703+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59704+ gr_log_learn_gid_change(real, effective, fs);
59705+
59706+ num = current->acl->group_trans_num;
59707+ gidlist = current->acl->group_transitions;
59708+
59709+ if (gidlist == NULL)
59710+ return 0;
59711+
59712+ if (!gid_valid(real)) {
59713+ realok = 1;
59714+ globalreal = (gid_t)-1;
59715+ } else {
59716+ globalreal = GR_GLOBAL_GID(real);
59717+ }
59718+ if (!gid_valid(effective)) {
59719+ effectiveok = 1;
59720+ globaleffective = (gid_t)-1;
59721+ } else {
59722+ globaleffective = GR_GLOBAL_GID(effective);
59723+ }
59724+ if (!gid_valid(fs)) {
59725+ fsok = 1;
59726+ globalfs = (gid_t)-1;
59727+ } else {
59728+ globalfs = GR_GLOBAL_GID(fs);
59729+ }
59730+
59731+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
59732+ for (i = 0; i < num; i++) {
59733+ curgid = gidlist[i];
59734+ if (globalreal == curgid)
59735+ realok = 1;
59736+ if (globaleffective == curgid)
59737+ effectiveok = 1;
59738+ if (globalfs == curgid)
59739+ fsok = 1;
59740+ }
59741+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
59742+ for (i = 0; i < num; i++) {
59743+ curgid = gidlist[i];
59744+ if (globalreal == curgid)
59745+ break;
59746+ if (globaleffective == curgid)
59747+ break;
59748+ if (globalfs == curgid)
59749+ break;
59750+ }
59751+ /* not in deny list */
59752+ if (i == num) {
59753+ realok = 1;
59754+ effectiveok = 1;
59755+ fsok = 1;
59756+ }
59757+ }
59758+
59759+ if (realok && effectiveok && fsok)
59760+ return 0;
59761+ else {
59762+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59763+ return 1;
59764+ }
59765+}
59766+
59767+extern int gr_acl_is_capable(const int cap);
59768+
59769+void
59770+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59771+{
59772+ struct acl_role_label *role = task->role;
59773+ struct acl_subject_label *subj = NULL;
59774+ struct acl_object_label *obj;
59775+ struct file *filp;
59776+ uid_t uid;
59777+ gid_t gid;
59778+
59779+ if (unlikely(!(gr_status & GR_READY)))
59780+ return;
59781+
59782+ uid = GR_GLOBAL_UID(kuid);
59783+ gid = GR_GLOBAL_GID(kgid);
59784+
59785+ filp = task->exec_file;
59786+
59787+ /* kernel process, we'll give them the kernel role */
59788+ if (unlikely(!filp)) {
59789+ task->role = kernel_role;
59790+ task->acl = kernel_role->root_label;
59791+ return;
59792+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59793+ role = lookup_acl_role_label(task, uid, gid);
59794+
59795+ /* don't change the role if we're not a privileged process */
59796+ if (role && task->role != role &&
59797+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59798+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59799+ return;
59800+
59801+ /* perform subject lookup in possibly new role
59802+ we can use this result below in the case where role == task->role
59803+ */
59804+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59805+
59806+ /* if we changed uid/gid, but result in the same role
59807+ and are using inheritance, don't lose the inherited subject
59808+ if current subject is other than what normal lookup
59809+ would result in, we arrived via inheritance, don't
59810+ lose subject
59811+ */
59812+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59813+ (subj == task->acl)))
59814+ task->acl = subj;
59815+
59816+ task->role = role;
59817+
59818+ task->is_writable = 0;
59819+
59820+ /* ignore additional mmap checks for processes that are writable
59821+ by the default ACL */
59822+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59823+ if (unlikely(obj->mode & GR_WRITE))
59824+ task->is_writable = 1;
59825+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59826+ if (unlikely(obj->mode & GR_WRITE))
59827+ task->is_writable = 1;
59828+
59829+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59830+ 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);
59831+#endif
59832+
59833+ gr_set_proc_res(task);
59834+
59835+ return;
59836+}
59837+
59838+int
59839+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59840+ const int unsafe_flags)
59841+{
59842+ struct task_struct *task = current;
59843+ struct acl_subject_label *newacl;
59844+ struct acl_object_label *obj;
59845+ __u32 retmode;
59846+
59847+ if (unlikely(!(gr_status & GR_READY)))
59848+ return 0;
59849+
59850+ newacl = chk_subj_label(dentry, mnt, task->role);
59851+
59852+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59853+ did an exec
59854+ */
59855+ rcu_read_lock();
59856+ read_lock(&tasklist_lock);
59857+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59858+ (task->parent->acl->mode & GR_POVERRIDE))) {
59859+ read_unlock(&tasklist_lock);
59860+ rcu_read_unlock();
59861+ goto skip_check;
59862+ }
59863+ read_unlock(&tasklist_lock);
59864+ rcu_read_unlock();
59865+
59866+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59867+ !(task->role->roletype & GR_ROLE_GOD) &&
59868+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59869+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59870+ if (unsafe_flags & LSM_UNSAFE_SHARE)
59871+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59872+ else
59873+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59874+ return -EACCES;
59875+ }
59876+
59877+skip_check:
59878+
59879+ obj = chk_obj_label(dentry, mnt, task->acl);
59880+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59881+
59882+ if (!(task->acl->mode & GR_INHERITLEARN) &&
59883+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59884+ if (obj->nested)
59885+ task->acl = obj->nested;
59886+ else
59887+ task->acl = newacl;
59888+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59889+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59890+
59891+ task->is_writable = 0;
59892+
59893+ /* ignore additional mmap checks for processes that are writable
59894+ by the default ACL */
59895+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
59896+ if (unlikely(obj->mode & GR_WRITE))
59897+ task->is_writable = 1;
59898+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
59899+ if (unlikely(obj->mode & GR_WRITE))
59900+ task->is_writable = 1;
59901+
59902+ gr_set_proc_res(task);
59903+
59904+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59905+ 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);
59906+#endif
59907+ return 0;
59908+}
59909+
59910+/* always called with valid inodev ptr */
59911+static void
59912+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59913+{
59914+ struct acl_object_label *matchpo;
59915+ struct acl_subject_label *matchps;
59916+ struct acl_subject_label *subj;
59917+ struct acl_role_label *role;
59918+ unsigned int x;
59919+
59920+ FOR_EACH_ROLE_START(role)
59921+ FOR_EACH_SUBJECT_START(role, subj, x)
59922+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59923+ matchpo->mode |= GR_DELETED;
59924+ FOR_EACH_SUBJECT_END(subj,x)
59925+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
59926+ /* nested subjects aren't in the role's subj_hash table */
59927+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59928+ matchpo->mode |= GR_DELETED;
59929+ FOR_EACH_NESTED_SUBJECT_END(subj)
59930+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59931+ matchps->mode |= GR_DELETED;
59932+ FOR_EACH_ROLE_END(role)
59933+
59934+ inodev->nentry->deleted = 1;
59935+
59936+ return;
59937+}
59938+
59939+void
59940+gr_handle_delete(const ino_t ino, const dev_t dev)
59941+{
59942+ struct inodev_entry *inodev;
59943+
59944+ if (unlikely(!(gr_status & GR_READY)))
59945+ return;
59946+
59947+ write_lock(&gr_inode_lock);
59948+ inodev = lookup_inodev_entry(ino, dev);
59949+ if (inodev != NULL)
59950+ do_handle_delete(inodev, ino, dev);
59951+ write_unlock(&gr_inode_lock);
59952+
59953+ return;
59954+}
59955+
59956+static void
59957+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59958+ const ino_t newinode, const dev_t newdevice,
59959+ struct acl_subject_label *subj)
59960+{
59961+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59962+ struct acl_object_label *match;
59963+
59964+ match = subj->obj_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+ subj->obj_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_obj_label(match, subj);
59990+ }
59991+
59992+ return;
59993+}
59994+
59995+static void
59996+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
59997+ const ino_t newinode, const dev_t newdevice,
59998+ struct acl_role_label *role)
59999+{
60000+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60001+ struct acl_subject_label *match;
60002+
60003+ match = role->subj_hash[index];
60004+
60005+ while (match && (match->inode != oldinode ||
60006+ match->device != olddevice ||
60007+ !(match->mode & GR_DELETED)))
60008+ match = match->next;
60009+
60010+ if (match && (match->inode == oldinode)
60011+ && (match->device == olddevice)
60012+ && (match->mode & GR_DELETED)) {
60013+ if (match->prev == NULL) {
60014+ role->subj_hash[index] = match->next;
60015+ if (match->next != NULL)
60016+ match->next->prev = NULL;
60017+ } else {
60018+ match->prev->next = match->next;
60019+ if (match->next != NULL)
60020+ match->next->prev = match->prev;
60021+ }
60022+ match->prev = NULL;
60023+ match->next = NULL;
60024+ match->inode = newinode;
60025+ match->device = newdevice;
60026+ match->mode &= ~GR_DELETED;
60027+
60028+ insert_acl_subj_label(match, role);
60029+ }
60030+
60031+ return;
60032+}
60033+
60034+static void
60035+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60036+ const ino_t newinode, const dev_t newdevice)
60037+{
60038+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60039+ struct inodev_entry *match;
60040+
60041+ match = inodev_set.i_hash[index];
60042+
60043+ while (match && (match->nentry->inode != oldinode ||
60044+ match->nentry->device != olddevice || !match->nentry->deleted))
60045+ match = match->next;
60046+
60047+ if (match && (match->nentry->inode == oldinode)
60048+ && (match->nentry->device == olddevice) &&
60049+ match->nentry->deleted) {
60050+ if (match->prev == NULL) {
60051+ inodev_set.i_hash[index] = match->next;
60052+ if (match->next != NULL)
60053+ match->next->prev = NULL;
60054+ } else {
60055+ match->prev->next = match->next;
60056+ if (match->next != NULL)
60057+ match->next->prev = match->prev;
60058+ }
60059+ match->prev = NULL;
60060+ match->next = NULL;
60061+ match->nentry->inode = newinode;
60062+ match->nentry->device = newdevice;
60063+ match->nentry->deleted = 0;
60064+
60065+ insert_inodev_entry(match);
60066+ }
60067+
60068+ return;
60069+}
60070+
60071+static void
60072+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
60073+{
60074+ struct acl_subject_label *subj;
60075+ struct acl_role_label *role;
60076+ unsigned int x;
60077+
60078+ FOR_EACH_ROLE_START(role)
60079+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
60080+
60081+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60082+ if ((subj->inode == ino) && (subj->device == dev)) {
60083+ subj->inode = ino;
60084+ subj->device = dev;
60085+ }
60086+ /* nested subjects aren't in the role's subj_hash table */
60087+ update_acl_obj_label(matchn->inode, matchn->device,
60088+ ino, dev, subj);
60089+ FOR_EACH_NESTED_SUBJECT_END(subj)
60090+ FOR_EACH_SUBJECT_START(role, subj, x)
60091+ update_acl_obj_label(matchn->inode, matchn->device,
60092+ ino, dev, subj);
60093+ FOR_EACH_SUBJECT_END(subj,x)
60094+ FOR_EACH_ROLE_END(role)
60095+
60096+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
60097+
60098+ return;
60099+}
60100+
60101+static void
60102+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
60103+ const struct vfsmount *mnt)
60104+{
60105+ ino_t ino = dentry->d_inode->i_ino;
60106+ dev_t dev = __get_dev(dentry);
60107+
60108+ __do_handle_create(matchn, ino, dev);
60109+
60110+ return;
60111+}
60112+
60113+void
60114+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60115+{
60116+ struct name_entry *matchn;
60117+
60118+ if (unlikely(!(gr_status & GR_READY)))
60119+ return;
60120+
60121+ preempt_disable();
60122+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
60123+
60124+ if (unlikely((unsigned long)matchn)) {
60125+ write_lock(&gr_inode_lock);
60126+ do_handle_create(matchn, dentry, mnt);
60127+ write_unlock(&gr_inode_lock);
60128+ }
60129+ preempt_enable();
60130+
60131+ return;
60132+}
60133+
60134+void
60135+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60136+{
60137+ struct name_entry *matchn;
60138+
60139+ if (unlikely(!(gr_status & GR_READY)))
60140+ return;
60141+
60142+ preempt_disable();
60143+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
60144+
60145+ if (unlikely((unsigned long)matchn)) {
60146+ write_lock(&gr_inode_lock);
60147+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
60148+ write_unlock(&gr_inode_lock);
60149+ }
60150+ preempt_enable();
60151+
60152+ return;
60153+}
60154+
60155+void
60156+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60157+ struct dentry *old_dentry,
60158+ struct dentry *new_dentry,
60159+ struct vfsmount *mnt, const __u8 replace)
60160+{
60161+ struct name_entry *matchn;
60162+ struct inodev_entry *inodev;
60163+ struct inode *inode = new_dentry->d_inode;
60164+ ino_t old_ino = old_dentry->d_inode->i_ino;
60165+ dev_t old_dev = __get_dev(old_dentry);
60166+
60167+ /* vfs_rename swaps the name and parent link for old_dentry and
60168+ new_dentry
60169+ at this point, old_dentry has the new name, parent link, and inode
60170+ for the renamed file
60171+ if a file is being replaced by a rename, new_dentry has the inode
60172+ and name for the replaced file
60173+ */
60174+
60175+ if (unlikely(!(gr_status & GR_READY)))
60176+ return;
60177+
60178+ preempt_disable();
60179+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
60180+
60181+ /* we wouldn't have to check d_inode if it weren't for
60182+ NFS silly-renaming
60183+ */
60184+
60185+ write_lock(&gr_inode_lock);
60186+ if (unlikely(replace && inode)) {
60187+ ino_t new_ino = inode->i_ino;
60188+ dev_t new_dev = __get_dev(new_dentry);
60189+
60190+ inodev = lookup_inodev_entry(new_ino, new_dev);
60191+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
60192+ do_handle_delete(inodev, new_ino, new_dev);
60193+ }
60194+
60195+ inodev = lookup_inodev_entry(old_ino, old_dev);
60196+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
60197+ do_handle_delete(inodev, old_ino, old_dev);
60198+
60199+ if (unlikely((unsigned long)matchn))
60200+ do_handle_create(matchn, old_dentry, mnt);
60201+
60202+ write_unlock(&gr_inode_lock);
60203+ preempt_enable();
60204+
60205+ return;
60206+}
60207+
60208+static int
60209+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
60210+ unsigned char **sum)
60211+{
60212+ struct acl_role_label *r;
60213+ struct role_allowed_ip *ipp;
60214+ struct role_transition *trans;
60215+ unsigned int i;
60216+ int found = 0;
60217+ u32 curr_ip = current->signal->curr_ip;
60218+
60219+ current->signal->saved_ip = curr_ip;
60220+
60221+ /* check transition table */
60222+
60223+ for (trans = current->role->transitions; trans; trans = trans->next) {
60224+ if (!strcmp(rolename, trans->rolename)) {
60225+ found = 1;
60226+ break;
60227+ }
60228+ }
60229+
60230+ if (!found)
60231+ return 0;
60232+
60233+ /* handle special roles that do not require authentication
60234+ and check ip */
60235+
60236+ FOR_EACH_ROLE_START(r)
60237+ if (!strcmp(rolename, r->rolename) &&
60238+ (r->roletype & GR_ROLE_SPECIAL)) {
60239+ found = 0;
60240+ if (r->allowed_ips != NULL) {
60241+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
60242+ if ((ntohl(curr_ip) & ipp->netmask) ==
60243+ (ntohl(ipp->addr) & ipp->netmask))
60244+ found = 1;
60245+ }
60246+ } else
60247+ found = 2;
60248+ if (!found)
60249+ return 0;
60250+
60251+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
60252+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
60253+ *salt = NULL;
60254+ *sum = NULL;
60255+ return 1;
60256+ }
60257+ }
60258+ FOR_EACH_ROLE_END(r)
60259+
60260+ for (i = 0; i < num_sprole_pws; i++) {
60261+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
60262+ *salt = acl_special_roles[i]->salt;
60263+ *sum = acl_special_roles[i]->sum;
60264+ return 1;
60265+ }
60266+ }
60267+
60268+ return 0;
60269+}
60270+
60271+static void
60272+assign_special_role(char *rolename)
60273+{
60274+ struct acl_object_label *obj;
60275+ struct acl_role_label *r;
60276+ struct acl_role_label *assigned = NULL;
60277+ struct task_struct *tsk;
60278+ struct file *filp;
60279+
60280+ FOR_EACH_ROLE_START(r)
60281+ if (!strcmp(rolename, r->rolename) &&
60282+ (r->roletype & GR_ROLE_SPECIAL)) {
60283+ assigned = r;
60284+ break;
60285+ }
60286+ FOR_EACH_ROLE_END(r)
60287+
60288+ if (!assigned)
60289+ return;
60290+
60291+ read_lock(&tasklist_lock);
60292+ read_lock(&grsec_exec_file_lock);
60293+
60294+ tsk = current->real_parent;
60295+ if (tsk == NULL)
60296+ goto out_unlock;
60297+
60298+ filp = tsk->exec_file;
60299+ if (filp == NULL)
60300+ goto out_unlock;
60301+
60302+ tsk->is_writable = 0;
60303+
60304+ tsk->acl_sp_role = 1;
60305+ tsk->acl_role_id = ++acl_sp_role_value;
60306+ tsk->role = assigned;
60307+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
60308+
60309+ /* ignore additional mmap checks for processes that are writable
60310+ by the default ACL */
60311+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60312+ if (unlikely(obj->mode & GR_WRITE))
60313+ tsk->is_writable = 1;
60314+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
60315+ if (unlikely(obj->mode & GR_WRITE))
60316+ tsk->is_writable = 1;
60317+
60318+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60319+ 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));
60320+#endif
60321+
60322+out_unlock:
60323+ read_unlock(&grsec_exec_file_lock);
60324+ read_unlock(&tasklist_lock);
60325+ return;
60326+}
60327+
60328+int gr_check_secure_terminal(struct task_struct *task)
60329+{
60330+ struct task_struct *p, *p2, *p3;
60331+ struct files_struct *files;
60332+ struct fdtable *fdt;
60333+ struct file *our_file = NULL, *file;
60334+ int i;
60335+
60336+ if (task->signal->tty == NULL)
60337+ return 1;
60338+
60339+ files = get_files_struct(task);
60340+ if (files != NULL) {
60341+ rcu_read_lock();
60342+ fdt = files_fdtable(files);
60343+ for (i=0; i < fdt->max_fds; i++) {
60344+ file = fcheck_files(files, i);
60345+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
60346+ get_file(file);
60347+ our_file = file;
60348+ }
60349+ }
60350+ rcu_read_unlock();
60351+ put_files_struct(files);
60352+ }
60353+
60354+ if (our_file == NULL)
60355+ return 1;
60356+
60357+ read_lock(&tasklist_lock);
60358+ do_each_thread(p2, p) {
60359+ files = get_files_struct(p);
60360+ if (files == NULL ||
60361+ (p->signal && p->signal->tty == task->signal->tty)) {
60362+ if (files != NULL)
60363+ put_files_struct(files);
60364+ continue;
60365+ }
60366+ rcu_read_lock();
60367+ fdt = files_fdtable(files);
60368+ for (i=0; i < fdt->max_fds; i++) {
60369+ file = fcheck_files(files, i);
60370+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
60371+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
60372+ p3 = task;
60373+ while (task_pid_nr(p3) > 0) {
60374+ if (p3 == p)
60375+ break;
60376+ p3 = p3->real_parent;
60377+ }
60378+ if (p3 == p)
60379+ break;
60380+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
60381+ gr_handle_alertkill(p);
60382+ rcu_read_unlock();
60383+ put_files_struct(files);
60384+ read_unlock(&tasklist_lock);
60385+ fput(our_file);
60386+ return 0;
60387+ }
60388+ }
60389+ rcu_read_unlock();
60390+ put_files_struct(files);
60391+ } while_each_thread(p2, p);
60392+ read_unlock(&tasklist_lock);
60393+
60394+ fput(our_file);
60395+ return 1;
60396+}
60397+
60398+static int gr_rbac_disable(void *unused)
60399+{
60400+ pax_open_kernel();
60401+ gr_status &= ~GR_READY;
60402+ pax_close_kernel();
60403+
60404+ return 0;
60405+}
60406+
60407+ssize_t
60408+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
60409+{
60410+ struct gr_arg_wrapper uwrap;
60411+ unsigned char *sprole_salt = NULL;
60412+ unsigned char *sprole_sum = NULL;
60413+ int error = sizeof (struct gr_arg_wrapper);
60414+ int error2 = 0;
60415+
60416+ mutex_lock(&gr_dev_mutex);
60417+
60418+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
60419+ error = -EPERM;
60420+ goto out;
60421+ }
60422+
60423+ if (count != sizeof (struct gr_arg_wrapper)) {
60424+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
60425+ error = -EINVAL;
60426+ goto out;
60427+ }
60428+
60429+
60430+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
60431+ gr_auth_expires = 0;
60432+ gr_auth_attempts = 0;
60433+ }
60434+
60435+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
60436+ error = -EFAULT;
60437+ goto out;
60438+ }
60439+
60440+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
60441+ error = -EINVAL;
60442+ goto out;
60443+ }
60444+
60445+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
60446+ error = -EFAULT;
60447+ goto out;
60448+ }
60449+
60450+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60451+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60452+ time_after(gr_auth_expires, get_seconds())) {
60453+ error = -EBUSY;
60454+ goto out;
60455+ }
60456+
60457+ /* if non-root trying to do anything other than use a special role,
60458+ do not attempt authentication, do not count towards authentication
60459+ locking
60460+ */
60461+
60462+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
60463+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60464+ gr_is_global_nonroot(current_uid())) {
60465+ error = -EPERM;
60466+ goto out;
60467+ }
60468+
60469+ /* ensure pw and special role name are null terminated */
60470+
60471+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
60472+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
60473+
60474+ /* Okay.
60475+ * We have our enough of the argument structure..(we have yet
60476+ * to copy_from_user the tables themselves) . Copy the tables
60477+ * only if we need them, i.e. for loading operations. */
60478+
60479+ switch (gr_usermode->mode) {
60480+ case GR_STATUS:
60481+ if (gr_status & GR_READY) {
60482+ error = 1;
60483+ if (!gr_check_secure_terminal(current))
60484+ error = 3;
60485+ } else
60486+ error = 2;
60487+ goto out;
60488+ case GR_SHUTDOWN:
60489+ if ((gr_status & GR_READY)
60490+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60491+ stop_machine(gr_rbac_disable, NULL, NULL);
60492+ free_variables();
60493+ memset(gr_usermode, 0, sizeof (struct gr_arg));
60494+ memset(gr_system_salt, 0, GR_SALT_LEN);
60495+ memset(gr_system_sum, 0, GR_SHA_LEN);
60496+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60497+ } else if (gr_status & GR_READY) {
60498+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60499+ error = -EPERM;
60500+ } else {
60501+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60502+ error = -EAGAIN;
60503+ }
60504+ break;
60505+ case GR_ENABLE:
60506+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60507+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60508+ else {
60509+ if (gr_status & GR_READY)
60510+ error = -EAGAIN;
60511+ else
60512+ error = error2;
60513+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60514+ }
60515+ break;
60516+ case GR_RELOAD:
60517+ if (!(gr_status & GR_READY)) {
60518+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60519+ error = -EAGAIN;
60520+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60521+ stop_machine(gr_rbac_disable, NULL, NULL);
60522+ free_variables();
60523+ error2 = gracl_init(gr_usermode);
60524+ if (!error2)
60525+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60526+ else {
60527+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60528+ error = error2;
60529+ }
60530+ } else {
60531+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60532+ error = -EPERM;
60533+ }
60534+ break;
60535+ case GR_SEGVMOD:
60536+ if (unlikely(!(gr_status & GR_READY))) {
60537+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60538+ error = -EAGAIN;
60539+ break;
60540+ }
60541+
60542+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60543+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60544+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60545+ struct acl_subject_label *segvacl;
60546+ segvacl =
60547+ lookup_acl_subj_label(gr_usermode->segv_inode,
60548+ gr_usermode->segv_device,
60549+ current->role);
60550+ if (segvacl) {
60551+ segvacl->crashes = 0;
60552+ segvacl->expires = 0;
60553+ }
60554+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60555+ gr_remove_uid(gr_usermode->segv_uid);
60556+ }
60557+ } else {
60558+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60559+ error = -EPERM;
60560+ }
60561+ break;
60562+ case GR_SPROLE:
60563+ case GR_SPROLEPAM:
60564+ if (unlikely(!(gr_status & GR_READY))) {
60565+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60566+ error = -EAGAIN;
60567+ break;
60568+ }
60569+
60570+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60571+ current->role->expires = 0;
60572+ current->role->auth_attempts = 0;
60573+ }
60574+
60575+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60576+ time_after(current->role->expires, get_seconds())) {
60577+ error = -EBUSY;
60578+ goto out;
60579+ }
60580+
60581+ if (lookup_special_role_auth
60582+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60583+ && ((!sprole_salt && !sprole_sum)
60584+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60585+ char *p = "";
60586+ assign_special_role(gr_usermode->sp_role);
60587+ read_lock(&tasklist_lock);
60588+ if (current->real_parent)
60589+ p = current->real_parent->role->rolename;
60590+ read_unlock(&tasklist_lock);
60591+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60592+ p, acl_sp_role_value);
60593+ } else {
60594+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60595+ error = -EPERM;
60596+ if(!(current->role->auth_attempts++))
60597+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60598+
60599+ goto out;
60600+ }
60601+ break;
60602+ case GR_UNSPROLE:
60603+ if (unlikely(!(gr_status & GR_READY))) {
60604+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60605+ error = -EAGAIN;
60606+ break;
60607+ }
60608+
60609+ if (current->role->roletype & GR_ROLE_SPECIAL) {
60610+ char *p = "";
60611+ int i = 0;
60612+
60613+ read_lock(&tasklist_lock);
60614+ if (current->real_parent) {
60615+ p = current->real_parent->role->rolename;
60616+ i = current->real_parent->acl_role_id;
60617+ }
60618+ read_unlock(&tasklist_lock);
60619+
60620+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60621+ gr_set_acls(1);
60622+ } else {
60623+ error = -EPERM;
60624+ goto out;
60625+ }
60626+ break;
60627+ default:
60628+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60629+ error = -EINVAL;
60630+ break;
60631+ }
60632+
60633+ if (error != -EPERM)
60634+ goto out;
60635+
60636+ if(!(gr_auth_attempts++))
60637+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60638+
60639+ out:
60640+ mutex_unlock(&gr_dev_mutex);
60641+ return error;
60642+}
60643+
60644+/* must be called with
60645+ rcu_read_lock();
60646+ read_lock(&tasklist_lock);
60647+ read_lock(&grsec_exec_file_lock);
60648+*/
60649+int gr_apply_subject_to_task(struct task_struct *task)
60650+{
60651+ struct acl_object_label *obj;
60652+ char *tmpname;
60653+ struct acl_subject_label *tmpsubj;
60654+ struct file *filp;
60655+ struct name_entry *nmatch;
60656+
60657+ filp = task->exec_file;
60658+ if (filp == NULL)
60659+ return 0;
60660+
60661+ /* the following is to apply the correct subject
60662+ on binaries running when the RBAC system
60663+ is enabled, when the binaries have been
60664+ replaced or deleted since their execution
60665+ -----
60666+ when the RBAC system starts, the inode/dev
60667+ from exec_file will be one the RBAC system
60668+ is unaware of. It only knows the inode/dev
60669+ of the present file on disk, or the absence
60670+ of it.
60671+ */
60672+ preempt_disable();
60673+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60674+
60675+ nmatch = lookup_name_entry(tmpname);
60676+ preempt_enable();
60677+ tmpsubj = NULL;
60678+ if (nmatch) {
60679+ if (nmatch->deleted)
60680+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60681+ else
60682+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60683+ if (tmpsubj != NULL)
60684+ task->acl = tmpsubj;
60685+ }
60686+ if (tmpsubj == NULL)
60687+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60688+ task->role);
60689+ if (task->acl) {
60690+ task->is_writable = 0;
60691+ /* ignore additional mmap checks for processes that are writable
60692+ by the default ACL */
60693+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60694+ if (unlikely(obj->mode & GR_WRITE))
60695+ task->is_writable = 1;
60696+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60697+ if (unlikely(obj->mode & GR_WRITE))
60698+ task->is_writable = 1;
60699+
60700+ gr_set_proc_res(task);
60701+
60702+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60703+ 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);
60704+#endif
60705+ } else {
60706+ return 1;
60707+ }
60708+
60709+ return 0;
60710+}
60711+
60712+int
60713+gr_set_acls(const int type)
60714+{
60715+ struct task_struct *task, *task2;
60716+ struct acl_role_label *role = current->role;
60717+ __u16 acl_role_id = current->acl_role_id;
60718+ const struct cred *cred;
60719+ int ret;
60720+
60721+ rcu_read_lock();
60722+ read_lock(&tasklist_lock);
60723+ read_lock(&grsec_exec_file_lock);
60724+ do_each_thread(task2, task) {
60725+ /* check to see if we're called from the exit handler,
60726+ if so, only replace ACLs that have inherited the admin
60727+ ACL */
60728+
60729+ if (type && (task->role != role ||
60730+ task->acl_role_id != acl_role_id))
60731+ continue;
60732+
60733+ task->acl_role_id = 0;
60734+ task->acl_sp_role = 0;
60735+
60736+ if (task->exec_file) {
60737+ cred = __task_cred(task);
60738+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60739+ ret = gr_apply_subject_to_task(task);
60740+ if (ret) {
60741+ read_unlock(&grsec_exec_file_lock);
60742+ read_unlock(&tasklist_lock);
60743+ rcu_read_unlock();
60744+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60745+ return ret;
60746+ }
60747+ } else {
60748+ // it's a kernel process
60749+ task->role = kernel_role;
60750+ task->acl = kernel_role->root_label;
60751+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60752+ task->acl->mode &= ~GR_PROCFIND;
60753+#endif
60754+ }
60755+ } while_each_thread(task2, task);
60756+ read_unlock(&grsec_exec_file_lock);
60757+ read_unlock(&tasklist_lock);
60758+ rcu_read_unlock();
60759+
60760+ return 0;
60761+}
60762+
60763+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60764+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60765+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60766+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60767+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60768+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60769+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60770+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60771+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60772+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60773+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60774+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60775+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60776+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60777+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60778+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60779+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60780+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60781+};
60782+
60783+void
60784+gr_learn_resource(const struct task_struct *task,
60785+ const int res, const unsigned long wanted, const int gt)
60786+{
60787+ struct acl_subject_label *acl;
60788+ const struct cred *cred;
60789+
60790+ if (unlikely((gr_status & GR_READY) &&
60791+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60792+ goto skip_reslog;
60793+
60794+ gr_log_resource(task, res, wanted, gt);
60795+skip_reslog:
60796+
60797+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60798+ return;
60799+
60800+ acl = task->acl;
60801+
60802+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60803+ !(acl->resmask & (1 << (unsigned short) res))))
60804+ return;
60805+
60806+ if (wanted >= acl->res[res].rlim_cur) {
60807+ unsigned long res_add;
60808+
60809+ res_add = wanted + res_learn_bumps[res];
60810+
60811+ acl->res[res].rlim_cur = res_add;
60812+
60813+ if (wanted > acl->res[res].rlim_max)
60814+ acl->res[res].rlim_max = res_add;
60815+
60816+ /* only log the subject filename, since resource logging is supported for
60817+ single-subject learning only */
60818+ rcu_read_lock();
60819+ cred = __task_cred(task);
60820+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60821+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60822+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60823+ "", (unsigned long) res, &task->signal->saved_ip);
60824+ rcu_read_unlock();
60825+ }
60826+
60827+ return;
60828+}
60829+EXPORT_SYMBOL(gr_learn_resource);
60830+#endif
60831+
60832+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60833+void
60834+pax_set_initial_flags(struct linux_binprm *bprm)
60835+{
60836+ struct task_struct *task = current;
60837+ struct acl_subject_label *proc;
60838+ unsigned long flags;
60839+
60840+ if (unlikely(!(gr_status & GR_READY)))
60841+ return;
60842+
60843+ flags = pax_get_flags(task);
60844+
60845+ proc = task->acl;
60846+
60847+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60848+ flags &= ~MF_PAX_PAGEEXEC;
60849+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60850+ flags &= ~MF_PAX_SEGMEXEC;
60851+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60852+ flags &= ~MF_PAX_RANDMMAP;
60853+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60854+ flags &= ~MF_PAX_EMUTRAMP;
60855+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60856+ flags &= ~MF_PAX_MPROTECT;
60857+
60858+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60859+ flags |= MF_PAX_PAGEEXEC;
60860+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60861+ flags |= MF_PAX_SEGMEXEC;
60862+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60863+ flags |= MF_PAX_RANDMMAP;
60864+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60865+ flags |= MF_PAX_EMUTRAMP;
60866+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60867+ flags |= MF_PAX_MPROTECT;
60868+
60869+ pax_set_flags(task, flags);
60870+
60871+ return;
60872+}
60873+#endif
60874+
60875+int
60876+gr_handle_proc_ptrace(struct task_struct *task)
60877+{
60878+ struct file *filp;
60879+ struct task_struct *tmp = task;
60880+ struct task_struct *curtemp = current;
60881+ __u32 retmode;
60882+
60883+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60884+ if (unlikely(!(gr_status & GR_READY)))
60885+ return 0;
60886+#endif
60887+
60888+ read_lock(&tasklist_lock);
60889+ read_lock(&grsec_exec_file_lock);
60890+ filp = task->exec_file;
60891+
60892+ while (task_pid_nr(tmp) > 0) {
60893+ if (tmp == curtemp)
60894+ break;
60895+ tmp = tmp->real_parent;
60896+ }
60897+
60898+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60899+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60900+ read_unlock(&grsec_exec_file_lock);
60901+ read_unlock(&tasklist_lock);
60902+ return 1;
60903+ }
60904+
60905+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60906+ if (!(gr_status & GR_READY)) {
60907+ read_unlock(&grsec_exec_file_lock);
60908+ read_unlock(&tasklist_lock);
60909+ return 0;
60910+ }
60911+#endif
60912+
60913+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60914+ read_unlock(&grsec_exec_file_lock);
60915+ read_unlock(&tasklist_lock);
60916+
60917+ if (retmode & GR_NOPTRACE)
60918+ return 1;
60919+
60920+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60921+ && (current->acl != task->acl || (current->acl != current->role->root_label
60922+ && task_pid_nr(current) != task_pid_nr(task))))
60923+ return 1;
60924+
60925+ return 0;
60926+}
60927+
60928+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60929+{
60930+ if (unlikely(!(gr_status & GR_READY)))
60931+ return;
60932+
60933+ if (!(current->role->roletype & GR_ROLE_GOD))
60934+ return;
60935+
60936+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60937+ p->role->rolename, gr_task_roletype_to_char(p),
60938+ p->acl->filename);
60939+}
60940+
60941+int
60942+gr_handle_ptrace(struct task_struct *task, const long request)
60943+{
60944+ struct task_struct *tmp = task;
60945+ struct task_struct *curtemp = current;
60946+ __u32 retmode;
60947+
60948+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60949+ if (unlikely(!(gr_status & GR_READY)))
60950+ return 0;
60951+#endif
60952+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60953+ read_lock(&tasklist_lock);
60954+ while (task_pid_nr(tmp) > 0) {
60955+ if (tmp == curtemp)
60956+ break;
60957+ tmp = tmp->real_parent;
60958+ }
60959+
60960+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60961+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60962+ read_unlock(&tasklist_lock);
60963+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60964+ return 1;
60965+ }
60966+ read_unlock(&tasklist_lock);
60967+ }
60968+
60969+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60970+ if (!(gr_status & GR_READY))
60971+ return 0;
60972+#endif
60973+
60974+ read_lock(&grsec_exec_file_lock);
60975+ if (unlikely(!task->exec_file)) {
60976+ read_unlock(&grsec_exec_file_lock);
60977+ return 0;
60978+ }
60979+
60980+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60981+ read_unlock(&grsec_exec_file_lock);
60982+
60983+ if (retmode & GR_NOPTRACE) {
60984+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60985+ return 1;
60986+ }
60987+
60988+ if (retmode & GR_PTRACERD) {
60989+ switch (request) {
60990+ case PTRACE_SEIZE:
60991+ case PTRACE_POKETEXT:
60992+ case PTRACE_POKEDATA:
60993+ case PTRACE_POKEUSR:
60994+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60995+ case PTRACE_SETREGS:
60996+ case PTRACE_SETFPREGS:
60997+#endif
60998+#ifdef CONFIG_X86
60999+ case PTRACE_SETFPXREGS:
61000+#endif
61001+#ifdef CONFIG_ALTIVEC
61002+ case PTRACE_SETVRREGS:
61003+#endif
61004+ return 1;
61005+ default:
61006+ return 0;
61007+ }
61008+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61009+ !(current->role->roletype & GR_ROLE_GOD) &&
61010+ (current->acl != task->acl)) {
61011+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61012+ return 1;
61013+ }
61014+
61015+ return 0;
61016+}
61017+
61018+static int is_writable_mmap(const struct file *filp)
61019+{
61020+ struct task_struct *task = current;
61021+ struct acl_object_label *obj, *obj2;
61022+
61023+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61024+ !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))) {
61025+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61026+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61027+ task->role->root_label);
61028+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61029+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61030+ return 1;
61031+ }
61032+ }
61033+ return 0;
61034+}
61035+
61036+int
61037+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61038+{
61039+ __u32 mode;
61040+
61041+ if (unlikely(!file || !(prot & PROT_EXEC)))
61042+ return 1;
61043+
61044+ if (is_writable_mmap(file))
61045+ return 0;
61046+
61047+ mode =
61048+ gr_search_file(file->f_path.dentry,
61049+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61050+ file->f_path.mnt);
61051+
61052+ if (!gr_tpe_allow(file))
61053+ return 0;
61054+
61055+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61056+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61057+ return 0;
61058+ } else if (unlikely(!(mode & GR_EXEC))) {
61059+ return 0;
61060+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61061+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61062+ return 1;
61063+ }
61064+
61065+ return 1;
61066+}
61067+
61068+int
61069+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61070+{
61071+ __u32 mode;
61072+
61073+ if (unlikely(!file || !(prot & PROT_EXEC)))
61074+ return 1;
61075+
61076+ if (is_writable_mmap(file))
61077+ return 0;
61078+
61079+ mode =
61080+ gr_search_file(file->f_path.dentry,
61081+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61082+ file->f_path.mnt);
61083+
61084+ if (!gr_tpe_allow(file))
61085+ return 0;
61086+
61087+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61088+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61089+ return 0;
61090+ } else if (unlikely(!(mode & GR_EXEC))) {
61091+ return 0;
61092+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61093+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61094+ return 1;
61095+ }
61096+
61097+ return 1;
61098+}
61099+
61100+void
61101+gr_acl_handle_psacct(struct task_struct *task, const long code)
61102+{
61103+ unsigned long runtime;
61104+ unsigned long cputime;
61105+ unsigned int wday, cday;
61106+ __u8 whr, chr;
61107+ __u8 wmin, cmin;
61108+ __u8 wsec, csec;
61109+ struct timespec timeval;
61110+
61111+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
61112+ !(task->acl->mode & GR_PROCACCT)))
61113+ return;
61114+
61115+ do_posix_clock_monotonic_gettime(&timeval);
61116+ runtime = timeval.tv_sec - task->start_time.tv_sec;
61117+ wday = runtime / (3600 * 24);
61118+ runtime -= wday * (3600 * 24);
61119+ whr = runtime / 3600;
61120+ runtime -= whr * 3600;
61121+ wmin = runtime / 60;
61122+ runtime -= wmin * 60;
61123+ wsec = runtime;
61124+
61125+ cputime = (task->utime + task->stime) / HZ;
61126+ cday = cputime / (3600 * 24);
61127+ cputime -= cday * (3600 * 24);
61128+ chr = cputime / 3600;
61129+ cputime -= chr * 3600;
61130+ cmin = cputime / 60;
61131+ cputime -= cmin * 60;
61132+ csec = cputime;
61133+
61134+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
61135+
61136+ return;
61137+}
61138+
61139+void gr_set_kernel_label(struct task_struct *task)
61140+{
61141+ if (gr_status & GR_READY) {
61142+ task->role = kernel_role;
61143+ task->acl = kernel_role->root_label;
61144+ }
61145+ return;
61146+}
61147+
61148+#ifdef CONFIG_TASKSTATS
61149+int gr_is_taskstats_denied(int pid)
61150+{
61151+ struct task_struct *task;
61152+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61153+ const struct cred *cred;
61154+#endif
61155+ int ret = 0;
61156+
61157+ /* restrict taskstats viewing to un-chrooted root users
61158+ who have the 'view' subject flag if the RBAC system is enabled
61159+ */
61160+
61161+ rcu_read_lock();
61162+ read_lock(&tasklist_lock);
61163+ task = find_task_by_vpid(pid);
61164+ if (task) {
61165+#ifdef CONFIG_GRKERNSEC_CHROOT
61166+ if (proc_is_chrooted(task))
61167+ ret = -EACCES;
61168+#endif
61169+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61170+ cred = __task_cred(task);
61171+#ifdef CONFIG_GRKERNSEC_PROC_USER
61172+ if (gr_is_global_nonroot(cred->uid))
61173+ ret = -EACCES;
61174+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61175+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
61176+ ret = -EACCES;
61177+#endif
61178+#endif
61179+ if (gr_status & GR_READY) {
61180+ if (!(task->acl->mode & GR_VIEW))
61181+ ret = -EACCES;
61182+ }
61183+ } else
61184+ ret = -ENOENT;
61185+
61186+ read_unlock(&tasklist_lock);
61187+ rcu_read_unlock();
61188+
61189+ return ret;
61190+}
61191+#endif
61192+
61193+/* AUXV entries are filled via a descendant of search_binary_handler
61194+ after we've already applied the subject for the target
61195+*/
61196+int gr_acl_enable_at_secure(void)
61197+{
61198+ if (unlikely(!(gr_status & GR_READY)))
61199+ return 0;
61200+
61201+ if (current->acl->mode & GR_ATSECURE)
61202+ return 1;
61203+
61204+ return 0;
61205+}
61206+
61207+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
61208+{
61209+ struct task_struct *task = current;
61210+ struct dentry *dentry = file->f_path.dentry;
61211+ struct vfsmount *mnt = file->f_path.mnt;
61212+ struct acl_object_label *obj, *tmp;
61213+ struct acl_subject_label *subj;
61214+ unsigned int bufsize;
61215+ int is_not_root;
61216+ char *path;
61217+ dev_t dev = __get_dev(dentry);
61218+
61219+ if (unlikely(!(gr_status & GR_READY)))
61220+ return 1;
61221+
61222+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61223+ return 1;
61224+
61225+ /* ignore Eric Biederman */
61226+ if (IS_PRIVATE(dentry->d_inode))
61227+ return 1;
61228+
61229+ subj = task->acl;
61230+ read_lock(&gr_inode_lock);
61231+ do {
61232+ obj = lookup_acl_obj_label(ino, dev, subj);
61233+ if (obj != NULL) {
61234+ read_unlock(&gr_inode_lock);
61235+ return (obj->mode & GR_FIND) ? 1 : 0;
61236+ }
61237+ } while ((subj = subj->parent_subject));
61238+ read_unlock(&gr_inode_lock);
61239+
61240+ /* this is purely an optimization since we're looking for an object
61241+ for the directory we're doing a readdir on
61242+ if it's possible for any globbed object to match the entry we're
61243+ filling into the directory, then the object we find here will be
61244+ an anchor point with attached globbed objects
61245+ */
61246+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
61247+ if (obj->globbed == NULL)
61248+ return (obj->mode & GR_FIND) ? 1 : 0;
61249+
61250+ is_not_root = ((obj->filename[0] == '/') &&
61251+ (obj->filename[1] == '\0')) ? 0 : 1;
61252+ bufsize = PAGE_SIZE - namelen - is_not_root;
61253+
61254+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
61255+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
61256+ return 1;
61257+
61258+ preempt_disable();
61259+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
61260+ bufsize);
61261+
61262+ bufsize = strlen(path);
61263+
61264+ /* if base is "/", don't append an additional slash */
61265+ if (is_not_root)
61266+ *(path + bufsize) = '/';
61267+ memcpy(path + bufsize + is_not_root, name, namelen);
61268+ *(path + bufsize + namelen + is_not_root) = '\0';
61269+
61270+ tmp = obj->globbed;
61271+ while (tmp) {
61272+ if (!glob_match(tmp->filename, path)) {
61273+ preempt_enable();
61274+ return (tmp->mode & GR_FIND) ? 1 : 0;
61275+ }
61276+ tmp = tmp->next;
61277+ }
61278+ preempt_enable();
61279+ return (obj->mode & GR_FIND) ? 1 : 0;
61280+}
61281+
61282+void gr_put_exec_file(struct task_struct *task)
61283+{
61284+ struct file *filp;
61285+
61286+ write_lock(&grsec_exec_file_lock);
61287+ filp = task->exec_file;
61288+ task->exec_file = NULL;
61289+ write_unlock(&grsec_exec_file_lock);
61290+
61291+ if (filp)
61292+ fput(filp);
61293+
61294+ return;
61295+}
61296+
61297+
61298+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
61299+EXPORT_SYMBOL(gr_acl_is_enabled);
61300+#endif
61301+EXPORT_SYMBOL(gr_set_kernel_label);
61302+#ifdef CONFIG_SECURITY
61303+EXPORT_SYMBOL(gr_check_user_change);
61304+EXPORT_SYMBOL(gr_check_group_change);
61305+#endif
61306+
61307diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
61308new file mode 100644
61309index 0000000..34fefda
61310--- /dev/null
61311+++ b/grsecurity/gracl_alloc.c
61312@@ -0,0 +1,105 @@
61313+#include <linux/kernel.h>
61314+#include <linux/mm.h>
61315+#include <linux/slab.h>
61316+#include <linux/vmalloc.h>
61317+#include <linux/gracl.h>
61318+#include <linux/grsecurity.h>
61319+
61320+static unsigned long alloc_stack_next = 1;
61321+static unsigned long alloc_stack_size = 1;
61322+static void **alloc_stack;
61323+
61324+static __inline__ int
61325+alloc_pop(void)
61326+{
61327+ if (alloc_stack_next == 1)
61328+ return 0;
61329+
61330+ kfree(alloc_stack[alloc_stack_next - 2]);
61331+
61332+ alloc_stack_next--;
61333+
61334+ return 1;
61335+}
61336+
61337+static __inline__ int
61338+alloc_push(void *buf)
61339+{
61340+ if (alloc_stack_next >= alloc_stack_size)
61341+ return 1;
61342+
61343+ alloc_stack[alloc_stack_next - 1] = buf;
61344+
61345+ alloc_stack_next++;
61346+
61347+ return 0;
61348+}
61349+
61350+void *
61351+acl_alloc(unsigned long len)
61352+{
61353+ void *ret = NULL;
61354+
61355+ if (!len || len > PAGE_SIZE)
61356+ goto out;
61357+
61358+ ret = kmalloc(len, GFP_KERNEL);
61359+
61360+ if (ret) {
61361+ if (alloc_push(ret)) {
61362+ kfree(ret);
61363+ ret = NULL;
61364+ }
61365+ }
61366+
61367+out:
61368+ return ret;
61369+}
61370+
61371+void *
61372+acl_alloc_num(unsigned long num, unsigned long len)
61373+{
61374+ if (!len || (num > (PAGE_SIZE / len)))
61375+ return NULL;
61376+
61377+ return acl_alloc(num * len);
61378+}
61379+
61380+void
61381+acl_free_all(void)
61382+{
61383+ if (gr_acl_is_enabled() || !alloc_stack)
61384+ return;
61385+
61386+ while (alloc_pop()) ;
61387+
61388+ if (alloc_stack) {
61389+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
61390+ kfree(alloc_stack);
61391+ else
61392+ vfree(alloc_stack);
61393+ }
61394+
61395+ alloc_stack = NULL;
61396+ alloc_stack_size = 1;
61397+ alloc_stack_next = 1;
61398+
61399+ return;
61400+}
61401+
61402+int
61403+acl_alloc_stack_init(unsigned long size)
61404+{
61405+ if ((size * sizeof (void *)) <= PAGE_SIZE)
61406+ alloc_stack =
61407+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
61408+ else
61409+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
61410+
61411+ alloc_stack_size = size;
61412+
61413+ if (!alloc_stack)
61414+ return 0;
61415+ else
61416+ return 1;
61417+}
61418diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
61419new file mode 100644
61420index 0000000..bdd51ea
61421--- /dev/null
61422+++ b/grsecurity/gracl_cap.c
61423@@ -0,0 +1,110 @@
61424+#include <linux/kernel.h>
61425+#include <linux/module.h>
61426+#include <linux/sched.h>
61427+#include <linux/gracl.h>
61428+#include <linux/grsecurity.h>
61429+#include <linux/grinternal.h>
61430+
61431+extern const char *captab_log[];
61432+extern int captab_log_entries;
61433+
61434+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61435+{
61436+ struct acl_subject_label *curracl;
61437+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61438+ kernel_cap_t cap_audit = __cap_empty_set;
61439+
61440+ if (!gr_acl_is_enabled())
61441+ return 1;
61442+
61443+ curracl = task->acl;
61444+
61445+ cap_drop = curracl->cap_lower;
61446+ cap_mask = curracl->cap_mask;
61447+ cap_audit = curracl->cap_invert_audit;
61448+
61449+ while ((curracl = curracl->parent_subject)) {
61450+ /* if the cap isn't specified in the current computed mask but is specified in the
61451+ current level subject, and is lowered in the current level subject, then add
61452+ it to the set of dropped capabilities
61453+ otherwise, add the current level subject's mask to the current computed mask
61454+ */
61455+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61456+ cap_raise(cap_mask, cap);
61457+ if (cap_raised(curracl->cap_lower, cap))
61458+ cap_raise(cap_drop, cap);
61459+ if (cap_raised(curracl->cap_invert_audit, cap))
61460+ cap_raise(cap_audit, cap);
61461+ }
61462+ }
61463+
61464+ if (!cap_raised(cap_drop, cap)) {
61465+ if (cap_raised(cap_audit, cap))
61466+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
61467+ return 1;
61468+ }
61469+
61470+ curracl = task->acl;
61471+
61472+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
61473+ && cap_raised(cred->cap_effective, cap)) {
61474+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61475+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
61476+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
61477+ gr_to_filename(task->exec_file->f_path.dentry,
61478+ task->exec_file->f_path.mnt) : curracl->filename,
61479+ curracl->filename, 0UL,
61480+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
61481+ return 1;
61482+ }
61483+
61484+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
61485+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
61486+
61487+ return 0;
61488+}
61489+
61490+int
61491+gr_acl_is_capable(const int cap)
61492+{
61493+ return gr_task_acl_is_capable(current, current_cred(), cap);
61494+}
61495+
61496+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61497+{
61498+ struct acl_subject_label *curracl;
61499+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61500+
61501+ if (!gr_acl_is_enabled())
61502+ return 1;
61503+
61504+ curracl = task->acl;
61505+
61506+ cap_drop = curracl->cap_lower;
61507+ cap_mask = curracl->cap_mask;
61508+
61509+ while ((curracl = curracl->parent_subject)) {
61510+ /* if the cap isn't specified in the current computed mask but is specified in the
61511+ current level subject, and is lowered in the current level subject, then add
61512+ it to the set of dropped capabilities
61513+ otherwise, add the current level subject's mask to the current computed mask
61514+ */
61515+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61516+ cap_raise(cap_mask, cap);
61517+ if (cap_raised(curracl->cap_lower, cap))
61518+ cap_raise(cap_drop, cap);
61519+ }
61520+ }
61521+
61522+ if (!cap_raised(cap_drop, cap))
61523+ return 1;
61524+
61525+ return 0;
61526+}
61527+
61528+int
61529+gr_acl_is_capable_nolog(const int cap)
61530+{
61531+ return gr_task_acl_is_capable_nolog(current, cap);
61532+}
61533+
61534diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61535new file mode 100644
61536index 0000000..a340c17
61537--- /dev/null
61538+++ b/grsecurity/gracl_fs.c
61539@@ -0,0 +1,431 @@
61540+#include <linux/kernel.h>
61541+#include <linux/sched.h>
61542+#include <linux/types.h>
61543+#include <linux/fs.h>
61544+#include <linux/file.h>
61545+#include <linux/stat.h>
61546+#include <linux/grsecurity.h>
61547+#include <linux/grinternal.h>
61548+#include <linux/gracl.h>
61549+
61550+umode_t
61551+gr_acl_umask(void)
61552+{
61553+ if (unlikely(!gr_acl_is_enabled()))
61554+ return 0;
61555+
61556+ return current->role->umask;
61557+}
61558+
61559+__u32
61560+gr_acl_handle_hidden_file(const struct dentry * dentry,
61561+ const struct vfsmount * mnt)
61562+{
61563+ __u32 mode;
61564+
61565+ if (unlikely(!dentry->d_inode))
61566+ return GR_FIND;
61567+
61568+ mode =
61569+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61570+
61571+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61572+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61573+ return mode;
61574+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61575+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61576+ return 0;
61577+ } else if (unlikely(!(mode & GR_FIND)))
61578+ return 0;
61579+
61580+ return GR_FIND;
61581+}
61582+
61583+__u32
61584+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61585+ int acc_mode)
61586+{
61587+ __u32 reqmode = GR_FIND;
61588+ __u32 mode;
61589+
61590+ if (unlikely(!dentry->d_inode))
61591+ return reqmode;
61592+
61593+ if (acc_mode & MAY_APPEND)
61594+ reqmode |= GR_APPEND;
61595+ else if (acc_mode & MAY_WRITE)
61596+ reqmode |= GR_WRITE;
61597+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61598+ reqmode |= GR_READ;
61599+
61600+ mode =
61601+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61602+ mnt);
61603+
61604+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61605+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61606+ reqmode & GR_READ ? " reading" : "",
61607+ reqmode & GR_WRITE ? " writing" : reqmode &
61608+ GR_APPEND ? " appending" : "");
61609+ return reqmode;
61610+ } else
61611+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61612+ {
61613+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61614+ reqmode & GR_READ ? " reading" : "",
61615+ reqmode & GR_WRITE ? " writing" : reqmode &
61616+ GR_APPEND ? " appending" : "");
61617+ return 0;
61618+ } else if (unlikely((mode & reqmode) != reqmode))
61619+ return 0;
61620+
61621+ return reqmode;
61622+}
61623+
61624+__u32
61625+gr_acl_handle_creat(const struct dentry * dentry,
61626+ const struct dentry * p_dentry,
61627+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61628+ const int imode)
61629+{
61630+ __u32 reqmode = GR_WRITE | GR_CREATE;
61631+ __u32 mode;
61632+
61633+ if (acc_mode & MAY_APPEND)
61634+ reqmode |= GR_APPEND;
61635+ // if a directory was required or the directory already exists, then
61636+ // don't count this open as a read
61637+ if ((acc_mode & MAY_READ) &&
61638+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61639+ reqmode |= GR_READ;
61640+ if ((open_flags & O_CREAT) &&
61641+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61642+ reqmode |= GR_SETID;
61643+
61644+ mode =
61645+ gr_check_create(dentry, p_dentry, p_mnt,
61646+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61647+
61648+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61649+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61650+ reqmode & GR_READ ? " reading" : "",
61651+ reqmode & GR_WRITE ? " writing" : reqmode &
61652+ GR_APPEND ? " appending" : "");
61653+ return reqmode;
61654+ } else
61655+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61656+ {
61657+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61658+ reqmode & GR_READ ? " reading" : "",
61659+ reqmode & GR_WRITE ? " writing" : reqmode &
61660+ GR_APPEND ? " appending" : "");
61661+ return 0;
61662+ } else if (unlikely((mode & reqmode) != reqmode))
61663+ return 0;
61664+
61665+ return reqmode;
61666+}
61667+
61668+__u32
61669+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61670+ const int fmode)
61671+{
61672+ __u32 mode, reqmode = GR_FIND;
61673+
61674+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61675+ reqmode |= GR_EXEC;
61676+ if (fmode & S_IWOTH)
61677+ reqmode |= GR_WRITE;
61678+ if (fmode & S_IROTH)
61679+ reqmode |= GR_READ;
61680+
61681+ mode =
61682+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61683+ mnt);
61684+
61685+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61686+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61687+ reqmode & GR_READ ? " reading" : "",
61688+ reqmode & GR_WRITE ? " writing" : "",
61689+ reqmode & GR_EXEC ? " executing" : "");
61690+ return reqmode;
61691+ } else
61692+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61693+ {
61694+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61695+ reqmode & GR_READ ? " reading" : "",
61696+ reqmode & GR_WRITE ? " writing" : "",
61697+ reqmode & GR_EXEC ? " executing" : "");
61698+ return 0;
61699+ } else if (unlikely((mode & reqmode) != reqmode))
61700+ return 0;
61701+
61702+ return reqmode;
61703+}
61704+
61705+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61706+{
61707+ __u32 mode;
61708+
61709+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61710+
61711+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61712+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61713+ return mode;
61714+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61715+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61716+ return 0;
61717+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61718+ return 0;
61719+
61720+ return (reqmode);
61721+}
61722+
61723+__u32
61724+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61725+{
61726+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61727+}
61728+
61729+__u32
61730+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61731+{
61732+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61733+}
61734+
61735+__u32
61736+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61737+{
61738+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61739+}
61740+
61741+__u32
61742+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61743+{
61744+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61745+}
61746+
61747+__u32
61748+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61749+ umode_t *modeptr)
61750+{
61751+ umode_t mode;
61752+
61753+ *modeptr &= ~gr_acl_umask();
61754+ mode = *modeptr;
61755+
61756+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61757+ return 1;
61758+
61759+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61760+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61761+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61762+ GR_CHMOD_ACL_MSG);
61763+ } else {
61764+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61765+ }
61766+}
61767+
61768+__u32
61769+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61770+{
61771+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61772+}
61773+
61774+__u32
61775+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61776+{
61777+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61778+}
61779+
61780+__u32
61781+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61782+{
61783+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61784+}
61785+
61786+__u32
61787+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61788+{
61789+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61790+ GR_UNIXCONNECT_ACL_MSG);
61791+}
61792+
61793+/* hardlinks require at minimum create and link permission,
61794+ any additional privilege required is based on the
61795+ privilege of the file being linked to
61796+*/
61797+__u32
61798+gr_acl_handle_link(const struct dentry * new_dentry,
61799+ const struct dentry * parent_dentry,
61800+ const struct vfsmount * parent_mnt,
61801+ const struct dentry * old_dentry,
61802+ const struct vfsmount * old_mnt, const struct filename *to)
61803+{
61804+ __u32 mode;
61805+ __u32 needmode = GR_CREATE | GR_LINK;
61806+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61807+
61808+ mode =
61809+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61810+ old_mnt);
61811+
61812+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61813+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61814+ return mode;
61815+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61816+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61817+ return 0;
61818+ } else if (unlikely((mode & needmode) != needmode))
61819+ return 0;
61820+
61821+ return 1;
61822+}
61823+
61824+__u32
61825+gr_acl_handle_symlink(const struct dentry * new_dentry,
61826+ const struct dentry * parent_dentry,
61827+ const struct vfsmount * parent_mnt, const struct filename *from)
61828+{
61829+ __u32 needmode = GR_WRITE | GR_CREATE;
61830+ __u32 mode;
61831+
61832+ mode =
61833+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
61834+ GR_CREATE | GR_AUDIT_CREATE |
61835+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61836+
61837+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61838+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61839+ return mode;
61840+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61841+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61842+ return 0;
61843+ } else if (unlikely((mode & needmode) != needmode))
61844+ return 0;
61845+
61846+ return (GR_WRITE | GR_CREATE);
61847+}
61848+
61849+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)
61850+{
61851+ __u32 mode;
61852+
61853+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61854+
61855+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61856+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61857+ return mode;
61858+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61859+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61860+ return 0;
61861+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61862+ return 0;
61863+
61864+ return (reqmode);
61865+}
61866+
61867+__u32
61868+gr_acl_handle_mknod(const struct dentry * new_dentry,
61869+ const struct dentry * parent_dentry,
61870+ const struct vfsmount * parent_mnt,
61871+ const int mode)
61872+{
61873+ __u32 reqmode = GR_WRITE | GR_CREATE;
61874+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61875+ reqmode |= GR_SETID;
61876+
61877+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61878+ reqmode, GR_MKNOD_ACL_MSG);
61879+}
61880+
61881+__u32
61882+gr_acl_handle_mkdir(const struct dentry *new_dentry,
61883+ const struct dentry *parent_dentry,
61884+ const struct vfsmount *parent_mnt)
61885+{
61886+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61887+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61888+}
61889+
61890+#define RENAME_CHECK_SUCCESS(old, new) \
61891+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61892+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61893+
61894+int
61895+gr_acl_handle_rename(struct dentry *new_dentry,
61896+ struct dentry *parent_dentry,
61897+ const struct vfsmount *parent_mnt,
61898+ struct dentry *old_dentry,
61899+ struct inode *old_parent_inode,
61900+ struct vfsmount *old_mnt, const struct filename *newname)
61901+{
61902+ __u32 comp1, comp2;
61903+ int error = 0;
61904+
61905+ if (unlikely(!gr_acl_is_enabled()))
61906+ return 0;
61907+
61908+ if (!new_dentry->d_inode) {
61909+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61910+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61911+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61912+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61913+ GR_DELETE | GR_AUDIT_DELETE |
61914+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61915+ GR_SUPPRESS, old_mnt);
61916+ } else {
61917+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61918+ GR_CREATE | GR_DELETE |
61919+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61920+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61921+ GR_SUPPRESS, parent_mnt);
61922+ comp2 =
61923+ gr_search_file(old_dentry,
61924+ GR_READ | GR_WRITE | GR_AUDIT_READ |
61925+ GR_DELETE | GR_AUDIT_DELETE |
61926+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61927+ }
61928+
61929+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61930+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61931+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61932+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61933+ && !(comp2 & GR_SUPPRESS)) {
61934+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61935+ error = -EACCES;
61936+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61937+ error = -EACCES;
61938+
61939+ return error;
61940+}
61941+
61942+void
61943+gr_acl_handle_exit(void)
61944+{
61945+ u16 id;
61946+ char *rolename;
61947+
61948+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61949+ !(current->role->roletype & GR_ROLE_PERSIST))) {
61950+ id = current->acl_role_id;
61951+ rolename = current->role->rolename;
61952+ gr_set_acls(1);
61953+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61954+ }
61955+
61956+ gr_put_exec_file(current);
61957+ return;
61958+}
61959+
61960+int
61961+gr_acl_handle_procpidmem(const struct task_struct *task)
61962+{
61963+ if (unlikely(!gr_acl_is_enabled()))
61964+ return 0;
61965+
61966+ if (task != current && task->acl->mode & GR_PROTPROCFD)
61967+ return -EACCES;
61968+
61969+ return 0;
61970+}
61971diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61972new file mode 100644
61973index 0000000..4699807
61974--- /dev/null
61975+++ b/grsecurity/gracl_ip.c
61976@@ -0,0 +1,384 @@
61977+#include <linux/kernel.h>
61978+#include <asm/uaccess.h>
61979+#include <asm/errno.h>
61980+#include <net/sock.h>
61981+#include <linux/file.h>
61982+#include <linux/fs.h>
61983+#include <linux/net.h>
61984+#include <linux/in.h>
61985+#include <linux/skbuff.h>
61986+#include <linux/ip.h>
61987+#include <linux/udp.h>
61988+#include <linux/types.h>
61989+#include <linux/sched.h>
61990+#include <linux/netdevice.h>
61991+#include <linux/inetdevice.h>
61992+#include <linux/gracl.h>
61993+#include <linux/grsecurity.h>
61994+#include <linux/grinternal.h>
61995+
61996+#define GR_BIND 0x01
61997+#define GR_CONNECT 0x02
61998+#define GR_INVERT 0x04
61999+#define GR_BINDOVERRIDE 0x08
62000+#define GR_CONNECTOVERRIDE 0x10
62001+#define GR_SOCK_FAMILY 0x20
62002+
62003+static const char * gr_protocols[IPPROTO_MAX] = {
62004+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62005+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62006+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62007+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62008+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62009+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62010+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62011+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62012+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62013+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62014+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62015+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62016+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62017+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62018+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62019+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62020+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62021+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62022+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62023+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62024+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62025+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62026+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62027+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62028+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62029+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62030+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62031+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62032+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62033+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62034+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62035+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62036+ };
62037+
62038+static const char * gr_socktypes[SOCK_MAX] = {
62039+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62040+ "unknown:7", "unknown:8", "unknown:9", "packet"
62041+ };
62042+
62043+static const char * gr_sockfamilies[AF_MAX+1] = {
62044+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62045+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62046+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62047+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62048+ };
62049+
62050+const char *
62051+gr_proto_to_name(unsigned char proto)
62052+{
62053+ return gr_protocols[proto];
62054+}
62055+
62056+const char *
62057+gr_socktype_to_name(unsigned char type)
62058+{
62059+ return gr_socktypes[type];
62060+}
62061+
62062+const char *
62063+gr_sockfamily_to_name(unsigned char family)
62064+{
62065+ return gr_sockfamilies[family];
62066+}
62067+
62068+int
62069+gr_search_socket(const int domain, const int type, const int protocol)
62070+{
62071+ struct acl_subject_label *curr;
62072+ const struct cred *cred = current_cred();
62073+
62074+ if (unlikely(!gr_acl_is_enabled()))
62075+ goto exit;
62076+
62077+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
62078+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
62079+ goto exit; // let the kernel handle it
62080+
62081+ curr = current->acl;
62082+
62083+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
62084+ /* the family is allowed, if this is PF_INET allow it only if
62085+ the extra sock type/protocol checks pass */
62086+ if (domain == PF_INET)
62087+ goto inet_check;
62088+ goto exit;
62089+ } else {
62090+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62091+ __u32 fakeip = 0;
62092+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62093+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62094+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62095+ gr_to_filename(current->exec_file->f_path.dentry,
62096+ current->exec_file->f_path.mnt) :
62097+ curr->filename, curr->filename,
62098+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
62099+ &current->signal->saved_ip);
62100+ goto exit;
62101+ }
62102+ goto exit_fail;
62103+ }
62104+
62105+inet_check:
62106+ /* the rest of this checking is for IPv4 only */
62107+ if (!curr->ips)
62108+ goto exit;
62109+
62110+ if ((curr->ip_type & (1 << type)) &&
62111+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
62112+ goto exit;
62113+
62114+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62115+ /* we don't place acls on raw sockets , and sometimes
62116+ dgram/ip sockets are opened for ioctl and not
62117+ bind/connect, so we'll fake a bind learn log */
62118+ if (type == SOCK_RAW || type == SOCK_PACKET) {
62119+ __u32 fakeip = 0;
62120+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62121+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62122+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62123+ gr_to_filename(current->exec_file->f_path.dentry,
62124+ current->exec_file->f_path.mnt) :
62125+ curr->filename, curr->filename,
62126+ &fakeip, 0, type,
62127+ protocol, GR_CONNECT, &current->signal->saved_ip);
62128+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
62129+ __u32 fakeip = 0;
62130+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62131+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62132+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62133+ gr_to_filename(current->exec_file->f_path.dentry,
62134+ current->exec_file->f_path.mnt) :
62135+ curr->filename, curr->filename,
62136+ &fakeip, 0, type,
62137+ protocol, GR_BIND, &current->signal->saved_ip);
62138+ }
62139+ /* we'll log when they use connect or bind */
62140+ goto exit;
62141+ }
62142+
62143+exit_fail:
62144+ if (domain == PF_INET)
62145+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
62146+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
62147+ else
62148+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
62149+ gr_socktype_to_name(type), protocol);
62150+
62151+ return 0;
62152+exit:
62153+ return 1;
62154+}
62155+
62156+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)
62157+{
62158+ if ((ip->mode & mode) &&
62159+ (ip_port >= ip->low) &&
62160+ (ip_port <= ip->high) &&
62161+ ((ntohl(ip_addr) & our_netmask) ==
62162+ (ntohl(our_addr) & our_netmask))
62163+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
62164+ && (ip->type & (1 << type))) {
62165+ if (ip->mode & GR_INVERT)
62166+ return 2; // specifically denied
62167+ else
62168+ return 1; // allowed
62169+ }
62170+
62171+ return 0; // not specifically allowed, may continue parsing
62172+}
62173+
62174+static int
62175+gr_search_connectbind(const int full_mode, struct sock *sk,
62176+ struct sockaddr_in *addr, const int type)
62177+{
62178+ char iface[IFNAMSIZ] = {0};
62179+ struct acl_subject_label *curr;
62180+ struct acl_ip_label *ip;
62181+ struct inet_sock *isk;
62182+ struct net_device *dev;
62183+ struct in_device *idev;
62184+ unsigned long i;
62185+ int ret;
62186+ int mode = full_mode & (GR_BIND | GR_CONNECT);
62187+ __u32 ip_addr = 0;
62188+ __u32 our_addr;
62189+ __u32 our_netmask;
62190+ char *p;
62191+ __u16 ip_port = 0;
62192+ const struct cred *cred = current_cred();
62193+
62194+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
62195+ return 0;
62196+
62197+ curr = current->acl;
62198+ isk = inet_sk(sk);
62199+
62200+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
62201+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
62202+ addr->sin_addr.s_addr = curr->inaddr_any_override;
62203+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
62204+ struct sockaddr_in saddr;
62205+ int err;
62206+
62207+ saddr.sin_family = AF_INET;
62208+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
62209+ saddr.sin_port = isk->inet_sport;
62210+
62211+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62212+ if (err)
62213+ return err;
62214+
62215+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62216+ if (err)
62217+ return err;
62218+ }
62219+
62220+ if (!curr->ips)
62221+ return 0;
62222+
62223+ ip_addr = addr->sin_addr.s_addr;
62224+ ip_port = ntohs(addr->sin_port);
62225+
62226+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62227+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62228+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62229+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62230+ gr_to_filename(current->exec_file->f_path.dentry,
62231+ current->exec_file->f_path.mnt) :
62232+ curr->filename, curr->filename,
62233+ &ip_addr, ip_port, type,
62234+ sk->sk_protocol, mode, &current->signal->saved_ip);
62235+ return 0;
62236+ }
62237+
62238+ for (i = 0; i < curr->ip_num; i++) {
62239+ ip = *(curr->ips + i);
62240+ if (ip->iface != NULL) {
62241+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
62242+ p = strchr(iface, ':');
62243+ if (p != NULL)
62244+ *p = '\0';
62245+ dev = dev_get_by_name(sock_net(sk), iface);
62246+ if (dev == NULL)
62247+ continue;
62248+ idev = in_dev_get(dev);
62249+ if (idev == NULL) {
62250+ dev_put(dev);
62251+ continue;
62252+ }
62253+ rcu_read_lock();
62254+ for_ifa(idev) {
62255+ if (!strcmp(ip->iface, ifa->ifa_label)) {
62256+ our_addr = ifa->ifa_address;
62257+ our_netmask = 0xffffffff;
62258+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62259+ if (ret == 1) {
62260+ rcu_read_unlock();
62261+ in_dev_put(idev);
62262+ dev_put(dev);
62263+ return 0;
62264+ } else if (ret == 2) {
62265+ rcu_read_unlock();
62266+ in_dev_put(idev);
62267+ dev_put(dev);
62268+ goto denied;
62269+ }
62270+ }
62271+ } endfor_ifa(idev);
62272+ rcu_read_unlock();
62273+ in_dev_put(idev);
62274+ dev_put(dev);
62275+ } else {
62276+ our_addr = ip->addr;
62277+ our_netmask = ip->netmask;
62278+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62279+ if (ret == 1)
62280+ return 0;
62281+ else if (ret == 2)
62282+ goto denied;
62283+ }
62284+ }
62285+
62286+denied:
62287+ if (mode == GR_BIND)
62288+ 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));
62289+ else if (mode == GR_CONNECT)
62290+ 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));
62291+
62292+ return -EACCES;
62293+}
62294+
62295+int
62296+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
62297+{
62298+ /* always allow disconnection of dgram sockets with connect */
62299+ if (addr->sin_family == AF_UNSPEC)
62300+ return 0;
62301+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
62302+}
62303+
62304+int
62305+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
62306+{
62307+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
62308+}
62309+
62310+int gr_search_listen(struct socket *sock)
62311+{
62312+ struct sock *sk = sock->sk;
62313+ struct sockaddr_in addr;
62314+
62315+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62316+ addr.sin_port = inet_sk(sk)->inet_sport;
62317+
62318+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62319+}
62320+
62321+int gr_search_accept(struct socket *sock)
62322+{
62323+ struct sock *sk = sock->sk;
62324+ struct sockaddr_in addr;
62325+
62326+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62327+ addr.sin_port = inet_sk(sk)->inet_sport;
62328+
62329+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62330+}
62331+
62332+int
62333+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
62334+{
62335+ if (addr)
62336+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
62337+ else {
62338+ struct sockaddr_in sin;
62339+ const struct inet_sock *inet = inet_sk(sk);
62340+
62341+ sin.sin_addr.s_addr = inet->inet_daddr;
62342+ sin.sin_port = inet->inet_dport;
62343+
62344+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62345+ }
62346+}
62347+
62348+int
62349+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
62350+{
62351+ struct sockaddr_in sin;
62352+
62353+ if (unlikely(skb->len < sizeof (struct udphdr)))
62354+ return 0; // skip this packet
62355+
62356+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
62357+ sin.sin_port = udp_hdr(skb)->source;
62358+
62359+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62360+}
62361diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
62362new file mode 100644
62363index 0000000..25f54ef
62364--- /dev/null
62365+++ b/grsecurity/gracl_learn.c
62366@@ -0,0 +1,207 @@
62367+#include <linux/kernel.h>
62368+#include <linux/mm.h>
62369+#include <linux/sched.h>
62370+#include <linux/poll.h>
62371+#include <linux/string.h>
62372+#include <linux/file.h>
62373+#include <linux/types.h>
62374+#include <linux/vmalloc.h>
62375+#include <linux/grinternal.h>
62376+
62377+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
62378+ size_t count, loff_t *ppos);
62379+extern int gr_acl_is_enabled(void);
62380+
62381+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
62382+static int gr_learn_attached;
62383+
62384+/* use a 512k buffer */
62385+#define LEARN_BUFFER_SIZE (512 * 1024)
62386+
62387+static DEFINE_SPINLOCK(gr_learn_lock);
62388+static DEFINE_MUTEX(gr_learn_user_mutex);
62389+
62390+/* we need to maintain two buffers, so that the kernel context of grlearn
62391+ uses a semaphore around the userspace copying, and the other kernel contexts
62392+ use a spinlock when copying into the buffer, since they cannot sleep
62393+*/
62394+static char *learn_buffer;
62395+static char *learn_buffer_user;
62396+static int learn_buffer_len;
62397+static int learn_buffer_user_len;
62398+
62399+static ssize_t
62400+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
62401+{
62402+ DECLARE_WAITQUEUE(wait, current);
62403+ ssize_t retval = 0;
62404+
62405+ add_wait_queue(&learn_wait, &wait);
62406+ set_current_state(TASK_INTERRUPTIBLE);
62407+ do {
62408+ mutex_lock(&gr_learn_user_mutex);
62409+ spin_lock(&gr_learn_lock);
62410+ if (learn_buffer_len)
62411+ break;
62412+ spin_unlock(&gr_learn_lock);
62413+ mutex_unlock(&gr_learn_user_mutex);
62414+ if (file->f_flags & O_NONBLOCK) {
62415+ retval = -EAGAIN;
62416+ goto out;
62417+ }
62418+ if (signal_pending(current)) {
62419+ retval = -ERESTARTSYS;
62420+ goto out;
62421+ }
62422+
62423+ schedule();
62424+ } while (1);
62425+
62426+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
62427+ learn_buffer_user_len = learn_buffer_len;
62428+ retval = learn_buffer_len;
62429+ learn_buffer_len = 0;
62430+
62431+ spin_unlock(&gr_learn_lock);
62432+
62433+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
62434+ retval = -EFAULT;
62435+
62436+ mutex_unlock(&gr_learn_user_mutex);
62437+out:
62438+ set_current_state(TASK_RUNNING);
62439+ remove_wait_queue(&learn_wait, &wait);
62440+ return retval;
62441+}
62442+
62443+static unsigned int
62444+poll_learn(struct file * file, poll_table * wait)
62445+{
62446+ poll_wait(file, &learn_wait, wait);
62447+
62448+ if (learn_buffer_len)
62449+ return (POLLIN | POLLRDNORM);
62450+
62451+ return 0;
62452+}
62453+
62454+void
62455+gr_clear_learn_entries(void)
62456+{
62457+ char *tmp;
62458+
62459+ mutex_lock(&gr_learn_user_mutex);
62460+ spin_lock(&gr_learn_lock);
62461+ tmp = learn_buffer;
62462+ learn_buffer = NULL;
62463+ spin_unlock(&gr_learn_lock);
62464+ if (tmp)
62465+ vfree(tmp);
62466+ if (learn_buffer_user != NULL) {
62467+ vfree(learn_buffer_user);
62468+ learn_buffer_user = NULL;
62469+ }
62470+ learn_buffer_len = 0;
62471+ mutex_unlock(&gr_learn_user_mutex);
62472+
62473+ return;
62474+}
62475+
62476+void
62477+gr_add_learn_entry(const char *fmt, ...)
62478+{
62479+ va_list args;
62480+ unsigned int len;
62481+
62482+ if (!gr_learn_attached)
62483+ return;
62484+
62485+ spin_lock(&gr_learn_lock);
62486+
62487+ /* leave a gap at the end so we know when it's "full" but don't have to
62488+ compute the exact length of the string we're trying to append
62489+ */
62490+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
62491+ spin_unlock(&gr_learn_lock);
62492+ wake_up_interruptible(&learn_wait);
62493+ return;
62494+ }
62495+ if (learn_buffer == NULL) {
62496+ spin_unlock(&gr_learn_lock);
62497+ return;
62498+ }
62499+
62500+ va_start(args, fmt);
62501+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62502+ va_end(args);
62503+
62504+ learn_buffer_len += len + 1;
62505+
62506+ spin_unlock(&gr_learn_lock);
62507+ wake_up_interruptible(&learn_wait);
62508+
62509+ return;
62510+}
62511+
62512+static int
62513+open_learn(struct inode *inode, struct file *file)
62514+{
62515+ if (file->f_mode & FMODE_READ && gr_learn_attached)
62516+ return -EBUSY;
62517+ if (file->f_mode & FMODE_READ) {
62518+ int retval = 0;
62519+ mutex_lock(&gr_learn_user_mutex);
62520+ if (learn_buffer == NULL)
62521+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62522+ if (learn_buffer_user == NULL)
62523+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62524+ if (learn_buffer == NULL) {
62525+ retval = -ENOMEM;
62526+ goto out_error;
62527+ }
62528+ if (learn_buffer_user == NULL) {
62529+ retval = -ENOMEM;
62530+ goto out_error;
62531+ }
62532+ learn_buffer_len = 0;
62533+ learn_buffer_user_len = 0;
62534+ gr_learn_attached = 1;
62535+out_error:
62536+ mutex_unlock(&gr_learn_user_mutex);
62537+ return retval;
62538+ }
62539+ return 0;
62540+}
62541+
62542+static int
62543+close_learn(struct inode *inode, struct file *file)
62544+{
62545+ if (file->f_mode & FMODE_READ) {
62546+ char *tmp = NULL;
62547+ mutex_lock(&gr_learn_user_mutex);
62548+ spin_lock(&gr_learn_lock);
62549+ tmp = learn_buffer;
62550+ learn_buffer = NULL;
62551+ spin_unlock(&gr_learn_lock);
62552+ if (tmp)
62553+ vfree(tmp);
62554+ if (learn_buffer_user != NULL) {
62555+ vfree(learn_buffer_user);
62556+ learn_buffer_user = NULL;
62557+ }
62558+ learn_buffer_len = 0;
62559+ learn_buffer_user_len = 0;
62560+ gr_learn_attached = 0;
62561+ mutex_unlock(&gr_learn_user_mutex);
62562+ }
62563+
62564+ return 0;
62565+}
62566+
62567+const struct file_operations grsec_fops = {
62568+ .read = read_learn,
62569+ .write = write_grsec_handler,
62570+ .open = open_learn,
62571+ .release = close_learn,
62572+ .poll = poll_learn,
62573+};
62574diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62575new file mode 100644
62576index 0000000..39645c9
62577--- /dev/null
62578+++ b/grsecurity/gracl_res.c
62579@@ -0,0 +1,68 @@
62580+#include <linux/kernel.h>
62581+#include <linux/sched.h>
62582+#include <linux/gracl.h>
62583+#include <linux/grinternal.h>
62584+
62585+static const char *restab_log[] = {
62586+ [RLIMIT_CPU] = "RLIMIT_CPU",
62587+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62588+ [RLIMIT_DATA] = "RLIMIT_DATA",
62589+ [RLIMIT_STACK] = "RLIMIT_STACK",
62590+ [RLIMIT_CORE] = "RLIMIT_CORE",
62591+ [RLIMIT_RSS] = "RLIMIT_RSS",
62592+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
62593+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62594+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62595+ [RLIMIT_AS] = "RLIMIT_AS",
62596+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62597+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62598+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62599+ [RLIMIT_NICE] = "RLIMIT_NICE",
62600+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62601+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62602+ [GR_CRASH_RES] = "RLIMIT_CRASH"
62603+};
62604+
62605+void
62606+gr_log_resource(const struct task_struct *task,
62607+ const int res, const unsigned long wanted, const int gt)
62608+{
62609+ const struct cred *cred;
62610+ unsigned long rlim;
62611+
62612+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
62613+ return;
62614+
62615+ // not yet supported resource
62616+ if (unlikely(!restab_log[res]))
62617+ return;
62618+
62619+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62620+ rlim = task_rlimit_max(task, res);
62621+ else
62622+ rlim = task_rlimit(task, res);
62623+
62624+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62625+ return;
62626+
62627+ rcu_read_lock();
62628+ cred = __task_cred(task);
62629+
62630+ if (res == RLIMIT_NPROC &&
62631+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62632+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62633+ goto out_rcu_unlock;
62634+ else if (res == RLIMIT_MEMLOCK &&
62635+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62636+ goto out_rcu_unlock;
62637+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62638+ goto out_rcu_unlock;
62639+ rcu_read_unlock();
62640+
62641+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62642+
62643+ return;
62644+out_rcu_unlock:
62645+ rcu_read_unlock();
62646+ return;
62647+}
62648diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62649new file mode 100644
62650index 0000000..8c8fc9d
62651--- /dev/null
62652+++ b/grsecurity/gracl_segv.c
62653@@ -0,0 +1,303 @@
62654+#include <linux/kernel.h>
62655+#include <linux/mm.h>
62656+#include <asm/uaccess.h>
62657+#include <asm/errno.h>
62658+#include <asm/mman.h>
62659+#include <net/sock.h>
62660+#include <linux/file.h>
62661+#include <linux/fs.h>
62662+#include <linux/net.h>
62663+#include <linux/in.h>
62664+#include <linux/slab.h>
62665+#include <linux/types.h>
62666+#include <linux/sched.h>
62667+#include <linux/timer.h>
62668+#include <linux/gracl.h>
62669+#include <linux/grsecurity.h>
62670+#include <linux/grinternal.h>
62671+
62672+static struct crash_uid *uid_set;
62673+static unsigned short uid_used;
62674+static DEFINE_SPINLOCK(gr_uid_lock);
62675+extern rwlock_t gr_inode_lock;
62676+extern struct acl_subject_label *
62677+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62678+ struct acl_role_label *role);
62679+
62680+#ifdef CONFIG_BTRFS_FS
62681+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62682+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62683+#endif
62684+
62685+static inline dev_t __get_dev(const struct dentry *dentry)
62686+{
62687+#ifdef CONFIG_BTRFS_FS
62688+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62689+ return get_btrfs_dev_from_inode(dentry->d_inode);
62690+ else
62691+#endif
62692+ return dentry->d_inode->i_sb->s_dev;
62693+}
62694+
62695+int
62696+gr_init_uidset(void)
62697+{
62698+ uid_set =
62699+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62700+ uid_used = 0;
62701+
62702+ return uid_set ? 1 : 0;
62703+}
62704+
62705+void
62706+gr_free_uidset(void)
62707+{
62708+ if (uid_set)
62709+ kfree(uid_set);
62710+
62711+ return;
62712+}
62713+
62714+int
62715+gr_find_uid(const uid_t uid)
62716+{
62717+ struct crash_uid *tmp = uid_set;
62718+ uid_t buid;
62719+ int low = 0, high = uid_used - 1, mid;
62720+
62721+ while (high >= low) {
62722+ mid = (low + high) >> 1;
62723+ buid = tmp[mid].uid;
62724+ if (buid == uid)
62725+ return mid;
62726+ if (buid > uid)
62727+ high = mid - 1;
62728+ if (buid < uid)
62729+ low = mid + 1;
62730+ }
62731+
62732+ return -1;
62733+}
62734+
62735+static __inline__ void
62736+gr_insertsort(void)
62737+{
62738+ unsigned short i, j;
62739+ struct crash_uid index;
62740+
62741+ for (i = 1; i < uid_used; i++) {
62742+ index = uid_set[i];
62743+ j = i;
62744+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62745+ uid_set[j] = uid_set[j - 1];
62746+ j--;
62747+ }
62748+ uid_set[j] = index;
62749+ }
62750+
62751+ return;
62752+}
62753+
62754+static __inline__ void
62755+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62756+{
62757+ int loc;
62758+ uid_t uid = GR_GLOBAL_UID(kuid);
62759+
62760+ if (uid_used == GR_UIDTABLE_MAX)
62761+ return;
62762+
62763+ loc = gr_find_uid(uid);
62764+
62765+ if (loc >= 0) {
62766+ uid_set[loc].expires = expires;
62767+ return;
62768+ }
62769+
62770+ uid_set[uid_used].uid = uid;
62771+ uid_set[uid_used].expires = expires;
62772+ uid_used++;
62773+
62774+ gr_insertsort();
62775+
62776+ return;
62777+}
62778+
62779+void
62780+gr_remove_uid(const unsigned short loc)
62781+{
62782+ unsigned short i;
62783+
62784+ for (i = loc + 1; i < uid_used; i++)
62785+ uid_set[i - 1] = uid_set[i];
62786+
62787+ uid_used--;
62788+
62789+ return;
62790+}
62791+
62792+int
62793+gr_check_crash_uid(const kuid_t kuid)
62794+{
62795+ int loc;
62796+ int ret = 0;
62797+ uid_t uid;
62798+
62799+ if (unlikely(!gr_acl_is_enabled()))
62800+ return 0;
62801+
62802+ uid = GR_GLOBAL_UID(kuid);
62803+
62804+ spin_lock(&gr_uid_lock);
62805+ loc = gr_find_uid(uid);
62806+
62807+ if (loc < 0)
62808+ goto out_unlock;
62809+
62810+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
62811+ gr_remove_uid(loc);
62812+ else
62813+ ret = 1;
62814+
62815+out_unlock:
62816+ spin_unlock(&gr_uid_lock);
62817+ return ret;
62818+}
62819+
62820+static __inline__ int
62821+proc_is_setxid(const struct cred *cred)
62822+{
62823+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62824+ !uid_eq(cred->uid, cred->fsuid))
62825+ return 1;
62826+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62827+ !gid_eq(cred->gid, cred->fsgid))
62828+ return 1;
62829+
62830+ return 0;
62831+}
62832+
62833+extern int gr_fake_force_sig(int sig, struct task_struct *t);
62834+
62835+void
62836+gr_handle_crash(struct task_struct *task, const int sig)
62837+{
62838+ struct acl_subject_label *curr;
62839+ struct task_struct *tsk, *tsk2;
62840+ const struct cred *cred;
62841+ const struct cred *cred2;
62842+
62843+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62844+ return;
62845+
62846+ if (unlikely(!gr_acl_is_enabled()))
62847+ return;
62848+
62849+ curr = task->acl;
62850+
62851+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
62852+ return;
62853+
62854+ if (time_before_eq(curr->expires, get_seconds())) {
62855+ curr->expires = 0;
62856+ curr->crashes = 0;
62857+ }
62858+
62859+ curr->crashes++;
62860+
62861+ if (!curr->expires)
62862+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62863+
62864+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62865+ time_after(curr->expires, get_seconds())) {
62866+ rcu_read_lock();
62867+ cred = __task_cred(task);
62868+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62869+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62870+ spin_lock(&gr_uid_lock);
62871+ gr_insert_uid(cred->uid, curr->expires);
62872+ spin_unlock(&gr_uid_lock);
62873+ curr->expires = 0;
62874+ curr->crashes = 0;
62875+ read_lock(&tasklist_lock);
62876+ do_each_thread(tsk2, tsk) {
62877+ cred2 = __task_cred(tsk);
62878+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
62879+ gr_fake_force_sig(SIGKILL, tsk);
62880+ } while_each_thread(tsk2, tsk);
62881+ read_unlock(&tasklist_lock);
62882+ } else {
62883+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62884+ read_lock(&tasklist_lock);
62885+ read_lock(&grsec_exec_file_lock);
62886+ do_each_thread(tsk2, tsk) {
62887+ if (likely(tsk != task)) {
62888+ // if this thread has the same subject as the one that triggered
62889+ // RES_CRASH and it's the same binary, kill it
62890+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62891+ gr_fake_force_sig(SIGKILL, tsk);
62892+ }
62893+ } while_each_thread(tsk2, tsk);
62894+ read_unlock(&grsec_exec_file_lock);
62895+ read_unlock(&tasklist_lock);
62896+ }
62897+ rcu_read_unlock();
62898+ }
62899+
62900+ return;
62901+}
62902+
62903+int
62904+gr_check_crash_exec(const struct file *filp)
62905+{
62906+ struct acl_subject_label *curr;
62907+
62908+ if (unlikely(!gr_acl_is_enabled()))
62909+ return 0;
62910+
62911+ read_lock(&gr_inode_lock);
62912+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62913+ __get_dev(filp->f_path.dentry),
62914+ current->role);
62915+ read_unlock(&gr_inode_lock);
62916+
62917+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62918+ (!curr->crashes && !curr->expires))
62919+ return 0;
62920+
62921+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62922+ time_after(curr->expires, get_seconds()))
62923+ return 1;
62924+ else if (time_before_eq(curr->expires, get_seconds())) {
62925+ curr->crashes = 0;
62926+ curr->expires = 0;
62927+ }
62928+
62929+ return 0;
62930+}
62931+
62932+void
62933+gr_handle_alertkill(struct task_struct *task)
62934+{
62935+ struct acl_subject_label *curracl;
62936+ __u32 curr_ip;
62937+ struct task_struct *p, *p2;
62938+
62939+ if (unlikely(!gr_acl_is_enabled()))
62940+ return;
62941+
62942+ curracl = task->acl;
62943+ curr_ip = task->signal->curr_ip;
62944+
62945+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62946+ read_lock(&tasklist_lock);
62947+ do_each_thread(p2, p) {
62948+ if (p->signal->curr_ip == curr_ip)
62949+ gr_fake_force_sig(SIGKILL, p);
62950+ } while_each_thread(p2, p);
62951+ read_unlock(&tasklist_lock);
62952+ } else if (curracl->mode & GR_KILLPROC)
62953+ gr_fake_force_sig(SIGKILL, task);
62954+
62955+ return;
62956+}
62957diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62958new file mode 100644
62959index 0000000..98011b0
62960--- /dev/null
62961+++ b/grsecurity/gracl_shm.c
62962@@ -0,0 +1,40 @@
62963+#include <linux/kernel.h>
62964+#include <linux/mm.h>
62965+#include <linux/sched.h>
62966+#include <linux/file.h>
62967+#include <linux/ipc.h>
62968+#include <linux/gracl.h>
62969+#include <linux/grsecurity.h>
62970+#include <linux/grinternal.h>
62971+
62972+int
62973+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62974+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
62975+{
62976+ struct task_struct *task;
62977+
62978+ if (!gr_acl_is_enabled())
62979+ return 1;
62980+
62981+ rcu_read_lock();
62982+ read_lock(&tasklist_lock);
62983+
62984+ task = find_task_by_vpid(shm_cprid);
62985+
62986+ if (unlikely(!task))
62987+ task = find_task_by_vpid(shm_lapid);
62988+
62989+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62990+ (task_pid_nr(task) == shm_lapid)) &&
62991+ (task->acl->mode & GR_PROTSHM) &&
62992+ (task->acl != current->acl))) {
62993+ read_unlock(&tasklist_lock);
62994+ rcu_read_unlock();
62995+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
62996+ return 0;
62997+ }
62998+ read_unlock(&tasklist_lock);
62999+ rcu_read_unlock();
63000+
63001+ return 1;
63002+}
63003diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63004new file mode 100644
63005index 0000000..bc0be01
63006--- /dev/null
63007+++ b/grsecurity/grsec_chdir.c
63008@@ -0,0 +1,19 @@
63009+#include <linux/kernel.h>
63010+#include <linux/sched.h>
63011+#include <linux/fs.h>
63012+#include <linux/file.h>
63013+#include <linux/grsecurity.h>
63014+#include <linux/grinternal.h>
63015+
63016+void
63017+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63018+{
63019+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63020+ if ((grsec_enable_chdir && grsec_enable_group &&
63021+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63022+ !grsec_enable_group)) {
63023+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63024+ }
63025+#endif
63026+ return;
63027+}
63028diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63029new file mode 100644
63030index 0000000..6d2de57
63031--- /dev/null
63032+++ b/grsecurity/grsec_chroot.c
63033@@ -0,0 +1,357 @@
63034+#include <linux/kernel.h>
63035+#include <linux/module.h>
63036+#include <linux/sched.h>
63037+#include <linux/file.h>
63038+#include <linux/fs.h>
63039+#include <linux/mount.h>
63040+#include <linux/types.h>
63041+#include "../fs/mount.h"
63042+#include <linux/grsecurity.h>
63043+#include <linux/grinternal.h>
63044+
63045+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
63046+{
63047+#ifdef CONFIG_GRKERNSEC
63048+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
63049+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
63050+ task->gr_is_chrooted = 1;
63051+ else
63052+ task->gr_is_chrooted = 0;
63053+
63054+ task->gr_chroot_dentry = path->dentry;
63055+#endif
63056+ return;
63057+}
63058+
63059+void gr_clear_chroot_entries(struct task_struct *task)
63060+{
63061+#ifdef CONFIG_GRKERNSEC
63062+ task->gr_is_chrooted = 0;
63063+ task->gr_chroot_dentry = NULL;
63064+#endif
63065+ return;
63066+}
63067+
63068+int
63069+gr_handle_chroot_unix(const pid_t pid)
63070+{
63071+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63072+ struct task_struct *p;
63073+
63074+ if (unlikely(!grsec_enable_chroot_unix))
63075+ return 1;
63076+
63077+ if (likely(!proc_is_chrooted(current)))
63078+ return 1;
63079+
63080+ rcu_read_lock();
63081+ read_lock(&tasklist_lock);
63082+ p = find_task_by_vpid_unrestricted(pid);
63083+ if (unlikely(p && !have_same_root(current, p))) {
63084+ read_unlock(&tasklist_lock);
63085+ rcu_read_unlock();
63086+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
63087+ return 0;
63088+ }
63089+ read_unlock(&tasklist_lock);
63090+ rcu_read_unlock();
63091+#endif
63092+ return 1;
63093+}
63094+
63095+int
63096+gr_handle_chroot_nice(void)
63097+{
63098+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63099+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
63100+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
63101+ return -EPERM;
63102+ }
63103+#endif
63104+ return 0;
63105+}
63106+
63107+int
63108+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
63109+{
63110+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63111+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
63112+ && proc_is_chrooted(current)) {
63113+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
63114+ return -EACCES;
63115+ }
63116+#endif
63117+ return 0;
63118+}
63119+
63120+int
63121+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
63122+{
63123+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63124+ struct task_struct *p;
63125+ int ret = 0;
63126+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
63127+ return ret;
63128+
63129+ read_lock(&tasklist_lock);
63130+ do_each_pid_task(pid, type, p) {
63131+ if (!have_same_root(current, p)) {
63132+ ret = 1;
63133+ goto out;
63134+ }
63135+ } while_each_pid_task(pid, type, p);
63136+out:
63137+ read_unlock(&tasklist_lock);
63138+ return ret;
63139+#endif
63140+ return 0;
63141+}
63142+
63143+int
63144+gr_pid_is_chrooted(struct task_struct *p)
63145+{
63146+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63147+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
63148+ return 0;
63149+
63150+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
63151+ !have_same_root(current, p)) {
63152+ return 1;
63153+ }
63154+#endif
63155+ return 0;
63156+}
63157+
63158+EXPORT_SYMBOL(gr_pid_is_chrooted);
63159+
63160+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
63161+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
63162+{
63163+ struct path path, currentroot;
63164+ int ret = 0;
63165+
63166+ path.dentry = (struct dentry *)u_dentry;
63167+ path.mnt = (struct vfsmount *)u_mnt;
63168+ get_fs_root(current->fs, &currentroot);
63169+ if (path_is_under(&path, &currentroot))
63170+ ret = 1;
63171+ path_put(&currentroot);
63172+
63173+ return ret;
63174+}
63175+#endif
63176+
63177+int
63178+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
63179+{
63180+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63181+ if (!grsec_enable_chroot_fchdir)
63182+ return 1;
63183+
63184+ if (!proc_is_chrooted(current))
63185+ return 1;
63186+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
63187+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
63188+ return 0;
63189+ }
63190+#endif
63191+ return 1;
63192+}
63193+
63194+int
63195+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63196+ const time_t shm_createtime)
63197+{
63198+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63199+ struct task_struct *p;
63200+ time_t starttime;
63201+
63202+ if (unlikely(!grsec_enable_chroot_shmat))
63203+ return 1;
63204+
63205+ if (likely(!proc_is_chrooted(current)))
63206+ return 1;
63207+
63208+ rcu_read_lock();
63209+ read_lock(&tasklist_lock);
63210+
63211+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
63212+ starttime = p->start_time.tv_sec;
63213+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
63214+ if (have_same_root(current, p)) {
63215+ goto allow;
63216+ } else {
63217+ read_unlock(&tasklist_lock);
63218+ rcu_read_unlock();
63219+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63220+ return 0;
63221+ }
63222+ }
63223+ /* creator exited, pid reuse, fall through to next check */
63224+ }
63225+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
63226+ if (unlikely(!have_same_root(current, p))) {
63227+ read_unlock(&tasklist_lock);
63228+ rcu_read_unlock();
63229+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63230+ return 0;
63231+ }
63232+ }
63233+
63234+allow:
63235+ read_unlock(&tasklist_lock);
63236+ rcu_read_unlock();
63237+#endif
63238+ return 1;
63239+}
63240+
63241+void
63242+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
63243+{
63244+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63245+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
63246+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
63247+#endif
63248+ return;
63249+}
63250+
63251+int
63252+gr_handle_chroot_mknod(const struct dentry *dentry,
63253+ const struct vfsmount *mnt, const int mode)
63254+{
63255+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63256+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
63257+ proc_is_chrooted(current)) {
63258+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
63259+ return -EPERM;
63260+ }
63261+#endif
63262+ return 0;
63263+}
63264+
63265+int
63266+gr_handle_chroot_mount(const struct dentry *dentry,
63267+ const struct vfsmount *mnt, const char *dev_name)
63268+{
63269+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63270+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
63271+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
63272+ return -EPERM;
63273+ }
63274+#endif
63275+ return 0;
63276+}
63277+
63278+int
63279+gr_handle_chroot_pivot(void)
63280+{
63281+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63282+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
63283+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
63284+ return -EPERM;
63285+ }
63286+#endif
63287+ return 0;
63288+}
63289+
63290+int
63291+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
63292+{
63293+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63294+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
63295+ !gr_is_outside_chroot(dentry, mnt)) {
63296+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
63297+ return -EPERM;
63298+ }
63299+#endif
63300+ return 0;
63301+}
63302+
63303+extern const char *captab_log[];
63304+extern int captab_log_entries;
63305+
63306+int
63307+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63308+{
63309+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63310+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63311+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63312+ if (cap_raised(chroot_caps, cap)) {
63313+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
63314+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
63315+ }
63316+ return 0;
63317+ }
63318+ }
63319+#endif
63320+ return 1;
63321+}
63322+
63323+int
63324+gr_chroot_is_capable(const int cap)
63325+{
63326+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63327+ return gr_task_chroot_is_capable(current, current_cred(), cap);
63328+#endif
63329+ return 1;
63330+}
63331+
63332+int
63333+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
63334+{
63335+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63336+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63337+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63338+ if (cap_raised(chroot_caps, cap)) {
63339+ return 0;
63340+ }
63341+ }
63342+#endif
63343+ return 1;
63344+}
63345+
63346+int
63347+gr_chroot_is_capable_nolog(const int cap)
63348+{
63349+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63350+ return gr_task_chroot_is_capable_nolog(current, cap);
63351+#endif
63352+ return 1;
63353+}
63354+
63355+int
63356+gr_handle_chroot_sysctl(const int op)
63357+{
63358+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63359+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
63360+ proc_is_chrooted(current))
63361+ return -EACCES;
63362+#endif
63363+ return 0;
63364+}
63365+
63366+void
63367+gr_handle_chroot_chdir(struct path *path)
63368+{
63369+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63370+ if (grsec_enable_chroot_chdir)
63371+ set_fs_pwd(current->fs, path);
63372+#endif
63373+ return;
63374+}
63375+
63376+int
63377+gr_handle_chroot_chmod(const struct dentry *dentry,
63378+ const struct vfsmount *mnt, const int mode)
63379+{
63380+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63381+ /* allow chmod +s on directories, but not files */
63382+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
63383+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
63384+ proc_is_chrooted(current)) {
63385+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
63386+ return -EPERM;
63387+ }
63388+#endif
63389+ return 0;
63390+}
63391diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
63392new file mode 100644
63393index 0000000..207d409
63394--- /dev/null
63395+++ b/grsecurity/grsec_disabled.c
63396@@ -0,0 +1,434 @@
63397+#include <linux/kernel.h>
63398+#include <linux/module.h>
63399+#include <linux/sched.h>
63400+#include <linux/file.h>
63401+#include <linux/fs.h>
63402+#include <linux/kdev_t.h>
63403+#include <linux/net.h>
63404+#include <linux/in.h>
63405+#include <linux/ip.h>
63406+#include <linux/skbuff.h>
63407+#include <linux/sysctl.h>
63408+
63409+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63410+void
63411+pax_set_initial_flags(struct linux_binprm *bprm)
63412+{
63413+ return;
63414+}
63415+#endif
63416+
63417+#ifdef CONFIG_SYSCTL
63418+__u32
63419+gr_handle_sysctl(const struct ctl_table * table, const int op)
63420+{
63421+ return 0;
63422+}
63423+#endif
63424+
63425+#ifdef CONFIG_TASKSTATS
63426+int gr_is_taskstats_denied(int pid)
63427+{
63428+ return 0;
63429+}
63430+#endif
63431+
63432+int
63433+gr_acl_is_enabled(void)
63434+{
63435+ return 0;
63436+}
63437+
63438+void
63439+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
63440+{
63441+ return;
63442+}
63443+
63444+int
63445+gr_handle_rawio(const struct inode *inode)
63446+{
63447+ return 0;
63448+}
63449+
63450+void
63451+gr_acl_handle_psacct(struct task_struct *task, const long code)
63452+{
63453+ return;
63454+}
63455+
63456+int
63457+gr_handle_ptrace(struct task_struct *task, const long request)
63458+{
63459+ return 0;
63460+}
63461+
63462+int
63463+gr_handle_proc_ptrace(struct task_struct *task)
63464+{
63465+ return 0;
63466+}
63467+
63468+int
63469+gr_set_acls(const int type)
63470+{
63471+ return 0;
63472+}
63473+
63474+int
63475+gr_check_hidden_task(const struct task_struct *tsk)
63476+{
63477+ return 0;
63478+}
63479+
63480+int
63481+gr_check_protected_task(const struct task_struct *task)
63482+{
63483+ return 0;
63484+}
63485+
63486+int
63487+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
63488+{
63489+ return 0;
63490+}
63491+
63492+void
63493+gr_copy_label(struct task_struct *tsk)
63494+{
63495+ return;
63496+}
63497+
63498+void
63499+gr_set_pax_flags(struct task_struct *task)
63500+{
63501+ return;
63502+}
63503+
63504+int
63505+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63506+ const int unsafe_share)
63507+{
63508+ return 0;
63509+}
63510+
63511+void
63512+gr_handle_delete(const ino_t ino, const dev_t dev)
63513+{
63514+ return;
63515+}
63516+
63517+void
63518+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63519+{
63520+ return;
63521+}
63522+
63523+void
63524+gr_handle_crash(struct task_struct *task, const int sig)
63525+{
63526+ return;
63527+}
63528+
63529+int
63530+gr_check_crash_exec(const struct file *filp)
63531+{
63532+ return 0;
63533+}
63534+
63535+int
63536+gr_check_crash_uid(const kuid_t uid)
63537+{
63538+ return 0;
63539+}
63540+
63541+void
63542+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63543+ struct dentry *old_dentry,
63544+ struct dentry *new_dentry,
63545+ struct vfsmount *mnt, const __u8 replace)
63546+{
63547+ return;
63548+}
63549+
63550+int
63551+gr_search_socket(const int family, const int type, const int protocol)
63552+{
63553+ return 1;
63554+}
63555+
63556+int
63557+gr_search_connectbind(const int mode, const struct socket *sock,
63558+ const struct sockaddr_in *addr)
63559+{
63560+ return 0;
63561+}
63562+
63563+void
63564+gr_handle_alertkill(struct task_struct *task)
63565+{
63566+ return;
63567+}
63568+
63569+__u32
63570+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63571+{
63572+ return 1;
63573+}
63574+
63575+__u32
63576+gr_acl_handle_hidden_file(const struct dentry * dentry,
63577+ const struct vfsmount * mnt)
63578+{
63579+ return 1;
63580+}
63581+
63582+__u32
63583+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63584+ int acc_mode)
63585+{
63586+ return 1;
63587+}
63588+
63589+__u32
63590+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63591+{
63592+ return 1;
63593+}
63594+
63595+__u32
63596+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63597+{
63598+ return 1;
63599+}
63600+
63601+int
63602+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63603+ unsigned int *vm_flags)
63604+{
63605+ return 1;
63606+}
63607+
63608+__u32
63609+gr_acl_handle_truncate(const struct dentry * dentry,
63610+ const struct vfsmount * mnt)
63611+{
63612+ return 1;
63613+}
63614+
63615+__u32
63616+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63617+{
63618+ return 1;
63619+}
63620+
63621+__u32
63622+gr_acl_handle_access(const struct dentry * dentry,
63623+ const struct vfsmount * mnt, const int fmode)
63624+{
63625+ return 1;
63626+}
63627+
63628+__u32
63629+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63630+ umode_t *mode)
63631+{
63632+ return 1;
63633+}
63634+
63635+__u32
63636+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63637+{
63638+ return 1;
63639+}
63640+
63641+__u32
63642+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63643+{
63644+ return 1;
63645+}
63646+
63647+void
63648+grsecurity_init(void)
63649+{
63650+ return;
63651+}
63652+
63653+umode_t gr_acl_umask(void)
63654+{
63655+ return 0;
63656+}
63657+
63658+__u32
63659+gr_acl_handle_mknod(const struct dentry * new_dentry,
63660+ const struct dentry * parent_dentry,
63661+ const struct vfsmount * parent_mnt,
63662+ const int mode)
63663+{
63664+ return 1;
63665+}
63666+
63667+__u32
63668+gr_acl_handle_mkdir(const struct dentry * new_dentry,
63669+ const struct dentry * parent_dentry,
63670+ const struct vfsmount * parent_mnt)
63671+{
63672+ return 1;
63673+}
63674+
63675+__u32
63676+gr_acl_handle_symlink(const struct dentry * new_dentry,
63677+ const struct dentry * parent_dentry,
63678+ const struct vfsmount * parent_mnt, const struct filename *from)
63679+{
63680+ return 1;
63681+}
63682+
63683+__u32
63684+gr_acl_handle_link(const struct dentry * new_dentry,
63685+ const struct dentry * parent_dentry,
63686+ const struct vfsmount * parent_mnt,
63687+ const struct dentry * old_dentry,
63688+ const struct vfsmount * old_mnt, const struct filename *to)
63689+{
63690+ return 1;
63691+}
63692+
63693+int
63694+gr_acl_handle_rename(const struct dentry *new_dentry,
63695+ const struct dentry *parent_dentry,
63696+ const struct vfsmount *parent_mnt,
63697+ const struct dentry *old_dentry,
63698+ const struct inode *old_parent_inode,
63699+ const struct vfsmount *old_mnt, const struct filename *newname)
63700+{
63701+ return 0;
63702+}
63703+
63704+int
63705+gr_acl_handle_filldir(const struct file *file, const char *name,
63706+ const int namelen, const ino_t ino)
63707+{
63708+ return 1;
63709+}
63710+
63711+int
63712+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63713+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63714+{
63715+ return 1;
63716+}
63717+
63718+int
63719+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63720+{
63721+ return 0;
63722+}
63723+
63724+int
63725+gr_search_accept(const struct socket *sock)
63726+{
63727+ return 0;
63728+}
63729+
63730+int
63731+gr_search_listen(const struct socket *sock)
63732+{
63733+ return 0;
63734+}
63735+
63736+int
63737+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63738+{
63739+ return 0;
63740+}
63741+
63742+__u32
63743+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63744+{
63745+ return 1;
63746+}
63747+
63748+__u32
63749+gr_acl_handle_creat(const struct dentry * dentry,
63750+ const struct dentry * p_dentry,
63751+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63752+ const int imode)
63753+{
63754+ return 1;
63755+}
63756+
63757+void
63758+gr_acl_handle_exit(void)
63759+{
63760+ return;
63761+}
63762+
63763+int
63764+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63765+{
63766+ return 1;
63767+}
63768+
63769+void
63770+gr_set_role_label(const kuid_t uid, const kgid_t gid)
63771+{
63772+ return;
63773+}
63774+
63775+int
63776+gr_acl_handle_procpidmem(const struct task_struct *task)
63777+{
63778+ return 0;
63779+}
63780+
63781+int
63782+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63783+{
63784+ return 0;
63785+}
63786+
63787+int
63788+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63789+{
63790+ return 0;
63791+}
63792+
63793+void
63794+gr_set_kernel_label(struct task_struct *task)
63795+{
63796+ return;
63797+}
63798+
63799+int
63800+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63801+{
63802+ return 0;
63803+}
63804+
63805+int
63806+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63807+{
63808+ return 0;
63809+}
63810+
63811+int gr_acl_enable_at_secure(void)
63812+{
63813+ return 0;
63814+}
63815+
63816+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63817+{
63818+ return dentry->d_inode->i_sb->s_dev;
63819+}
63820+
63821+void gr_put_exec_file(struct task_struct *task)
63822+{
63823+ return;
63824+}
63825+
63826+EXPORT_SYMBOL(gr_set_kernel_label);
63827+#ifdef CONFIG_SECURITY
63828+EXPORT_SYMBOL(gr_check_user_change);
63829+EXPORT_SYMBOL(gr_check_group_change);
63830+#endif
63831diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63832new file mode 100644
63833index 0000000..387032b
63834--- /dev/null
63835+++ b/grsecurity/grsec_exec.c
63836@@ -0,0 +1,187 @@
63837+#include <linux/kernel.h>
63838+#include <linux/sched.h>
63839+#include <linux/file.h>
63840+#include <linux/binfmts.h>
63841+#include <linux/fs.h>
63842+#include <linux/types.h>
63843+#include <linux/grdefs.h>
63844+#include <linux/grsecurity.h>
63845+#include <linux/grinternal.h>
63846+#include <linux/capability.h>
63847+#include <linux/module.h>
63848+#include <linux/compat.h>
63849+
63850+#include <asm/uaccess.h>
63851+
63852+#ifdef CONFIG_GRKERNSEC_EXECLOG
63853+static char gr_exec_arg_buf[132];
63854+static DEFINE_MUTEX(gr_exec_arg_mutex);
63855+#endif
63856+
63857+struct user_arg_ptr {
63858+#ifdef CONFIG_COMPAT
63859+ bool is_compat;
63860+#endif
63861+ union {
63862+ const char __user *const __user *native;
63863+#ifdef CONFIG_COMPAT
63864+ const compat_uptr_t __user *compat;
63865+#endif
63866+ } ptr;
63867+};
63868+
63869+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63870+
63871+void
63872+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63873+{
63874+#ifdef CONFIG_GRKERNSEC_EXECLOG
63875+ char *grarg = gr_exec_arg_buf;
63876+ unsigned int i, x, execlen = 0;
63877+ char c;
63878+
63879+ if (!((grsec_enable_execlog && grsec_enable_group &&
63880+ in_group_p(grsec_audit_gid))
63881+ || (grsec_enable_execlog && !grsec_enable_group)))
63882+ return;
63883+
63884+ mutex_lock(&gr_exec_arg_mutex);
63885+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
63886+
63887+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
63888+ const char __user *p;
63889+ unsigned int len;
63890+
63891+ p = get_user_arg_ptr(argv, i);
63892+ if (IS_ERR(p))
63893+ goto log;
63894+
63895+ len = strnlen_user(p, 128 - execlen);
63896+ if (len > 128 - execlen)
63897+ len = 128 - execlen;
63898+ else if (len > 0)
63899+ len--;
63900+ if (copy_from_user(grarg + execlen, p, len))
63901+ goto log;
63902+
63903+ /* rewrite unprintable characters */
63904+ for (x = 0; x < len; x++) {
63905+ c = *(grarg + execlen + x);
63906+ if (c < 32 || c > 126)
63907+ *(grarg + execlen + x) = ' ';
63908+ }
63909+
63910+ execlen += len;
63911+ *(grarg + execlen) = ' ';
63912+ *(grarg + execlen + 1) = '\0';
63913+ execlen++;
63914+ }
63915+
63916+ log:
63917+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63918+ bprm->file->f_path.mnt, grarg);
63919+ mutex_unlock(&gr_exec_arg_mutex);
63920+#endif
63921+ return;
63922+}
63923+
63924+#ifdef CONFIG_GRKERNSEC
63925+extern int gr_acl_is_capable(const int cap);
63926+extern int gr_acl_is_capable_nolog(const int cap);
63927+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63928+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63929+extern int gr_chroot_is_capable(const int cap);
63930+extern int gr_chroot_is_capable_nolog(const int cap);
63931+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63932+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63933+#endif
63934+
63935+const char *captab_log[] = {
63936+ "CAP_CHOWN",
63937+ "CAP_DAC_OVERRIDE",
63938+ "CAP_DAC_READ_SEARCH",
63939+ "CAP_FOWNER",
63940+ "CAP_FSETID",
63941+ "CAP_KILL",
63942+ "CAP_SETGID",
63943+ "CAP_SETUID",
63944+ "CAP_SETPCAP",
63945+ "CAP_LINUX_IMMUTABLE",
63946+ "CAP_NET_BIND_SERVICE",
63947+ "CAP_NET_BROADCAST",
63948+ "CAP_NET_ADMIN",
63949+ "CAP_NET_RAW",
63950+ "CAP_IPC_LOCK",
63951+ "CAP_IPC_OWNER",
63952+ "CAP_SYS_MODULE",
63953+ "CAP_SYS_RAWIO",
63954+ "CAP_SYS_CHROOT",
63955+ "CAP_SYS_PTRACE",
63956+ "CAP_SYS_PACCT",
63957+ "CAP_SYS_ADMIN",
63958+ "CAP_SYS_BOOT",
63959+ "CAP_SYS_NICE",
63960+ "CAP_SYS_RESOURCE",
63961+ "CAP_SYS_TIME",
63962+ "CAP_SYS_TTY_CONFIG",
63963+ "CAP_MKNOD",
63964+ "CAP_LEASE",
63965+ "CAP_AUDIT_WRITE",
63966+ "CAP_AUDIT_CONTROL",
63967+ "CAP_SETFCAP",
63968+ "CAP_MAC_OVERRIDE",
63969+ "CAP_MAC_ADMIN",
63970+ "CAP_SYSLOG",
63971+ "CAP_WAKE_ALARM"
63972+};
63973+
63974+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63975+
63976+int gr_is_capable(const int cap)
63977+{
63978+#ifdef CONFIG_GRKERNSEC
63979+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63980+ return 1;
63981+ return 0;
63982+#else
63983+ return 1;
63984+#endif
63985+}
63986+
63987+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63988+{
63989+#ifdef CONFIG_GRKERNSEC
63990+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63991+ return 1;
63992+ return 0;
63993+#else
63994+ return 1;
63995+#endif
63996+}
63997+
63998+int gr_is_capable_nolog(const int cap)
63999+{
64000+#ifdef CONFIG_GRKERNSEC
64001+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64002+ return 1;
64003+ return 0;
64004+#else
64005+ return 1;
64006+#endif
64007+}
64008+
64009+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64010+{
64011+#ifdef CONFIG_GRKERNSEC
64012+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64013+ return 1;
64014+ return 0;
64015+#else
64016+ return 1;
64017+#endif
64018+}
64019+
64020+EXPORT_SYMBOL(gr_is_capable);
64021+EXPORT_SYMBOL(gr_is_capable_nolog);
64022+EXPORT_SYMBOL(gr_task_is_capable);
64023+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64024diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64025new file mode 100644
64026index 0000000..06cc6ea
64027--- /dev/null
64028+++ b/grsecurity/grsec_fifo.c
64029@@ -0,0 +1,24 @@
64030+#include <linux/kernel.h>
64031+#include <linux/sched.h>
64032+#include <linux/fs.h>
64033+#include <linux/file.h>
64034+#include <linux/grinternal.h>
64035+
64036+int
64037+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
64038+ const struct dentry *dir, const int flag, const int acc_mode)
64039+{
64040+#ifdef CONFIG_GRKERNSEC_FIFO
64041+ const struct cred *cred = current_cred();
64042+
64043+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
64044+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
64045+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
64046+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
64047+ if (!inode_permission(dentry->d_inode, acc_mode))
64048+ 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));
64049+ return -EACCES;
64050+ }
64051+#endif
64052+ return 0;
64053+}
64054diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
64055new file mode 100644
64056index 0000000..8ca18bf
64057--- /dev/null
64058+++ b/grsecurity/grsec_fork.c
64059@@ -0,0 +1,23 @@
64060+#include <linux/kernel.h>
64061+#include <linux/sched.h>
64062+#include <linux/grsecurity.h>
64063+#include <linux/grinternal.h>
64064+#include <linux/errno.h>
64065+
64066+void
64067+gr_log_forkfail(const int retval)
64068+{
64069+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64070+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
64071+ switch (retval) {
64072+ case -EAGAIN:
64073+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
64074+ break;
64075+ case -ENOMEM:
64076+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
64077+ break;
64078+ }
64079+ }
64080+#endif
64081+ return;
64082+}
64083diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
64084new file mode 100644
64085index 0000000..a862e9f
64086--- /dev/null
64087+++ b/grsecurity/grsec_init.c
64088@@ -0,0 +1,283 @@
64089+#include <linux/kernel.h>
64090+#include <linux/sched.h>
64091+#include <linux/mm.h>
64092+#include <linux/gracl.h>
64093+#include <linux/slab.h>
64094+#include <linux/vmalloc.h>
64095+#include <linux/percpu.h>
64096+#include <linux/module.h>
64097+
64098+int grsec_enable_ptrace_readexec;
64099+int grsec_enable_setxid;
64100+int grsec_enable_symlinkown;
64101+kgid_t grsec_symlinkown_gid;
64102+int grsec_enable_brute;
64103+int grsec_enable_link;
64104+int grsec_enable_dmesg;
64105+int grsec_enable_harden_ptrace;
64106+int grsec_enable_fifo;
64107+int grsec_enable_execlog;
64108+int grsec_enable_signal;
64109+int grsec_enable_forkfail;
64110+int grsec_enable_audit_ptrace;
64111+int grsec_enable_time;
64112+int grsec_enable_audit_textrel;
64113+int grsec_enable_group;
64114+kgid_t grsec_audit_gid;
64115+int grsec_enable_chdir;
64116+int grsec_enable_mount;
64117+int grsec_enable_rofs;
64118+int grsec_enable_chroot_findtask;
64119+int grsec_enable_chroot_mount;
64120+int grsec_enable_chroot_shmat;
64121+int grsec_enable_chroot_fchdir;
64122+int grsec_enable_chroot_double;
64123+int grsec_enable_chroot_pivot;
64124+int grsec_enable_chroot_chdir;
64125+int grsec_enable_chroot_chmod;
64126+int grsec_enable_chroot_mknod;
64127+int grsec_enable_chroot_nice;
64128+int grsec_enable_chroot_execlog;
64129+int grsec_enable_chroot_caps;
64130+int grsec_enable_chroot_sysctl;
64131+int grsec_enable_chroot_unix;
64132+int grsec_enable_tpe;
64133+kgid_t grsec_tpe_gid;
64134+int grsec_enable_blackhole;
64135+#ifdef CONFIG_IPV6_MODULE
64136+EXPORT_SYMBOL(grsec_enable_blackhole);
64137+#endif
64138+int grsec_lastack_retries;
64139+int grsec_enable_tpe_all;
64140+int grsec_enable_tpe_invert;
64141+int grsec_enable_socket_all;
64142+kgid_t grsec_socket_all_gid;
64143+int grsec_enable_socket_client;
64144+kgid_t grsec_socket_client_gid;
64145+int grsec_enable_socket_server;
64146+kgid_t grsec_socket_server_gid;
64147+int grsec_resource_logging;
64148+int grsec_disable_privio;
64149+int grsec_enable_log_rwxmaps;
64150+int grsec_lock;
64151+
64152+DEFINE_SPINLOCK(grsec_alert_lock);
64153+unsigned long grsec_alert_wtime = 0;
64154+unsigned long grsec_alert_fyet = 0;
64155+
64156+DEFINE_SPINLOCK(grsec_audit_lock);
64157+
64158+DEFINE_RWLOCK(grsec_exec_file_lock);
64159+
64160+char *gr_shared_page[4];
64161+
64162+char *gr_alert_log_fmt;
64163+char *gr_audit_log_fmt;
64164+char *gr_alert_log_buf;
64165+char *gr_audit_log_buf;
64166+
64167+extern struct gr_arg *gr_usermode;
64168+extern unsigned char *gr_system_salt;
64169+extern unsigned char *gr_system_sum;
64170+
64171+void __init
64172+grsecurity_init(void)
64173+{
64174+ int j;
64175+ /* create the per-cpu shared pages */
64176+
64177+#ifdef CONFIG_X86
64178+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
64179+#endif
64180+
64181+ for (j = 0; j < 4; j++) {
64182+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
64183+ if (gr_shared_page[j] == NULL) {
64184+ panic("Unable to allocate grsecurity shared page");
64185+ return;
64186+ }
64187+ }
64188+
64189+ /* allocate log buffers */
64190+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
64191+ if (!gr_alert_log_fmt) {
64192+ panic("Unable to allocate grsecurity alert log format buffer");
64193+ return;
64194+ }
64195+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
64196+ if (!gr_audit_log_fmt) {
64197+ panic("Unable to allocate grsecurity audit log format buffer");
64198+ return;
64199+ }
64200+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64201+ if (!gr_alert_log_buf) {
64202+ panic("Unable to allocate grsecurity alert log buffer");
64203+ return;
64204+ }
64205+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64206+ if (!gr_audit_log_buf) {
64207+ panic("Unable to allocate grsecurity audit log buffer");
64208+ return;
64209+ }
64210+
64211+ /* allocate memory for authentication structure */
64212+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
64213+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
64214+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
64215+
64216+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
64217+ panic("Unable to allocate grsecurity authentication structure");
64218+ return;
64219+ }
64220+
64221+
64222+#ifdef CONFIG_GRKERNSEC_IO
64223+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
64224+ grsec_disable_privio = 1;
64225+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64226+ grsec_disable_privio = 1;
64227+#else
64228+ grsec_disable_privio = 0;
64229+#endif
64230+#endif
64231+
64232+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64233+ /* for backward compatibility, tpe_invert always defaults to on if
64234+ enabled in the kernel
64235+ */
64236+ grsec_enable_tpe_invert = 1;
64237+#endif
64238+
64239+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64240+#ifndef CONFIG_GRKERNSEC_SYSCTL
64241+ grsec_lock = 1;
64242+#endif
64243+
64244+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64245+ grsec_enable_audit_textrel = 1;
64246+#endif
64247+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64248+ grsec_enable_log_rwxmaps = 1;
64249+#endif
64250+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64251+ grsec_enable_group = 1;
64252+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
64253+#endif
64254+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64255+ grsec_enable_ptrace_readexec = 1;
64256+#endif
64257+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64258+ grsec_enable_chdir = 1;
64259+#endif
64260+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64261+ grsec_enable_harden_ptrace = 1;
64262+#endif
64263+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64264+ grsec_enable_mount = 1;
64265+#endif
64266+#ifdef CONFIG_GRKERNSEC_LINK
64267+ grsec_enable_link = 1;
64268+#endif
64269+#ifdef CONFIG_GRKERNSEC_BRUTE
64270+ grsec_enable_brute = 1;
64271+#endif
64272+#ifdef CONFIG_GRKERNSEC_DMESG
64273+ grsec_enable_dmesg = 1;
64274+#endif
64275+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64276+ grsec_enable_blackhole = 1;
64277+ grsec_lastack_retries = 4;
64278+#endif
64279+#ifdef CONFIG_GRKERNSEC_FIFO
64280+ grsec_enable_fifo = 1;
64281+#endif
64282+#ifdef CONFIG_GRKERNSEC_EXECLOG
64283+ grsec_enable_execlog = 1;
64284+#endif
64285+#ifdef CONFIG_GRKERNSEC_SETXID
64286+ grsec_enable_setxid = 1;
64287+#endif
64288+#ifdef CONFIG_GRKERNSEC_SIGNAL
64289+ grsec_enable_signal = 1;
64290+#endif
64291+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64292+ grsec_enable_forkfail = 1;
64293+#endif
64294+#ifdef CONFIG_GRKERNSEC_TIME
64295+ grsec_enable_time = 1;
64296+#endif
64297+#ifdef CONFIG_GRKERNSEC_RESLOG
64298+ grsec_resource_logging = 1;
64299+#endif
64300+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64301+ grsec_enable_chroot_findtask = 1;
64302+#endif
64303+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64304+ grsec_enable_chroot_unix = 1;
64305+#endif
64306+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64307+ grsec_enable_chroot_mount = 1;
64308+#endif
64309+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64310+ grsec_enable_chroot_fchdir = 1;
64311+#endif
64312+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64313+ grsec_enable_chroot_shmat = 1;
64314+#endif
64315+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64316+ grsec_enable_audit_ptrace = 1;
64317+#endif
64318+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64319+ grsec_enable_chroot_double = 1;
64320+#endif
64321+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64322+ grsec_enable_chroot_pivot = 1;
64323+#endif
64324+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64325+ grsec_enable_chroot_chdir = 1;
64326+#endif
64327+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64328+ grsec_enable_chroot_chmod = 1;
64329+#endif
64330+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64331+ grsec_enable_chroot_mknod = 1;
64332+#endif
64333+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64334+ grsec_enable_chroot_nice = 1;
64335+#endif
64336+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64337+ grsec_enable_chroot_execlog = 1;
64338+#endif
64339+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64340+ grsec_enable_chroot_caps = 1;
64341+#endif
64342+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64343+ grsec_enable_chroot_sysctl = 1;
64344+#endif
64345+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64346+ grsec_enable_symlinkown = 1;
64347+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
64348+#endif
64349+#ifdef CONFIG_GRKERNSEC_TPE
64350+ grsec_enable_tpe = 1;
64351+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
64352+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64353+ grsec_enable_tpe_all = 1;
64354+#endif
64355+#endif
64356+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64357+ grsec_enable_socket_all = 1;
64358+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
64359+#endif
64360+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64361+ grsec_enable_socket_client = 1;
64362+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
64363+#endif
64364+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64365+ grsec_enable_socket_server = 1;
64366+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
64367+#endif
64368+#endif
64369+
64370+ return;
64371+}
64372diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
64373new file mode 100644
64374index 0000000..5e05e20
64375--- /dev/null
64376+++ b/grsecurity/grsec_link.c
64377@@ -0,0 +1,58 @@
64378+#include <linux/kernel.h>
64379+#include <linux/sched.h>
64380+#include <linux/fs.h>
64381+#include <linux/file.h>
64382+#include <linux/grinternal.h>
64383+
64384+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
64385+{
64386+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64387+ const struct inode *link_inode = link->dentry->d_inode;
64388+
64389+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
64390+ /* ignore root-owned links, e.g. /proc/self */
64391+ gr_is_global_nonroot(link_inode->i_uid) && target &&
64392+ !uid_eq(link_inode->i_uid, target->i_uid)) {
64393+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
64394+ return 1;
64395+ }
64396+#endif
64397+ return 0;
64398+}
64399+
64400+int
64401+gr_handle_follow_link(const struct inode *parent,
64402+ const struct inode *inode,
64403+ const struct dentry *dentry, const struct vfsmount *mnt)
64404+{
64405+#ifdef CONFIG_GRKERNSEC_LINK
64406+ const struct cred *cred = current_cred();
64407+
64408+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
64409+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
64410+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
64411+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
64412+ return -EACCES;
64413+ }
64414+#endif
64415+ return 0;
64416+}
64417+
64418+int
64419+gr_handle_hardlink(const struct dentry *dentry,
64420+ const struct vfsmount *mnt,
64421+ struct inode *inode, const int mode, const struct filename *to)
64422+{
64423+#ifdef CONFIG_GRKERNSEC_LINK
64424+ const struct cred *cred = current_cred();
64425+
64426+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
64427+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
64428+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
64429+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
64430+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
64431+ return -EPERM;
64432+ }
64433+#endif
64434+ return 0;
64435+}
64436diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
64437new file mode 100644
64438index 0000000..7c06085
64439--- /dev/null
64440+++ b/grsecurity/grsec_log.c
64441@@ -0,0 +1,326 @@
64442+#include <linux/kernel.h>
64443+#include <linux/sched.h>
64444+#include <linux/file.h>
64445+#include <linux/tty.h>
64446+#include <linux/fs.h>
64447+#include <linux/grinternal.h>
64448+
64449+#ifdef CONFIG_TREE_PREEMPT_RCU
64450+#define DISABLE_PREEMPT() preempt_disable()
64451+#define ENABLE_PREEMPT() preempt_enable()
64452+#else
64453+#define DISABLE_PREEMPT()
64454+#define ENABLE_PREEMPT()
64455+#endif
64456+
64457+#define BEGIN_LOCKS(x) \
64458+ DISABLE_PREEMPT(); \
64459+ rcu_read_lock(); \
64460+ read_lock(&tasklist_lock); \
64461+ read_lock(&grsec_exec_file_lock); \
64462+ if (x != GR_DO_AUDIT) \
64463+ spin_lock(&grsec_alert_lock); \
64464+ else \
64465+ spin_lock(&grsec_audit_lock)
64466+
64467+#define END_LOCKS(x) \
64468+ if (x != GR_DO_AUDIT) \
64469+ spin_unlock(&grsec_alert_lock); \
64470+ else \
64471+ spin_unlock(&grsec_audit_lock); \
64472+ read_unlock(&grsec_exec_file_lock); \
64473+ read_unlock(&tasklist_lock); \
64474+ rcu_read_unlock(); \
64475+ ENABLE_PREEMPT(); \
64476+ if (x == GR_DONT_AUDIT) \
64477+ gr_handle_alertkill(current)
64478+
64479+enum {
64480+ FLOODING,
64481+ NO_FLOODING
64482+};
64483+
64484+extern char *gr_alert_log_fmt;
64485+extern char *gr_audit_log_fmt;
64486+extern char *gr_alert_log_buf;
64487+extern char *gr_audit_log_buf;
64488+
64489+static int gr_log_start(int audit)
64490+{
64491+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
64492+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
64493+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64494+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
64495+ unsigned long curr_secs = get_seconds();
64496+
64497+ if (audit == GR_DO_AUDIT)
64498+ goto set_fmt;
64499+
64500+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
64501+ grsec_alert_wtime = curr_secs;
64502+ grsec_alert_fyet = 0;
64503+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
64504+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
64505+ grsec_alert_fyet++;
64506+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
64507+ grsec_alert_wtime = curr_secs;
64508+ grsec_alert_fyet++;
64509+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64510+ return FLOODING;
64511+ }
64512+ else return FLOODING;
64513+
64514+set_fmt:
64515+#endif
64516+ memset(buf, 0, PAGE_SIZE);
64517+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
64518+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64519+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64520+ } else if (current->signal->curr_ip) {
64521+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64522+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64523+ } else if (gr_acl_is_enabled()) {
64524+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64525+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64526+ } else {
64527+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
64528+ strcpy(buf, fmt);
64529+ }
64530+
64531+ return NO_FLOODING;
64532+}
64533+
64534+static void gr_log_middle(int audit, const char *msg, va_list ap)
64535+ __attribute__ ((format (printf, 2, 0)));
64536+
64537+static void gr_log_middle(int audit, const char *msg, va_list ap)
64538+{
64539+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64540+ unsigned int len = strlen(buf);
64541+
64542+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64543+
64544+ return;
64545+}
64546+
64547+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64548+ __attribute__ ((format (printf, 2, 3)));
64549+
64550+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64551+{
64552+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64553+ unsigned int len = strlen(buf);
64554+ va_list ap;
64555+
64556+ va_start(ap, msg);
64557+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64558+ va_end(ap);
64559+
64560+ return;
64561+}
64562+
64563+static void gr_log_end(int audit, int append_default)
64564+{
64565+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64566+ if (append_default) {
64567+ struct task_struct *task = current;
64568+ struct task_struct *parent = task->real_parent;
64569+ const struct cred *cred = __task_cred(task);
64570+ const struct cred *pcred = __task_cred(parent);
64571+ unsigned int len = strlen(buf);
64572+
64573+ 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));
64574+ }
64575+
64576+ printk("%s\n", buf);
64577+
64578+ return;
64579+}
64580+
64581+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64582+{
64583+ int logtype;
64584+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64585+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64586+ void *voidptr = NULL;
64587+ int num1 = 0, num2 = 0;
64588+ unsigned long ulong1 = 0, ulong2 = 0;
64589+ struct dentry *dentry = NULL;
64590+ struct vfsmount *mnt = NULL;
64591+ struct file *file = NULL;
64592+ struct task_struct *task = NULL;
64593+ const struct cred *cred, *pcred;
64594+ va_list ap;
64595+
64596+ BEGIN_LOCKS(audit);
64597+ logtype = gr_log_start(audit);
64598+ if (logtype == FLOODING) {
64599+ END_LOCKS(audit);
64600+ return;
64601+ }
64602+ va_start(ap, argtypes);
64603+ switch (argtypes) {
64604+ case GR_TTYSNIFF:
64605+ task = va_arg(ap, struct task_struct *);
64606+ 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));
64607+ break;
64608+ case GR_SYSCTL_HIDDEN:
64609+ str1 = va_arg(ap, char *);
64610+ gr_log_middle_varargs(audit, msg, result, str1);
64611+ break;
64612+ case GR_RBAC:
64613+ dentry = va_arg(ap, struct dentry *);
64614+ mnt = va_arg(ap, struct vfsmount *);
64615+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64616+ break;
64617+ case GR_RBAC_STR:
64618+ dentry = va_arg(ap, struct dentry *);
64619+ mnt = va_arg(ap, struct vfsmount *);
64620+ str1 = va_arg(ap, char *);
64621+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64622+ break;
64623+ case GR_STR_RBAC:
64624+ str1 = va_arg(ap, char *);
64625+ dentry = va_arg(ap, struct dentry *);
64626+ mnt = va_arg(ap, struct vfsmount *);
64627+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64628+ break;
64629+ case GR_RBAC_MODE2:
64630+ dentry = va_arg(ap, struct dentry *);
64631+ mnt = va_arg(ap, struct vfsmount *);
64632+ str1 = va_arg(ap, char *);
64633+ str2 = va_arg(ap, char *);
64634+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64635+ break;
64636+ case GR_RBAC_MODE3:
64637+ dentry = va_arg(ap, struct dentry *);
64638+ mnt = va_arg(ap, struct vfsmount *);
64639+ str1 = va_arg(ap, char *);
64640+ str2 = va_arg(ap, char *);
64641+ str3 = va_arg(ap, char *);
64642+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64643+ break;
64644+ case GR_FILENAME:
64645+ dentry = va_arg(ap, struct dentry *);
64646+ mnt = va_arg(ap, struct vfsmount *);
64647+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64648+ break;
64649+ case GR_STR_FILENAME:
64650+ str1 = va_arg(ap, char *);
64651+ dentry = va_arg(ap, struct dentry *);
64652+ mnt = va_arg(ap, struct vfsmount *);
64653+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64654+ break;
64655+ case GR_FILENAME_STR:
64656+ dentry = va_arg(ap, struct dentry *);
64657+ mnt = va_arg(ap, struct vfsmount *);
64658+ str1 = va_arg(ap, char *);
64659+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64660+ break;
64661+ case GR_FILENAME_TWO_INT:
64662+ dentry = va_arg(ap, struct dentry *);
64663+ mnt = va_arg(ap, struct vfsmount *);
64664+ num1 = va_arg(ap, int);
64665+ num2 = va_arg(ap, int);
64666+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64667+ break;
64668+ case GR_FILENAME_TWO_INT_STR:
64669+ dentry = va_arg(ap, struct dentry *);
64670+ mnt = va_arg(ap, struct vfsmount *);
64671+ num1 = va_arg(ap, int);
64672+ num2 = va_arg(ap, int);
64673+ str1 = va_arg(ap, char *);
64674+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64675+ break;
64676+ case GR_TEXTREL:
64677+ file = va_arg(ap, struct file *);
64678+ ulong1 = va_arg(ap, unsigned long);
64679+ ulong2 = va_arg(ap, unsigned long);
64680+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64681+ break;
64682+ case GR_PTRACE:
64683+ task = va_arg(ap, struct task_struct *);
64684+ 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));
64685+ break;
64686+ case GR_RESOURCE:
64687+ task = va_arg(ap, struct task_struct *);
64688+ cred = __task_cred(task);
64689+ pcred = __task_cred(task->real_parent);
64690+ ulong1 = va_arg(ap, unsigned long);
64691+ str1 = va_arg(ap, char *);
64692+ ulong2 = va_arg(ap, unsigned long);
64693+ 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));
64694+ break;
64695+ case GR_CAP:
64696+ task = va_arg(ap, struct task_struct *);
64697+ cred = __task_cred(task);
64698+ pcred = __task_cred(task->real_parent);
64699+ str1 = va_arg(ap, char *);
64700+ 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));
64701+ break;
64702+ case GR_SIG:
64703+ str1 = va_arg(ap, char *);
64704+ voidptr = va_arg(ap, void *);
64705+ gr_log_middle_varargs(audit, msg, str1, voidptr);
64706+ break;
64707+ case GR_SIG2:
64708+ task = va_arg(ap, struct task_struct *);
64709+ cred = __task_cred(task);
64710+ pcred = __task_cred(task->real_parent);
64711+ num1 = va_arg(ap, int);
64712+ 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));
64713+ break;
64714+ case GR_CRASH1:
64715+ task = va_arg(ap, struct task_struct *);
64716+ cred = __task_cred(task);
64717+ pcred = __task_cred(task->real_parent);
64718+ ulong1 = va_arg(ap, unsigned long);
64719+ 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);
64720+ break;
64721+ case GR_CRASH2:
64722+ task = va_arg(ap, struct task_struct *);
64723+ cred = __task_cred(task);
64724+ pcred = __task_cred(task->real_parent);
64725+ ulong1 = va_arg(ap, unsigned long);
64726+ 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);
64727+ break;
64728+ case GR_RWXMAP:
64729+ file = va_arg(ap, struct file *);
64730+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64731+ break;
64732+ case GR_PSACCT:
64733+ {
64734+ unsigned int wday, cday;
64735+ __u8 whr, chr;
64736+ __u8 wmin, cmin;
64737+ __u8 wsec, csec;
64738+ char cur_tty[64] = { 0 };
64739+ char parent_tty[64] = { 0 };
64740+
64741+ task = va_arg(ap, struct task_struct *);
64742+ wday = va_arg(ap, unsigned int);
64743+ cday = va_arg(ap, unsigned int);
64744+ whr = va_arg(ap, int);
64745+ chr = va_arg(ap, int);
64746+ wmin = va_arg(ap, int);
64747+ cmin = va_arg(ap, int);
64748+ wsec = va_arg(ap, int);
64749+ csec = va_arg(ap, int);
64750+ ulong1 = va_arg(ap, unsigned long);
64751+ cred = __task_cred(task);
64752+ pcred = __task_cred(task->real_parent);
64753+
64754+ 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));
64755+ }
64756+ break;
64757+ default:
64758+ gr_log_middle(audit, msg, ap);
64759+ }
64760+ va_end(ap);
64761+ // these don't need DEFAULTSECARGS printed on the end
64762+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64763+ gr_log_end(audit, 0);
64764+ else
64765+ gr_log_end(audit, 1);
64766+ END_LOCKS(audit);
64767+}
64768diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64769new file mode 100644
64770index 0000000..f536303
64771--- /dev/null
64772+++ b/grsecurity/grsec_mem.c
64773@@ -0,0 +1,40 @@
64774+#include <linux/kernel.h>
64775+#include <linux/sched.h>
64776+#include <linux/mm.h>
64777+#include <linux/mman.h>
64778+#include <linux/grinternal.h>
64779+
64780+void
64781+gr_handle_ioperm(void)
64782+{
64783+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64784+ return;
64785+}
64786+
64787+void
64788+gr_handle_iopl(void)
64789+{
64790+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64791+ return;
64792+}
64793+
64794+void
64795+gr_handle_mem_readwrite(u64 from, u64 to)
64796+{
64797+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64798+ return;
64799+}
64800+
64801+void
64802+gr_handle_vm86(void)
64803+{
64804+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64805+ return;
64806+}
64807+
64808+void
64809+gr_log_badprocpid(const char *entry)
64810+{
64811+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64812+ return;
64813+}
64814diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64815new file mode 100644
64816index 0000000..2131422
64817--- /dev/null
64818+++ b/grsecurity/grsec_mount.c
64819@@ -0,0 +1,62 @@
64820+#include <linux/kernel.h>
64821+#include <linux/sched.h>
64822+#include <linux/mount.h>
64823+#include <linux/grsecurity.h>
64824+#include <linux/grinternal.h>
64825+
64826+void
64827+gr_log_remount(const char *devname, const int retval)
64828+{
64829+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64830+ if (grsec_enable_mount && (retval >= 0))
64831+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64832+#endif
64833+ return;
64834+}
64835+
64836+void
64837+gr_log_unmount(const char *devname, const int retval)
64838+{
64839+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64840+ if (grsec_enable_mount && (retval >= 0))
64841+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64842+#endif
64843+ return;
64844+}
64845+
64846+void
64847+gr_log_mount(const char *from, const char *to, const int retval)
64848+{
64849+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64850+ if (grsec_enable_mount && (retval >= 0))
64851+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64852+#endif
64853+ return;
64854+}
64855+
64856+int
64857+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64858+{
64859+#ifdef CONFIG_GRKERNSEC_ROFS
64860+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64861+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64862+ return -EPERM;
64863+ } else
64864+ return 0;
64865+#endif
64866+ return 0;
64867+}
64868+
64869+int
64870+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64871+{
64872+#ifdef CONFIG_GRKERNSEC_ROFS
64873+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64874+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64875+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64876+ return -EPERM;
64877+ } else
64878+ return 0;
64879+#endif
64880+ return 0;
64881+}
64882diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64883new file mode 100644
64884index 0000000..a3b12a0
64885--- /dev/null
64886+++ b/grsecurity/grsec_pax.c
64887@@ -0,0 +1,36 @@
64888+#include <linux/kernel.h>
64889+#include <linux/sched.h>
64890+#include <linux/mm.h>
64891+#include <linux/file.h>
64892+#include <linux/grinternal.h>
64893+#include <linux/grsecurity.h>
64894+
64895+void
64896+gr_log_textrel(struct vm_area_struct * vma)
64897+{
64898+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64899+ if (grsec_enable_audit_textrel)
64900+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64901+#endif
64902+ return;
64903+}
64904+
64905+void
64906+gr_log_rwxmmap(struct file *file)
64907+{
64908+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64909+ if (grsec_enable_log_rwxmaps)
64910+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64911+#endif
64912+ return;
64913+}
64914+
64915+void
64916+gr_log_rwxmprotect(struct file *file)
64917+{
64918+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64919+ if (grsec_enable_log_rwxmaps)
64920+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64921+#endif
64922+ return;
64923+}
64924diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64925new file mode 100644
64926index 0000000..f7f29aa
64927--- /dev/null
64928+++ b/grsecurity/grsec_ptrace.c
64929@@ -0,0 +1,30 @@
64930+#include <linux/kernel.h>
64931+#include <linux/sched.h>
64932+#include <linux/grinternal.h>
64933+#include <linux/security.h>
64934+
64935+void
64936+gr_audit_ptrace(struct task_struct *task)
64937+{
64938+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64939+ if (grsec_enable_audit_ptrace)
64940+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64941+#endif
64942+ return;
64943+}
64944+
64945+int
64946+gr_ptrace_readexec(struct file *file, int unsafe_flags)
64947+{
64948+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64949+ const struct dentry *dentry = file->f_path.dentry;
64950+ const struct vfsmount *mnt = file->f_path.mnt;
64951+
64952+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64953+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64954+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64955+ return -EACCES;
64956+ }
64957+#endif
64958+ return 0;
64959+}
64960diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64961new file mode 100644
64962index 0000000..e09715a
64963--- /dev/null
64964+++ b/grsecurity/grsec_sig.c
64965@@ -0,0 +1,222 @@
64966+#include <linux/kernel.h>
64967+#include <linux/sched.h>
64968+#include <linux/delay.h>
64969+#include <linux/grsecurity.h>
64970+#include <linux/grinternal.h>
64971+#include <linux/hardirq.h>
64972+
64973+char *signames[] = {
64974+ [SIGSEGV] = "Segmentation fault",
64975+ [SIGILL] = "Illegal instruction",
64976+ [SIGABRT] = "Abort",
64977+ [SIGBUS] = "Invalid alignment/Bus error"
64978+};
64979+
64980+void
64981+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64982+{
64983+#ifdef CONFIG_GRKERNSEC_SIGNAL
64984+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64985+ (sig == SIGABRT) || (sig == SIGBUS))) {
64986+ if (task_pid_nr(t) == task_pid_nr(current)) {
64987+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64988+ } else {
64989+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64990+ }
64991+ }
64992+#endif
64993+ return;
64994+}
64995+
64996+int
64997+gr_handle_signal(const struct task_struct *p, const int sig)
64998+{
64999+#ifdef CONFIG_GRKERNSEC
65000+ /* ignore the 0 signal for protected task checks */
65001+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65002+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65003+ return -EPERM;
65004+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65005+ return -EPERM;
65006+ }
65007+#endif
65008+ return 0;
65009+}
65010+
65011+#ifdef CONFIG_GRKERNSEC
65012+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65013+
65014+int gr_fake_force_sig(int sig, struct task_struct *t)
65015+{
65016+ unsigned long int flags;
65017+ int ret, blocked, ignored;
65018+ struct k_sigaction *action;
65019+
65020+ spin_lock_irqsave(&t->sighand->siglock, flags);
65021+ action = &t->sighand->action[sig-1];
65022+ ignored = action->sa.sa_handler == SIG_IGN;
65023+ blocked = sigismember(&t->blocked, sig);
65024+ if (blocked || ignored) {
65025+ action->sa.sa_handler = SIG_DFL;
65026+ if (blocked) {
65027+ sigdelset(&t->blocked, sig);
65028+ recalc_sigpending_and_wake(t);
65029+ }
65030+ }
65031+ if (action->sa.sa_handler == SIG_DFL)
65032+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
65033+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
65034+
65035+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
65036+
65037+ return ret;
65038+}
65039+#endif
65040+
65041+#ifdef CONFIG_GRKERNSEC_BRUTE
65042+#define GR_USER_BAN_TIME (15 * 60)
65043+#define GR_DAEMON_BRUTE_TIME (30 * 60)
65044+
65045+static int __get_dumpable(unsigned long mm_flags)
65046+{
65047+ int ret;
65048+
65049+ ret = mm_flags & MMF_DUMPABLE_MASK;
65050+ return (ret >= 2) ? 2 : ret;
65051+}
65052+#endif
65053+
65054+void gr_handle_brute_attach(unsigned long mm_flags)
65055+{
65056+#ifdef CONFIG_GRKERNSEC_BRUTE
65057+ struct task_struct *p = current;
65058+ kuid_t uid = GLOBAL_ROOT_UID;
65059+ int daemon = 0;
65060+
65061+ if (!grsec_enable_brute)
65062+ return;
65063+
65064+ rcu_read_lock();
65065+ read_lock(&tasklist_lock);
65066+ read_lock(&grsec_exec_file_lock);
65067+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
65068+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
65069+ p->real_parent->brute = 1;
65070+ daemon = 1;
65071+ } else {
65072+ const struct cred *cred = __task_cred(p), *cred2;
65073+ struct task_struct *tsk, *tsk2;
65074+
65075+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
65076+ struct user_struct *user;
65077+
65078+ uid = cred->uid;
65079+
65080+ /* this is put upon execution past expiration */
65081+ user = find_user(uid);
65082+ if (user == NULL)
65083+ goto unlock;
65084+ user->banned = 1;
65085+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
65086+ if (user->ban_expires == ~0UL)
65087+ user->ban_expires--;
65088+
65089+ do_each_thread(tsk2, tsk) {
65090+ cred2 = __task_cred(tsk);
65091+ if (tsk != p && uid_eq(cred2->uid, uid))
65092+ gr_fake_force_sig(SIGKILL, tsk);
65093+ } while_each_thread(tsk2, tsk);
65094+ }
65095+ }
65096+unlock:
65097+ read_unlock(&grsec_exec_file_lock);
65098+ read_unlock(&tasklist_lock);
65099+ rcu_read_unlock();
65100+
65101+ if (gr_is_global_nonroot(uid))
65102+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
65103+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
65104+ else if (daemon)
65105+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
65106+
65107+#endif
65108+ return;
65109+}
65110+
65111+void gr_handle_brute_check(void)
65112+{
65113+#ifdef CONFIG_GRKERNSEC_BRUTE
65114+ struct task_struct *p = current;
65115+
65116+ if (unlikely(p->brute)) {
65117+ if (!grsec_enable_brute)
65118+ p->brute = 0;
65119+ else if (time_before(get_seconds(), p->brute_expires))
65120+ msleep(30 * 1000);
65121+ }
65122+#endif
65123+ return;
65124+}
65125+
65126+void gr_handle_kernel_exploit(void)
65127+{
65128+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
65129+ const struct cred *cred;
65130+ struct task_struct *tsk, *tsk2;
65131+ struct user_struct *user;
65132+ kuid_t uid;
65133+
65134+ if (in_irq() || in_serving_softirq() || in_nmi())
65135+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
65136+
65137+ uid = current_uid();
65138+
65139+ if (gr_is_global_root(uid))
65140+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
65141+ else {
65142+ /* kill all the processes of this user, hold a reference
65143+ to their creds struct, and prevent them from creating
65144+ another process until system reset
65145+ */
65146+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
65147+ GR_GLOBAL_UID(uid));
65148+ /* we intentionally leak this ref */
65149+ user = get_uid(current->cred->user);
65150+ if (user) {
65151+ user->banned = 1;
65152+ user->ban_expires = ~0UL;
65153+ }
65154+
65155+ read_lock(&tasklist_lock);
65156+ do_each_thread(tsk2, tsk) {
65157+ cred = __task_cred(tsk);
65158+ if (uid_eq(cred->uid, uid))
65159+ gr_fake_force_sig(SIGKILL, tsk);
65160+ } while_each_thread(tsk2, tsk);
65161+ read_unlock(&tasklist_lock);
65162+ }
65163+#endif
65164+}
65165+
65166+int __gr_process_user_ban(struct user_struct *user)
65167+{
65168+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65169+ if (unlikely(user->banned)) {
65170+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
65171+ user->banned = 0;
65172+ user->ban_expires = 0;
65173+ free_uid(user);
65174+ } else
65175+ return -EPERM;
65176+ }
65177+#endif
65178+ return 0;
65179+}
65180+
65181+int gr_process_user_ban(void)
65182+{
65183+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65184+ return __gr_process_user_ban(current->cred->user);
65185+#endif
65186+ return 0;
65187+}
65188diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
65189new file mode 100644
65190index 0000000..4030d57
65191--- /dev/null
65192+++ b/grsecurity/grsec_sock.c
65193@@ -0,0 +1,244 @@
65194+#include <linux/kernel.h>
65195+#include <linux/module.h>
65196+#include <linux/sched.h>
65197+#include <linux/file.h>
65198+#include <linux/net.h>
65199+#include <linux/in.h>
65200+#include <linux/ip.h>
65201+#include <net/sock.h>
65202+#include <net/inet_sock.h>
65203+#include <linux/grsecurity.h>
65204+#include <linux/grinternal.h>
65205+#include <linux/gracl.h>
65206+
65207+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
65208+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
65209+
65210+EXPORT_SYMBOL(gr_search_udp_recvmsg);
65211+EXPORT_SYMBOL(gr_search_udp_sendmsg);
65212+
65213+#ifdef CONFIG_UNIX_MODULE
65214+EXPORT_SYMBOL(gr_acl_handle_unix);
65215+EXPORT_SYMBOL(gr_acl_handle_mknod);
65216+EXPORT_SYMBOL(gr_handle_chroot_unix);
65217+EXPORT_SYMBOL(gr_handle_create);
65218+#endif
65219+
65220+#ifdef CONFIG_GRKERNSEC
65221+#define gr_conn_table_size 32749
65222+struct conn_table_entry {
65223+ struct conn_table_entry *next;
65224+ struct signal_struct *sig;
65225+};
65226+
65227+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
65228+DEFINE_SPINLOCK(gr_conn_table_lock);
65229+
65230+extern const char * gr_socktype_to_name(unsigned char type);
65231+extern const char * gr_proto_to_name(unsigned char proto);
65232+extern const char * gr_sockfamily_to_name(unsigned char family);
65233+
65234+static __inline__ int
65235+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
65236+{
65237+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
65238+}
65239+
65240+static __inline__ int
65241+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
65242+ __u16 sport, __u16 dport)
65243+{
65244+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
65245+ sig->gr_sport == sport && sig->gr_dport == dport))
65246+ return 1;
65247+ else
65248+ return 0;
65249+}
65250+
65251+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
65252+{
65253+ struct conn_table_entry **match;
65254+ unsigned int index;
65255+
65256+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65257+ sig->gr_sport, sig->gr_dport,
65258+ gr_conn_table_size);
65259+
65260+ newent->sig = sig;
65261+
65262+ match = &gr_conn_table[index];
65263+ newent->next = *match;
65264+ *match = newent;
65265+
65266+ return;
65267+}
65268+
65269+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
65270+{
65271+ struct conn_table_entry *match, *last = NULL;
65272+ unsigned int index;
65273+
65274+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65275+ sig->gr_sport, sig->gr_dport,
65276+ gr_conn_table_size);
65277+
65278+ match = gr_conn_table[index];
65279+ while (match && !conn_match(match->sig,
65280+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
65281+ sig->gr_dport)) {
65282+ last = match;
65283+ match = match->next;
65284+ }
65285+
65286+ if (match) {
65287+ if (last)
65288+ last->next = match->next;
65289+ else
65290+ gr_conn_table[index] = NULL;
65291+ kfree(match);
65292+ }
65293+
65294+ return;
65295+}
65296+
65297+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
65298+ __u16 sport, __u16 dport)
65299+{
65300+ struct conn_table_entry *match;
65301+ unsigned int index;
65302+
65303+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
65304+
65305+ match = gr_conn_table[index];
65306+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
65307+ match = match->next;
65308+
65309+ if (match)
65310+ return match->sig;
65311+ else
65312+ return NULL;
65313+}
65314+
65315+#endif
65316+
65317+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
65318+{
65319+#ifdef CONFIG_GRKERNSEC
65320+ struct signal_struct *sig = task->signal;
65321+ struct conn_table_entry *newent;
65322+
65323+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
65324+ if (newent == NULL)
65325+ return;
65326+ /* no bh lock needed since we are called with bh disabled */
65327+ spin_lock(&gr_conn_table_lock);
65328+ gr_del_task_from_ip_table_nolock(sig);
65329+ sig->gr_saddr = inet->inet_rcv_saddr;
65330+ sig->gr_daddr = inet->inet_daddr;
65331+ sig->gr_sport = inet->inet_sport;
65332+ sig->gr_dport = inet->inet_dport;
65333+ gr_add_to_task_ip_table_nolock(sig, newent);
65334+ spin_unlock(&gr_conn_table_lock);
65335+#endif
65336+ return;
65337+}
65338+
65339+void gr_del_task_from_ip_table(struct task_struct *task)
65340+{
65341+#ifdef CONFIG_GRKERNSEC
65342+ spin_lock_bh(&gr_conn_table_lock);
65343+ gr_del_task_from_ip_table_nolock(task->signal);
65344+ spin_unlock_bh(&gr_conn_table_lock);
65345+#endif
65346+ return;
65347+}
65348+
65349+void
65350+gr_attach_curr_ip(const struct sock *sk)
65351+{
65352+#ifdef CONFIG_GRKERNSEC
65353+ struct signal_struct *p, *set;
65354+ const struct inet_sock *inet = inet_sk(sk);
65355+
65356+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
65357+ return;
65358+
65359+ set = current->signal;
65360+
65361+ spin_lock_bh(&gr_conn_table_lock);
65362+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
65363+ inet->inet_dport, inet->inet_sport);
65364+ if (unlikely(p != NULL)) {
65365+ set->curr_ip = p->curr_ip;
65366+ set->used_accept = 1;
65367+ gr_del_task_from_ip_table_nolock(p);
65368+ spin_unlock_bh(&gr_conn_table_lock);
65369+ return;
65370+ }
65371+ spin_unlock_bh(&gr_conn_table_lock);
65372+
65373+ set->curr_ip = inet->inet_daddr;
65374+ set->used_accept = 1;
65375+#endif
65376+ return;
65377+}
65378+
65379+int
65380+gr_handle_sock_all(const int family, const int type, const int protocol)
65381+{
65382+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65383+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
65384+ (family != AF_UNIX)) {
65385+ if (family == AF_INET)
65386+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
65387+ else
65388+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
65389+ return -EACCES;
65390+ }
65391+#endif
65392+ return 0;
65393+}
65394+
65395+int
65396+gr_handle_sock_server(const struct sockaddr *sck)
65397+{
65398+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65399+ if (grsec_enable_socket_server &&
65400+ in_group_p(grsec_socket_server_gid) &&
65401+ sck && (sck->sa_family != AF_UNIX) &&
65402+ (sck->sa_family != AF_LOCAL)) {
65403+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65404+ return -EACCES;
65405+ }
65406+#endif
65407+ return 0;
65408+}
65409+
65410+int
65411+gr_handle_sock_server_other(const struct sock *sck)
65412+{
65413+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65414+ if (grsec_enable_socket_server &&
65415+ in_group_p(grsec_socket_server_gid) &&
65416+ sck && (sck->sk_family != AF_UNIX) &&
65417+ (sck->sk_family != AF_LOCAL)) {
65418+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65419+ return -EACCES;
65420+ }
65421+#endif
65422+ return 0;
65423+}
65424+
65425+int
65426+gr_handle_sock_client(const struct sockaddr *sck)
65427+{
65428+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65429+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
65430+ sck && (sck->sa_family != AF_UNIX) &&
65431+ (sck->sa_family != AF_LOCAL)) {
65432+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
65433+ return -EACCES;
65434+ }
65435+#endif
65436+ return 0;
65437+}
65438diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
65439new file mode 100644
65440index 0000000..f55ef0f
65441--- /dev/null
65442+++ b/grsecurity/grsec_sysctl.c
65443@@ -0,0 +1,469 @@
65444+#include <linux/kernel.h>
65445+#include <linux/sched.h>
65446+#include <linux/sysctl.h>
65447+#include <linux/grsecurity.h>
65448+#include <linux/grinternal.h>
65449+
65450+int
65451+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
65452+{
65453+#ifdef CONFIG_GRKERNSEC_SYSCTL
65454+ if (dirname == NULL || name == NULL)
65455+ return 0;
65456+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
65457+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
65458+ return -EACCES;
65459+ }
65460+#endif
65461+ return 0;
65462+}
65463+
65464+#ifdef CONFIG_GRKERNSEC_ROFS
65465+static int __maybe_unused one = 1;
65466+#endif
65467+
65468+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
65469+struct ctl_table grsecurity_table[] = {
65470+#ifdef CONFIG_GRKERNSEC_SYSCTL
65471+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
65472+#ifdef CONFIG_GRKERNSEC_IO
65473+ {
65474+ .procname = "disable_priv_io",
65475+ .data = &grsec_disable_privio,
65476+ .maxlen = sizeof(int),
65477+ .mode = 0600,
65478+ .proc_handler = &proc_dointvec,
65479+ },
65480+#endif
65481+#endif
65482+#ifdef CONFIG_GRKERNSEC_LINK
65483+ {
65484+ .procname = "linking_restrictions",
65485+ .data = &grsec_enable_link,
65486+ .maxlen = sizeof(int),
65487+ .mode = 0600,
65488+ .proc_handler = &proc_dointvec,
65489+ },
65490+#endif
65491+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65492+ {
65493+ .procname = "enforce_symlinksifowner",
65494+ .data = &grsec_enable_symlinkown,
65495+ .maxlen = sizeof(int),
65496+ .mode = 0600,
65497+ .proc_handler = &proc_dointvec,
65498+ },
65499+ {
65500+ .procname = "symlinkown_gid",
65501+ .data = &grsec_symlinkown_gid,
65502+ .maxlen = sizeof(int),
65503+ .mode = 0600,
65504+ .proc_handler = &proc_dointvec,
65505+ },
65506+#endif
65507+#ifdef CONFIG_GRKERNSEC_BRUTE
65508+ {
65509+ .procname = "deter_bruteforce",
65510+ .data = &grsec_enable_brute,
65511+ .maxlen = sizeof(int),
65512+ .mode = 0600,
65513+ .proc_handler = &proc_dointvec,
65514+ },
65515+#endif
65516+#ifdef CONFIG_GRKERNSEC_FIFO
65517+ {
65518+ .procname = "fifo_restrictions",
65519+ .data = &grsec_enable_fifo,
65520+ .maxlen = sizeof(int),
65521+ .mode = 0600,
65522+ .proc_handler = &proc_dointvec,
65523+ },
65524+#endif
65525+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65526+ {
65527+ .procname = "ptrace_readexec",
65528+ .data = &grsec_enable_ptrace_readexec,
65529+ .maxlen = sizeof(int),
65530+ .mode = 0600,
65531+ .proc_handler = &proc_dointvec,
65532+ },
65533+#endif
65534+#ifdef CONFIG_GRKERNSEC_SETXID
65535+ {
65536+ .procname = "consistent_setxid",
65537+ .data = &grsec_enable_setxid,
65538+ .maxlen = sizeof(int),
65539+ .mode = 0600,
65540+ .proc_handler = &proc_dointvec,
65541+ },
65542+#endif
65543+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65544+ {
65545+ .procname = "ip_blackhole",
65546+ .data = &grsec_enable_blackhole,
65547+ .maxlen = sizeof(int),
65548+ .mode = 0600,
65549+ .proc_handler = &proc_dointvec,
65550+ },
65551+ {
65552+ .procname = "lastack_retries",
65553+ .data = &grsec_lastack_retries,
65554+ .maxlen = sizeof(int),
65555+ .mode = 0600,
65556+ .proc_handler = &proc_dointvec,
65557+ },
65558+#endif
65559+#ifdef CONFIG_GRKERNSEC_EXECLOG
65560+ {
65561+ .procname = "exec_logging",
65562+ .data = &grsec_enable_execlog,
65563+ .maxlen = sizeof(int),
65564+ .mode = 0600,
65565+ .proc_handler = &proc_dointvec,
65566+ },
65567+#endif
65568+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65569+ {
65570+ .procname = "rwxmap_logging",
65571+ .data = &grsec_enable_log_rwxmaps,
65572+ .maxlen = sizeof(int),
65573+ .mode = 0600,
65574+ .proc_handler = &proc_dointvec,
65575+ },
65576+#endif
65577+#ifdef CONFIG_GRKERNSEC_SIGNAL
65578+ {
65579+ .procname = "signal_logging",
65580+ .data = &grsec_enable_signal,
65581+ .maxlen = sizeof(int),
65582+ .mode = 0600,
65583+ .proc_handler = &proc_dointvec,
65584+ },
65585+#endif
65586+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65587+ {
65588+ .procname = "forkfail_logging",
65589+ .data = &grsec_enable_forkfail,
65590+ .maxlen = sizeof(int),
65591+ .mode = 0600,
65592+ .proc_handler = &proc_dointvec,
65593+ },
65594+#endif
65595+#ifdef CONFIG_GRKERNSEC_TIME
65596+ {
65597+ .procname = "timechange_logging",
65598+ .data = &grsec_enable_time,
65599+ .maxlen = sizeof(int),
65600+ .mode = 0600,
65601+ .proc_handler = &proc_dointvec,
65602+ },
65603+#endif
65604+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65605+ {
65606+ .procname = "chroot_deny_shmat",
65607+ .data = &grsec_enable_chroot_shmat,
65608+ .maxlen = sizeof(int),
65609+ .mode = 0600,
65610+ .proc_handler = &proc_dointvec,
65611+ },
65612+#endif
65613+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65614+ {
65615+ .procname = "chroot_deny_unix",
65616+ .data = &grsec_enable_chroot_unix,
65617+ .maxlen = sizeof(int),
65618+ .mode = 0600,
65619+ .proc_handler = &proc_dointvec,
65620+ },
65621+#endif
65622+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65623+ {
65624+ .procname = "chroot_deny_mount",
65625+ .data = &grsec_enable_chroot_mount,
65626+ .maxlen = sizeof(int),
65627+ .mode = 0600,
65628+ .proc_handler = &proc_dointvec,
65629+ },
65630+#endif
65631+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65632+ {
65633+ .procname = "chroot_deny_fchdir",
65634+ .data = &grsec_enable_chroot_fchdir,
65635+ .maxlen = sizeof(int),
65636+ .mode = 0600,
65637+ .proc_handler = &proc_dointvec,
65638+ },
65639+#endif
65640+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65641+ {
65642+ .procname = "chroot_deny_chroot",
65643+ .data = &grsec_enable_chroot_double,
65644+ .maxlen = sizeof(int),
65645+ .mode = 0600,
65646+ .proc_handler = &proc_dointvec,
65647+ },
65648+#endif
65649+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65650+ {
65651+ .procname = "chroot_deny_pivot",
65652+ .data = &grsec_enable_chroot_pivot,
65653+ .maxlen = sizeof(int),
65654+ .mode = 0600,
65655+ .proc_handler = &proc_dointvec,
65656+ },
65657+#endif
65658+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65659+ {
65660+ .procname = "chroot_enforce_chdir",
65661+ .data = &grsec_enable_chroot_chdir,
65662+ .maxlen = sizeof(int),
65663+ .mode = 0600,
65664+ .proc_handler = &proc_dointvec,
65665+ },
65666+#endif
65667+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65668+ {
65669+ .procname = "chroot_deny_chmod",
65670+ .data = &grsec_enable_chroot_chmod,
65671+ .maxlen = sizeof(int),
65672+ .mode = 0600,
65673+ .proc_handler = &proc_dointvec,
65674+ },
65675+#endif
65676+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65677+ {
65678+ .procname = "chroot_deny_mknod",
65679+ .data = &grsec_enable_chroot_mknod,
65680+ .maxlen = sizeof(int),
65681+ .mode = 0600,
65682+ .proc_handler = &proc_dointvec,
65683+ },
65684+#endif
65685+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65686+ {
65687+ .procname = "chroot_restrict_nice",
65688+ .data = &grsec_enable_chroot_nice,
65689+ .maxlen = sizeof(int),
65690+ .mode = 0600,
65691+ .proc_handler = &proc_dointvec,
65692+ },
65693+#endif
65694+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65695+ {
65696+ .procname = "chroot_execlog",
65697+ .data = &grsec_enable_chroot_execlog,
65698+ .maxlen = sizeof(int),
65699+ .mode = 0600,
65700+ .proc_handler = &proc_dointvec,
65701+ },
65702+#endif
65703+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65704+ {
65705+ .procname = "chroot_caps",
65706+ .data = &grsec_enable_chroot_caps,
65707+ .maxlen = sizeof(int),
65708+ .mode = 0600,
65709+ .proc_handler = &proc_dointvec,
65710+ },
65711+#endif
65712+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65713+ {
65714+ .procname = "chroot_deny_sysctl",
65715+ .data = &grsec_enable_chroot_sysctl,
65716+ .maxlen = sizeof(int),
65717+ .mode = 0600,
65718+ .proc_handler = &proc_dointvec,
65719+ },
65720+#endif
65721+#ifdef CONFIG_GRKERNSEC_TPE
65722+ {
65723+ .procname = "tpe",
65724+ .data = &grsec_enable_tpe,
65725+ .maxlen = sizeof(int),
65726+ .mode = 0600,
65727+ .proc_handler = &proc_dointvec,
65728+ },
65729+ {
65730+ .procname = "tpe_gid",
65731+ .data = &grsec_tpe_gid,
65732+ .maxlen = sizeof(int),
65733+ .mode = 0600,
65734+ .proc_handler = &proc_dointvec,
65735+ },
65736+#endif
65737+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65738+ {
65739+ .procname = "tpe_invert",
65740+ .data = &grsec_enable_tpe_invert,
65741+ .maxlen = sizeof(int),
65742+ .mode = 0600,
65743+ .proc_handler = &proc_dointvec,
65744+ },
65745+#endif
65746+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65747+ {
65748+ .procname = "tpe_restrict_all",
65749+ .data = &grsec_enable_tpe_all,
65750+ .maxlen = sizeof(int),
65751+ .mode = 0600,
65752+ .proc_handler = &proc_dointvec,
65753+ },
65754+#endif
65755+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65756+ {
65757+ .procname = "socket_all",
65758+ .data = &grsec_enable_socket_all,
65759+ .maxlen = sizeof(int),
65760+ .mode = 0600,
65761+ .proc_handler = &proc_dointvec,
65762+ },
65763+ {
65764+ .procname = "socket_all_gid",
65765+ .data = &grsec_socket_all_gid,
65766+ .maxlen = sizeof(int),
65767+ .mode = 0600,
65768+ .proc_handler = &proc_dointvec,
65769+ },
65770+#endif
65771+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65772+ {
65773+ .procname = "socket_client",
65774+ .data = &grsec_enable_socket_client,
65775+ .maxlen = sizeof(int),
65776+ .mode = 0600,
65777+ .proc_handler = &proc_dointvec,
65778+ },
65779+ {
65780+ .procname = "socket_client_gid",
65781+ .data = &grsec_socket_client_gid,
65782+ .maxlen = sizeof(int),
65783+ .mode = 0600,
65784+ .proc_handler = &proc_dointvec,
65785+ },
65786+#endif
65787+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65788+ {
65789+ .procname = "socket_server",
65790+ .data = &grsec_enable_socket_server,
65791+ .maxlen = sizeof(int),
65792+ .mode = 0600,
65793+ .proc_handler = &proc_dointvec,
65794+ },
65795+ {
65796+ .procname = "socket_server_gid",
65797+ .data = &grsec_socket_server_gid,
65798+ .maxlen = sizeof(int),
65799+ .mode = 0600,
65800+ .proc_handler = &proc_dointvec,
65801+ },
65802+#endif
65803+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65804+ {
65805+ .procname = "audit_group",
65806+ .data = &grsec_enable_group,
65807+ .maxlen = sizeof(int),
65808+ .mode = 0600,
65809+ .proc_handler = &proc_dointvec,
65810+ },
65811+ {
65812+ .procname = "audit_gid",
65813+ .data = &grsec_audit_gid,
65814+ .maxlen = sizeof(int),
65815+ .mode = 0600,
65816+ .proc_handler = &proc_dointvec,
65817+ },
65818+#endif
65819+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65820+ {
65821+ .procname = "audit_chdir",
65822+ .data = &grsec_enable_chdir,
65823+ .maxlen = sizeof(int),
65824+ .mode = 0600,
65825+ .proc_handler = &proc_dointvec,
65826+ },
65827+#endif
65828+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65829+ {
65830+ .procname = "audit_mount",
65831+ .data = &grsec_enable_mount,
65832+ .maxlen = sizeof(int),
65833+ .mode = 0600,
65834+ .proc_handler = &proc_dointvec,
65835+ },
65836+#endif
65837+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65838+ {
65839+ .procname = "audit_textrel",
65840+ .data = &grsec_enable_audit_textrel,
65841+ .maxlen = sizeof(int),
65842+ .mode = 0600,
65843+ .proc_handler = &proc_dointvec,
65844+ },
65845+#endif
65846+#ifdef CONFIG_GRKERNSEC_DMESG
65847+ {
65848+ .procname = "dmesg",
65849+ .data = &grsec_enable_dmesg,
65850+ .maxlen = sizeof(int),
65851+ .mode = 0600,
65852+ .proc_handler = &proc_dointvec,
65853+ },
65854+#endif
65855+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65856+ {
65857+ .procname = "chroot_findtask",
65858+ .data = &grsec_enable_chroot_findtask,
65859+ .maxlen = sizeof(int),
65860+ .mode = 0600,
65861+ .proc_handler = &proc_dointvec,
65862+ },
65863+#endif
65864+#ifdef CONFIG_GRKERNSEC_RESLOG
65865+ {
65866+ .procname = "resource_logging",
65867+ .data = &grsec_resource_logging,
65868+ .maxlen = sizeof(int),
65869+ .mode = 0600,
65870+ .proc_handler = &proc_dointvec,
65871+ },
65872+#endif
65873+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65874+ {
65875+ .procname = "audit_ptrace",
65876+ .data = &grsec_enable_audit_ptrace,
65877+ .maxlen = sizeof(int),
65878+ .mode = 0600,
65879+ .proc_handler = &proc_dointvec,
65880+ },
65881+#endif
65882+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65883+ {
65884+ .procname = "harden_ptrace",
65885+ .data = &grsec_enable_harden_ptrace,
65886+ .maxlen = sizeof(int),
65887+ .mode = 0600,
65888+ .proc_handler = &proc_dointvec,
65889+ },
65890+#endif
65891+ {
65892+ .procname = "grsec_lock",
65893+ .data = &grsec_lock,
65894+ .maxlen = sizeof(int),
65895+ .mode = 0600,
65896+ .proc_handler = &proc_dointvec,
65897+ },
65898+#endif
65899+#ifdef CONFIG_GRKERNSEC_ROFS
65900+ {
65901+ .procname = "romount_protect",
65902+ .data = &grsec_enable_rofs,
65903+ .maxlen = sizeof(int),
65904+ .mode = 0600,
65905+ .proc_handler = &proc_dointvec_minmax,
65906+ .extra1 = &one,
65907+ .extra2 = &one,
65908+ },
65909+#endif
65910+ { }
65911+};
65912+#endif
65913diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65914new file mode 100644
65915index 0000000..0dc13c3
65916--- /dev/null
65917+++ b/grsecurity/grsec_time.c
65918@@ -0,0 +1,16 @@
65919+#include <linux/kernel.h>
65920+#include <linux/sched.h>
65921+#include <linux/grinternal.h>
65922+#include <linux/module.h>
65923+
65924+void
65925+gr_log_timechange(void)
65926+{
65927+#ifdef CONFIG_GRKERNSEC_TIME
65928+ if (grsec_enable_time)
65929+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65930+#endif
65931+ return;
65932+}
65933+
65934+EXPORT_SYMBOL(gr_log_timechange);
65935diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65936new file mode 100644
65937index 0000000..ee57dcf
65938--- /dev/null
65939+++ b/grsecurity/grsec_tpe.c
65940@@ -0,0 +1,73 @@
65941+#include <linux/kernel.h>
65942+#include <linux/sched.h>
65943+#include <linux/file.h>
65944+#include <linux/fs.h>
65945+#include <linux/grinternal.h>
65946+
65947+extern int gr_acl_tpe_check(void);
65948+
65949+int
65950+gr_tpe_allow(const struct file *file)
65951+{
65952+#ifdef CONFIG_GRKERNSEC
65953+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65954+ const struct cred *cred = current_cred();
65955+ char *msg = NULL;
65956+ char *msg2 = NULL;
65957+
65958+ // never restrict root
65959+ if (gr_is_global_root(cred->uid))
65960+ return 1;
65961+
65962+ if (grsec_enable_tpe) {
65963+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65964+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65965+ msg = "not being in trusted group";
65966+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65967+ msg = "being in untrusted group";
65968+#else
65969+ if (in_group_p(grsec_tpe_gid))
65970+ msg = "being in untrusted group";
65971+#endif
65972+ }
65973+ if (!msg && gr_acl_tpe_check())
65974+ msg = "being in untrusted role";
65975+
65976+ // not in any affected group/role
65977+ if (!msg)
65978+ goto next_check;
65979+
65980+ if (gr_is_global_nonroot(inode->i_uid))
65981+ msg2 = "file in non-root-owned directory";
65982+ else if (inode->i_mode & S_IWOTH)
65983+ msg2 = "file in world-writable directory";
65984+ else if (inode->i_mode & S_IWGRP)
65985+ msg2 = "file in group-writable directory";
65986+
65987+ if (msg && msg2) {
65988+ char fullmsg[70] = {0};
65989+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65990+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65991+ return 0;
65992+ }
65993+ msg = NULL;
65994+next_check:
65995+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65996+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
65997+ return 1;
65998+
65999+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66000+ msg = "directory not owned by user";
66001+ else if (inode->i_mode & S_IWOTH)
66002+ msg = "file in world-writable directory";
66003+ else if (inode->i_mode & S_IWGRP)
66004+ msg = "file in group-writable directory";
66005+
66006+ if (msg) {
66007+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66008+ return 0;
66009+ }
66010+#endif
66011+#endif
66012+ return 1;
66013+}
66014diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66015new file mode 100644
66016index 0000000..9f7b1ac
66017--- /dev/null
66018+++ b/grsecurity/grsum.c
66019@@ -0,0 +1,61 @@
66020+#include <linux/err.h>
66021+#include <linux/kernel.h>
66022+#include <linux/sched.h>
66023+#include <linux/mm.h>
66024+#include <linux/scatterlist.h>
66025+#include <linux/crypto.h>
66026+#include <linux/gracl.h>
66027+
66028+
66029+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66030+#error "crypto and sha256 must be built into the kernel"
66031+#endif
66032+
66033+int
66034+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
66035+{
66036+ char *p;
66037+ struct crypto_hash *tfm;
66038+ struct hash_desc desc;
66039+ struct scatterlist sg;
66040+ unsigned char temp_sum[GR_SHA_LEN];
66041+ volatile int retval = 0;
66042+ volatile int dummy = 0;
66043+ unsigned int i;
66044+
66045+ sg_init_table(&sg, 1);
66046+
66047+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
66048+ if (IS_ERR(tfm)) {
66049+ /* should never happen, since sha256 should be built in */
66050+ return 1;
66051+ }
66052+
66053+ desc.tfm = tfm;
66054+ desc.flags = 0;
66055+
66056+ crypto_hash_init(&desc);
66057+
66058+ p = salt;
66059+ sg_set_buf(&sg, p, GR_SALT_LEN);
66060+ crypto_hash_update(&desc, &sg, sg.length);
66061+
66062+ p = entry->pw;
66063+ sg_set_buf(&sg, p, strlen(p));
66064+
66065+ crypto_hash_update(&desc, &sg, sg.length);
66066+
66067+ crypto_hash_final(&desc, temp_sum);
66068+
66069+ memset(entry->pw, 0, GR_PW_LEN);
66070+
66071+ for (i = 0; i < GR_SHA_LEN; i++)
66072+ if (sum[i] != temp_sum[i])
66073+ retval = 1;
66074+ else
66075+ dummy = 1; // waste a cycle
66076+
66077+ crypto_free_hash(tfm);
66078+
66079+ return retval;
66080+}
66081diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
66082index 77ff547..181834f 100644
66083--- a/include/asm-generic/4level-fixup.h
66084+++ b/include/asm-generic/4level-fixup.h
66085@@ -13,8 +13,10 @@
66086 #define pmd_alloc(mm, pud, address) \
66087 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
66088 NULL: pmd_offset(pud, address))
66089+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
66090
66091 #define pud_alloc(mm, pgd, address) (pgd)
66092+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
66093 #define pud_offset(pgd, start) (pgd)
66094 #define pud_none(pud) 0
66095 #define pud_bad(pud) 0
66096diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
66097index b7babf0..04ad282 100644
66098--- a/include/asm-generic/atomic-long.h
66099+++ b/include/asm-generic/atomic-long.h
66100@@ -22,6 +22,12 @@
66101
66102 typedef atomic64_t atomic_long_t;
66103
66104+#ifdef CONFIG_PAX_REFCOUNT
66105+typedef atomic64_unchecked_t atomic_long_unchecked_t;
66106+#else
66107+typedef atomic64_t atomic_long_unchecked_t;
66108+#endif
66109+
66110 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
66111
66112 static inline long atomic_long_read(atomic_long_t *l)
66113@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66114 return (long)atomic64_read(v);
66115 }
66116
66117+#ifdef CONFIG_PAX_REFCOUNT
66118+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66119+{
66120+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66121+
66122+ return (long)atomic64_read_unchecked(v);
66123+}
66124+#endif
66125+
66126 static inline void atomic_long_set(atomic_long_t *l, long i)
66127 {
66128 atomic64_t *v = (atomic64_t *)l;
66129@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66130 atomic64_set(v, i);
66131 }
66132
66133+#ifdef CONFIG_PAX_REFCOUNT
66134+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66135+{
66136+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66137+
66138+ atomic64_set_unchecked(v, i);
66139+}
66140+#endif
66141+
66142 static inline void atomic_long_inc(atomic_long_t *l)
66143 {
66144 atomic64_t *v = (atomic64_t *)l;
66145@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66146 atomic64_inc(v);
66147 }
66148
66149+#ifdef CONFIG_PAX_REFCOUNT
66150+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66151+{
66152+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66153+
66154+ atomic64_inc_unchecked(v);
66155+}
66156+#endif
66157+
66158 static inline void atomic_long_dec(atomic_long_t *l)
66159 {
66160 atomic64_t *v = (atomic64_t *)l;
66161@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66162 atomic64_dec(v);
66163 }
66164
66165+#ifdef CONFIG_PAX_REFCOUNT
66166+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66167+{
66168+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66169+
66170+ atomic64_dec_unchecked(v);
66171+}
66172+#endif
66173+
66174 static inline void atomic_long_add(long i, atomic_long_t *l)
66175 {
66176 atomic64_t *v = (atomic64_t *)l;
66177@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66178 atomic64_add(i, v);
66179 }
66180
66181+#ifdef CONFIG_PAX_REFCOUNT
66182+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66183+{
66184+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66185+
66186+ atomic64_add_unchecked(i, v);
66187+}
66188+#endif
66189+
66190 static inline void atomic_long_sub(long i, atomic_long_t *l)
66191 {
66192 atomic64_t *v = (atomic64_t *)l;
66193@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66194 atomic64_sub(i, v);
66195 }
66196
66197+#ifdef CONFIG_PAX_REFCOUNT
66198+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66199+{
66200+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66201+
66202+ atomic64_sub_unchecked(i, v);
66203+}
66204+#endif
66205+
66206 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66207 {
66208 atomic64_t *v = (atomic64_t *)l;
66209@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66210 return (long)atomic64_add_return(i, v);
66211 }
66212
66213+#ifdef CONFIG_PAX_REFCOUNT
66214+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66215+{
66216+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66217+
66218+ return (long)atomic64_add_return_unchecked(i, v);
66219+}
66220+#endif
66221+
66222 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66223 {
66224 atomic64_t *v = (atomic64_t *)l;
66225@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66226 return (long)atomic64_inc_return(v);
66227 }
66228
66229+#ifdef CONFIG_PAX_REFCOUNT
66230+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66231+{
66232+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66233+
66234+ return (long)atomic64_inc_return_unchecked(v);
66235+}
66236+#endif
66237+
66238 static inline long atomic_long_dec_return(atomic_long_t *l)
66239 {
66240 atomic64_t *v = (atomic64_t *)l;
66241@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66242
66243 typedef atomic_t atomic_long_t;
66244
66245+#ifdef CONFIG_PAX_REFCOUNT
66246+typedef atomic_unchecked_t atomic_long_unchecked_t;
66247+#else
66248+typedef atomic_t atomic_long_unchecked_t;
66249+#endif
66250+
66251 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
66252 static inline long atomic_long_read(atomic_long_t *l)
66253 {
66254@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66255 return (long)atomic_read(v);
66256 }
66257
66258+#ifdef CONFIG_PAX_REFCOUNT
66259+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66260+{
66261+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66262+
66263+ return (long)atomic_read_unchecked(v);
66264+}
66265+#endif
66266+
66267 static inline void atomic_long_set(atomic_long_t *l, long i)
66268 {
66269 atomic_t *v = (atomic_t *)l;
66270@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66271 atomic_set(v, i);
66272 }
66273
66274+#ifdef CONFIG_PAX_REFCOUNT
66275+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66276+{
66277+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66278+
66279+ atomic_set_unchecked(v, i);
66280+}
66281+#endif
66282+
66283 static inline void atomic_long_inc(atomic_long_t *l)
66284 {
66285 atomic_t *v = (atomic_t *)l;
66286@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66287 atomic_inc(v);
66288 }
66289
66290+#ifdef CONFIG_PAX_REFCOUNT
66291+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66292+{
66293+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66294+
66295+ atomic_inc_unchecked(v);
66296+}
66297+#endif
66298+
66299 static inline void atomic_long_dec(atomic_long_t *l)
66300 {
66301 atomic_t *v = (atomic_t *)l;
66302@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66303 atomic_dec(v);
66304 }
66305
66306+#ifdef CONFIG_PAX_REFCOUNT
66307+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66308+{
66309+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66310+
66311+ atomic_dec_unchecked(v);
66312+}
66313+#endif
66314+
66315 static inline void atomic_long_add(long i, atomic_long_t *l)
66316 {
66317 atomic_t *v = (atomic_t *)l;
66318@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66319 atomic_add(i, v);
66320 }
66321
66322+#ifdef CONFIG_PAX_REFCOUNT
66323+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66324+{
66325+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66326+
66327+ atomic_add_unchecked(i, v);
66328+}
66329+#endif
66330+
66331 static inline void atomic_long_sub(long i, atomic_long_t *l)
66332 {
66333 atomic_t *v = (atomic_t *)l;
66334@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66335 atomic_sub(i, v);
66336 }
66337
66338+#ifdef CONFIG_PAX_REFCOUNT
66339+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66340+{
66341+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66342+
66343+ atomic_sub_unchecked(i, v);
66344+}
66345+#endif
66346+
66347 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66348 {
66349 atomic_t *v = (atomic_t *)l;
66350@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66351 return (long)atomic_add_return(i, v);
66352 }
66353
66354+#ifdef CONFIG_PAX_REFCOUNT
66355+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66356+{
66357+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66358+
66359+ return (long)atomic_add_return_unchecked(i, v);
66360+}
66361+
66362+#endif
66363+
66364 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66365 {
66366 atomic_t *v = (atomic_t *)l;
66367@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66368 return (long)atomic_inc_return(v);
66369 }
66370
66371+#ifdef CONFIG_PAX_REFCOUNT
66372+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66373+{
66374+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66375+
66376+ return (long)atomic_inc_return_unchecked(v);
66377+}
66378+#endif
66379+
66380 static inline long atomic_long_dec_return(atomic_long_t *l)
66381 {
66382 atomic_t *v = (atomic_t *)l;
66383@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66384
66385 #endif /* BITS_PER_LONG == 64 */
66386
66387+#ifdef CONFIG_PAX_REFCOUNT
66388+static inline void pax_refcount_needs_these_functions(void)
66389+{
66390+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
66391+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
66392+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
66393+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
66394+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
66395+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
66396+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
66397+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
66398+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
66399+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
66400+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
66401+#ifdef CONFIG_X86
66402+ atomic_clear_mask_unchecked(0, NULL);
66403+ atomic_set_mask_unchecked(0, NULL);
66404+#endif
66405+
66406+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
66407+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
66408+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
66409+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
66410+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
66411+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
66412+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
66413+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
66414+}
66415+#else
66416+#define atomic_read_unchecked(v) atomic_read(v)
66417+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
66418+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
66419+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
66420+#define atomic_inc_unchecked(v) atomic_inc(v)
66421+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
66422+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
66423+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
66424+#define atomic_dec_unchecked(v) atomic_dec(v)
66425+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
66426+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
66427+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
66428+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
66429+
66430+#define atomic_long_read_unchecked(v) atomic_long_read(v)
66431+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
66432+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
66433+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
66434+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
66435+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
66436+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
66437+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
66438+#endif
66439+
66440 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
66441diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
66442index 1ced641..c896ee8 100644
66443--- a/include/asm-generic/atomic.h
66444+++ b/include/asm-generic/atomic.h
66445@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
66446 * Atomically clears the bits set in @mask from @v
66447 */
66448 #ifndef atomic_clear_mask
66449-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
66450+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
66451 {
66452 unsigned long flags;
66453
66454diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
66455index b18ce4f..2ee2843 100644
66456--- a/include/asm-generic/atomic64.h
66457+++ b/include/asm-generic/atomic64.h
66458@@ -16,6 +16,8 @@ typedef struct {
66459 long long counter;
66460 } atomic64_t;
66461
66462+typedef atomic64_t atomic64_unchecked_t;
66463+
66464 #define ATOMIC64_INIT(i) { (i) }
66465
66466 extern long long atomic64_read(const atomic64_t *v);
66467@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
66468 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
66469 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
66470
66471+#define atomic64_read_unchecked(v) atomic64_read(v)
66472+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
66473+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
66474+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
66475+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
66476+#define atomic64_inc_unchecked(v) atomic64_inc(v)
66477+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
66478+#define atomic64_dec_unchecked(v) atomic64_dec(v)
66479+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
66480+
66481 #endif /* _ASM_GENERIC_ATOMIC64_H */
66482diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
66483index 1bfcfe5..e04c5c9 100644
66484--- a/include/asm-generic/cache.h
66485+++ b/include/asm-generic/cache.h
66486@@ -6,7 +6,7 @@
66487 * cache lines need to provide their own cache.h.
66488 */
66489
66490-#define L1_CACHE_SHIFT 5
66491-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
66492+#define L1_CACHE_SHIFT 5UL
66493+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
66494
66495 #endif /* __ASM_GENERIC_CACHE_H */
66496diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
66497index 0d68a1e..b74a761 100644
66498--- a/include/asm-generic/emergency-restart.h
66499+++ b/include/asm-generic/emergency-restart.h
66500@@ -1,7 +1,7 @@
66501 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
66502 #define _ASM_GENERIC_EMERGENCY_RESTART_H
66503
66504-static inline void machine_emergency_restart(void)
66505+static inline __noreturn void machine_emergency_restart(void)
66506 {
66507 machine_restart(NULL);
66508 }
66509diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66510index 90f99c7..00ce236 100644
66511--- a/include/asm-generic/kmap_types.h
66512+++ b/include/asm-generic/kmap_types.h
66513@@ -2,9 +2,9 @@
66514 #define _ASM_GENERIC_KMAP_TYPES_H
66515
66516 #ifdef __WITH_KM_FENCE
66517-# define KM_TYPE_NR 41
66518+# define KM_TYPE_NR 42
66519 #else
66520-# define KM_TYPE_NR 20
66521+# define KM_TYPE_NR 21
66522 #endif
66523
66524 #endif
66525diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66526index 9ceb03b..62b0b8f 100644
66527--- a/include/asm-generic/local.h
66528+++ b/include/asm-generic/local.h
66529@@ -23,24 +23,37 @@ typedef struct
66530 atomic_long_t a;
66531 } local_t;
66532
66533+typedef struct {
66534+ atomic_long_unchecked_t a;
66535+} local_unchecked_t;
66536+
66537 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66538
66539 #define local_read(l) atomic_long_read(&(l)->a)
66540+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66541 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66542+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66543 #define local_inc(l) atomic_long_inc(&(l)->a)
66544+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66545 #define local_dec(l) atomic_long_dec(&(l)->a)
66546+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66547 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66548+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66549 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66550+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66551
66552 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66553 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66554 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66555 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66556 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66557+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66558 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66559 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66560+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66561
66562 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66563+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66564 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66565 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66566 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66567diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66568index 725612b..9cc513a 100644
66569--- a/include/asm-generic/pgtable-nopmd.h
66570+++ b/include/asm-generic/pgtable-nopmd.h
66571@@ -1,14 +1,19 @@
66572 #ifndef _PGTABLE_NOPMD_H
66573 #define _PGTABLE_NOPMD_H
66574
66575-#ifndef __ASSEMBLY__
66576-
66577 #include <asm-generic/pgtable-nopud.h>
66578
66579-struct mm_struct;
66580-
66581 #define __PAGETABLE_PMD_FOLDED
66582
66583+#define PMD_SHIFT PUD_SHIFT
66584+#define PTRS_PER_PMD 1
66585+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66586+#define PMD_MASK (~(PMD_SIZE-1))
66587+
66588+#ifndef __ASSEMBLY__
66589+
66590+struct mm_struct;
66591+
66592 /*
66593 * Having the pmd type consist of a pud gets the size right, and allows
66594 * us to conceptually access the pud entry that this pmd is folded into
66595@@ -16,11 +21,6 @@ struct mm_struct;
66596 */
66597 typedef struct { pud_t pud; } pmd_t;
66598
66599-#define PMD_SHIFT PUD_SHIFT
66600-#define PTRS_PER_PMD 1
66601-#define PMD_SIZE (1UL << PMD_SHIFT)
66602-#define PMD_MASK (~(PMD_SIZE-1))
66603-
66604 /*
66605 * The "pud_xxx()" functions here are trivial for a folded two-level
66606 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66607diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66608index 810431d..0ec4804f 100644
66609--- a/include/asm-generic/pgtable-nopud.h
66610+++ b/include/asm-generic/pgtable-nopud.h
66611@@ -1,10 +1,15 @@
66612 #ifndef _PGTABLE_NOPUD_H
66613 #define _PGTABLE_NOPUD_H
66614
66615-#ifndef __ASSEMBLY__
66616-
66617 #define __PAGETABLE_PUD_FOLDED
66618
66619+#define PUD_SHIFT PGDIR_SHIFT
66620+#define PTRS_PER_PUD 1
66621+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66622+#define PUD_MASK (~(PUD_SIZE-1))
66623+
66624+#ifndef __ASSEMBLY__
66625+
66626 /*
66627 * Having the pud type consist of a pgd gets the size right, and allows
66628 * us to conceptually access the pgd entry that this pud is folded into
66629@@ -12,11 +17,6 @@
66630 */
66631 typedef struct { pgd_t pgd; } pud_t;
66632
66633-#define PUD_SHIFT PGDIR_SHIFT
66634-#define PTRS_PER_PUD 1
66635-#define PUD_SIZE (1UL << PUD_SHIFT)
66636-#define PUD_MASK (~(PUD_SIZE-1))
66637-
66638 /*
66639 * The "pgd_xxx()" functions here are trivial for a folded two-level
66640 * setup: the pud is never bad, and a pud always exists (as it's folded
66641@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66642 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66643
66644 #define pgd_populate(mm, pgd, pud) do { } while (0)
66645+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66646 /*
66647 * (puds are folded into pgds so this doesn't get actually called,
66648 * but the define is needed for a generic inline function.)
66649diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66650index 5cf680a..4b74d62 100644
66651--- a/include/asm-generic/pgtable.h
66652+++ b/include/asm-generic/pgtable.h
66653@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66654 }
66655 #endif /* CONFIG_NUMA_BALANCING */
66656
66657+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66658+static inline unsigned long pax_open_kernel(void) { return 0; }
66659+#endif
66660+
66661+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66662+static inline unsigned long pax_close_kernel(void) { return 0; }
66663+#endif
66664+
66665 #endif /* CONFIG_MMU */
66666
66667 #endif /* !__ASSEMBLY__ */
66668diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66669index d1ea7ce..b1ebf2a 100644
66670--- a/include/asm-generic/vmlinux.lds.h
66671+++ b/include/asm-generic/vmlinux.lds.h
66672@@ -218,6 +218,7 @@
66673 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66674 VMLINUX_SYMBOL(__start_rodata) = .; \
66675 *(.rodata) *(.rodata.*) \
66676+ *(.data..read_only) \
66677 *(__vermagic) /* Kernel version magic */ \
66678 . = ALIGN(8); \
66679 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66680@@ -725,17 +726,18 @@
66681 * section in the linker script will go there too. @phdr should have
66682 * a leading colon.
66683 *
66684- * Note that this macros defines __per_cpu_load as an absolute symbol.
66685+ * Note that this macros defines per_cpu_load as an absolute symbol.
66686 * If there is no need to put the percpu section at a predetermined
66687 * address, use PERCPU_SECTION.
66688 */
66689 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66690- VMLINUX_SYMBOL(__per_cpu_load) = .; \
66691- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66692+ per_cpu_load = .; \
66693+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66694 - LOAD_OFFSET) { \
66695+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66696 PERCPU_INPUT(cacheline) \
66697 } phdr \
66698- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66699+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66700
66701 /**
66702 * PERCPU_SECTION - define output section for percpu area, simple version
66703diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66704index 418d270..bfd2794 100644
66705--- a/include/crypto/algapi.h
66706+++ b/include/crypto/algapi.h
66707@@ -34,7 +34,7 @@ struct crypto_type {
66708 unsigned int maskclear;
66709 unsigned int maskset;
66710 unsigned int tfmsize;
66711-};
66712+} __do_const;
66713
66714 struct crypto_instance {
66715 struct crypto_alg alg;
66716diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66717index fad21c9..ab858bc 100644
66718--- a/include/drm/drmP.h
66719+++ b/include/drm/drmP.h
66720@@ -72,6 +72,7 @@
66721 #include <linux/workqueue.h>
66722 #include <linux/poll.h>
66723 #include <asm/pgalloc.h>
66724+#include <asm/local.h>
66725 #include <drm/drm.h>
66726 #include <drm/drm_sarea.h>
66727
66728@@ -293,10 +294,12 @@ do { \
66729 * \param cmd command.
66730 * \param arg argument.
66731 */
66732-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66733+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66734+ struct drm_file *file_priv);
66735+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66736 struct drm_file *file_priv);
66737
66738-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66739+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66740 unsigned long arg);
66741
66742 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66743@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66744 struct drm_ioctl_desc {
66745 unsigned int cmd;
66746 int flags;
66747- drm_ioctl_t *func;
66748+ drm_ioctl_t func;
66749 unsigned int cmd_drv;
66750-};
66751+} __do_const;
66752
66753 /**
66754 * Creates a driver or general drm_ioctl_desc array entry for the given
66755@@ -995,7 +998,7 @@ struct drm_info_list {
66756 int (*show)(struct seq_file*, void*); /** show callback */
66757 u32 driver_features; /**< Required driver features for this entry */
66758 void *data;
66759-};
66760+} __do_const;
66761
66762 /**
66763 * debugfs node structure. This structure represents a debugfs file.
66764@@ -1068,7 +1071,7 @@ struct drm_device {
66765
66766 /** \name Usage Counters */
66767 /*@{ */
66768- int open_count; /**< Outstanding files open */
66769+ local_t open_count; /**< Outstanding files open */
66770 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66771 atomic_t vma_count; /**< Outstanding vma areas open */
66772 int buf_use; /**< Buffers in use -- cannot alloc */
66773@@ -1079,7 +1082,7 @@ struct drm_device {
66774 /*@{ */
66775 unsigned long counters;
66776 enum drm_stat_type types[15];
66777- atomic_t counts[15];
66778+ atomic_unchecked_t counts[15];
66779 /*@} */
66780
66781 struct list_head filelist;
66782diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66783index f43d556..94d9343 100644
66784--- a/include/drm/drm_crtc_helper.h
66785+++ b/include/drm/drm_crtc_helper.h
66786@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66787 struct drm_connector *connector);
66788 /* disable encoder when not in use - more explicit than dpms off */
66789 void (*disable)(struct drm_encoder *encoder);
66790-};
66791+} __no_const;
66792
66793 /**
66794 * drm_connector_helper_funcs - helper operations for connectors
66795diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66796index 72dcbe8..8db58d7 100644
66797--- a/include/drm/ttm/ttm_memory.h
66798+++ b/include/drm/ttm/ttm_memory.h
66799@@ -48,7 +48,7 @@
66800
66801 struct ttm_mem_shrink {
66802 int (*do_shrink) (struct ttm_mem_shrink *);
66803-};
66804+} __no_const;
66805
66806 /**
66807 * struct ttm_mem_global - Global memory accounting structure.
66808diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66809index 4b840e8..155d235 100644
66810--- a/include/keys/asymmetric-subtype.h
66811+++ b/include/keys/asymmetric-subtype.h
66812@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66813 /* Verify the signature on a key of this subtype (optional) */
66814 int (*verify_signature)(const struct key *key,
66815 const struct public_key_signature *sig);
66816-};
66817+} __do_const;
66818
66819 /**
66820 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66821diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66822index c1da539..1dcec55 100644
66823--- a/include/linux/atmdev.h
66824+++ b/include/linux/atmdev.h
66825@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66826 #endif
66827
66828 struct k_atm_aal_stats {
66829-#define __HANDLE_ITEM(i) atomic_t i
66830+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66831 __AAL_STAT_ITEMS
66832 #undef __HANDLE_ITEM
66833 };
66834@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66835 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66836 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66837 struct module *owner;
66838-};
66839+} __do_const ;
66840
66841 struct atmphy_ops {
66842 int (*start)(struct atm_dev *dev);
66843diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66844index 0530b98..96a8ac0 100644
66845--- a/include/linux/binfmts.h
66846+++ b/include/linux/binfmts.h
66847@@ -73,8 +73,9 @@ struct linux_binfmt {
66848 int (*load_binary)(struct linux_binprm *);
66849 int (*load_shlib)(struct file *);
66850 int (*core_dump)(struct coredump_params *cprm);
66851+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66852 unsigned long min_coredump; /* minimal dump size */
66853-};
66854+} __do_const;
66855
66856 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66857
66858diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66859index f94bc83..62b9cfe 100644
66860--- a/include/linux/blkdev.h
66861+++ b/include/linux/blkdev.h
66862@@ -1498,7 +1498,7 @@ struct block_device_operations {
66863 /* this callback is with swap_lock and sometimes page table lock held */
66864 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66865 struct module *owner;
66866-};
66867+} __do_const;
66868
66869 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66870 unsigned long);
66871diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66872index 7c2e030..b72475d 100644
66873--- a/include/linux/blktrace_api.h
66874+++ b/include/linux/blktrace_api.h
66875@@ -23,7 +23,7 @@ struct blk_trace {
66876 struct dentry *dir;
66877 struct dentry *dropped_file;
66878 struct dentry *msg_file;
66879- atomic_t dropped;
66880+ atomic_unchecked_t dropped;
66881 };
66882
66883 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66884diff --git a/include/linux/cache.h b/include/linux/cache.h
66885index 4c57065..4307975 100644
66886--- a/include/linux/cache.h
66887+++ b/include/linux/cache.h
66888@@ -16,6 +16,10 @@
66889 #define __read_mostly
66890 #endif
66891
66892+#ifndef __read_only
66893+#define __read_only __read_mostly
66894+#endif
66895+
66896 #ifndef ____cacheline_aligned
66897 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66898 #endif
66899diff --git a/include/linux/capability.h b/include/linux/capability.h
66900index 98503b7..cc36d18 100644
66901--- a/include/linux/capability.h
66902+++ b/include/linux/capability.h
66903@@ -211,8 +211,13 @@ extern bool capable(int cap);
66904 extern bool ns_capable(struct user_namespace *ns, int cap);
66905 extern bool nsown_capable(int cap);
66906 extern bool inode_capable(const struct inode *inode, int cap);
66907+extern bool capable_nolog(int cap);
66908+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66909+extern bool inode_capable_nolog(const struct inode *inode, int cap);
66910
66911 /* audit system wants to get cap info from files as well */
66912 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66913
66914+extern int is_privileged_binary(const struct dentry *dentry);
66915+
66916 #endif /* !_LINUX_CAPABILITY_H */
66917diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66918index 8609d57..86e4d79 100644
66919--- a/include/linux/cdrom.h
66920+++ b/include/linux/cdrom.h
66921@@ -87,7 +87,6 @@ struct cdrom_device_ops {
66922
66923 /* driver specifications */
66924 const int capability; /* capability flags */
66925- int n_minors; /* number of active minor devices */
66926 /* handle uniform packets for scsi type devices (scsi,atapi) */
66927 int (*generic_packet) (struct cdrom_device_info *,
66928 struct packet_command *);
66929diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66930index 42e55de..1cd0e66 100644
66931--- a/include/linux/cleancache.h
66932+++ b/include/linux/cleancache.h
66933@@ -31,7 +31,7 @@ struct cleancache_ops {
66934 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66935 void (*invalidate_inode)(int, struct cleancache_filekey);
66936 void (*invalidate_fs)(int);
66937-};
66938+} __no_const;
66939
66940 extern struct cleancache_ops
66941 cleancache_register_ops(struct cleancache_ops *ops);
66942diff --git a/include/linux/compat.h b/include/linux/compat.h
66943index dec7e2d..45db13f 100644
66944--- a/include/linux/compat.h
66945+++ b/include/linux/compat.h
66946@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
66947 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
66948 int version, void __user *uptr);
66949 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
66950- void __user *uptr);
66951+ void __user *uptr) __intentional_overflow(0);
66952 #else
66953 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
66954 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
66955 compat_ssize_t msgsz, int msgflg);
66956 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
66957 compat_ssize_t msgsz, long msgtyp, int msgflg);
66958-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
66959+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
66960 #endif
66961 long compat_sys_msgctl(int first, int second, void __user *uptr);
66962 long compat_sys_shmctl(int first, int second, void __user *uptr);
66963@@ -414,7 +414,7 @@ extern int compat_ptrace_request(struct task_struct *child,
66964 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
66965 compat_ulong_t addr, compat_ulong_t data);
66966 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
66967- compat_long_t addr, compat_long_t data);
66968+ compat_ulong_t addr, compat_ulong_t data);
66969
66970 /*
66971 * epoll (fs/eventpoll.c) compat bits follow ...
66972diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66973index 662fd1b..e801992 100644
66974--- a/include/linux/compiler-gcc4.h
66975+++ b/include/linux/compiler-gcc4.h
66976@@ -34,6 +34,21 @@
66977 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66978
66979 #if __GNUC_MINOR__ >= 5
66980+
66981+#ifdef CONSTIFY_PLUGIN
66982+#define __no_const __attribute__((no_const))
66983+#define __do_const __attribute__((do_const))
66984+#endif
66985+
66986+#ifdef SIZE_OVERFLOW_PLUGIN
66987+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66988+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66989+#endif
66990+
66991+#ifdef LATENT_ENTROPY_PLUGIN
66992+#define __latent_entropy __attribute__((latent_entropy))
66993+#endif
66994+
66995 /*
66996 * Mark a position in code as unreachable. This can be used to
66997 * suppress control flow warnings after asm blocks that transfer
66998@@ -49,6 +64,11 @@
66999 #define __noclone __attribute__((__noclone__))
67000
67001 #endif
67002+
67003+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67004+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67005+#define __bos0(ptr) __bos((ptr), 0)
67006+#define __bos1(ptr) __bos((ptr), 1)
67007 #endif
67008
67009 #if __GNUC_MINOR__ >= 6
67010diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67011index dd852b7..72924c0 100644
67012--- a/include/linux/compiler.h
67013+++ b/include/linux/compiler.h
67014@@ -5,11 +5,14 @@
67015
67016 #ifdef __CHECKER__
67017 # define __user __attribute__((noderef, address_space(1)))
67018+# define __force_user __force __user
67019 # define __kernel __attribute__((address_space(0)))
67020+# define __force_kernel __force __kernel
67021 # define __safe __attribute__((safe))
67022 # define __force __attribute__((force))
67023 # define __nocast __attribute__((nocast))
67024 # define __iomem __attribute__((noderef, address_space(2)))
67025+# define __force_iomem __force __iomem
67026 # define __must_hold(x) __attribute__((context(x,1,1)))
67027 # define __acquires(x) __attribute__((context(x,0,1)))
67028 # define __releases(x) __attribute__((context(x,1,0)))
67029@@ -17,20 +20,48 @@
67030 # define __release(x) __context__(x,-1)
67031 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
67032 # define __percpu __attribute__((noderef, address_space(3)))
67033+# define __force_percpu __force __percpu
67034 #ifdef CONFIG_SPARSE_RCU_POINTER
67035 # define __rcu __attribute__((noderef, address_space(4)))
67036+# define __force_rcu __force __rcu
67037 #else
67038 # define __rcu
67039+# define __force_rcu
67040 #endif
67041 extern void __chk_user_ptr(const volatile void __user *);
67042 extern void __chk_io_ptr(const volatile void __iomem *);
67043+#elif defined(CHECKER_PLUGIN)
67044+//# define __user
67045+//# define __force_user
67046+//# define __kernel
67047+//# define __force_kernel
67048+# define __safe
67049+# define __force
67050+# define __nocast
67051+# define __iomem
67052+# define __force_iomem
67053+# define __chk_user_ptr(x) (void)0
67054+# define __chk_io_ptr(x) (void)0
67055+# define __builtin_warning(x, y...) (1)
67056+# define __acquires(x)
67057+# define __releases(x)
67058+# define __acquire(x) (void)0
67059+# define __release(x) (void)0
67060+# define __cond_lock(x,c) (c)
67061+# define __percpu
67062+# define __force_percpu
67063+# define __rcu
67064+# define __force_rcu
67065 #else
67066 # define __user
67067+# define __force_user
67068 # define __kernel
67069+# define __force_kernel
67070 # define __safe
67071 # define __force
67072 # define __nocast
67073 # define __iomem
67074+# define __force_iomem
67075 # define __chk_user_ptr(x) (void)0
67076 # define __chk_io_ptr(x) (void)0
67077 # define __builtin_warning(x, y...) (1)
67078@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
67079 # define __release(x) (void)0
67080 # define __cond_lock(x,c) (c)
67081 # define __percpu
67082+# define __force_percpu
67083 # define __rcu
67084+# define __force_rcu
67085 #endif
67086
67087 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
67088@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67089 # define __attribute_const__ /* unimplemented */
67090 #endif
67091
67092+#ifndef __no_const
67093+# define __no_const
67094+#endif
67095+
67096+#ifndef __do_const
67097+# define __do_const
67098+#endif
67099+
67100+#ifndef __size_overflow
67101+# define __size_overflow(...)
67102+#endif
67103+
67104+#ifndef __intentional_overflow
67105+# define __intentional_overflow(...)
67106+#endif
67107+
67108+#ifndef __latent_entropy
67109+# define __latent_entropy
67110+#endif
67111+
67112 /*
67113 * Tell gcc if a function is cold. The compiler will assume any path
67114 * directly leading to the call is unlikely.
67115@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67116 #define __cold
67117 #endif
67118
67119+#ifndef __alloc_size
67120+#define __alloc_size(...)
67121+#endif
67122+
67123+#ifndef __bos
67124+#define __bos(ptr, arg)
67125+#endif
67126+
67127+#ifndef __bos0
67128+#define __bos0(ptr)
67129+#endif
67130+
67131+#ifndef __bos1
67132+#define __bos1(ptr)
67133+#endif
67134+
67135 /* Simple shorthand for a section definition */
67136 #ifndef __section
67137 # define __section(S) __attribute__ ((__section__(#S)))
67138@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67139 * use is to mediate communication between process-level code and irq/NMI
67140 * handlers, all running on the same CPU.
67141 */
67142-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
67143+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
67144+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
67145
67146 #endif /* __LINUX_COMPILER_H */
67147diff --git a/include/linux/completion.h b/include/linux/completion.h
67148index 51494e6..0fd1b61 100644
67149--- a/include/linux/completion.h
67150+++ b/include/linux/completion.h
67151@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
67152
67153 extern void wait_for_completion(struct completion *);
67154 extern int wait_for_completion_interruptible(struct completion *x);
67155-extern int wait_for_completion_killable(struct completion *x);
67156+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
67157 extern unsigned long wait_for_completion_timeout(struct completion *x,
67158 unsigned long timeout);
67159 extern long wait_for_completion_interruptible_timeout(
67160- struct completion *x, unsigned long timeout);
67161+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67162 extern long wait_for_completion_killable_timeout(
67163- struct completion *x, unsigned long timeout);
67164+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67165 extern bool try_wait_for_completion(struct completion *x);
67166 extern bool completion_done(struct completion *x);
67167
67168diff --git a/include/linux/configfs.h b/include/linux/configfs.h
67169index 34025df..d94bbbc 100644
67170--- a/include/linux/configfs.h
67171+++ b/include/linux/configfs.h
67172@@ -125,7 +125,7 @@ struct configfs_attribute {
67173 const char *ca_name;
67174 struct module *ca_owner;
67175 umode_t ca_mode;
67176-};
67177+} __do_const;
67178
67179 /*
67180 * Users often need to create attribute structures for their configurable
67181diff --git a/include/linux/cpu.h b/include/linux/cpu.h
67182index ce7a074..01ab8ac 100644
67183--- a/include/linux/cpu.h
67184+++ b/include/linux/cpu.h
67185@@ -115,7 +115,7 @@ enum {
67186 /* Need to know about CPUs going up/down? */
67187 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
67188 #define cpu_notifier(fn, pri) { \
67189- static struct notifier_block fn##_nb __cpuinitdata = \
67190+ static struct notifier_block fn##_nb = \
67191 { .notifier_call = fn, .priority = pri }; \
67192 register_cpu_notifier(&fn##_nb); \
67193 }
67194diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
67195index a55b88e..fba90c5 100644
67196--- a/include/linux/cpufreq.h
67197+++ b/include/linux/cpufreq.h
67198@@ -240,7 +240,7 @@ struct cpufreq_driver {
67199 int (*suspend) (struct cpufreq_policy *policy);
67200 int (*resume) (struct cpufreq_policy *policy);
67201 struct freq_attr **attr;
67202-};
67203+} __do_const;
67204
67205 /* flags */
67206
67207@@ -299,6 +299,7 @@ struct global_attr {
67208 ssize_t (*store)(struct kobject *a, struct attribute *b,
67209 const char *c, size_t count);
67210 };
67211+typedef struct global_attr __no_const global_attr_no_const;
67212
67213 #define define_one_global_ro(_name) \
67214 static struct global_attr _name = \
67215diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
67216index 24cd1037..20a63aae 100644
67217--- a/include/linux/cpuidle.h
67218+++ b/include/linux/cpuidle.h
67219@@ -54,7 +54,8 @@ struct cpuidle_state {
67220 int index);
67221
67222 int (*enter_dead) (struct cpuidle_device *dev, int index);
67223-};
67224+} __do_const;
67225+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
67226
67227 /* Idle State Flags */
67228 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
67229@@ -216,7 +217,7 @@ struct cpuidle_governor {
67230 void (*reflect) (struct cpuidle_device *dev, int index);
67231
67232 struct module *owner;
67233-};
67234+} __do_const;
67235
67236 #ifdef CONFIG_CPU_IDLE
67237
67238diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
67239index 0325602..5e9feff 100644
67240--- a/include/linux/cpumask.h
67241+++ b/include/linux/cpumask.h
67242@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67243 }
67244
67245 /* Valid inputs for n are -1 and 0. */
67246-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67247+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67248 {
67249 return n+1;
67250 }
67251
67252-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67253+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67254 {
67255 return n+1;
67256 }
67257
67258-static inline unsigned int cpumask_next_and(int n,
67259+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
67260 const struct cpumask *srcp,
67261 const struct cpumask *andp)
67262 {
67263@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67264 *
67265 * Returns >= nr_cpu_ids if no further cpus set.
67266 */
67267-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67268+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67269 {
67270 /* -1 is a legal arg here. */
67271 if (n != -1)
67272@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67273 *
67274 * Returns >= nr_cpu_ids if no further cpus unset.
67275 */
67276-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67277+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67278 {
67279 /* -1 is a legal arg here. */
67280 if (n != -1)
67281@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67282 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
67283 }
67284
67285-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
67286+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
67287 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
67288
67289 /**
67290diff --git a/include/linux/cred.h b/include/linux/cred.h
67291index 04421e8..6bce4ef 100644
67292--- a/include/linux/cred.h
67293+++ b/include/linux/cred.h
67294@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
67295 static inline void validate_process_creds(void)
67296 {
67297 }
67298+static inline void validate_task_creds(struct task_struct *task)
67299+{
67300+}
67301 #endif
67302
67303 /**
67304diff --git a/include/linux/crypto.h b/include/linux/crypto.h
67305index b92eadf..b4ecdc1 100644
67306--- a/include/linux/crypto.h
67307+++ b/include/linux/crypto.h
67308@@ -373,7 +373,7 @@ struct cipher_tfm {
67309 const u8 *key, unsigned int keylen);
67310 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67311 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67312-};
67313+} __no_const;
67314
67315 struct hash_tfm {
67316 int (*init)(struct hash_desc *desc);
67317@@ -394,13 +394,13 @@ struct compress_tfm {
67318 int (*cot_decompress)(struct crypto_tfm *tfm,
67319 const u8 *src, unsigned int slen,
67320 u8 *dst, unsigned int *dlen);
67321-};
67322+} __no_const;
67323
67324 struct rng_tfm {
67325 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
67326 unsigned int dlen);
67327 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
67328-};
67329+} __no_const;
67330
67331 #define crt_ablkcipher crt_u.ablkcipher
67332 #define crt_aead crt_u.aead
67333diff --git a/include/linux/ctype.h b/include/linux/ctype.h
67334index 8acfe31..6ffccd63 100644
67335--- a/include/linux/ctype.h
67336+++ b/include/linux/ctype.h
67337@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
67338 * Fast implementation of tolower() for internal usage. Do not use in your
67339 * code.
67340 */
67341-static inline char _tolower(const char c)
67342+static inline unsigned char _tolower(const unsigned char c)
67343 {
67344 return c | 0x20;
67345 }
67346diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
67347index 7925bf0..d5143d2 100644
67348--- a/include/linux/decompress/mm.h
67349+++ b/include/linux/decompress/mm.h
67350@@ -77,7 +77,7 @@ static void free(void *where)
67351 * warnings when not needed (indeed large_malloc / large_free are not
67352 * needed by inflate */
67353
67354-#define malloc(a) kmalloc(a, GFP_KERNEL)
67355+#define malloc(a) kmalloc((a), GFP_KERNEL)
67356 #define free(a) kfree(a)
67357
67358 #define large_malloc(a) vmalloc(a)
67359diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
67360index e83ef39..33e0eb3 100644
67361--- a/include/linux/devfreq.h
67362+++ b/include/linux/devfreq.h
67363@@ -114,7 +114,7 @@ struct devfreq_governor {
67364 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
67365 int (*event_handler)(struct devfreq *devfreq,
67366 unsigned int event, void *data);
67367-};
67368+} __do_const;
67369
67370 /**
67371 * struct devfreq - Device devfreq structure
67372diff --git a/include/linux/device.h b/include/linux/device.h
67373index 43dcda9..7a1fb65 100644
67374--- a/include/linux/device.h
67375+++ b/include/linux/device.h
67376@@ -294,7 +294,7 @@ struct subsys_interface {
67377 struct list_head node;
67378 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
67379 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
67380-};
67381+} __do_const;
67382
67383 int subsys_interface_register(struct subsys_interface *sif);
67384 void subsys_interface_unregister(struct subsys_interface *sif);
67385@@ -474,7 +474,7 @@ struct device_type {
67386 void (*release)(struct device *dev);
67387
67388 const struct dev_pm_ops *pm;
67389-};
67390+} __do_const;
67391
67392 /* interface for exporting device attributes */
67393 struct device_attribute {
67394@@ -484,11 +484,12 @@ struct device_attribute {
67395 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
67396 const char *buf, size_t count);
67397 };
67398+typedef struct device_attribute __no_const device_attribute_no_const;
67399
67400 struct dev_ext_attribute {
67401 struct device_attribute attr;
67402 void *var;
67403-};
67404+} __do_const;
67405
67406 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
67407 char *buf);
67408diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
67409index 94af418..b1ca7a2 100644
67410--- a/include/linux/dma-mapping.h
67411+++ b/include/linux/dma-mapping.h
67412@@ -54,7 +54,7 @@ struct dma_map_ops {
67413 u64 (*get_required_mask)(struct device *dev);
67414 #endif
67415 int is_phys;
67416-};
67417+} __do_const;
67418
67419 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
67420
67421diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
67422index d3201e4..8281e63 100644
67423--- a/include/linux/dmaengine.h
67424+++ b/include/linux/dmaengine.h
67425@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
67426 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
67427 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
67428
67429-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67430+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67431 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
67432-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67433+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67434 struct dma_pinned_list *pinned_list, struct page *page,
67435 unsigned int offset, size_t len);
67436
67437diff --git a/include/linux/efi.h b/include/linux/efi.h
67438index 7a9498a..155713d 100644
67439--- a/include/linux/efi.h
67440+++ b/include/linux/efi.h
67441@@ -733,6 +733,7 @@ struct efivar_operations {
67442 efi_set_variable_t *set_variable;
67443 efi_query_variable_info_t *query_variable_info;
67444 };
67445+typedef struct efivar_operations __no_const efivar_operations_no_const;
67446
67447 struct efivars {
67448 /*
67449diff --git a/include/linux/elf.h b/include/linux/elf.h
67450index 8c9048e..16a4665 100644
67451--- a/include/linux/elf.h
67452+++ b/include/linux/elf.h
67453@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
67454 #define elf_note elf32_note
67455 #define elf_addr_t Elf32_Off
67456 #define Elf_Half Elf32_Half
67457+#define elf_dyn Elf32_Dyn
67458
67459 #else
67460
67461@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
67462 #define elf_note elf64_note
67463 #define elf_addr_t Elf64_Off
67464 #define Elf_Half Elf64_Half
67465+#define elf_dyn Elf64_Dyn
67466
67467 #endif
67468
67469diff --git a/include/linux/err.h b/include/linux/err.h
67470index f2edce2..cc2082c 100644
67471--- a/include/linux/err.h
67472+++ b/include/linux/err.h
67473@@ -19,12 +19,12 @@
67474
67475 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
67476
67477-static inline void * __must_check ERR_PTR(long error)
67478+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
67479 {
67480 return (void *) error;
67481 }
67482
67483-static inline long __must_check PTR_ERR(const void *ptr)
67484+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
67485 {
67486 return (long) ptr;
67487 }
67488diff --git a/include/linux/extcon.h b/include/linux/extcon.h
67489index fcb51c8..bdafcf6 100644
67490--- a/include/linux/extcon.h
67491+++ b/include/linux/extcon.h
67492@@ -134,7 +134,7 @@ struct extcon_dev {
67493 /* /sys/class/extcon/.../mutually_exclusive/... */
67494 struct attribute_group attr_g_muex;
67495 struct attribute **attrs_muex;
67496- struct device_attribute *d_attrs_muex;
67497+ device_attribute_no_const *d_attrs_muex;
67498 };
67499
67500 /**
67501diff --git a/include/linux/fb.h b/include/linux/fb.h
67502index c7a9571..02eeffe 100644
67503--- a/include/linux/fb.h
67504+++ b/include/linux/fb.h
67505@@ -302,7 +302,7 @@ struct fb_ops {
67506 /* called at KDB enter and leave time to prepare the console */
67507 int (*fb_debug_enter)(struct fb_info *info);
67508 int (*fb_debug_leave)(struct fb_info *info);
67509-};
67510+} __do_const;
67511
67512 #ifdef CONFIG_FB_TILEBLITTING
67513 #define FB_TILE_CURSOR_NONE 0
67514diff --git a/include/linux/filter.h b/include/linux/filter.h
67515index c45eabc..baa0be5 100644
67516--- a/include/linux/filter.h
67517+++ b/include/linux/filter.h
67518@@ -20,6 +20,7 @@ struct compat_sock_fprog {
67519
67520 struct sk_buff;
67521 struct sock;
67522+struct bpf_jit_work;
67523
67524 struct sk_filter
67525 {
67526@@ -27,6 +28,9 @@ struct sk_filter
67527 unsigned int len; /* Number of filter blocks */
67528 unsigned int (*bpf_func)(const struct sk_buff *skb,
67529 const struct sock_filter *filter);
67530+#ifdef CONFIG_BPF_JIT
67531+ struct bpf_jit_work *work;
67532+#endif
67533 struct rcu_head rcu;
67534 struct sock_filter insns[0];
67535 };
67536diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
67537index 3044254..9767f41 100644
67538--- a/include/linux/frontswap.h
67539+++ b/include/linux/frontswap.h
67540@@ -11,7 +11,7 @@ struct frontswap_ops {
67541 int (*load)(unsigned, pgoff_t, struct page *);
67542 void (*invalidate_page)(unsigned, pgoff_t);
67543 void (*invalidate_area)(unsigned);
67544-};
67545+} __no_const;
67546
67547 extern bool frontswap_enabled;
67548 extern struct frontswap_ops
67549diff --git a/include/linux/fs.h b/include/linux/fs.h
67550index 7617ee0..b575199 100644
67551--- a/include/linux/fs.h
67552+++ b/include/linux/fs.h
67553@@ -1541,7 +1541,8 @@ struct file_operations {
67554 long (*fallocate)(struct file *file, int mode, loff_t offset,
67555 loff_t len);
67556 int (*show_fdinfo)(struct seq_file *m, struct file *f);
67557-};
67558+} __do_const;
67559+typedef struct file_operations __no_const file_operations_no_const;
67560
67561 struct inode_operations {
67562 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
67563@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
67564 inode->i_flags |= S_NOSEC;
67565 }
67566
67567+static inline bool is_sidechannel_device(const struct inode *inode)
67568+{
67569+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
67570+ umode_t mode = inode->i_mode;
67571+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
67572+#else
67573+ return false;
67574+#endif
67575+}
67576+
67577 #endif /* _LINUX_FS_H */
67578diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
67579index d0ae3a8..0244b34 100644
67580--- a/include/linux/fs_struct.h
67581+++ b/include/linux/fs_struct.h
67582@@ -6,7 +6,7 @@
67583 #include <linux/seqlock.h>
67584
67585 struct fs_struct {
67586- int users;
67587+ atomic_t users;
67588 spinlock_t lock;
67589 seqcount_t seq;
67590 int umask;
67591diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
67592index 5dfa0aa..6acf322 100644
67593--- a/include/linux/fscache-cache.h
67594+++ b/include/linux/fscache-cache.h
67595@@ -112,7 +112,7 @@ struct fscache_operation {
67596 fscache_operation_release_t release;
67597 };
67598
67599-extern atomic_t fscache_op_debug_id;
67600+extern atomic_unchecked_t fscache_op_debug_id;
67601 extern void fscache_op_work_func(struct work_struct *work);
67602
67603 extern void fscache_enqueue_operation(struct fscache_operation *);
67604@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
67605 INIT_WORK(&op->work, fscache_op_work_func);
67606 atomic_set(&op->usage, 1);
67607 op->state = FSCACHE_OP_ST_INITIALISED;
67608- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
67609+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
67610 op->processor = processor;
67611 op->release = release;
67612 INIT_LIST_HEAD(&op->pend_link);
67613diff --git a/include/linux/fscache.h b/include/linux/fscache.h
67614index 7a08623..4c07b0f 100644
67615--- a/include/linux/fscache.h
67616+++ b/include/linux/fscache.h
67617@@ -152,7 +152,7 @@ struct fscache_cookie_def {
67618 * - this is mandatory for any object that may have data
67619 */
67620 void (*now_uncached)(void *cookie_netfs_data);
67621-};
67622+} __do_const;
67623
67624 /*
67625 * fscache cached network filesystem type
67626diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
67627index 0fbfb46..508eb0d 100644
67628--- a/include/linux/fsnotify.h
67629+++ b/include/linux/fsnotify.h
67630@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
67631 struct inode *inode = path->dentry->d_inode;
67632 __u32 mask = FS_ACCESS;
67633
67634+ if (is_sidechannel_device(inode))
67635+ return;
67636+
67637 if (S_ISDIR(inode->i_mode))
67638 mask |= FS_ISDIR;
67639
67640@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
67641 struct inode *inode = path->dentry->d_inode;
67642 __u32 mask = FS_MODIFY;
67643
67644+ if (is_sidechannel_device(inode))
67645+ return;
67646+
67647 if (S_ISDIR(inode->i_mode))
67648 mask |= FS_ISDIR;
67649
67650@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
67651 */
67652 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
67653 {
67654- return kstrdup(name, GFP_KERNEL);
67655+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
67656 }
67657
67658 /*
67659diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
67660index a3d4895..ddd2a50 100644
67661--- a/include/linux/ftrace_event.h
67662+++ b/include/linux/ftrace_event.h
67663@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
67664 extern int trace_add_event_call(struct ftrace_event_call *call);
67665 extern void trace_remove_event_call(struct ftrace_event_call *call);
67666
67667-#define is_signed_type(type) (((type)(-1)) < 0)
67668+#define is_signed_type(type) (((type)(-1)) < (type)1)
67669
67670 int trace_set_clr_event(const char *system, const char *event, int set);
67671
67672diff --git a/include/linux/genhd.h b/include/linux/genhd.h
67673index 79b8bba..86b539e 100644
67674--- a/include/linux/genhd.h
67675+++ b/include/linux/genhd.h
67676@@ -194,7 +194,7 @@ struct gendisk {
67677 struct kobject *slave_dir;
67678
67679 struct timer_rand_state *random;
67680- atomic_t sync_io; /* RAID */
67681+ atomic_unchecked_t sync_io; /* RAID */
67682 struct disk_events *ev;
67683 #ifdef CONFIG_BLK_DEV_INTEGRITY
67684 struct blk_integrity *integrity;
67685diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
67686index 023bc34..b02b46a 100644
67687--- a/include/linux/genl_magic_func.h
67688+++ b/include/linux/genl_magic_func.h
67689@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
67690 },
67691
67692 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
67693-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
67694+static struct genl_ops ZZZ_genl_ops[] = {
67695 #include GENL_MAGIC_INCLUDE_FILE
67696 };
67697
67698diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67699index 0f615eb..5c3832f 100644
67700--- a/include/linux/gfp.h
67701+++ b/include/linux/gfp.h
67702@@ -35,6 +35,13 @@ struct vm_area_struct;
67703 #define ___GFP_NO_KSWAPD 0x400000u
67704 #define ___GFP_OTHER_NODE 0x800000u
67705 #define ___GFP_WRITE 0x1000000u
67706+
67707+#ifdef CONFIG_PAX_USERCOPY_SLABS
67708+#define ___GFP_USERCOPY 0x2000000u
67709+#else
67710+#define ___GFP_USERCOPY 0
67711+#endif
67712+
67713 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67714
67715 /*
67716@@ -92,6 +99,7 @@ struct vm_area_struct;
67717 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67718 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67719 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67720+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67721
67722 /*
67723 * This may seem redundant, but it's a way of annotating false positives vs.
67724@@ -99,7 +107,7 @@ struct vm_area_struct;
67725 */
67726 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67727
67728-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67729+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67730 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67731
67732 /* This equals 0, but use constants in case they ever change */
67733@@ -153,6 +161,8 @@ struct vm_area_struct;
67734 /* 4GB DMA on some platforms */
67735 #define GFP_DMA32 __GFP_DMA32
67736
67737+#define GFP_USERCOPY __GFP_USERCOPY
67738+
67739 /* Convert GFP flags to their corresponding migrate type */
67740 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67741 {
67742diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67743new file mode 100644
67744index 0000000..ebe6d72
67745--- /dev/null
67746+++ b/include/linux/gracl.h
67747@@ -0,0 +1,319 @@
67748+#ifndef GR_ACL_H
67749+#define GR_ACL_H
67750+
67751+#include <linux/grdefs.h>
67752+#include <linux/resource.h>
67753+#include <linux/capability.h>
67754+#include <linux/dcache.h>
67755+#include <asm/resource.h>
67756+
67757+/* Major status information */
67758+
67759+#define GR_VERSION "grsecurity 2.9.1"
67760+#define GRSECURITY_VERSION 0x2901
67761+
67762+enum {
67763+ GR_SHUTDOWN = 0,
67764+ GR_ENABLE = 1,
67765+ GR_SPROLE = 2,
67766+ GR_RELOAD = 3,
67767+ GR_SEGVMOD = 4,
67768+ GR_STATUS = 5,
67769+ GR_UNSPROLE = 6,
67770+ GR_PASSSET = 7,
67771+ GR_SPROLEPAM = 8,
67772+};
67773+
67774+/* Password setup definitions
67775+ * kernel/grhash.c */
67776+enum {
67777+ GR_PW_LEN = 128,
67778+ GR_SALT_LEN = 16,
67779+ GR_SHA_LEN = 32,
67780+};
67781+
67782+enum {
67783+ GR_SPROLE_LEN = 64,
67784+};
67785+
67786+enum {
67787+ GR_NO_GLOB = 0,
67788+ GR_REG_GLOB,
67789+ GR_CREATE_GLOB
67790+};
67791+
67792+#define GR_NLIMITS 32
67793+
67794+/* Begin Data Structures */
67795+
67796+struct sprole_pw {
67797+ unsigned char *rolename;
67798+ unsigned char salt[GR_SALT_LEN];
67799+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67800+};
67801+
67802+struct name_entry {
67803+ __u32 key;
67804+ ino_t inode;
67805+ dev_t device;
67806+ char *name;
67807+ __u16 len;
67808+ __u8 deleted;
67809+ struct name_entry *prev;
67810+ struct name_entry *next;
67811+};
67812+
67813+struct inodev_entry {
67814+ struct name_entry *nentry;
67815+ struct inodev_entry *prev;
67816+ struct inodev_entry *next;
67817+};
67818+
67819+struct acl_role_db {
67820+ struct acl_role_label **r_hash;
67821+ __u32 r_size;
67822+};
67823+
67824+struct inodev_db {
67825+ struct inodev_entry **i_hash;
67826+ __u32 i_size;
67827+};
67828+
67829+struct name_db {
67830+ struct name_entry **n_hash;
67831+ __u32 n_size;
67832+};
67833+
67834+struct crash_uid {
67835+ uid_t uid;
67836+ unsigned long expires;
67837+};
67838+
67839+struct gr_hash_struct {
67840+ void **table;
67841+ void **nametable;
67842+ void *first;
67843+ __u32 table_size;
67844+ __u32 used_size;
67845+ int type;
67846+};
67847+
67848+/* Userspace Grsecurity ACL data structures */
67849+
67850+struct acl_subject_label {
67851+ char *filename;
67852+ ino_t inode;
67853+ dev_t device;
67854+ __u32 mode;
67855+ kernel_cap_t cap_mask;
67856+ kernel_cap_t cap_lower;
67857+ kernel_cap_t cap_invert_audit;
67858+
67859+ struct rlimit res[GR_NLIMITS];
67860+ __u32 resmask;
67861+
67862+ __u8 user_trans_type;
67863+ __u8 group_trans_type;
67864+ uid_t *user_transitions;
67865+ gid_t *group_transitions;
67866+ __u16 user_trans_num;
67867+ __u16 group_trans_num;
67868+
67869+ __u32 sock_families[2];
67870+ __u32 ip_proto[8];
67871+ __u32 ip_type;
67872+ struct acl_ip_label **ips;
67873+ __u32 ip_num;
67874+ __u32 inaddr_any_override;
67875+
67876+ __u32 crashes;
67877+ unsigned long expires;
67878+
67879+ struct acl_subject_label *parent_subject;
67880+ struct gr_hash_struct *hash;
67881+ struct acl_subject_label *prev;
67882+ struct acl_subject_label *next;
67883+
67884+ struct acl_object_label **obj_hash;
67885+ __u32 obj_hash_size;
67886+ __u16 pax_flags;
67887+};
67888+
67889+struct role_allowed_ip {
67890+ __u32 addr;
67891+ __u32 netmask;
67892+
67893+ struct role_allowed_ip *prev;
67894+ struct role_allowed_ip *next;
67895+};
67896+
67897+struct role_transition {
67898+ char *rolename;
67899+
67900+ struct role_transition *prev;
67901+ struct role_transition *next;
67902+};
67903+
67904+struct acl_role_label {
67905+ char *rolename;
67906+ uid_t uidgid;
67907+ __u16 roletype;
67908+
67909+ __u16 auth_attempts;
67910+ unsigned long expires;
67911+
67912+ struct acl_subject_label *root_label;
67913+ struct gr_hash_struct *hash;
67914+
67915+ struct acl_role_label *prev;
67916+ struct acl_role_label *next;
67917+
67918+ struct role_transition *transitions;
67919+ struct role_allowed_ip *allowed_ips;
67920+ uid_t *domain_children;
67921+ __u16 domain_child_num;
67922+
67923+ umode_t umask;
67924+
67925+ struct acl_subject_label **subj_hash;
67926+ __u32 subj_hash_size;
67927+};
67928+
67929+struct user_acl_role_db {
67930+ struct acl_role_label **r_table;
67931+ __u32 num_pointers; /* Number of allocations to track */
67932+ __u32 num_roles; /* Number of roles */
67933+ __u32 num_domain_children; /* Number of domain children */
67934+ __u32 num_subjects; /* Number of subjects */
67935+ __u32 num_objects; /* Number of objects */
67936+};
67937+
67938+struct acl_object_label {
67939+ char *filename;
67940+ ino_t inode;
67941+ dev_t device;
67942+ __u32 mode;
67943+
67944+ struct acl_subject_label *nested;
67945+ struct acl_object_label *globbed;
67946+
67947+ /* next two structures not used */
67948+
67949+ struct acl_object_label *prev;
67950+ struct acl_object_label *next;
67951+};
67952+
67953+struct acl_ip_label {
67954+ char *iface;
67955+ __u32 addr;
67956+ __u32 netmask;
67957+ __u16 low, high;
67958+ __u8 mode;
67959+ __u32 type;
67960+ __u32 proto[8];
67961+
67962+ /* next two structures not used */
67963+
67964+ struct acl_ip_label *prev;
67965+ struct acl_ip_label *next;
67966+};
67967+
67968+struct gr_arg {
67969+ struct user_acl_role_db role_db;
67970+ unsigned char pw[GR_PW_LEN];
67971+ unsigned char salt[GR_SALT_LEN];
67972+ unsigned char sum[GR_SHA_LEN];
67973+ unsigned char sp_role[GR_SPROLE_LEN];
67974+ struct sprole_pw *sprole_pws;
67975+ dev_t segv_device;
67976+ ino_t segv_inode;
67977+ uid_t segv_uid;
67978+ __u16 num_sprole_pws;
67979+ __u16 mode;
67980+};
67981+
67982+struct gr_arg_wrapper {
67983+ struct gr_arg *arg;
67984+ __u32 version;
67985+ __u32 size;
67986+};
67987+
67988+struct subject_map {
67989+ struct acl_subject_label *user;
67990+ struct acl_subject_label *kernel;
67991+ struct subject_map *prev;
67992+ struct subject_map *next;
67993+};
67994+
67995+struct acl_subj_map_db {
67996+ struct subject_map **s_hash;
67997+ __u32 s_size;
67998+};
67999+
68000+/* End Data Structures Section */
68001+
68002+/* Hash functions generated by empirical testing by Brad Spengler
68003+ Makes good use of the low bits of the inode. Generally 0-1 times
68004+ in loop for successful match. 0-3 for unsuccessful match.
68005+ Shift/add algorithm with modulus of table size and an XOR*/
68006+
68007+static __inline__ unsigned int
68008+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68009+{
68010+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68011+}
68012+
68013+ static __inline__ unsigned int
68014+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68015+{
68016+ return ((const unsigned long)userp % sz);
68017+}
68018+
68019+static __inline__ unsigned int
68020+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68021+{
68022+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68023+}
68024+
68025+static __inline__ unsigned int
68026+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68027+{
68028+ return full_name_hash((const unsigned char *)name, len) % sz;
68029+}
68030+
68031+#define FOR_EACH_ROLE_START(role) \
68032+ role = role_list; \
68033+ while (role) {
68034+
68035+#define FOR_EACH_ROLE_END(role) \
68036+ role = role->prev; \
68037+ }
68038+
68039+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68040+ subj = NULL; \
68041+ iter = 0; \
68042+ while (iter < role->subj_hash_size) { \
68043+ if (subj == NULL) \
68044+ subj = role->subj_hash[iter]; \
68045+ if (subj == NULL) { \
68046+ iter++; \
68047+ continue; \
68048+ }
68049+
68050+#define FOR_EACH_SUBJECT_END(subj,iter) \
68051+ subj = subj->next; \
68052+ if (subj == NULL) \
68053+ iter++; \
68054+ }
68055+
68056+
68057+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
68058+ subj = role->hash->first; \
68059+ while (subj != NULL) {
68060+
68061+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
68062+ subj = subj->next; \
68063+ }
68064+
68065+#endif
68066+
68067diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
68068new file mode 100644
68069index 0000000..323ecf2
68070--- /dev/null
68071+++ b/include/linux/gralloc.h
68072@@ -0,0 +1,9 @@
68073+#ifndef __GRALLOC_H
68074+#define __GRALLOC_H
68075+
68076+void acl_free_all(void);
68077+int acl_alloc_stack_init(unsigned long size);
68078+void *acl_alloc(unsigned long len);
68079+void *acl_alloc_num(unsigned long num, unsigned long len);
68080+
68081+#endif
68082diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
68083new file mode 100644
68084index 0000000..be66033
68085--- /dev/null
68086+++ b/include/linux/grdefs.h
68087@@ -0,0 +1,140 @@
68088+#ifndef GRDEFS_H
68089+#define GRDEFS_H
68090+
68091+/* Begin grsecurity status declarations */
68092+
68093+enum {
68094+ GR_READY = 0x01,
68095+ GR_STATUS_INIT = 0x00 // disabled state
68096+};
68097+
68098+/* Begin ACL declarations */
68099+
68100+/* Role flags */
68101+
68102+enum {
68103+ GR_ROLE_USER = 0x0001,
68104+ GR_ROLE_GROUP = 0x0002,
68105+ GR_ROLE_DEFAULT = 0x0004,
68106+ GR_ROLE_SPECIAL = 0x0008,
68107+ GR_ROLE_AUTH = 0x0010,
68108+ GR_ROLE_NOPW = 0x0020,
68109+ GR_ROLE_GOD = 0x0040,
68110+ GR_ROLE_LEARN = 0x0080,
68111+ GR_ROLE_TPE = 0x0100,
68112+ GR_ROLE_DOMAIN = 0x0200,
68113+ GR_ROLE_PAM = 0x0400,
68114+ GR_ROLE_PERSIST = 0x0800
68115+};
68116+
68117+/* ACL Subject and Object mode flags */
68118+enum {
68119+ GR_DELETED = 0x80000000
68120+};
68121+
68122+/* ACL Object-only mode flags */
68123+enum {
68124+ GR_READ = 0x00000001,
68125+ GR_APPEND = 0x00000002,
68126+ GR_WRITE = 0x00000004,
68127+ GR_EXEC = 0x00000008,
68128+ GR_FIND = 0x00000010,
68129+ GR_INHERIT = 0x00000020,
68130+ GR_SETID = 0x00000040,
68131+ GR_CREATE = 0x00000080,
68132+ GR_DELETE = 0x00000100,
68133+ GR_LINK = 0x00000200,
68134+ GR_AUDIT_READ = 0x00000400,
68135+ GR_AUDIT_APPEND = 0x00000800,
68136+ GR_AUDIT_WRITE = 0x00001000,
68137+ GR_AUDIT_EXEC = 0x00002000,
68138+ GR_AUDIT_FIND = 0x00004000,
68139+ GR_AUDIT_INHERIT= 0x00008000,
68140+ GR_AUDIT_SETID = 0x00010000,
68141+ GR_AUDIT_CREATE = 0x00020000,
68142+ GR_AUDIT_DELETE = 0x00040000,
68143+ GR_AUDIT_LINK = 0x00080000,
68144+ GR_PTRACERD = 0x00100000,
68145+ GR_NOPTRACE = 0x00200000,
68146+ GR_SUPPRESS = 0x00400000,
68147+ GR_NOLEARN = 0x00800000,
68148+ GR_INIT_TRANSFER= 0x01000000
68149+};
68150+
68151+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
68152+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
68153+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
68154+
68155+/* ACL subject-only mode flags */
68156+enum {
68157+ GR_KILL = 0x00000001,
68158+ GR_VIEW = 0x00000002,
68159+ GR_PROTECTED = 0x00000004,
68160+ GR_LEARN = 0x00000008,
68161+ GR_OVERRIDE = 0x00000010,
68162+ /* just a placeholder, this mode is only used in userspace */
68163+ GR_DUMMY = 0x00000020,
68164+ GR_PROTSHM = 0x00000040,
68165+ GR_KILLPROC = 0x00000080,
68166+ GR_KILLIPPROC = 0x00000100,
68167+ /* just a placeholder, this mode is only used in userspace */
68168+ GR_NOTROJAN = 0x00000200,
68169+ GR_PROTPROCFD = 0x00000400,
68170+ GR_PROCACCT = 0x00000800,
68171+ GR_RELAXPTRACE = 0x00001000,
68172+ //GR_NESTED = 0x00002000,
68173+ GR_INHERITLEARN = 0x00004000,
68174+ GR_PROCFIND = 0x00008000,
68175+ GR_POVERRIDE = 0x00010000,
68176+ GR_KERNELAUTH = 0x00020000,
68177+ GR_ATSECURE = 0x00040000,
68178+ GR_SHMEXEC = 0x00080000
68179+};
68180+
68181+enum {
68182+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
68183+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
68184+ GR_PAX_ENABLE_MPROTECT = 0x0004,
68185+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
68186+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
68187+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
68188+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
68189+ GR_PAX_DISABLE_MPROTECT = 0x0400,
68190+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
68191+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
68192+};
68193+
68194+enum {
68195+ GR_ID_USER = 0x01,
68196+ GR_ID_GROUP = 0x02,
68197+};
68198+
68199+enum {
68200+ GR_ID_ALLOW = 0x01,
68201+ GR_ID_DENY = 0x02,
68202+};
68203+
68204+#define GR_CRASH_RES 31
68205+#define GR_UIDTABLE_MAX 500
68206+
68207+/* begin resource learning section */
68208+enum {
68209+ GR_RLIM_CPU_BUMP = 60,
68210+ GR_RLIM_FSIZE_BUMP = 50000,
68211+ GR_RLIM_DATA_BUMP = 10000,
68212+ GR_RLIM_STACK_BUMP = 1000,
68213+ GR_RLIM_CORE_BUMP = 10000,
68214+ GR_RLIM_RSS_BUMP = 500000,
68215+ GR_RLIM_NPROC_BUMP = 1,
68216+ GR_RLIM_NOFILE_BUMP = 5,
68217+ GR_RLIM_MEMLOCK_BUMP = 50000,
68218+ GR_RLIM_AS_BUMP = 500000,
68219+ GR_RLIM_LOCKS_BUMP = 2,
68220+ GR_RLIM_SIGPENDING_BUMP = 5,
68221+ GR_RLIM_MSGQUEUE_BUMP = 10000,
68222+ GR_RLIM_NICE_BUMP = 1,
68223+ GR_RLIM_RTPRIO_BUMP = 1,
68224+ GR_RLIM_RTTIME_BUMP = 1000000
68225+};
68226+
68227+#endif
68228diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
68229new file mode 100644
68230index 0000000..9bb6662
68231--- /dev/null
68232+++ b/include/linux/grinternal.h
68233@@ -0,0 +1,215 @@
68234+#ifndef __GRINTERNAL_H
68235+#define __GRINTERNAL_H
68236+
68237+#ifdef CONFIG_GRKERNSEC
68238+
68239+#include <linux/fs.h>
68240+#include <linux/mnt_namespace.h>
68241+#include <linux/nsproxy.h>
68242+#include <linux/gracl.h>
68243+#include <linux/grdefs.h>
68244+#include <linux/grmsg.h>
68245+
68246+void gr_add_learn_entry(const char *fmt, ...)
68247+ __attribute__ ((format (printf, 1, 2)));
68248+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
68249+ const struct vfsmount *mnt);
68250+__u32 gr_check_create(const struct dentry *new_dentry,
68251+ const struct dentry *parent,
68252+ const struct vfsmount *mnt, const __u32 mode);
68253+int gr_check_protected_task(const struct task_struct *task);
68254+__u32 to_gr_audit(const __u32 reqmode);
68255+int gr_set_acls(const int type);
68256+int gr_apply_subject_to_task(struct task_struct *task);
68257+int gr_acl_is_enabled(void);
68258+char gr_roletype_to_char(void);
68259+
68260+void gr_handle_alertkill(struct task_struct *task);
68261+char *gr_to_filename(const struct dentry *dentry,
68262+ const struct vfsmount *mnt);
68263+char *gr_to_filename1(const struct dentry *dentry,
68264+ const struct vfsmount *mnt);
68265+char *gr_to_filename2(const struct dentry *dentry,
68266+ const struct vfsmount *mnt);
68267+char *gr_to_filename3(const struct dentry *dentry,
68268+ const struct vfsmount *mnt);
68269+
68270+extern int grsec_enable_ptrace_readexec;
68271+extern int grsec_enable_harden_ptrace;
68272+extern int grsec_enable_link;
68273+extern int grsec_enable_fifo;
68274+extern int grsec_enable_execve;
68275+extern int grsec_enable_shm;
68276+extern int grsec_enable_execlog;
68277+extern int grsec_enable_signal;
68278+extern int grsec_enable_audit_ptrace;
68279+extern int grsec_enable_forkfail;
68280+extern int grsec_enable_time;
68281+extern int grsec_enable_rofs;
68282+extern int grsec_enable_chroot_shmat;
68283+extern int grsec_enable_chroot_mount;
68284+extern int grsec_enable_chroot_double;
68285+extern int grsec_enable_chroot_pivot;
68286+extern int grsec_enable_chroot_chdir;
68287+extern int grsec_enable_chroot_chmod;
68288+extern int grsec_enable_chroot_mknod;
68289+extern int grsec_enable_chroot_fchdir;
68290+extern int grsec_enable_chroot_nice;
68291+extern int grsec_enable_chroot_execlog;
68292+extern int grsec_enable_chroot_caps;
68293+extern int grsec_enable_chroot_sysctl;
68294+extern int grsec_enable_chroot_unix;
68295+extern int grsec_enable_symlinkown;
68296+extern kgid_t grsec_symlinkown_gid;
68297+extern int grsec_enable_tpe;
68298+extern kgid_t grsec_tpe_gid;
68299+extern int grsec_enable_tpe_all;
68300+extern int grsec_enable_tpe_invert;
68301+extern int grsec_enable_socket_all;
68302+extern kgid_t grsec_socket_all_gid;
68303+extern int grsec_enable_socket_client;
68304+extern kgid_t grsec_socket_client_gid;
68305+extern int grsec_enable_socket_server;
68306+extern kgid_t grsec_socket_server_gid;
68307+extern kgid_t grsec_audit_gid;
68308+extern int grsec_enable_group;
68309+extern int grsec_enable_audit_textrel;
68310+extern int grsec_enable_log_rwxmaps;
68311+extern int grsec_enable_mount;
68312+extern int grsec_enable_chdir;
68313+extern int grsec_resource_logging;
68314+extern int grsec_enable_blackhole;
68315+extern int grsec_lastack_retries;
68316+extern int grsec_enable_brute;
68317+extern int grsec_lock;
68318+
68319+extern spinlock_t grsec_alert_lock;
68320+extern unsigned long grsec_alert_wtime;
68321+extern unsigned long grsec_alert_fyet;
68322+
68323+extern spinlock_t grsec_audit_lock;
68324+
68325+extern rwlock_t grsec_exec_file_lock;
68326+
68327+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
68328+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
68329+ (tsk)->exec_file->f_vfsmnt) : "/")
68330+
68331+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
68332+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
68333+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68334+
68335+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
68336+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
68337+ (tsk)->exec_file->f_vfsmnt) : "/")
68338+
68339+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
68340+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
68341+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68342+
68343+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
68344+
68345+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
68346+
68347+#define GR_CHROOT_CAPS {{ \
68348+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
68349+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
68350+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
68351+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
68352+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
68353+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
68354+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
68355+
68356+#define security_learn(normal_msg,args...) \
68357+({ \
68358+ read_lock(&grsec_exec_file_lock); \
68359+ gr_add_learn_entry(normal_msg "\n", ## args); \
68360+ read_unlock(&grsec_exec_file_lock); \
68361+})
68362+
68363+enum {
68364+ GR_DO_AUDIT,
68365+ GR_DONT_AUDIT,
68366+ /* used for non-audit messages that we shouldn't kill the task on */
68367+ GR_DONT_AUDIT_GOOD
68368+};
68369+
68370+enum {
68371+ GR_TTYSNIFF,
68372+ GR_RBAC,
68373+ GR_RBAC_STR,
68374+ GR_STR_RBAC,
68375+ GR_RBAC_MODE2,
68376+ GR_RBAC_MODE3,
68377+ GR_FILENAME,
68378+ GR_SYSCTL_HIDDEN,
68379+ GR_NOARGS,
68380+ GR_ONE_INT,
68381+ GR_ONE_INT_TWO_STR,
68382+ GR_ONE_STR,
68383+ GR_STR_INT,
68384+ GR_TWO_STR_INT,
68385+ GR_TWO_INT,
68386+ GR_TWO_U64,
68387+ GR_THREE_INT,
68388+ GR_FIVE_INT_TWO_STR,
68389+ GR_TWO_STR,
68390+ GR_THREE_STR,
68391+ GR_FOUR_STR,
68392+ GR_STR_FILENAME,
68393+ GR_FILENAME_STR,
68394+ GR_FILENAME_TWO_INT,
68395+ GR_FILENAME_TWO_INT_STR,
68396+ GR_TEXTREL,
68397+ GR_PTRACE,
68398+ GR_RESOURCE,
68399+ GR_CAP,
68400+ GR_SIG,
68401+ GR_SIG2,
68402+ GR_CRASH1,
68403+ GR_CRASH2,
68404+ GR_PSACCT,
68405+ GR_RWXMAP
68406+};
68407+
68408+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
68409+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
68410+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
68411+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
68412+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
68413+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
68414+#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)
68415+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
68416+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
68417+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
68418+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
68419+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
68420+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
68421+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
68422+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
68423+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
68424+#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)
68425+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
68426+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
68427+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
68428+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
68429+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
68430+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
68431+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
68432+#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)
68433+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
68434+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
68435+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
68436+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
68437+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
68438+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
68439+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
68440+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
68441+#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)
68442+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
68443+
68444+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
68445+
68446+#endif
68447+
68448+#endif
68449diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
68450new file mode 100644
68451index 0000000..2bd4c8d
68452--- /dev/null
68453+++ b/include/linux/grmsg.h
68454@@ -0,0 +1,111 @@
68455+#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"
68456+#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"
68457+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
68458+#define GR_STOPMOD_MSG "denied modification of module state by "
68459+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
68460+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
68461+#define GR_IOPERM_MSG "denied use of ioperm() by "
68462+#define GR_IOPL_MSG "denied use of iopl() by "
68463+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
68464+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
68465+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
68466+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
68467+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
68468+#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"
68469+#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"
68470+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
68471+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
68472+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
68473+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
68474+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
68475+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
68476+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
68477+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
68478+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
68479+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
68480+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
68481+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
68482+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
68483+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
68484+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
68485+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
68486+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
68487+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
68488+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
68489+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
68490+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
68491+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
68492+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
68493+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
68494+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
68495+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
68496+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
68497+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
68498+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
68499+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
68500+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
68501+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
68502+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
68503+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
68504+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
68505+#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"
68506+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
68507+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
68508+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
68509+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
68510+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
68511+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
68512+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
68513+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
68514+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
68515+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
68516+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
68517+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
68518+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
68519+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
68520+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
68521+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
68522+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
68523+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
68524+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
68525+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
68526+#define GR_FAILFORK_MSG "failed fork with errno %s by "
68527+#define GR_NICE_CHROOT_MSG "denied priority change by "
68528+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
68529+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
68530+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
68531+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
68532+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
68533+#define GR_TIME_MSG "time set by "
68534+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
68535+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
68536+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
68537+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
68538+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
68539+#define GR_BIND_MSG "denied bind() by "
68540+#define GR_CONNECT_MSG "denied connect() by "
68541+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
68542+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
68543+#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"
68544+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
68545+#define GR_CAP_ACL_MSG "use of %s denied for "
68546+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
68547+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
68548+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
68549+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
68550+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
68551+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
68552+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
68553+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
68554+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
68555+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
68556+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
68557+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
68558+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
68559+#define GR_VM86_MSG "denied use of vm86 by "
68560+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
68561+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
68562+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
68563+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
68564+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
68565+#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 "
68566diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
68567new file mode 100644
68568index 0000000..8da63a4
68569--- /dev/null
68570+++ b/include/linux/grsecurity.h
68571@@ -0,0 +1,242 @@
68572+#ifndef GR_SECURITY_H
68573+#define GR_SECURITY_H
68574+#include <linux/fs.h>
68575+#include <linux/fs_struct.h>
68576+#include <linux/binfmts.h>
68577+#include <linux/gracl.h>
68578+
68579+/* notify of brain-dead configs */
68580+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68581+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
68582+#endif
68583+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
68584+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
68585+#endif
68586+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
68587+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
68588+#endif
68589+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
68590+#error "CONFIG_PAX enabled, but no PaX options are enabled."
68591+#endif
68592+
68593+void gr_handle_brute_attach(unsigned long mm_flags);
68594+void gr_handle_brute_check(void);
68595+void gr_handle_kernel_exploit(void);
68596+int gr_process_user_ban(void);
68597+
68598+char gr_roletype_to_char(void);
68599+
68600+int gr_acl_enable_at_secure(void);
68601+
68602+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
68603+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
68604+
68605+void gr_del_task_from_ip_table(struct task_struct *p);
68606+
68607+int gr_pid_is_chrooted(struct task_struct *p);
68608+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
68609+int gr_handle_chroot_nice(void);
68610+int gr_handle_chroot_sysctl(const int op);
68611+int gr_handle_chroot_setpriority(struct task_struct *p,
68612+ const int niceval);
68613+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
68614+int gr_handle_chroot_chroot(const struct dentry *dentry,
68615+ const struct vfsmount *mnt);
68616+void gr_handle_chroot_chdir(struct path *path);
68617+int gr_handle_chroot_chmod(const struct dentry *dentry,
68618+ const struct vfsmount *mnt, const int mode);
68619+int gr_handle_chroot_mknod(const struct dentry *dentry,
68620+ const struct vfsmount *mnt, const int mode);
68621+int gr_handle_chroot_mount(const struct dentry *dentry,
68622+ const struct vfsmount *mnt,
68623+ const char *dev_name);
68624+int gr_handle_chroot_pivot(void);
68625+int gr_handle_chroot_unix(const pid_t pid);
68626+
68627+int gr_handle_rawio(const struct inode *inode);
68628+
68629+void gr_handle_ioperm(void);
68630+void gr_handle_iopl(void);
68631+
68632+umode_t gr_acl_umask(void);
68633+
68634+int gr_tpe_allow(const struct file *file);
68635+
68636+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
68637+void gr_clear_chroot_entries(struct task_struct *task);
68638+
68639+void gr_log_forkfail(const int retval);
68640+void gr_log_timechange(void);
68641+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
68642+void gr_log_chdir(const struct dentry *dentry,
68643+ const struct vfsmount *mnt);
68644+void gr_log_chroot_exec(const struct dentry *dentry,
68645+ const struct vfsmount *mnt);
68646+void gr_log_remount(const char *devname, const int retval);
68647+void gr_log_unmount(const char *devname, const int retval);
68648+void gr_log_mount(const char *from, const char *to, const int retval);
68649+void gr_log_textrel(struct vm_area_struct *vma);
68650+void gr_log_rwxmmap(struct file *file);
68651+void gr_log_rwxmprotect(struct file *file);
68652+
68653+int gr_handle_follow_link(const struct inode *parent,
68654+ const struct inode *inode,
68655+ const struct dentry *dentry,
68656+ const struct vfsmount *mnt);
68657+int gr_handle_fifo(const struct dentry *dentry,
68658+ const struct vfsmount *mnt,
68659+ const struct dentry *dir, const int flag,
68660+ const int acc_mode);
68661+int gr_handle_hardlink(const struct dentry *dentry,
68662+ const struct vfsmount *mnt,
68663+ struct inode *inode,
68664+ const int mode, const struct filename *to);
68665+
68666+int gr_is_capable(const int cap);
68667+int gr_is_capable_nolog(const int cap);
68668+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68669+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
68670+
68671+void gr_copy_label(struct task_struct *tsk);
68672+void gr_handle_crash(struct task_struct *task, const int sig);
68673+int gr_handle_signal(const struct task_struct *p, const int sig);
68674+int gr_check_crash_uid(const kuid_t uid);
68675+int gr_check_protected_task(const struct task_struct *task);
68676+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
68677+int gr_acl_handle_mmap(const struct file *file,
68678+ const unsigned long prot);
68679+int gr_acl_handle_mprotect(const struct file *file,
68680+ const unsigned long prot);
68681+int gr_check_hidden_task(const struct task_struct *tsk);
68682+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68683+ const struct vfsmount *mnt);
68684+__u32 gr_acl_handle_utime(const struct dentry *dentry,
68685+ const struct vfsmount *mnt);
68686+__u32 gr_acl_handle_access(const struct dentry *dentry,
68687+ const struct vfsmount *mnt, const int fmode);
68688+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68689+ const struct vfsmount *mnt, umode_t *mode);
68690+__u32 gr_acl_handle_chown(const struct dentry *dentry,
68691+ const struct vfsmount *mnt);
68692+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68693+ const struct vfsmount *mnt);
68694+int gr_handle_ptrace(struct task_struct *task, const long request);
68695+int gr_handle_proc_ptrace(struct task_struct *task);
68696+__u32 gr_acl_handle_execve(const struct dentry *dentry,
68697+ const struct vfsmount *mnt);
68698+int gr_check_crash_exec(const struct file *filp);
68699+int gr_acl_is_enabled(void);
68700+void gr_set_kernel_label(struct task_struct *task);
68701+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68702+ const kgid_t gid);
68703+int gr_set_proc_label(const struct dentry *dentry,
68704+ const struct vfsmount *mnt,
68705+ const int unsafe_flags);
68706+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68707+ const struct vfsmount *mnt);
68708+__u32 gr_acl_handle_open(const struct dentry *dentry,
68709+ const struct vfsmount *mnt, int acc_mode);
68710+__u32 gr_acl_handle_creat(const struct dentry *dentry,
68711+ const struct dentry *p_dentry,
68712+ const struct vfsmount *p_mnt,
68713+ int open_flags, int acc_mode, const int imode);
68714+void gr_handle_create(const struct dentry *dentry,
68715+ const struct vfsmount *mnt);
68716+void gr_handle_proc_create(const struct dentry *dentry,
68717+ const struct inode *inode);
68718+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68719+ const struct dentry *parent_dentry,
68720+ const struct vfsmount *parent_mnt,
68721+ const int mode);
68722+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68723+ const struct dentry *parent_dentry,
68724+ const struct vfsmount *parent_mnt);
68725+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68726+ const struct vfsmount *mnt);
68727+void gr_handle_delete(const ino_t ino, const dev_t dev);
68728+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68729+ const struct vfsmount *mnt);
68730+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68731+ const struct dentry *parent_dentry,
68732+ const struct vfsmount *parent_mnt,
68733+ const struct filename *from);
68734+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68735+ const struct dentry *parent_dentry,
68736+ const struct vfsmount *parent_mnt,
68737+ const struct dentry *old_dentry,
68738+ const struct vfsmount *old_mnt, const struct filename *to);
68739+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68740+int gr_acl_handle_rename(struct dentry *new_dentry,
68741+ struct dentry *parent_dentry,
68742+ const struct vfsmount *parent_mnt,
68743+ struct dentry *old_dentry,
68744+ struct inode *old_parent_inode,
68745+ struct vfsmount *old_mnt, const struct filename *newname);
68746+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68747+ struct dentry *old_dentry,
68748+ struct dentry *new_dentry,
68749+ struct vfsmount *mnt, const __u8 replace);
68750+__u32 gr_check_link(const struct dentry *new_dentry,
68751+ const struct dentry *parent_dentry,
68752+ const struct vfsmount *parent_mnt,
68753+ const struct dentry *old_dentry,
68754+ const struct vfsmount *old_mnt);
68755+int gr_acl_handle_filldir(const struct file *file, const char *name,
68756+ const unsigned int namelen, const ino_t ino);
68757+
68758+__u32 gr_acl_handle_unix(const struct dentry *dentry,
68759+ const struct vfsmount *mnt);
68760+void gr_acl_handle_exit(void);
68761+void gr_acl_handle_psacct(struct task_struct *task, const long code);
68762+int gr_acl_handle_procpidmem(const struct task_struct *task);
68763+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68764+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68765+void gr_audit_ptrace(struct task_struct *task);
68766+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68767+void gr_put_exec_file(struct task_struct *task);
68768+
68769+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68770+
68771+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68772+extern void gr_learn_resource(const struct task_struct *task, const int res,
68773+ const unsigned long wanted, const int gt);
68774+#else
68775+static inline void gr_learn_resource(const struct task_struct *task, const int res,
68776+ const unsigned long wanted, const int gt)
68777+{
68778+}
68779+#endif
68780+
68781+#ifdef CONFIG_GRKERNSEC_RESLOG
68782+extern void gr_log_resource(const struct task_struct *task, const int res,
68783+ const unsigned long wanted, const int gt);
68784+#else
68785+static inline void gr_log_resource(const struct task_struct *task, const int res,
68786+ const unsigned long wanted, const int gt)
68787+{
68788+}
68789+#endif
68790+
68791+#ifdef CONFIG_GRKERNSEC
68792+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68793+void gr_handle_vm86(void);
68794+void gr_handle_mem_readwrite(u64 from, u64 to);
68795+
68796+void gr_log_badprocpid(const char *entry);
68797+
68798+extern int grsec_enable_dmesg;
68799+extern int grsec_disable_privio;
68800+
68801+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68802+extern kgid_t grsec_proc_gid;
68803+#endif
68804+
68805+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68806+extern int grsec_enable_chroot_findtask;
68807+#endif
68808+#ifdef CONFIG_GRKERNSEC_SETXID
68809+extern int grsec_enable_setxid;
68810+#endif
68811+#endif
68812+
68813+#endif
68814diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68815new file mode 100644
68816index 0000000..e7ffaaf
68817--- /dev/null
68818+++ b/include/linux/grsock.h
68819@@ -0,0 +1,19 @@
68820+#ifndef __GRSOCK_H
68821+#define __GRSOCK_H
68822+
68823+extern void gr_attach_curr_ip(const struct sock *sk);
68824+extern int gr_handle_sock_all(const int family, const int type,
68825+ const int protocol);
68826+extern int gr_handle_sock_server(const struct sockaddr *sck);
68827+extern int gr_handle_sock_server_other(const struct sock *sck);
68828+extern int gr_handle_sock_client(const struct sockaddr *sck);
68829+extern int gr_search_connect(struct socket * sock,
68830+ struct sockaddr_in * addr);
68831+extern int gr_search_bind(struct socket * sock,
68832+ struct sockaddr_in * addr);
68833+extern int gr_search_listen(struct socket * sock);
68834+extern int gr_search_accept(struct socket * sock);
68835+extern int gr_search_socket(const int domain, const int type,
68836+ const int protocol);
68837+
68838+#endif
68839diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68840index ef788b5..ac41b7b 100644
68841--- a/include/linux/highmem.h
68842+++ b/include/linux/highmem.h
68843@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68844 kunmap_atomic(kaddr);
68845 }
68846
68847+static inline void sanitize_highpage(struct page *page)
68848+{
68849+ void *kaddr;
68850+ unsigned long flags;
68851+
68852+ local_irq_save(flags);
68853+ kaddr = kmap_atomic(page);
68854+ clear_page(kaddr);
68855+ kunmap_atomic(kaddr);
68856+ local_irq_restore(flags);
68857+}
68858+
68859 static inline void zero_user_segments(struct page *page,
68860 unsigned start1, unsigned end1,
68861 unsigned start2, unsigned end2)
68862diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68863index 1c7b89a..7f52502 100644
68864--- a/include/linux/hwmon-sysfs.h
68865+++ b/include/linux/hwmon-sysfs.h
68866@@ -25,7 +25,8 @@
68867 struct sensor_device_attribute{
68868 struct device_attribute dev_attr;
68869 int index;
68870-};
68871+} __do_const;
68872+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68873 #define to_sensor_dev_attr(_dev_attr) \
68874 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68875
68876@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68877 struct device_attribute dev_attr;
68878 u8 index;
68879 u8 nr;
68880-};
68881+} __do_const;
68882 #define to_sensor_dev_attr_2(_dev_attr) \
68883 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68884
68885diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68886index d0c4db7..61b3577 100644
68887--- a/include/linux/i2c.h
68888+++ b/include/linux/i2c.h
68889@@ -369,6 +369,7 @@ struct i2c_algorithm {
68890 /* To determine what the adapter supports */
68891 u32 (*functionality) (struct i2c_adapter *);
68892 };
68893+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68894
68895 /*
68896 * i2c_adapter is the structure used to identify a physical i2c bus along
68897diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68898index d23c3c2..eb63c81 100644
68899--- a/include/linux/i2o.h
68900+++ b/include/linux/i2o.h
68901@@ -565,7 +565,7 @@ struct i2o_controller {
68902 struct i2o_device *exec; /* Executive */
68903 #if BITS_PER_LONG == 64
68904 spinlock_t context_list_lock; /* lock for context_list */
68905- atomic_t context_list_counter; /* needed for unique contexts */
68906+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68907 struct list_head context_list; /* list of context id's
68908 and pointers */
68909 #endif
68910diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68911index aff7ad8..3942bbd 100644
68912--- a/include/linux/if_pppox.h
68913+++ b/include/linux/if_pppox.h
68914@@ -76,7 +76,7 @@ struct pppox_proto {
68915 int (*ioctl)(struct socket *sock, unsigned int cmd,
68916 unsigned long arg);
68917 struct module *owner;
68918-};
68919+} __do_const;
68920
68921 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68922 extern void unregister_pppox_proto(int proto_num);
68923diff --git a/include/linux/init.h b/include/linux/init.h
68924index 10ed4f4..8e8490d 100644
68925--- a/include/linux/init.h
68926+++ b/include/linux/init.h
68927@@ -39,9 +39,36 @@
68928 * Also note, that this data cannot be "const".
68929 */
68930
68931+#ifdef MODULE
68932+#define add_init_latent_entropy
68933+#define add_devinit_latent_entropy
68934+#define add_cpuinit_latent_entropy
68935+#define add_meminit_latent_entropy
68936+#else
68937+#define add_init_latent_entropy __latent_entropy
68938+
68939+#ifdef CONFIG_HOTPLUG
68940+#define add_devinit_latent_entropy
68941+#else
68942+#define add_devinit_latent_entropy __latent_entropy
68943+#endif
68944+
68945+#ifdef CONFIG_HOTPLUG_CPU
68946+#define add_cpuinit_latent_entropy
68947+#else
68948+#define add_cpuinit_latent_entropy __latent_entropy
68949+#endif
68950+
68951+#ifdef CONFIG_MEMORY_HOTPLUG
68952+#define add_meminit_latent_entropy
68953+#else
68954+#define add_meminit_latent_entropy __latent_entropy
68955+#endif
68956+#endif
68957+
68958 /* These are for everybody (although not all archs will actually
68959 discard it in modules) */
68960-#define __init __section(.init.text) __cold notrace
68961+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68962 #define __initdata __section(.init.data)
68963 #define __initconst __constsection(.init.rodata)
68964 #define __exitdata __section(.exit.data)
68965@@ -94,7 +121,7 @@
68966 #define __exit __section(.exit.text) __exitused __cold notrace
68967
68968 /* Used for HOTPLUG_CPU */
68969-#define __cpuinit __section(.cpuinit.text) __cold notrace
68970+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68971 #define __cpuinitdata __section(.cpuinit.data)
68972 #define __cpuinitconst __constsection(.cpuinit.rodata)
68973 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68974@@ -102,7 +129,7 @@
68975 #define __cpuexitconst __constsection(.cpuexit.rodata)
68976
68977 /* Used for MEMORY_HOTPLUG */
68978-#define __meminit __section(.meminit.text) __cold notrace
68979+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68980 #define __meminitdata __section(.meminit.data)
68981 #define __meminitconst __constsection(.meminit.rodata)
68982 #define __memexit __section(.memexit.text) __exitused __cold notrace
68983diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68984index 6d087c5..401cab8 100644
68985--- a/include/linux/init_task.h
68986+++ b/include/linux/init_task.h
68987@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68988
68989 #define INIT_TASK_COMM "swapper"
68990
68991+#ifdef CONFIG_X86
68992+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68993+#else
68994+#define INIT_TASK_THREAD_INFO
68995+#endif
68996+
68997 /*
68998 * INIT_TASK is used to set up the first task table, touch at
68999 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69000@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
69001 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69002 .comm = INIT_TASK_COMM, \
69003 .thread = INIT_THREAD, \
69004+ INIT_TASK_THREAD_INFO \
69005 .fs = &init_fs, \
69006 .files = &init_files, \
69007 .signal = &init_signals, \
69008diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69009index 5fa5afe..ac55b25 100644
69010--- a/include/linux/interrupt.h
69011+++ b/include/linux/interrupt.h
69012@@ -430,7 +430,7 @@ enum
69013 /* map softirq index to softirq name. update 'softirq_to_name' in
69014 * kernel/softirq.c when adding a new softirq.
69015 */
69016-extern char *softirq_to_name[NR_SOFTIRQS];
69017+extern const char * const softirq_to_name[NR_SOFTIRQS];
69018
69019 /* softirq mask and active fields moved to irq_cpustat_t in
69020 * asm/hardirq.h to get better cache usage. KAO
69021@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69022
69023 struct softirq_action
69024 {
69025- void (*action)(struct softirq_action *);
69026-};
69027+ void (*action)(void);
69028+} __no_const;
69029
69030 asmlinkage void do_softirq(void);
69031 asmlinkage void __do_softirq(void);
69032-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69033+extern void open_softirq(int nr, void (*action)(void));
69034 extern void softirq_init(void);
69035 extern void __raise_softirq_irqoff(unsigned int nr);
69036
69037diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69038index f3b99e1..9b73cee 100644
69039--- a/include/linux/iommu.h
69040+++ b/include/linux/iommu.h
69041@@ -101,7 +101,7 @@ struct iommu_ops {
69042 int (*domain_set_attr)(struct iommu_domain *domain,
69043 enum iommu_attr attr, void *data);
69044 unsigned long pgsize_bitmap;
69045-};
69046+} __do_const;
69047
69048 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
69049 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
69050diff --git a/include/linux/irq.h b/include/linux/irq.h
69051index fdf2c4a..5332486 100644
69052--- a/include/linux/irq.h
69053+++ b/include/linux/irq.h
69054@@ -328,7 +328,8 @@ struct irq_chip {
69055 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
69056
69057 unsigned long flags;
69058-};
69059+} __do_const;
69060+typedef struct irq_chip __no_const irq_chip_no_const;
69061
69062 /*
69063 * irq_chip specific flags
69064diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
69065index 6883e19..06992b1 100644
69066--- a/include/linux/kallsyms.h
69067+++ b/include/linux/kallsyms.h
69068@@ -15,7 +15,8 @@
69069
69070 struct module;
69071
69072-#ifdef CONFIG_KALLSYMS
69073+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
69074+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69075 /* Lookup the address for a symbol. Returns 0 if not found. */
69076 unsigned long kallsyms_lookup_name(const char *name);
69077
69078@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
69079 /* Stupid that this does nothing, but I didn't create this mess. */
69080 #define __print_symbol(fmt, addr)
69081 #endif /*CONFIG_KALLSYMS*/
69082+#else /* when included by kallsyms.c, vsnprintf.c, or
69083+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
69084+extern void __print_symbol(const char *fmt, unsigned long address);
69085+extern int sprint_backtrace(char *buffer, unsigned long address);
69086+extern int sprint_symbol(char *buffer, unsigned long address);
69087+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
69088+const char *kallsyms_lookup(unsigned long addr,
69089+ unsigned long *symbolsize,
69090+ unsigned long *offset,
69091+ char **modname, char *namebuf);
69092+#endif
69093
69094 /* This macro allows us to keep printk typechecking */
69095 static __printf(1, 2)
69096diff --git a/include/linux/key-type.h b/include/linux/key-type.h
69097index 518a53a..5e28358 100644
69098--- a/include/linux/key-type.h
69099+++ b/include/linux/key-type.h
69100@@ -125,7 +125,7 @@ struct key_type {
69101 /* internal fields */
69102 struct list_head link; /* link in types list */
69103 struct lock_class_key lock_class; /* key->sem lock class */
69104-};
69105+} __do_const;
69106
69107 extern struct key_type key_type_keyring;
69108
69109diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
69110index 4dff0c6..1ca9b72 100644
69111--- a/include/linux/kgdb.h
69112+++ b/include/linux/kgdb.h
69113@@ -53,7 +53,7 @@ extern int kgdb_connected;
69114 extern int kgdb_io_module_registered;
69115
69116 extern atomic_t kgdb_setting_breakpoint;
69117-extern atomic_t kgdb_cpu_doing_single_step;
69118+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
69119
69120 extern struct task_struct *kgdb_usethread;
69121 extern struct task_struct *kgdb_contthread;
69122@@ -255,7 +255,7 @@ struct kgdb_arch {
69123 void (*correct_hw_break)(void);
69124
69125 void (*enable_nmi)(bool on);
69126-};
69127+} __do_const;
69128
69129 /**
69130 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
69131@@ -280,7 +280,7 @@ struct kgdb_io {
69132 void (*pre_exception) (void);
69133 void (*post_exception) (void);
69134 int is_console;
69135-};
69136+} __do_const;
69137
69138 extern struct kgdb_arch arch_kgdb_ops;
69139
69140diff --git a/include/linux/kmod.h b/include/linux/kmod.h
69141index 5398d58..5883a34 100644
69142--- a/include/linux/kmod.h
69143+++ b/include/linux/kmod.h
69144@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
69145 * usually useless though. */
69146 extern __printf(2, 3)
69147 int __request_module(bool wait, const char *name, ...);
69148+extern __printf(3, 4)
69149+int ___request_module(bool wait, char *param_name, const char *name, ...);
69150 #define request_module(mod...) __request_module(true, mod)
69151 #define request_module_nowait(mod...) __request_module(false, mod)
69152 #define try_then_request_module(x, mod...) \
69153diff --git a/include/linux/kobject.h b/include/linux/kobject.h
69154index 939b112..ed6ed51 100644
69155--- a/include/linux/kobject.h
69156+++ b/include/linux/kobject.h
69157@@ -111,7 +111,7 @@ struct kobj_type {
69158 struct attribute **default_attrs;
69159 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
69160 const void *(*namespace)(struct kobject *kobj);
69161-};
69162+} __do_const;
69163
69164 struct kobj_uevent_env {
69165 char *envp[UEVENT_NUM_ENVP];
69166@@ -134,6 +134,7 @@ struct kobj_attribute {
69167 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
69168 const char *buf, size_t count);
69169 };
69170+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
69171
69172 extern const struct sysfs_ops kobj_sysfs_ops;
69173
69174diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
69175index f66b065..c2c29b4 100644
69176--- a/include/linux/kobject_ns.h
69177+++ b/include/linux/kobject_ns.h
69178@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
69179 const void *(*netlink_ns)(struct sock *sk);
69180 const void *(*initial_ns)(void);
69181 void (*drop_ns)(void *);
69182-};
69183+} __do_const;
69184
69185 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
69186 int kobj_ns_type_registered(enum kobj_ns_type type);
69187diff --git a/include/linux/kref.h b/include/linux/kref.h
69188index 4972e6e..de4d19b 100644
69189--- a/include/linux/kref.h
69190+++ b/include/linux/kref.h
69191@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
69192 static inline int kref_sub(struct kref *kref, unsigned int count,
69193 void (*release)(struct kref *kref))
69194 {
69195- WARN_ON(release == NULL);
69196+ BUG_ON(release == NULL);
69197
69198 if (atomic_sub_and_test((int) count, &kref->refcount)) {
69199 release(kref);
69200diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
69201index 2c497ab..afe32f5 100644
69202--- a/include/linux/kvm_host.h
69203+++ b/include/linux/kvm_host.h
69204@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
69205 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
69206 void vcpu_put(struct kvm_vcpu *vcpu);
69207
69208-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69209+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69210 struct module *module);
69211 void kvm_exit(void);
69212
69213@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
69214 struct kvm_guest_debug *dbg);
69215 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
69216
69217-int kvm_arch_init(void *opaque);
69218+int kvm_arch_init(const void *opaque);
69219 void kvm_arch_exit(void);
69220
69221 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
69222diff --git a/include/linux/libata.h b/include/linux/libata.h
69223index 649e5f8..ead5194 100644
69224--- a/include/linux/libata.h
69225+++ b/include/linux/libata.h
69226@@ -915,7 +915,7 @@ struct ata_port_operations {
69227 * fields must be pointers.
69228 */
69229 const struct ata_port_operations *inherits;
69230-};
69231+} __do_const;
69232
69233 struct ata_port_info {
69234 unsigned long flags;
69235diff --git a/include/linux/list.h b/include/linux/list.h
69236index cc6d2aa..c10ee83 100644
69237--- a/include/linux/list.h
69238+++ b/include/linux/list.h
69239@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
69240 extern void list_del(struct list_head *entry);
69241 #endif
69242
69243+extern void __pax_list_add(struct list_head *new,
69244+ struct list_head *prev,
69245+ struct list_head *next);
69246+static inline void pax_list_add(struct list_head *new, struct list_head *head)
69247+{
69248+ __pax_list_add(new, head, head->next);
69249+}
69250+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
69251+{
69252+ __pax_list_add(new, head->prev, head);
69253+}
69254+extern void pax_list_del(struct list_head *entry);
69255+
69256 /**
69257 * list_replace - replace old entry by new one
69258 * @old : the element to be replaced
69259@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
69260 INIT_LIST_HEAD(entry);
69261 }
69262
69263+extern void pax_list_del_init(struct list_head *entry);
69264+
69265 /**
69266 * list_move - delete from one list and add as another's head
69267 * @list: the entry to move
69268diff --git a/include/linux/math64.h b/include/linux/math64.h
69269index b8ba855..0148090 100644
69270--- a/include/linux/math64.h
69271+++ b/include/linux/math64.h
69272@@ -14,7 +14,7 @@
69273 * This is commonly provided by 32bit archs to provide an optimized 64bit
69274 * divide.
69275 */
69276-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69277+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69278 {
69279 *remainder = dividend % divisor;
69280 return dividend / divisor;
69281@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
69282 #define div64_long(x,y) div_s64((x),(y))
69283
69284 #ifndef div_u64_rem
69285-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69286+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69287 {
69288 *remainder = do_div(dividend, divisor);
69289 return dividend;
69290@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
69291 * divide.
69292 */
69293 #ifndef div_u64
69294-static inline u64 div_u64(u64 dividend, u32 divisor)
69295+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
69296 {
69297 u32 remainder;
69298 return div_u64_rem(dividend, divisor, &remainder);
69299diff --git a/include/linux/mm.h b/include/linux/mm.h
69300index 66e2f7c..a398fb2 100644
69301--- a/include/linux/mm.h
69302+++ b/include/linux/mm.h
69303@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
69304 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
69305 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
69306 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
69307+
69308+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69309+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
69310+#endif
69311+
69312 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
69313
69314 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
69315@@ -231,6 +236,7 @@ struct vm_operations_struct {
69316 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
69317 unsigned long size, pgoff_t pgoff);
69318 };
69319+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
69320
69321 struct mmu_gather;
69322 struct inode;
69323@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
69324 int set_page_dirty_lock(struct page *page);
69325 int clear_page_dirty_for_io(struct page *page);
69326
69327-/* Is the vma a continuation of the stack vma above it? */
69328-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
69329-{
69330- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
69331-}
69332-
69333-static inline int stack_guard_page_start(struct vm_area_struct *vma,
69334- unsigned long addr)
69335-{
69336- return (vma->vm_flags & VM_GROWSDOWN) &&
69337- (vma->vm_start == addr) &&
69338- !vma_growsdown(vma->vm_prev, addr);
69339-}
69340-
69341-/* Is the vma a continuation of the stack vma below it? */
69342-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
69343-{
69344- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
69345-}
69346-
69347-static inline int stack_guard_page_end(struct vm_area_struct *vma,
69348- unsigned long addr)
69349-{
69350- return (vma->vm_flags & VM_GROWSUP) &&
69351- (vma->vm_end == addr) &&
69352- !vma_growsup(vma->vm_next, addr);
69353-}
69354-
69355 extern pid_t
69356 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
69357
69358@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
69359 }
69360 #endif
69361
69362+#ifdef CONFIG_MMU
69363+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
69364+#else
69365+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
69366+{
69367+ return __pgprot(0);
69368+}
69369+#endif
69370+
69371 int vma_wants_writenotify(struct vm_area_struct *vma);
69372
69373 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
69374@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
69375 {
69376 return 0;
69377 }
69378+
69379+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
69380+ unsigned long address)
69381+{
69382+ return 0;
69383+}
69384 #else
69385 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69386+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69387 #endif
69388
69389 #ifdef __PAGETABLE_PMD_FOLDED
69390@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
69391 {
69392 return 0;
69393 }
69394+
69395+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
69396+ unsigned long address)
69397+{
69398+ return 0;
69399+}
69400 #else
69401 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
69402+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
69403 #endif
69404
69405 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
69406@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
69407 NULL: pud_offset(pgd, address);
69408 }
69409
69410+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
69411+{
69412+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
69413+ NULL: pud_offset(pgd, address);
69414+}
69415+
69416 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
69417 {
69418 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
69419 NULL: pmd_offset(pud, address);
69420 }
69421+
69422+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
69423+{
69424+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
69425+ NULL: pmd_offset(pud, address);
69426+}
69427 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
69428
69429 #if USE_SPLIT_PTLOCKS
69430@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
69431 unsigned long, unsigned long,
69432 unsigned long, unsigned long);
69433 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
69434+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
69435
69436 /* These take the mm semaphore themselves */
69437 extern unsigned long vm_brk(unsigned long, unsigned long);
69438@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
69439 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
69440 struct vm_area_struct **pprev);
69441
69442+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
69443+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
69444+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
69445+
69446 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
69447 NULL if none. Assume start_addr < end_addr. */
69448 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
69449@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
69450 return vma;
69451 }
69452
69453-#ifdef CONFIG_MMU
69454-pgprot_t vm_get_page_prot(unsigned long vm_flags);
69455-#else
69456-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
69457-{
69458- return __pgprot(0);
69459-}
69460-#endif
69461-
69462 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
69463 unsigned long change_prot_numa(struct vm_area_struct *vma,
69464 unsigned long start, unsigned long end);
69465@@ -1649,6 +1658,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
69466 static inline void vm_stat_account(struct mm_struct *mm,
69467 unsigned long flags, struct file *file, long pages)
69468 {
69469+
69470+#ifdef CONFIG_PAX_RANDMMAP
69471+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
69472+#endif
69473+
69474 mm->total_vm += pages;
69475 }
69476 #endif /* CONFIG_PROC_FS */
69477@@ -1721,7 +1735,7 @@ extern int unpoison_memory(unsigned long pfn);
69478 extern int sysctl_memory_failure_early_kill;
69479 extern int sysctl_memory_failure_recovery;
69480 extern void shake_page(struct page *p, int access);
69481-extern atomic_long_t mce_bad_pages;
69482+extern atomic_long_unchecked_t mce_bad_pages;
69483 extern int soft_offline_page(struct page *page, int flags);
69484
69485 extern void dump_page(struct page *page);
69486@@ -1752,5 +1766,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
69487 static inline bool page_is_guard(struct page *page) { return false; }
69488 #endif /* CONFIG_DEBUG_PAGEALLOC */
69489
69490+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69491+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
69492+#else
69493+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
69494+#endif
69495+
69496 #endif /* __KERNEL__ */
69497 #endif /* _LINUX_MM_H */
69498diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
69499index f8f5162..3aaf20f 100644
69500--- a/include/linux/mm_types.h
69501+++ b/include/linux/mm_types.h
69502@@ -288,6 +288,8 @@ struct vm_area_struct {
69503 #ifdef CONFIG_NUMA
69504 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
69505 #endif
69506+
69507+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
69508 };
69509
69510 struct core_thread {
69511@@ -436,6 +438,24 @@ struct mm_struct {
69512 int first_nid;
69513 #endif
69514 struct uprobes_state uprobes_state;
69515+
69516+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69517+ unsigned long pax_flags;
69518+#endif
69519+
69520+#ifdef CONFIG_PAX_DLRESOLVE
69521+ unsigned long call_dl_resolve;
69522+#endif
69523+
69524+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
69525+ unsigned long call_syscall;
69526+#endif
69527+
69528+#ifdef CONFIG_PAX_ASLR
69529+ unsigned long delta_mmap; /* randomized offset */
69530+ unsigned long delta_stack; /* randomized offset */
69531+#endif
69532+
69533 };
69534
69535 /* first nid will either be a valid NID or one of these values */
69536diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
69537index c5d5278..f0b68c8 100644
69538--- a/include/linux/mmiotrace.h
69539+++ b/include/linux/mmiotrace.h
69540@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
69541 /* Called from ioremap.c */
69542 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
69543 void __iomem *addr);
69544-extern void mmiotrace_iounmap(volatile void __iomem *addr);
69545+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
69546
69547 /* For anyone to insert markers. Remember trailing newline. */
69548 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
69549@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
69550 {
69551 }
69552
69553-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
69554+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
69555 {
69556 }
69557
69558diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
69559index 73b64a3..6562925 100644
69560--- a/include/linux/mmzone.h
69561+++ b/include/linux/mmzone.h
69562@@ -412,7 +412,7 @@ struct zone {
69563 unsigned long flags; /* zone flags, see below */
69564
69565 /* Zone statistics */
69566- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69567+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69568
69569 /*
69570 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
69571diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
69572index fed3def..c933f99 100644
69573--- a/include/linux/mod_devicetable.h
69574+++ b/include/linux/mod_devicetable.h
69575@@ -12,7 +12,7 @@
69576 typedef unsigned long kernel_ulong_t;
69577 #endif
69578
69579-#define PCI_ANY_ID (~0)
69580+#define PCI_ANY_ID ((__u16)~0)
69581
69582 struct pci_device_id {
69583 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
69584@@ -139,7 +139,7 @@ struct usb_device_id {
69585 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
69586 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
69587
69588-#define HID_ANY_ID (~0)
69589+#define HID_ANY_ID (~0U)
69590 #define HID_BUS_ANY 0xffff
69591 #define HID_GROUP_ANY 0x0000
69592
69593@@ -498,7 +498,7 @@ struct dmi_system_id {
69594 const char *ident;
69595 struct dmi_strmatch matches[4];
69596 void *driver_data;
69597-};
69598+} __do_const;
69599 /*
69600 * struct dmi_device_id appears during expansion of
69601 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
69602diff --git a/include/linux/module.h b/include/linux/module.h
69603index 1375ee3..ced8177 100644
69604--- a/include/linux/module.h
69605+++ b/include/linux/module.h
69606@@ -17,9 +17,11 @@
69607 #include <linux/moduleparam.h>
69608 #include <linux/tracepoint.h>
69609 #include <linux/export.h>
69610+#include <linux/fs.h>
69611
69612 #include <linux/percpu.h>
69613 #include <asm/module.h>
69614+#include <asm/pgtable.h>
69615
69616 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
69617 #define MODULE_SIG_STRING "~Module signature appended~\n"
69618@@ -54,12 +56,13 @@ struct module_attribute {
69619 int (*test)(struct module *);
69620 void (*free)(struct module *);
69621 };
69622+typedef struct module_attribute __no_const module_attribute_no_const;
69623
69624 struct module_version_attribute {
69625 struct module_attribute mattr;
69626 const char *module_name;
69627 const char *version;
69628-} __attribute__ ((__aligned__(sizeof(void *))));
69629+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
69630
69631 extern ssize_t __modver_version_show(struct module_attribute *,
69632 struct module_kobject *, char *);
69633@@ -232,7 +235,7 @@ struct module
69634
69635 /* Sysfs stuff. */
69636 struct module_kobject mkobj;
69637- struct module_attribute *modinfo_attrs;
69638+ module_attribute_no_const *modinfo_attrs;
69639 const char *version;
69640 const char *srcversion;
69641 struct kobject *holders_dir;
69642@@ -281,19 +284,16 @@ struct module
69643 int (*init)(void);
69644
69645 /* If this is non-NULL, vfree after init() returns */
69646- void *module_init;
69647+ void *module_init_rx, *module_init_rw;
69648
69649 /* Here is the actual code + data, vfree'd on unload. */
69650- void *module_core;
69651+ void *module_core_rx, *module_core_rw;
69652
69653 /* Here are the sizes of the init and core sections */
69654- unsigned int init_size, core_size;
69655+ unsigned int init_size_rw, core_size_rw;
69656
69657 /* The size of the executable code in each section. */
69658- unsigned int init_text_size, core_text_size;
69659-
69660- /* Size of RO sections of the module (text+rodata) */
69661- unsigned int init_ro_size, core_ro_size;
69662+ unsigned int init_size_rx, core_size_rx;
69663
69664 /* Arch-specific module values */
69665 struct mod_arch_specific arch;
69666@@ -349,6 +349,10 @@ struct module
69667 #ifdef CONFIG_EVENT_TRACING
69668 struct ftrace_event_call **trace_events;
69669 unsigned int num_trace_events;
69670+ struct file_operations trace_id;
69671+ struct file_operations trace_enable;
69672+ struct file_operations trace_format;
69673+ struct file_operations trace_filter;
69674 #endif
69675 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69676 unsigned int num_ftrace_callsites;
69677@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
69678 bool is_module_percpu_address(unsigned long addr);
69679 bool is_module_text_address(unsigned long addr);
69680
69681+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
69682+{
69683+
69684+#ifdef CONFIG_PAX_KERNEXEC
69685+ if (ktla_ktva(addr) >= (unsigned long)start &&
69686+ ktla_ktva(addr) < (unsigned long)start + size)
69687+ return 1;
69688+#endif
69689+
69690+ return ((void *)addr >= start && (void *)addr < start + size);
69691+}
69692+
69693+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
69694+{
69695+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
69696+}
69697+
69698+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
69699+{
69700+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
69701+}
69702+
69703+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
69704+{
69705+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
69706+}
69707+
69708+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
69709+{
69710+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
69711+}
69712+
69713 static inline int within_module_core(unsigned long addr, struct module *mod)
69714 {
69715- return (unsigned long)mod->module_core <= addr &&
69716- addr < (unsigned long)mod->module_core + mod->core_size;
69717+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69718 }
69719
69720 static inline int within_module_init(unsigned long addr, struct module *mod)
69721 {
69722- return (unsigned long)mod->module_init <= addr &&
69723- addr < (unsigned long)mod->module_init + mod->init_size;
69724+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69725 }
69726
69727 /* Search for module by name: must hold module_mutex. */
69728diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69729index 560ca53..5ee8d73 100644
69730--- a/include/linux/moduleloader.h
69731+++ b/include/linux/moduleloader.h
69732@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69733
69734 /* Allocator used for allocating struct module, core sections and init
69735 sections. Returns NULL on failure. */
69736-void *module_alloc(unsigned long size);
69737+void *module_alloc(unsigned long size) __size_overflow(1);
69738+
69739+#ifdef CONFIG_PAX_KERNEXEC
69740+void *module_alloc_exec(unsigned long size) __size_overflow(1);
69741+#else
69742+#define module_alloc_exec(x) module_alloc(x)
69743+#endif
69744
69745 /* Free memory returned from module_alloc. */
69746 void module_free(struct module *mod, void *module_region);
69747
69748+#ifdef CONFIG_PAX_KERNEXEC
69749+void module_free_exec(struct module *mod, void *module_region);
69750+#else
69751+#define module_free_exec(x, y) module_free((x), (y))
69752+#endif
69753+
69754 /*
69755 * Apply the given relocation to the (simplified) ELF. Return -error
69756 * or 0.
69757@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69758 unsigned int relsec,
69759 struct module *me)
69760 {
69761+#ifdef CONFIG_MODULES
69762 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69763+#endif
69764 return -ENOEXEC;
69765 }
69766 #endif
69767@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69768 unsigned int relsec,
69769 struct module *me)
69770 {
69771+#ifdef CONFIG_MODULES
69772 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69773+#endif
69774 return -ENOEXEC;
69775 }
69776 #endif
69777diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69778index 137b419..fe663ec 100644
69779--- a/include/linux/moduleparam.h
69780+++ b/include/linux/moduleparam.h
69781@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69782 * @len is usually just sizeof(string).
69783 */
69784 #define module_param_string(name, string, len, perm) \
69785- static const struct kparam_string __param_string_##name \
69786+ static const struct kparam_string __param_string_##name __used \
69787 = { len, string }; \
69788 __module_param_call(MODULE_PARAM_PREFIX, name, \
69789 &param_ops_string, \
69790@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69791 */
69792 #define module_param_array_named(name, array, type, nump, perm) \
69793 param_check_##type(name, &(array)[0]); \
69794- static const struct kparam_array __param_arr_##name \
69795+ static const struct kparam_array __param_arr_##name __used \
69796 = { .max = ARRAY_SIZE(array), .num = nump, \
69797 .ops = &param_ops_##type, \
69798 .elemsize = sizeof(array[0]), .elem = array }; \
69799diff --git a/include/linux/namei.h b/include/linux/namei.h
69800index 5a5ff57..5ae5070 100644
69801--- a/include/linux/namei.h
69802+++ b/include/linux/namei.h
69803@@ -19,7 +19,7 @@ struct nameidata {
69804 unsigned seq;
69805 int last_type;
69806 unsigned depth;
69807- char *saved_names[MAX_NESTED_LINKS + 1];
69808+ const char *saved_names[MAX_NESTED_LINKS + 1];
69809 };
69810
69811 /*
69812@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69813
69814 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69815
69816-static inline void nd_set_link(struct nameidata *nd, char *path)
69817+static inline void nd_set_link(struct nameidata *nd, const char *path)
69818 {
69819 nd->saved_names[nd->depth] = path;
69820 }
69821
69822-static inline char *nd_get_link(struct nameidata *nd)
69823+static inline const char *nd_get_link(const struct nameidata *nd)
69824 {
69825 return nd->saved_names[nd->depth];
69826 }
69827diff --git a/include/linux/net.h b/include/linux/net.h
69828index aa16731..514b875 100644
69829--- a/include/linux/net.h
69830+++ b/include/linux/net.h
69831@@ -183,7 +183,7 @@ struct net_proto_family {
69832 int (*create)(struct net *net, struct socket *sock,
69833 int protocol, int kern);
69834 struct module *owner;
69835-};
69836+} __do_const;
69837
69838 struct iovec;
69839 struct kvec;
69840diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69841index 9ef07d0..130a5d9 100644
69842--- a/include/linux/netdevice.h
69843+++ b/include/linux/netdevice.h
69844@@ -1012,6 +1012,7 @@ struct net_device_ops {
69845 u32 pid, u32 seq,
69846 struct net_device *dev);
69847 };
69848+typedef struct net_device_ops __no_const net_device_ops_no_const;
69849
69850 /*
69851 * The DEVICE structure.
69852@@ -1078,7 +1079,7 @@ struct net_device {
69853 int iflink;
69854
69855 struct net_device_stats stats;
69856- atomic_long_t rx_dropped; /* dropped packets by core network
69857+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69858 * Do not use this in drivers.
69859 */
69860
69861diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69862index ee14284..bc65d63 100644
69863--- a/include/linux/netfilter.h
69864+++ b/include/linux/netfilter.h
69865@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69866 #endif
69867 /* Use the module struct to lock set/get code in place */
69868 struct module *owner;
69869-};
69870+} __do_const;
69871
69872 /* Function to register/unregister hook points. */
69873 int nf_register_hook(struct nf_hook_ops *reg);
69874diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69875index 7958e84..ed74d7a 100644
69876--- a/include/linux/netfilter/ipset/ip_set.h
69877+++ b/include/linux/netfilter/ipset/ip_set.h
69878@@ -98,7 +98,7 @@ struct ip_set_type_variant {
69879 /* Return true if "b" set is the same as "a"
69880 * according to the create set parameters */
69881 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69882-};
69883+} __do_const;
69884
69885 /* The core set type structure */
69886 struct ip_set_type {
69887diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69888index 4966dde..7d8ce06 100644
69889--- a/include/linux/netfilter/nfnetlink.h
69890+++ b/include/linux/netfilter/nfnetlink.h
69891@@ -16,7 +16,7 @@ struct nfnl_callback {
69892 const struct nlattr * const cda[]);
69893 const struct nla_policy *policy; /* netlink attribute policy */
69894 const u_int16_t attr_count; /* number of nlattr's */
69895-};
69896+} __do_const;
69897
69898 struct nfnetlink_subsystem {
69899 const char *name;
69900diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69901new file mode 100644
69902index 0000000..33f4af8
69903--- /dev/null
69904+++ b/include/linux/netfilter/xt_gradm.h
69905@@ -0,0 +1,9 @@
69906+#ifndef _LINUX_NETFILTER_XT_GRADM_H
69907+#define _LINUX_NETFILTER_XT_GRADM_H 1
69908+
69909+struct xt_gradm_mtinfo {
69910+ __u16 flags;
69911+ __u16 invflags;
69912+};
69913+
69914+#endif
69915diff --git a/include/linux/nls.h b/include/linux/nls.h
69916index 5dc635f..35f5e11 100644
69917--- a/include/linux/nls.h
69918+++ b/include/linux/nls.h
69919@@ -31,7 +31,7 @@ struct nls_table {
69920 const unsigned char *charset2upper;
69921 struct module *owner;
69922 struct nls_table *next;
69923-};
69924+} __do_const;
69925
69926 /* this value hold the maximum octet of charset */
69927 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69928diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69929index d65746e..62e72c2 100644
69930--- a/include/linux/notifier.h
69931+++ b/include/linux/notifier.h
69932@@ -51,7 +51,8 @@ struct notifier_block {
69933 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69934 struct notifier_block __rcu *next;
69935 int priority;
69936-};
69937+} __do_const;
69938+typedef struct notifier_block __no_const notifier_block_no_const;
69939
69940 struct atomic_notifier_head {
69941 spinlock_t lock;
69942diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69943index a4c5624..79d6d88 100644
69944--- a/include/linux/oprofile.h
69945+++ b/include/linux/oprofile.h
69946@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69947 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69948 char const * name, ulong * val);
69949
69950-/** Create a file for read-only access to an atomic_t. */
69951+/** Create a file for read-only access to an atomic_unchecked_t. */
69952 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69953- char const * name, atomic_t * val);
69954+ char const * name, atomic_unchecked_t * val);
69955
69956 /** create a directory */
69957 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69958diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69959index 45fc162..01a4068 100644
69960--- a/include/linux/pci_hotplug.h
69961+++ b/include/linux/pci_hotplug.h
69962@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69963 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69964 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69965 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69966-};
69967+} __do_const;
69968+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69969
69970 /**
69971 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69972diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69973index a280650..2b67b91 100644
69974--- a/include/linux/perf_event.h
69975+++ b/include/linux/perf_event.h
69976@@ -328,8 +328,8 @@ struct perf_event {
69977
69978 enum perf_event_active_state state;
69979 unsigned int attach_state;
69980- local64_t count;
69981- atomic64_t child_count;
69982+ local64_t count; /* PaX: fix it one day */
69983+ atomic64_unchecked_t child_count;
69984
69985 /*
69986 * These are the total time in nanoseconds that the event
69987@@ -380,8 +380,8 @@ struct perf_event {
69988 * These accumulate total time (in nanoseconds) that children
69989 * events have been enabled and running, respectively.
69990 */
69991- atomic64_t child_total_time_enabled;
69992- atomic64_t child_total_time_running;
69993+ atomic64_unchecked_t child_total_time_enabled;
69994+ atomic64_unchecked_t child_total_time_running;
69995
69996 /*
69997 * Protect attach/detach and child_list:
69998@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
69999 */
70000 #define perf_cpu_notifier(fn) \
70001 do { \
70002- static struct notifier_block fn##_nb __cpuinitdata = \
70003+ static struct notifier_block fn##_nb = \
70004 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
70005 unsigned long cpu = smp_processor_id(); \
70006 unsigned long flags; \
70007diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
70008index ad1a427..6419649 100644
70009--- a/include/linux/pipe_fs_i.h
70010+++ b/include/linux/pipe_fs_i.h
70011@@ -45,9 +45,9 @@ struct pipe_buffer {
70012 struct pipe_inode_info {
70013 wait_queue_head_t wait;
70014 unsigned int nrbufs, curbuf, buffers;
70015- unsigned int readers;
70016- unsigned int writers;
70017- unsigned int waiting_writers;
70018+ atomic_t readers;
70019+ atomic_t writers;
70020+ atomic_t waiting_writers;
70021 unsigned int r_counter;
70022 unsigned int w_counter;
70023 struct page *tmp_page;
70024diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
70025index 5f28cae..3d23723 100644
70026--- a/include/linux/platform_data/usb-ehci-s5p.h
70027+++ b/include/linux/platform_data/usb-ehci-s5p.h
70028@@ -14,7 +14,7 @@
70029 struct s5p_ehci_platdata {
70030 int (*phy_init)(struct platform_device *pdev, int type);
70031 int (*phy_exit)(struct platform_device *pdev, int type);
70032-};
70033+} __no_const;
70034
70035 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
70036
70037diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
70038index c256c59..8ea94c7 100644
70039--- a/include/linux/platform_data/usb-exynos.h
70040+++ b/include/linux/platform_data/usb-exynos.h
70041@@ -14,7 +14,7 @@
70042 struct exynos4_ohci_platdata {
70043 int (*phy_init)(struct platform_device *pdev, int type);
70044 int (*phy_exit)(struct platform_device *pdev, int type);
70045-};
70046+} __no_const;
70047
70048 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
70049
70050diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
70051index 7c1d252..c5c773e 100644
70052--- a/include/linux/pm_domain.h
70053+++ b/include/linux/pm_domain.h
70054@@ -48,7 +48,7 @@ struct gpd_dev_ops {
70055
70056 struct gpd_cpu_data {
70057 unsigned int saved_exit_latency;
70058- struct cpuidle_state *idle_state;
70059+ cpuidle_state_no_const *idle_state;
70060 };
70061
70062 struct generic_pm_domain {
70063diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
70064index f271860..6b3bec5 100644
70065--- a/include/linux/pm_runtime.h
70066+++ b/include/linux/pm_runtime.h
70067@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
70068
70069 static inline void pm_runtime_mark_last_busy(struct device *dev)
70070 {
70071- ACCESS_ONCE(dev->power.last_busy) = jiffies;
70072+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
70073 }
70074
70075 #else /* !CONFIG_PM_RUNTIME */
70076diff --git a/include/linux/pnp.h b/include/linux/pnp.h
70077index 195aafc..49a7bc2 100644
70078--- a/include/linux/pnp.h
70079+++ b/include/linux/pnp.h
70080@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
70081 struct pnp_fixup {
70082 char id[7];
70083 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
70084-};
70085+} __do_const;
70086
70087 /* config parameters */
70088 #define PNP_CONFIG_NORMAL 0x0001
70089diff --git a/include/linux/poison.h b/include/linux/poison.h
70090index 2110a81..13a11bb 100644
70091--- a/include/linux/poison.h
70092+++ b/include/linux/poison.h
70093@@ -19,8 +19,8 @@
70094 * under normal circumstances, used to verify that nobody uses
70095 * non-initialized list entries.
70096 */
70097-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
70098-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
70099+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
70100+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
70101
70102 /********** include/linux/timer.h **********/
70103 /*
70104diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
70105index c0f44c2..1572583 100644
70106--- a/include/linux/power/smartreflex.h
70107+++ b/include/linux/power/smartreflex.h
70108@@ -238,7 +238,7 @@ struct omap_sr_class_data {
70109 int (*notify)(struct omap_sr *sr, u32 status);
70110 u8 notify_flags;
70111 u8 class_type;
70112-};
70113+} __do_const;
70114
70115 /**
70116 * struct omap_sr_nvalue_table - Smartreflex n-target value info
70117diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
70118index 4ea1d37..80f4b33 100644
70119--- a/include/linux/ppp-comp.h
70120+++ b/include/linux/ppp-comp.h
70121@@ -84,7 +84,7 @@ struct compressor {
70122 struct module *owner;
70123 /* Extra skb space needed by the compressor algorithm */
70124 unsigned int comp_extra;
70125-};
70126+} __do_const;
70127
70128 /*
70129 * The return value from decompress routine is the length of the
70130diff --git a/include/linux/printk.h b/include/linux/printk.h
70131index 9afc01e..92c32e8 100644
70132--- a/include/linux/printk.h
70133+++ b/include/linux/printk.h
70134@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
70135 extern int printk_needs_cpu(int cpu);
70136 extern void printk_tick(void);
70137
70138+extern int kptr_restrict;
70139+
70140 #ifdef CONFIG_PRINTK
70141 asmlinkage __printf(5, 0)
70142 int vprintk_emit(int facility, int level,
70143@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
70144
70145 extern int printk_delay_msec;
70146 extern int dmesg_restrict;
70147-extern int kptr_restrict;
70148
70149 void log_buf_kexec_setup(void);
70150 void __init setup_log_buf(int early);
70151diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
70152index 32676b3..8f7a182 100644
70153--- a/include/linux/proc_fs.h
70154+++ b/include/linux/proc_fs.h
70155@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
70156 return proc_create_data(name, mode, parent, proc_fops, NULL);
70157 }
70158
70159+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
70160+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
70161+{
70162+#ifdef CONFIG_GRKERNSEC_PROC_USER
70163+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
70164+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70165+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
70166+#else
70167+ return proc_create_data(name, mode, parent, proc_fops, NULL);
70168+#endif
70169+}
70170+
70171 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
70172 umode_t mode, struct proc_dir_entry *base,
70173 read_proc_t *read_proc, void * data)
70174diff --git a/include/linux/random.h b/include/linux/random.h
70175index d984608..d6f0042 100644
70176--- a/include/linux/random.h
70177+++ b/include/linux/random.h
70178@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
70179 u32 prandom_u32_state(struct rnd_state *);
70180 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
70181
70182+static inline unsigned long pax_get_random_long(void)
70183+{
70184+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
70185+}
70186+
70187 /*
70188 * Handle minimum values for seeds
70189 */
70190diff --git a/include/linux/rculist.h b/include/linux/rculist.h
70191index c92dd28..08f4eab 100644
70192--- a/include/linux/rculist.h
70193+++ b/include/linux/rculist.h
70194@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
70195 struct list_head *prev, struct list_head *next);
70196 #endif
70197
70198+extern void __pax_list_add_rcu(struct list_head *new,
70199+ struct list_head *prev, struct list_head *next);
70200+
70201 /**
70202 * list_add_rcu - add a new entry to rcu-protected list
70203 * @new: new entry to be added
70204@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
70205 __list_add_rcu(new, head, head->next);
70206 }
70207
70208+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
70209+{
70210+ __pax_list_add_rcu(new, head, head->next);
70211+}
70212+
70213 /**
70214 * list_add_tail_rcu - add a new entry to rcu-protected list
70215 * @new: new entry to be added
70216@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
70217 __list_add_rcu(new, head->prev, head);
70218 }
70219
70220+static inline void pax_list_add_tail_rcu(struct list_head *new,
70221+ struct list_head *head)
70222+{
70223+ __pax_list_add_rcu(new, head->prev, head);
70224+}
70225+
70226 /**
70227 * list_del_rcu - deletes entry from list without re-initialization
70228 * @entry: the element to delete from the list.
70229@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
70230 entry->prev = LIST_POISON2;
70231 }
70232
70233+extern void pax_list_del_rcu(struct list_head *entry);
70234+
70235 /**
70236 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
70237 * @n: the element to delete from the hash list.
70238diff --git a/include/linux/reboot.h b/include/linux/reboot.h
70239index 23b3630..e1bc12b 100644
70240--- a/include/linux/reboot.h
70241+++ b/include/linux/reboot.h
70242@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
70243 * Architecture-specific implementations of sys_reboot commands.
70244 */
70245
70246-extern void machine_restart(char *cmd);
70247-extern void machine_halt(void);
70248-extern void machine_power_off(void);
70249+extern void machine_restart(char *cmd) __noreturn;
70250+extern void machine_halt(void) __noreturn;
70251+extern void machine_power_off(void) __noreturn;
70252
70253 extern void machine_shutdown(void);
70254 struct pt_regs;
70255@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
70256 */
70257
70258 extern void kernel_restart_prepare(char *cmd);
70259-extern void kernel_restart(char *cmd);
70260-extern void kernel_halt(void);
70261-extern void kernel_power_off(void);
70262+extern void kernel_restart(char *cmd) __noreturn;
70263+extern void kernel_halt(void) __noreturn;
70264+extern void kernel_power_off(void) __noreturn;
70265
70266 extern int C_A_D; /* for sysctl */
70267 void ctrl_alt_del(void);
70268@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
70269 * Emergency restart, callable from an interrupt handler.
70270 */
70271
70272-extern void emergency_restart(void);
70273+extern void emergency_restart(void) __noreturn;
70274 #include <asm/emergency-restart.h>
70275
70276 #endif /* _LINUX_REBOOT_H */
70277diff --git a/include/linux/regset.h b/include/linux/regset.h
70278index 8e0c9fe..ac4d221 100644
70279--- a/include/linux/regset.h
70280+++ b/include/linux/regset.h
70281@@ -161,7 +161,8 @@ struct user_regset {
70282 unsigned int align;
70283 unsigned int bias;
70284 unsigned int core_note_type;
70285-};
70286+} __do_const;
70287+typedef struct user_regset __no_const user_regset_no_const;
70288
70289 /**
70290 * struct user_regset_view - available regsets
70291diff --git a/include/linux/relay.h b/include/linux/relay.h
70292index 91cacc3..b55ff74 100644
70293--- a/include/linux/relay.h
70294+++ b/include/linux/relay.h
70295@@ -160,7 +160,7 @@ struct rchan_callbacks
70296 * The callback should return 0 if successful, negative if not.
70297 */
70298 int (*remove_buf_file)(struct dentry *dentry);
70299-};
70300+} __no_const;
70301
70302 /*
70303 * CONFIG_RELAY kernel API, kernel/relay.c
70304diff --git a/include/linux/rio.h b/include/linux/rio.h
70305index a3e7842..d973ca6 100644
70306--- a/include/linux/rio.h
70307+++ b/include/linux/rio.h
70308@@ -339,7 +339,7 @@ struct rio_ops {
70309 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
70310 u64 rstart, u32 size, u32 flags);
70311 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
70312-};
70313+} __no_const;
70314
70315 #define RIO_RESOURCE_MEM 0x00000100
70316 #define RIO_RESOURCE_DOORBELL 0x00000200
70317diff --git a/include/linux/rmap.h b/include/linux/rmap.h
70318index c20635c..2f5def4 100644
70319--- a/include/linux/rmap.h
70320+++ b/include/linux/rmap.h
70321@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
70322 void anon_vma_init(void); /* create anon_vma_cachep */
70323 int anon_vma_prepare(struct vm_area_struct *);
70324 void unlink_anon_vmas(struct vm_area_struct *);
70325-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
70326-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
70327+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
70328+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
70329
70330 static inline void anon_vma_merge(struct vm_area_struct *vma,
70331 struct vm_area_struct *next)
70332diff --git a/include/linux/sched.h b/include/linux/sched.h
70333index d211247..eac6c2c 100644
70334--- a/include/linux/sched.h
70335+++ b/include/linux/sched.h
70336@@ -61,6 +61,7 @@ struct bio_list;
70337 struct fs_struct;
70338 struct perf_event_context;
70339 struct blk_plug;
70340+struct linux_binprm;
70341
70342 /*
70343 * List of flags we want to share for kernel threads,
70344@@ -327,7 +328,7 @@ extern char __sched_text_start[], __sched_text_end[];
70345 extern int in_sched_functions(unsigned long addr);
70346
70347 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
70348-extern signed long schedule_timeout(signed long timeout);
70349+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
70350 extern signed long schedule_timeout_interruptible(signed long timeout);
70351 extern signed long schedule_timeout_killable(signed long timeout);
70352 extern signed long schedule_timeout_uninterruptible(signed long timeout);
70353@@ -354,10 +355,23 @@ struct user_namespace;
70354 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
70355
70356 extern int sysctl_max_map_count;
70357+extern unsigned long sysctl_heap_stack_gap;
70358
70359 #include <linux/aio.h>
70360
70361 #ifdef CONFIG_MMU
70362+
70363+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
70364+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
70365+#else
70366+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
70367+{
70368+ return 0;
70369+}
70370+#endif
70371+
70372+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
70373+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
70374 extern void arch_pick_mmap_layout(struct mm_struct *mm);
70375 extern unsigned long
70376 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
70377@@ -639,6 +653,17 @@ struct signal_struct {
70378 #ifdef CONFIG_TASKSTATS
70379 struct taskstats *stats;
70380 #endif
70381+
70382+#ifdef CONFIG_GRKERNSEC
70383+ u32 curr_ip;
70384+ u32 saved_ip;
70385+ u32 gr_saddr;
70386+ u32 gr_daddr;
70387+ u16 gr_sport;
70388+ u16 gr_dport;
70389+ u8 used_accept:1;
70390+#endif
70391+
70392 #ifdef CONFIG_AUDIT
70393 unsigned audit_tty;
70394 struct tty_audit_buf *tty_audit_buf;
70395@@ -717,6 +742,11 @@ struct user_struct {
70396 struct key *session_keyring; /* UID's default session keyring */
70397 #endif
70398
70399+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
70400+ unsigned int banned;
70401+ unsigned long ban_expires;
70402+#endif
70403+
70404 /* Hash table maintenance information */
70405 struct hlist_node uidhash_node;
70406 kuid_t uid;
70407@@ -1116,7 +1146,7 @@ struct sched_class {
70408 #ifdef CONFIG_FAIR_GROUP_SCHED
70409 void (*task_move_group) (struct task_struct *p, int on_rq);
70410 #endif
70411-};
70412+} __do_const;
70413
70414 struct load_weight {
70415 unsigned long weight, inv_weight;
70416@@ -1360,8 +1390,8 @@ struct task_struct {
70417 struct list_head thread_group;
70418
70419 struct completion *vfork_done; /* for vfork() */
70420- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
70421- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70422+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
70423+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70424
70425 cputime_t utime, stime, utimescaled, stimescaled;
70426 cputime_t gtime;
70427@@ -1377,11 +1407,6 @@ struct task_struct {
70428 struct task_cputime cputime_expires;
70429 struct list_head cpu_timers[3];
70430
70431-/* process credentials */
70432- const struct cred __rcu *real_cred; /* objective and real subjective task
70433- * credentials (COW) */
70434- const struct cred __rcu *cred; /* effective (overridable) subjective task
70435- * credentials (COW) */
70436 char comm[TASK_COMM_LEN]; /* executable name excluding path
70437 - access with [gs]et_task_comm (which lock
70438 it with task_lock())
70439@@ -1398,6 +1423,10 @@ struct task_struct {
70440 #endif
70441 /* CPU-specific state of this task */
70442 struct thread_struct thread;
70443+/* thread_info moved to task_struct */
70444+#ifdef CONFIG_X86
70445+ struct thread_info tinfo;
70446+#endif
70447 /* filesystem information */
70448 struct fs_struct *fs;
70449 /* open file information */
70450@@ -1471,6 +1500,10 @@ struct task_struct {
70451 gfp_t lockdep_reclaim_gfp;
70452 #endif
70453
70454+/* process credentials */
70455+ const struct cred __rcu *real_cred; /* objective and real subjective task
70456+ * credentials (COW) */
70457+
70458 /* journalling filesystem info */
70459 void *journal_info;
70460
70461@@ -1509,6 +1542,10 @@ struct task_struct {
70462 /* cg_list protected by css_set_lock and tsk->alloc_lock */
70463 struct list_head cg_list;
70464 #endif
70465+
70466+ const struct cred __rcu *cred; /* effective (overridable) subjective task
70467+ * credentials (COW) */
70468+
70469 #ifdef CONFIG_FUTEX
70470 struct robust_list_head __user *robust_list;
70471 #ifdef CONFIG_COMPAT
70472@@ -1605,8 +1642,74 @@ struct task_struct {
70473 #ifdef CONFIG_UPROBES
70474 struct uprobe_task *utask;
70475 #endif
70476+
70477+#ifdef CONFIG_GRKERNSEC
70478+ /* grsecurity */
70479+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70480+ u64 exec_id;
70481+#endif
70482+#ifdef CONFIG_GRKERNSEC_SETXID
70483+ const struct cred *delayed_cred;
70484+#endif
70485+ struct dentry *gr_chroot_dentry;
70486+ struct acl_subject_label *acl;
70487+ struct acl_role_label *role;
70488+ struct file *exec_file;
70489+ unsigned long brute_expires;
70490+ u16 acl_role_id;
70491+ /* is this the task that authenticated to the special role */
70492+ u8 acl_sp_role;
70493+ u8 is_writable;
70494+ u8 brute;
70495+ u8 gr_is_chrooted;
70496+#endif
70497+
70498 };
70499
70500+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
70501+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
70502+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
70503+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
70504+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
70505+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
70506+
70507+#ifdef CONFIG_PAX_SOFTMODE
70508+extern int pax_softmode;
70509+#endif
70510+
70511+extern int pax_check_flags(unsigned long *);
70512+
70513+/* if tsk != current then task_lock must be held on it */
70514+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70515+static inline unsigned long pax_get_flags(struct task_struct *tsk)
70516+{
70517+ if (likely(tsk->mm))
70518+ return tsk->mm->pax_flags;
70519+ else
70520+ return 0UL;
70521+}
70522+
70523+/* if tsk != current then task_lock must be held on it */
70524+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
70525+{
70526+ if (likely(tsk->mm)) {
70527+ tsk->mm->pax_flags = flags;
70528+ return 0;
70529+ }
70530+ return -EINVAL;
70531+}
70532+#endif
70533+
70534+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70535+extern void pax_set_initial_flags(struct linux_binprm *bprm);
70536+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
70537+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
70538+#endif
70539+
70540+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
70541+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
70542+extern void pax_report_refcount_overflow(struct pt_regs *regs);
70543+
70544 /* Future-safe accessor for struct task_struct's cpus_allowed. */
70545 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
70546
70547@@ -1696,7 +1799,7 @@ struct pid_namespace;
70548 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
70549 struct pid_namespace *ns);
70550
70551-static inline pid_t task_pid_nr(struct task_struct *tsk)
70552+static inline pid_t task_pid_nr(const struct task_struct *tsk)
70553 {
70554 return tsk->pid;
70555 }
70556@@ -2155,7 +2258,9 @@ void yield(void);
70557 extern struct exec_domain default_exec_domain;
70558
70559 union thread_union {
70560+#ifndef CONFIG_X86
70561 struct thread_info thread_info;
70562+#endif
70563 unsigned long stack[THREAD_SIZE/sizeof(long)];
70564 };
70565
70566@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
70567 */
70568
70569 extern struct task_struct *find_task_by_vpid(pid_t nr);
70570+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
70571 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
70572 struct pid_namespace *ns);
70573
70574@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
70575 extern void exit_itimers(struct signal_struct *);
70576 extern void flush_itimer_signals(void);
70577
70578-extern void do_group_exit(int);
70579+extern __noreturn void do_group_exit(int);
70580
70581 extern int allow_signal(int);
70582 extern int disallow_signal(int);
70583@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
70584
70585 #endif
70586
70587-static inline int object_is_on_stack(void *obj)
70588+static inline int object_starts_on_stack(void *obj)
70589 {
70590- void *stack = task_stack_page(current);
70591+ const void *stack = task_stack_page(current);
70592
70593 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
70594 }
70595diff --git a/include/linux/security.h b/include/linux/security.h
70596index eee7478..290f7ba 100644
70597--- a/include/linux/security.h
70598+++ b/include/linux/security.h
70599@@ -26,6 +26,7 @@
70600 #include <linux/capability.h>
70601 #include <linux/slab.h>
70602 #include <linux/err.h>
70603+#include <linux/grsecurity.h>
70604
70605 struct linux_binprm;
70606 struct cred;
70607diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
70608index 68a04a3..866e6a1 100644
70609--- a/include/linux/seq_file.h
70610+++ b/include/linux/seq_file.h
70611@@ -26,6 +26,9 @@ struct seq_file {
70612 struct mutex lock;
70613 const struct seq_operations *op;
70614 int poll_event;
70615+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70616+ u64 exec_id;
70617+#endif
70618 #ifdef CONFIG_USER_NS
70619 struct user_namespace *user_ns;
70620 #endif
70621@@ -38,6 +41,7 @@ struct seq_operations {
70622 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
70623 int (*show) (struct seq_file *m, void *v);
70624 };
70625+typedef struct seq_operations __no_const seq_operations_no_const;
70626
70627 #define SEQ_SKIP 1
70628
70629diff --git a/include/linux/shm.h b/include/linux/shm.h
70630index 429c199..4d42e38 100644
70631--- a/include/linux/shm.h
70632+++ b/include/linux/shm.h
70633@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
70634
70635 /* The task created the shm object. NULL if the task is dead. */
70636 struct task_struct *shm_creator;
70637+#ifdef CONFIG_GRKERNSEC
70638+ time_t shm_createtime;
70639+ pid_t shm_lapid;
70640+#endif
70641 };
70642
70643 /* shm_mode upper byte flags */
70644diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
70645index 320e976..fd52553 100644
70646--- a/include/linux/skbuff.h
70647+++ b/include/linux/skbuff.h
70648@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
70649 extern struct sk_buff *__alloc_skb(unsigned int size,
70650 gfp_t priority, int flags, int node);
70651 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
70652-static inline struct sk_buff *alloc_skb(unsigned int size,
70653+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
70654 gfp_t priority)
70655 {
70656 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
70657@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
70658 */
70659 static inline int skb_queue_empty(const struct sk_buff_head *list)
70660 {
70661- return list->next == (struct sk_buff *)list;
70662+ return list->next == (const struct sk_buff *)list;
70663 }
70664
70665 /**
70666@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
70667 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70668 const struct sk_buff *skb)
70669 {
70670- return skb->next == (struct sk_buff *)list;
70671+ return skb->next == (const struct sk_buff *)list;
70672 }
70673
70674 /**
70675@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70676 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
70677 const struct sk_buff *skb)
70678 {
70679- return skb->prev == (struct sk_buff *)list;
70680+ return skb->prev == (const struct sk_buff *)list;
70681 }
70682
70683 /**
70684@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
70685 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
70686 */
70687 #ifndef NET_SKB_PAD
70688-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
70689+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
70690 #endif
70691
70692 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
70693@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
70694 int noblock, int *err);
70695 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
70696 struct poll_table_struct *wait);
70697-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
70698+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
70699 int offset, struct iovec *to,
70700 int size);
70701 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
70702diff --git a/include/linux/slab.h b/include/linux/slab.h
70703index 5d168d7..720bff3 100644
70704--- a/include/linux/slab.h
70705+++ b/include/linux/slab.h
70706@@ -12,13 +12,20 @@
70707 #include <linux/gfp.h>
70708 #include <linux/types.h>
70709 #include <linux/workqueue.h>
70710-
70711+#include <linux/err.h>
70712
70713 /*
70714 * Flags to pass to kmem_cache_create().
70715 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
70716 */
70717 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
70718+
70719+#ifdef CONFIG_PAX_USERCOPY_SLABS
70720+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
70721+#else
70722+#define SLAB_USERCOPY 0x00000000UL
70723+#endif
70724+
70725 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70726 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70727 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70728@@ -89,10 +96,13 @@
70729 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70730 * Both make kfree a no-op.
70731 */
70732-#define ZERO_SIZE_PTR ((void *)16)
70733+#define ZERO_SIZE_PTR \
70734+({ \
70735+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70736+ (void *)(-MAX_ERRNO-1L); \
70737+})
70738
70739-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70740- (unsigned long)ZERO_SIZE_PTR)
70741+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70742
70743 /*
70744 * Common fields provided in kmem_cache by all slab allocators
70745@@ -112,7 +122,7 @@ struct kmem_cache {
70746 unsigned int align; /* Alignment as calculated */
70747 unsigned long flags; /* Active flags on the slab */
70748 const char *name; /* Slab name for sysfs */
70749- int refcount; /* Use counter */
70750+ atomic_t refcount; /* Use counter */
70751 void (*ctor)(void *); /* Called on object slot creation */
70752 struct list_head list; /* List of all slab caches on the system */
70753 };
70754@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70755 void kfree(const void *);
70756 void kzfree(const void *);
70757 size_t ksize(const void *);
70758+const char *check_heap_object(const void *ptr, unsigned long n);
70759+bool is_usercopy_object(const void *ptr);
70760
70761 /*
70762 * Allocator specific definitions. These are mainly used to establish optimized
70763@@ -311,6 +323,7 @@ size_t ksize(const void *);
70764 * for general use, and so are not documented here. For a full list of
70765 * potential flags, always refer to linux/gfp.h.
70766 */
70767+
70768 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70769 {
70770 if (size != 0 && n > SIZE_MAX / size)
70771@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70772 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70773 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70774 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70775-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70776+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70777 #define kmalloc_track_caller(size, flags) \
70778 __kmalloc_track_caller(size, flags, _RET_IP_)
70779 #else
70780@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70781 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70782 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70783 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70784-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70785+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70786 #define kmalloc_node_track_caller(size, flags, node) \
70787 __kmalloc_node_track_caller(size, flags, node, \
70788 _RET_IP_)
70789diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70790index 8bb6e0e..8eb0dbe 100644
70791--- a/include/linux/slab_def.h
70792+++ b/include/linux/slab_def.h
70793@@ -52,7 +52,7 @@ struct kmem_cache {
70794 /* 4) cache creation/removal */
70795 const char *name;
70796 struct list_head list;
70797- int refcount;
70798+ atomic_t refcount;
70799 int object_size;
70800 int align;
70801
70802@@ -68,10 +68,10 @@ struct kmem_cache {
70803 unsigned long node_allocs;
70804 unsigned long node_frees;
70805 unsigned long node_overflow;
70806- atomic_t allochit;
70807- atomic_t allocmiss;
70808- atomic_t freehit;
70809- atomic_t freemiss;
70810+ atomic_unchecked_t allochit;
70811+ atomic_unchecked_t allocmiss;
70812+ atomic_unchecked_t freehit;
70813+ atomic_unchecked_t freemiss;
70814
70815 /*
70816 * If debugging is enabled, then the allocator can add additional
70817@@ -111,11 +111,16 @@ struct cache_sizes {
70818 #ifdef CONFIG_ZONE_DMA
70819 struct kmem_cache *cs_dmacachep;
70820 #endif
70821+
70822+#ifdef CONFIG_PAX_USERCOPY_SLABS
70823+ struct kmem_cache *cs_usercopycachep;
70824+#endif
70825+
70826 };
70827 extern struct cache_sizes malloc_sizes[];
70828
70829 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70830-void *__kmalloc(size_t size, gfp_t flags);
70831+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70832
70833 #ifdef CONFIG_TRACING
70834 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70835@@ -152,6 +157,13 @@ found:
70836 cachep = malloc_sizes[i].cs_dmacachep;
70837 else
70838 #endif
70839+
70840+#ifdef CONFIG_PAX_USERCOPY_SLABS
70841+ if (flags & GFP_USERCOPY)
70842+ cachep = malloc_sizes[i].cs_usercopycachep;
70843+ else
70844+#endif
70845+
70846 cachep = malloc_sizes[i].cs_cachep;
70847
70848 ret = kmem_cache_alloc_trace(cachep, flags, size);
70849@@ -162,7 +174,7 @@ found:
70850 }
70851
70852 #ifdef CONFIG_NUMA
70853-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70854+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70855 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70856
70857 #ifdef CONFIG_TRACING
70858@@ -205,6 +217,13 @@ found:
70859 cachep = malloc_sizes[i].cs_dmacachep;
70860 else
70861 #endif
70862+
70863+#ifdef CONFIG_PAX_USERCOPY_SLABS
70864+ if (flags & GFP_USERCOPY)
70865+ cachep = malloc_sizes[i].cs_usercopycachep;
70866+ else
70867+#endif
70868+
70869 cachep = malloc_sizes[i].cs_cachep;
70870
70871 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70872diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70873index f28e14a..7831211 100644
70874--- a/include/linux/slob_def.h
70875+++ b/include/linux/slob_def.h
70876@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70877 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70878 }
70879
70880-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70881+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70882
70883 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70884 {
70885@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70886 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70887 }
70888
70889-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70890+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70891 {
70892 return kmalloc(size, flags);
70893 }
70894diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70895index 9db4825..ed42fb5 100644
70896--- a/include/linux/slub_def.h
70897+++ b/include/linux/slub_def.h
70898@@ -91,7 +91,7 @@ struct kmem_cache {
70899 struct kmem_cache_order_objects max;
70900 struct kmem_cache_order_objects min;
70901 gfp_t allocflags; /* gfp flags to use on each alloc */
70902- int refcount; /* Refcount for slab cache destroy */
70903+ atomic_t refcount; /* Refcount for slab cache destroy */
70904 void (*ctor)(void *);
70905 int inuse; /* Offset to metadata */
70906 int align; /* Alignment */
70907@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70908 * Sorry that the following has to be that ugly but some versions of GCC
70909 * have trouble with constant propagation and loops.
70910 */
70911-static __always_inline int kmalloc_index(size_t size)
70912+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70913 {
70914 if (!size)
70915 return 0;
70916@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70917 }
70918
70919 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70920-void *__kmalloc(size_t size, gfp_t flags);
70921+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70922
70923 static __always_inline void *
70924 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70925@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70926 }
70927 #endif
70928
70929-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70930+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70931 {
70932 unsigned int order = get_order(size);
70933 return kmalloc_order_trace(size, flags, order);
70934@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70935 }
70936
70937 #ifdef CONFIG_NUMA
70938-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70939+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70940 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70941
70942 #ifdef CONFIG_TRACING
70943diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70944index e8d702e..0a56eb4 100644
70945--- a/include/linux/sock_diag.h
70946+++ b/include/linux/sock_diag.h
70947@@ -10,7 +10,7 @@ struct sock;
70948 struct sock_diag_handler {
70949 __u8 family;
70950 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70951-};
70952+} __do_const;
70953
70954 int sock_diag_register(const struct sock_diag_handler *h);
70955 void sock_diag_unregister(const struct sock_diag_handler *h);
70956diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70957index 680f9a3..f13aeb0 100644
70958--- a/include/linux/sonet.h
70959+++ b/include/linux/sonet.h
70960@@ -7,7 +7,7 @@
70961 #include <uapi/linux/sonet.h>
70962
70963 struct k_sonet_stats {
70964-#define __HANDLE_ITEM(i) atomic_t i
70965+#define __HANDLE_ITEM(i) atomic_unchecked_t i
70966 __SONET_ITEMS
70967 #undef __HANDLE_ITEM
70968 };
70969diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70970index 34206b8..3db7f1c 100644
70971--- a/include/linux/sunrpc/clnt.h
70972+++ b/include/linux/sunrpc/clnt.h
70973@@ -96,7 +96,7 @@ struct rpc_procinfo {
70974 unsigned int p_timer; /* Which RTT timer to use */
70975 u32 p_statidx; /* Which procedure to account */
70976 const char * p_name; /* name of procedure */
70977-};
70978+} __do_const;
70979
70980 #ifdef __KERNEL__
70981
70982@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70983 {
70984 switch (sap->sa_family) {
70985 case AF_INET:
70986- return ntohs(((struct sockaddr_in *)sap)->sin_port);
70987+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70988 case AF_INET6:
70989- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70990+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70991 }
70992 return 0;
70993 }
70994@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70995 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70996 const struct sockaddr *src)
70997 {
70998- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70999+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
71000 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
71001
71002 dsin->sin_family = ssin->sin_family;
71003@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
71004 if (sa->sa_family != AF_INET6)
71005 return 0;
71006
71007- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
71008+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
71009 }
71010
71011 #endif /* __KERNEL__ */
71012diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
71013index 676ddf5..4c519a1 100644
71014--- a/include/linux/sunrpc/svc.h
71015+++ b/include/linux/sunrpc/svc.h
71016@@ -410,7 +410,7 @@ struct svc_procedure {
71017 unsigned int pc_count; /* call count */
71018 unsigned int pc_cachetype; /* cache info (NFS) */
71019 unsigned int pc_xdrressize; /* maximum size of XDR reply */
71020-};
71021+} __do_const;
71022
71023 /*
71024 * Function prototypes.
71025diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
71026index 0b8e3e6..33e0a01 100644
71027--- a/include/linux/sunrpc/svc_rdma.h
71028+++ b/include/linux/sunrpc/svc_rdma.h
71029@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
71030 extern unsigned int svcrdma_max_requests;
71031 extern unsigned int svcrdma_max_req_size;
71032
71033-extern atomic_t rdma_stat_recv;
71034-extern atomic_t rdma_stat_read;
71035-extern atomic_t rdma_stat_write;
71036-extern atomic_t rdma_stat_sq_starve;
71037-extern atomic_t rdma_stat_rq_starve;
71038-extern atomic_t rdma_stat_rq_poll;
71039-extern atomic_t rdma_stat_rq_prod;
71040-extern atomic_t rdma_stat_sq_poll;
71041-extern atomic_t rdma_stat_sq_prod;
71042+extern atomic_unchecked_t rdma_stat_recv;
71043+extern atomic_unchecked_t rdma_stat_read;
71044+extern atomic_unchecked_t rdma_stat_write;
71045+extern atomic_unchecked_t rdma_stat_sq_starve;
71046+extern atomic_unchecked_t rdma_stat_rq_starve;
71047+extern atomic_unchecked_t rdma_stat_rq_poll;
71048+extern atomic_unchecked_t rdma_stat_rq_prod;
71049+extern atomic_unchecked_t rdma_stat_sq_poll;
71050+extern atomic_unchecked_t rdma_stat_sq_prod;
71051
71052 #define RPCRDMA_VERSION 1
71053
71054diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
71055index dd74084a..7f509d5 100644
71056--- a/include/linux/sunrpc/svcauth.h
71057+++ b/include/linux/sunrpc/svcauth.h
71058@@ -109,7 +109,7 @@ struct auth_ops {
71059 int (*release)(struct svc_rqst *rq);
71060 void (*domain_release)(struct auth_domain *);
71061 int (*set_client)(struct svc_rqst *rq);
71062-};
71063+} __do_const;
71064
71065 #define SVC_GARBAGE 1
71066 #define SVC_SYSERR 2
71067diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
71068index 071d62c..4ccc7ac 100644
71069--- a/include/linux/swiotlb.h
71070+++ b/include/linux/swiotlb.h
71071@@ -59,7 +59,8 @@ extern void
71072
71073 extern void
71074 swiotlb_free_coherent(struct device *hwdev, size_t size,
71075- void *vaddr, dma_addr_t dma_handle);
71076+ void *vaddr, dma_addr_t dma_handle,
71077+ struct dma_attrs *attrs);
71078
71079 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
71080 unsigned long offset, size_t size,
71081diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
71082index 27b3b0b..e093dd9 100644
71083--- a/include/linux/syscore_ops.h
71084+++ b/include/linux/syscore_ops.h
71085@@ -16,7 +16,7 @@ struct syscore_ops {
71086 int (*suspend)(void);
71087 void (*resume)(void);
71088 void (*shutdown)(void);
71089-};
71090+} __do_const;
71091
71092 extern void register_syscore_ops(struct syscore_ops *ops);
71093 extern void unregister_syscore_ops(struct syscore_ops *ops);
71094diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
71095index 14a8ff2..af52bad 100644
71096--- a/include/linux/sysctl.h
71097+++ b/include/linux/sysctl.h
71098@@ -34,13 +34,13 @@ struct ctl_table_root;
71099 struct ctl_table_header;
71100 struct ctl_dir;
71101
71102-typedef struct ctl_table ctl_table;
71103-
71104 typedef int proc_handler (struct ctl_table *ctl, int write,
71105 void __user *buffer, size_t *lenp, loff_t *ppos);
71106
71107 extern int proc_dostring(struct ctl_table *, int,
71108 void __user *, size_t *, loff_t *);
71109+extern int proc_dostring_modpriv(struct ctl_table *, int,
71110+ void __user *, size_t *, loff_t *);
71111 extern int proc_dointvec(struct ctl_table *, int,
71112 void __user *, size_t *, loff_t *);
71113 extern int proc_dointvec_minmax(struct ctl_table *, int,
71114@@ -115,7 +115,9 @@ struct ctl_table
71115 struct ctl_table_poll *poll;
71116 void *extra1;
71117 void *extra2;
71118-};
71119+} __do_const;
71120+typedef struct ctl_table __no_const ctl_table_no_const;
71121+typedef struct ctl_table ctl_table;
71122
71123 struct ctl_node {
71124 struct rb_node node;
71125diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
71126index 381f06d..dc16cc7 100644
71127--- a/include/linux/sysfs.h
71128+++ b/include/linux/sysfs.h
71129@@ -31,7 +31,8 @@ struct attribute {
71130 struct lock_class_key *key;
71131 struct lock_class_key skey;
71132 #endif
71133-};
71134+} __do_const;
71135+typedef struct attribute __no_const attribute_no_const;
71136
71137 /**
71138 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
71139@@ -59,8 +60,8 @@ struct attribute_group {
71140 umode_t (*is_visible)(struct kobject *,
71141 struct attribute *, int);
71142 struct attribute **attrs;
71143-};
71144-
71145+} __do_const;
71146+typedef struct attribute_group __no_const attribute_group_no_const;
71147
71148
71149 /**
71150@@ -107,7 +108,8 @@ struct bin_attribute {
71151 char *, loff_t, size_t);
71152 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
71153 struct vm_area_struct *vma);
71154-};
71155+} __do_const;
71156+typedef struct bin_attribute __no_const bin_attribute_no_const;
71157
71158 /**
71159 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
71160diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
71161index 7faf933..4657127 100644
71162--- a/include/linux/sysrq.h
71163+++ b/include/linux/sysrq.h
71164@@ -15,7 +15,9 @@
71165 #define _LINUX_SYSRQ_H
71166
71167 #include <linux/errno.h>
71168+#include <linux/compiler.h>
71169 #include <linux/types.h>
71170+#include <linux/compiler.h>
71171
71172 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
71173 #define SYSRQ_DEFAULT_ENABLE 1
71174@@ -36,7 +38,7 @@ struct sysrq_key_op {
71175 char *help_msg;
71176 char *action_msg;
71177 int enable_mask;
71178-};
71179+} __do_const;
71180
71181 #ifdef CONFIG_MAGIC_SYSRQ
71182
71183diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
71184index e7e0473..39b7b52 100644
71185--- a/include/linux/thread_info.h
71186+++ b/include/linux/thread_info.h
71187@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
71188 #error "no set_restore_sigmask() provided and default one won't work"
71189 #endif
71190
71191+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
71192+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
71193+{
71194+#ifndef CONFIG_PAX_USERCOPY_DEBUG
71195+ if (!__builtin_constant_p(n))
71196+#endif
71197+ __check_object_size(ptr, n, to);
71198+}
71199+
71200 #endif /* __KERNEL__ */
71201
71202 #endif /* _LINUX_THREAD_INFO_H */
71203diff --git a/include/linux/tty.h b/include/linux/tty.h
71204index 8db1b56..c16a040 100644
71205--- a/include/linux/tty.h
71206+++ b/include/linux/tty.h
71207@@ -194,7 +194,7 @@ struct tty_port {
71208 const struct tty_port_operations *ops; /* Port operations */
71209 spinlock_t lock; /* Lock protecting tty field */
71210 int blocked_open; /* Waiting to open */
71211- int count; /* Usage count */
71212+ atomic_t count; /* Usage count */
71213 wait_queue_head_t open_wait; /* Open waiters */
71214 wait_queue_head_t close_wait; /* Close waiters */
71215 wait_queue_head_t delta_msr_wait; /* Modem status change */
71216@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
71217 struct tty_struct *tty, struct file *filp);
71218 static inline int tty_port_users(struct tty_port *port)
71219 {
71220- return port->count + port->blocked_open;
71221+ return atomic_read(&port->count) + port->blocked_open;
71222 }
71223
71224 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
71225diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
71226index dd976cf..e272742 100644
71227--- a/include/linux/tty_driver.h
71228+++ b/include/linux/tty_driver.h
71229@@ -284,7 +284,7 @@ struct tty_operations {
71230 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
71231 #endif
71232 const struct file_operations *proc_fops;
71233-};
71234+} __do_const;
71235
71236 struct tty_driver {
71237 int magic; /* magic number for this structure */
71238diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
71239index fb79dd8d..07d4773 100644
71240--- a/include/linux/tty_ldisc.h
71241+++ b/include/linux/tty_ldisc.h
71242@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
71243
71244 struct module *owner;
71245
71246- int refcount;
71247+ atomic_t refcount;
71248 };
71249
71250 struct tty_ldisc {
71251diff --git a/include/linux/types.h b/include/linux/types.h
71252index 4d118ba..c3ee9bf 100644
71253--- a/include/linux/types.h
71254+++ b/include/linux/types.h
71255@@ -176,10 +176,26 @@ typedef struct {
71256 int counter;
71257 } atomic_t;
71258
71259+#ifdef CONFIG_PAX_REFCOUNT
71260+typedef struct {
71261+ int counter;
71262+} atomic_unchecked_t;
71263+#else
71264+typedef atomic_t atomic_unchecked_t;
71265+#endif
71266+
71267 #ifdef CONFIG_64BIT
71268 typedef struct {
71269 long counter;
71270 } atomic64_t;
71271+
71272+#ifdef CONFIG_PAX_REFCOUNT
71273+typedef struct {
71274+ long counter;
71275+} atomic64_unchecked_t;
71276+#else
71277+typedef atomic64_t atomic64_unchecked_t;
71278+#endif
71279 #endif
71280
71281 struct list_head {
71282diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
71283index 5ca0951..ab496a5 100644
71284--- a/include/linux/uaccess.h
71285+++ b/include/linux/uaccess.h
71286@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
71287 long ret; \
71288 mm_segment_t old_fs = get_fs(); \
71289 \
71290- set_fs(KERNEL_DS); \
71291 pagefault_disable(); \
71292- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
71293- pagefault_enable(); \
71294+ set_fs(KERNEL_DS); \
71295+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
71296 set_fs(old_fs); \
71297+ pagefault_enable(); \
71298 ret; \
71299 })
71300
71301diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
71302index 8e522cbc..aa8572d 100644
71303--- a/include/linux/uidgid.h
71304+++ b/include/linux/uidgid.h
71305@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
71306
71307 #endif /* CONFIG_USER_NS */
71308
71309+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
71310+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
71311+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
71312+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
71313+
71314 #endif /* _LINUX_UIDGID_H */
71315diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
71316index 99c1b4d..562e6f3 100644
71317--- a/include/linux/unaligned/access_ok.h
71318+++ b/include/linux/unaligned/access_ok.h
71319@@ -4,34 +4,34 @@
71320 #include <linux/kernel.h>
71321 #include <asm/byteorder.h>
71322
71323-static inline u16 get_unaligned_le16(const void *p)
71324+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
71325 {
71326- return le16_to_cpup((__le16 *)p);
71327+ return le16_to_cpup((const __le16 *)p);
71328 }
71329
71330-static inline u32 get_unaligned_le32(const void *p)
71331+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
71332 {
71333- return le32_to_cpup((__le32 *)p);
71334+ return le32_to_cpup((const __le32 *)p);
71335 }
71336
71337-static inline u64 get_unaligned_le64(const void *p)
71338+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
71339 {
71340- return le64_to_cpup((__le64 *)p);
71341+ return le64_to_cpup((const __le64 *)p);
71342 }
71343
71344-static inline u16 get_unaligned_be16(const void *p)
71345+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
71346 {
71347- return be16_to_cpup((__be16 *)p);
71348+ return be16_to_cpup((const __be16 *)p);
71349 }
71350
71351-static inline u32 get_unaligned_be32(const void *p)
71352+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
71353 {
71354- return be32_to_cpup((__be32 *)p);
71355+ return be32_to_cpup((const __be32 *)p);
71356 }
71357
71358-static inline u64 get_unaligned_be64(const void *p)
71359+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
71360 {
71361- return be64_to_cpup((__be64 *)p);
71362+ return be64_to_cpup((const __be64 *)p);
71363 }
71364
71365 static inline void put_unaligned_le16(u16 val, void *p)
71366diff --git a/include/linux/usb.h b/include/linux/usb.h
71367index 4d22d0f..8d0e8f8 100644
71368--- a/include/linux/usb.h
71369+++ b/include/linux/usb.h
71370@@ -554,7 +554,7 @@ struct usb_device {
71371 int maxchild;
71372
71373 u32 quirks;
71374- atomic_t urbnum;
71375+ atomic_unchecked_t urbnum;
71376
71377 unsigned long active_duration;
71378
71379@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
71380
71381 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
71382 __u8 request, __u8 requesttype, __u16 value, __u16 index,
71383- void *data, __u16 size, int timeout);
71384+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
71385 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
71386 void *data, int len, int *actual_length, int timeout);
71387 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
71388diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
71389index c5d36c6..108f4f9 100644
71390--- a/include/linux/usb/renesas_usbhs.h
71391+++ b/include/linux/usb/renesas_usbhs.h
71392@@ -39,7 +39,7 @@ enum {
71393 */
71394 struct renesas_usbhs_driver_callback {
71395 int (*notify_hotplug)(struct platform_device *pdev);
71396-};
71397+} __no_const;
71398
71399 /*
71400 * callback functions for platform
71401diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
71402index b9bd2e6..4ce0093 100644
71403--- a/include/linux/user_namespace.h
71404+++ b/include/linux/user_namespace.h
71405@@ -21,7 +21,7 @@ struct user_namespace {
71406 struct uid_gid_map uid_map;
71407 struct uid_gid_map gid_map;
71408 struct uid_gid_map projid_map;
71409- struct kref kref;
71410+ atomic_t count;
71411 struct user_namespace *parent;
71412 kuid_t owner;
71413 kgid_t group;
71414@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
71415 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
71416 {
71417 if (ns)
71418- kref_get(&ns->kref);
71419+ atomic_inc(&ns->count);
71420 return ns;
71421 }
71422
71423 extern int create_user_ns(struct cred *new);
71424 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
71425-extern void free_user_ns(struct kref *kref);
71426+extern void free_user_ns(struct user_namespace *ns);
71427
71428 static inline void put_user_ns(struct user_namespace *ns)
71429 {
71430- if (ns)
71431- kref_put(&ns->kref, free_user_ns);
71432+ if (ns && atomic_dec_and_test(&ns->count))
71433+ free_user_ns(ns);
71434 }
71435
71436 struct seq_operations;
71437diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
71438index 6f8fbcf..8259001 100644
71439--- a/include/linux/vermagic.h
71440+++ b/include/linux/vermagic.h
71441@@ -25,9 +25,35 @@
71442 #define MODULE_ARCH_VERMAGIC ""
71443 #endif
71444
71445+#ifdef CONFIG_PAX_REFCOUNT
71446+#define MODULE_PAX_REFCOUNT "REFCOUNT "
71447+#else
71448+#define MODULE_PAX_REFCOUNT ""
71449+#endif
71450+
71451+#ifdef CONSTIFY_PLUGIN
71452+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
71453+#else
71454+#define MODULE_CONSTIFY_PLUGIN ""
71455+#endif
71456+
71457+#ifdef STACKLEAK_PLUGIN
71458+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
71459+#else
71460+#define MODULE_STACKLEAK_PLUGIN ""
71461+#endif
71462+
71463+#ifdef CONFIG_GRKERNSEC
71464+#define MODULE_GRSEC "GRSEC "
71465+#else
71466+#define MODULE_GRSEC ""
71467+#endif
71468+
71469 #define VERMAGIC_STRING \
71470 UTS_RELEASE " " \
71471 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
71472 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
71473- MODULE_ARCH_VERMAGIC
71474+ MODULE_ARCH_VERMAGIC \
71475+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
71476+ MODULE_GRSEC
71477
71478diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
71479index 6071e91..ca6a489 100644
71480--- a/include/linux/vmalloc.h
71481+++ b/include/linux/vmalloc.h
71482@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
71483 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
71484 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
71485 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
71486+
71487+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71488+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
71489+#endif
71490+
71491 /* bits [20..32] reserved for arch specific ioremap internals */
71492
71493 /*
71494@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
71495 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
71496 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
71497 unsigned long start, unsigned long end, gfp_t gfp_mask,
71498- pgprot_t prot, int node, const void *caller);
71499+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
71500 extern void vfree(const void *addr);
71501
71502 extern void *vmap(struct page **pages, unsigned int count,
71503@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
71504 extern void free_vm_area(struct vm_struct *area);
71505
71506 /* for /dev/kmem */
71507-extern long vread(char *buf, char *addr, unsigned long count);
71508-extern long vwrite(char *buf, char *addr, unsigned long count);
71509+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
71510+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
71511
71512 /*
71513 * Internals. Dont't use..
71514diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
71515index a13291f..af51fa3 100644
71516--- a/include/linux/vmstat.h
71517+++ b/include/linux/vmstat.h
71518@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
71519 /*
71520 * Zone based page accounting with per cpu differentials.
71521 */
71522-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71523+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71524
71525 static inline void zone_page_state_add(long x, struct zone *zone,
71526 enum zone_stat_item item)
71527 {
71528- atomic_long_add(x, &zone->vm_stat[item]);
71529- atomic_long_add(x, &vm_stat[item]);
71530+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
71531+ atomic_long_add_unchecked(x, &vm_stat[item]);
71532 }
71533
71534 static inline unsigned long global_page_state(enum zone_stat_item item)
71535 {
71536- long x = atomic_long_read(&vm_stat[item]);
71537+ long x = atomic_long_read_unchecked(&vm_stat[item]);
71538 #ifdef CONFIG_SMP
71539 if (x < 0)
71540 x = 0;
71541@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
71542 static inline unsigned long zone_page_state(struct zone *zone,
71543 enum zone_stat_item item)
71544 {
71545- long x = atomic_long_read(&zone->vm_stat[item]);
71546+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71547 #ifdef CONFIG_SMP
71548 if (x < 0)
71549 x = 0;
71550@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
71551 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
71552 enum zone_stat_item item)
71553 {
71554- long x = atomic_long_read(&zone->vm_stat[item]);
71555+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71556
71557 #ifdef CONFIG_SMP
71558 int cpu;
71559@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
71560
71561 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
71562 {
71563- atomic_long_inc(&zone->vm_stat[item]);
71564- atomic_long_inc(&vm_stat[item]);
71565+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
71566+ atomic_long_inc_unchecked(&vm_stat[item]);
71567 }
71568
71569 static inline void __inc_zone_page_state(struct page *page,
71570@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
71571
71572 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
71573 {
71574- atomic_long_dec(&zone->vm_stat[item]);
71575- atomic_long_dec(&vm_stat[item]);
71576+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
71577+ atomic_long_dec_unchecked(&vm_stat[item]);
71578 }
71579
71580 static inline void __dec_zone_page_state(struct page *page,
71581diff --git a/include/linux/xattr.h b/include/linux/xattr.h
71582index fdbafc6..b7ffd47 100644
71583--- a/include/linux/xattr.h
71584+++ b/include/linux/xattr.h
71585@@ -28,7 +28,7 @@ struct xattr_handler {
71586 size_t size, int handler_flags);
71587 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
71588 size_t size, int flags, int handler_flags);
71589-};
71590+} __do_const;
71591
71592 struct xattr {
71593 char *name;
71594diff --git a/include/linux/zlib.h b/include/linux/zlib.h
71595index 9c5a6b4..09c9438 100644
71596--- a/include/linux/zlib.h
71597+++ b/include/linux/zlib.h
71598@@ -31,6 +31,7 @@
71599 #define _ZLIB_H
71600
71601 #include <linux/zconf.h>
71602+#include <linux/compiler.h>
71603
71604 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
71605 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
71606@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
71607
71608 /* basic functions */
71609
71610-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
71611+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
71612 /*
71613 Returns the number of bytes that needs to be allocated for a per-
71614 stream workspace with the specified parameters. A pointer to this
71615diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
71616index 95d1c91..6798cca 100644
71617--- a/include/media/v4l2-dev.h
71618+++ b/include/media/v4l2-dev.h
71619@@ -76,7 +76,7 @@ struct v4l2_file_operations {
71620 int (*mmap) (struct file *, struct vm_area_struct *);
71621 int (*open) (struct file *);
71622 int (*release) (struct file *);
71623-};
71624+} __do_const;
71625
71626 /*
71627 * Newer version of video_device, handled by videodev2.c
71628diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
71629index 4118ad1..cb7e25f 100644
71630--- a/include/media/v4l2-ioctl.h
71631+++ b/include/media/v4l2-ioctl.h
71632@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
71633 bool valid_prio, int cmd, void *arg);
71634 };
71635
71636-
71637 /* v4l debugging and diagnostics */
71638
71639 /* Debug bitmask flags to be used on V4L2 */
71640diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
71641index adcbb20..62c2559 100644
71642--- a/include/net/9p/transport.h
71643+++ b/include/net/9p/transport.h
71644@@ -57,7 +57,7 @@ struct p9_trans_module {
71645 int (*cancel) (struct p9_client *, struct p9_req_t *req);
71646 int (*zc_request)(struct p9_client *, struct p9_req_t *,
71647 char *, char *, int , int, int, int);
71648-};
71649+} __do_const;
71650
71651 void v9fs_register_trans(struct p9_trans_module *m);
71652 void v9fs_unregister_trans(struct p9_trans_module *m);
71653diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
71654index 7588ef4..e62d35f 100644
71655--- a/include/net/bluetooth/l2cap.h
71656+++ b/include/net/bluetooth/l2cap.h
71657@@ -552,7 +552,7 @@ struct l2cap_ops {
71658 void (*defer) (struct l2cap_chan *chan);
71659 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
71660 unsigned long len, int nb);
71661-};
71662+} __do_const;
71663
71664 struct l2cap_conn {
71665 struct hci_conn *hcon;
71666diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
71667index 9e5425b..8136ffc 100644
71668--- a/include/net/caif/cfctrl.h
71669+++ b/include/net/caif/cfctrl.h
71670@@ -52,7 +52,7 @@ struct cfctrl_rsp {
71671 void (*radioset_rsp)(void);
71672 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
71673 struct cflayer *client_layer);
71674-};
71675+} __no_const;
71676
71677 /* Link Setup Parameters for CAIF-Links. */
71678 struct cfctrl_link_param {
71679@@ -101,8 +101,8 @@ struct cfctrl_request_info {
71680 struct cfctrl {
71681 struct cfsrvl serv;
71682 struct cfctrl_rsp res;
71683- atomic_t req_seq_no;
71684- atomic_t rsp_seq_no;
71685+ atomic_unchecked_t req_seq_no;
71686+ atomic_unchecked_t rsp_seq_no;
71687 struct list_head list;
71688 /* Protects from simultaneous access to first_req list */
71689 spinlock_t info_list_lock;
71690diff --git a/include/net/flow.h b/include/net/flow.h
71691index 628e11b..4c475df 100644
71692--- a/include/net/flow.h
71693+++ b/include/net/flow.h
71694@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
71695
71696 extern void flow_cache_flush(void);
71697 extern void flow_cache_flush_deferred(void);
71698-extern atomic_t flow_cache_genid;
71699+extern atomic_unchecked_t flow_cache_genid;
71700
71701 #endif
71702diff --git a/include/net/genetlink.h b/include/net/genetlink.h
71703index bdfbe68..4402ebe 100644
71704--- a/include/net/genetlink.h
71705+++ b/include/net/genetlink.h
71706@@ -118,7 +118,7 @@ struct genl_ops {
71707 struct netlink_callback *cb);
71708 int (*done)(struct netlink_callback *cb);
71709 struct list_head ops_list;
71710-};
71711+} __do_const;
71712
71713 extern int genl_register_family(struct genl_family *family);
71714 extern int genl_register_family_with_ops(struct genl_family *family,
71715diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
71716index e5062c9..48a9a4b 100644
71717--- a/include/net/gro_cells.h
71718+++ b/include/net/gro_cells.h
71719@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
71720 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
71721
71722 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
71723- atomic_long_inc(&dev->rx_dropped);
71724+ atomic_long_inc_unchecked(&dev->rx_dropped);
71725 kfree_skb(skb);
71726 return;
71727 }
71728@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
71729 int i;
71730
71731 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
71732- gcells->cells = kcalloc(sizeof(struct gro_cell),
71733- gcells->gro_cells_mask + 1,
71734+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
71735+ sizeof(struct gro_cell),
71736 GFP_KERNEL);
71737 if (!gcells->cells)
71738 return -ENOMEM;
71739diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
71740index 1832927..ce39aea 100644
71741--- a/include/net/inet_connection_sock.h
71742+++ b/include/net/inet_connection_sock.h
71743@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
71744 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
71745 int (*bind_conflict)(const struct sock *sk,
71746 const struct inet_bind_bucket *tb, bool relax);
71747-};
71748+} __do_const;
71749
71750 /** inet_connection_sock - INET connection oriented sock
71751 *
71752diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
71753index 53f464d..ba76aaa 100644
71754--- a/include/net/inetpeer.h
71755+++ b/include/net/inetpeer.h
71756@@ -47,8 +47,8 @@ struct inet_peer {
71757 */
71758 union {
71759 struct {
71760- atomic_t rid; /* Frag reception counter */
71761- atomic_t ip_id_count; /* IP ID for the next packet */
71762+ atomic_unchecked_t rid; /* Frag reception counter */
71763+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71764 };
71765 struct rcu_head rcu;
71766 struct inet_peer *gc_next;
71767@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71768 more++;
71769 inet_peer_refcheck(p);
71770 do {
71771- old = atomic_read(&p->ip_id_count);
71772+ old = atomic_read_unchecked(&p->ip_id_count);
71773 new = old + more;
71774 if (!new)
71775 new = 1;
71776- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71777+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71778 return new;
71779 }
71780
71781diff --git a/include/net/ip.h b/include/net/ip.h
71782index a68f838..74518ab 100644
71783--- a/include/net/ip.h
71784+++ b/include/net/ip.h
71785@@ -202,7 +202,7 @@ extern struct local_ports {
71786 } sysctl_local_ports;
71787 extern void inet_get_local_port_range(int *low, int *high);
71788
71789-extern unsigned long *sysctl_local_reserved_ports;
71790+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71791 static inline int inet_is_reserved_local_port(int port)
71792 {
71793 return test_bit(port, sysctl_local_reserved_ports);
71794diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71795index 9497be1..5a4fafe 100644
71796--- a/include/net/ip_fib.h
71797+++ b/include/net/ip_fib.h
71798@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71799
71800 #define FIB_RES_SADDR(net, res) \
71801 ((FIB_RES_NH(res).nh_saddr_genid == \
71802- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71803+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71804 FIB_RES_NH(res).nh_saddr : \
71805 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71806 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71807diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71808index 68c69d5..bdab192 100644
71809--- a/include/net/ip_vs.h
71810+++ b/include/net/ip_vs.h
71811@@ -599,7 +599,7 @@ struct ip_vs_conn {
71812 struct ip_vs_conn *control; /* Master control connection */
71813 atomic_t n_control; /* Number of controlled ones */
71814 struct ip_vs_dest *dest; /* real server */
71815- atomic_t in_pkts; /* incoming packet counter */
71816+ atomic_unchecked_t in_pkts; /* incoming packet counter */
71817
71818 /* packet transmitter for different forwarding methods. If it
71819 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71820@@ -737,7 +737,7 @@ struct ip_vs_dest {
71821 __be16 port; /* port number of the server */
71822 union nf_inet_addr addr; /* IP address of the server */
71823 volatile unsigned int flags; /* dest status flags */
71824- atomic_t conn_flags; /* flags to copy to conn */
71825+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
71826 atomic_t weight; /* server weight */
71827
71828 atomic_t refcnt; /* reference counter */
71829@@ -980,11 +980,11 @@ struct netns_ipvs {
71830 /* ip_vs_lblc */
71831 int sysctl_lblc_expiration;
71832 struct ctl_table_header *lblc_ctl_header;
71833- struct ctl_table *lblc_ctl_table;
71834+ ctl_table_no_const *lblc_ctl_table;
71835 /* ip_vs_lblcr */
71836 int sysctl_lblcr_expiration;
71837 struct ctl_table_header *lblcr_ctl_header;
71838- struct ctl_table *lblcr_ctl_table;
71839+ ctl_table_no_const *lblcr_ctl_table;
71840 /* ip_vs_est */
71841 struct list_head est_list; /* estimator list */
71842 spinlock_t est_lock;
71843diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71844index 80ffde3..968b0f4 100644
71845--- a/include/net/irda/ircomm_tty.h
71846+++ b/include/net/irda/ircomm_tty.h
71847@@ -35,6 +35,7 @@
71848 #include <linux/termios.h>
71849 #include <linux/timer.h>
71850 #include <linux/tty.h> /* struct tty_struct */
71851+#include <asm/local.h>
71852
71853 #include <net/irda/irias_object.h>
71854 #include <net/irda/ircomm_core.h>
71855diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71856index cc7c197..9f2da2a 100644
71857--- a/include/net/iucv/af_iucv.h
71858+++ b/include/net/iucv/af_iucv.h
71859@@ -141,7 +141,7 @@ struct iucv_sock {
71860 struct iucv_sock_list {
71861 struct hlist_head head;
71862 rwlock_t lock;
71863- atomic_t autobind_name;
71864+ atomic_unchecked_t autobind_name;
71865 };
71866
71867 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71868diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71869index df83f69..9b640b8 100644
71870--- a/include/net/llc_c_ac.h
71871+++ b/include/net/llc_c_ac.h
71872@@ -87,7 +87,7 @@
71873 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
71874 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
71875
71876-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71877+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71878
71879 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
71880 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71881diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71882index 6ca3113..f8026dd 100644
71883--- a/include/net/llc_c_ev.h
71884+++ b/include/net/llc_c_ev.h
71885@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71886 return (struct llc_conn_state_ev *)skb->cb;
71887 }
71888
71889-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71890-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71891+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71892+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71893
71894 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71895 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71896diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71897index 0e79cfb..f46db31 100644
71898--- a/include/net/llc_c_st.h
71899+++ b/include/net/llc_c_st.h
71900@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71901 u8 next_state;
71902 llc_conn_ev_qfyr_t *ev_qualifiers;
71903 llc_conn_action_t *ev_actions;
71904-};
71905+} __do_const;
71906
71907 struct llc_conn_state {
71908 u8 current_state;
71909diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71910index 37a3bbd..55a4241 100644
71911--- a/include/net/llc_s_ac.h
71912+++ b/include/net/llc_s_ac.h
71913@@ -23,7 +23,7 @@
71914 #define SAP_ACT_TEST_IND 9
71915
71916 /* All action functions must look like this */
71917-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71918+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71919
71920 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71921 struct sk_buff *skb);
71922diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71923index 567c681..cd73ac0 100644
71924--- a/include/net/llc_s_st.h
71925+++ b/include/net/llc_s_st.h
71926@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71927 llc_sap_ev_t ev;
71928 u8 next_state;
71929 llc_sap_action_t *ev_actions;
71930-};
71931+} __do_const;
71932
71933 struct llc_sap_state {
71934 u8 curr_state;
71935diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71936index ee50c5e..1bc3b1a 100644
71937--- a/include/net/mac80211.h
71938+++ b/include/net/mac80211.h
71939@@ -3996,7 +3996,7 @@ struct rate_control_ops {
71940 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71941 struct dentry *dir);
71942 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71943-};
71944+} __do_const;
71945
71946 static inline int rate_supported(struct ieee80211_sta *sta,
71947 enum ieee80211_band band,
71948diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71949index 0dab173..1b76af0 100644
71950--- a/include/net/neighbour.h
71951+++ b/include/net/neighbour.h
71952@@ -123,7 +123,7 @@ struct neigh_ops {
71953 void (*error_report)(struct neighbour *, struct sk_buff *);
71954 int (*output)(struct neighbour *, struct sk_buff *);
71955 int (*connected_output)(struct neighbour *, struct sk_buff *);
71956-};
71957+} __do_const;
71958
71959 struct pneigh_entry {
71960 struct pneigh_entry *next;
71961diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71962index de644bc..351fd4e 100644
71963--- a/include/net/net_namespace.h
71964+++ b/include/net/net_namespace.h
71965@@ -115,7 +115,7 @@ struct net {
71966 #endif
71967 struct netns_ipvs *ipvs;
71968 struct sock *diag_nlsk;
71969- atomic_t rt_genid;
71970+ atomic_unchecked_t rt_genid;
71971 };
71972
71973 /*
71974@@ -282,7 +282,7 @@ struct pernet_operations {
71975 void (*exit_batch)(struct list_head *net_exit_list);
71976 int *id;
71977 size_t size;
71978-};
71979+} __do_const;
71980
71981 /*
71982 * Use these carefully. If you implement a network device and it
71983@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71984
71985 static inline int rt_genid(struct net *net)
71986 {
71987- return atomic_read(&net->rt_genid);
71988+ return atomic_read_unchecked(&net->rt_genid);
71989 }
71990
71991 static inline void rt_genid_bump(struct net *net)
71992 {
71993- atomic_inc(&net->rt_genid);
71994+ atomic_inc_unchecked(&net->rt_genid);
71995 }
71996
71997 #endif /* __NET_NET_NAMESPACE_H */
71998diff --git a/include/net/netdma.h b/include/net/netdma.h
71999index 8ba8ce2..99b7fff 100644
72000--- a/include/net/netdma.h
72001+++ b/include/net/netdma.h
72002@@ -24,7 +24,7 @@
72003 #include <linux/dmaengine.h>
72004 #include <linux/skbuff.h>
72005
72006-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72007+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72008 struct sk_buff *skb, int offset, struct iovec *to,
72009 size_t len, struct dma_pinned_list *pinned_list);
72010
72011diff --git a/include/net/netlink.h b/include/net/netlink.h
72012index 9690b0f..87aded7 100644
72013--- a/include/net/netlink.h
72014+++ b/include/net/netlink.h
72015@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
72016 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
72017 {
72018 if (mark)
72019- skb_trim(skb, (unsigned char *) mark - skb->data);
72020+ skb_trim(skb, (const unsigned char *) mark - skb->data);
72021 }
72022
72023 /**
72024diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
72025index 923cb20..deae816 100644
72026--- a/include/net/netns/conntrack.h
72027+++ b/include/net/netns/conntrack.h
72028@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
72029 struct nf_proto_net {
72030 #ifdef CONFIG_SYSCTL
72031 struct ctl_table_header *ctl_table_header;
72032- struct ctl_table *ctl_table;
72033+ ctl_table_no_const *ctl_table;
72034 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
72035 struct ctl_table_header *ctl_compat_header;
72036- struct ctl_table *ctl_compat_table;
72037+ ctl_table_no_const *ctl_compat_table;
72038 #endif
72039 #endif
72040 unsigned int users;
72041@@ -58,7 +58,7 @@ struct nf_ip_net {
72042 struct nf_icmp_net icmpv6;
72043 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
72044 struct ctl_table_header *ctl_table_header;
72045- struct ctl_table *ctl_table;
72046+ ctl_table_no_const *ctl_table;
72047 #endif
72048 };
72049
72050diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
72051index 2ae2b83..dbdc85e 100644
72052--- a/include/net/netns/ipv4.h
72053+++ b/include/net/netns/ipv4.h
72054@@ -64,7 +64,7 @@ struct netns_ipv4 {
72055 kgid_t sysctl_ping_group_range[2];
72056 long sysctl_tcp_mem[3];
72057
72058- atomic_t dev_addr_genid;
72059+ atomic_unchecked_t dev_addr_genid;
72060
72061 #ifdef CONFIG_IP_MROUTE
72062 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
72063diff --git a/include/net/protocol.h b/include/net/protocol.h
72064index 047c047..b9dad15 100644
72065--- a/include/net/protocol.h
72066+++ b/include/net/protocol.h
72067@@ -44,7 +44,7 @@ struct net_protocol {
72068 void (*err_handler)(struct sk_buff *skb, u32 info);
72069 unsigned int no_policy:1,
72070 netns_ok:1;
72071-};
72072+} __do_const;
72073
72074 #if IS_ENABLED(CONFIG_IPV6)
72075 struct inet6_protocol {
72076@@ -57,7 +57,7 @@ struct inet6_protocol {
72077 u8 type, u8 code, int offset,
72078 __be32 info);
72079 unsigned int flags; /* INET6_PROTO_xxx */
72080-};
72081+} __do_const;
72082
72083 #define INET6_PROTO_NOPOLICY 0x1
72084 #define INET6_PROTO_FINAL 0x2
72085diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
72086index 5a15fab..d799ea7 100644
72087--- a/include/net/rtnetlink.h
72088+++ b/include/net/rtnetlink.h
72089@@ -81,7 +81,7 @@ struct rtnl_link_ops {
72090 const struct net_device *dev);
72091 unsigned int (*get_num_tx_queues)(void);
72092 unsigned int (*get_num_rx_queues)(void);
72093-};
72094+} __do_const;
72095
72096 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
72097 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
72098diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
72099index 7fdf298..197e9f7 100644
72100--- a/include/net/sctp/sctp.h
72101+++ b/include/net/sctp/sctp.h
72102@@ -330,9 +330,9 @@ do { \
72103
72104 #else /* SCTP_DEBUG */
72105
72106-#define SCTP_DEBUG_PRINTK(whatever...)
72107-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
72108-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
72109+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
72110+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
72111+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
72112 #define SCTP_ENABLE_DEBUG
72113 #define SCTP_DISABLE_DEBUG
72114 #define SCTP_ASSERT(expr, str, func)
72115diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
72116index 2a82d13..62a31c2 100644
72117--- a/include/net/sctp/sm.h
72118+++ b/include/net/sctp/sm.h
72119@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
72120 typedef struct {
72121 sctp_state_fn_t *fn;
72122 const char *name;
72123-} sctp_sm_table_entry_t;
72124+} __do_const sctp_sm_table_entry_t;
72125
72126 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
72127 * currently in use.
72128@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
72129 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
72130
72131 /* Extern declarations for major data structures. */
72132-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72133+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72134
72135
72136 /* Get the size of a DATA chunk payload. */
72137diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
72138index fdeb85a..1329d95 100644
72139--- a/include/net/sctp/structs.h
72140+++ b/include/net/sctp/structs.h
72141@@ -517,7 +517,7 @@ struct sctp_pf {
72142 struct sctp_association *asoc);
72143 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
72144 struct sctp_af *af;
72145-};
72146+} __do_const;
72147
72148
72149 /* Structure to track chunk fragments that have been acked, but peer
72150diff --git a/include/net/sock.h b/include/net/sock.h
72151index 25afaa0..8bb0070 100644
72152--- a/include/net/sock.h
72153+++ b/include/net/sock.h
72154@@ -322,7 +322,7 @@ struct sock {
72155 #ifdef CONFIG_RPS
72156 __u32 sk_rxhash;
72157 #endif
72158- atomic_t sk_drops;
72159+ atomic_unchecked_t sk_drops;
72160 int sk_rcvbuf;
72161
72162 struct sk_filter __rcu *sk_filter;
72163@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
72164 }
72165
72166 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
72167- char __user *from, char *to,
72168+ char __user *from, unsigned char *to,
72169 int copy, int offset)
72170 {
72171 if (skb->ip_summed == CHECKSUM_NONE) {
72172@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
72173 }
72174 }
72175
72176-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72177+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72178
72179 /**
72180 * sk_page_frag - return an appropriate page_frag
72181diff --git a/include/net/tcp.h b/include/net/tcp.h
72182index aed42c7..43890c6 100644
72183--- a/include/net/tcp.h
72184+++ b/include/net/tcp.h
72185@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
72186 extern void tcp_xmit_retransmit_queue(struct sock *);
72187 extern void tcp_simple_retransmit(struct sock *);
72188 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
72189-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72190+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72191
72192 extern void tcp_send_probe0(struct sock *);
72193 extern void tcp_send_partial(struct sock *);
72194@@ -701,8 +701,8 @@ struct tcp_skb_cb {
72195 struct inet6_skb_parm h6;
72196 #endif
72197 } header; /* For incoming frames */
72198- __u32 seq; /* Starting sequence number */
72199- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
72200+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
72201+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
72202 __u32 when; /* used to compute rtt's */
72203 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
72204
72205@@ -716,7 +716,7 @@ struct tcp_skb_cb {
72206
72207 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
72208 /* 1 byte hole */
72209- __u32 ack_seq; /* Sequence number ACK'd */
72210+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
72211 };
72212
72213 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
72214diff --git a/include/net/xfrm.h b/include/net/xfrm.h
72215index 63445ed..d6fc34f 100644
72216--- a/include/net/xfrm.h
72217+++ b/include/net/xfrm.h
72218@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
72219 struct net_device *dev,
72220 const struct flowi *fl);
72221 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
72222-};
72223+} __do_const;
72224
72225 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
72226 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
72227@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
72228 struct sk_buff *skb);
72229 int (*transport_finish)(struct sk_buff *skb,
72230 int async);
72231-};
72232+} __do_const;
72233
72234 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
72235 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
72236@@ -423,7 +423,7 @@ struct xfrm_mode {
72237 struct module *owner;
72238 unsigned int encap;
72239 int flags;
72240-};
72241+} __do_const;
72242
72243 /* Flags for xfrm_mode. */
72244 enum {
72245@@ -514,7 +514,7 @@ struct xfrm_policy {
72246 struct timer_list timer;
72247
72248 struct flow_cache_object flo;
72249- atomic_t genid;
72250+ atomic_unchecked_t genid;
72251 u32 priority;
72252 u32 index;
72253 struct xfrm_mark mark;
72254diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
72255index 1a046b1..ee0bef0 100644
72256--- a/include/rdma/iw_cm.h
72257+++ b/include/rdma/iw_cm.h
72258@@ -122,7 +122,7 @@ struct iw_cm_verbs {
72259 int backlog);
72260
72261 int (*destroy_listen)(struct iw_cm_id *cm_id);
72262-};
72263+} __no_const;
72264
72265 /**
72266 * iw_create_cm_id - Create an IW CM identifier.
72267diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
72268index 399162b..b337f1a 100644
72269--- a/include/scsi/libfc.h
72270+++ b/include/scsi/libfc.h
72271@@ -762,6 +762,7 @@ struct libfc_function_template {
72272 */
72273 void (*disc_stop_final) (struct fc_lport *);
72274 };
72275+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
72276
72277 /**
72278 * struct fc_disc - Discovery context
72279@@ -866,7 +867,7 @@ struct fc_lport {
72280 struct fc_vport *vport;
72281
72282 /* Operational Information */
72283- struct libfc_function_template tt;
72284+ libfc_function_template_no_const tt;
72285 u8 link_up;
72286 u8 qfull;
72287 enum fc_lport_state state;
72288diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
72289index e65c62e..aa2e5a2 100644
72290--- a/include/scsi/scsi_device.h
72291+++ b/include/scsi/scsi_device.h
72292@@ -170,9 +170,9 @@ struct scsi_device {
72293 unsigned int max_device_blocked; /* what device_blocked counts down from */
72294 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
72295
72296- atomic_t iorequest_cnt;
72297- atomic_t iodone_cnt;
72298- atomic_t ioerr_cnt;
72299+ atomic_unchecked_t iorequest_cnt;
72300+ atomic_unchecked_t iodone_cnt;
72301+ atomic_unchecked_t ioerr_cnt;
72302
72303 struct device sdev_gendev,
72304 sdev_dev;
72305diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
72306index b797e8f..8e2c3aa 100644
72307--- a/include/scsi/scsi_transport_fc.h
72308+++ b/include/scsi/scsi_transport_fc.h
72309@@ -751,7 +751,8 @@ struct fc_function_template {
72310 unsigned long show_host_system_hostname:1;
72311
72312 unsigned long disable_target_scan:1;
72313-};
72314+} __do_const;
72315+typedef struct fc_function_template __no_const fc_function_template_no_const;
72316
72317
72318 /**
72319diff --git a/include/sound/soc.h b/include/sound/soc.h
72320index bc56738..a4be132 100644
72321--- a/include/sound/soc.h
72322+++ b/include/sound/soc.h
72323@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
72324 /* probe ordering - for components with runtime dependencies */
72325 int probe_order;
72326 int remove_order;
72327-};
72328+} __do_const;
72329
72330 /* SoC platform interface */
72331 struct snd_soc_platform_driver {
72332@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
72333 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
72334 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
72335 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
72336-};
72337+} __do_const;
72338
72339 struct snd_soc_platform {
72340 const char *name;
72341diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
72342index 663e34a..91b306a 100644
72343--- a/include/target/target_core_base.h
72344+++ b/include/target/target_core_base.h
72345@@ -654,7 +654,7 @@ struct se_device {
72346 spinlock_t stats_lock;
72347 /* Active commands on this virtual SE device */
72348 atomic_t simple_cmds;
72349- atomic_t dev_ordered_id;
72350+ atomic_unchecked_t dev_ordered_id;
72351 atomic_t dev_ordered_sync;
72352 atomic_t dev_qf_count;
72353 int export_count;
72354diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
72355new file mode 100644
72356index 0000000..fb634b7
72357--- /dev/null
72358+++ b/include/trace/events/fs.h
72359@@ -0,0 +1,53 @@
72360+#undef TRACE_SYSTEM
72361+#define TRACE_SYSTEM fs
72362+
72363+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
72364+#define _TRACE_FS_H
72365+
72366+#include <linux/fs.h>
72367+#include <linux/tracepoint.h>
72368+
72369+TRACE_EVENT(do_sys_open,
72370+
72371+ TP_PROTO(const char *filename, int flags, int mode),
72372+
72373+ TP_ARGS(filename, flags, mode),
72374+
72375+ TP_STRUCT__entry(
72376+ __string( filename, filename )
72377+ __field( int, flags )
72378+ __field( int, mode )
72379+ ),
72380+
72381+ TP_fast_assign(
72382+ __assign_str(filename, filename);
72383+ __entry->flags = flags;
72384+ __entry->mode = mode;
72385+ ),
72386+
72387+ TP_printk("\"%s\" %x %o",
72388+ __get_str(filename), __entry->flags, __entry->mode)
72389+);
72390+
72391+TRACE_EVENT(open_exec,
72392+
72393+ TP_PROTO(const char *filename),
72394+
72395+ TP_ARGS(filename),
72396+
72397+ TP_STRUCT__entry(
72398+ __string( filename, filename )
72399+ ),
72400+
72401+ TP_fast_assign(
72402+ __assign_str(filename, filename);
72403+ ),
72404+
72405+ TP_printk("\"%s\"",
72406+ __get_str(filename))
72407+);
72408+
72409+#endif /* _TRACE_FS_H */
72410+
72411+/* This part must be outside protection */
72412+#include <trace/define_trace.h>
72413diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
72414index 1c09820..7f5ec79 100644
72415--- a/include/trace/events/irq.h
72416+++ b/include/trace/events/irq.h
72417@@ -36,7 +36,7 @@ struct softirq_action;
72418 */
72419 TRACE_EVENT(irq_handler_entry,
72420
72421- TP_PROTO(int irq, struct irqaction *action),
72422+ TP_PROTO(int irq, const struct irqaction *action),
72423
72424 TP_ARGS(irq, action),
72425
72426@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
72427 */
72428 TRACE_EVENT(irq_handler_exit,
72429
72430- TP_PROTO(int irq, struct irqaction *action, int ret),
72431+ TP_PROTO(int irq, const struct irqaction *action, int ret),
72432
72433 TP_ARGS(irq, action, ret),
72434
72435diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
72436index 7caf44c..23c6f27 100644
72437--- a/include/uapi/linux/a.out.h
72438+++ b/include/uapi/linux/a.out.h
72439@@ -39,6 +39,14 @@ enum machine_type {
72440 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
72441 };
72442
72443+/* Constants for the N_FLAGS field */
72444+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72445+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
72446+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
72447+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
72448+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72449+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72450+
72451 #if !defined (N_MAGIC)
72452 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
72453 #endif
72454diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
72455index d876736..ccce5c0 100644
72456--- a/include/uapi/linux/byteorder/little_endian.h
72457+++ b/include/uapi/linux/byteorder/little_endian.h
72458@@ -42,51 +42,51 @@
72459
72460 static inline __le64 __cpu_to_le64p(const __u64 *p)
72461 {
72462- return (__force __le64)*p;
72463+ return (__force const __le64)*p;
72464 }
72465-static inline __u64 __le64_to_cpup(const __le64 *p)
72466+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
72467 {
72468- return (__force __u64)*p;
72469+ return (__force const __u64)*p;
72470 }
72471 static inline __le32 __cpu_to_le32p(const __u32 *p)
72472 {
72473- return (__force __le32)*p;
72474+ return (__force const __le32)*p;
72475 }
72476 static inline __u32 __le32_to_cpup(const __le32 *p)
72477 {
72478- return (__force __u32)*p;
72479+ return (__force const __u32)*p;
72480 }
72481 static inline __le16 __cpu_to_le16p(const __u16 *p)
72482 {
72483- return (__force __le16)*p;
72484+ return (__force const __le16)*p;
72485 }
72486 static inline __u16 __le16_to_cpup(const __le16 *p)
72487 {
72488- return (__force __u16)*p;
72489+ return (__force const __u16)*p;
72490 }
72491 static inline __be64 __cpu_to_be64p(const __u64 *p)
72492 {
72493- return (__force __be64)__swab64p(p);
72494+ return (__force const __be64)__swab64p(p);
72495 }
72496 static inline __u64 __be64_to_cpup(const __be64 *p)
72497 {
72498- return __swab64p((__u64 *)p);
72499+ return __swab64p((const __u64 *)p);
72500 }
72501 static inline __be32 __cpu_to_be32p(const __u32 *p)
72502 {
72503- return (__force __be32)__swab32p(p);
72504+ return (__force const __be32)__swab32p(p);
72505 }
72506-static inline __u32 __be32_to_cpup(const __be32 *p)
72507+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
72508 {
72509- return __swab32p((__u32 *)p);
72510+ return __swab32p((const __u32 *)p);
72511 }
72512 static inline __be16 __cpu_to_be16p(const __u16 *p)
72513 {
72514- return (__force __be16)__swab16p(p);
72515+ return (__force const __be16)__swab16p(p);
72516 }
72517 static inline __u16 __be16_to_cpup(const __be16 *p)
72518 {
72519- return __swab16p((__u16 *)p);
72520+ return __swab16p((const __u16 *)p);
72521 }
72522 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
72523 #define __le64_to_cpus(x) do { (void)(x); } while (0)
72524diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
72525index 126a817..d522bd1 100644
72526--- a/include/uapi/linux/elf.h
72527+++ b/include/uapi/linux/elf.h
72528@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
72529 #define PT_GNU_EH_FRAME 0x6474e550
72530
72531 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
72532+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
72533+
72534+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
72535+
72536+/* Constants for the e_flags field */
72537+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72538+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
72539+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
72540+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
72541+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72542+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72543
72544 /*
72545 * Extended Numbering
72546@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
72547 #define DT_DEBUG 21
72548 #define DT_TEXTREL 22
72549 #define DT_JMPREL 23
72550+#define DT_FLAGS 30
72551+ #define DF_TEXTREL 0x00000004
72552 #define DT_ENCODING 32
72553 #define OLD_DT_LOOS 0x60000000
72554 #define DT_LOOS 0x6000000d
72555@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
72556 #define PF_W 0x2
72557 #define PF_X 0x1
72558
72559+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
72560+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
72561+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
72562+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
72563+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
72564+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
72565+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
72566+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
72567+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
72568+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
72569+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
72570+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
72571+
72572 typedef struct elf32_phdr{
72573 Elf32_Word p_type;
72574 Elf32_Off p_offset;
72575@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
72576 #define EI_OSABI 7
72577 #define EI_PAD 8
72578
72579+#define EI_PAX 14
72580+
72581 #define ELFMAG0 0x7f /* EI_MAG */
72582 #define ELFMAG1 'E'
72583 #define ELFMAG2 'L'
72584diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
72585index aa169c4..6a2771d 100644
72586--- a/include/uapi/linux/personality.h
72587+++ b/include/uapi/linux/personality.h
72588@@ -30,6 +30,7 @@ enum {
72589 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
72590 ADDR_NO_RANDOMIZE | \
72591 ADDR_COMPAT_LAYOUT | \
72592+ ADDR_LIMIT_3GB | \
72593 MMAP_PAGE_ZERO)
72594
72595 /*
72596diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
72597index 7530e74..e714828 100644
72598--- a/include/uapi/linux/screen_info.h
72599+++ b/include/uapi/linux/screen_info.h
72600@@ -43,7 +43,8 @@ struct screen_info {
72601 __u16 pages; /* 0x32 */
72602 __u16 vesa_attributes; /* 0x34 */
72603 __u32 capabilities; /* 0x36 */
72604- __u8 _reserved[6]; /* 0x3a */
72605+ __u16 vesapm_size; /* 0x3a */
72606+ __u8 _reserved[4]; /* 0x3c */
72607 } __attribute__((packed));
72608
72609 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
72610diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
72611index 0e011eb..82681b1 100644
72612--- a/include/uapi/linux/swab.h
72613+++ b/include/uapi/linux/swab.h
72614@@ -43,7 +43,7 @@
72615 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
72616 */
72617
72618-static inline __attribute_const__ __u16 __fswab16(__u16 val)
72619+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
72620 {
72621 #ifdef __HAVE_BUILTIN_BSWAP16__
72622 return __builtin_bswap16(val);
72623@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
72624 #endif
72625 }
72626
72627-static inline __attribute_const__ __u32 __fswab32(__u32 val)
72628+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
72629 {
72630 #ifdef __HAVE_BUILTIN_BSWAP32__
72631 return __builtin_bswap32(val);
72632@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
72633 #endif
72634 }
72635
72636-static inline __attribute_const__ __u64 __fswab64(__u64 val)
72637+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
72638 {
72639 #ifdef __HAVE_BUILTIN_BSWAP64__
72640 return __builtin_bswap64(val);
72641diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
72642index 6d67213..8dab561 100644
72643--- a/include/uapi/linux/sysctl.h
72644+++ b/include/uapi/linux/sysctl.h
72645@@ -155,7 +155,11 @@ enum
72646 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
72647 };
72648
72649-
72650+#ifdef CONFIG_PAX_SOFTMODE
72651+enum {
72652+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
72653+};
72654+#endif
72655
72656 /* CTL_VM names: */
72657 enum
72658diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
72659index 26607bd..588b65f 100644
72660--- a/include/uapi/linux/xattr.h
72661+++ b/include/uapi/linux/xattr.h
72662@@ -60,5 +60,9 @@
72663 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
72664 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
72665
72666+/* User namespace */
72667+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
72668+#define XATTR_PAX_FLAGS_SUFFIX "flags"
72669+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
72670
72671 #endif /* _UAPI_LINUX_XATTR_H */
72672diff --git a/include/video/udlfb.h b/include/video/udlfb.h
72673index f9466fa..f4e2b81 100644
72674--- a/include/video/udlfb.h
72675+++ b/include/video/udlfb.h
72676@@ -53,10 +53,10 @@ struct dlfb_data {
72677 u32 pseudo_palette[256];
72678 int blank_mode; /*one of FB_BLANK_ */
72679 /* blit-only rendering path metrics, exposed through sysfs */
72680- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72681- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
72682- atomic_t bytes_sent; /* to usb, after compression including overhead */
72683- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
72684+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72685+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
72686+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
72687+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
72688 };
72689
72690 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
72691diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
72692index 0993a22..32ba2fe 100644
72693--- a/include/video/uvesafb.h
72694+++ b/include/video/uvesafb.h
72695@@ -177,6 +177,7 @@ struct uvesafb_par {
72696 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
72697 u8 pmi_setpal; /* PMI for palette changes */
72698 u16 *pmi_base; /* protected mode interface location */
72699+ u8 *pmi_code; /* protected mode code location */
72700 void *pmi_start;
72701 void *pmi_pal;
72702 u8 *vbe_state_orig; /*
72703diff --git a/init/Kconfig b/init/Kconfig
72704index be8b7f5..1eeca9b 100644
72705--- a/init/Kconfig
72706+++ b/init/Kconfig
72707@@ -990,6 +990,7 @@ endif # CGROUPS
72708
72709 config CHECKPOINT_RESTORE
72710 bool "Checkpoint/restore support" if EXPERT
72711+ depends on !GRKERNSEC
72712 default n
72713 help
72714 Enables additional kernel features in a sake of checkpoint/restore.
72715@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
72716
72717 config COMPAT_BRK
72718 bool "Disable heap randomization"
72719- default y
72720+ default n
72721 help
72722 Randomizing heap placement makes heap exploits harder, but it
72723 also breaks ancient binaries (including anything libc5 based).
72724@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
72725 config STOP_MACHINE
72726 bool
72727 default y
72728- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
72729+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
72730 help
72731 Need stop_machine() primitive.
72732
72733diff --git a/init/Makefile b/init/Makefile
72734index 7bc47ee..6da2dc7 100644
72735--- a/init/Makefile
72736+++ b/init/Makefile
72737@@ -2,6 +2,9 @@
72738 # Makefile for the linux kernel.
72739 #
72740
72741+ccflags-y := $(GCC_PLUGINS_CFLAGS)
72742+asflags-y := $(GCC_PLUGINS_AFLAGS)
72743+
72744 obj-y := main.o version.o mounts.o
72745 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
72746 obj-y += noinitramfs.o
72747diff --git a/init/do_mounts.c b/init/do_mounts.c
72748index 1d1b634..a1c810f 100644
72749--- a/init/do_mounts.c
72750+++ b/init/do_mounts.c
72751@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
72752 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
72753 {
72754 struct super_block *s;
72755- int err = sys_mount(name, "/root", fs, flags, data);
72756+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
72757 if (err)
72758 return err;
72759
72760- sys_chdir("/root");
72761+ sys_chdir((const char __force_user *)"/root");
72762 s = current->fs->pwd.dentry->d_sb;
72763 ROOT_DEV = s->s_dev;
72764 printk(KERN_INFO
72765@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
72766 va_start(args, fmt);
72767 vsprintf(buf, fmt, args);
72768 va_end(args);
72769- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
72770+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
72771 if (fd >= 0) {
72772 sys_ioctl(fd, FDEJECT, 0);
72773 sys_close(fd);
72774 }
72775 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
72776- fd = sys_open("/dev/console", O_RDWR, 0);
72777+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
72778 if (fd >= 0) {
72779 sys_ioctl(fd, TCGETS, (long)&termios);
72780 termios.c_lflag &= ~ICANON;
72781 sys_ioctl(fd, TCSETSF, (long)&termios);
72782- sys_read(fd, &c, 1);
72783+ sys_read(fd, (char __user *)&c, 1);
72784 termios.c_lflag |= ICANON;
72785 sys_ioctl(fd, TCSETSF, (long)&termios);
72786 sys_close(fd);
72787@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
72788 mount_root();
72789 out:
72790 devtmpfs_mount("dev");
72791- sys_mount(".", "/", NULL, MS_MOVE, NULL);
72792- sys_chroot(".");
72793+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72794+ sys_chroot((const char __force_user *)".");
72795 }
72796diff --git a/init/do_mounts.h b/init/do_mounts.h
72797index f5b978a..69dbfe8 100644
72798--- a/init/do_mounts.h
72799+++ b/init/do_mounts.h
72800@@ -15,15 +15,15 @@ extern int root_mountflags;
72801
72802 static inline int create_dev(char *name, dev_t dev)
72803 {
72804- sys_unlink(name);
72805- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72806+ sys_unlink((char __force_user *)name);
72807+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72808 }
72809
72810 #if BITS_PER_LONG == 32
72811 static inline u32 bstat(char *name)
72812 {
72813 struct stat64 stat;
72814- if (sys_stat64(name, &stat) != 0)
72815+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72816 return 0;
72817 if (!S_ISBLK(stat.st_mode))
72818 return 0;
72819@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72820 static inline u32 bstat(char *name)
72821 {
72822 struct stat stat;
72823- if (sys_newstat(name, &stat) != 0)
72824+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72825 return 0;
72826 if (!S_ISBLK(stat.st_mode))
72827 return 0;
72828diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72829index f9acf71..1e19144 100644
72830--- a/init/do_mounts_initrd.c
72831+++ b/init/do_mounts_initrd.c
72832@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72833 create_dev("/dev/root.old", Root_RAM0);
72834 /* mount initrd on rootfs' /root */
72835 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72836- sys_mkdir("/old", 0700);
72837- sys_chdir("/old");
72838+ sys_mkdir((const char __force_user *)"/old", 0700);
72839+ sys_chdir((const char __force_user *)"/old");
72840
72841 /*
72842 * In case that a resume from disk is carried out by linuxrc or one of
72843@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72844 current->flags &= ~PF_FREEZER_SKIP;
72845
72846 /* move initrd to rootfs' /old */
72847- sys_mount("..", ".", NULL, MS_MOVE, NULL);
72848+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72849 /* switch root and cwd back to / of rootfs */
72850- sys_chroot("..");
72851+ sys_chroot((const char __force_user *)"..");
72852
72853 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72854- sys_chdir("/old");
72855+ sys_chdir((const char __force_user *)"/old");
72856 return;
72857 }
72858
72859- sys_chdir("/");
72860+ sys_chdir((const char __force_user *)"/");
72861 ROOT_DEV = new_decode_dev(real_root_dev);
72862 mount_root();
72863
72864 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
72865- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
72866+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
72867 if (!error)
72868 printk("okay\n");
72869 else {
72870- int fd = sys_open("/dev/root.old", O_RDWR, 0);
72871+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
72872 if (error == -ENOENT)
72873 printk("/initrd does not exist. Ignored.\n");
72874 else
72875 printk("failed\n");
72876 printk(KERN_NOTICE "Unmounting old root\n");
72877- sys_umount("/old", MNT_DETACH);
72878+ sys_umount((char __force_user *)"/old", MNT_DETACH);
72879 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
72880 if (fd < 0) {
72881 error = fd;
72882@@ -120,11 +120,11 @@ int __init initrd_load(void)
72883 * mounted in the normal path.
72884 */
72885 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
72886- sys_unlink("/initrd.image");
72887+ sys_unlink((const char __force_user *)"/initrd.image");
72888 handle_initrd();
72889 return 1;
72890 }
72891 }
72892- sys_unlink("/initrd.image");
72893+ sys_unlink((const char __force_user *)"/initrd.image");
72894 return 0;
72895 }
72896diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
72897index 8cb6db5..d729f50 100644
72898--- a/init/do_mounts_md.c
72899+++ b/init/do_mounts_md.c
72900@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
72901 partitioned ? "_d" : "", minor,
72902 md_setup_args[ent].device_names);
72903
72904- fd = sys_open(name, 0, 0);
72905+ fd = sys_open((char __force_user *)name, 0, 0);
72906 if (fd < 0) {
72907 printk(KERN_ERR "md: open failed - cannot start "
72908 "array %s\n", name);
72909@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
72910 * array without it
72911 */
72912 sys_close(fd);
72913- fd = sys_open(name, 0, 0);
72914+ fd = sys_open((char __force_user *)name, 0, 0);
72915 sys_ioctl(fd, BLKRRPART, 0);
72916 }
72917 sys_close(fd);
72918@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72919
72920 wait_for_device_probe();
72921
72922- fd = sys_open("/dev/md0", 0, 0);
72923+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72924 if (fd >= 0) {
72925 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72926 sys_close(fd);
72927diff --git a/init/init_task.c b/init/init_task.c
72928index 8b2f399..f0797c9 100644
72929--- a/init/init_task.c
72930+++ b/init/init_task.c
72931@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72932 * Initial thread structure. Alignment of this is handled by a special
72933 * linker map entry.
72934 */
72935+#ifdef CONFIG_X86
72936+union thread_union init_thread_union __init_task_data;
72937+#else
72938 union thread_union init_thread_union __init_task_data =
72939 { INIT_THREAD_INFO(init_task) };
72940+#endif
72941diff --git a/init/initramfs.c b/init/initramfs.c
72942index 84c6bf1..8899338 100644
72943--- a/init/initramfs.c
72944+++ b/init/initramfs.c
72945@@ -84,7 +84,7 @@ static void __init free_hash(void)
72946 }
72947 }
72948
72949-static long __init do_utime(char *filename, time_t mtime)
72950+static long __init do_utime(char __force_user *filename, time_t mtime)
72951 {
72952 struct timespec t[2];
72953
72954@@ -119,7 +119,7 @@ static void __init dir_utime(void)
72955 struct dir_entry *de, *tmp;
72956 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72957 list_del(&de->list);
72958- do_utime(de->name, de->mtime);
72959+ do_utime((char __force_user *)de->name, de->mtime);
72960 kfree(de->name);
72961 kfree(de);
72962 }
72963@@ -281,7 +281,7 @@ static int __init maybe_link(void)
72964 if (nlink >= 2) {
72965 char *old = find_link(major, minor, ino, mode, collected);
72966 if (old)
72967- return (sys_link(old, collected) < 0) ? -1 : 1;
72968+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72969 }
72970 return 0;
72971 }
72972@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72973 {
72974 struct stat st;
72975
72976- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72977+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72978 if (S_ISDIR(st.st_mode))
72979- sys_rmdir(path);
72980+ sys_rmdir((char __force_user *)path);
72981 else
72982- sys_unlink(path);
72983+ sys_unlink((char __force_user *)path);
72984 }
72985 }
72986
72987@@ -315,7 +315,7 @@ static int __init do_name(void)
72988 int openflags = O_WRONLY|O_CREAT;
72989 if (ml != 1)
72990 openflags |= O_TRUNC;
72991- wfd = sys_open(collected, openflags, mode);
72992+ wfd = sys_open((char __force_user *)collected, openflags, mode);
72993
72994 if (wfd >= 0) {
72995 sys_fchown(wfd, uid, gid);
72996@@ -327,17 +327,17 @@ static int __init do_name(void)
72997 }
72998 }
72999 } else if (S_ISDIR(mode)) {
73000- sys_mkdir(collected, mode);
73001- sys_chown(collected, uid, gid);
73002- sys_chmod(collected, mode);
73003+ sys_mkdir((char __force_user *)collected, mode);
73004+ sys_chown((char __force_user *)collected, uid, gid);
73005+ sys_chmod((char __force_user *)collected, mode);
73006 dir_add(collected, mtime);
73007 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
73008 S_ISFIFO(mode) || S_ISSOCK(mode)) {
73009 if (maybe_link() == 0) {
73010- sys_mknod(collected, mode, rdev);
73011- sys_chown(collected, uid, gid);
73012- sys_chmod(collected, mode);
73013- do_utime(collected, mtime);
73014+ sys_mknod((char __force_user *)collected, mode, rdev);
73015+ sys_chown((char __force_user *)collected, uid, gid);
73016+ sys_chmod((char __force_user *)collected, mode);
73017+ do_utime((char __force_user *)collected, mtime);
73018 }
73019 }
73020 return 0;
73021@@ -346,15 +346,15 @@ static int __init do_name(void)
73022 static int __init do_copy(void)
73023 {
73024 if (count >= body_len) {
73025- sys_write(wfd, victim, body_len);
73026+ sys_write(wfd, (char __force_user *)victim, body_len);
73027 sys_close(wfd);
73028- do_utime(vcollected, mtime);
73029+ do_utime((char __force_user *)vcollected, mtime);
73030 kfree(vcollected);
73031 eat(body_len);
73032 state = SkipIt;
73033 return 0;
73034 } else {
73035- sys_write(wfd, victim, count);
73036+ sys_write(wfd, (char __force_user *)victim, count);
73037 body_len -= count;
73038 eat(count);
73039 return 1;
73040@@ -365,9 +365,9 @@ static int __init do_symlink(void)
73041 {
73042 collected[N_ALIGN(name_len) + body_len] = '\0';
73043 clean_path(collected, 0);
73044- sys_symlink(collected + N_ALIGN(name_len), collected);
73045- sys_lchown(collected, uid, gid);
73046- do_utime(collected, mtime);
73047+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
73048+ sys_lchown((char __force_user *)collected, uid, gid);
73049+ do_utime((char __force_user *)collected, mtime);
73050 state = SkipIt;
73051 next_state = Reset;
73052 return 0;
73053diff --git a/init/main.c b/init/main.c
73054index cee4b5c..360e10a 100644
73055--- a/init/main.c
73056+++ b/init/main.c
73057@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
73058 extern void tc_init(void);
73059 #endif
73060
73061+extern void grsecurity_init(void);
73062+
73063 /*
73064 * Debug helper: via this flag we know that we are in 'early bootup code'
73065 * where only the boot processor is running with IRQ disabled. This means
73066@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
73067
73068 __setup("reset_devices", set_reset_devices);
73069
73070+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73071+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
73072+static int __init setup_grsec_proc_gid(char *str)
73073+{
73074+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
73075+ return 1;
73076+}
73077+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
73078+#endif
73079+
73080+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
73081+extern char pax_enter_kernel_user[];
73082+extern char pax_exit_kernel_user[];
73083+extern pgdval_t clone_pgd_mask;
73084+#endif
73085+
73086+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
73087+static int __init setup_pax_nouderef(char *str)
73088+{
73089+#ifdef CONFIG_X86_32
73090+ unsigned int cpu;
73091+ struct desc_struct *gdt;
73092+
73093+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
73094+ gdt = get_cpu_gdt_table(cpu);
73095+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
73096+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
73097+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
73098+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
73099+ }
73100+ loadsegment(ds, __KERNEL_DS);
73101+ loadsegment(es, __KERNEL_DS);
73102+ loadsegment(ss, __KERNEL_DS);
73103+#else
73104+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
73105+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
73106+ clone_pgd_mask = ~(pgdval_t)0UL;
73107+#endif
73108+
73109+ return 0;
73110+}
73111+early_param("pax_nouderef", setup_pax_nouderef);
73112+#endif
73113+
73114+#ifdef CONFIG_PAX_SOFTMODE
73115+int pax_softmode;
73116+
73117+static int __init setup_pax_softmode(char *str)
73118+{
73119+ get_option(&str, &pax_softmode);
73120+ return 1;
73121+}
73122+__setup("pax_softmode=", setup_pax_softmode);
73123+#endif
73124+
73125 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
73126 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
73127 static const char *panic_later, *panic_param;
73128@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
73129 {
73130 int count = preempt_count();
73131 int ret;
73132+ const char *msg1 = "", *msg2 = "";
73133
73134 if (initcall_debug)
73135 ret = do_one_initcall_debug(fn);
73136@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
73137 sprintf(msgbuf, "error code %d ", ret);
73138
73139 if (preempt_count() != count) {
73140- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
73141+ msg1 = " preemption imbalance";
73142 preempt_count() = count;
73143 }
73144 if (irqs_disabled()) {
73145- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
73146+ msg2 = " disabled interrupts";
73147 local_irq_enable();
73148 }
73149- if (msgbuf[0]) {
73150- printk("initcall %pF returned with %s\n", fn, msgbuf);
73151+ if (msgbuf[0] || *msg1 || *msg2) {
73152+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
73153 }
73154
73155 return ret;
73156@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
73157 level, level,
73158 &repair_env_string);
73159
73160- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
73161+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
73162 do_one_initcall(*fn);
73163+
73164+#ifdef LATENT_ENTROPY_PLUGIN
73165+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73166+#endif
73167+
73168+ }
73169 }
73170
73171 static void __init do_initcalls(void)
73172@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
73173 {
73174 initcall_t *fn;
73175
73176- for (fn = __initcall_start; fn < __initcall0_start; fn++)
73177+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
73178 do_one_initcall(*fn);
73179+
73180+#ifdef LATENT_ENTROPY_PLUGIN
73181+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73182+#endif
73183+
73184+ }
73185 }
73186
73187 static int run_init_process(const char *init_filename)
73188@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
73189 do_basic_setup();
73190
73191 /* Open the /dev/console on the rootfs, this should never fail */
73192- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
73193+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
73194 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
73195
73196 (void) sys_dup(0);
73197@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
73198 if (!ramdisk_execute_command)
73199 ramdisk_execute_command = "/init";
73200
73201- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
73202+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
73203 ramdisk_execute_command = NULL;
73204 prepare_namespace();
73205 }
73206
73207+ grsecurity_init();
73208+
73209 /*
73210 * Ok, we have completed the initial bootup, and
73211 * we're essentially up and running. Get rid of the
73212diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
73213index 130dfec..cc88451 100644
73214--- a/ipc/ipc_sysctl.c
73215+++ b/ipc/ipc_sysctl.c
73216@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
73217 static int proc_ipc_dointvec(ctl_table *table, int write,
73218 void __user *buffer, size_t *lenp, loff_t *ppos)
73219 {
73220- struct ctl_table ipc_table;
73221+ ctl_table_no_const ipc_table;
73222
73223 memcpy(&ipc_table, table, sizeof(ipc_table));
73224 ipc_table.data = get_ipc(table);
73225@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
73226 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
73227 void __user *buffer, size_t *lenp, loff_t *ppos)
73228 {
73229- struct ctl_table ipc_table;
73230+ ctl_table_no_const ipc_table;
73231
73232 memcpy(&ipc_table, table, sizeof(ipc_table));
73233 ipc_table.data = get_ipc(table);
73234@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
73235 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73236 void __user *buffer, size_t *lenp, loff_t *ppos)
73237 {
73238- struct ctl_table ipc_table;
73239+ ctl_table_no_const ipc_table;
73240 size_t lenp_bef = *lenp;
73241 int rc;
73242
73243@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73244 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
73245 void __user *buffer, size_t *lenp, loff_t *ppos)
73246 {
73247- struct ctl_table ipc_table;
73248+ ctl_table_no_const ipc_table;
73249 memcpy(&ipc_table, table, sizeof(ipc_table));
73250 ipc_table.data = get_ipc(table);
73251
73252@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
73253 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
73254 void __user *buffer, size_t *lenp, loff_t *ppos)
73255 {
73256- struct ctl_table ipc_table;
73257+ ctl_table_no_const ipc_table;
73258 size_t lenp_bef = *lenp;
73259 int oldval;
73260 int rc;
73261diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
73262index 383d638..943fdbb 100644
73263--- a/ipc/mq_sysctl.c
73264+++ b/ipc/mq_sysctl.c
73265@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
73266 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
73267 void __user *buffer, size_t *lenp, loff_t *ppos)
73268 {
73269- struct ctl_table mq_table;
73270+ ctl_table_no_const mq_table;
73271 memcpy(&mq_table, table, sizeof(mq_table));
73272 mq_table.data = get_mq(table);
73273
73274diff --git a/ipc/mqueue.c b/ipc/mqueue.c
73275index 71a3ca1..cc330ee 100644
73276--- a/ipc/mqueue.c
73277+++ b/ipc/mqueue.c
73278@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
73279 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
73280 info->attr.mq_msgsize);
73281
73282+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
73283 spin_lock(&mq_lock);
73284 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
73285 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
73286diff --git a/ipc/msg.c b/ipc/msg.c
73287index 31cd1bf..362ea07 100644
73288--- a/ipc/msg.c
73289+++ b/ipc/msg.c
73290@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
73291 return security_msg_queue_associate(msq, msgflg);
73292 }
73293
73294+static struct ipc_ops msg_ops = {
73295+ .getnew = newque,
73296+ .associate = msg_security,
73297+ .more_checks = NULL
73298+};
73299+
73300 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
73301 {
73302 struct ipc_namespace *ns;
73303- struct ipc_ops msg_ops;
73304 struct ipc_params msg_params;
73305
73306 ns = current->nsproxy->ipc_ns;
73307
73308- msg_ops.getnew = newque;
73309- msg_ops.associate = msg_security;
73310- msg_ops.more_checks = NULL;
73311-
73312 msg_params.key = key;
73313 msg_params.flg = msgflg;
73314
73315diff --git a/ipc/sem.c b/ipc/sem.c
73316index 58d31f1..cce7a55 100644
73317--- a/ipc/sem.c
73318+++ b/ipc/sem.c
73319@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
73320 return 0;
73321 }
73322
73323+static struct ipc_ops sem_ops = {
73324+ .getnew = newary,
73325+ .associate = sem_security,
73326+ .more_checks = sem_more_checks
73327+};
73328+
73329 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73330 {
73331 struct ipc_namespace *ns;
73332- struct ipc_ops sem_ops;
73333 struct ipc_params sem_params;
73334
73335 ns = current->nsproxy->ipc_ns;
73336@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73337 if (nsems < 0 || nsems > ns->sc_semmsl)
73338 return -EINVAL;
73339
73340- sem_ops.getnew = newary;
73341- sem_ops.associate = sem_security;
73342- sem_ops.more_checks = sem_more_checks;
73343-
73344 sem_params.key = key;
73345 sem_params.flg = semflg;
73346 sem_params.u.nsems = nsems;
73347diff --git a/ipc/shm.c b/ipc/shm.c
73348index 4fa6d8f..55cff14 100644
73349--- a/ipc/shm.c
73350+++ b/ipc/shm.c
73351@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
73352 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
73353 #endif
73354
73355+#ifdef CONFIG_GRKERNSEC
73356+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73357+ const time_t shm_createtime, const kuid_t cuid,
73358+ const int shmid);
73359+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73360+ const time_t shm_createtime);
73361+#endif
73362+
73363 void shm_init_ns(struct ipc_namespace *ns)
73364 {
73365 ns->shm_ctlmax = SHMMAX;
73366@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
73367 shp->shm_lprid = 0;
73368 shp->shm_atim = shp->shm_dtim = 0;
73369 shp->shm_ctim = get_seconds();
73370+#ifdef CONFIG_GRKERNSEC
73371+ {
73372+ struct timespec timeval;
73373+ do_posix_clock_monotonic_gettime(&timeval);
73374+
73375+ shp->shm_createtime = timeval.tv_sec;
73376+ }
73377+#endif
73378 shp->shm_segsz = size;
73379 shp->shm_nattch = 0;
73380 shp->shm_file = file;
73381@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
73382 return 0;
73383 }
73384
73385+static struct ipc_ops shm_ops = {
73386+ .getnew = newseg,
73387+ .associate = shm_security,
73388+ .more_checks = shm_more_checks
73389+};
73390+
73391 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
73392 {
73393 struct ipc_namespace *ns;
73394- struct ipc_ops shm_ops;
73395 struct ipc_params shm_params;
73396
73397 ns = current->nsproxy->ipc_ns;
73398
73399- shm_ops.getnew = newseg;
73400- shm_ops.associate = shm_security;
73401- shm_ops.more_checks = shm_more_checks;
73402-
73403 shm_params.key = key;
73404 shm_params.flg = shmflg;
73405 shm_params.u.size = size;
73406@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73407 f_mode = FMODE_READ | FMODE_WRITE;
73408 }
73409 if (shmflg & SHM_EXEC) {
73410+
73411+#ifdef CONFIG_PAX_MPROTECT
73412+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
73413+ goto out;
73414+#endif
73415+
73416 prot |= PROT_EXEC;
73417 acc_mode |= S_IXUGO;
73418 }
73419@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73420 if (err)
73421 goto out_unlock;
73422
73423+#ifdef CONFIG_GRKERNSEC
73424+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
73425+ shp->shm_perm.cuid, shmid) ||
73426+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
73427+ err = -EACCES;
73428+ goto out_unlock;
73429+ }
73430+#endif
73431+
73432 path = shp->shm_file->f_path;
73433 path_get(&path);
73434 shp->shm_nattch++;
73435+#ifdef CONFIG_GRKERNSEC
73436+ shp->shm_lapid = current->pid;
73437+#endif
73438 size = i_size_read(path.dentry->d_inode);
73439 shm_unlock(shp);
73440
73441diff --git a/kernel/acct.c b/kernel/acct.c
73442index 051e071..15e0920 100644
73443--- a/kernel/acct.c
73444+++ b/kernel/acct.c
73445@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
73446 */
73447 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
73448 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
73449- file->f_op->write(file, (char *)&ac,
73450+ file->f_op->write(file, (char __force_user *)&ac,
73451 sizeof(acct_t), &file->f_pos);
73452 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
73453 set_fs(fs);
73454diff --git a/kernel/audit.c b/kernel/audit.c
73455index d596e53..dbef3c3 100644
73456--- a/kernel/audit.c
73457+++ b/kernel/audit.c
73458@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
73459 3) suppressed due to audit_rate_limit
73460 4) suppressed due to audit_backlog_limit
73461 */
73462-static atomic_t audit_lost = ATOMIC_INIT(0);
73463+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
73464
73465 /* The netlink socket. */
73466 static struct sock *audit_sock;
73467@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
73468 unsigned long now;
73469 int print;
73470
73471- atomic_inc(&audit_lost);
73472+ atomic_inc_unchecked(&audit_lost);
73473
73474 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
73475
73476@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
73477 printk(KERN_WARNING
73478 "audit: audit_lost=%d audit_rate_limit=%d "
73479 "audit_backlog_limit=%d\n",
73480- atomic_read(&audit_lost),
73481+ atomic_read_unchecked(&audit_lost),
73482 audit_rate_limit,
73483 audit_backlog_limit);
73484 audit_panic(message);
73485@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
73486 status_set.pid = audit_pid;
73487 status_set.rate_limit = audit_rate_limit;
73488 status_set.backlog_limit = audit_backlog_limit;
73489- status_set.lost = atomic_read(&audit_lost);
73490+ status_set.lost = atomic_read_unchecked(&audit_lost);
73491 status_set.backlog = skb_queue_len(&audit_skb_queue);
73492 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
73493 &status_set, sizeof(status_set));
73494diff --git a/kernel/auditsc.c b/kernel/auditsc.c
73495index a371f85..da826c1 100644
73496--- a/kernel/auditsc.c
73497+++ b/kernel/auditsc.c
73498@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
73499 }
73500
73501 /* global counter which is incremented every time something logs in */
73502-static atomic_t session_id = ATOMIC_INIT(0);
73503+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
73504
73505 /**
73506 * audit_set_loginuid - set current task's audit_context loginuid
73507@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
73508 return -EPERM;
73509 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
73510
73511- sessionid = atomic_inc_return(&session_id);
73512+ sessionid = atomic_inc_return_unchecked(&session_id);
73513 if (context && context->in_syscall) {
73514 struct audit_buffer *ab;
73515
73516diff --git a/kernel/capability.c b/kernel/capability.c
73517index 493d972..f87dfbd 100644
73518--- a/kernel/capability.c
73519+++ b/kernel/capability.c
73520@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
73521 * before modification is attempted and the application
73522 * fails.
73523 */
73524+ if (tocopy > ARRAY_SIZE(kdata))
73525+ return -EFAULT;
73526+
73527 if (copy_to_user(dataptr, kdata, tocopy
73528 * sizeof(struct __user_cap_data_struct))) {
73529 return -EFAULT;
73530@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
73531 int ret;
73532
73533 rcu_read_lock();
73534- ret = security_capable(__task_cred(t), ns, cap);
73535+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
73536+ gr_task_is_capable(t, __task_cred(t), cap);
73537 rcu_read_unlock();
73538
73539- return (ret == 0);
73540+ return ret;
73541 }
73542
73543 /**
73544@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
73545 int ret;
73546
73547 rcu_read_lock();
73548- ret = security_capable_noaudit(__task_cred(t), ns, cap);
73549+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
73550 rcu_read_unlock();
73551
73552- return (ret == 0);
73553+ return ret;
73554 }
73555
73556 /**
73557@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
73558 BUG();
73559 }
73560
73561- if (security_capable(current_cred(), ns, cap) == 0) {
73562+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
73563 current->flags |= PF_SUPERPRIV;
73564 return true;
73565 }
73566@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
73567 }
73568 EXPORT_SYMBOL(ns_capable);
73569
73570+bool ns_capable_nolog(struct user_namespace *ns, int cap)
73571+{
73572+ if (unlikely(!cap_valid(cap))) {
73573+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
73574+ BUG();
73575+ }
73576+
73577+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
73578+ current->flags |= PF_SUPERPRIV;
73579+ return true;
73580+ }
73581+ return false;
73582+}
73583+EXPORT_SYMBOL(ns_capable_nolog);
73584+
73585 /**
73586 * capable - Determine if the current task has a superior capability in effect
73587 * @cap: The capability to be tested for
73588@@ -408,6 +427,12 @@ bool capable(int cap)
73589 }
73590 EXPORT_SYMBOL(capable);
73591
73592+bool capable_nolog(int cap)
73593+{
73594+ return ns_capable_nolog(&init_user_ns, cap);
73595+}
73596+EXPORT_SYMBOL(capable_nolog);
73597+
73598 /**
73599 * nsown_capable - Check superior capability to one's own user_ns
73600 * @cap: The capability in question
73601@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
73602
73603 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73604 }
73605+
73606+bool inode_capable_nolog(const struct inode *inode, int cap)
73607+{
73608+ struct user_namespace *ns = current_user_ns();
73609+
73610+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73611+}
73612diff --git a/kernel/cgroup.c b/kernel/cgroup.c
73613index 1e23664..570a83d 100644
73614--- a/kernel/cgroup.c
73615+++ b/kernel/cgroup.c
73616@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
73617 struct css_set *cg = link->cg;
73618 struct task_struct *task;
73619 int count = 0;
73620- seq_printf(seq, "css_set %p\n", cg);
73621+ seq_printf(seq, "css_set %pK\n", cg);
73622 list_for_each_entry(task, &cg->tasks, cg_list) {
73623 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
73624 seq_puts(seq, " ...\n");
73625diff --git a/kernel/compat.c b/kernel/compat.c
73626index 36700e9..73d770c 100644
73627--- a/kernel/compat.c
73628+++ b/kernel/compat.c
73629@@ -13,6 +13,7 @@
73630
73631 #include <linux/linkage.h>
73632 #include <linux/compat.h>
73633+#include <linux/module.h>
73634 #include <linux/errno.h>
73635 #include <linux/time.h>
73636 #include <linux/signal.h>
73637@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
73638 mm_segment_t oldfs;
73639 long ret;
73640
73641- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
73642+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
73643 oldfs = get_fs();
73644 set_fs(KERNEL_DS);
73645 ret = hrtimer_nanosleep_restart(restart);
73646@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
73647 oldfs = get_fs();
73648 set_fs(KERNEL_DS);
73649 ret = hrtimer_nanosleep(&tu,
73650- rmtp ? (struct timespec __user *)&rmt : NULL,
73651+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
73652 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
73653 set_fs(oldfs);
73654
73655@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
73656 mm_segment_t old_fs = get_fs();
73657
73658 set_fs(KERNEL_DS);
73659- ret = sys_sigpending((old_sigset_t __user *) &s);
73660+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
73661 set_fs(old_fs);
73662 if (ret == 0)
73663 ret = put_user(s, set);
73664@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
73665 mm_segment_t old_fs = get_fs();
73666
73667 set_fs(KERNEL_DS);
73668- ret = sys_old_getrlimit(resource, &r);
73669+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
73670 set_fs(old_fs);
73671
73672 if (!ret) {
73673@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
73674 mm_segment_t old_fs = get_fs();
73675
73676 set_fs(KERNEL_DS);
73677- ret = sys_getrusage(who, (struct rusage __user *) &r);
73678+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
73679 set_fs(old_fs);
73680
73681 if (ret)
73682@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
73683 set_fs (KERNEL_DS);
73684 ret = sys_wait4(pid,
73685 (stat_addr ?
73686- (unsigned int __user *) &status : NULL),
73687- options, (struct rusage __user *) &r);
73688+ (unsigned int __force_user *) &status : NULL),
73689+ options, (struct rusage __force_user *) &r);
73690 set_fs (old_fs);
73691
73692 if (ret > 0) {
73693@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
73694 memset(&info, 0, sizeof(info));
73695
73696 set_fs(KERNEL_DS);
73697- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
73698- uru ? (struct rusage __user *)&ru : NULL);
73699+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
73700+ uru ? (struct rusage __force_user *)&ru : NULL);
73701 set_fs(old_fs);
73702
73703 if ((ret < 0) || (info.si_signo == 0))
73704@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
73705 oldfs = get_fs();
73706 set_fs(KERNEL_DS);
73707 err = sys_timer_settime(timer_id, flags,
73708- (struct itimerspec __user *) &newts,
73709- (struct itimerspec __user *) &oldts);
73710+ (struct itimerspec __force_user *) &newts,
73711+ (struct itimerspec __force_user *) &oldts);
73712 set_fs(oldfs);
73713 if (!err && old && put_compat_itimerspec(old, &oldts))
73714 return -EFAULT;
73715@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
73716 oldfs = get_fs();
73717 set_fs(KERNEL_DS);
73718 err = sys_timer_gettime(timer_id,
73719- (struct itimerspec __user *) &ts);
73720+ (struct itimerspec __force_user *) &ts);
73721 set_fs(oldfs);
73722 if (!err && put_compat_itimerspec(setting, &ts))
73723 return -EFAULT;
73724@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
73725 oldfs = get_fs();
73726 set_fs(KERNEL_DS);
73727 err = sys_clock_settime(which_clock,
73728- (struct timespec __user *) &ts);
73729+ (struct timespec __force_user *) &ts);
73730 set_fs(oldfs);
73731 return err;
73732 }
73733@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
73734 oldfs = get_fs();
73735 set_fs(KERNEL_DS);
73736 err = sys_clock_gettime(which_clock,
73737- (struct timespec __user *) &ts);
73738+ (struct timespec __force_user *) &ts);
73739 set_fs(oldfs);
73740 if (!err && put_compat_timespec(&ts, tp))
73741 return -EFAULT;
73742@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
73743
73744 oldfs = get_fs();
73745 set_fs(KERNEL_DS);
73746- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
73747+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
73748 set_fs(oldfs);
73749
73750 err = compat_put_timex(utp, &txc);
73751@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
73752 oldfs = get_fs();
73753 set_fs(KERNEL_DS);
73754 err = sys_clock_getres(which_clock,
73755- (struct timespec __user *) &ts);
73756+ (struct timespec __force_user *) &ts);
73757 set_fs(oldfs);
73758 if (!err && tp && put_compat_timespec(&ts, tp))
73759 return -EFAULT;
73760@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
73761 long err;
73762 mm_segment_t oldfs;
73763 struct timespec tu;
73764- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
73765+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
73766
73767- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
73768+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
73769 oldfs = get_fs();
73770 set_fs(KERNEL_DS);
73771 err = clock_nanosleep_restart(restart);
73772@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
73773 oldfs = get_fs();
73774 set_fs(KERNEL_DS);
73775 err = sys_clock_nanosleep(which_clock, flags,
73776- (struct timespec __user *) &in,
73777- (struct timespec __user *) &out);
73778+ (struct timespec __force_user *) &in,
73779+ (struct timespec __force_user *) &out);
73780 set_fs(oldfs);
73781
73782 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
73783diff --git a/kernel/configs.c b/kernel/configs.c
73784index 42e8fa0..9e7406b 100644
73785--- a/kernel/configs.c
73786+++ b/kernel/configs.c
73787@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
73788 struct proc_dir_entry *entry;
73789
73790 /* create the current config file */
73791+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
73792+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
73793+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73794+ &ikconfig_file_ops);
73795+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73796+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73797+ &ikconfig_file_ops);
73798+#endif
73799+#else
73800 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73801 &ikconfig_file_ops);
73802+#endif
73803+
73804 if (!entry)
73805 return -ENOMEM;
73806
73807diff --git a/kernel/cred.c b/kernel/cred.c
73808index e0573a4..3874e41 100644
73809--- a/kernel/cred.c
73810+++ b/kernel/cred.c
73811@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73812 validate_creds(cred);
73813 alter_cred_subscribers(cred, -1);
73814 put_cred(cred);
73815+
73816+#ifdef CONFIG_GRKERNSEC_SETXID
73817+ cred = (struct cred *) tsk->delayed_cred;
73818+ if (cred != NULL) {
73819+ tsk->delayed_cred = NULL;
73820+ validate_creds(cred);
73821+ alter_cred_subscribers(cred, -1);
73822+ put_cred(cred);
73823+ }
73824+#endif
73825 }
73826
73827 /**
73828@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73829 * Always returns 0 thus allowing this function to be tail-called at the end
73830 * of, say, sys_setgid().
73831 */
73832-int commit_creds(struct cred *new)
73833+static int __commit_creds(struct cred *new)
73834 {
73835 struct task_struct *task = current;
73836 const struct cred *old = task->real_cred;
73837@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73838
73839 get_cred(new); /* we will require a ref for the subj creds too */
73840
73841+ gr_set_role_label(task, new->uid, new->gid);
73842+
73843 /* dumpability changes */
73844 if (!uid_eq(old->euid, new->euid) ||
73845 !gid_eq(old->egid, new->egid) ||
73846@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73847 put_cred(old);
73848 return 0;
73849 }
73850+#ifdef CONFIG_GRKERNSEC_SETXID
73851+extern int set_user(struct cred *new);
73852+
73853+void gr_delayed_cred_worker(void)
73854+{
73855+ const struct cred *new = current->delayed_cred;
73856+ struct cred *ncred;
73857+
73858+ current->delayed_cred = NULL;
73859+
73860+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73861+ // from doing get_cred on it when queueing this
73862+ put_cred(new);
73863+ return;
73864+ } else if (new == NULL)
73865+ return;
73866+
73867+ ncred = prepare_creds();
73868+ if (!ncred)
73869+ goto die;
73870+ // uids
73871+ ncred->uid = new->uid;
73872+ ncred->euid = new->euid;
73873+ ncred->suid = new->suid;
73874+ ncred->fsuid = new->fsuid;
73875+ // gids
73876+ ncred->gid = new->gid;
73877+ ncred->egid = new->egid;
73878+ ncred->sgid = new->sgid;
73879+ ncred->fsgid = new->fsgid;
73880+ // groups
73881+ if (set_groups(ncred, new->group_info) < 0) {
73882+ abort_creds(ncred);
73883+ goto die;
73884+ }
73885+ // caps
73886+ ncred->securebits = new->securebits;
73887+ ncred->cap_inheritable = new->cap_inheritable;
73888+ ncred->cap_permitted = new->cap_permitted;
73889+ ncred->cap_effective = new->cap_effective;
73890+ ncred->cap_bset = new->cap_bset;
73891+
73892+ if (set_user(ncred)) {
73893+ abort_creds(ncred);
73894+ goto die;
73895+ }
73896+
73897+ // from doing get_cred on it when queueing this
73898+ put_cred(new);
73899+
73900+ __commit_creds(ncred);
73901+ return;
73902+die:
73903+ // from doing get_cred on it when queueing this
73904+ put_cred(new);
73905+ do_group_exit(SIGKILL);
73906+}
73907+#endif
73908+
73909+int commit_creds(struct cred *new)
73910+{
73911+#ifdef CONFIG_GRKERNSEC_SETXID
73912+ int ret;
73913+ int schedule_it = 0;
73914+ struct task_struct *t;
73915+
73916+ /* we won't get called with tasklist_lock held for writing
73917+ and interrupts disabled as the cred struct in that case is
73918+ init_cred
73919+ */
73920+ if (grsec_enable_setxid && !current_is_single_threaded() &&
73921+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73922+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73923+ schedule_it = 1;
73924+ }
73925+ ret = __commit_creds(new);
73926+ if (schedule_it) {
73927+ rcu_read_lock();
73928+ read_lock(&tasklist_lock);
73929+ for (t = next_thread(current); t != current;
73930+ t = next_thread(t)) {
73931+ if (t->delayed_cred == NULL) {
73932+ t->delayed_cred = get_cred(new);
73933+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73934+ set_tsk_need_resched(t);
73935+ }
73936+ }
73937+ read_unlock(&tasklist_lock);
73938+ rcu_read_unlock();
73939+ }
73940+ return ret;
73941+#else
73942+ return __commit_creds(new);
73943+#endif
73944+}
73945+
73946 EXPORT_SYMBOL(commit_creds);
73947
73948 /**
73949diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73950index 9a61738..c5c8f3a 100644
73951--- a/kernel/debug/debug_core.c
73952+++ b/kernel/debug/debug_core.c
73953@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73954 */
73955 static atomic_t masters_in_kgdb;
73956 static atomic_t slaves_in_kgdb;
73957-static atomic_t kgdb_break_tasklet_var;
73958+static atomic_unchecked_t kgdb_break_tasklet_var;
73959 atomic_t kgdb_setting_breakpoint;
73960
73961 struct task_struct *kgdb_usethread;
73962@@ -132,7 +132,7 @@ int kgdb_single_step;
73963 static pid_t kgdb_sstep_pid;
73964
73965 /* to keep track of the CPU which is doing the single stepping*/
73966-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73967+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73968
73969 /*
73970 * If you are debugging a problem where roundup (the collection of
73971@@ -540,7 +540,7 @@ return_normal:
73972 * kernel will only try for the value of sstep_tries before
73973 * giving up and continuing on.
73974 */
73975- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73976+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73977 (kgdb_info[cpu].task &&
73978 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73979 atomic_set(&kgdb_active, -1);
73980@@ -634,8 +634,8 @@ cpu_master_loop:
73981 }
73982
73983 kgdb_restore:
73984- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73985- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73986+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73987+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73988 if (kgdb_info[sstep_cpu].task)
73989 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73990 else
73991@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73992 static void kgdb_tasklet_bpt(unsigned long ing)
73993 {
73994 kgdb_breakpoint();
73995- atomic_set(&kgdb_break_tasklet_var, 0);
73996+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73997 }
73998
73999 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
74000
74001 void kgdb_schedule_breakpoint(void)
74002 {
74003- if (atomic_read(&kgdb_break_tasklet_var) ||
74004+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
74005 atomic_read(&kgdb_active) != -1 ||
74006 atomic_read(&kgdb_setting_breakpoint))
74007 return;
74008- atomic_inc(&kgdb_break_tasklet_var);
74009+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
74010 tasklet_schedule(&kgdb_tasklet_breakpoint);
74011 }
74012 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
74013diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
74014index 8875254..7cf4928 100644
74015--- a/kernel/debug/kdb/kdb_main.c
74016+++ b/kernel/debug/kdb/kdb_main.c
74017@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
74018 continue;
74019
74020 kdb_printf("%-20s%8u 0x%p ", mod->name,
74021- mod->core_size, (void *)mod);
74022+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
74023 #ifdef CONFIG_MODULE_UNLOAD
74024 kdb_printf("%4ld ", module_refcount(mod));
74025 #endif
74026@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
74027 kdb_printf(" (Loading)");
74028 else
74029 kdb_printf(" (Live)");
74030- kdb_printf(" 0x%p", mod->module_core);
74031+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
74032
74033 #ifdef CONFIG_MODULE_UNLOAD
74034 {
74035diff --git a/kernel/events/core.c b/kernel/events/core.c
74036index 7b6646a..3cb1135 100644
74037--- a/kernel/events/core.c
74038+++ b/kernel/events/core.c
74039@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
74040 return 0;
74041 }
74042
74043-static atomic64_t perf_event_id;
74044+static atomic64_unchecked_t perf_event_id;
74045
74046 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
74047 enum event_type_t event_type);
74048@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
74049
74050 static inline u64 perf_event_count(struct perf_event *event)
74051 {
74052- return local64_read(&event->count) + atomic64_read(&event->child_count);
74053+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
74054 }
74055
74056 static u64 perf_event_read(struct perf_event *event)
74057@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
74058 mutex_lock(&event->child_mutex);
74059 total += perf_event_read(event);
74060 *enabled += event->total_time_enabled +
74061- atomic64_read(&event->child_total_time_enabled);
74062+ atomic64_read_unchecked(&event->child_total_time_enabled);
74063 *running += event->total_time_running +
74064- atomic64_read(&event->child_total_time_running);
74065+ atomic64_read_unchecked(&event->child_total_time_running);
74066
74067 list_for_each_entry(child, &event->child_list, child_list) {
74068 total += perf_event_read(child);
74069@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
74070 userpg->offset -= local64_read(&event->hw.prev_count);
74071
74072 userpg->time_enabled = enabled +
74073- atomic64_read(&event->child_total_time_enabled);
74074+ atomic64_read_unchecked(&event->child_total_time_enabled);
74075
74076 userpg->time_running = running +
74077- atomic64_read(&event->child_total_time_running);
74078+ atomic64_read_unchecked(&event->child_total_time_running);
74079
74080 arch_perf_update_userpage(userpg, now);
74081
74082@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
74083 values[n++] = perf_event_count(event);
74084 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
74085 values[n++] = enabled +
74086- atomic64_read(&event->child_total_time_enabled);
74087+ atomic64_read_unchecked(&event->child_total_time_enabled);
74088 }
74089 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
74090 values[n++] = running +
74091- atomic64_read(&event->child_total_time_running);
74092+ atomic64_read_unchecked(&event->child_total_time_running);
74093 }
74094 if (read_format & PERF_FORMAT_ID)
74095 values[n++] = primary_event_id(event);
74096@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
74097 * need to add enough zero bytes after the string to handle
74098 * the 64bit alignment we do later.
74099 */
74100- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
74101+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
74102 if (!buf) {
74103 name = strncpy(tmp, "//enomem", sizeof(tmp));
74104 goto got_name;
74105 }
74106- name = d_path(&file->f_path, buf, PATH_MAX);
74107+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
74108 if (IS_ERR(name)) {
74109 name = strncpy(tmp, "//toolong", sizeof(tmp));
74110 goto got_name;
74111@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
74112 event->parent = parent_event;
74113
74114 event->ns = get_pid_ns(task_active_pid_ns(current));
74115- event->id = atomic64_inc_return(&perf_event_id);
74116+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
74117
74118 event->state = PERF_EVENT_STATE_INACTIVE;
74119
74120@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
74121 /*
74122 * Add back the child's count to the parent's count:
74123 */
74124- atomic64_add(child_val, &parent_event->child_count);
74125- atomic64_add(child_event->total_time_enabled,
74126+ atomic64_add_unchecked(child_val, &parent_event->child_count);
74127+ atomic64_add_unchecked(child_event->total_time_enabled,
74128 &parent_event->child_total_time_enabled);
74129- atomic64_add(child_event->total_time_running,
74130+ atomic64_add_unchecked(child_event->total_time_running,
74131 &parent_event->child_total_time_running);
74132
74133 /*
74134diff --git a/kernel/exit.c b/kernel/exit.c
74135index b4df219..f13c02d 100644
74136--- a/kernel/exit.c
74137+++ b/kernel/exit.c
74138@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
74139 struct task_struct *leader;
74140 int zap_leader;
74141 repeat:
74142+#ifdef CONFIG_NET
74143+ gr_del_task_from_ip_table(p);
74144+#endif
74145+
74146 /* don't need to get the RCU readlock here - the process is dead and
74147 * can't be modifying its own credentials. But shut RCU-lockdep up */
74148 rcu_read_lock();
74149@@ -338,7 +342,7 @@ int allow_signal(int sig)
74150 * know it'll be handled, so that they don't get converted to
74151 * SIGKILL or just silently dropped.
74152 */
74153- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
74154+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
74155 recalc_sigpending();
74156 spin_unlock_irq(&current->sighand->siglock);
74157 return 0;
74158@@ -708,6 +712,8 @@ void do_exit(long code)
74159 struct task_struct *tsk = current;
74160 int group_dead;
74161
74162+ set_fs(USER_DS);
74163+
74164 profile_task_exit(tsk);
74165
74166 WARN_ON(blk_needs_flush_plug(tsk));
74167@@ -724,7 +730,6 @@ void do_exit(long code)
74168 * mm_release()->clear_child_tid() from writing to a user-controlled
74169 * kernel address.
74170 */
74171- set_fs(USER_DS);
74172
74173 ptrace_event(PTRACE_EVENT_EXIT, code);
74174
74175@@ -783,6 +788,9 @@ void do_exit(long code)
74176 tsk->exit_code = code;
74177 taskstats_exit(tsk, group_dead);
74178
74179+ gr_acl_handle_psacct(tsk, code);
74180+ gr_acl_handle_exit();
74181+
74182 exit_mm(tsk);
74183
74184 if (group_dead)
74185@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
74186 * Take down every thread in the group. This is called by fatal signals
74187 * as well as by sys_exit_group (below).
74188 */
74189-void
74190+__noreturn void
74191 do_group_exit(int exit_code)
74192 {
74193 struct signal_struct *sig = current->signal;
74194diff --git a/kernel/fork.c b/kernel/fork.c
74195index 5630e52..0cee608 100644
74196--- a/kernel/fork.c
74197+++ b/kernel/fork.c
74198@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
74199 *stackend = STACK_END_MAGIC; /* for overflow detection */
74200
74201 #ifdef CONFIG_CC_STACKPROTECTOR
74202- tsk->stack_canary = get_random_int();
74203+ tsk->stack_canary = pax_get_random_long();
74204 #endif
74205
74206 /*
74207@@ -344,13 +344,81 @@ free_tsk:
74208 }
74209
74210 #ifdef CONFIG_MMU
74211+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
74212+{
74213+ struct vm_area_struct *tmp;
74214+ unsigned long charge;
74215+ struct mempolicy *pol;
74216+ struct file *file;
74217+
74218+ charge = 0;
74219+ if (mpnt->vm_flags & VM_ACCOUNT) {
74220+ unsigned long len = vma_pages(mpnt);
74221+
74222+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74223+ goto fail_nomem;
74224+ charge = len;
74225+ }
74226+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74227+ if (!tmp)
74228+ goto fail_nomem;
74229+ *tmp = *mpnt;
74230+ tmp->vm_mm = mm;
74231+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
74232+ pol = mpol_dup(vma_policy(mpnt));
74233+ if (IS_ERR(pol))
74234+ goto fail_nomem_policy;
74235+ vma_set_policy(tmp, pol);
74236+ if (anon_vma_fork(tmp, mpnt))
74237+ goto fail_nomem_anon_vma_fork;
74238+ tmp->vm_flags &= ~VM_LOCKED;
74239+ tmp->vm_next = tmp->vm_prev = NULL;
74240+ tmp->vm_mirror = NULL;
74241+ file = tmp->vm_file;
74242+ if (file) {
74243+ struct inode *inode = file->f_path.dentry->d_inode;
74244+ struct address_space *mapping = file->f_mapping;
74245+
74246+ get_file(file);
74247+ if (tmp->vm_flags & VM_DENYWRITE)
74248+ atomic_dec(&inode->i_writecount);
74249+ mutex_lock(&mapping->i_mmap_mutex);
74250+ if (tmp->vm_flags & VM_SHARED)
74251+ mapping->i_mmap_writable++;
74252+ flush_dcache_mmap_lock(mapping);
74253+ /* insert tmp into the share list, just after mpnt */
74254+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74255+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
74256+ else
74257+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
74258+ flush_dcache_mmap_unlock(mapping);
74259+ mutex_unlock(&mapping->i_mmap_mutex);
74260+ }
74261+
74262+ /*
74263+ * Clear hugetlb-related page reserves for children. This only
74264+ * affects MAP_PRIVATE mappings. Faults generated by the child
74265+ * are not guaranteed to succeed, even if read-only
74266+ */
74267+ if (is_vm_hugetlb_page(tmp))
74268+ reset_vma_resv_huge_pages(tmp);
74269+
74270+ return tmp;
74271+
74272+fail_nomem_anon_vma_fork:
74273+ mpol_put(pol);
74274+fail_nomem_policy:
74275+ kmem_cache_free(vm_area_cachep, tmp);
74276+fail_nomem:
74277+ vm_unacct_memory(charge);
74278+ return NULL;
74279+}
74280+
74281 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74282 {
74283 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
74284 struct rb_node **rb_link, *rb_parent;
74285 int retval;
74286- unsigned long charge;
74287- struct mempolicy *pol;
74288
74289 uprobe_start_dup_mmap();
74290 down_write(&oldmm->mmap_sem);
74291@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74292 mm->locked_vm = 0;
74293 mm->mmap = NULL;
74294 mm->mmap_cache = NULL;
74295- mm->free_area_cache = oldmm->mmap_base;
74296- mm->cached_hole_size = ~0UL;
74297+ mm->free_area_cache = oldmm->free_area_cache;
74298+ mm->cached_hole_size = oldmm->cached_hole_size;
74299 mm->map_count = 0;
74300 cpumask_clear(mm_cpumask(mm));
74301 mm->mm_rb = RB_ROOT;
74302@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74303
74304 prev = NULL;
74305 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
74306- struct file *file;
74307-
74308 if (mpnt->vm_flags & VM_DONTCOPY) {
74309 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
74310 -vma_pages(mpnt));
74311 continue;
74312 }
74313- charge = 0;
74314- if (mpnt->vm_flags & VM_ACCOUNT) {
74315- unsigned long len = vma_pages(mpnt);
74316-
74317- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74318- goto fail_nomem;
74319- charge = len;
74320- }
74321- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74322- if (!tmp)
74323- goto fail_nomem;
74324- *tmp = *mpnt;
74325- INIT_LIST_HEAD(&tmp->anon_vma_chain);
74326- pol = mpol_dup(vma_policy(mpnt));
74327- retval = PTR_ERR(pol);
74328- if (IS_ERR(pol))
74329- goto fail_nomem_policy;
74330- vma_set_policy(tmp, pol);
74331- tmp->vm_mm = mm;
74332- if (anon_vma_fork(tmp, mpnt))
74333- goto fail_nomem_anon_vma_fork;
74334- tmp->vm_flags &= ~VM_LOCKED;
74335- tmp->vm_next = tmp->vm_prev = NULL;
74336- file = tmp->vm_file;
74337- if (file) {
74338- struct inode *inode = file->f_path.dentry->d_inode;
74339- struct address_space *mapping = file->f_mapping;
74340-
74341- get_file(file);
74342- if (tmp->vm_flags & VM_DENYWRITE)
74343- atomic_dec(&inode->i_writecount);
74344- mutex_lock(&mapping->i_mmap_mutex);
74345- if (tmp->vm_flags & VM_SHARED)
74346- mapping->i_mmap_writable++;
74347- flush_dcache_mmap_lock(mapping);
74348- /* insert tmp into the share list, just after mpnt */
74349- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74350- vma_nonlinear_insert(tmp,
74351- &mapping->i_mmap_nonlinear);
74352- else
74353- vma_interval_tree_insert_after(tmp, mpnt,
74354- &mapping->i_mmap);
74355- flush_dcache_mmap_unlock(mapping);
74356- mutex_unlock(&mapping->i_mmap_mutex);
74357+ tmp = dup_vma(mm, oldmm, mpnt);
74358+ if (!tmp) {
74359+ retval = -ENOMEM;
74360+ goto out;
74361 }
74362
74363 /*
74364@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74365 if (retval)
74366 goto out;
74367 }
74368+
74369+#ifdef CONFIG_PAX_SEGMEXEC
74370+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
74371+ struct vm_area_struct *mpnt_m;
74372+
74373+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
74374+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
74375+
74376+ if (!mpnt->vm_mirror)
74377+ continue;
74378+
74379+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
74380+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
74381+ mpnt->vm_mirror = mpnt_m;
74382+ } else {
74383+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
74384+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
74385+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
74386+ mpnt->vm_mirror->vm_mirror = mpnt;
74387+ }
74388+ }
74389+ BUG_ON(mpnt_m);
74390+ }
74391+#endif
74392+
74393 /* a new mm has just been created */
74394 arch_dup_mmap(oldmm, mm);
74395 retval = 0;
74396@@ -472,14 +523,6 @@ out:
74397 up_write(&oldmm->mmap_sem);
74398 uprobe_end_dup_mmap();
74399 return retval;
74400-fail_nomem_anon_vma_fork:
74401- mpol_put(pol);
74402-fail_nomem_policy:
74403- kmem_cache_free(vm_area_cachep, tmp);
74404-fail_nomem:
74405- retval = -ENOMEM;
74406- vm_unacct_memory(charge);
74407- goto out;
74408 }
74409
74410 static inline int mm_alloc_pgd(struct mm_struct *mm)
74411@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
74412 return ERR_PTR(err);
74413
74414 mm = get_task_mm(task);
74415- if (mm && mm != current->mm &&
74416- !ptrace_may_access(task, mode)) {
74417+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
74418+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
74419 mmput(mm);
74420 mm = ERR_PTR(-EACCES);
74421 }
74422@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
74423 spin_unlock(&fs->lock);
74424 return -EAGAIN;
74425 }
74426- fs->users++;
74427+ atomic_inc(&fs->users);
74428 spin_unlock(&fs->lock);
74429 return 0;
74430 }
74431 tsk->fs = copy_fs_struct(fs);
74432 if (!tsk->fs)
74433 return -ENOMEM;
74434+ /* Carry through gr_chroot_dentry and is_chrooted instead
74435+ of recomputing it here. Already copied when the task struct
74436+ is duplicated. This allows pivot_root to not be treated as
74437+ a chroot
74438+ */
74439+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
74440+
74441 return 0;
74442 }
74443
74444@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74445 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
74446 #endif
74447 retval = -EAGAIN;
74448+
74449+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
74450+
74451 if (atomic_read(&p->real_cred->user->processes) >=
74452 task_rlimit(p, RLIMIT_NPROC)) {
74453 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
74454@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74455 goto bad_fork_free_pid;
74456 }
74457
74458+ /* synchronizes with gr_set_acls()
74459+ we need to call this past the point of no return for fork()
74460+ */
74461+ gr_copy_label(p);
74462+
74463 if (clone_flags & CLONE_THREAD) {
74464 current->signal->nr_threads++;
74465 atomic_inc(&current->signal->live);
74466@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
74467 bad_fork_free:
74468 free_task(p);
74469 fork_out:
74470+ gr_log_forkfail(retval);
74471+
74472 return ERR_PTR(retval);
74473 }
74474
74475@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
74476 return -EINVAL;
74477 }
74478
74479+#ifdef CONFIG_GRKERNSEC
74480+ if (clone_flags & CLONE_NEWUSER) {
74481+ /*
74482+ * This doesn't really inspire confidence:
74483+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
74484+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
74485+ * Increases kernel attack surface in areas developers
74486+ * previously cared little about ("low importance due
74487+ * to requiring "root" capability")
74488+ * To be removed when this code receives *proper* review
74489+ */
74490+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
74491+ !capable(CAP_SETGID))
74492+ return -EPERM;
74493+ }
74494+#endif
74495+
74496 /*
74497 * Determine whether and which event to report to ptracer. When
74498 * called from kernel_thread or CLONE_UNTRACED is explicitly
74499@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
74500 if (clone_flags & CLONE_PARENT_SETTID)
74501 put_user(nr, parent_tidptr);
74502
74503+ gr_handle_brute_check();
74504+
74505 if (clone_flags & CLONE_VFORK) {
74506 p->vfork_done = &vfork;
74507 init_completion(&vfork);
74508@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
74509 return 0;
74510
74511 /* don't need lock here; in the worst case we'll do useless copy */
74512- if (fs->users == 1)
74513+ if (atomic_read(&fs->users) == 1)
74514 return 0;
74515
74516 *new_fsp = copy_fs_struct(fs);
74517@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
74518 fs = current->fs;
74519 spin_lock(&fs->lock);
74520 current->fs = new_fs;
74521- if (--fs->users)
74522+ gr_set_chroot_entries(current, &current->fs->root);
74523+ if (atomic_dec_return(&fs->users))
74524 new_fs = NULL;
74525 else
74526 new_fs = fs;
74527diff --git a/kernel/futex.c b/kernel/futex.c
74528index 8879430..31696f1 100644
74529--- a/kernel/futex.c
74530+++ b/kernel/futex.c
74531@@ -54,6 +54,7 @@
74532 #include <linux/mount.h>
74533 #include <linux/pagemap.h>
74534 #include <linux/syscalls.h>
74535+#include <linux/ptrace.h>
74536 #include <linux/signal.h>
74537 #include <linux/export.h>
74538 #include <linux/magic.h>
74539@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
74540 struct page *page, *page_head;
74541 int err, ro = 0;
74542
74543+#ifdef CONFIG_PAX_SEGMEXEC
74544+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
74545+ return -EFAULT;
74546+#endif
74547+
74548 /*
74549 * The futex address must be "naturally" aligned.
74550 */
74551@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
74552 {
74553 u32 curval;
74554 int i;
74555+ mm_segment_t oldfs;
74556
74557 /*
74558 * This will fail and we want it. Some arch implementations do
74559@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
74560 * implementation, the non-functional ones will return
74561 * -ENOSYS.
74562 */
74563+ oldfs = get_fs();
74564+ set_fs(USER_DS);
74565 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
74566 futex_cmpxchg_enabled = 1;
74567+ set_fs(oldfs);
74568
74569 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
74570 plist_head_init(&futex_queues[i].chain);
74571diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
74572index 9b22d03..6295b62 100644
74573--- a/kernel/gcov/base.c
74574+++ b/kernel/gcov/base.c
74575@@ -102,11 +102,6 @@ void gcov_enable_events(void)
74576 }
74577
74578 #ifdef CONFIG_MODULES
74579-static inline int within(void *addr, void *start, unsigned long size)
74580-{
74581- return ((addr >= start) && (addr < start + size));
74582-}
74583-
74584 /* Update list and generate events when modules are unloaded. */
74585 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74586 void *data)
74587@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74588 prev = NULL;
74589 /* Remove entries located in module from linked list. */
74590 for (info = gcov_info_head; info; info = info->next) {
74591- if (within(info, mod->module_core, mod->core_size)) {
74592+ if (within_module_core_rw((unsigned long)info, mod)) {
74593 if (prev)
74594 prev->next = info->next;
74595 else
74596diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
74597index cdd5607..c3fc919 100644
74598--- a/kernel/hrtimer.c
74599+++ b/kernel/hrtimer.c
74600@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
74601 local_irq_restore(flags);
74602 }
74603
74604-static void run_hrtimer_softirq(struct softirq_action *h)
74605+static void run_hrtimer_softirq(void)
74606 {
74607 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
74608
74609@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
74610 return NOTIFY_OK;
74611 }
74612
74613-static struct notifier_block __cpuinitdata hrtimers_nb = {
74614+static struct notifier_block hrtimers_nb = {
74615 .notifier_call = hrtimer_cpu_notify,
74616 };
74617
74618diff --git a/kernel/jump_label.c b/kernel/jump_label.c
74619index 60f48fa..7f3a770 100644
74620--- a/kernel/jump_label.c
74621+++ b/kernel/jump_label.c
74622@@ -13,6 +13,7 @@
74623 #include <linux/sort.h>
74624 #include <linux/err.h>
74625 #include <linux/static_key.h>
74626+#include <linux/mm.h>
74627
74628 #ifdef HAVE_JUMP_LABEL
74629
74630@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
74631
74632 size = (((unsigned long)stop - (unsigned long)start)
74633 / sizeof(struct jump_entry));
74634+ pax_open_kernel();
74635 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
74636+ pax_close_kernel();
74637 }
74638
74639 static void jump_label_update(struct static_key *key, int enable);
74640@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
74641 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
74642 struct jump_entry *iter;
74643
74644+ pax_open_kernel();
74645 for (iter = iter_start; iter < iter_stop; iter++) {
74646 if (within_module_init(iter->code, mod))
74647 iter->code = 0;
74648 }
74649+ pax_close_kernel();
74650 }
74651
74652 static int
74653diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
74654index 2169fee..706ccca 100644
74655--- a/kernel/kallsyms.c
74656+++ b/kernel/kallsyms.c
74657@@ -11,6 +11,9 @@
74658 * Changed the compression method from stem compression to "table lookup"
74659 * compression (see scripts/kallsyms.c for a more complete description)
74660 */
74661+#ifdef CONFIG_GRKERNSEC_HIDESYM
74662+#define __INCLUDED_BY_HIDESYM 1
74663+#endif
74664 #include <linux/kallsyms.h>
74665 #include <linux/module.h>
74666 #include <linux/init.h>
74667@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
74668
74669 static inline int is_kernel_inittext(unsigned long addr)
74670 {
74671+ if (system_state != SYSTEM_BOOTING)
74672+ return 0;
74673+
74674 if (addr >= (unsigned long)_sinittext
74675 && addr <= (unsigned long)_einittext)
74676 return 1;
74677 return 0;
74678 }
74679
74680+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74681+#ifdef CONFIG_MODULES
74682+static inline int is_module_text(unsigned long addr)
74683+{
74684+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
74685+ return 1;
74686+
74687+ addr = ktla_ktva(addr);
74688+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
74689+}
74690+#else
74691+static inline int is_module_text(unsigned long addr)
74692+{
74693+ return 0;
74694+}
74695+#endif
74696+#endif
74697+
74698 static inline int is_kernel_text(unsigned long addr)
74699 {
74700 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
74701@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
74702
74703 static inline int is_kernel(unsigned long addr)
74704 {
74705+
74706+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74707+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
74708+ return 1;
74709+
74710+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
74711+#else
74712 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
74713+#endif
74714+
74715 return 1;
74716 return in_gate_area_no_mm(addr);
74717 }
74718
74719 static int is_ksym_addr(unsigned long addr)
74720 {
74721+
74722+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74723+ if (is_module_text(addr))
74724+ return 0;
74725+#endif
74726+
74727 if (all_var)
74728 return is_kernel(addr);
74729
74730@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
74731
74732 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
74733 {
74734- iter->name[0] = '\0';
74735 iter->nameoff = get_symbol_offset(new_pos);
74736 iter->pos = new_pos;
74737 }
74738@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
74739 {
74740 struct kallsym_iter *iter = m->private;
74741
74742+#ifdef CONFIG_GRKERNSEC_HIDESYM
74743+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
74744+ return 0;
74745+#endif
74746+
74747 /* Some debugging symbols have no name. Ignore them. */
74748 if (!iter->name[0])
74749 return 0;
74750@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
74751 */
74752 type = iter->exported ? toupper(iter->type) :
74753 tolower(iter->type);
74754+
74755 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
74756 type, iter->name, iter->module_name);
74757 } else
74758@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
74759 struct kallsym_iter *iter;
74760 int ret;
74761
74762- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
74763+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
74764 if (!iter)
74765 return -ENOMEM;
74766 reset_iter(iter, 0);
74767diff --git a/kernel/kcmp.c b/kernel/kcmp.c
74768index e30ac0f..3528cac 100644
74769--- a/kernel/kcmp.c
74770+++ b/kernel/kcmp.c
74771@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
74772 struct task_struct *task1, *task2;
74773 int ret;
74774
74775+#ifdef CONFIG_GRKERNSEC
74776+ return -ENOSYS;
74777+#endif
74778+
74779 rcu_read_lock();
74780
74781 /*
74782diff --git a/kernel/kexec.c b/kernel/kexec.c
74783index 5e4bd78..00c5b91 100644
74784--- a/kernel/kexec.c
74785+++ b/kernel/kexec.c
74786@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
74787 unsigned long flags)
74788 {
74789 struct compat_kexec_segment in;
74790- struct kexec_segment out, __user *ksegments;
74791+ struct kexec_segment out;
74792+ struct kexec_segment __user *ksegments;
74793 unsigned long i, result;
74794
74795 /* Don't allow clients that don't understand the native
74796diff --git a/kernel/kmod.c b/kernel/kmod.c
74797index 0023a87..9c0c068 100644
74798--- a/kernel/kmod.c
74799+++ b/kernel/kmod.c
74800@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74801 kfree(info->argv);
74802 }
74803
74804-static int call_modprobe(char *module_name, int wait)
74805+static int call_modprobe(char *module_name, char *module_param, int wait)
74806 {
74807 static char *envp[] = {
74808 "HOME=/",
74809@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74810 NULL
74811 };
74812
74813- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74814+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74815 if (!argv)
74816 goto out;
74817
74818@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74819 argv[1] = "-q";
74820 argv[2] = "--";
74821 argv[3] = module_name; /* check free_modprobe_argv() */
74822- argv[4] = NULL;
74823+ argv[4] = module_param;
74824+ argv[5] = NULL;
74825
74826 return call_usermodehelper_fns(modprobe_path, argv, envp,
74827 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74828@@ -120,9 +121,8 @@ out:
74829 * If module auto-loading support is disabled then this function
74830 * becomes a no-operation.
74831 */
74832-int __request_module(bool wait, const char *fmt, ...)
74833+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74834 {
74835- va_list args;
74836 char module_name[MODULE_NAME_LEN];
74837 unsigned int max_modprobes;
74838 int ret;
74839@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74840 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74841 static int kmod_loop_msg;
74842
74843- va_start(args, fmt);
74844- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74845- va_end(args);
74846+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74847 if (ret >= MODULE_NAME_LEN)
74848 return -ENAMETOOLONG;
74849
74850@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
74851 if (ret)
74852 return ret;
74853
74854+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74855+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74856+ /* hack to workaround consolekit/udisks stupidity */
74857+ read_lock(&tasklist_lock);
74858+ if (!strcmp(current->comm, "mount") &&
74859+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
74860+ read_unlock(&tasklist_lock);
74861+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
74862+ return -EPERM;
74863+ }
74864+ read_unlock(&tasklist_lock);
74865+ }
74866+#endif
74867+
74868 /* If modprobe needs a service that is in a module, we get a recursive
74869 * loop. Limit the number of running kmod threads to max_threads/2 or
74870 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
74871@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
74872
74873 trace_module_request(module_name, wait, _RET_IP_);
74874
74875- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74876+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74877
74878 atomic_dec(&kmod_concurrent);
74879 return ret;
74880 }
74881+
74882+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
74883+{
74884+ va_list args;
74885+ int ret;
74886+
74887+ va_start(args, fmt);
74888+ ret = ____request_module(wait, module_param, fmt, args);
74889+ va_end(args);
74890+
74891+ return ret;
74892+}
74893+
74894+int __request_module(bool wait, const char *fmt, ...)
74895+{
74896+ va_list args;
74897+ int ret;
74898+
74899+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74900+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74901+ char module_param[MODULE_NAME_LEN];
74902+
74903+ memset(module_param, 0, sizeof(module_param));
74904+
74905+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74906+
74907+ va_start(args, fmt);
74908+ ret = ____request_module(wait, module_param, fmt, args);
74909+ va_end(args);
74910+
74911+ return ret;
74912+ }
74913+#endif
74914+
74915+ va_start(args, fmt);
74916+ ret = ____request_module(wait, NULL, fmt, args);
74917+ va_end(args);
74918+
74919+ return ret;
74920+}
74921+
74922 EXPORT_SYMBOL(__request_module);
74923 #endif /* CONFIG_MODULES */
74924
74925@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74926 *
74927 * Thus the __user pointer cast is valid here.
74928 */
74929- sys_wait4(pid, (int __user *)&ret, 0, NULL);
74930+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74931
74932 /*
74933 * If ret is 0, either ____call_usermodehelper failed and the
74934@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74935 static int proc_cap_handler(struct ctl_table *table, int write,
74936 void __user *buffer, size_t *lenp, loff_t *ppos)
74937 {
74938- struct ctl_table t;
74939+ ctl_table_no_const t;
74940 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74941 kernel_cap_t new_cap;
74942 int err, i;
74943diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74944index 098f396..fe85ff1 100644
74945--- a/kernel/kprobes.c
74946+++ b/kernel/kprobes.c
74947@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74948 * kernel image and loaded module images reside. This is required
74949 * so x86_64 can correctly handle the %rip-relative fixups.
74950 */
74951- kip->insns = module_alloc(PAGE_SIZE);
74952+ kip->insns = module_alloc_exec(PAGE_SIZE);
74953 if (!kip->insns) {
74954 kfree(kip);
74955 return NULL;
74956@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74957 */
74958 if (!list_is_singular(&kip->list)) {
74959 list_del(&kip->list);
74960- module_free(NULL, kip->insns);
74961+ module_free_exec(NULL, kip->insns);
74962 kfree(kip);
74963 }
74964 return 1;
74965@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74966 {
74967 int i, err = 0;
74968 unsigned long offset = 0, size = 0;
74969- char *modname, namebuf[128];
74970+ char *modname, namebuf[KSYM_NAME_LEN];
74971 const char *symbol_name;
74972 void *addr;
74973 struct kprobe_blackpoint *kb;
74974@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74975 kprobe_type = "k";
74976
74977 if (sym)
74978- seq_printf(pi, "%p %s %s+0x%x %s ",
74979+ seq_printf(pi, "%pK %s %s+0x%x %s ",
74980 p->addr, kprobe_type, sym, offset,
74981 (modname ? modname : " "));
74982 else
74983- seq_printf(pi, "%p %s %p ",
74984+ seq_printf(pi, "%pK %s %pK ",
74985 p->addr, kprobe_type, p->addr);
74986
74987 if (!pp)
74988@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74989 const char *sym = NULL;
74990 unsigned int i = *(loff_t *) v;
74991 unsigned long offset = 0;
74992- char *modname, namebuf[128];
74993+ char *modname, namebuf[KSYM_NAME_LEN];
74994
74995 head = &kprobe_table[i];
74996 preempt_disable();
74997diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74998index 6ada93c..dce7d5d 100644
74999--- a/kernel/ksysfs.c
75000+++ b/kernel/ksysfs.c
75001@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
75002 {
75003 if (count+1 > UEVENT_HELPER_PATH_LEN)
75004 return -ENOENT;
75005+ if (!capable(CAP_SYS_ADMIN))
75006+ return -EPERM;
75007 memcpy(uevent_helper, buf, count);
75008 uevent_helper[count] = '\0';
75009 if (count && uevent_helper[count-1] == '\n')
75010@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
75011 return count;
75012 }
75013
75014-static struct bin_attribute notes_attr = {
75015+static bin_attribute_no_const notes_attr __read_only = {
75016 .attr = {
75017 .name = "notes",
75018 .mode = S_IRUGO,
75019diff --git a/kernel/lockdep.c b/kernel/lockdep.c
75020index 7981e5b..7f2105c 100644
75021--- a/kernel/lockdep.c
75022+++ b/kernel/lockdep.c
75023@@ -590,6 +590,10 @@ static int static_obj(void *obj)
75024 end = (unsigned long) &_end,
75025 addr = (unsigned long) obj;
75026
75027+#ifdef CONFIG_PAX_KERNEXEC
75028+ start = ktla_ktva(start);
75029+#endif
75030+
75031 /*
75032 * static variable?
75033 */
75034@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
75035 if (!static_obj(lock->key)) {
75036 debug_locks_off();
75037 printk("INFO: trying to register non-static key.\n");
75038+ printk("lock:%pS key:%pS.\n", lock, lock->key);
75039 printk("the code is fine but needs lockdep annotation.\n");
75040 printk("turning off the locking correctness validator.\n");
75041 dump_stack();
75042@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
75043 if (!class)
75044 return 0;
75045 }
75046- atomic_inc((atomic_t *)&class->ops);
75047+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
75048 if (very_verbose(class)) {
75049 printk("\nacquire class [%p] %s", class->key, class->name);
75050 if (class->name_version > 1)
75051diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
75052index b2c71c5..7b88d63 100644
75053--- a/kernel/lockdep_proc.c
75054+++ b/kernel/lockdep_proc.c
75055@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
75056 return 0;
75057 }
75058
75059- seq_printf(m, "%p", class->key);
75060+ seq_printf(m, "%pK", class->key);
75061 #ifdef CONFIG_DEBUG_LOCKDEP
75062 seq_printf(m, " OPS:%8ld", class->ops);
75063 #endif
75064@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
75065
75066 list_for_each_entry(entry, &class->locks_after, entry) {
75067 if (entry->distance == 1) {
75068- seq_printf(m, " -> [%p] ", entry->class->key);
75069+ seq_printf(m, " -> [%pK] ", entry->class->key);
75070 print_name(m, entry->class);
75071 seq_puts(m, "\n");
75072 }
75073@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
75074 if (!class->key)
75075 continue;
75076
75077- seq_printf(m, "[%p] ", class->key);
75078+ seq_printf(m, "[%pK] ", class->key);
75079 print_name(m, class);
75080 seq_puts(m, "\n");
75081 }
75082@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75083 if (!i)
75084 seq_line(m, '-', 40-namelen, namelen);
75085
75086- snprintf(ip, sizeof(ip), "[<%p>]",
75087+ snprintf(ip, sizeof(ip), "[<%pK>]",
75088 (void *)class->contention_point[i]);
75089 seq_printf(m, "%40s %14lu %29s %pS\n",
75090 name, stats->contention_point[i],
75091@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75092 if (!i)
75093 seq_line(m, '-', 40-namelen, namelen);
75094
75095- snprintf(ip, sizeof(ip), "[<%p>]",
75096+ snprintf(ip, sizeof(ip), "[<%pK>]",
75097 (void *)class->contending_point[i]);
75098 seq_printf(m, "%40s %14lu %29s %pS\n",
75099 name, stats->contending_point[i],
75100diff --git a/kernel/module.c b/kernel/module.c
75101index eab0827..f488603 100644
75102--- a/kernel/module.c
75103+++ b/kernel/module.c
75104@@ -61,6 +61,7 @@
75105 #include <linux/pfn.h>
75106 #include <linux/bsearch.h>
75107 #include <linux/fips.h>
75108+#include <linux/grsecurity.h>
75109 #include <uapi/linux/module.h>
75110 #include "module-internal.h"
75111
75112@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
75113
75114 /* Bounds of module allocation, for speeding __module_address.
75115 * Protected by module_mutex. */
75116-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
75117+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
75118+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
75119
75120 int register_module_notifier(struct notifier_block * nb)
75121 {
75122@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75123 return true;
75124
75125 list_for_each_entry_rcu(mod, &modules, list) {
75126- struct symsearch arr[] = {
75127+ struct symsearch modarr[] = {
75128 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
75129 NOT_GPL_ONLY, false },
75130 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
75131@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75132 if (mod->state == MODULE_STATE_UNFORMED)
75133 continue;
75134
75135- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
75136+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
75137 return true;
75138 }
75139 return false;
75140@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
75141 static int percpu_modalloc(struct module *mod,
75142 unsigned long size, unsigned long align)
75143 {
75144- if (align > PAGE_SIZE) {
75145+ if (align-1 >= PAGE_SIZE) {
75146 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
75147 mod->name, align, PAGE_SIZE);
75148 align = PAGE_SIZE;
75149@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
75150 static ssize_t show_coresize(struct module_attribute *mattr,
75151 struct module_kobject *mk, char *buffer)
75152 {
75153- return sprintf(buffer, "%u\n", mk->mod->core_size);
75154+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
75155 }
75156
75157 static struct module_attribute modinfo_coresize =
75158@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
75159 static ssize_t show_initsize(struct module_attribute *mattr,
75160 struct module_kobject *mk, char *buffer)
75161 {
75162- return sprintf(buffer, "%u\n", mk->mod->init_size);
75163+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
75164 }
75165
75166 static struct module_attribute modinfo_initsize =
75167@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
75168 */
75169 #ifdef CONFIG_SYSFS
75170
75171-#ifdef CONFIG_KALLSYMS
75172+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75173 static inline bool sect_empty(const Elf_Shdr *sect)
75174 {
75175 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
75176@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
75177 {
75178 unsigned int notes, loaded, i;
75179 struct module_notes_attrs *notes_attrs;
75180- struct bin_attribute *nattr;
75181+ bin_attribute_no_const *nattr;
75182
75183 /* failed to create section attributes, so can't create notes */
75184 if (!mod->sect_attrs)
75185@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
75186 static int module_add_modinfo_attrs(struct module *mod)
75187 {
75188 struct module_attribute *attr;
75189- struct module_attribute *temp_attr;
75190+ module_attribute_no_const *temp_attr;
75191 int error = 0;
75192 int i;
75193
75194@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
75195
75196 static void unset_module_core_ro_nx(struct module *mod)
75197 {
75198- set_page_attributes(mod->module_core + mod->core_text_size,
75199- mod->module_core + mod->core_size,
75200+ set_page_attributes(mod->module_core_rw,
75201+ mod->module_core_rw + mod->core_size_rw,
75202 set_memory_x);
75203- set_page_attributes(mod->module_core,
75204- mod->module_core + mod->core_ro_size,
75205+ set_page_attributes(mod->module_core_rx,
75206+ mod->module_core_rx + mod->core_size_rx,
75207 set_memory_rw);
75208 }
75209
75210 static void unset_module_init_ro_nx(struct module *mod)
75211 {
75212- set_page_attributes(mod->module_init + mod->init_text_size,
75213- mod->module_init + mod->init_size,
75214+ set_page_attributes(mod->module_init_rw,
75215+ mod->module_init_rw + mod->init_size_rw,
75216 set_memory_x);
75217- set_page_attributes(mod->module_init,
75218- mod->module_init + mod->init_ro_size,
75219+ set_page_attributes(mod->module_init_rx,
75220+ mod->module_init_rx + mod->init_size_rx,
75221 set_memory_rw);
75222 }
75223
75224@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
75225 list_for_each_entry_rcu(mod, &modules, list) {
75226 if (mod->state == MODULE_STATE_UNFORMED)
75227 continue;
75228- if ((mod->module_core) && (mod->core_text_size)) {
75229- set_page_attributes(mod->module_core,
75230- mod->module_core + mod->core_text_size,
75231+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75232+ set_page_attributes(mod->module_core_rx,
75233+ mod->module_core_rx + mod->core_size_rx,
75234 set_memory_rw);
75235 }
75236- if ((mod->module_init) && (mod->init_text_size)) {
75237- set_page_attributes(mod->module_init,
75238- mod->module_init + mod->init_text_size,
75239+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75240+ set_page_attributes(mod->module_init_rx,
75241+ mod->module_init_rx + mod->init_size_rx,
75242 set_memory_rw);
75243 }
75244 }
75245@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
75246 list_for_each_entry_rcu(mod, &modules, list) {
75247 if (mod->state == MODULE_STATE_UNFORMED)
75248 continue;
75249- if ((mod->module_core) && (mod->core_text_size)) {
75250- set_page_attributes(mod->module_core,
75251- mod->module_core + mod->core_text_size,
75252+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75253+ set_page_attributes(mod->module_core_rx,
75254+ mod->module_core_rx + mod->core_size_rx,
75255 set_memory_ro);
75256 }
75257- if ((mod->module_init) && (mod->init_text_size)) {
75258- set_page_attributes(mod->module_init,
75259- mod->module_init + mod->init_text_size,
75260+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75261+ set_page_attributes(mod->module_init_rx,
75262+ mod->module_init_rx + mod->init_size_rx,
75263 set_memory_ro);
75264 }
75265 }
75266@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
75267
75268 /* This may be NULL, but that's OK */
75269 unset_module_init_ro_nx(mod);
75270- module_free(mod, mod->module_init);
75271+ module_free(mod, mod->module_init_rw);
75272+ module_free_exec(mod, mod->module_init_rx);
75273 kfree(mod->args);
75274 percpu_modfree(mod);
75275
75276 /* Free lock-classes: */
75277- lockdep_free_key_range(mod->module_core, mod->core_size);
75278+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
75279+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
75280
75281 /* Finally, free the core (containing the module structure) */
75282 unset_module_core_ro_nx(mod);
75283- module_free(mod, mod->module_core);
75284+ module_free_exec(mod, mod->module_core_rx);
75285+ module_free(mod, mod->module_core_rw);
75286
75287 #ifdef CONFIG_MPU
75288 update_protections(current->mm);
75289@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75290 int ret = 0;
75291 const struct kernel_symbol *ksym;
75292
75293+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75294+ int is_fs_load = 0;
75295+ int register_filesystem_found = 0;
75296+ char *p;
75297+
75298+ p = strstr(mod->args, "grsec_modharden_fs");
75299+ if (p) {
75300+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
75301+ /* copy \0 as well */
75302+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
75303+ is_fs_load = 1;
75304+ }
75305+#endif
75306+
75307 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
75308 const char *name = info->strtab + sym[i].st_name;
75309
75310+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75311+ /* it's a real shame this will never get ripped and copied
75312+ upstream! ;(
75313+ */
75314+ if (is_fs_load && !strcmp(name, "register_filesystem"))
75315+ register_filesystem_found = 1;
75316+#endif
75317+
75318 switch (sym[i].st_shndx) {
75319 case SHN_COMMON:
75320 /* We compiled with -fno-common. These are not
75321@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75322 ksym = resolve_symbol_wait(mod, info, name);
75323 /* Ok if resolved. */
75324 if (ksym && !IS_ERR(ksym)) {
75325+ pax_open_kernel();
75326 sym[i].st_value = ksym->value;
75327+ pax_close_kernel();
75328 break;
75329 }
75330
75331@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75332 secbase = (unsigned long)mod_percpu(mod);
75333 else
75334 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
75335+ pax_open_kernel();
75336 sym[i].st_value += secbase;
75337+ pax_close_kernel();
75338 break;
75339 }
75340 }
75341
75342+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75343+ if (is_fs_load && !register_filesystem_found) {
75344+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
75345+ ret = -EPERM;
75346+ }
75347+#endif
75348+
75349 return ret;
75350 }
75351
75352@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
75353 || s->sh_entsize != ~0UL
75354 || strstarts(sname, ".init"))
75355 continue;
75356- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
75357+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75358+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
75359+ else
75360+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
75361 pr_debug("\t%s\n", sname);
75362 }
75363- switch (m) {
75364- case 0: /* executable */
75365- mod->core_size = debug_align(mod->core_size);
75366- mod->core_text_size = mod->core_size;
75367- break;
75368- case 1: /* RO: text and ro-data */
75369- mod->core_size = debug_align(mod->core_size);
75370- mod->core_ro_size = mod->core_size;
75371- break;
75372- case 3: /* whole core */
75373- mod->core_size = debug_align(mod->core_size);
75374- break;
75375- }
75376 }
75377
75378 pr_debug("Init section allocation order:\n");
75379@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
75380 || s->sh_entsize != ~0UL
75381 || !strstarts(sname, ".init"))
75382 continue;
75383- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
75384- | INIT_OFFSET_MASK);
75385+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75386+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
75387+ else
75388+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
75389+ s->sh_entsize |= INIT_OFFSET_MASK;
75390 pr_debug("\t%s\n", sname);
75391 }
75392- switch (m) {
75393- case 0: /* executable */
75394- mod->init_size = debug_align(mod->init_size);
75395- mod->init_text_size = mod->init_size;
75396- break;
75397- case 1: /* RO: text and ro-data */
75398- mod->init_size = debug_align(mod->init_size);
75399- mod->init_ro_size = mod->init_size;
75400- break;
75401- case 3: /* whole init */
75402- mod->init_size = debug_align(mod->init_size);
75403- break;
75404- }
75405 }
75406 }
75407
75408@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75409
75410 /* Put symbol section at end of init part of module. */
75411 symsect->sh_flags |= SHF_ALLOC;
75412- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
75413+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
75414 info->index.sym) | INIT_OFFSET_MASK;
75415 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
75416
75417@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75418 }
75419
75420 /* Append room for core symbols at end of core part. */
75421- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
75422- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
75423- mod->core_size += strtab_size;
75424+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
75425+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
75426+ mod->core_size_rx += strtab_size;
75427
75428 /* Put string table section at end of init part of module. */
75429 strsect->sh_flags |= SHF_ALLOC;
75430- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
75431+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
75432 info->index.str) | INIT_OFFSET_MASK;
75433 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
75434 }
75435@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75436 /* Make sure we get permanent strtab: don't use info->strtab. */
75437 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
75438
75439+ pax_open_kernel();
75440+
75441 /* Set types up while we still have access to sections. */
75442 for (i = 0; i < mod->num_symtab; i++)
75443 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
75444
75445- mod->core_symtab = dst = mod->module_core + info->symoffs;
75446- mod->core_strtab = s = mod->module_core + info->stroffs;
75447+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
75448+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
75449 src = mod->symtab;
75450 for (ndst = i = 0; i < mod->num_symtab; i++) {
75451 if (i == 0 ||
75452@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75453 }
75454 }
75455 mod->core_num_syms = ndst;
75456+
75457+ pax_close_kernel();
75458 }
75459 #else
75460 static inline void layout_symtab(struct module *mod, struct load_info *info)
75461@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
75462 return vmalloc_exec(size);
75463 }
75464
75465-static void *module_alloc_update_bounds(unsigned long size)
75466+static void *module_alloc_update_bounds_rw(unsigned long size)
75467 {
75468 void *ret = module_alloc(size);
75469
75470 if (ret) {
75471 mutex_lock(&module_mutex);
75472 /* Update module bounds. */
75473- if ((unsigned long)ret < module_addr_min)
75474- module_addr_min = (unsigned long)ret;
75475- if ((unsigned long)ret + size > module_addr_max)
75476- module_addr_max = (unsigned long)ret + size;
75477+ if ((unsigned long)ret < module_addr_min_rw)
75478+ module_addr_min_rw = (unsigned long)ret;
75479+ if ((unsigned long)ret + size > module_addr_max_rw)
75480+ module_addr_max_rw = (unsigned long)ret + size;
75481+ mutex_unlock(&module_mutex);
75482+ }
75483+ return ret;
75484+}
75485+
75486+static void *module_alloc_update_bounds_rx(unsigned long size)
75487+{
75488+ void *ret = module_alloc_exec(size);
75489+
75490+ if (ret) {
75491+ mutex_lock(&module_mutex);
75492+ /* Update module bounds. */
75493+ if ((unsigned long)ret < module_addr_min_rx)
75494+ module_addr_min_rx = (unsigned long)ret;
75495+ if ((unsigned long)ret + size > module_addr_max_rx)
75496+ module_addr_max_rx = (unsigned long)ret + size;
75497 mutex_unlock(&module_mutex);
75498 }
75499 return ret;
75500@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
75501 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75502 {
75503 const char *modmagic = get_modinfo(info, "vermagic");
75504+ const char *license = get_modinfo(info, "license");
75505 int err;
75506
75507+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
75508+ if (!license || !license_is_gpl_compatible(license))
75509+ return -ENOEXEC;
75510+#endif
75511+
75512 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
75513 modmagic = NULL;
75514
75515@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75516 }
75517
75518 /* Set up license info based on the info section */
75519- set_license(mod, get_modinfo(info, "license"));
75520+ set_license(mod, license);
75521
75522 return 0;
75523 }
75524@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
75525 void *ptr;
75526
75527 /* Do the allocs. */
75528- ptr = module_alloc_update_bounds(mod->core_size);
75529+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
75530 /*
75531 * The pointer to this block is stored in the module structure
75532 * which is inside the block. Just mark it as not being a
75533@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
75534 if (!ptr)
75535 return -ENOMEM;
75536
75537- memset(ptr, 0, mod->core_size);
75538- mod->module_core = ptr;
75539+ memset(ptr, 0, mod->core_size_rw);
75540+ mod->module_core_rw = ptr;
75541
75542- if (mod->init_size) {
75543- ptr = module_alloc_update_bounds(mod->init_size);
75544+ if (mod->init_size_rw) {
75545+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
75546 /*
75547 * The pointer to this block is stored in the module structure
75548 * which is inside the block. This block doesn't need to be
75549@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
75550 */
75551 kmemleak_ignore(ptr);
75552 if (!ptr) {
75553- module_free(mod, mod->module_core);
75554+ module_free(mod, mod->module_core_rw);
75555 return -ENOMEM;
75556 }
75557- memset(ptr, 0, mod->init_size);
75558- mod->module_init = ptr;
75559+ memset(ptr, 0, mod->init_size_rw);
75560+ mod->module_init_rw = ptr;
75561 } else
75562- mod->module_init = NULL;
75563+ mod->module_init_rw = NULL;
75564+
75565+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
75566+ kmemleak_not_leak(ptr);
75567+ if (!ptr) {
75568+ if (mod->module_init_rw)
75569+ module_free(mod, mod->module_init_rw);
75570+ module_free(mod, mod->module_core_rw);
75571+ return -ENOMEM;
75572+ }
75573+
75574+ pax_open_kernel();
75575+ memset(ptr, 0, mod->core_size_rx);
75576+ pax_close_kernel();
75577+ mod->module_core_rx = ptr;
75578+
75579+ if (mod->init_size_rx) {
75580+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
75581+ kmemleak_ignore(ptr);
75582+ if (!ptr && mod->init_size_rx) {
75583+ module_free_exec(mod, mod->module_core_rx);
75584+ if (mod->module_init_rw)
75585+ module_free(mod, mod->module_init_rw);
75586+ module_free(mod, mod->module_core_rw);
75587+ return -ENOMEM;
75588+ }
75589+
75590+ pax_open_kernel();
75591+ memset(ptr, 0, mod->init_size_rx);
75592+ pax_close_kernel();
75593+ mod->module_init_rx = ptr;
75594+ } else
75595+ mod->module_init_rx = NULL;
75596
75597 /* Transfer each section which specifies SHF_ALLOC */
75598 pr_debug("final section addresses:\n");
75599@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
75600 if (!(shdr->sh_flags & SHF_ALLOC))
75601 continue;
75602
75603- if (shdr->sh_entsize & INIT_OFFSET_MASK)
75604- dest = mod->module_init
75605- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75606- else
75607- dest = mod->module_core + shdr->sh_entsize;
75608+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
75609+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75610+ dest = mod->module_init_rw
75611+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75612+ else
75613+ dest = mod->module_init_rx
75614+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75615+ } else {
75616+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75617+ dest = mod->module_core_rw + shdr->sh_entsize;
75618+ else
75619+ dest = mod->module_core_rx + shdr->sh_entsize;
75620+ }
75621+
75622+ if (shdr->sh_type != SHT_NOBITS) {
75623+
75624+#ifdef CONFIG_PAX_KERNEXEC
75625+#ifdef CONFIG_X86_64
75626+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
75627+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
75628+#endif
75629+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
75630+ pax_open_kernel();
75631+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75632+ pax_close_kernel();
75633+ } else
75634+#endif
75635
75636- if (shdr->sh_type != SHT_NOBITS)
75637 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75638+ }
75639 /* Update sh_addr to point to copy in image. */
75640- shdr->sh_addr = (unsigned long)dest;
75641+
75642+#ifdef CONFIG_PAX_KERNEXEC
75643+ if (shdr->sh_flags & SHF_EXECINSTR)
75644+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
75645+ else
75646+#endif
75647+
75648+ shdr->sh_addr = (unsigned long)dest;
75649 pr_debug("\t0x%lx %s\n",
75650 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
75651 }
75652@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
75653 * Do it before processing of module parameters, so the module
75654 * can provide parameter accessor functions of its own.
75655 */
75656- if (mod->module_init)
75657- flush_icache_range((unsigned long)mod->module_init,
75658- (unsigned long)mod->module_init
75659- + mod->init_size);
75660- flush_icache_range((unsigned long)mod->module_core,
75661- (unsigned long)mod->module_core + mod->core_size);
75662+ if (mod->module_init_rx)
75663+ flush_icache_range((unsigned long)mod->module_init_rx,
75664+ (unsigned long)mod->module_init_rx
75665+ + mod->init_size_rx);
75666+ flush_icache_range((unsigned long)mod->module_core_rx,
75667+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
75668
75669 set_fs(old_fs);
75670 }
75671@@ -2983,8 +3088,10 @@ out:
75672 static void module_deallocate(struct module *mod, struct load_info *info)
75673 {
75674 percpu_modfree(mod);
75675- module_free(mod, mod->module_init);
75676- module_free(mod, mod->module_core);
75677+ module_free_exec(mod, mod->module_init_rx);
75678+ module_free_exec(mod, mod->module_core_rx);
75679+ module_free(mod, mod->module_init_rw);
75680+ module_free(mod, mod->module_core_rw);
75681 }
75682
75683 int __weak module_finalize(const Elf_Ehdr *hdr,
75684@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
75685 static int post_relocation(struct module *mod, const struct load_info *info)
75686 {
75687 /* Sort exception table now relocations are done. */
75688+ pax_open_kernel();
75689 sort_extable(mod->extable, mod->extable + mod->num_exentries);
75690+ pax_close_kernel();
75691
75692 /* Copy relocated percpu area over. */
75693 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
75694@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
75695 MODULE_STATE_COMING, mod);
75696
75697 /* Set RO and NX regions for core */
75698- set_section_ro_nx(mod->module_core,
75699- mod->core_text_size,
75700- mod->core_ro_size,
75701- mod->core_size);
75702+ set_section_ro_nx(mod->module_core_rx,
75703+ mod->core_size_rx,
75704+ mod->core_size_rx,
75705+ mod->core_size_rx);
75706
75707 /* Set RO and NX regions for init */
75708- set_section_ro_nx(mod->module_init,
75709- mod->init_text_size,
75710- mod->init_ro_size,
75711- mod->init_size);
75712+ set_section_ro_nx(mod->module_init_rx,
75713+ mod->init_size_rx,
75714+ mod->init_size_rx,
75715+ mod->init_size_rx);
75716
75717 do_mod_ctors(mod);
75718 /* Start the module */
75719@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
75720 mod->strtab = mod->core_strtab;
75721 #endif
75722 unset_module_init_ro_nx(mod);
75723- module_free(mod, mod->module_init);
75724- mod->module_init = NULL;
75725- mod->init_size = 0;
75726- mod->init_ro_size = 0;
75727- mod->init_text_size = 0;
75728+ module_free(mod, mod->module_init_rw);
75729+ module_free_exec(mod, mod->module_init_rx);
75730+ mod->module_init_rw = NULL;
75731+ mod->module_init_rx = NULL;
75732+ mod->init_size_rw = 0;
75733+ mod->init_size_rx = 0;
75734 mutex_unlock(&module_mutex);
75735 wake_up_all(&module_wq);
75736
75737@@ -3209,9 +3319,38 @@ again:
75738 if (err)
75739 goto free_unload;
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_unload;
75746+ }
75747+
75748 /* Set up MODINFO_ATTR fields */
75749 setup_modinfo(mod, info);
75750
75751+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75752+ {
75753+ char *p, *p2;
75754+
75755+ if (strstr(mod->args, "grsec_modharden_netdev")) {
75756+ 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);
75757+ err = -EPERM;
75758+ goto free_modinfo;
75759+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
75760+ p += sizeof("grsec_modharden_normal") - 1;
75761+ p2 = strstr(p, "_");
75762+ if (p2) {
75763+ *p2 = '\0';
75764+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
75765+ *p2 = '_';
75766+ }
75767+ err = -EPERM;
75768+ goto free_modinfo;
75769+ }
75770+ }
75771+#endif
75772+
75773 /* Fix up syms, so that st_value is a pointer to location. */
75774 err = simplify_symbols(mod, info);
75775 if (err < 0)
75776@@ -3227,13 +3366,6 @@ again:
75777
75778 flush_module_icache(mod);
75779
75780- /* Now copy in args */
75781- mod->args = strndup_user(uargs, ~0UL >> 1);
75782- if (IS_ERR(mod->args)) {
75783- err = PTR_ERR(mod->args);
75784- goto free_arch_cleanup;
75785- }
75786-
75787 dynamic_debug_setup(info->debug, info->num_debug);
75788
75789 mutex_lock(&module_mutex);
75790@@ -3278,11 +3410,10 @@ again:
75791 mutex_unlock(&module_mutex);
75792 dynamic_debug_remove(info->debug);
75793 synchronize_sched();
75794- kfree(mod->args);
75795- free_arch_cleanup:
75796 module_arch_cleanup(mod);
75797 free_modinfo:
75798 free_modinfo(mod);
75799+ kfree(mod->args);
75800 free_unload:
75801 module_unload_free(mod);
75802 unlink_mod:
75803@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75804 unsigned long nextval;
75805
75806 /* At worse, next value is at end of module */
75807- if (within_module_init(addr, mod))
75808- nextval = (unsigned long)mod->module_init+mod->init_text_size;
75809+ if (within_module_init_rx(addr, mod))
75810+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75811+ else if (within_module_init_rw(addr, mod))
75812+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75813+ else if (within_module_core_rx(addr, mod))
75814+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75815+ else if (within_module_core_rw(addr, mod))
75816+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75817 else
75818- nextval = (unsigned long)mod->module_core+mod->core_text_size;
75819+ return NULL;
75820
75821 /* Scan for closest preceding symbol, and next symbol. (ELF
75822 starts real symbols at 1). */
75823@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75824 return 0;
75825
75826 seq_printf(m, "%s %u",
75827- mod->name, mod->init_size + mod->core_size);
75828+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75829 print_unload_info(m, mod);
75830
75831 /* Informative for users. */
75832@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75833 mod->state == MODULE_STATE_COMING ? "Loading":
75834 "Live");
75835 /* Used by oprofile and other similar tools. */
75836- seq_printf(m, " 0x%pK", mod->module_core);
75837+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75838
75839 /* Taints info */
75840 if (mod->taints)
75841@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75842
75843 static int __init proc_modules_init(void)
75844 {
75845+#ifndef CONFIG_GRKERNSEC_HIDESYM
75846+#ifdef CONFIG_GRKERNSEC_PROC_USER
75847+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75848+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75849+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
75850+#else
75851 proc_create("modules", 0, NULL, &proc_modules_operations);
75852+#endif
75853+#else
75854+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75855+#endif
75856 return 0;
75857 }
75858 module_init(proc_modules_init);
75859@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
75860 {
75861 struct module *mod;
75862
75863- if (addr < module_addr_min || addr > module_addr_max)
75864+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
75865+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
75866 return NULL;
75867
75868 list_for_each_entry_rcu(mod, &modules, list) {
75869 if (mod->state == MODULE_STATE_UNFORMED)
75870 continue;
75871- if (within_module_core(addr, mod)
75872- || within_module_init(addr, mod))
75873+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
75874 return mod;
75875 }
75876 return NULL;
75877@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
75878 */
75879 struct module *__module_text_address(unsigned long addr)
75880 {
75881- struct module *mod = __module_address(addr);
75882+ struct module *mod;
75883+
75884+#ifdef CONFIG_X86_32
75885+ addr = ktla_ktva(addr);
75886+#endif
75887+
75888+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
75889+ return NULL;
75890+
75891+ mod = __module_address(addr);
75892+
75893 if (mod) {
75894 /* Make sure it's within the text section. */
75895- if (!within(addr, mod->module_init, mod->init_text_size)
75896- && !within(addr, mod->module_core, mod->core_text_size))
75897+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
75898 mod = NULL;
75899 }
75900 return mod;
75901diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
75902index 7e3443f..b2a1e6b 100644
75903--- a/kernel/mutex-debug.c
75904+++ b/kernel/mutex-debug.c
75905@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75906 }
75907
75908 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75909- struct thread_info *ti)
75910+ struct task_struct *task)
75911 {
75912 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75913
75914 /* Mark the current thread as blocked on the lock: */
75915- ti->task->blocked_on = waiter;
75916+ task->blocked_on = waiter;
75917 }
75918
75919 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75920- struct thread_info *ti)
75921+ struct task_struct *task)
75922 {
75923 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75924- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75925- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75926- ti->task->blocked_on = NULL;
75927+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
75928+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75929+ task->blocked_on = NULL;
75930
75931 list_del_init(&waiter->list);
75932 waiter->task = NULL;
75933diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75934index 0799fd3..d06ae3b 100644
75935--- a/kernel/mutex-debug.h
75936+++ b/kernel/mutex-debug.h
75937@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75938 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75939 extern void debug_mutex_add_waiter(struct mutex *lock,
75940 struct mutex_waiter *waiter,
75941- struct thread_info *ti);
75942+ struct task_struct *task);
75943 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75944- struct thread_info *ti);
75945+ struct task_struct *task);
75946 extern void debug_mutex_unlock(struct mutex *lock);
75947 extern void debug_mutex_init(struct mutex *lock, const char *name,
75948 struct lock_class_key *key);
75949diff --git a/kernel/mutex.c b/kernel/mutex.c
75950index a307cc9..27fd2e9 100644
75951--- a/kernel/mutex.c
75952+++ b/kernel/mutex.c
75953@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75954 spin_lock_mutex(&lock->wait_lock, flags);
75955
75956 debug_mutex_lock_common(lock, &waiter);
75957- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75958+ debug_mutex_add_waiter(lock, &waiter, task);
75959
75960 /* add waiting tasks to the end of the waitqueue (FIFO): */
75961 list_add_tail(&waiter.list, &lock->wait_list);
75962@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75963 * TASK_UNINTERRUPTIBLE case.)
75964 */
75965 if (unlikely(signal_pending_state(state, task))) {
75966- mutex_remove_waiter(lock, &waiter,
75967- task_thread_info(task));
75968+ mutex_remove_waiter(lock, &waiter, task);
75969 mutex_release(&lock->dep_map, 1, ip);
75970 spin_unlock_mutex(&lock->wait_lock, flags);
75971
75972@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75973 done:
75974 lock_acquired(&lock->dep_map, ip);
75975 /* got the lock - rejoice! */
75976- mutex_remove_waiter(lock, &waiter, current_thread_info());
75977+ mutex_remove_waiter(lock, &waiter, task);
75978 mutex_set_owner(lock);
75979
75980 /* set it to 0 if there are no waiters left: */
75981diff --git a/kernel/notifier.c b/kernel/notifier.c
75982index 2d5cc4c..d9ea600 100644
75983--- a/kernel/notifier.c
75984+++ b/kernel/notifier.c
75985@@ -5,6 +5,7 @@
75986 #include <linux/rcupdate.h>
75987 #include <linux/vmalloc.h>
75988 #include <linux/reboot.h>
75989+#include <linux/mm.h>
75990
75991 /*
75992 * Notifier list for kernel code which wants to be called
75993@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75994 while ((*nl) != NULL) {
75995 if (n->priority > (*nl)->priority)
75996 break;
75997- nl = &((*nl)->next);
75998+ nl = (struct notifier_block **)&((*nl)->next);
75999 }
76000- n->next = *nl;
76001+ pax_open_kernel();
76002+ *(const void **)&n->next = *nl;
76003 rcu_assign_pointer(*nl, n);
76004+ pax_close_kernel();
76005 return 0;
76006 }
76007
76008@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
76009 return 0;
76010 if (n->priority > (*nl)->priority)
76011 break;
76012- nl = &((*nl)->next);
76013+ nl = (struct notifier_block **)&((*nl)->next);
76014 }
76015- n->next = *nl;
76016+ pax_open_kernel();
76017+ *(const void **)&n->next = *nl;
76018 rcu_assign_pointer(*nl, n);
76019+ pax_close_kernel();
76020 return 0;
76021 }
76022
76023@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
76024 {
76025 while ((*nl) != NULL) {
76026 if ((*nl) == n) {
76027+ pax_open_kernel();
76028 rcu_assign_pointer(*nl, n->next);
76029+ pax_close_kernel();
76030 return 0;
76031 }
76032- nl = &((*nl)->next);
76033+ nl = (struct notifier_block **)&((*nl)->next);
76034 }
76035 return -ENOENT;
76036 }
76037diff --git a/kernel/panic.c b/kernel/panic.c
76038index e1b2822..5edc1d9 100644
76039--- a/kernel/panic.c
76040+++ b/kernel/panic.c
76041@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
76042 const char *board;
76043
76044 printk(KERN_WARNING "------------[ cut here ]------------\n");
76045- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
76046+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
76047 board = dmi_get_system_info(DMI_PRODUCT_NAME);
76048 if (board)
76049 printk(KERN_WARNING "Hardware name: %s\n", board);
76050@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
76051 */
76052 void __stack_chk_fail(void)
76053 {
76054- panic("stack-protector: Kernel stack is corrupted in: %p\n",
76055+ dump_stack();
76056+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
76057 __builtin_return_address(0));
76058 }
76059 EXPORT_SYMBOL(__stack_chk_fail);
76060diff --git a/kernel/pid.c b/kernel/pid.c
76061index f2c6a68..4922d97 100644
76062--- a/kernel/pid.c
76063+++ b/kernel/pid.c
76064@@ -33,6 +33,7 @@
76065 #include <linux/rculist.h>
76066 #include <linux/bootmem.h>
76067 #include <linux/hash.h>
76068+#include <linux/security.h>
76069 #include <linux/pid_namespace.h>
76070 #include <linux/init_task.h>
76071 #include <linux/syscalls.h>
76072@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
76073
76074 int pid_max = PID_MAX_DEFAULT;
76075
76076-#define RESERVED_PIDS 300
76077+#define RESERVED_PIDS 500
76078
76079 int pid_max_min = RESERVED_PIDS + 1;
76080 int pid_max_max = PID_MAX_LIMIT;
76081@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
76082 */
76083 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
76084 {
76085+ struct task_struct *task;
76086+
76087 rcu_lockdep_assert(rcu_read_lock_held(),
76088 "find_task_by_pid_ns() needs rcu_read_lock()"
76089 " protection");
76090- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76091+
76092+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76093+
76094+ if (gr_pid_is_chrooted(task))
76095+ return NULL;
76096+
76097+ return task;
76098 }
76099
76100 struct task_struct *find_task_by_vpid(pid_t vnr)
76101@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
76102 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
76103 }
76104
76105+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
76106+{
76107+ rcu_lockdep_assert(rcu_read_lock_held(),
76108+ "find_task_by_pid_ns() needs rcu_read_lock()"
76109+ " protection");
76110+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
76111+}
76112+
76113 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
76114 {
76115 struct pid *pid;
76116diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
76117index c1c3dc1..bbeaf31 100644
76118--- a/kernel/pid_namespace.c
76119+++ b/kernel/pid_namespace.c
76120@@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
76121 void __user *buffer, size_t *lenp, loff_t *ppos)
76122 {
76123 struct pid_namespace *pid_ns = task_active_pid_ns(current);
76124- struct ctl_table tmp = *table;
76125+ ctl_table_no_const tmp = *table;
76126
76127 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
76128 return -EPERM;
76129diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
76130index 942ca27..111e609 100644
76131--- a/kernel/posix-cpu-timers.c
76132+++ b/kernel/posix-cpu-timers.c
76133@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
76134
76135 static __init int init_posix_cpu_timers(void)
76136 {
76137- struct k_clock process = {
76138+ static struct k_clock process = {
76139 .clock_getres = process_cpu_clock_getres,
76140 .clock_get = process_cpu_clock_get,
76141 .timer_create = process_cpu_timer_create,
76142 .nsleep = process_cpu_nsleep,
76143 .nsleep_restart = process_cpu_nsleep_restart,
76144 };
76145- struct k_clock thread = {
76146+ static struct k_clock thread = {
76147 .clock_getres = thread_cpu_clock_getres,
76148 .clock_get = thread_cpu_clock_get,
76149 .timer_create = thread_cpu_timer_create,
76150diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
76151index e885be1..380fe76 100644
76152--- a/kernel/posix-timers.c
76153+++ b/kernel/posix-timers.c
76154@@ -43,6 +43,7 @@
76155 #include <linux/idr.h>
76156 #include <linux/posix-clock.h>
76157 #include <linux/posix-timers.h>
76158+#include <linux/grsecurity.h>
76159 #include <linux/syscalls.h>
76160 #include <linux/wait.h>
76161 #include <linux/workqueue.h>
76162@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
76163 * which we beg off on and pass to do_sys_settimeofday().
76164 */
76165
76166-static struct k_clock posix_clocks[MAX_CLOCKS];
76167+static struct k_clock *posix_clocks[MAX_CLOCKS];
76168
76169 /*
76170 * These ones are defined below.
76171@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
76172 */
76173 static __init int init_posix_timers(void)
76174 {
76175- struct k_clock clock_realtime = {
76176+ static struct k_clock clock_realtime = {
76177 .clock_getres = hrtimer_get_res,
76178 .clock_get = posix_clock_realtime_get,
76179 .clock_set = posix_clock_realtime_set,
76180@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
76181 .timer_get = common_timer_get,
76182 .timer_del = common_timer_del,
76183 };
76184- struct k_clock clock_monotonic = {
76185+ static struct k_clock clock_monotonic = {
76186 .clock_getres = hrtimer_get_res,
76187 .clock_get = posix_ktime_get_ts,
76188 .nsleep = common_nsleep,
76189@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
76190 .timer_get = common_timer_get,
76191 .timer_del = common_timer_del,
76192 };
76193- struct k_clock clock_monotonic_raw = {
76194+ static struct k_clock clock_monotonic_raw = {
76195 .clock_getres = hrtimer_get_res,
76196 .clock_get = posix_get_monotonic_raw,
76197 };
76198- struct k_clock clock_realtime_coarse = {
76199+ static struct k_clock clock_realtime_coarse = {
76200 .clock_getres = posix_get_coarse_res,
76201 .clock_get = posix_get_realtime_coarse,
76202 };
76203- struct k_clock clock_monotonic_coarse = {
76204+ static struct k_clock clock_monotonic_coarse = {
76205 .clock_getres = posix_get_coarse_res,
76206 .clock_get = posix_get_monotonic_coarse,
76207 };
76208- struct k_clock clock_boottime = {
76209+ static struct k_clock clock_boottime = {
76210 .clock_getres = hrtimer_get_res,
76211 .clock_get = posix_get_boottime,
76212 .nsleep = common_nsleep,
76213@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
76214 return;
76215 }
76216
76217- posix_clocks[clock_id] = *new_clock;
76218+ posix_clocks[clock_id] = new_clock;
76219 }
76220 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
76221
76222@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
76223 return (id & CLOCKFD_MASK) == CLOCKFD ?
76224 &clock_posix_dynamic : &clock_posix_cpu;
76225
76226- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
76227+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
76228 return NULL;
76229- return &posix_clocks[id];
76230+ return posix_clocks[id];
76231 }
76232
76233 static int common_timer_create(struct k_itimer *new_timer)
76234@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
76235 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
76236 return -EFAULT;
76237
76238+ /* only the CLOCK_REALTIME clock can be set, all other clocks
76239+ have their clock_set fptr set to a nosettime dummy function
76240+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
76241+ call common_clock_set, which calls do_sys_settimeofday, which
76242+ we hook
76243+ */
76244+
76245 return kc->clock_set(which_clock, &new_tp);
76246 }
76247
76248diff --git a/kernel/power/process.c b/kernel/power/process.c
76249index d5a258b..4271191 100644
76250--- a/kernel/power/process.c
76251+++ b/kernel/power/process.c
76252@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
76253 u64 elapsed_csecs64;
76254 unsigned int elapsed_csecs;
76255 bool wakeup = false;
76256+ bool timedout = false;
76257
76258 do_gettimeofday(&start);
76259
76260@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
76261
76262 while (true) {
76263 todo = 0;
76264+ if (time_after(jiffies, end_time))
76265+ timedout = true;
76266 read_lock(&tasklist_lock);
76267 do_each_thread(g, p) {
76268 if (p == current || !freeze_task(p))
76269 continue;
76270
76271- if (!freezer_should_skip(p))
76272+ if (!freezer_should_skip(p)) {
76273 todo++;
76274+ if (timedout) {
76275+ printk(KERN_ERR "Task refusing to freeze:\n");
76276+ sched_show_task(p);
76277+ }
76278+ }
76279 } while_each_thread(g, p);
76280 read_unlock(&tasklist_lock);
76281
76282@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
76283 todo += wq_busy;
76284 }
76285
76286- if (!todo || time_after(jiffies, end_time))
76287+ if (!todo || timedout)
76288 break;
76289
76290 if (pm_wakeup_pending()) {
76291diff --git a/kernel/printk.c b/kernel/printk.c
76292index 267ce78..2487112 100644
76293--- a/kernel/printk.c
76294+++ b/kernel/printk.c
76295@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
76296 return ret;
76297 }
76298
76299+static int check_syslog_permissions(int type, bool from_file);
76300+
76301 static int devkmsg_open(struct inode *inode, struct file *file)
76302 {
76303 struct devkmsg_user *user;
76304 int err;
76305
76306+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
76307+ if (err)
76308+ return err;
76309+
76310 /* write-only does not need any file context */
76311 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
76312 return 0;
76313@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
76314 if (dmesg_restrict)
76315 return 1;
76316 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
76317- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76318+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76319 }
76320
76321 static int check_syslog_permissions(int type, bool from_file)
76322@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
76323 if (from_file && type != SYSLOG_ACTION_OPEN)
76324 return 0;
76325
76326+#ifdef CONFIG_GRKERNSEC_DMESG
76327+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
76328+ return -EPERM;
76329+#endif
76330+
76331 if (syslog_action_restricted(type)) {
76332 if (capable(CAP_SYSLOG))
76333 return 0;
76334diff --git a/kernel/profile.c b/kernel/profile.c
76335index 1f39181..86093471 100644
76336--- a/kernel/profile.c
76337+++ b/kernel/profile.c
76338@@ -40,7 +40,7 @@ struct profile_hit {
76339 /* Oprofile timer tick hook */
76340 static int (*timer_hook)(struct pt_regs *) __read_mostly;
76341
76342-static atomic_t *prof_buffer;
76343+static atomic_unchecked_t *prof_buffer;
76344 static unsigned long prof_len, prof_shift;
76345
76346 int prof_on __read_mostly;
76347@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
76348 hits[i].pc = 0;
76349 continue;
76350 }
76351- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76352+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76353 hits[i].hits = hits[i].pc = 0;
76354 }
76355 }
76356@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76357 * Add the current hit(s) and flush the write-queue out
76358 * to the global buffer:
76359 */
76360- atomic_add(nr_hits, &prof_buffer[pc]);
76361+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
76362 for (i = 0; i < NR_PROFILE_HIT; ++i) {
76363- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76364+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76365 hits[i].pc = hits[i].hits = 0;
76366 }
76367 out:
76368@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76369 {
76370 unsigned long pc;
76371 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
76372- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76373+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76374 }
76375 #endif /* !CONFIG_SMP */
76376
76377@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
76378 return -EFAULT;
76379 buf++; p++; count--; read++;
76380 }
76381- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
76382+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
76383 if (copy_to_user(buf, (void *)pnt, count))
76384 return -EFAULT;
76385 read += count;
76386@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
76387 }
76388 #endif
76389 profile_discard_flip_buffers();
76390- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
76391+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
76392 return count;
76393 }
76394
76395diff --git a/kernel/ptrace.c b/kernel/ptrace.c
76396index 6cbeaae..cfe7ff0 100644
76397--- a/kernel/ptrace.c
76398+++ b/kernel/ptrace.c
76399@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
76400 if (seize)
76401 flags |= PT_SEIZED;
76402 rcu_read_lock();
76403- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76404+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76405 flags |= PT_PTRACE_CAP;
76406 rcu_read_unlock();
76407 task->ptrace = flags;
76408@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
76409 break;
76410 return -EIO;
76411 }
76412- if (copy_to_user(dst, buf, retval))
76413+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
76414 return -EFAULT;
76415 copied += retval;
76416 src += retval;
76417@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
76418 bool seized = child->ptrace & PT_SEIZED;
76419 int ret = -EIO;
76420 siginfo_t siginfo, *si;
76421- void __user *datavp = (void __user *) data;
76422+ void __user *datavp = (__force void __user *) data;
76423 unsigned long __user *datalp = datavp;
76424 unsigned long flags;
76425
76426@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
76427 goto out;
76428 }
76429
76430+ if (gr_handle_ptrace(child, request)) {
76431+ ret = -EPERM;
76432+ goto out_put_task_struct;
76433+ }
76434+
76435 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76436 ret = ptrace_attach(child, request, addr, data);
76437 /*
76438 * Some architectures need to do book-keeping after
76439 * a ptrace attach.
76440 */
76441- if (!ret)
76442+ if (!ret) {
76443 arch_ptrace_attach(child);
76444+ gr_audit_ptrace(child);
76445+ }
76446 goto out_put_task_struct;
76447 }
76448
76449@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
76450 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
76451 if (copied != sizeof(tmp))
76452 return -EIO;
76453- return put_user(tmp, (unsigned long __user *)data);
76454+ return put_user(tmp, (__force unsigned long __user *)data);
76455 }
76456
76457 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
76458@@ -1051,7 +1058,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
76459 }
76460
76461 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76462- compat_long_t addr, compat_long_t data)
76463+ compat_ulong_t addr, compat_ulong_t data)
76464 {
76465 struct task_struct *child;
76466 long ret;
76467@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76468 goto out;
76469 }
76470
76471+ if (gr_handle_ptrace(child, request)) {
76472+ ret = -EPERM;
76473+ goto out_put_task_struct;
76474+ }
76475+
76476 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76477 ret = ptrace_attach(child, request, addr, data);
76478 /*
76479 * Some architectures need to do book-keeping after
76480 * a ptrace attach.
76481 */
76482- if (!ret)
76483+ if (!ret) {
76484 arch_ptrace_attach(child);
76485+ gr_audit_ptrace(child);
76486+ }
76487 goto out_put_task_struct;
76488 }
76489
76490diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
76491index e7dce58..ad0d7b7 100644
76492--- a/kernel/rcutiny.c
76493+++ b/kernel/rcutiny.c
76494@@ -46,7 +46,7 @@
76495 struct rcu_ctrlblk;
76496 static void invoke_rcu_callbacks(void);
76497 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
76498-static void rcu_process_callbacks(struct softirq_action *unused);
76499+static void rcu_process_callbacks(void);
76500 static void __call_rcu(struct rcu_head *head,
76501 void (*func)(struct rcu_head *rcu),
76502 struct rcu_ctrlblk *rcp);
76503@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
76504 rcu_is_callbacks_kthread()));
76505 }
76506
76507-static void rcu_process_callbacks(struct softirq_action *unused)
76508+static void rcu_process_callbacks(void)
76509 {
76510 __rcu_process_callbacks(&rcu_sched_ctrlblk);
76511 __rcu_process_callbacks(&rcu_bh_ctrlblk);
76512diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
76513index f85016a..91cb03b 100644
76514--- a/kernel/rcutiny_plugin.h
76515+++ b/kernel/rcutiny_plugin.h
76516@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
76517 have_rcu_kthread_work = morework;
76518 local_irq_restore(flags);
76519 if (work)
76520- rcu_process_callbacks(NULL);
76521+ rcu_process_callbacks();
76522 schedule_timeout_interruptible(1); /* Leave CPU for others. */
76523 }
76524
76525diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
76526index 31dea01..ad91ffb 100644
76527--- a/kernel/rcutorture.c
76528+++ b/kernel/rcutorture.c
76529@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
76530 { 0 };
76531 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
76532 { 0 };
76533-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76534-static atomic_t n_rcu_torture_alloc;
76535-static atomic_t n_rcu_torture_alloc_fail;
76536-static atomic_t n_rcu_torture_free;
76537-static atomic_t n_rcu_torture_mberror;
76538-static atomic_t n_rcu_torture_error;
76539+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76540+static atomic_unchecked_t n_rcu_torture_alloc;
76541+static atomic_unchecked_t n_rcu_torture_alloc_fail;
76542+static atomic_unchecked_t n_rcu_torture_free;
76543+static atomic_unchecked_t n_rcu_torture_mberror;
76544+static atomic_unchecked_t n_rcu_torture_error;
76545 static long n_rcu_torture_barrier_error;
76546 static long n_rcu_torture_boost_ktrerror;
76547 static long n_rcu_torture_boost_rterror;
76548@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
76549
76550 spin_lock_bh(&rcu_torture_lock);
76551 if (list_empty(&rcu_torture_freelist)) {
76552- atomic_inc(&n_rcu_torture_alloc_fail);
76553+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
76554 spin_unlock_bh(&rcu_torture_lock);
76555 return NULL;
76556 }
76557- atomic_inc(&n_rcu_torture_alloc);
76558+ atomic_inc_unchecked(&n_rcu_torture_alloc);
76559 p = rcu_torture_freelist.next;
76560 list_del_init(p);
76561 spin_unlock_bh(&rcu_torture_lock);
76562@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
76563 static void
76564 rcu_torture_free(struct rcu_torture *p)
76565 {
76566- atomic_inc(&n_rcu_torture_free);
76567+ atomic_inc_unchecked(&n_rcu_torture_free);
76568 spin_lock_bh(&rcu_torture_lock);
76569 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
76570 spin_unlock_bh(&rcu_torture_lock);
76571@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
76572 i = rp->rtort_pipe_count;
76573 if (i > RCU_TORTURE_PIPE_LEN)
76574 i = RCU_TORTURE_PIPE_LEN;
76575- atomic_inc(&rcu_torture_wcount[i]);
76576+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76577 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76578 rp->rtort_mbtest = 0;
76579 rcu_torture_free(rp);
76580@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
76581 i = rp->rtort_pipe_count;
76582 if (i > RCU_TORTURE_PIPE_LEN)
76583 i = RCU_TORTURE_PIPE_LEN;
76584- atomic_inc(&rcu_torture_wcount[i]);
76585+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76586 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76587 rp->rtort_mbtest = 0;
76588 list_del(&rp->rtort_free);
76589@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
76590 i = old_rp->rtort_pipe_count;
76591 if (i > RCU_TORTURE_PIPE_LEN)
76592 i = RCU_TORTURE_PIPE_LEN;
76593- atomic_inc(&rcu_torture_wcount[i]);
76594+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76595 old_rp->rtort_pipe_count++;
76596 cur_ops->deferred_free(old_rp);
76597 }
76598@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
76599 }
76600 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76601 if (p->rtort_mbtest == 0)
76602- atomic_inc(&n_rcu_torture_mberror);
76603+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76604 spin_lock(&rand_lock);
76605 cur_ops->read_delay(&rand);
76606 n_rcu_torture_timers++;
76607@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
76608 }
76609 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76610 if (p->rtort_mbtest == 0)
76611- atomic_inc(&n_rcu_torture_mberror);
76612+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76613 cur_ops->read_delay(&rand);
76614 preempt_disable();
76615 pipe_count = p->rtort_pipe_count;
76616@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
76617 rcu_torture_current,
76618 rcu_torture_current_version,
76619 list_empty(&rcu_torture_freelist),
76620- atomic_read(&n_rcu_torture_alloc),
76621- atomic_read(&n_rcu_torture_alloc_fail),
76622- atomic_read(&n_rcu_torture_free));
76623+ atomic_read_unchecked(&n_rcu_torture_alloc),
76624+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
76625+ atomic_read_unchecked(&n_rcu_torture_free));
76626 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
76627- atomic_read(&n_rcu_torture_mberror),
76628+ atomic_read_unchecked(&n_rcu_torture_mberror),
76629 n_rcu_torture_boost_ktrerror,
76630 n_rcu_torture_boost_rterror);
76631 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
76632@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
76633 n_barrier_attempts,
76634 n_rcu_torture_barrier_error);
76635 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
76636- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
76637+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
76638 n_rcu_torture_barrier_error != 0 ||
76639 n_rcu_torture_boost_ktrerror != 0 ||
76640 n_rcu_torture_boost_rterror != 0 ||
76641 n_rcu_torture_boost_failure != 0 ||
76642 i > 1) {
76643 cnt += sprintf(&page[cnt], "!!! ");
76644- atomic_inc(&n_rcu_torture_error);
76645+ atomic_inc_unchecked(&n_rcu_torture_error);
76646 WARN_ON_ONCE(1);
76647 }
76648 cnt += sprintf(&page[cnt], "Reader Pipe: ");
76649@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
76650 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
76651 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76652 cnt += sprintf(&page[cnt], " %d",
76653- atomic_read(&rcu_torture_wcount[i]));
76654+ atomic_read_unchecked(&rcu_torture_wcount[i]));
76655 }
76656 cnt += sprintf(&page[cnt], "\n");
76657 if (cur_ops->stats)
76658@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
76659
76660 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
76661
76662- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76663+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76664 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
76665 else if (n_online_successes != n_online_attempts ||
76666 n_offline_successes != n_offline_attempts)
76667@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
76668
76669 rcu_torture_current = NULL;
76670 rcu_torture_current_version = 0;
76671- atomic_set(&n_rcu_torture_alloc, 0);
76672- atomic_set(&n_rcu_torture_alloc_fail, 0);
76673- atomic_set(&n_rcu_torture_free, 0);
76674- atomic_set(&n_rcu_torture_mberror, 0);
76675- atomic_set(&n_rcu_torture_error, 0);
76676+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
76677+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
76678+ atomic_set_unchecked(&n_rcu_torture_free, 0);
76679+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
76680+ atomic_set_unchecked(&n_rcu_torture_error, 0);
76681 n_rcu_torture_barrier_error = 0;
76682 n_rcu_torture_boost_ktrerror = 0;
76683 n_rcu_torture_boost_rterror = 0;
76684 n_rcu_torture_boost_failure = 0;
76685 n_rcu_torture_boosts = 0;
76686 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
76687- atomic_set(&rcu_torture_wcount[i], 0);
76688+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
76689 for_each_possible_cpu(cpu) {
76690 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76691 per_cpu(rcu_torture_count, cpu)[i] = 0;
76692diff --git a/kernel/rcutree.c b/kernel/rcutree.c
76693index e441b77..dd54f17 100644
76694--- a/kernel/rcutree.c
76695+++ b/kernel/rcutree.c
76696@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
76697 rcu_prepare_for_idle(smp_processor_id());
76698 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76699 smp_mb__before_atomic_inc(); /* See above. */
76700- atomic_inc(&rdtp->dynticks);
76701+ atomic_inc_unchecked(&rdtp->dynticks);
76702 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
76703- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76704+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76705
76706 /*
76707 * It is illegal to enter an extended quiescent state while
76708@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
76709 int user)
76710 {
76711 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
76712- atomic_inc(&rdtp->dynticks);
76713+ atomic_inc_unchecked(&rdtp->dynticks);
76714 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76715 smp_mb__after_atomic_inc(); /* See above. */
76716- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76717+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76718 rcu_cleanup_after_idle(smp_processor_id());
76719 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
76720 if (!user && !is_idle_task(current)) {
76721@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
76722 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
76723
76724 if (rdtp->dynticks_nmi_nesting == 0 &&
76725- (atomic_read(&rdtp->dynticks) & 0x1))
76726+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
76727 return;
76728 rdtp->dynticks_nmi_nesting++;
76729 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
76730- atomic_inc(&rdtp->dynticks);
76731+ atomic_inc_unchecked(&rdtp->dynticks);
76732 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76733 smp_mb__after_atomic_inc(); /* See above. */
76734- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76735+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76736 }
76737
76738 /**
76739@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
76740 return;
76741 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76742 smp_mb__before_atomic_inc(); /* See above. */
76743- atomic_inc(&rdtp->dynticks);
76744+ atomic_inc_unchecked(&rdtp->dynticks);
76745 smp_mb__after_atomic_inc(); /* Force delay to next write. */
76746- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76747+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76748 }
76749
76750 /**
76751@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
76752 int ret;
76753
76754 preempt_disable();
76755- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76756+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76757 preempt_enable();
76758 return ret;
76759 }
76760@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
76761 */
76762 static int dyntick_save_progress_counter(struct rcu_data *rdp)
76763 {
76764- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
76765+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76766 return (rdp->dynticks_snap & 0x1) == 0;
76767 }
76768
76769@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
76770 unsigned int curr;
76771 unsigned int snap;
76772
76773- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
76774+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76775 snap = (unsigned int)rdp->dynticks_snap;
76776
76777 /*
76778@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
76779 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
76780 */
76781 if (till_stall_check < 3) {
76782- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
76783+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
76784 till_stall_check = 3;
76785 } else if (till_stall_check > 300) {
76786- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
76787+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
76788 till_stall_check = 300;
76789 }
76790 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
76791@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
76792 rsp->qlen += rdp->qlen;
76793 rdp->n_cbs_orphaned += rdp->qlen;
76794 rdp->qlen_lazy = 0;
76795- ACCESS_ONCE(rdp->qlen) = 0;
76796+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76797 }
76798
76799 /*
76800@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
76801 }
76802 smp_mb(); /* List handling before counting for rcu_barrier(). */
76803 rdp->qlen_lazy -= count_lazy;
76804- ACCESS_ONCE(rdp->qlen) -= count;
76805+ ACCESS_ONCE_RW(rdp->qlen) -= count;
76806 rdp->n_cbs_invoked += count;
76807
76808 /* Reinstate batch limit if we have worked down the excess. */
76809@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76810 /*
76811 * Do RCU core processing for the current CPU.
76812 */
76813-static void rcu_process_callbacks(struct softirq_action *unused)
76814+static void rcu_process_callbacks(void)
76815 {
76816 struct rcu_state *rsp;
76817
76818@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76819 local_irq_restore(flags);
76820 return;
76821 }
76822- ACCESS_ONCE(rdp->qlen)++;
76823+ ACCESS_ONCE_RW(rdp->qlen)++;
76824 if (lazy)
76825 rdp->qlen_lazy++;
76826 else
76827@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76828 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76829 * course be required on a 64-bit system.
76830 */
76831- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76832+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76833 (ulong)atomic_long_read(&rsp->expedited_done) +
76834 ULONG_MAX / 8)) {
76835 synchronize_sched();
76836- atomic_long_inc(&rsp->expedited_wrap);
76837+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
76838 return;
76839 }
76840
76841@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76842 * Take a ticket. Note that atomic_inc_return() implies a
76843 * full memory barrier.
76844 */
76845- snap = atomic_long_inc_return(&rsp->expedited_start);
76846+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76847 firstsnap = snap;
76848 get_online_cpus();
76849 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
76850@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
76851 synchronize_sched_expedited_cpu_stop,
76852 NULL) == -EAGAIN) {
76853 put_online_cpus();
76854- atomic_long_inc(&rsp->expedited_tryfail);
76855+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
76856
76857 /* Check to see if someone else did our work for us. */
76858 s = atomic_long_read(&rsp->expedited_done);
76859 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76860 /* ensure test happens before caller kfree */
76861 smp_mb__before_atomic_inc(); /* ^^^ */
76862- atomic_long_inc(&rsp->expedited_workdone1);
76863+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
76864 return;
76865 }
76866
76867@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
76868 udelay(trycount * num_online_cpus());
76869 } else {
76870 wait_rcu_gp(call_rcu_sched);
76871- atomic_long_inc(&rsp->expedited_normal);
76872+ atomic_long_inc_unchecked(&rsp->expedited_normal);
76873 return;
76874 }
76875
76876@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
76877 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76878 /* ensure test happens before caller kfree */
76879 smp_mb__before_atomic_inc(); /* ^^^ */
76880- atomic_long_inc(&rsp->expedited_workdone2);
76881+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
76882 return;
76883 }
76884
76885@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
76886 * period works for us.
76887 */
76888 get_online_cpus();
76889- snap = atomic_long_read(&rsp->expedited_start);
76890+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
76891 smp_mb(); /* ensure read is before try_stop_cpus(). */
76892 }
76893- atomic_long_inc(&rsp->expedited_stoppedcpus);
76894+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
76895
76896 /*
76897 * Everyone up to our most recent fetch is covered by our grace
76898@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
76899 * than we did already did their update.
76900 */
76901 do {
76902- atomic_long_inc(&rsp->expedited_done_tries);
76903+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
76904 s = atomic_long_read(&rsp->expedited_done);
76905 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
76906 /* ensure test happens before caller kfree */
76907 smp_mb__before_atomic_inc(); /* ^^^ */
76908- atomic_long_inc(&rsp->expedited_done_lost);
76909+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
76910 break;
76911 }
76912 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76913- atomic_long_inc(&rsp->expedited_done_exit);
76914+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76915
76916 put_online_cpus();
76917 }
76918@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76919 * ACCESS_ONCE() to prevent the compiler from speculating
76920 * the increment to precede the early-exit check.
76921 */
76922- ACCESS_ONCE(rsp->n_barrier_done)++;
76923+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76924 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76925 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76926 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76927@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76928
76929 /* Increment ->n_barrier_done to prevent duplicate work. */
76930 smp_mb(); /* Keep increment after above mechanism. */
76931- ACCESS_ONCE(rsp->n_barrier_done)++;
76932+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76933 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76934 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76935 smp_mb(); /* Keep increment before caller's subsequent code. */
76936@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76937 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76938 init_callback_list(rdp);
76939 rdp->qlen_lazy = 0;
76940- ACCESS_ONCE(rdp->qlen) = 0;
76941+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76942 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76943 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76944- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76945+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76946 #ifdef CONFIG_RCU_USER_QS
76947 WARN_ON_ONCE(rdp->dynticks->in_user);
76948 #endif
76949@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76950 rdp->blimit = blimit;
76951 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76952 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76953- atomic_set(&rdp->dynticks->dynticks,
76954- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76955+ atomic_set_unchecked(&rdp->dynticks->dynticks,
76956+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76957 rcu_prepare_for_idle_init(cpu);
76958 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76959
76960diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76961index 4b69291..704c92e 100644
76962--- a/kernel/rcutree.h
76963+++ b/kernel/rcutree.h
76964@@ -86,7 +86,7 @@ struct rcu_dynticks {
76965 long long dynticks_nesting; /* Track irq/process nesting level. */
76966 /* Process level is worth LLONG_MAX/2. */
76967 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76968- atomic_t dynticks; /* Even value for idle, else odd. */
76969+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76970 #ifdef CONFIG_RCU_FAST_NO_HZ
76971 int dyntick_drain; /* Prepare-for-idle state variable. */
76972 unsigned long dyntick_holdoff;
76973@@ -423,17 +423,17 @@ struct rcu_state {
76974 /* _rcu_barrier(). */
76975 /* End of fields guarded by barrier_mutex. */
76976
76977- atomic_long_t expedited_start; /* Starting ticket. */
76978- atomic_long_t expedited_done; /* Done ticket. */
76979- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76980- atomic_long_t expedited_tryfail; /* # acquisition failures. */
76981- atomic_long_t expedited_workdone1; /* # done by others #1. */
76982- atomic_long_t expedited_workdone2; /* # done by others #2. */
76983- atomic_long_t expedited_normal; /* # fallbacks to normal. */
76984- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76985- atomic_long_t expedited_done_tries; /* # tries to update _done. */
76986- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76987- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76988+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76989+ atomic_long_t expedited_done; /* Done ticket. */
76990+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76991+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76992+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76993+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76994+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76995+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76996+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76997+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76998+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76999
77000 unsigned long jiffies_force_qs; /* Time at which to invoke */
77001 /* force_quiescent_state(). */
77002diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
77003index c1cc7e1..f62e436 100644
77004--- a/kernel/rcutree_plugin.h
77005+++ b/kernel/rcutree_plugin.h
77006@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
77007
77008 /* Clean up and exit. */
77009 smp_mb(); /* ensure expedited GP seen before counter increment. */
77010- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
77011+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
77012 unlock_mb_ret:
77013 mutex_unlock(&sync_rcu_preempt_exp_mutex);
77014 mb_ret:
77015@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
77016 free_cpumask_var(cm);
77017 }
77018
77019-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
77020+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
77021 .store = &rcu_cpu_kthread_task,
77022 .thread_should_run = rcu_cpu_kthread_should_run,
77023 .thread_fn = rcu_cpu_kthread,
77024@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
77025 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
77026 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
77027 cpu, ticks_value, ticks_title,
77028- atomic_read(&rdtp->dynticks) & 0xfff,
77029+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
77030 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
77031 fast_no_hz);
77032 }
77033@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
77034
77035 /* Enqueue the callback on the nocb list and update counts. */
77036 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
77037- ACCESS_ONCE(*old_rhpp) = rhp;
77038+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
77039 atomic_long_add(rhcount, &rdp->nocb_q_count);
77040 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
77041
77042@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
77043 * Extract queued callbacks, update counts, and wait
77044 * for a grace period to elapse.
77045 */
77046- ACCESS_ONCE(rdp->nocb_head) = NULL;
77047+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
77048 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
77049 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
77050 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
77051- ACCESS_ONCE(rdp->nocb_p_count) += c;
77052- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
77053+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
77054+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
77055 wait_rcu_gp(rdp->rsp->call_remote);
77056
77057 /* Each pass through the following loop invokes a callback. */
77058@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
77059 list = next;
77060 }
77061 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
77062- ACCESS_ONCE(rdp->nocb_p_count) -= c;
77063- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
77064+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
77065+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
77066 rdp->n_nocbs_invoked += c;
77067 }
77068 return 0;
77069@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
77070 rdp = per_cpu_ptr(rsp->rda, cpu);
77071 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
77072 BUG_ON(IS_ERR(t));
77073- ACCESS_ONCE(rdp->nocb_kthread) = t;
77074+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
77075 }
77076 }
77077
77078diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
77079index 0d095dc..1985b19 100644
77080--- a/kernel/rcutree_trace.c
77081+++ b/kernel/rcutree_trace.c
77082@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
77083 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
77084 rdp->passed_quiesce, rdp->qs_pending);
77085 seq_printf(m, " dt=%d/%llx/%d df=%lu",
77086- atomic_read(&rdp->dynticks->dynticks),
77087+ atomic_read_unchecked(&rdp->dynticks->dynticks),
77088 rdp->dynticks->dynticks_nesting,
77089 rdp->dynticks->dynticks_nmi_nesting,
77090 rdp->dynticks_fqs);
77091@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
77092 struct rcu_state *rsp = (struct rcu_state *)m->private;
77093
77094 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",
77095- atomic_long_read(&rsp->expedited_start),
77096+ atomic_long_read_unchecked(&rsp->expedited_start),
77097 atomic_long_read(&rsp->expedited_done),
77098- atomic_long_read(&rsp->expedited_wrap),
77099- atomic_long_read(&rsp->expedited_tryfail),
77100- atomic_long_read(&rsp->expedited_workdone1),
77101- atomic_long_read(&rsp->expedited_workdone2),
77102- atomic_long_read(&rsp->expedited_normal),
77103- atomic_long_read(&rsp->expedited_stoppedcpus),
77104- atomic_long_read(&rsp->expedited_done_tries),
77105- atomic_long_read(&rsp->expedited_done_lost),
77106- atomic_long_read(&rsp->expedited_done_exit));
77107+ atomic_long_read_unchecked(&rsp->expedited_wrap),
77108+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
77109+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
77110+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
77111+ atomic_long_read_unchecked(&rsp->expedited_normal),
77112+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
77113+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
77114+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
77115+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
77116 return 0;
77117 }
77118
77119diff --git a/kernel/resource.c b/kernel/resource.c
77120index 73f35d4..4684fc4 100644
77121--- a/kernel/resource.c
77122+++ b/kernel/resource.c
77123@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
77124
77125 static int __init ioresources_init(void)
77126 {
77127+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77128+#ifdef CONFIG_GRKERNSEC_PROC_USER
77129+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
77130+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
77131+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77132+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
77133+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
77134+#endif
77135+#else
77136 proc_create("ioports", 0, NULL, &proc_ioports_operations);
77137 proc_create("iomem", 0, NULL, &proc_iomem_operations);
77138+#endif
77139 return 0;
77140 }
77141 __initcall(ioresources_init);
77142diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
77143index 98ec494..4241d6d 100644
77144--- a/kernel/rtmutex-tester.c
77145+++ b/kernel/rtmutex-tester.c
77146@@ -20,7 +20,7 @@
77147 #define MAX_RT_TEST_MUTEXES 8
77148
77149 static spinlock_t rttest_lock;
77150-static atomic_t rttest_event;
77151+static atomic_unchecked_t rttest_event;
77152
77153 struct test_thread_data {
77154 int opcode;
77155@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77156
77157 case RTTEST_LOCKCONT:
77158 td->mutexes[td->opdata] = 1;
77159- td->event = atomic_add_return(1, &rttest_event);
77160+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77161 return 0;
77162
77163 case RTTEST_RESET:
77164@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77165 return 0;
77166
77167 case RTTEST_RESETEVENT:
77168- atomic_set(&rttest_event, 0);
77169+ atomic_set_unchecked(&rttest_event, 0);
77170 return 0;
77171
77172 default:
77173@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77174 return ret;
77175
77176 td->mutexes[id] = 1;
77177- td->event = atomic_add_return(1, &rttest_event);
77178+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77179 rt_mutex_lock(&mutexes[id]);
77180- td->event = atomic_add_return(1, &rttest_event);
77181+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77182 td->mutexes[id] = 4;
77183 return 0;
77184
77185@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77186 return ret;
77187
77188 td->mutexes[id] = 1;
77189- td->event = atomic_add_return(1, &rttest_event);
77190+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77191 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
77192- td->event = atomic_add_return(1, &rttest_event);
77193+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77194 td->mutexes[id] = ret ? 0 : 4;
77195 return ret ? -EINTR : 0;
77196
77197@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77198 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
77199 return ret;
77200
77201- td->event = atomic_add_return(1, &rttest_event);
77202+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77203 rt_mutex_unlock(&mutexes[id]);
77204- td->event = atomic_add_return(1, &rttest_event);
77205+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77206 td->mutexes[id] = 0;
77207 return 0;
77208
77209@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77210 break;
77211
77212 td->mutexes[dat] = 2;
77213- td->event = atomic_add_return(1, &rttest_event);
77214+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77215 break;
77216
77217 default:
77218@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77219 return;
77220
77221 td->mutexes[dat] = 3;
77222- td->event = atomic_add_return(1, &rttest_event);
77223+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77224 break;
77225
77226 case RTTEST_LOCKNOWAIT:
77227@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77228 return;
77229
77230 td->mutexes[dat] = 1;
77231- td->event = atomic_add_return(1, &rttest_event);
77232+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77233 return;
77234
77235 default:
77236diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
77237index 0984a21..939f183 100644
77238--- a/kernel/sched/auto_group.c
77239+++ b/kernel/sched/auto_group.c
77240@@ -11,7 +11,7 @@
77241
77242 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
77243 static struct autogroup autogroup_default;
77244-static atomic_t autogroup_seq_nr;
77245+static atomic_unchecked_t autogroup_seq_nr;
77246
77247 void __init autogroup_init(struct task_struct *init_task)
77248 {
77249@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
77250
77251 kref_init(&ag->kref);
77252 init_rwsem(&ag->lock);
77253- ag->id = atomic_inc_return(&autogroup_seq_nr);
77254+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
77255 ag->tg = tg;
77256 #ifdef CONFIG_RT_GROUP_SCHED
77257 /*
77258diff --git a/kernel/sched/core.c b/kernel/sched/core.c
77259index 26058d0..e315889 100644
77260--- a/kernel/sched/core.c
77261+++ b/kernel/sched/core.c
77262@@ -3367,7 +3367,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
77263 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77264 * positive (at least 1, or number of jiffies left till timeout) if completed.
77265 */
77266-long __sched
77267+long __sched __intentional_overflow(-1)
77268 wait_for_completion_interruptible_timeout(struct completion *x,
77269 unsigned long timeout)
77270 {
77271@@ -3384,7 +3384,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
77272 *
77273 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
77274 */
77275-int __sched wait_for_completion_killable(struct completion *x)
77276+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
77277 {
77278 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
77279 if (t == -ERESTARTSYS)
77280@@ -3405,7 +3405,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
77281 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77282 * positive (at least 1, or number of jiffies left till timeout) if completed.
77283 */
77284-long __sched
77285+long __sched __intentional_overflow(-1)
77286 wait_for_completion_killable_timeout(struct completion *x,
77287 unsigned long timeout)
77288 {
77289@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
77290 /* convert nice value [19,-20] to rlimit style value [1,40] */
77291 int nice_rlim = 20 - nice;
77292
77293+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
77294+
77295 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
77296 capable(CAP_SYS_NICE));
77297 }
77298@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
77299 if (nice > 19)
77300 nice = 19;
77301
77302- if (increment < 0 && !can_nice(current, nice))
77303+ if (increment < 0 && (!can_nice(current, nice) ||
77304+ gr_handle_chroot_nice()))
77305 return -EPERM;
77306
77307 retval = security_task_setnice(current, nice);
77308@@ -3818,6 +3821,7 @@ recheck:
77309 unsigned long rlim_rtprio =
77310 task_rlimit(p, RLIMIT_RTPRIO);
77311
77312+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
77313 /* can't set/change the rt policy */
77314 if (policy != p->policy && !rlim_rtprio)
77315 return -EPERM;
77316@@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
77317
77318 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
77319
77320-static struct ctl_table sd_ctl_dir[] = {
77321+static ctl_table_no_const sd_ctl_dir[] __read_only = {
77322 {
77323 .procname = "sched_domain",
77324 .mode = 0555,
77325@@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
77326 {}
77327 };
77328
77329-static struct ctl_table *sd_alloc_ctl_entry(int n)
77330+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
77331 {
77332- struct ctl_table *entry =
77333+ ctl_table_no_const *entry =
77334 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
77335
77336 return entry;
77337 }
77338
77339-static void sd_free_ctl_entry(struct ctl_table **tablep)
77340+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
77341 {
77342- struct ctl_table *entry;
77343+ ctl_table_no_const *entry;
77344
77345 /*
77346 * In the intermediate directories, both the child directory and
77347@@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
77348 * will always be set. In the lowest directory the names are
77349 * static strings and all have proc handlers.
77350 */
77351- for (entry = *tablep; entry->mode; entry++) {
77352- if (entry->child)
77353- sd_free_ctl_entry(&entry->child);
77354+ for (entry = tablep; entry->mode; entry++) {
77355+ if (entry->child) {
77356+ sd_free_ctl_entry(entry->child);
77357+ pax_open_kernel();
77358+ entry->child = NULL;
77359+ pax_close_kernel();
77360+ }
77361 if (entry->proc_handler == NULL)
77362 kfree(entry->procname);
77363 }
77364
77365- kfree(*tablep);
77366- *tablep = NULL;
77367+ kfree(tablep);
77368 }
77369
77370 static int min_load_idx = 0;
77371 static int max_load_idx = CPU_LOAD_IDX_MAX;
77372
77373 static void
77374-set_table_entry(struct ctl_table *entry,
77375+set_table_entry(ctl_table_no_const *entry,
77376 const char *procname, void *data, int maxlen,
77377 umode_t mode, proc_handler *proc_handler,
77378 bool load_idx)
77379@@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
77380 static struct ctl_table *
77381 sd_alloc_ctl_domain_table(struct sched_domain *sd)
77382 {
77383- struct ctl_table *table = sd_alloc_ctl_entry(13);
77384+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
77385
77386 if (table == NULL)
77387 return NULL;
77388@@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
77389 return table;
77390 }
77391
77392-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
77393+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
77394 {
77395- struct ctl_table *entry, *table;
77396+ ctl_table_no_const *entry, *table;
77397 struct sched_domain *sd;
77398 int domain_num = 0, i;
77399 char buf[32];
77400@@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
77401 static void register_sched_domain_sysctl(void)
77402 {
77403 int i, cpu_num = num_possible_cpus();
77404- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
77405+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
77406 char buf[32];
77407
77408 WARN_ON(sd_ctl_dir[0].child);
77409+ pax_open_kernel();
77410 sd_ctl_dir[0].child = entry;
77411+ pax_close_kernel();
77412
77413 if (entry == NULL)
77414 return;
77415@@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
77416 if (sd_sysctl_header)
77417 unregister_sysctl_table(sd_sysctl_header);
77418 sd_sysctl_header = NULL;
77419- if (sd_ctl_dir[0].child)
77420- sd_free_ctl_entry(&sd_ctl_dir[0].child);
77421+ if (sd_ctl_dir[0].child) {
77422+ sd_free_ctl_entry(sd_ctl_dir[0].child);
77423+ pax_open_kernel();
77424+ sd_ctl_dir[0].child = NULL;
77425+ pax_close_kernel();
77426+ }
77427 }
77428 #else
77429 static void register_sched_domain_sysctl(void)
77430@@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
77431 * happens before everything else. This has to be lower priority than
77432 * the notifier in the perf_event subsystem, though.
77433 */
77434-static struct notifier_block __cpuinitdata migration_notifier = {
77435+static struct notifier_block migration_notifier = {
77436 .notifier_call = migration_call,
77437 .priority = CPU_PRI_MIGRATION,
77438 };
77439diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
77440index 81fa536..6ccf96a 100644
77441--- a/kernel/sched/fair.c
77442+++ b/kernel/sched/fair.c
77443@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
77444
77445 static void reset_ptenuma_scan(struct task_struct *p)
77446 {
77447- ACCESS_ONCE(p->mm->numa_scan_seq)++;
77448+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
77449 p->mm->numa_scan_offset = 0;
77450 }
77451
77452@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
77453 */
77454 static int select_idle_sibling(struct task_struct *p, int target)
77455 {
77456- int cpu = smp_processor_id();
77457- int prev_cpu = task_cpu(p);
77458 struct sched_domain *sd;
77459 struct sched_group *sg;
77460- int i;
77461+ int i = task_cpu(p);
77462
77463- /*
77464- * If the task is going to be woken-up on this cpu and if it is
77465- * already idle, then it is the right target.
77466- */
77467- if (target == cpu && idle_cpu(cpu))
77468- return cpu;
77469+ if (idle_cpu(target))
77470+ return target;
77471
77472 /*
77473- * If the task is going to be woken-up on the cpu where it previously
77474- * ran and if it is currently idle, then it the right target.
77475+ * If the prevous cpu is cache affine and idle, don't be stupid.
77476 */
77477- if (target == prev_cpu && idle_cpu(prev_cpu))
77478- return prev_cpu;
77479+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
77480+ return i;
77481
77482 /*
77483 * Otherwise, iterate the domains and find an elegible idle cpu.
77484@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
77485 goto next;
77486
77487 for_each_cpu(i, sched_group_cpus(sg)) {
77488- if (!idle_cpu(i))
77489+ if (i == target || !idle_cpu(i))
77490 goto next;
77491 }
77492
77493@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
77494 * run_rebalance_domains is triggered when needed from the scheduler tick.
77495 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
77496 */
77497-static void run_rebalance_domains(struct softirq_action *h)
77498+static void run_rebalance_domains(void)
77499 {
77500 int this_cpu = smp_processor_id();
77501 struct rq *this_rq = cpu_rq(this_cpu);
77502diff --git a/kernel/signal.c b/kernel/signal.c
77503index 7591ccc..8988390 100644
77504--- a/kernel/signal.c
77505+++ b/kernel/signal.c
77506@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
77507
77508 int print_fatal_signals __read_mostly;
77509
77510-static void __user *sig_handler(struct task_struct *t, int sig)
77511+static __sighandler_t sig_handler(struct task_struct *t, int sig)
77512 {
77513 return t->sighand->action[sig - 1].sa.sa_handler;
77514 }
77515
77516-static int sig_handler_ignored(void __user *handler, int sig)
77517+static int sig_handler_ignored(__sighandler_t handler, int sig)
77518 {
77519 /* Is it explicitly or implicitly ignored? */
77520 return handler == SIG_IGN ||
77521@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
77522
77523 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
77524 {
77525- void __user *handler;
77526+ __sighandler_t handler;
77527
77528 handler = sig_handler(t, sig);
77529
77530@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
77531 atomic_inc(&user->sigpending);
77532 rcu_read_unlock();
77533
77534+ if (!override_rlimit)
77535+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
77536+
77537 if (override_rlimit ||
77538 atomic_read(&user->sigpending) <=
77539 task_rlimit(t, RLIMIT_SIGPENDING)) {
77540@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
77541
77542 int unhandled_signal(struct task_struct *tsk, int sig)
77543 {
77544- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
77545+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
77546 if (is_global_init(tsk))
77547 return 1;
77548 if (handler != SIG_IGN && handler != SIG_DFL)
77549@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
77550 }
77551 }
77552
77553+ /* allow glibc communication via tgkill to other threads in our
77554+ thread group */
77555+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
77556+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
77557+ && gr_handle_signal(t, sig))
77558+ return -EPERM;
77559+
77560 return security_task_kill(t, info, sig, 0);
77561 }
77562
77563@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77564 return send_signal(sig, info, p, 1);
77565 }
77566
77567-static int
77568+int
77569 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77570 {
77571 return send_signal(sig, info, t, 0);
77572@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77573 unsigned long int flags;
77574 int ret, blocked, ignored;
77575 struct k_sigaction *action;
77576+ int is_unhandled = 0;
77577
77578 spin_lock_irqsave(&t->sighand->siglock, flags);
77579 action = &t->sighand->action[sig-1];
77580@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77581 }
77582 if (action->sa.sa_handler == SIG_DFL)
77583 t->signal->flags &= ~SIGNAL_UNKILLABLE;
77584+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
77585+ is_unhandled = 1;
77586 ret = specific_send_sig_info(sig, info, t);
77587 spin_unlock_irqrestore(&t->sighand->siglock, flags);
77588
77589+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
77590+ normal operation */
77591+ if (is_unhandled) {
77592+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
77593+ gr_handle_crash(t, sig);
77594+ }
77595+
77596 return ret;
77597 }
77598
77599@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77600 ret = check_kill_permission(sig, info, p);
77601 rcu_read_unlock();
77602
77603- if (!ret && sig)
77604+ if (!ret && sig) {
77605 ret = do_send_sig_info(sig, info, p, true);
77606+ if (!ret)
77607+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
77608+ }
77609
77610 return ret;
77611 }
77612@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
77613 int error = -ESRCH;
77614
77615 rcu_read_lock();
77616- p = find_task_by_vpid(pid);
77617+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77618+ /* allow glibc communication via tgkill to other threads in our
77619+ thread group */
77620+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
77621+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
77622+ p = find_task_by_vpid_unrestricted(pid);
77623+ else
77624+#endif
77625+ p = find_task_by_vpid(pid);
77626 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
77627 error = check_kill_permission(sig, info, p);
77628 /*
77629@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
77630 }
77631 seg = get_fs();
77632 set_fs(KERNEL_DS);
77633- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
77634- (stack_t __force __user *) &uoss,
77635+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
77636+ (stack_t __force_user *) &uoss,
77637 compat_user_stack_pointer());
77638 set_fs(seg);
77639 if (ret >= 0 && uoss_ptr) {
77640diff --git a/kernel/smp.c b/kernel/smp.c
77641index 69f38bd..77bbf12 100644
77642--- a/kernel/smp.c
77643+++ b/kernel/smp.c
77644@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
77645 return NOTIFY_OK;
77646 }
77647
77648-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
77649+static struct notifier_block hotplug_cfd_notifier = {
77650 .notifier_call = hotplug_cfd,
77651 };
77652
77653diff --git a/kernel/smpboot.c b/kernel/smpboot.c
77654index d6c5fc0..530560c 100644
77655--- a/kernel/smpboot.c
77656+++ b/kernel/smpboot.c
77657@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
77658 }
77659 smpboot_unpark_thread(plug_thread, cpu);
77660 }
77661- list_add(&plug_thread->list, &hotplug_threads);
77662+ pax_list_add(&plug_thread->list, &hotplug_threads);
77663 out:
77664 mutex_unlock(&smpboot_threads_lock);
77665 return ret;
77666@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
77667 {
77668 get_online_cpus();
77669 mutex_lock(&smpboot_threads_lock);
77670- list_del(&plug_thread->list);
77671+ pax_list_del(&plug_thread->list);
77672 smpboot_destroy_threads(plug_thread);
77673 mutex_unlock(&smpboot_threads_lock);
77674 put_online_cpus();
77675diff --git a/kernel/softirq.c b/kernel/softirq.c
77676index ed567ba..e71dabf 100644
77677--- a/kernel/softirq.c
77678+++ b/kernel/softirq.c
77679@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
77680 EXPORT_SYMBOL(irq_stat);
77681 #endif
77682
77683-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
77684+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
77685
77686 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
77687
77688-char *softirq_to_name[NR_SOFTIRQS] = {
77689+const char * const softirq_to_name[NR_SOFTIRQS] = {
77690 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
77691 "TASKLET", "SCHED", "HRTIMER", "RCU"
77692 };
77693@@ -244,7 +244,7 @@ restart:
77694 kstat_incr_softirqs_this_cpu(vec_nr);
77695
77696 trace_softirq_entry(vec_nr);
77697- h->action(h);
77698+ h->action();
77699 trace_softirq_exit(vec_nr);
77700 if (unlikely(prev_count != preempt_count())) {
77701 printk(KERN_ERR "huh, entered softirq %u %s %p"
77702@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
77703 or_softirq_pending(1UL << nr);
77704 }
77705
77706-void open_softirq(int nr, void (*action)(struct softirq_action *))
77707+void __init open_softirq(int nr, void (*action)(void))
77708 {
77709 softirq_vec[nr].action = action;
77710 }
77711@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
77712
77713 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
77714
77715-static void tasklet_action(struct softirq_action *a)
77716+static void tasklet_action(void)
77717 {
77718 struct tasklet_struct *list;
77719
77720@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
77721 }
77722 }
77723
77724-static void tasklet_hi_action(struct softirq_action *a)
77725+static void tasklet_hi_action(void)
77726 {
77727 struct tasklet_struct *list;
77728
77729@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
77730 return NOTIFY_OK;
77731 }
77732
77733-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
77734+static struct notifier_block remote_softirq_cpu_notifier = {
77735 .notifier_call = remote_softirq_cpu_notify,
77736 };
77737
77738@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
77739 return NOTIFY_OK;
77740 }
77741
77742-static struct notifier_block __cpuinitdata cpu_nfb = {
77743+static struct notifier_block cpu_nfb = {
77744 .notifier_call = cpu_callback
77745 };
77746
77747-static struct smp_hotplug_thread softirq_threads = {
77748+static struct smp_hotplug_thread softirq_threads __read_only = {
77749 .store = &ksoftirqd,
77750 .thread_should_run = ksoftirqd_should_run,
77751 .thread_fn = run_ksoftirqd,
77752diff --git a/kernel/srcu.c b/kernel/srcu.c
77753index 2b85982..d52ab26 100644
77754--- a/kernel/srcu.c
77755+++ b/kernel/srcu.c
77756@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
77757 preempt_disable();
77758 idx = rcu_dereference_index_check(sp->completed,
77759 rcu_read_lock_sched_held()) & 0x1;
77760- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77761+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77762 smp_mb(); /* B */ /* Avoid leaking the critical section. */
77763- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77764+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77765 preempt_enable();
77766 return idx;
77767 }
77768@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
77769 {
77770 preempt_disable();
77771 smp_mb(); /* C */ /* Avoid leaking the critical section. */
77772- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77773+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77774 preempt_enable();
77775 }
77776 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
77777diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
77778index 2f194e9..2c05ea9 100644
77779--- a/kernel/stop_machine.c
77780+++ b/kernel/stop_machine.c
77781@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
77782 * cpu notifiers. It currently shares the same priority as sched
77783 * migration_notifier.
77784 */
77785-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
77786+static struct notifier_block cpu_stop_cpu_notifier = {
77787 .notifier_call = cpu_stop_cpu_callback,
77788 .priority = 10,
77789 };
77790diff --git a/kernel/sys.c b/kernel/sys.c
77791index 265b376..4e42ef5 100644
77792--- a/kernel/sys.c
77793+++ b/kernel/sys.c
77794@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
77795 error = -EACCES;
77796 goto out;
77797 }
77798+
77799+ if (gr_handle_chroot_setpriority(p, niceval)) {
77800+ error = -EACCES;
77801+ goto out;
77802+ }
77803+
77804 no_nice = security_task_setnice(p, niceval);
77805 if (no_nice) {
77806 error = no_nice;
77807@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
77808 goto error;
77809 }
77810
77811+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
77812+ goto error;
77813+
77814 if (rgid != (gid_t) -1 ||
77815 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
77816 new->sgid = new->egid;
77817@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
77818 old = current_cred();
77819
77820 retval = -EPERM;
77821+
77822+ if (gr_check_group_change(kgid, kgid, kgid))
77823+ goto error;
77824+
77825 if (nsown_capable(CAP_SETGID))
77826 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77827 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77828@@ -647,7 +660,7 @@ error:
77829 /*
77830 * change the user struct in a credentials set to match the new UID
77831 */
77832-static int set_user(struct cred *new)
77833+int set_user(struct cred *new)
77834 {
77835 struct user_struct *new_user;
77836
77837@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77838 goto error;
77839 }
77840
77841+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77842+ goto error;
77843+
77844 if (!uid_eq(new->uid, old->uid)) {
77845 retval = set_user(new);
77846 if (retval < 0)
77847@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77848 old = current_cred();
77849
77850 retval = -EPERM;
77851+
77852+ if (gr_check_crash_uid(kuid))
77853+ goto error;
77854+ if (gr_check_user_change(kuid, kuid, kuid))
77855+ goto error;
77856+
77857 if (nsown_capable(CAP_SETUID)) {
77858 new->suid = new->uid = kuid;
77859 if (!uid_eq(kuid, old->uid)) {
77860@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
77861 goto error;
77862 }
77863
77864+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
77865+ goto error;
77866+
77867 if (ruid != (uid_t) -1) {
77868 new->uid = kruid;
77869 if (!uid_eq(kruid, old->uid)) {
77870@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
77871 goto error;
77872 }
77873
77874+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
77875+ goto error;
77876+
77877 if (rgid != (gid_t) -1)
77878 new->gid = krgid;
77879 if (egid != (gid_t) -1)
77880@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77881 if (!uid_valid(kuid))
77882 return old_fsuid;
77883
77884+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
77885+ goto error;
77886+
77887 new = prepare_creds();
77888 if (!new)
77889 return old_fsuid;
77890@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77891 }
77892 }
77893
77894+error:
77895 abort_creds(new);
77896 return old_fsuid;
77897
77898@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
77899 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
77900 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
77901 nsown_capable(CAP_SETGID)) {
77902+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
77903+ goto error;
77904+
77905 if (!gid_eq(kgid, old->fsgid)) {
77906 new->fsgid = kgid;
77907 goto change_okay;
77908 }
77909 }
77910
77911+error:
77912 abort_creds(new);
77913 return old_fsgid;
77914
77915@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
77916 return -EFAULT;
77917
77918 down_read(&uts_sem);
77919- error = __copy_to_user(&name->sysname, &utsname()->sysname,
77920+ error = __copy_to_user(name->sysname, &utsname()->sysname,
77921 __OLD_UTS_LEN);
77922 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
77923- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
77924+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
77925 __OLD_UTS_LEN);
77926 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
77927- error |= __copy_to_user(&name->release, &utsname()->release,
77928+ error |= __copy_to_user(name->release, &utsname()->release,
77929 __OLD_UTS_LEN);
77930 error |= __put_user(0, name->release + __OLD_UTS_LEN);
77931- error |= __copy_to_user(&name->version, &utsname()->version,
77932+ error |= __copy_to_user(name->version, &utsname()->version,
77933 __OLD_UTS_LEN);
77934 error |= __put_user(0, name->version + __OLD_UTS_LEN);
77935- error |= __copy_to_user(&name->machine, &utsname()->machine,
77936+ error |= __copy_to_user(name->machine, &utsname()->machine,
77937 __OLD_UTS_LEN);
77938 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77939 up_read(&uts_sem);
77940@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77941 error = get_dumpable(me->mm);
77942 break;
77943 case PR_SET_DUMPABLE:
77944- if (arg2 < 0 || arg2 > 1) {
77945+ if (arg2 > 1) {
77946 error = -EINVAL;
77947 break;
77948 }
77949diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77950index c88878d..e4fa5d1 100644
77951--- a/kernel/sysctl.c
77952+++ b/kernel/sysctl.c
77953@@ -92,7 +92,6 @@
77954
77955
77956 #if defined(CONFIG_SYSCTL)
77957-
77958 /* External variables not in a header file. */
77959 extern int sysctl_overcommit_memory;
77960 extern int sysctl_overcommit_ratio;
77961@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77962 void __user *buffer, size_t *lenp, loff_t *ppos);
77963 #endif
77964
77965-#ifdef CONFIG_PRINTK
77966 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77967 void __user *buffer, size_t *lenp, loff_t *ppos);
77968-#endif
77969
77970 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77971 void __user *buffer, size_t *lenp, loff_t *ppos);
77972@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77973
77974 #endif
77975
77976+extern struct ctl_table grsecurity_table[];
77977+
77978 static struct ctl_table kern_table[];
77979 static struct ctl_table vm_table[];
77980 static struct ctl_table fs_table[];
77981@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77982 int sysctl_legacy_va_layout;
77983 #endif
77984
77985+#ifdef CONFIG_PAX_SOFTMODE
77986+static ctl_table pax_table[] = {
77987+ {
77988+ .procname = "softmode",
77989+ .data = &pax_softmode,
77990+ .maxlen = sizeof(unsigned int),
77991+ .mode = 0600,
77992+ .proc_handler = &proc_dointvec,
77993+ },
77994+
77995+ { }
77996+};
77997+#endif
77998+
77999 /* The default sysctl tables: */
78000
78001 static struct ctl_table sysctl_base_table[] = {
78002@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
78003 #endif
78004
78005 static struct ctl_table kern_table[] = {
78006+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
78007+ {
78008+ .procname = "grsecurity",
78009+ .mode = 0500,
78010+ .child = grsecurity_table,
78011+ },
78012+#endif
78013+
78014+#ifdef CONFIG_PAX_SOFTMODE
78015+ {
78016+ .procname = "pax",
78017+ .mode = 0500,
78018+ .child = pax_table,
78019+ },
78020+#endif
78021+
78022 {
78023 .procname = "sched_child_runs_first",
78024 .data = &sysctl_sched_child_runs_first,
78025@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
78026 .data = &modprobe_path,
78027 .maxlen = KMOD_PATH_LEN,
78028 .mode = 0644,
78029- .proc_handler = proc_dostring,
78030+ .proc_handler = proc_dostring_modpriv,
78031 },
78032 {
78033 .procname = "modules_disabled",
78034@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
78035 .extra1 = &zero,
78036 .extra2 = &one,
78037 },
78038+#endif
78039 {
78040 .procname = "kptr_restrict",
78041 .data = &kptr_restrict,
78042 .maxlen = sizeof(int),
78043 .mode = 0644,
78044 .proc_handler = proc_dointvec_minmax_sysadmin,
78045+#ifdef CONFIG_GRKERNSEC_HIDESYM
78046+ .extra1 = &two,
78047+#else
78048 .extra1 = &zero,
78049+#endif
78050 .extra2 = &two,
78051 },
78052-#endif
78053 {
78054 .procname = "ngroups_max",
78055 .data = &ngroups_max,
78056@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
78057 .proc_handler = proc_dointvec_minmax,
78058 .extra1 = &zero,
78059 },
78060+ {
78061+ .procname = "heap_stack_gap",
78062+ .data = &sysctl_heap_stack_gap,
78063+ .maxlen = sizeof(sysctl_heap_stack_gap),
78064+ .mode = 0644,
78065+ .proc_handler = proc_doulongvec_minmax,
78066+ },
78067 #else
78068 {
78069 .procname = "nr_trim_pages",
78070@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
78071 buffer, lenp, ppos);
78072 }
78073
78074+int proc_dostring_modpriv(struct ctl_table *table, int write,
78075+ void __user *buffer, size_t *lenp, loff_t *ppos)
78076+{
78077+ if (write && !capable(CAP_SYS_MODULE))
78078+ return -EPERM;
78079+
78080+ return _proc_do_string(table->data, table->maxlen, write,
78081+ buffer, lenp, ppos);
78082+}
78083+
78084 static size_t proc_skip_spaces(char **buf)
78085 {
78086 size_t ret;
78087@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
78088 len = strlen(tmp);
78089 if (len > *size)
78090 len = *size;
78091+ if (len > sizeof(tmp))
78092+ len = sizeof(tmp);
78093 if (copy_to_user(*buf, tmp, len))
78094 return -EFAULT;
78095 *size -= len;
78096@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
78097 static int proc_taint(struct ctl_table *table, int write,
78098 void __user *buffer, size_t *lenp, loff_t *ppos)
78099 {
78100- struct ctl_table t;
78101+ ctl_table_no_const t;
78102 unsigned long tmptaint = get_taint();
78103 int err;
78104
78105@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
78106 return err;
78107 }
78108
78109-#ifdef CONFIG_PRINTK
78110 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78111 void __user *buffer, size_t *lenp, loff_t *ppos)
78112 {
78113@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78114
78115 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
78116 }
78117-#endif
78118
78119 struct do_proc_dointvec_minmax_conv_param {
78120 int *min;
78121@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
78122 *i = val;
78123 } else {
78124 val = convdiv * (*i) / convmul;
78125- if (!first)
78126+ if (!first) {
78127 err = proc_put_char(&buffer, &left, '\t');
78128+ if (err)
78129+ break;
78130+ }
78131 err = proc_put_long(&buffer, &left, val, false);
78132 if (err)
78133 break;
78134@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
78135 return -ENOSYS;
78136 }
78137
78138+int proc_dostring_modpriv(struct ctl_table *table, int write,
78139+ void __user *buffer, size_t *lenp, loff_t *ppos)
78140+{
78141+ return -ENOSYS;
78142+}
78143+
78144 int proc_dointvec(struct ctl_table *table, int write,
78145 void __user *buffer, size_t *lenp, loff_t *ppos)
78146 {
78147@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
78148 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
78149 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
78150 EXPORT_SYMBOL(proc_dostring);
78151+EXPORT_SYMBOL(proc_dostring_modpriv);
78152 EXPORT_SYMBOL(proc_doulongvec_minmax);
78153 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
78154diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
78155index 0ddf3a0..a199f50 100644
78156--- a/kernel/sysctl_binary.c
78157+++ b/kernel/sysctl_binary.c
78158@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
78159 int i;
78160
78161 set_fs(KERNEL_DS);
78162- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78163+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78164 set_fs(old_fs);
78165 if (result < 0)
78166 goto out_kfree;
78167@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
78168 }
78169
78170 set_fs(KERNEL_DS);
78171- result = vfs_write(file, buffer, str - buffer, &pos);
78172+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78173 set_fs(old_fs);
78174 if (result < 0)
78175 goto out_kfree;
78176@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
78177 int i;
78178
78179 set_fs(KERNEL_DS);
78180- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78181+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78182 set_fs(old_fs);
78183 if (result < 0)
78184 goto out_kfree;
78185@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
78186 }
78187
78188 set_fs(KERNEL_DS);
78189- result = vfs_write(file, buffer, str - buffer, &pos);
78190+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78191 set_fs(old_fs);
78192 if (result < 0)
78193 goto out_kfree;
78194@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
78195 int i;
78196
78197 set_fs(KERNEL_DS);
78198- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78199+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78200 set_fs(old_fs);
78201 if (result < 0)
78202 goto out;
78203@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78204 __le16 dnaddr;
78205
78206 set_fs(KERNEL_DS);
78207- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78208+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78209 set_fs(old_fs);
78210 if (result < 0)
78211 goto out;
78212@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78213 le16_to_cpu(dnaddr) & 0x3ff);
78214
78215 set_fs(KERNEL_DS);
78216- result = vfs_write(file, buf, len, &pos);
78217+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
78218 set_fs(old_fs);
78219 if (result < 0)
78220 goto out;
78221diff --git a/kernel/taskstats.c b/kernel/taskstats.c
78222index 145bb4d..b2aa969 100644
78223--- a/kernel/taskstats.c
78224+++ b/kernel/taskstats.c
78225@@ -28,9 +28,12 @@
78226 #include <linux/fs.h>
78227 #include <linux/file.h>
78228 #include <linux/pid_namespace.h>
78229+#include <linux/grsecurity.h>
78230 #include <net/genetlink.h>
78231 #include <linux/atomic.h>
78232
78233+extern int gr_is_taskstats_denied(int pid);
78234+
78235 /*
78236 * Maximum length of a cpumask that can be specified in
78237 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
78238@@ -570,6 +573,9 @@ err:
78239
78240 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
78241 {
78242+ if (gr_is_taskstats_denied(current->pid))
78243+ return -EACCES;
78244+
78245 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
78246 return cmd_attr_register_cpumask(info);
78247 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
78248diff --git a/kernel/time.c b/kernel/time.c
78249index d226c6a..2f0d217 100644
78250--- a/kernel/time.c
78251+++ b/kernel/time.c
78252@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
78253 return error;
78254
78255 if (tz) {
78256+ /* we log in do_settimeofday called below, so don't log twice
78257+ */
78258+ if (!tv)
78259+ gr_log_timechange();
78260+
78261 sys_tz = *tz;
78262 update_vsyscall_tz();
78263 if (firsttime) {
78264@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
78265 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
78266 * value to a scaled second value.
78267 */
78268-unsigned long
78269+unsigned long __intentional_overflow(-1)
78270 timespec_to_jiffies(const struct timespec *value)
78271 {
78272 unsigned long sec = value->tv_sec;
78273diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
78274index f11d83b..d016d91 100644
78275--- a/kernel/time/alarmtimer.c
78276+++ b/kernel/time/alarmtimer.c
78277@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
78278 struct platform_device *pdev;
78279 int error = 0;
78280 int i;
78281- struct k_clock alarm_clock = {
78282+ static struct k_clock alarm_clock = {
78283 .clock_getres = alarm_clock_getres,
78284 .clock_get = alarm_clock_get,
78285 .timer_create = alarm_timer_create,
78286diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
78287index f113755..ec24223 100644
78288--- a/kernel/time/tick-broadcast.c
78289+++ b/kernel/time/tick-broadcast.c
78290@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
78291 * then clear the broadcast bit.
78292 */
78293 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
78294- int cpu = smp_processor_id();
78295+ cpu = smp_processor_id();
78296
78297 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
78298 tick_broadcast_clear_oneshot(cpu);
78299diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
78300index cbc6acb..3a77191 100644
78301--- a/kernel/time/timekeeping.c
78302+++ b/kernel/time/timekeeping.c
78303@@ -15,6 +15,7 @@
78304 #include <linux/init.h>
78305 #include <linux/mm.h>
78306 #include <linux/sched.h>
78307+#include <linux/grsecurity.h>
78308 #include <linux/syscore_ops.h>
78309 #include <linux/clocksource.h>
78310 #include <linux/jiffies.h>
78311@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
78312 if (!timespec_valid_strict(tv))
78313 return -EINVAL;
78314
78315+ gr_log_timechange();
78316+
78317 write_seqlock_irqsave(&tk->lock, flags);
78318
78319 timekeeping_forward_now(tk);
78320diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
78321index af5a7e9..715611a 100644
78322--- a/kernel/time/timer_list.c
78323+++ b/kernel/time/timer_list.c
78324@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
78325
78326 static void print_name_offset(struct seq_file *m, void *sym)
78327 {
78328+#ifdef CONFIG_GRKERNSEC_HIDESYM
78329+ SEQ_printf(m, "<%p>", NULL);
78330+#else
78331 char symname[KSYM_NAME_LEN];
78332
78333 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
78334 SEQ_printf(m, "<%pK>", sym);
78335 else
78336 SEQ_printf(m, "%s", symname);
78337+#endif
78338 }
78339
78340 static void
78341@@ -112,7 +116,11 @@ next_one:
78342 static void
78343 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
78344 {
78345+#ifdef CONFIG_GRKERNSEC_HIDESYM
78346+ SEQ_printf(m, " .base: %p\n", NULL);
78347+#else
78348 SEQ_printf(m, " .base: %pK\n", base);
78349+#endif
78350 SEQ_printf(m, " .index: %d\n",
78351 base->index);
78352 SEQ_printf(m, " .resolution: %Lu nsecs\n",
78353@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
78354 {
78355 struct proc_dir_entry *pe;
78356
78357+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78358+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
78359+#else
78360 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
78361+#endif
78362 if (!pe)
78363 return -ENOMEM;
78364 return 0;
78365diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
78366index 0b537f2..40d6c20 100644
78367--- a/kernel/time/timer_stats.c
78368+++ b/kernel/time/timer_stats.c
78369@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
78370 static unsigned long nr_entries;
78371 static struct entry entries[MAX_ENTRIES];
78372
78373-static atomic_t overflow_count;
78374+static atomic_unchecked_t overflow_count;
78375
78376 /*
78377 * The entries are in a hash-table, for fast lookup:
78378@@ -140,7 +140,7 @@ static void reset_entries(void)
78379 nr_entries = 0;
78380 memset(entries, 0, sizeof(entries));
78381 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
78382- atomic_set(&overflow_count, 0);
78383+ atomic_set_unchecked(&overflow_count, 0);
78384 }
78385
78386 static struct entry *alloc_entry(void)
78387@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78388 if (likely(entry))
78389 entry->count++;
78390 else
78391- atomic_inc(&overflow_count);
78392+ atomic_inc_unchecked(&overflow_count);
78393
78394 out_unlock:
78395 raw_spin_unlock_irqrestore(lock, flags);
78396@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78397
78398 static void print_name_offset(struct seq_file *m, unsigned long addr)
78399 {
78400+#ifdef CONFIG_GRKERNSEC_HIDESYM
78401+ seq_printf(m, "<%p>", NULL);
78402+#else
78403 char symname[KSYM_NAME_LEN];
78404
78405 if (lookup_symbol_name(addr, symname) < 0)
78406- seq_printf(m, "<%p>", (void *)addr);
78407+ seq_printf(m, "<%pK>", (void *)addr);
78408 else
78409 seq_printf(m, "%s", symname);
78410+#endif
78411 }
78412
78413 static int tstats_show(struct seq_file *m, void *v)
78414@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
78415
78416 seq_puts(m, "Timer Stats Version: v0.2\n");
78417 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
78418- if (atomic_read(&overflow_count))
78419+ if (atomic_read_unchecked(&overflow_count))
78420 seq_printf(m, "Overflow: %d entries\n",
78421- atomic_read(&overflow_count));
78422+ atomic_read_unchecked(&overflow_count));
78423
78424 for (i = 0; i < nr_entries; i++) {
78425 entry = entries + i;
78426@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
78427 {
78428 struct proc_dir_entry *pe;
78429
78430+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78431+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
78432+#else
78433 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
78434+#endif
78435 if (!pe)
78436 return -ENOMEM;
78437 return 0;
78438diff --git a/kernel/timer.c b/kernel/timer.c
78439index 367d008..5dee98f 100644
78440--- a/kernel/timer.c
78441+++ b/kernel/timer.c
78442@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
78443 /*
78444 * This function runs timers and the timer-tq in bottom half context.
78445 */
78446-static void run_timer_softirq(struct softirq_action *h)
78447+static void run_timer_softirq(void)
78448 {
78449 struct tvec_base *base = __this_cpu_read(tvec_bases);
78450
78451@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
78452 *
78453 * In all cases the return value is guaranteed to be non-negative.
78454 */
78455-signed long __sched schedule_timeout(signed long timeout)
78456+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
78457 {
78458 struct timer_list timer;
78459 unsigned long expire;
78460@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
78461 return NOTIFY_OK;
78462 }
78463
78464-static struct notifier_block __cpuinitdata timers_nb = {
78465+static struct notifier_block timers_nb = {
78466 .notifier_call = timer_cpu_notify,
78467 };
78468
78469diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
78470index c0bd030..62a1927 100644
78471--- a/kernel/trace/blktrace.c
78472+++ b/kernel/trace/blktrace.c
78473@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
78474 struct blk_trace *bt = filp->private_data;
78475 char buf[16];
78476
78477- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
78478+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
78479
78480 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
78481 }
78482@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
78483 return 1;
78484
78485 bt = buf->chan->private_data;
78486- atomic_inc(&bt->dropped);
78487+ atomic_inc_unchecked(&bt->dropped);
78488 return 0;
78489 }
78490
78491@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
78492
78493 bt->dir = dir;
78494 bt->dev = dev;
78495- atomic_set(&bt->dropped, 0);
78496+ atomic_set_unchecked(&bt->dropped, 0);
78497
78498 ret = -EIO;
78499 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
78500diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
78501index 43defd1..76da436 100644
78502--- a/kernel/trace/ftrace.c
78503+++ b/kernel/trace/ftrace.c
78504@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
78505 if (unlikely(ftrace_disabled))
78506 return 0;
78507
78508+ ret = ftrace_arch_code_modify_prepare();
78509+ FTRACE_WARN_ON(ret);
78510+ if (ret)
78511+ return 0;
78512+
78513 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
78514+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
78515 if (ret) {
78516 ftrace_bug(ret, ip);
78517- return 0;
78518 }
78519- return 1;
78520+ return ret ? 0 : 1;
78521 }
78522
78523 /*
78524@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
78525
78526 int
78527 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
78528- void *data)
78529+ void *data)
78530 {
78531 struct ftrace_func_probe *entry;
78532 struct ftrace_page *pg;
78533@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
78534 if (!count)
78535 return 0;
78536
78537+ pax_open_kernel();
78538 sort(start, count, sizeof(*start),
78539 ftrace_cmp_ips, ftrace_swap_ips);
78540+ pax_close_kernel();
78541
78542 start_pg = ftrace_allocate_pages(count);
78543 if (!start_pg)
78544@@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
78545 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
78546
78547 static int ftrace_graph_active;
78548-static struct notifier_block ftrace_suspend_notifier;
78549-
78550 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
78551 {
78552 return 0;
78553@@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
78554 return NOTIFY_DONE;
78555 }
78556
78557+static struct notifier_block ftrace_suspend_notifier = {
78558+ .notifier_call = ftrace_suspend_notifier_call
78559+};
78560+
78561 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78562 trace_func_graph_ent_t entryfunc)
78563 {
78564@@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78565 goto out;
78566 }
78567
78568- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
78569 register_pm_notifier(&ftrace_suspend_notifier);
78570
78571 ftrace_graph_active++;
78572diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
78573index ce8514f..8233573 100644
78574--- a/kernel/trace/ring_buffer.c
78575+++ b/kernel/trace/ring_buffer.c
78576@@ -346,9 +346,9 @@ struct buffer_data_page {
78577 */
78578 struct buffer_page {
78579 struct list_head list; /* list of buffer pages */
78580- local_t write; /* index for next write */
78581+ local_unchecked_t write; /* index for next write */
78582 unsigned read; /* index for next read */
78583- local_t entries; /* entries on this page */
78584+ local_unchecked_t entries; /* entries on this page */
78585 unsigned long real_end; /* real end of data */
78586 struct buffer_data_page *page; /* Actual data page */
78587 };
78588@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
78589 unsigned long last_overrun;
78590 local_t entries_bytes;
78591 local_t entries;
78592- local_t overrun;
78593- local_t commit_overrun;
78594+ local_unchecked_t overrun;
78595+ local_unchecked_t commit_overrun;
78596 local_t dropped_events;
78597 local_t committing;
78598 local_t commits;
78599@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78600 *
78601 * We add a counter to the write field to denote this.
78602 */
78603- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
78604- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
78605+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
78606+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
78607
78608 /*
78609 * Just make sure we have seen our old_write and synchronize
78610@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78611 * cmpxchg to only update if an interrupt did not already
78612 * do it for us. If the cmpxchg fails, we don't care.
78613 */
78614- (void)local_cmpxchg(&next_page->write, old_write, val);
78615- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
78616+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
78617+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
78618
78619 /*
78620 * No need to worry about races with clearing out the commit.
78621@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
78622
78623 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
78624 {
78625- return local_read(&bpage->entries) & RB_WRITE_MASK;
78626+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
78627 }
78628
78629 static inline unsigned long rb_page_write(struct buffer_page *bpage)
78630 {
78631- return local_read(&bpage->write) & RB_WRITE_MASK;
78632+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
78633 }
78634
78635 static int
78636@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
78637 * bytes consumed in ring buffer from here.
78638 * Increment overrun to account for the lost events.
78639 */
78640- local_add(page_entries, &cpu_buffer->overrun);
78641+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
78642 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78643 }
78644
78645@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
78646 * it is our responsibility to update
78647 * the counters.
78648 */
78649- local_add(entries, &cpu_buffer->overrun);
78650+ local_add_unchecked(entries, &cpu_buffer->overrun);
78651 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78652
78653 /*
78654@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78655 if (tail == BUF_PAGE_SIZE)
78656 tail_page->real_end = 0;
78657
78658- local_sub(length, &tail_page->write);
78659+ local_sub_unchecked(length, &tail_page->write);
78660 return;
78661 }
78662
78663@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78664 rb_event_set_padding(event);
78665
78666 /* Set the write back to the previous setting */
78667- local_sub(length, &tail_page->write);
78668+ local_sub_unchecked(length, &tail_page->write);
78669 return;
78670 }
78671
78672@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78673
78674 /* Set write to end of buffer */
78675 length = (tail + length) - BUF_PAGE_SIZE;
78676- local_sub(length, &tail_page->write);
78677+ local_sub_unchecked(length, &tail_page->write);
78678 }
78679
78680 /*
78681@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78682 * about it.
78683 */
78684 if (unlikely(next_page == commit_page)) {
78685- local_inc(&cpu_buffer->commit_overrun);
78686+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78687 goto out_reset;
78688 }
78689
78690@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78691 cpu_buffer->tail_page) &&
78692 (cpu_buffer->commit_page ==
78693 cpu_buffer->reader_page))) {
78694- local_inc(&cpu_buffer->commit_overrun);
78695+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78696 goto out_reset;
78697 }
78698 }
78699@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78700 length += RB_LEN_TIME_EXTEND;
78701
78702 tail_page = cpu_buffer->tail_page;
78703- write = local_add_return(length, &tail_page->write);
78704+ write = local_add_return_unchecked(length, &tail_page->write);
78705
78706 /* set write to only the index of the write */
78707 write &= RB_WRITE_MASK;
78708@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78709 kmemcheck_annotate_bitfield(event, bitfield);
78710 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
78711
78712- local_inc(&tail_page->entries);
78713+ local_inc_unchecked(&tail_page->entries);
78714
78715 /*
78716 * If this is the first commit on the page, then update
78717@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78718
78719 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
78720 unsigned long write_mask =
78721- local_read(&bpage->write) & ~RB_WRITE_MASK;
78722+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
78723 unsigned long event_length = rb_event_length(event);
78724 /*
78725 * This is on the tail page. It is possible that
78726@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78727 */
78728 old_index += write_mask;
78729 new_index += write_mask;
78730- index = local_cmpxchg(&bpage->write, old_index, new_index);
78731+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
78732 if (index == old_index) {
78733 /* update counters */
78734 local_sub(event_length, &cpu_buffer->entries_bytes);
78735@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78736
78737 /* Do the likely case first */
78738 if (likely(bpage->page == (void *)addr)) {
78739- local_dec(&bpage->entries);
78740+ local_dec_unchecked(&bpage->entries);
78741 return;
78742 }
78743
78744@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78745 start = bpage;
78746 do {
78747 if (bpage->page == (void *)addr) {
78748- local_dec(&bpage->entries);
78749+ local_dec_unchecked(&bpage->entries);
78750 return;
78751 }
78752 rb_inc_page(cpu_buffer, &bpage);
78753@@ -2926,7 +2926,7 @@ static inline unsigned long
78754 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
78755 {
78756 return local_read(&cpu_buffer->entries) -
78757- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
78758+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
78759 }
78760
78761 /**
78762@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
78763 return 0;
78764
78765 cpu_buffer = buffer->buffers[cpu];
78766- ret = local_read(&cpu_buffer->overrun);
78767+ ret = local_read_unchecked(&cpu_buffer->overrun);
78768
78769 return ret;
78770 }
78771@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
78772 return 0;
78773
78774 cpu_buffer = buffer->buffers[cpu];
78775- ret = local_read(&cpu_buffer->commit_overrun);
78776+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
78777
78778 return ret;
78779 }
78780@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
78781 /* if you care about this being correct, lock the buffer */
78782 for_each_buffer_cpu(buffer, cpu) {
78783 cpu_buffer = buffer->buffers[cpu];
78784- overruns += local_read(&cpu_buffer->overrun);
78785+ overruns += local_read_unchecked(&cpu_buffer->overrun);
78786 }
78787
78788 return overruns;
78789@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78790 /*
78791 * Reset the reader page to size zero.
78792 */
78793- local_set(&cpu_buffer->reader_page->write, 0);
78794- local_set(&cpu_buffer->reader_page->entries, 0);
78795+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78796+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78797 local_set(&cpu_buffer->reader_page->page->commit, 0);
78798 cpu_buffer->reader_page->real_end = 0;
78799
78800@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78801 * want to compare with the last_overrun.
78802 */
78803 smp_mb();
78804- overwrite = local_read(&(cpu_buffer->overrun));
78805+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
78806
78807 /*
78808 * Here's the tricky part.
78809@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78810
78811 cpu_buffer->head_page
78812 = list_entry(cpu_buffer->pages, struct buffer_page, list);
78813- local_set(&cpu_buffer->head_page->write, 0);
78814- local_set(&cpu_buffer->head_page->entries, 0);
78815+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
78816+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
78817 local_set(&cpu_buffer->head_page->page->commit, 0);
78818
78819 cpu_buffer->head_page->read = 0;
78820@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78821
78822 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
78823 INIT_LIST_HEAD(&cpu_buffer->new_pages);
78824- local_set(&cpu_buffer->reader_page->write, 0);
78825- local_set(&cpu_buffer->reader_page->entries, 0);
78826+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78827+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78828 local_set(&cpu_buffer->reader_page->page->commit, 0);
78829 cpu_buffer->reader_page->read = 0;
78830
78831 local_set(&cpu_buffer->entries_bytes, 0);
78832- local_set(&cpu_buffer->overrun, 0);
78833- local_set(&cpu_buffer->commit_overrun, 0);
78834+ local_set_unchecked(&cpu_buffer->overrun, 0);
78835+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
78836 local_set(&cpu_buffer->dropped_events, 0);
78837 local_set(&cpu_buffer->entries, 0);
78838 local_set(&cpu_buffer->committing, 0);
78839@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78840 rb_init_page(bpage);
78841 bpage = reader->page;
78842 reader->page = *data_page;
78843- local_set(&reader->write, 0);
78844- local_set(&reader->entries, 0);
78845+ local_set_unchecked(&reader->write, 0);
78846+ local_set_unchecked(&reader->entries, 0);
78847 reader->read = 0;
78848 *data_page = bpage;
78849
78850diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
78851index 3c13e46..883d039 100644
78852--- a/kernel/trace/trace.c
78853+++ b/kernel/trace/trace.c
78854@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
78855 };
78856 #endif
78857
78858-static struct dentry *d_tracer;
78859-
78860 struct dentry *tracing_init_dentry(void)
78861 {
78862+ static struct dentry *d_tracer;
78863 static int once;
78864
78865 if (d_tracer)
78866@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
78867 return d_tracer;
78868 }
78869
78870-static struct dentry *d_percpu;
78871-
78872 struct dentry *tracing_dentry_percpu(void)
78873 {
78874+ static struct dentry *d_percpu;
78875 static int once;
78876 struct dentry *d_tracer;
78877
78878diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
78879index 880073d..42db7c3 100644
78880--- a/kernel/trace/trace_events.c
78881+++ b/kernel/trace/trace_events.c
78882@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
78883 struct ftrace_module_file_ops {
78884 struct list_head list;
78885 struct module *mod;
78886- struct file_operations id;
78887- struct file_operations enable;
78888- struct file_operations format;
78889- struct file_operations filter;
78890 };
78891
78892 static struct ftrace_module_file_ops *
78893@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
78894
78895 file_ops->mod = mod;
78896
78897- file_ops->id = ftrace_event_id_fops;
78898- file_ops->id.owner = mod;
78899-
78900- file_ops->enable = ftrace_enable_fops;
78901- file_ops->enable.owner = mod;
78902-
78903- file_ops->filter = ftrace_event_filter_fops;
78904- file_ops->filter.owner = mod;
78905-
78906- file_ops->format = ftrace_event_format_fops;
78907- file_ops->format.owner = mod;
78908+ pax_open_kernel();
78909+ mod->trace_id.owner = mod;
78910+ mod->trace_enable.owner = mod;
78911+ mod->trace_filter.owner = mod;
78912+ mod->trace_format.owner = mod;
78913+ pax_close_kernel();
78914
78915 list_add(&file_ops->list, &ftrace_module_file_list);
78916
78917@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
78918
78919 for_each_event(call, start, end) {
78920 __trace_add_event_call(*call, mod,
78921- &file_ops->id, &file_ops->enable,
78922- &file_ops->filter, &file_ops->format);
78923+ &mod->trace_id, &mod->trace_enable,
78924+ &mod->trace_filter, &mod->trace_format);
78925 }
78926 }
78927
78928diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
78929index fd3c8aa..5f324a6 100644
78930--- a/kernel/trace/trace_mmiotrace.c
78931+++ b/kernel/trace/trace_mmiotrace.c
78932@@ -24,7 +24,7 @@ struct header_iter {
78933 static struct trace_array *mmio_trace_array;
78934 static bool overrun_detected;
78935 static unsigned long prev_overruns;
78936-static atomic_t dropped_count;
78937+static atomic_unchecked_t dropped_count;
78938
78939 static void mmio_reset_data(struct trace_array *tr)
78940 {
78941@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
78942
78943 static unsigned long count_overruns(struct trace_iterator *iter)
78944 {
78945- unsigned long cnt = atomic_xchg(&dropped_count, 0);
78946+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
78947 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
78948
78949 if (over > prev_overruns)
78950@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
78951 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
78952 sizeof(*entry), 0, pc);
78953 if (!event) {
78954- atomic_inc(&dropped_count);
78955+ atomic_inc_unchecked(&dropped_count);
78956 return;
78957 }
78958 entry = ring_buffer_event_data(event);
78959@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78960 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78961 sizeof(*entry), 0, pc);
78962 if (!event) {
78963- atomic_inc(&dropped_count);
78964+ atomic_inc_unchecked(&dropped_count);
78965 return;
78966 }
78967 entry = ring_buffer_event_data(event);
78968diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78969index 194d796..76edb8f 100644
78970--- a/kernel/trace/trace_output.c
78971+++ b/kernel/trace/trace_output.c
78972@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78973
78974 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78975 if (!IS_ERR(p)) {
78976- p = mangle_path(s->buffer + s->len, p, "\n");
78977+ p = mangle_path(s->buffer + s->len, p, "\n\\");
78978 if (p) {
78979 s->len = p - s->buffer;
78980 return 1;
78981@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78982 goto out;
78983 }
78984
78985+ pax_open_kernel();
78986 if (event->funcs->trace == NULL)
78987- event->funcs->trace = trace_nop_print;
78988+ *(void **)&event->funcs->trace = trace_nop_print;
78989 if (event->funcs->raw == NULL)
78990- event->funcs->raw = trace_nop_print;
78991+ *(void **)&event->funcs->raw = trace_nop_print;
78992 if (event->funcs->hex == NULL)
78993- event->funcs->hex = trace_nop_print;
78994+ *(void **)&event->funcs->hex = trace_nop_print;
78995 if (event->funcs->binary == NULL)
78996- event->funcs->binary = trace_nop_print;
78997+ *(void **)&event->funcs->binary = trace_nop_print;
78998+ pax_close_kernel();
78999
79000 key = event->type & (EVENT_HASHSIZE - 1);
79001
79002diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
79003index 42ca822..cdcacc6 100644
79004--- a/kernel/trace/trace_stack.c
79005+++ b/kernel/trace/trace_stack.c
79006@@ -52,7 +52,7 @@ static inline void check_stack(void)
79007 return;
79008
79009 /* we do not handle interrupt stacks yet */
79010- if (!object_is_on_stack(&this_size))
79011+ if (!object_starts_on_stack(&this_size))
79012 return;
79013
79014 local_irq_save(flags);
79015diff --git a/kernel/user.c b/kernel/user.c
79016index 33acb5e..57ebfd4 100644
79017--- a/kernel/user.c
79018+++ b/kernel/user.c
79019@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
79020 .count = 4294967295U,
79021 },
79022 },
79023- .kref = {
79024- .refcount = ATOMIC_INIT(3),
79025- },
79026+ .count = ATOMIC_INIT(3),
79027 .owner = GLOBAL_ROOT_UID,
79028 .group = GLOBAL_ROOT_GID,
79029 .proc_inum = PROC_USER_INIT_INO,
79030diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
79031index dbfe36a7..2a3c1df 100644
79032--- a/kernel/user_namespace.c
79033+++ b/kernel/user_namespace.c
79034@@ -79,7 +79,7 @@ int create_user_ns(struct cred *new)
79035 return ret;
79036 }
79037
79038- kref_init(&ns->kref);
79039+ atomic_set(&ns->count, 1);
79040 /* Leave the new->user_ns reference with the new user namespace. */
79041 ns->parent = parent_ns;
79042 ns->owner = owner;
79043@@ -105,15 +105,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
79044 return create_user_ns(cred);
79045 }
79046
79047-void free_user_ns(struct kref *kref)
79048+void free_user_ns(struct user_namespace *ns)
79049 {
79050- struct user_namespace *parent, *ns =
79051- container_of(kref, struct user_namespace, kref);
79052+ struct user_namespace *parent;
79053
79054- parent = ns->parent;
79055- proc_free_inum(ns->proc_inum);
79056- kmem_cache_free(user_ns_cachep, ns);
79057- put_user_ns(parent);
79058+ do {
79059+ parent = ns->parent;
79060+ proc_free_inum(ns->proc_inum);
79061+ kmem_cache_free(user_ns_cachep, ns);
79062+ ns = parent;
79063+ } while (atomic_dec_and_test(&parent->count));
79064 }
79065 EXPORT_SYMBOL(free_user_ns);
79066
79067@@ -804,7 +805,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
79068 if (atomic_read(&current->mm->mm_users) > 1)
79069 return -EINVAL;
79070
79071- if (current->fs->users != 1)
79072+ if (atomic_read(&current->fs->users) != 1)
79073 return -EINVAL;
79074
79075 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
79076diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
79077index 63da38c..639904e 100644
79078--- a/kernel/utsname_sysctl.c
79079+++ b/kernel/utsname_sysctl.c
79080@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
79081 static int proc_do_uts_string(ctl_table *table, int write,
79082 void __user *buffer, size_t *lenp, loff_t *ppos)
79083 {
79084- struct ctl_table uts_table;
79085+ ctl_table_no_const uts_table;
79086 int r;
79087 memcpy(&uts_table, table, sizeof(uts_table));
79088 uts_table.data = get_uts(table, write);
79089diff --git a/kernel/watchdog.c b/kernel/watchdog.c
79090index 75a2ab3..5961da7 100644
79091--- a/kernel/watchdog.c
79092+++ b/kernel/watchdog.c
79093@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
79094 }
79095 #endif /* CONFIG_SYSCTL */
79096
79097-static struct smp_hotplug_thread watchdog_threads = {
79098+static struct smp_hotplug_thread watchdog_threads __read_only = {
79099 .store = &softlockup_watchdog,
79100 .thread_should_run = watchdog_should_run,
79101 .thread_fn = watchdog,
79102diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
79103index 67604e5..fe94fb1 100644
79104--- a/lib/Kconfig.debug
79105+++ b/lib/Kconfig.debug
79106@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
79107
79108 config DEBUG_LOCK_ALLOC
79109 bool "Lock debugging: detect incorrect freeing of live locks"
79110- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79111+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79112 select DEBUG_SPINLOCK
79113 select DEBUG_MUTEXES
79114 select LOCKDEP
79115@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
79116
79117 config PROVE_LOCKING
79118 bool "Lock debugging: prove locking correctness"
79119- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79120+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79121 select LOCKDEP
79122 select DEBUG_SPINLOCK
79123 select DEBUG_MUTEXES
79124@@ -670,7 +670,7 @@ config LOCKDEP
79125
79126 config LOCK_STAT
79127 bool "Lock usage statistics"
79128- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79129+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79130 select LOCKDEP
79131 select DEBUG_SPINLOCK
79132 select DEBUG_MUTEXES
79133@@ -1278,6 +1278,7 @@ config LATENCYTOP
79134 depends on DEBUG_KERNEL
79135 depends on STACKTRACE_SUPPORT
79136 depends on PROC_FS
79137+ depends on !GRKERNSEC_HIDESYM
79138 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
79139 select KALLSYMS
79140 select KALLSYMS_ALL
79141@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
79142
79143 config PROVIDE_OHCI1394_DMA_INIT
79144 bool "Remote debugging over FireWire early on boot"
79145- depends on PCI && X86
79146+ depends on PCI && X86 && !GRKERNSEC
79147 help
79148 If you want to debug problems which hang or crash the kernel early
79149 on boot and the crashing machine has a FireWire port, you can use
79150@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
79151
79152 config FIREWIRE_OHCI_REMOTE_DMA
79153 bool "Remote debugging over FireWire with firewire-ohci"
79154- depends on FIREWIRE_OHCI
79155+ depends on FIREWIRE_OHCI && !GRKERNSEC
79156 help
79157 This option lets you use the FireWire bus for remote debugging
79158 with help of the firewire-ohci driver. It enables unfiltered
79159diff --git a/lib/Makefile b/lib/Makefile
79160index 02ed6c0..bd243da 100644
79161--- a/lib/Makefile
79162+++ b/lib/Makefile
79163@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
79164
79165 obj-$(CONFIG_BTREE) += btree.o
79166 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
79167-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
79168+obj-y += list_debug.o
79169 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
79170
79171 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
79172diff --git a/lib/bitmap.c b/lib/bitmap.c
79173index 06f7e4f..f3cf2b0 100644
79174--- a/lib/bitmap.c
79175+++ b/lib/bitmap.c
79176@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
79177 {
79178 int c, old_c, totaldigits, ndigits, nchunks, nbits;
79179 u32 chunk;
79180- const char __user __force *ubuf = (const char __user __force *)buf;
79181+ const char __user *ubuf = (const char __force_user *)buf;
79182
79183 bitmap_zero(maskp, nmaskbits);
79184
79185@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
79186 {
79187 if (!access_ok(VERIFY_READ, ubuf, ulen))
79188 return -EFAULT;
79189- return __bitmap_parse((const char __force *)ubuf,
79190+ return __bitmap_parse((const char __force_kernel *)ubuf,
79191 ulen, 1, maskp, nmaskbits);
79192
79193 }
79194@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
79195 {
79196 unsigned a, b;
79197 int c, old_c, totaldigits;
79198- const char __user __force *ubuf = (const char __user __force *)buf;
79199+ const char __user *ubuf = (const char __force_user *)buf;
79200 int exp_digit, in_range;
79201
79202 totaldigits = c = 0;
79203@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
79204 {
79205 if (!access_ok(VERIFY_READ, ubuf, ulen))
79206 return -EFAULT;
79207- return __bitmap_parselist((const char __force *)ubuf,
79208+ return __bitmap_parselist((const char __force_kernel *)ubuf,
79209 ulen, 1, maskp, nmaskbits);
79210 }
79211 EXPORT_SYMBOL(bitmap_parselist_user);
79212diff --git a/lib/bug.c b/lib/bug.c
79213index d0cdf14..4d07bd2 100644
79214--- a/lib/bug.c
79215+++ b/lib/bug.c
79216@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
79217 return BUG_TRAP_TYPE_NONE;
79218
79219 bug = find_bug(bugaddr);
79220+ if (!bug)
79221+ return BUG_TRAP_TYPE_NONE;
79222
79223 file = NULL;
79224 line = 0;
79225diff --git a/lib/debugobjects.c b/lib/debugobjects.c
79226index d11808c..dc2d6f8 100644
79227--- a/lib/debugobjects.c
79228+++ b/lib/debugobjects.c
79229@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
79230 if (limit > 4)
79231 return;
79232
79233- is_on_stack = object_is_on_stack(addr);
79234+ is_on_stack = object_starts_on_stack(addr);
79235 if (is_on_stack == onstack)
79236 return;
79237
79238diff --git a/lib/devres.c b/lib/devres.c
79239index 80b9c76..9e32279 100644
79240--- a/lib/devres.c
79241+++ b/lib/devres.c
79242@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
79243 void devm_iounmap(struct device *dev, void __iomem *addr)
79244 {
79245 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
79246- (void *)addr));
79247+ (void __force *)addr));
79248 iounmap(addr);
79249 }
79250 EXPORT_SYMBOL(devm_iounmap);
79251@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
79252 {
79253 ioport_unmap(addr);
79254 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
79255- devm_ioport_map_match, (void *)addr));
79256+ devm_ioport_map_match, (void __force *)addr));
79257 }
79258 EXPORT_SYMBOL(devm_ioport_unmap);
79259
79260diff --git a/lib/div64.c b/lib/div64.c
79261index a163b6c..9618fa5 100644
79262--- a/lib/div64.c
79263+++ b/lib/div64.c
79264@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
79265 EXPORT_SYMBOL(__div64_32);
79266
79267 #ifndef div_s64_rem
79268-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79269+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79270 {
79271 u64 quotient;
79272
79273@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
79274 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
79275 */
79276 #ifndef div64_u64
79277-u64 div64_u64(u64 dividend, u64 divisor)
79278+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79279 {
79280 u32 high = divisor >> 32;
79281 u64 quot;
79282diff --git a/lib/dma-debug.c b/lib/dma-debug.c
79283index 5e396ac..58d5de1 100644
79284--- a/lib/dma-debug.c
79285+++ b/lib/dma-debug.c
79286@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
79287
79288 void dma_debug_add_bus(struct bus_type *bus)
79289 {
79290- struct notifier_block *nb;
79291+ notifier_block_no_const *nb;
79292
79293 if (global_disable)
79294 return;
79295@@ -942,7 +942,7 @@ out:
79296
79297 static void check_for_stack(struct device *dev, void *addr)
79298 {
79299- if (object_is_on_stack(addr))
79300+ if (object_starts_on_stack(addr))
79301 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
79302 "stack [addr=%p]\n", addr);
79303 }
79304diff --git a/lib/inflate.c b/lib/inflate.c
79305index 013a761..c28f3fc 100644
79306--- a/lib/inflate.c
79307+++ b/lib/inflate.c
79308@@ -269,7 +269,7 @@ static void free(void *where)
79309 malloc_ptr = free_mem_ptr;
79310 }
79311 #else
79312-#define malloc(a) kmalloc(a, GFP_KERNEL)
79313+#define malloc(a) kmalloc((a), GFP_KERNEL)
79314 #define free(a) kfree(a)
79315 #endif
79316
79317diff --git a/lib/ioremap.c b/lib/ioremap.c
79318index 0c9216c..863bd89 100644
79319--- a/lib/ioremap.c
79320+++ b/lib/ioremap.c
79321@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
79322 unsigned long next;
79323
79324 phys_addr -= addr;
79325- pmd = pmd_alloc(&init_mm, pud, addr);
79326+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79327 if (!pmd)
79328 return -ENOMEM;
79329 do {
79330@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
79331 unsigned long next;
79332
79333 phys_addr -= addr;
79334- pud = pud_alloc(&init_mm, pgd, addr);
79335+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79336 if (!pud)
79337 return -ENOMEM;
79338 do {
79339diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
79340index bd2bea9..6b3c95e 100644
79341--- a/lib/is_single_threaded.c
79342+++ b/lib/is_single_threaded.c
79343@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
79344 struct task_struct *p, *t;
79345 bool ret;
79346
79347+ if (!mm)
79348+ return true;
79349+
79350 if (atomic_read(&task->signal->live) != 1)
79351 return false;
79352
79353diff --git a/lib/kobject.c b/lib/kobject.c
79354index e07ee1f..998489d 100644
79355--- a/lib/kobject.c
79356+++ b/lib/kobject.c
79357@@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
79358
79359
79360 static DEFINE_SPINLOCK(kobj_ns_type_lock);
79361-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
79362+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
79363
79364-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79365+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79366 {
79367 enum kobj_ns_type type = ops->type;
79368 int error;
79369diff --git a/lib/list_debug.c b/lib/list_debug.c
79370index c24c2f7..0475b78 100644
79371--- a/lib/list_debug.c
79372+++ b/lib/list_debug.c
79373@@ -11,7 +11,9 @@
79374 #include <linux/bug.h>
79375 #include <linux/kernel.h>
79376 #include <linux/rculist.h>
79377+#include <linux/mm.h>
79378
79379+#ifdef CONFIG_DEBUG_LIST
79380 /*
79381 * Insert a new entry between two known consecutive entries.
79382 *
79383@@ -19,21 +21,32 @@
79384 * the prev/next entries already!
79385 */
79386
79387-void __list_add(struct list_head *new,
79388- struct list_head *prev,
79389- struct list_head *next)
79390+static bool __list_add_debug(struct list_head *new,
79391+ struct list_head *prev,
79392+ struct list_head *next)
79393 {
79394- WARN(next->prev != prev,
79395+ if (WARN(next->prev != prev,
79396 "list_add corruption. next->prev should be "
79397 "prev (%p), but was %p. (next=%p).\n",
79398- prev, next->prev, next);
79399- WARN(prev->next != next,
79400+ prev, next->prev, next) ||
79401+ WARN(prev->next != next,
79402 "list_add corruption. prev->next should be "
79403 "next (%p), but was %p. (prev=%p).\n",
79404- next, prev->next, prev);
79405- WARN(new == prev || new == next,
79406+ next, prev->next, prev) ||
79407+ WARN(new == prev || new == next,
79408 "list_add double add: new=%p, prev=%p, next=%p.\n",
79409- new, prev, next);
79410+ new, prev, next))
79411+ return false;
79412+ return true;
79413+}
79414+
79415+void __list_add(struct list_head *new,
79416+ struct list_head *prev,
79417+ struct list_head *next)
79418+{
79419+ if (!__list_add_debug(new, prev, next))
79420+ return;
79421+
79422 next->prev = new;
79423 new->next = next;
79424 new->prev = prev;
79425@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
79426 }
79427 EXPORT_SYMBOL(__list_add);
79428
79429-void __list_del_entry(struct list_head *entry)
79430+static bool __list_del_entry_debug(struct list_head *entry)
79431 {
79432 struct list_head *prev, *next;
79433
79434@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
79435 WARN(next->prev != entry,
79436 "list_del corruption. next->prev should be %p, "
79437 "but was %p\n", entry, next->prev))
79438+ return false;
79439+ return true;
79440+}
79441+
79442+void __list_del_entry(struct list_head *entry)
79443+{
79444+ if (!__list_del_entry_debug(entry))
79445 return;
79446
79447- __list_del(prev, next);
79448+ __list_del(entry->prev, entry->next);
79449 }
79450 EXPORT_SYMBOL(__list_del_entry);
79451
79452@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
79453 void __list_add_rcu(struct list_head *new,
79454 struct list_head *prev, struct list_head *next)
79455 {
79456- WARN(next->prev != prev,
79457- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
79458- prev, next->prev, next);
79459- WARN(prev->next != next,
79460- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
79461- next, prev->next, prev);
79462+ if (!__list_add_debug(new, prev, next))
79463+ return;
79464+
79465 new->next = next;
79466 new->prev = prev;
79467 rcu_assign_pointer(list_next_rcu(prev), new);
79468 next->prev = new;
79469 }
79470 EXPORT_SYMBOL(__list_add_rcu);
79471+#endif
79472+
79473+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
79474+{
79475+#ifdef CONFIG_DEBUG_LIST
79476+ if (!__list_add_debug(new, prev, next))
79477+ return;
79478+#endif
79479+
79480+ pax_open_kernel();
79481+ next->prev = new;
79482+ new->next = next;
79483+ new->prev = prev;
79484+ prev->next = new;
79485+ pax_close_kernel();
79486+}
79487+EXPORT_SYMBOL(__pax_list_add);
79488+
79489+void pax_list_del(struct list_head *entry)
79490+{
79491+#ifdef CONFIG_DEBUG_LIST
79492+ if (!__list_del_entry_debug(entry))
79493+ return;
79494+#endif
79495+
79496+ pax_open_kernel();
79497+ __list_del(entry->prev, entry->next);
79498+ entry->next = LIST_POISON1;
79499+ entry->prev = LIST_POISON2;
79500+ pax_close_kernel();
79501+}
79502+EXPORT_SYMBOL(pax_list_del);
79503+
79504+void pax_list_del_init(struct list_head *entry)
79505+{
79506+ pax_open_kernel();
79507+ __list_del(entry->prev, entry->next);
79508+ INIT_LIST_HEAD(entry);
79509+ pax_close_kernel();
79510+}
79511+EXPORT_SYMBOL(pax_list_del_init);
79512+
79513+void __pax_list_add_rcu(struct list_head *new,
79514+ struct list_head *prev, struct list_head *next)
79515+{
79516+#ifdef CONFIG_DEBUG_LIST
79517+ if (!__list_add_debug(new, prev, next))
79518+ return;
79519+#endif
79520+
79521+ pax_open_kernel();
79522+ new->next = next;
79523+ new->prev = prev;
79524+ rcu_assign_pointer(list_next_rcu(prev), new);
79525+ next->prev = new;
79526+ pax_close_kernel();
79527+}
79528+EXPORT_SYMBOL(__pax_list_add_rcu);
79529+
79530+void pax_list_del_rcu(struct list_head *entry)
79531+{
79532+#ifdef CONFIG_DEBUG_LIST
79533+ if (!__list_del_entry_debug(entry))
79534+ return;
79535+#endif
79536+
79537+ pax_open_kernel();
79538+ __list_del(entry->prev, entry->next);
79539+ entry->next = LIST_POISON1;
79540+ entry->prev = LIST_POISON2;
79541+ pax_close_kernel();
79542+}
79543+EXPORT_SYMBOL(pax_list_del_rcu);
79544diff --git a/lib/radix-tree.c b/lib/radix-tree.c
79545index e796429..6e38f9f 100644
79546--- a/lib/radix-tree.c
79547+++ b/lib/radix-tree.c
79548@@ -92,7 +92,7 @@ struct radix_tree_preload {
79549 int nr;
79550 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
79551 };
79552-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
79553+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
79554
79555 static inline void *ptr_to_indirect(void *ptr)
79556 {
79557diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
79558index bb2b201..46abaf9 100644
79559--- a/lib/strncpy_from_user.c
79560+++ b/lib/strncpy_from_user.c
79561@@ -21,7 +21,7 @@
79562 */
79563 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
79564 {
79565- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79566+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79567 long res = 0;
79568
79569 /*
79570diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
79571index a28df52..3d55877 100644
79572--- a/lib/strnlen_user.c
79573+++ b/lib/strnlen_user.c
79574@@ -26,7 +26,7 @@
79575 */
79576 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
79577 {
79578- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79579+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79580 long align, res = 0;
79581 unsigned long c;
79582
79583diff --git a/lib/swiotlb.c b/lib/swiotlb.c
79584index 196b069..358f342 100644
79585--- a/lib/swiotlb.c
79586+++ b/lib/swiotlb.c
79587@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
79588
79589 void
79590 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
79591- dma_addr_t dev_addr)
79592+ dma_addr_t dev_addr, struct dma_attrs *attrs)
79593 {
79594 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
79595
79596diff --git a/lib/vsprintf.c b/lib/vsprintf.c
79597index fab33a9..3b5fe68 100644
79598--- a/lib/vsprintf.c
79599+++ b/lib/vsprintf.c
79600@@ -16,6 +16,9 @@
79601 * - scnprintf and vscnprintf
79602 */
79603
79604+#ifdef CONFIG_GRKERNSEC_HIDESYM
79605+#define __INCLUDED_BY_HIDESYM 1
79606+#endif
79607 #include <stdarg.h>
79608 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
79609 #include <linux/types.h>
79610@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
79611 char sym[KSYM_SYMBOL_LEN];
79612 if (ext == 'B')
79613 sprint_backtrace(sym, value);
79614- else if (ext != 'f' && ext != 's')
79615+ else if (ext != 'f' && ext != 's' && ext != 'a')
79616 sprint_symbol(sym, value);
79617 else
79618 sprint_symbol_no_offset(sym, value);
79619@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
79620 return number(buf, end, *(const netdev_features_t *)addr, spec);
79621 }
79622
79623+#ifdef CONFIG_GRKERNSEC_HIDESYM
79624+int kptr_restrict __read_mostly = 2;
79625+#else
79626 int kptr_restrict __read_mostly;
79627+#endif
79628
79629 /*
79630 * Show a '%p' thing. A kernel extension is that the '%p' is followed
79631@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
79632 * - 'S' For symbolic direct pointers with offset
79633 * - 's' For symbolic direct pointers without offset
79634 * - 'B' For backtraced symbolic direct pointers with offset
79635+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
79636+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
79637 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
79638 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
79639 * - 'M' For a 6-byte MAC address, it prints the address in the
79640@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79641
79642 if (!ptr && *fmt != 'K') {
79643 /*
79644- * Print (null) with the same width as a pointer so it makes
79645+ * Print (nil) with the same width as a pointer so it makes
79646 * tabular output look nice.
79647 */
79648 if (spec.field_width == -1)
79649 spec.field_width = default_width;
79650- return string(buf, end, "(null)", spec);
79651+ return string(buf, end, "(nil)", spec);
79652 }
79653
79654 switch (*fmt) {
79655@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79656 /* Fallthrough */
79657 case 'S':
79658 case 's':
79659+#ifdef CONFIG_GRKERNSEC_HIDESYM
79660+ break;
79661+#else
79662+ return symbol_string(buf, end, ptr, spec, *fmt);
79663+#endif
79664+ case 'A':
79665+ case 'a':
79666 case 'B':
79667 return symbol_string(buf, end, ptr, spec, *fmt);
79668 case 'R':
79669@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79670 va_end(va);
79671 return buf;
79672 }
79673+ case 'P':
79674+ break;
79675 case 'K':
79676 /*
79677 * %pK cannot be used in IRQ context because its test
79678@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79679 }
79680 break;
79681 }
79682+
79683+#ifdef CONFIG_GRKERNSEC_HIDESYM
79684+ /* 'P' = approved pointers to copy to userland,
79685+ as in the /proc/kallsyms case, as we make it display nothing
79686+ for non-root users, and the real contents for root users
79687+ Also ignore 'K' pointers, since we force their NULLing for non-root users
79688+ above
79689+ */
79690+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
79691+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
79692+ dump_stack();
79693+ ptr = NULL;
79694+ }
79695+#endif
79696+
79697 spec.flags |= SMALL;
79698 if (spec.field_width == -1) {
79699 spec.field_width = default_width;
79700@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79701 typeof(type) value; \
79702 if (sizeof(type) == 8) { \
79703 args = PTR_ALIGN(args, sizeof(u32)); \
79704- *(u32 *)&value = *(u32 *)args; \
79705- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
79706+ *(u32 *)&value = *(const u32 *)args; \
79707+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
79708 } else { \
79709 args = PTR_ALIGN(args, sizeof(type)); \
79710- value = *(typeof(type) *)args; \
79711+ value = *(const typeof(type) *)args; \
79712 } \
79713 args += sizeof(type); \
79714 value; \
79715@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79716 case FORMAT_TYPE_STR: {
79717 const char *str_arg = args;
79718 args += strlen(str_arg) + 1;
79719- str = string(str, end, (char *)str_arg, spec);
79720+ str = string(str, end, str_arg, spec);
79721 break;
79722 }
79723
79724diff --git a/localversion-grsec b/localversion-grsec
79725new file mode 100644
79726index 0000000..7cd6065
79727--- /dev/null
79728+++ b/localversion-grsec
79729@@ -0,0 +1 @@
79730+-grsec
79731diff --git a/mm/Kconfig b/mm/Kconfig
79732index 278e3ab..87c384d 100644
79733--- a/mm/Kconfig
79734+++ b/mm/Kconfig
79735@@ -286,10 +286,10 @@ config KSM
79736 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
79737
79738 config DEFAULT_MMAP_MIN_ADDR
79739- int "Low address space to protect from user allocation"
79740+ int "Low address space to protect from user allocation"
79741 depends on MMU
79742- default 4096
79743- help
79744+ default 65536
79745+ help
79746 This is the portion of low virtual memory which should be protected
79747 from userspace allocation. Keeping a user from writing to low pages
79748 can help reduce the impact of kernel NULL pointer bugs.
79749@@ -320,7 +320,7 @@ config MEMORY_FAILURE
79750
79751 config HWPOISON_INJECT
79752 tristate "HWPoison pages injector"
79753- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
79754+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
79755 select PROC_PAGE_MONITOR
79756
79757 config NOMMU_INITIAL_TRIM_EXCESS
79758diff --git a/mm/filemap.c b/mm/filemap.c
79759index 83efee7..3f99381 100644
79760--- a/mm/filemap.c
79761+++ b/mm/filemap.c
79762@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
79763 struct address_space *mapping = file->f_mapping;
79764
79765 if (!mapping->a_ops->readpage)
79766- return -ENOEXEC;
79767+ return -ENODEV;
79768 file_accessed(file);
79769 vma->vm_ops = &generic_file_vm_ops;
79770 return 0;
79771@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
79772 *pos = i_size_read(inode);
79773
79774 if (limit != RLIM_INFINITY) {
79775+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
79776 if (*pos >= limit) {
79777 send_sig(SIGXFSZ, current, 0);
79778 return -EFBIG;
79779diff --git a/mm/fremap.c b/mm/fremap.c
79780index a0aaf0e..20325c3 100644
79781--- a/mm/fremap.c
79782+++ b/mm/fremap.c
79783@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
79784 retry:
79785 vma = find_vma(mm, start);
79786
79787+#ifdef CONFIG_PAX_SEGMEXEC
79788+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
79789+ goto out;
79790+#endif
79791+
79792 /*
79793 * Make sure the vma is shared, that it supports prefaulting,
79794 * and that the remapped range is valid and fully within
79795diff --git a/mm/highmem.c b/mm/highmem.c
79796index b32b70c..e512eb0 100644
79797--- a/mm/highmem.c
79798+++ b/mm/highmem.c
79799@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
79800 * So no dangers, even with speculative execution.
79801 */
79802 page = pte_page(pkmap_page_table[i]);
79803+ pax_open_kernel();
79804 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
79805-
79806+ pax_close_kernel();
79807 set_page_address(page, NULL);
79808 need_flush = 1;
79809 }
79810@@ -198,9 +199,11 @@ start:
79811 }
79812 }
79813 vaddr = PKMAP_ADDR(last_pkmap_nr);
79814+
79815+ pax_open_kernel();
79816 set_pte_at(&init_mm, vaddr,
79817 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
79818-
79819+ pax_close_kernel();
79820 pkmap_count[last_pkmap_nr] = 1;
79821 set_page_address(page, (void *)vaddr);
79822
79823diff --git a/mm/hugetlb.c b/mm/hugetlb.c
79824index 546db81..34830af 100644
79825--- a/mm/hugetlb.c
79826+++ b/mm/hugetlb.c
79827@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
79828 struct hstate *h = &default_hstate;
79829 unsigned long tmp;
79830 int ret;
79831+ ctl_table_no_const hugetlb_table;
79832
79833 tmp = h->max_huge_pages;
79834
79835 if (write && h->order >= MAX_ORDER)
79836 return -EINVAL;
79837
79838- table->data = &tmp;
79839- table->maxlen = sizeof(unsigned long);
79840- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79841+ hugetlb_table = *table;
79842+ hugetlb_table.data = &tmp;
79843+ hugetlb_table.maxlen = sizeof(unsigned long);
79844+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79845 if (ret)
79846 goto out;
79847
79848@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
79849 struct hstate *h = &default_hstate;
79850 unsigned long tmp;
79851 int ret;
79852+ ctl_table_no_const hugetlb_table;
79853
79854 tmp = h->nr_overcommit_huge_pages;
79855
79856 if (write && h->order >= MAX_ORDER)
79857 return -EINVAL;
79858
79859- table->data = &tmp;
79860- table->maxlen = sizeof(unsigned long);
79861- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79862+ hugetlb_table = *table;
79863+ hugetlb_table.data = &tmp;
79864+ hugetlb_table.maxlen = sizeof(unsigned long);
79865+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79866 if (ret)
79867 goto out;
79868
79869@@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
79870 return 1;
79871 }
79872
79873+#ifdef CONFIG_PAX_SEGMEXEC
79874+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
79875+{
79876+ struct mm_struct *mm = vma->vm_mm;
79877+ struct vm_area_struct *vma_m;
79878+ unsigned long address_m;
79879+ pte_t *ptep_m;
79880+
79881+ vma_m = pax_find_mirror_vma(vma);
79882+ if (!vma_m)
79883+ return;
79884+
79885+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79886+ address_m = address + SEGMEXEC_TASK_SIZE;
79887+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
79888+ get_page(page_m);
79889+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
79890+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
79891+}
79892+#endif
79893+
79894 /*
79895 * Hugetlb_cow() should be called with page lock of the original hugepage held.
79896 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
79897@@ -2629,6 +2654,11 @@ retry_avoidcopy:
79898 make_huge_pte(vma, new_page, 1));
79899 page_remove_rmap(old_page);
79900 hugepage_add_new_anon_rmap(new_page, vma, address);
79901+
79902+#ifdef CONFIG_PAX_SEGMEXEC
79903+ pax_mirror_huge_pte(vma, address, new_page);
79904+#endif
79905+
79906 /* Make the old page be freed below */
79907 new_page = old_page;
79908 }
79909@@ -2788,6 +2818,10 @@ retry:
79910 && (vma->vm_flags & VM_SHARED)));
79911 set_huge_pte_at(mm, address, ptep, new_pte);
79912
79913+#ifdef CONFIG_PAX_SEGMEXEC
79914+ pax_mirror_huge_pte(vma, address, page);
79915+#endif
79916+
79917 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
79918 /* Optimization, do the COW without a second fault */
79919 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
79920@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79921 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
79922 struct hstate *h = hstate_vma(vma);
79923
79924+#ifdef CONFIG_PAX_SEGMEXEC
79925+ struct vm_area_struct *vma_m;
79926+#endif
79927+
79928 address &= huge_page_mask(h);
79929
79930 ptep = huge_pte_offset(mm, address);
79931@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79932 VM_FAULT_SET_HINDEX(hstate_index(h));
79933 }
79934
79935+#ifdef CONFIG_PAX_SEGMEXEC
79936+ vma_m = pax_find_mirror_vma(vma);
79937+ if (vma_m) {
79938+ unsigned long address_m;
79939+
79940+ if (vma->vm_start > vma_m->vm_start) {
79941+ address_m = address;
79942+ address -= SEGMEXEC_TASK_SIZE;
79943+ vma = vma_m;
79944+ h = hstate_vma(vma);
79945+ } else
79946+ address_m = address + SEGMEXEC_TASK_SIZE;
79947+
79948+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
79949+ return VM_FAULT_OOM;
79950+ address_m &= HPAGE_MASK;
79951+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
79952+ }
79953+#endif
79954+
79955 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
79956 if (!ptep)
79957 return VM_FAULT_OOM;
79958diff --git a/mm/internal.h b/mm/internal.h
79959index 9ba2110..eaf0674 100644
79960--- a/mm/internal.h
79961+++ b/mm/internal.h
79962@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
79963 * in mm/page_alloc.c
79964 */
79965 extern void __free_pages_bootmem(struct page *page, unsigned int order);
79966+extern void free_compound_page(struct page *page);
79967 extern void prep_compound_page(struct page *page, unsigned long order);
79968 #ifdef CONFIG_MEMORY_FAILURE
79969 extern bool is_free_buddy_page(struct page *page);
79970diff --git a/mm/kmemleak.c b/mm/kmemleak.c
79971index 752a705..6c3102e 100644
79972--- a/mm/kmemleak.c
79973+++ b/mm/kmemleak.c
79974@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
79975
79976 for (i = 0; i < object->trace_len; i++) {
79977 void *ptr = (void *)object->trace[i];
79978- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
79979+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
79980 }
79981 }
79982
79983@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
79984 return -ENOMEM;
79985 }
79986
79987- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79988+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79989 &kmemleak_fops);
79990 if (!dentry)
79991 pr_warning("Failed to create the debugfs kmemleak file\n");
79992diff --git a/mm/maccess.c b/mm/maccess.c
79993index d53adf9..03a24bf 100644
79994--- a/mm/maccess.c
79995+++ b/mm/maccess.c
79996@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79997 set_fs(KERNEL_DS);
79998 pagefault_disable();
79999 ret = __copy_from_user_inatomic(dst,
80000- (__force const void __user *)src, size);
80001+ (const void __force_user *)src, size);
80002 pagefault_enable();
80003 set_fs(old_fs);
80004
80005@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
80006
80007 set_fs(KERNEL_DS);
80008 pagefault_disable();
80009- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
80010+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
80011 pagefault_enable();
80012 set_fs(old_fs);
80013
80014diff --git a/mm/madvise.c b/mm/madvise.c
80015index 03dfa5c..b032917 100644
80016--- a/mm/madvise.c
80017+++ b/mm/madvise.c
80018@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
80019 pgoff_t pgoff;
80020 unsigned long new_flags = vma->vm_flags;
80021
80022+#ifdef CONFIG_PAX_SEGMEXEC
80023+ struct vm_area_struct *vma_m;
80024+#endif
80025+
80026 switch (behavior) {
80027 case MADV_NORMAL:
80028 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
80029@@ -123,6 +127,13 @@ success:
80030 /*
80031 * vm_flags is protected by the mmap_sem held in write mode.
80032 */
80033+
80034+#ifdef CONFIG_PAX_SEGMEXEC
80035+ vma_m = pax_find_mirror_vma(vma);
80036+ if (vma_m)
80037+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
80038+#endif
80039+
80040 vma->vm_flags = new_flags;
80041
80042 out:
80043@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80044 struct vm_area_struct ** prev,
80045 unsigned long start, unsigned long end)
80046 {
80047+
80048+#ifdef CONFIG_PAX_SEGMEXEC
80049+ struct vm_area_struct *vma_m;
80050+#endif
80051+
80052 *prev = vma;
80053 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
80054 return -EINVAL;
80055@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80056 zap_page_range(vma, start, end - start, &details);
80057 } else
80058 zap_page_range(vma, start, end - start, NULL);
80059+
80060+#ifdef CONFIG_PAX_SEGMEXEC
80061+ vma_m = pax_find_mirror_vma(vma);
80062+ if (vma_m) {
80063+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
80064+ struct zap_details details = {
80065+ .nonlinear_vma = vma_m,
80066+ .last_index = ULONG_MAX,
80067+ };
80068+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
80069+ } else
80070+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
80071+ }
80072+#endif
80073+
80074 return 0;
80075 }
80076
80077@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
80078 if (end < start)
80079 goto out;
80080
80081+#ifdef CONFIG_PAX_SEGMEXEC
80082+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
80083+ if (end > SEGMEXEC_TASK_SIZE)
80084+ goto out;
80085+ } else
80086+#endif
80087+
80088+ if (end > TASK_SIZE)
80089+ goto out;
80090+
80091 error = 0;
80092 if (end == start)
80093 goto out;
80094diff --git a/mm/memory-failure.c b/mm/memory-failure.c
80095index c6e4dd3..1f41988 100644
80096--- a/mm/memory-failure.c
80097+++ b/mm/memory-failure.c
80098@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
80099
80100 int sysctl_memory_failure_recovery __read_mostly = 1;
80101
80102-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
80103+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
80104
80105 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
80106
80107@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
80108 pfn, t->comm, t->pid);
80109 si.si_signo = SIGBUS;
80110 si.si_errno = 0;
80111- si.si_addr = (void *)addr;
80112+ si.si_addr = (void __user *)addr;
80113 #ifdef __ARCH_SI_TRAPNO
80114 si.si_trapno = trapno;
80115 #endif
80116@@ -760,7 +760,7 @@ static struct page_state {
80117 unsigned long res;
80118 char *msg;
80119 int (*action)(struct page *p, unsigned long pfn);
80120-} error_states[] = {
80121+} __do_const error_states[] = {
80122 { reserved, reserved, "reserved kernel", me_kernel },
80123 /*
80124 * free pages are specially detected outside this table:
80125@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80126 }
80127
80128 nr_pages = 1 << compound_trans_order(hpage);
80129- atomic_long_add(nr_pages, &mce_bad_pages);
80130+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
80131
80132 /*
80133 * We need/can do nothing about count=0 pages.
80134@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80135 if (!PageHWPoison(hpage)
80136 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
80137 || (p != hpage && TestSetPageHWPoison(hpage))) {
80138- atomic_long_sub(nr_pages, &mce_bad_pages);
80139+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80140 return 0;
80141 }
80142 set_page_hwpoison_huge_page(hpage);
80143@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80144 }
80145 if (hwpoison_filter(p)) {
80146 if (TestClearPageHWPoison(p))
80147- atomic_long_sub(nr_pages, &mce_bad_pages);
80148+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80149 unlock_page(hpage);
80150 put_page(hpage);
80151 return 0;
80152@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
80153 return 0;
80154 }
80155 if (TestClearPageHWPoison(p))
80156- atomic_long_sub(nr_pages, &mce_bad_pages);
80157+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80158 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
80159 return 0;
80160 }
80161@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
80162 */
80163 if (TestClearPageHWPoison(page)) {
80164 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
80165- atomic_long_sub(nr_pages, &mce_bad_pages);
80166+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80167 freeit = 1;
80168 if (PageHuge(page))
80169 clear_page_hwpoison_huge_page(page);
80170@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
80171 }
80172 done:
80173 if (!PageHWPoison(hpage))
80174- atomic_long_add(1 << compound_trans_order(hpage),
80175+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80176 &mce_bad_pages);
80177 set_page_hwpoison_huge_page(hpage);
80178 dequeue_hwpoisoned_huge_page(hpage);
80179@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
80180 return ret;
80181
80182 done:
80183- atomic_long_add(1, &mce_bad_pages);
80184+ atomic_long_add_unchecked(1, &mce_bad_pages);
80185 SetPageHWPoison(page);
80186 /* keep elevated page count for bad page */
80187 return ret;
80188diff --git a/mm/memory.c b/mm/memory.c
80189index bb1369f..efb96b5 100644
80190--- a/mm/memory.c
80191+++ b/mm/memory.c
80192@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80193 free_pte_range(tlb, pmd, addr);
80194 } while (pmd++, addr = next, addr != end);
80195
80196+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
80197 start &= PUD_MASK;
80198 if (start < floor)
80199 return;
80200@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80201 pmd = pmd_offset(pud, start);
80202 pud_clear(pud);
80203 pmd_free_tlb(tlb, pmd, start);
80204+#endif
80205+
80206 }
80207
80208 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80209@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80210 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
80211 } while (pud++, addr = next, addr != end);
80212
80213+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
80214 start &= PGDIR_MASK;
80215 if (start < floor)
80216 return;
80217@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80218 pud = pud_offset(pgd, start);
80219 pgd_clear(pgd);
80220 pud_free_tlb(tlb, pud, start);
80221+#endif
80222+
80223 }
80224
80225 /*
80226@@ -1618,12 +1624,6 @@ no_page_table:
80227 return page;
80228 }
80229
80230-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
80231-{
80232- return stack_guard_page_start(vma, addr) ||
80233- stack_guard_page_end(vma, addr+PAGE_SIZE);
80234-}
80235-
80236 /**
80237 * __get_user_pages() - pin user pages in memory
80238 * @tsk: task_struct of target task
80239@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80240
80241 i = 0;
80242
80243- do {
80244+ while (nr_pages) {
80245 struct vm_area_struct *vma;
80246
80247- vma = find_extend_vma(mm, start);
80248+ vma = find_vma(mm, start);
80249 if (!vma && in_gate_area(mm, start)) {
80250 unsigned long pg = start & PAGE_MASK;
80251 pgd_t *pgd;
80252@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80253 goto next_page;
80254 }
80255
80256- if (!vma ||
80257+ if (!vma || start < vma->vm_start ||
80258 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
80259 !(vm_flags & vma->vm_flags))
80260 return i ? : -EFAULT;
80261@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80262 int ret;
80263 unsigned int fault_flags = 0;
80264
80265- /* For mlock, just skip the stack guard page. */
80266- if (foll_flags & FOLL_MLOCK) {
80267- if (stack_guard_page(vma, start))
80268- goto next_page;
80269- }
80270 if (foll_flags & FOLL_WRITE)
80271 fault_flags |= FAULT_FLAG_WRITE;
80272 if (nonblocking)
80273@@ -1865,7 +1860,7 @@ next_page:
80274 start += PAGE_SIZE;
80275 nr_pages--;
80276 } while (nr_pages && start < vma->vm_end);
80277- } while (nr_pages);
80278+ }
80279 return i;
80280 }
80281 EXPORT_SYMBOL(__get_user_pages);
80282@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
80283 page_add_file_rmap(page);
80284 set_pte_at(mm, addr, pte, mk_pte(page, prot));
80285
80286+#ifdef CONFIG_PAX_SEGMEXEC
80287+ pax_mirror_file_pte(vma, addr, page, ptl);
80288+#endif
80289+
80290 retval = 0;
80291 pte_unmap_unlock(pte, ptl);
80292 return retval;
80293@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
80294 if (!page_count(page))
80295 return -EINVAL;
80296 if (!(vma->vm_flags & VM_MIXEDMAP)) {
80297+
80298+#ifdef CONFIG_PAX_SEGMEXEC
80299+ struct vm_area_struct *vma_m;
80300+#endif
80301+
80302 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
80303 BUG_ON(vma->vm_flags & VM_PFNMAP);
80304 vma->vm_flags |= VM_MIXEDMAP;
80305+
80306+#ifdef CONFIG_PAX_SEGMEXEC
80307+ vma_m = pax_find_mirror_vma(vma);
80308+ if (vma_m)
80309+ vma_m->vm_flags |= VM_MIXEDMAP;
80310+#endif
80311+
80312 }
80313 return insert_page(vma, addr, page, vma->vm_page_prot);
80314 }
80315@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
80316 unsigned long pfn)
80317 {
80318 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
80319+ BUG_ON(vma->vm_mirror);
80320
80321 if (addr < vma->vm_start || addr >= vma->vm_end)
80322 return -EFAULT;
80323@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
80324
80325 BUG_ON(pud_huge(*pud));
80326
80327- pmd = pmd_alloc(mm, pud, addr);
80328+ pmd = (mm == &init_mm) ?
80329+ pmd_alloc_kernel(mm, pud, addr) :
80330+ pmd_alloc(mm, pud, addr);
80331 if (!pmd)
80332 return -ENOMEM;
80333 do {
80334@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
80335 unsigned long next;
80336 int err;
80337
80338- pud = pud_alloc(mm, pgd, addr);
80339+ pud = (mm == &init_mm) ?
80340+ pud_alloc_kernel(mm, pgd, addr) :
80341+ pud_alloc(mm, pgd, addr);
80342 if (!pud)
80343 return -ENOMEM;
80344 do {
80345@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
80346 copy_user_highpage(dst, src, va, vma);
80347 }
80348
80349+#ifdef CONFIG_PAX_SEGMEXEC
80350+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
80351+{
80352+ struct mm_struct *mm = vma->vm_mm;
80353+ spinlock_t *ptl;
80354+ pte_t *pte, entry;
80355+
80356+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
80357+ entry = *pte;
80358+ if (!pte_present(entry)) {
80359+ if (!pte_none(entry)) {
80360+ BUG_ON(pte_file(entry));
80361+ free_swap_and_cache(pte_to_swp_entry(entry));
80362+ pte_clear_not_present_full(mm, address, pte, 0);
80363+ }
80364+ } else {
80365+ struct page *page;
80366+
80367+ flush_cache_page(vma, address, pte_pfn(entry));
80368+ entry = ptep_clear_flush(vma, address, pte);
80369+ BUG_ON(pte_dirty(entry));
80370+ page = vm_normal_page(vma, address, entry);
80371+ if (page) {
80372+ update_hiwater_rss(mm);
80373+ if (PageAnon(page))
80374+ dec_mm_counter_fast(mm, MM_ANONPAGES);
80375+ else
80376+ dec_mm_counter_fast(mm, MM_FILEPAGES);
80377+ page_remove_rmap(page);
80378+ page_cache_release(page);
80379+ }
80380+ }
80381+ pte_unmap_unlock(pte, ptl);
80382+}
80383+
80384+/* PaX: if vma is mirrored, synchronize the mirror's PTE
80385+ *
80386+ * the ptl of the lower mapped page is held on entry and is not released on exit
80387+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
80388+ */
80389+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80390+{
80391+ struct mm_struct *mm = vma->vm_mm;
80392+ unsigned long address_m;
80393+ spinlock_t *ptl_m;
80394+ struct vm_area_struct *vma_m;
80395+ pmd_t *pmd_m;
80396+ pte_t *pte_m, entry_m;
80397+
80398+ BUG_ON(!page_m || !PageAnon(page_m));
80399+
80400+ vma_m = pax_find_mirror_vma(vma);
80401+ if (!vma_m)
80402+ return;
80403+
80404+ BUG_ON(!PageLocked(page_m));
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_anon_rmap(page_m, vma_m, address_m);
80419+ inc_mm_counter_fast(mm, MM_ANONPAGES);
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+ unlock_page(page_m);
80427+}
80428+
80429+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80430+{
80431+ struct mm_struct *mm = vma->vm_mm;
80432+ unsigned long address_m;
80433+ spinlock_t *ptl_m;
80434+ struct vm_area_struct *vma_m;
80435+ pmd_t *pmd_m;
80436+ pte_t *pte_m, entry_m;
80437+
80438+ BUG_ON(!page_m || PageAnon(page_m));
80439+
80440+ vma_m = pax_find_mirror_vma(vma);
80441+ if (!vma_m)
80442+ return;
80443+
80444+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80445+ address_m = address + SEGMEXEC_TASK_SIZE;
80446+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80447+ pte_m = pte_offset_map(pmd_m, address_m);
80448+ ptl_m = pte_lockptr(mm, pmd_m);
80449+ if (ptl != ptl_m) {
80450+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80451+ if (!pte_none(*pte_m))
80452+ goto out;
80453+ }
80454+
80455+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80456+ page_cache_get(page_m);
80457+ page_add_file_rmap(page_m);
80458+ inc_mm_counter_fast(mm, MM_FILEPAGES);
80459+ set_pte_at(mm, address_m, pte_m, entry_m);
80460+ update_mmu_cache(vma_m, address_m, entry_m);
80461+out:
80462+ if (ptl != ptl_m)
80463+ spin_unlock(ptl_m);
80464+ pte_unmap(pte_m);
80465+}
80466+
80467+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
80468+{
80469+ struct mm_struct *mm = vma->vm_mm;
80470+ unsigned long address_m;
80471+ spinlock_t *ptl_m;
80472+ struct vm_area_struct *vma_m;
80473+ pmd_t *pmd_m;
80474+ pte_t *pte_m, entry_m;
80475+
80476+ vma_m = pax_find_mirror_vma(vma);
80477+ if (!vma_m)
80478+ return;
80479+
80480+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80481+ address_m = address + SEGMEXEC_TASK_SIZE;
80482+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80483+ pte_m = pte_offset_map(pmd_m, address_m);
80484+ ptl_m = pte_lockptr(mm, pmd_m);
80485+ if (ptl != ptl_m) {
80486+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80487+ if (!pte_none(*pte_m))
80488+ goto out;
80489+ }
80490+
80491+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
80492+ set_pte_at(mm, address_m, pte_m, entry_m);
80493+out:
80494+ if (ptl != ptl_m)
80495+ spin_unlock(ptl_m);
80496+ pte_unmap(pte_m);
80497+}
80498+
80499+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
80500+{
80501+ struct page *page_m;
80502+ pte_t entry;
80503+
80504+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
80505+ goto out;
80506+
80507+ entry = *pte;
80508+ page_m = vm_normal_page(vma, address, entry);
80509+ if (!page_m)
80510+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
80511+ else if (PageAnon(page_m)) {
80512+ if (pax_find_mirror_vma(vma)) {
80513+ pte_unmap_unlock(pte, ptl);
80514+ lock_page(page_m);
80515+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
80516+ if (pte_same(entry, *pte))
80517+ pax_mirror_anon_pte(vma, address, page_m, ptl);
80518+ else
80519+ unlock_page(page_m);
80520+ }
80521+ } else
80522+ pax_mirror_file_pte(vma, address, page_m, ptl);
80523+
80524+out:
80525+ pte_unmap_unlock(pte, ptl);
80526+}
80527+#endif
80528+
80529 /*
80530 * This routine handles present pages, when users try to write
80531 * to a shared page. It is done by copying the page to a new address
80532@@ -2725,6 +2921,12 @@ gotten:
80533 */
80534 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80535 if (likely(pte_same(*page_table, orig_pte))) {
80536+
80537+#ifdef CONFIG_PAX_SEGMEXEC
80538+ if (pax_find_mirror_vma(vma))
80539+ BUG_ON(!trylock_page(new_page));
80540+#endif
80541+
80542 if (old_page) {
80543 if (!PageAnon(old_page)) {
80544 dec_mm_counter_fast(mm, MM_FILEPAGES);
80545@@ -2776,6 +2978,10 @@ gotten:
80546 page_remove_rmap(old_page);
80547 }
80548
80549+#ifdef CONFIG_PAX_SEGMEXEC
80550+ pax_mirror_anon_pte(vma, address, new_page, ptl);
80551+#endif
80552+
80553 /* Free the old page.. */
80554 new_page = old_page;
80555 ret |= VM_FAULT_WRITE;
80556@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80557 swap_free(entry);
80558 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
80559 try_to_free_swap(page);
80560+
80561+#ifdef CONFIG_PAX_SEGMEXEC
80562+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
80563+#endif
80564+
80565 unlock_page(page);
80566 if (swapcache) {
80567 /*
80568@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80569
80570 /* No need to invalidate - it was non-present before */
80571 update_mmu_cache(vma, address, page_table);
80572+
80573+#ifdef CONFIG_PAX_SEGMEXEC
80574+ pax_mirror_anon_pte(vma, address, page, ptl);
80575+#endif
80576+
80577 unlock:
80578 pte_unmap_unlock(page_table, ptl);
80579 out:
80580@@ -3093,40 +3309,6 @@ out_release:
80581 }
80582
80583 /*
80584- * This is like a special single-page "expand_{down|up}wards()",
80585- * except we must first make sure that 'address{-|+}PAGE_SIZE'
80586- * doesn't hit another vma.
80587- */
80588-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
80589-{
80590- address &= PAGE_MASK;
80591- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
80592- struct vm_area_struct *prev = vma->vm_prev;
80593-
80594- /*
80595- * Is there a mapping abutting this one below?
80596- *
80597- * That's only ok if it's the same stack mapping
80598- * that has gotten split..
80599- */
80600- if (prev && prev->vm_end == address)
80601- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
80602-
80603- expand_downwards(vma, address - PAGE_SIZE);
80604- }
80605- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
80606- struct vm_area_struct *next = vma->vm_next;
80607-
80608- /* As VM_GROWSDOWN but s/below/above/ */
80609- if (next && next->vm_start == address + PAGE_SIZE)
80610- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
80611-
80612- expand_upwards(vma, address + PAGE_SIZE);
80613- }
80614- return 0;
80615-}
80616-
80617-/*
80618 * We enter with non-exclusive mmap_sem (to exclude vma changes,
80619 * but allow concurrent faults), and pte mapped but not yet locked.
80620 * We return with mmap_sem still held, but pte unmapped and unlocked.
80621@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80622 unsigned long address, pte_t *page_table, pmd_t *pmd,
80623 unsigned int flags)
80624 {
80625- struct page *page;
80626+ struct page *page = NULL;
80627 spinlock_t *ptl;
80628 pte_t entry;
80629
80630- pte_unmap(page_table);
80631-
80632- /* Check if we need to add a guard page to the stack */
80633- if (check_stack_guard_page(vma, address) < 0)
80634- return VM_FAULT_SIGBUS;
80635-
80636- /* Use the zero-page for reads */
80637 if (!(flags & FAULT_FLAG_WRITE)) {
80638 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
80639 vma->vm_page_prot));
80640- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80641+ ptl = pte_lockptr(mm, pmd);
80642+ spin_lock(ptl);
80643 if (!pte_none(*page_table))
80644 goto unlock;
80645 goto setpte;
80646 }
80647
80648 /* Allocate our own private page. */
80649+ pte_unmap(page_table);
80650+
80651 if (unlikely(anon_vma_prepare(vma)))
80652 goto oom;
80653 page = alloc_zeroed_user_highpage_movable(vma, address);
80654@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80655 if (!pte_none(*page_table))
80656 goto release;
80657
80658+#ifdef CONFIG_PAX_SEGMEXEC
80659+ if (pax_find_mirror_vma(vma))
80660+ BUG_ON(!trylock_page(page));
80661+#endif
80662+
80663 inc_mm_counter_fast(mm, MM_ANONPAGES);
80664 page_add_new_anon_rmap(page, vma, address);
80665 setpte:
80666@@ -3181,6 +3364,12 @@ setpte:
80667
80668 /* No need to invalidate - it was non-present before */
80669 update_mmu_cache(vma, address, page_table);
80670+
80671+#ifdef CONFIG_PAX_SEGMEXEC
80672+ if (page)
80673+ pax_mirror_anon_pte(vma, address, page, ptl);
80674+#endif
80675+
80676 unlock:
80677 pte_unmap_unlock(page_table, ptl);
80678 return 0;
80679@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80680 */
80681 /* Only go through if we didn't race with anybody else... */
80682 if (likely(pte_same(*page_table, orig_pte))) {
80683+
80684+#ifdef CONFIG_PAX_SEGMEXEC
80685+ if (anon && pax_find_mirror_vma(vma))
80686+ BUG_ON(!trylock_page(page));
80687+#endif
80688+
80689 flush_icache_page(vma, page);
80690 entry = mk_pte(page, vma->vm_page_prot);
80691 if (flags & FAULT_FLAG_WRITE)
80692@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80693
80694 /* no need to invalidate: a not-present page won't be cached */
80695 update_mmu_cache(vma, address, page_table);
80696+
80697+#ifdef CONFIG_PAX_SEGMEXEC
80698+ if (anon)
80699+ pax_mirror_anon_pte(vma, address, page, ptl);
80700+ else
80701+ pax_mirror_file_pte(vma, address, page, ptl);
80702+#endif
80703+
80704 } else {
80705 if (cow_page)
80706 mem_cgroup_uncharge_page(cow_page);
80707@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
80708 if (flags & FAULT_FLAG_WRITE)
80709 flush_tlb_fix_spurious_fault(vma, address);
80710 }
80711+
80712+#ifdef CONFIG_PAX_SEGMEXEC
80713+ pax_mirror_pte(vma, address, pte, pmd, ptl);
80714+ return 0;
80715+#endif
80716+
80717 unlock:
80718 pte_unmap_unlock(pte, ptl);
80719 return 0;
80720@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80721 pmd_t *pmd;
80722 pte_t *pte;
80723
80724+#ifdef CONFIG_PAX_SEGMEXEC
80725+ struct vm_area_struct *vma_m;
80726+#endif
80727+
80728 __set_current_state(TASK_RUNNING);
80729
80730 count_vm_event(PGFAULT);
80731@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80732 if (unlikely(is_vm_hugetlb_page(vma)))
80733 return hugetlb_fault(mm, vma, address, flags);
80734
80735+#ifdef CONFIG_PAX_SEGMEXEC
80736+ vma_m = pax_find_mirror_vma(vma);
80737+ if (vma_m) {
80738+ unsigned long address_m;
80739+ pgd_t *pgd_m;
80740+ pud_t *pud_m;
80741+ pmd_t *pmd_m;
80742+
80743+ if (vma->vm_start > vma_m->vm_start) {
80744+ address_m = address;
80745+ address -= SEGMEXEC_TASK_SIZE;
80746+ vma = vma_m;
80747+ } else
80748+ address_m = address + SEGMEXEC_TASK_SIZE;
80749+
80750+ pgd_m = pgd_offset(mm, address_m);
80751+ pud_m = pud_alloc(mm, pgd_m, address_m);
80752+ if (!pud_m)
80753+ return VM_FAULT_OOM;
80754+ pmd_m = pmd_alloc(mm, pud_m, address_m);
80755+ if (!pmd_m)
80756+ return VM_FAULT_OOM;
80757+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
80758+ return VM_FAULT_OOM;
80759+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
80760+ }
80761+#endif
80762+
80763 retry:
80764 pgd = pgd_offset(mm, address);
80765 pud = pud_alloc(mm, pgd, address);
80766@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80767 spin_unlock(&mm->page_table_lock);
80768 return 0;
80769 }
80770+
80771+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80772+{
80773+ pud_t *new = pud_alloc_one(mm, address);
80774+ if (!new)
80775+ return -ENOMEM;
80776+
80777+ smp_wmb(); /* See comment in __pte_alloc */
80778+
80779+ spin_lock(&mm->page_table_lock);
80780+ if (pgd_present(*pgd)) /* Another has populated it */
80781+ pud_free(mm, new);
80782+ else
80783+ pgd_populate_kernel(mm, pgd, new);
80784+ spin_unlock(&mm->page_table_lock);
80785+ return 0;
80786+}
80787 #endif /* __PAGETABLE_PUD_FOLDED */
80788
80789 #ifndef __PAGETABLE_PMD_FOLDED
80790@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80791 spin_unlock(&mm->page_table_lock);
80792 return 0;
80793 }
80794+
80795+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80796+{
80797+ pmd_t *new = pmd_alloc_one(mm, address);
80798+ if (!new)
80799+ return -ENOMEM;
80800+
80801+ smp_wmb(); /* See comment in __pte_alloc */
80802+
80803+ spin_lock(&mm->page_table_lock);
80804+#ifndef __ARCH_HAS_4LEVEL_HACK
80805+ if (pud_present(*pud)) /* Another has populated it */
80806+ pmd_free(mm, new);
80807+ else
80808+ pud_populate_kernel(mm, pud, new);
80809+#else
80810+ if (pgd_present(*pud)) /* Another has populated it */
80811+ pmd_free(mm, new);
80812+ else
80813+ pgd_populate_kernel(mm, pud, new);
80814+#endif /* __ARCH_HAS_4LEVEL_HACK */
80815+ spin_unlock(&mm->page_table_lock);
80816+ return 0;
80817+}
80818 #endif /* __PAGETABLE_PMD_FOLDED */
80819
80820 int make_pages_present(unsigned long addr, unsigned long end)
80821@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
80822 gate_vma.vm_start = FIXADDR_USER_START;
80823 gate_vma.vm_end = FIXADDR_USER_END;
80824 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
80825- gate_vma.vm_page_prot = __P101;
80826+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
80827
80828 return 0;
80829 }
80830diff --git a/mm/mempolicy.c b/mm/mempolicy.c
80831index 3df6d12..a11056a 100644
80832--- a/mm/mempolicy.c
80833+++ b/mm/mempolicy.c
80834@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80835 unsigned long vmstart;
80836 unsigned long vmend;
80837
80838+#ifdef CONFIG_PAX_SEGMEXEC
80839+ struct vm_area_struct *vma_m;
80840+#endif
80841+
80842 vma = find_vma(mm, start);
80843 if (!vma || vma->vm_start > start)
80844 return -EFAULT;
80845@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80846 if (err)
80847 goto out;
80848 }
80849+
80850 err = vma_replace_policy(vma, new_pol);
80851 if (err)
80852 goto out;
80853+
80854+#ifdef CONFIG_PAX_SEGMEXEC
80855+ vma_m = pax_find_mirror_vma(vma);
80856+ if (vma_m) {
80857+ err = vma_replace_policy(vma_m, new_pol);
80858+ if (err)
80859+ goto out;
80860+ }
80861+#endif
80862+
80863 }
80864
80865 out:
80866@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
80867
80868 if (end < start)
80869 return -EINVAL;
80870+
80871+#ifdef CONFIG_PAX_SEGMEXEC
80872+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80873+ if (end > SEGMEXEC_TASK_SIZE)
80874+ return -EINVAL;
80875+ } else
80876+#endif
80877+
80878+ if (end > TASK_SIZE)
80879+ return -EINVAL;
80880+
80881 if (end == start)
80882 return 0;
80883
80884@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80885 */
80886 tcred = __task_cred(task);
80887 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80888- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80889- !capable(CAP_SYS_NICE)) {
80890+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80891 rcu_read_unlock();
80892 err = -EPERM;
80893 goto out_put;
80894@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80895 goto out;
80896 }
80897
80898+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80899+ if (mm != current->mm &&
80900+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
80901+ mmput(mm);
80902+ err = -EPERM;
80903+ goto out;
80904+ }
80905+#endif
80906+
80907 err = do_migrate_pages(mm, old, new,
80908 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
80909
80910diff --git a/mm/migrate.c b/mm/migrate.c
80911index 2fd8b4a..d70358f 100644
80912--- a/mm/migrate.c
80913+++ b/mm/migrate.c
80914@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
80915 */
80916 tcred = __task_cred(task);
80917 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80918- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80919- !capable(CAP_SYS_NICE)) {
80920+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80921 rcu_read_unlock();
80922 err = -EPERM;
80923 goto out;
80924diff --git a/mm/mlock.c b/mm/mlock.c
80925index c9bd528..da8d069 100644
80926--- a/mm/mlock.c
80927+++ b/mm/mlock.c
80928@@ -13,6 +13,7 @@
80929 #include <linux/pagemap.h>
80930 #include <linux/mempolicy.h>
80931 #include <linux/syscalls.h>
80932+#include <linux/security.h>
80933 #include <linux/sched.h>
80934 #include <linux/export.h>
80935 #include <linux/rmap.h>
80936@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
80937 {
80938 unsigned long nstart, end, tmp;
80939 struct vm_area_struct * vma, * prev;
80940- int error;
80941+ int error = 0;
80942
80943 VM_BUG_ON(start & ~PAGE_MASK);
80944 VM_BUG_ON(len != PAGE_ALIGN(len));
80945@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
80946 return -EINVAL;
80947 if (end == start)
80948 return 0;
80949+ if (end > TASK_SIZE)
80950+ return -EINVAL;
80951+
80952 vma = find_vma(current->mm, start);
80953 if (!vma || vma->vm_start > start)
80954 return -ENOMEM;
80955@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
80956 for (nstart = start ; ; ) {
80957 vm_flags_t newflags;
80958
80959+#ifdef CONFIG_PAX_SEGMEXEC
80960+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80961+ break;
80962+#endif
80963+
80964 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
80965
80966 newflags = vma->vm_flags | VM_LOCKED;
80967@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
80968 lock_limit >>= PAGE_SHIFT;
80969
80970 /* check against resource limits */
80971+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
80972 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
80973 error = do_mlock(start, len, 1);
80974 up_write(&current->mm->mmap_sem);
80975@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
80976 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
80977 vm_flags_t newflags;
80978
80979+#ifdef CONFIG_PAX_SEGMEXEC
80980+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80981+ break;
80982+#endif
80983+
80984+ BUG_ON(vma->vm_end > TASK_SIZE);
80985 newflags = vma->vm_flags | VM_LOCKED;
80986 if (!(flags & MCL_CURRENT))
80987 newflags &= ~VM_LOCKED;
80988@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80989 lock_limit >>= PAGE_SHIFT;
80990
80991 ret = -ENOMEM;
80992+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80993 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80994 capable(CAP_IPC_LOCK))
80995 ret = do_mlockall(flags);
80996diff --git a/mm/mmap.c b/mm/mmap.c
80997index 8832b87..4bbb1b2 100644
80998--- a/mm/mmap.c
80999+++ b/mm/mmap.c
81000@@ -32,6 +32,7 @@
81001 #include <linux/khugepaged.h>
81002 #include <linux/uprobes.h>
81003 #include <linux/rbtree_augmented.h>
81004+#include <linux/random.h>
81005
81006 #include <asm/uaccess.h>
81007 #include <asm/cacheflush.h>
81008@@ -48,6 +49,16 @@
81009 #define arch_rebalance_pgtables(addr, len) (addr)
81010 #endif
81011
81012+static inline void verify_mm_writelocked(struct mm_struct *mm)
81013+{
81014+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
81015+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81016+ up_read(&mm->mmap_sem);
81017+ BUG();
81018+ }
81019+#endif
81020+}
81021+
81022 static void unmap_region(struct mm_struct *mm,
81023 struct vm_area_struct *vma, struct vm_area_struct *prev,
81024 unsigned long start, unsigned long end);
81025@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
81026 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
81027 *
81028 */
81029-pgprot_t protection_map[16] = {
81030+pgprot_t protection_map[16] __read_only = {
81031 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
81032 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
81033 };
81034
81035-pgprot_t vm_get_page_prot(unsigned long vm_flags)
81036+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
81037 {
81038- return __pgprot(pgprot_val(protection_map[vm_flags &
81039+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
81040 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
81041 pgprot_val(arch_vm_get_page_prot(vm_flags)));
81042+
81043+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81044+ if (!(__supported_pte_mask & _PAGE_NX) &&
81045+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
81046+ (vm_flags & (VM_READ | VM_WRITE)))
81047+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
81048+#endif
81049+
81050+ return prot;
81051 }
81052 EXPORT_SYMBOL(vm_get_page_prot);
81053
81054 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
81055 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
81056 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
81057+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
81058 /*
81059 * Make sure vm_committed_as in one cacheline and not cacheline shared with
81060 * other variables. It can be updated by several CPUs frequently.
81061@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
81062 struct vm_area_struct *next = vma->vm_next;
81063
81064 might_sleep();
81065+ BUG_ON(vma->vm_mirror);
81066 if (vma->vm_ops && vma->vm_ops->close)
81067 vma->vm_ops->close(vma);
81068 if (vma->vm_file)
81069@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
81070 * not page aligned -Ram Gupta
81071 */
81072 rlim = rlimit(RLIMIT_DATA);
81073+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
81074 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
81075 (mm->end_data - mm->start_data) > rlim)
81076 goto out;
81077@@ -888,6 +911,12 @@ static int
81078 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
81079 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81080 {
81081+
81082+#ifdef CONFIG_PAX_SEGMEXEC
81083+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
81084+ return 0;
81085+#endif
81086+
81087 if (is_mergeable_vma(vma, file, vm_flags) &&
81088 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81089 if (vma->vm_pgoff == vm_pgoff)
81090@@ -907,6 +936,12 @@ static int
81091 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81092 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81093 {
81094+
81095+#ifdef CONFIG_PAX_SEGMEXEC
81096+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
81097+ return 0;
81098+#endif
81099+
81100 if (is_mergeable_vma(vma, file, vm_flags) &&
81101 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81102 pgoff_t vm_pglen;
81103@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81104 struct vm_area_struct *vma_merge(struct mm_struct *mm,
81105 struct vm_area_struct *prev, unsigned long addr,
81106 unsigned long end, unsigned long vm_flags,
81107- struct anon_vma *anon_vma, struct file *file,
81108+ struct anon_vma *anon_vma, struct file *file,
81109 pgoff_t pgoff, struct mempolicy *policy)
81110 {
81111 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
81112 struct vm_area_struct *area, *next;
81113 int err;
81114
81115+#ifdef CONFIG_PAX_SEGMEXEC
81116+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
81117+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
81118+
81119+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
81120+#endif
81121+
81122 /*
81123 * We later require that vma->vm_flags == vm_flags,
81124 * so this tests vma->vm_flags & VM_SPECIAL, too.
81125@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81126 if (next && next->vm_end == end) /* cases 6, 7, 8 */
81127 next = next->vm_next;
81128
81129+#ifdef CONFIG_PAX_SEGMEXEC
81130+ if (prev)
81131+ prev_m = pax_find_mirror_vma(prev);
81132+ if (area)
81133+ area_m = pax_find_mirror_vma(area);
81134+ if (next)
81135+ next_m = pax_find_mirror_vma(next);
81136+#endif
81137+
81138 /*
81139 * Can it merge with the predecessor?
81140 */
81141@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81142 /* cases 1, 6 */
81143 err = vma_adjust(prev, prev->vm_start,
81144 next->vm_end, prev->vm_pgoff, NULL);
81145- } else /* cases 2, 5, 7 */
81146+
81147+#ifdef CONFIG_PAX_SEGMEXEC
81148+ if (!err && prev_m)
81149+ err = vma_adjust(prev_m, prev_m->vm_start,
81150+ next_m->vm_end, prev_m->vm_pgoff, NULL);
81151+#endif
81152+
81153+ } else { /* cases 2, 5, 7 */
81154 err = vma_adjust(prev, prev->vm_start,
81155 end, prev->vm_pgoff, NULL);
81156+
81157+#ifdef CONFIG_PAX_SEGMEXEC
81158+ if (!err && prev_m)
81159+ err = vma_adjust(prev_m, prev_m->vm_start,
81160+ end_m, prev_m->vm_pgoff, NULL);
81161+#endif
81162+
81163+ }
81164 if (err)
81165 return NULL;
81166 khugepaged_enter_vma_merge(prev);
81167@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81168 mpol_equal(policy, vma_policy(next)) &&
81169 can_vma_merge_before(next, vm_flags,
81170 anon_vma, file, pgoff+pglen)) {
81171- if (prev && addr < prev->vm_end) /* case 4 */
81172+ if (prev && addr < prev->vm_end) { /* case 4 */
81173 err = vma_adjust(prev, prev->vm_start,
81174 addr, prev->vm_pgoff, NULL);
81175- else /* cases 3, 8 */
81176+
81177+#ifdef CONFIG_PAX_SEGMEXEC
81178+ if (!err && prev_m)
81179+ err = vma_adjust(prev_m, prev_m->vm_start,
81180+ addr_m, prev_m->vm_pgoff, NULL);
81181+#endif
81182+
81183+ } else { /* cases 3, 8 */
81184 err = vma_adjust(area, addr, next->vm_end,
81185 next->vm_pgoff - pglen, NULL);
81186+
81187+#ifdef CONFIG_PAX_SEGMEXEC
81188+ if (!err && area_m)
81189+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
81190+ next_m->vm_pgoff - pglen, NULL);
81191+#endif
81192+
81193+ }
81194 if (err)
81195 return NULL;
81196 khugepaged_enter_vma_merge(area);
81197@@ -1120,8 +1201,10 @@ none:
81198 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81199 struct file *file, long pages)
81200 {
81201- const unsigned long stack_flags
81202- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
81203+
81204+#ifdef CONFIG_PAX_RANDMMAP
81205+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81206+#endif
81207
81208 mm->total_vm += pages;
81209
81210@@ -1129,7 +1212,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81211 mm->shared_vm += pages;
81212 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
81213 mm->exec_vm += pages;
81214- } else if (flags & stack_flags)
81215+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
81216 mm->stack_vm += pages;
81217 }
81218 #endif /* CONFIG_PROC_FS */
81219@@ -1165,7 +1248,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81220 * (the exception is when the underlying filesystem is noexec
81221 * mounted, in which case we dont add PROT_EXEC.)
81222 */
81223- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81224+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81225 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
81226 prot |= PROT_EXEC;
81227
81228@@ -1191,7 +1274,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81229 /* Obtain the address to map to. we verify (or select) it and ensure
81230 * that it represents a valid section of the address space.
81231 */
81232- addr = get_unmapped_area(file, addr, len, pgoff, flags);
81233+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
81234 if (addr & ~PAGE_MASK)
81235 return addr;
81236
81237@@ -1202,6 +1285,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81238 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
81239 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
81240
81241+#ifdef CONFIG_PAX_MPROTECT
81242+ if (mm->pax_flags & MF_PAX_MPROTECT) {
81243+#ifndef CONFIG_PAX_MPROTECT_COMPAT
81244+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
81245+ gr_log_rwxmmap(file);
81246+
81247+#ifdef CONFIG_PAX_EMUPLT
81248+ vm_flags &= ~VM_EXEC;
81249+#else
81250+ return -EPERM;
81251+#endif
81252+
81253+ }
81254+
81255+ if (!(vm_flags & VM_EXEC))
81256+ vm_flags &= ~VM_MAYEXEC;
81257+#else
81258+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81259+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81260+#endif
81261+ else
81262+ vm_flags &= ~VM_MAYWRITE;
81263+ }
81264+#endif
81265+
81266+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81267+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
81268+ vm_flags &= ~VM_PAGEEXEC;
81269+#endif
81270+
81271 if (flags & MAP_LOCKED)
81272 if (!can_do_mlock())
81273 return -EPERM;
81274@@ -1213,6 +1326,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81275 locked += mm->locked_vm;
81276 lock_limit = rlimit(RLIMIT_MEMLOCK);
81277 lock_limit >>= PAGE_SHIFT;
81278+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81279 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
81280 return -EAGAIN;
81281 }
81282@@ -1279,6 +1393,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81283 }
81284 }
81285
81286+ if (!gr_acl_handle_mmap(file, prot))
81287+ return -EACCES;
81288+
81289 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
81290 }
81291
81292@@ -1356,7 +1473,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
81293 vm_flags_t vm_flags = vma->vm_flags;
81294
81295 /* If it was private or non-writable, the write bit is already clear */
81296- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
81297+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
81298 return 0;
81299
81300 /* The backer wishes to know when pages are first written to? */
81301@@ -1405,16 +1522,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
81302 unsigned long charged = 0;
81303 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
81304
81305+#ifdef CONFIG_PAX_SEGMEXEC
81306+ struct vm_area_struct *vma_m = NULL;
81307+#endif
81308+
81309+ /*
81310+ * mm->mmap_sem is required to protect against another thread
81311+ * changing the mappings in case we sleep.
81312+ */
81313+ verify_mm_writelocked(mm);
81314+
81315 /* Clear old maps */
81316 error = -ENOMEM;
81317-munmap_back:
81318 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81319 if (do_munmap(mm, addr, len))
81320 return -ENOMEM;
81321- goto munmap_back;
81322+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81323 }
81324
81325 /* Check against address space limit. */
81326+
81327+#ifdef CONFIG_PAX_RANDMMAP
81328+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81329+#endif
81330+
81331 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81332 return -ENOMEM;
81333
81334@@ -1460,6 +1591,16 @@ munmap_back:
81335 goto unacct_error;
81336 }
81337
81338+#ifdef CONFIG_PAX_SEGMEXEC
81339+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
81340+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81341+ if (!vma_m) {
81342+ error = -ENOMEM;
81343+ goto free_vma;
81344+ }
81345+ }
81346+#endif
81347+
81348 vma->vm_mm = mm;
81349 vma->vm_start = addr;
81350 vma->vm_end = addr + len;
81351@@ -1484,6 +1625,13 @@ munmap_back:
81352 if (error)
81353 goto unmap_and_free_vma;
81354
81355+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81356+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
81357+ vma->vm_flags |= VM_PAGEEXEC;
81358+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81359+ }
81360+#endif
81361+
81362 /* Can addr have changed??
81363 *
81364 * Answer: Yes, several device drivers can do it in their
81365@@ -1522,6 +1670,11 @@ munmap_back:
81366 vma_link(mm, vma, prev, rb_link, rb_parent);
81367 file = vma->vm_file;
81368
81369+#ifdef CONFIG_PAX_SEGMEXEC
81370+ if (vma_m)
81371+ BUG_ON(pax_mirror_vma(vma_m, vma));
81372+#endif
81373+
81374 /* Once vma denies write, undo our temporary denial count */
81375 if (correct_wcount)
81376 atomic_inc(&inode->i_writecount);
81377@@ -1529,6 +1682,7 @@ out:
81378 perf_event_mmap(vma);
81379
81380 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
81381+ track_exec_limit(mm, addr, addr + len, vm_flags);
81382 if (vm_flags & VM_LOCKED) {
81383 if (!mlock_vma_pages_range(vma, addr, addr + len))
81384 mm->locked_vm += (len >> PAGE_SHIFT);
81385@@ -1550,6 +1704,12 @@ unmap_and_free_vma:
81386 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
81387 charged = 0;
81388 free_vma:
81389+
81390+#ifdef CONFIG_PAX_SEGMEXEC
81391+ if (vma_m)
81392+ kmem_cache_free(vm_area_cachep, vma_m);
81393+#endif
81394+
81395 kmem_cache_free(vm_area_cachep, vma);
81396 unacct_error:
81397 if (charged)
81398@@ -1557,6 +1717,62 @@ unacct_error:
81399 return error;
81400 }
81401
81402+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81403+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81404+{
81405+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
81406+ return (random32() & 0xFF) << PAGE_SHIFT;
81407+
81408+ return 0;
81409+}
81410+#endif
81411+
81412+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
81413+{
81414+ if (!vma) {
81415+#ifdef CONFIG_STACK_GROWSUP
81416+ if (addr > sysctl_heap_stack_gap)
81417+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
81418+ else
81419+ vma = find_vma(current->mm, 0);
81420+ if (vma && (vma->vm_flags & VM_GROWSUP))
81421+ return false;
81422+#endif
81423+ return true;
81424+ }
81425+
81426+ if (addr + len > vma->vm_start)
81427+ return false;
81428+
81429+ if (vma->vm_flags & VM_GROWSDOWN)
81430+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
81431+#ifdef CONFIG_STACK_GROWSUP
81432+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
81433+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
81434+#endif
81435+ else if (offset)
81436+ return offset <= vma->vm_start - addr - len;
81437+
81438+ return true;
81439+}
81440+
81441+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
81442+{
81443+ if (vma->vm_start < len)
81444+ return -ENOMEM;
81445+
81446+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
81447+ if (offset <= vma->vm_start - len)
81448+ return vma->vm_start - len - offset;
81449+ else
81450+ return -ENOMEM;
81451+ }
81452+
81453+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
81454+ return vma->vm_start - len - sysctl_heap_stack_gap;
81455+ return -ENOMEM;
81456+}
81457+
81458 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
81459 {
81460 /*
81461@@ -1776,6 +1992,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81462 struct mm_struct *mm = current->mm;
81463 struct vm_area_struct *vma;
81464 struct vm_unmapped_area_info info;
81465+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81466
81467 if (len > TASK_SIZE)
81468 return -ENOMEM;
81469@@ -1783,17 +2000,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81470 if (flags & MAP_FIXED)
81471 return addr;
81472
81473+#ifdef CONFIG_PAX_RANDMMAP
81474+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81475+#endif
81476+
81477 if (addr) {
81478 addr = PAGE_ALIGN(addr);
81479 vma = find_vma(mm, addr);
81480- if (TASK_SIZE - len >= addr &&
81481- (!vma || addr + len <= vma->vm_start))
81482+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81483 return addr;
81484 }
81485
81486 info.flags = 0;
81487 info.length = len;
81488 info.low_limit = TASK_UNMAPPED_BASE;
81489+
81490+#ifdef CONFIG_PAX_RANDMMAP
81491+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81492+ info.low_limit += mm->delta_mmap;
81493+#endif
81494+
81495 info.high_limit = TASK_SIZE;
81496 info.align_mask = 0;
81497 return vm_unmapped_area(&info);
81498@@ -1802,10 +2028,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81499
81500 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
81501 {
81502+
81503+#ifdef CONFIG_PAX_SEGMEXEC
81504+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81505+ return;
81506+#endif
81507+
81508 /*
81509 * Is this a new hole at the lowest possible address?
81510 */
81511- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
81512+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
81513 mm->free_area_cache = addr;
81514 }
81515
81516@@ -1823,6 +2055,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81517 struct mm_struct *mm = current->mm;
81518 unsigned long addr = addr0;
81519 struct vm_unmapped_area_info info;
81520+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81521
81522 /* requested length too big for entire address space */
81523 if (len > TASK_SIZE)
81524@@ -1831,12 +2064,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81525 if (flags & MAP_FIXED)
81526 return addr;
81527
81528+#ifdef CONFIG_PAX_RANDMMAP
81529+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81530+#endif
81531+
81532 /* requesting a specific address */
81533 if (addr) {
81534 addr = PAGE_ALIGN(addr);
81535 vma = find_vma(mm, addr);
81536- if (TASK_SIZE - len >= addr &&
81537- (!vma || addr + len <= vma->vm_start))
81538+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81539 return addr;
81540 }
81541
81542@@ -1857,6 +2093,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81543 VM_BUG_ON(addr != -ENOMEM);
81544 info.flags = 0;
81545 info.low_limit = TASK_UNMAPPED_BASE;
81546+
81547+#ifdef CONFIG_PAX_RANDMMAP
81548+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81549+ info.low_limit += mm->delta_mmap;
81550+#endif
81551+
81552 info.high_limit = TASK_SIZE;
81553 addr = vm_unmapped_area(&info);
81554 }
81555@@ -1867,6 +2109,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81556
81557 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81558 {
81559+
81560+#ifdef CONFIG_PAX_SEGMEXEC
81561+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81562+ return;
81563+#endif
81564+
81565 /*
81566 * Is this a new hole at the highest possible address?
81567 */
81568@@ -1874,8 +2122,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81569 mm->free_area_cache = addr;
81570
81571 /* dont allow allocations above current base */
81572- if (mm->free_area_cache > mm->mmap_base)
81573+ if (mm->free_area_cache > mm->mmap_base) {
81574 mm->free_area_cache = mm->mmap_base;
81575+ mm->cached_hole_size = ~0UL;
81576+ }
81577 }
81578
81579 unsigned long
81580@@ -1974,6 +2224,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
81581 return vma;
81582 }
81583
81584+#ifdef CONFIG_PAX_SEGMEXEC
81585+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
81586+{
81587+ struct vm_area_struct *vma_m;
81588+
81589+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
81590+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
81591+ BUG_ON(vma->vm_mirror);
81592+ return NULL;
81593+ }
81594+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
81595+ vma_m = vma->vm_mirror;
81596+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
81597+ BUG_ON(vma->vm_file != vma_m->vm_file);
81598+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
81599+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
81600+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
81601+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
81602+ return vma_m;
81603+}
81604+#endif
81605+
81606 /*
81607 * Verify that the stack growth is acceptable and
81608 * update accounting. This is shared with both the
81609@@ -1990,6 +2262,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81610 return -ENOMEM;
81611
81612 /* Stack limit test */
81613+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
81614 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
81615 return -ENOMEM;
81616
81617@@ -2000,6 +2273,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81618 locked = mm->locked_vm + grow;
81619 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
81620 limit >>= PAGE_SHIFT;
81621+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81622 if (locked > limit && !capable(CAP_IPC_LOCK))
81623 return -ENOMEM;
81624 }
81625@@ -2029,37 +2303,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81626 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
81627 * vma is the last one with address > vma->vm_end. Have to extend vma.
81628 */
81629+#ifndef CONFIG_IA64
81630+static
81631+#endif
81632 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81633 {
81634 int error;
81635+ bool locknext;
81636
81637 if (!(vma->vm_flags & VM_GROWSUP))
81638 return -EFAULT;
81639
81640+ /* Also guard against wrapping around to address 0. */
81641+ if (address < PAGE_ALIGN(address+1))
81642+ address = PAGE_ALIGN(address+1);
81643+ else
81644+ return -ENOMEM;
81645+
81646 /*
81647 * We must make sure the anon_vma is allocated
81648 * so that the anon_vma locking is not a noop.
81649 */
81650 if (unlikely(anon_vma_prepare(vma)))
81651 return -ENOMEM;
81652+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
81653+ if (locknext && anon_vma_prepare(vma->vm_next))
81654+ return -ENOMEM;
81655 vma_lock_anon_vma(vma);
81656+ if (locknext)
81657+ vma_lock_anon_vma(vma->vm_next);
81658
81659 /*
81660 * vma->vm_start/vm_end cannot change under us because the caller
81661 * is required to hold the mmap_sem in read mode. We need the
81662- * anon_vma lock to serialize against concurrent expand_stacks.
81663- * Also guard against wrapping around to address 0.
81664+ * anon_vma locks to serialize against concurrent expand_stacks
81665+ * and expand_upwards.
81666 */
81667- if (address < PAGE_ALIGN(address+4))
81668- address = PAGE_ALIGN(address+4);
81669- else {
81670- vma_unlock_anon_vma(vma);
81671- return -ENOMEM;
81672- }
81673 error = 0;
81674
81675 /* Somebody else might have raced and expanded it already */
81676- if (address > vma->vm_end) {
81677+ 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)
81678+ error = -ENOMEM;
81679+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
81680 unsigned long size, grow;
81681
81682 size = address - vma->vm_start;
81683@@ -2094,6 +2379,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81684 }
81685 }
81686 }
81687+ if (locknext)
81688+ vma_unlock_anon_vma(vma->vm_next);
81689 vma_unlock_anon_vma(vma);
81690 khugepaged_enter_vma_merge(vma);
81691 validate_mm(vma->vm_mm);
81692@@ -2108,6 +2395,8 @@ int expand_downwards(struct vm_area_struct *vma,
81693 unsigned long address)
81694 {
81695 int error;
81696+ bool lockprev = false;
81697+ struct vm_area_struct *prev;
81698
81699 /*
81700 * We must make sure the anon_vma is allocated
81701@@ -2121,6 +2410,15 @@ int expand_downwards(struct vm_area_struct *vma,
81702 if (error)
81703 return error;
81704
81705+ prev = vma->vm_prev;
81706+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
81707+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
81708+#endif
81709+ if (lockprev && anon_vma_prepare(prev))
81710+ return -ENOMEM;
81711+ if (lockprev)
81712+ vma_lock_anon_vma(prev);
81713+
81714 vma_lock_anon_vma(vma);
81715
81716 /*
81717@@ -2130,9 +2428,17 @@ int expand_downwards(struct vm_area_struct *vma,
81718 */
81719
81720 /* Somebody else might have raced and expanded it already */
81721- if (address < vma->vm_start) {
81722+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
81723+ error = -ENOMEM;
81724+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
81725 unsigned long size, grow;
81726
81727+#ifdef CONFIG_PAX_SEGMEXEC
81728+ struct vm_area_struct *vma_m;
81729+
81730+ vma_m = pax_find_mirror_vma(vma);
81731+#endif
81732+
81733 size = vma->vm_end - address;
81734 grow = (vma->vm_start - address) >> PAGE_SHIFT;
81735
81736@@ -2157,6 +2463,18 @@ int expand_downwards(struct vm_area_struct *vma,
81737 vma->vm_pgoff -= grow;
81738 anon_vma_interval_tree_post_update_vma(vma);
81739 vma_gap_update(vma);
81740+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
81741+
81742+#ifdef CONFIG_PAX_SEGMEXEC
81743+ if (vma_m) {
81744+ anon_vma_interval_tree_pre_update_vma(vma_m);
81745+ vma_m->vm_start -= grow << PAGE_SHIFT;
81746+ vma_m->vm_pgoff -= grow;
81747+ anon_vma_interval_tree_post_update_vma(vma_m);
81748+ vma_gap_update(vma_m);
81749+ }
81750+#endif
81751+
81752 spin_unlock(&vma->vm_mm->page_table_lock);
81753
81754 perf_event_mmap(vma);
81755@@ -2263,6 +2581,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
81756 do {
81757 long nrpages = vma_pages(vma);
81758
81759+#ifdef CONFIG_PAX_SEGMEXEC
81760+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
81761+ vma = remove_vma(vma);
81762+ continue;
81763+ }
81764+#endif
81765+
81766 if (vma->vm_flags & VM_ACCOUNT)
81767 nr_accounted += nrpages;
81768 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
81769@@ -2308,6 +2633,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
81770 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
81771 vma->vm_prev = NULL;
81772 do {
81773+
81774+#ifdef CONFIG_PAX_SEGMEXEC
81775+ if (vma->vm_mirror) {
81776+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
81777+ vma->vm_mirror->vm_mirror = NULL;
81778+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
81779+ vma->vm_mirror = NULL;
81780+ }
81781+#endif
81782+
81783 vma_rb_erase(vma, &mm->mm_rb);
81784 mm->map_count--;
81785 tail_vma = vma;
81786@@ -2339,14 +2674,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81787 struct vm_area_struct *new;
81788 int err = -ENOMEM;
81789
81790+#ifdef CONFIG_PAX_SEGMEXEC
81791+ struct vm_area_struct *vma_m, *new_m = NULL;
81792+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
81793+#endif
81794+
81795 if (is_vm_hugetlb_page(vma) && (addr &
81796 ~(huge_page_mask(hstate_vma(vma)))))
81797 return -EINVAL;
81798
81799+#ifdef CONFIG_PAX_SEGMEXEC
81800+ vma_m = pax_find_mirror_vma(vma);
81801+#endif
81802+
81803 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81804 if (!new)
81805 goto out_err;
81806
81807+#ifdef CONFIG_PAX_SEGMEXEC
81808+ if (vma_m) {
81809+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81810+ if (!new_m) {
81811+ kmem_cache_free(vm_area_cachep, new);
81812+ goto out_err;
81813+ }
81814+ }
81815+#endif
81816+
81817 /* most fields are the same, copy all, and then fixup */
81818 *new = *vma;
81819
81820@@ -2359,6 +2713,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81821 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
81822 }
81823
81824+#ifdef CONFIG_PAX_SEGMEXEC
81825+ if (vma_m) {
81826+ *new_m = *vma_m;
81827+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
81828+ new_m->vm_mirror = new;
81829+ new->vm_mirror = new_m;
81830+
81831+ if (new_below)
81832+ new_m->vm_end = addr_m;
81833+ else {
81834+ new_m->vm_start = addr_m;
81835+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
81836+ }
81837+ }
81838+#endif
81839+
81840 pol = mpol_dup(vma_policy(vma));
81841 if (IS_ERR(pol)) {
81842 err = PTR_ERR(pol);
81843@@ -2381,6 +2751,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81844 else
81845 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
81846
81847+#ifdef CONFIG_PAX_SEGMEXEC
81848+ if (!err && vma_m) {
81849+ if (anon_vma_clone(new_m, vma_m))
81850+ goto out_free_mpol;
81851+
81852+ mpol_get(pol);
81853+ vma_set_policy(new_m, pol);
81854+
81855+ if (new_m->vm_file)
81856+ get_file(new_m->vm_file);
81857+
81858+ if (new_m->vm_ops && new_m->vm_ops->open)
81859+ new_m->vm_ops->open(new_m);
81860+
81861+ if (new_below)
81862+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
81863+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
81864+ else
81865+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
81866+
81867+ if (err) {
81868+ if (new_m->vm_ops && new_m->vm_ops->close)
81869+ new_m->vm_ops->close(new_m);
81870+ if (new_m->vm_file)
81871+ fput(new_m->vm_file);
81872+ mpol_put(pol);
81873+ }
81874+ }
81875+#endif
81876+
81877 /* Success. */
81878 if (!err)
81879 return 0;
81880@@ -2390,10 +2790,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81881 new->vm_ops->close(new);
81882 if (new->vm_file)
81883 fput(new->vm_file);
81884- unlink_anon_vmas(new);
81885 out_free_mpol:
81886 mpol_put(pol);
81887 out_free_vma:
81888+
81889+#ifdef CONFIG_PAX_SEGMEXEC
81890+ if (new_m) {
81891+ unlink_anon_vmas(new_m);
81892+ kmem_cache_free(vm_area_cachep, new_m);
81893+ }
81894+#endif
81895+
81896+ unlink_anon_vmas(new);
81897 kmem_cache_free(vm_area_cachep, new);
81898 out_err:
81899 return err;
81900@@ -2406,6 +2814,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81901 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81902 unsigned long addr, int new_below)
81903 {
81904+
81905+#ifdef CONFIG_PAX_SEGMEXEC
81906+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81907+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
81908+ if (mm->map_count >= sysctl_max_map_count-1)
81909+ return -ENOMEM;
81910+ } else
81911+#endif
81912+
81913 if (mm->map_count >= sysctl_max_map_count)
81914 return -ENOMEM;
81915
81916@@ -2417,11 +2834,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81917 * work. This now handles partial unmappings.
81918 * Jeremy Fitzhardinge <jeremy@goop.org>
81919 */
81920+#ifdef CONFIG_PAX_SEGMEXEC
81921 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81922 {
81923+ int ret = __do_munmap(mm, start, len);
81924+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
81925+ return ret;
81926+
81927+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
81928+}
81929+
81930+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81931+#else
81932+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81933+#endif
81934+{
81935 unsigned long end;
81936 struct vm_area_struct *vma, *prev, *last;
81937
81938+ /*
81939+ * mm->mmap_sem is required to protect against another thread
81940+ * changing the mappings in case we sleep.
81941+ */
81942+ verify_mm_writelocked(mm);
81943+
81944 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
81945 return -EINVAL;
81946
81947@@ -2496,6 +2932,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81948 /* Fix up all other VM information */
81949 remove_vma_list(mm, vma);
81950
81951+ track_exec_limit(mm, start, end, 0UL);
81952+
81953 return 0;
81954 }
81955
81956@@ -2504,6 +2942,13 @@ int vm_munmap(unsigned long start, size_t len)
81957 int ret;
81958 struct mm_struct *mm = current->mm;
81959
81960+
81961+#ifdef CONFIG_PAX_SEGMEXEC
81962+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
81963+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
81964+ return -EINVAL;
81965+#endif
81966+
81967 down_write(&mm->mmap_sem);
81968 ret = do_munmap(mm, start, len);
81969 up_write(&mm->mmap_sem);
81970@@ -2517,16 +2962,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
81971 return vm_munmap(addr, len);
81972 }
81973
81974-static inline void verify_mm_writelocked(struct mm_struct *mm)
81975-{
81976-#ifdef CONFIG_DEBUG_VM
81977- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81978- WARN_ON(1);
81979- up_read(&mm->mmap_sem);
81980- }
81981-#endif
81982-}
81983-
81984 /*
81985 * this is really a simplified "do_mmap". it only handles
81986 * anonymous maps. eventually we may be able to do some
81987@@ -2540,6 +2975,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81988 struct rb_node ** rb_link, * rb_parent;
81989 pgoff_t pgoff = addr >> PAGE_SHIFT;
81990 int error;
81991+ unsigned long charged;
81992
81993 len = PAGE_ALIGN(len);
81994 if (!len)
81995@@ -2547,16 +2983,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81996
81997 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
81998
81999+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
82000+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
82001+ flags &= ~VM_EXEC;
82002+
82003+#ifdef CONFIG_PAX_MPROTECT
82004+ if (mm->pax_flags & MF_PAX_MPROTECT)
82005+ flags &= ~VM_MAYEXEC;
82006+#endif
82007+
82008+ }
82009+#endif
82010+
82011 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
82012 if (error & ~PAGE_MASK)
82013 return error;
82014
82015+ charged = len >> PAGE_SHIFT;
82016+
82017 /*
82018 * mlock MCL_FUTURE?
82019 */
82020 if (mm->def_flags & VM_LOCKED) {
82021 unsigned long locked, lock_limit;
82022- locked = len >> PAGE_SHIFT;
82023+ locked = charged;
82024 locked += mm->locked_vm;
82025 lock_limit = rlimit(RLIMIT_MEMLOCK);
82026 lock_limit >>= PAGE_SHIFT;
82027@@ -2573,21 +3023,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82028 /*
82029 * Clear old maps. this also does some error checking for us
82030 */
82031- munmap_back:
82032 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82033 if (do_munmap(mm, addr, len))
82034 return -ENOMEM;
82035- goto munmap_back;
82036+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82037 }
82038
82039 /* Check against address space limits *after* clearing old maps... */
82040- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82041+ if (!may_expand_vm(mm, charged))
82042 return -ENOMEM;
82043
82044 if (mm->map_count > sysctl_max_map_count)
82045 return -ENOMEM;
82046
82047- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
82048+ if (security_vm_enough_memory_mm(mm, charged))
82049 return -ENOMEM;
82050
82051 /* Can we just expand an old private anonymous mapping? */
82052@@ -2601,7 +3050,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82053 */
82054 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82055 if (!vma) {
82056- vm_unacct_memory(len >> PAGE_SHIFT);
82057+ vm_unacct_memory(charged);
82058 return -ENOMEM;
82059 }
82060
82061@@ -2615,11 +3064,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82062 vma_link(mm, vma, prev, rb_link, rb_parent);
82063 out:
82064 perf_event_mmap(vma);
82065- mm->total_vm += len >> PAGE_SHIFT;
82066+ mm->total_vm += charged;
82067 if (flags & VM_LOCKED) {
82068 if (!mlock_vma_pages_range(vma, addr, addr + len))
82069- mm->locked_vm += (len >> PAGE_SHIFT);
82070+ mm->locked_vm += charged;
82071 }
82072+ track_exec_limit(mm, addr, addr + len, flags);
82073 return addr;
82074 }
82075
82076@@ -2677,6 +3127,7 @@ void exit_mmap(struct mm_struct *mm)
82077 while (vma) {
82078 if (vma->vm_flags & VM_ACCOUNT)
82079 nr_accounted += vma_pages(vma);
82080+ vma->vm_mirror = NULL;
82081 vma = remove_vma(vma);
82082 }
82083 vm_unacct_memory(nr_accounted);
82084@@ -2693,6 +3144,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82085 struct vm_area_struct *prev;
82086 struct rb_node **rb_link, *rb_parent;
82087
82088+#ifdef CONFIG_PAX_SEGMEXEC
82089+ struct vm_area_struct *vma_m = NULL;
82090+#endif
82091+
82092+ if (security_mmap_addr(vma->vm_start))
82093+ return -EPERM;
82094+
82095 /*
82096 * The vm_pgoff of a purely anonymous vma should be irrelevant
82097 * until its first write fault, when page's anon_vma and index
82098@@ -2716,7 +3174,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82099 security_vm_enough_memory_mm(mm, vma_pages(vma)))
82100 return -ENOMEM;
82101
82102+#ifdef CONFIG_PAX_SEGMEXEC
82103+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
82104+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82105+ if (!vma_m)
82106+ return -ENOMEM;
82107+ }
82108+#endif
82109+
82110 vma_link(mm, vma, prev, rb_link, rb_parent);
82111+
82112+#ifdef CONFIG_PAX_SEGMEXEC
82113+ if (vma_m)
82114+ BUG_ON(pax_mirror_vma(vma_m, vma));
82115+#endif
82116+
82117 return 0;
82118 }
82119
82120@@ -2736,6 +3208,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82121 struct mempolicy *pol;
82122 bool faulted_in_anon_vma = true;
82123
82124+ BUG_ON(vma->vm_mirror);
82125+
82126 /*
82127 * If anonymous vma has not yet been faulted, update new pgoff
82128 * to match new location, to increase its chance of merging.
82129@@ -2802,6 +3276,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82130 return NULL;
82131 }
82132
82133+#ifdef CONFIG_PAX_SEGMEXEC
82134+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
82135+{
82136+ struct vm_area_struct *prev_m;
82137+ struct rb_node **rb_link_m, *rb_parent_m;
82138+ struct mempolicy *pol_m;
82139+
82140+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
82141+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
82142+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
82143+ *vma_m = *vma;
82144+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
82145+ if (anon_vma_clone(vma_m, vma))
82146+ return -ENOMEM;
82147+ pol_m = vma_policy(vma_m);
82148+ mpol_get(pol_m);
82149+ vma_set_policy(vma_m, pol_m);
82150+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
82151+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
82152+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
82153+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
82154+ if (vma_m->vm_file)
82155+ get_file(vma_m->vm_file);
82156+ if (vma_m->vm_ops && vma_m->vm_ops->open)
82157+ vma_m->vm_ops->open(vma_m);
82158+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
82159+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
82160+ vma_m->vm_mirror = vma;
82161+ vma->vm_mirror = vma_m;
82162+ return 0;
82163+}
82164+#endif
82165+
82166 /*
82167 * Return true if the calling process may expand its vm space by the passed
82168 * number of pages
82169@@ -2813,6 +3320,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
82170
82171 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
82172
82173+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
82174 if (cur + npages > lim)
82175 return 0;
82176 return 1;
82177@@ -2883,6 +3391,22 @@ int install_special_mapping(struct mm_struct *mm,
82178 vma->vm_start = addr;
82179 vma->vm_end = addr + len;
82180
82181+#ifdef CONFIG_PAX_MPROTECT
82182+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82183+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82184+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
82185+ return -EPERM;
82186+ if (!(vm_flags & VM_EXEC))
82187+ vm_flags &= ~VM_MAYEXEC;
82188+#else
82189+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82190+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82191+#endif
82192+ else
82193+ vm_flags &= ~VM_MAYWRITE;
82194+ }
82195+#endif
82196+
82197 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
82198 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82199
82200diff --git a/mm/mprotect.c b/mm/mprotect.c
82201index 94722a4..9837984 100644
82202--- a/mm/mprotect.c
82203+++ b/mm/mprotect.c
82204@@ -23,10 +23,17 @@
82205 #include <linux/mmu_notifier.h>
82206 #include <linux/migrate.h>
82207 #include <linux/perf_event.h>
82208+
82209+#ifdef CONFIG_PAX_MPROTECT
82210+#include <linux/elf.h>
82211+#include <linux/binfmts.h>
82212+#endif
82213+
82214 #include <asm/uaccess.h>
82215 #include <asm/pgtable.h>
82216 #include <asm/cacheflush.h>
82217 #include <asm/tlbflush.h>
82218+#include <asm/mmu_context.h>
82219
82220 #ifndef pgprot_modify
82221 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
82222@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
82223 return pages;
82224 }
82225
82226+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82227+/* called while holding the mmap semaphor for writing except stack expansion */
82228+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
82229+{
82230+ unsigned long oldlimit, newlimit = 0UL;
82231+
82232+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
82233+ return;
82234+
82235+ spin_lock(&mm->page_table_lock);
82236+ oldlimit = mm->context.user_cs_limit;
82237+ if ((prot & VM_EXEC) && oldlimit < end)
82238+ /* USER_CS limit moved up */
82239+ newlimit = end;
82240+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
82241+ /* USER_CS limit moved down */
82242+ newlimit = start;
82243+
82244+ if (newlimit) {
82245+ mm->context.user_cs_limit = newlimit;
82246+
82247+#ifdef CONFIG_SMP
82248+ wmb();
82249+ cpus_clear(mm->context.cpu_user_cs_mask);
82250+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
82251+#endif
82252+
82253+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
82254+ }
82255+ spin_unlock(&mm->page_table_lock);
82256+ if (newlimit == end) {
82257+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
82258+
82259+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
82260+ if (is_vm_hugetlb_page(vma))
82261+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
82262+ else
82263+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
82264+ }
82265+}
82266+#endif
82267+
82268 int
82269 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82270 unsigned long start, unsigned long end, unsigned long newflags)
82271@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82272 int error;
82273 int dirty_accountable = 0;
82274
82275+#ifdef CONFIG_PAX_SEGMEXEC
82276+ struct vm_area_struct *vma_m = NULL;
82277+ unsigned long start_m, end_m;
82278+
82279+ start_m = start + SEGMEXEC_TASK_SIZE;
82280+ end_m = end + SEGMEXEC_TASK_SIZE;
82281+#endif
82282+
82283 if (newflags == oldflags) {
82284 *pprev = vma;
82285 return 0;
82286 }
82287
82288+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
82289+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
82290+
82291+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
82292+ return -ENOMEM;
82293+
82294+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
82295+ return -ENOMEM;
82296+ }
82297+
82298 /*
82299 * If we make a private mapping writable we increase our commit;
82300 * but (without finer accounting) cannot reduce our commit if we
82301@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82302 }
82303 }
82304
82305+#ifdef CONFIG_PAX_SEGMEXEC
82306+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
82307+ if (start != vma->vm_start) {
82308+ error = split_vma(mm, vma, start, 1);
82309+ if (error)
82310+ goto fail;
82311+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
82312+ *pprev = (*pprev)->vm_next;
82313+ }
82314+
82315+ if (end != vma->vm_end) {
82316+ error = split_vma(mm, vma, end, 0);
82317+ if (error)
82318+ goto fail;
82319+ }
82320+
82321+ if (pax_find_mirror_vma(vma)) {
82322+ error = __do_munmap(mm, start_m, end_m - start_m);
82323+ if (error)
82324+ goto fail;
82325+ } else {
82326+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82327+ if (!vma_m) {
82328+ error = -ENOMEM;
82329+ goto fail;
82330+ }
82331+ vma->vm_flags = newflags;
82332+ error = pax_mirror_vma(vma_m, vma);
82333+ if (error) {
82334+ vma->vm_flags = oldflags;
82335+ goto fail;
82336+ }
82337+ }
82338+ }
82339+#endif
82340+
82341 /*
82342 * First try to merge with previous and/or next vma.
82343 */
82344@@ -296,9 +399,21 @@ success:
82345 * vm_flags and vm_page_prot are protected by the mmap_sem
82346 * held in write mode.
82347 */
82348+
82349+#ifdef CONFIG_PAX_SEGMEXEC
82350+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
82351+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
82352+#endif
82353+
82354 vma->vm_flags = newflags;
82355+
82356+#ifdef CONFIG_PAX_MPROTECT
82357+ if (mm->binfmt && mm->binfmt->handle_mprotect)
82358+ mm->binfmt->handle_mprotect(vma, newflags);
82359+#endif
82360+
82361 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
82362- vm_get_page_prot(newflags));
82363+ vm_get_page_prot(vma->vm_flags));
82364
82365 if (vma_wants_writenotify(vma)) {
82366 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
82367@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82368 end = start + len;
82369 if (end <= start)
82370 return -ENOMEM;
82371+
82372+#ifdef CONFIG_PAX_SEGMEXEC
82373+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
82374+ if (end > SEGMEXEC_TASK_SIZE)
82375+ return -EINVAL;
82376+ } else
82377+#endif
82378+
82379+ if (end > TASK_SIZE)
82380+ return -EINVAL;
82381+
82382 if (!arch_validate_prot(prot))
82383 return -EINVAL;
82384
82385@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82386 /*
82387 * Does the application expect PROT_READ to imply PROT_EXEC:
82388 */
82389- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82390+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82391 prot |= PROT_EXEC;
82392
82393 vm_flags = calc_vm_prot_bits(prot);
82394@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82395 if (start > vma->vm_start)
82396 prev = vma;
82397
82398+#ifdef CONFIG_PAX_MPROTECT
82399+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
82400+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
82401+#endif
82402+
82403 for (nstart = start ; ; ) {
82404 unsigned long newflags;
82405
82406@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82407
82408 /* newflags >> 4 shift VM_MAY% in place of VM_% */
82409 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
82410+ if (prot & (PROT_WRITE | PROT_EXEC))
82411+ gr_log_rwxmprotect(vma->vm_file);
82412+
82413+ error = -EACCES;
82414+ goto out;
82415+ }
82416+
82417+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
82418 error = -EACCES;
82419 goto out;
82420 }
82421@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82422 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
82423 if (error)
82424 goto out;
82425+
82426+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
82427+
82428 nstart = tmp;
82429
82430 if (nstart < prev->vm_end)
82431diff --git a/mm/mremap.c b/mm/mremap.c
82432index e1031e1..1f2a0a1 100644
82433--- a/mm/mremap.c
82434+++ b/mm/mremap.c
82435@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
82436 continue;
82437 pte = ptep_get_and_clear(mm, old_addr, old_pte);
82438 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
82439+
82440+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82441+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
82442+ pte = pte_exprotect(pte);
82443+#endif
82444+
82445 set_pte_at(mm, new_addr, new_pte, pte);
82446 }
82447
82448@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
82449 if (is_vm_hugetlb_page(vma))
82450 goto Einval;
82451
82452+#ifdef CONFIG_PAX_SEGMEXEC
82453+ if (pax_find_mirror_vma(vma))
82454+ goto Einval;
82455+#endif
82456+
82457 /* We can't remap across vm area boundaries */
82458 if (old_len > vma->vm_end - addr)
82459 goto Efault;
82460@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
82461 unsigned long ret = -EINVAL;
82462 unsigned long charged = 0;
82463 unsigned long map_flags;
82464+ unsigned long pax_task_size = TASK_SIZE;
82465
82466 if (new_addr & ~PAGE_MASK)
82467 goto out;
82468
82469- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
82470+#ifdef CONFIG_PAX_SEGMEXEC
82471+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82472+ pax_task_size = SEGMEXEC_TASK_SIZE;
82473+#endif
82474+
82475+ pax_task_size -= PAGE_SIZE;
82476+
82477+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
82478 goto out;
82479
82480 /* Check if the location we're moving into overlaps the
82481 * old location at all, and fail if it does.
82482 */
82483- if ((new_addr <= addr) && (new_addr+new_len) > addr)
82484- goto out;
82485-
82486- if ((addr <= new_addr) && (addr+old_len) > new_addr)
82487+ if (addr + old_len > new_addr && new_addr + new_len > addr)
82488 goto out;
82489
82490 ret = do_munmap(mm, new_addr, new_len);
82491@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82492 struct vm_area_struct *vma;
82493 unsigned long ret = -EINVAL;
82494 unsigned long charged = 0;
82495+ unsigned long pax_task_size = TASK_SIZE;
82496
82497 down_write(&current->mm->mmap_sem);
82498
82499@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82500 if (!new_len)
82501 goto out;
82502
82503+#ifdef CONFIG_PAX_SEGMEXEC
82504+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82505+ pax_task_size = SEGMEXEC_TASK_SIZE;
82506+#endif
82507+
82508+ pax_task_size -= PAGE_SIZE;
82509+
82510+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
82511+ old_len > pax_task_size || addr > pax_task_size-old_len)
82512+ goto out;
82513+
82514 if (flags & MREMAP_FIXED) {
82515 if (flags & MREMAP_MAYMOVE)
82516 ret = mremap_to(addr, old_len, new_addr, new_len);
82517@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82518 addr + new_len);
82519 }
82520 ret = addr;
82521+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
82522 goto out;
82523 }
82524 }
82525@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82526 goto out;
82527 }
82528
82529+ map_flags = vma->vm_flags;
82530 ret = move_vma(vma, addr, old_len, new_len, new_addr);
82531+ if (!(ret & ~PAGE_MASK)) {
82532+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
82533+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
82534+ }
82535 }
82536 out:
82537 if (ret & ~PAGE_MASK)
82538diff --git a/mm/nommu.c b/mm/nommu.c
82539index 79c3cac..4d357e0 100644
82540--- a/mm/nommu.c
82541+++ b/mm/nommu.c
82542@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
82543 int sysctl_overcommit_ratio = 50; /* default is 50% */
82544 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
82545 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
82546-int heap_stack_gap = 0;
82547
82548 atomic_long_t mmap_pages_allocated;
82549
82550@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
82551 EXPORT_SYMBOL(find_vma);
82552
82553 /*
82554- * find a VMA
82555- * - we don't extend stack VMAs under NOMMU conditions
82556- */
82557-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
82558-{
82559- return find_vma(mm, addr);
82560-}
82561-
82562-/*
82563 * expand a stack to a given address
82564 * - not supported under NOMMU conditions
82565 */
82566@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82567
82568 /* most fields are the same, copy all, and then fixup */
82569 *new = *vma;
82570+ INIT_LIST_HEAD(&new->anon_vma_chain);
82571 *region = *vma->vm_region;
82572 new->vm_region = region;
82573
82574diff --git a/mm/page-writeback.c b/mm/page-writeback.c
82575index 0713bfb..b95bb87 100644
82576--- a/mm/page-writeback.c
82577+++ b/mm/page-writeback.c
82578@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
82579 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
82580 * - the bdi dirty thresh drops quickly due to change of JBOD workload
82581 */
82582-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
82583+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
82584 unsigned long thresh,
82585 unsigned long bg_thresh,
82586 unsigned long dirty,
82587@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
82588 }
82589 }
82590
82591-static struct notifier_block __cpuinitdata ratelimit_nb = {
82592+static struct notifier_block ratelimit_nb = {
82593 .notifier_call = ratelimit_handler,
82594 .next = NULL,
82595 };
82596diff --git a/mm/page_alloc.c b/mm/page_alloc.c
82597index 6a83cd3..3ab04ef 100644
82598--- a/mm/page_alloc.c
82599+++ b/mm/page_alloc.c
82600@@ -58,6 +58,7 @@
82601 #include <linux/prefetch.h>
82602 #include <linux/migrate.h>
82603 #include <linux/page-debug-flags.h>
82604+#include <linux/random.h>
82605
82606 #include <asm/tlbflush.h>
82607 #include <asm/div64.h>
82608@@ -338,7 +339,7 @@ out:
82609 * This usage means that zero-order pages may not be compound.
82610 */
82611
82612-static void free_compound_page(struct page *page)
82613+void free_compound_page(struct page *page)
82614 {
82615 __free_pages_ok(page, compound_order(page));
82616 }
82617@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82618 int i;
82619 int bad = 0;
82620
82621+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82622+ unsigned long index = 1UL << order;
82623+#endif
82624+
82625 trace_mm_page_free(page, order);
82626 kmemcheck_free_shadow(page, order);
82627
82628@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82629 debug_check_no_obj_freed(page_address(page),
82630 PAGE_SIZE << order);
82631 }
82632+
82633+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82634+ for (; index; --index)
82635+ sanitize_highpage(page + index - 1);
82636+#endif
82637+
82638 arch_free_page(page, order);
82639 kernel_map_pages(page, 1 << order, 0);
82640
82641@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
82642 local_irq_restore(flags);
82643 }
82644
82645+#ifdef CONFIG_PAX_LATENT_ENTROPY
82646+bool __meminitdata extra_latent_entropy;
82647+
82648+static int __init setup_pax_extra_latent_entropy(char *str)
82649+{
82650+ extra_latent_entropy = true;
82651+ return 0;
82652+}
82653+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
82654+
82655+volatile u64 latent_entropy;
82656+#endif
82657+
82658 /*
82659 * Read access to zone->managed_pages is safe because it's unsigned long,
82660 * but we still need to serialize writers. Currently all callers of
82661@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
82662 set_page_count(p, 0);
82663 }
82664
82665+#ifdef CONFIG_PAX_LATENT_ENTROPY
82666+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
82667+ u64 hash = 0;
82668+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
82669+ const u64 *data = lowmem_page_address(page);
82670+
82671+ for (index = 0; index < end; index++)
82672+ hash ^= hash + data[index];
82673+ latent_entropy ^= hash;
82674+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82675+ }
82676+#endif
82677+
82678 page_zone(page)->managed_pages += 1 << order;
82679 set_page_refcounted(page);
82680 __free_pages(page, order);
82681@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
82682 arch_alloc_page(page, order);
82683 kernel_map_pages(page, 1 << order, 1);
82684
82685+#ifndef CONFIG_PAX_MEMORY_SANITIZE
82686 if (gfp_flags & __GFP_ZERO)
82687 prep_zero_page(page, order, gfp_flags);
82688+#endif
82689
82690 if (order && (gfp_flags & __GFP_COMP))
82691 prep_compound_page(page, order);
82692@@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
82693 unsigned long pfn;
82694
82695 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
82696+#ifdef CONFIG_X86_32
82697+ /* boot failures in VMware 8 on 32bit vanilla since
82698+ this change */
82699+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
82700+#else
82701 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
82702+#endif
82703 return 1;
82704 }
82705 return 0;
82706diff --git a/mm/percpu.c b/mm/percpu.c
82707index 8c8e08f..73a5cda 100644
82708--- a/mm/percpu.c
82709+++ b/mm/percpu.c
82710@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
82711 static unsigned int pcpu_high_unit_cpu __read_mostly;
82712
82713 /* the address of the first chunk which starts with the kernel static area */
82714-void *pcpu_base_addr __read_mostly;
82715+void *pcpu_base_addr __read_only;
82716 EXPORT_SYMBOL_GPL(pcpu_base_addr);
82717
82718 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
82719diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
82720index fd26d04..0cea1b0 100644
82721--- a/mm/process_vm_access.c
82722+++ b/mm/process_vm_access.c
82723@@ -13,6 +13,7 @@
82724 #include <linux/uio.h>
82725 #include <linux/sched.h>
82726 #include <linux/highmem.h>
82727+#include <linux/security.h>
82728 #include <linux/ptrace.h>
82729 #include <linux/slab.h>
82730 #include <linux/syscalls.h>
82731@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82732 size_t iov_l_curr_offset = 0;
82733 ssize_t iov_len;
82734
82735+ return -ENOSYS; // PaX: until properly audited
82736+
82737 /*
82738 * Work out how many pages of struct pages we're going to need
82739 * when eventually calling get_user_pages
82740 */
82741 for (i = 0; i < riovcnt; i++) {
82742 iov_len = rvec[i].iov_len;
82743- if (iov_len > 0) {
82744- nr_pages_iov = ((unsigned long)rvec[i].iov_base
82745- + iov_len)
82746- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
82747- / PAGE_SIZE + 1;
82748- nr_pages = max(nr_pages, nr_pages_iov);
82749- }
82750+ if (iov_len <= 0)
82751+ continue;
82752+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
82753+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
82754+ nr_pages = max(nr_pages, nr_pages_iov);
82755 }
82756
82757 if (nr_pages == 0)
82758@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82759 goto free_proc_pages;
82760 }
82761
82762+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
82763+ rc = -EPERM;
82764+ goto put_task_struct;
82765+ }
82766+
82767 mm = mm_access(task, PTRACE_MODE_ATTACH);
82768 if (!mm || IS_ERR(mm)) {
82769 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
82770diff --git a/mm/rmap.c b/mm/rmap.c
82771index 2c78f8c..9e9c624 100644
82772--- a/mm/rmap.c
82773+++ b/mm/rmap.c
82774@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82775 struct anon_vma *anon_vma = vma->anon_vma;
82776 struct anon_vma_chain *avc;
82777
82778+#ifdef CONFIG_PAX_SEGMEXEC
82779+ struct anon_vma_chain *avc_m = NULL;
82780+#endif
82781+
82782 might_sleep();
82783 if (unlikely(!anon_vma)) {
82784 struct mm_struct *mm = vma->vm_mm;
82785@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82786 if (!avc)
82787 goto out_enomem;
82788
82789+#ifdef CONFIG_PAX_SEGMEXEC
82790+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
82791+ if (!avc_m)
82792+ goto out_enomem_free_avc;
82793+#endif
82794+
82795 anon_vma = find_mergeable_anon_vma(vma);
82796 allocated = NULL;
82797 if (!anon_vma) {
82798@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82799 /* page_table_lock to protect against threads */
82800 spin_lock(&mm->page_table_lock);
82801 if (likely(!vma->anon_vma)) {
82802+
82803+#ifdef CONFIG_PAX_SEGMEXEC
82804+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
82805+
82806+ if (vma_m) {
82807+ BUG_ON(vma_m->anon_vma);
82808+ vma_m->anon_vma = anon_vma;
82809+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
82810+ avc_m = NULL;
82811+ }
82812+#endif
82813+
82814 vma->anon_vma = anon_vma;
82815 anon_vma_chain_link(vma, avc, anon_vma);
82816 allocated = NULL;
82817@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82818
82819 if (unlikely(allocated))
82820 put_anon_vma(allocated);
82821+
82822+#ifdef CONFIG_PAX_SEGMEXEC
82823+ if (unlikely(avc_m))
82824+ anon_vma_chain_free(avc_m);
82825+#endif
82826+
82827 if (unlikely(avc))
82828 anon_vma_chain_free(avc);
82829 }
82830 return 0;
82831
82832 out_enomem_free_avc:
82833+
82834+#ifdef CONFIG_PAX_SEGMEXEC
82835+ if (avc_m)
82836+ anon_vma_chain_free(avc_m);
82837+#endif
82838+
82839 anon_vma_chain_free(avc);
82840 out_enomem:
82841 return -ENOMEM;
82842@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
82843 * Attach the anon_vmas from src to dst.
82844 * Returns 0 on success, -ENOMEM on failure.
82845 */
82846-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82847+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
82848 {
82849 struct anon_vma_chain *avc, *pavc;
82850 struct anon_vma *root = NULL;
82851@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82852 * the corresponding VMA in the parent process is attached to.
82853 * Returns 0 on success, non-zero on failure.
82854 */
82855-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
82856+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
82857 {
82858 struct anon_vma_chain *avc;
82859 struct anon_vma *anon_vma;
82860diff --git a/mm/shmem.c b/mm/shmem.c
82861index efd0b3a..994b702 100644
82862--- a/mm/shmem.c
82863+++ b/mm/shmem.c
82864@@ -31,7 +31,7 @@
82865 #include <linux/export.h>
82866 #include <linux/swap.h>
82867
82868-static struct vfsmount *shm_mnt;
82869+struct vfsmount *shm_mnt;
82870
82871 #ifdef CONFIG_SHMEM
82872 /*
82873@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
82874 #define BOGO_DIRENT_SIZE 20
82875
82876 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
82877-#define SHORT_SYMLINK_LEN 128
82878+#define SHORT_SYMLINK_LEN 64
82879
82880 /*
82881 * shmem_fallocate and shmem_writepage communicate via inode->i_private
82882@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
82883 static int shmem_xattr_validate(const char *name)
82884 {
82885 struct { const char *prefix; size_t len; } arr[] = {
82886+
82887+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82888+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
82889+#endif
82890+
82891 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
82892 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
82893 };
82894@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
82895 if (err)
82896 return err;
82897
82898+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82899+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
82900+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
82901+ return -EOPNOTSUPP;
82902+ if (size > 8)
82903+ return -EINVAL;
82904+ }
82905+#endif
82906+
82907 return simple_xattr_set(&info->xattrs, name, value, size, flags);
82908 }
82909
82910@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
82911 int err = -ENOMEM;
82912
82913 /* Round up to L1_CACHE_BYTES to resist false sharing */
82914- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
82915- L1_CACHE_BYTES), GFP_KERNEL);
82916+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
82917 if (!sbinfo)
82918 return -ENOMEM;
82919
82920diff --git a/mm/slab.c b/mm/slab.c
82921index e7667a3..b62c169 100644
82922--- a/mm/slab.c
82923+++ b/mm/slab.c
82924@@ -306,7 +306,7 @@ struct kmem_list3 {
82925 * Need this for bootstrapping a per node allocator.
82926 */
82927 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
82928-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
82929+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
82930 #define CACHE_CACHE 0
82931 #define SIZE_AC MAX_NUMNODES
82932 #define SIZE_L3 (2 * MAX_NUMNODES)
82933@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
82934 if ((x)->max_freeable < i) \
82935 (x)->max_freeable = i; \
82936 } while (0)
82937-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
82938-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
82939-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
82940-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
82941+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
82942+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
82943+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
82944+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
82945 #else
82946 #define STATS_INC_ACTIVE(x) do { } while (0)
82947 #define STATS_DEC_ACTIVE(x) do { } while (0)
82948@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
82949 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
82950 */
82951 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
82952- const struct slab *slab, void *obj)
82953+ const struct slab *slab, const void *obj)
82954 {
82955 u32 offset = (obj - slab->s_mem);
82956 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
82957@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
82958 struct cache_names {
82959 char *name;
82960 char *name_dma;
82961+ char *name_usercopy;
82962 };
82963
82964 static struct cache_names __initdata cache_names[] = {
82965-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
82966+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
82967 #include <linux/kmalloc_sizes.h>
82968- {NULL,}
82969+ {NULL}
82970 #undef CACHE
82971 };
82972
82973@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
82974 if (unlikely(gfpflags & GFP_DMA))
82975 return csizep->cs_dmacachep;
82976 #endif
82977+
82978+#ifdef CONFIG_PAX_USERCOPY_SLABS
82979+ if (unlikely(gfpflags & GFP_USERCOPY))
82980+ return csizep->cs_usercopycachep;
82981+#endif
82982+
82983 return csizep->cs_cachep;
82984 }
82985
82986@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
82987 return notifier_from_errno(err);
82988 }
82989
82990-static struct notifier_block __cpuinitdata cpucache_notifier = {
82991+static struct notifier_block cpucache_notifier = {
82992 &cpuup_callback, NULL, 0
82993 };
82994
82995@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
82996 */
82997
82998 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
82999- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
83000+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83001
83002 if (INDEX_AC != INDEX_L3)
83003 sizes[INDEX_L3].cs_cachep =
83004 create_kmalloc_cache(names[INDEX_L3].name,
83005- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
83006+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83007
83008 slab_early_init = 0;
83009
83010@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
83011 */
83012 if (!sizes->cs_cachep)
83013 sizes->cs_cachep = create_kmalloc_cache(names->name,
83014- sizes->cs_size, ARCH_KMALLOC_FLAGS);
83015+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83016
83017 #ifdef CONFIG_ZONE_DMA
83018 sizes->cs_dmacachep = create_kmalloc_cache(
83019 names->name_dma, sizes->cs_size,
83020 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
83021 #endif
83022+
83023+#ifdef CONFIG_PAX_USERCOPY_SLABS
83024+ sizes->cs_usercopycachep = create_kmalloc_cache(
83025+ names->name_usercopy, sizes->cs_size,
83026+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83027+#endif
83028+
83029 sizes++;
83030 names++;
83031 }
83032@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
83033 }
83034 /* cpu stats */
83035 {
83036- unsigned long allochit = atomic_read(&cachep->allochit);
83037- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
83038- unsigned long freehit = atomic_read(&cachep->freehit);
83039- unsigned long freemiss = atomic_read(&cachep->freemiss);
83040+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
83041+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
83042+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
83043+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
83044
83045 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
83046 allochit, allocmiss, freehit, freemiss);
83047@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
83048 static int __init slab_proc_init(void)
83049 {
83050 #ifdef CONFIG_DEBUG_SLAB_LEAK
83051- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
83052+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
83053 #endif
83054 return 0;
83055 }
83056 module_init(slab_proc_init);
83057 #endif
83058
83059+bool is_usercopy_object(const void *ptr)
83060+{
83061+ struct page *page;
83062+ struct kmem_cache *cachep;
83063+
83064+ if (ZERO_OR_NULL_PTR(ptr))
83065+ return false;
83066+
83067+ if (!slab_is_available())
83068+ return false;
83069+
83070+ if (!virt_addr_valid(ptr))
83071+ return false;
83072+
83073+ page = virt_to_head_page(ptr);
83074+
83075+ if (!PageSlab(page))
83076+ return false;
83077+
83078+ cachep = page->slab_cache;
83079+ return cachep->flags & SLAB_USERCOPY;
83080+}
83081+
83082+#ifdef CONFIG_PAX_USERCOPY
83083+const char *check_heap_object(const void *ptr, unsigned long n)
83084+{
83085+ struct page *page;
83086+ struct kmem_cache *cachep;
83087+ struct slab *slabp;
83088+ unsigned int objnr;
83089+ unsigned long offset;
83090+
83091+ if (ZERO_OR_NULL_PTR(ptr))
83092+ return "<null>";
83093+
83094+ if (!virt_addr_valid(ptr))
83095+ return NULL;
83096+
83097+ page = virt_to_head_page(ptr);
83098+
83099+ if (!PageSlab(page))
83100+ return NULL;
83101+
83102+ cachep = page->slab_cache;
83103+ if (!(cachep->flags & SLAB_USERCOPY))
83104+ return cachep->name;
83105+
83106+ slabp = page->slab_page;
83107+ objnr = obj_to_index(cachep, slabp, ptr);
83108+ BUG_ON(objnr >= cachep->num);
83109+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
83110+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
83111+ return NULL;
83112+
83113+ return cachep->name;
83114+}
83115+#endif
83116+
83117 /**
83118 * ksize - get the actual amount of memory allocated for a given object
83119 * @objp: Pointer to the object
83120diff --git a/mm/slab.h b/mm/slab.h
83121index 34a98d6..73633d1 100644
83122--- a/mm/slab.h
83123+++ b/mm/slab.h
83124@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83125
83126 /* Legal flag mask for kmem_cache_create(), for various configurations */
83127 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
83128- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
83129+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
83130
83131 #if defined(CONFIG_DEBUG_SLAB)
83132 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
83133@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
83134 return s;
83135
83136 page = virt_to_head_page(x);
83137+
83138+ BUG_ON(!PageSlab(page));
83139+
83140 cachep = page->slab_cache;
83141 if (slab_equal_or_root(cachep, s))
83142 return cachep;
83143diff --git a/mm/slab_common.c b/mm/slab_common.c
83144index 3f3cd97..93b0236 100644
83145--- a/mm/slab_common.c
83146+++ b/mm/slab_common.c
83147@@ -22,7 +22,7 @@
83148
83149 #include "slab.h"
83150
83151-enum slab_state slab_state;
83152+enum slab_state slab_state __read_only;
83153 LIST_HEAD(slab_caches);
83154 DEFINE_MUTEX(slab_mutex);
83155 struct kmem_cache *kmem_cache;
83156@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
83157
83158 err = __kmem_cache_create(s, flags);
83159 if (!err) {
83160- s->refcount = 1;
83161+ atomic_set(&s->refcount, 1);
83162 list_add(&s->list, &slab_caches);
83163 memcg_cache_list_add(memcg, s);
83164 } else {
83165@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
83166
83167 get_online_cpus();
83168 mutex_lock(&slab_mutex);
83169- s->refcount--;
83170- if (!s->refcount) {
83171+ if (atomic_dec_and_test(&s->refcount)) {
83172 list_del(&s->list);
83173
83174 if (!__kmem_cache_shutdown(s)) {
83175@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
83176 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
83177 name, size, err);
83178
83179- s->refcount = -1; /* Exempt from merging for now */
83180+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
83181 }
83182
83183 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83184@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83185
83186 create_boot_cache(s, name, size, flags);
83187 list_add(&s->list, &slab_caches);
83188- s->refcount = 1;
83189+ atomic_set(&s->refcount, 1);
83190 return s;
83191 }
83192
83193diff --git a/mm/slob.c b/mm/slob.c
83194index a99fdf7..f5b6577 100644
83195--- a/mm/slob.c
83196+++ b/mm/slob.c
83197@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
83198 /*
83199 * Return the size of a slob block.
83200 */
83201-static slobidx_t slob_units(slob_t *s)
83202+static slobidx_t slob_units(const slob_t *s)
83203 {
83204 if (s->units > 0)
83205 return s->units;
83206@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
83207 /*
83208 * Return the next free slob block pointer after this one.
83209 */
83210-static slob_t *slob_next(slob_t *s)
83211+static slob_t *slob_next(const slob_t *s)
83212 {
83213 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
83214 slobidx_t next;
83215@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
83216 /*
83217 * Returns true if s is the last free block in its page.
83218 */
83219-static int slob_last(slob_t *s)
83220+static int slob_last(const slob_t *s)
83221 {
83222 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
83223 }
83224
83225-static void *slob_new_pages(gfp_t gfp, int order, int node)
83226+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
83227 {
83228- void *page;
83229+ struct page *page;
83230
83231 #ifdef CONFIG_NUMA
83232 if (node != NUMA_NO_NODE)
83233@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
83234 if (!page)
83235 return NULL;
83236
83237- return page_address(page);
83238+ __SetPageSlab(page);
83239+ return page;
83240 }
83241
83242-static void slob_free_pages(void *b, int order)
83243+static void slob_free_pages(struct page *sp, int order)
83244 {
83245 if (current->reclaim_state)
83246 current->reclaim_state->reclaimed_slab += 1 << order;
83247- free_pages((unsigned long)b, order);
83248+ __ClearPageSlab(sp);
83249+ reset_page_mapcount(sp);
83250+ sp->private = 0;
83251+ __free_pages(sp, order);
83252 }
83253
83254 /*
83255@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
83256
83257 /* Not enough space: must allocate a new page */
83258 if (!b) {
83259- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83260- if (!b)
83261+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83262+ if (!sp)
83263 return NULL;
83264- sp = virt_to_page(b);
83265- __SetPageSlab(sp);
83266+ b = page_address(sp);
83267
83268 spin_lock_irqsave(&slob_lock, flags);
83269 sp->units = SLOB_UNITS(PAGE_SIZE);
83270 sp->freelist = b;
83271+ sp->private = 0;
83272 INIT_LIST_HEAD(&sp->list);
83273 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
83274 set_slob_page_free(sp, slob_list);
83275@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
83276 if (slob_page_free(sp))
83277 clear_slob_page_free(sp);
83278 spin_unlock_irqrestore(&slob_lock, flags);
83279- __ClearPageSlab(sp);
83280- reset_page_mapcount(sp);
83281- slob_free_pages(b, 0);
83282+ slob_free_pages(sp, 0);
83283 return;
83284 }
83285
83286@@ -424,11 +426,10 @@ out:
83287 */
83288
83289 static __always_inline void *
83290-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83291+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
83292 {
83293- unsigned int *m;
83294- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83295- void *ret;
83296+ slob_t *m;
83297+ void *ret = NULL;
83298
83299 gfp &= gfp_allowed_mask;
83300
83301@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83302
83303 if (!m)
83304 return NULL;
83305- *m = size;
83306+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
83307+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
83308+ m[0].units = size;
83309+ m[1].units = align;
83310 ret = (void *)m + align;
83311
83312 trace_kmalloc_node(caller, ret,
83313 size, size + align, gfp, node);
83314 } else {
83315 unsigned int order = get_order(size);
83316+ struct page *page;
83317
83318 if (likely(order))
83319 gfp |= __GFP_COMP;
83320- ret = slob_new_pages(gfp, order, node);
83321+ page = slob_new_pages(gfp, order, node);
83322+ if (page) {
83323+ ret = page_address(page);
83324+ page->private = size;
83325+ }
83326
83327 trace_kmalloc_node(caller, ret,
83328 size, PAGE_SIZE << order, gfp, node);
83329 }
83330
83331- kmemleak_alloc(ret, size, 1, gfp);
83332+ return ret;
83333+}
83334+
83335+static __always_inline void *
83336+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83337+{
83338+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83339+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
83340+
83341+ if (!ZERO_OR_NULL_PTR(ret))
83342+ kmemleak_alloc(ret, size, 1, gfp);
83343 return ret;
83344 }
83345
83346@@ -494,33 +513,110 @@ void kfree(const void *block)
83347 kmemleak_free(block);
83348
83349 sp = virt_to_page(block);
83350- if (PageSlab(sp)) {
83351+ VM_BUG_ON(!PageSlab(sp));
83352+ if (!sp->private) {
83353 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83354- unsigned int *m = (unsigned int *)(block - align);
83355- slob_free(m, *m + align);
83356- } else
83357+ slob_t *m = (slob_t *)(block - align);
83358+ slob_free(m, m[0].units + align);
83359+ } else {
83360+ __ClearPageSlab(sp);
83361+ reset_page_mapcount(sp);
83362+ sp->private = 0;
83363 __free_pages(sp, compound_order(sp));
83364+ }
83365 }
83366 EXPORT_SYMBOL(kfree);
83367
83368+bool is_usercopy_object(const void *ptr)
83369+{
83370+ if (!slab_is_available())
83371+ return false;
83372+
83373+ // PAX: TODO
83374+
83375+ return false;
83376+}
83377+
83378+#ifdef CONFIG_PAX_USERCOPY
83379+const char *check_heap_object(const void *ptr, unsigned long n)
83380+{
83381+ struct page *page;
83382+ const slob_t *free;
83383+ const void *base;
83384+ unsigned long flags;
83385+
83386+ if (ZERO_OR_NULL_PTR(ptr))
83387+ return "<null>";
83388+
83389+ if (!virt_addr_valid(ptr))
83390+ return NULL;
83391+
83392+ page = virt_to_head_page(ptr);
83393+ if (!PageSlab(page))
83394+ return NULL;
83395+
83396+ if (page->private) {
83397+ base = page;
83398+ if (base <= ptr && n <= page->private - (ptr - base))
83399+ return NULL;
83400+ return "<slob>";
83401+ }
83402+
83403+ /* some tricky double walking to find the chunk */
83404+ spin_lock_irqsave(&slob_lock, flags);
83405+ base = (void *)((unsigned long)ptr & PAGE_MASK);
83406+ free = page->freelist;
83407+
83408+ while (!slob_last(free) && (void *)free <= ptr) {
83409+ base = free + slob_units(free);
83410+ free = slob_next(free);
83411+ }
83412+
83413+ while (base < (void *)free) {
83414+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
83415+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
83416+ int offset;
83417+
83418+ if (ptr < base + align)
83419+ break;
83420+
83421+ offset = ptr - base - align;
83422+ if (offset >= m) {
83423+ base += size;
83424+ continue;
83425+ }
83426+
83427+ if (n > m - offset)
83428+ break;
83429+
83430+ spin_unlock_irqrestore(&slob_lock, flags);
83431+ return NULL;
83432+ }
83433+
83434+ spin_unlock_irqrestore(&slob_lock, flags);
83435+ return "<slob>";
83436+}
83437+#endif
83438+
83439 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
83440 size_t ksize(const void *block)
83441 {
83442 struct page *sp;
83443 int align;
83444- unsigned int *m;
83445+ slob_t *m;
83446
83447 BUG_ON(!block);
83448 if (unlikely(block == ZERO_SIZE_PTR))
83449 return 0;
83450
83451 sp = virt_to_page(block);
83452- if (unlikely(!PageSlab(sp)))
83453- return PAGE_SIZE << compound_order(sp);
83454+ VM_BUG_ON(!PageSlab(sp));
83455+ if (sp->private)
83456+ return sp->private;
83457
83458 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83459- m = (unsigned int *)(block - align);
83460- return SLOB_UNITS(*m) * SLOB_UNIT;
83461+ m = (slob_t *)(block - align);
83462+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
83463 }
83464 EXPORT_SYMBOL(ksize);
83465
83466@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
83467
83468 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
83469 {
83470- void *b;
83471+ void *b = NULL;
83472
83473 flags &= gfp_allowed_mask;
83474
83475 lockdep_trace_alloc(flags);
83476
83477+#ifdef CONFIG_PAX_USERCOPY_SLABS
83478+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
83479+#else
83480 if (c->size < PAGE_SIZE) {
83481 b = slob_alloc(c->size, flags, c->align, node);
83482 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83483 SLOB_UNITS(c->size) * SLOB_UNIT,
83484 flags, node);
83485 } else {
83486- b = slob_new_pages(flags, get_order(c->size), node);
83487+ struct page *sp;
83488+
83489+ sp = slob_new_pages(flags, get_order(c->size), node);
83490+ if (sp) {
83491+ b = page_address(sp);
83492+ sp->private = c->size;
83493+ }
83494 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83495 PAGE_SIZE << get_order(c->size),
83496 flags, node);
83497 }
83498+#endif
83499
83500 if (c->ctor)
83501 c->ctor(b);
83502@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
83503
83504 static void __kmem_cache_free(void *b, int size)
83505 {
83506- if (size < PAGE_SIZE)
83507+ struct page *sp;
83508+
83509+ sp = virt_to_page(b);
83510+ BUG_ON(!PageSlab(sp));
83511+ if (!sp->private)
83512 slob_free(b, size);
83513 else
83514- slob_free_pages(b, get_order(size));
83515+ slob_free_pages(sp, get_order(size));
83516 }
83517
83518 static void kmem_rcu_free(struct rcu_head *head)
83519@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
83520
83521 void kmem_cache_free(struct kmem_cache *c, void *b)
83522 {
83523+ int size = c->size;
83524+
83525+#ifdef CONFIG_PAX_USERCOPY_SLABS
83526+ if (size + c->align < PAGE_SIZE) {
83527+ size += c->align;
83528+ b -= c->align;
83529+ }
83530+#endif
83531+
83532 kmemleak_free_recursive(b, c->flags);
83533 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
83534 struct slob_rcu *slob_rcu;
83535- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
83536- slob_rcu->size = c->size;
83537+ slob_rcu = b + (size - sizeof(struct slob_rcu));
83538+ slob_rcu->size = size;
83539 call_rcu(&slob_rcu->head, kmem_rcu_free);
83540 } else {
83541- __kmem_cache_free(b, c->size);
83542+ __kmem_cache_free(b, size);
83543 }
83544
83545+#ifdef CONFIG_PAX_USERCOPY_SLABS
83546+ trace_kfree(_RET_IP_, b);
83547+#else
83548 trace_kmem_cache_free(_RET_IP_, b);
83549+#endif
83550+
83551 }
83552 EXPORT_SYMBOL(kmem_cache_free);
83553
83554diff --git a/mm/slub.c b/mm/slub.c
83555index ba2ca53..00b1f4e 100644
83556--- a/mm/slub.c
83557+++ b/mm/slub.c
83558@@ -197,7 +197,7 @@ struct track {
83559
83560 enum track_item { TRACK_ALLOC, TRACK_FREE };
83561
83562-#ifdef CONFIG_SYSFS
83563+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83564 static int sysfs_slab_add(struct kmem_cache *);
83565 static int sysfs_slab_alias(struct kmem_cache *, const char *);
83566 static void sysfs_slab_remove(struct kmem_cache *);
83567@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
83568 if (!t->addr)
83569 return;
83570
83571- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
83572+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
83573 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
83574 #ifdef CONFIG_STACKTRACE
83575 {
83576@@ -2653,7 +2653,7 @@ static int slub_min_objects;
83577 * Merge control. If this is set then no merging of slab caches will occur.
83578 * (Could be removed. This was introduced to pacify the merge skeptics.)
83579 */
83580-static int slub_nomerge;
83581+static int slub_nomerge = 1;
83582
83583 /*
83584 * Calculate the order of allocation given an slab object size.
83585@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
83586 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
83587 #endif
83588
83589+#ifdef CONFIG_PAX_USERCOPY_SLABS
83590+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
83591+#endif
83592+
83593 static int __init setup_slub_min_order(char *str)
83594 {
83595 get_option(&str, &slub_min_order);
83596@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
83597 return kmalloc_dma_caches[index];
83598
83599 #endif
83600+
83601+#ifdef CONFIG_PAX_USERCOPY_SLABS
83602+ if (flags & SLAB_USERCOPY)
83603+ return kmalloc_usercopy_caches[index];
83604+
83605+#endif
83606+
83607 return kmalloc_caches[index];
83608 }
83609
83610@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
83611 EXPORT_SYMBOL(__kmalloc_node);
83612 #endif
83613
83614+bool is_usercopy_object(const void *ptr)
83615+{
83616+ struct page *page;
83617+ struct kmem_cache *s;
83618+
83619+ if (ZERO_OR_NULL_PTR(ptr))
83620+ return false;
83621+
83622+ if (!slab_is_available())
83623+ return false;
83624+
83625+ if (!virt_addr_valid(ptr))
83626+ return false;
83627+
83628+ page = virt_to_head_page(ptr);
83629+
83630+ if (!PageSlab(page))
83631+ return false;
83632+
83633+ s = page->slab_cache;
83634+ return s->flags & SLAB_USERCOPY;
83635+}
83636+
83637+#ifdef CONFIG_PAX_USERCOPY
83638+const char *check_heap_object(const void *ptr, unsigned long n)
83639+{
83640+ struct page *page;
83641+ struct kmem_cache *s;
83642+ unsigned long offset;
83643+
83644+ if (ZERO_OR_NULL_PTR(ptr))
83645+ return "<null>";
83646+
83647+ if (!virt_addr_valid(ptr))
83648+ return NULL;
83649+
83650+ page = virt_to_head_page(ptr);
83651+
83652+ if (!PageSlab(page))
83653+ return NULL;
83654+
83655+ s = page->slab_cache;
83656+ if (!(s->flags & SLAB_USERCOPY))
83657+ return s->name;
83658+
83659+ offset = (ptr - page_address(page)) % s->size;
83660+ if (offset <= s->object_size && n <= s->object_size - offset)
83661+ return NULL;
83662+
83663+ return s->name;
83664+}
83665+#endif
83666+
83667 size_t ksize(const void *object)
83668 {
83669 struct page *page;
83670@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
83671
83672 /* Caches that are not of the two-to-the-power-of size */
83673 if (KMALLOC_MIN_SIZE <= 32) {
83674- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
83675+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
83676 caches++;
83677 }
83678
83679 if (KMALLOC_MIN_SIZE <= 64) {
83680- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
83681+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
83682 caches++;
83683 }
83684
83685 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
83686- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
83687+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
83688 caches++;
83689 }
83690
83691@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
83692 }
83693 }
83694 #endif
83695+
83696+#ifdef CONFIG_PAX_USERCOPY_SLABS
83697+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
83698+ struct kmem_cache *s = kmalloc_caches[i];
83699+
83700+ if (s && s->size) {
83701+ char *name = kasprintf(GFP_NOWAIT,
83702+ "usercopy-kmalloc-%d", s->object_size);
83703+
83704+ BUG_ON(!name);
83705+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
83706+ s->object_size, SLAB_USERCOPY);
83707+ }
83708+ }
83709+#endif
83710+
83711 printk(KERN_INFO
83712 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
83713 " CPUs=%d, Nodes=%d\n",
83714@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
83715 /*
83716 * We may have set a slab to be unmergeable during bootstrap.
83717 */
83718- if (s->refcount < 0)
83719+ if (atomic_read(&s->refcount) < 0)
83720 return 1;
83721
83722 return 0;
83723@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83724
83725 s = find_mergeable(memcg, size, align, flags, name, ctor);
83726 if (s) {
83727- s->refcount++;
83728+ atomic_inc(&s->refcount);
83729 /*
83730 * Adjust the object sizes so that we clear
83731 * the complete object on kzalloc.
83732@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83733 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
83734
83735 if (sysfs_slab_alias(s, name)) {
83736- s->refcount--;
83737+ atomic_dec(&s->refcount);
83738 s = NULL;
83739 }
83740 }
83741@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
83742 return NOTIFY_OK;
83743 }
83744
83745-static struct notifier_block __cpuinitdata slab_notifier = {
83746+static struct notifier_block slab_notifier = {
83747 .notifier_call = slab_cpuup_callback
83748 };
83749
83750@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
83751 }
83752 #endif
83753
83754-#ifdef CONFIG_SYSFS
83755+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83756 static int count_inuse(struct page *page)
83757 {
83758 return page->inuse;
83759@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
83760 validate_slab_cache(kmalloc_caches[9]);
83761 }
83762 #else
83763-#ifdef CONFIG_SYSFS
83764+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83765 static void resiliency_test(void) {};
83766 #endif
83767 #endif
83768
83769-#ifdef CONFIG_SYSFS
83770+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83771 enum slab_stat_type {
83772 SL_ALL, /* All slabs */
83773 SL_PARTIAL, /* Only partially allocated slabs */
83774@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
83775
83776 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
83777 {
83778- return sprintf(buf, "%d\n", s->refcount - 1);
83779+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
83780 }
83781 SLAB_ATTR_RO(aliases);
83782
83783@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
83784 return name;
83785 }
83786
83787+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83788 static int sysfs_slab_add(struct kmem_cache *s)
83789 {
83790 int err;
83791@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
83792 kobject_del(&s->kobj);
83793 kobject_put(&s->kobj);
83794 }
83795+#endif
83796
83797 /*
83798 * Need to buffer aliases during bootup until sysfs becomes
83799@@ -5336,6 +5418,7 @@ struct saved_alias {
83800
83801 static struct saved_alias *alias_list;
83802
83803+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83804 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83805 {
83806 struct saved_alias *al;
83807@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83808 alias_list = al;
83809 return 0;
83810 }
83811+#endif
83812
83813 static int __init slab_sysfs_init(void)
83814 {
83815diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
83816index 1b7e22a..3fcd4f3 100644
83817--- a/mm/sparse-vmemmap.c
83818+++ b/mm/sparse-vmemmap.c
83819@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
83820 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83821 if (!p)
83822 return NULL;
83823- pud_populate(&init_mm, pud, p);
83824+ pud_populate_kernel(&init_mm, pud, p);
83825 }
83826 return pud;
83827 }
83828@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
83829 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83830 if (!p)
83831 return NULL;
83832- pgd_populate(&init_mm, pgd, p);
83833+ pgd_populate_kernel(&init_mm, pgd, p);
83834 }
83835 return pgd;
83836 }
83837diff --git a/mm/sparse.c b/mm/sparse.c
83838index 6b5fb76..db0c190 100644
83839--- a/mm/sparse.c
83840+++ b/mm/sparse.c
83841@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
83842
83843 for (i = 0; i < PAGES_PER_SECTION; i++) {
83844 if (PageHWPoison(&memmap[i])) {
83845- atomic_long_sub(1, &mce_bad_pages);
83846+ atomic_long_sub_unchecked(1, &mce_bad_pages);
83847 ClearPageHWPoison(&memmap[i]);
83848 }
83849 }
83850diff --git a/mm/swap.c b/mm/swap.c
83851index 6310dc2..3662b3f 100644
83852--- a/mm/swap.c
83853+++ b/mm/swap.c
83854@@ -30,6 +30,7 @@
83855 #include <linux/backing-dev.h>
83856 #include <linux/memcontrol.h>
83857 #include <linux/gfp.h>
83858+#include <linux/hugetlb.h>
83859
83860 #include "internal.h"
83861
83862@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
83863
83864 __page_cache_release(page);
83865 dtor = get_compound_page_dtor(page);
83866+ if (!PageHuge(page))
83867+ BUG_ON(dtor != free_compound_page);
83868 (*dtor)(page);
83869 }
83870
83871diff --git a/mm/swapfile.c b/mm/swapfile.c
83872index e97a0e5..b50e796 100644
83873--- a/mm/swapfile.c
83874+++ b/mm/swapfile.c
83875@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
83876
83877 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
83878 /* Activity counter to indicate that a swapon or swapoff has occurred */
83879-static atomic_t proc_poll_event = ATOMIC_INIT(0);
83880+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
83881
83882 static inline unsigned char swap_count(unsigned char ent)
83883 {
83884@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
83885 }
83886 filp_close(swap_file, NULL);
83887 err = 0;
83888- atomic_inc(&proc_poll_event);
83889+ atomic_inc_unchecked(&proc_poll_event);
83890 wake_up_interruptible(&proc_poll_wait);
83891
83892 out_dput:
83893@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
83894
83895 poll_wait(file, &proc_poll_wait, wait);
83896
83897- if (seq->poll_event != atomic_read(&proc_poll_event)) {
83898- seq->poll_event = atomic_read(&proc_poll_event);
83899+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
83900+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83901 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
83902 }
83903
83904@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
83905 return ret;
83906
83907 seq = file->private_data;
83908- seq->poll_event = atomic_read(&proc_poll_event);
83909+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83910 return 0;
83911 }
83912
83913@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
83914 (frontswap_map) ? "FS" : "");
83915
83916 mutex_unlock(&swapon_mutex);
83917- atomic_inc(&proc_poll_event);
83918+ atomic_inc_unchecked(&proc_poll_event);
83919 wake_up_interruptible(&proc_poll_wait);
83920
83921 if (S_ISREG(inode->i_mode))
83922diff --git a/mm/util.c b/mm/util.c
83923index c55e26b..3f913a9 100644
83924--- a/mm/util.c
83925+++ b/mm/util.c
83926@@ -292,6 +292,12 @@ done:
83927 void arch_pick_mmap_layout(struct mm_struct *mm)
83928 {
83929 mm->mmap_base = TASK_UNMAPPED_BASE;
83930+
83931+#ifdef CONFIG_PAX_RANDMMAP
83932+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83933+ mm->mmap_base += mm->delta_mmap;
83934+#endif
83935+
83936 mm->get_unmapped_area = arch_get_unmapped_area;
83937 mm->unmap_area = arch_unmap_area;
83938 }
83939diff --git a/mm/vmalloc.c b/mm/vmalloc.c
83940index 5123a16..f234a48 100644
83941--- a/mm/vmalloc.c
83942+++ b/mm/vmalloc.c
83943@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
83944
83945 pte = pte_offset_kernel(pmd, addr);
83946 do {
83947- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83948- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83949+
83950+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83951+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
83952+ BUG_ON(!pte_exec(*pte));
83953+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
83954+ continue;
83955+ }
83956+#endif
83957+
83958+ {
83959+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83960+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83961+ }
83962 } while (pte++, addr += PAGE_SIZE, addr != end);
83963 }
83964
83965@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
83966 pte = pte_alloc_kernel(pmd, addr);
83967 if (!pte)
83968 return -ENOMEM;
83969+
83970+ pax_open_kernel();
83971 do {
83972 struct page *page = pages[*nr];
83973
83974- if (WARN_ON(!pte_none(*pte)))
83975+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83976+ if (pgprot_val(prot) & _PAGE_NX)
83977+#endif
83978+
83979+ if (!pte_none(*pte)) {
83980+ pax_close_kernel();
83981+ WARN_ON(1);
83982 return -EBUSY;
83983- if (WARN_ON(!page))
83984+ }
83985+ if (!page) {
83986+ pax_close_kernel();
83987+ WARN_ON(1);
83988 return -ENOMEM;
83989+ }
83990 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
83991 (*nr)++;
83992 } while (pte++, addr += PAGE_SIZE, addr != end);
83993+ pax_close_kernel();
83994 return 0;
83995 }
83996
83997@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
83998 pmd_t *pmd;
83999 unsigned long next;
84000
84001- pmd = pmd_alloc(&init_mm, pud, addr);
84002+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
84003 if (!pmd)
84004 return -ENOMEM;
84005 do {
84006@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
84007 pud_t *pud;
84008 unsigned long next;
84009
84010- pud = pud_alloc(&init_mm, pgd, addr);
84011+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
84012 if (!pud)
84013 return -ENOMEM;
84014 do {
84015@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
84016 * and fall back on vmalloc() if that fails. Others
84017 * just put it in the vmalloc space.
84018 */
84019-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
84020+#ifdef CONFIG_MODULES
84021+#ifdef MODULES_VADDR
84022 unsigned long addr = (unsigned long)x;
84023 if (addr >= MODULES_VADDR && addr < MODULES_END)
84024 return 1;
84025 #endif
84026+
84027+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84028+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
84029+ return 1;
84030+#endif
84031+
84032+#endif
84033+
84034 return is_vmalloc_addr(x);
84035 }
84036
84037@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
84038
84039 if (!pgd_none(*pgd)) {
84040 pud_t *pud = pud_offset(pgd, addr);
84041+#ifdef CONFIG_X86
84042+ if (!pud_large(*pud))
84043+#endif
84044 if (!pud_none(*pud)) {
84045 pmd_t *pmd = pmd_offset(pud, addr);
84046+#ifdef CONFIG_X86
84047+ if (!pmd_large(*pmd))
84048+#endif
84049 if (!pmd_none(*pmd)) {
84050 pte_t *ptep, pte;
84051
84052@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
84053 * Allocate a region of KVA of the specified size and alignment, within the
84054 * vstart and vend.
84055 */
84056-static struct vmap_area *alloc_vmap_area(unsigned long size,
84057+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
84058 unsigned long align,
84059 unsigned long vstart, unsigned long vend,
84060 int node, gfp_t gfp_mask)
84061@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
84062 struct vm_struct *area;
84063
84064 BUG_ON(in_interrupt());
84065+
84066+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84067+ if (flags & VM_KERNEXEC) {
84068+ if (start != VMALLOC_START || end != VMALLOC_END)
84069+ return NULL;
84070+ start = (unsigned long)MODULES_EXEC_VADDR;
84071+ end = (unsigned long)MODULES_EXEC_END;
84072+ }
84073+#endif
84074+
84075 if (flags & VM_IOREMAP) {
84076 int bit = fls(size);
84077
84078@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
84079 if (count > totalram_pages)
84080 return NULL;
84081
84082+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84083+ if (!(pgprot_val(prot) & _PAGE_NX))
84084+ flags |= VM_KERNEXEC;
84085+#endif
84086+
84087 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
84088 __builtin_return_address(0));
84089 if (!area)
84090@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
84091 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
84092 goto fail;
84093
84094+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84095+ if (!(pgprot_val(prot) & _PAGE_NX))
84096+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
84097+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
84098+ else
84099+#endif
84100+
84101 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
84102 start, end, node, gfp_mask, caller);
84103 if (!area)
84104@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
84105 * For tight control over page level allocator and protection flags
84106 * use __vmalloc() instead.
84107 */
84108-
84109 void *vmalloc_exec(unsigned long size)
84110 {
84111- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
84112+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
84113 -1, __builtin_return_address(0));
84114 }
84115
84116@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
84117 unsigned long uaddr = vma->vm_start;
84118 unsigned long usize = vma->vm_end - vma->vm_start;
84119
84120+ BUG_ON(vma->vm_mirror);
84121+
84122 if ((PAGE_SIZE-1) & (unsigned long)addr)
84123 return -EINVAL;
84124
84125@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
84126 v->addr, v->addr + v->size, v->size);
84127
84128 if (v->caller)
84129+#ifdef CONFIG_GRKERNSEC_HIDESYM
84130+ seq_printf(m, " %pK", v->caller);
84131+#else
84132 seq_printf(m, " %pS", v->caller);
84133+#endif
84134
84135 if (v->nr_pages)
84136 seq_printf(m, " pages=%d", v->nr_pages);
84137diff --git a/mm/vmstat.c b/mm/vmstat.c
84138index 9800306..76b4b27 100644
84139--- a/mm/vmstat.c
84140+++ b/mm/vmstat.c
84141@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
84142 *
84143 * vm_stat contains the global counters
84144 */
84145-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84146+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84147 EXPORT_SYMBOL(vm_stat);
84148
84149 #ifdef CONFIG_SMP
84150@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
84151 v = p->vm_stat_diff[i];
84152 p->vm_stat_diff[i] = 0;
84153 local_irq_restore(flags);
84154- atomic_long_add(v, &zone->vm_stat[i]);
84155+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84156 global_diff[i] += v;
84157 #ifdef CONFIG_NUMA
84158 /* 3 seconds idle till flush */
84159@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
84160
84161 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
84162 if (global_diff[i])
84163- atomic_long_add(global_diff[i], &vm_stat[i]);
84164+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
84165 }
84166
84167 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84168@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84169 if (pset->vm_stat_diff[i]) {
84170 int v = pset->vm_stat_diff[i];
84171 pset->vm_stat_diff[i] = 0;
84172- atomic_long_add(v, &zone->vm_stat[i]);
84173- atomic_long_add(v, &vm_stat[i]);
84174+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84175+ atomic_long_add_unchecked(v, &vm_stat[i]);
84176 }
84177 }
84178 #endif
84179@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
84180 return NOTIFY_OK;
84181 }
84182
84183-static struct notifier_block __cpuinitdata vmstat_notifier =
84184+static struct notifier_block vmstat_notifier =
84185 { &vmstat_cpuup_callback, NULL, 0 };
84186 #endif
84187
84188@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
84189 start_cpu_timer(cpu);
84190 #endif
84191 #ifdef CONFIG_PROC_FS
84192- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
84193- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
84194- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
84195- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
84196+ {
84197+ mode_t gr_mode = S_IRUGO;
84198+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84199+ gr_mode = S_IRUSR;
84200+#endif
84201+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
84202+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
84203+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84204+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
84205+#else
84206+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
84207+#endif
84208+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
84209+ }
84210 #endif
84211 return 0;
84212 }
84213diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
84214index a292e80..785ee68 100644
84215--- a/net/8021q/vlan.c
84216+++ b/net/8021q/vlan.c
84217@@ -485,7 +485,7 @@ out:
84218 return NOTIFY_DONE;
84219 }
84220
84221-static struct notifier_block vlan_notifier_block __read_mostly = {
84222+static struct notifier_block vlan_notifier_block = {
84223 .notifier_call = vlan_device_event,
84224 };
84225
84226@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
84227 err = -EPERM;
84228 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
84229 break;
84230- if ((args.u.name_type >= 0) &&
84231- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
84232+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
84233 struct vlan_net *vn;
84234
84235 vn = net_generic(net, vlan_net_id);
84236diff --git a/net/9p/mod.c b/net/9p/mod.c
84237index 6ab36ae..6f1841b 100644
84238--- a/net/9p/mod.c
84239+++ b/net/9p/mod.c
84240@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
84241 void v9fs_register_trans(struct p9_trans_module *m)
84242 {
84243 spin_lock(&v9fs_trans_lock);
84244- list_add_tail(&m->list, &v9fs_trans_list);
84245+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
84246 spin_unlock(&v9fs_trans_lock);
84247 }
84248 EXPORT_SYMBOL(v9fs_register_trans);
84249@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
84250 void v9fs_unregister_trans(struct p9_trans_module *m)
84251 {
84252 spin_lock(&v9fs_trans_lock);
84253- list_del_init(&m->list);
84254+ pax_list_del_init((struct list_head *)&m->list);
84255 spin_unlock(&v9fs_trans_lock);
84256 }
84257 EXPORT_SYMBOL(v9fs_unregister_trans);
84258diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
84259index 02efb25..41541a9 100644
84260--- a/net/9p/trans_fd.c
84261+++ b/net/9p/trans_fd.c
84262@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
84263 oldfs = get_fs();
84264 set_fs(get_ds());
84265 /* The cast to a user pointer is valid due to the set_fs() */
84266- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
84267+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
84268 set_fs(oldfs);
84269
84270 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
84271diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
84272index 876fbe8..8bbea9f 100644
84273--- a/net/atm/atm_misc.c
84274+++ b/net/atm/atm_misc.c
84275@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
84276 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
84277 return 1;
84278 atm_return(vcc, truesize);
84279- atomic_inc(&vcc->stats->rx_drop);
84280+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84281 return 0;
84282 }
84283 EXPORT_SYMBOL(atm_charge);
84284@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
84285 }
84286 }
84287 atm_return(vcc, guess);
84288- atomic_inc(&vcc->stats->rx_drop);
84289+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84290 return NULL;
84291 }
84292 EXPORT_SYMBOL(atm_alloc_charge);
84293@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
84294
84295 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84296 {
84297-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84298+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84299 __SONET_ITEMS
84300 #undef __HANDLE_ITEM
84301 }
84302@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
84303
84304 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84305 {
84306-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84307+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
84308 __SONET_ITEMS
84309 #undef __HANDLE_ITEM
84310 }
84311diff --git a/net/atm/lec.h b/net/atm/lec.h
84312index a86aff9..3a0d6f6 100644
84313--- a/net/atm/lec.h
84314+++ b/net/atm/lec.h
84315@@ -48,7 +48,7 @@ struct lane2_ops {
84316 const u8 *tlvs, u32 sizeoftlvs);
84317 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
84318 const u8 *tlvs, u32 sizeoftlvs);
84319-};
84320+} __no_const;
84321
84322 /*
84323 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
84324diff --git a/net/atm/proc.c b/net/atm/proc.c
84325index 0d020de..011c7bb 100644
84326--- a/net/atm/proc.c
84327+++ b/net/atm/proc.c
84328@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
84329 const struct k_atm_aal_stats *stats)
84330 {
84331 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
84332- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
84333- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
84334- atomic_read(&stats->rx_drop));
84335+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
84336+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
84337+ atomic_read_unchecked(&stats->rx_drop));
84338 }
84339
84340 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
84341diff --git a/net/atm/resources.c b/net/atm/resources.c
84342index 0447d5d..3cf4728 100644
84343--- a/net/atm/resources.c
84344+++ b/net/atm/resources.c
84345@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
84346 static void copy_aal_stats(struct k_atm_aal_stats *from,
84347 struct atm_aal_stats *to)
84348 {
84349-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84350+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84351 __AAL_STAT_ITEMS
84352 #undef __HANDLE_ITEM
84353 }
84354@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
84355 static void subtract_aal_stats(struct k_atm_aal_stats *from,
84356 struct atm_aal_stats *to)
84357 {
84358-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84359+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
84360 __AAL_STAT_ITEMS
84361 #undef __HANDLE_ITEM
84362 }
84363diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
84364index d5744b7..506bae3 100644
84365--- a/net/ax25/sysctl_net_ax25.c
84366+++ b/net/ax25/sysctl_net_ax25.c
84367@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
84368 {
84369 char path[sizeof("net/ax25/") + IFNAMSIZ];
84370 int k;
84371- struct ctl_table *table;
84372+ ctl_table_no_const *table;
84373
84374 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
84375 if (!table)
84376diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
84377index 7d02ebd..4d4cc01 100644
84378--- a/net/batman-adv/bat_iv_ogm.c
84379+++ b/net/batman-adv/bat_iv_ogm.c
84380@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
84381
84382 /* randomize initial seqno to avoid collision */
84383 get_random_bytes(&random_seqno, sizeof(random_seqno));
84384- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84385+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84386
84387 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
84388 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
84389@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
84390 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
84391
84392 /* change sequence number to network order */
84393- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
84394+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
84395 batadv_ogm_packet->seqno = htonl(seqno);
84396- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
84397+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
84398
84399 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
84400 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
84401@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
84402 return;
84403
84404 /* could be changed by schedule_own_packet() */
84405- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
84406+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
84407
84408 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
84409 has_directlink_flag = 1;
84410diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
84411index f1d37cd..4190879 100644
84412--- a/net/batman-adv/hard-interface.c
84413+++ b/net/batman-adv/hard-interface.c
84414@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
84415 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
84416 dev_add_pack(&hard_iface->batman_adv_ptype);
84417
84418- atomic_set(&hard_iface->frag_seqno, 1);
84419+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
84420 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
84421 hard_iface->net_dev->name);
84422
84423@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
84424 /* This can't be called via a bat_priv callback because
84425 * we have no bat_priv yet.
84426 */
84427- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
84428+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
84429 hard_iface->bat_iv.ogm_buff = NULL;
84430
84431 return hard_iface;
84432diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
84433index 6b548fd..fc32c8d 100644
84434--- a/net/batman-adv/soft-interface.c
84435+++ b/net/batman-adv/soft-interface.c
84436@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
84437 primary_if->net_dev->dev_addr, ETH_ALEN);
84438
84439 /* set broadcast sequence number */
84440- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
84441+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
84442 bcast_packet->seqno = htonl(seqno);
84443
84444 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
84445@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
84446 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
84447
84448 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
84449- atomic_set(&bat_priv->bcast_seqno, 1);
84450+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
84451 atomic_set(&bat_priv->tt.vn, 0);
84452 atomic_set(&bat_priv->tt.local_changes, 0);
84453 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
84454diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
84455index ae9ac9a..11e0fe7 100644
84456--- a/net/batman-adv/types.h
84457+++ b/net/batman-adv/types.h
84458@@ -48,7 +48,7 @@
84459 struct batadv_hard_iface_bat_iv {
84460 unsigned char *ogm_buff;
84461 int ogm_buff_len;
84462- atomic_t ogm_seqno;
84463+ atomic_unchecked_t ogm_seqno;
84464 };
84465
84466 struct batadv_hard_iface {
84467@@ -56,7 +56,7 @@ struct batadv_hard_iface {
84468 int16_t if_num;
84469 char if_status;
84470 struct net_device *net_dev;
84471- atomic_t frag_seqno;
84472+ atomic_unchecked_t frag_seqno;
84473 struct kobject *hardif_obj;
84474 atomic_t refcount;
84475 struct packet_type batman_adv_ptype;
84476@@ -284,7 +284,7 @@ struct batadv_priv {
84477 atomic_t orig_interval; /* uint */
84478 atomic_t hop_penalty; /* uint */
84479 atomic_t log_level; /* uint */
84480- atomic_t bcast_seqno;
84481+ atomic_unchecked_t bcast_seqno;
84482 atomic_t bcast_queue_left;
84483 atomic_t batman_queue_left;
84484 char num_ifaces;
84485diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
84486index 10aff49..ea8e021 100644
84487--- a/net/batman-adv/unicast.c
84488+++ b/net/batman-adv/unicast.c
84489@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
84490 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
84491 frag2->flags = large_tail;
84492
84493- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
84494+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
84495 frag1->seqno = htons(seqno - 1);
84496 frag2->seqno = htons(seqno);
84497
84498diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
84499index 07f0739..3c42e34 100644
84500--- a/net/bluetooth/hci_sock.c
84501+++ b/net/bluetooth/hci_sock.c
84502@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
84503 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
84504 }
84505
84506- len = min_t(unsigned int, len, sizeof(uf));
84507+ len = min((size_t)len, sizeof(uf));
84508 if (copy_from_user(&uf, optval, len)) {
84509 err = -EFAULT;
84510 break;
84511diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
84512index 22e6583..426e2f3 100644
84513--- a/net/bluetooth/l2cap_core.c
84514+++ b/net/bluetooth/l2cap_core.c
84515@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
84516 break;
84517
84518 case L2CAP_CONF_RFC:
84519- if (olen == sizeof(rfc))
84520- memcpy(&rfc, (void *)val, olen);
84521+ if (olen != sizeof(rfc))
84522+ break;
84523+
84524+ memcpy(&rfc, (void *)val, olen);
84525
84526 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
84527 rfc.mode != chan->mode)
84528diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
84529index 1bcfb84..dad9f98 100644
84530--- a/net/bluetooth/l2cap_sock.c
84531+++ b/net/bluetooth/l2cap_sock.c
84532@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84533 struct sock *sk = sock->sk;
84534 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
84535 struct l2cap_options opts;
84536- int len, err = 0;
84537+ int err = 0;
84538+ size_t len = optlen;
84539 u32 opt;
84540
84541 BT_DBG("sk %p", sk);
84542@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84543 opts.max_tx = chan->max_tx;
84544 opts.txwin_size = chan->tx_win;
84545
84546- len = min_t(unsigned int, sizeof(opts), optlen);
84547+ len = min(sizeof(opts), len);
84548 if (copy_from_user((char *) &opts, optval, len)) {
84549 err = -EFAULT;
84550 break;
84551@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84552 struct bt_security sec;
84553 struct bt_power pwr;
84554 struct l2cap_conn *conn;
84555- int len, err = 0;
84556+ int err = 0;
84557+ size_t len = optlen;
84558 u32 opt;
84559
84560 BT_DBG("sk %p", sk);
84561@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84562
84563 sec.level = BT_SECURITY_LOW;
84564
84565- len = min_t(unsigned int, sizeof(sec), optlen);
84566+ len = min(sizeof(sec), len);
84567 if (copy_from_user((char *) &sec, optval, len)) {
84568 err = -EFAULT;
84569 break;
84570@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84571
84572 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
84573
84574- len = min_t(unsigned int, sizeof(pwr), optlen);
84575+ len = min(sizeof(pwr), len);
84576 if (copy_from_user((char *) &pwr, optval, len)) {
84577 err = -EFAULT;
84578 break;
84579diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
84580index ce3f665..2c7d08f 100644
84581--- a/net/bluetooth/rfcomm/sock.c
84582+++ b/net/bluetooth/rfcomm/sock.c
84583@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84584 struct sock *sk = sock->sk;
84585 struct bt_security sec;
84586 int err = 0;
84587- size_t len;
84588+ size_t len = optlen;
84589 u32 opt;
84590
84591 BT_DBG("sk %p", sk);
84592@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84593
84594 sec.level = BT_SECURITY_LOW;
84595
84596- len = min_t(unsigned int, sizeof(sec), optlen);
84597+ len = min(sizeof(sec), len);
84598 if (copy_from_user((char *) &sec, optval, len)) {
84599 err = -EFAULT;
84600 break;
84601diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
84602index bd6fd0f..6492cba 100644
84603--- a/net/bluetooth/rfcomm/tty.c
84604+++ b/net/bluetooth/rfcomm/tty.c
84605@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
84606 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
84607
84608 spin_lock_irqsave(&dev->port.lock, flags);
84609- if (dev->port.count > 0) {
84610+ if (atomic_read(&dev->port.count) > 0) {
84611 spin_unlock_irqrestore(&dev->port.lock, flags);
84612 return;
84613 }
84614@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
84615 return -ENODEV;
84616
84617 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
84618- dev->channel, dev->port.count);
84619+ dev->channel, atomic_read(&dev->port.count));
84620
84621 spin_lock_irqsave(&dev->port.lock, flags);
84622- if (++dev->port.count > 1) {
84623+ if (atomic_inc_return(&dev->port.count) > 1) {
84624 spin_unlock_irqrestore(&dev->port.lock, flags);
84625 return 0;
84626 }
84627@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
84628 return;
84629
84630 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
84631- dev->port.count);
84632+ atomic_read(&dev->port.count));
84633
84634 spin_lock_irqsave(&dev->port.lock, flags);
84635- if (!--dev->port.count) {
84636+ if (!atomic_dec_return(&dev->port.count)) {
84637 spin_unlock_irqrestore(&dev->port.lock, flags);
84638 if (dev->tty_dev->parent)
84639 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
84640diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
84641index 5fe2ff3..121d696 100644
84642--- a/net/bridge/netfilter/ebtables.c
84643+++ b/net/bridge/netfilter/ebtables.c
84644@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
84645 tmp.valid_hooks = t->table->valid_hooks;
84646 }
84647 mutex_unlock(&ebt_mutex);
84648- if (copy_to_user(user, &tmp, *len) != 0){
84649+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
84650 BUGPRINT("c2u Didn't work\n");
84651 ret = -EFAULT;
84652 break;
84653@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84654 goto out;
84655 tmp.valid_hooks = t->valid_hooks;
84656
84657- if (copy_to_user(user, &tmp, *len) != 0) {
84658+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84659 ret = -EFAULT;
84660 break;
84661 }
84662@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84663 tmp.entries_size = t->table->entries_size;
84664 tmp.valid_hooks = t->table->valid_hooks;
84665
84666- if (copy_to_user(user, &tmp, *len) != 0) {
84667+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84668 ret = -EFAULT;
84669 break;
84670 }
84671diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
84672index a376ec1..1fbd6be 100644
84673--- a/net/caif/cfctrl.c
84674+++ b/net/caif/cfctrl.c
84675@@ -10,6 +10,7 @@
84676 #include <linux/spinlock.h>
84677 #include <linux/slab.h>
84678 #include <linux/pkt_sched.h>
84679+#include <linux/sched.h>
84680 #include <net/caif/caif_layer.h>
84681 #include <net/caif/cfpkt.h>
84682 #include <net/caif/cfctrl.h>
84683@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
84684 memset(&dev_info, 0, sizeof(dev_info));
84685 dev_info.id = 0xff;
84686 cfsrvl_init(&this->serv, 0, &dev_info, false);
84687- atomic_set(&this->req_seq_no, 1);
84688- atomic_set(&this->rsp_seq_no, 1);
84689+ atomic_set_unchecked(&this->req_seq_no, 1);
84690+ atomic_set_unchecked(&this->rsp_seq_no, 1);
84691 this->serv.layer.receive = cfctrl_recv;
84692 sprintf(this->serv.layer.name, "ctrl");
84693 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
84694@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
84695 struct cfctrl_request_info *req)
84696 {
84697 spin_lock_bh(&ctrl->info_list_lock);
84698- atomic_inc(&ctrl->req_seq_no);
84699- req->sequence_no = atomic_read(&ctrl->req_seq_no);
84700+ atomic_inc_unchecked(&ctrl->req_seq_no);
84701+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
84702 list_add_tail(&req->list, &ctrl->list);
84703 spin_unlock_bh(&ctrl->info_list_lock);
84704 }
84705@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
84706 if (p != first)
84707 pr_warn("Requests are not received in order\n");
84708
84709- atomic_set(&ctrl->rsp_seq_no,
84710+ atomic_set_unchecked(&ctrl->rsp_seq_no,
84711 p->sequence_no);
84712 list_del(&p->list);
84713 goto out;
84714diff --git a/net/can/af_can.c b/net/can/af_can.c
84715index ddac1ee..3ee0a78 100644
84716--- a/net/can/af_can.c
84717+++ b/net/can/af_can.c
84718@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
84719 };
84720
84721 /* notifier block for netdevice event */
84722-static struct notifier_block can_netdev_notifier __read_mostly = {
84723+static struct notifier_block can_netdev_notifier = {
84724 .notifier_call = can_notifier,
84725 };
84726
84727diff --git a/net/can/gw.c b/net/can/gw.c
84728index 574dda78e..3d2b3da 100644
84729--- a/net/can/gw.c
84730+++ b/net/can/gw.c
84731@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
84732 MODULE_ALIAS("can-gw");
84733
84734 static HLIST_HEAD(cgw_list);
84735-static struct notifier_block notifier;
84736
84737 static struct kmem_cache *cgw_cache __read_mostly;
84738
84739@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
84740 return err;
84741 }
84742
84743+static struct notifier_block notifier = {
84744+ .notifier_call = cgw_notifier
84745+};
84746+
84747 static __init int cgw_module_init(void)
84748 {
84749 printk(banner);
84750@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
84751 return -ENOMEM;
84752
84753 /* set notifier */
84754- notifier.notifier_call = cgw_notifier;
84755 register_netdevice_notifier(&notifier);
84756
84757 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
84758diff --git a/net/compat.c b/net/compat.c
84759index 79ae884..17c5c09 100644
84760--- a/net/compat.c
84761+++ b/net/compat.c
84762@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
84763 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
84764 __get_user(kmsg->msg_flags, &umsg->msg_flags))
84765 return -EFAULT;
84766- kmsg->msg_name = compat_ptr(tmp1);
84767- kmsg->msg_iov = compat_ptr(tmp2);
84768- kmsg->msg_control = compat_ptr(tmp3);
84769+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
84770+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
84771+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
84772 return 0;
84773 }
84774
84775@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84776
84777 if (kern_msg->msg_namelen) {
84778 if (mode == VERIFY_READ) {
84779- int err = move_addr_to_kernel(kern_msg->msg_name,
84780+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
84781 kern_msg->msg_namelen,
84782 kern_address);
84783 if (err < 0)
84784@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84785 kern_msg->msg_name = NULL;
84786
84787 tot_len = iov_from_user_compat_to_kern(kern_iov,
84788- (struct compat_iovec __user *)kern_msg->msg_iov,
84789+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
84790 kern_msg->msg_iovlen);
84791 if (tot_len >= 0)
84792 kern_msg->msg_iov = kern_iov;
84793@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84794
84795 #define CMSG_COMPAT_FIRSTHDR(msg) \
84796 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
84797- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
84798+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
84799 (struct compat_cmsghdr __user *)NULL)
84800
84801 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
84802 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
84803 (ucmlen) <= (unsigned long) \
84804 ((mhdr)->msg_controllen - \
84805- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
84806+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
84807
84808 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
84809 struct compat_cmsghdr __user *cmsg, int cmsg_len)
84810 {
84811 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
84812- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
84813+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
84814 msg->msg_controllen)
84815 return NULL;
84816 return (struct compat_cmsghdr __user *)ptr;
84817@@ -219,7 +219,7 @@ Efault:
84818
84819 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
84820 {
84821- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84822+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84823 struct compat_cmsghdr cmhdr;
84824 struct compat_timeval ctv;
84825 struct compat_timespec cts[3];
84826@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
84827
84828 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
84829 {
84830- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84831+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84832 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
84833 int fdnum = scm->fp->count;
84834 struct file **fp = scm->fp->fp;
84835@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
84836 return -EFAULT;
84837 old_fs = get_fs();
84838 set_fs(KERNEL_DS);
84839- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
84840+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
84841 set_fs(old_fs);
84842
84843 return err;
84844@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
84845 len = sizeof(ktime);
84846 old_fs = get_fs();
84847 set_fs(KERNEL_DS);
84848- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
84849+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
84850 set_fs(old_fs);
84851
84852 if (!err) {
84853@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84854 case MCAST_JOIN_GROUP:
84855 case MCAST_LEAVE_GROUP:
84856 {
84857- struct compat_group_req __user *gr32 = (void *)optval;
84858+ struct compat_group_req __user *gr32 = (void __user *)optval;
84859 struct group_req __user *kgr =
84860 compat_alloc_user_space(sizeof(struct group_req));
84861 u32 interface;
84862@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84863 case MCAST_BLOCK_SOURCE:
84864 case MCAST_UNBLOCK_SOURCE:
84865 {
84866- struct compat_group_source_req __user *gsr32 = (void *)optval;
84867+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
84868 struct group_source_req __user *kgsr = compat_alloc_user_space(
84869 sizeof(struct group_source_req));
84870 u32 interface;
84871@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84872 }
84873 case MCAST_MSFILTER:
84874 {
84875- struct compat_group_filter __user *gf32 = (void *)optval;
84876+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84877 struct group_filter __user *kgf;
84878 u32 interface, fmode, numsrc;
84879
84880@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
84881 char __user *optval, int __user *optlen,
84882 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
84883 {
84884- struct compat_group_filter __user *gf32 = (void *)optval;
84885+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84886 struct group_filter __user *kgf;
84887 int __user *koptlen;
84888 u32 interface, fmode, numsrc;
84889@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
84890
84891 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
84892 return -EINVAL;
84893- if (copy_from_user(a, args, nas[call]))
84894+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
84895 return -EFAULT;
84896 a0 = a[0];
84897 a1 = a[1];
84898diff --git a/net/core/datagram.c b/net/core/datagram.c
84899index 368f9c3..f82d4a3 100644
84900--- a/net/core/datagram.c
84901+++ b/net/core/datagram.c
84902@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
84903 }
84904
84905 kfree_skb(skb);
84906- atomic_inc(&sk->sk_drops);
84907+ atomic_inc_unchecked(&sk->sk_drops);
84908 sk_mem_reclaim_partial(sk);
84909
84910 return err;
84911diff --git a/net/core/dev.c b/net/core/dev.c
84912index 1339f77..6fd27dc 100644
84913--- a/net/core/dev.c
84914+++ b/net/core/dev.c
84915@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
84916 if (no_module && capable(CAP_NET_ADMIN))
84917 no_module = request_module("netdev-%s", name);
84918 if (no_module && capable(CAP_SYS_MODULE)) {
84919+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84920+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
84921+#else
84922 if (!request_module("%s", name))
84923 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
84924 name);
84925+#endif
84926 }
84927 }
84928 EXPORT_SYMBOL(dev_load);
84929@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84930 {
84931 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
84932 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
84933- atomic_long_inc(&dev->rx_dropped);
84934+ atomic_long_inc_unchecked(&dev->rx_dropped);
84935 kfree_skb(skb);
84936 return NET_RX_DROP;
84937 }
84938@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84939 nf_reset(skb);
84940
84941 if (unlikely(!is_skb_forwardable(dev, skb))) {
84942- atomic_long_inc(&dev->rx_dropped);
84943+ atomic_long_inc_unchecked(&dev->rx_dropped);
84944 kfree_skb(skb);
84945 return NET_RX_DROP;
84946 }
84947@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
84948
84949 struct dev_gso_cb {
84950 void (*destructor)(struct sk_buff *skb);
84951-};
84952+} __no_const;
84953
84954 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
84955
84956@@ -3053,7 +3057,7 @@ enqueue:
84957
84958 local_irq_restore(flags);
84959
84960- atomic_long_inc(&skb->dev->rx_dropped);
84961+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84962 kfree_skb(skb);
84963 return NET_RX_DROP;
84964 }
84965@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
84966 }
84967 EXPORT_SYMBOL(netif_rx_ni);
84968
84969-static void net_tx_action(struct softirq_action *h)
84970+static void net_tx_action(void)
84971 {
84972 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84973
84974@@ -3457,7 +3461,7 @@ ncls:
84975 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
84976 } else {
84977 drop:
84978- atomic_long_inc(&skb->dev->rx_dropped);
84979+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84980 kfree_skb(skb);
84981 /* Jamal, now you will not able to escape explaining
84982 * me how you were going to use this. :-)
84983@@ -4040,7 +4044,7 @@ void netif_napi_del(struct napi_struct *napi)
84984 }
84985 EXPORT_SYMBOL(netif_napi_del);
84986
84987-static void net_rx_action(struct softirq_action *h)
84988+static void net_rx_action(void)
84989 {
84990 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84991 unsigned long time_limit = jiffies + 2;
84992@@ -4524,8 +4528,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
84993 else
84994 seq_printf(seq, "%04x", ntohs(pt->type));
84995
84996+#ifdef CONFIG_GRKERNSEC_HIDESYM
84997+ seq_printf(seq, " %-8s %p\n",
84998+ pt->dev ? pt->dev->name : "", NULL);
84999+#else
85000 seq_printf(seq, " %-8s %pF\n",
85001 pt->dev ? pt->dev->name : "", pt->func);
85002+#endif
85003 }
85004
85005 return 0;
85006@@ -6097,7 +6106,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
85007 } else {
85008 netdev_stats_to_stats64(storage, &dev->stats);
85009 }
85010- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
85011+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
85012 return storage;
85013 }
85014 EXPORT_SYMBOL(dev_get_stats);
85015diff --git a/net/core/flow.c b/net/core/flow.c
85016index b0901ee..7d3c2ca 100644
85017--- a/net/core/flow.c
85018+++ b/net/core/flow.c
85019@@ -61,7 +61,7 @@ struct flow_cache {
85020 struct timer_list rnd_timer;
85021 };
85022
85023-atomic_t flow_cache_genid = ATOMIC_INIT(0);
85024+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
85025 EXPORT_SYMBOL(flow_cache_genid);
85026 static struct flow_cache flow_cache_global;
85027 static struct kmem_cache *flow_cachep __read_mostly;
85028@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
85029
85030 static int flow_entry_valid(struct flow_cache_entry *fle)
85031 {
85032- if (atomic_read(&flow_cache_genid) != fle->genid)
85033+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
85034 return 0;
85035 if (fle->object && !fle->object->ops->check(fle->object))
85036 return 0;
85037@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
85038 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
85039 fcp->hash_count++;
85040 }
85041- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
85042+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
85043 flo = fle->object;
85044 if (!flo)
85045 goto ret_object;
85046@@ -280,7 +280,7 @@ nocache:
85047 }
85048 flo = resolver(net, key, family, dir, flo, ctx);
85049 if (fle) {
85050- fle->genid = atomic_read(&flow_cache_genid);
85051+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
85052 if (!IS_ERR(flo))
85053 fle->object = flo;
85054 else
85055diff --git a/net/core/iovec.c b/net/core/iovec.c
85056index 7e7aeb0..2a998cb 100644
85057--- a/net/core/iovec.c
85058+++ b/net/core/iovec.c
85059@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85060 if (m->msg_namelen) {
85061 if (mode == VERIFY_READ) {
85062 void __user *namep;
85063- namep = (void __user __force *) m->msg_name;
85064+ namep = (void __force_user *) m->msg_name;
85065 err = move_addr_to_kernel(namep, m->msg_namelen,
85066 address);
85067 if (err < 0)
85068@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85069 }
85070
85071 size = m->msg_iovlen * sizeof(struct iovec);
85072- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
85073+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
85074 return -EFAULT;
85075
85076 m->msg_iov = iov;
85077diff --git a/net/core/neighbour.c b/net/core/neighbour.c
85078index c815f28..e6403f2 100644
85079--- a/net/core/neighbour.c
85080+++ b/net/core/neighbour.c
85081@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
85082 size_t *lenp, loff_t *ppos)
85083 {
85084 int size, ret;
85085- ctl_table tmp = *ctl;
85086+ ctl_table_no_const tmp = *ctl;
85087
85088 tmp.extra1 = &zero;
85089 tmp.extra2 = &unres_qlen_max;
85090diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
85091index 28c5f5a..7edf2e2 100644
85092--- a/net/core/net-sysfs.c
85093+++ b/net/core/net-sysfs.c
85094@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
85095 }
85096 EXPORT_SYMBOL(netdev_class_remove_file);
85097
85098-int netdev_kobject_init(void)
85099+int __init netdev_kobject_init(void)
85100 {
85101 kobj_ns_type_register(&net_ns_type_operations);
85102 return class_register(&net_class);
85103diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
85104index 8acce01..2e306bb 100644
85105--- a/net/core/net_namespace.c
85106+++ b/net/core/net_namespace.c
85107@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
85108 int error;
85109 LIST_HEAD(net_exit_list);
85110
85111- list_add_tail(&ops->list, list);
85112+ pax_list_add_tail((struct list_head *)&ops->list, list);
85113 if (ops->init || (ops->id && ops->size)) {
85114 for_each_net(net) {
85115 error = ops_init(ops, net);
85116@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
85117
85118 out_undo:
85119 /* If I have an error cleanup all namespaces I initialized */
85120- list_del(&ops->list);
85121+ pax_list_del((struct list_head *)&ops->list);
85122 ops_exit_list(ops, &net_exit_list);
85123 ops_free_list(ops, &net_exit_list);
85124 return error;
85125@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
85126 struct net *net;
85127 LIST_HEAD(net_exit_list);
85128
85129- list_del(&ops->list);
85130+ pax_list_del((struct list_head *)&ops->list);
85131 for_each_net(net)
85132 list_add_tail(&net->exit_list, &net_exit_list);
85133 ops_exit_list(ops, &net_exit_list);
85134@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
85135 mutex_lock(&net_mutex);
85136 error = register_pernet_operations(&pernet_list, ops);
85137 if (!error && (first_device == &pernet_list))
85138- first_device = &ops->list;
85139+ first_device = (struct list_head *)&ops->list;
85140 mutex_unlock(&net_mutex);
85141 return error;
85142 }
85143diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
85144index 798f920..e2261f5 100644
85145--- a/net/core/rtnetlink.c
85146+++ b/net/core/rtnetlink.c
85147@@ -58,7 +58,7 @@ struct rtnl_link {
85148 rtnl_doit_func doit;
85149 rtnl_dumpit_func dumpit;
85150 rtnl_calcit_func calcit;
85151-};
85152+} __no_const;
85153
85154 static DEFINE_MUTEX(rtnl_mutex);
85155
85156@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
85157 if (rtnl_link_ops_get(ops->kind))
85158 return -EEXIST;
85159
85160- if (!ops->dellink)
85161- ops->dellink = unregister_netdevice_queue;
85162+ if (!ops->dellink) {
85163+ pax_open_kernel();
85164+ *(void **)&ops->dellink = unregister_netdevice_queue;
85165+ pax_close_kernel();
85166+ }
85167
85168- list_add_tail(&ops->list, &link_ops);
85169+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
85170 return 0;
85171 }
85172 EXPORT_SYMBOL_GPL(__rtnl_link_register);
85173@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
85174 for_each_net(net) {
85175 __rtnl_kill_links(net, ops);
85176 }
85177- list_del(&ops->list);
85178+ pax_list_del((struct list_head *)&ops->list);
85179 }
85180 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
85181
85182diff --git a/net/core/scm.c b/net/core/scm.c
85183index 905dcc6..14ee2d6 100644
85184--- a/net/core/scm.c
85185+++ b/net/core/scm.c
85186@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
85187 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85188 {
85189 struct cmsghdr __user *cm
85190- = (__force struct cmsghdr __user *)msg->msg_control;
85191+ = (struct cmsghdr __force_user *)msg->msg_control;
85192 struct cmsghdr cmhdr;
85193 int cmlen = CMSG_LEN(len);
85194 int err;
85195@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85196 err = -EFAULT;
85197 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
85198 goto out;
85199- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
85200+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
85201 goto out;
85202 cmlen = CMSG_SPACE(len);
85203 if (msg->msg_controllen < cmlen)
85204@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
85205 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85206 {
85207 struct cmsghdr __user *cm
85208- = (__force struct cmsghdr __user*)msg->msg_control;
85209+ = (struct cmsghdr __force_user *)msg->msg_control;
85210
85211 int fdmax = 0;
85212 int fdnum = scm->fp->count;
85213@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85214 if (fdnum < fdmax)
85215 fdmax = fdnum;
85216
85217- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
85218+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
85219 i++, cmfptr++)
85220 {
85221 struct socket *sock;
85222diff --git a/net/core/sock.c b/net/core/sock.c
85223index bc131d4..029e378 100644
85224--- a/net/core/sock.c
85225+++ b/net/core/sock.c
85226@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85227 struct sk_buff_head *list = &sk->sk_receive_queue;
85228
85229 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
85230- atomic_inc(&sk->sk_drops);
85231+ atomic_inc_unchecked(&sk->sk_drops);
85232 trace_sock_rcvqueue_full(sk, skb);
85233 return -ENOMEM;
85234 }
85235@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85236 return err;
85237
85238 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
85239- atomic_inc(&sk->sk_drops);
85240+ atomic_inc_unchecked(&sk->sk_drops);
85241 return -ENOBUFS;
85242 }
85243
85244@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85245 skb_dst_force(skb);
85246
85247 spin_lock_irqsave(&list->lock, flags);
85248- skb->dropcount = atomic_read(&sk->sk_drops);
85249+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
85250 __skb_queue_tail(list, skb);
85251 spin_unlock_irqrestore(&list->lock, flags);
85252
85253@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85254 skb->dev = NULL;
85255
85256 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
85257- atomic_inc(&sk->sk_drops);
85258+ atomic_inc_unchecked(&sk->sk_drops);
85259 goto discard_and_relse;
85260 }
85261 if (nested)
85262@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85263 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
85264 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
85265 bh_unlock_sock(sk);
85266- atomic_inc(&sk->sk_drops);
85267+ atomic_inc_unchecked(&sk->sk_drops);
85268 goto discard_and_relse;
85269 }
85270
85271@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85272 struct timeval tm;
85273 } v;
85274
85275- int lv = sizeof(int);
85276- int len;
85277+ unsigned int lv = sizeof(int);
85278+ unsigned int len;
85279
85280 if (get_user(len, optlen))
85281 return -EFAULT;
85282- if (len < 0)
85283+ if (len > INT_MAX)
85284 return -EINVAL;
85285
85286 memset(&v, 0, sizeof(v));
85287@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85288
85289 case SO_PEERNAME:
85290 {
85291- char address[128];
85292+ char address[_K_SS_MAXSIZE];
85293
85294 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
85295 return -ENOTCONN;
85296- if (lv < len)
85297+ if (lv < len || sizeof address < len)
85298 return -EINVAL;
85299 if (copy_to_user(optval, address, len))
85300 return -EFAULT;
85301@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85302
85303 if (len > lv)
85304 len = lv;
85305- if (copy_to_user(optval, &v, len))
85306+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
85307 return -EFAULT;
85308 lenout:
85309 if (put_user(len, optlen))
85310@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
85311 */
85312 smp_wmb();
85313 atomic_set(&sk->sk_refcnt, 1);
85314- atomic_set(&sk->sk_drops, 0);
85315+ atomic_set_unchecked(&sk->sk_drops, 0);
85316 }
85317 EXPORT_SYMBOL(sock_init_data);
85318
85319diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
85320index 750f44f..922399c 100644
85321--- a/net/core/sock_diag.c
85322+++ b/net/core/sock_diag.c
85323@@ -9,26 +9,33 @@
85324 #include <linux/inet_diag.h>
85325 #include <linux/sock_diag.h>
85326
85327-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
85328+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
85329 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
85330 static DEFINE_MUTEX(sock_diag_table_mutex);
85331
85332 int sock_diag_check_cookie(void *sk, __u32 *cookie)
85333 {
85334+#ifndef CONFIG_GRKERNSEC_HIDESYM
85335 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
85336 cookie[1] != INET_DIAG_NOCOOKIE) &&
85337 ((u32)(unsigned long)sk != cookie[0] ||
85338 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
85339 return -ESTALE;
85340 else
85341+#endif
85342 return 0;
85343 }
85344 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
85345
85346 void sock_diag_save_cookie(void *sk, __u32 *cookie)
85347 {
85348+#ifdef CONFIG_GRKERNSEC_HIDESYM
85349+ cookie[0] = 0;
85350+ cookie[1] = 0;
85351+#else
85352 cookie[0] = (u32)(unsigned long)sk;
85353 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
85354+#endif
85355 }
85356 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
85357
85358@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
85359 mutex_lock(&sock_diag_table_mutex);
85360 if (sock_diag_handlers[hndl->family])
85361 err = -EBUSY;
85362- else
85363+ else {
85364+ pax_open_kernel();
85365 sock_diag_handlers[hndl->family] = hndl;
85366+ pax_close_kernel();
85367+ }
85368 mutex_unlock(&sock_diag_table_mutex);
85369
85370 return err;
85371@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
85372
85373 mutex_lock(&sock_diag_table_mutex);
85374 BUG_ON(sock_diag_handlers[family] != hnld);
85375+ pax_open_kernel();
85376 sock_diag_handlers[family] = NULL;
85377+ pax_close_kernel();
85378 mutex_unlock(&sock_diag_table_mutex);
85379 }
85380 EXPORT_SYMBOL_GPL(sock_diag_unregister);
85381
85382-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
85383-{
85384- if (sock_diag_handlers[family] == NULL)
85385- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85386- NETLINK_SOCK_DIAG, family);
85387-
85388- mutex_lock(&sock_diag_table_mutex);
85389- return sock_diag_handlers[family];
85390-}
85391-
85392-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
85393-{
85394- mutex_unlock(&sock_diag_table_mutex);
85395-}
85396-
85397 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85398 {
85399 int err;
85400@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85401 if (req->sdiag_family >= AF_MAX)
85402 return -EINVAL;
85403
85404- hndl = sock_diag_lock_handler(req->sdiag_family);
85405+ if (sock_diag_handlers[req->sdiag_family] == NULL)
85406+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85407+ NETLINK_SOCK_DIAG, req->sdiag_family);
85408+
85409+ mutex_lock(&sock_diag_table_mutex);
85410+ hndl = sock_diag_handlers[req->sdiag_family];
85411 if (hndl == NULL)
85412 err = -ENOENT;
85413 else
85414 err = hndl->dump(skb, nlh);
85415- sock_diag_unlock_handler(hndl);
85416+ mutex_unlock(&sock_diag_table_mutex);
85417
85418 return err;
85419 }
85420diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
85421index d1b0804..4aed0a5 100644
85422--- a/net/core/sysctl_net_core.c
85423+++ b/net/core/sysctl_net_core.c
85424@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
85425 {
85426 unsigned int orig_size, size;
85427 int ret, i;
85428- ctl_table tmp = {
85429+ ctl_table_no_const tmp = {
85430 .data = &size,
85431 .maxlen = sizeof(size),
85432 .mode = table->mode
85433@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
85434
85435 static __net_init int sysctl_core_net_init(struct net *net)
85436 {
85437- struct ctl_table *tbl;
85438+ ctl_table_no_const *tbl = NULL;
85439
85440 net->core.sysctl_somaxconn = SOMAXCONN;
85441
85442- tbl = netns_core_table;
85443 if (!net_eq(net, &init_net)) {
85444- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
85445+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
85446 if (tbl == NULL)
85447 goto err_dup;
85448
85449@@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
85450 if (net->user_ns != &init_user_ns) {
85451 tbl[0].procname = NULL;
85452 }
85453- }
85454-
85455- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85456+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85457+ } else
85458+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
85459 if (net->core.sysctl_hdr == NULL)
85460 goto err_reg;
85461
85462 return 0;
85463
85464 err_reg:
85465- if (tbl != netns_core_table)
85466+ if (tbl)
85467 kfree(tbl);
85468 err_dup:
85469 return -ENOMEM;
85470@@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
85471 kfree(tbl);
85472 }
85473
85474-static __net_initdata struct pernet_operations sysctl_core_ops = {
85475+static __net_initconst struct pernet_operations sysctl_core_ops = {
85476 .init = sysctl_core_net_init,
85477 .exit = sysctl_core_net_exit,
85478 };
85479diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
85480index 307c322..78a4c6f 100644
85481--- a/net/decnet/af_decnet.c
85482+++ b/net/decnet/af_decnet.c
85483@@ -468,6 +468,7 @@ static struct proto dn_proto = {
85484 .sysctl_rmem = sysctl_decnet_rmem,
85485 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
85486 .obj_size = sizeof(struct dn_sock),
85487+ .slab_flags = SLAB_USERCOPY,
85488 };
85489
85490 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
85491diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
85492index a55eecc..dd8428c 100644
85493--- a/net/decnet/sysctl_net_decnet.c
85494+++ b/net/decnet/sysctl_net_decnet.c
85495@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
85496
85497 if (len > *lenp) len = *lenp;
85498
85499- if (copy_to_user(buffer, addr, len))
85500+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
85501 return -EFAULT;
85502
85503 *lenp = len;
85504@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
85505
85506 if (len > *lenp) len = *lenp;
85507
85508- if (copy_to_user(buffer, devname, len))
85509+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
85510 return -EFAULT;
85511
85512 *lenp = len;
85513diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
85514index fcf104e..95552d4 100644
85515--- a/net/ipv4/af_inet.c
85516+++ b/net/ipv4/af_inet.c
85517@@ -1717,13 +1717,9 @@ static int __init inet_init(void)
85518
85519 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
85520
85521- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
85522- if (!sysctl_local_reserved_ports)
85523- goto out;
85524-
85525 rc = proto_register(&tcp_prot, 1);
85526 if (rc)
85527- goto out_free_reserved_ports;
85528+ goto out;
85529
85530 rc = proto_register(&udp_prot, 1);
85531 if (rc)
85532@@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
85533 proto_unregister(&udp_prot);
85534 out_unregister_tcp_proto:
85535 proto_unregister(&tcp_prot);
85536-out_free_reserved_ports:
85537- kfree(sysctl_local_reserved_ports);
85538 goto out;
85539 }
85540
85541diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
85542index a69b4e4..dbccba5 100644
85543--- a/net/ipv4/ah4.c
85544+++ b/net/ipv4/ah4.c
85545@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
85546 return;
85547
85548 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85549- atomic_inc(&flow_cache_genid);
85550+ atomic_inc_unchecked(&flow_cache_genid);
85551 rt_genid_bump(net);
85552
85553 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
85554diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
85555index a8e4f26..25e5f40 100644
85556--- a/net/ipv4/devinet.c
85557+++ b/net/ipv4/devinet.c
85558@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
85559 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
85560 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
85561
85562-static struct devinet_sysctl_table {
85563+static const struct devinet_sysctl_table {
85564 struct ctl_table_header *sysctl_header;
85565 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
85566 } devinet_sysctl = {
85567@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
85568 int err;
85569 struct ipv4_devconf *all, *dflt;
85570 #ifdef CONFIG_SYSCTL
85571- struct ctl_table *tbl = ctl_forward_entry;
85572+ ctl_table_no_const *tbl = NULL;
85573 struct ctl_table_header *forw_hdr;
85574 #endif
85575
85576@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
85577 goto err_alloc_dflt;
85578
85579 #ifdef CONFIG_SYSCTL
85580- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
85581+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
85582 if (tbl == NULL)
85583 goto err_alloc_ctl;
85584
85585@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
85586 goto err_reg_dflt;
85587
85588 err = -ENOMEM;
85589- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85590+ if (!net_eq(net, &init_net))
85591+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85592+ else
85593+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
85594 if (forw_hdr == NULL)
85595 goto err_reg_ctl;
85596 net->ipv4.forw_hdr = forw_hdr;
85597@@ -1935,8 +1938,7 @@ err_reg_ctl:
85598 err_reg_dflt:
85599 __devinet_sysctl_unregister(all);
85600 err_reg_all:
85601- if (tbl != ctl_forward_entry)
85602- kfree(tbl);
85603+ kfree(tbl);
85604 err_alloc_ctl:
85605 #endif
85606 if (dflt != &ipv4_devconf_dflt)
85607diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
85608index 3b4f0cd..8cb864c 100644
85609--- a/net/ipv4/esp4.c
85610+++ b/net/ipv4/esp4.c
85611@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
85612 return;
85613
85614 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85615- atomic_inc(&flow_cache_genid);
85616+ atomic_inc_unchecked(&flow_cache_genid);
85617 rt_genid_bump(net);
85618
85619 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
85620diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
85621index 5cd75e2..f57ef39 100644
85622--- a/net/ipv4/fib_frontend.c
85623+++ b/net/ipv4/fib_frontend.c
85624@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
85625 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85626 fib_sync_up(dev);
85627 #endif
85628- atomic_inc(&net->ipv4.dev_addr_genid);
85629+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85630 rt_cache_flush(dev_net(dev));
85631 break;
85632 case NETDEV_DOWN:
85633 fib_del_ifaddr(ifa, NULL);
85634- atomic_inc(&net->ipv4.dev_addr_genid);
85635+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85636 if (ifa->ifa_dev->ifa_list == NULL) {
85637 /* Last address was deleted from this interface.
85638 * Disable IP.
85639@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
85640 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85641 fib_sync_up(dev);
85642 #endif
85643- atomic_inc(&net->ipv4.dev_addr_genid);
85644+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85645 rt_cache_flush(net);
85646 break;
85647 case NETDEV_DOWN:
85648diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
85649index 4797a80..2bd54e9 100644
85650--- a/net/ipv4/fib_semantics.c
85651+++ b/net/ipv4/fib_semantics.c
85652@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
85653 nh->nh_saddr = inet_select_addr(nh->nh_dev,
85654 nh->nh_gw,
85655 nh->nh_parent->fib_scope);
85656- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
85657+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
85658
85659 return nh->nh_saddr;
85660 }
85661diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
85662index d0670f0..744ac80 100644
85663--- a/net/ipv4/inet_connection_sock.c
85664+++ b/net/ipv4/inet_connection_sock.c
85665@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
85666 .range = { 32768, 61000 },
85667 };
85668
85669-unsigned long *sysctl_local_reserved_ports;
85670+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
85671 EXPORT_SYMBOL(sysctl_local_reserved_ports);
85672
85673 void inet_get_local_port_range(int *low, int *high)
85674diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
85675index fa3ae81..0dbe6b8 100644
85676--- a/net/ipv4/inet_hashtables.c
85677+++ b/net/ipv4/inet_hashtables.c
85678@@ -18,12 +18,15 @@
85679 #include <linux/sched.h>
85680 #include <linux/slab.h>
85681 #include <linux/wait.h>
85682+#include <linux/security.h>
85683
85684 #include <net/inet_connection_sock.h>
85685 #include <net/inet_hashtables.h>
85686 #include <net/secure_seq.h>
85687 #include <net/ip.h>
85688
85689+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
85690+
85691 /*
85692 * Allocate and initialize a new local port bind bucket.
85693 * The bindhash mutex for snum's hash chain must be held here.
85694@@ -540,6 +543,8 @@ ok:
85695 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
85696 spin_unlock(&head->lock);
85697
85698+ gr_update_task_in_ip_table(current, inet_sk(sk));
85699+
85700 if (tw) {
85701 inet_twsk_deschedule(tw, death_row);
85702 while (twrefcnt) {
85703diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
85704index 000e3d2..5472da3 100644
85705--- a/net/ipv4/inetpeer.c
85706+++ b/net/ipv4/inetpeer.c
85707@@ -503,8 +503,8 @@ relookup:
85708 if (p) {
85709 p->daddr = *daddr;
85710 atomic_set(&p->refcnt, 1);
85711- atomic_set(&p->rid, 0);
85712- atomic_set(&p->ip_id_count,
85713+ atomic_set_unchecked(&p->rid, 0);
85714+ atomic_set_unchecked(&p->ip_id_count,
85715 (daddr->family == AF_INET) ?
85716 secure_ip_id(daddr->addr.a4) :
85717 secure_ipv6_id(daddr->addr.a6));
85718diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
85719index eb9d63a..31c5372 100644
85720--- a/net/ipv4/ip_fragment.c
85721+++ b/net/ipv4/ip_fragment.c
85722@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
85723 return 0;
85724
85725 start = qp->rid;
85726- end = atomic_inc_return(&peer->rid);
85727+ end = atomic_inc_return_unchecked(&peer->rid);
85728 qp->rid = end;
85729
85730 rc = qp->q.fragments && (end - start) > max;
85731@@ -789,12 +789,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
85732
85733 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85734 {
85735- struct ctl_table *table;
85736+ ctl_table_no_const *table = NULL;
85737 struct ctl_table_header *hdr;
85738
85739- table = ip4_frags_ns_ctl_table;
85740 if (!net_eq(net, &init_net)) {
85741- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85742+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85743 if (table == NULL)
85744 goto err_alloc;
85745
85746@@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85747 /* Don't export sysctls to unprivileged users */
85748 if (net->user_ns != &init_user_ns)
85749 table[0].procname = NULL;
85750- }
85751+ hdr = register_net_sysctl(net, "net/ipv4", table);
85752+ } else
85753+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
85754
85755- hdr = register_net_sysctl(net, "net/ipv4", table);
85756 if (hdr == NULL)
85757 goto err_reg;
85758
85759@@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85760 return 0;
85761
85762 err_reg:
85763- if (!net_eq(net, &init_net))
85764- kfree(table);
85765+ kfree(table);
85766 err_alloc:
85767 return -ENOMEM;
85768 }
85769diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
85770index e81b1ca..6f3b5b9 100644
85771--- a/net/ipv4/ip_gre.c
85772+++ b/net/ipv4/ip_gre.c
85773@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85774 module_param(log_ecn_error, bool, 0644);
85775 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85776
85777-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85778+static struct rtnl_link_ops ipgre_link_ops;
85779 static int ipgre_tunnel_init(struct net_device *dev);
85780 static void ipgre_tunnel_setup(struct net_device *dev);
85781 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85782@@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85783 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85784 };
85785
85786-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85787+static struct rtnl_link_ops ipgre_link_ops = {
85788 .kind = "gre",
85789 .maxtype = IFLA_GRE_MAX,
85790 .policy = ipgre_policy,
85791@@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85792 .fill_info = ipgre_fill_info,
85793 };
85794
85795-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85796+static struct rtnl_link_ops ipgre_tap_ops = {
85797 .kind = "gretap",
85798 .maxtype = IFLA_GRE_MAX,
85799 .policy = ipgre_policy,
85800diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85801index d9c4f11..02b82db 100644
85802--- a/net/ipv4/ip_sockglue.c
85803+++ b/net/ipv4/ip_sockglue.c
85804@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85805 len = min_t(unsigned int, len, opt->optlen);
85806 if (put_user(len, optlen))
85807 return -EFAULT;
85808- if (copy_to_user(optval, opt->__data, len))
85809+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85810+ copy_to_user(optval, opt->__data, len))
85811 return -EFAULT;
85812 return 0;
85813 }
85814@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85815 if (sk->sk_type != SOCK_STREAM)
85816 return -ENOPROTOOPT;
85817
85818- msg.msg_control = optval;
85819+ msg.msg_control = (void __force_kernel *)optval;
85820 msg.msg_controllen = len;
85821 msg.msg_flags = flags;
85822
85823diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85824index c3a4233..1412161 100644
85825--- a/net/ipv4/ip_vti.c
85826+++ b/net/ipv4/ip_vti.c
85827@@ -47,7 +47,7 @@
85828 #define HASH_SIZE 16
85829 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
85830
85831-static struct rtnl_link_ops vti_link_ops __read_mostly;
85832+static struct rtnl_link_ops vti_link_ops;
85833
85834 static int vti_net_id __read_mostly;
85835 struct vti_net {
85836@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
85837 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
85838 };
85839
85840-static struct rtnl_link_ops vti_link_ops __read_mostly = {
85841+static struct rtnl_link_ops vti_link_ops = {
85842 .kind = "vti",
85843 .maxtype = IFLA_VTI_MAX,
85844 .policy = vti_policy,
85845diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
85846index 9a46dae..5f793a0 100644
85847--- a/net/ipv4/ipcomp.c
85848+++ b/net/ipv4/ipcomp.c
85849@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
85850 return;
85851
85852 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85853- atomic_inc(&flow_cache_genid);
85854+ atomic_inc_unchecked(&flow_cache_genid);
85855 rt_genid_bump(net);
85856
85857 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
85858diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
85859index a2e50ae..e152b7c 100644
85860--- a/net/ipv4/ipconfig.c
85861+++ b/net/ipv4/ipconfig.c
85862@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
85863
85864 mm_segment_t oldfs = get_fs();
85865 set_fs(get_ds());
85866- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85867+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85868 set_fs(oldfs);
85869 return res;
85870 }
85871@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
85872
85873 mm_segment_t oldfs = get_fs();
85874 set_fs(get_ds());
85875- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85876+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85877 set_fs(oldfs);
85878 return res;
85879 }
85880@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
85881
85882 mm_segment_t oldfs = get_fs();
85883 set_fs(get_ds());
85884- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
85885+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
85886 set_fs(oldfs);
85887 return res;
85888 }
85889diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
85890index 191fc24..1b3b804 100644
85891--- a/net/ipv4/ipip.c
85892+++ b/net/ipv4/ipip.c
85893@@ -138,7 +138,7 @@ struct ipip_net {
85894 static int ipip_tunnel_init(struct net_device *dev);
85895 static void ipip_tunnel_setup(struct net_device *dev);
85896 static void ipip_dev_free(struct net_device *dev);
85897-static struct rtnl_link_ops ipip_link_ops __read_mostly;
85898+static struct rtnl_link_ops ipip_link_ops;
85899
85900 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
85901 struct rtnl_link_stats64 *tot)
85902@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
85903 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
85904 };
85905
85906-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
85907+static struct rtnl_link_ops ipip_link_ops = {
85908 .kind = "ipip",
85909 .maxtype = IFLA_IPTUN_MAX,
85910 .policy = ipip_policy,
85911diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
85912index 3ea4127..849297b 100644
85913--- a/net/ipv4/netfilter/arp_tables.c
85914+++ b/net/ipv4/netfilter/arp_tables.c
85915@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
85916 #endif
85917
85918 static int get_info(struct net *net, void __user *user,
85919- const int *len, int compat)
85920+ int len, int compat)
85921 {
85922 char name[XT_TABLE_MAXNAMELEN];
85923 struct xt_table *t;
85924 int ret;
85925
85926- if (*len != sizeof(struct arpt_getinfo)) {
85927- duprintf("length %u != %Zu\n", *len,
85928+ if (len != sizeof(struct arpt_getinfo)) {
85929+ duprintf("length %u != %Zu\n", len,
85930 sizeof(struct arpt_getinfo));
85931 return -EINVAL;
85932 }
85933@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
85934 info.size = private->size;
85935 strcpy(info.name, name);
85936
85937- if (copy_to_user(user, &info, *len) != 0)
85938+ if (copy_to_user(user, &info, len) != 0)
85939 ret = -EFAULT;
85940 else
85941 ret = 0;
85942@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
85943
85944 switch (cmd) {
85945 case ARPT_SO_GET_INFO:
85946- ret = get_info(sock_net(sk), user, len, 1);
85947+ ret = get_info(sock_net(sk), user, *len, 1);
85948 break;
85949 case ARPT_SO_GET_ENTRIES:
85950 ret = compat_get_entries(sock_net(sk), user, len);
85951@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
85952
85953 switch (cmd) {
85954 case ARPT_SO_GET_INFO:
85955- ret = get_info(sock_net(sk), user, len, 0);
85956+ ret = get_info(sock_net(sk), user, *len, 0);
85957 break;
85958
85959 case ARPT_SO_GET_ENTRIES:
85960diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
85961index 17c5e06..1b91206 100644
85962--- a/net/ipv4/netfilter/ip_tables.c
85963+++ b/net/ipv4/netfilter/ip_tables.c
85964@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
85965 #endif
85966
85967 static int get_info(struct net *net, void __user *user,
85968- const int *len, int compat)
85969+ int len, int compat)
85970 {
85971 char name[XT_TABLE_MAXNAMELEN];
85972 struct xt_table *t;
85973 int ret;
85974
85975- if (*len != sizeof(struct ipt_getinfo)) {
85976- duprintf("length %u != %zu\n", *len,
85977+ if (len != sizeof(struct ipt_getinfo)) {
85978+ duprintf("length %u != %zu\n", len,
85979 sizeof(struct ipt_getinfo));
85980 return -EINVAL;
85981 }
85982@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
85983 info.size = private->size;
85984 strcpy(info.name, name);
85985
85986- if (copy_to_user(user, &info, *len) != 0)
85987+ if (copy_to_user(user, &info, len) != 0)
85988 ret = -EFAULT;
85989 else
85990 ret = 0;
85991@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85992
85993 switch (cmd) {
85994 case IPT_SO_GET_INFO:
85995- ret = get_info(sock_net(sk), user, len, 1);
85996+ ret = get_info(sock_net(sk), user, *len, 1);
85997 break;
85998 case IPT_SO_GET_ENTRIES:
85999 ret = compat_get_entries(sock_net(sk), user, len);
86000@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86001
86002 switch (cmd) {
86003 case IPT_SO_GET_INFO:
86004- ret = get_info(sock_net(sk), user, len, 0);
86005+ ret = get_info(sock_net(sk), user, *len, 0);
86006 break;
86007
86008 case IPT_SO_GET_ENTRIES:
86009diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
86010index dc454cc..5bb917f 100644
86011--- a/net/ipv4/ping.c
86012+++ b/net/ipv4/ping.c
86013@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
86014 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86015 0, sock_i_ino(sp),
86016 atomic_read(&sp->sk_refcnt), sp,
86017- atomic_read(&sp->sk_drops), len);
86018+ atomic_read_unchecked(&sp->sk_drops), len);
86019 }
86020
86021 static int ping_seq_show(struct seq_file *seq, void *v)
86022diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
86023index 6f08991..55867ad 100644
86024--- a/net/ipv4/raw.c
86025+++ b/net/ipv4/raw.c
86026@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
86027 int raw_rcv(struct sock *sk, struct sk_buff *skb)
86028 {
86029 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
86030- atomic_inc(&sk->sk_drops);
86031+ atomic_inc_unchecked(&sk->sk_drops);
86032 kfree_skb(skb);
86033 return NET_RX_DROP;
86034 }
86035@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
86036
86037 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
86038 {
86039+ struct icmp_filter filter;
86040+
86041 if (optlen > sizeof(struct icmp_filter))
86042 optlen = sizeof(struct icmp_filter);
86043- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
86044+ if (copy_from_user(&filter, optval, optlen))
86045 return -EFAULT;
86046+ raw_sk(sk)->filter = filter;
86047 return 0;
86048 }
86049
86050 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
86051 {
86052 int len, ret = -EFAULT;
86053+ struct icmp_filter filter;
86054
86055 if (get_user(len, optlen))
86056 goto out;
86057@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
86058 if (len > sizeof(struct icmp_filter))
86059 len = sizeof(struct icmp_filter);
86060 ret = -EFAULT;
86061- if (put_user(len, optlen) ||
86062- copy_to_user(optval, &raw_sk(sk)->filter, len))
86063+ filter = raw_sk(sk)->filter;
86064+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
86065 goto out;
86066 ret = 0;
86067 out: return ret;
86068@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86069 0, 0L, 0,
86070 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86071 0, sock_i_ino(sp),
86072- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86073+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86074 }
86075
86076 static int raw_seq_show(struct seq_file *seq, void *v)
86077diff --git a/net/ipv4/route.c b/net/ipv4/route.c
86078index a0fcc47..32e2c89 100644
86079--- a/net/ipv4/route.c
86080+++ b/net/ipv4/route.c
86081@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
86082 .maxlen = sizeof(int),
86083 .mode = 0200,
86084 .proc_handler = ipv4_sysctl_rtcache_flush,
86085+ .extra1 = &init_net,
86086 },
86087 { },
86088 };
86089
86090 static __net_init int sysctl_route_net_init(struct net *net)
86091 {
86092- struct ctl_table *tbl;
86093+ ctl_table_no_const *tbl = NULL;
86094
86095- tbl = ipv4_route_flush_table;
86096 if (!net_eq(net, &init_net)) {
86097- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86098+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86099 if (tbl == NULL)
86100 goto err_dup;
86101
86102 /* Don't export sysctls to unprivileged users */
86103 if (net->user_ns != &init_user_ns)
86104 tbl[0].procname = NULL;
86105- }
86106- tbl[0].extra1 = net;
86107+ tbl[0].extra1 = net;
86108+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86109+ } else
86110+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
86111
86112- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86113 if (net->ipv4.route_hdr == NULL)
86114 goto err_reg;
86115 return 0;
86116
86117 err_reg:
86118- if (tbl != ipv4_route_flush_table)
86119- kfree(tbl);
86120+ kfree(tbl);
86121 err_dup:
86122 return -ENOMEM;
86123 }
86124@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
86125
86126 static __net_init int rt_genid_init(struct net *net)
86127 {
86128- atomic_set(&net->rt_genid, 0);
86129+ atomic_set_unchecked(&net->rt_genid, 0);
86130 get_random_bytes(&net->ipv4.dev_addr_genid,
86131 sizeof(net->ipv4.dev_addr_genid));
86132 return 0;
86133diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
86134index d84400b..62e066e 100644
86135--- a/net/ipv4/sysctl_net_ipv4.c
86136+++ b/net/ipv4/sysctl_net_ipv4.c
86137@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
86138 {
86139 int ret;
86140 int range[2];
86141- ctl_table tmp = {
86142+ ctl_table_no_const tmp = {
86143 .data = &range,
86144 .maxlen = sizeof(range),
86145 .mode = table->mode,
86146@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
86147 int ret;
86148 gid_t urange[2];
86149 kgid_t low, high;
86150- ctl_table tmp = {
86151+ ctl_table_no_const tmp = {
86152 .data = &urange,
86153 .maxlen = sizeof(urange),
86154 .mode = table->mode,
86155@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
86156 void __user *buffer, size_t *lenp, loff_t *ppos)
86157 {
86158 char val[TCP_CA_NAME_MAX];
86159- ctl_table tbl = {
86160+ ctl_table_no_const tbl = {
86161 .data = val,
86162 .maxlen = TCP_CA_NAME_MAX,
86163 };
86164@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
86165 void __user *buffer, size_t *lenp,
86166 loff_t *ppos)
86167 {
86168- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
86169+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
86170 int ret;
86171
86172 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86173@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
86174 void __user *buffer, size_t *lenp,
86175 loff_t *ppos)
86176 {
86177- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
86178+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
86179 int ret;
86180
86181 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86182@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86183 struct mem_cgroup *memcg;
86184 #endif
86185
86186- ctl_table tmp = {
86187+ ctl_table_no_const tmp = {
86188 .data = &vec,
86189 .maxlen = sizeof(vec),
86190 .mode = ctl->mode,
86191 };
86192
86193 if (!write) {
86194- ctl->data = &net->ipv4.sysctl_tcp_mem;
86195- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
86196+ ctl_table_no_const tcp_mem = *ctl;
86197+
86198+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
86199+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
86200 }
86201
86202 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
86203@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86204 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
86205 size_t *lenp, loff_t *ppos)
86206 {
86207- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86208+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86209 struct tcp_fastopen_context *ctxt;
86210 int ret;
86211 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
86212@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
86213 },
86214 {
86215 .procname = "ip_local_reserved_ports",
86216- .data = NULL, /* initialized in sysctl_ipv4_init */
86217+ .data = sysctl_local_reserved_ports,
86218 .maxlen = 65536,
86219 .mode = 0644,
86220 .proc_handler = proc_do_large_bitmap,
86221@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
86222
86223 static __net_init int ipv4_sysctl_init_net(struct net *net)
86224 {
86225- struct ctl_table *table;
86226+ ctl_table_no_const *table = NULL;
86227
86228- table = ipv4_net_table;
86229 if (!net_eq(net, &init_net)) {
86230- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
86231+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
86232 if (table == NULL)
86233 goto err_alloc;
86234
86235@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
86236
86237 tcp_init_mem(net);
86238
86239- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86240+ if (!net_eq(net, &init_net))
86241+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86242+ else
86243+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
86244 if (net->ipv4.ipv4_hdr == NULL)
86245 goto err_reg;
86246
86247 return 0;
86248
86249 err_reg:
86250- if (!net_eq(net, &init_net))
86251- kfree(table);
86252+ kfree(table);
86253 err_alloc:
86254 return -ENOMEM;
86255 }
86256@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
86257 static __init int sysctl_ipv4_init(void)
86258 {
86259 struct ctl_table_header *hdr;
86260- struct ctl_table *i;
86261-
86262- for (i = ipv4_table; i->procname; i++) {
86263- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
86264- i->data = sysctl_local_reserved_ports;
86265- break;
86266- }
86267- }
86268- if (!i->procname)
86269- return -EINVAL;
86270
86271 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
86272 if (hdr == NULL)
86273diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
86274index 66702d3..31ff8f9 100644
86275--- a/net/ipv4/tcp_input.c
86276+++ b/net/ipv4/tcp_input.c
86277@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
86278 * simplifies code)
86279 */
86280 static void
86281-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86282+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86283 struct sk_buff *head, struct sk_buff *tail,
86284 u32 start, u32 end)
86285 {
86286@@ -5850,6 +5850,7 @@ discard:
86287 tcp_paws_reject(&tp->rx_opt, 0))
86288 goto discard_and_undo;
86289
86290+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
86291 if (th->syn) {
86292 /* We see SYN without ACK. It is attempt of
86293 * simultaneous connect with crossed SYNs.
86294@@ -5900,6 +5901,7 @@ discard:
86295 goto discard;
86296 #endif
86297 }
86298+#endif
86299 /* "fifth, if neither of the SYN or RST bits is set then
86300 * drop the segment and return."
86301 */
86302@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
86303 goto discard;
86304
86305 if (th->syn) {
86306- if (th->fin)
86307+ if (th->fin || th->urg || th->psh)
86308 goto discard;
86309 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
86310 return 1;
86311diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
86312index eadb693..e8f7251 100644
86313--- a/net/ipv4/tcp_ipv4.c
86314+++ b/net/ipv4/tcp_ipv4.c
86315@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
86316 EXPORT_SYMBOL(sysctl_tcp_low_latency);
86317
86318
86319+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86320+extern int grsec_enable_blackhole;
86321+#endif
86322+
86323 #ifdef CONFIG_TCP_MD5SIG
86324 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
86325 __be32 daddr, __be32 saddr, const struct tcphdr *th);
86326@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
86327 return 0;
86328
86329 reset:
86330+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86331+ if (!grsec_enable_blackhole)
86332+#endif
86333 tcp_v4_send_reset(rsk, skb);
86334 discard:
86335 kfree_skb(skb);
86336@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
86337 TCP_SKB_CB(skb)->sacked = 0;
86338
86339 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86340- if (!sk)
86341+ if (!sk) {
86342+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86343+ ret = 1;
86344+#endif
86345 goto no_tcp_socket;
86346-
86347+ }
86348 process:
86349- if (sk->sk_state == TCP_TIME_WAIT)
86350+ if (sk->sk_state == TCP_TIME_WAIT) {
86351+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86352+ ret = 2;
86353+#endif
86354 goto do_time_wait;
86355+ }
86356
86357 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
86358 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86359@@ -2050,6 +2064,10 @@ no_tcp_socket:
86360 bad_packet:
86361 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86362 } else {
86363+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86364+ if (!grsec_enable_blackhole || (ret == 1 &&
86365+ (skb->dev->flags & IFF_LOOPBACK)))
86366+#endif
86367 tcp_v4_send_reset(NULL, skb);
86368 }
86369
86370diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
86371index f35f2df..ccb5ca6 100644
86372--- a/net/ipv4/tcp_minisocks.c
86373+++ b/net/ipv4/tcp_minisocks.c
86374@@ -27,6 +27,10 @@
86375 #include <net/inet_common.h>
86376 #include <net/xfrm.h>
86377
86378+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86379+extern int grsec_enable_blackhole;
86380+#endif
86381+
86382 int sysctl_tcp_syncookies __read_mostly = 1;
86383 EXPORT_SYMBOL(sysctl_tcp_syncookies);
86384
86385@@ -742,7 +746,10 @@ embryonic_reset:
86386 * avoid becoming vulnerable to outside attack aiming at
86387 * resetting legit local connections.
86388 */
86389- req->rsk_ops->send_reset(sk, skb);
86390+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86391+ if (!grsec_enable_blackhole)
86392+#endif
86393+ req->rsk_ops->send_reset(sk, skb);
86394 } else if (fastopen) { /* received a valid RST pkt */
86395 reqsk_fastopen_remove(sk, req, true);
86396 tcp_reset(sk);
86397diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
86398index 4526fe6..1a34e43 100644
86399--- a/net/ipv4/tcp_probe.c
86400+++ b/net/ipv4/tcp_probe.c
86401@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
86402 if (cnt + width >= len)
86403 break;
86404
86405- if (copy_to_user(buf + cnt, tbuf, width))
86406+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
86407 return -EFAULT;
86408 cnt += width;
86409 }
86410diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
86411index b78aac3..e18230b 100644
86412--- a/net/ipv4/tcp_timer.c
86413+++ b/net/ipv4/tcp_timer.c
86414@@ -22,6 +22,10 @@
86415 #include <linux/gfp.h>
86416 #include <net/tcp.h>
86417
86418+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86419+extern int grsec_lastack_retries;
86420+#endif
86421+
86422 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
86423 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
86424 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
86425@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
86426 }
86427 }
86428
86429+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86430+ if ((sk->sk_state == TCP_LAST_ACK) &&
86431+ (grsec_lastack_retries > 0) &&
86432+ (grsec_lastack_retries < retry_until))
86433+ retry_until = grsec_lastack_retries;
86434+#endif
86435+
86436 if (retransmits_timed_out(sk, retry_until,
86437 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
86438 /* Has it gone just too far? */
86439diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
86440index 1f4d405..3524677 100644
86441--- a/net/ipv4/udp.c
86442+++ b/net/ipv4/udp.c
86443@@ -87,6 +87,7 @@
86444 #include <linux/types.h>
86445 #include <linux/fcntl.h>
86446 #include <linux/module.h>
86447+#include <linux/security.h>
86448 #include <linux/socket.h>
86449 #include <linux/sockios.h>
86450 #include <linux/igmp.h>
86451@@ -111,6 +112,10 @@
86452 #include <trace/events/skb.h>
86453 #include "udp_impl.h"
86454
86455+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86456+extern int grsec_enable_blackhole;
86457+#endif
86458+
86459 struct udp_table udp_table __read_mostly;
86460 EXPORT_SYMBOL(udp_table);
86461
86462@@ -569,6 +574,9 @@ found:
86463 return s;
86464 }
86465
86466+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
86467+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
86468+
86469 /*
86470 * This routine is called by the ICMP module when it gets some
86471 * sort of error condition. If err < 0 then the socket should
86472@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
86473 dport = usin->sin_port;
86474 if (dport == 0)
86475 return -EINVAL;
86476+
86477+ err = gr_search_udp_sendmsg(sk, usin);
86478+ if (err)
86479+ return err;
86480 } else {
86481 if (sk->sk_state != TCP_ESTABLISHED)
86482 return -EDESTADDRREQ;
86483+
86484+ err = gr_search_udp_sendmsg(sk, NULL);
86485+ if (err)
86486+ return err;
86487+
86488 daddr = inet->inet_daddr;
86489 dport = inet->inet_dport;
86490 /* Open fast path for connected socket.
86491@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
86492 udp_lib_checksum_complete(skb)) {
86493 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86494 IS_UDPLITE(sk));
86495- atomic_inc(&sk->sk_drops);
86496+ atomic_inc_unchecked(&sk->sk_drops);
86497 __skb_unlink(skb, rcvq);
86498 __skb_queue_tail(&list_kill, skb);
86499 }
86500@@ -1194,6 +1211,10 @@ try_again:
86501 if (!skb)
86502 goto out;
86503
86504+ err = gr_search_udp_recvmsg(sk, skb);
86505+ if (err)
86506+ goto out_free;
86507+
86508 ulen = skb->len - sizeof(struct udphdr);
86509 copied = len;
86510 if (copied > ulen)
86511@@ -1227,7 +1248,7 @@ try_again:
86512 if (unlikely(err)) {
86513 trace_kfree_skb(skb, udp_recvmsg);
86514 if (!peeked) {
86515- atomic_inc(&sk->sk_drops);
86516+ atomic_inc_unchecked(&sk->sk_drops);
86517 UDP_INC_STATS_USER(sock_net(sk),
86518 UDP_MIB_INERRORS, is_udplite);
86519 }
86520@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86521
86522 drop:
86523 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86524- atomic_inc(&sk->sk_drops);
86525+ atomic_inc_unchecked(&sk->sk_drops);
86526 kfree_skb(skb);
86527 return -1;
86528 }
86529@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86530 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86531
86532 if (!skb1) {
86533- atomic_inc(&sk->sk_drops);
86534+ atomic_inc_unchecked(&sk->sk_drops);
86535 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86536 IS_UDPLITE(sk));
86537 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86538@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86539 goto csum_error;
86540
86541 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86542+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86543+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86544+#endif
86545 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
86546
86547 /*
86548@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
86549 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86550 0, sock_i_ino(sp),
86551 atomic_read(&sp->sk_refcnt), sp,
86552- atomic_read(&sp->sk_drops), len);
86553+ atomic_read_unchecked(&sp->sk_drops), len);
86554 }
86555
86556 int udp4_seq_show(struct seq_file *seq, void *v)
86557diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
86558index 1b5d8cb..ffb0833 100644
86559--- a/net/ipv6/addrconf.c
86560+++ b/net/ipv6/addrconf.c
86561@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
86562 p.iph.ihl = 5;
86563 p.iph.protocol = IPPROTO_IPV6;
86564 p.iph.ttl = 64;
86565- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
86566+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
86567
86568 if (ops->ndo_do_ioctl) {
86569 mm_segment_t oldfs = get_fs();
86570@@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
86571 int *valp = ctl->data;
86572 int val = *valp;
86573 loff_t pos = *ppos;
86574- ctl_table lctl;
86575+ ctl_table_no_const lctl;
86576 int ret;
86577
86578 /*
86579@@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
86580 int *valp = ctl->data;
86581 int val = *valp;
86582 loff_t pos = *ppos;
86583- ctl_table lctl;
86584+ ctl_table_no_const lctl;
86585 int ret;
86586
86587 /*
86588diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
86589index fff5bdd..15194fb 100644
86590--- a/net/ipv6/icmp.c
86591+++ b/net/ipv6/icmp.c
86592@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
86593
86594 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
86595 {
86596- struct ctl_table *table;
86597+ ctl_table_no_const *table;
86598
86599 table = kmemdup(ipv6_icmp_table_template,
86600 sizeof(ipv6_icmp_table_template),
86601diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
86602index 131dd09..f7ed64f 100644
86603--- a/net/ipv6/ip6_gre.c
86604+++ b/net/ipv6/ip6_gre.c
86605@@ -73,7 +73,7 @@ struct ip6gre_net {
86606 struct net_device *fb_tunnel_dev;
86607 };
86608
86609-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
86610+static struct rtnl_link_ops ip6gre_link_ops;
86611 static int ip6gre_tunnel_init(struct net_device *dev);
86612 static void ip6gre_tunnel_setup(struct net_device *dev);
86613 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
86614@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
86615 }
86616
86617
86618-static struct inet6_protocol ip6gre_protocol __read_mostly = {
86619+static struct inet6_protocol ip6gre_protocol = {
86620 .handler = ip6gre_rcv,
86621 .err_handler = ip6gre_err,
86622 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
86623@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
86624 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
86625 };
86626
86627-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86628+static struct rtnl_link_ops ip6gre_link_ops = {
86629 .kind = "ip6gre",
86630 .maxtype = IFLA_GRE_MAX,
86631 .policy = ip6gre_policy,
86632@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86633 .fill_info = ip6gre_fill_info,
86634 };
86635
86636-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
86637+static struct rtnl_link_ops ip6gre_tap_ops = {
86638 .kind = "ip6gretap",
86639 .maxtype = IFLA_GRE_MAX,
86640 .policy = ip6gre_policy,
86641diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
86642index a14f28b..b4b8956 100644
86643--- a/net/ipv6/ip6_tunnel.c
86644+++ b/net/ipv6/ip6_tunnel.c
86645@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
86646
86647 static int ip6_tnl_dev_init(struct net_device *dev);
86648 static void ip6_tnl_dev_setup(struct net_device *dev);
86649-static struct rtnl_link_ops ip6_link_ops __read_mostly;
86650+static struct rtnl_link_ops ip6_link_ops;
86651
86652 static int ip6_tnl_net_id __read_mostly;
86653 struct ip6_tnl_net {
86654@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
86655 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
86656 };
86657
86658-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
86659+static struct rtnl_link_ops ip6_link_ops = {
86660 .kind = "ip6tnl",
86661 .maxtype = IFLA_IPTUN_MAX,
86662 .policy = ip6_tnl_policy,
86663diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
86664index d1e2e8e..51c19ae 100644
86665--- a/net/ipv6/ipv6_sockglue.c
86666+++ b/net/ipv6/ipv6_sockglue.c
86667@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
86668 if (sk->sk_type != SOCK_STREAM)
86669 return -ENOPROTOOPT;
86670
86671- msg.msg_control = optval;
86672+ msg.msg_control = (void __force_kernel *)optval;
86673 msg.msg_controllen = len;
86674 msg.msg_flags = flags;
86675
86676diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
86677index 125a90d..2a11f36 100644
86678--- a/net/ipv6/netfilter/ip6_tables.c
86679+++ b/net/ipv6/netfilter/ip6_tables.c
86680@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
86681 #endif
86682
86683 static int get_info(struct net *net, void __user *user,
86684- const int *len, int compat)
86685+ int len, int compat)
86686 {
86687 char name[XT_TABLE_MAXNAMELEN];
86688 struct xt_table *t;
86689 int ret;
86690
86691- if (*len != sizeof(struct ip6t_getinfo)) {
86692- duprintf("length %u != %zu\n", *len,
86693+ if (len != sizeof(struct ip6t_getinfo)) {
86694+ duprintf("length %u != %zu\n", len,
86695 sizeof(struct ip6t_getinfo));
86696 return -EINVAL;
86697 }
86698@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
86699 info.size = private->size;
86700 strcpy(info.name, name);
86701
86702- if (copy_to_user(user, &info, *len) != 0)
86703+ if (copy_to_user(user, &info, len) != 0)
86704 ret = -EFAULT;
86705 else
86706 ret = 0;
86707@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86708
86709 switch (cmd) {
86710 case IP6T_SO_GET_INFO:
86711- ret = get_info(sock_net(sk), user, len, 1);
86712+ ret = get_info(sock_net(sk), user, *len, 1);
86713 break;
86714 case IP6T_SO_GET_ENTRIES:
86715 ret = compat_get_entries(sock_net(sk), user, len);
86716@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86717
86718 switch (cmd) {
86719 case IP6T_SO_GET_INFO:
86720- ret = get_info(sock_net(sk), user, len, 0);
86721+ ret = get_info(sock_net(sk), user, *len, 0);
86722 break;
86723
86724 case IP6T_SO_GET_ENTRIES:
86725diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
86726index 3dacecc..2939087 100644
86727--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
86728+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
86729@@ -87,12 +87,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
86730
86731 static int nf_ct_frag6_sysctl_register(struct net *net)
86732 {
86733- struct ctl_table *table;
86734+ ctl_table_no_const *table = NULL;
86735 struct ctl_table_header *hdr;
86736
86737- table = nf_ct_frag6_sysctl_table;
86738 if (!net_eq(net, &init_net)) {
86739- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
86740+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
86741 GFP_KERNEL);
86742 if (table == NULL)
86743 goto err_alloc;
86744@@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86745 table[0].data = &net->ipv6.frags.high_thresh;
86746 table[1].data = &net->ipv6.frags.low_thresh;
86747 table[2].data = &net->ipv6.frags.timeout;
86748- }
86749-
86750- hdr = register_net_sysctl(net, "net/netfilter", table);
86751+ hdr = register_net_sysctl(net, "net/netfilter", table);
86752+ } else
86753+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
86754 if (hdr == NULL)
86755 goto err_reg;
86756
86757@@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86758 return 0;
86759
86760 err_reg:
86761- if (!net_eq(net, &init_net))
86762- kfree(table);
86763+ kfree(table);
86764 err_alloc:
86765 return -ENOMEM;
86766 }
86767diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
86768index 70fa814..d70c28c 100644
86769--- a/net/ipv6/raw.c
86770+++ b/net/ipv6/raw.c
86771@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
86772 {
86773 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86774 skb_checksum_complete(skb)) {
86775- atomic_inc(&sk->sk_drops);
86776+ atomic_inc_unchecked(&sk->sk_drops);
86777 kfree_skb(skb);
86778 return NET_RX_DROP;
86779 }
86780@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86781 struct raw6_sock *rp = raw6_sk(sk);
86782
86783 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86784- atomic_inc(&sk->sk_drops);
86785+ atomic_inc_unchecked(&sk->sk_drops);
86786 kfree_skb(skb);
86787 return NET_RX_DROP;
86788 }
86789@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86790
86791 if (inet->hdrincl) {
86792 if (skb_checksum_complete(skb)) {
86793- atomic_inc(&sk->sk_drops);
86794+ atomic_inc_unchecked(&sk->sk_drops);
86795 kfree_skb(skb);
86796 return NET_RX_DROP;
86797 }
86798@@ -604,7 +604,7 @@ out:
86799 return err;
86800 }
86801
86802-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86803+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86804 struct flowi6 *fl6, struct dst_entry **dstp,
86805 unsigned int flags)
86806 {
86807@@ -916,12 +916,15 @@ do_confirm:
86808 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86809 char __user *optval, int optlen)
86810 {
86811+ struct icmp6_filter filter;
86812+
86813 switch (optname) {
86814 case ICMPV6_FILTER:
86815 if (optlen > sizeof(struct icmp6_filter))
86816 optlen = sizeof(struct icmp6_filter);
86817- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86818+ if (copy_from_user(&filter, optval, optlen))
86819 return -EFAULT;
86820+ raw6_sk(sk)->filter = filter;
86821 return 0;
86822 default:
86823 return -ENOPROTOOPT;
86824@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86825 char __user *optval, int __user *optlen)
86826 {
86827 int len;
86828+ struct icmp6_filter filter;
86829
86830 switch (optname) {
86831 case ICMPV6_FILTER:
86832@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86833 len = sizeof(struct icmp6_filter);
86834 if (put_user(len, optlen))
86835 return -EFAULT;
86836- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
86837+ filter = raw6_sk(sk)->filter;
86838+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
86839 return -EFAULT;
86840 return 0;
86841 default:
86842@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86843 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86844 0,
86845 sock_i_ino(sp),
86846- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86847+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86848 }
86849
86850 static int raw6_seq_show(struct seq_file *seq, void *v)
86851diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
86852index e5253ec..0410257 100644
86853--- a/net/ipv6/reassembly.c
86854+++ b/net/ipv6/reassembly.c
86855@@ -604,12 +604,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
86856
86857 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86858 {
86859- struct ctl_table *table;
86860+ ctl_table_no_const *table = NULL;
86861 struct ctl_table_header *hdr;
86862
86863- table = ip6_frags_ns_ctl_table;
86864 if (!net_eq(net, &init_net)) {
86865- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86866+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86867 if (table == NULL)
86868 goto err_alloc;
86869
86870@@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86871 /* Don't export sysctls to unprivileged users */
86872 if (net->user_ns != &init_user_ns)
86873 table[0].procname = NULL;
86874- }
86875+ hdr = register_net_sysctl(net, "net/ipv6", table);
86876+ } else
86877+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
86878
86879- hdr = register_net_sysctl(net, "net/ipv6", table);
86880 if (hdr == NULL)
86881 goto err_reg;
86882
86883@@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86884 return 0;
86885
86886 err_reg:
86887- if (!net_eq(net, &init_net))
86888- kfree(table);
86889+ kfree(table);
86890 err_alloc:
86891 return -ENOMEM;
86892 }
86893diff --git a/net/ipv6/route.c b/net/ipv6/route.c
86894index 5845613..3af8fc7 100644
86895--- a/net/ipv6/route.c
86896+++ b/net/ipv6/route.c
86897@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
86898
86899 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
86900 {
86901- struct ctl_table *table;
86902+ ctl_table_no_const *table;
86903
86904 table = kmemdup(ipv6_route_table_template,
86905 sizeof(ipv6_route_table_template),
86906diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
86907index cfba99b..20ca511 100644
86908--- a/net/ipv6/sit.c
86909+++ b/net/ipv6/sit.c
86910@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86911 static int ipip6_tunnel_init(struct net_device *dev);
86912 static void ipip6_tunnel_setup(struct net_device *dev);
86913 static void ipip6_dev_free(struct net_device *dev);
86914-static struct rtnl_link_ops sit_link_ops __read_mostly;
86915+static struct rtnl_link_ops sit_link_ops;
86916
86917 static int sit_net_id __read_mostly;
86918 struct sit_net {
86919@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
86920 #endif
86921 };
86922
86923-static struct rtnl_link_ops sit_link_ops __read_mostly = {
86924+static struct rtnl_link_ops sit_link_ops = {
86925 .kind = "sit",
86926 .maxtype = IFLA_IPTUN_MAX,
86927 .policy = ipip6_policy,
86928diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
86929index e85c48b..b8268d3 100644
86930--- a/net/ipv6/sysctl_net_ipv6.c
86931+++ b/net/ipv6/sysctl_net_ipv6.c
86932@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
86933
86934 static int __net_init ipv6_sysctl_net_init(struct net *net)
86935 {
86936- struct ctl_table *ipv6_table;
86937+ ctl_table_no_const *ipv6_table;
86938 struct ctl_table *ipv6_route_table;
86939 struct ctl_table *ipv6_icmp_table;
86940 int err;
86941diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
86942index 4f435371..5de9da7 100644
86943--- a/net/ipv6/tcp_ipv6.c
86944+++ b/net/ipv6/tcp_ipv6.c
86945@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
86946 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
86947 }
86948
86949+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86950+extern int grsec_enable_blackhole;
86951+#endif
86952+
86953 static void tcp_v6_hash(struct sock *sk)
86954 {
86955 if (sk->sk_state != TCP_CLOSE) {
86956@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
86957 return 0;
86958
86959 reset:
86960+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86961+ if (!grsec_enable_blackhole)
86962+#endif
86963 tcp_v6_send_reset(sk, skb);
86964 discard:
86965 if (opt_skb)
86966@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
86967 TCP_SKB_CB(skb)->sacked = 0;
86968
86969 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86970- if (!sk)
86971+ if (!sk) {
86972+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86973+ ret = 1;
86974+#endif
86975 goto no_tcp_socket;
86976+ }
86977
86978 process:
86979- if (sk->sk_state == TCP_TIME_WAIT)
86980+ if (sk->sk_state == TCP_TIME_WAIT) {
86981+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86982+ ret = 2;
86983+#endif
86984 goto do_time_wait;
86985+ }
86986
86987 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
86988 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86989@@ -1568,6 +1583,10 @@ no_tcp_socket:
86990 bad_packet:
86991 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86992 } else {
86993+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86994+ if (!grsec_enable_blackhole || (ret == 1 &&
86995+ (skb->dev->flags & IFF_LOOPBACK)))
86996+#endif
86997 tcp_v6_send_reset(NULL, skb);
86998 }
86999
87000diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
87001index fb08329..2d6919e 100644
87002--- a/net/ipv6/udp.c
87003+++ b/net/ipv6/udp.c
87004@@ -51,6 +51,10 @@
87005 #include <trace/events/skb.h>
87006 #include "udp_impl.h"
87007
87008+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87009+extern int grsec_enable_blackhole;
87010+#endif
87011+
87012 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
87013 {
87014 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
87015@@ -395,7 +399,7 @@ try_again:
87016 if (unlikely(err)) {
87017 trace_kfree_skb(skb, udpv6_recvmsg);
87018 if (!peeked) {
87019- atomic_inc(&sk->sk_drops);
87020+ atomic_inc_unchecked(&sk->sk_drops);
87021 if (is_udp4)
87022 UDP_INC_STATS_USER(sock_net(sk),
87023 UDP_MIB_INERRORS,
87024@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87025 return rc;
87026 drop:
87027 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87028- atomic_inc(&sk->sk_drops);
87029+ atomic_inc_unchecked(&sk->sk_drops);
87030 kfree_skb(skb);
87031 return -1;
87032 }
87033@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87034 if (likely(skb1 == NULL))
87035 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87036 if (!skb1) {
87037- atomic_inc(&sk->sk_drops);
87038+ atomic_inc_unchecked(&sk->sk_drops);
87039 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87040 IS_UDPLITE(sk));
87041 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87042@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87043 goto discard;
87044
87045 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87046+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87047+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87048+#endif
87049 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
87050
87051 kfree_skb(skb);
87052@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
87053 0,
87054 sock_i_ino(sp),
87055 atomic_read(&sp->sk_refcnt), sp,
87056- atomic_read(&sp->sk_drops));
87057+ atomic_read_unchecked(&sp->sk_drops));
87058 }
87059
87060 int udp6_seq_show(struct seq_file *seq, void *v)
87061diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
87062index b833677..4d04105 100644
87063--- a/net/irda/af_irda.c
87064+++ b/net/irda/af_irda.c
87065@@ -2584,8 +2584,10 @@ bed:
87066 NULL, NULL, NULL);
87067
87068 /* Check if the we got some results */
87069- if (!self->cachedaddr)
87070- return -EAGAIN; /* Didn't find any devices */
87071+ if (!self->cachedaddr) {
87072+ err = -EAGAIN; /* Didn't find any devices */
87073+ goto out;
87074+ }
87075 daddr = self->cachedaddr;
87076 /* Cleanup */
87077 self->cachedaddr = 0;
87078diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
87079index a68c88c..d55b0c5 100644
87080--- a/net/irda/ircomm/ircomm_tty.c
87081+++ b/net/irda/ircomm/ircomm_tty.c
87082@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87083 add_wait_queue(&port->open_wait, &wait);
87084
87085 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
87086- __FILE__, __LINE__, tty->driver->name, port->count);
87087+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87088
87089 spin_lock_irqsave(&port->lock, flags);
87090 if (!tty_hung_up_p(filp)) {
87091 extra_count = 1;
87092- port->count--;
87093+ atomic_dec(&port->count);
87094 }
87095 spin_unlock_irqrestore(&port->lock, flags);
87096 port->blocked_open++;
87097@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87098 }
87099
87100 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
87101- __FILE__, __LINE__, tty->driver->name, port->count);
87102+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87103
87104 schedule();
87105 }
87106@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87107 if (extra_count) {
87108 /* ++ is not atomic, so this should be protected - Jean II */
87109 spin_lock_irqsave(&port->lock, flags);
87110- port->count++;
87111+ atomic_inc(&port->count);
87112 spin_unlock_irqrestore(&port->lock, flags);
87113 }
87114 port->blocked_open--;
87115
87116 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
87117- __FILE__, __LINE__, tty->driver->name, port->count);
87118+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87119
87120 if (!retval)
87121 port->flags |= ASYNC_NORMAL_ACTIVE;
87122@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
87123
87124 /* ++ is not atomic, so this should be protected - Jean II */
87125 spin_lock_irqsave(&self->port.lock, flags);
87126- self->port.count++;
87127+ atomic_inc(&self->port.count);
87128 spin_unlock_irqrestore(&self->port.lock, flags);
87129 tty_port_tty_set(&self->port, tty);
87130
87131 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
87132- self->line, self->port.count);
87133+ self->line, atomic_read(&self->port.count));
87134
87135 /* Not really used by us, but lets do it anyway */
87136 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
87137@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
87138 tty_kref_put(port->tty);
87139 }
87140 port->tty = NULL;
87141- port->count = 0;
87142+ atomic_set(&port->count, 0);
87143 spin_unlock_irqrestore(&port->lock, flags);
87144
87145 wake_up_interruptible(&port->open_wait);
87146@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
87147 seq_putc(m, '\n');
87148
87149 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
87150- seq_printf(m, "Open count: %d\n", self->port.count);
87151+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
87152 seq_printf(m, "Max data size: %d\n", self->max_data_size);
87153 seq_printf(m, "Max header size: %d\n", self->max_header_size);
87154
87155diff --git a/net/irda/iriap.c b/net/irda/iriap.c
87156index e71e85b..29340a9 100644
87157--- a/net/irda/iriap.c
87158+++ b/net/irda/iriap.c
87159@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
87160 /* case CS_ISO_8859_9: */
87161 /* case CS_UNICODE: */
87162 default:
87163- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
87164- __func__, ias_charset_types[charset]);
87165+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
87166+ __func__, charset,
87167+ charset < ARRAY_SIZE(ias_charset_types) ?
87168+ ias_charset_types[charset] :
87169+ "(unknown)");
87170
87171 /* Aborting, close connection! */
87172 iriap_disconnect_request(self);
87173diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
87174index cd6f7a9..e63fe89 100644
87175--- a/net/iucv/af_iucv.c
87176+++ b/net/iucv/af_iucv.c
87177@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
87178
87179 write_lock_bh(&iucv_sk_list.lock);
87180
87181- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
87182+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87183 while (__iucv_get_sock_by_name(name)) {
87184 sprintf(name, "%08x",
87185- atomic_inc_return(&iucv_sk_list.autobind_name));
87186+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87187 }
87188
87189 write_unlock_bh(&iucv_sk_list.lock);
87190diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
87191index df08250..02021fe 100644
87192--- a/net/iucv/iucv.c
87193+++ b/net/iucv/iucv.c
87194@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
87195 return NOTIFY_OK;
87196 }
87197
87198-static struct notifier_block __refdata iucv_cpu_notifier = {
87199+static struct notifier_block iucv_cpu_notifier = {
87200 .notifier_call = iucv_cpu_notify,
87201 };
87202
87203diff --git a/net/key/af_key.c b/net/key/af_key.c
87204index 5b426a6..970032b 100644
87205--- a/net/key/af_key.c
87206+++ b/net/key/af_key.c
87207@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
87208 static u32 get_acqseq(void)
87209 {
87210 u32 res;
87211- static atomic_t acqseq;
87212+ static atomic_unchecked_t acqseq;
87213
87214 do {
87215- res = atomic_inc_return(&acqseq);
87216+ res = atomic_inc_return_unchecked(&acqseq);
87217 } while (!res);
87218 return res;
87219 }
87220diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
87221index 0479c64..d031db6 100644
87222--- a/net/mac80211/cfg.c
87223+++ b/net/mac80211/cfg.c
87224@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
87225 ret = ieee80211_vif_use_channel(sdata, chandef,
87226 IEEE80211_CHANCTX_EXCLUSIVE);
87227 }
87228- } else if (local->open_count == local->monitors) {
87229+ } else if (local_read(&local->open_count) == local->monitors) {
87230 local->_oper_channel = chandef->chan;
87231 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
87232 ieee80211_hw_config(local, 0);
87233@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
87234 else
87235 local->probe_req_reg--;
87236
87237- if (!local->open_count)
87238+ if (!local_read(&local->open_count))
87239 break;
87240
87241 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
87242diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
87243index 2ed065c..948177f 100644
87244--- a/net/mac80211/ieee80211_i.h
87245+++ b/net/mac80211/ieee80211_i.h
87246@@ -28,6 +28,7 @@
87247 #include <net/ieee80211_radiotap.h>
87248 #include <net/cfg80211.h>
87249 #include <net/mac80211.h>
87250+#include <asm/local.h>
87251 #include "key.h"
87252 #include "sta_info.h"
87253 #include "debug.h"
87254@@ -909,7 +910,7 @@ struct ieee80211_local {
87255 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
87256 spinlock_t queue_stop_reason_lock;
87257
87258- int open_count;
87259+ local_t open_count;
87260 int monitors, cooked_mntrs;
87261 /* number of interfaces with corresponding FIF_ flags */
87262 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
87263diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
87264index 8be854e..ad72a69 100644
87265--- a/net/mac80211/iface.c
87266+++ b/net/mac80211/iface.c
87267@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87268 break;
87269 }
87270
87271- if (local->open_count == 0) {
87272+ if (local_read(&local->open_count) == 0) {
87273 res = drv_start(local);
87274 if (res)
87275 goto err_del_bss;
87276@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87277 break;
87278 }
87279
87280- if (local->monitors == 0 && local->open_count == 0) {
87281+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
87282 res = ieee80211_add_virtual_monitor(local);
87283 if (res)
87284 goto err_stop;
87285@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87286 mutex_unlock(&local->mtx);
87287
87288 if (coming_up)
87289- local->open_count++;
87290+ local_inc(&local->open_count);
87291
87292 if (hw_reconf_flags)
87293 ieee80211_hw_config(local, hw_reconf_flags);
87294@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87295 err_del_interface:
87296 drv_remove_interface(local, sdata);
87297 err_stop:
87298- if (!local->open_count)
87299+ if (!local_read(&local->open_count))
87300 drv_stop(local);
87301 err_del_bss:
87302 sdata->bss = NULL;
87303@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87304 }
87305
87306 if (going_down)
87307- local->open_count--;
87308+ local_dec(&local->open_count);
87309
87310 switch (sdata->vif.type) {
87311 case NL80211_IFTYPE_AP_VLAN:
87312@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87313
87314 ieee80211_recalc_ps(local, -1);
87315
87316- if (local->open_count == 0) {
87317+ if (local_read(&local->open_count) == 0) {
87318 if (local->ops->napi_poll)
87319 napi_disable(&local->napi);
87320 ieee80211_clear_tx_pending(local);
87321@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87322 }
87323 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
87324
87325- if (local->monitors == local->open_count && local->monitors > 0)
87326+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
87327 ieee80211_add_virtual_monitor(local);
87328 }
87329
87330diff --git a/net/mac80211/main.c b/net/mac80211/main.c
87331index 1b087ff..bf600e9 100644
87332--- a/net/mac80211/main.c
87333+++ b/net/mac80211/main.c
87334@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
87335 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
87336 IEEE80211_CONF_CHANGE_POWER);
87337
87338- if (changed && local->open_count) {
87339+ if (changed && local_read(&local->open_count)) {
87340 ret = drv_config(local, changed);
87341 /*
87342 * Goal:
87343diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
87344index 79a48f3..5e185c9 100644
87345--- a/net/mac80211/pm.c
87346+++ b/net/mac80211/pm.c
87347@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87348 struct sta_info *sta;
87349 struct ieee80211_chanctx *ctx;
87350
87351- if (!local->open_count)
87352+ if (!local_read(&local->open_count))
87353 goto suspend;
87354
87355 ieee80211_scan_cancel(local);
87356@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87357 cancel_work_sync(&local->dynamic_ps_enable_work);
87358 del_timer_sync(&local->dynamic_ps_timer);
87359
87360- local->wowlan = wowlan && local->open_count;
87361+ local->wowlan = wowlan && local_read(&local->open_count);
87362 if (local->wowlan) {
87363 int err = drv_suspend(local, wowlan);
87364 if (err < 0) {
87365@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87366 mutex_unlock(&local->chanctx_mtx);
87367
87368 /* stop hardware - this must stop RX */
87369- if (local->open_count)
87370+ if (local_read(&local->open_count))
87371 ieee80211_stop_device(local);
87372
87373 suspend:
87374diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
87375index dd88381..eef4dd6 100644
87376--- a/net/mac80211/rate.c
87377+++ b/net/mac80211/rate.c
87378@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
87379
87380 ASSERT_RTNL();
87381
87382- if (local->open_count)
87383+ if (local_read(&local->open_count))
87384 return -EBUSY;
87385
87386 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
87387diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
87388index c97a065..ff61928 100644
87389--- a/net/mac80211/rc80211_pid_debugfs.c
87390+++ b/net/mac80211/rc80211_pid_debugfs.c
87391@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
87392
87393 spin_unlock_irqrestore(&events->lock, status);
87394
87395- if (copy_to_user(buf, pb, p))
87396+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
87397 return -EFAULT;
87398
87399 return p;
87400diff --git a/net/mac80211/util.c b/net/mac80211/util.c
87401index f11e8c5..08d0013 100644
87402--- a/net/mac80211/util.c
87403+++ b/net/mac80211/util.c
87404@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
87405 }
87406 #endif
87407 /* everything else happens only if HW was up & running */
87408- if (!local->open_count)
87409+ if (!local_read(&local->open_count))
87410 goto wake_up;
87411
87412 /*
87413diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
87414index 49e96df..63a51c3 100644
87415--- a/net/netfilter/Kconfig
87416+++ b/net/netfilter/Kconfig
87417@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
87418
87419 To compile it as a module, choose M here. If unsure, say N.
87420
87421+config NETFILTER_XT_MATCH_GRADM
87422+ tristate '"gradm" match support'
87423+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
87424+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
87425+ ---help---
87426+ The gradm match allows to match on grsecurity RBAC being enabled.
87427+ It is useful when iptables rules are applied early on bootup to
87428+ prevent connections to the machine (except from a trusted host)
87429+ while the RBAC system is disabled.
87430+
87431 config NETFILTER_XT_MATCH_HASHLIMIT
87432 tristate '"hashlimit" match support'
87433 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
87434diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
87435index 3259697..54d5393 100644
87436--- a/net/netfilter/Makefile
87437+++ b/net/netfilter/Makefile
87438@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
87439 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
87440 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
87441 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
87442+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
87443 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
87444 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
87445 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
87446diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
87447index 6d6d8f2..a676749 100644
87448--- a/net/netfilter/ipset/ip_set_core.c
87449+++ b/net/netfilter/ipset/ip_set_core.c
87450@@ -1800,7 +1800,7 @@ done:
87451 return ret;
87452 }
87453
87454-static struct nf_sockopt_ops so_set __read_mostly = {
87455+static struct nf_sockopt_ops so_set = {
87456 .pf = PF_INET,
87457 .get_optmin = SO_IP_SET,
87458 .get_optmax = SO_IP_SET + 1,
87459diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
87460index 30e764a..c3b6a9d 100644
87461--- a/net/netfilter/ipvs/ip_vs_conn.c
87462+++ b/net/netfilter/ipvs/ip_vs_conn.c
87463@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
87464 /* Increase the refcnt counter of the dest */
87465 atomic_inc(&dest->refcnt);
87466
87467- conn_flags = atomic_read(&dest->conn_flags);
87468+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
87469 if (cp->protocol != IPPROTO_UDP)
87470 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
87471 flags = cp->flags;
87472@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
87473 atomic_set(&cp->refcnt, 1);
87474
87475 atomic_set(&cp->n_control, 0);
87476- atomic_set(&cp->in_pkts, 0);
87477+ atomic_set_unchecked(&cp->in_pkts, 0);
87478
87479 atomic_inc(&ipvs->conn_count);
87480 if (flags & IP_VS_CONN_F_NO_CPORT)
87481@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
87482
87483 /* Don't drop the entry if its number of incoming packets is not
87484 located in [0, 8] */
87485- i = atomic_read(&cp->in_pkts);
87486+ i = atomic_read_unchecked(&cp->in_pkts);
87487 if (i > 8 || i < 0) return 0;
87488
87489 if (!todrop_rate[i]) return 0;
87490diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
87491index 47edf5a..235b07d 100644
87492--- a/net/netfilter/ipvs/ip_vs_core.c
87493+++ b/net/netfilter/ipvs/ip_vs_core.c
87494@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
87495 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
87496 /* do not touch skb anymore */
87497
87498- atomic_inc(&cp->in_pkts);
87499+ atomic_inc_unchecked(&cp->in_pkts);
87500 ip_vs_conn_put(cp);
87501 return ret;
87502 }
87503@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
87504 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
87505 pkts = sysctl_sync_threshold(ipvs);
87506 else
87507- pkts = atomic_add_return(1, &cp->in_pkts);
87508+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87509
87510 if (ipvs->sync_state & IP_VS_STATE_MASTER)
87511 ip_vs_sync_conn(net, cp, pkts);
87512diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
87513index ec664cb..7f34a77 100644
87514--- a/net/netfilter/ipvs/ip_vs_ctl.c
87515+++ b/net/netfilter/ipvs/ip_vs_ctl.c
87516@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
87517 ip_vs_rs_hash(ipvs, dest);
87518 write_unlock_bh(&ipvs->rs_lock);
87519 }
87520- atomic_set(&dest->conn_flags, conn_flags);
87521+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
87522
87523 /* bind the service */
87524 if (!dest->svc) {
87525@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
87526 * align with netns init in ip_vs_control_net_init()
87527 */
87528
87529-static struct ctl_table vs_vars[] = {
87530+static ctl_table_no_const vs_vars[] __read_only = {
87531 {
87532 .procname = "amemthresh",
87533 .maxlen = sizeof(int),
87534@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87535 " %-7s %-6d %-10d %-10d\n",
87536 &dest->addr.in6,
87537 ntohs(dest->port),
87538- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87539+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87540 atomic_read(&dest->weight),
87541 atomic_read(&dest->activeconns),
87542 atomic_read(&dest->inactconns));
87543@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87544 "%-7s %-6d %-10d %-10d\n",
87545 ntohl(dest->addr.ip),
87546 ntohs(dest->port),
87547- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87548+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87549 atomic_read(&dest->weight),
87550 atomic_read(&dest->activeconns),
87551 atomic_read(&dest->inactconns));
87552@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
87553
87554 entry.addr = dest->addr.ip;
87555 entry.port = dest->port;
87556- entry.conn_flags = atomic_read(&dest->conn_flags);
87557+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
87558 entry.weight = atomic_read(&dest->weight);
87559 entry.u_threshold = dest->u_threshold;
87560 entry.l_threshold = dest->l_threshold;
87561@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
87562 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
87563 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
87564 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
87565- (atomic_read(&dest->conn_flags) &
87566+ (atomic_read_unchecked(&dest->conn_flags) &
87567 IP_VS_CONN_F_FWD_MASK)) ||
87568 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
87569 atomic_read(&dest->weight)) ||
87570@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
87571 {
87572 int idx;
87573 struct netns_ipvs *ipvs = net_ipvs(net);
87574- struct ctl_table *tbl;
87575+ ctl_table_no_const *tbl;
87576
87577 atomic_set(&ipvs->dropentry, 0);
87578 spin_lock_init(&ipvs->dropentry_lock);
87579diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
87580index fdd89b9..bd96aa9 100644
87581--- a/net/netfilter/ipvs/ip_vs_lblc.c
87582+++ b/net/netfilter/ipvs/ip_vs_lblc.c
87583@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
87584 * IPVS LBLC sysctl table
87585 */
87586 #ifdef CONFIG_SYSCTL
87587-static ctl_table vs_vars_table[] = {
87588+static ctl_table_no_const vs_vars_table[] __read_only = {
87589 {
87590 .procname = "lblc_expiration",
87591 .data = NULL,
87592diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
87593index c03b6a3..8ce3681 100644
87594--- a/net/netfilter/ipvs/ip_vs_lblcr.c
87595+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
87596@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
87597 * IPVS LBLCR sysctl table
87598 */
87599
87600-static ctl_table vs_vars_table[] = {
87601+static ctl_table_no_const vs_vars_table[] __read_only = {
87602 {
87603 .procname = "lblcr_expiration",
87604 .data = NULL,
87605diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
87606index 44fd10c..2a163b3 100644
87607--- a/net/netfilter/ipvs/ip_vs_sync.c
87608+++ b/net/netfilter/ipvs/ip_vs_sync.c
87609@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
87610 cp = cp->control;
87611 if (cp) {
87612 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87613- pkts = atomic_add_return(1, &cp->in_pkts);
87614+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87615 else
87616 pkts = sysctl_sync_threshold(ipvs);
87617 ip_vs_sync_conn(net, cp->control, pkts);
87618@@ -758,7 +758,7 @@ control:
87619 if (!cp)
87620 return;
87621 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87622- pkts = atomic_add_return(1, &cp->in_pkts);
87623+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87624 else
87625 pkts = sysctl_sync_threshold(ipvs);
87626 goto sloop;
87627@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
87628
87629 if (opt)
87630 memcpy(&cp->in_seq, opt, sizeof(*opt));
87631- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87632+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87633 cp->state = state;
87634 cp->old_state = cp->state;
87635 /*
87636diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
87637index ee6b7a9..f9a89f6 100644
87638--- a/net/netfilter/ipvs/ip_vs_xmit.c
87639+++ b/net/netfilter/ipvs/ip_vs_xmit.c
87640@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
87641 else
87642 rc = NF_ACCEPT;
87643 /* do not touch skb anymore */
87644- atomic_inc(&cp->in_pkts);
87645+ atomic_inc_unchecked(&cp->in_pkts);
87646 goto out;
87647 }
87648
87649@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
87650 else
87651 rc = NF_ACCEPT;
87652 /* do not touch skb anymore */
87653- atomic_inc(&cp->in_pkts);
87654+ atomic_inc_unchecked(&cp->in_pkts);
87655 goto out;
87656 }
87657
87658diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
87659index 7df424e..a527b02 100644
87660--- a/net/netfilter/nf_conntrack_acct.c
87661+++ b/net/netfilter/nf_conntrack_acct.c
87662@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
87663 #ifdef CONFIG_SYSCTL
87664 static int nf_conntrack_acct_init_sysctl(struct net *net)
87665 {
87666- struct ctl_table *table;
87667+ ctl_table_no_const *table;
87668
87669 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
87670 GFP_KERNEL);
87671diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
87672index e4a0c4f..c263f28 100644
87673--- a/net/netfilter/nf_conntrack_core.c
87674+++ b/net/netfilter/nf_conntrack_core.c
87675@@ -1529,6 +1529,10 @@ err_extend:
87676 #define DYING_NULLS_VAL ((1<<30)+1)
87677 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
87678
87679+#ifdef CONFIG_GRKERNSEC_HIDESYM
87680+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
87681+#endif
87682+
87683 static int nf_conntrack_init_net(struct net *net)
87684 {
87685 int ret;
87686@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
87687 goto err_stat;
87688 }
87689
87690+#ifdef CONFIG_GRKERNSEC_HIDESYM
87691+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
87692+#else
87693 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
87694+#endif
87695 if (!net->ct.slabname) {
87696 ret = -ENOMEM;
87697 goto err_slabname;
87698diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
87699index faa978f..1afb18f 100644
87700--- a/net/netfilter/nf_conntrack_ecache.c
87701+++ b/net/netfilter/nf_conntrack_ecache.c
87702@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
87703 #ifdef CONFIG_SYSCTL
87704 static int nf_conntrack_event_init_sysctl(struct net *net)
87705 {
87706- struct ctl_table *table;
87707+ ctl_table_no_const *table;
87708
87709 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
87710 GFP_KERNEL);
87711diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
87712index 884f2b3..d53b33a 100644
87713--- a/net/netfilter/nf_conntrack_helper.c
87714+++ b/net/netfilter/nf_conntrack_helper.c
87715@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
87716
87717 static int nf_conntrack_helper_init_sysctl(struct net *net)
87718 {
87719- struct ctl_table *table;
87720+ ctl_table_no_const *table;
87721
87722 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
87723 GFP_KERNEL);
87724diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
87725index 51e928d..72a413a 100644
87726--- a/net/netfilter/nf_conntrack_proto.c
87727+++ b/net/netfilter/nf_conntrack_proto.c
87728@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
87729
87730 static void
87731 nf_ct_unregister_sysctl(struct ctl_table_header **header,
87732- struct ctl_table **table,
87733+ ctl_table_no_const **table,
87734 unsigned int users)
87735 {
87736 if (users > 0)
87737diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
87738index e7185c6..4ad6c9c 100644
87739--- a/net/netfilter/nf_conntrack_standalone.c
87740+++ b/net/netfilter/nf_conntrack_standalone.c
87741@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
87742
87743 static int nf_conntrack_standalone_init_sysctl(struct net *net)
87744 {
87745- struct ctl_table *table;
87746+ ctl_table_no_const *table;
87747
87748 if (net_eq(net, &init_net)) {
87749 nf_ct_netfilter_header =
87750diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
87751index 7ea8026..bc9512d 100644
87752--- a/net/netfilter/nf_conntrack_timestamp.c
87753+++ b/net/netfilter/nf_conntrack_timestamp.c
87754@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
87755 #ifdef CONFIG_SYSCTL
87756 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
87757 {
87758- struct ctl_table *table;
87759+ ctl_table_no_const *table;
87760
87761 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
87762 GFP_KERNEL);
87763diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
87764index 9e31269..bc4c1b7 100644
87765--- a/net/netfilter/nf_log.c
87766+++ b/net/netfilter/nf_log.c
87767@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
87768
87769 #ifdef CONFIG_SYSCTL
87770 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
87771-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
87772+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
87773 static struct ctl_table_header *nf_log_dir_header;
87774
87775 static int nf_log_proc_dostring(ctl_table *table, int write,
87776@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
87777 rcu_assign_pointer(nf_loggers[tindex], logger);
87778 mutex_unlock(&nf_log_mutex);
87779 } else {
87780+ ctl_table_no_const nf_log_table = *table;
87781+
87782 mutex_lock(&nf_log_mutex);
87783 logger = rcu_dereference_protected(nf_loggers[tindex],
87784 lockdep_is_held(&nf_log_mutex));
87785 if (!logger)
87786- table->data = "NONE";
87787+ nf_log_table.data = "NONE";
87788 else
87789- table->data = logger->name;
87790- r = proc_dostring(table, write, buffer, lenp, ppos);
87791+ nf_log_table.data = logger->name;
87792+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87793 mutex_unlock(&nf_log_mutex);
87794 }
87795
87796diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87797index f042ae5..30ea486 100644
87798--- a/net/netfilter/nf_sockopt.c
87799+++ b/net/netfilter/nf_sockopt.c
87800@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87801 }
87802 }
87803
87804- list_add(&reg->list, &nf_sockopts);
87805+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87806 out:
87807 mutex_unlock(&nf_sockopt_mutex);
87808 return ret;
87809@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87810 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87811 {
87812 mutex_lock(&nf_sockopt_mutex);
87813- list_del(&reg->list);
87814+ pax_list_del((struct list_head *)&reg->list);
87815 mutex_unlock(&nf_sockopt_mutex);
87816 }
87817 EXPORT_SYMBOL(nf_unregister_sockopt);
87818diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87819index 92fd8ec..3f6ea4b 100644
87820--- a/net/netfilter/nfnetlink_log.c
87821+++ b/net/netfilter/nfnetlink_log.c
87822@@ -72,7 +72,7 @@ struct nfulnl_instance {
87823 };
87824
87825 static DEFINE_SPINLOCK(instances_lock);
87826-static atomic_t global_seq;
87827+static atomic_unchecked_t global_seq;
87828
87829 #define INSTANCE_BUCKETS 16
87830 static struct hlist_head instance_table[INSTANCE_BUCKETS];
87831@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
87832 /* global sequence number */
87833 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
87834 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
87835- htonl(atomic_inc_return(&global_seq))))
87836+ htonl(atomic_inc_return_unchecked(&global_seq))))
87837 goto nla_put_failure;
87838
87839 if (data_len) {
87840diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
87841new file mode 100644
87842index 0000000..c566332
87843--- /dev/null
87844+++ b/net/netfilter/xt_gradm.c
87845@@ -0,0 +1,51 @@
87846+/*
87847+ * gradm match for netfilter
87848